fp.pas 12 KB

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