syslinux.pp 17 KB

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