cobjects.pas 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. interface
  25. uses
  26. strings
  27. {$ifndef linux}
  28. ,dos
  29. {$else}
  30. ,linux
  31. {$endif}
  32. ;
  33. const hasharraysize = 253; {The size of a hasharray should be a prime
  34. number for better spreading of nodes in
  35. the array!! (DM)}
  36. type
  37. pstring = ^string;
  38. {$ifdef TP}
  39. { redeclare dword only in case of emergency, some small things
  40. of the compiler won't work then correctly (FK)
  41. }
  42. dword = longint;
  43. {$endif TP}
  44. pfileposinfo = ^tfileposinfo;
  45. tfileposinfo = record
  46. line : longint;
  47. column : word;
  48. fileindex : word;
  49. end;
  50. { some help data types }
  51. pstringitem = ^tstringitem;
  52. tstringitem = record
  53. data : pstring;
  54. next : pstringitem;
  55. fileinfo : tfileposinfo; { pointer to tinputfile }
  56. end;
  57. plinkedlist_item = ^tlinkedlist_item;
  58. tlinkedlist_item = object
  59. next,previous : plinkedlist_item;
  60. { does nothing }
  61. constructor init;
  62. destructor done;virtual;
  63. function getcopy:plinkedlist_item;virtual;
  64. end;
  65. pstring_item = ^tstring_item;
  66. tstring_item = object(tlinkedlist_item)
  67. str : pstring;
  68. constructor init(const s : string);
  69. destructor done;virtual;
  70. end;
  71. { this implements a double linked list }
  72. plinkedlist = ^tlinkedlist;
  73. tlinkedlist = object
  74. first,last : plinkedlist_item;
  75. constructor init;
  76. destructor done;
  77. { disposes the items of the list }
  78. procedure clear;
  79. { concats a new item at the end }
  80. procedure concat(p : plinkedlist_item);
  81. { inserts a new item at the begin }
  82. procedure insert(p : plinkedlist_item);
  83. { inserts another list at the begin and make this list empty }
  84. procedure insertlist(p : plinkedlist);
  85. { concats another list at the end and make this list empty }
  86. procedure concatlist(p : plinkedlist);
  87. procedure concatlistcopy(p : plinkedlist);
  88. { removes p from the list (p isn't disposed) }
  89. { it's not tested if p is in the list ! }
  90. procedure remove(p : plinkedlist_item);
  91. { is the linkedlist empty ? }
  92. function empty:boolean;
  93. end;
  94. { String Queue}
  95. PStringQueue=^TStringQueue;
  96. TStringQueue=object
  97. first,last : PStringItem;
  98. constructor Init;
  99. destructor Done;
  100. function Empty:boolean;
  101. function Get:string;
  102. procedure Insert(const s:string);
  103. procedure Concat(const s:string);
  104. procedure Clear;
  105. end;
  106. { string container }
  107. pstringcontainer = ^tstringcontainer;
  108. tstringcontainer = object
  109. root,
  110. last : pstringitem;
  111. doubles : boolean; { if this is set to true, doubles are allowed }
  112. constructor init;
  113. constructor init_no_double;
  114. destructor done;
  115. { true when the container is empty }
  116. function empty:boolean;
  117. { inserts a string }
  118. procedure insert(const s : string);
  119. procedure insert_with_tokeninfo(const s : string;const file_info : tfileposinfo);
  120. { gets a string }
  121. function get : string;
  122. function get_with_tokeninfo(var file_info : tfileposinfo) : string;
  123. { true if string is in the container }
  124. function find(const s:string):boolean;
  125. { deletes all strings }
  126. procedure clear;
  127. end;
  128. Pnamed_object=^Tnamed_object;
  129. Pdictionary=^Tdictionary;
  130. Pdictionaryhasharray=^Tdictionaryhasharray;
  131. Tdictionaryhasharray=array[0..hasharraysize-1] of Pnamed_object;
  132. Tcallback = procedure(p:Pnamed_object);
  133. Tdictionary=object
  134. root:Pnamed_object;
  135. hasharray:Pdictionaryhasharray;
  136. replace_existing : boolean;
  137. constructor init(usehash:boolean);
  138. procedure clear;virtual;
  139. procedure foreach(proc2call:Tcallback);
  140. function insert(obj:Pnamed_object):Pnamed_object;virtual;
  141. function search(const s:string):Pnamed_object;
  142. function speedsearch(const s:string;
  143. speedvalue:longint):Pnamed_object;virtual;
  144. destructor done;virtual;
  145. end;
  146. Tnamed_object=object
  147. _name:Pstring;
  148. left,right:Pnamed_object;
  149. speedvalue:longint;
  150. owner:Pdictionary;
  151. constructor init(const n:string);
  152. destructor done;virtual;
  153. function name:string;
  154. end;
  155. pdynamicarray = ^tdynamicarray;
  156. tdynamicarray = object
  157. posn,
  158. count,
  159. limit,
  160. elemlen,
  161. growcount : longint;
  162. data : pchar;
  163. constructor init(Aelemlen,Agrow:longint);
  164. destructor done;
  165. function size:longint;
  166. function usedsize:longint;
  167. procedure grow;
  168. procedure align(i:longint);
  169. procedure seek(i:longint);
  170. procedure write(var d;len:longint);
  171. procedure read(var d;len:longint);
  172. procedure writepos(pos:longint;var d;len:longint);
  173. procedure readpos(pos:longint;var d;len:longint);
  174. end;
  175. {$ifdef BUFFEREDFILE}
  176. { this is implemented to allow buffered binary I/O }
  177. pbufferedfile = ^tbufferedfile;
  178. tbufferedfile = object
  179. f : file;
  180. buf : pchar;
  181. bufsize,buflast,bufpos : longint;
  182. { 0 closed, 1 input, 2 output }
  183. iomode : byte;
  184. { true, if the compile should change the endian of the output }
  185. change_endian : boolean;
  186. { calcules a crc for the file, }
  187. { but it's assumed, that there no seek while do_crc is true }
  188. do_crc : boolean;
  189. crc : longint;
  190. { temporary closing feature }
  191. tempclosed : boolean;
  192. tempmode : byte;
  193. temppos : longint;
  194. { inits a buffer with the size bufsize which is assigned to }
  195. { the file filename }
  196. constructor init(const filename : string;_bufsize : longint);
  197. { closes the file, if needed, and releases the memory }
  198. destructor done;virtual;
  199. { opens the file for input, other accesses are rejected }
  200. function reset:boolean;
  201. { opens the file for output, other accesses are rejected }
  202. procedure rewrite;
  203. { reads or writes the buffer from or to disk }
  204. procedure flush;
  205. { writes a string to the file }
  206. { the string is written without a length byte }
  207. procedure write_string(const s : string);
  208. { writes a zero terminated string }
  209. procedure write_pchar(p : pchar);
  210. { write specific data types, takes care of }
  211. { byte order }
  212. procedure write_byte(b : byte);
  213. procedure write_word(w : word);
  214. procedure write_long(l : longint);
  215. procedure write_double(d : double);
  216. { writes any data }
  217. procedure write_data(var data;count : longint);
  218. { reads any data }
  219. procedure read_data(var data;bytes : longint;var count : longint);
  220. { closes the file and releases the buffer }
  221. procedure close;
  222. { temporary closing }
  223. procedure tempclose;
  224. procedure tempreopen;
  225. { goto the given position }
  226. procedure seek(l : longint);
  227. { installes an user defined buffer }
  228. { and releases the old one, but be }
  229. { careful, if the old buffer contains }
  230. { data, this data is lost }
  231. procedure setbuf(p : pchar;s : longint);
  232. { reads the file time stamp of the file, }
  233. { the file must be opened }
  234. function getftime : longint;
  235. { returns filesize }
  236. function getsize : longint;
  237. { returns the path }
  238. function getpath : string;
  239. { resets the crc }
  240. procedure clear_crc;
  241. { returns the crc }
  242. function getcrc : longint;
  243. end;
  244. {$endif BUFFEREDFILE}
  245. { releases the string p and assignes nil to p }
  246. { if p=nil then freemem isn't called }
  247. procedure stringdispose(var p : pstring);
  248. { idem for ansistrings }
  249. procedure ansistringdispose(var p : pchar;length : longint);
  250. { allocates mem for a copy of s, copies s to this mem and returns }
  251. { a pointer to this mem }
  252. function stringdup(const s : string) : pstring;
  253. { allocates memory for s and copies s as zero terminated string
  254. to that mem and returns a pointer to that mem }
  255. function strpnew(const s : string) : pchar;
  256. { makes a char lowercase, with spanish, french and german char set }
  257. function lowercase(c : char) : char;
  258. { makes zero terminated string to a pascal string }
  259. { the data in p is modified and p is returned }
  260. function pchar2pstring(p : pchar) : pstring;
  261. { ambivalent to pchar2pstring }
  262. function pstring2pchar(p : pstring) : pchar;
  263. implementation
  264. {$ifdef FPC}
  265. function getspeedvalue(const s : string) : longint;
  266. var
  267. p1,p2:^byte;
  268. begin
  269. p1:=@s;
  270. longint(p2):=longint(p1)+p1^+1;
  271. inc(longint(p1));
  272. getspeedvalue:=0;
  273. while p1<>p2 do
  274. begin
  275. inc(getspeedvalue,p1^);
  276. inc(longint(p1));
  277. end;
  278. end;
  279. {$else}
  280. function getspeedvalue(const s : string) : longint;
  281. type
  282. ptrrec=record
  283. ofs,seg:word;
  284. end;
  285. var
  286. l,w : longint;
  287. p1,p2 : ^byte;
  288. begin
  289. p1:=@s;
  290. ptrrec(p2).seg:=ptrrec(p1).seg;
  291. ptrrec(p2).ofs:=ptrrec(p1).ofs+p1^+1;
  292. inc(p1);
  293. l:=0;
  294. while p1<>p2 do
  295. begin
  296. l:=l+p1^;
  297. inc(p1);
  298. end;
  299. getspeedvalue:=l;
  300. end;
  301. {$endif}
  302. function pchar2pstring(p : pchar) : pstring;
  303. var
  304. w,i : longint;
  305. begin
  306. w:=strlen(p);
  307. for i:=w-1 downto 0 do
  308. p[i+1]:=p[i];
  309. p[0]:=chr(w);
  310. pchar2pstring:=pstring(p);
  311. end;
  312. function pstring2pchar(p : pstring) : pchar;
  313. var
  314. w,i : longint;
  315. begin
  316. w:=length(p^);
  317. for i:=1 to w do
  318. p^[i-1]:=p^[i];
  319. p^[w]:=#0;
  320. pstring2pchar:=pchar(p);
  321. end;
  322. function lowercase(c : char) : char;
  323. begin
  324. case c of
  325. #65..#90 : c := chr(ord (c) + 32);
  326. #154 : c:=#129; { german }
  327. #142 : c:=#132; { german }
  328. #153 : c:=#148; { german }
  329. #144 : c:=#130; { french }
  330. #128 : c:=#135; { french }
  331. #143 : c:=#134; { swedish/norge (?) }
  332. #165 : c:=#164; { spanish }
  333. #228 : c:=#229; { greek }
  334. #226 : c:=#231; { greek }
  335. #232 : c:=#227; { greek }
  336. end;
  337. lowercase := c;
  338. end;
  339. function strpnew(const s : string) : pchar;
  340. var
  341. p : pchar;
  342. begin
  343. getmem(p,length(s)+1);
  344. strpcopy(p,s);
  345. strpnew:=p;
  346. end;
  347. procedure stringdispose(var p : pstring);
  348. begin
  349. if assigned(p) then
  350. freemem(p,length(p^)+1);
  351. p:=nil;
  352. end;
  353. procedure ansistringdispose(var p : pchar;length : longint);
  354. begin
  355. if assigned(p) then
  356. freemem(p,length+1);
  357. p:=nil;
  358. end;
  359. function stringdup(const s : string) : pstring;
  360. var
  361. p : pstring;
  362. begin
  363. getmem(p,length(s)+1);
  364. p^:=s;
  365. stringdup:=p;
  366. end;
  367. {****************************************************************************
  368. TStringQueue
  369. ****************************************************************************}
  370. constructor TStringQueue.Init;
  371. begin
  372. first:=nil;
  373. end;
  374. function TStringQueue.Empty:boolean;
  375. begin
  376. Empty:=(first=nil);
  377. end;
  378. function TStringQueue.Get:string;
  379. var
  380. hp : pstringitem;
  381. begin
  382. if first=nil then
  383. begin
  384. Get:='';
  385. exit;
  386. end;
  387. Get:=first^.data^;
  388. stringdispose(first^.data);
  389. hp:=first;
  390. first:=first^.next;
  391. dispose(hp);
  392. end;
  393. procedure TStringQueue.Insert(const s:string);
  394. var
  395. hp : pstringitem;
  396. begin
  397. new(hp);
  398. hp^.next:=first;
  399. hp^.data:=stringdup(s);
  400. first:=hp;
  401. if last=nil then
  402. last:=hp;
  403. end;
  404. procedure TStringQueue.Concat(const s:string);
  405. var
  406. hp : pstringitem;
  407. begin
  408. new(hp);
  409. hp^.next:=nil;
  410. hp^.data:=stringdup(s);
  411. if first=nil then
  412. first:=hp
  413. else
  414. last^.next:=hp;
  415. last:=hp;
  416. end;
  417. procedure TStringQueue.Clear;
  418. var
  419. hp : pstringitem;
  420. begin
  421. while (first<>nil) do
  422. begin
  423. hp:=first;
  424. stringdispose(first^.data);
  425. first:=first^.next;
  426. dispose(hp);
  427. end;
  428. end;
  429. destructor TStringQueue.Done;
  430. begin
  431. Clear;
  432. end;
  433. {****************************************************************************
  434. TSTRINGCONTAINER
  435. ****************************************************************************}
  436. constructor tstringcontainer.init;
  437. begin
  438. root:=nil;
  439. last:=nil;
  440. doubles:=true;
  441. end;
  442. constructor tstringcontainer.init_no_double;
  443. begin
  444. root:=nil;
  445. last:=nil;
  446. doubles:=false;
  447. end;
  448. destructor tstringcontainer.done;
  449. begin
  450. clear;
  451. end;
  452. function tstringcontainer.empty:boolean;
  453. begin
  454. empty:=(root=nil);
  455. end;
  456. procedure tstringcontainer.insert(const s : string);
  457. var
  458. hp : pstringitem;
  459. begin
  460. if not(doubles) then
  461. begin
  462. hp:=root;
  463. while assigned(hp) do
  464. begin
  465. if hp^.data^=s then exit;
  466. hp:=hp^.next;
  467. end;
  468. end;
  469. new(hp);
  470. hp^.next:=nil;
  471. hp^.data:=stringdup(s);
  472. if root=nil then root:=hp
  473. else last^.next:=hp;
  474. last:=hp;
  475. end;
  476. procedure tstringcontainer.insert_with_tokeninfo(const s : string; const file_info : tfileposinfo);
  477. var
  478. hp : pstringitem;
  479. begin
  480. if not(doubles) then
  481. begin
  482. hp:=root;
  483. while assigned(hp) do
  484. begin
  485. if hp^.data^=s then exit;
  486. hp:=hp^.next;
  487. end;
  488. end;
  489. new(hp);
  490. hp^.next:=nil;
  491. hp^.data:=stringdup(s);
  492. hp^.fileinfo:=file_info;
  493. if root=nil then root:=hp
  494. else last^.next:=hp;
  495. last:=hp;
  496. end;
  497. procedure tstringcontainer.clear;
  498. var
  499. hp : pstringitem;
  500. begin
  501. hp:=root;
  502. while assigned(hp) do
  503. begin
  504. stringdispose(hp^.data);
  505. root:=hp^.next;
  506. dispose(hp);
  507. hp:=root;
  508. end;
  509. last:=nil;
  510. root:=nil;
  511. end;
  512. function tstringcontainer.get : string;
  513. var
  514. hp : pstringitem;
  515. begin
  516. if root=nil then
  517. get:=''
  518. else
  519. begin
  520. get:=root^.data^;
  521. hp:=root;
  522. root:=root^.next;
  523. stringdispose(hp^.data);
  524. dispose(hp);
  525. end;
  526. end;
  527. function tstringcontainer.get_with_tokeninfo(var file_info : tfileposinfo) : string;
  528. var
  529. hp : pstringitem;
  530. begin
  531. if root=nil then
  532. begin
  533. get_with_tokeninfo:='';
  534. file_info.fileindex:=0;
  535. file_info.line:=0;
  536. file_info.column:=0;
  537. end
  538. else
  539. begin
  540. get_with_tokeninfo:=root^.data^;
  541. hp:=root;
  542. root:=root^.next;
  543. stringdispose(hp^.data);
  544. file_info:=hp^.fileinfo;
  545. dispose(hp);
  546. end;
  547. end;
  548. function tstringcontainer.find(const s:string):boolean;
  549. var
  550. hp : pstringitem;
  551. begin
  552. find:=false;
  553. hp:=root;
  554. while assigned(hp) do
  555. begin
  556. if hp^.data^=s then
  557. begin
  558. find:=true;
  559. exit;
  560. end;
  561. hp:=hp^.next;
  562. end;
  563. end;
  564. {****************************************************************************
  565. TLINKEDLIST_ITEM
  566. ****************************************************************************}
  567. constructor tlinkedlist_item.init;
  568. begin
  569. previous:=nil;
  570. next:=nil;
  571. end;
  572. destructor tlinkedlist_item.done;
  573. begin
  574. end;
  575. function tlinkedlist_item.getcopy:plinkedlist_item;
  576. var
  577. l : longint;
  578. p : plinkedlist_item;
  579. begin
  580. l:=sizeof(self);
  581. getmem(p,l);
  582. move(self,p^,l);
  583. getcopy:=p;
  584. end;
  585. {****************************************************************************
  586. TSTRING_ITEM
  587. ****************************************************************************}
  588. constructor tstring_item.init(const s : string);
  589. begin
  590. str:=stringdup(s);
  591. end;
  592. destructor tstring_item.done;
  593. begin
  594. stringdispose(str);
  595. inherited done;
  596. end;
  597. {****************************************************************************
  598. TLINKEDLIST
  599. ****************************************************************************}
  600. constructor tlinkedlist.init;
  601. begin
  602. first:=nil;
  603. last:=nil;
  604. end;
  605. destructor tlinkedlist.done;
  606. begin
  607. clear;
  608. end;
  609. procedure tlinkedlist.clear;
  610. var
  611. hp : plinkedlist_item;
  612. begin
  613. hp:=first;
  614. while assigned(hp) do
  615. begin
  616. first:=hp^.next;
  617. dispose(hp,done);
  618. hp:=first;
  619. end;
  620. end;
  621. procedure tlinkedlist.insertlist(p : plinkedlist);
  622. begin
  623. { empty list ? }
  624. if not(assigned(p^.first)) then
  625. exit;
  626. p^.last^.next:=first;
  627. { we have a double linked list }
  628. if assigned(first) then
  629. first^.previous:=p^.last;
  630. first:=p^.first;
  631. if not(assigned(last)) then
  632. last:=p^.last;
  633. { p becomes empty }
  634. p^.first:=nil;
  635. p^.last:=nil;
  636. end;
  637. procedure tlinkedlist.concat(p : plinkedlist_item);
  638. begin
  639. if not(assigned(first)) then
  640. begin
  641. first:=p;
  642. p^.previous:=nil;
  643. p^.next:=nil;
  644. end
  645. else
  646. begin
  647. last^.next:=p;
  648. p^.previous:=last;
  649. p^.next:=nil;
  650. end;
  651. last:=p;
  652. end;
  653. procedure tlinkedlist.insert(p : plinkedlist_item);
  654. begin
  655. if not(assigned(first)) then
  656. begin
  657. last:=p;
  658. p^.previous:=nil;
  659. p^.next:=nil;
  660. end
  661. else
  662. begin
  663. first^.previous:=p;
  664. p^.previous:=nil;
  665. p^.next:=first;
  666. end;
  667. first:=p;
  668. end;
  669. procedure tlinkedlist.remove(p : plinkedlist_item);
  670. begin
  671. if not(assigned(p)) then
  672. exit;
  673. if (first=p) and (last=p) then
  674. begin
  675. first:=nil;
  676. last:=nil;
  677. end
  678. else if first=p then
  679. begin
  680. first:=p^.next;
  681. if assigned(first) then
  682. first^.previous:=nil;
  683. end
  684. else if last=p then
  685. begin
  686. last:=last^.previous;
  687. if assigned(last) then
  688. last^.next:=nil;
  689. end
  690. else
  691. begin
  692. p^.previous^.next:=p^.next;
  693. p^.next^.previous:=p^.previous;
  694. end;
  695. p^.next:=nil;
  696. p^.previous:=nil;
  697. end;
  698. procedure tlinkedlist.concatlist(p : plinkedlist);
  699. begin
  700. if not(assigned(p^.first)) then
  701. exit;
  702. if not(assigned(first)) then
  703. first:=p^.first
  704. else
  705. begin
  706. last^.next:=p^.first;
  707. p^.first^.previous:=last;
  708. end;
  709. last:=p^.last;
  710. { make p empty }
  711. p^.last:=nil;
  712. p^.first:=nil;
  713. end;
  714. procedure tlinkedlist.concatlistcopy(p : plinkedlist);
  715. var
  716. hp,hp2 : plinkedlist_item;
  717. begin
  718. hp:=p^.first;
  719. while assigned(hp) do
  720. begin
  721. hp2:=hp^.getcopy;
  722. if assigned(hp2) then
  723. begin
  724. if not(assigned(first)) then
  725. begin
  726. first:=hp2;
  727. hp2^.previous:=nil;
  728. hp2^.next:=nil;
  729. end
  730. else
  731. begin
  732. last^.next:=hp2;
  733. hp2^.previous:=last;
  734. hp2^.next:=nil;
  735. end;
  736. last:=hp2;
  737. end;
  738. hp:=hp^.next;
  739. end;
  740. end;
  741. function tlinkedlist.empty:boolean;
  742. begin
  743. empty:=(first=nil);
  744. end;
  745. {****************************************************************************
  746. TNAMED_OBJECT
  747. ****************************************************************************}
  748. constructor Tnamed_object.init(const n:string);
  749. begin
  750. left:=nil;
  751. right:=nil;
  752. _name:=stringdup(n);
  753. speedvalue:=getspeedvalue(n);
  754. end;
  755. destructor Tnamed_object.done;
  756. begin
  757. stringdispose(_name);
  758. if assigned(left) then
  759. dispose(left,done);
  760. if assigned(right) then
  761. dispose(right,done);
  762. end;
  763. function Tnamed_object.name:string;
  764. begin
  765. name:=_name^;
  766. end;
  767. {****************************************************************************
  768. TDICTIONARY
  769. ****************************************************************************}
  770. constructor Tdictionary.init(usehash:boolean);
  771. begin
  772. root:=nil;
  773. hasharray:=nil;
  774. replace_existing:=false;
  775. if usehash then
  776. begin
  777. new(hasharray);
  778. fillchar(hasharray^,sizeof(hasharray^),0);
  779. end;
  780. end;
  781. procedure Tdictionary.clear;
  782. var w:longint;
  783. begin
  784. {remove no entry from a withsymtable as it is only a pointer to the
  785. recorddef or objectdef symtable }
  786. { remove all entry from a symbol table }
  787. if assigned(root) then
  788. dispose(root,done);
  789. if assigned(hasharray) then
  790. for w:=0 to hasharraysize-1 do
  791. if assigned(hasharray^[w]) then
  792. begin
  793. dispose(hasharray^[w],done);
  794. hasharray^[w]:=nil;
  795. end;
  796. end;
  797. procedure Tdictionary.foreach(proc2call:Tcallback);
  798. procedure a(p:Pnamed_object);
  799. { must be preorder, because it's used by reading in }
  800. { a PPU file }
  801. begin
  802. proc2call(p);
  803. if assigned(p^.left) then
  804. a(p^.left);
  805. if assigned(p^.right) then
  806. a(p^.right);
  807. end;
  808. var i:longint;
  809. begin
  810. if assigned(hasharray) then
  811. begin
  812. for i:=0 to hasharraysize-1 do
  813. if assigned(hasharray^[i]) then
  814. a(hasharray^[i]);
  815. end
  816. else
  817. if assigned(root) then
  818. a(root);
  819. end;
  820. function Tdictionary.insert(obj:Pnamed_object):Pnamed_object;
  821. function _insert(var osym:Pnamed_object):Pnamed_object;
  822. {To prevent TP from allocating temp space for temp strings, we allocate
  823. some temp strings manually. We can use two temp strings, plus a third
  824. one that TP adds, where TP alone needs five temp strings!. Storing
  825. these on the heap saves even more, totally 1016 bytes per recursion!}
  826. var s1,s2:^string;
  827. begin
  828. if osym=nil then
  829. begin
  830. osym:=obj;
  831. _insert:=osym;
  832. end
  833. { first check speedvalue, to allow a fast insert }
  834. else
  835. if osym^.speedvalue>obj^.speedvalue then
  836. _insert:=_insert(osym^.right)
  837. else
  838. if osym^.speedvalue<obj^.speedvalue then
  839. _insert:=_insert(osym^.left)
  840. else
  841. begin
  842. new(s1);
  843. new(s2);
  844. s1^:=osym^._name^;
  845. s2^:=obj^._name^;
  846. if s1^>s2^ then
  847. begin
  848. dispose(s2);
  849. dispose(s1);
  850. _insert:=_insert(osym^.right);
  851. end
  852. else
  853. if s1^<s2^ then
  854. begin
  855. dispose(s2);
  856. dispose(s1);
  857. _insert:=_insert(osym^.left);
  858. end
  859. else
  860. begin
  861. dispose(s2);
  862. dispose(s1);
  863. if replace_existing and
  864. assigned(osym) then
  865. begin
  866. obj^.left:=osym^.left;
  867. obj^.right:=osym^.right;
  868. osym:=obj;
  869. _insert:=obj;
  870. end
  871. else
  872. _insert:=osym;
  873. end;
  874. end;
  875. end;
  876. begin
  877. obj^.owner:=@self;
  878. obj^.speedvalue:=getspeedvalue(obj^._name^);
  879. if assigned(hasharray) then
  880. insert:=_insert(hasharray^[obj^.speedvalue mod hasharraysize])
  881. else
  882. insert:=_insert(root);
  883. end;
  884. function Tdictionary.search(const s:string):Pnamed_object;
  885. begin
  886. search:=speedsearch(s,getspeedvalue(s));
  887. end;
  888. function Tdictionary.speedsearch(const s:string;
  889. speedvalue:longint):Pnamed_object;
  890. var hp:Pnamed_object;
  891. begin
  892. if assigned(hasharray) then
  893. hp:=hasharray^[speedvalue mod hasharraysize]
  894. else
  895. hp:=root;
  896. while assigned(hp) do
  897. begin
  898. if speedvalue>hp^.speedvalue then
  899. hp:=hp^.left
  900. else
  901. if speedvalue<hp^.speedvalue then
  902. hp:=hp^.right
  903. else
  904. begin
  905. if (hp^._name^=s) then
  906. begin
  907. speedsearch:=hp;
  908. exit;
  909. end
  910. else
  911. if s>hp^._name^ then
  912. hp:=hp^.left
  913. else
  914. hp:=hp^.right;
  915. end;
  916. end;
  917. speedsearch:=nil;
  918. end;
  919. destructor Tdictionary.done;
  920. begin
  921. clear;
  922. if assigned(hasharray) then
  923. dispose(hasharray);
  924. end;
  925. {****************************************************************************
  926. tdynamicarray
  927. ****************************************************************************}
  928. constructor tdynamicarray.init(Aelemlen,Agrow:longint);
  929. begin
  930. posn:=0;
  931. count:=0;
  932. limit:=0;
  933. data:=nil;
  934. elemlen:=Aelemlen;
  935. growcount:=Agrow;
  936. grow;
  937. end;
  938. function tdynamicarray.size:longint;
  939. begin
  940. size:=limit*elemlen;
  941. end;
  942. function tdynamicarray.usedsize:longint;
  943. begin
  944. usedsize:=count*elemlen;
  945. end;
  946. procedure tdynamicarray.grow;
  947. var
  948. osize : longint;
  949. odata : pchar;
  950. begin
  951. osize:=size;
  952. odata:=data;
  953. inc(limit,growcount);
  954. getmem(data,size);
  955. if assigned(odata) then
  956. begin
  957. move(odata^,data^,osize);
  958. freemem(odata,osize);
  959. end;
  960. fillchar(data[osize],growcount*elemlen,0);
  961. end;
  962. procedure tdynamicarray.align(i:longint);
  963. var
  964. j : longint;
  965. begin
  966. j:=(posn*elemlen mod i);
  967. if j<>0 then
  968. begin
  969. j:=i-j;
  970. while limit<(posn+j) do
  971. grow;
  972. inc(posn,j);
  973. if (posn>count) then
  974. count:=posn;
  975. end;
  976. end;
  977. procedure tdynamicarray.seek(i:longint);
  978. begin
  979. while limit<i do
  980. grow;
  981. posn:=i;
  982. if (posn>count) then
  983. count:=posn;
  984. end;
  985. procedure tdynamicarray.write(var d;len:longint);
  986. begin
  987. while limit<(posn+len) do
  988. grow;
  989. move(d,data[posn*elemlen],len*elemlen);
  990. inc(posn,len);
  991. if (posn>count) then
  992. count:=posn;
  993. end;
  994. procedure tdynamicarray.read(var d;len:longint);
  995. begin
  996. move(data[posn*elemlen],d,len*elemlen);
  997. inc(posn,len);
  998. if (posn>count) then
  999. count:=posn;
  1000. end;
  1001. procedure tdynamicarray.writepos(pos:longint;var d;len:longint);
  1002. begin
  1003. while limit<(pos+len) do
  1004. grow;
  1005. move(d,data[pos*elemlen],len*elemlen);
  1006. posn:=pos+len;
  1007. if (posn>count) then
  1008. count:=posn;
  1009. end;
  1010. procedure tdynamicarray.readpos(pos:longint;var d;len:longint);
  1011. begin
  1012. while limit<(pos+len) do
  1013. grow;
  1014. move(data[pos*elemlen],d,len*elemlen);
  1015. posn:=pos+len;
  1016. if (posn>count) then
  1017. count:=posn;
  1018. end;
  1019. destructor tdynamicarray.done;
  1020. begin
  1021. if assigned(data) then
  1022. freemem(data,size);
  1023. end;
  1024. {$ifdef BUFFEREDFILE}
  1025. {****************************************************************************
  1026. TBUFFEREDFILE
  1027. ****************************************************************************}
  1028. Const
  1029. crcseed = $ffffffff;
  1030. crctable : array[0..255] of longint = (
  1031. $00000000,$77073096,$ee0e612c,$990951ba,$076dc419,$706af48f,
  1032. $e963a535,$9e6495a3,$0edb8832,$79dcb8a4,$e0d5e91e,$97d2d988,
  1033. $09b64c2b,$7eb17cbd,$e7b82d07,$90bf1d91,$1db71064,$6ab020f2,
  1034. $f3b97148,$84be41de,$1adad47d,$6ddde4eb,$f4d4b551,$83d385c7,
  1035. $136c9856,$646ba8c0,$fd62f97a,$8a65c9ec,$14015c4f,$63066cd9,
  1036. $fa0f3d63,$8d080df5,$3b6e20c8,$4c69105e,$d56041e4,$a2677172,
  1037. $3c03e4d1,$4b04d447,$d20d85fd,$a50ab56b,$35b5a8fa,$42b2986c,
  1038. $dbbbc9d6,$acbcf940,$32d86ce3,$45df5c75,$dcd60dcf,$abd13d59,
  1039. $26d930ac,$51de003a,$c8d75180,$bfd06116,$21b4f4b5,$56b3c423,
  1040. $cfba9599,$b8bda50f,$2802b89e,$5f058808,$c60cd9b2,$b10be924,
  1041. $2f6f7c87,$58684c11,$c1611dab,$b6662d3d,$76dc4190,$01db7106,
  1042. $98d220bc,$efd5102a,$71b18589,$06b6b51f,$9fbfe4a5,$e8b8d433,
  1043. $7807c9a2,$0f00f934,$9609a88e,$e10e9818,$7f6a0dbb,$086d3d2d,
  1044. $91646c97,$e6635c01,$6b6b51f4,$1c6c6162,$856530d8,$f262004e,
  1045. $6c0695ed,$1b01a57b,$8208f4c1,$f50fc457,$65b0d9c6,$12b7e950,
  1046. $8bbeb8ea,$fcb9887c,$62dd1ddf,$15da2d49,$8cd37cf3,$fbd44c65,
  1047. $4db26158,$3ab551ce,$a3bc0074,$d4bb30e2,$4adfa541,$3dd895d7,
  1048. $a4d1c46d,$d3d6f4fb,$4369e96a,$346ed9fc,$ad678846,$da60b8d0,
  1049. $44042d73,$33031de5,$aa0a4c5f,$dd0d7cc9,$5005713c,$270241aa,
  1050. $be0b1010,$c90c2086,$5768b525,$206f85b3,$b966d409,$ce61e49f,
  1051. $5edef90e,$29d9c998,$b0d09822,$c7d7a8b4,$59b33d17,$2eb40d81,
  1052. $b7bd5c3b,$c0ba6cad,$edb88320,$9abfb3b6,$03b6e20c,$74b1d29a,
  1053. $ead54739,$9dd277af,$04db2615,$73dc1683,$e3630b12,$94643b84,
  1054. $0d6d6a3e,$7a6a5aa8,$e40ecf0b,$9309ff9d,$0a00ae27,$7d079eb1,
  1055. $f00f9344,$8708a3d2,$1e01f268,$6906c2fe,$f762575d,$806567cb,
  1056. $196c3671,$6e6b06e7,$fed41b76,$89d32be0,$10da7a5a,$67dd4acc,
  1057. $f9b9df6f,$8ebeeff9,$17b7be43,$60b08ed5,$d6d6a3e8,$a1d1937e,
  1058. $38d8c2c4,$4fdff252,$d1bb67f1,$a6bc5767,$3fb506dd,$48b2364b,
  1059. $d80d2bda,$af0a1b4c,$36034af6,$41047a60,$df60efc3,$a867df55,
  1060. $316e8eef,$4669be79,$cb61b38c,$bc66831a,$256fd2a0,$5268e236,
  1061. $cc0c7795,$bb0b4703,$220216b9,$5505262f,$c5ba3bbe,$b2bd0b28,
  1062. $2bb45a92,$5cb36a04,$c2d7ffa7,$b5d0cf31,$2cd99e8b,$5bdeae1d,
  1063. $9b64c2b0,$ec63f226,$756aa39c,$026d930a,$9c0906a9,$eb0e363f,
  1064. $72076785,$05005713,$95bf4a82,$e2b87a14,$7bb12bae,$0cb61b38,
  1065. $92d28e9b,$e5d5be0d,$7cdcefb7,$0bdbdf21,$86d3d2d4,$f1d4e242,
  1066. $68ddb3f8,$1fda836e,$81be16cd,$f6b9265b,$6fb077e1,$18b74777,
  1067. $88085ae6,$ff0f6a70,$66063bca,$11010b5c,$8f659eff,$f862ae69,
  1068. $616bffd3,$166ccf45,$a00ae278,$d70dd2ee,$4e048354,$3903b3c2,
  1069. $a7672661,$d06016f7,$4969474d,$3e6e77db,$aed16a4a,$d9d65adc,
  1070. $40df0b66,$37d83bf0,$a9bcae53,$debb9ec5,$47b2cf7f,$30b5ffe9,
  1071. $bdbdf21c,$cabac28a,$53b39330,$24b4a3a6,$bad03605,$cdd70693,
  1072. $54de5729,$23d967bf,$b3667a2e,$c4614ab8,$5d681b02,$2a6f2b94,
  1073. $b40bbe37,$c30c8ea1,$5a05df1b,$2d02ef8d);
  1074. constructor tbufferedfile.init(const filename : string;_bufsize : longint);
  1075. begin
  1076. assign(f,filename);
  1077. bufsize:=_bufsize;
  1078. bufpos:=0;
  1079. buflast:=0;
  1080. do_crc:=false;
  1081. iomode:=0;
  1082. tempclosed:=false;
  1083. change_endian:=false;
  1084. clear_crc;
  1085. end;
  1086. destructor tbufferedfile.done;
  1087. begin
  1088. close;
  1089. end;
  1090. procedure tbufferedfile.clear_crc;
  1091. begin
  1092. crc:=crcseed;
  1093. end;
  1094. procedure tbufferedfile.setbuf(p : pchar;s : longint);
  1095. begin
  1096. flush;
  1097. freemem(buf,bufsize);
  1098. bufsize:=s;
  1099. buf:=p;
  1100. end;
  1101. function tbufferedfile.reset:boolean;
  1102. var
  1103. ofm : byte;
  1104. begin
  1105. ofm:=filemode;
  1106. iomode:=1;
  1107. getmem(buf,bufsize);
  1108. filemode:=0;
  1109. {$I-}
  1110. system.reset(f,1);
  1111. {$I+}
  1112. reset:=(ioresult=0);
  1113. filemode:=ofm;
  1114. end;
  1115. procedure tbufferedfile.rewrite;
  1116. begin
  1117. iomode:=2;
  1118. getmem(buf,bufsize);
  1119. system.rewrite(f,1);
  1120. end;
  1121. procedure tbufferedfile.flush;
  1122. var
  1123. {$ifdef FPC}
  1124. count : longint;
  1125. {$else}
  1126. count : integer;
  1127. {$endif}
  1128. begin
  1129. if iomode=2 then
  1130. begin
  1131. if bufpos=0 then
  1132. exit;
  1133. blockwrite(f,buf^,bufpos)
  1134. end
  1135. else if iomode=1 then
  1136. if buflast=bufpos then
  1137. begin
  1138. blockread(f,buf^,bufsize,count);
  1139. buflast:=count;
  1140. end;
  1141. bufpos:=0;
  1142. end;
  1143. function tbufferedfile.getftime : longint;
  1144. var
  1145. l : longint;
  1146. {$ifdef linux}
  1147. Info : Stat;
  1148. {$endif}
  1149. begin
  1150. {$ifndef linux}
  1151. { this only works if the file is open !! }
  1152. dos.getftime(f,l);
  1153. {$else}
  1154. Fstat(f,Info);
  1155. l:=info.mtime;
  1156. {$endif}
  1157. getftime:=l;
  1158. end;
  1159. function tbufferedfile.getsize : longint;
  1160. begin
  1161. getsize:=filesize(f);
  1162. end;
  1163. procedure tbufferedfile.seek(l : longint);
  1164. begin
  1165. if iomode=2 then
  1166. begin
  1167. flush;
  1168. system.seek(f,l);
  1169. end
  1170. else if iomode=1 then
  1171. begin
  1172. { forces a reload }
  1173. bufpos:=buflast;
  1174. system.seek(f,l);
  1175. flush;
  1176. end;
  1177. end;
  1178. type
  1179. {$ifdef tp}
  1180. bytearray1 = array [1..65535] of byte;
  1181. {$else}
  1182. bytearray1 = array [1..10000000] of byte;
  1183. {$endif}
  1184. procedure tbufferedfile.read_data(var data;bytes : longint;var count : longint);
  1185. var
  1186. p : pchar;
  1187. c,i : longint;
  1188. begin
  1189. p:=pchar(@data);
  1190. count:=0;
  1191. while bytes-count>0 do
  1192. begin
  1193. if bytes-count>buflast-bufpos then
  1194. begin
  1195. move((buf+bufpos)^,(p+count)^,buflast-bufpos);
  1196. inc(count,buflast-bufpos);
  1197. bufpos:=buflast;
  1198. flush;
  1199. { can't we read anything ? }
  1200. if bufpos=buflast then
  1201. break;
  1202. end
  1203. else
  1204. begin
  1205. move((buf+bufpos)^,(p+count)^,bytes-count);
  1206. inc(bufpos,bytes-count);
  1207. count:=bytes;
  1208. break;
  1209. end;
  1210. end;
  1211. if do_crc then
  1212. begin
  1213. c:=crc;
  1214. for i:=1 to bytes do
  1215. c:=(c shr 8) xor crctable[byte(c) xor (bytearray1(data)[i])];
  1216. crc:=c;
  1217. end;
  1218. end;
  1219. procedure tbufferedfile.write_data(var data;count : longint);
  1220. var
  1221. c,i : longint;
  1222. begin
  1223. if bufpos+count>bufsize then
  1224. flush;
  1225. move(data,(buf+bufpos)^,count);
  1226. inc(bufpos,count);
  1227. if do_crc then
  1228. begin
  1229. c:=crc;
  1230. for i:=1 to count do
  1231. c:=(c shr 8) xor crctable[byte(c) xor (bytearray1(data)[i])];
  1232. crc:=c;
  1233. end;
  1234. end;
  1235. function tbufferedfile.getcrc : longint;
  1236. begin
  1237. getcrc:=crc xor crcseed;
  1238. end;
  1239. procedure tbufferedfile.write_string(const s : string);
  1240. begin
  1241. if bufpos+length(s)>bufsize then
  1242. flush;
  1243. { why is there not CRC here ??? }
  1244. move(s[1],(buf+bufpos)^,length(s));
  1245. inc(bufpos,length(s));
  1246. { should be
  1247. write_data(s[1],length(s)); }
  1248. end;
  1249. procedure tbufferedfile.write_pchar(p : pchar);
  1250. var
  1251. l : longint;
  1252. begin
  1253. l:=strlen(p);
  1254. if l>=bufsize then
  1255. runerror(222);
  1256. { why is there not CRC here ???}
  1257. if bufpos+l>bufsize then
  1258. flush;
  1259. move(p^,(buf+bufpos)^,l);
  1260. inc(bufpos,l);
  1261. { should be
  1262. write_data(p^,l); }
  1263. end;
  1264. procedure tbufferedfile.write_byte(b : byte);
  1265. begin
  1266. write_data(b,sizeof(byte));
  1267. end;
  1268. procedure tbufferedfile.write_long(l : longint);
  1269. var
  1270. w1,w2 : word;
  1271. begin
  1272. if change_endian then
  1273. begin
  1274. w1:=l and $ffff;
  1275. w2:=l shr 16;
  1276. l:=swap(w2)+(longint(swap(w1)) shl 16);
  1277. write_data(l,sizeof(longint))
  1278. end
  1279. else
  1280. write_data(l,sizeof(longint))
  1281. end;
  1282. procedure tbufferedfile.write_word(w : word);
  1283. begin
  1284. if change_endian then
  1285. begin
  1286. w:=swap(w);
  1287. write_data(w,sizeof(word))
  1288. end
  1289. else
  1290. write_data(w,sizeof(word));
  1291. end;
  1292. procedure tbufferedfile.write_double(d : double);
  1293. begin
  1294. write_data(d,sizeof(double));
  1295. end;
  1296. function tbufferedfile.getpath : string;
  1297. begin
  1298. {$ifdef dummy}
  1299. getpath:=strpas(filerec(f).name);
  1300. {$endif}
  1301. getpath:='';
  1302. end;
  1303. procedure tbufferedfile.close;
  1304. begin
  1305. if iomode<>0 then
  1306. begin
  1307. flush;
  1308. system.close(f);
  1309. freemem(buf,bufsize);
  1310. buf:=nil;
  1311. iomode:=0;
  1312. end;
  1313. end;
  1314. procedure tbufferedfile.tempclose;
  1315. begin
  1316. if iomode<>0 then
  1317. begin
  1318. temppos:=system.filepos(f);
  1319. tempmode:=iomode;
  1320. tempclosed:=true;
  1321. system.close(f);
  1322. iomode:=0;
  1323. end
  1324. else
  1325. tempclosed:=false;
  1326. end;
  1327. procedure tbufferedfile.tempreopen;
  1328. var
  1329. ofm : byte;
  1330. begin
  1331. if tempclosed then
  1332. begin
  1333. case tempmode of
  1334. 1 : begin
  1335. ofm:=filemode;
  1336. iomode:=1;
  1337. filemode:=0;
  1338. system.reset(f,1);
  1339. filemode:=ofm;
  1340. end;
  1341. 2 : begin
  1342. iomode:=2;
  1343. system.rewrite(f,1);
  1344. end;
  1345. end;
  1346. system.seek(f,temppos);
  1347. tempclosed:=false;
  1348. end;
  1349. end;
  1350. {$endif BUFFEREDFILE}
  1351. end.
  1352. {
  1353. $Log$
  1354. Revision 1.23 1999-04-08 20:59:39 florian
  1355. * fixed problem with default properties which are a class
  1356. * case bug (from the mailing list with -O2) fixed, the
  1357. distance of the case labels can be greater than the positive
  1358. range of a longint => it is now a dword for fpc
  1359. Revision 1.22 1999/03/31 13:55:10 peter
  1360. * assembler inlining working for ag386bin
  1361. Revision 1.21 1999/03/19 16:35:29 pierre
  1362. * Tnamed_object done also removed left and right
  1363. Revision 1.20 1999/03/18 20:30:45 peter
  1364. + .a writer
  1365. Revision 1.19 1999/03/01 13:32:00 pierre
  1366. * external used before implemented problem fixed
  1367. Revision 1.18 1999/02/24 00:59:13 peter
  1368. * small updates for ag386bin
  1369. Revision 1.17 1999/01/19 11:00:33 daniel
  1370. + Tdictionary object: Tsymtable will become object(TTdictionary) in the
  1371. future
  1372. + Tnamed_item object: Tsym will become object(Tnamed_item) in the future
  1373. Revision 1.16 1998/11/04 10:11:37 peter
  1374. * ansistring fixes
  1375. Revision 1.15 1998/10/19 18:04:40 peter
  1376. + tstringcontainer.init_no_doubles
  1377. Revision 1.14 1998/09/18 16:03:37 florian
  1378. * some changes to compile with Delphi
  1379. Revision 1.13 1998/08/12 19:28:16 peter
  1380. * better libc support
  1381. Revision 1.12 1998/07/14 14:46:47 peter
  1382. * released NEWINPUT
  1383. Revision 1.11 1998/07/07 11:19:54 peter
  1384. + NEWINPUT for a better inputfile and scanner object
  1385. Revision 1.10 1998/07/01 15:26:59 peter
  1386. * better bufferfile.reset error handling
  1387. Revision 1.9 1998/06/03 23:40:37 peter
  1388. + unlimited file support, release tempclose
  1389. Revision 1.8 1998/05/20 09:42:33 pierre
  1390. + UseTokenInfo now default
  1391. * unit in interface uses and implementation uses gives error now
  1392. * only one error for unknown symbol (uses lastsymknown boolean)
  1393. the problem came from the label code !
  1394. + first inlined procedures and function work
  1395. (warning there might be allowed cases were the result is still wrong !!)
  1396. * UseBrower updated gives a global list of all position of all used symbols
  1397. with switch -gb
  1398. Revision 1.7 1998/05/06 18:36:53 peter
  1399. * tai_section extended with code,data,bss sections and enumerated type
  1400. * ident 'compiled by FPC' moved to pmodules
  1401. * small fix for smartlink
  1402. Revision 1.6 1998/05/06 08:38:37 pierre
  1403. * better position info with UseTokenInfo
  1404. UseTokenInfo greatly simplified
  1405. + added check for changed tree after first time firstpass
  1406. (if we could remove all the cases were it happen
  1407. we could skip all firstpass if firstpasscount > 1)
  1408. Only with ExtDebug
  1409. Revision 1.5 1998/04/30 15:59:40 pierre
  1410. * GDB works again better :
  1411. correct type info in one pass
  1412. + UseTokenInfo for better source position
  1413. * fixed one remaining bug in scanner for line counts
  1414. * several little fixes
  1415. Revision 1.4 1998/04/29 10:33:50 pierre
  1416. + added some code for ansistring (not complete nor working yet)
  1417. * corrected operator overloading
  1418. * corrected nasm output
  1419. + started inline procedures
  1420. + added starstarn : use ** for exponentiation (^ gave problems)
  1421. + started UseTokenInfo cond to get accurate positions
  1422. Revision 1.3 1998/04/27 23:10:28 peter
  1423. + new scanner
  1424. * $makelib -> if smartlink
  1425. * small filename fixes pmodule.setfilename
  1426. * moved import from files.pas -> import.pas
  1427. Revision 1.2 1998/04/07 11:09:04 peter
  1428. + filemode is set correct in tbufferedfile.reset
  1429. }