home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Amiga
/
Internet
/
Web
/
2b_Cashana.lha
/
Cashana
/
Src
/
Cashana.e
next >
Wrap
Text File
|
1998-05-04
|
4KB
|
195 lines
/*
Changes IB 1.12 Cache to normal files in HTML document
$VER: 0.35
0.35:
- dodany licznik bεδd≤w
- obsεuguje starΓ wersjδ kaszy Voyagera.
*/
OPT PREPROCESS
#define VERSION '$VER: Cashana 0.35 (04.05.98) BLABLA Production\0'
MODULE 'dos/dos'
ENUM O,ER_BADARGS, ER_BREAK
DEF sourcelist:PTR TO LONG, rdargs
DEF destdir, errors=NIL
PROC main() HANDLE
DEF next=NIL
getargs()
WHILE sourcelist[next]<>NIL
processFile(sourcelist[next])
INC next
IF CtrlC() THEN Raise(ER_BREAK)
ENDWHILE
EXCEPT DO
WriteF('Number of problems counted: \d\n',errors)
IF exception
SELECT exception
CASE ER_BADARGS; WriteF('CACHEFILE - files(s) to process\nDESTDIR - directory where to copy files\n')
CASE ER_BREAK; WriteF('BREAK **CtrlC\n')
DEFAULT; WriteF('Exception: \d\n',exception)
ENDSELECT
ENDIF
FreeArgs(rdargs)
CleanUp()
ENDPROC
/*
Gε≤wna procedura wczytujΓca pliki!
cachename=nazwa pliku z cachy do spreparowania...
*/
PROC processFile(cachename:PTR TO CHAR) HANDLE
DEF info:fileinfoblock,lock,c=0
IF lock:=Lock(cachename,-2)
IF Examine(lock,info)
WriteF('\s[17] \d[7]\n', info.filename, info.size)
cache2File(cachename,info.comment)
ENDIF
UnLock(lock)
ELSE
WriteF('Wrong file name!\n')
ENDIF
EXCEPT
INC errors
SELECT exception
CASE "OPEN"; WriteF('Cannot open file for reading\n')
CASE "IN"; WriteF('Cannot read file properly\n')
DEFAULT; WriteF('Unknown error!\n')
ENDSELECT
ENDPROC
/*
Pobiera plik, zmienia nazwe i kopiuje!
cachename...
comment - komentarz pliku
*/
PROC cache2File(cachename:PTR TO CHAR,comment:PTR TO CHAR)
DEF com:PTR TO CHAR, newfile:PTR TO CHAR
DEF mem,len, pos
-> Pobranie komentarza
IF StrLen(comment)>7
IF (pos:=InStr(comment,'http://'))<>-1
-> com:=String(StrLen(cachename)+StrLen(comment)-7)
com:=String(StrLen(comment)-7)
MidStr(com,comment,pos+7)
-> WriteF('to file: \s...\n',com)
makeDirs(com) /* tworzy potrzebne katalogi, jesli trzeba */
-> Kopiujemy plik pod nowΓ nazwΓ!
newfile:=String(StrLen(destdir)+StrLen(com)+12)
StrCopy(newfile,destdir)
AddPart(newfile,com,StrLen(destdir)+StrLen(com)+2)
IF StrCmp(newfile+StrLen(newfile)-1,'/',1) THEN AddPart(newfile,'index.html',StrLen(newfile)+12)
WriteF('Writing file as \s\n',newfile)
mem,len:=readf(cachename)
IF mem THEN savefile(newfile,mem,len) ELSE WriteF('File not saved...\n')
DisposeLink(com)
DisposeLink(newfile)
ELSE
INC errors
ENDIF
ELSE
WriteF('This file is not part of the cache\n')
INC errors
ENDIF
ENDPROC
/*
Tworzy katalogi potrzebne do przekopiowania plik≤w
w odpowiednie miejsca...
*/
PROC makeDirs(newfile:PTR TO CHAR)
DEF pos=0, dir:PTR TO CHAR, newdir:PTR TO CHAR, r
dir:=String(StrLen(newfile))
LOOP
IF (pos:=InStr(newfile,'/',pos))=-1 THEN JUMP x
StrCopy(dir,newfile,pos)
newdir:=String(StrLen(destdir)+StrLen(dir)+2)
StrCopy(newdir,destdir)
AddPart(newdir,dir,StrLen(destdir)+StrLen(dir)+2)
IF (r:=CreateDir(newdir))=NIL
-> WriteF('Nie utworzyεem katalogu!\n')
ELSE
WriteF('Creating dir \s\n',newdir)
UnLock(r)
ENDIF
DisposeLink(newdir)
INC pos
ENDLOOP
x:
ENDPROC pos
PROC readf(filename)
DEF len,memory,rl,fh
IF (len:=FileLength(filename))<1 THEN Raise("OPEN")
memory:=NewR(len)
IF (fh:=Open(filename,OLDFILE))=NIL THEN Raise("OPEN")
rl:=Read(fh,memory,len)
Close(fh)
IF rl<>len THEN Raise("IN")
ENDPROC memory,len
PROC savefile(name:PTR TO CHAR,addy,len)
DEF flock,lastlen
IF (flock:=Open(name,MODE_NEWFILE))=NIL THEN WriteF('Cannot write!\n')
lastlen:=Write(flock,addy,len)
IF lastlen<>len THEN WriteF('Cannot write!\n')
IF flock THEN Close(flock)
ENDPROC
/*
Pobranie argument≤w z CLI
*/
PROC getargs()
DEF myargs:PTR TO LONG
myargs:=[0,0,0]
IF (rdargs:=ReadArgs('CACHEFILE/A/M,DESTDIR/A',myargs,NIL))=NIL THEN Raise(ER_BADARGS)
sourcelist:=myargs[0]
destdir:=String(StrLen(myargs[1])+4)
StrCopy(destdir,myargs[1])
ENDPROC
CHAR VERSION