I am completing an acronym replacer script and have all of the dialogs and front end business as I desire. However I can not seem to complete the cod that woudl read from the file, and replace the acronym with the whole word(s). (example LOL should equal Laughs Out Loud).
As I mentioned I have the creation of the file, and editable through dialog. The file looks like this:
[Inputs]
N1=stfu
N2=heh
N3=lol
[Outputs]
N1=4Shut the F*ck Up
N2=4Grins
N3=4Laughs Out Loud
So far all I can complete is the following:
on *:INPUT:?,#:{ if ($1- isin ($readini -n $mircdiracronyms\acronyms.ini Inputs)) { set %Acrotext ($readini -n $mircdiracronyms\acronyms.ini Outputs)
but that doesnt seem right, and I'm not certian how to display it. Thanks for any help.
Why not use
[Acronym]
lol=Laughing Out Load
rofl=Rolling On Floor Laughing
then cycle through the words in your input trigger. If the word exists in the ini file, replace it >:D
Why not just use $replace($1-,lol,Laugh Out Loud)? :|
because then your stuck with just the list in remotes. With an ini, you can make a dialog and the user can add and remove them easily, without having to touch a single line of code >:D
Ah, I see now. Sorry for me butting in.
Thanks for replies. King Tomato - I can certianly format the .ini file that way (I prefer the current format but whatver works is acceptable). but, I stil am not certain how I would script this to work.
on *:INPUT:?,#:{ if ($1- isin ($readini -n $mircdiracronyms\acronyms.ini Acronyms))
I cant think of where to go from there. sorry for my lack of scripting ability.
np, your entitile to questioning something thats how ya learn >:D
Why isnt this working: (Im using my exisintg ini file format, I have not udpated to the way you suggested KT as I dont know how to implement that either)
alias Acronyms.read { return $readini -n " $+ acro.ini $+ " $1 $2 }
on *:input:*: {
if ($left($1,1) == /) || ($left($1,1) == :) { return }
else {
var %Acronyms.temp = 0
:Acrocheck
inc %Acronyms.temp 1
if ($1- isin $Acronyms.read(Inputs,%Acronyms.temp)) { set %Acrotext $Acronyms.read(Outputs,%Acronyms.temp) | goto Acrotalk }
if ($Acronyms.read(Inputs,%Acronyms.temp) != $null) { goto Acrocheck }
:Acrotalk
set %acrotmp $Acronyms.read(Inputs,%Acronyms.temp)
say $replace($1-,%Acrotmp,%tmp) | halt
}
}
Try changing:
alias Acronyms.read { return $readini -n " $+ acro.ini $+ " $1 $2 }
to:
alias Acronyms.read { return $readini(acro.ini,n,$1,N $+ $2) }
No it didnt seem to make a difference. my problem is pry in my output: say $replace($1-,%Acrotmp,%tmp)
I dont know, im a little frustrated wiht it now, I'm going to take a break and work on it later.
acro.ini
[acro]
lol=laughing out loud
brb=be right back
afk=away from keyboard
Remote,
On *:input:#:{
if /* iswm $1 || $ctrlenter { return }
var %i = 1, %total = $0, %word, %string
while %i <= %total {
%word = $ [ $+ [ %i ] ]
if $readini(acro.ini,acro,%word) {
%string = %string $ifmatch
}
else %string = %string %word
%i = %i + 1
}
say %string
halt
}
Doing a several $readini for every input slows down.
I would store my acronyms in a
hash table (faster)
and use $hget(table,%word) instead of $readini().
Thank You, that small bit of script worked. (you should have seen the spaghetti I was turning it into). The only other hurdle I need to try to get over is that it doesn display formatting and colors, for example
rather than displaying as
laughs It shows as 4laughs. Can I get around this somehow ?
INI's don't save color codes. If u used /writeini to write a color to the ini, it was stripped. You need to use comething like replace to change ^c into something like <c>, ^b = <b>, etc. Then when you read it, replace <c> -> ^cm <b> --> ^b, etc.
very good point ..... your better off the just saving it to a .mrc and reading it from that ..... saving your color codes
As Tomato suggested, here's color replacement aliases,
alias rini { echo return $replacecs($$readini($1,$2,$3),^B,$chr(2),^K,$chr(3),^O,$chr(15),^R,$chr(22),^U,$chr(31)) }
alias wini { !writeini $1-3 $replacecs($4-,$chr(2),^B,$chr(3),^K,$chr(15),^O,$chr(22),^R,$chr(31),^U) }
//wini test.ini a b 10colorboldunderlinereverse
//echo -a $rini(test.ini,a,b)
In our example it would become: $rini(acro.ini,acro,%word)
The inability of storing colors in ini files is one of the reasons why I prefer hash tables.