2
0

dmisc.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. {$H-}
  2. unit dmisc;
  3. interface
  4. {$ifndef linux}
  5. {$define MSWindows}
  6. {$endif}
  7. uses
  8. {$ifdef linux}
  9. Libc,
  10. {$else}
  11. windows,
  12. {$endif}
  13. sysutils;
  14. {$ifdef VER100}
  15. type int64 = longint;
  16. {$endif}
  17. Const
  18. Max_Path = 255;
  19. {Bitmasks for CPU Flags}
  20. fcarry = $0001;
  21. fparity = $0004;
  22. fauxiliary = $0010;
  23. fzero = $0040;
  24. fsign = $0080;
  25. foverflow = $0800;
  26. {Bitmasks for file attribute}
  27. readonly = $01;
  28. hidden = $02;
  29. sysfile = $04;
  30. volumeid = $08;
  31. directory = $10;
  32. archive = $20;
  33. anyfile = $3F;
  34. {File Status}
  35. fmclosed = $D7B0;
  36. fminput = $D7B1;
  37. fmoutput = $D7B2;
  38. fminout = $D7B3;
  39. Type
  40. DWord = Cardinal;
  41. { Needed for Win95 LFN Support }
  42. ComStr = String[255];
  43. PathStr = String[255];
  44. DirStr = String[255];
  45. NameStr = String[255];
  46. ExtStr = String[255];
  47. FileRec = TFileRec;
  48. DateTime = packed record
  49. Year,
  50. Month,
  51. Day,
  52. Hour,
  53. Min,
  54. Sec : word;
  55. End;
  56. SearchRec = Sysutils.TSearchRec;
  57. registers = packed record
  58. case i : integer of
  59. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  60. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  61. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  62. end;
  63. Var
  64. DosError : integer;
  65. {Interrupt}
  66. Procedure Intr(intno: byte; var regs: registers);
  67. Procedure MSDos(var regs: registers);
  68. {Info/Date/Time}
  69. Function DosVersion: Word;
  70. Procedure GetDate(var year, month, mday, wday: word);
  71. Procedure GetTime(var hour, minute, second, sec100: word);
  72. Procedure UnpackTime(p: longint; var t: datetime);
  73. Procedure PackTime(var t: datetime; var p: longint);
  74. {Exec}
  75. Procedure Exec(const path: pathstr; const comline: comstr);
  76. Function DosExitCode: word;
  77. {Disk}
  78. Function DiskFree(drive: byte) : int64;
  79. Function DiskSize(drive: byte) : int64;
  80. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  81. Procedure FindNext(var f: searchRec);
  82. Procedure FindClose(Var f: SearchRec);
  83. {File}
  84. Procedure GetFAttr(var f; var attr: word);
  85. Procedure GetFTime(var f; var tim: longint);
  86. Function FSearch(path: pathstr; dirlist: string): pathstr;
  87. Function FExpand(const path: pathstr): pathstr;
  88. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  89. {Environment}
  90. Function EnvCount: longint;
  91. Function EnvStr(index: integer): string;
  92. Function GetEnv(envvar: string): string;
  93. {Misc}
  94. Procedure SetFAttr(var f; attr: word);
  95. Procedure SetFTime(var f; time: longint);
  96. Procedure GetCBreak(var breakvalue: boolean);
  97. Procedure SetCBreak(breakvalue: boolean);
  98. Procedure GetVerify(var verify: boolean);
  99. Procedure SetVerify(verify: boolean);
  100. {Do Nothing Functions}
  101. Procedure SwapVectors;
  102. Procedure GetIntVec(intno: byte; var vector: pointer);
  103. Procedure SetIntVec(intno: byte; vector: pointer);
  104. Procedure Keep(exitcode: word);
  105. implementation
  106. function upper(const s : string) : string;
  107. {
  108. return uppercased string of s
  109. }
  110. var
  111. i : longint;
  112. begin
  113. for i:=1 to length(s) do
  114. if s[i] in ['a'..'z'] then
  115. upper[i]:=char(byte(s[i])-32)
  116. else
  117. upper[i]:=s[i];
  118. upper[0]:=s[0];
  119. end;
  120. {******************************************************************************
  121. --- Conversion ---
  122. ******************************************************************************}
  123. {$ifdef MSWindows}
  124. function GetLastError : DWORD;stdcall;
  125. external 'Kernel32.dll' name 'GetLastError';
  126. function FileTimeToDosDateTime(const ft :TFileTime;var data,time : word) : boolean;stdcall;
  127. external 'Kernel32.dll' name 'FileTimeToDosDateTime';
  128. function DosDateTimeToFileTime(date,time : word;var ft :TFileTime) : boolean;stdcall;
  129. external 'Kernel32.dll' name 'DosDateTimeToFileTime';
  130. function FileTimeToLocalFileTime(const ft : TFileTime;var lft : TFileTime) : boolean;stdcall;
  131. external 'Kernel32.dll' name 'FileTimeToLocalFileTime';
  132. function LocalFileTimeToFileTime(const lft : TFileTime;var ft : TFileTime) : boolean;stdcall;
  133. external 'Kernel32.dll' name 'LocalFileTimeToFileTime';
  134. type
  135. Longrec=packed record
  136. lo,hi : word;
  137. end;
  138. function Last2DosError(d:dword):integer;
  139. begin
  140. Last2DosError:=d;
  141. end;
  142. Function DosToWinAttr (Const Attr : Longint) : longint;
  143. begin
  144. DosToWinAttr:=Attr;
  145. end;
  146. Function WinToDosAttr (Const Attr : Longint) : longint;
  147. begin
  148. WinToDosAttr:=Attr;
  149. end;
  150. Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):boolean;
  151. var
  152. lft : TFileTime;
  153. begin
  154. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,lft) and
  155. LocalFileTimeToFileTime(lft,Wtime);
  156. end;
  157. Function WinToDosTime (Const Wtime : TFileTime;var DTime:longint):boolean;
  158. var
  159. lft : TFileTime;
  160. begin
  161. WinToDosTime:=FileTimeToLocalFileTime(WTime,lft) and
  162. FileTimeToDosDateTime(lft,longrec(dtime).hi,longrec(dtime).lo);
  163. end;
  164. {$endif}
  165. {******************************************************************************
  166. --- Dos Interrupt ---
  167. ******************************************************************************}
  168. procedure intr(intno : byte;var regs : registers);
  169. begin
  170. { !!!!!!!! }
  171. end;
  172. procedure msdos(var regs : registers);
  173. begin
  174. { !!!!!!!! }
  175. end;
  176. {******************************************************************************
  177. --- Info / Date / Time ---
  178. ******************************************************************************}
  179. function dosversion : word;
  180. begin
  181. dosversion:=0;
  182. end;
  183. procedure getdate(var year,month,mday,wday : word);
  184. begin
  185. DecodeDate(Now,Year,Month,MDay);
  186. WDay:=0;
  187. // DecodeDateFully(Now,Year,Month,MDay,WDay);
  188. end;
  189. procedure gettime(var hour,minute,second,sec100 : word);
  190. begin
  191. DecodeTime(Now,Hour,Minute,Second,Sec100);
  192. Sec100:=Sec100 div 10;
  193. end;
  194. Procedure packtime(var t : datetime;var p : longint);
  195. Begin
  196. 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);
  197. End;
  198. Procedure unpacktime(p : longint;var t : datetime);
  199. Begin
  200. with t do
  201. begin
  202. sec:=(p and 31) shl 1;
  203. min:=(p shr 5) and 63;
  204. hour:=(p shr 11) and 31;
  205. day:=(p shr 16) and 31;
  206. month:=(p shr 21) and 15;
  207. year:=(p shr 25)+1980;
  208. end;
  209. End;
  210. {******************************************************************************
  211. --- Exec ---
  212. ******************************************************************************}
  213. var
  214. lastdosexitcode : word;
  215. {$ifdef MSWindows}
  216. procedure exec(const path : pathstr;const comline : comstr);
  217. var
  218. SI: TStartupInfo;
  219. PI: TProcessInformation;
  220. Proc : THandle;
  221. l : DWord;
  222. AppPath,
  223. AppParam : array[0..255] of char;
  224. begin
  225. FillChar(SI, SizeOf(SI), 0);
  226. SI.cb:=SizeOf(SI);
  227. SI.wShowWindow:=1;
  228. Move(Path[1],AppPath,length(Path));
  229. AppPath[Length(Path)]:=#0;
  230. AppParam[0]:='-';
  231. AppParam[1]:=' ';
  232. Move(ComLine[1],AppParam[2],length(Comline));
  233. AppParam[Length(ComLine)+2]:=#0;
  234. if not CreateProcess(PChar(@AppPath), PChar(@AppParam), Nil, Nil, False,$20, Nil, Nil, SI, PI) then
  235. begin
  236. DosError:=Last2DosError(GetLastError);
  237. exit;
  238. end
  239. else
  240. DosError:=0;
  241. Proc:=PI.hProcess;
  242. CloseHandle(PI.hThread);
  243. if WaitForSingleObject(Proc, Infinite) <> $ffffffff then
  244. GetExitCodeProcess(Proc,l)
  245. else
  246. l:=$ffffffff;
  247. CloseHandle(Proc);
  248. LastDosExitCode:=l;
  249. end;
  250. {$endif MSWindows}
  251. {$ifdef Linux}
  252. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  253. var
  254. pid,status : longint;
  255. Begin
  256. LastDosExitCode:=0;
  257. pid:=Fork;
  258. if pid=0 then
  259. begin
  260. {The child does the actual exec, and then exits}
  261. Execl(@Path[1],@ComLine[1]);
  262. {If the execve fails, we return an exitvalue of 127, to let it be known}
  263. __exit(127);
  264. end
  265. else
  266. if pid=-1 then {Fork failed}
  267. begin
  268. DosError:=8;
  269. exit
  270. end;
  271. {We're in the parent, let's wait.}
  272. WaitPid(Pid,@Status,0);
  273. LastDosExitCode:=Status; // WaitPid and result-convert
  274. if (LastDosExitCode>=0) and (LastDosExitCode<>127) then
  275. DosError:=0
  276. else
  277. DosError:=8; // perhaps one time give an better error
  278. End;
  279. {$endif Linux}
  280. function dosexitcode : word;
  281. begin
  282. dosexitcode:=lastdosexitcode;
  283. end;
  284. procedure swapvectors;
  285. begin
  286. end;
  287. procedure getcbreak(var breakvalue : boolean);
  288. begin
  289. { !! No Win32 Function !! }
  290. end;
  291. procedure setcbreak(breakvalue : boolean);
  292. begin
  293. { !! No Win32 Function !! }
  294. end;
  295. procedure getverify(var verify : boolean);
  296. begin
  297. { !! No Win32 Function !! }
  298. end;
  299. procedure setverify(verify : boolean);
  300. begin
  301. { !! No Win32 Function !! }
  302. end;
  303. {******************************************************************************
  304. --- Disk ---
  305. ******************************************************************************}
  306. {$ifdef Linux]
  307. {
  308. The Diskfree and Disksize functions need a file on the specified drive, since this
  309. is required for the statfs system call.
  310. These filenames are set in drivestr[0..26], and have been preset to :
  311. 0 - '.' (default drive - hence current dir is ok.)
  312. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  313. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  314. 3 - '/' (C: equivalent of dos is the root partition)
  315. 4..26 (can be set by you're own applications)
  316. ! Use AddDisk() to Add new drives !
  317. They both return -1 when a failure occurs.
  318. }
  319. Const
  320. FixDriveStr : array[0..3] of pchar=(
  321. '.',
  322. '/fd0/.',
  323. '/fd1/.',
  324. '/.'
  325. );
  326. var
  327. Drives : byte = 4;
  328. var
  329. DriveStr : array[4..26] of pchar;
  330. Procedure AddDisk(const path:string);
  331. begin
  332. if not (DriveStr[Drives]=nil) then
  333. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  334. GetMem(DriveStr[Drives],length(Path)+1);
  335. StrPCopy(DriveStr[Drives],path);
  336. inc(Drives);
  337. if Drives>26 then
  338. Drives:=4;
  339. end;
  340. Function DiskFree(Drive: Byte): int64;
  341. var
  342. fs : tstatfs;
  343. Begin
  344. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (statfs(fixdrivestr[drive],fs)=0)) or
  345. ((not (drivestr[Drive]=nil)) and (statfs(drivestr[drive],fs)=0)) then
  346. Diskfree:=int64(fs.f_bavail)*int64(fs.f_bsize)
  347. else
  348. Diskfree:=-1;
  349. End;
  350. Function DiskSize(Drive: Byte): int64;
  351. var
  352. fs : tstatfs;
  353. Begin
  354. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (statfs(fixdrivestr[drive],fs)=0)) or
  355. ((not (drivestr[Drive]=nil)) and (statfs(drivestr[drive],fs)=0)) then
  356. Disksize:=int64(fs.f_blocks)*int64(fs.f_bsize)
  357. else
  358. Disksize:=-1;
  359. End;
  360. {$else linux}
  361. function diskfree(drive : byte) : int64;
  362. begin
  363. DiskFree:=SysUtils.DiskFree(drive);
  364. end;
  365. function disksize(drive : byte) : int64;
  366. begin
  367. DiskSize:=SysUtils.DiskSize(drive);
  368. end;
  369. {$endif linux}
  370. {******************************************************************************
  371. --- Findfirst FindNext ---
  372. ******************************************************************************}
  373. procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
  374. begin
  375. DosError:=SysUtils.FindFirst(Path,Attr,f);
  376. end;
  377. procedure findnext(var f : searchRec);
  378. begin
  379. DosError:=Sysutils.FindNext(f);
  380. end;
  381. Procedure FindClose(Var f: SearchRec);
  382. begin
  383. Sysutils.FindClose(f);
  384. end;
  385. {******************************************************************************
  386. --- File ---
  387. ******************************************************************************}
  388. procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;var ext : extstr);
  389. var
  390. p1,i : longint;
  391. begin
  392. { allow slash as backslash }
  393. for i:=1 to length(path) do
  394. if path[i]='/' then path[i]:='\';
  395. { get drive name }
  396. p1:=pos(':',path);
  397. if p1>0 then
  398. begin
  399. dir:=path[1]+':';
  400. delete(path,1,p1);
  401. end
  402. else
  403. dir:='';
  404. { split the path and the name, there are no more path informtions }
  405. { if path contains no backslashes }
  406. while true do
  407. begin
  408. p1:=pos('\',path);
  409. if p1=0 then
  410. break;
  411. dir:=dir+copy(path,1,p1);
  412. delete(path,1,p1);
  413. end;
  414. { try to find out a extension }
  415. p1:=pos('.',path);
  416. if p1>0 then
  417. begin
  418. ext:=copy(path,p1,4);
  419. delete(path,p1,length(path)-p1+1);
  420. end
  421. else
  422. ext:='';
  423. name:=path;
  424. end;
  425. function fexpand(const path : pathstr) : pathstr;
  426. var
  427. s,pa : string[79];
  428. i,j : longint;
  429. begin
  430. getdir(0,s);
  431. pa:=upper(path);
  432. { allow slash as backslash }
  433. for i:=1 to length(pa) do
  434. if pa[i]='/' then
  435. pa[i]:='\';
  436. if (length(pa)>1) and (pa[1] in ['A'..'Z']) and (pa[2]=':') then
  437. begin
  438. { we must get the right directory }
  439. getdir(ord(pa[1])-ord('A')+1,s);
  440. if (ord(pa[0])>2) and (pa[3]<>'\') then
  441. if pa[1]=s[1] then
  442. pa:=s+'\'+copy (pa,3,length(pa))
  443. else
  444. pa:=pa[1]+':\'+copy (pa,3,length(pa))
  445. end
  446. else
  447. if pa[1]='\' then
  448. pa:=s[1]+':'+pa
  449. else if s[0]=#3 then
  450. pa:=s+pa
  451. else
  452. pa:=s+'\'+pa;
  453. { Turbo Pascal gives current dir on drive if only drive given as parameter! }
  454. if length(pa) = 2 then
  455. begin
  456. getdir(byte(pa[1])-64,s);
  457. pa := s;
  458. end;
  459. {First remove all references to '\.\'}
  460. while pos ('\.\',pa)<>0 do
  461. delete (pa,pos('\.\',pa),2);
  462. {Now remove also all references to '\..\' + of course previous dirs..}
  463. repeat
  464. i:=pos('\..\',pa);
  465. if i<>0 then
  466. begin
  467. j:=i-1;
  468. while (j>1) and (pa[j]<>'\') do
  469. dec (j);
  470. if pa[j+1] = ':' then j := 3;
  471. delete (pa,j,i-j+3);
  472. end;
  473. until i=0;
  474. { Turbo Pascal gets rid of a \.. at the end of the path }
  475. { Now remove also any reference to '\..' at end of line
  476. + of course previous dir.. }
  477. i:=pos('\..',pa);
  478. if i<>0 then
  479. begin
  480. if i = length(pa) - 2 then
  481. begin
  482. j:=i-1;
  483. while (j>1) and (pa[j]<>'\') do
  484. dec (j);
  485. delete (pa,j,i-j+3);
  486. end;
  487. pa := pa + '\';
  488. end;
  489. { Remove End . and \}
  490. if (length(pa)>0) and (pa[length(pa)]='.') then
  491. dec(byte(pa[0]));
  492. { if only the drive + a '\' is left then the '\' should be left to prevtn the program
  493. accessing the current directory on the drive rather than the root!}
  494. { if the last char of path = '\' then leave it in as this is what TP does! }
  495. if ((length(pa)>3) and (pa[length(pa)]='\')) and (path[length(path)] <> '\') then
  496. dec(byte(pa[0]));
  497. { if only a drive is given in path then there should be a '\' at the
  498. end of the string given back }
  499. if length(path) = 2 then pa := pa + '\';
  500. fexpand:=pa;
  501. end;
  502. Function FSearch(path: pathstr; dirlist: string): pathstr;
  503. var
  504. i,p1 : longint;
  505. s : searchrec;
  506. newdir : pathstr;
  507. begin
  508. { No wildcards allowed in these things }
  509. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  510. fsearch:=''
  511. else
  512. begin
  513. { allow slash as backslash }
  514. for i:=1 to length(dirlist) do
  515. if dirlist[i]='/' then dirlist[i]:='\';
  516. repeat
  517. p1:=pos(';',dirlist);
  518. if p1=0 then
  519. begin
  520. newdir:=copy(dirlist,1,p1-1);
  521. delete(dirlist,1,p1);
  522. end
  523. else
  524. begin
  525. newdir:=dirlist;
  526. dirlist:='';
  527. end;
  528. if (newdir<>'') and (not (newdir[length(newdir)] in ['\',':'])) then
  529. newdir:=newdir+'\';
  530. findfirst(newdir+path,anyfile,s);
  531. if doserror=0 then
  532. newdir:=newdir+path
  533. else
  534. newdir:='';
  535. until (dirlist='') or (newdir<>'');
  536. fsearch:=newdir;
  537. end;
  538. end;
  539. procedure getftime(var f;var tim : longint);
  540. begin
  541. tim:=FileGetDate(filerec(f).handle);
  542. end;
  543. procedure setftime(var f;time : longint);
  544. begin
  545. {$ifdef linux}
  546. FileSetDate(filerec(f).name,Time);
  547. {$else}
  548. FileSetDate(filerec(f).handle,Time);
  549. {$endif}
  550. end;
  551. {$ifdef linux}
  552. procedure getfattr(var f;var attr : word);
  553. Var
  554. info : tstatbuf;
  555. LinAttr : longint;
  556. Begin
  557. DosError:=0;
  558. if (FStat(filerec(f).handle,info)<>0) then
  559. begin
  560. Attr:=0;
  561. DosError:=3;
  562. exit;
  563. end
  564. else
  565. LinAttr:=Info.st_Mode;
  566. if S_ISDIR(LinAttr) then
  567. Attr:=$10
  568. else
  569. Attr:=$20;
  570. if Access(@filerec(f).name,W_OK)<>0 then
  571. Attr:=Attr or $1;
  572. if (not S_ISDIR(LinAttr)) and (filerec(f).name[0]='.') then
  573. Attr:=Attr or $2;
  574. end;
  575. {$else}
  576. procedure getfattr(var f;var attr : word);
  577. var
  578. l : longint;
  579. begin
  580. l:=FileGetAttr(filerec(f).name);
  581. attr:=l;
  582. end;
  583. {$endif}
  584. procedure setfattr(var f;attr : word);
  585. begin
  586. {$ifdef MSWindows}
  587. FileSetAttr(filerec(f).name,attr);
  588. {$endif}
  589. end;
  590. {******************************************************************************
  591. --- Environment ---
  592. ******************************************************************************}
  593. {
  594. The environment is a block of zero terminated strings
  595. terminated by a #0
  596. }
  597. {$ifdef MSWindows}
  598. function GetEnvironmentStrings : pchar;stdcall;
  599. external 'Kernel32.dll' name 'GetEnvironmentStringsA';
  600. function FreeEnvironmentStrings(p : pchar) : boolean;stdcall;
  601. external 'Kernel32.dll' name 'FreeEnvironmentStringsA';
  602. function envcount : longint;
  603. var
  604. hp,p : pchar;
  605. count : longint;
  606. begin
  607. p:=GetEnvironmentStrings;
  608. hp:=p;
  609. count:=0;
  610. while hp^<>#0 do
  611. begin
  612. { next string entry}
  613. hp:=hp+strlen(hp)+1;
  614. inc(count);
  615. end;
  616. FreeEnvironmentStrings(p);
  617. envcount:=count;
  618. end;
  619. Function EnvStr(index: integer): string;
  620. var
  621. hp,p : pchar;
  622. count,i : longint;
  623. begin
  624. { envcount takes some time in win32 }
  625. count:=envcount;
  626. { range checking }
  627. if (index<=0) or (index>count) then
  628. begin
  629. envstr:='';
  630. exit;
  631. end;
  632. p:=GetEnvironmentStrings;
  633. hp:=p;
  634. { retrive the string with the given index }
  635. for i:=2 to index do
  636. hp:=hp+strlen(hp)+1;
  637. envstr:=strpas(hp);
  638. FreeEnvironmentStrings(p);
  639. end;
  640. Function GetEnv(envvar: string): string;
  641. var
  642. s : string;
  643. i : longint;
  644. hp,p : pchar;
  645. begin
  646. getenv:='';
  647. p:=GetEnvironmentStrings;
  648. hp:=p;
  649. while hp^<>#0 do
  650. begin
  651. s:=strpas(hp);
  652. i:=pos('=',s);
  653. if copy(s,1,i-1)=envvar then
  654. begin
  655. getenv:=copy(s,i+1,length(s)-i);
  656. break;
  657. end;
  658. { next string entry}
  659. hp:=hp+strlen(hp)+1;
  660. end;
  661. FreeEnvironmentStrings(p);
  662. end;
  663. {$else}
  664. function envcount : longint;
  665. begin
  666. envcount:=0;
  667. end;
  668. Function EnvStr(index: integer): string;
  669. begin
  670. envstr:='';
  671. end;
  672. Function GetEnv(envvar: string): string;
  673. begin
  674. getenv:=GetEnvironmentVariable(envvar);
  675. end;
  676. {$endif}
  677. {******************************************************************************
  678. --- Not Supported ---
  679. ******************************************************************************}
  680. Procedure keep(exitcode : word);
  681. Begin
  682. End;
  683. Procedure getintvec(intno : byte;var vector : pointer);
  684. Begin
  685. End;
  686. Procedure setintvec(intno : byte;vector : pointer);
  687. Begin
  688. End;
  689. end.