dos.pp 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team.
  5. Dos unit for BP7 compatible RTL
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit dos;
  13. {$I os.inc}
  14. interface
  15. Uses Go32;
  16. Const
  17. {Bitmasks for CPU Flags}
  18. fcarry = $0001;
  19. fparity = $0004;
  20. fauxiliary = $0010;
  21. fzero = $0040;
  22. fsign = $0080;
  23. foverflow = $0800;
  24. {Bitmasks for file attribute}
  25. readonly = $01;
  26. hidden = $02;
  27. sysfile = $04;
  28. volumeid = $08;
  29. directory = $10;
  30. archive = $20;
  31. anyfile = $3F;
  32. {File Status}
  33. fmclosed = $D7B0;
  34. fminput = $D7B1;
  35. fmoutput = $D7B2;
  36. fminout = $D7B3;
  37. Type
  38. {$IFDEF GO32V2}
  39. { Needed for Win95 LFN Support }
  40. ComStr = String[255];
  41. PathStr = String[255];
  42. DirStr = String[255];
  43. NameStr = String[255];
  44. ExtStr = String[255];
  45. {$ELSE}
  46. comstr = string[127]; { command line string }
  47. pathstr = string[79]; { string for a file path }
  48. dirstr = string[67]; { string for a directory }
  49. namestr = string[8]; { string for a file name }
  50. extstr = string[4]; { string for an extension }
  51. {$ENDIF}
  52. {
  53. filerec.inc contains the definition of the filerec.
  54. textrec.inc contains the definition of the textrec.
  55. It is in a separate file to make it available in other units without
  56. having to use the DOS unit for it.
  57. }
  58. {$i filerec.inc}
  59. {$i textrec.inc}
  60. DateTime = packed record
  61. Year,
  62. Month,
  63. Day,
  64. Hour,
  65. Min,
  66. Sec : word;
  67. End;
  68. {$ifdef GO32V2}
  69. searchrec = packed record
  70. fill : array[1..21] of byte;
  71. attr : byte;
  72. time : longint;
  73. { reserved : word; not in DJGPP V2 }
  74. size : longint;
  75. name : string[12]; { the same size as declared by (DJ GNU C) }
  76. end;
  77. Registers = Go32.Registers;
  78. {$ELSE}
  79. searchrec = packed record
  80. fill : array[1..21] of byte;
  81. attr : byte;
  82. time : longint;
  83. reserved : word; { requires the DOS extender (DJ GNU-C) }
  84. size : longint;
  85. name : string[15]; { the same size as declared by (DJ GNU C) }
  86. end;
  87. registers = packed record
  88. case i : integer of
  89. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  90. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  91. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  92. end;
  93. {$endif GO32V1}
  94. Var
  95. DosError : integer;
  96. {Interrupt}
  97. Procedure Intr(intno: byte; var regs: registers);
  98. Procedure MSDos(var regs: registers);
  99. {Info/Date/Time}
  100. Function DosVersion: Word;
  101. Procedure GetDate(var year, month, mday, wday: word);
  102. Procedure GetTime(var hour, minute, second, sec100: word);
  103. procedure SetDate(year,month,day: word);
  104. Procedure SetTime(hour,minute,second,sec100: word);
  105. Procedure UnpackTime(p: longint; var t: datetime);
  106. Procedure PackTime(var t: datetime; var p: longint);
  107. {Exec}
  108. Procedure Exec(const path: pathstr; const comline: comstr);
  109. Function DosExitCode: word;
  110. {Disk}
  111. Function DiskFree(drive: byte) : longint;
  112. Function DiskSize(drive: byte) : longint;
  113. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  114. Procedure FindNext(var f: searchRec);
  115. Procedure FindClose(Var f: SearchRec);
  116. {File}
  117. Procedure GetFAttr(var f; var attr: word);
  118. Procedure GetFTime(var f; var time: longint);
  119. Function FSearch(path: pathstr; dirlist: string): pathstr;
  120. Function FExpand(const path: pathstr): pathstr;
  121. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  122. {Environment}
  123. Function EnvCount: longint;
  124. Function EnvStr(index: integer): string;
  125. Function GetEnv(envvar: string): string;
  126. {Misc}
  127. Procedure SetFAttr(var f; attr: word);
  128. Procedure SetFTime(var f; time: longint);
  129. Procedure GetCBreak(var breakvalue: boolean);
  130. Procedure SetCBreak(breakvalue: boolean);
  131. Procedure GetVerify(var verify: boolean);
  132. Procedure SetVerify(verify: boolean);
  133. {Do Nothing Functions}
  134. Procedure SwapVectors;
  135. Procedure GetIntVec(intno: byte; var vector: pointer);
  136. Procedure SetIntVec(intno: byte; vector: pointer);
  137. Procedure Keep(exitcode: word);
  138. implementation
  139. uses
  140. strings;
  141. {$ASMMODE ATT}
  142. {******************************************************************************
  143. --- Dos Interrupt ---
  144. ******************************************************************************}
  145. var
  146. dosregs : registers;
  147. procedure LoadDosError;
  148. begin
  149. if (dosregs.flags and carryflag) <> 0 then
  150. doserror:=dosregs.ax
  151. else
  152. doserror:=0;
  153. end;
  154. {$ifdef GO32V2}
  155. procedure intr(intno : byte;var regs : registers);
  156. begin
  157. realintr(intno,regs);
  158. end;
  159. {$else GO32V2}
  160. {$ASMMODE DIRECT}
  161. procedure intr(intno : byte;var regs : registers);
  162. begin
  163. asm
  164. .data
  165. int86:
  166. .byte 0xcd
  167. int86_vec:
  168. .byte 0x03
  169. jmp int86_retjmp
  170. .text
  171. movl 8(%ebp),%eax
  172. movb %al,int86_vec
  173. movl 10(%ebp),%eax
  174. // do not use first int
  175. addl $2,%eax
  176. movl 4(%eax),%ebx
  177. movl 8(%eax),%ecx
  178. movl 12(%eax),%edx
  179. movl 16(%eax),%ebp
  180. movl 20(%eax),%esi
  181. movl 24(%eax),%edi
  182. movl (%eax),%eax
  183. jmp int86
  184. int86_retjmp:
  185. pushf
  186. pushl %ebp
  187. pushl %eax
  188. movl %esp,%ebp
  189. // calc EBP new
  190. addl $12,%ebp
  191. movl 10(%ebp),%eax
  192. // do not use first int
  193. addl $2,%eax
  194. popl (%eax)
  195. movl %ebx,4(%eax)
  196. movl %ecx,8(%eax)
  197. movl %edx,12(%eax)
  198. // restore EBP
  199. popl %edx
  200. movl %edx,16(%eax)
  201. movl %esi,20(%eax)
  202. movl %edi,24(%eax)
  203. // ignore ES and DS
  204. popl %ebx /* flags */
  205. movl %ebx,32(%eax)
  206. // FS and GS too
  207. end;
  208. end;
  209. {$ASMMODE ATT}
  210. {$endif GO32V2}
  211. procedure msdos(var regs : registers);
  212. begin
  213. intr($21,regs);
  214. end;
  215. {******************************************************************************
  216. --- Info / Date / Time ---
  217. ******************************************************************************}
  218. function dosversion : word;
  219. begin
  220. dosregs.ax:=$3000;
  221. msdos(dosregs);
  222. dosversion:=dosregs.ax;
  223. end;
  224. procedure getdate(var year,month,mday,wday : word);
  225. begin
  226. dosregs.ax:=$2a00;
  227. msdos(dosregs);
  228. wday:=dosregs.al;
  229. year:=dosregs.cx;
  230. month:=dosregs.dh;
  231. mday:=dosregs.dl;
  232. end;
  233. procedure setdate(year,month,day : word);
  234. begin
  235. dosregs.cx:=year;
  236. dosregs.dh:=month;
  237. dosregs.dl:=day;
  238. dosregs.ah:=$2b;
  239. msdos(dosregs);
  240. LoadDosError;
  241. end;
  242. procedure gettime(var hour,minute,second,sec100 : word);
  243. begin
  244. dosregs.ah:=$2c;
  245. msdos(dosregs);
  246. hour:=dosregs.ch;
  247. minute:=dosregs.cl;
  248. second:=dosregs.dh;
  249. sec100:=dosregs.dl;
  250. end;
  251. procedure settime(hour,minute,second,sec100 : word);
  252. begin
  253. dosregs.ch:=hour;
  254. dosregs.cl:=minute;
  255. dosregs.dh:=second;
  256. dosregs.dl:=sec100;
  257. dosregs.ah:=$2d;
  258. msdos(dosregs);
  259. LoadDosError;
  260. end;
  261. Procedure packtime(var t : datetime;var p : longint);
  262. Begin
  263. p:=(t.sec shr 1)+(t.min shl 5)+(t.hour shl 11)+(t.day shl 16)+(t.month shl 21)+((t.year-1980) shl 25);
  264. End;
  265. Procedure unpacktime(p : longint;var t : datetime);
  266. Begin
  267. with t do
  268. begin
  269. sec:=(p and 31) shl 1;
  270. min:=(p shr 5) and 63;
  271. hour:=(p shr 11) and 31;
  272. day:=(p shr 16) and 31;
  273. month:=(p shr 21) and 15;
  274. year:=(p shr 25)+1980;
  275. end;
  276. End;
  277. {******************************************************************************
  278. --- Exec ---
  279. ******************************************************************************}
  280. var
  281. lastdosexitcode : word;
  282. {$ifdef GO32V2}
  283. {
  284. Table 0931
  285. Format of EXEC parameter block for AL=00h,01h,04h:
  286. Offset Size Description
  287. 00h WORD segment of environment to copy for child process (copy caller's
  288. environment if 0000h)
  289. this does not seem to work (PM)
  290. 02h DWORD pointer to command tail to be copied into child's PSP
  291. 06h DWORD pointer to first FCB to be copied into child's PSP
  292. 0Ah DWORD pointer to second FCB to be copied into child's PSP
  293. 0Eh DWORD (AL=01h) will hold subprogram's initial SS:SP on return
  294. 12h DWORD (AL=01h) will hold entry point (CS:IP) on return
  295. INT 21 4B--
  296. }
  297. procedure exec(const path : pathstr;const comline : comstr);
  298. type
  299. realptr = packed record
  300. ofs,seg : word;
  301. end;
  302. texecblock = packed record
  303. envseg : word;
  304. comtail : realptr;
  305. firstFCB : realptr;
  306. secondFCB : realptr;
  307. iniStack : realptr;
  308. iniCSIP : realptr;
  309. end;
  310. var
  311. current_dos_buffer_pos,
  312. arg_ofs,
  313. i,la_env,
  314. la_p,la_c,la_e,
  315. fcb1_la,fcb2_la : longint;
  316. execblock : texecblock;
  317. c,p : string;
  318. function paste_to_dos(src : string) : boolean;
  319. var
  320. c : array[0..255] of char;
  321. begin
  322. paste_to_dos:=false;
  323. if current_dos_buffer_pos+length(src)+1>transfer_buffer+tb_size then
  324. RunError(217);
  325. move(src[1],c[0],length(src));
  326. c[length(src)]:=#0;
  327. seg_move(get_ds,longint(@c),dosmemselector,current_dos_buffer_pos,length(src)+1);
  328. current_dos_buffer_pos:=current_dos_buffer_pos+length(src)+1;
  329. paste_to_dos:=true;
  330. end;
  331. begin
  332. { create command line }
  333. move(comline[0],c[1],length(comline)+1);
  334. c[length(comline)+2]:=#13;
  335. c[0]:=char(length(comline)+2);
  336. { create path }
  337. p:=path;
  338. for i:=1 to length(p) do
  339. if p[i]='/' then
  340. p[i]:='\';
  341. { create buffer }
  342. la_env:=transfer_buffer;
  343. while (la_env and 15)<>0 do
  344. inc(la_env);
  345. current_dos_buffer_pos:=la_env;
  346. { copy environment }
  347. for i:=1 to envcount do
  348. paste_to_dos(envstr(i));
  349. paste_to_dos(''); { adds a double zero at the end }
  350. { allow slash as backslash }
  351. la_p:=current_dos_buffer_pos;
  352. paste_to_dos(p);
  353. la_c:=current_dos_buffer_pos;
  354. paste_to_dos(c);
  355. la_e:=current_dos_buffer_pos;
  356. fcb1_la:=la_e;
  357. la_e:=la_e+16;
  358. fcb2_la:=la_e;
  359. la_e:=la_e+16;
  360. { allocate FCB see dosexec code }
  361. arg_ofs:=1;
  362. while (c[arg_ofs] in [' ',#9]) do
  363. inc(arg_ofs);
  364. dosregs.ax:=$2901;
  365. dosregs.ds:=(la_c+arg_ofs) shr 4;
  366. dosregs.esi:=(la_c+arg_ofs) and 15;
  367. dosregs.es:=fcb1_la shr 4;
  368. dosregs.edi:=fcb1_la and 15;
  369. msdos(dosregs);
  370. { allocate second FCB see dosexec code }
  371. repeat
  372. inc(arg_ofs);
  373. until (c[arg_ofs] in [' ',#9,#13]);
  374. if c[arg_ofs]<>#13 then
  375. begin
  376. repeat
  377. inc(arg_ofs);
  378. until not (c[arg_ofs] in [' ',#9]);
  379. end;
  380. dosregs.ax:=$2901;
  381. dosregs.ds:=(la_c+arg_ofs) shr 4;
  382. dosregs.si:=(la_c+arg_ofs) and 15;
  383. dosregs.es:=fcb2_la shr 4;
  384. dosregs.di:=fcb2_la and 15;
  385. msdos(dosregs);
  386. with execblock do
  387. begin
  388. envseg:=la_env shr 4;
  389. comtail.seg:=la_c shr 4;
  390. comtail.ofs:=la_c and 15;
  391. firstFCB.seg:=fcb1_la shr 4;
  392. firstFCB.ofs:=fcb1_la and 15;
  393. secondFCB.seg:=fcb2_la shr 4;
  394. secondFCB.ofs:=fcb2_la and 15;
  395. end;
  396. seg_move(get_ds,longint(@execblock),dosmemselector,la_e,sizeof(texecblock));
  397. dosregs.edx:=la_p and 15;
  398. dosregs.ds:=la_p shr 4;
  399. dosregs.ebx:=la_e and 15;
  400. dosregs.es:=la_e shr 4;
  401. dosregs.ax:=$4b00;
  402. msdos(dosregs);
  403. LoadDosError;
  404. if DosError=0 then
  405. begin
  406. dosregs.ax:=$4d00;
  407. msdos(dosregs);
  408. LastDosExitCode:=DosRegs.al
  409. end
  410. else
  411. LastDosExitCode:=0;
  412. end;
  413. {$else GO32V2}
  414. procedure exec(const path : pathstr;const comline : comstr);
  415. var
  416. i : longint;
  417. b : array[0..255] of char;
  418. begin
  419. doserror:=0;
  420. for i:=1to length(path) do
  421. if path[i]='/' then
  422. b[i-1]:='\'
  423. else
  424. b[i-1]:=path[i];
  425. b[i]:=' ';
  426. inc(i);
  427. move(comline[1],b[i],length(comline));
  428. inc(i,length(comline));
  429. b[i]:=#0;
  430. asm
  431. leal b,%ebx
  432. movw $0xff07,%ax
  433. int $0x21
  434. movw %ax,LastDosExitCode
  435. end;
  436. end;
  437. {$endif}
  438. function dosexitcode : word;
  439. begin
  440. dosexitcode:=lastdosexitcode;
  441. end;
  442. procedure getcbreak(var breakvalue : boolean);
  443. begin
  444. dosregs.ax:=$3300;
  445. msdos(dosregs);
  446. breakvalue:=dosregs.dl<>0;
  447. end;
  448. procedure setcbreak(breakvalue : boolean);
  449. begin
  450. dosregs.ax:=$3301;
  451. dosregs.dl:=ord(breakvalue);
  452. msdos(dosregs);
  453. end;
  454. procedure getverify(var verify : boolean);
  455. begin
  456. dosregs.ah:=$54;
  457. msdos(dosregs);
  458. verify:=dosregs.al<>0;
  459. end;
  460. procedure setverify(verify : boolean);
  461. begin
  462. dosregs.ah:=$2e;
  463. dosregs.al:=ord(verify);
  464. msdos(dosregs);
  465. end;
  466. {******************************************************************************
  467. --- Disk ---
  468. ******************************************************************************}
  469. function diskfree(drive : byte) : longint;
  470. begin
  471. dosregs.dl:=drive;
  472. dosregs.ah:=$36;
  473. msdos(dosregs);
  474. if dosregs.ax<>$FFFF then
  475. diskfree:=dosregs.ax*dosregs.bx*dosregs.cx
  476. else
  477. diskfree:=-1;
  478. end;
  479. function disksize(drive : byte) : longint;
  480. begin
  481. dosregs.dl:=drive;
  482. dosregs.ah:=$36;
  483. msdos(dosregs);
  484. if dosregs.ax<>$FFFF then
  485. disksize:=dosregs.ax*dosregs.cx*dosregs.dx
  486. else
  487. disksize:=-1;
  488. end;
  489. {******************************************************************************
  490. --- Findfirst FindNext ---
  491. ******************************************************************************}
  492. procedure searchrec2dossearchrec(var f : searchrec);
  493. var
  494. l,i : longint;
  495. begin
  496. l:=length(f.name);
  497. for i:=1 to 12 do
  498. f.name[i-1]:=f.name[i];
  499. f.name[l]:=#0;
  500. end;
  501. procedure dossearchrec2searchrec(var f : searchrec);
  502. var
  503. l,i : longint;
  504. begin
  505. l:=12;
  506. for i:=0 to 12 do
  507. if f.name[i]=#0 then
  508. begin
  509. l:=i;
  510. break;
  511. end;
  512. for i:=11 downto 0 do
  513. f.name[i+1]:=f.name[i];
  514. f.name[0]:=chr(l);
  515. end;
  516. procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
  517. {$ifdef GO32V2}
  518. procedure _findfirst(path : pchar;attr : word;var f : searchrec);
  519. var
  520. i : longint;
  521. begin
  522. { allow slash as backslash }
  523. for i:=0 to strlen(path) do
  524. if path[i]='/' then path[i]:='\';
  525. copytodos(f,sizeof(searchrec));
  526. dosregs.edx:=transfer_buffer mod 16;
  527. dosregs.ds:=transfer_buffer div 16;
  528. dosregs.ah:=$1a;
  529. msdos(dosregs);
  530. dosregs.ecx:=attr;
  531. dosregs.edx:=(transfer_buffer mod 16) + Sizeof(searchrec)+1;
  532. dosmemput(transfer_buffer div 16,
  533. (transfer_buffer mod 16) +Sizeof(searchrec)+1,path^,strlen(path)+1);
  534. dosregs.ds:=transfer_buffer div 16;
  535. dosregs.ah:=$4e;
  536. msdos(dosregs);
  537. copyfromdos(f,sizeof(searchrec));
  538. LoadDosError;
  539. end;
  540. {$else GO32V2}
  541. procedure _findfirst(path : pchar;attr : word;var f : searchrec);
  542. var
  543. i : longint;
  544. begin
  545. { allow slash as backslash }
  546. for i:=0 to strlen(path) do
  547. if path[i]='/' then path[i]:='\';
  548. asm
  549. movl f,%edx
  550. movb $0x1a,%ah
  551. int $0x21
  552. movl path,%edx
  553. movzwl attr,%ecx
  554. movb $0x4e,%ah
  555. int $0x21
  556. jnc .LFF
  557. movw %ax,DosError
  558. .LFF:
  559. end;
  560. end;
  561. {$endif GO32V2}
  562. var
  563. path0 : array[0..80] of char;
  564. begin
  565. { no error }
  566. doserror:=0;
  567. strpcopy(path0,path);
  568. _findfirst(path0,attr,f);
  569. dossearchrec2searchrec(f);
  570. end;
  571. procedure findnext(var f : searchRec);
  572. {$ifdef GO32V2}
  573. procedure _findnext(var f : searchrec);
  574. begin
  575. copytodos(f,sizeof(searchrec));
  576. dosregs.edx:=transfer_buffer mod 16;
  577. dosregs.ds:=transfer_buffer div 16;
  578. dosregs.ah:=$1a;
  579. msdos(dosregs);
  580. dosregs.ah:=$4f;
  581. msdos(dosregs);
  582. copyfromdos(f,sizeof(searchrec));
  583. LoadDosError;
  584. end;
  585. {$else GO32V2}
  586. procedure _findnext(var f : searchrec);
  587. begin
  588. asm
  589. movl 12(%ebp),%edx
  590. movb $0x1a,%ah
  591. int $0x21
  592. movb $0x4f,%ah
  593. int $0x21
  594. jnc .LFN
  595. movw %ax,DosError
  596. .LFN:
  597. end;
  598. end;
  599. {$endif GO32V2}
  600. begin
  601. { no error }
  602. doserror:=0;
  603. searchrec2dossearchrec(f);
  604. _findnext(f);
  605. dossearchrec2searchrec(f);
  606. end;
  607. procedure swapvectors;
  608. {$ifdef go32v2}
  609. { uses four global symbols from v2prt0.as to be able to know the current
  610. exception state without using dpmiexcp unit }
  611. {$ASMMODE DIRECT}
  612. begin
  613. asm
  614. movl _exception_exit,%eax
  615. orl %eax,%eax
  616. je .Lno_excep
  617. movl _v2prt0_exceptions_on,%eax
  618. orl %eax,%eax
  619. je .Lexceptions_off
  620. movl _swap_out,%eax
  621. call *%eax
  622. jmp .Lno_excep
  623. .Lexceptions_off:
  624. movl _swap_in,%eax
  625. call *%eax
  626. .Lno_excep:
  627. end;
  628. end;
  629. {$ASMMODE ATT}
  630. {$else not go32v2}
  631. begin
  632. end;
  633. {$endif go32v2}
  634. Procedure FindClose(Var f: SearchRec);
  635. begin
  636. end;
  637. {******************************************************************************
  638. --- File ---
  639. ******************************************************************************}
  640. procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;var ext : extstr);
  641. var
  642. p1,i : longint;
  643. begin
  644. { allow slash as backslash }
  645. for i:=1 to length(path) do
  646. if path[i]='/' then path[i]:='\';
  647. { get drive name }
  648. p1:=pos(':',path);
  649. if p1>0 then
  650. begin
  651. dir:=path[1]+':';
  652. delete(path,1,p1);
  653. end
  654. else
  655. dir:='';
  656. { split the path and the name, there are no more path informtions }
  657. { if path contains no backslashes }
  658. while true do
  659. begin
  660. p1:=pos('\',path);
  661. if p1=0 then
  662. break;
  663. dir:=dir+copy(path,1,p1);
  664. delete(path,1,p1);
  665. end;
  666. { try to find out a extension }
  667. p1:=pos('.',path);
  668. if p1>0 then
  669. begin
  670. ext:=copy(path,p1,4);
  671. delete(path,p1,length(path)-p1+1);
  672. end
  673. else
  674. ext:='';
  675. name:=path;
  676. end;
  677. function fexpand(const path : pathstr) : pathstr;
  678. var
  679. s,pa : string[79];
  680. i,j : longint;
  681. begin
  682. getdir(0,s);
  683. pa:=upcase(path);
  684. { allow slash as backslash }
  685. for i:=1 to length(pa) do
  686. if pa[i]='/' then
  687. pa[i]:='\';
  688. if (length(pa)>1) and (pa[1] in ['A'..'Z']) and (pa[2]=':') then
  689. begin
  690. { we must get the right directory }
  691. getdir(ord(pa[1])-ord('A')+1,s);
  692. if (ord(pa[0])>2) and (pa[3]<>'\') then
  693. if pa[1]=s[1] then
  694. pa:=s+'\'+copy (pa,3,length(pa))
  695. else
  696. pa:=pa[1]+':\'+copy (pa,3,length(pa))
  697. end
  698. else
  699. if pa[1]='\' then
  700. pa:=s[1]+':'+pa
  701. else if s[0]=#3 then
  702. pa:=s+pa
  703. else
  704. pa:=s+'\'+pa;
  705. {First remove all references to '\.\'}
  706. while pos ('\.\',pa)<>0 do
  707. delete (pa,pos('\.\',pa),2);
  708. {Now remove also all references to '\..\' + of course previous dirs..}
  709. repeat
  710. i:=pos('\..\',pa);
  711. if i<>0 then
  712. begin
  713. j:=i-1;
  714. while (j>1) and (pa[j]<>'\') do
  715. dec (j);
  716. delete (pa,j,i-j+3);
  717. end;
  718. until i=0;
  719. {Remove End . and \}
  720. if (length(pa)>0) and (pa[length(pa)]='.') then
  721. dec(byte(pa[0]));
  722. if (length(pa)>0) and (pa[length(pa)]='\') then
  723. dec(byte(pa[0]));
  724. fexpand:=pa;
  725. end;
  726. Function FSearch(path: pathstr; dirlist: string): pathstr;
  727. var
  728. i,p1 : longint;
  729. s : searchrec;
  730. newdir : pathstr;
  731. begin
  732. { No wildcards allowed in these things }
  733. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  734. fsearch:=''
  735. else
  736. begin
  737. { allow slash as backslash }
  738. for i:=1 to length(dirlist) do
  739. if dirlist[i]='/' then dirlist[i]:='\';
  740. repeat
  741. p1:=pos(';',dirlist);
  742. if p1=0 then
  743. begin
  744. newdir:=copy(dirlist,1,p1-1);
  745. delete(dirlist,1,p1);
  746. end
  747. else
  748. begin
  749. newdir:=dirlist;
  750. dirlist:='';
  751. end;
  752. if (newdir<>'') and (not (newdir[length(newdir)] in ['\',':'])) then
  753. newdir:=newdir+'\';
  754. findfirst(newdir+path,anyfile,s);
  755. if doserror=0 then
  756. newdir:=newdir+path
  757. else
  758. newdir:='';
  759. until (dirlist='') or (newdir<>'');
  760. fsearch:=newdir;
  761. end;
  762. end;
  763. procedure getftime(var f;var time : longint);
  764. begin
  765. dosregs.bx:=textrec(f).handle;
  766. dosregs.ax:=$5700;
  767. msdos(dosregs);
  768. time:=(dosregs.dx shl 16)+dosregs.cx;
  769. doserror:=dosregs.al;
  770. end;
  771. procedure setftime(var f;time : longint);
  772. begin
  773. dosregs.bx:=textrec(f).handle;
  774. dosregs.cx:=time and $ffff;
  775. dosregs.dx:=time shr 16;
  776. dosregs.ax:=$5701;
  777. msdos(dosregs);
  778. doserror:=dosregs.al;
  779. end;
  780. procedure getfattr(var f;var attr : word);
  781. {$ifndef GO32V2}
  782. var
  783. n : array[0..255] of char;
  784. {$endif}
  785. begin
  786. {$ifdef GO32V2}
  787. copytodos(filerec(f).name,strlen(filerec(f).name)+1);
  788. dosregs.edx:=transfer_buffer and 15;
  789. dosregs.ds:=transfer_buffer shr 4;
  790. {$else}
  791. strpcopy(n,filerec(f).name);
  792. dosregs.edx:=longint(@n);
  793. {$endif}
  794. dosregs.ax:=$4300;
  795. msdos(dosregs);
  796. LoadDosError;
  797. Attr:=dosregs.cx;
  798. end;
  799. procedure setfattr(var f;attr : word);
  800. {$ifndef GO32V2}
  801. var
  802. n : array[0..255] of char;
  803. {$endif}
  804. begin
  805. {$ifdef GO32V2}
  806. copytodos(filerec(f).name,strlen(filerec(f).name)+1);
  807. dosregs.edx:=transfer_buffer mod 16;
  808. dosregs.ds:=transfer_buffer div 16;
  809. {$else}
  810. strpcopy(n,filerec(f).name);
  811. dosregs.edx:=longint(@n);
  812. {$endif}
  813. dosregs.ax:=$4301;
  814. dosregs.cx:=attr;
  815. msdos(dosregs);
  816. LoadDosError;
  817. end;
  818. {******************************************************************************
  819. --- Environment ---
  820. ******************************************************************************}
  821. function envcount : longint;
  822. var
  823. hp : ppchar;
  824. begin
  825. hp:=envp;
  826. envcount:=0;
  827. while assigned(hp^) do
  828. begin
  829. inc(envcount);
  830. hp:=hp+4;
  831. end;
  832. end;
  833. function envstr(index : integer) : string;
  834. begin
  835. if (index<=0) or (index>envcount) then
  836. begin
  837. envstr:='';
  838. exit;
  839. end;
  840. envstr:=strpas(ppchar(envp+4*(index-1))^);
  841. end;
  842. Function GetEnv(envvar: string): string;
  843. var
  844. hp : ppchar;
  845. hs : string;
  846. eqpos : longint;
  847. begin
  848. envvar:=upcase(envvar);
  849. hp:=envp;
  850. getenv:='';
  851. while assigned(hp^) do
  852. begin
  853. hs:=strpas(hp^);
  854. eqpos:=pos('=',hs);
  855. if copy(hs,1,eqpos-1)=envvar then
  856. begin
  857. getenv:=copy(hs,eqpos+1,255);
  858. exit;
  859. end;
  860. hp:=hp+4;
  861. end;
  862. end;
  863. {******************************************************************************
  864. --- Not Supported ---
  865. ******************************************************************************}
  866. Procedure keep(exitcode : word);
  867. Begin
  868. End;
  869. Procedure getintvec(intno : byte;var vector : pointer);
  870. Begin
  871. End;
  872. Procedure setintvec(intno : byte;vector : pointer);
  873. Begin
  874. End;
  875. end.
  876. {
  877. $Log$
  878. Revision 1.5 1998-05-31 14:18:13 peter
  879. * force att or direct assembling
  880. * cleanup of some files
  881. Revision 1.4 1998/05/22 00:39:22 peter
  882. * go32v1, go32v2 recompiles with the new objects
  883. * remake3 works again with go32v2
  884. - removed some "optimizes" from daniel which were wrong
  885. Revision 1.3 1998/05/21 19:30:47 peter
  886. * objects compiles for linux
  887. + assign(pchar), assign(char), rename(pchar), rename(char)
  888. * fixed read_text_as_array
  889. + read_text_as_pchar which was not yet in the rtl
  890. }