Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
weird string problem
#1
i downloaded a strange file which seems like it's a tarball, but tar doesn't work on it, so i thought i'd make up a fb program to extract the files, to save myself hours of copy-paste work. it works up to parsing the directory path "servers/posix/trunk/include/db/db_misc.h" here's my code
Code:
b$=" "
cls
print "what is the dir to the busted-up tarball?"
line input "",dire$
open dire$+"alurio.tar" for input as #1
open dire$+"alurio.tar" for input as #3
open dire$+"alurio.tar" for binary as #2
while not eof(1)
   line input #1,a$
   if a$="" or a$="tools/rsee" then
      seek #2,seek(3)
      b$=chr$(0)
      while b$=chr$(0)
         get #2,,b$
      wend
      fname$=b$
      while b$<>chr$(0) and b$<>chr$(13) and b$<>chr$(10)
         get #2,,b$
         fname$=fname$+b$
      wend
      if b$<>chr$(13) and b$<>chr$(10) then
         'extract first line (easy!)
         b$=chr$(0)
         while b$<>chr$(10) and b$<>chr$(13):get #2,,b$:wend
         seek #2,seek(2)-2
         while b$<>chr$(0)
            get #2,,b$
            if b$<>chr$(0) then a$=b$+a$
            seek #2,seek(2)-2
         wend
         close #5
         'navigate to correct folder & open output file
         shell "cd > dir.txt"
         open "dir.txt" for input as #4
         line input #4, somestuffs$
         close #4
         print fname$:if instr(fname$,"servers/posix/trunk/include/db/db_misc.h")>0 then cool=1:print "cool...?"
         while instr(fname$,"/")>0
            dar$=mid$(fname$,1,instr(fname$,"/")-1)
            shell "cd "+somestuffs$+"\"+dar$
            shell "cd > dir.txt"
            open "dir.txt" for input as #4
            line input #4, stuff$
            close #4
            if stuff$<>somestuffs$+"\"+dar$ then mkdir somestuffs$+"\"+dar$:shell "cd "+somestuffs$+"\"+dar$
            somestuffs$=somestuffs$+"\"+dar$
            if cool=1 then print "pre:"+fname$;instr(fname$,"/"),mid$(fname$,6,1),mid$(fname$,6,1)="/"
            fname$=mid$(fname$,instr(fname$,"/")+1)
            if cool=1 then print fname$;instr(fname$,"/"),mid$(fname$,6,1),mid$(fname$,6,1)="/"
         wend
         open somestuffs$+"\"+fname$ for output as #5
         print somestuffs$+"\"+fname$+" now open."
      end if
   end if
   seek #3,seek(1)
   print #5, a$
wend
close
while inkey$="":sleep 100:wend
end
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#2
First rule with FB strings: never put null characters (chr$(0)) on them, use BYTE vars instead. FB strings are null-terminated as in C, to be able to call any C API/lib directly w/o wrappers.

In QB you had no alternative to declare a byte variable than using "dim b as string * 1", in FB you can do "dim b as byte". All operations done on them are a magnitude faster than on strings.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)