syswin32.pp 20 KB

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