syslinux.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member 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. { These things are set in the makefile, }
  13. { But you can override them here.}
  14. { If you want to link to the C library, set the conditional crtlib }
  15. { $define crtlib}
  16. { If you use an aout system, set the conditional AOUT}
  17. { $Define AOUT}
  18. Unit SysLinux;
  19. Interface
  20. {$ifdef m68k}
  21. { used for single computations }
  22. const
  23. BIAS4 = $7f-1;
  24. {$endif}
  25. {$I systemh.inc}
  26. {$I heaph.inc}
  27. const
  28. UnusedHandle = -1;
  29. StdInputHandle = 0;
  30. StdOutputHandle = 1;
  31. StdErrorHandle = 2;
  32. var
  33. argc : longint;
  34. argv : ppchar;
  35. envp : ppchar;
  36. Implementation
  37. {$I system.inc}
  38. {$ifdef crtlib}
  39. Procedure _rtl_exit(l: longint); cdecl;
  40. Function _rtl_paramcount: longint; cdecl;
  41. Procedure _rtl_paramstr(st: pchar; l: longint); cdecl;
  42. Function _rtl_open(f: pchar; flags: longint): longint; cdecl;
  43. Procedure _rtl_close(h: longint); cdecl;
  44. Procedure _rtl_write(h: longint; addr: longInt; len : longint); cdecl;
  45. Procedure _rtl_erase(p: pchar); cdecl;
  46. Procedure _rtl_rename(p1: pchar; p2 : pchar); cdecl;
  47. Function _rtl_read(h: longInt; addr: longInt; len : longint) : longint; cdecl;
  48. Function _rtl_filepos(Handle: longint): longint; cdecl;
  49. Procedure _rtl_seek(Handle: longint; pos:longint); cdecl;
  50. Function _rtl_filesize(Handle:longint): longInt; cdecl;
  51. Procedure _rtl_rmdir(buffer: pchar); cdecl;
  52. Procedure _rtl_mkdir(buffer: pchar); cdecl;
  53. Procedure _rtl_chdir(buffer: pchar); cdecl;
  54. {$else}
  55. { used in syscall to report errors.}
  56. var
  57. Errno : longint;
  58. { Include constant and type definitions }
  59. {$i errno.inc } { Error numbers }
  60. {$i sysnr.inc } { System call numbers }
  61. {$i sysconst.inc } { Miscellaneous constants }
  62. {$i systypes.inc } { Types needed for system calls }
  63. { Read actual system call definitions. }
  64. {$i syscalls.inc }
  65. {$endif}
  66. {*****************************************************************************
  67. Misc. System Dependent Functions
  68. *****************************************************************************}
  69. procedure prthaltproc;external name '_haltproc';
  70. procedure System_exit;
  71. begin
  72. {$ifdef i386}
  73. asm
  74. jmp prthaltproc
  75. end;
  76. {$else}
  77. asm
  78. jmp prthaltproc
  79. end;
  80. {$endif}
  81. End;
  82. Function ParamCount: Longint;
  83. Begin
  84. Paramcount:=argc-1
  85. End;
  86. Function ParamStr(l: Longint): String;
  87. var
  88. link,
  89. hs : string;
  90. i : longint;
  91. begin
  92. if l=0 then
  93. begin
  94. str(sys_getpid,hs);
  95. hs:='/proc/'+hs+'/exe'#0;
  96. i:=Sys_readlink(@hs[1],@link[1],high(link));
  97. if i>0 then
  98. begin
  99. link[0]:=chr(i);
  100. paramstr:=link;
  101. end
  102. else
  103. paramstr:=strpas(argv[0]);
  104. end
  105. else
  106. if (l>0) and (l<argc) then
  107. paramstr:=strpas(argv[l])
  108. else
  109. paramstr:='';
  110. end;
  111. Procedure Randomize;
  112. Begin
  113. randseed:=sys_time;
  114. End;
  115. {*****************************************************************************
  116. Heap Management
  117. *****************************************************************************}
  118. var
  119. _HEAP : longint;external name 'HEAP';
  120. _HEAPSIZE : longint;external name 'HEAPSIZE';
  121. function getheapstart:pointer;assembler;
  122. {$ifdef i386}
  123. asm
  124. leal _HEAP,%eax
  125. end ['EAX'];
  126. {$else}
  127. asm
  128. lea.l _HEAP,a0
  129. move.l a0,d0
  130. end;
  131. {$endif}
  132. function getheapsize:longint;assembler;
  133. {$ifdef i386}
  134. asm
  135. movl _HEAPSIZE,%eax
  136. end ['EAX'];
  137. {$else}
  138. asm
  139. move.l _HEAPSIZE,d0
  140. end ['D0'];
  141. {$endif}
  142. Function sbrk(size : longint) : Longint;
  143. type
  144. tmmapargs=packed record
  145. address : longint;
  146. size : longint;
  147. prot : longint;
  148. flags : longint;
  149. fd : longint;
  150. offset : longint;
  151. end;
  152. var
  153. t : syscallregs;
  154. mmapargs : tmmapargs;
  155. begin
  156. mmapargs.address:=0;
  157. mmapargs.size:=Size;
  158. mmapargs.prot:=3;
  159. mmapargs.flags:=$22;
  160. mmapargs.fd:=-1;
  161. mmapargs.offset:=0;
  162. t.reg2:=longint(@mmapargs);
  163. Sbrk:=syscall(syscall_nr_mmap,t);
  164. if ErrNo<>0 then
  165. Sbrk:=0;
  166. end;
  167. { include standard heap management }
  168. {$I heap.inc}
  169. {*****************************************************************************
  170. Low Level File Routines
  171. *****************************************************************************}
  172. {
  173. The lowlevel file functions should take care of setting the InOutRes to the
  174. correct value if an error has occured, else leave it untouched
  175. }
  176. Procedure Errno2Inoutres;
  177. {
  178. Convert ErrNo error to the correct Inoutres value
  179. }
  180. begin
  181. if ErrNo=0 then { Else it will go through all the cases }
  182. exit;
  183. case ErrNo of
  184. Sys_ENFILE,
  185. Sys_EMFILE : Inoutres:=4;
  186. Sys_ENOENT : Inoutres:=2;
  187. Sys_EBADF : Inoutres:=6;
  188. Sys_ENOMEM,
  189. Sys_EFAULT : Inoutres:=217;
  190. Sys_EINVAL : Inoutres:=218;
  191. Sys_EPIPE,
  192. Sys_EINTR,
  193. Sys_EIO,
  194. Sys_EAGAIN,
  195. Sys_ENOSPC : Inoutres:=101;
  196. Sys_ENAMETOOLONG,
  197. Sys_ELOOP,
  198. Sys_ENOTDIR : Inoutres:=3;
  199. Sys_EROFS,
  200. Sys_EEXIST,
  201. Sys_EACCES : Inoutres:=5;
  202. Sys_ETXTBSY : Inoutres:=162;
  203. end;
  204. end;
  205. Procedure Do_Close(Handle:Longint);
  206. Begin
  207. {$ifdef crtlib}
  208. _rtl_close(Handle);
  209. {$else}
  210. sys_close(Handle);
  211. {$endif}
  212. End;
  213. Procedure Do_Erase(p:pchar);
  214. Begin
  215. {$ifdef crtlib}
  216. _rtl_erase(p);
  217. {$else}
  218. sys_unlink(p);
  219. Errno2Inoutres;
  220. {$endif}
  221. End;
  222. Procedure Do_Rename(p1,p2:pchar);
  223. Begin
  224. {$ifdef crtlib}
  225. _rtl_rename(p1,p2);
  226. {$else }
  227. sys_rename(p1,p2);
  228. Errno2Inoutres;
  229. {$endif}
  230. End;
  231. Function Do_Write(Handle,Addr,Len:Longint):longint;
  232. Begin
  233. {$ifdef crtlib}
  234. _rtl_write(Handle,addr,len);
  235. Do_Write:=Len;
  236. {$else}
  237. Do_Write:=sys_write(Handle,pchar(addr),len);
  238. Errno2Inoutres;
  239. {$endif}
  240. if Do_Write<0 then
  241. Do_Write:=0;
  242. End;
  243. Function Do_Read(Handle,Addr,Len:Longint):Longint;
  244. Begin
  245. {$ifdef crtlib}
  246. Do_Read:=_rtl_read(Handle,addr,len);
  247. {$else}
  248. Do_Read:=sys_read(Handle,pchar(addr),len);
  249. Errno2Inoutres;
  250. {$endif}
  251. if Do_Read<0 then
  252. Do_Read:=0;
  253. End;
  254. Function Do_FilePos(Handle: Longint): Longint;
  255. Begin
  256. {$ifdef crtlib}
  257. Do_FilePos:=_rtl_filepos(Handle);
  258. {$else}
  259. Do_FilePos:=sys_lseek(Handle, 0, Seek_Cur);
  260. Errno2Inoutres;
  261. {$endif}
  262. End;
  263. Procedure Do_Seek(Handle,Pos:Longint);
  264. Begin
  265. {$ifdef crtlib}
  266. _rtl_seek(Handle, Pos);
  267. {$else}
  268. sys_lseek(Handle, pos, Seek_set);
  269. {$endif}
  270. End;
  271. Function Do_SeekEnd(Handle:Longint): Longint;
  272. begin
  273. {$ifdef crtlib}
  274. Do_SeekEnd:=_rtl_filesize(Handle);
  275. {$else}
  276. Do_SeekEnd:=sys_lseek(Handle,0,Seek_End);
  277. {$endif}
  278. end;
  279. Function Do_FileSize(Handle:Longint): Longint;
  280. {$ifndef crtlib}
  281. var
  282. regs : Syscallregs;
  283. Info : Stat;
  284. {$endif}
  285. Begin
  286. {$ifdef crtlib}
  287. Do_FileSize:=_rtl_filesize(Handle);
  288. {$else}
  289. regs.reg2:=Handle;
  290. regs.reg3:=longint(@Info);
  291. if SysCall(SysCall_nr_fstat,regs)=0 then
  292. Do_FileSize:=Info.Size
  293. else
  294. Do_FileSize:=0;
  295. Errno2Inoutres;
  296. {$endif}
  297. End;
  298. Procedure Do_Truncate(Handle,Pos:longint);
  299. {$ifndef crtlib}
  300. var
  301. sr : syscallregs;
  302. {$endif}
  303. begin
  304. {$ifndef crtlib}
  305. sr.reg2:=Handle;
  306. sr.reg3:=Pos;
  307. syscall(syscall_nr_ftruncate,sr);
  308. Errno2Inoutres;
  309. {$endif}
  310. end;
  311. Procedure Do_Open(var f;p:pchar;flags:longint);
  312. {
  313. FileRec and textrec have both Handle and mode as the first items so
  314. they could use the same routine for opening/creating.
  315. when (flags and $100) the file will be append
  316. when (flags and $1000) the file will be truncate/rewritten
  317. when (flags and $10000) there is no check for close (needed for textfiles)
  318. }
  319. var
  320. {$ifndef crtlib}
  321. oflags : longint;
  322. {$endif}
  323. Begin
  324. { close first if opened }
  325. if ((flags and $10000)=0) then
  326. begin
  327. case FileRec(f).mode of
  328. fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
  329. fmclosed : ;
  330. else
  331. begin
  332. inoutres:=102; {not assigned}
  333. exit;
  334. end;
  335. end;
  336. end;
  337. { reset file Handle }
  338. FileRec(f).Handle:=UnusedHandle;
  339. { We do the conversion of filemodes here, concentrated on 1 place }
  340. case (flags and 3) of
  341. 0 : begin
  342. oflags :=Open_RDONLY;
  343. FileRec(f).mode:=fminput;
  344. end;
  345. 1 : begin
  346. oflags :=Open_WRONLY;
  347. FileRec(f).mode:=fmoutput;
  348. end;
  349. 2 : begin
  350. oflags :=Open_RDWR;
  351. FileRec(f).mode:=fminout;
  352. end;
  353. end;
  354. if (flags and $1000)=$1000 then
  355. oflags:=oflags or (Open_CREAT or Open_TRUNC)
  356. else
  357. if (flags and $100)=$100 then
  358. oflags:=oflags or (Open_APPEND);
  359. { empty name is special }
  360. if p[0]=#0 then
  361. begin
  362. case FileRec(f).mode of
  363. fminput :
  364. FileRec(f).Handle:=StdInputHandle;
  365. fminout, { this is set by rewrite }
  366. fmoutput :
  367. FileRec(f).Handle:=StdOutputHandle;
  368. fmappend :
  369. begin
  370. FileRec(f).Handle:=StdOutputHandle;
  371. FileRec(f).mode:=fmoutput; {fool fmappend}
  372. end;
  373. end;
  374. exit;
  375. end;
  376. { real open call }
  377. {$ifdef crtlib}
  378. FileRec(f).Handle:=_rtl_open(p, oflags);
  379. if FileRec(f).Handle<0 then
  380. InOutRes:=2
  381. else
  382. InOutRes:=0;
  383. {$else}
  384. FileRec(f).Handle:=sys_open(p,oflags,438);
  385. if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
  386. begin
  387. Oflags:=Oflags and not(Open_RDWR);
  388. FileRec(f).Handle:=sys_open(p,oflags,438);
  389. end;
  390. Errno2Inoutres;
  391. {$endif}
  392. End;
  393. Function Do_IsDevice(Handle:Longint):boolean;
  394. {
  395. Interface to Unix ioctl call.
  396. Performs various operations on the filedescriptor Handle.
  397. Ndx describes the operation to perform.
  398. Data points to data needed for the Ndx function. The structure of this
  399. data is function-dependent.
  400. }
  401. var
  402. sr: SysCallRegs;
  403. Data : array[0..255] of byte; {Large enough for termios info}
  404. begin
  405. sr.reg2:=Handle;
  406. sr.reg3:=$5401; {=TCGETS}
  407. sr.reg4:=Longint(@Data);
  408. Do_IsDevice:=(SysCall(Syscall_nr_ioctl,sr)=0);
  409. end;
  410. {*****************************************************************************
  411. UnTyped File Handling
  412. *****************************************************************************}
  413. {$i file.inc}
  414. {*****************************************************************************
  415. Typed File Handling
  416. *****************************************************************************}
  417. {$i typefile.inc}
  418. {*****************************************************************************
  419. Text File Handling
  420. *****************************************************************************}
  421. {$DEFINE SHORT_LINEBREAK}
  422. {$DEFINE EXTENDED_EOF}
  423. {$i text.inc}
  424. {*****************************************************************************
  425. Directory Handling
  426. *****************************************************************************}
  427. Procedure MkDir(Const s: String);[IOCheck];
  428. Var
  429. Buffer: Array[0..255] of Char;
  430. Begin
  431. If InOutRes <> 0 then exit;
  432. Move(s[1], Buffer, Length(s));
  433. Buffer[Length(s)] := #0;
  434. {$ifdef crtlib}
  435. _rtl_mkdir(@buffer);
  436. {$else}
  437. sys_mkdir(@buffer, 511);
  438. Errno2Inoutres;
  439. {$endif}
  440. End;
  441. Procedure RmDir(Const s: String);[IOCheck];
  442. Var
  443. Buffer: Array[0..255] of Char;
  444. Begin
  445. If InOutRes <> 0 then exit;
  446. Move(s[1], Buffer, Length(s));
  447. Buffer[Length(s)] := #0;
  448. {$ifdef crtlib}
  449. _rtl_rmdir(@buffer);
  450. {$else}
  451. sys_rmdir(@buffer);
  452. Errno2Inoutres;
  453. {$endif}
  454. End;
  455. Procedure ChDir(Const s: String);[IOCheck];
  456. Var
  457. Buffer: Array[0..255] of Char;
  458. Begin
  459. If InOutRes <> 0 then exit;
  460. Move(s[1], Buffer, Length(s));
  461. Buffer[Length(s)] := #0;
  462. {$ifdef crtlib}
  463. _rtl_chdir(@buffer);
  464. {$else}
  465. sys_chdir(@buffer);
  466. Errno2Inoutres;
  467. {$endif}
  468. End;
  469. procedure getdir(drivenr : byte;var dir : shortstring);
  470. {$ifndef crtlib}
  471. var
  472. thisdir : stat;
  473. rootino,
  474. thisino,
  475. dotdotino : longint;
  476. rootdev,
  477. thisdev,
  478. dotdotdev : word;
  479. thedir,dummy : string[255];
  480. dirstream : pdir;
  481. d : pdirent;
  482. mountpoint,validdir : boolean;
  483. predot : string[255];
  484. {$endif}
  485. begin
  486. drivenr:=0;
  487. dir:='';
  488. {$ifndef crtlib}
  489. thedir:='/'#0;
  490. if sys_stat(@thedir[1],thisdir)<0 then
  491. exit;
  492. rootino:=thisdir.ino;
  493. rootdev:=thisdir.dev;
  494. thedir:='.'#0;
  495. if sys_stat(@thedir[1],thisdir)<0 then
  496. exit;
  497. thisino:=thisdir.ino;
  498. thisdev:=thisdir.dev;
  499. { Now we can uniquely identify the current and root dir }
  500. thedir:='';
  501. predot:='';
  502. while not ((thisino=rootino) and (thisdev=rootdev)) do
  503. begin
  504. { Are we on a mount point ? }
  505. dummy:=predot+'..'#0;
  506. if sys_stat(@dummy[1],thisdir)<0 then
  507. exit;
  508. dotdotino:=thisdir.ino;
  509. dotdotdev:=thisdir.dev;
  510. mountpoint:=(thisdev<>dotdotdev);
  511. { Now, Try to find the name of this dir in the previous one }
  512. dirstream:=opendir (@dummy[1]);
  513. if dirstream=nil then
  514. exit;
  515. repeat
  516. d:=sys_readdir (dirstream);
  517. validdir:=false;
  518. if (d<>nil) and
  519. (not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.') and (
  520. d^.name[2]=#0))))) and
  521. (mountpoint or (d^.ino=thisino)) then
  522. begin
  523. dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
  524. validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
  525. end
  526. else
  527. validdir:=false;
  528. until (d=nil) or
  529. ((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
  530. if (closedir(dirstream)<0) or (d=nil) then
  531. exit;
  532. { At this point, d.name contains the name of the current dir}
  533. thedir:='/'+strpas(@(d^.name[0]))+thedir;
  534. thisdev:=dotdotdev;
  535. thisino:=dotdotino;
  536. predot:=predot+'../';
  537. end;
  538. { Now rootino=thisino and rootdev=thisdev so we've reached / }
  539. dir:=thedir
  540. {$endif}
  541. end;
  542. {*****************************************************************************
  543. SystemUnit Initialization
  544. *****************************************************************************}
  545. {$ifdef I386}
  546. { this should be defined in i386 directory !! PM }
  547. const
  548. fpucw : word = $1332;
  549. FPU_Invalid = 1;
  550. FPU_Denormal = 2;
  551. FPU_DivisionByZero = 4;
  552. FPU_Overflow = 8;
  553. FPU_Underflow = $10;
  554. FPU_StackUnderflow = $20;
  555. FPU_StackOverflow = $40;
  556. {$endif I386}
  557. Procedure ResetFPU;
  558. begin
  559. {$ifdef I386}
  560. asm
  561. fninit
  562. fldcw fpucw
  563. end;
  564. {$endif I386}
  565. end;
  566. {$ifndef newSignal}
  567. Procedure SignalToRunError(Sig:longint);
  568. begin
  569. case sig of
  570. 8 : begin
  571. { this is not allways necessary but I don't know yet
  572. how to tell if it is or not PM }
  573. ResetFPU;
  574. HandleError(200);
  575. end;
  576. 11 : HandleError(216);
  577. end;
  578. end;
  579. Procedure InstallSignals;
  580. var
  581. sr : syscallregs;
  582. begin
  583. sr.reg3:=longint(@SignalToRunError);
  584. { sigsegv }
  585. sr.reg2:=11;
  586. syscall(syscall_nr_signal,sr);
  587. { sigfpe }
  588. sr.reg2:=8;
  589. syscall(syscall_nr_signal,sr);
  590. end;
  591. {$else newSignal}
  592. {$i i386/signal.inc}
  593. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
  594. var
  595. res,fpustate : word;
  596. begin
  597. case sig of
  598. 8 : begin
  599. { this is not allways necessary but I don't know yet
  600. how to tell if it is or not PM }
  601. {$ifdef I386}
  602. fpustate:=0;
  603. res:=200;
  604. if assigned(SigContext.fpstate) then
  605. fpuState:=SigContext.fpstate^.sw;
  606. {$ifdef SYSTEMDEBUG}
  607. Writeln(stderr,'FpuState = ',Hexstr(FpuState,4));
  608. {$endif SYSTEMDEBUG}
  609. if (FpuState and $7f) <> 0 then
  610. begin
  611. if (FpuState and FPU_Invalid)<>0 then
  612. res:=216
  613. else if (FpuState and FPU_Denormal)<>0 then
  614. res:=216
  615. else if (FpuState and FPU_DivisionByZero)<>0 then
  616. res:=200
  617. else if (FpuState and FPU_Overflow)<>0 then
  618. res:=205
  619. else if (FpuState and FPU_Underflow)<>0 then
  620. res:=206
  621. else
  622. res:=207; {'Coprocessor Error'}
  623. end;
  624. {$endif I386}
  625. ResetFPU;
  626. HandleError(res);
  627. end;
  628. 11 : HandleError(216);
  629. end;
  630. end;
  631. Procedure InstallSignals;
  632. const
  633. act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
  634. Sa_restorer: NIL);
  635. oldact: PSigActionRec = Nil;
  636. begin
  637. ResetFPU;
  638. SigAction(8,@act,oldact);
  639. SigAction(11,@act,oldact);
  640. end;
  641. {$endif newSignal}
  642. procedure SetupCmdLine;
  643. var
  644. bufsize,
  645. len,j,
  646. size,i : longint;
  647. found : boolean;
  648. buf : array[0..1026] of char;
  649. procedure AddBuf;
  650. begin
  651. reallocmem(cmdline,size+bufsize);
  652. move(buf,cmdline[size],bufsize);
  653. inc(size,bufsize);
  654. bufsize:=0;
  655. end;
  656. begin
  657. size:=0;
  658. bufsize:=0;
  659. i:=0;
  660. while (i<argc) do
  661. begin
  662. len:=strlen(argv[i]);
  663. if len>sizeof(buf)-2 then
  664. len:=sizeof(buf)-2;
  665. found:=false;
  666. for j:=1 to len do
  667. if argv[i][j]=' ' then
  668. begin
  669. found:=true;
  670. break;
  671. end;
  672. if bufsize+len>=sizeof(buf)-2 then
  673. AddBuf;
  674. if found then
  675. begin
  676. buf[bufsize]:='"';
  677. inc(bufsize);
  678. end;
  679. move(argv[i]^,buf[bufsize],len);
  680. inc(bufsize,len);
  681. if found then
  682. begin
  683. buf[bufsize]:='"';
  684. inc(bufsize);
  685. end;
  686. if i<argc then
  687. buf[bufsize]:=' '
  688. else
  689. buf[bufsize]:=#0;
  690. inc(bufsize);
  691. inc(i);
  692. end;
  693. AddBuf;
  694. end;
  695. Begin
  696. { Set up signals handlers }
  697. InstallSignals;
  698. { Setup heap }
  699. InitHeap;
  700. InitExceptions;
  701. { Arguments }
  702. SetupCmdLine;
  703. { Setup stdin, stdout and stderr }
  704. OpenStdIO(Input,fmInput,StdInputHandle);
  705. OpenStdIO(Output,fmOutput,StdOutputHandle);
  706. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  707. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  708. { Reset IO Error }
  709. InOutRes:=0;
  710. End.
  711. {
  712. $Log$
  713. Revision 1.42 2000-03-31 23:26:32 pierre
  714. * FPU needs reset for all SIGFPE even from integer division by zero
  715. Revision 1.41 2000/03/31 23:21:19 pierre
  716. * multiple exception handling works
  717. (for linux only if syslinux is compiled with -dnewsignal)
  718. Revision 1.40 2000/03/31 13:24:28 jonas
  719. * signal handling using sigaction when compiled with -dnewsignal
  720. (allows multiple signals to be received in one run)
  721. Revision 1.39 2000/03/25 12:28:37 peter
  722. * patch for getdir from Pierre
  723. Revision 1.38 2000/03/23 15:24:18 peter
  724. * remove handle check for do_close
  725. Revision 1.37 2000/02/09 16:59:32 peter
  726. * truncated log
  727. Revision 1.36 2000/02/09 12:17:51 peter
  728. * moved halt to system.inc
  729. * syslinux doesn't use direct asm anymore
  730. Revision 1.35 2000/02/08 11:47:09 peter
  731. * paramstr(0) support
  732. Revision 1.34 2000/01/20 23:38:02 peter
  733. * support fm_inout as stdoutput for assign(f,'');rewrite(f,1); becuase
  734. rewrite opens always with filemode 2
  735. Revision 1.33 2000/01/16 22:25:38 peter
  736. * check handle for file closing
  737. Revision 1.32 2000/01/07 16:41:41 daniel
  738. * copyright 2000
  739. Revision 1.31 2000/01/07 16:32:28 daniel
  740. * copyright 2000 added
  741. Revision 1.30 1999/12/01 22:57:31 peter
  742. * cmdline support
  743. Revision 1.29 1999/11/06 14:39:12 peter
  744. * truncated log
  745. Revision 1.28 1999/10/28 09:50:06 peter
  746. * use mmap instead of brk
  747. Revision 1.27 1999/09/10 15:40:35 peter
  748. * fixed do_open flags to be > $100, becuase filemode can be upto 255
  749. Revision 1.26 1999/09/08 16:14:43 peter
  750. * pointer fixes
  751. Revision 1.25 1999/07/28 23:18:36 peter
  752. * closedir fixes, which now disposes the pdir itself
  753. }