fp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998-2000 by Berczi Gabor
  5. Main program of the IDE
  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. program FP;
  13. {$I globdir.inc}
  14. (**********************************************************************)
  15. (* CONDITIONAL DEFINES *)
  16. (* - NODEBUG No Debugging support *)
  17. (* - TP Turbo Pascal mode *)
  18. (* - i386 Target is an i386 IDE *)
  19. (**********************************************************************)
  20. uses
  21. {$ifndef NODEBUG}
  22. {$ifdef win32}
  23. fpcygwin,
  24. {$endif win32}
  25. {$endif NODEBUG}
  26. {$ifdef IDEHeapTrc}
  27. PPheap,
  28. {$endif IDEHeapTrc}
  29. {$ifdef go32v2}
  30. dpmiexcp,
  31. {$endif go32v2}
  32. {$ifdef fpc}
  33. keyboard,video,mouse,
  34. {$endif fpc}
  35. {$ifdef HasSignal}
  36. fpcatch,
  37. {$endif HasSignal}
  38. Dos,Objects,
  39. BrowCol,
  40. {$ifdef FVISION}
  41. FVConsts,
  42. {$else}
  43. Commands,
  44. {$endif}
  45. Drivers,Views,App,Dialogs,
  46. Menus,StdDlg,Validate,
  47. {$ifdef EDITORS}Editors{$else}WEditor,WCEdit{$endif},
  48. {$ifndef FVISION}
  49. ColorSel,
  50. {$endif FVISION}
  51. ASCIITab,
  52. WUtils,WViews,WHTMLScn,WHelp,
  53. FPIDE,FPCalc,FPCompil,FPString,
  54. FPIni,FPViews,FPConst,FPVars,FPUtils,FPHelp,FPSwitch,FPUsrScr,
  55. FPTools,
  56. {$ifndef NODEBUG}
  57. FPDebug,FPRegs,
  58. {$endif}
  59. FPTemplt,FPRedir,FPDesk,
  60. FPCodTmp,FPCodCmp;
  61. {$ifdef fpc}
  62. Const
  63. DummyMouseDriver : TMouseDriver = (
  64. useDefaultQueue : true;
  65. InitDriver : nil;
  66. DoneDriver : nil;
  67. DetectMouse : nil;
  68. ShowMouse : nil;
  69. HideMouse : nil;
  70. GetMouseX : nil;
  71. GetMouseY : nil;
  72. GetMouseButtons : nil;
  73. SetMouseXY : nil;
  74. GetMouseEvent : nil;
  75. PollMouseEvent : nil;
  76. PutMouseEvent : nil;
  77. );
  78. {$endif fpc}
  79. {$ifdef DEBUG}
  80. const
  81. CloseImmediately : boolean = false;
  82. var
  83. StartTime : real;
  84. function getrealtime : real;
  85. var
  86. h,m,s,s100 : word;
  87. begin
  88. gettime(h,m,s,s100);
  89. getrealtime:=h*3600.0+m*60.0+s+s100/100.0;
  90. end;
  91. {$endif DEBUG}
  92. procedure ProcessParams(BeforeINI: boolean);
  93. function IsSwitch(const Param: string): boolean;
  94. begin
  95. IsSwitch:=(Param<>'') and (Param[1]<>DirSep) { <- allow UNIX root-relative paths }
  96. and (Param[1] in ['-','/']); { <- but still accept dos switch char, eg. '/' }
  97. end;
  98. var I: Sw_integer;
  99. Param: string;
  100. begin
  101. for I:=1 to ParamCount do
  102. begin
  103. Param:=System.ParamStr(I);
  104. if IsSwitch(Param) then
  105. begin
  106. Param:=copy(Param,2,255);
  107. if Param<>'' then
  108. if UpcaseStr(copy(Param,1,2))='HM' then
  109. { HeapMonitor }
  110. begin
  111. if (copy(Param,3,1)='+') or (copy(Param,3,1)='') then
  112. StartupOptions:=StartupOptions or soHeapMonitor
  113. else
  114. if (copy(Param,3,1)='-') then
  115. StartupOptions:=StartupOptions and not soHeapMonitor;
  116. end else
  117. {$ifdef go32v2}
  118. if UpcaseStr(Param)='NOLFN' then
  119. begin
  120. LFNSupport:=false;
  121. end else
  122. {$endif go32v2}
  123. if UpcaseStr(Param)='README' then
  124. begin
  125. ShowReadme:=true;
  126. end else
  127. case Upcase(Param[1]) of
  128. 'C' : { custom config file (BP compatiblity) }
  129. if BeforeINI then
  130. begin
  131. if (length(Param)>=1) and (Param[1] in['=',':']) then
  132. Delete(Param,1,1); { eat separator }
  133. IniFileName:=Param;
  134. end;
  135. 'R' : { enter the directory last exited from (BP comp.) }
  136. begin
  137. Param:=copy(Param,2,255);
  138. if (Param='') or (Param='+') then
  139. StartupOptions:=StartupOptions or soReturnToLastDir
  140. else
  141. if (Param='-') then
  142. StartupOptions:=StartupOptions and (not soReturnToLastDir);
  143. end;
  144. 'S' :
  145. if Length(Param)=1 then
  146. begin
  147. UseMouse:=false;
  148. {$ifdef fpc}
  149. DoneMouse;
  150. SetMouseDriver(DummyMouseDriver);
  151. {$endif fpc}
  152. ButtonCount:=0;
  153. end;
  154. {$ifdef fpc}
  155. 'F' :
  156. if Length(Param)=1 then
  157. NoExtendedFrame:=true;
  158. {$ifdef Unix}
  159. 'T' : DebuggeeTTY:=Copy(Param,2,High(Param));
  160. {$endif Unix}
  161. { 'M' : TryToMaximizeScreen:=true;}
  162. {$endif fpc}
  163. {$ifdef DEBUG}
  164. 'Z' : UseOldBufStreamMethod:=true;
  165. 'X' : CloseImmediately:=true;
  166. {$endif DEBUG}
  167. end;
  168. end
  169. else
  170. if not BeforeINI then
  171. TryToOpenFile(nil,Param,0,0,{false}true);
  172. end;
  173. end;
  174. Procedure MyStreamError(Var S: TStream); {$ifndef FPC}far;{$endif}
  175. var ErrS: string;
  176. begin
  177. case S.Status of
  178. stGetError : ErrS:='Get of unregistered object type';
  179. stPutError : ErrS:='Put of unregistered object type';
  180. else ErrS:='';
  181. end;
  182. if ErrS<>'' then
  183. begin
  184. {$ifdef GABOR}{$ifdef TP}asm int 3;end;{$endif}{$endif}
  185. if Assigned(Application) then
  186. ErrorBox('Stream error: '+#13+ErrS,nil)
  187. else
  188. writeln('Error: ',ErrS);
  189. end;
  190. end;
  191. procedure DelTempFiles;
  192. begin
  193. DeleteFile(FPOutFileName);
  194. DeleteFile(FPErrFileName);
  195. DeleteFile(GDBOutFileName);
  196. DeleteFile(GDBOutPutFileName);
  197. DeleteFile(GREPOutName);
  198. DeleteFile(GREPErrName);
  199. end;
  200. procedure RegisterIDEObjects;
  201. begin
  202. RegisterApp;
  203. RegisterCodeComplete;
  204. RegisterCodeTemplates;
  205. {$ifndef FVISION}
  206. RegisterColorSel;
  207. {$endif FVISION}
  208. RegisterAsciiTab;
  209. RegisterDialogs;
  210. {$ifdef EDITORS}
  211. RegisterEditors;
  212. {$else}
  213. RegisterWEditor;
  214. RegisterWCEdit;
  215. {$endif}
  216. RegisterFPCalc;
  217. RegisterFPCompile;
  218. RegisterFPTools;
  219. RegisterFPViews;
  220. {$ifndef NODEBUG}
  221. RegisterFPDebugViews;
  222. RegisterFPRegsViews;
  223. {$endif}
  224. RegisterMenus;
  225. RegisterStdDlg;
  226. RegisterSymbols;
  227. RegisterObjects;
  228. RegisterValidate;
  229. RegisterViews;
  230. RegisterWHTMLScan;
  231. RegisterWUtils;
  232. RegisterWViews;
  233. end;
  234. var CanExit : boolean;
  235. SetJmpRes : longint;
  236. StoreExitProc : pointer;
  237. ErrS : String;
  238. P : record
  239. l1 : longint;
  240. s : pstring;
  241. end;
  242. {$ifdef win32}
  243. ShowMouseExe : string;
  244. {$endif win32}
  245. const
  246. ExitIntercepted : boolean = false;
  247. SeenExitCode : longint =0;
  248. SeenErrorAddr : pointer = nil;
  249. UserWantsToGoOn: boolean = false;
  250. procedure InterceptExit;
  251. begin
  252. {$IFDEF HasSignal}
  253. if StopJmpValid then
  254. begin
  255. ExitIntercepted:=true;
  256. SeenExitCode:=ExitCode;
  257. SeenErrorAddr:=ErrorAddr;
  258. LongJmp(StopJmp,1);
  259. end;
  260. {$ENDIF}
  261. end;
  262. BEGIN
  263. {$IFDEF HasSignal}
  264. EnableCatchSignals;
  265. {$ENDIF}
  266. {$ifdef DEV}
  267. HeapLimit:=4096;
  268. {$endif}
  269. writeln('þ Free Pascal IDE Version '+VersionStr);
  270. {$ifdef win32}
  271. Win32ShowMouse;
  272. {$endif win32}
  273. {$ifndef NODEBUG}
  274. {$ifdef win32}
  275. writeln('Using "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  276. CheckCygwinVersion;
  277. {$endif win32}
  278. {$endif NODEBUG}
  279. ProcessParams(true);
  280. {$ifdef DEBUG}
  281. StartTime:=getrealtime;
  282. {$endif DEBUG}
  283. InitDirs;
  284. RegisterIDEObjects;
  285. StreamError:=@MyStreamError;
  286. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  287. {$ifdef VESA}
  288. InitVESAScreenModes;
  289. {$endif}
  290. InitRedir;
  291. {$ifndef NODEBUG}
  292. InitBreakpoints;
  293. InitWatches;
  294. {$endif}
  295. InitReservedWords;
  296. InitHelpFiles;
  297. InitSwitches;
  298. InitINIFile;
  299. InitUserScreen;
  300. InitTools;
  301. InitTemplates;
  302. InitCodeTemplates;
  303. InitCodeComplete;
  304. IDEApp.Init;
  305. CheckINIFile;
  306. ReadSwitches(SwitchesPath);
  307. { load all options after init because of open files }
  308. ReadINIFile;
  309. InitDesktopFile;
  310. LoadDesktop;
  311. { Handle Standard Units }
  312. if UseAllUnitsInCodeComplete then
  313. AddAvailableUnitsToCodeComplete(false);
  314. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  315. AddStandardUnitsToCodeComplete;
  316. { why are the screen contents parsed at startup? Gabor
  317. to be able to find location of error in last compilation
  318. from command line PM }
  319. ParseUserScreen;
  320. { Update IDE }
  321. IDEApp.Update;
  322. IDEApp.UpdateMode;
  323. IDEApp.UpdateTarget;
  324. ProcessParams(false);
  325. if ShowReadme then
  326. begin
  327. PutCommand(Application,evCommand,cmShowReadme,nil);
  328. ShowReadme:=false; { do not show next time }
  329. end;
  330. StoreExitProc:=ExitProc;
  331. ExitProc:=@InterceptExit;
  332. repeat
  333. {$IFDEF HasSignal}
  334. SetJmpRes:=setjmp(StopJmp);
  335. StopJmpValid:=true;
  336. {$ENDIF}
  337. UserWantsToGoOn:=false;
  338. if SetJmpRes=0 then
  339. begin
  340. {$ifdef DEBUG}
  341. if not CloseImmediately then
  342. {$endif DEBUG}
  343. IDEApp.Run;
  344. end
  345. else
  346. begin
  347. if (SetJmpRes=1) and ExitIntercepted then
  348. begin
  349. { If ExitProc=@InterceptExit then
  350. ExitProc:=StoreExitProc;}
  351. Str(SeenExitCode,ErrS);
  352. if Assigned(Application) then
  353. begin
  354. P.l1:=SeenExitCode;
  355. ErrS:=hexstr(longint(SeenErrorAddr),8);
  356. P.s:=@ErrS;
  357. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  358. UserWantsToGoOn:=true;
  359. end
  360. else
  361. writeln('Abnormal exit error: ',ErrS);
  362. end
  363. else
  364. begin
  365. Str(SetJmpRes,ErrS);
  366. { Longjmp was called by fpcatch }
  367. if Assigned(Application) then
  368. begin
  369. P.l1:=SetJmpRes;
  370. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  371. UserWantsToGoOn:=true;
  372. end
  373. else
  374. writeln('Signal error: ',ErrS);
  375. end;
  376. end;
  377. if (AutoSaveOptions and asEditorFiles)=0 then
  378. CanExit:=IDEApp.AskSaveAll
  379. else
  380. CanExit:=IDEApp.SaveAll;
  381. {$IFDEF HasSignal}
  382. StopJmpValid:=false;
  383. {$ENDIF}
  384. if (SetJmpRes<>0) then
  385. begin
  386. if (not CanExit) or UserWantsToGoOn then
  387. begin
  388. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  389. CanExit:=true
  390. else
  391. CanExit:=false;
  392. end
  393. else
  394. begin
  395. ErrorBox(leaving_after_error,nil);
  396. end;
  397. end;
  398. until CanExit;
  399. If ExitProc=pointer(@InterceptExit) then
  400. ExitProc:=StoreExitProc;
  401. IDEApp.AutoSave;
  402. DoneDesktopFile;
  403. DelTempFiles;
  404. IDEApp.Done;
  405. WriteSwitches(SwitchesPath);
  406. {$IFDEF HasSignal}
  407. DisableCatchSignals;
  408. {$ENDIF}
  409. DoneCodeComplete;
  410. DoneCodeTemplates;
  411. DoneTemplates;
  412. DoneTools;
  413. DoneUserScreen;
  414. DoneSwitches;
  415. DoneHelpFiles;
  416. DoneHelpFilesTypes;
  417. DoneReservedWords;
  418. DoneToolMessages;
  419. DoneBrowserCol;
  420. {$ifndef NODEBUG}
  421. DoneDebugger;
  422. DoneBreakpoints;
  423. DoneWatches;
  424. {$endif}
  425. {$ifdef fpc}
  426. {$ifdef unix}
  427. Video.ClearScreen;
  428. {$endif unix}
  429. Video.DoneVideo;
  430. Keyboard.DoneKeyboard;
  431. {$endif fpc}
  432. {$ifdef VESA}
  433. DoneVESAScreenModes;
  434. {$endif}
  435. {$ifdef unix}
  436. Keyboard.RestoreStartMode;
  437. {$endif unix}
  438. StreamError:=nil;
  439. {$ifdef DEBUG}
  440. if CloseImmediately then
  441. writeln('Used time is ',getrealtime-StartTime:0:2);
  442. {$endif DEBUG}
  443. END.
  444. {
  445. $Log$
  446. Revision 1.17 2002-12-12 00:08:09 pierre
  447. Use fpregs unit
  448. Revision 1.16 2002/11/28 12:49:20 pierre
  449. * enable signals catching earlier
  450. Revision 1.15 2002/10/30 22:12:13 pierre
  451. * use ppheap with IDEHEAPTRC conditional
  452. Revision 1.14 2002/10/12 19:43:07 hajny
  453. * missing HasSignal conditionals added (needed for FPC/2)
  454. Revision 1.13 2002/09/10 12:19:14 pierre
  455. * use faster method for loading files by default
  456. Revision 1.12 2002/09/09 06:59:16 pierre
  457. * new debug options added
  458. Revision 1.11 2002/09/07 15:40:41 peter
  459. * old logs removed and tabs fixed
  460. Revision 1.10 2002/09/04 14:07:12 pierre
  461. + Enhance code complete by inserting unit symbols
  462. Revision 1.9 2002/05/29 22:29:42 pierre
  463. Asciitab now in fvision
  464. Revision 1.8 2002/04/12 11:28:55 pierre
  465. + use fpcygwin unit for win32 debug IDE
  466. Revision 1.7 2002/04/12 09:00:01 pierre
  467. * enhance internal error handling
  468. Revision 1.6 2002/03/28 16:32:48 pierre
  469. * clearscrenn at exit for unix
  470. Revision 1.5 2002/03/20 14:56:41 pierre
  471. * correct last commit
  472. Revision 1.4 2002/03/20 14:53:37 pierre
  473. + rescue handlers in main loop
  474. Revision 1.3 2002/01/09 09:46:10 pierre
  475. * fix problems with -S option
  476. }