123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344 |
- {****************************************************************************
- FPKPascal Runtime-Library
- Copyright (c) 1994,97 by
- Florian Klaempfl and Michael Spiegel
- OS/2 port by Dani‰l Mantione
- ****************************************************************************}
- {
- History:
- 2.7.1994: Version 0.2
- Datenstrukturen sind deklariert sowie
- 50 % der Unterprogramme sind implementiert
- 12.8.1994: exec implemented
- 14.8.1994: findfirst and findnext implemented
- 24.8.1994: Version 0.3
- 28.2.1995: Version 0.31
- some parameter lists with const optimized
- 3.7.1996: bug in fsplit removed (dir and ext were not intializised)
- 7.7.1996: packtime and unpacktime implemented
- 20.9.1996: Version 0.5
- setftime and getftime implemented
- some optimizations done (integer -> longint)
- procedure fsearch from the LINUX version ported
- msdos call implemented
- 26th november 1996:
- better fexpand
- 29th january 1997:
- bug in getftime and setftime removed
- setfattr and getfattr added
- 2th february 1997: Version 0.9
- bug of searchrec corrected
- 2 june 1997:
- OS/2 support added.
- 12 june 1997:
- OS/2 port done.
- 12 November 1997:
- Adapted to new DLL stuff.
- }
- unit dos;
- {$I os.inc}
- {$I386_DIRECT}
- interface
- uses
- strings;
- const
- { bit masks for CPU flags}
- fcarry = $0001;
- fparity = $0004;
- fauxiliary = $0010;
- fzero = $0040;
- fsign = $0080;
- foverflow = $0800;
- { Bitmasken fuer Dateiattribute }
- readonly = $01;
- hidden = $02;
- sysfile = $04;
- volumeid = $08;
- directory = $10;
- archive = $20;
- anyfile = $3F;
- fmclosed = $D7B0;
- fminput = $D7B1;
- fmoutput = $D7B2;
- fminout = $D7B3;
- type
- { some string types }
- {$IFDEF OS2}
- comstr=string; {Filenames can be long in OS/2.}
- pathstr=string;
- {$ELSE}
- comstr = string[127]; { Kommandozeilenstring }
- pathstr = string[79]; { String fuer einen Pfadnamen }
- {$ENDIF}
- dirstr = string[67]; { String fuer kompletten Pfad }
- namestr = string[8]; { Dateinamenstring }
- extstr = string[4]; { String fuer Dateinamensuffix }
- { search record which is used by findfirst and findnext }
- {$PACKRECORDS 1}
- searchrec = record
- fill : array[1..21] of byte;
- attr : byte;
- time : longint;
- {$IFNDEF OS2} { A DJGPP strange thing.}
- reserved : word; { requires the DOS extender (DJ GNU-C) }
- {$ENDIF}
- size : longint;
- {$IFNDEF OS2}
- name : string[15]; { the same size as declared by (DJ GNU C) }
- {$ELSE}
- name:string; {Filenames can be very long in OS/2!}
- {$ENDIF}
- end;
- {$PACKRECORDS 2}
- { file record for untyped files }
- filerec = record
- handle : word;
- mode : word;
- recsize : word;
- _private : array[1..26] of byte;
- userdata: array[1..16] of byte;
- name: array[0..79] of char;
- end;
- { file record for text files }
- textbuf = array[0..127] of char;
- textrec = record
- handle : word;
- mode : word;
- bufSize : word;
- _private : word;
- bufpos : word;
- bufend : word;
- bufptr : ^textbuf;
- openfunc : pointer;
- inoutfunc : pointer;
- flushfunc : pointer;
- closefunc : pointer;
- userdata : array[1..16] of byte;
- name : array[0..79] of char;
- buffer : textbuf;
- end;
- { data structure for the registers needed by msdos and intr }
- registers = record
- case i : integer of
- 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
- 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
- 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
- end;
- { record for date and time }
- datetime = record
- year,month,day,hour,min,sec : word;
- end;
- {Flags for the exec procedure:
- Starting the program:
- efwait: Wait until program terminates, otherwise the program
- continues execution.
- efno_wait: ? Function unknown. Not implemented in EMX.
- efoverlay: Terminate this program, then execute the requested
- program. WARNING: Exit-procedures are not called!
- efdebug: Debug program. Details are unknown.
- efsession: Do not execute as child of this program. Use a seperate
- session instead.
- efdetach: Detached. Function unknown. Info wanted!
- efpm: Run as presentation manager program.
- Determining the window state of the program:
- efdefault: Run the pm program in it's default situation.
- efminimize: Run the pm program minimized.
- efmaximize: Run the pm program maximized.
- effullscreen: Run the non-pm program fullscreen.
- efwindowed: Run the non-pm program in a window.
- Other options are not implemented defined because lack of
- knowledge abou what they do.}
- type execrunflags=(efwait,efno_wait,efoverlay,efdebug,efsession,
- efdetach,efpm);
- execwinflags=(efdefault,efminimize,efmaximize,effullscreen,
- efwindowed);
- execset=set of execrunflags;
- var
- { error variable }
- doserror : integer;
- procedure getdate(var year,month,day,dayofweek : word);
- procedure gettime(var hour,minute,second,sec100 : word);
- function dosversion : word;
- procedure setdate(year,month,day : word);
- procedure settime(hour,minute,second,sec100 : word);
- procedure getcbreak(var breakvalue : boolean);
- procedure setcbreak(breakvalue : boolean);
- procedure getverify(var verify : boolean);
- procedure setverify(verify : boolean);
- function diskfree(drive : byte) : longint;
- function disksize(drive : byte) : longint;
- procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
- procedure findnext(var f : searchRec);
- { is a dummy }
- procedure swapvectors;
- { not supported:
- procedure getintvec(intno : byte;var vector : pointer);
- procedure setintvec(intno : byte;vector : pointer);
- procedure keep(exitcode : word);
- }
- procedure msdos(var regs : registers);
- procedure intr(intno : byte;var regs : registers);
- procedure getfattr(var f;var attr : word);
- procedure setfattr(var f;attr : word);
- function fsearch(const path : pathstr;dirlist : string) : pathstr;
- procedure getftime(var f;var time : longint);
- procedure setftime(var f;time : longint);
- procedure packtime (var d: datetime; var time: longint);
- procedure unpacktime (time: longint; var d: datetime);
- function fexpand(const path : pathstr) : pathstr;
- procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;
- var ext : extstr);
- procedure exec(const path : pathstr;const comline : comstr);
- {$IFDEF OS2}
- function exec(path:pathstr;runflags:execset;winflags:execwinflags;
- const comline:comstr):longint;
- {$ENDIF}
- function dosexitcode : word;
- function envcount : longint;
- function envstr(index : longint) : string;
- function getenv(const envvar : string): string;
- implementation
- {$ifdef OS2}
- type OS2FSAllocate=record
- idfilesystem,
- csectorunit,
- cunit,
- cunitavail:longint;
- cbsector:word;
- end;
- function dosqueryFSinfo(driveno:word;infolevel:word;
- var info;infolen:word):word;
- external 'DOSCALLS' index 278;
- {$endif OS2}
- { this was first written for the LINUX version, }
- { by Michael Van Canneyt but it works also }
- { for the DOS version (I hope so) }
- function fsearch(const path : pathstr;dirlist : string) : pathstr;
- var
- newdir : pathstr;
- p1 : byte;
- s : searchrec;
- begin
- if (pos('?',path)<>0) or (pos('*',path)<>0) then
- { No wildcards allowed in these things }
- fsearch:=''
- else
- begin
- repeat
- { get first path }
- p1:=pos(';',dirlist);
- if p1>0 then
- begin
- newdir:=copy(dirlist,1,p1-1);
- delete(dirlist,1,p1)
- end
- else
- begin
- newdir:=dirlist;
- dirlist:=''
- end;
- findfirst(newdir+'\'+path,anyfile,s);
- if doserror=0 then
- begin
- newdir:=newdir+'\'+s.name;
- { this was for LINUX:
- if pos('.\',newdir)=1 then
- delete(newdir, 1, 2)
- { DOS strips off an initial .\ }
- }
- end
- else newdir:='';
- until(dirlist='') or (length(newdir)>0);
- fsearch:=newdir;
- end;
- end;
- procedure getftime(var f;var time : longint);
- begin
- {$IFNDEF OS2}
- asm
- { load handle }
- movl f,%ebx
- movw (%ebx),%bx
- { get date }
- movw $0x5700,%ax
- int $0x21
- shll $16,%edx
- movw %cx,%dx
- movl time,%ebx
- movl %edx,(%ebx)
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ELSE}
- asm
- { load handle }
- movl f,%ebx
- movw (%ebx),%bx
- { get date }
- movw $0x5700,%ax
- call ___SYSCALL
- shll $16,%edx
- movw %cx,%dx
- movl time,%ebx
- movl %edx,(%ebx)
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ENDIF}
- end;
- procedure setftime(var f;time : longint);
- begin
- {$IFNDEF OS2}
- asm
- { load handle }
- movl f,%ebx
- movw (%ebx),%bx
- movl time,%ecx
- shldl $16,%ecx,%edx
- { set date }
- movw $0x5701,%ax
- int $0x21
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ELSE}
- asm
- { load handle }
- movl f,%ebx
- movw (%ebx),%bx
- movl time,%ecx
- shldl $16,%ecx,%edx
- { set date }
- movw $0x5701,%ax
- call ___SYSCALL
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ENDIF}
- end;
- procedure msdos(var regs : registers);
- { Not recommended for EMX. Only works in DOS mode, not in OS/2 mode.}
- begin
- intr($21,regs);
- end;
- procedure intr(intno : byte;var regs : registers);
- { Not recommended for EMX. Only works in DOS mode, not in OS/2 mode.}
- begin
- asm
- .data
- int86:
- .byte 0xcd
- int86_vec:
- .byte 0x03
- jmp int86_retjmp
- .text
- movl 8(%ebp),%eax
- movb %al,int86_vec
- movl 10(%ebp),%eax
- {do not use first int}
- addl $2,%eax
- movl 4(%eax),%ebx
- movl 8(%eax),%ecx
- movl 12(%eax),%edx
- movl 16(%eax),%ebp
- movl 20(%eax),%esi
- movl 24(%eax),%edi
- movl (%eax),%eax
- jmp int86
- int86_retjmp:
- pushf
- pushl %ebp
- pushl %eax
- movl %esp,%ebp
- {calc EBP new}
- addl $12,%ebp
- movl 10(%ebp),%eax
- {do not use first int}
- addl $2,%eax
- popl (%eax)
- movl %ebx,4(%eax)
- movl %ecx,8(%eax)
- movl %edx,12(%eax)
- {restore EBP}
- popl %edx
- movl %edx,16(%eax)
- movl %esi,20(%eax)
- movl %edi,24(%eax)
- {ignore ES and DS}
- popl %ebx /* flags */
- movl %ebx,32(%eax)
- {FS and GS too}
- end;
- end;
- var
- lastdosexitcode : word;
- {$IFNDEF OS2}
- procedure exec(const path : pathstr;const comline : comstr);
- procedure do_system(p : pchar);
- begin
- asm
- movl 12(%ebp),%ebx
- movw $0xff07,%ax
- int $0x21
- movw %ax,_LASTDOSEXITCODE
- end;
- end;
- var
- execute : string;
- b : array[0..255] of char;
- begin
- execute:=path+' '+comline;
- move(execute[1],b,length(execute));
- b[length(execute)]:=#0;
- do_system(b);
- end;
- {$ELSE}
- procedure exec(const path:pathstr;const comline:comstr);
- {Execute a program.}
- begin
- exec(path,[efwait],efdefault,comline);
- end;
- function exec(path:pathstr;runflags:execset;winflags:execwinflags;
- const comline:comstr):longint;
- {Execute a program. More suitable for OS/2 than the exec above.}
- {512 bytes should be enough to contain the command-line.}
- type bytearray=array[0..8191] of byte;
- Pbytearray=^bytearray;
- setarray=array[0..3] of byte;
- execstruc=record
- argofs,envofs,nameofs:pointer;
- argseg,envseg,nameseg:word;
- numarg,sizearg,
- numenv,sizeenv:word;
- mode1,mode2:byte;
- end;
- var args:Pbytearray;
- env:Pbytearray;
- i,j:word;
- es:execstruc;
- esadr:pointer;
- begin
- getmem(args,512);
- getmem(env,8192);
- i:=1;
- j:=0;
- es.numarg:=0;
- while i<=length(comline) do
- begin
- if comline[i]<>' ' then
- begin
- {Commandline argument found. Copy it.}
- inc(es.numarg);
- args^[j]:=$80;
- inc(j);
- while (i<=length(comline)) and (comline[i]<>' ') do
- begin
- args^[j]:=byte(comline[i]);
- inc(j);
- inc(i);
- end;
- args^[j]:=0;
- inc(j);
- end;
- inc(i);
- end;
- args^[j]:=0;
- inc(j);
- {Commandline ready, now build the environment.
- Oh boy, I always had the opinion that executing a program under Dos
- was a hard job!}
- asm
- movl env,%edi {Setup destination pointer.}
- movl _envc,%ecx {Load number of arguments in edx.}
- movl _environ,%esi {Load env. strings.}
- xorl %edx,%edx {Count environment size.}
- exa1:
- lodsl {Load a Pchar.}
- xchgl %eax,%ebx
- exa2:
- movb (%ebx),%al {Load a byte.}
- incl %ebx {Point to next byte.}
- stosb {Store it.}
- incl %edx {Increase counter.}
- cmpb $0,%al {Ready ?.}
- jne exa2
- loop exa1 {Next argument.}
- stosb {Store an extra 0 to finish. (AL is now 0).}
- incl %edx
- movl %edx,(24)es {Store environment size.}
- end;
- {Environtment ready, now set-up exec structure.}
- es.argofs:=args;
- es.envofs:=env;
- asm
- leal path,%esi
- lodsb
- movzbl %al,%eax
- incl %eax
- addl %eax,%esi
- movb $0,(%esi)
- end;
- es.nameofs:=pointer(longint(@path)+1);
- asm
- movw %ss,(12)es {Compiler doesn't like record elems in asm.}
- movw %ss,(14)es
- movw %ss,(16)es
- end;
- es.sizearg:=j;
- es.numenv:=0;
- {Typecasting of sets in FPK is a bit hard.}
- es.mode1:=setarray(runflags)[0];
- es.mode2:=byte(winflags);
- {Now exec the program.}
- esadr:=@es;
- asm
- movl esadr,%edx
- mov $0x7f06,%ax
- call ___SYSCALL
- jnc exprg1
- movl %eax,U_DOS_DOSERROR
- xorl %eax,%eax
- decl %eax
- exprg1:
- movl %eax,__RESULT
- end;
- freemem(args,512);
- freemem(env,8192);
- {Phew! That's it. This was the most sophisticated procedure to call
- a system function I ever wrote!}
- end;
- {$ENDIF}
- function dosexitcode : word;
- begin
- dosexitcode:=lastdosexitcode;
- end;
- function dosversion : word;
- begin
- {$IFNDEF OS2}
- asm
- movb $0x30,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- leave
- ret
- end;
- {$ELSE}
- {Returns DOS version in DOS and OS/2 version in OS/2}
- asm
- movb $0x30,%ah
- call ___SYSCALL
- leave
- ret
- end;
- {$ENDIF}
- end;
- procedure getdate(var year,month,day,dayofweek : word);
- begin
- {$IFNDEF OS/2}
- asm
- movb $0x2a,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- xorb %ah,%ah
- movl 20(%ebp),%edi
- stosw
- movl 16(%ebp),%edi
- movb %dl,%al
- stosw
- movl 12(%ebp),%edi
- movb %dh,%al
- stosw
- movl 8(%ebp),%edi
- movw %cx,%ax
- stosw
- end;
- {$ELSE}
- asm
- movb $0x2a,%ah
- call ___SYSCALL
- xorb %ah,%ah
- movl 20(%ebp),%edi
- stosw
- movl 16(%ebp),%edi
- movb %dl,%al
- stosw
- movl 12(%ebp),%edi
- movb %dh,%al
- stosw
- movl 8(%ebp),%edi
- xchgw %ecx,%eax
- stosw
- end;
- {$ENDIF}
- end;
- procedure setdate(year,month,day : word);
- begin
- {$IFNDEF OS2}
- asm
- movw 8(%ebp),%cx
- movb 10(%ebp),%dh
- movb 12(%ebp),%dl
- movb $0x2b,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ELSE}
- {DOS only! You cannot change the system date in OS/2!}
- asm
- movw 8(%ebp),%cx
- movb 10(%ebp),%dh
- movb 12(%ebp),%dl
- movb $0x2b,%ah
- call ___SYSCALL
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ENDIF}
- end;
- procedure gettime(var hour,minute,second,sec100 : word);
- begin
- {$IFNDEF OS2}
- asm
- movb $0x2c,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- xorb %ah,%ah
- movl 20(%ebp),%edi
- movb %dl,%al
- stosw
- movl 16(%ebp),%edi
- movb %dh,%al
- stosw
- movl 12(%ebp),%edi
- movb %cl,%al
- stosw
- movl 8(%ebp),%edi
- movb %ch,%al
- stosw
- end;
- {$ELSE}
- asm
- movb $0x2c,%ah
- call ___SYSCALL
- xorb %ah,%ah
- movl 20(%ebp),%edi
- movb %dl,%al
- stosw
- movl 16(%ebp),%edi
- movb %dh,%al
- stosw
- movl 12(%ebp),%edi
- movb %cl,%al
- stosw
- movl 8(%ebp),%edi
- movb %ch,%al
- stosw
- end;
- {$ENDIF}
- end;
- procedure settime(hour,minute,second,sec100 : word);
- begin
- {$IFNDEF OS2}
- asm
- movb 8(%ebp),%ch
- movb 10(%ebp),%cl
- movb 12(%ebp),%dh
- movb 14(%ebp),%dl
- movb $0x2d,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ELSE}
- asm
- movb 8(%ebp),%ch
- movb 10(%ebp),%cl
- movb 12(%ebp),%dh
- movb 14(%ebp),%dl
- movb $0x2d,%ah
- call ___SYSCALL
- xorb %ah,%ah
- movw %ax,U_DOS_DOSERROR
- end;
- {$ENDIF}
- end;
- procedure getcbreak(var breakvalue : boolean);
- begin
- {$IFNDEF OS2}
- asm
- movw $0x3300,%ax
- pushl %ebp
- int $0x21
- popl %ebp
- movl 8(%ebp),%eax
- movb %dl,(%eax)
- end;
- {$ELSE}
- {! Do not use in OS/2. Also not recommended in DOS. Use
- signal handling instead.}
- asm
- movw $0x3300,%ax
- call ___SYSCALL
- movl 8(%ebp),%eax
- movb %dl,(%eax)
- end;
- {$ENDIF}
- end;
- procedure setcbreak(breakvalue : boolean);
- begin
- {$IFNDEF OS2}
- asm
- movb 8(%ebp),%dl
- movl $0x3301,%ax
- pushl %ebp
- int $0x21
- popl %ebp
- end;
- {$ELSE}
- {! Do not use in OS/2. Also not recommended in DOS. Use
- signal handling instead.}
- asm
- movb 8(%ebp),%dl
- movl $0x3301,%ax
- call ___SYSCALL
- end;
- {$ENDIF}
- end;
- procedure getverify(var verify : boolean);
- begin
- {$IFNDEF OS2}
- asm
- movb $0x54,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- movl 8(%ebp),%edi
- stosb
- end;
- {$ELSE}
- {! Do not use in OS/2.}
- asm
- movb $0x54,%ah
- call ___SYSCALL
- movl 8(%ebp),%edi
- stosb
- end;
- {$ENDIF}
- end;
- procedure setverify(verify : boolean);
- begin
- {$IFNDEF OS2}
- asm
- movb 8(%ebp),%al
- movl $0x2e,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- end;
- {$ELSE}
- {! Do not use in OS/2.}
- asm
- movb 8(%ebp),%al
- movl $0x2e,%ah
- call ___SYSCALL
- end;
- {$ENDIF}
- end;
- function diskfree(drive : byte) : longint;
- var fi:OS2FSallocate;
- begin
- {$IFNDEF OS2}
- asm
- movb 8(%ebp),%dl
- movb $0x36,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- cmpw $-1,%ax
- je LDISKFREE1
- mulw %cx
- mulw %bx
- shll $16,%edx
- movw %ax,%dx
- movl %edx,%eax
- leave
- ret
- LDISKFREE1:
- cwde
- leave
- ret
- end;
- {$ELSE}
- if os_mode=osDOS then
- {Function 36 is not supported in OS/2.}
- asm
- movb 8(%ebp),%dl
- movb $0x36,%ah
- call ___SYSCALL
- cmpw $-1,%ax
- je LDISKFREE1
- mulw %cx
- mulw %bx
- shll $16,%edx
- movw %ax,%dx
- xchgl %edx,%eax
- leave
- ret
- LDISKFREE1:
- cwde
- leave
- ret
- end
- else
- {In OS/2, we use the filesystem information.}
- begin
- doserror:=dosqueryFSinfo(drive,1,FI,sizeof(FI));
- if doserror=0 then
- diskfree:=FI.cunitavail*FI.csectorunit*FI.cbsector
- else
- diskfree:=-1;
- end;
- {$ENDIF}
- end;
- function disksize(drive : byte) : longint;
- begin
- {$IFNDEF OS/2}
- asm
- movb 8(%ebp),%dl
- movb $0x36,%ah
- pushl %ebp
- int $0x21
- popl %ebp
- movw %dx,%bx
- cmpw $-1,%ax
- je LDISKSIZE1
- mulw %cx
- mulw %bx
- shll $16,%edx
- movw %ax,%dx
- movl %edx,%eax
- leave
- ret
- LDISKSIZE1:
- movl $-1,%eax
- leave
- ret
- end;
- {$ELSE}
- if os_mode=osDOS then
- {Function 36 is not supported in OS/2.}
- asm
- movb 8(%ebp),%dl
- movb $0x36,%ah
- call ___SYSCALL
- movw %dx,%bx
- cmpw $-1,%ax
- je LDISKSIZE1
- mulw %cx
- mulw %bx
- shll $16,%edx
- movw %ax,%dx
- xchgl %edx,%eax
- leave
- ret
- LDISKSIZE1:
- cwde
- leave
- ret
- end;
- else
- {In OS/2, we use the filesystem information.}
- begin
- doserror:=dosQFSinfo(drive,1,FI,sizeof(FI));
- if doserror=0 then
- diskfree:=FI.cunit*FI.csectorunit*FI.cbsector
- else
- diskfree:=-1;
- end;
- {$ENDIF}
- end;
- procedure searchrec2dossearchrec(var f : searchrec);
- var
- l,i : longint;
- {$IFDEF OS2}
- const namesize=255;
- {$ELSE}
- const namesize=12;
- {$ENDIF}
- begin
- l:=length(f.name);
- for i:=1 to namesize do
- f.name[i-1]:=f.name[i];
- f.name[l]:=#0;
- end;
- procedure dossearchrec2searchrec(var f : searchrec);
- var
- l,i : longint;
- {$IFDEF OS2}
- const namesize=255;
- {$ELSE}
- const namesize=12;
- {$ENDIF}
- begin
- for i:=0 to namesize do
- if f.name[i]=#0 then
- begin
- l:=i;
- break;
- end;
- for i:=namesize-1 downto 0 do
- f.name[i+1]:=f.name[i];
- f.name[0]:=chr(l);
- end;
- procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
- procedure _findfirst(path : pchar;attr : word;var f : searchrec);
- begin
- {$IFNDEF OS2}
- asm
- movl 18(%ebp),%edx
- movb $0x1a,%ah
- int $0x21
- movl 12(%esp),%edx
- movzwl 16(%esp),%ecx
- movb $0x4e,%ah
- int $0x21
- jnc LFF
- movw %ax,U_DOS_DOSERROR
- LFF:
- end;
- {$ELSE}
- asm
- movl 12(%esp),%edx
- movw 16(%esp),%cx
- {No need to set DTA in EMX. Just give a pointer in ESI.}
- movl 18(%ebp),%esi
- movb $0x4e,%ah
- call ___SYSCALL
- jnc LFF
- movw %ax,U_DOS_DOSERROR
- LFF:
- end;
- {$ENDIF}
- end;
- var
- path0 : array[0..80] of char;
- begin
- { no error }
- doserror:=0;
- strpcopy(path0,path);
- _findfirst(path0,attr,f);
- dossearchrec2searchrec(f);
- end;
- procedure findnext(var f : searchRec);
- procedure _findnext(var f : searchrec);
- begin
- {$IFNDEF OS2}
- asm
- movl 12(%ebp),%edx
- movb $0x1a,%ah
- int $0x21
- movb $0x4f,%ah
- int $0x21
- jnc LFN
- movw %ax,U_DOS_DOSERROR
- LFN:
- end;
- {$ELSE}
- asm
- movl 12(%ebp),%esi
- movb $0x4f,%ah
- call ___SYSCALL
- jnc LFN
- movw %ax,U_DOS_DOSERROR
- LFN:
- end;
- {$ENDIF}
- end;
- begin
- { no error }
- doserror:=0;
- searchrec2dossearchrec(f);
- _findnext(f);
- dossearchrec2searchrec(f);
- end;
- procedure swapvectors;
- begin
- { tut nichts, DOS-Extender �bernimmt das N”tige }
- { normalerweise selber }
- { nur aus Kompatibilit„tsgr�nden implementiert }
- end;
- type
- ppchar = ^pchar;
- function envs : ppchar;
- begin
- asm
- movl _environ,%eax
- leave
- ret
- end ['EAX'];
- end;
- function envcount : longint;
- var
- hp : ppchar;
- begin
- {$IFNDEF OS2}
- hp:=envs;
- envcount:=0;
- while assigned(hp^) do
- begin
- { not the best solution, but quite understandable }
- inc(envcount);
- hp:=hp+4;
- end;
- {$ELSE}
- asm
- movl _envc,%eax
- leave
- ret
- end ['EAX'];
- {$ENDIF}
- end;
- function envstr(index : longint) : string;
- var
- hp : ppchar;
- begin
- if (index<=0) or (index>envcount) then
- begin
- envstr:='';
- exit;
- end;
- hp:=envs+4*(index-1);
- envstr:=strpas(hp^);
- end;
- function getenv(const envvar : string) : string;
- var
- hs,_envvar : string;
- eqpos,i : longint;
- begin
- _envvar:=upcase(envvar);
- getenv:='';
- for i:=1 to envcount do
- begin
- hs:=envstr(i);
- eqpos:=pos('=',hs);
- if copy(hs,1,eqpos-1)=_envvar then
- begin
- getenv:=copy(hs,eqpos+1,length(hs)-eqpos);
- exit;
- end;
- end;
- end;
- procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;
- var ext : extstr);
- var
- p1 : byte;
- begin
- { try to find out a extension }
- p1:=pos('.',path);
- if p1>0 then
- begin
- ext:=copy(path,p1,4);
- delete(path,p1,length(path)-p1+1);
- end
- else
- ext:='';
- { get drive name }
- p1:=pos(':',path);
- if p1>0 then
- begin
- dir:=path[1]+':';
- delete(path,1,p1);
- end
- else
- dir:='';
- { split the path and the name, there are no more path informtions }
- { if path contains no backslashes }
- while true do
- begin
- p1:=pos('\',path);
- if p1=0 then
- break;
- dir:=dir+copy(path,1,p1);
- delete(path,1,p1);
- end;
- name:=path;
- end;
- function fexpand(const path : pathstr) : pathstr;
- function get_current_drive : byte;
-
- var
- r : registers;
-
- begin
- r.ah:=$19;
- msdos(r);
- get_current_drive:=r.al;
- end;
- var
- {$IFDEF DOS}
- s,pa : string[79];
- {$ELSE}
- s,pa:string;
- {$ENDIF}
- begin
- { There are differences between FPKPascal and Turbo Pascal
- e.g. for the string 'D:\DEMO\..\HELLO' which isn't handled }
- getdir(0,s);
- pa:=upcase(path);
- if (byte(pa[0])>1) and ((pa[1] in ['A'..'Z']) and (pa[2]=':')) then
- begin
- if (byte(pa[0])>2) and (pa[3]<>'\') then
- if pa[1]=s[1] then
- pa:=s+'\'+copy (pa,3,length(pa))
- else
- pa:=pa[1]+':\'+copy (pa,3,length(pa))
- end
- else
- if pa[1]='\' then
- pa:=s[1]+':'+pa
- else if s[0]=#3 then
- pa:=s+pa
- else
- pa:=s+'\'+pa;
- fexpand:=pa;
- end;
- procedure packtime(var d : datetime;var time : longint);
- var
- zs : longint;
- begin
- time:=-1980;
- time:=time+d.year and 127;
- time:=time shl 4;
- time:=time+d.month;
- time:=time shl 5;
- time:=time+d.day;
- time:=time shl 16;
- zs:=d.hour;
- zs:=zs shl 6;
- zs:=zs+d.min;
- zs:=zs shl 5;
- zs:=zs+d.sec div 2;
- time:=time+(zs and $ffff);
- end;
- procedure unpacktime (time: longint; var d: datetime);
- begin
- d.sec:=(time and 31) * 2;
- time:=time shr 5;
- d.min:=time and 63;
- time:=time shr 6;
- d.hour:=time and 31;
- time:=time shr 5;
- d.day:=time and 31;
- time:=time shr 5;
- d.month:=time and 15;
- time:=time shr 4;
- d.year:=time + 1980;
- end;
- procedure getfattr(var f;var attr : word);
- var
- { to avoid problems }
- n : array[0..255] of char;
- {$IFNDEF OS2}
- r : registers;
- {$ENDIF}
- begin
- strpcopy(n,filerec(f).name);
- {$IFNDEF OS2}
- r.ax:=$4300;
- r.edx:=longint(@n);
- msdos(r);
- attr:=r.cx;
- {$ELSE}
- {Alas, msdos(r) doesn't work when we are running in OS/2.}
- asm
- movw $0x4300,%ax
- leal n,%edx
- call ___SYSCALL
- movl attr,%ebx
- movw %cx,(%ebx)
- end;
- {$ENDIF}
- end;
- procedure setfattr(var f;attr : word);
- var
- { to avoid problems }
- n : array[0..255] of char;
- {$IFNDEF OS2}
- r : registers;
- {$ENDIF}
- begin
- strpcopy(n,filerec(f).name);
- {$IFNDEF OS2}
- r.ax:=$4301;
- r.edx:=longint(@n);
- r.cx:=attr;
- msdos(r);
- {$ELSE}
- {Alas, msdos(r) doesn't work when we are running in OS/2.}
- asm
- movw $0x4301,%ax
- leal n,%edx
- movw attr,%cx
- call ___SYSCALL
- end;
- {$ENDIF}
- end;
- end.
|