syswin32.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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. { 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. GlobalLock(h);
  224. l:=GlobalSize(h);
  225. writeln(l);
  226. sbrk:=l;
  227. end;
  228. { include standard heap management }
  229. {$I heap.inc}
  230. {$endif WinHeap}
  231. {*****************************************************************************
  232. Low Level File Routines
  233. *****************************************************************************}
  234. function WriteFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  235. overlap:pointer):longint;
  236. external 'kernel32' name 'WriteFile';
  237. function ReadFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  238. overlap:pointer):longint;
  239. external 'kernel32' name 'ReadFile';
  240. function CloseHandle(h : longint) : longint;
  241. external 'kernel32' name 'CloseHandle';
  242. function DeleteFile(p : pchar) : longint;
  243. external 'kernel32' name 'DeleteFileA';
  244. function MoveFile(old,_new : pchar) : longint;
  245. external 'kernel32' name 'MoveFileA';
  246. function SetFilePointer(l1,l2 : longint;l3 : pointer;l4 : longint) : longint;
  247. external 'kernel32' name 'SetFilePointer';
  248. function GetFileSize(h:longint;p:pointer) : longint;
  249. external 'kernel32' name 'GetFileSize';
  250. function CreateFile(name : pointer;access,sharing : longint;
  251. security : pointer;how,attr,template : longint) : longint;
  252. external 'kernel32' name 'CreateFileA';
  253. function SetEndOfFile(h : longint) : boolean;
  254. external 'kernel32' name 'SetEndOfFile';
  255. function GetFileType(Handle:DWORD):DWord;
  256. external 'kernel32' name 'GetFileType';
  257. procedure AllowSlash(p:pchar);
  258. var
  259. i : longint;
  260. begin
  261. { allow slash as backslash }
  262. for i:=0 to strlen(p) do
  263. if p[i]='/' then p[i]:='\';
  264. end;
  265. procedure do_close(h : longint);
  266. begin
  267. closehandle(h);
  268. end;
  269. procedure do_erase(p : pchar);
  270. begin
  271. AllowSlash(p);
  272. if DeleteFile(p)=0 then
  273. Begin
  274. errno:=GetLastError;
  275. Errno2InoutRes;
  276. end;
  277. end;
  278. procedure do_rename(p1,p2 : pchar);
  279. begin
  280. AllowSlash(p1);
  281. AllowSlash(p2);
  282. if MoveFile(p1,p2)=0 then
  283. Begin
  284. errno:=GetLastError;
  285. Errno2InoutRes;
  286. end;
  287. end;
  288. function do_write(h,addr,len : longint) : longint;
  289. var
  290. size:longint;
  291. begin
  292. if writefile(h,pointer(addr),len,size,nil)=0 then
  293. Begin
  294. errno:=GetLastError;
  295. Errno2InoutRes;
  296. end;
  297. do_write:=size;
  298. end;
  299. function do_read(h,addr,len : longint) : longint;
  300. var
  301. result:longint;
  302. begin
  303. if readfile(h,pointer(addr),len,result,nil)=0 then
  304. Begin
  305. errno:=GetLastError;
  306. Errno2InoutRes;
  307. end;
  308. do_read:=result;
  309. end;
  310. function do_filepos(handle : longint) : longint;
  311. var
  312. l:longint;
  313. begin
  314. l:=SetFilePointer(handle,0,nil,FILE_CURRENT);
  315. if l=-1 then
  316. begin
  317. l:=0;
  318. errno:=GetLastError;
  319. Errno2InoutRes;
  320. end;
  321. do_filepos:=l;
  322. end;
  323. procedure do_seek(handle,pos : longint);
  324. begin
  325. if SetFilePointer(handle,pos,nil,FILE_BEGIN)=-1 then
  326. Begin
  327. errno:=GetLastError;
  328. Errno2InoutRes;
  329. end;
  330. end;
  331. function do_seekend(handle:longint):longint;
  332. begin
  333. do_seekend:=SetFilePointer(handle,0,nil,FILE_END);
  334. if do_seekend=-1 then
  335. begin
  336. errno:=GetLastError;
  337. Errno2InoutRes;
  338. end;
  339. end;
  340. function do_filesize(handle : longint) : longint;
  341. var
  342. aktfilepos : longint;
  343. begin
  344. aktfilepos:=do_filepos(handle);
  345. do_filesize:=do_seekend(handle);
  346. do_seek(handle,aktfilepos);
  347. end;
  348. procedure do_truncate (handle,pos:longint);
  349. begin
  350. do_seek(handle,pos);
  351. if not(SetEndOfFile(handle)) then
  352. begin
  353. errno:=GetLastError;
  354. Errno2InoutRes;
  355. end;
  356. end;
  357. procedure do_open(var f;p : pchar;flags:longint);
  358. {
  359. filerec and textrec have both handle and mode as the first items so
  360. they could use the same routine for opening/creating.
  361. when (flags and $10) the file will be append
  362. when (flags and $100) the file will be truncate/rewritten
  363. when (flags and $1000) there is no check for close (needed for textfiles)
  364. }
  365. var
  366. oflags,cd : longint;
  367. begin
  368. AllowSlash(p);
  369. { close first if opened }
  370. if ((flags and $1000)=0) then
  371. begin
  372. case filerec(f).mode of
  373. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  374. fmclosed : ;
  375. else
  376. begin
  377. {not assigned}
  378. inoutres:=102;
  379. exit;
  380. end;
  381. end;
  382. end;
  383. { reset file handle }
  384. filerec(f).handle:=UnusedHandle;
  385. { convert filemode to filerec modes }
  386. case (flags and 3) of
  387. 0 : begin
  388. filerec(f).mode:=fminput;
  389. oflags:=GENERIC_READ;
  390. end;
  391. 1 : begin
  392. filerec(f).mode:=fmoutput;
  393. oflags:=GENERIC_WRITE;
  394. end;
  395. 2 : begin
  396. filerec(f).mode:=fminout;
  397. oflags:=GENERIC_WRITE or GENERIC_READ;
  398. end;
  399. end;
  400. { standard is opening and existing file }
  401. cd:=OPEN_EXISTING;
  402. { create it ? }
  403. if (flags and $100)<>0 then
  404. cd:=CREATE_ALWAYS
  405. { or append ? }
  406. else
  407. if (flags and $10)<>0 then
  408. cd:=OPEN_ALWAYS;
  409. { empty name is special }
  410. if p[0]=#0 then
  411. begin
  412. case filerec(f).mode of
  413. fminput : filerec(f).handle:=StdInputHandle;
  414. fmappend,
  415. fmoutput : begin
  416. filerec(f).handle:=StdOutputHandle;
  417. filerec(f).mode:=fmoutput; {fool fmappend}
  418. end;
  419. end;
  420. exit;
  421. end;
  422. filerec(f).handle:=CreateFile(p,oflags,0,nil,cd,FILE_ATTRIBUTE_NORMAL,0);
  423. { append mode }
  424. if (flags and $10)<>0 then
  425. begin
  426. do_seekend(filerec(f).handle);
  427. filerec(f).mode:=fmoutput; {fool fmappend}
  428. end;
  429. { get errors }
  430. if filerec(f).handle=0 then
  431. begin
  432. errno:=GetLastError;
  433. Errno2InoutRes;
  434. end;
  435. end;
  436. function do_isdevice(handle:longint):boolean;
  437. begin
  438. do_isdevice:=(getfiletype(handle)=2);
  439. end;
  440. {*****************************************************************************
  441. UnTyped File Handling
  442. *****************************************************************************}
  443. {$i file.inc}
  444. {*****************************************************************************
  445. Typed File Handling
  446. *****************************************************************************}
  447. {$i typefile.inc}
  448. {*****************************************************************************
  449. Text File Handling
  450. *****************************************************************************}
  451. {$DEFINE EOF_CTRLZ}
  452. {$i text.inc}
  453. {*****************************************************************************
  454. Directory Handling
  455. *****************************************************************************}
  456. function CreateDirectory(name : pointer;sec : pointer) : longint;
  457. external 'kernel32' name 'CreateDirectoryA';
  458. function RemoveDirectory(name:pointer):longint;
  459. external 'kernel32' name 'RemoveDirectoryA';
  460. function SetCurrentDirectory(name : pointer) : longint;
  461. external 'kernel32' name 'SetCurrentDirectoryA';
  462. function GetCurrentDirectory(bufsize : longint;name : pchar) : longint;
  463. external 'kernel32' name 'GetCurrentDirectoryA';
  464. type
  465. TDirFnType=function(name:pointer):word;
  466. procedure dirfn(afunc : TDirFnType;const s:string);
  467. var
  468. buffer : array[0..255] of char;
  469. begin
  470. move(s[1],buffer,length(s));
  471. buffer[length(s)]:=#0;
  472. AllowSlash(pchar(@buffer));
  473. if aFunc(@buffer)=0 then
  474. begin
  475. errno:=GetLastError;
  476. Errno2InoutRes;
  477. end;
  478. end;
  479. function CreateDirectoryTrunc(name:pointer):word;
  480. begin
  481. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  482. end;
  483. procedure mkdir(const s:string);[IOCHECK];
  484. begin
  485. If InOutRes <> 0 then exit;
  486. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  487. end;
  488. procedure rmdir(const s:string);[IOCHECK];
  489. begin
  490. If InOutRes <> 0 then exit;
  491. dirfn(TDirFnType(@RemoveDirectory),s);
  492. end;
  493. procedure chdir(const s:string);[IOCHECK];
  494. begin
  495. If InOutRes <> 0 then exit;
  496. dirfn(TDirFnType(@SetCurrentDirectory),s);
  497. end;
  498. procedure getdir(drivenr:byte;var dir:string);
  499. const
  500. Drive:array[0..3]of char=(#0,':',#0,#0);
  501. var
  502. defaultdrive:boolean;
  503. DirBuf,SaveBuf:array[0..259] of Char;
  504. begin
  505. defaultdrive:=drivenr=0;
  506. if not defaultdrive then
  507. begin
  508. byte(Drive[0]):=Drivenr+64;
  509. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  510. SetCurrentDirectory(@Drive);
  511. end;
  512. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  513. if not defaultdrive then
  514. SetCurrentDirectory(@SaveBuf);
  515. dir:=strpas(DirBuf);
  516. end;
  517. {*****************************************************************************
  518. SystemUnit Initialization
  519. *****************************************************************************}
  520. { Startup }
  521. procedure GetStartupInfo(p : pointer);
  522. external 'kernel32' name 'GetStartupInfoA';
  523. function GetStdHandle(nStdHandle:DWORD):THANDLE;
  524. external 'kernel32' name 'GetStdHandle';
  525. { command line/enviroment functions }
  526. function GetCommandLine : pchar;
  527. external 'kernel32' name 'GetCommandLineA';
  528. { module functions }
  529. function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
  530. external 'kernel32' name 'GetModuleFileNameA';
  531. function GetModuleHandle(p : pointer) : longint;
  532. external 'kernel32' name 'GetModuleHandleA';
  533. var
  534. ModuleName : array[0..255] of char;
  535. function GetCommandFile:pchar;
  536. begin
  537. GetModuleFileName(0,@ModuleName,255);
  538. GetCommandFile:=@ModuleName;
  539. end;
  540. procedure setup_arguments;
  541. var
  542. arglen,
  543. count : longint;
  544. argstart,
  545. cmdline : pchar;
  546. quote : set of char;
  547. argsbuf : array[0..127] of pchar;
  548. begin
  549. { create commandline, it starts with the executed filename which is argv[0] }
  550. cmdline:=GetCommandLine;
  551. count:=0;
  552. repeat
  553. { skip leading spaces }
  554. while cmdline^ in [' ',#9,#13] do
  555. inc(longint(cmdline));
  556. case cmdline^ of
  557. #0 : break;
  558. '"' : begin
  559. quote:=['"'];
  560. inc(longint(cmdline));
  561. end;
  562. '''' : begin
  563. quote:=[''''];
  564. inc(longint(cmdline));
  565. end;
  566. else
  567. quote:=[' ',#9,#13];
  568. end;
  569. { scan until the end of the argument }
  570. argstart:=cmdline;
  571. while (cmdline^<>#0) and not(cmdline^ in quote) do
  572. inc(longint(cmdline));
  573. { reserve some memory }
  574. arglen:=cmdline-argstart;
  575. getmem(argsbuf[count],arglen+1);
  576. move(argstart^,argsbuf[count]^,arglen);
  577. argsbuf[count][arglen]:=#0;
  578. { skip quote }
  579. if cmdline^ in quote then
  580. inc(longint(cmdline));
  581. inc(count);
  582. until false;
  583. { create argc }
  584. argc:=count;
  585. { create an nil entry }
  586. argsbuf[count]:=nil;
  587. inc(count);
  588. { create the argv }
  589. getmem(argv,count shl 2);
  590. move(argsbuf,argv^,count shl 2);
  591. end;
  592. {$ASMMODE DIRECT}
  593. procedure Entry;[public,alias: '_mainCRTStartup'];
  594. begin
  595. { call to the pascal main }
  596. asm
  597. call PASCALMAIN
  598. end;
  599. { that's all folks }
  600. ExitProcess(0);
  601. end;
  602. {$ifdef dummy}
  603. Function SetUpStack : longint;
  604. { This routine does the following : }
  605. { returns the value of the initial SP - __stklen }
  606. begin
  607. asm
  608. pushl %ebx
  609. pushl %eax
  610. movl __stklen,%ebx
  611. movl %esp,%eax
  612. subl %ebx,%eax
  613. movl %eax,__RESULT
  614. popl %eax
  615. popl %ebx
  616. end;
  617. end;
  618. {$endif}
  619. {$ASMMODE ATT}
  620. begin
  621. { get some helpful informations }
  622. GetStartupInfo(@startupinfo);
  623. { some misc Win32 stuff }
  624. hprevinst:=0;
  625. hinstance:=getmodulehandle(GetCommandFile);
  626. cmdshow:=startupinfo.wshowwindow;
  627. { to test stack depth }
  628. loweststack:=maxlongint;
  629. { real test stack depth }
  630. { stacklimit := setupstack; }
  631. { Setup heap }
  632. {$ifndef WinHeap}
  633. InitHeap;
  634. {$endif WinHeap}
  635. { Setup stdin, stdout and stderr }
  636. StdInputHandle:=longint(GetStdHandle(STD_INPUT_HANDLE));
  637. StdOutputHandle:=longint(GetStdHandle(STD_OUTPUT_HANDLE));
  638. StdErrorHandle:=longint(GetStdHandle(STD_ERROR_HANDLE));
  639. OpenStdIO(Input,fmInput,StdInputHandle);
  640. OpenStdIO(Output,fmOutput,StdOutputHandle);
  641. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  642. { Arguments }
  643. setup_arguments;
  644. { Reset IO Error }
  645. InOutRes:=0;
  646. { Reset internal error variable }
  647. errno := 0;
  648. end.
  649. {
  650. $Log$
  651. Revision 1.14 1998-07-30 13:27:19 michael
  652. + Added support for errorproc. Changed runerror to HandleError
  653. Revision 1.13 1998/07/13 21:19:15 florian
  654. * some problems with ansi string support fixed
  655. Revision 1.12 1998/07/07 12:37:28 carl
  656. * correct mapping of error codes for TP compatibility
  657. + implemented stack checking in ifdef dummy
  658. Revision 1.11 1998/07/02 12:33:18 carl
  659. * IOCheck/InOutRes check for mkdir,rmdir and chdir like in TP
  660. Revision 1.10 1998/07/01 15:30:02 peter
  661. * better readln/writeln
  662. Revision 1.9 1998/06/10 10:39:17 peter
  663. * working w32 rtl
  664. Revision 1.8 1998/06/08 23:07:47 peter
  665. * dos interface is now 100% compatible
  666. * fixed call PASCALMAIN which must be direct asm
  667. Revision 1.7 1998/05/06 12:36:51 michael
  668. + Removed log from before restored version.
  669. Revision 1.6 1998/04/27 18:29:09 florian
  670. + do_open implemented, the file-I/O should be now complete
  671. Revision 1.5 1998/04/27 13:58:21 florian
  672. + paramstr/paramcount implemented
  673. Revision 1.4 1998/04/26 22:37:22 florian
  674. * some small extensions
  675. Revision 1.3 1998/04/26 21:49:57 florian
  676. + more stuff added (??dir procedures etc.)
  677. }