fp.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. if StopJmpValid then
  248. begin
  249. ExitIntercepted:=true;
  250. SeenExitCode:=ExitCode;
  251. SeenErrorAddr:=ErrorAddr;
  252. LongJmp(StopJmp,1);
  253. end;
  254. end;
  255. BEGIN
  256. {$ifdef DEV}HeapLimit:=4096;{$endif}
  257. writeln('þ Free Pascal IDE Version '+VersionStr);
  258. {$ifdef win32}
  259. Win32ShowMouse;
  260. {$endif win32}
  261. {$ifndef NODEBUG}
  262. {$ifdef win32}
  263. writeln('Using "',GetCygwinFullName,'" version ',GetCygwinVersionString);
  264. CheckCygwinVersion;
  265. {$endif win32}
  266. {$endif NODEBUG}
  267. ProcessParams(true);
  268. {$ifdef DEBUG}
  269. StartTime:=getrealtime;
  270. {$endif DEBUG}
  271. InitDirs;
  272. RegisterIDEObjects;
  273. StreamError:=@MyStreamError;
  274. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  275. {$ifdef VESA}
  276. InitVESAScreenModes;
  277. {$endif}
  278. InitRedir;
  279. {$ifndef NODEBUG}
  280. InitBreakpoints;
  281. InitWatches;
  282. {$endif}
  283. InitReservedWords;
  284. InitHelpFiles;
  285. InitSwitches;
  286. InitINIFile;
  287. InitUserScreen;
  288. InitTools;
  289. InitTemplates;
  290. InitCodeTemplates;
  291. InitCodeComplete;
  292. IDEApp.Init;
  293. CheckINIFile;
  294. ReadSwitches(SwitchesPath);
  295. { load all options after init because of open files }
  296. ReadINIFile;
  297. InitDesktopFile;
  298. LoadDesktop;
  299. { Handle Standard Units }
  300. if UseAllUnitsInCodeComplete then
  301. AddAvailableUnitsToCodeComplete(false);
  302. if UseStandardUnitsInCodeComplete and not assigned(UnitsCodeCompleteWords) then
  303. AddStandardUnitsToCodeComplete;
  304. { why are the screen contents parsed at startup? Gabor
  305. to be able to find location of error in last compilation
  306. from command line PM }
  307. ParseUserScreen;
  308. EnableCatchSignals;
  309. { Update IDE }
  310. IDEApp.Update;
  311. IDEApp.UpdateMode;
  312. IDEApp.UpdateTarget;
  313. ProcessParams(false);
  314. if ShowReadme then
  315. begin
  316. PutCommand(Application,evCommand,cmShowReadme,nil);
  317. ShowReadme:=false; { do not show next time }
  318. end;
  319. StoreExitProc:=ExitProc;
  320. ExitProc:=@InterceptExit;
  321. repeat
  322. SetJmpRes:=setjmp(StopJmp);
  323. StopJmpValid:=true;
  324. UserWantsToGoOn:=false;
  325. if SetJmpRes=0 then
  326. begin
  327. {$ifdef DEBUG}
  328. if not CloseImmediately then
  329. {$endif DEBUG}
  330. IDEApp.Run;
  331. end
  332. else
  333. begin
  334. if (SetJmpRes=1) and ExitIntercepted then
  335. begin
  336. { If ExitProc=@InterceptExit then
  337. ExitProc:=StoreExitProc;}
  338. Str(SeenExitCode,ErrS);
  339. if Assigned(Application) then
  340. begin
  341. P.l1:=SeenExitCode;
  342. ErrS:=hexstr(longint(SeenErrorAddr),8);
  343. P.s:=@ErrS;
  344. if OKCancelBox(error_programexitedwitherror,@P)=cmCancel then
  345. UserWantsToGoOn:=true;
  346. end
  347. else
  348. writeln('Abnormal exit error: ',ErrS);
  349. end
  350. else
  351. begin
  352. Str(SetJmpRes,ErrS);
  353. { Longjmp was called by fpcatch }
  354. if Assigned(Application) then
  355. begin
  356. P.l1:=SetJmpRes;
  357. if OKCancelBox(error_programexitedwithsignal,@P)=cmCancel then
  358. UserWantsToGoOn:=true;
  359. end
  360. else
  361. writeln('Signal error: ',ErrS);
  362. end;
  363. end;
  364. if (AutoSaveOptions and asEditorFiles)=0 then
  365. CanExit:=IDEApp.AskSaveAll
  366. else
  367. CanExit:=IDEApp.SaveAll;
  368. StopJmpValid:=false;
  369. if (SetJmpRes<>0) then
  370. begin
  371. if (not CanExit) or UserWantsToGoOn then
  372. begin
  373. if ConfirmBox(continue_despite_error,nil,false)=cmNo then
  374. CanExit:=true
  375. else
  376. CanExit:=false;
  377. end
  378. else
  379. begin
  380. ErrorBox(leaving_after_error,nil);
  381. end;
  382. end;
  383. until CanExit;
  384. If ExitProc=pointer(@InterceptExit) then
  385. ExitProc:=StoreExitProc;
  386. IDEApp.AutoSave;
  387. DoneDesktopFile;
  388. DelTempFiles;
  389. IDEApp.Done;
  390. WriteSwitches(SwitchesPath);
  391. DisableCatchSignals;
  392. DoneCodeComplete;
  393. DoneCodeTemplates;
  394. DoneTemplates;
  395. DoneTools;
  396. DoneUserScreen;
  397. DoneSwitches;
  398. DoneHelpFiles;
  399. DoneHelpFilesTypes;
  400. DoneReservedWords;
  401. DoneToolMessages;
  402. DoneBrowserCol;
  403. {$ifndef NODEBUG}
  404. DoneDebugger;
  405. DoneBreakpoints;
  406. DoneWatches;
  407. {$endif}
  408. {$ifdef fpc}
  409. {$ifdef unix}
  410. Video.ClearScreen;
  411. {$endif unix}
  412. Video.DoneVideo;
  413. Keyboard.DoneKeyboard;
  414. {$endif fpc}
  415. {$ifdef VESA}
  416. DoneVESAScreenModes;
  417. {$endif}
  418. {$ifdef unix}
  419. Keyboard.RestoreStartMode;
  420. {$endif unix}
  421. StreamError:=nil;
  422. {$ifdef DEBUG}
  423. if CloseImmediately then
  424. writeln('Used time is ',getrealtime-StartTime:0:2);
  425. {$endif DEBUG}
  426. END.
  427. {
  428. $Log$
  429. Revision 1.13 2002-09-10 12:19:14 pierre
  430. * use faster method for loading files by default
  431. Revision 1.12 2002/09/09 06:59:16 pierre
  432. * new debug options added
  433. Revision 1.11 2002/09/07 15:40:41 peter
  434. * old logs removed and tabs fixed
  435. Revision 1.10 2002/09/04 14:07:12 pierre
  436. + Enhance code complete by inserting unit symbols
  437. Revision 1.9 2002/05/29 22:29:42 pierre
  438. Asciitab now in fvision
  439. Revision 1.8 2002/04/12 11:28:55 pierre
  440. + use fpcygwin unit for win32 debug IDE
  441. Revision 1.7 2002/04/12 09:00:01 pierre
  442. * enhance internal error handling
  443. Revision 1.6 2002/03/28 16:32:48 pierre
  444. * clearscrenn at exit for unix
  445. Revision 1.5 2002/03/20 14:56:41 pierre
  446. * correct last commit
  447. Revision 1.4 2002/03/20 14:53:37 pierre
  448. + rescue handlers in main loop
  449. Revision 1.3 2002/01/09 09:46:10 pierre
  450. * fix problems with -S option
  451. }