fp.pas 11 KB

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