mIRC Home    About    Download    Register    News    Help

Print Thread
/write filename (no extension) + $chr(160) #253040
23/05/15 06:05 PM
23/05/15 06:05 PM
Joined: Dec 2014
Posts: 12
W
WhatdaFox Offline OP
Pikka bird
WhatdaFox  Offline OP
Pikka bird
W

Joined: Dec 2014
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.

Last edited by WhatdaFox; 23/05/15 06:10 PM.
Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox] #253041
23/05/15 06:33 PM
23/05/15 06:33 PM
Joined: Dec 2014
Posts: 12
W
WhatdaFox Offline OP
Pikka bird
WhatdaFox  Offline OP
Pikka bird
W

Joined: Dec 2014
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?

Last edited by WhatdaFox; 23/05/15 06:43 PM.
Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox] #253042
23/05/15 06:48 PM
23/05/15 06:48 PM
Joined: Feb 2015
Posts: 243
Greece
O
OrFeAsGr Offline
Fjord artisan
OrFeAsGr  Offline
Fjord artisan
O

Joined: Feb 2015
Posts: 243
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.

Re: /write filename (no extension) + $chr(160) [Re: OrFeAsGr] #253043
23/05/15 06:51 PM
23/05/15 06:51 PM
Joined: Dec 2014
Posts: 12
W
WhatdaFox Offline OP
Pikka bird
WhatdaFox  Offline OP
Pikka bird
W

Joined: Dec 2014
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).

Last edited by WhatdaFox; 23/05/15 06:53 PM.
Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox] #253057
23/05/15 11:32 PM
23/05/15 11:32 PM
Joined: Jan 2004
Posts: 1,271
L
Loki12583 Offline
Hoopy frood
Loki12583  Offline
Hoopy frood
L

Joined: Jan 2004
Posts: 1,271
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
}

Last edited by Loki12583; 24/05/15 05:31 AM.
Re: /write filename (no extension) + $chr(160) [Re: WhatdaFox] #253066
24/05/15 04:22 PM
24/05/15 04:22 PM
Joined: Jul 2006
Posts: 3,518
France
W
Wims Offline
Hoopy frood
Wims  Offline
Hoopy frood
W

Joined: Jul 2006
Posts: 3,518
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
Re: /write filename (no extension) + $chr(160) [Re: Wims] #253067
24/05/15 04:53 PM
24/05/15 04:53 PM
Joined: Jan 2004
Posts: 1,271
L
Loki12583 Offline
Hoopy frood
Loki12583  Offline
Hoopy frood
L

Joined: Jan 2004
Posts: 1,271
//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.

Re: /write filename (no extension) + $chr(160) [Re: Wims] #253068
24/05/15 05:01 PM
24/05/15 05:01 PM
Joined: Dec 2014
Posts: 12
W
WhatdaFox Offline OP
Pikka bird
WhatdaFox  Offline OP
Pikka bird
W

Joined: Dec 2014
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.

Last edited by WhatdaFox; 24/05/15 05:08 PM.
Re: /write filename (no extension) + $chr(160) [Re: Loki12583] #253072
24/05/15 06:27 PM
24/05/15 06:27 PM
Joined: Jul 2006
Posts: 3,518
France
W
Wims Offline
Hoopy frood
Wims  Offline
Hoopy frood
W

Joined: Jul 2006
Posts: 3,518
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