2
0

dos.pp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998 by Nils Sjoholm and Carl Eric Codere
  5. members of the Free Pascal development team
  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. {
  14. History:
  15. 10.02.1998 First version for Amiga.
  16. Just GetDate and GetTime.
  17. 11.02.1998 Added AmigaToDt and DtToAmiga
  18. Changed GetDate and GetTime to
  19. use AmigaToDt and DtToAmiga.
  20. Added DiskSize and DiskFree.
  21. They are using a string as arg
  22. have to try to fix that.
  23. 12.02.1998 Added Fsplit and FExpand.
  24. Cleaned up the unit and removed
  25. stuff that was not used yet.
  26. 13.02.1998 Added CToPas and PasToC and removed
  27. the uses of strings.
  28. 14.02.1998 Removed AmigaToDt and DtToAmiga
  29. from public area.
  30. Added deviceids and devicenames
  31. arrays so now diskfree and disksize
  32. is compatible with dos.
  33. }
  34. {--------------------------------------------------------------------}
  35. { LEFT TO DO: }
  36. {--------------------------------------------------------------------}
  37. { o DiskFree / Disksize don't work as expected }
  38. { o Implement SetDate and SetTime }
  39. { o Implement Setftime }
  40. { o Implement EnvCount,EnvStr }
  41. { o FindFirst should only work with correct attributes }
  42. {--------------------------------------------------------------------}
  43. Interface
  44. {$I os.inc}
  45. Const
  46. {Bitmasks for CPU Flags}
  47. fcarry = $0001;
  48. fparity = $0004;
  49. fauxiliary = $0010;
  50. fzero = $0040;
  51. fsign = $0080;
  52. foverflow = $0800;
  53. {Bitmasks for file attribute}
  54. readonly = $01;
  55. hidden = $02;
  56. sysfile = $04;
  57. volumeid = $08;
  58. directory = $10;
  59. archive = $20;
  60. anyfile = $3F;
  61. {File Status}
  62. fmclosed = $D7B0;
  63. fminput = $D7B1;
  64. fmoutput = $D7B2;
  65. fminout = $D7B3;
  66. Type
  67. ComStr = String[255]; { size increased to be more compatible with Unix}
  68. PathStr = String[255]; { size increased to be more compatible with Unix}
  69. DirStr = String[255]; { size increased to be more compatible with Unix}
  70. NameStr = String[255]; { size increased to be more compatible with Unix}
  71. ExtStr = String[255]; { size increased to be more compatible with Unix}
  72. { If you need more devicenames just expand this two arrays }
  73. { device zero is for the current drive }
  74. deviceids = (NOTHING, DF0ID, DF1ID, DF2ID, DF3ID, DH0ID, DH1ID,
  75. CD0ID, MDOS1ID, MDOS2ID);
  76. Const
  77. devicenames : array [DF0ID..MDOS2ID] of String = (
  78. 'df0:','df1:','df2:','df3:','dh0:',
  79. 'dh1:','cd0:','A:','B:');
  80. {
  81. filerec.inc contains the definition of the filerec.
  82. textrec.inc contains the definition of the textrec.
  83. It is in a separate file to make it available in other units without
  84. having to use the DOS unit for it.
  85. }
  86. {$i filerec.inc}
  87. {$i textrec.inc}
  88. Type
  89. SearchRec = Packed Record
  90. { Replacement for Fill }
  91. AnchorPtr : Pointer; { Pointer to the Anchorpath structure }
  92. Fill: Array[1..14] of Byte; {future use}
  93. {End of replacement for fill}
  94. Attr : BYTE; {attribute of found file}
  95. Time : LongInt; {last modify date of found file}
  96. Size : LongInt; {file size of found file}
  97. Name : String[255]; {name of found file}
  98. End;
  99. DateTime = packed record
  100. Year: Word;
  101. Month: Word;
  102. Day: Word;
  103. Hour: Word;
  104. Min: Word;
  105. Sec: word;
  106. End;
  107. Var
  108. DosError : integer;
  109. {Interrupt}
  110. {Procedure Intr(intno: byte; var regs: registers);
  111. Procedure MSDos(var regs: registers);}
  112. {Info/Date/Time}
  113. Function DosVersion: Word;
  114. Procedure GetDate(var year, month, mday, wday: word);
  115. Procedure GetTime(var hour, minute, second, sec100: word);
  116. procedure SetDate(year,month,day: word);
  117. Procedure SetTime(hour,minute,second,sec100: word);
  118. Procedure UnpackTime(p: longint; var t: datetime);
  119. Procedure PackTime(var t: datetime; var p: longint);
  120. {Exec}
  121. Procedure Exec(const path: pathstr; const comline: comstr);
  122. Function DosExitCode: word;
  123. {Disk}
  124. Function DiskFree(drive: byte) : longint;
  125. Function DiskSize(drive: byte) : longint;
  126. Procedure FindFirst(path: pathstr; attr: word; var f: searchRec);
  127. Procedure FindNext(var f: searchRec);
  128. Procedure FindClose(Var f: SearchRec);
  129. {File}
  130. Procedure GetFAttr(var f; var attr: word);
  131. Procedure GetFTime(var f; var time: longint);
  132. Function FSearch(path: pathstr; dirlist: string): pathstr;
  133. Function FExpand(path: pathstr): pathstr;
  134. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  135. {Environment}
  136. Function EnvCount: longint;
  137. Function EnvStr(index: integer): string;
  138. Function GetEnv(envvar: string): string;
  139. {Misc}
  140. Procedure SetFAttr(var f; attr: word);
  141. Procedure SetFTime(var f; time: longint);
  142. Procedure GetCBreak(var breakvalue: boolean);
  143. Procedure SetCBreak(breakvalue: boolean);
  144. Procedure GetVerify(var verify: boolean);
  145. Procedure SetVerify(verify: boolean);
  146. {Do Nothing Functions}
  147. Procedure SwapVectors;
  148. Procedure GetIntVec(intno: byte; var vector: pointer);
  149. Procedure SetIntVec(intno: byte; vector: pointer);
  150. Procedure Keep(exitcode: word);
  151. implementation
  152. Type
  153. pClockData = ^tClockData;
  154. tClockData = packed Record
  155. sec : Word;
  156. min : Word;
  157. hour : Word;
  158. mday : Word;
  159. month : Word;
  160. year : Word;
  161. wday : Word;
  162. END;
  163. BPTR = Longint;
  164. BSTR = Longint;
  165. TDateStamp = packed record
  166. ds_Days : Longint; { Number of days since Jan. 1, 1978 }
  167. ds_Minute : Longint; { Number of minutes past midnight }
  168. ds_Tick : Longint; { Number of ticks past minute }
  169. end;
  170. PDateStamp = ^TDateStamp;
  171. { Returned by Examine() and ExInfo(), must be on a 4 byte boundary }
  172. PFileInfoBlock = ^TfileInfoBlock;
  173. TFileInfoBlock = packed record
  174. fib_DiskKey : Longint;
  175. fib_DirEntryType : Longint;
  176. { Type of Directory. If < 0, then a plain file.
  177. If > 0 a directory }
  178. fib_FileName : Array [0..107] of Char;
  179. { Null terminated. Max 30 chars used for now }
  180. fib_Protection : Longint;
  181. { bit mask of protection, rwxd are 3-0. }
  182. fib_EntryType : Longint;
  183. fib_Size : Longint; { Number of bytes in file }
  184. fib_NumBlocks : Longint; { Number of blocks in file }
  185. fib_Date : TDateStamp; { Date file last changed }
  186. fib_Comment : Array [0..79] of Char;
  187. { Null terminated comment associated with file }
  188. fib_Reserved : Array [0..35] of Char;
  189. end;
  190. { returned by Info(), must be on a 4 byte boundary }
  191. pInfoData = ^tInfoData;
  192. tInfoData = packed record
  193. id_NumSoftErrors : Longint; { number of soft errors on disk }
  194. id_UnitNumber : Longint; { Which unit disk is (was) mounted on }
  195. id_DiskState : Longint; { See defines below }
  196. id_NumBlocks : Longint; { Number of blocks on disk }
  197. id_NumBlocksUsed : Longint; { Number of block in use }
  198. id_BytesPerBlock : Longint;
  199. id_DiskType : Longint; { Disk Type code }
  200. id_VolumeNode : BPTR; { BCPL pointer to volume node }
  201. id_InUse : Longint; { Flag, zero if not in use }
  202. end;
  203. { ------ Library Base Structure ---------------------------------- }
  204. { Also used for Devices and some Resources }
  205. { * List Node Structure. Each member in a list starts with a Node * }
  206. pNode = ^tNode;
  207. tNode = Packed Record
  208. ln_Succ, { * Pointer to next (successor) * }
  209. ln_Pred : pNode; { * Pointer to previous (predecessor) * }
  210. ln_Type : Byte;
  211. ln_Pri : Shortint; { * Priority, for sorting * }
  212. ln_Name : PCHAR; { * ID string, null terminated * }
  213. End; { * Note: Integer aligned * }
  214. pLibrary = ^tLibrary;
  215. tLibrary = packed record
  216. lib_Node : tNode;
  217. lib_Flags,
  218. lib_pad : Byte;
  219. lib_NegSize, { number of bytes before library }
  220. lib_PosSize, { number of bytes after library }
  221. lib_Version, { major }
  222. lib_Revision : Word; { minor }
  223. lib_IdString : PCHAR; { ASCII identification }
  224. lib_Sum : LONGINT; { the checksum itself }
  225. lib_OpenCnt : Word; { number of current opens }
  226. end; { * Warning: size is not a longword multiple ! * }
  227. PChain = ^TChain;
  228. TChain = packed record
  229. an_Child : PChain;
  230. an_Parent: PChain;
  231. an_Lock : BPTR;
  232. an_info : TFileInfoBlock;
  233. an_Flags : shortint;
  234. an_string: Array[0..0] of char;
  235. end;
  236. PAnchorPath = ^TAnchorPath;
  237. TAnchorPath = packed record
  238. ap_Base : PChain; {* pointer to first anchor *}
  239. ap_First : PChain; {* pointer to last anchor *}
  240. ap_BreakBits : LONGINT; {* Bits we want to break on *}
  241. ap_FondBreak : LONGINT; {* Bits we broke on. Also returns ERROR_BREAK *}
  242. ap_Flags : shortint; {* New use for extra word. *}
  243. ap_reserved : BYTE;
  244. ap_StrLen : WORD;
  245. ap_Info : TFileInfoBlock;
  246. ap_Buf : Array[0..0] of Char; {* Buffer for path name, allocated by user *}
  247. END;
  248. pCommandLineInterface = ^TCommandLineInterface;
  249. TCommandLineInterface = packed record
  250. cli_result2 : longint; {* Value of IoErr from last command *}
  251. cli_SetName : BSTR; {* Name of current directory *}
  252. cli_CommandDir : BPTR; {* Head of the path locklist *}
  253. cli_ReturnCode : longint; {* Return code from last command *}
  254. cli_CommandName : BSTR; {* Name of current command *}
  255. cli_FailLevel : longint; {* Fail level (set by FAILAT) *}
  256. cli_Prompt : BSTR; {* Current prompt (set by PROMPT) *}
  257. cli_StandardInput: BPTR; {* Default (terminal) CLI input *}
  258. cli_CurrentInput : BPTR; {* Current CLI input *}
  259. cli_CommandFile : BSTR; {* Name of EXECUTE command file *}
  260. cli_Interactive : longint; {* Boolean; True if prompts required *}
  261. cli_Background : longint {* Boolean; True if CLI created by RUN*}
  262. cli_CurrentOutput: BPTR; {* Current CLI output *}
  263. cli_DefautlStack : longint; {* Stack size to be obtained in long words *}
  264. cli_StandardOutput : BPTR; {* Default (terminal) CLI output *}
  265. cli_Module : BPTR; {* SegList of currently loaded command*}
  266. END;
  267. CONST
  268. { DOS Lib Offsets }
  269. _LVOMatchFirst = -822;
  270. _LVOMatchNext = -828;
  271. _LVOMatchEnd = -834;
  272. _LVOCli = -492;
  273. _LVOExecute = -222;
  274. _LVOSystemTagList = -606;
  275. ERROR_NO_MORE_ENTRIES = 232;
  276. FIBF_SCRIPT = 64; { program is a script }
  277. FIBF_PURE = 32; { program is reentrant }
  278. FIBF_ARCHIVE = 16; { cleared whenever file is changed }
  279. FIBF_READ = 8; { ignoed by old filesystem }
  280. FIBF_WRITE = 4; { ignored by old filesystem }
  281. FIBF_EXECUTE = 2; { ignored by system, used by shell }
  282. FIBF_DELETE = 1; { prevent file from being deleted }
  283. {******************************************************************************
  284. --- Internal routines ---
  285. ******************************************************************************}
  286. procedure CurrentTime(var Seconds, Micros : Longint);
  287. Begin
  288. asm
  289. MOVE.L A6,-(A7)
  290. MOVE.L Seconds,a0
  291. MOVE.L Micros,a1
  292. MOVE.L _IntuitionBase,A6
  293. JSR -084(A6)
  294. MOVE.L (A7)+,A6
  295. end;
  296. end;
  297. function Date2Amiga(date : pClockData) : Longint;
  298. Begin
  299. asm
  300. MOVE.L A6,-(A7)
  301. MOVE.L date,a0
  302. MOVE.L _UtilityBase,A6
  303. JSR -126(A6)
  304. MOVE.L (A7)+,A6
  305. MOVE.L d0,@RESULT
  306. end;
  307. end;
  308. procedure Amiga2Date(amigatime : Longint;
  309. resultat : pClockData);
  310. Begin
  311. asm
  312. MOVE.L A6,-(A7)
  313. MOVE.L amigatime,d0
  314. MOVE.L resultat,a0
  315. MOVE.L _UtilityBase,A6
  316. JSR -120(A6)
  317. MOVE.L (A7)+,A6
  318. end;
  319. end;
  320. function Examine(lock : BPTR;
  321. info : pFileInfoBlock) : Boolean;
  322. Begin
  323. asm
  324. MOVEM.L d2/a6,-(A7)
  325. MOVE.L lock,d1
  326. MOVE.L info,d2
  327. MOVE.L _DOSBase,A6
  328. JSR -102(A6)
  329. MOVEM.L (A7)+,d2/a6
  330. TST.L d0
  331. SNE d0
  332. NEG.B d0
  333. MOVE.B d0,@RESULT
  334. end;
  335. end;
  336. function Lock(const name : string;
  337. accessmode : Longint) : BPTR;
  338. var
  339. buffer: Array[0..50] of char;
  340. Begin
  341. move(name[1],buffer,length(name));
  342. buffer[length(name)]:=#0;
  343. asm
  344. MOVEM.L d2/a6,-(A7)
  345. LEA buffer,a0
  346. MOVE.L a0,d1
  347. MOVE.L accessmode,d2
  348. MOVE.L _DOSBase,A6
  349. JSR -084(A6)
  350. MOVEM.L (A7)+,d2/a6
  351. MOVE.L d0,@RESULT
  352. end;
  353. end;
  354. procedure UnLock(lock : BPTR);
  355. Begin
  356. asm
  357. MOVE.L A6,-(A7)
  358. MOVE.L lock,d1
  359. MOVE.L _DOSBase,A6
  360. JSR -090(A6)
  361. MOVE.L (A7)+,A6
  362. end;
  363. end;
  364. function Info(lock : BPTR;
  365. params : pInfoData) : Boolean;
  366. Begin
  367. asm
  368. MOVEM.L d2/a6,-(A7)
  369. MOVE.L lock,d1
  370. MOVE.L params,d2
  371. MOVE.L _DOSBase,A6
  372. JSR -114(A6)
  373. MOVEM.L (A7)+,d2/a6
  374. TST.L d0
  375. SNE d0
  376. NEG.B d0
  377. MOVE.B d0,@RESULT
  378. end;
  379. end;
  380. function NameFromLock(Datei : BPTR;
  381. Buffer : Pchar;
  382. BufferSize : Longint) : Boolean;
  383. Begin
  384. asm
  385. MOVEM.L d2/d3/a6,-(A7)
  386. MOVE.L Datei,d1
  387. MOVE.L Buffer,d2
  388. MOVE.L BufferSize,d3
  389. MOVE.L _DOSBase,A6
  390. JSR -402(A6)
  391. MOVEM.L (A7)+,d2/d3/a6
  392. TST.L d0
  393. SNE d0
  394. NEG.B d0
  395. MOVE.B d0,@RESULT
  396. end;
  397. end;
  398. function GetVar(name : pchar; Buffer : pchar; BufferSize : Longint;
  399. flags : Longint) : Longint;
  400. begin
  401. asm
  402. MOVEM.L d2/d3/d4/a6,-(A7)
  403. MOVE.L name,d1
  404. MOVE.L Buffer,d2
  405. MOVE.L BufferSize,d3
  406. MOVE.L flags,d4
  407. MOVE.L _DOSBase,A6
  408. JSR -906(A6)
  409. MOVEM.L (A7)+,d2/d3/d4/a6
  410. MOVE.L d0,@RESULT
  411. end;
  412. end;
  413. (* Function FindTask(p : PChar): PProcess;
  414. Begin
  415. asm
  416. move.l a6,d6 { Save base pointer }
  417. move.l p,d0
  418. move.l d0,a1
  419. move.l _ExecBase,a6
  420. jsr _LVOFindTask(a6)
  421. move.l d6,a6 { Restore base pointer }
  422. move.l d0,@Result
  423. end;
  424. end;*)
  425. Function MatchFirst(pat: pchar; Anchor: pAnchorPath) : longint;
  426. Begin
  427. asm
  428. move.l d2,-(sp)
  429. move.l a6,d6
  430. move.l pat,d1
  431. move.l Anchor,d2
  432. move.l _DosBase,a6
  433. jsr _LVOMatchFirst(a6)
  434. move.l (sp)+,d2
  435. move.l d6,a6
  436. move.l d0,@Result
  437. end;
  438. end;
  439. Function MatchNext(Anchor : pAnchorPath): longint;
  440. Begin
  441. asm
  442. move.l anchor,d1
  443. move.l a6,d6
  444. move.l _DosBase,a6
  445. jsr _LVOMatchNext(a6)
  446. move.l d6,a6
  447. move.l d0,@Result
  448. end;
  449. end;
  450. Procedure MatchEnd(Anchor : pAnchorPath);
  451. Begin
  452. asm
  453. move.l anchor,d1
  454. move.l a6,d6
  455. move.l _DosBase,a6
  456. jsr _LVOMatchEnd(a6)
  457. move.l d6,a6
  458. end;
  459. end;
  460. Function Cli: Pointer; assembler;
  461. { Returns a pointer to the current cli process }
  462. asm
  463. move.l a6,d6
  464. move.l _DosBase,a6
  465. jsr _LVOCli(a6)
  466. move.l d6,a6 { value is returned in d0 }
  467. end;
  468. Function _Execute(p: pchar): longint;
  469. Begin
  470. asm
  471. move.l a6,d6 { save base pointer }
  472. move.l d2,-(sp)
  473. move.l p,d1 { command to execute }
  474. clr.l d2 { No TagList for command }
  475. move.l _DosBase,a6
  476. jsr _LVOSystemTagList(a6)
  477. move.l (sp)+,d2
  478. move.l d6,a6 { restore base pointer }
  479. move.l d0,@RESULT
  480. end;
  481. end;
  482. function PasToC(var s: string): Pchar;
  483. var i: integer;
  484. begin
  485. i := Length(s) + 1;
  486. if i > 255 then
  487. begin
  488. Delete(s, 255, 1); { ensure there is a spare byte }
  489. Dec(i)
  490. end;
  491. s[i] := #0;
  492. PasToC := @s[1]
  493. end;
  494. Function strpas(Str: pchar): string;
  495. { only 255 first characters are actually copied. }
  496. var
  497. counter : byte;
  498. lstr: string;
  499. Begin
  500. counter := 0;
  501. lstr := '';
  502. while (ord(Str[counter]) <> 0) and (counter < 255) do
  503. begin
  504. Inc(counter);
  505. lstr[counter] := char(Str[counter-1]);
  506. end;
  507. lstr[0] := char(counter);
  508. strpas := lstr;
  509. end;
  510. Procedure AmigaToDt(SecsPast: LongInt; Var Dt: DateTime);
  511. var
  512. cd : pClockData;
  513. Begin
  514. New(cd);
  515. Amiga2Date(SecsPast,cd);
  516. Dt.sec := cd^.sec;
  517. Dt.min := cd^.min;
  518. Dt.hour := cd^.hour;
  519. Dt.day := cd^.mday;
  520. Dt.month := cd^.month;
  521. Dt.year := cd^.year;
  522. Dispose(cd);
  523. End;
  524. Function DtToAmiga(DT: DateTime): LongInt;
  525. var
  526. cd : pClockData;
  527. temp : Longint;
  528. Begin
  529. New(cd);
  530. cd^.sec := Dt.sec;
  531. cd^.min := Dt.min;
  532. cd^.hour := Dt.hour;
  533. cd^.mday := Dt.day;
  534. cd^.month := Dt.month;
  535. cd^.year := Dt.year;
  536. temp := Date2Amiga(cd);
  537. Dispose(cd);
  538. DtToAmiga := temp;
  539. end;
  540. Function SetProtection(const name: string; mask:longint): longint;
  541. var
  542. buffer : array[0..255] of char;
  543. Begin
  544. move(name[1],buffer,length(name));
  545. buffer[length(name)]:=#0;
  546. asm
  547. move.l a6,d6
  548. lea buffer,a0
  549. move.l a0,d1
  550. move.l mask,d2
  551. move.l _DosBase,a6
  552. jsr -186(a6)
  553. move.l d6,a6
  554. move.l d0,@RESULT
  555. end;
  556. end;
  557. {******************************************************************************
  558. --- Dos Interrupt ---
  559. ******************************************************************************}
  560. (*Procedure Intr (intno: byte; var regs: registers);
  561. Begin
  562. { Does not apply to Linux - not implemented }
  563. End;*)
  564. Procedure SwapVectors;
  565. Begin
  566. { Does not apply to Linux - Do Nothing }
  567. End;
  568. (*Procedure msdos(var regs : registers);
  569. Begin
  570. { ! Not implemented in Linux ! }
  571. End;*)
  572. Procedure getintvec(intno : byte;var vector : pointer);
  573. Begin
  574. { ! Not implemented in Linux ! }
  575. End;
  576. Procedure setintvec(intno : byte;vector : pointer);
  577. Begin
  578. { ! Not implemented in Linux ! }
  579. End;
  580. {******************************************************************************
  581. --- Info / Date / Time ---
  582. ******************************************************************************}
  583. Function DosVersion: Word;
  584. var p: pLibrary;
  585. Begin
  586. p:=pLibrary(_DosBase);
  587. DosVersion:= p^.lib_Version or (p^.lib_Revision shl 8);
  588. End;
  589. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  590. Var
  591. cd : pClockData;
  592. mysec,
  593. tick : Longint;
  594. begin
  595. New(cd);
  596. CurrentTime(mysec,tick);
  597. Amiga2Date(mysec,cd);
  598. Year := cd^.year;
  599. Month := cd^.month;
  600. MDay := cd^.mday;
  601. WDay := cd^.wday;
  602. Dispose(cd);
  603. end;
  604. Procedure SetDate(Year, Month, Day: Word);
  605. Begin
  606. { !! }
  607. End;
  608. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  609. Var
  610. mysec,
  611. tick : Longint;
  612. cd : pClockData;
  613. begin
  614. New(cd);
  615. CurrentTime(mysec,tick);
  616. Amiga2Date(mysec,cd);
  617. Hour := cd^.hour;
  618. Minute := cd^.min;
  619. Second := cd^.sec;
  620. Sec100 := 0;
  621. Dispose(cd);
  622. END;
  623. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  624. Begin
  625. { !! }
  626. End;
  627. Procedure unpacktime(p : longint;var t : datetime);
  628. Begin
  629. AmigaToDt(p,t);
  630. End;
  631. Procedure packtime(var t : datetime;var p : longint);
  632. Begin
  633. p := DtToAmiga(t);
  634. end;
  635. {******************************************************************************
  636. --- Exec ---
  637. ******************************************************************************}
  638. Var
  639. LastDosExitCode: word;
  640. breakflag : Boolean;
  641. ver: Boolean;
  642. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  643. var
  644. p : string;
  645. buf: array[0..255] of char;
  646. result : longint;
  647. MyLock : longint;
  648. Begin
  649. DosError := 0;
  650. LastdosExitCode := 0;
  651. p:=Path+' '+ComLine;
  652. Move(p[1],buf,length(p));
  653. buf[Length(p)]:=#0;
  654. { Here we must first check if the command we wish to execute }
  655. { actually exists, because this is NOT handled by the }
  656. { _SystemTagList call (program will abort!!) }
  657. { Try to open with shared lock }
  658. MyLock:=Lock(path,-2);
  659. if MyLock <> 0 then
  660. Begin
  661. { File exists - therefore unlock it }
  662. Unlock(MyLock);
  663. result:=_Execute(buf);
  664. { on return of -1 the shell could not be executed }
  665. { probably because there was not enough memory }
  666. if result = -1 then
  667. DosError:=8
  668. else
  669. LastDosExitCode:=word(result);
  670. end
  671. else
  672. DosError:=3;
  673. End;
  674. Function DosExitCode: Word;
  675. Begin
  676. DosExitCode:=LastdosExitCode;
  677. End;
  678. Procedure GetCBreak(Var BreakValue: Boolean);
  679. Begin
  680. { Not implemented for Linux, but set to true as a precaution. }
  681. breakvalue:=breakflag;
  682. End;
  683. Procedure SetCBreak(BreakValue: Boolean);
  684. Begin
  685. breakflag:=BreakValue;
  686. { ! No Linux equivalent ! }
  687. End;
  688. Procedure GetVerify(Var Verify: Boolean);
  689. Begin
  690. verify:=ver;
  691. End;
  692. Procedure SetVerify(Verify: Boolean);
  693. Begin
  694. ver:=Verify;
  695. End;
  696. {******************************************************************************
  697. --- Disk ---
  698. ******************************************************************************}
  699. { How to solve the problem with this: }
  700. { We could walk through the device list }
  701. { at startup to determine possible devices }
  702. Function DiskFree(Drive: Byte): Longint;
  703. Var
  704. MyLock : BPTR;
  705. Inf : pInfoData;
  706. Free : Longint;
  707. Begin
  708. Free := -1;
  709. New(Inf);
  710. MyLock := Lock(devicenames[deviceids(Drive)],-2);
  711. If MyLock <> 0 then begin
  712. if Info(MyLock,Inf) then begin
  713. Free := (Inf^.id_NumBlocks * Inf^.id_BytesPerBlock) -
  714. (Inf^.id_NumBlocksUsed * Inf^.id_BytesPerBlock);
  715. end;
  716. Unlock(MyLock);
  717. end;
  718. Dispose(Inf);
  719. diskfree := Free;
  720. end;
  721. Function DiskSize(Drive: Byte): Longint;
  722. Var
  723. MyLock : BPTR;
  724. Inf : pInfoData;
  725. Size : Longint;
  726. Begin
  727. Size := -1;
  728. New(Inf);
  729. MyLock := Lock(devicenames[deviceids(Drive)],-2);
  730. If MyLock <> 0 then begin
  731. if Info(MyLock,Inf) then begin
  732. Size := (Inf^.id_NumBlocks * Inf^.id_BytesPerBlock);
  733. end;
  734. Unlock(MyLock);
  735. end;
  736. Dispose(Inf);
  737. disksize := Size;
  738. end;
  739. Procedure FindFirst(Path: PathStr; Attr: Word; Var f: SearchRec);
  740. var
  741. buf: Array[0..255] of char;
  742. Anchor : pAnchorPath;
  743. Result : Longint;
  744. index : Integer;
  745. Begin
  746. DosError:=0;
  747. New(Anchor);
  748. {----- allow backslash as slash -----}
  749. for index:=0 to length(path) do
  750. if path[index]='\' then path[index]:='/';
  751. {----- replace * by #? AmigaOs strings -----}
  752. repeat
  753. index:= pos('*',Path);
  754. if index <> 0 then
  755. Begin
  756. delete(Path,index,1);
  757. insert('#?',Path,index);
  758. end;
  759. until index =0;
  760. {--------------------------------------------}
  761. FillChar(Anchor^,sizeof(TAnchorPath),#0);
  762. move(path[1],buf,length(path));
  763. buf[length(path)]:=#0;
  764. Result:=MatchFirst(@buf,Anchor);
  765. f.AnchorPtr:=Anchor;
  766. if Result = ERROR_NO_MORE_ENTRIES then
  767. DosError:=18
  768. else
  769. if Result <> 0 then
  770. DosError:=3;
  771. { If there is an error, deallocate }
  772. { the anchorpath structure }
  773. if DosError <> 0 then
  774. Begin
  775. MatchEnd(Anchor);
  776. if assigned(Anchor) then
  777. Dispose(Anchor);
  778. end
  779. else
  780. {-------------------------------------------------------------------}
  781. { Here we fill up the SearchRec attribute, but we also do check }
  782. { something else, if the it does not match the mask we are looking }
  783. { for we should go to the next file or directory. }
  784. {-------------------------------------------------------------------}
  785. Begin
  786. with Anchor^.ap_Info do
  787. Begin
  788. f.Time := fib_Date.ds_Days * (24 * 60 * 60) +
  789. fib_Date.ds_Minute * 60 +
  790. fib_Date.ds_Tick div 50;
  791. {*------------------------------------*}
  792. {* Determine if is a file or a folder *}
  793. {*------------------------------------*}
  794. if fib_DirEntryType > 0 then
  795. f.attr:=f.attr OR DIRECTORY;
  796. {*------------------------------------*}
  797. {* Determine if Read only *}
  798. {* Readonly if R flag on and W flag *}
  799. {* off. *}
  800. {* Should we check also that EXEC *}
  801. {* is zero? for read only? *}
  802. {*------------------------------------*}
  803. if ((fib_Protection and FIBF_READ) <> 0)
  804. AND ((fib_Protection and FIBF_WRITE) = 0)
  805. then
  806. f.attr:=f.attr or READONLY;
  807. f.Name := strpas(fib_FileName);
  808. f.Size := fib_Size;
  809. end; { end with }
  810. end;
  811. End;
  812. Procedure FindNext(Var f: SearchRec);
  813. var
  814. Result: longint;
  815. Anchor : pAnchorPath;
  816. Begin
  817. DosError:=0;
  818. Result:=MatchNext(f.AnchorPtr);
  819. if Result = ERROR_NO_MORE_ENTRIES then
  820. DosError:=18
  821. else
  822. if Result <> 0 then
  823. DosError:=3;
  824. { If there is an error, deallocate }
  825. { the anchorpath structure }
  826. if DosError <> 0 then
  827. Begin
  828. MatchEnd(f.AnchorPtr);
  829. if assigned(f.AnchorPtr) then
  830. Dispose(f.AnchorPtr);
  831. end
  832. else
  833. { Fill up the Searchrec information }
  834. { and also check if the files are with }
  835. { the correct attributes }
  836. Begin
  837. Anchor:=pAnchorPath(f.AnchorPtr);
  838. with Anchor^.ap_Info do
  839. Begin
  840. f.Time := fib_Date.ds_Days * (24 * 60 * 60) +
  841. fib_Date.ds_Minute * 60 +
  842. fib_Date.ds_Tick div 50;
  843. {*------------------------------------*}
  844. {* Determine if is a file or a folder *}
  845. {*------------------------------------*}
  846. if fib_DirEntryType > 0 then
  847. f.attr:=f.attr OR DIRECTORY;
  848. {*------------------------------------*}
  849. {* Determine if Read only *}
  850. {* Readonly if R flag on and W flag *}
  851. {* off. *}
  852. {* Should we check also that EXEC *}
  853. {* is zero? for read only? *}
  854. {*------------------------------------*}
  855. if ((fib_Protection and FIBF_READ) <> 0)
  856. AND ((fib_Protection and FIBF_WRITE) = 0)
  857. then
  858. f.attr:=f.attr or READONLY;
  859. f.Name := strpas(fib_FileName);
  860. f.Size := fib_Size;
  861. end; { end with }
  862. end;
  863. End;
  864. Procedure FindClose(Var f: SearchRec);
  865. begin
  866. end;
  867. {******************************************************************************
  868. --- File ---
  869. ******************************************************************************}
  870. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  871. var
  872. I: Word;
  873. begin
  874. { allow backslash as slash }
  875. for i:=1 to length(path) do
  876. if path[i]='\' then path[i]:='/';
  877. I := Length(Path);
  878. while (I > 0) and not ((Path[I] = '/') or (Path[I] = ':'))
  879. do Dec(I);
  880. if Path[I] = '/' then
  881. dir := Copy(Path, 0, I-1)
  882. else dir := Copy(Path,0,I);
  883. if Length(Path) > Length(dir) then
  884. name := Copy(Path, I + 1, Length(Path)-I)
  885. else
  886. name := '';
  887. { Remove extension }
  888. if pos('.',name) <> 0 then
  889. delete(name,pos('.',name),length(name));
  890. I := Pos('.',Path);
  891. if I > 0 then
  892. ext := Copy(Path,I,Length(Path)-(I-1))
  893. else ext := '';
  894. end;
  895. Function FExpand(Path: PathStr): PathStr;
  896. var
  897. FLock : BPTR;
  898. buffer : array[0..255] of char;
  899. i :integer;
  900. begin
  901. { allow backslash as slash }
  902. for i:=1 to length(path) do
  903. if path[i]='\' then path[i]:='/';
  904. FLock := Lock(Path,-2);
  905. if FLock <> 0 then begin
  906. if NameFromLock(FLock,buffer,255) then begin
  907. Unlock(FLock);
  908. FExpand := strpas(buffer);
  909. end else begin
  910. Unlock(FLock);
  911. FExpand := '';
  912. end;
  913. end else FExpand := '';
  914. end;
  915. Function fsearch(path : pathstr;dirlist : string) : pathstr;
  916. var
  917. i,p1 : longint;
  918. s : searchrec;
  919. newdir : pathstr;
  920. begin
  921. { No wildcards allowed in these things }
  922. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  923. fsearch:=''
  924. else
  925. begin
  926. { allow slash as backslash }
  927. for i:=1 to length(dirlist) do
  928. if dirlist[i]='\' then dirlist[i]:='/';
  929. repeat
  930. p1:=pos(';',dirlist);
  931. if p1=0 then
  932. begin
  933. newdir:=copy(dirlist,1,p1-1);
  934. delete(dirlist,1,p1);
  935. end
  936. else
  937. begin
  938. newdir:=dirlist;
  939. dirlist:='';
  940. end;
  941. if (newdir<>'') and (not (newdir[length(newdir)] in ['/',':'])) then
  942. newdir:=newdir+'/';
  943. findfirst(newdir+path,anyfile,s);
  944. if doserror=0 then
  945. newdir:=newdir+path
  946. else
  947. newdir:='';
  948. until (dirlist='') or (newdir<>'');
  949. fsearch:=newdir;
  950. end;
  951. end;
  952. Procedure getftime (var f; var time : longint);
  953. {
  954. This function returns a file's date and time as the number of
  955. seconds after January 1, 1978 that the file was created.
  956. }
  957. var
  958. FInfo : pFileInfoBlock;
  959. FTime : Longint;
  960. FLock : Longint;
  961. begin
  962. DosError:=0;
  963. FTime := 0;
  964. FLock := Lock(StrPas(filerec(f).name), -2);
  965. IF FLock <> 0 then begin
  966. New(FInfo);
  967. if Examine(FLock, FInfo) then begin
  968. with FInfo^.fib_Date do
  969. FTime := ds_Days * (24 * 60 * 60) +
  970. ds_Minute * 60 +
  971. ds_Tick div 50;
  972. end else begin
  973. FTime := 0;
  974. end;
  975. Unlock(FLock);
  976. Dispose(FInfo);
  977. end
  978. else
  979. DosError:=6;
  980. time := FTime;
  981. end;
  982. Procedure setftime(var f; time : longint);
  983. var
  984. ClockData: pClockData;
  985. Begin
  986. DosError:=0;
  987. New(ClockData);
  988. (* { We must find the number of days since jan-1978 }
  989. ds_Days:=Time div 3600;
  990. ds_Minute:=Time mod 3600;
  991. ds_Tick:=
  992. Amiga2Date(Time, ClockData);
  993. ds_Days : Longint; { Number of days since Jan. 1, 1978 }
  994. ds_Minute : Longint; { Number of minutes past midnight }
  995. ds_Tick : Longint; { Number of ticks past minute }*)
  996. Dispose(ClockData);
  997. End;
  998. Procedure getfattr(var f; var attr : word);
  999. var
  1000. info : pFileInfoBlock;
  1001. MyLock : Longint;
  1002. flags: word;
  1003. Begin
  1004. DosError:=0;
  1005. flags:=0;
  1006. New(info);
  1007. { open with shared lock }
  1008. MyLock:=Lock(StrPas(filerec(f).name),-2);
  1009. if MyLock <> 0 then
  1010. Begin
  1011. Examine(MyLock,info);
  1012. {*------------------------------------*}
  1013. {* Determine if is a file or a folder *}
  1014. {*------------------------------------*}
  1015. if info^.fib_DirEntryType > 0 then
  1016. flags:=flags OR DIRECTORY;
  1017. {*------------------------------------*}
  1018. {* Determine if Read only *}
  1019. {* Readonly if R flag on and W flag *}
  1020. {* off. *}
  1021. {* Should we check also that EXEC *}
  1022. {* is zero? for read only? *}
  1023. {*------------------------------------*}
  1024. if ((info^.fib_Protection and FIBF_READ) <> 0)
  1025. AND ((info^.fib_Protection and FIBF_WRITE) = 0)
  1026. then
  1027. flags:=flags OR ReadOnly;
  1028. Unlock(mylock);
  1029. end
  1030. else
  1031. DosError:=3;
  1032. attr:=flags;
  1033. Dispose(info);
  1034. End;
  1035. Procedure setfattr (var f;attr : word);
  1036. var
  1037. flags: longint;
  1038. MyLock : longint;
  1039. Begin
  1040. DosError:=0;
  1041. flags:=FIBF_WRITE;
  1042. { open with shared lock }
  1043. MyLock:=Lock(StrPas(filerec(f).name),-2);
  1044. { By default files are read-write }
  1045. if attr AND ReadOnly <> 0 then
  1046. { Clear the Fibf_write flags }
  1047. flags:=FIBF_READ;
  1048. if MyLock <> 0 then
  1049. Begin
  1050. Unlock(MyLock);
  1051. if SetProtection(StrPas(filerec(f).name),flags) = 0 then
  1052. DosError:=5;
  1053. end
  1054. else
  1055. DosError:=3;
  1056. End;
  1057. {******************************************************************************
  1058. --- Environment ---
  1059. ******************************************************************************}
  1060. Function EnvCount: Longint;
  1061. { HOW TO GET THIS VALUE: }
  1062. { Each time this function is called, we look at the }
  1063. { local variables in the Process structure (2.0+) }
  1064. { And we also read all files in the ENV: directory }
  1065. Begin
  1066. End;
  1067. Function EnvStr(Index: Integer): String;
  1068. Begin
  1069. EnvStr:='';
  1070. End;
  1071. function GetEnv(envvar : String): String;
  1072. var
  1073. buffer : Pchar;
  1074. bufarr : array[0..500] of char;
  1075. strbuffer : array[0..255] of char;
  1076. temp : Longint;
  1077. begin
  1078. move(envvar[1],strbuffer,length(envvar));
  1079. strbuffer[length(envvar)] := #0;
  1080. buffer := @bufarr;
  1081. temp := GetVar(strbuffer,buffer,500,$100);
  1082. if temp = -1 then
  1083. GetEnv := ''
  1084. else GetEnv := StrPas(buffer);
  1085. end;
  1086. {******************************************************************************
  1087. --- Not Supported ---
  1088. ******************************************************************************}
  1089. Procedure keep(exitcode : word);
  1090. Begin
  1091. { ! Not implemented in Linux ! }
  1092. End;
  1093. Begin
  1094. DosError:=0;
  1095. ver:=TRUE;
  1096. breakflag:=TRUE;
  1097. End.
  1098. {
  1099. $Log$
  1100. Revision 1.4 1998-07-21 12:08:06 carl
  1101. * FExpand bugfix was returning a pchar!
  1102. }