fp.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. {$ifdef IDEHeapTrc}
  22. HeapTrc,
  23. {$endif IDEHeapTrc}
  24. {$ifdef go32v2}
  25. dpmiexcp,
  26. {$endif go32v2}
  27. {$ifdef fpc}
  28. keyboard,video,mouse,
  29. {$endif fpc}
  30. {$ifdef HasSignal}
  31. fpcatch,
  32. {$endif HasSignal}
  33. Dos,Objects,
  34. BrowCol,
  35. Drivers,Views,App,Dialogs,
  36. Menus,StdDlg,Validate,
  37. {$ifdef EDITORS}Editors{$else}WEditor,WCEdit{$endif},
  38. {$ifndef FVISION}
  39. ColorSel,
  40. ASCIITab,
  41. {$endif FVISION}
  42. WUtils,WViews,WHTMLScn,WHelp,
  43. FPIDE,FPCalc,FPCompil,FPString,
  44. FPIni,FPViews,FPConst,FPVars,FPUtils,FPHelp,FPSwitch,FPUsrScr,
  45. FPTools,{$ifndef NODEBUG}FPDebug,{$endif}FPTemplt,FPRedir,FPDesk,
  46. FPCodTmp,FPCodCmp;
  47. {$ifdef fpc}
  48. Const
  49. DummyMouseDriver : TMouseDriver = (
  50. useDefaultQueue : true;
  51. InitDriver : nil;
  52. DoneDriver : nil;
  53. DetectMouse : nil;
  54. ShowMouse : nil;
  55. HideMouse : nil;
  56. GetMouseX : nil;
  57. GetMouseY : nil;
  58. GetMouseButtons : nil;
  59. SetMouseXY : nil;
  60. GetMouseEvent : nil;
  61. PollMouseEvent : nil;
  62. PutMouseEvent : nil;
  63. );
  64. {$endif fpc}
  65. procedure ProcessParams(BeforeINI: boolean);
  66. function IsSwitch(const Param: string): boolean;
  67. begin
  68. IsSwitch:=(Param<>'') and (Param[1]<>DirSep) { <- allow UNIX root-relative paths }
  69. and (Param[1] in ['-','/']); { <- but still accept dos switch char, eg. '/' }
  70. end;
  71. var I: Sw_integer;
  72. Param: string;
  73. begin
  74. for I:=1 to ParamCount do
  75. begin
  76. Param:=System.ParamStr(I);
  77. if IsSwitch(Param) then
  78. begin
  79. Param:=copy(Param,2,255);
  80. if Param<>'' then
  81. if UpcaseStr(copy(Param,1,2))='HM' then
  82. { HeapMonitor }
  83. begin
  84. if (copy(Param,3,1)='+') or (copy(Param,3,1)='') then
  85. StartupOptions:=StartupOptions or soHeapMonitor
  86. else
  87. if (copy(Param,3,1)='-') then
  88. StartupOptions:=StartupOptions and not soHeapMonitor;
  89. end else
  90. {$ifdef go32v2}
  91. if UpcaseStr(Param)='NOLFN' then
  92. begin
  93. LFNSupport:=false;
  94. end else
  95. {$endif go32v2}
  96. if UpcaseStr(Param)='README' then
  97. begin
  98. ShowReadme:=true;
  99. end else
  100. case Upcase(Param[1]) of
  101. 'C' : { custom config file (BP compatiblity) }
  102. if BeforeINI then
  103. begin
  104. if (length(Param)>=1) and (Param[1] in['=',':']) then
  105. Delete(Param,1,1); { eat separator }
  106. IniFileName:=Param;
  107. end;
  108. 'R' : { enter the directory last exited from (BP comp.) }
  109. begin
  110. Param:=copy(Param,2,255);
  111. if (Param='') or (Param='+') then
  112. StartupOptions:=StartupOptions or soReturnToLastDir
  113. else
  114. if (Param='-') then
  115. StartupOptions:=StartupOptions and (not soReturnToLastDir);
  116. end;
  117. 'S' :
  118. if Length(Param)=1 then
  119. begin
  120. UseMouse:=false;
  121. {$ifdef fpc}
  122. DoneMouse;
  123. SetMouseDriver(DummyMouseDriver);
  124. {$endif fpc}
  125. ButtonCount:=0;
  126. end;
  127. {$ifdef fpc}
  128. 'F' :
  129. if Length(Param)=1 then
  130. NoExtendedFrame:=true;
  131. {$ifdef Unix}
  132. 'T' : DebuggeeTTY:=Copy(Param,2,High(Param));
  133. {$endif Unix}
  134. { 'M' : TryToMaximizeScreen:=true;}
  135. {$endif fpc}
  136. end;
  137. end
  138. else
  139. if not BeforeINI then
  140. TryToOpenFile(nil,Param,0,0,{false}true);
  141. end;
  142. end;
  143. Procedure MyStreamError(Var S: TStream); {$ifndef FPC}far;{$endif}
  144. var ErrS: string;
  145. begin
  146. case S.Status of
  147. stGetError : ErrS:='Get of unregistered object type';
  148. stPutError : ErrS:='Put of unregistered object type';
  149. else ErrS:='';
  150. end;
  151. if ErrS<>'' then
  152. begin
  153. {$ifdef GABOR}{$ifdef TP}asm int 3;end;{$endif}{$endif}
  154. if Assigned(Application) then
  155. ErrorBox('Stream error: '+#13+ErrS,nil)
  156. else
  157. writeln('Error: ',ErrS);
  158. end;
  159. end;
  160. procedure DelTempFiles;
  161. begin
  162. DeleteFile(FPOutFileName);
  163. DeleteFile(FPErrFileName);
  164. DeleteFile(GDBOutFileName);
  165. DeleteFile(GDBOutPutFileName);
  166. DeleteFile(GREPOutName);
  167. DeleteFile(GREPErrName);
  168. end;
  169. procedure RegisterIDEObjects;
  170. begin
  171. RegisterApp;
  172. RegisterCodeComplete;
  173. RegisterCodeTemplates;
  174. {$ifndef FVISION}
  175. RegisterColorSel;
  176. RegisterAsciiTab;
  177. {$endif FVISION}
  178. RegisterDialogs;
  179. {$ifdef EDITORS}
  180. RegisterEditors;
  181. {$else}
  182. RegisterWEditor;
  183. RegisterWCEdit;
  184. {$endif}
  185. RegisterFPCalc;
  186. RegisterFPCompile;
  187. RegisterFPTools;
  188. RegisterFPViews;
  189. {$ifndef NODEBUG}
  190. RegisterFPDebugViews;
  191. {$endif}
  192. RegisterMenus;
  193. RegisterStdDlg;
  194. RegisterSymbols;
  195. RegisterObjects;
  196. RegisterValidate;
  197. RegisterViews;
  198. RegisterWHTMLScan;
  199. RegisterWUtils;
  200. RegisterWViews;
  201. end;
  202. var CanExit : boolean;
  203. SetJmpRes : longint;
  204. StoreExitProc : pointer;
  205. ErrS : String;
  206. P : record
  207. l1 : longint;
  208. s : pstring;
  209. end;
  210. {$ifdef win32}
  211. ShowMouseExe : string;
  212. {$endif win32}
  213. const
  214. ExitIntercepted : boolean = false;
  215. SeenExitCode : longint =0;
  216. SeenErrorAddr : pointer = nil;
  217. procedure InterceptExit;
  218. begin
  219. if StopJmpValid then
  220. begin
  221. ExitIntercepted:=true;
  222. SeenExitCode:=ExitCode;
  223. SeenErrorAddr:=ErrorAddr;
  224. LongJmp(StopJmp,1);
  225. end;
  226. end;
  227. BEGIN
  228. {$ifdef DEV}HeapLimit:=4096;{$endif}
  229. writeln('þ Free Pascal IDE Version '+VersionStr);
  230. {$ifdef win32}
  231. Win32ShowMouse;
  232. {$endif win32}
  233. ProcessParams(true);
  234. InitDirs;
  235. RegisterIDEObjects;
  236. StreamError:=@MyStreamError;
  237. ShowReadme:=ShowReadme or (LocateFile(INIFileName)='');
  238. {$ifdef VESA}
  239. InitVESAScreenModes;
  240. {$endif}
  241. InitRedir;
  242. {$ifndef NODEBUG}
  243. InitBreakpoints;
  244. InitWatches;
  245. {$endif}
  246. InitReservedWords;
  247. InitHelpFiles;
  248. InitSwitches;
  249. InitINIFile;
  250. InitUserScreen;
  251. InitTools;
  252. InitTemplates;
  253. InitCodeTemplates;
  254. InitCodeComplete;
  255. IDEApp.Init;
  256. CheckINIFile;
  257. ReadSwitches(SwitchesPath);
  258. { load all options after init because of open files }
  259. ReadINIFile;
  260. InitDesktopFile;
  261. LoadDesktop;
  262. ParseUserScreen;
  263. { why are the screen contents parsed at startup? Gabor }
  264. EnableCatchSignals;
  265. { Update IDE }
  266. IDEApp.Update;
  267. IDEApp.UpdateMode;
  268. IDEApp.UpdateTarget;
  269. ProcessParams(false);
  270. if ShowReadme then
  271. begin
  272. PutCommand(Application,evCommand,cmShowReadme,nil);
  273. ShowReadme:=false; { do not show next time }
  274. end;
  275. StoreExitProc:=ExitProc;
  276. ExitProc:=@InterceptExit;
  277. repeat
  278. SetJmpRes:=setjmp(StopJmp);
  279. StopJmpValid:=true;
  280. if SetJmpRes=0 then
  281. IDEApp.Run
  282. else
  283. begin
  284. if (SetJmpRes=1) and ExitIntercepted then
  285. begin
  286. { If ExitProc=@InterceptExit then
  287. ExitProc:=StoreExitProc;}
  288. Str(SeenExitCode,ErrS);
  289. if Assigned(Application) then
  290. begin
  291. P.l1:=SeenExitCode;
  292. ErrS:=hexstr(longint(SeenErrorAddr),8);
  293. P.s:=@ErrS;
  294. WarningBox(error_programexitedwitherror,@P);
  295. end
  296. else
  297. writeln('Abnormal exit error: ',ErrS);
  298. end
  299. else
  300. begin
  301. Str(SetJmpRes,ErrS);
  302. { Longjmp was called by fpcatch }
  303. if Assigned(Application) then
  304. begin
  305. P.l1:=SetJmpRes;
  306. WarningBox(error_programexitedwithsignal,@P);
  307. end
  308. else
  309. writeln('Signal error: ',ErrS);
  310. end;
  311. end;
  312. if (AutoSaveOptions and asEditorFiles)=0 then
  313. CanExit:=IDEApp.AskSaveAll
  314. else
  315. CanExit:=IDEApp.SaveAll;
  316. StopJmpValid:=false;
  317. until CanExit;
  318. If ExitProc=pointer(@InterceptExit) then
  319. ExitProc:=StoreExitProc;
  320. IDEApp.AutoSave;
  321. DoneDesktopFile;
  322. DelTempFiles;
  323. IDEApp.Done;
  324. WriteSwitches(SwitchesPath);
  325. DisableCatchSignals;
  326. DoneCodeComplete;
  327. DoneCodeTemplates;
  328. DoneTemplates;
  329. DoneTools;
  330. DoneUserScreen;
  331. DoneSwitches;
  332. DoneHelpFiles;
  333. DoneHelpFilesTypes;
  334. DoneReservedWords;
  335. DoneToolMessages;
  336. DoneBrowserCol;
  337. {$ifndef NODEBUG}
  338. DoneDebugger;
  339. DoneBreakpoints;
  340. DoneWatches;
  341. {$endif}
  342. {$ifdef fpc}
  343. {$ifdef unix}
  344. Video.ClearScreen;
  345. {$endif unix}
  346. Video.DoneVideo;
  347. Keyboard.DoneKeyboard;
  348. {$endif fpc}
  349. {$ifdef unix}
  350. Keyboard.RestoreStartMode;
  351. {$endif unix}
  352. StreamError:=nil;
  353. END.
  354. {
  355. $Log$
  356. Revision 1.6 2002-03-28 16:32:48 pierre
  357. * clearscrenn at exit for unix
  358. Revision 1.5 2002/03/20 14:56:41 pierre
  359. * correct last commit
  360. Revision 1.4 2002/03/20 14:53:37 pierre
  361. + rescue handlers in main loop
  362. Revision 1.3 2002/01/09 09:46:10 pierre
  363. * fix problems with -S option
  364. Revision 1.2 2001/08/05 12:23:00 peter
  365. * Automatically support for fvision or old fv
  366. Revision 1.1 2001/08/04 11:30:22 peter
  367. * ide works now with both compiler versions
  368. Revision 1.1.2.10 2001/03/27 12:39:27 pierre
  369. * Use RestoreStartMode function for Unix
  370. Revision 1.1.2.9 2001/03/20 00:20:41 pierre
  371. * fix some memory leaks + several small enhancements
  372. Revision 1.1.2.8 2001/03/14 17:57:07 pierre
  373. * fix invisible mouse problem for win32 on win9X
  374. Revision 1.1.2.7 2000/12/20 14:27:48 pierre
  375. * fp.ini for unix
  376. Revision 1.1.2.6 2000/12/13 16:56:41 pierre
  377. + -t option to specify tty for program run input/output for unix
  378. Revision 1.1.2.5 2000/11/29 00:54:44 pierre
  379. + preserve window number and save special windows
  380. Revision 1.1.2.4 2000/11/09 08:53:35 pierre
  381. + -F option to force use of only one graphic set
  382. Revision 1.1.2.3 2000/09/27 22:32:26 pierre
  383. * suppress lineinfo explicit in _uses
  384. Revision 1.1.2.2 2000/08/16 18:46:14 peter
  385. [*] double clicking on a droplistbox caused GPF (due to invalid recurson)
  386. [*] Make, Build now possible even in Compiler Messages Window
  387. [+] when started in a new dir the IDE now ask whether to create a local
  388. config, or to use the one located in the IDE dir
  389. Revision 1.1.2.1 2000/07/18 05:50:22 michael
  390. + Merged Gabors fixes
  391. Revision 1.1 2000/07/13 09:48:34 michael
  392. + Initial import
  393. Revision 1.47 2000/06/16 08:50:40 pierre
  394. + new bunch of Gabor's changes
  395. Revision 1.46 2000/05/29 10:44:56 pierre
  396. + New bunch of Gabor's changes: see fixes.txt
  397. Revision 1.45 2000/05/02 08:42:26 pierre
  398. * new set of Gabor changes: see fixes.txt
  399. Revision 1.44 2000/04/25 08:42:32 pierre
  400. * New Gabor changes : see fixes.txt
  401. Revision 1.43 2000/04/18 11:42:36 pierre
  402. lot of Gabor changes : see fixes.txt
  403. Revision 1.42 2000/03/21 23:34:10 pierre
  404. adapted to wcedit addition by Gabor
  405. Revision 1.41 2000/03/13 20:41:34 pierre
  406. + option -S to disable the mouse
  407. * adapted to changes in fpusrscr for DOS
  408. Revision 1.40 2000/03/07 21:58:58 pierre
  409. + uses ParseUserScreen and UpdateMode
  410. Revision 1.39 2000/02/12 23:58:26 carl
  411. + Conditional define explanaations
  412. Revision 1.38 2000/02/07 11:54:17 pierre
  413. + RegisterWUtils by Gabor
  414. Revision 1.37 2000/01/25 00:26:35 pierre
  415. + Browser info saving
  416. Revision 1.36 2000/01/10 15:53:37 pierre
  417. * WViews objects were not registered
  418. Revision 1.35 2000/01/03 11:38:33 michael
  419. Changes from Gabor
  420. Revision 1.34 1999/12/20 14:23:16 pierre
  421. * MyApp renamed IDEApp
  422. * TDebugController.ResetDebuggerRows added to
  423. get resetting of debugger rows
  424. Revision 1.33 1999/12/20 09:36:49 pierre
  425. * get the mouse visible on win32 fp
  426. Revision 1.32 1999/12/10 13:02:05 pierre
  427. + VideoMode save/restore
  428. Revision 1.31 1999/09/13 11:43:59 peter
  429. * fixes from gabor, idle event, html fix
  430. Revision 1.30 1999/08/22 22:24:15 pierre
  431. * avoid objpas paramstr functions
  432. Revision 1.29 1999/08/03 20:22:25 peter
  433. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  434. + Desktop saving should work now
  435. - History saved
  436. - Clipboard content saved
  437. - Desktop saved
  438. - Symbol info saved
  439. * syntax-highlight bug fixed, which compared special keywords case sensitive
  440. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  441. * with 'whole words only' set, the editor didn't found occourences of the
  442. searched text, if the text appeared previously in the same line, but didn't
  443. satisfied the 'whole-word' condition
  444. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  445. (ie. the beginning of the selection)
  446. * when started typing in a new line, but not at the start (X=0) of it,
  447. the editor inserted the text one character more to left as it should...
  448. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  449. * Shift shouldn't cause so much trouble in TCodeEditor now...
  450. * Syntax highlight had problems recognizing a special symbol if it was
  451. prefixed by another symbol character in the source text
  452. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  453. Revision 1.28 1999/07/10 01:24:11 pierre
  454. + First implementation of watches window
  455. Revision 1.27 1999/06/29 22:43:12 peter
  456. * try to add extensions to params
  457. Revision 1.26 1999/06/28 23:31:14 pierre
  458. * typo inside go32v2 cond error removed
  459. Revision 1.25 1999/06/28 19:25:34 peter
  460. * fixes from gabor
  461. Revision 1.24 1999/06/28 12:40:56 pierre
  462. + clear tool messages at exit
  463. Revision 1.23 1999/06/25 00:48:05 pierre
  464. + adds current target in menu at startup
  465. Revision 1.22 1999/05/22 13:44:28 peter
  466. * fixed couple of bugs
  467. Revision 1.21 1999/04/07 21:55:40 peter
  468. + object support for browser
  469. * html help fixes
  470. * more desktop saving things
  471. * NODEBUG directive to exclude debugger
  472. Revision 1.20 1999/03/23 16:16:36 peter
  473. * linux fixes
  474. Revision 1.19 1999/03/23 15:11:26 peter
  475. * desktop saving things
  476. * vesa mode
  477. * preferences dialog
  478. Revision 1.18 1999/03/21 22:51:35 florian
  479. + functional screen mode switching added
  480. Revision 1.17 1999/03/16 12:38:06 peter
  481. * tools macro fixes
  482. + tph writer
  483. + first things for resource files
  484. Revision 1.16 1999/03/12 01:13:01 peter
  485. * use TryToOpen() with parameter files to overcome double opened files
  486. at startup
  487. Revision 1.15 1999/03/08 14:58:08 peter
  488. + prompt with dialogs for tools
  489. Revision 1.14 1999/03/05 17:53:00 pierre
  490. + saving and opening of open files on exit
  491. Revision 1.13 1999/03/01 15:41:48 peter
  492. + Added dummy entries for functions not yet implemented
  493. * MenuBar didn't update itself automatically on command-set changes
  494. * Fixed Debugging/Profiling options dialog
  495. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  496. set
  497. * efBackSpaceUnindents works correctly
  498. + 'Messages' window implemented
  499. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  500. + Added TP message-filter support (for ex. you can call GREP thru
  501. GREP2MSG and view the result in the messages window - just like in TP)
  502. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  503. so topic search didn't work...
  504. * In FPHELP.PAS there were still context-variables defined as word instead
  505. of THelpCtx
  506. * StdStatusKeys() was missing from the statusdef for help windows
  507. + Topic-title for index-table can be specified when adding a HTML-files
  508. Revision 1.12 1999/02/20 15:18:25 peter
  509. + ctrl-c capture with confirm dialog
  510. + ascii table in the tools menu
  511. + heapviewer
  512. * empty file fixed
  513. * fixed callback routines in fpdebug to have far for tp7
  514. Revision 1.11 1999/02/18 13:44:30 peter
  515. * search fixed
  516. + backward search
  517. * help fixes
  518. * browser updates
  519. Revision 1.10 1999/02/15 09:07:10 pierre
  520. * HEAPTRC conditionnal renamed IDEHEAPTRC
  521. Revision 1.9 1999/02/10 09:55:43 pierre
  522. + Memory tracing if compiled with -dHEAPTRC
  523. * Many memory leaks removed
  524. Revision 1.8 1999/02/08 09:30:59 florian
  525. + some split heap stuff, in $ifdef TEMPHEAP
  526. Revision 1.7 1999/02/05 13:51:38 peter
  527. * unit name of FPSwitches -> FPSwitch which is easier to use
  528. * some fixes for tp7 compiling
  529. Revision 1.6 1999/01/21 11:54:10 peter
  530. + tools menu
  531. + speedsearch in symbolbrowser
  532. * working run command
  533. Revision 1.5 1999/01/12 14:29:31 peter
  534. + Implemented still missing 'switch' entries in Options menu
  535. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  536. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  537. ASCII chars and inserted directly in the text.
  538. + Added symbol browser
  539. * splitted fp.pas to fpide.pas
  540. }