mIRC Home    About    Download    Register    News    Help

Print Thread
#188502 25/10/07 01:12 AM
Joined: Oct 2007
Posts: 214
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Oct 2007
Posts: 214
Hello and thank you for whoever can help me on this.

I would like to be able to write/delete and return information to and from a txt as a database
given the following piece of information. (please note I do not wish to use the .ini method)

[1]
Nickname: Buggs2007
Address: 629c3c899819f28cbf068691b1c7c618@Passport
Channel: %#HelpDesk

an alias that would be able to return the following:

echo -a $findinfo(1) would return 1, Nickname, Address, Channel

echo -a $findinfo(1,Nickname) would return Buggs2007

echo -a $findinfo(1,Nickname,Address) would return Nickname, Address


an alias to write to a txt file and so fourth ex. $Writeinfo($nick,$address,$chan)

[2]
Nickname: $nick
Address: $address
Channel: $chan

last but not least an alias to delete info from the database

$delinfo(1) deletes everything for:

[1]
Nickname: Buggs2007
Address: 629c3c899819f28cbf068691b1c7c618@Passport
Channel: %#HelpDesk

or selectively,

$delinfo(1,channel)


and another alias to replace or add info

$replaceinfo(1,channel,%#testing101)

I understand that this may be a little confusing, and probably huge to do, but I would like to give great thanks and credit
to whoever helps me on this.

Thanks a bunch,

Cheers,

Jason

Buggs2008 #188516 25/10/07 03:53 AM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
First off you love doing things complicated, lol... hash tables / ini would be best here but since you want txt here it is

A) don't critisize the length
B) As per your post its written
C) I even went out of my way to put a routine were if you delete a sector that on the next write it will write the sector however I didn't extend the delete routine for if you delete more then 1 sector a time before writting a new one you will cause the #'s on the script to not be proper like [1] [2] [3] [4] instead you will have [1] [3] [3] if for example you delete line [2] or something similar

Here's the script don't wear it out... hope its what your looking for, and since no one is writting for you others can maybe look at what I wrote and make it smaller. I know I can make a few extra alias and cut the script size if not half atleast 1/3rd it's size.

Code:
alias findinfo {
  if ($$1 isnum) && (!$2) && (!$3) { 
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    var %y = $readn
    return $read(ty.txt,n,%y) $read(ty.txt,n,$calc(%y + 1)) $read(ty.txt,n,$calc(%y + 2)) $read(ty.txt,n,$calc(%y + 3))
  }
  if ($$1 isnum) && ($$2 == Nickname) && (!$3) { 
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    var %y = $readn
    return $gettok($read(ty.txt,n,$calc(%y + 1)),2,32)
  }
  if ($$1 isnum) && ($$2 == Nickname) && ($$3 == Address) { 
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    var %y = $readn
    return $read(ty.txt,n,%y) $read(ty.txt,n,$calc(%y + 1)) $read(ty.txt,n,$calc(%y + 2))  
  }
}

alias writeinfo { 
  if (%info.v) {
    var %x = $gettok(%info.v,2,32)
    .write -il $+ %x ty.txt $+([,$gettok($v1,1,32),])
    .write -il $+ $calc(%x + 1) ty.txt Nickname: $1
    .write -il $+ $calc(%x + 2) ty.txt Address: $2
    .write -il $+ $calc(%x + 3) ty.txt Channel: $3
    .unset %info.v
  }
  else {
    if (%info.d) {
      .write ty.txt $+([,%info.d,]) | inc %info.d
      .write ty.txt Nickname: $1
      .write ty.txt Address: $2
      .write ty.txt Channel: $3
    }
    else { 
      .write ty.txt $+([,1,]) | %info.d = 2
      .write ty.txt Nickname: $1
      .write ty.txt Address: $2
      .write ty.txt Channel: $3
    }
  }
}

alias delinfo {
  if ($$1 isnum) && (!$2) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*)) 
    .write -dl $+ $readn ty.txt
    .write -dl $+ $readn ty.txt
    .write -dl $+ $readn ty.txt
    .write -dl $+ $readn ty.txt
    %info.v = $$1 $readn
  }
  if ($$1 isnum) && ($$2 == Channel) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Channel:
  }
  if ($$1 isnum) && ($$2 == Address) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Address:
  }
  if ($$1 isnum) && ($$2 == Nickname) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Nickname:
  }
}

alias replaceinfo {
  if ($$1 isnum) && ($$2 == Channel) && ($$3) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Channel: $$3
  }
  if ($$1 isnum) && ($$2 == Address) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Address: $$3
  }
  if ($$1 isnum) && ($$2 == Nickname) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Nickname: $$3
  }
}


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Buggs2008 #188535 25/10/07 01:10 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Why in the world wouldn't you use a better method of saving the data? An INI file or hash table would cut the script down to only 10 or so lines.

Anyhow, here.

Code:
alias findinfo {
  if ($1 !isnum) { echo -a ERROR:  Invalid format. | return }
  var %Section = $read(Data.txt,w,$chr(91) $+ $1 $+ $chr(93))
  if (%Section == $null) { echo -a ERROR: That section number is not available. | return }
  var %Data = $read(Data.txt,$calc($readn + 1))
  while (: isin %Data) {
    var % $+ $gettok(%Data,1,58) $gettok(%Data,2-,58)
    var %Data = $read(Data.txt,$calc($readn + 1))
  }
  if ($2) {
  var %cnt = 2
  while (%cnt <= $0) {
    var %Output = %Output $(% $+ $($ $+ %cnt,2),2)
    inc %cnt
  }
  return %Output
  }
  else {
    return $1 $+ $iif(%Nickname,$chr(44) $+ $v1) $+ $iif(%Address,$chr(44) $+ $v1) $+ $iif(%Channel,$chr(44) $+ $v1)
  }
}

alias writeinfo {
  if (!$1) { echo -a ERROR: Invalid format. | return }
  var %cnt = 1
  if ($exists(Data.txt)) {
    filter -ffcu Data.txt Data.tmp [*
    while ($read(Data.tmp,w,$chr(91) $+ %cnt $+ $chr(93))) {
      inc %cnt
    }
    .remove Data.tmp
  }
  write Data.txt $+([, %cnt ,])
  write Data.txt Nickname: $1
  if ($2) { write Data.txt Address: $2 }
  if ($3) { write Data.txt Channel: $3 }
}

alias delinfo {
  if ($1 !isnum) { echo -a Invalid format. | return }
  var %Section = $read(Data.txt,w,$chr(91) $+ $1 $+ $chr(93))
  if (%Section == $null) { echo -a ERROR: That section number is not available. | return }
  if (!$2) {
    write -dl $readn Data.txt
    while (: isin $read(Data.txt,$readn)) {
      write -dl $readn Data.txt
    }
  }
  else {
    var %Data = $read(Data.txt,$calc($readn + 1)), %line = $readn
    while (: isin %Data) {
      if ($istok($2-,$gettok(%Data,1,58),32)) {
        write -dl %line Data.txt
      }
      else inc %line
      var %Data = $read(Data.txt,%line)
    }
  }
}

alias replaceinfo {
  if ($1 !isnum) { echo -a Invalid format. | return }
  var %Section = $read(Data.txt,w,$chr(91) $+ $1 $+ $chr(93))
  if (%Section == $null) { echo -a ERROR: That section number is not available. | return }
  var %Data = $read(Data.txt,$calc($readn + 1))
  while (: isin %Data) {
    if ($2 == $gettok(%Data,1,58)) {
      write -l $readn Data.txt $2 $+ : $3-
    }
    var %Data = $read(Data.txt,$calc($readn + 1))
  }
}


Fully tested.

USES:
N = An item number
Something = Nickname,Address,Channel,Anything else
Type = The name of the type of information (i.e. Nickname)
TypeData = The data for the specific Type (basically the same as Something)

$findinfo(N,Something)
Displays the information for Something on item N

$findinfo(N,Something,Something)
Displays the information for Something and Something on item N

Note that you can put the "Something's" in any order you want to depending on how you want them to appear.

$writeinfo(Nickname,Address,Channel)
Writes the information to the file in the first unused section #.

You don't have to include everything... $writeinfo(Nickname) will work... but you do need to put those into the correct order and cannot skip something... $writeinfo(Nickname,Channel) is invalid.

If you want to be able to write the items in any order, with or without certain data, and/or add additional types of data, this can be adjusted to use a format of $writeinfo(Type,TypeData,Type,TypeData,Type,TypeData,Type,TypeData) ... basically, include the type before the data for that type. If you need that, just ask.


$delinfo(N)
Delete all information for section N

$delinfo(N,Something)
Delete only Something from section N

$replaceinfo(N,Type,TypeData)
Replace the existing data for Type with the new TypeData

You cannot replace multiple types with the same $replaceinfo. You'll have to call it multiple times if you want to replace more than one Type's data at a time.

Any questions, just ask.


Invision Support
#Invision on irc.irchighway.net
Lpfix5 #188536 25/10/07 01:13 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Lpfix5, just a note. You should make your script verify that it's deleting valid information. You have it deleting 4 lines indiscriminately right now. If he deleted just Nickname from the section and later tried deleting the entire section, you'd end up deleting the next section number line.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #188540 25/10/07 03:07 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Not true, if you take a peek when theres a specific info delete like Channel it writes channel: in place with blank data, then the replace feature writes channel: + data therefore the actual line is never deleted...

Code:
  if ($$1 isnum) && ($$2 == Channel) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Channel:
  }
  if ($$1 isnum) && ($$2 == Address) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Address:
  }
  if ($$1 isnum) && ($$2 == Nickname) {
    var %x = $read(ty.txt,nw,$+(*[,$$1,]*))
    .write -l $+ $calc($readn + 3) ty.txt Nickname:
  }


see...

+ I wrote it in less then 20 mins. I could even make it really smaller if i choosed too laugh

Something im really formiliar with is manipulation of .txt files or online data.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Lpfix5 #188578 25/10/07 11:49 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, I see. I just glanced at it, so didn't see what you did there.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #188586 26/10/07 03:22 AM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
It's ok the interpretation of something that you didnt write is sometimes a little intimidating if it's lengthy to go through it lol alot of times I look at what people write and I try to find their issue and I get lost in lala land


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Buggs2008 #188657 27/10/07 04:51 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
What is your reason for not wanting to use the *ini commands? Someone mentioned that an ini-based script would be smaller, when in fact it would be non-existant. All those things you want already exist (to some extent) in mIRC. The only minor stumbling block is that your sample data would have to be altered to match ini formatting. If possible, the easiest way would be to change whatever generates the data. If that is not possible, a very simple script could be used to convert it (once or on the fly).

In any case, scripts have been given above that do what you want.

-genius_at_work

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
When I started scripting new commands were intimidating to me therefore I stuck with what the basics were.. and try to make everything work around it, then I found it you spend less time learning a new command that will cut your work in 2 3rds its size.

I still don't know why he didnt request INI or HASH I would personally choose hash over ini. and it would be much and i mean much more a smaller script also less confusing to target an issue if ever he brought this script forward in the future and you werent the original creator.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Buggs2008 #188679 28/10/07 01:54 AM
Joined: Oct 2007
Posts: 214
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Oct 2007
Posts: 214
Thanks for everything guys, you have helped me out alot, I was just trying to compare, how much work it would be doing txt vs. ini, it seems ini is much cleaner, and faster, but thank you for everything again. You guys are the best

Lpfix5 #188706 28/10/07 09:35 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
What he wanted wouldn't have been any smaller or less confusing as a hash over an ini. There are built in ini commands for basically everything there. Choosing hash over ini would just be a preference issue for something like this unless you're using the data regularly enough that speed/resources might be an issue, but I doubt that would be the case for this sort of data.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #188708 28/10/07 10:14 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
I meant to say that ini and hash would be smaller then the text scripts lol


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }

Link Copied to Clipboard