syslinux.pp 17 KB

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