fp.pas 11 KB

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