mIRC Home    About    Download    Register    News    Help

Topic Options
#253040 - 23/05/15 07:05 PM /write filename (no extension) + $chr(160)
WhatdaFox Offline
Pikka bird

Registered: 04/12/14
Posts: 12
I have an issue. Basically I'm trying to simulate Twitch chatters tmi thingy (tmi.twitch.tv/group/user/USERNAME/chatters) for active users on the channel. Everytime I write something on the file that contains $chr(160) it replaces it with "".

I know that's due to the abstence of BOM (byte order mark). How do I fix this?

ps: I'm using v7.36.
ps2: File is constantly being updated.


Edited by WhatdaFox (23/05/15 07:10 PM)

Top
#253041 - 23/05/15 07:33 PM Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox]
WhatdaFox Offline
Pikka bird

Registered: 04/12/14
Posts: 12
Okay... Apparently I can just write as a text file and then rename it.

*Edit* works manually but it doesn't when you try to automate it. Help?


Edited by WhatdaFox (23/05/15 07:43 PM)

Top
#253042 - 23/05/15 07:48 PM Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox]
OrFeAsGr Offline
Fjord artisan

Registered: 01/02/15
Posts: 243
Loc: Greece
i don't know the answer to the 1st post but you can rename a file by using /rename filename newfilename
I'm not sure if it's going to change the file type though.. if this is what you're tring to do.

Top
#253043 - 23/05/15 07:51 PM Re: /write filename (no extension) + $chr(160) [Re: OrFeAsGr]
WhatdaFox Offline
Pikka bird

Registered: 04/12/14
Posts: 12
You can actually rename the file but it doesn't work. Once you do it, it replaces every space with " " (not on the file. if you upload it to a webserver, you will see that weird character).


Edited by WhatdaFox (23/05/15 07:53 PM)

Top
#253057 - 24/05/15 12:32 AM Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox]
Loki12583 Offline
Hoopy frood

Registered: 22/01/04
Posts: 1263
Configure your server to specify the charset in the content-type header: content-type:text/plain; charset=UTF-8

In nginx this is accomplished with the "charset UTF-8;" directive.

When the charset is not specified by the server Firefox and IE use Western encoding whereas Chrome uses Unicode.

----

Edit: Simply writing $chr(65279) as the first character will write the BOM

In general mIRC does not play well with the BOM, and subsequent calls to write the first line will remove the BOM.

I've created two methods to insert a BOM, the first attempts to prepend and rewrite the first line of the file; as usual mIRC will drop trailing/ending spaces. The second reads the entire file, writes the BOM, then rewrites the file. This may be less efficient than mIRC's write function but does not alter the file other than inserting the BOM.

Code:
alias bom return $chr(65279)

alias hasbom {
  var %file = $qt($1-)
  bread $qt(%file) 0 3 &test
  if ($bvar(&test,1-).text == $bom) { return $true }
  return $false
}

alias insertbom {
  var %file = $qt($1-)

  if ($hasbom(%file)) { return }

  if ($lines(%file)) {
    write -l1 %file $bom $+ $read(%file,n,1)
  }
  else {
    bset -t &bom 1 $bom
    bwrite %file 0 -1 &bom
  }
}

alias insertbom2 {
  var %file = $qt($1-)

  if ($hasbom(%file)) { return }

  if ($file(%file).size) {
    bread $qt(%file) 0 $v1 &read
  }

  bset &bom 1 239 187 191
  bwrite %file 0 -1 &bom
  
  if ($bvar(&read,0)) bwrite %file 3 -1 &read
}


Edited by Loki12583 (24/05/15 06:31 AM)

Top
#253066 - 24/05/15 05:22 PM Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
Hum, your post is very very confusing.

Quote:
Everytime I write something on the file that contains $chr(160) it replaces it with "".
This doesn't mean anything, are you using /write with $chr(160) and it doesn't write the $chr(160) correctly? if so what does it write to the file, how are you checking that it didn't write to the file correctly?
If you are unaware, mIRC will write to the file with Unicode, that means $chr(160) will be wrote as the two bytes 194 and 160, which will, when $read back to mirc be combined to form the real $chr(160), could it be that you didn't know that and that's why got you confused?

In any case please describe as much as possible your problem and don't bring ttwich, it's not a problem with twitch.

@Loki, how do you figure it's a BOM problem? mIRC uses it fine, it's there if /write to a file (which is an unicode file already or doesn't exist)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#253067 - 24/05/15 05:53 PM Re: /write filename (no extension) + $chr(160) [Re: Wims]
Loki12583 Offline
Hoopy frood

Registered: 22/01/04
Posts: 1263
//write file.txt $chr(160) will result in the following file: c2 a0 0d 0a (no BOM)

Adding the BOM manually results in this file: ef bb bf c2 a0 0d 0a

//write -l1 file.txt $chr(160) results in the BOM being removed

Viewing the file without the BOM in Firefox or IE results in "" being displayed because they interpret it as Western encoding.

Top
#253068 - 24/05/15 06:01 PM Re: /write filename (no extension) + $chr(160) [Re: Wims]
WhatdaFox Offline
Pikka bird

Registered: 04/12/14
Posts: 12
Originally Posted By: Wims
In any case please describe as much as possible your problem and don't bring ttwich, it's not a problem with twitch.


When did I say it was a twitch problem? Geez -_-


@Loki12583 thank you for your help, it's working now. I really appreciate it.


Edited by WhatdaFox (24/05/15 06:08 PM)

Top
#253072 - 24/05/15 07:27 PM Re: /write filename (no extension) + $chr(160) [Re: Loki12583]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
Hu, I was thinking mIRC was using BOM, for /write or whenever it could be required. I remember some thread about it,

@OP Didn't mean to be annoying, I didn't say you said it was a twitch problem, I just tried to understand, you didn't say how you were writting to the file and who was it that 'replaced' it with "" (it wasn't replaced then, just displayed/interpreted).
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top