cobjects.pas 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This module provides some basic objects
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$ifdef tp}
  19. {$E+,N+,D+,F+}
  20. {$endif}
  21. {$I-}
  22. {$R-}{ necessary for crc calculation }
  23. unit cobjects;
  24. { define OLDSPEEDVALUE}
  25. interface
  26. uses
  27. {$ifdef DELPHI4}
  28. dmisc,
  29. sysutils
  30. {$else DELPHI4}
  31. strings
  32. {$ifndef linux}
  33. ,dos
  34. {$else}
  35. ,linux
  36. {$endif}
  37. {$endif DELPHI4}
  38. ;
  39. const
  40. { the real size will be [-hasharray..hasharray] ! }
  41. {$ifdef TP}
  42. hasharraysize = 127;
  43. {$else}
  44. hasharraysize = 2047;
  45. {$endif}
  46. type
  47. pstring = ^string;
  48. {$ifdef TP}
  49. { redeclare dword only in case of emergency, some small things
  50. of the compiler won't work then correctly (FK)
  51. }
  52. dword = longint;
  53. {$endif TP}
  54. pfileposinfo = ^tfileposinfo;
  55. tfileposinfo = record
  56. line : longint;
  57. column : word;
  58. fileindex : word;
  59. end;
  60. pmemdebug = ^tmemdebug;
  61. tmemdebug = object
  62. constructor init(const s:string);
  63. destructor done;
  64. procedure show;
  65. private
  66. startmem : longint;
  67. infostr : string[40];
  68. end;
  69. plinkedlist_item = ^tlinkedlist_item;
  70. tlinkedlist_item = object
  71. next,previous : plinkedlist_item;
  72. { does nothing }
  73. constructor init;
  74. destructor done;virtual;
  75. function getcopy:plinkedlist_item;virtual;
  76. end;
  77. pstring_item = ^tstring_item;
  78. tstring_item = object(tlinkedlist_item)
  79. str : pstring;
  80. constructor init(const s : string);
  81. destructor done;virtual;
  82. end;
  83. { this implements a double linked list }
  84. plinkedlist = ^tlinkedlist;
  85. tlinkedlist = object
  86. first,last : plinkedlist_item;
  87. constructor init;
  88. destructor done;
  89. { disposes the items of the list }
  90. procedure clear;
  91. { concats a new item at the end }
  92. procedure concat(p : plinkedlist_item);
  93. { inserts a new item at the begin }
  94. procedure insert(p : plinkedlist_item);
  95. { inserts another list at the begin and make this list empty }
  96. procedure insertlist(p : plinkedlist);
  97. { concats another list at the end and make this list empty }
  98. procedure concatlist(p : plinkedlist);
  99. procedure concatlistcopy(p : plinkedlist);
  100. { removes p from the list (p isn't disposed) }
  101. { it's not tested if p is in the list ! }
  102. procedure remove(p : plinkedlist_item);
  103. { is the linkedlist empty ? }
  104. function empty:boolean;
  105. { items in the list }
  106. function count:longint;
  107. end;
  108. { some help data types }
  109. pstringqueueitem = ^tstringqueueitem;
  110. tstringqueueitem = object
  111. data : pstring;
  112. next : pstringqueueitem;
  113. end;
  114. { String Queue}
  115. PStringQueue=^TStringQueue;
  116. TStringQueue=object
  117. first,last : PStringqueueItem;
  118. constructor Init;
  119. destructor Done;
  120. function Empty:boolean;
  121. function Get:string;
  122. function Find(const s:string):PStringqueueItem;
  123. function Delete(const s:string):boolean;
  124. procedure Insert(const s:string);
  125. procedure Concat(const s:string);
  126. procedure Clear;
  127. end;
  128. { containeritem }
  129. pcontaineritem = ^tcontaineritem;
  130. tcontaineritem = object
  131. next : pcontaineritem;
  132. constructor init;
  133. destructor done;virtual;
  134. end;
  135. { container }
  136. pcontainer = ^tcontainer;
  137. tcontainer = object
  138. root,
  139. last : pcontaineritem;
  140. constructor init;
  141. destructor done;
  142. { true when the container is empty }
  143. function empty:boolean;
  144. { amount of strings in the container }
  145. function count:longint;
  146. { inserts a string }
  147. procedure insert(item:pcontaineritem);
  148. { gets a string }
  149. function get:pcontaineritem;
  150. { deletes all items }
  151. procedure clear;
  152. end;
  153. { containeritem }
  154. pstringcontaineritem = ^tstringcontaineritem;
  155. tstringcontaineritem = object(tcontaineritem)
  156. data : pstring;
  157. file_info : tfileposinfo;
  158. constructor init(const s:string);
  159. constructor Init_TokenInfo(const s:string;const pos:tfileposinfo);
  160. destructor done;virtual;
  161. end;
  162. { string container }
  163. pstringcontainer = ^tstringcontainer;
  164. tstringcontainer = object(tcontainer)
  165. doubles : boolean; { if this is set to true, doubles are allowed }
  166. constructor init;
  167. constructor init_no_double;
  168. procedure insert(const s : string);
  169. procedure insert_with_tokeninfo(const s : string;const file_info : tfileposinfo);
  170. { gets a string }
  171. function get : string;
  172. function get_with_tokeninfo(var file_info : tfileposinfo) : string;
  173. { true if string is in the container }
  174. function find(const s:string):boolean;
  175. end;
  176. { namedindexobject for use with dictionary and indexarray }
  177. Pnamedindexobject=^Tnamedindexobject;
  178. Tnamedindexobject=object
  179. indexnr : longint;
  180. _name : Pstring;
  181. next,
  182. left,right : Pnamedindexobject;
  183. speedvalue : longint;
  184. constructor init;
  185. constructor initname(const n:string);
  186. destructor done;virtual;
  187. procedure setname(const n:string);virtual;
  188. function name:string;virtual;
  189. end;
  190. Pdictionaryhasharray=^Tdictionaryhasharray;
  191. Tdictionaryhasharray=array[-hasharraysize..hasharraysize] of Pnamedindexobject;
  192. Tnamedindexcallback = procedure(p:Pnamedindexobject);
  193. Pdictionary=^Tdictionary;
  194. Tdictionary=object
  195. noclear : boolean;
  196. replace_existing : boolean;
  197. constructor init;
  198. destructor done;virtual;
  199. procedure usehash;
  200. procedure clear;
  201. function delete(const s:string):Pnamedindexobject;
  202. function empty:boolean;
  203. procedure foreach(proc2call:Tnamedindexcallback);
  204. function insert(obj:Pnamedindexobject):Pnamedindexobject;
  205. function rename(const olds,news : string):Pnamedindexobject;
  206. function search(const s:string):Pnamedindexobject;
  207. function speedsearch(const s:string;speedvalue:longint):Pnamedindexobject;
  208. private
  209. root : Pnamedindexobject;
  210. hasharray : Pdictionaryhasharray;
  211. procedure cleartree(obj:Pnamedindexobject);
  212. function insertnode(newnode:Pnamedindexobject;var currnode:Pnamedindexobject):Pnamedindexobject;
  213. procedure inserttree(currtree,currroot:Pnamedindexobject);
  214. end;
  215. pdynamicarray = ^tdynamicarray;
  216. tdynamicarray = object
  217. posn,
  218. count,
  219. limit,
  220. elemlen,
  221. growcount : longint;
  222. data : pchar;
  223. constructor init(Aelemlen,Agrow:longint);
  224. destructor done;
  225. function size:longint;
  226. function usedsize:longint;
  227. procedure grow;
  228. procedure align(i:longint);
  229. procedure seek(i:longint);
  230. procedure write(var d;len:longint);
  231. procedure read(var d;len:longint);
  232. procedure writepos(pos:longint;var d;len:longint);
  233. procedure readpos(pos:longint;var d;len:longint);
  234. end;
  235. tindexobjectarray=array[1..16000] of Pnamedindexobject;
  236. Pnamedindexobjectarray=^tindexobjectarray;
  237. pindexarray=^tindexarray;
  238. tindexarray=object
  239. first : Pnamedindexobject;
  240. count : longint;
  241. constructor init(Agrowsize:longint);
  242. destructor done;
  243. procedure clear;
  244. procedure foreach(proc2call : Tnamedindexcallback);
  245. procedure deleteindex(p:Pnamedindexobject);
  246. procedure delete(p:Pnamedindexobject);
  247. procedure insert(p:Pnamedindexobject);
  248. function search(nr:longint):Pnamedindexobject;
  249. private
  250. growsize,
  251. size : longint;
  252. data : Pnamedindexobjectarray;
  253. procedure grow(gsize:longint);
  254. end;
  255. {$ifdef BUFFEREDFILE}
  256. { this is implemented to allow buffered binary I/O }
  257. pbufferedfile = ^tbufferedfile;
  258. tbufferedfile = object
  259. f : file;
  260. buf : pchar;
  261. bufsize,buflast,bufpos : longint;
  262. { 0 closed, 1 input, 2 output }
  263. iomode : byte;
  264. { true, if the compile should change the endian of the output }
  265. change_endian : boolean;
  266. { calcules a crc for the file, }
  267. { but it's assumed, that there no seek while do_crc is true }
  268. do_crc : boolean;
  269. crc : longint;
  270. { temporary closing feature }
  271. tempclosed : boolean;
  272. tempmode : byte;
  273. temppos : longint;
  274. { inits a buffer with the size bufsize which is assigned to }
  275. { the file filename }
  276. constructor init(const filename : string;_bufsize : longint);
  277. { closes the file, if needed, and releases the memory }
  278. destructor done;virtual;
  279. { opens the file for input, other accesses are rejected }
  280. function reset:boolean;
  281. { opens the file for output, other accesses are rejected }
  282. procedure rewrite;
  283. { reads or writes the buffer from or to disk }
  284. procedure flush;
  285. { writes a string to the file }
  286. { the string is written without a length byte }
  287. procedure write_string(const s : string);
  288. { writes a zero terminated string }
  289. procedure write_pchar(p : pchar);
  290. { write specific data types, takes care of }
  291. { byte order }
  292. procedure write_byte(b : byte);
  293. procedure write_word(w : word);
  294. procedure write_long(l : longint);
  295. procedure write_double(d : double);
  296. { writes any data }
  297. procedure write_data(var data;count : longint);
  298. { reads any data }
  299. procedure read_data(var data;bytes : longint;var count : longint);
  300. { closes the file and releases the buffer }
  301. procedure close;
  302. { temporary closing }
  303. procedure tempclose;
  304. procedure tempreopen;
  305. { goto the given position }
  306. procedure seek(l : longint);
  307. { installes an user defined buffer }
  308. { and releases the old one, but be }
  309. { careful, if the old buffer contains }
  310. { data, this data is lost }
  311. procedure setbuf(p : pchar;s : longint);
  312. { reads the file time stamp of the file, }
  313. { the file must be opened }
  314. function getftime : longint;
  315. { returns filesize }
  316. function getsize : longint;
  317. { returns the path }
  318. function getpath : string;
  319. { resets the crc }
  320. procedure clear_crc;
  321. { returns the crc }
  322. function getcrc : longint;
  323. end;
  324. {$endif BUFFEREDFILE}
  325. {$ifdef fixLeaksOnError}
  326. PStackItem = ^TStackItem;
  327. TStackItem = record
  328. next: PStackItem;
  329. data: pointer;
  330. end;
  331. PStack = ^TStack;
  332. TStack = object
  333. constructor init;
  334. destructor done;
  335. procedure push(p: pointer);
  336. function pop: pointer;
  337. function top: pointer;
  338. function isEmpty: boolean;
  339. private
  340. head: PStackItem;
  341. end;
  342. {$endif fixLeaksOnError}
  343. function getspeedvalue(const s : string) : longint;
  344. { releases the string p and assignes nil to p }
  345. { if p=nil then freemem isn't called }
  346. procedure stringdispose(var p : pstring);
  347. { idem for ansistrings }
  348. procedure ansistringdispose(var p : pchar;length : longint);
  349. { allocates mem for a copy of s, copies s to this mem and returns }
  350. { a pointer to this mem }
  351. function stringdup(const s : string) : pstring;
  352. { allocates memory for s and copies s as zero terminated string
  353. to that mem and returns a pointer to that mem }
  354. function strpnew(const s : string) : pchar;
  355. procedure strdispose(var p : pchar);
  356. { makes a char lowercase, with spanish, french and german char set }
  357. function lowercase(c : char) : char;
  358. { makes zero terminated string to a pascal string }
  359. { the data in p is modified and p is returned }
  360. function pchar2pstring(p : pchar) : pstring;
  361. { ambivalent to pchar2pstring }
  362. function pstring2pchar(p : pstring) : pchar;
  363. implementation
  364. uses
  365. comphook;
  366. {*****************************************************************************
  367. Memory debug
  368. *****************************************************************************}
  369. constructor tmemdebug.init(const s:string);
  370. begin
  371. infostr:=s;
  372. {$ifdef Delphi}
  373. startmem:=0;
  374. {$else}
  375. startmem:=memavail;
  376. {$endif Delphi}
  377. end;
  378. procedure tmemdebug.show;
  379. var
  380. l : longint;
  381. begin
  382. {$ifndef Delphi}
  383. write('memory [',infostr,'] ');
  384. l:=memavail;
  385. if l>startmem then
  386. writeln(l-startmem,' released')
  387. else
  388. writeln(startmem-l,' allocated');
  389. {$endif Delphi}
  390. end;
  391. destructor tmemdebug.done;
  392. begin
  393. show;
  394. end;
  395. {*****************************************************************************
  396. Stack
  397. *****************************************************************************}
  398. {$ifdef fixLeaksOnError}
  399. constructor TStack.init;
  400. begin
  401. head := nil;
  402. end;
  403. procedure TStack.push(p: pointer);
  404. var s: PStackItem;
  405. begin
  406. new(s);
  407. s^.data := p;
  408. s^.next := head;
  409. head := s;
  410. end;
  411. function TStack.pop: pointer;
  412. var s: PStackItem;
  413. begin
  414. pop := top;
  415. if assigned(head) then
  416. begin
  417. s := head^.next;
  418. dispose(head);
  419. head := s;
  420. end
  421. end;
  422. function TStack.top: pointer;
  423. begin
  424. if not isEmpty then
  425. top := head^.data
  426. else top := NIL;
  427. end;
  428. function TStack.isEmpty: boolean;
  429. begin
  430. isEmpty := head = nil;
  431. end;
  432. destructor TStack.done;
  433. var temp: PStackItem;
  434. begin
  435. while head <> nil do
  436. begin
  437. temp := head^.next;
  438. dispose(head);
  439. head := temp;
  440. end;
  441. end;
  442. {$endif fixLeaksOnError}
  443. {$ifndef OLDSPEEDVALUE}
  444. {*****************************************************************************
  445. Crc 32
  446. *****************************************************************************}
  447. var
  448. Crc32Tbl : array[0..255] of longint;
  449. procedure MakeCRC32Tbl;
  450. var
  451. crc : longint;
  452. i,n : byte;
  453. begin
  454. for i:=0 to 255 do
  455. begin
  456. crc:=i;
  457. for n:=1 to 8 do
  458. if odd(crc) then
  459. crc:=(crc shr 1) xor longint($edb88320)
  460. else
  461. crc:=crc shr 1;
  462. Crc32Tbl[i]:=crc;
  463. end;
  464. end;
  465. {$ifopt R+}
  466. {$define Range_check_on}
  467. {$endif opt R+}
  468. {$R- needed here }
  469. {CRC 32}
  470. Function GetSpeedValue(Const s:String):longint;
  471. var
  472. i,InitCrc : longint;
  473. begin
  474. if Crc32Tbl[1]=0 then
  475. MakeCrc32Tbl;
  476. InitCrc:=$ffffffff;
  477. for i:=1 to Length(s) do
  478. InitCrc:=Crc32Tbl[byte(InitCrc) xor ord(s[i])] xor (InitCrc shr 8);
  479. GetSpeedValue:=InitCrc;
  480. end;
  481. {$ifdef Range_check_on}
  482. {$R+}
  483. {$undef Range_check_on}
  484. {$endif Range_check_on}
  485. {$else}
  486. {$ifndef TP}
  487. function getspeedvalue(const s : string) : longint;
  488. var
  489. p1,p2:^byte;
  490. i : longint;
  491. begin
  492. p1:=@s;
  493. longint(p2):=longint(p1)+p1^+1;
  494. inc(longint(p1));
  495. i:=0;
  496. while p1<>p2 do
  497. begin
  498. i:=i + ord(p1^);
  499. inc(longint(p1));
  500. end;
  501. getspeedvalue:=i;
  502. end;
  503. {$else}
  504. function getspeedvalue(const s : string) : longint;
  505. type
  506. ptrrec=record
  507. ofs,seg:word;
  508. end;
  509. var
  510. l,w : longint;
  511. p1,p2 : ^byte;
  512. begin
  513. p1:=@s;
  514. ptrrec(p2).seg:=ptrrec(p1).seg;
  515. ptrrec(p2).ofs:=ptrrec(p1).ofs+p1^+1;
  516. inc(p1);
  517. l:=0;
  518. while p1<>p2 do
  519. begin
  520. l:=l + ord(p1^);
  521. inc(p1);
  522. end;
  523. getspeedvalue:=l;
  524. end;
  525. {$endif}
  526. {$endif OLDSPEEDVALUE}
  527. function pchar2pstring(p : pchar) : pstring;
  528. var
  529. w,i : longint;
  530. begin
  531. w:=strlen(p);
  532. for i:=w-1 downto 0 do
  533. p[i+1]:=p[i];
  534. p[0]:=chr(w);
  535. pchar2pstring:=pstring(p);
  536. end;
  537. function pstring2pchar(p : pstring) : pchar;
  538. var
  539. w,i : longint;
  540. begin
  541. w:=length(p^);
  542. for i:=1 to w do
  543. p^[i-1]:=p^[i];
  544. p^[w]:=#0;
  545. pstring2pchar:=pchar(p);
  546. end;
  547. function lowercase(c : char) : char;
  548. begin
  549. case c of
  550. #65..#90 : c := chr(ord (c) + 32);
  551. #154 : c:=#129; { german }
  552. #142 : c:=#132; { german }
  553. #153 : c:=#148; { german }
  554. #144 : c:=#130; { french }
  555. #128 : c:=#135; { french }
  556. #143 : c:=#134; { swedish/norge (?) }
  557. #165 : c:=#164; { spanish }
  558. #228 : c:=#229; { greek }
  559. #226 : c:=#231; { greek }
  560. #232 : c:=#227; { greek }
  561. end;
  562. lowercase := c;
  563. end;
  564. function strpnew(const s : string) : pchar;
  565. var
  566. p : pchar;
  567. begin
  568. getmem(p,length(s)+1);
  569. strpcopy(p,s);
  570. strpnew:=p;
  571. end;
  572. procedure strdispose(var p : pchar);
  573. begin
  574. if assigned(p) then
  575. begin
  576. freemem(p,strlen(p)+1);
  577. p:=nil;
  578. end;
  579. end;
  580. procedure stringdispose(var p : pstring);
  581. begin
  582. if assigned(p) then
  583. freemem(p,length(p^)+1);
  584. p:=nil;
  585. end;
  586. procedure ansistringdispose(var p : pchar;length : longint);
  587. begin
  588. if assigned(p) then
  589. freemem(p,length+1);
  590. p:=nil;
  591. end;
  592. function stringdup(const s : string) : pstring;
  593. var
  594. p : pstring;
  595. begin
  596. getmem(p,length(s)+1);
  597. p^:=s;
  598. stringdup:=p;
  599. end;
  600. {****************************************************************************
  601. TStringQueue
  602. ****************************************************************************}
  603. constructor TStringQueue.Init;
  604. begin
  605. first:=nil;
  606. last:=nil;
  607. end;
  608. function TStringQueue.Empty:boolean;
  609. begin
  610. Empty:=(first=nil);
  611. end;
  612. function TStringQueue.Get:string;
  613. var
  614. newnode : pstringqueueitem;
  615. begin
  616. if first=nil then
  617. begin
  618. Get:='';
  619. exit;
  620. end;
  621. Get:=first^.data^;
  622. stringdispose(first^.data);
  623. newnode:=first;
  624. first:=first^.next;
  625. dispose(newnode);
  626. end;
  627. function TStringQueue.Find(const s:string):PStringqueueItem;
  628. var
  629. p : PStringqueueItem;
  630. begin
  631. p:=first;
  632. while assigned(p) do
  633. begin
  634. if p^.data^=s then
  635. break;
  636. p:=p^.next;
  637. end;
  638. Find:=p;
  639. end;
  640. function TStringQueue.Delete(const s:string):boolean;
  641. var
  642. prev,p : PStringqueueItem;
  643. begin
  644. Delete:=false;
  645. prev:=nil;
  646. p:=first;
  647. while assigned(p) do
  648. begin
  649. if p^.data^=s then
  650. begin
  651. if p=last then
  652. last:=prev;
  653. if assigned(prev) then
  654. prev^.next:=p^.next
  655. else
  656. first:=p^.next;
  657. dispose(p);
  658. Delete:=true;
  659. exit;
  660. end;
  661. prev:=p;
  662. p:=p^.next;
  663. end;
  664. end;
  665. procedure TStringQueue.Insert(const s:string);
  666. var
  667. newnode : pstringqueueitem;
  668. begin
  669. new(newnode);
  670. newnode^.next:=first;
  671. newnode^.data:=stringdup(s);
  672. first:=newnode;
  673. if last=nil then
  674. last:=newnode;
  675. end;
  676. procedure TStringQueue.Concat(const s:string);
  677. var
  678. newnode : pstringqueueitem;
  679. begin
  680. new(newnode);
  681. newnode^.next:=nil;
  682. newnode^.data:=stringdup(s);
  683. if first=nil then
  684. first:=newnode
  685. else
  686. last^.next:=newnode;
  687. last:=newnode;
  688. end;
  689. procedure TStringQueue.Clear;
  690. var
  691. newnode : pstringqueueitem;
  692. begin
  693. while (first<>nil) do
  694. begin
  695. newnode:=first;
  696. stringdispose(first^.data);
  697. first:=first^.next;
  698. dispose(newnode);
  699. end;
  700. last:=nil;
  701. end;
  702. destructor TStringQueue.Done;
  703. begin
  704. Clear;
  705. end;
  706. {****************************************************************************
  707. TContainerItem
  708. ****************************************************************************}
  709. constructor TContainerItem.Init;
  710. begin
  711. end;
  712. destructor TContainerItem.Done;
  713. begin
  714. end;
  715. {****************************************************************************
  716. TStringContainerItem
  717. ****************************************************************************}
  718. constructor TStringContainerItem.Init(const s:string);
  719. begin
  720. inherited Init;
  721. data:=stringdup(s);
  722. file_info.fileindex:=0;
  723. file_info.line:=0;
  724. file_info.column:=0;
  725. end;
  726. constructor TStringContainerItem.Init_TokenInfo(const s:string;const pos:tfileposinfo);
  727. begin
  728. inherited Init;
  729. data:=stringdup(s);
  730. file_info:=pos;
  731. end;
  732. destructor TStringContainerItem.Done;
  733. begin
  734. stringdispose(data);
  735. end;
  736. {****************************************************************************
  737. TCONTAINER
  738. ****************************************************************************}
  739. constructor tcontainer.init;
  740. begin
  741. root:=nil;
  742. last:=nil;
  743. end;
  744. destructor tcontainer.done;
  745. begin
  746. clear;
  747. end;
  748. function tcontainer.empty:boolean;
  749. begin
  750. empty:=(root=nil);
  751. end;
  752. function tcontainer.count:longint;
  753. var
  754. i : longint;
  755. p : pcontaineritem;
  756. begin
  757. i:=0;
  758. p:=root;
  759. while assigned(p) do
  760. begin
  761. p:=p^.next;
  762. inc(i);
  763. end;
  764. count:=i;
  765. end;
  766. procedure tcontainer.insert(item:pcontaineritem);
  767. begin
  768. item^.next:=nil;
  769. if root=nil then
  770. root:=item
  771. else
  772. last^.next:=item;
  773. last:=item;
  774. end;
  775. procedure tcontainer.clear;
  776. var
  777. newnode : pcontaineritem;
  778. begin
  779. newnode:=root;
  780. while assigned(newnode) do
  781. begin
  782. root:=newnode^.next;
  783. dispose(newnode,done);
  784. newnode:=root;
  785. end;
  786. last:=nil;
  787. root:=nil;
  788. end;
  789. function tcontainer.get:pcontaineritem;
  790. begin
  791. if root=nil then
  792. get:=nil
  793. else
  794. begin
  795. get:=root;
  796. root:=root^.next;
  797. end;
  798. end;
  799. {****************************************************************************
  800. TSTRINGCONTAINER
  801. ****************************************************************************}
  802. constructor tstringcontainer.init;
  803. begin
  804. inherited init;
  805. doubles:=true;
  806. end;
  807. constructor tstringcontainer.init_no_double;
  808. begin
  809. inherited init;
  810. doubles:=false;
  811. end;
  812. procedure tstringcontainer.insert(const s : string);
  813. var
  814. newnode : pstringcontaineritem;
  815. begin
  816. if (s='') or
  817. ((not doubles) and find(s)) then
  818. exit;
  819. new(newnode,init(s));
  820. inherited insert(newnode);
  821. end;
  822. procedure tstringcontainer.insert_with_tokeninfo(const s : string; const file_info : tfileposinfo);
  823. var
  824. newnode : pstringcontaineritem;
  825. begin
  826. if (not doubles) and find(s) then
  827. exit;
  828. new(newnode,init_tokeninfo(s,file_info));
  829. inherited insert(newnode);
  830. end;
  831. function tstringcontainer.get : string;
  832. var
  833. p : pstringcontaineritem;
  834. begin
  835. p:=pstringcontaineritem(inherited get);
  836. if p=nil then
  837. get:=''
  838. else
  839. begin
  840. get:=p^.data^;
  841. dispose(p,done);
  842. end;
  843. end;
  844. function tstringcontainer.get_with_tokeninfo(var file_info : tfileposinfo) : string;
  845. var
  846. p : pstringcontaineritem;
  847. begin
  848. p:=pstringcontaineritem(inherited get);
  849. if p=nil then
  850. begin
  851. get_with_tokeninfo:='';
  852. file_info.fileindex:=0;
  853. file_info.line:=0;
  854. file_info.column:=0;
  855. end
  856. else
  857. begin
  858. get_with_tokeninfo:=p^.data^;
  859. file_info:=p^.file_info;
  860. dispose(p,done);
  861. end;
  862. end;
  863. function tstringcontainer.find(const s:string):boolean;
  864. var
  865. newnode : pstringcontaineritem;
  866. begin
  867. find:=false;
  868. newnode:=pstringcontaineritem(root);
  869. while assigned(newnode) do
  870. begin
  871. if newnode^.data^=s then
  872. begin
  873. find:=true;
  874. exit;
  875. end;
  876. newnode:=pstringcontaineritem(newnode^.next);
  877. end;
  878. end;
  879. {****************************************************************************
  880. TLINKEDLIST_ITEM
  881. ****************************************************************************}
  882. constructor tlinkedlist_item.init;
  883. begin
  884. previous:=nil;
  885. next:=nil;
  886. end;
  887. destructor tlinkedlist_item.done;
  888. begin
  889. end;
  890. function tlinkedlist_item.getcopy:plinkedlist_item;
  891. var
  892. l : longint;
  893. p : plinkedlist_item;
  894. begin
  895. l:=sizeof(self);
  896. getmem(p,l);
  897. move(self,p^,l);
  898. getcopy:=p;
  899. end;
  900. {****************************************************************************
  901. TSTRING_ITEM
  902. ****************************************************************************}
  903. constructor tstring_item.init(const s : string);
  904. begin
  905. str:=stringdup(s);
  906. end;
  907. destructor tstring_item.done;
  908. begin
  909. stringdispose(str);
  910. inherited done;
  911. end;
  912. {****************************************************************************
  913. TLINKEDLIST
  914. ****************************************************************************}
  915. constructor tlinkedlist.init;
  916. begin
  917. first:=nil;
  918. last:=nil;
  919. end;
  920. destructor tlinkedlist.done;
  921. begin
  922. clear;
  923. end;
  924. procedure tlinkedlist.clear;
  925. var
  926. newnode : plinkedlist_item;
  927. begin
  928. newnode:=first;
  929. while assigned(newnode) do
  930. begin
  931. first:=newnode^.next;
  932. dispose(newnode,done);
  933. newnode:=first;
  934. end;
  935. end;
  936. procedure tlinkedlist.insertlist(p : plinkedlist);
  937. begin
  938. { empty list ? }
  939. if not(assigned(p^.first)) then
  940. exit;
  941. p^.last^.next:=first;
  942. { we have a double linked list }
  943. if assigned(first) then
  944. first^.previous:=p^.last;
  945. first:=p^.first;
  946. if not(assigned(last)) then
  947. last:=p^.last;
  948. { p becomes empty }
  949. p^.first:=nil;
  950. p^.last:=nil;
  951. end;
  952. procedure tlinkedlist.concat(p : plinkedlist_item);
  953. begin
  954. if not(assigned(first)) then
  955. begin
  956. first:=p;
  957. p^.previous:=nil;
  958. p^.next:=nil;
  959. end
  960. else
  961. begin
  962. last^.next:=p;
  963. p^.previous:=last;
  964. p^.next:=nil;
  965. end;
  966. last:=p;
  967. end;
  968. procedure tlinkedlist.insert(p : plinkedlist_item);
  969. begin
  970. if not(assigned(first)) then
  971. begin
  972. last:=p;
  973. p^.previous:=nil;
  974. p^.next:=nil;
  975. end
  976. else
  977. begin
  978. first^.previous:=p;
  979. p^.previous:=nil;
  980. p^.next:=first;
  981. end;
  982. first:=p;
  983. end;
  984. procedure tlinkedlist.remove(p : plinkedlist_item);
  985. begin
  986. if not(assigned(p)) then
  987. exit;
  988. if (first=p) and (last=p) then
  989. begin
  990. first:=nil;
  991. last:=nil;
  992. end
  993. else if first=p then
  994. begin
  995. first:=p^.next;
  996. if assigned(first) then
  997. first^.previous:=nil;
  998. end
  999. else if last=p then
  1000. begin
  1001. last:=last^.previous;
  1002. if assigned(last) then
  1003. last^.next:=nil;
  1004. end
  1005. else
  1006. begin
  1007. p^.previous^.next:=p^.next;
  1008. p^.next^.previous:=p^.previous;
  1009. end;
  1010. p^.next:=nil;
  1011. p^.previous:=nil;
  1012. end;
  1013. procedure tlinkedlist.concatlist(p : plinkedlist);
  1014. begin
  1015. if not(assigned(p^.first)) then
  1016. exit;
  1017. if not(assigned(first)) then
  1018. first:=p^.first
  1019. else
  1020. begin
  1021. last^.next:=p^.first;
  1022. p^.first^.previous:=last;
  1023. end;
  1024. last:=p^.last;
  1025. { make p empty }
  1026. p^.last:=nil;
  1027. p^.first:=nil;
  1028. end;
  1029. procedure tlinkedlist.concatlistcopy(p : plinkedlist);
  1030. var
  1031. newnode,newnode2 : plinkedlist_item;
  1032. begin
  1033. newnode:=p^.first;
  1034. while assigned(newnode) do
  1035. begin
  1036. newnode2:=newnode^.getcopy;
  1037. if assigned(newnode2) then
  1038. begin
  1039. if not(assigned(first)) then
  1040. begin
  1041. first:=newnode2;
  1042. newnode2^.previous:=nil;
  1043. newnode2^.next:=nil;
  1044. end
  1045. else
  1046. begin
  1047. last^.next:=newnode2;
  1048. newnode2^.previous:=last;
  1049. newnode2^.next:=nil;
  1050. end;
  1051. last:=newnode2;
  1052. end;
  1053. newnode:=newnode^.next;
  1054. end;
  1055. end;
  1056. function tlinkedlist.empty:boolean;
  1057. begin
  1058. empty:=(first=nil);
  1059. end;
  1060. function tlinkedlist.count:longint;
  1061. var
  1062. i : longint;
  1063. hp : plinkedlist_item;
  1064. begin
  1065. hp:=first;
  1066. i:=0;
  1067. while assigned(hp) do
  1068. begin
  1069. inc(i);
  1070. hp:=hp^.next;
  1071. end;
  1072. count:=i;
  1073. end;
  1074. {****************************************************************************
  1075. Tnamedindexobject
  1076. ****************************************************************************}
  1077. constructor Tnamedindexobject.init;
  1078. begin
  1079. { index }
  1080. indexnr:=-1;
  1081. next:=nil;
  1082. { dictionary }
  1083. left:=nil;
  1084. right:=nil;
  1085. _name:=nil;
  1086. speedvalue:=-1;
  1087. end;
  1088. constructor Tnamedindexobject.initname(const n:string);
  1089. begin
  1090. { index }
  1091. indexnr:=-1;
  1092. next:=nil;
  1093. { dictionary }
  1094. left:=nil;
  1095. right:=nil;
  1096. speedvalue:=-1;
  1097. _name:=stringdup(n);
  1098. end;
  1099. destructor Tnamedindexobject.done;
  1100. begin
  1101. stringdispose(_name);
  1102. end;
  1103. procedure Tnamedindexobject.setname(const n:string);
  1104. begin
  1105. if speedvalue=-1 then
  1106. begin
  1107. if assigned(_name) then
  1108. stringdispose(_name);
  1109. _name:=stringdup(n);
  1110. end;
  1111. end;
  1112. function Tnamedindexobject.name:string;
  1113. begin
  1114. if assigned(_name) then
  1115. name:=_name^
  1116. else
  1117. name:='';
  1118. end;
  1119. {****************************************************************************
  1120. TDICTIONARY
  1121. ****************************************************************************}
  1122. constructor Tdictionary.init;
  1123. begin
  1124. root:=nil;
  1125. hasharray:=nil;
  1126. noclear:=false;
  1127. replace_existing:=false;
  1128. end;
  1129. procedure Tdictionary.usehash;
  1130. begin
  1131. if not(assigned(root)) and
  1132. not(assigned(hasharray)) then
  1133. begin
  1134. new(hasharray);
  1135. fillchar(hasharray^,sizeof(hasharray^),0);
  1136. end;
  1137. end;
  1138. destructor Tdictionary.done;
  1139. begin
  1140. if not noclear then
  1141. clear;
  1142. if assigned(hasharray) then
  1143. dispose(hasharray);
  1144. end;
  1145. procedure Tdictionary.cleartree(obj:Pnamedindexobject);
  1146. begin
  1147. if assigned(obj^.left) then
  1148. cleartree(obj^.left);
  1149. if assigned(obj^.right) then
  1150. cleartree(obj^.right);
  1151. dispose(obj,done);
  1152. obj:=nil;
  1153. end;
  1154. procedure Tdictionary.clear;
  1155. var
  1156. w : longint;
  1157. begin
  1158. if assigned(root) then
  1159. cleartree(root);
  1160. if assigned(hasharray) then
  1161. for w:=-hasharraysize to hasharraysize do
  1162. if assigned(hasharray^[w]) then
  1163. cleartree(hasharray^[w]);
  1164. end;
  1165. function Tdictionary.delete(const s:string):Pnamedindexobject;
  1166. var p,speedvalue:longint;
  1167. n:Pnamedindexobject;
  1168. procedure insert_right_bottom(var root,Atree:Pnamedindexobject);
  1169. begin
  1170. while root^.right<>nil do
  1171. root:=root^.right;
  1172. root^.right:=Atree;
  1173. end;
  1174. function delete_from_tree(root:Pnamedindexobject):Pnamedindexobject;
  1175. type leftright=(left,right);
  1176. var lr:leftright;
  1177. oldroot:Pnamedindexobject;
  1178. begin
  1179. oldroot:=nil;
  1180. while (root<>nil) and (root^.speedvalue<>speedvalue) do
  1181. begin
  1182. oldroot:=root;
  1183. if speedvalue<root^.speedvalue then
  1184. begin
  1185. root:=root^.right;
  1186. lr:=right;
  1187. end
  1188. else
  1189. begin
  1190. root:=root^.left;
  1191. lr:=left;
  1192. end;
  1193. end;
  1194. while (root<>nil) and (root^._name^<>s) do
  1195. begin
  1196. oldroot:=root;
  1197. if s<root^._name^ then
  1198. begin
  1199. root:=root^.right;
  1200. lr:=right;
  1201. end
  1202. else
  1203. begin
  1204. root:=root^.left;
  1205. lr:=left;
  1206. end;
  1207. end;
  1208. if (oldroot=nil) or (root=nil) then
  1209. do_internalerror(218); {Internalerror is not available...}
  1210. if root^.left<>nil then
  1211. begin
  1212. {Now the node pointing to root must point to the left
  1213. subtree of root. The right subtree of root must be
  1214. connected to the right bottom of the left subtree.}
  1215. if lr=left then
  1216. oldroot^.left:=root^.left
  1217. else
  1218. oldroot^.right:=root^.left;
  1219. if root^.right<>nil then
  1220. insert_right_bottom(root^.left,root^.right);
  1221. end
  1222. else
  1223. {There is no left subtree. So we can just replace the node to
  1224. delete with the right subtree.}
  1225. if lr=left then
  1226. oldroot^.left:=root^.right
  1227. else
  1228. oldroot^.right:=root^.right;
  1229. delete_from_tree:=root;
  1230. end;
  1231. begin
  1232. speedvalue:=getspeedvalue(s);
  1233. n:=root;
  1234. if assigned(hasharray) then
  1235. begin
  1236. {First, check if the node to delete directly located under
  1237. the hasharray.}
  1238. p:=speedvalue mod hasharraysize;
  1239. n:=hasharray^[p];
  1240. if (n<>nil) and (n^.speedvalue=speedvalue) and
  1241. (n^._name^=s) then
  1242. begin
  1243. {The node to delete is directly located under the
  1244. hasharray. Make the hasharray point to the left
  1245. subtree of the node and place the right subtree on
  1246. the right-bottom of the left subtree.}
  1247. if n^.left<>nil then
  1248. begin
  1249. hasharray^[p]:=n^.left;
  1250. if n^.right<>nil then
  1251. insert_right_bottom(n^.left,n^.right);
  1252. end
  1253. else
  1254. hasharray^[p]:=n^.right;
  1255. delete:=n;
  1256. exit;
  1257. end;
  1258. end
  1259. else
  1260. begin
  1261. {First check if the node to delete is the root.}
  1262. if (root<>nil) and (n^.speedvalue=speedvalue)
  1263. and (n^._name^=s) then
  1264. begin
  1265. if n^.left<>nil then
  1266. begin
  1267. root:=n^.left;
  1268. if n^.right<>nil then
  1269. insert_right_bottom(n^.left,n^.right);
  1270. end
  1271. else
  1272. root:=n^.right;
  1273. delete:=n;
  1274. exit;
  1275. end;
  1276. end;
  1277. delete:=delete_from_tree(n);
  1278. end;
  1279. function Tdictionary.empty:boolean;
  1280. var
  1281. w : longint;
  1282. begin
  1283. if assigned(hasharray) then
  1284. begin
  1285. empty:=false;
  1286. for w:=-hasharraysize to hasharraysize do
  1287. if assigned(hasharray^[w]) then
  1288. exit;
  1289. empty:=true;
  1290. end
  1291. else
  1292. empty:=(root=nil);
  1293. end;
  1294. procedure Tdictionary.foreach(proc2call:Tnamedindexcallback);
  1295. procedure a(p:Pnamedindexobject);
  1296. begin
  1297. proc2call(p);
  1298. if assigned(p^.left) then
  1299. a(p^.left);
  1300. if assigned(p^.right) then
  1301. a(p^.right);
  1302. end;
  1303. var
  1304. i : longint;
  1305. begin
  1306. if assigned(hasharray) then
  1307. begin
  1308. for i:=-hasharraysize to hasharraysize do
  1309. if assigned(hasharray^[i]) then
  1310. a(hasharray^[i]);
  1311. end
  1312. else
  1313. if assigned(root) then
  1314. a(root);
  1315. end;
  1316. function Tdictionary.insert(obj:Pnamedindexobject):Pnamedindexobject;
  1317. begin
  1318. obj^.speedvalue:=getspeedvalue(obj^._name^);
  1319. if assigned(hasharray) then
  1320. insert:=insertnode(obj,hasharray^[obj^.speedvalue mod hasharraysize])
  1321. else
  1322. insert:=insertnode(obj,root);
  1323. end;
  1324. function tdictionary.insertnode(newnode:Pnamedindexobject;var currnode:Pnamedindexobject):Pnamedindexobject;
  1325. begin
  1326. if currnode=nil then
  1327. begin
  1328. currnode:=newnode;
  1329. insertnode:=newnode;
  1330. end
  1331. { first check speedvalue, to allow a fast insert }
  1332. else
  1333. if currnode^.speedvalue>newnode^.speedvalue then
  1334. insertnode:=insertnode(newnode,currnode^.right)
  1335. else
  1336. if currnode^.speedvalue<newnode^.speedvalue then
  1337. insertnode:=insertnode(newnode,currnode^.left)
  1338. else
  1339. begin
  1340. if currnode^._name^>newnode^._name^ then
  1341. insertnode:=insertnode(newnode,currnode^.right)
  1342. else
  1343. if currnode^._name^<newnode^._name^ then
  1344. insertnode:=insertnode(newnode,currnode^.left)
  1345. else
  1346. begin
  1347. if replace_existing and
  1348. assigned(currnode) then
  1349. begin
  1350. newnode^.left:=currnode^.left;
  1351. newnode^.right:=currnode^.right;
  1352. currnode:=newnode;
  1353. insertnode:=newnode;
  1354. end
  1355. else
  1356. insertnode:=currnode;
  1357. end;
  1358. end;
  1359. end;
  1360. procedure tdictionary.inserttree(currtree,currroot:Pnamedindexobject);
  1361. begin
  1362. if assigned(currtree) then
  1363. begin
  1364. inserttree(currtree^.left,currroot);
  1365. inserttree(currtree^.right,currroot);
  1366. currtree^.right:=nil;
  1367. currtree^.left:=nil;
  1368. insertnode(currtree,currroot);
  1369. end;
  1370. end;
  1371. function tdictionary.rename(const olds,news : string):Pnamedindexobject;
  1372. var
  1373. spdval : longint;
  1374. lasthp,
  1375. hp,hp2,hp3 : Pnamedindexobject;
  1376. begin
  1377. spdval:=getspeedvalue(olds);
  1378. if assigned(hasharray) then
  1379. hp:=hasharray^[spdval mod hasharraysize]
  1380. else
  1381. hp:=root;
  1382. lasthp:=nil;
  1383. while assigned(hp) do
  1384. begin
  1385. if spdval>hp^.speedvalue then
  1386. begin
  1387. lasthp:=hp;
  1388. hp:=hp^.left
  1389. end
  1390. else
  1391. if spdval<hp^.speedvalue then
  1392. begin
  1393. lasthp:=hp;
  1394. hp:=hp^.right
  1395. end
  1396. else
  1397. begin
  1398. if (hp^.name=olds) then
  1399. begin
  1400. { get in hp2 the replacer for the root or hasharr }
  1401. hp2:=hp^.left;
  1402. hp3:=hp^.right;
  1403. if not assigned(hp2) then
  1404. begin
  1405. hp2:=hp^.right;
  1406. hp3:=hp^.left;
  1407. end;
  1408. { remove entry from the tree }
  1409. if assigned(lasthp) then
  1410. begin
  1411. if lasthp^.left=hp then
  1412. lasthp^.left:=hp2
  1413. else
  1414. lasthp^.right:=hp2;
  1415. end
  1416. else
  1417. begin
  1418. if assigned(hasharray) then
  1419. hasharray^[spdval mod hasharraysize]:=hp2
  1420. else
  1421. root:=hp2;
  1422. end;
  1423. { reinsert the hp3 in the tree from hp2 }
  1424. inserttree(hp3,hp2);
  1425. { reset node with new values }
  1426. stringdispose(hp^._name);
  1427. hp^._name:=stringdup(news);
  1428. hp^.speedvalue:=getspeedvalue(news);
  1429. hp^.left:=nil;
  1430. hp^.right:=nil;
  1431. { reinsert }
  1432. if assigned(hasharray) then
  1433. rename:=insertnode(hp,hasharray^[hp^.speedvalue mod hasharraysize])
  1434. else
  1435. rename:=insertnode(hp,root);
  1436. exit;
  1437. end
  1438. else
  1439. if olds>hp^.name then
  1440. begin
  1441. lasthp:=hp;
  1442. hp:=hp^.left
  1443. end
  1444. else
  1445. begin
  1446. lasthp:=hp;
  1447. hp:=hp^.right;
  1448. end;
  1449. end;
  1450. end;
  1451. end;
  1452. function Tdictionary.search(const s:string):Pnamedindexobject;
  1453. begin
  1454. search:=speedsearch(s,getspeedvalue(s));
  1455. end;
  1456. function Tdictionary.speedsearch(const s:string;speedvalue:longint):Pnamedindexobject;
  1457. var
  1458. newnode:Pnamedindexobject;
  1459. begin
  1460. if assigned(hasharray) then
  1461. newnode:=hasharray^[speedvalue mod hasharraysize]
  1462. else
  1463. newnode:=root;
  1464. while assigned(newnode) do
  1465. begin
  1466. if speedvalue>newnode^.speedvalue then
  1467. newnode:=newnode^.left
  1468. else
  1469. if speedvalue<newnode^.speedvalue then
  1470. newnode:=newnode^.right
  1471. else
  1472. begin
  1473. if (newnode^._name^=s) then
  1474. begin
  1475. speedsearch:=newnode;
  1476. exit;
  1477. end
  1478. else
  1479. if s>newnode^._name^ then
  1480. newnode:=newnode^.left
  1481. else
  1482. newnode:=newnode^.right;
  1483. end;
  1484. end;
  1485. speedsearch:=nil;
  1486. end;
  1487. {****************************************************************************
  1488. tdynamicarray
  1489. ****************************************************************************}
  1490. constructor tdynamicarray.init(Aelemlen,Agrow:longint);
  1491. begin
  1492. posn:=0;
  1493. count:=0;
  1494. limit:=0;
  1495. data:=nil;
  1496. elemlen:=Aelemlen;
  1497. growcount:=Agrow;
  1498. grow;
  1499. end;
  1500. function tdynamicarray.size:longint;
  1501. begin
  1502. size:=limit*elemlen;
  1503. end;
  1504. function tdynamicarray.usedsize:longint;
  1505. begin
  1506. usedsize:=count*elemlen;
  1507. end;
  1508. procedure tdynamicarray.grow;
  1509. var
  1510. osize : longint;
  1511. odata : pchar;
  1512. begin
  1513. osize:=size;
  1514. odata:=data;
  1515. inc(limit,growcount);
  1516. getmem(data,size);
  1517. if assigned(odata) then
  1518. begin
  1519. move(odata^,data^,osize);
  1520. freemem(odata,osize);
  1521. end;
  1522. fillchar(data[osize],growcount*elemlen,0);
  1523. end;
  1524. procedure tdynamicarray.align(i:longint);
  1525. var
  1526. j : longint;
  1527. begin
  1528. j:=(posn*elemlen mod i);
  1529. if j<>0 then
  1530. begin
  1531. j:=i-j;
  1532. while limit<(posn+j) do
  1533. grow;
  1534. inc(posn,j);
  1535. if (posn>count) then
  1536. count:=posn;
  1537. end;
  1538. end;
  1539. procedure tdynamicarray.seek(i:longint);
  1540. begin
  1541. while limit<i do
  1542. grow;
  1543. posn:=i;
  1544. if (posn>count) then
  1545. count:=posn;
  1546. end;
  1547. procedure tdynamicarray.write(var d;len:longint);
  1548. begin
  1549. while limit<(posn+len) do
  1550. grow;
  1551. move(d,data[posn*elemlen],len*elemlen);
  1552. inc(posn,len);
  1553. if (posn>count) then
  1554. count:=posn;
  1555. end;
  1556. procedure tdynamicarray.read(var d;len:longint);
  1557. begin
  1558. move(data[posn*elemlen],d,len*elemlen);
  1559. inc(posn,len);
  1560. if (posn>count) then
  1561. count:=posn;
  1562. end;
  1563. procedure tdynamicarray.writepos(pos:longint;var d;len:longint);
  1564. begin
  1565. while limit<(pos+len) do
  1566. grow;
  1567. move(d,data[pos*elemlen],len*elemlen);
  1568. posn:=pos+len;
  1569. if (posn>count) then
  1570. count:=posn;
  1571. end;
  1572. procedure tdynamicarray.readpos(pos:longint;var d;len:longint);
  1573. begin
  1574. while limit<(pos+len) do
  1575. grow;
  1576. move(data[pos*elemlen],d,len*elemlen);
  1577. posn:=pos+len;
  1578. if (posn>count) then
  1579. count:=posn;
  1580. end;
  1581. destructor tdynamicarray.done;
  1582. begin
  1583. if assigned(data) then
  1584. freemem(data,size);
  1585. end;
  1586. {****************************************************************************
  1587. tindexarray
  1588. ****************************************************************************}
  1589. constructor tindexarray.init(Agrowsize:longint);
  1590. begin
  1591. growsize:=Agrowsize;
  1592. size:=0;
  1593. count:=0;
  1594. data:=nil;
  1595. first:=nil;
  1596. end;
  1597. destructor tindexarray.done;
  1598. begin
  1599. if assigned(data) then
  1600. begin
  1601. clear;
  1602. freemem(data,size*4);
  1603. data:=nil;
  1604. end;
  1605. end;
  1606. function tindexarray.search(nr:longint):Pnamedindexobject;
  1607. begin
  1608. if nr<=count then
  1609. search:=data^[nr]
  1610. else
  1611. search:=nil;
  1612. end;
  1613. procedure tindexarray.clear;
  1614. var
  1615. i : longint;
  1616. begin
  1617. for i:=1 to count do
  1618. if assigned(data^[i]) then
  1619. begin
  1620. dispose(data^[i],done);
  1621. data^[i]:=nil;
  1622. end;
  1623. count:=0;
  1624. first:=nil;
  1625. end;
  1626. procedure tindexarray.foreach(proc2call : Tnamedindexcallback);
  1627. var
  1628. i : longint;
  1629. begin
  1630. for i:=1 to count do
  1631. if assigned(data^[i]) then
  1632. proc2call(data^[i]);
  1633. end;
  1634. procedure tindexarray.grow(gsize:longint);
  1635. var
  1636. osize : longint;
  1637. odata : Pnamedindexobjectarray;
  1638. begin
  1639. osize:=size;
  1640. odata:=data;
  1641. inc(size,gsize);
  1642. getmem(data,size*4);
  1643. if assigned(odata) then
  1644. begin
  1645. move(odata^,data^,osize*4);
  1646. freemem(odata,osize*4);
  1647. end;
  1648. fillchar(data^[osize+1],gsize*4,0);
  1649. end;
  1650. procedure tindexarray.deleteindex(p:Pnamedindexobject);
  1651. var
  1652. i : longint;
  1653. begin
  1654. i:=p^.indexnr;
  1655. { update counter }
  1656. if i=count then
  1657. dec(count);
  1658. { update linked list }
  1659. while (i>0) do
  1660. begin
  1661. dec(i);
  1662. if (i>0) and assigned(data^[i]) then
  1663. begin
  1664. data^[i]^.next:=data^[p^.indexnr]^.next;
  1665. break;
  1666. end;
  1667. end;
  1668. if i=0 then
  1669. first:=p^.next;
  1670. data^[p^.indexnr]:=nil;
  1671. { clear entry }
  1672. p^.indexnr:=-1;
  1673. p^.next:=nil;
  1674. end;
  1675. procedure tindexarray.delete(p:Pnamedindexobject);
  1676. begin
  1677. deleteindex(p);
  1678. dispose(p,done);
  1679. p:=nil;
  1680. end;
  1681. procedure tindexarray.insert(p:Pnamedindexobject);
  1682. var
  1683. i : longint;
  1684. begin
  1685. if p^.indexnr=-1 then
  1686. begin
  1687. inc(count);
  1688. p^.indexnr:=count;
  1689. end;
  1690. if p^.indexnr>count then
  1691. count:=p^.indexnr;
  1692. if count>size then
  1693. grow(((count div growsize)+1)*growsize);
  1694. data^[p^.indexnr]:=p;
  1695. { update linked list backward }
  1696. i:=p^.indexnr;
  1697. while (i>0) do
  1698. begin
  1699. dec(i);
  1700. if (i>0) and assigned(data^[i]) then
  1701. begin
  1702. data^[i]^.next:=p;
  1703. break;
  1704. end;
  1705. end;
  1706. if i=0 then
  1707. first:=p;
  1708. { update linked list forward }
  1709. i:=p^.indexnr;
  1710. while (i<=count) do
  1711. begin
  1712. inc(i);
  1713. if (i<=count) and assigned(data^[i]) then
  1714. begin
  1715. p^.next:=data^[i];
  1716. exit;
  1717. end;
  1718. end;
  1719. if i>count then
  1720. p^.next:=nil;
  1721. end;
  1722. {$ifdef BUFFEREDFILE}
  1723. {****************************************************************************
  1724. TBUFFEREDFILE
  1725. ****************************************************************************}
  1726. Const
  1727. crcseed = $ffffffff;
  1728. crctable : array[0..255] of longint = (
  1729. $00000000,$77073096,$ee0e612c,$990951ba,$076dc419,$706af48f,
  1730. $e963a535,$9e6495a3,$0edb8832,$79dcb8a4,$e0d5e91e,$97d2d988,
  1731. $09b64c2b,$7eb17cbd,$e7b82d07,$90bf1d91,$1db71064,$6ab020f2,
  1732. $f3b97148,$84be41de,$1adad47d,$6ddde4eb,$f4d4b551,$83d385c7,
  1733. $136c9856,$646ba8c0,$fd62f97a,$8a65c9ec,$14015c4f,$63066cd9,
  1734. $fa0f3d63,$8d080df5,$3b6e20c8,$4c69105e,$d56041e4,$a2677172,
  1735. $3c03e4d1,$4b04d447,$d20d85fd,$a50ab56b,$35b5a8fa,$42b2986c,
  1736. $dbbbc9d6,$acbcf940,$32d86ce3,$45df5c75,$dcd60dcf,$abd13d59,
  1737. $26d930ac,$51de003a,$c8d75180,$bfd06116,$21b4f4b5,$56b3c423,
  1738. $cfba9599,$b8bda50f,$2802b89e,$5f058808,$c60cd9b2,$b10be924,
  1739. $2f6f7c87,$58684c11,$c1611dab,$b6662d3d,$76dc4190,$01db7106,
  1740. $98d220bc,$efd5102a,$71b18589,$06b6b51f,$9fbfe4a5,$e8b8d433,
  1741. $7807c9a2,$0f00f934,$9609a88e,$e10e9818,$7f6a0dbb,$086d3d2d,
  1742. $91646c97,$e6635c01,$6b6b51f4,$1c6c6162,$856530d8,$f262004e,
  1743. $6c0695ed,$1b01a57b,$8208f4c1,$f50fc457,$65b0d9c6,$12b7e950,
  1744. $8bbeb8ea,$fcb9887c,$62dd1ddf,$15da2d49,$8cd37cf3,$fbd44c65,
  1745. $4db26158,$3ab551ce,$a3bc0074,$d4bb30e2,$4adfa541,$3dd895d7,
  1746. $a4d1c46d,$d3d6f4fb,$4369e96a,$346ed9fc,$ad678846,$da60b8d0,
  1747. $44042d73,$33031de5,$aa0a4c5f,$dd0d7cc9,$5005713c,$270241aa,
  1748. $be0b1010,$c90c2086,$5768b525,$206f85b3,$b966d409,$ce61e49f,
  1749. $5edef90e,$29d9c998,$b0d09822,$c7d7a8b4,$59b33d17,$2eb40d81,
  1750. $b7bd5c3b,$c0ba6cad,$edb88320,$9abfb3b6,$03b6e20c,$74b1d29a,
  1751. $ead54739,$9dd277af,$04db2615,$73dc1683,$e3630b12,$94643b84,
  1752. $0d6d6a3e,$7a6a5aa8,$e40ecf0b,$9309ff9d,$0a00ae27,$7d079eb1,
  1753. $f00f9344,$8708a3d2,$1e01f268,$6906c2fe,$f762575d,$806567cb,
  1754. $196c3671,$6e6b06e7,$fed41b76,$89d32be0,$10da7a5a,$67dd4acc,
  1755. $f9b9df6f,$8ebeeff9,$17b7be43,$60b08ed5,$d6d6a3e8,$a1d1937e,
  1756. $38d8c2c4,$4fdff252,$d1bb67f1,$a6bc5767,$3fb506dd,$48b2364b,
  1757. $d80d2bda,$af0a1b4c,$36034af6,$41047a60,$df60efc3,$a867df55,
  1758. $316e8eef,$4669be79,$cb61b38c,$bc66831a,$256fd2a0,$5268e236,
  1759. $cc0c7795,$bb0b4703,$220216b9,$5505262f,$c5ba3bbe,$b2bd0b28,
  1760. $2bb45a92,$5cb36a04,$c2d7ffa7,$b5d0cf31,$2cd99e8b,$5bdeae1d,
  1761. $9b64c2b0,$ec63f226,$756aa39c,$026d930a,$9c0906a9,$eb0e363f,
  1762. $72076785,$05005713,$95bf4a82,$e2b87a14,$7bb12bae,$0cb61b38,
  1763. $92d28e9b,$e5d5be0d,$7cdcefb7,$0bdbdf21,$86d3d2d4,$f1d4e242,
  1764. $68ddb3f8,$1fda836e,$81be16cd,$f6b9265b,$6fb077e1,$18b74777,
  1765. $88085ae6,$ff0f6a70,$66063bca,$11010b5c,$8f659eff,$f862ae69,
  1766. $616bffd3,$166ccf45,$a00ae278,$d70dd2ee,$4e048354,$3903b3c2,
  1767. $a7672661,$d06016f7,$4969474d,$3e6e77db,$aed16a4a,$d9d65adc,
  1768. $40df0b66,$37d83bf0,$a9bcae53,$debb9ec5,$47b2cf7f,$30b5ffe9,
  1769. $bdbdf21c,$cabac28a,$53b39330,$24b4a3a6,$bad03605,$cdd70693,
  1770. $54de5729,$23d967bf,$b3667a2e,$c4614ab8,$5d681b02,$2a6f2b94,
  1771. $b40bbe37,$c30c8ea1,$5a05df1b,$2d02ef8d);
  1772. constructor tbufferedfile.init(const filename : string;_bufsize : longint);
  1773. begin
  1774. assign(f,filename);
  1775. bufsize:=_bufsize;
  1776. bufpos:=0;
  1777. buflast:=0;
  1778. do_crc:=false;
  1779. iomode:=0;
  1780. tempclosed:=false;
  1781. change_endian:=false;
  1782. clear_crc;
  1783. end;
  1784. destructor tbufferedfile.done;
  1785. begin
  1786. close;
  1787. end;
  1788. procedure tbufferedfile.clear_crc;
  1789. begin
  1790. crc:=crcseed;
  1791. end;
  1792. procedure tbufferedfile.setbuf(p : pchar;s : longint);
  1793. begin
  1794. flush;
  1795. freemem(buf,bufsize);
  1796. bufsize:=s;
  1797. buf:=p;
  1798. end;
  1799. function tbufferedfile.reset:boolean;
  1800. var
  1801. ofm : byte;
  1802. begin
  1803. ofm:=filemode;
  1804. iomode:=1;
  1805. getmem(buf,bufsize);
  1806. filemode:=0;
  1807. {$I-}
  1808. system.reset(f,1);
  1809. {$I+}
  1810. reset:=(ioresult=0);
  1811. filemode:=ofm;
  1812. end;
  1813. procedure tbufferedfile.rewrite;
  1814. begin
  1815. iomode:=2;
  1816. getmem(buf,bufsize);
  1817. system.rewrite(f,1);
  1818. end;
  1819. procedure tbufferedfile.flush;
  1820. var
  1821. {$ifdef FPC}
  1822. count : longint;
  1823. {$else}
  1824. count : integer;
  1825. {$endif}
  1826. begin
  1827. if iomode=2 then
  1828. begin
  1829. if bufpos=0 then
  1830. exit;
  1831. blockwrite(f,buf^,bufpos)
  1832. end
  1833. else if iomode=1 then
  1834. if buflast=bufpos then
  1835. begin
  1836. blockread(f,buf^,bufsize,count);
  1837. buflast:=count;
  1838. end;
  1839. bufpos:=0;
  1840. end;
  1841. function tbufferedfile.getftime : longint;
  1842. var
  1843. l : longint;
  1844. {$ifdef linux}
  1845. Info : Stat;
  1846. {$endif}
  1847. begin
  1848. {$ifndef linux}
  1849. { this only works if the file is open !! }
  1850. dos.getftime(f,l);
  1851. {$else}
  1852. Fstat(f,Info);
  1853. l:=info.mtime;
  1854. {$endif}
  1855. getftime:=l;
  1856. end;
  1857. function tbufferedfile.getsize : longint;
  1858. begin
  1859. getsize:=filesize(f);
  1860. end;
  1861. procedure tbufferedfile.seek(l : longint);
  1862. begin
  1863. if iomode=2 then
  1864. begin
  1865. flush;
  1866. system.seek(f,l);
  1867. end
  1868. else if iomode=1 then
  1869. begin
  1870. { forces a reload }
  1871. bufpos:=buflast;
  1872. system.seek(f,l);
  1873. flush;
  1874. end;
  1875. end;
  1876. type
  1877. {$ifdef tp}
  1878. bytearray1 = array [1..65535] of byte;
  1879. {$else}
  1880. bytearray1 = array [1..10000000] of byte;
  1881. {$endif}
  1882. procedure tbufferedfile.read_data(var data;bytes : longint;var count : longint);
  1883. var
  1884. p : pchar;
  1885. c,i : longint;
  1886. begin
  1887. p:=pchar(@data);
  1888. count:=0;
  1889. while bytes-count>0 do
  1890. begin
  1891. if bytes-count>buflast-bufpos then
  1892. begin
  1893. move((buf+bufpos)^,(p+count)^,buflast-bufpos);
  1894. inc(count,buflast-bufpos);
  1895. bufpos:=buflast;
  1896. flush;
  1897. { can't we read anything ? }
  1898. if bufpos=buflast then
  1899. break;
  1900. end
  1901. else
  1902. begin
  1903. move((buf+bufpos)^,(p+count)^,bytes-count);
  1904. inc(bufpos,bytes-count);
  1905. count:=bytes;
  1906. break;
  1907. end;
  1908. end;
  1909. if do_crc then
  1910. begin
  1911. c:=crc;
  1912. for i:=1 to bytes do
  1913. c:=(c shr 8) xor crctable[byte(c) xor (bytearray1(data)[i])];
  1914. crc:=c;
  1915. end;
  1916. end;
  1917. procedure tbufferedfile.write_data(var data;count : longint);
  1918. var
  1919. c,i : longint;
  1920. begin
  1921. if bufpos+count>bufsize then
  1922. flush;
  1923. move(data,(buf+bufpos)^,count);
  1924. inc(bufpos,count);
  1925. if do_crc then
  1926. begin
  1927. c:=crc;
  1928. for i:=1 to count do
  1929. c:=(c shr 8) xor crctable[byte(c) xor (bytearray1(data)[i])];
  1930. crc:=c;
  1931. end;
  1932. end;
  1933. function tbufferedfile.getcrc : longint;
  1934. begin
  1935. getcrc:=crc xor crcseed;
  1936. end;
  1937. procedure tbufferedfile.write_string(const s : string);
  1938. begin
  1939. if bufpos+length(s)>bufsize then
  1940. flush;
  1941. { why is there not CRC here ??? }
  1942. move(s[1],(buf+bufpos)^,length(s));
  1943. inc(bufpos,length(s));
  1944. { should be
  1945. write_data(s[1],length(s)); }
  1946. end;
  1947. procedure tbufferedfile.write_pchar(p : pchar);
  1948. var
  1949. l : longint;
  1950. begin
  1951. l:=strlen(p);
  1952. if l>=bufsize then
  1953. do_internalerror(222);
  1954. { why is there not CRC here ???}
  1955. if bufpos+l>bufsize then
  1956. flush;
  1957. move(p^,(buf+bufpos)^,l);
  1958. inc(bufpos,l);
  1959. { should be
  1960. write_data(p^,l); }
  1961. end;
  1962. procedure tbufferedfile.write_byte(b : byte);
  1963. begin
  1964. write_data(b,sizeof(byte));
  1965. end;
  1966. procedure tbufferedfile.write_long(l : longint);
  1967. var
  1968. w1,w2 : word;
  1969. begin
  1970. if change_endian then
  1971. begin
  1972. w1:=l and $ffff;
  1973. w2:=l shr 16;
  1974. l:=swap(w2)+(longint(swap(w1)) shl 16);
  1975. end;
  1976. write_data(l,sizeof(longint));
  1977. end;
  1978. procedure tbufferedfile.write_word(w : word);
  1979. begin
  1980. if change_endian then
  1981. begin
  1982. w:=swap(w);
  1983. end;
  1984. write_data(w,sizeof(word));
  1985. end;
  1986. procedure tbufferedfile.write_double(d : double);
  1987. begin
  1988. write_data(d,sizeof(double));
  1989. end;
  1990. function tbufferedfile.getpath : string;
  1991. begin
  1992. {$ifdef dummy}
  1993. getpath:=strpas(filerec(f).name);
  1994. {$endif}
  1995. getpath:='';
  1996. end;
  1997. procedure tbufferedfile.close;
  1998. begin
  1999. if iomode<>0 then
  2000. begin
  2001. flush;
  2002. system.close(f);
  2003. freemem(buf,bufsize);
  2004. buf:=nil;
  2005. iomode:=0;
  2006. end;
  2007. end;
  2008. procedure tbufferedfile.tempclose;
  2009. begin
  2010. if iomode<>0 then
  2011. begin
  2012. temppos:=system.filepos(f);
  2013. tempmode:=iomode;
  2014. tempclosed:=true;
  2015. system.close(f);
  2016. iomode:=0;
  2017. end
  2018. else
  2019. tempclosed:=false;
  2020. end;
  2021. procedure tbufferedfile.tempreopen;
  2022. var
  2023. ofm : byte;
  2024. begin
  2025. if tempclosed then
  2026. begin
  2027. case tempmode of
  2028. 1 : begin
  2029. ofm:=filemode;
  2030. iomode:=1;
  2031. filemode:=0;
  2032. system.reset(f,1);
  2033. filemode:=ofm;
  2034. end;
  2035. 2 : begin
  2036. iomode:=2;
  2037. system.rewrite(f,1);
  2038. end;
  2039. end;
  2040. system.seek(f,temppos);
  2041. tempclosed:=false;
  2042. end;
  2043. end;
  2044. {$endif BUFFEREDFILE}
  2045. end.
  2046. {
  2047. $Log$
  2048. Revision 1.4 2000-08-06 19:42:40 peter
  2049. * removed note
  2050. Revision 1.3 2000/08/02 19:49:58 peter
  2051. * first things for default parameters
  2052. Revision 1.2 2000/07/13 11:32:38 michael
  2053. + removed logs
  2054. }