fpini.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Write/Read Options to INI File
  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. unit FPIni;
  13. interface
  14. uses
  15. FPUtils;
  16. procedure InitDirs;
  17. procedure InitINIFile;
  18. procedure CheckINIFile;
  19. function ReadINIFile: boolean;
  20. function WriteINIFile(FromSaveAs : boolean) : boolean;
  21. implementation
  22. uses
  23. Dos,Objects,Drivers,
  24. {$ifdef FVISION}
  25. FVConsts,
  26. {$else}
  27. Commands,
  28. {$endif}
  29. Version,
  30. {$ifdef USE_EXTERNAL_COMPILER}
  31. fpintf, { superseeds version_string of version unit }
  32. {$endif USE_EXTERNAL_COMPILER}
  33. WConsts,WUtils,WINI,WViews,{$ifndef EDITORS}WEditor,WCEdit{$else}Editors{$endif},
  34. {$ifndef NODEBUG}FPDebug,{$endif}FPConst,FPVars,
  35. FPIntf,FPTools,FPSwitch,FPString;
  36. const
  37. { INI file sections }
  38. secFiles = 'Files';
  39. secRun = 'Run';
  40. secCompile = 'Compile';
  41. secColors = 'Colors';
  42. secHelp = 'Help';
  43. secEditor = 'Editor';
  44. secBreakpoint = 'Breakpoints';
  45. secWatches = 'Watches';
  46. secHighlight = 'Highlight';
  47. secMouse = 'Mouse';
  48. secSearch = 'Search';
  49. secTools = 'Tools';
  50. secSourcePath = 'SourcePath';
  51. secPreferences = 'Preferences';
  52. secMisc = 'Misc';
  53. { INI file tags }
  54. ieRecentFile = 'RecentFile';
  55. (* ieOpenFile = 'OpenFile';
  56. ieOpenFileCount = 'OpenFileCount'; *)
  57. ieRunParameters = 'Parameters';
  58. ieDebuggeeRedir = 'DebugRedirection';
  59. iePrimaryFile = 'PrimaryFile';
  60. ieCompileMode = 'CompileMode';
  61. iePalette = 'Palette';
  62. ieHelpFiles = 'Files';
  63. ieDefaultTabSize = 'DefaultTabSize';
  64. ieDefaultIndentSize = 'DefaultIndentSize';
  65. ieDefaultEditorFlags='DefaultFlags';
  66. ieDefaultSaveExt = 'DefaultSaveExt';
  67. ieOpenExts = 'OpenExts';
  68. ieHighlightExts = 'Exts';
  69. ieTabsPattern = 'NeedsTabs';
  70. ieDoubleClickDelay = 'DoubleDelay';
  71. ieReverseButtons = 'ReverseButtons';
  72. ieAltClickAction = 'AltClickAction';
  73. ieCtrlClickAction = 'CtrlClickAction';
  74. ieFindFlags = 'FindFlags';
  75. ieToolName = 'Title';
  76. ieToolProgram = 'Program';
  77. ieToolParams = 'Params';
  78. ieToolHotKey = 'HotKey';
  79. ieBreakpointTyp = 'Type';
  80. ieBreakpointCount = 'Count';
  81. ieBreakpointState = 'State';
  82. ieBreakpointName = 'Name';
  83. ieBreakpointFile = 'FileName';
  84. ieBreakpointLine = 'LineNumber';
  85. ieBreakpointCond = 'Condition';
  86. ieWatchCount = 'Count';
  87. ieWatchName = 'Watch';
  88. ieSourceList = 'SourceList';
  89. { ieVideoMode = 'VideoMode';}
  90. ieAutoSave = 'AutoSaveFlags';
  91. ieMiscOptions = 'MiscOptions';
  92. ieDesktopLocation = 'DesktopLocation';
  93. ieDesktopFlags = 'DesktopFileFlags';
  94. ieCenterDebuggerRow= 'CenterCurrentLineWhileDebugging';
  95. ieShowReadme = 'ShowReadme';
  96. Procedure InitDirs;
  97. begin
  98. StartupDir:=CompleteDir(FExpand('.'));
  99. {$ifndef unix}
  100. IDEDir:=CompleteDir(DirOf(system.Paramstr(0)));
  101. {$else}
  102. SystemIDEDir:='/usr/lib/fpc/'+version_string+'/ide/text';
  103. IDEdir:=CompleteDir(FExpand('~/.fp'));
  104. If Not ExistsDir(IDEdir) Then
  105. begin
  106. IDEDir:=SystemIDEDir;
  107. if Not ExistsDir(IDEDir) then
  108. begin
  109. if DirOf(system.paramstr(0))<>'' then
  110. IDEDir:=CompleteDir(DirOf(system.ParamStr(0)))
  111. else
  112. IDEDir:=StartupDir;
  113. end;
  114. end;
  115. {$endif}
  116. end;
  117. procedure InitINIFile;
  118. var S: string;
  119. begin
  120. S:=LocateFile(INIFileName);
  121. if S<>'' then
  122. IniFileName:=S;
  123. IniFileName:=FExpand(IniFileName);
  124. end;
  125. procedure CheckINIFile;
  126. var IniDir,CurDir: DirStr;
  127. INI: PINIFile;
  128. const Btns : array[1..2] of longstring = (btn_config_copyexisting,btn_config_createnew);
  129. begin
  130. IniDir:=DirOf(IniFileName); CurDir:=GetCurDir;
  131. if CompareText(IniDir,CurDir)<>0 then
  132. if not ExistsFile(CurDir+DirInfoName) then
  133. if ConfirmBox(FormatStrStr(msg_doyouwanttocreatelocalconfigfile,IniDir),nil,false)=cmYes then
  134. begin
  135. if (not ExistsFile(IniFileName)) or
  136. (ChoiceBox(msg_configcopyexistingorcreatenew,nil,
  137. Btns,false)=cmUserBtn2) then
  138. begin
  139. { create new config here }
  140. IniFileName:=CurDir+IniName;
  141. SwitchesPath:=CurDir+SwitchesName;
  142. end
  143. else
  144. begin
  145. { copy config here }
  146. if CopyFile(IniFileName,CurDir+IniName)=false then
  147. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+IniName),nil)
  148. else
  149. IniFileName:=CurDir+IniName;
  150. if CopyFile(SwitchesPath,CurDir+SwitchesName)=false then
  151. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+SwitchesName),nil)
  152. else
  153. SwitchesPath:=CurDir+SwitchesName;
  154. end;
  155. end
  156. else
  157. begin
  158. New(INI, Init(CurDir+DirInfoName));
  159. INI^.SetEntry(MainSectionName,'Comment','Do NOT delete this file!!!');
  160. if INI^.Update=false then
  161. ErrorBox(FormatStrStr(msg_errorwritingfile,INI^.GetFileName),nil);
  162. Dispose(INI, Done);
  163. end;
  164. end;
  165. function PaletteToStr(S: string): string;
  166. var C: string;
  167. I: integer;
  168. begin
  169. C:='';
  170. for I:=1 to length(S) do
  171. begin
  172. Insert('#$'+IntToHex(ord(S[I]),2),C,Length(C)+1);
  173. end;
  174. PaletteToStr:=C;
  175. end;
  176. function StrToPalette(S: string): string;
  177. var I,P,X: integer;
  178. C: string;
  179. Hex: boolean;
  180. OK: boolean;
  181. begin
  182. C:=''; I:=1;
  183. OK:=S<>'';
  184. while OK and (I<=length(S)) and (S[I]='#') do
  185. begin
  186. Inc(I); Hex:=false;
  187. if S[I]='$' then begin Inc(I); Hex:=true; end;
  188. P:=Pos('#',copy(S,I,High(S))); if P>0 then P:=I+P-1 else P:=length(S)+1;
  189. if Hex=false then
  190. begin
  191. X:=StrToInt(copy(S,I,P-I));
  192. OK:=(LastStrToIntResult=0) and (0<=X) and (X<=High(S));
  193. end
  194. else
  195. begin
  196. X:=HexToInt(copy(S,I,P-I));
  197. OK:=(LastHexToIntResult=0) and (0<=X) and (X<=255);
  198. end;
  199. if OK then C:=C+chr(X);
  200. Inc(I,P-I);
  201. end;
  202. StrToPalette:=C;
  203. end;
  204. {$ifndef NODEBUG}
  205. procedure WriteOneWatchEntry(I : Longint;INIFile : PINIFile);
  206. var
  207. PW : PWatch;
  208. S : String;
  209. begin
  210. Str(I,S);
  211. PW:=WatchesCollection^.At(I);
  212. With PW^ do
  213. begin
  214. INIFile^.SetEntry(secWatches,ieWatchName+S,GetStr(expr));
  215. end;
  216. end;
  217. procedure WriteOneBreakPointEntry(I : longint;INIFile : PINIFile);
  218. var PB : PBreakpoint;
  219. S : String;
  220. begin
  221. Str(I,S);
  222. PB:=BreakpointsCollection^.At(I);
  223. If assigned(PB) then
  224. With PB^ do
  225. Begin
  226. INIFile^.SetEntry(secBreakpoint,ieBreakpointTyp+S,BreakpointTypeStr[typ]);
  227. INIFile^.SetEntry(secBreakpoint,ieBreakpointState+S,BreakpointStateStr[state]);
  228. if typ=bt_file_line then
  229. begin
  230. INIFile^.SetEntry(secBreakpoint,ieBreakpointFile+S,FileName^);
  231. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointLine+S,Line);
  232. end
  233. else
  234. INIFile^.SetEntry(secBreakpoint,ieBreakpointName+S,Name^);
  235. if assigned(Conditions) then
  236. INIFile^.SetEntry(secBreakpoint,ieBreakpointCond+S,Conditions^);
  237. end;
  238. end;
  239. procedure ReadOneWatchEntry(I : Longint;INIFile : PINIFile);
  240. var
  241. PW : PWatch;
  242. S : String;
  243. begin
  244. Str(I,S);
  245. PW:=new(PWatch,Init(INIFile^.GetEntry(secWatches,ieWatchName+S,'')));
  246. WatchesCollection^.Insert(PW);
  247. end;
  248. procedure ReadOneBreakPointEntry(i : longint;INIFile : PINIFile);
  249. var PB : PBreakpoint;
  250. S,S2,SC : string;
  251. Line : longint;
  252. typ : BreakpointType;
  253. state : BreakpointState;
  254. begin
  255. Str(I,S2);
  256. typ:=bt_invalid;
  257. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointTyp+S2,BreakpointTypeStr[typ]);
  258. for typ:=low(BreakpointType) to high(BreakpointType) do
  259. If pos(BreakpointTypeStr[typ],S)>0 then break;
  260. state:=bs_deleted;
  261. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointState+S2,BreakpointStateStr[state]);
  262. for state:=low(BreakpointState) to high(BreakpointState) do
  263. If pos(BreakpointStateStr[state],S)>0 then break;
  264. case typ of
  265. bt_invalid :;
  266. bt_file_line :
  267. begin
  268. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointFile+S2,'');
  269. Line:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointLine+S2,0);
  270. end;
  271. else
  272. begin
  273. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointName+S2,'');
  274. end;
  275. end;
  276. SC:=INIFile^.GetEntry(secBreakpoint,ieBreakpointCond+S2,'');
  277. if (typ=bt_function) and (S<>'') then
  278. new(PB,init_function(S))
  279. else if (typ=bt_file_line) and (S<>'') then
  280. new(PB,init_file_line(S,Line))
  281. else
  282. new(PB,init_type(typ,S));
  283. If assigned(PB) then
  284. begin
  285. PB^.state:=state;
  286. If SC<>'' then
  287. PB^.conditions:=NewStr(SC);
  288. BreakpointsCollection^.Insert(PB);
  289. end;
  290. end;
  291. {$endif NODEBUG}
  292. function ReadINIFile: boolean;
  293. var INIFile: PINIFile;
  294. S,PS,S1,S2,S3: string;
  295. I,P: integer;
  296. BreakPointCount,WatchesCount:longint;
  297. OK: boolean;
  298. ts : TSwitchMode;
  299. W: word;
  300. begin
  301. OK:=ExistsFile(IniFileName);
  302. if OK then
  303. begin
  304. New(INIFile, Init(IniFileName));
  305. { Files }
  306. OpenExts:=INIFile^.GetEntry(secFiles,ieOpenExts,OpenExts);
  307. RecentFileCount:=High(RecentFiles);
  308. for I:=Low(RecentFiles) to High(RecentFiles) do
  309. begin
  310. S:=INIFile^.GetEntry(secFiles,ieRecentFile+IntToStr(I),'');
  311. if (S='') and (RecentFileCount>I-1) then RecentFileCount:=I-1;
  312. with RecentFiles[I] do
  313. begin
  314. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  315. FileName:=copy(S,1,P-1); Delete(S,1,P);
  316. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  317. LastPos.X:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  318. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  319. LastPos.Y:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  320. end;
  321. end;
  322. { Run }
  323. { First read the primary file, which can also set the parameters which can
  324. be overruled with the parameter loading }
  325. SetPrimaryFile(INIFile^.GetEntry(secCompile,iePrimaryFile,PrimaryFile));
  326. SetRunParameters(INIFile^.GetEntry(secRun,ieRunParameters,GetRunParameters));
  327. {$ifndef GABOR}
  328. DebuggeeTTY := INIFile^.GetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  329. {$endif}
  330. { Compile }
  331. S:=INIFile^.GetEntry(secCompile,ieCompileMode,'');
  332. for ts:=low(TSwitchMode) to high(TSwitchMode) do
  333. begin
  334. if SwitchesModeStr[ts]=S then
  335. SwitchesMode:=ts;
  336. end;
  337. { Help }
  338. S:=INIFile^.GetEntry(secHelp,ieHelpFiles,'');
  339. repeat
  340. P:=Pos(';',S); if P=0 then P:=length(S)+1;
  341. PS:=copy(S,1,P-1);
  342. if PS<>'' then HelpFiles^.Insert(NewStr(PS));
  343. Delete(S,1,P);
  344. until S='';
  345. { Editor }
  346. {$ifndef EDITORS}
  347. DefaultTabSize:=INIFile^.GetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  348. DefaultIndentSize:=INIFile^.GetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  349. DefaultCodeEditorFlags:=INIFile^.GetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  350. DefaultSaveExt:=INIFile^.GetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  351. {$endif}
  352. { Highlight }
  353. HighlightExts:=INIFile^.GetEntry(secHighlight,ieHighlightExts,HighlightExts);
  354. TabsPattern:=INIFile^.GetEntry(secHighlight,ieTabsPattern,TabsPattern);
  355. { SourcePath }
  356. SourceDirs:=INIFile^.GetEntry(secSourcePath,ieSourceList,SourceDirs);
  357. { Mouse }
  358. DoubleDelay:=INIFile^.GetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  359. MouseReverse:=boolean(INIFile^.GetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse)));
  360. AltMouseAction:=INIFile^.GetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  361. CtrlMouseAction:=INIFile^.GetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  362. { Search }
  363. FindFlags:=INIFile^.GetIntEntry(secSearch,ieFindFlags,FindFlags);
  364. { Breakpoints }
  365. {$ifndef NODEBUG}
  366. BreakpointCount:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointCount,0);
  367. for i:=1 to BreakpointCount do
  368. ReadOneBreakPointEntry(i-1,INIFile);
  369. WatchesCount:=INIFile^.GetIntEntry(secWatches,ieWatchCount,0);
  370. for i:=1 to WatchesCount do
  371. ReadOneWatchEntry(i-1,INIFile);
  372. {$endif}
  373. { Tools }
  374. for I:=1 to MaxToolCount do
  375. begin
  376. S:=IntToStr(I);
  377. S1:=INIFile^.GetEntry(secTools,ieToolName+S,'');
  378. if S1='' then Break; { !!! }
  379. S2:=INIFile^.GetEntry(secTools,ieToolProgram+S,'');
  380. S3:=INIFile^.GetEntry(secTools,ieToolParams+S,'');
  381. W:=Max(0,Min(65535,INIFile^.GetIntEntry(secTools,ieToolHotKey+S,0)));
  382. AddTool(S1,S2,S3,W);
  383. end;
  384. { Colors }
  385. S:=AppPalette;
  386. PS:=StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40))));
  387. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40))));
  388. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40))));
  389. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40))));
  390. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
  391. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
  392. if length(PS)<length(CIDEAppColor) then
  393. PS:=PS+copy(CIDEAppColor,length(PS)+1,255);
  394. AppPalette:=PS;
  395. (* { Open files }
  396. for I:=INIFile^.GetIntEntry(secFiles,ieOpenFileCount,0) downto 1 do
  397. begin
  398. S:=INIFile^.GetEntry(secFiles,ieOpenFile+IntToStr(I),'');
  399. if (S='') then
  400. break;
  401. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  402. S1:=copy(S,1,P-1);
  403. Delete(S,1,P);
  404. P:=Pos(',',S);
  405. if P=0 then P:=length(S)+1;
  406. X:=Max(0,StrToInt(copy(S,1,P-1)));
  407. Delete(S,1,P);
  408. P:=Pos(',',S);
  409. if P=0 then P:=length(S)+1;
  410. Y:=Max(0,StrToInt(copy(S,1,P-1)));
  411. Delete(S,1,P);
  412. P:=Pos(',',S);
  413. if P=0 then P:=length(S)+1;
  414. R.A.X:=Max(0,StrToInt(copy(S,1,P-1)));
  415. Delete(S,1,P);
  416. P:=Pos(',',S);
  417. if P=0 then P:=length(S)+1;
  418. R.A.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  419. Delete(S,1,P);
  420. P:=Pos(',',S);
  421. if P=0 then P:=length(S)+1;
  422. R.B.X:=Max(0,StrToInt(copy(S,1,P-1)));
  423. Delete(S,1,P);
  424. P:=Pos(',',S);
  425. if P=0 then P:=length(S)+1;
  426. R.B.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  427. if (R.A.X<R.B.X) and (R.A.Y<R.B.Y) then
  428. TryToOpenFile(@R,S1,X,Y,false)
  429. else
  430. TryToOpenFile(nil,S1,X,Y,false);
  431. { remove it because otherwise we allways keep old files }
  432. INIFile^.DeleteEntry(secFiles,ieOpenFile+IntToStr(I));
  433. end;
  434. *)
  435. { Desktop }
  436. DesktopFileFlags:=INIFile^.GetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  437. { Debugger }
  438. IniCenterDebuggerRow:=INIFile^.GetIntEntry(secPreferences,ieCenterDebuggerRow,1)<>0;
  439. { Preferences }
  440. AutoSaveOptions:=INIFile^.GetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  441. MiscOptions:=INIFile^.GetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  442. DesktopLocation:=INIFile^.GetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  443. { Misc }
  444. ShowReadme:=INIFile^.GetIntEntry(secMisc,ieShowReadme,{integer(ShowReadme)}1)<>0;
  445. Dispose(INIFile, Done);
  446. end;
  447. ReadINIFile:=OK;
  448. end;
  449. function WriteINIFile (FromSaveAs : boolean): boolean;
  450. var INIFile: PINIFile;
  451. S: string;
  452. S1,S2,S3: string;
  453. W: word;
  454. BreakPointCount,WatchesCount:longint;
  455. I(*,OpenFileCount*): integer;
  456. OK: boolean;
  457. procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
  458. begin
  459. if (S<>'') then S:=S+';';
  460. S:=S+P^;
  461. end;
  462. begin
  463. {$ifdef Unix}
  464. if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) then
  465. begin
  466. IniFileName:=FExpand('~/.fp/'+IniName);
  467. If not ExistsDir(DirOf(IniFileName)) then
  468. MkDir(FExpand('~/.fp'));
  469. end;
  470. {$endif Unix}
  471. New(INIFile, Init(IniFileName));
  472. { Files }
  473. { avoid keeping old files }
  474. INIFile^.DeleteSection(secFiles);
  475. INIFile^.SetEntry(secFiles,ieOpenExts,'"'+OpenExts+'"');
  476. for I:=1 to High(RecentFiles) do
  477. begin
  478. if I<=RecentFileCount then
  479. with RecentFiles[I] do S:=FileName+','+IntToStr(LastPos.X)+','+IntToStr(LastPos.Y)
  480. else
  481. S:='';
  482. INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
  483. end;
  484. (*
  485. PW:=FirstEditorWindow;
  486. PPW:=PW;
  487. I:=1;
  488. while assigned(PW) do
  489. begin
  490. If PW^.HelpCtx=hcSourceWindow then
  491. begin
  492. With PW^.editor^ do
  493. S:=FileName+','+IntToStr(CurPos.X)+','+IntToStr(CurPos.Y);
  494. PW^.GetBounds(R);
  495. S:=S+','+IntToStr(R.A.X)+','+IntToStr(R.A.Y)+','+
  496. IntToStr(R.B.X)+','+IntToStr(R.B.Y);
  497. INIFile^.SetEntry(secFiles,ieOpenFile+IntToStr(I),S);
  498. Inc(I);
  499. OpenFileCount:=I-1;
  500. end;
  501. PW:=PSourceWindow(PW^.next);
  502. While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
  503. PW:=PSourceWindow(PW^.next);
  504. If PW=PPW then
  505. break;
  506. end;
  507. INIFile^.SetIntEntry(secFiles,ieOpenFileCount,OpenFileCount);
  508. *)
  509. { Run }
  510. INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
  511. {$ifndef GABOR}
  512. { If DebuggeeTTY<>'' then }
  513. INIFile^.SetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  514. {$endif}
  515. { Compile }
  516. INIFile^.SetEntry(secCompile,iePrimaryFile,PrimaryFile);
  517. INIFile^.SetEntry(secCompile,ieCompileMode,SwitchesModeStr[SwitchesMode]);
  518. { Help }
  519. S:='';
  520. HelpFiles^.ForEach(@ConcatName);
  521. INIFile^.SetEntry(secHelp,ieHelpFiles,'"'+S+'"');
  522. { Editor }
  523. {$ifndef EDITORS}
  524. INIFile^.SetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  525. INIFile^.SetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  526. INIFile^.SetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  527. INIFile^.SetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  528. {$endif}
  529. { Highlight }
  530. INIFile^.SetEntry(secHighlight,ieHighlightExts,'"'+HighlightExts+'"');
  531. INIFile^.SetEntry(secHighlight,ieTabsPattern,'"'+TabsPattern+'"');
  532. { SourcePath }
  533. INIFile^.SetEntry(secSourcePath,ieSourceList,'"'+SourceDirs+'"');
  534. { Mouse }
  535. INIFile^.SetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  536. INIFile^.SetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse));
  537. INIFile^.SetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  538. INIFile^.SetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  539. { Search }
  540. INIFile^.SetIntEntry(secSearch,ieFindFlags,FindFlags);
  541. { Breakpoints }
  542. {$ifndef NODEBUG}
  543. BreakPointCount:=BreakpointsCollection^.Count;
  544. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointCount,BreakpointCount);
  545. for i:=1 to BreakpointCount do
  546. WriteOneBreakPointEntry(I-1,INIFile);
  547. WatchesCount:=WatchesCollection^.Count;
  548. INIFile^.SetIntEntry(secWatches,ieWatchCount,WatchesCount);
  549. for i:=1 to WatchesCount do
  550. WriteOneWatchEntry(I-1,INIFile);
  551. {$endif}
  552. { Tools }
  553. INIFile^.DeleteSection(secTools);
  554. for I:=1 to GetToolCount do
  555. begin
  556. S:=IntToStr(I);
  557. GetToolParams(I-1,S1,S2,S3,W);
  558. if S1<>'' then S1:='"'+S1+'"';
  559. if S2<>'' then S2:='"'+S2+'"';
  560. if S3<>'' then S3:='"'+S3+'"';
  561. INIFile^.SetEntry(secTools,ieToolName+S,S1);
  562. INIFile^.SetEntry(secTools,ieToolProgram+S,S2);
  563. INIFile^.SetEntry(secTools,ieToolParams+S,S3);
  564. INIFile^.SetIntEntry(secTools,ieToolHotKey+S,W);
  565. end;
  566. { Colors }
  567. if AppPalette<>CIDEAppColor then
  568. begin
  569. { this has a bug. if a different palette has been read on startup, and
  570. then changed back to match the default, this will not update it in the
  571. ini file, eg. the original (non-default) will be left unmodified... }
  572. S:=AppPalette;
  573. INIFile^.SetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40)));
  574. INIFile^.SetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40)));
  575. INIFile^.SetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40)));
  576. INIFile^.SetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40)));
  577. INIFile^.SetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40)));
  578. INIFile^.SetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40)));
  579. end;
  580. { Desktop }
  581. INIFile^.SetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  582. INIFile^.SetIntEntry(secPreferences,ieCenterDebuggerRow,byte(IniCenterDebuggerRow));
  583. { Preferences }
  584. INIFile^.SetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  585. INIFile^.SetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  586. INIFile^.SetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  587. { Misc }
  588. INIFile^.SetIntEntry(secMisc,ieShowReadme,integer(ShowReadme));
  589. OK:=INIFile^.Update;
  590. Dispose(INIFile, Done);
  591. WriteINIFile:=OK;
  592. end;
  593. end.
  594. {
  595. $Log$
  596. Revision 1.4 2002-04-02 14:06:50 pierre
  597. * avoid a problem if resetting debuggee redirection
  598. Revision 1.3 2001/08/12 00:04:50 pierre
  599. * some speed improvements for string operations
  600. Revision 1.2 2001/08/05 02:01:48 peter
  601. * FVISION define to compile with fvision units
  602. Revision 1.1 2001/08/04 11:30:23 peter
  603. * ide works now with both compiler versions
  604. Revision 1.1.2.8 2001/03/08 16:39:22 pierre
  605. use external compiler version if compiler external
  606. Revision 1.1.2.7 2000/12/20 14:27:49 pierre
  607. * fp.ini for unix
  608. Revision 1.1.2.6 2000/12/09 17:41:20 florian
  609. * IndentSize is stored in the .INI file now
  610. Revision 1.1.2.5 2000/11/13 16:59:09 pierre
  611. * some function in double removed from fputils unit
  612. Revision 1.1.2.4 2000/10/18 21:53:27 pierre
  613. * several Gabor fixes
  614. Revision 1.1.2.3 2000/10/06 22:52:35 pierre
  615. * fixes for linux GDB tty command
  616. Revision 1.1.2.2 2000/08/16 18:46:14 peter
  617. [*] double clicking on a droplistbox caused GPF (due to invalid recurson)
  618. [*] Make, Build now possible even in Compiler Messages Window
  619. [+] when started in a new dir the IDE now ask whether to create a local
  620. config, or to use the one located in the IDE dir
  621. Revision 1.1.2.1 2000/07/20 11:02:15 michael
  622. + Fixes from gabor. See fixes.txt
  623. Revision 1.1 2000/07/13 09:48:34 michael
  624. + Initial import
  625. Revision 1.30 2000/06/22 09:07:12 pierre
  626. * Gabor changes: see fixes.txt
  627. Revision 1.29 2000/06/16 08:50:41 pierre
  628. + new bunch of Gabor's changes
  629. Revision 1.28 2000/03/21 23:30:22 pierre
  630. adapted to wcedit addition by Gabor
  631. Revision 1.27 2000/03/13 20:38:02 pierre
  632. IniPath removed and IniFileName moved to fpvars unit
  633. Revision 1.26 2000/02/04 00:08:35 pierre
  634. + IniCenterDebuggerRow
  635. Revision 1.25 1999/11/05 13:47:19 pierre
  636. * Breakpoint conditions were not reloaded correctly
  637. Revision 1.24 1999/09/16 14:34:59 pierre
  638. + TBreakpoint and TWatch registering
  639. + WatchesCollection and BreakpointsCollection stored in desk file
  640. * Syntax highlighting was broken
  641. Revision 1.23 1999/09/13 16:24:43 peter
  642. + clock
  643. * backspace unident like tp7
  644. Revision 1.22 1999/09/07 09:21:54 pierre
  645. + Watches saved
  646. Revision 1.21 1999/08/03 20:22:33 peter
  647. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  648. + Desktop saving should work now
  649. - History saved
  650. - Clipboard content saved
  651. - Desktop saved
  652. - Symbol info saved
  653. * syntax-highlight bug fixed, which compared special keywords case sensitive
  654. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  655. * with 'whole words only' set, the editor didn't found occourences of the
  656. searched text, if the text appeared previously in the same line, but didn't
  657. satisfied the 'whole-word' condition
  658. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  659. (ie. the beginning of the selection)
  660. * when started typing in a new line, but not at the start (X=0) of it,
  661. the editor inserted the text one character more to left as it should...
  662. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  663. * Shift shouldn't cause so much trouble in TCodeEditor now...
  664. * Syntax highlight had problems recognizing a special symbol if it was
  665. prefixed by another symbol character in the source text
  666. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  667. Revision 1.20 1999/06/28 12:36:51 pierre
  668. * avoid keeping old open file names
  669. Revision 1.19 1999/04/07 21:55:48 peter
  670. + object support for browser
  671. * html help fixes
  672. * more desktop saving things
  673. * NODEBUG directive to exclude debugger
  674. Revision 1.18 1999/03/23 15:11:31 peter
  675. * desktop saving things
  676. * vesa mode
  677. * preferences dialog
  678. Revision 1.17 1999/03/12 01:13:58 peter
  679. * flag if trytoopen should look for other extensions
  680. + browser tab in the tools-compiler
  681. Revision 1.16 1999/03/08 14:58:09 peter
  682. + prompt with dialogs for tools
  683. Revision 1.15 1999/03/05 17:53:02 pierre
  684. + saving and opening of open files on exit
  685. Revision 1.14 1999/03/01 15:41:55 peter
  686. + Added dummy entries for functions not yet implemented
  687. * MenuBar didn't update itself automatically on command-set changes
  688. * Fixed Debugging/Profiling options dialog
  689. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  690. set
  691. * efBackSpaceUnindents works correctly
  692. + 'Messages' window implemented
  693. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  694. + Added TP message-filter support (for ex. you can call GREP thru
  695. GREP2MSG and view the result in the messages window - just like in TP)
  696. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  697. so topic search didn't work...
  698. * In FPHELP.PAS there were still context-variables defined as word instead
  699. of THelpCtx
  700. * StdStatusKeys() was missing from the statusdef for help windows
  701. + Topic-title for index-table can be specified when adding a HTML-files
  702. Revision 1.13 1999/02/22 02:15:14 peter
  703. + default extension for save in the editor
  704. + Separate Text to Find for the grep dialog
  705. * fixed redir crash with tp7
  706. Revision 1.12 1999/02/19 18:43:46 peter
  707. + open dialog supports mask list
  708. Revision 1.11 1999/02/10 09:53:14 pierre
  709. * better storing of breakpoints
  710. Revision 1.10 1999/02/05 13:08:42 pierre
  711. + new breakpoint types added
  712. Revision 1.9 1999/02/05 12:11:55 pierre
  713. + SourceDir that stores directories for sources that the
  714. compiler should not know about
  715. Automatically asked for addition when a new file that
  716. needed filedialog to be found is in an unknown directory
  717. Stored and retrieved from INIFile
  718. + Breakpoints conditions added to INIFile
  719. * Breakpoints insterted and removed at debin and end of debug session
  720. Revision 1.8 1999/02/04 17:52:38 pierre
  721. * bs_invalid renamed bs_deleted
  722. Revision 1.7 1999/02/04 17:19:24 peter
  723. * linux fixes
  724. Revision 1.6 1999/02/04 13:32:04 pierre
  725. * Several things added (I cannot commit them independently !)
  726. + added TBreakpoint and TBreakpointCollection
  727. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  728. + Breakpoint list in INIFile
  729. * Select items now also depend of SwitchMode
  730. * Reading of option '-g' was not possible !
  731. + added search for -Fu args pathes in TryToOpen
  732. + added code for automatic opening of FileDialog
  733. if source not found
  734. Revision 1.5 1999/01/21 11:54:15 peter
  735. + tools menu
  736. + speedsearch in symbolbrowser
  737. * working run command
  738. Revision 1.4 1999/01/04 11:49:45 peter
  739. * 'Use tab characters' now works correctly
  740. + Syntax highlight now acts on File|Save As...
  741. + Added a new class to syntax highlight: 'hex numbers'.
  742. * There was something very wrong with the palette managment. Now fixed.
  743. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  744. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  745. process revised
  746. Revision 1.1 1998/12/28 15:47:45 peter
  747. + Added user screen support, display & window
  748. + Implemented Editor,Mouse Options dialog
  749. + Added location of .INI and .CFG file
  750. + Option (INI) file managment implemented (see bottom of Options Menu)
  751. + Switches updated
  752. + Run program
  753. }