dos.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2004 by the Free Pascal development team.
  5. Dos unit for BP7 compatible RTL (novell netware libc)
  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. interface
  14. uses libc;
  15. Const
  16. FileNameLen = 255;
  17. Type
  18. searchrec = packed record
  19. DirP : POINTER; { used for opendir }
  20. EntryP: POINTER; { and readdir }
  21. Magic : WORD;
  22. fill : array[1..11] of byte;
  23. attr : byte;
  24. time : longint;
  25. size : longint;
  26. name : string[255];
  27. { Internals used by netware port only: }
  28. _mask : string[255];
  29. _dir : string[255];
  30. _attr : word;
  31. end;
  32. registers = packed record
  33. case i : integer of
  34. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  35. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  36. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  37. end;
  38. {$i dosh.inc}
  39. {Extra Utils}
  40. function weekday(y,m,d : longint) : longint;
  41. implementation
  42. uses
  43. strings;
  44. {$ASMMODE ATT}
  45. {*****************************************************************************
  46. --- Info / Date / Time ---
  47. ******************************************************************************}
  48. {$PACKRECORDS 4}
  49. function dosversion : word;
  50. var i : Tutsname;
  51. begin
  52. if Fpuname (i) >= 0 then
  53. dosversion := WORD (i.netware_minor) SHL 8 + i.netware_major
  54. else dosversion := $0005;
  55. end;
  56. function WeekDay (y,m,d:longint):longint;
  57. {
  58. Calculates th day of the week. returns -1 on error
  59. }
  60. var
  61. u,v : longint;
  62. begin
  63. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  64. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  65. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  66. WeekDay:=-1
  67. else
  68. begin
  69. u:=m;
  70. v:=y;
  71. if m<3 then
  72. begin
  73. inc(u,12);
  74. dec(v);
  75. end;
  76. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  77. end;
  78. end;
  79. procedure getdate(var year,month,mday,wday : word);
  80. var
  81. t : TTime;
  82. tm : Ttm;
  83. begin
  84. time(t); localtime_r(t,tm);
  85. with tm do
  86. begin
  87. year := tm_year+1900;
  88. month := tm_mon+1;
  89. mday := tm_mday;
  90. wday := tm_wday;
  91. end;
  92. end;
  93. procedure setdate(year,month,day : word);
  94. begin
  95. end;
  96. procedure gettime(var hour,minute,second,sec100 : word);
  97. var
  98. t : TTime;
  99. tm : Ttm;
  100. begin
  101. time(t); localtime_r(t,tm);
  102. with tm do
  103. begin
  104. hour := tm_hour;
  105. minute := tm_min;
  106. second := tm_sec;
  107. sec100 := 0;
  108. end;
  109. end;
  110. procedure settime(hour,minute,second,sec100 : word);
  111. begin
  112. end;
  113. Procedure packtime(var t : datetime;var p : longint);
  114. Begin
  115. 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);
  116. End;
  117. Procedure unpacktime(p : longint;var t : datetime);
  118. Begin
  119. with t do
  120. begin
  121. sec:=(p and 31) shl 1;
  122. min:=(p shr 5) and 63;
  123. hour:=(p shr 11) and 31;
  124. day:=(p shr 16) and 31;
  125. month:=(p shr 21) and 15;
  126. year:=(p shr 25)+1980;
  127. end;
  128. End;
  129. {******************************************************************************
  130. --- Exec ---
  131. ******************************************************************************}
  132. {$ifdef HASTHREADVAR}
  133. threadvar
  134. {$else HASTHREADVAR}
  135. var
  136. {$endif HASTHREADVAR}
  137. lastdosexitcode : word;
  138. const maxargs=256;
  139. procedure exec(const path : pathstr;const comline : comstr);
  140. var c : comstr;
  141. i : integer;
  142. args : array[0..maxargs] of pchar;
  143. arg0 : pathstr;
  144. numargs,wstat : integer;
  145. Wiring : TWiring;
  146. begin
  147. if pos ('.',path) = 0 then
  148. arg0 := fexpand(path+'.nlm'#0) else
  149. arg0 := fexpand (path)+#0;
  150. //writeln (stderr,'dos.exec (',path,',',comline,') arg0:"',copy(arg0,1,length(arg0)-1),'"');
  151. args[0] := @arg0[1];
  152. numargs := 0;
  153. c:=comline;
  154. i:=1;
  155. while i<=length(c) do
  156. begin
  157. if c[i]<>' ' then
  158. begin
  159. {Commandline argument found. append #0 and set pointer in args }
  160. inc(numargs);
  161. args[numargs]:=@c[i];
  162. while (i<=length(c)) and (c[i]<>' ') do
  163. inc(i);
  164. c[i] := #0;
  165. end;
  166. inc(i);
  167. end;
  168. args[numargs+1] := nil;
  169. // i := spawnvp (P_WAIT,args[0],@args);
  170. Wiring.infd := StdInputHandle; //textrec(Stdin).Handle;
  171. Wiring.outfd:= textrec(stdout).Handle;
  172. Wiring.errfd:= textrec(stderr).Handle;
  173. //writeln (stderr,'calling procve');
  174. i := procve(args[0],
  175. PROC_CURRENT_SPACE+PROC_INHERIT_CWD,
  176. envP, // const char * env[] If passed as NULL, the child process inherits the parent.s environment at the time of the call.
  177. @Wiring, // wiring_t *wiring, Pass NULL to inherit system defaults for wiring.
  178. nil, // struct fd_set *fds, Not currently implemented. Pass in NULL.
  179. nil, // void *appdata, Not currently implemented. Pass in NULL.
  180. 0, // size_t appdata_size, Not currently implemented. Pass in 0
  181. nil, // void *reserved, Reserved. Pass NULL.
  182. @args); // const char *argv[]
  183. //writeln (stderr,'Ok');
  184. if i <> -1 then
  185. begin
  186. Fpwaitpid(i,@wstat,0);
  187. doserror := 0;
  188. lastdosexitcode := wstat;
  189. end else
  190. begin
  191. doserror := 8; // for now, what about errno ?
  192. end;
  193. end;
  194. function dosexitcode : word;
  195. begin
  196. dosexitcode:=lastdosexitcode;
  197. end;
  198. procedure getcbreak(var breakvalue : boolean);
  199. begin
  200. end;
  201. procedure setcbreak(breakvalue : boolean);
  202. begin
  203. end;
  204. procedure getverify(var verify : boolean);
  205. begin
  206. verify := true;
  207. end;
  208. procedure setverify(verify : boolean);
  209. begin
  210. end;
  211. {******************************************************************************
  212. --- Disk ---
  213. ******************************************************************************}
  214. function getvolnum (drive : byte) : longint;
  215. var dir : STRING[255];
  216. P,PS,
  217. V : LONGINT;
  218. begin
  219. {if drive = 0 then
  220. begin // get volume name from current directory (i.e. SERVER-NAME/VOL2:TEST)
  221. getdir (0,dir);
  222. p := pos (':', dir);
  223. if p = 0 then
  224. begin
  225. getvolnum := -1;
  226. exit;
  227. end;
  228. byte (dir[0]) := p-1;
  229. dir[p] := #0;
  230. PS := pos ('/', dir);
  231. INC (PS);
  232. if _GetVolumeNumber (@dir[PS], V) <> 0 then
  233. getvolnum := -1
  234. else
  235. getvolnum := V;
  236. end else
  237. getvolnum := drive-1;}
  238. getvolnum := -1;
  239. end;
  240. function diskfree(drive : byte) : int64;
  241. {VAR Buf : ARRAY [0..255] OF CHAR;
  242. TotalBlocks : WORD;
  243. SectorsPerBlock : WORD;
  244. availableBlocks : WORD;
  245. totalDirectorySlots : WORD;
  246. availableDirSlots : WORD;
  247. volumeisRemovable : WORD;
  248. volumeNumber : LONGINT;}
  249. begin
  250. // volumeNumber := getvolnum (drive);
  251. (*
  252. if volumeNumber >= 0 then
  253. begin
  254. {i think thats not the right function but for others i need a connection handle}
  255. if _GetVolumeInfoWithNumber (byte(volumeNumber),@Buf,
  256. TotalBlocks,
  257. SectorsPerBlock,
  258. availableBlocks,
  259. totalDirectorySlots,
  260. availableDirSlots,
  261. volumeisRemovable) = 0 THEN
  262. begin
  263. diskfree := int64 (availableBlocks) * int64 (SectorsPerBlock) * 512;
  264. end else
  265. diskfree := 0;
  266. end else*)
  267. diskfree := 0;
  268. end;
  269. function disksize(drive : byte) : int64;
  270. VAR Buf : ARRAY [0..255] OF CHAR;
  271. TotalBlocks : WORD;
  272. SectorsPerBlock : WORD;
  273. availableBlocks : WORD;
  274. totalDirectorySlots : WORD;
  275. availableDirSlots : WORD;
  276. volumeisRemovable : WORD;
  277. volumeNumber : LONGINT;
  278. begin
  279. volumeNumber := getvolnum (drive);
  280. (*
  281. if volumeNumber >= 0 then
  282. begin
  283. {i think thats not the right function but for others i need a connection handle}
  284. if _GetVolumeInfoWithNumber (byte(volumeNumber),@Buf,
  285. TotalBlocks,
  286. SectorsPerBlock,
  287. availableBlocks,
  288. totalDirectorySlots,
  289. availableDirSlots,
  290. volumeisRemovable) = 0 THEN
  291. begin
  292. disksize := int64 (TotalBlocks) * int64 (SectorsPerBlock) * 512;
  293. end else
  294. disksize := 0;
  295. end else*)
  296. disksize := 0;
  297. end;
  298. {******************************************************************************
  299. --- Utils ---
  300. ******************************************************************************}
  301. procedure timet2dostime (timet:longint; var dostime : longint);
  302. var tm : Ttm;
  303. begin
  304. localtime_r(timet,tm);
  305. dostime:=(tm.tm_sec shr 1)+(tm.tm_min shl 5)+(tm.tm_hour shl 11)+(tm.tm_mday shl 16)+((tm.tm_mon+1) shl 21)+((tm.tm_year+1900-1980) shl 25);
  306. end;
  307. function nwattr2dosattr (nwattr : longint) : word;
  308. begin
  309. nwattr2dosattr := 0;
  310. if nwattr and M_A_RDONLY > 0 then nwattr2dosattr := nwattr2dosattr + readonly;
  311. if nwattr and M_A_HIDDEN > 0 then nwattr2dosattr := nwattr2dosattr + hidden;
  312. if nwattr and M_A_SYSTEM > 0 then nwattr2dosattr := nwattr2dosattr + sysfile;
  313. if nwattr and M_A_SUBDIR > 0 then nwattr2dosattr := nwattr2dosattr + directory;
  314. if nwattr and M_A_ARCH > 0 then nwattr2dosattr := nwattr2dosattr + archive;
  315. end;
  316. {******************************************************************************
  317. --- Findfirst FindNext ---
  318. ******************************************************************************}
  319. {returns true if attributes match}
  320. function find_setfields (var f : searchRec) : boolean;
  321. var
  322. StatBuf : TStat;
  323. fname : string[255];
  324. begin
  325. find_setfields := false;
  326. with F do
  327. begin
  328. if Magic = $AD01 then
  329. begin
  330. attr := nwattr2dosattr (Pdirent(EntryP)^.d_mode);
  331. size := Pdirent(EntryP)^.d_size;
  332. name := strpas (Pdirent(EntryP)^.d_name);
  333. doserror := 0;
  334. fname := f._dir + f.name;
  335. if length (fname) = 255 then dec (byte(fname[0]));
  336. fname := fname + #0;
  337. if Fpstat (@fname[1],StatBuf) = 0 then
  338. timet2dostime (StatBuf.st_mtim.tv_sec, time)
  339. else
  340. time := 0;
  341. if (f._attr and hidden) = 0 then
  342. if attr and hidden > 0 then exit;
  343. if (f._attr and Directory) = 0 then
  344. if attr and Directory > 0 then exit;
  345. if (f._attr and SysFile) = 0 then
  346. if attr and SysFile > 0 then exit;
  347. find_setfields := true;
  348. end else
  349. begin
  350. FillChar (f,sizeof(f),0);
  351. doserror := 18;
  352. end;
  353. end;
  354. end;
  355. procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
  356. var
  357. path0 : array[0..256] of char;
  358. p : longint;
  359. begin
  360. IF path = '' then
  361. begin
  362. doserror := 18;
  363. exit;
  364. end;
  365. f._attr := attr;
  366. p := length (path);
  367. while (p > 0) and (not (path[p] in ['\','/'])) do
  368. dec (p);
  369. if p > 0 then
  370. begin
  371. f._mask := copy (path,p+1,255);
  372. f._dir := copy (path,1,p);
  373. strpcopy(path0,f._dir);
  374. end else
  375. begin
  376. f._mask := path;
  377. getdir (0,f._dir);
  378. if (f._dir[length(f._dir)] <> '/') and
  379. (f._dir[length(f._dir)] <> '\') then
  380. f._dir := f._dir + '/';
  381. strpcopy(path0,f._dir);
  382. end;
  383. if f._mask = '*' then f._mask := '';
  384. if f._mask = '*.*' then f._mask := '';
  385. //writeln (stderr,'mask: "',f._mask,'" dir:"',path0,'"');
  386. f._mask := f._mask + #0;
  387. Pdirent(f.DirP) := opendir (path0);
  388. if f.DirP = nil then
  389. doserror := 18
  390. else begin
  391. F.Magic := $AD01;
  392. findnext (f);
  393. end;
  394. end;
  395. procedure findnext(var f : searchRec);
  396. begin
  397. if F.Magic <> $AD01 then
  398. begin
  399. doserror := 18;
  400. exit;
  401. end;
  402. doserror:=0;
  403. repeat
  404. Pdirent(f.EntryP) := readdir (Pdirent(f.DirP));
  405. if F.EntryP = nil then
  406. doserror := 18
  407. else
  408. if find_setfields (f) then
  409. begin
  410. if f._mask = #0 then exit;
  411. if fnmatch(@f._mask[1],Pdirent(f.EntryP)^.d_name,FNM_CASEFOLD) = 0 then
  412. exit;
  413. end;
  414. until doserror <> 0;
  415. end;
  416. Procedure FindClose(Var f: SearchRec);
  417. begin
  418. if F.Magic <> $AD01 then
  419. begin
  420. doserror := 18;
  421. EXIT;
  422. end;
  423. doserror:=0;
  424. closedir (Pdirent(f.DirP));
  425. f.Magic := 0;
  426. f.DirP := NIL;
  427. f.EntryP := NIL;
  428. end;
  429. procedure swapvectors;
  430. begin
  431. end;
  432. {******************************************************************************
  433. --- File ---
  434. ******************************************************************************}
  435. procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;var ext : extstr);
  436. var
  437. dotpos,p1,i : longint;
  438. begin
  439. { allow backslash as slash }
  440. for i:=1 to length(path) do
  441. if path[i]='\' then path[i]:='/';
  442. { get volume name }
  443. p1:=pos(':',path);
  444. if p1>0 then
  445. begin
  446. dir:=copy(path,1,p1);
  447. delete(path,1,p1);
  448. end
  449. else
  450. dir:='';
  451. { split the path and the name, there are no more path informtions }
  452. { if path contains no backslashes }
  453. while true do
  454. begin
  455. p1:=pos('/',path);
  456. if p1=0 then
  457. break;
  458. dir:=dir+copy(path,1,p1);
  459. delete(path,1,p1);
  460. end;
  461. { try to find out a extension }
  462. //if LFNSupport then
  463. begin
  464. Ext:='';
  465. i:=Length(Path);
  466. DotPos:=256;
  467. While (i>0) Do
  468. Begin
  469. If (Path[i]='.') Then
  470. begin
  471. DotPos:=i;
  472. break;
  473. end;
  474. Dec(i);
  475. end;
  476. Ext:=Copy(Path,DotPos,255);
  477. Name:=Copy(Path,1,DotPos - 1);
  478. end
  479. end;
  480. function GetShortName(var p : String) : boolean;
  481. begin
  482. GetShortName := false;
  483. end;
  484. function GetLongName(var p : String) : boolean;
  485. begin
  486. GetLongName := false;
  487. end;
  488. {$define FPC_FEXPAND_DRIVES}
  489. {$define FPC_FEXPAND_VOLUMES}
  490. {$define FPC_FEXPAND_NO_DEFAULT_PATHS}
  491. {$i fexpand.inc}
  492. Function FSearch(path: pathstr; dirlist: string): pathstr;
  493. var
  494. i,p1 : longint;
  495. s : searchrec;
  496. newdir : pathstr;
  497. begin
  498. system.write ('FSearch ("',path,'","',dirlist,'"');
  499. { check if the file specified exists }
  500. findfirst(path,anyfile,s);
  501. if doserror=0 then
  502. begin
  503. findclose(s);
  504. fsearch:=path;
  505. exit;
  506. end;
  507. { No wildcards allowed in these things }
  508. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  509. fsearch:=''
  510. else
  511. begin
  512. { allow backslash as slash }
  513. for i:=1 to length(dirlist) do
  514. if dirlist[i]='\' then dirlist[i]:='/';
  515. repeat
  516. p1:=pos(';',dirlist);
  517. if p1<>0 then
  518. begin
  519. newdir:=copy(dirlist,1,p1-1);
  520. delete(dirlist,1,p1);
  521. end
  522. else
  523. begin
  524. newdir:=dirlist;
  525. dirlist:='';
  526. end;
  527. if (newdir<>'') and (not (newdir[length(newdir)] in ['/',':'])) then
  528. newdir:=newdir+'/';
  529. findfirst(newdir+path,anyfile,s);
  530. if doserror=0 then
  531. newdir:=newdir+path
  532. else
  533. newdir:='';
  534. until (dirlist='') or (newdir<>'');
  535. fsearch:=newdir;
  536. end;
  537. findclose(s);
  538. end;
  539. {******************************************************************************
  540. --- Get/Set File Time,Attr ---
  541. ******************************************************************************}
  542. procedure getftime(var f;var time : longint);
  543. var
  544. StatBuf : TStat;
  545. begin
  546. doserror := 0;
  547. if Fpfstat (filerec (f).handle, StatBuf) = 0 then
  548. timet2dostime (StatBuf.st_mtim.tv_sec,time)
  549. else begin
  550. time := 0;
  551. doserror := ___errno^;
  552. end;
  553. end;
  554. procedure setftime(var f;time : longint);
  555. Var
  556. utim: utimbuf;
  557. DT: DateTime;
  558. path: pathstr;
  559. tm : TTm;
  560. Begin
  561. doserror:=0;
  562. with utim do
  563. begin
  564. actime:=libc.time(nil); // getepochtime;
  565. UnPackTime(Time,DT);
  566. with tm do
  567. begin
  568. tm_sec := DT.Sec; // seconds after the minute [0..59]
  569. tm_min := DT.Min; // minutes after the hour [0..59]
  570. tm_hour := DT.hour; // hours since midnight [0..23]
  571. tm_mday := DT.Day; // days of the month [1..31]
  572. tm_mon := DT.month-1; // months since January [0..11]
  573. tm_year := DT.year-1900;
  574. tm_wday := -1;
  575. tm_yday := -1;
  576. tm_isdst := -1;
  577. end;
  578. modtime:=mktime(tm);
  579. end;
  580. if utime(@filerec(f).name,utim)<0 then
  581. begin
  582. Time:=0;
  583. doserror:=3;
  584. end;
  585. end;
  586. procedure getfattr(var f;var attr : word);
  587. VAR StatBuf : TStat;
  588. begin
  589. doserror := 0;
  590. if Fpstat (@textrec(f).name, StatBuf) = 0 then
  591. attr := nwattr2dosattr (StatBuf.st_mode)
  592. else
  593. begin
  594. attr := 0;
  595. doserror := ___errno^;
  596. end;
  597. end;
  598. procedure setfattr(var f;attr : word);
  599. var
  600. StatBuf : TStat;
  601. newMode : longint;
  602. begin
  603. if Fpstat (@textrec(f).name,StatBuf) = 0 then
  604. begin
  605. newmode := StatBuf.st_mode and ($FFFF0000 - M_A_RDONLY-M_A_HIDDEN-M_A_SYSTEM-M_A_ARCH); {only this can be set by dos unit}
  606. newmode := newmode or M_A_BITS_SIGNIFICANT; {set netware attributes}
  607. if attr and readonly > 0 then
  608. newmode := newmode or M_A_RDONLY;
  609. if attr and hidden > 0 then
  610. newmode := newmode or M_A_HIDDEN;
  611. if attr and sysfile > 0 then
  612. newmode := newmode or M_A_SYSTEM;
  613. if attr and archive > 0 then
  614. newmode := newmode or M_A_ARCH;
  615. if Fpchmod (@textrec(f).name,newMode) < 0 then
  616. doserror := ___errno^ else
  617. doserror := 0;
  618. end else
  619. doserror := ___errno^;
  620. end;
  621. {******************************************************************************
  622. --- Environment ---
  623. ******************************************************************************}
  624. Function EnvCount: Longint;
  625. var
  626. envcnt : longint;
  627. p : ppchar;
  628. Begin
  629. envcnt:=0;
  630. p:=envp; {defined in system}
  631. while (p^<>nil) do
  632. begin
  633. inc(envcnt);
  634. inc(p);
  635. end;
  636. EnvCount := envcnt
  637. End;
  638. Function EnvStr (Index: longint): String;
  639. Var
  640. i : longint;
  641. p : ppchar;
  642. Begin
  643. if Index <= 0 then
  644. envstr:=''
  645. else
  646. begin
  647. p:=envp; {defined in system}
  648. i:=1;
  649. while (i<Index) and (p^<>nil) do
  650. begin
  651. inc(i);
  652. inc(p);
  653. end;
  654. if p=nil then
  655. envstr:=''
  656. else
  657. envstr:=strpas(p^)
  658. end;
  659. end;
  660. { works fine (at least with netware 6.5) }
  661. Function GetEnv(envvar: string): string;
  662. var envvar0 : array[0..512] of char;
  663. p : pchar;
  664. SearchElement : string[255];
  665. i,isDosPath,res : longint;
  666. begin
  667. if upcase(envvar) = 'PATH' then
  668. begin // netware does not have search paths in the environment var PATH
  669. // return it here (needed for the compiler)
  670. GetEnv := '';
  671. i := 1;
  672. res := GetSearchPathElement (i, isdosPath, @SearchElement[0]);
  673. while res = 0 do
  674. begin
  675. if isDosPath = 0 then
  676. begin
  677. if GetEnv <> '' then GetEnv := GetEnv + ';';
  678. GetEnv := GetEnv + SearchElement;
  679. end;
  680. inc (i);
  681. res := GetSearchPathElement (i, isdosPath, @SearchElement[0]);
  682. end;
  683. for i := 1 to length(GetEnv) do
  684. if GetEnv[i] = '\' then
  685. GetEnv[i] := '/';
  686. end else
  687. begin
  688. strpcopy(envvar0,envvar);
  689. p := libc.getenv (envvar0);
  690. if p = NIL then
  691. GetEnv := ''
  692. else
  693. GetEnv := strpas (p);
  694. end;
  695. end;
  696. {******************************************************************************
  697. --- Not Supported ---
  698. ******************************************************************************}
  699. Procedure keep(exitcode : word);
  700. Begin
  701. { simply wait until nlm will be unloaded }
  702. while true do delay (60000);
  703. End;
  704. Procedure getintvec(intno : byte;var vector : pointer);
  705. Begin
  706. { no netware equivalent }
  707. End;
  708. Procedure setintvec(intno : byte;vector : pointer);
  709. Begin
  710. { no netware equivalent }
  711. End;
  712. procedure intr(intno : byte;var regs : registers);
  713. begin
  714. { no netware equivalent }
  715. end;
  716. procedure msdos(var regs : registers);
  717. begin
  718. { no netware equivalent }
  719. end;
  720. end.
  721. {
  722. $Log$
  723. Revision 1.4 2004-09-26 19:23:34 armin
  724. * exiting threads at nlm unload
  725. * renamed some libc functions
  726. Revision 1.3 2004/09/19 20:06:37 armin
  727. * removed get/free video buf from video.pp
  728. * implemented sockets
  729. * basic library support
  730. * threadvar memory leak removed
  731. * fixes (ide now starts and editor is usable)
  732. * support for lineinfo
  733. Revision 1.2 2004/09/12 20:51:22 armin
  734. * added keyboard and video
  735. * a lot of fixes
  736. Revision 1.1 2004/09/05 20:58:47 armin
  737. * first rtl version for netwlibc
  738. }