syswin32.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by Florian Klaempfl and Pavel Ozerski
  5. member of the Free Pascal development team.
  6. FPC Pascal system unit for the Win32 API.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$S-}
  14. unit syswin32;
  15. {$I os.inc}
  16. {$DEFINE WINHEAP}
  17. interface
  18. { include system-independent routine headers }
  19. {$I systemh.inc}
  20. {$ifndef WinHeap}
  21. { include heap support headers }
  22. {$I heaph.inc}
  23. {$endif}
  24. const
  25. { Default filehandles }
  26. UnusedHandle : longint = -1;
  27. StdInputHandle : longint = 0;
  28. StdOutputHandle : longint = 0;
  29. StdErrorHandle : longint = 0;
  30. type
  31. TStartupInfo=packed record
  32. cb : longint;
  33. lpReserved : Pointer;
  34. lpDesktop : Pointer;
  35. lpTitle : Pointer;
  36. dwX : longint;
  37. dwY : longint;
  38. dwXSize : longint;
  39. dwYSize : longint;
  40. dwXCountChars : longint;
  41. dwYCountChars : longint;
  42. dwFillAttribute : longint;
  43. dwFlags : longint;
  44. wShowWindow : Word;
  45. cbReserved2 : Word;
  46. lpReserved2 : Pointer;
  47. hStdInput : longint;
  48. hStdOutput : longint;
  49. hStdError : longint;
  50. end;
  51. var
  52. { C compatible arguments }
  53. argc : longint;
  54. argv : ppchar;
  55. { Win32 Info }
  56. startupinfo : tstartupinfo;
  57. hprevinst,
  58. hinstance,
  59. cmdshow : longint;
  60. {$ifdef WinHeap}
  61. var
  62. heaperror : pointer;
  63. function HeapSize:longint;
  64. {$endif}
  65. implementation
  66. { include system independent routines }
  67. {$I system.inc}
  68. { some declarations for Win32 API calls }
  69. {$I win32.inc}
  70. CONST
  71. { These constants are used for conversion of error codes }
  72. { from win32 i/o errors to tp i/o errors }
  73. { errors 1 to 18 are the same as in Turbo Pascal }
  74. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! }
  75. { The media is write protected. }
  76. ERROR_WRITE_PROTECT = 19;
  77. { The system cannot find the device specified. }
  78. ERROR_BAD_UNIT = 20;
  79. { The device is not ready. }
  80. ERROR_NOT_READY = 21;
  81. { The device does not recognize the command. }
  82. ERROR_BAD_COMMAND = 22;
  83. { Data error (cyclic redundancy check) }
  84. ERROR_CRC = 23;
  85. { The program issued a command but the }
  86. { command length is incorrect. }
  87. ERROR_BAD_LENGTH = 24;
  88. { The drive cannot locate a specific }
  89. { area or track on the disk. }
  90. ERROR_SEEK = 25;
  91. { The specified disk or diskette cannot be accessed. }
  92. ERROR_NOT_DOS_DISK = 26;
  93. { The drive cannot find the sector requested. }
  94. ERROR_SECTOR_NOT_FOUND = 27;
  95. { The printer is out of paper. }
  96. ERROR_OUT_OF_PAPER = 28;
  97. { The system cannot write to the specified device. }
  98. ERROR_WRITE_FAULT = 29;
  99. { The system cannot read from the specified device. }
  100. ERROR_READ_FAULT = 30;
  101. { A device attached to the system is not functioning.}
  102. ERROR_GEN_FAILURE = 31;
  103. { The process cannot access the file because }
  104. { it is being used by another process. }
  105. ERROR_SHARING_VIOLATION = 32;
  106. var
  107. errno : longint;
  108. type
  109. plongint = ^longint;
  110. { misc. functions }
  111. function GetLastError : DWORD;
  112. external 'kernel32' name 'GetLastError';
  113. function MessageBox(w1:longint;l1,l2:pointer;w2:longint):longint;
  114. external 'user32' name 'MessageBoxA';
  115. { time and date functions }
  116. function GetTickCount : longint;
  117. external 'kernel32' name 'GetTickCount';
  118. { process functions }
  119. procedure ExitProcess(uExitCode : UINT);
  120. external 'kernel32' name 'ExitProcess';
  121. Procedure Errno2InOutRes;
  122. Begin
  123. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
  124. if (errno >= ERROR_WRITE_PROTECT) and (errno <= ERROR_GEN_FAILURE) THEN
  125. BEGIN
  126. { This is the offset to the Win32 to add to directly map }
  127. { to the DOS/TP compatible error codes when in this range }
  128. InOutRes := word(errno)+131;
  129. END
  130. else
  131. { This case is special }
  132. if errno=ERROR_SHARING_VIOLATION THEN
  133. BEGIN
  134. InOutRes :=5;
  135. END
  136. else
  137. { other error codes can directly be mapped }
  138. InOutRes := Word(errno);
  139. errno:=0;
  140. end;
  141. {$ifdef dummy}
  142. procedure int_stackcheck(stack_size:longint);[public,alias: 'STACKCHECK'];
  143. {
  144. called when trying to get local stack if the compiler directive $S
  145. is set this function must preserve esi !!!! because esi is set by
  146. the calling proc for methods it must preserve all registers !!
  147. With a 2048 byte safe area used to write to StdIo without crossing
  148. the stack boundary
  149. }
  150. begin
  151. asm
  152. pushl %eax
  153. pushl %ebx
  154. movl stack_size,%ebx
  155. addl $2048,%ebx
  156. movl %esp,%eax
  157. subl %ebx,%eax
  158. movl stacklimit,%ebx
  159. cmpl %eax,%ebx
  160. jae __short_on_stack
  161. popl %ebx
  162. popl %eax
  163. leave
  164. ret $4
  165. __short_on_stack:
  166. { can be usefull for error recovery !! }
  167. popl %ebx
  168. popl %eax
  169. end['EAX','EBX'];
  170. RunError(202);
  171. end;
  172. {$endif dummy}
  173. procedure halt(errnum : byte);
  174. begin
  175. do_exit;
  176. ExitProcess(errnum);
  177. end;
  178. function paramcount : longint;
  179. begin
  180. paramcount := argc - 1;
  181. end;
  182. function paramstr(l : longint) : string;
  183. begin
  184. if (l>=0) and (l+1<=argc) then
  185. paramstr:=strpas(argv[l])
  186. else
  187. paramstr:='';
  188. end;
  189. procedure randomize;
  190. begin
  191. randseed:=GetTickCount;
  192. end;
  193. {*****************************************************************************
  194. Heap Management
  195. *****************************************************************************}
  196. {$ifdef WinHeap}
  197. {$i winheap.inc}
  198. {$else}
  199. { memory functions }
  200. function GlobalAlloc(mode,size:longint):longint;
  201. external 'kernel32' name 'GlobalAlloc';
  202. function GlobalReAlloc(mode,size:longint):longint;
  203. external 'kernel32' name 'GlobalReAlloc';
  204. function GlobalHandle(p:pointer):longint;
  205. external 'kernel32' name 'GlobalHandle';
  206. function GlobalLock(handle:longint):pointer;
  207. external 'kernel32' name 'GlobalLock';
  208. function GlobalUnlock(h:longint):longint;
  209. external 'kernel32' name 'GlobalUnlock';
  210. function GlobalFree(h:longint):longint;
  211. external 'kernel32' name 'GlobalFree';
  212. function GlobalSize(h:longint):longint;
  213. external 'kernel32' name 'GlobalSize';
  214. procedure GlobalMemoryStatus(p:pointer);
  215. external 'kernel32' name 'GlobalMemoryStatus';
  216. function LocalAlloc(uFlags : UINT;uBytes :UINT) : HLOCAL;
  217. external 'kernel32' name 'LocalAlloc';
  218. function LocalFree(hMem:HLOCAL):HLOCAL;
  219. external 'kernel32' name 'LocalFree';
  220. function Sbrk(size : longint):longint;
  221. var
  222. h,l : longint;
  223. begin
  224. h:=GlobalAlloc(258,size);
  225. GlobalLock(h);
  226. l:=GlobalSize(h);
  227. writeln(l);
  228. sbrk:=l;
  229. end;
  230. { include standard heap management }
  231. {$I heap.inc}
  232. {$endif WinHeap}
  233. {*****************************************************************************
  234. Low Level File Routines
  235. *****************************************************************************}
  236. function WriteFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  237. overlap:pointer):longint;
  238. external 'kernel32' name 'WriteFile';
  239. function ReadFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  240. overlap:pointer):longint;
  241. external 'kernel32' name 'ReadFile';
  242. function CloseHandle(h : longint) : longint;
  243. external 'kernel32' name 'CloseHandle';
  244. function DeleteFile(p : pchar) : longint;
  245. external 'kernel32' name 'DeleteFileA';
  246. function MoveFile(old,_new : pchar) : longint;
  247. external 'kernel32' name 'MoveFileA';
  248. function SetFilePointer(l1,l2 : longint;l3 : pointer;l4 : longint) : longint;
  249. external 'kernel32' name 'SetFilePointer';
  250. function GetFileSize(h:longint;p:pointer) : longint;
  251. external 'kernel32' name 'GetFileSize';
  252. function CreateFile(name : pointer;access,sharing : longint;
  253. security : pointer;how,attr,template : longint) : longint;
  254. external 'kernel32' name 'CreateFileA';
  255. function SetEndOfFile(h : longint) : boolean;
  256. external 'kernel32' name 'SetEndOfFile';
  257. function GetFileType(Handle:DWORD):DWord;
  258. external 'kernel32' name 'GetFileType';
  259. procedure AllowSlash(p:pchar);
  260. var
  261. i : longint;
  262. begin
  263. { allow slash as backslash }
  264. for i:=0 to strlen(p) do
  265. if p[i]='/' then p[i]:='\';
  266. end;
  267. procedure do_close(h : longint);
  268. begin
  269. closehandle(h);
  270. end;
  271. procedure do_erase(p : pchar);
  272. begin
  273. AllowSlash(p);
  274. if DeleteFile(p)=0 then
  275. Begin
  276. errno:=GetLastError;
  277. Errno2InoutRes;
  278. end;
  279. end;
  280. procedure do_rename(p1,p2 : pchar);
  281. begin
  282. AllowSlash(p1);
  283. AllowSlash(p2);
  284. if MoveFile(p1,p2)=0 then
  285. Begin
  286. errno:=GetLastError;
  287. Errno2InoutRes;
  288. end;
  289. end;
  290. function do_write(h,addr,len : longint) : longint;
  291. var
  292. size:longint;
  293. begin
  294. if writefile(h,pointer(addr),len,size,nil)=0 then
  295. Begin
  296. errno:=GetLastError;
  297. Errno2InoutRes;
  298. end;
  299. do_write:=size;
  300. end;
  301. function do_read(h,addr,len : longint) : longint;
  302. var
  303. result:longint;
  304. begin
  305. if readfile(h,pointer(addr),len,result,nil)=0 then
  306. Begin
  307. errno:=GetLastError;
  308. Errno2InoutRes;
  309. end;
  310. do_read:=result;
  311. end;
  312. function do_filepos(handle : longint) : longint;
  313. var
  314. l:longint;
  315. begin
  316. l:=SetFilePointer(handle,0,nil,FILE_CURRENT);
  317. if l=-1 then
  318. begin
  319. l:=0;
  320. errno:=GetLastError;
  321. Errno2InoutRes;
  322. end;
  323. do_filepos:=l;
  324. end;
  325. procedure do_seek(handle,pos : longint);
  326. begin
  327. if SetFilePointer(handle,pos,nil,FILE_BEGIN)=-1 then
  328. Begin
  329. errno:=GetLastError;
  330. Errno2InoutRes;
  331. end;
  332. end;
  333. function do_seekend(handle:longint):longint;
  334. begin
  335. do_seekend:=SetFilePointer(handle,0,nil,FILE_END);
  336. if do_seekend=-1 then
  337. begin
  338. errno:=GetLastError;
  339. Errno2InoutRes;
  340. end;
  341. end;
  342. function do_filesize(handle : longint) : longint;
  343. var
  344. aktfilepos : longint;
  345. begin
  346. aktfilepos:=do_filepos(handle);
  347. do_filesize:=do_seekend(handle);
  348. do_seek(handle,aktfilepos);
  349. end;
  350. procedure do_truncate (handle,pos:longint);
  351. begin
  352. do_seek(handle,pos);
  353. if not(SetEndOfFile(handle)) then
  354. begin
  355. errno:=GetLastError;
  356. Errno2InoutRes;
  357. end;
  358. end;
  359. procedure do_open(var f;p : pchar;flags:longint);
  360. {
  361. filerec and textrec have both handle and mode as the first items so
  362. they could use the same routine for opening/creating.
  363. when (flags and $10) the file will be append
  364. when (flags and $100) the file will be truncate/rewritten
  365. when (flags and $1000) there is no check for close (needed for textfiles)
  366. }
  367. var
  368. oflags,cd : longint;
  369. begin
  370. AllowSlash(p);
  371. { close first if opened }
  372. if ((flags and $1000)=0) then
  373. begin
  374. case filerec(f).mode of
  375. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  376. fmclosed : ;
  377. else
  378. begin
  379. {not assigned}
  380. inoutres:=102;
  381. exit;
  382. end;
  383. end;
  384. end;
  385. { reset file handle }
  386. filerec(f).handle:=UnusedHandle;
  387. { convert filemode to filerec modes }
  388. case (flags and 3) of
  389. 0 : begin
  390. filerec(f).mode:=fminput;
  391. oflags:=GENERIC_READ;
  392. end;
  393. 1 : begin
  394. filerec(f).mode:=fmoutput;
  395. oflags:=GENERIC_WRITE;
  396. end;
  397. 2 : begin
  398. filerec(f).mode:=fminout;
  399. oflags:=GENERIC_WRITE or GENERIC_READ;
  400. end;
  401. end;
  402. { standard is opening and existing file }
  403. cd:=OPEN_EXISTING;
  404. { create it ? }
  405. if (flags and $100)<>0 then
  406. cd:=CREATE_ALWAYS
  407. { or append ? }
  408. else
  409. if (flags and $10)<>0 then
  410. cd:=OPEN_ALWAYS;
  411. { empty name is special }
  412. if p[0]=#0 then
  413. begin
  414. case filerec(f).mode of
  415. fminput : filerec(f).handle:=StdInputHandle;
  416. fmappend,
  417. fmoutput : begin
  418. filerec(f).handle:=StdOutputHandle;
  419. filerec(f).mode:=fmoutput; {fool fmappend}
  420. end;
  421. end;
  422. exit;
  423. end;
  424. filerec(f).handle:=CreateFile(p,oflags,0,nil,cd,FILE_ATTRIBUTE_NORMAL,0);
  425. { append mode }
  426. if (flags and $10)<>0 then
  427. begin
  428. do_seekend(filerec(f).handle);
  429. filerec(f).mode:=fmoutput; {fool fmappend}
  430. end;
  431. { get errors }
  432. if filerec(f).handle=0 then
  433. begin
  434. errno:=GetLastError;
  435. Errno2InoutRes;
  436. end;
  437. end;
  438. function do_isdevice(handle:longint):boolean;
  439. begin
  440. do_isdevice:=(getfiletype(handle)=2);
  441. end;
  442. {*****************************************************************************
  443. UnTyped File Handling
  444. *****************************************************************************}
  445. {$i file.inc}
  446. {*****************************************************************************
  447. Typed File Handling
  448. *****************************************************************************}
  449. {$i typefile.inc}
  450. {*****************************************************************************
  451. Text File Handling
  452. *****************************************************************************}
  453. {$DEFINE EOF_CTRLZ}
  454. {$i text.inc}
  455. {*****************************************************************************
  456. Directory Handling
  457. *****************************************************************************}
  458. function CreateDirectory(name : pointer;sec : pointer) : longint;
  459. external 'kernel32' name 'CreateDirectoryA';
  460. function RemoveDirectory(name:pointer):longint;
  461. external 'kernel32' name 'RemoveDirectoryA';
  462. function SetCurrentDirectory(name : pointer) : longint;
  463. external 'kernel32' name 'SetCurrentDirectoryA';
  464. function GetCurrentDirectory(bufsize : longint;name : pchar) : longint;
  465. external 'kernel32' name 'GetCurrentDirectoryA';
  466. type
  467. TDirFnType=function(name:pointer):word;
  468. procedure dirfn(afunc : TDirFnType;const s:string);
  469. var
  470. buffer : array[0..255] of char;
  471. begin
  472. move(s[1],buffer,length(s));
  473. buffer[length(s)]:=#0;
  474. AllowSlash(pchar(@buffer));
  475. if aFunc(@buffer)=0 then
  476. begin
  477. errno:=GetLastError;
  478. Errno2InoutRes;
  479. end;
  480. end;
  481. function CreateDirectoryTrunc(name:pointer):word;
  482. begin
  483. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  484. end;
  485. procedure mkdir(const s:string);[IOCHECK];
  486. begin
  487. If InOutRes <> 0 then exit;
  488. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  489. end;
  490. procedure rmdir(const s:string);[IOCHECK];
  491. begin
  492. If InOutRes <> 0 then exit;
  493. dirfn(TDirFnType(@RemoveDirectory),s);
  494. end;
  495. procedure chdir(const s:string);[IOCHECK];
  496. begin
  497. If InOutRes <> 0 then exit;
  498. dirfn(TDirFnType(@SetCurrentDirectory),s);
  499. end;
  500. procedure getdir(drivenr:byte;var dir:string);
  501. const
  502. Drive:array[0..3]of char=(#0,':',#0,#0);
  503. var
  504. defaultdrive:boolean;
  505. DirBuf,SaveBuf:array[0..259] of Char;
  506. begin
  507. defaultdrive:=drivenr=0;
  508. if not defaultdrive then
  509. begin
  510. byte(Drive[0]):=Drivenr+64;
  511. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  512. SetCurrentDirectory(@Drive);
  513. end;
  514. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  515. if not defaultdrive then
  516. SetCurrentDirectory(@SaveBuf);
  517. dir:=strpas(DirBuf);
  518. end;
  519. {*****************************************************************************
  520. SystemUnit Initialization
  521. *****************************************************************************}
  522. { Startup }
  523. procedure GetStartupInfo(p : pointer);
  524. external 'kernel32' name 'GetStartupInfoA';
  525. function GetStdHandle(nStdHandle:DWORD):THANDLE;
  526. external 'kernel32' name 'GetStdHandle';
  527. { command line/enviroment functions }
  528. function GetCommandLine : pchar;
  529. external 'kernel32' name 'GetCommandLineA';
  530. { module functions }
  531. function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
  532. external 'kernel32' name 'GetModuleFileNameA';
  533. function GetModuleHandle(p : pointer) : longint;
  534. external 'kernel32' name 'GetModuleHandleA';
  535. var
  536. ModuleName : array[0..255] of char;
  537. function GetCommandFile:pchar;
  538. begin
  539. GetModuleFileName(0,@ModuleName,255);
  540. GetCommandFile:=@ModuleName;
  541. end;
  542. procedure setup_arguments;
  543. var
  544. arglen,
  545. count : longint;
  546. argstart,
  547. cmdline : pchar;
  548. quote : set of char;
  549. argsbuf : array[0..127] of pchar;
  550. begin
  551. { create commandline, it starts with the executed filename which is argv[0] }
  552. cmdline:=GetCommandLine;
  553. count:=0;
  554. repeat
  555. { skip leading spaces }
  556. while cmdline^ in [' ',#9,#13] do
  557. inc(longint(cmdline));
  558. case cmdline^ of
  559. #0 : break;
  560. '"' : begin
  561. quote:=['"'];
  562. inc(longint(cmdline));
  563. end;
  564. '''' : begin
  565. quote:=[''''];
  566. inc(longint(cmdline));
  567. end;
  568. else
  569. quote:=[' ',#9,#13];
  570. end;
  571. { scan until the end of the argument }
  572. argstart:=cmdline;
  573. while (cmdline^<>#0) and not(cmdline^ in quote) do
  574. inc(longint(cmdline));
  575. { reserve some memory }
  576. arglen:=cmdline-argstart;
  577. getmem(argsbuf[count],arglen+1);
  578. move(argstart^,argsbuf[count]^,arglen);
  579. argsbuf[count][arglen]:=#0;
  580. { skip quote }
  581. if cmdline^ in quote then
  582. inc(longint(cmdline));
  583. inc(count);
  584. until false;
  585. { create argc }
  586. argc:=count;
  587. { create an nil entry }
  588. argsbuf[count]:=nil;
  589. inc(count);
  590. { create the argv }
  591. getmem(argv,count shl 2);
  592. move(argsbuf,argv^,count shl 2);
  593. end;
  594. {$ASMMODE DIRECT}
  595. procedure Entry;[public,alias: '_mainCRTStartup'];
  596. begin
  597. { call to the pascal main }
  598. asm
  599. call PASCALMAIN
  600. end;
  601. { that's all folks }
  602. ExitProcess(0);
  603. end;
  604. {$ifdef dummy}
  605. Function SetUpStack : longint;
  606. { This routine does the following : }
  607. { returns the value of the initial SP - __stklen }
  608. begin
  609. asm
  610. pushl %ebx
  611. pushl %eax
  612. movl __stklen,%ebx
  613. movl %esp,%eax
  614. subl %ebx,%eax
  615. movl %eax,__RESULT
  616. popl %eax
  617. popl %ebx
  618. end;
  619. end;
  620. {$endif}
  621. {$ASMMODE ATT}
  622. begin
  623. { get some helpful informations }
  624. GetStartupInfo(@startupinfo);
  625. { some misc Win32 stuff }
  626. hprevinst:=0;
  627. hinstance:=getmodulehandle(GetCommandFile);
  628. cmdshow:=startupinfo.wshowwindow;
  629. { to test stack depth }
  630. loweststack:=maxlongint;
  631. { real test stack depth }
  632. { stacklimit := setupstack; }
  633. { Setup heap }
  634. {$ifndef WinHeap}
  635. InitHeap;
  636. {$endif WinHeap}
  637. { Setup stdin, stdout and stderr }
  638. StdInputHandle:=longint(GetStdHandle(STD_INPUT_HANDLE));
  639. StdOutputHandle:=longint(GetStdHandle(STD_OUTPUT_HANDLE));
  640. StdErrorHandle:=longint(GetStdHandle(STD_ERROR_HANDLE));
  641. OpenStdIO(Input,fmInput,StdInputHandle);
  642. OpenStdIO(Output,fmOutput,StdOutputHandle);
  643. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  644. { Arguments }
  645. setup_arguments;
  646. { Reset IO Error }
  647. InOutRes:=0;
  648. { Reset internal error variable }
  649. errno := 0;
  650. end.
  651. {
  652. $Log$
  653. Revision 1.12 1998-07-07 12:37:28 carl
  654. * correct mapping of error codes for TP compatibility
  655. + implemented stack checking in ifdef dummy
  656. Revision 1.11 1998/07/02 12:33:18 carl
  657. * IOCheck/InOutRes check for mkdir,rmdir and chdir like in TP
  658. Revision 1.10 1998/07/01 15:30:02 peter
  659. * better readln/writeln
  660. Revision 1.9 1998/06/10 10:39:17 peter
  661. * working w32 rtl
  662. Revision 1.8 1998/06/08 23:07:47 peter
  663. * dos interface is now 100% compatible
  664. * fixed call PASCALMAIN which must be direct asm
  665. Revision 1.7 1998/05/06 12:36:51 michael
  666. + Removed log from before restored version.
  667. Revision 1.6 1998/04/27 18:29:09 florian
  668. + do_open implemented, the file-I/O should be now complete
  669. Revision 1.5 1998/04/27 13:58:21 florian
  670. + paramstr/paramcount implemented
  671. Revision 1.4 1998/04/26 22:37:22 florian
  672. * some small extensions
  673. Revision 1.3 1998/04/26 21:49:57 florian
  674. + more stuff added (??dir procedures etc.)
  675. }