PACKET dirDEFINES opendir,insertdirentry,deletedirentry,initdirds,fileinfo, formatdir,dirlist,fileexists,subdirexists,allfiles,allsubdirs:LET maxdirentrys=1000;INITFLAG VAR dirblockdsused:=FALSE ;DATASPACE VAR dirblockds;BOUND STRUCT (ALIGN dummy,ROW 64REAL daten)VAR dirblock;REAL VAR lastreaddirblockno;PROC initdirblockio:lastreaddirblockno:=-1.0;IF NOT initialized(dirblockdsused)THEN dirblockds:=nilspace;dirblock:=dirblockdsFI . END PROC initdirblockio;PROC readdirblock(REAL CONST blocknr):IF lastreaddirblockno<>blocknrTHEN lastreaddirblockno:=-1.0; readdiskblockandcloseworkiferror(dirblockds,2,blocknr);lastreaddirblockno:= blocknrFI .END PROC readdirblock;PROC writedirblock(REAL CONST blocknr): writediskblockandcloseworkiferror(dirblockds,2,blocknr);lastreaddirblockno:= blocknr.END PROC writedirblock;PROC writedirblock:IF lastreaddirblockno<0.0 THEN errorstop("Lesefehler")FI ;writedirblock(lastreaddirblockno)END PROC writedirblock;PROC getdirentry(TEXT VAR entrybuffer,INT CONST blockentryno): entrybuffer:=32*".";INT CONST replaceoffset:=4*blockentryno;replace( entrybuffer,1,dirblock.daten[replaceoffset+1]);replace(entrybuffer,2,dirblock .daten[replaceoffset+2]);replace(entrybuffer,3,dirblock.daten[replaceoffset+3 ]);replace(entrybuffer,4,dirblock.daten[replaceoffset+4]).END PROC getdirentry;PROC putdirentry(TEXT CONST entrybuffer,INT CONST blockentryno): INT CONST offset:=4*blockentryno;dirblock.daten[offset+1]:=entrybufferRSUB 1; dirblock.daten[offset+2]:=entrybufferRSUB 2;dirblock.daten[offset+3]:= entrybufferRSUB 3;dirblock.daten[offset+4]:=entrybufferRSUB 4.END PROC putdirentry;LET DIRPOS =REAL ;DIRPOS PROC dirpos(REAL CONST blocknr,INT CONST entrynr):blocknr*16.0+real(entrynr).END PROC dirpos;REAL PROC blockno( DIRPOS CONST p):floor(p/16.0)END PROC blockno;INT PROC entryno(DIRPOS CONST p ):int(pMOD 16.0)END PROC entryno;PROC incr(DIRPOS VAR p):pINCR 1.0.END PROC incr;LET FREELIST =STRUCT (ROW maxdirentrysDIRPOS stack,INT stacktop,DIRPOS beginoffreearea,endofdir,REAL dirroot);PROC initfreelist(FREELIST VAR flist, REAL CONST root):flist.stacktop:=0;flist.beginoffreearea:=dirpos(9.0e99,0); flist.endofdir:=dirpos(-1.0,0);flist.dirroot:=root.END PROC initfreelist; PROC store(FREELIST VAR flist,DIRPOS CONST freepos):flist.stacktopINCR 1; flist.stack[flist.stacktop]:=freepos.END PROC store;PROC storebeginoffreearea (FREELIST VAR flist,DIRPOS CONST begin):flist.beginoffreearea:=beginEND PROC storebeginoffreearea;PROC storeendofdir(FREELIST VAR flist,DIRPOS CONST end): flist.endofdir:=endEND PROC storeendofdir;DIRPOS PROC freedirpos(FREELIST VAR flist):enablestop;DIRPOS VAR result;IF flist.stacktop>0THEN popELIF NOT freeareaemptyTHEN firstoffreeareaELIF expansionallowededTHEN allocatenewdircluster;result:=freedirpos(flist)ELSE errorstop( "Directory voll")FI ;result.pop:result:=flist.stack[flist.stacktop];flist. stacktopDECR 1.freeareaempty:flist.beginoffreearea>flist.endofdir. firstoffreearea:result:=flist.beginoffreearea;incr(flist.beginoffreearea). expansionalloweded:flist.dirroot>=2.0.allocatenewdircluster:REAL CONST newdircluster:=availablefatentry;REAL VAR lastentryno; searchlastentrynooffatchain;fatentry(newdircluster,lastfatchainentry); fatentry(lastentryno,newdircluster);writefat;storebeginoffreearea(flist, dirpos(firstnewblock,0));storeendofdir(flist,dirpos(lastnewblock,15)); initnewdircluster.searchlastentrynooffatchain:lastentryno:=flist.dirroot; WHILE NOT islastfatchainentry(fatentry(lastentryno))REP lastentryno:=fatentry (lastentryno)PER .firstnewblock:beginofcluster(newdircluster).lastnewblock: beginofcluster(newdircluster)+real(sectorspercluster-1).initnewdircluster: TEXT CONST emptydirentry:=32*"�";INT VAR i;FOR iFROM 0UPTO 15REP putdirentry( emptydirentry,i)PER ;disablestop;REAL VAR blockno:=firstnewblock;WHILE blockno<=lastnewblockREP writedirblock(blockno)PER .END PROC freedirpos;LET FILEENTRY =STRUCT (TEXT dateandtime,REAL size,firstcluster,DIRPOS dirpos), FILELIST =STRUCT (THESAURUS thes,ROW maxdirentrysFILEENTRY entry);PROC initfilelist(FILELIST VAR flist):flist.thes:=emptythesaurus.END PROC initfilelist;PROC storefileentry(FILELIST VAR flist,TEXT CONST entrytext, DIRPOS CONST position):INT VAR entryindex;insert(flist.thes,filename, entryindex);storefileentry(flist.entry[entryindex],entrytext,position). filename:TEXT CONST namepre:=compress(subtext(entrytext,1,8)),namepost:= compress(subtext(entrytext,9,11));IF namepost<>""THEN namepre+"."+namepost ELSE namepreFI .END PROC storefileentry;PROC storefileentry(FILEENTRY VAR fentry,TEXT CONST entrytext,DIRPOS CONST position):fentry.firstcluster:=real( entrytextISUB 14);fentry.dateandtime:=dosdate+" "+dostime;fentry.size:=dint( entrytextISUB 15,entrytextISUB 16);fentry.dirpos:=position.dosdate:day+"."+ month+"."+year.day:text2(code(entrytextSUB 25)MOD 32).month:text2(code( entrytextSUB 25)DIV 32+8*(code(entrytextSUB 26)MOD 2)).year:text(80+code( entrytextSUB 26)DIV 2,2).dostime:hour+":"+minute.hour:text2(code(entrytext SUB 24)DIV 8).minute:text2(code(entrytextSUB 23)DIV 32+8*(code(entrytextSUB 24)MOD 8)).END PROC storefileentry;TEXT PROC text2(INT CONST intvalue):IF intvalue<10THEN "0"+text(intvalue)ELSE text(intvalue)FI .END PROC text2; DIRPOS PROC fileentrypos(FILELIST CONST flist,TEXT CONST filename):INT CONST linkindex:=link(flist.thes,filename);IF linkindex=0THEN errorstop( "Die Datei """+filename+""" gibt es nicht")FI ;flist.entry[linkindex].dirpos. END PROC fileentrypos;PROC delete(FILELIST VAR flist,TEXT CONST filename): INT VAR dummy;delete(flist.thes,filename,dummy).END PROC delete;PROC fileinfo (FILELIST CONST flist,TEXT CONST filename,REAL VAR firstclusterno,storage): INT CONST linkindex:=link(flist.thes,filename);IF linkindex=0THEN errorstop( "Die Datei """+filename+""" gibt es nicht")FI ;firstclusterno:=flist.entry[ linkindex].firstcluster;storage:=flist.entry[linkindex].sizeEND PROC fileinfo ;BOOL PROC contains(FILELIST VAR flist,TEXT CONST filename):flist.thes CONTAINS filenameEND PROC contains;PROC list(FILE VAR f,FILELIST CONST flist) :INT VAR index:=0;TEXT VAR name;get(flist.thes,name,index);WHILE index>0REP listfile;get(flist.thes,name,index)PER .listfile:write(f,centeredname);write( f," ");write(f,text(flist.entry[index].size,11,0));write(f, " Bytes belegt ");write(f,flist.entry[index].dateandtime);write(f, " +++ ");write(f,text(flist.entry[index].firstcluster));line(f). centeredname:INT VAR pointpos:=pos(name,".");IF pointpos>0THEN namepre+"."+ namepostELSE text(name,12)FI .namepre:text(subtext(name,1,pointpos-1),8). namepost:text(subtext(name,pointpos+1,pointpos+4),3).END PROC list;LET DIRENTRY =REAL ,DIRLIST =STRUCT (THESAURUS thes,ROW maxdirentrysDIRENTRY entry);PROC initdirlist(DIRLIST VAR dlist):dlist.thes:=emptythesaurus.END PROC initdirlist;PROC storesubdirentry(DIRLIST VAR dlist,TEXT CONST entrytext ):INT VAR entryindex;insert(dlist.thes,subdirname,entryindex);dlist.entry[ entryindex]:=real(entrytextISUB 14).subdirname:TEXT CONST namepre:=compress( subtext(entrytext,1,8)),namepost:=compress(subtext(entrytext,9,11));IF namepost<>""THEN namepre+"."+namepostELSE namepreFI .END PROC storesubdirentry;REAL PROC firstclusterofsubdir(DIRLIST CONST dlist,TEXT CONST name):INT CONST linkindex:=link(dlist.thes,name);IF linkindex=0THEN errorstop("Das Unterverzeichnis """+name+""" gibt es nicht")FI ;dlist.entry[ linkindex].END PROC firstclusterofsubdir;BOOL PROC contains(DIRLIST CONST dlist,TEXT CONST subdirname):dlist.thesCONTAINS subdirnameEND PROC contains; PROC list(FILE VAR f,DIRLIST CONST dlist):INT VAR index:=0;TEXT VAR name;get( dlist.thes,name,index);WHILE index>0REP listdir;get(dlist.thes,name,index) PER .listdir:write(f,centeredname);write(f,"