fp.pas 11 KB

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