fixgtk.pp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. function lower(const s : string) : string;
  2. {
  3. return lowercased string of s
  4. }
  5. var
  6. i : longint;
  7. begin
  8. for i:=1 to length(s) do
  9. if s[i] in ['A'..'Z'] then
  10. lower[i]:=char(byte(s[i])+32)
  11. else
  12. lower[i]:=s[i];
  13. lower[0]:=s[0];
  14. end;
  15. function upper(const s : string) : string;
  16. {
  17. return lowercased string of s
  18. }
  19. var
  20. i : longint;
  21. begin
  22. for i:=1 to length(s) do
  23. if s[i] in ['a'..'z'] then
  24. upper[i]:=char(byte(s[i])-32)
  25. else
  26. upper[i]:=s[i];
  27. upper[0]:=s[0];
  28. end;
  29. function trimspace(const s:string):string;
  30. var
  31. i,j : longint;
  32. begin
  33. i:=length(s);
  34. while (i>0) and (s[i] in [#9,' ']) do
  35. dec(i);
  36. j:=1;
  37. while (j<i) and (s[j] in [#9,' ']) do
  38. inc(j);
  39. trimspace:=Copy(s,j,i-j+1);
  40. end;
  41. function trimbegin(const s:string):string;
  42. var
  43. i,j : longint;
  44. begin
  45. i:=length(s);
  46. j:=1;
  47. while (j<i) and (s[j] in [#9,' ']) do
  48. inc(j);
  49. trimbegin:=Copy(s,j,i-j+1);
  50. end;
  51. procedure Replace(var s:string;const s1,s2:string;single:boolean);
  52. var
  53. last,
  54. i : longint;
  55. begin
  56. last:=0;
  57. repeat
  58. i:=pos(s1,upper(s));
  59. if i=last then
  60. i:=0;
  61. if (i>0) then
  62. begin
  63. Delete(s,i,length(s1));
  64. Insert(s2,s,i);
  65. last:=i;
  66. end;
  67. until single or (i=0);
  68. end;
  69. procedure ReplaceCase(var s:string;const s1,s2:string;single:boolean);
  70. var
  71. last,
  72. i : longint;
  73. begin
  74. last:=0;
  75. repeat
  76. i:=pos(s1,s);
  77. if i=last then
  78. i:=0;
  79. if (i>0) then
  80. begin
  81. Delete(s,i,length(s1));
  82. Insert(s2,s,i);
  83. last:=i;
  84. end;
  85. until single or (i=0);
  86. end;
  87. procedure fixreplace(var s:string);
  88. begin
  89. replace(s,'P_GTK','PGtk',false);
  90. replace(s,'= ^T_GTK','= ^TGtk',false);
  91. replace(s,'^T_GTK','PGtk',false);
  92. replace(s,'T_GTK','TGtk',false);
  93. replace(s,'^GTK','PGtk',false);
  94. replace(s,'EXTERNAL_LIBRARY','gtkdll',false);
  95. replacecase(s,' Gtk',' TGtk',false);
  96. replacecase(s,':Gtk',':TGtk',false);
  97. replace(s,'^G','PG',false);
  98. end;
  99. var
  100. t,f : text;
  101. ssmall : string[20];
  102. hs,
  103. s : string;
  104. name : string;
  105. i : word;
  106. func,
  107. impl : boolean;
  108. begin
  109. impl:=false;
  110. assign(t,paramstr(1));
  111. assign(f,'fixgtk.tmp');
  112. reset(t);
  113. rewrite(f);
  114. writeln(f,'{');
  115. writeln(f,' $Id$');
  116. writeln(f,'}');
  117. writeln(f,'');
  118. writeln(f,'{$ifndef gtk_include_files}');
  119. writeln(f,' {$define read_interface}');
  120. writeln(f,' {$define read_implementation}');
  121. writeln(f,'{$endif not gtk_include_files}');
  122. writeln(f,'');
  123. writeln(f,'{$ifndef gtk_include_files}');
  124. writeln(f,'');
  125. writeln(f,' unit ',Copy(paramstr(1),1,pos('.',paramstr(1))-1),';');
  126. writeln(f,' interface');
  127. writeln(f,'');
  128. writeln(f,' uses');
  129. writeln(f,' glib,gdkmain,');
  130. writeln(f,' gtkobjects;');
  131. writeln(f,'');
  132. writeln(f,' {$ifdef win32}');
  133. writeln(f,' const');
  134. writeln(f,' gtkdll=''gtk-1.1.dll''; { leave the .dll else .1.1 -> .1 !! }');
  135. writeln(f,' {$else}');
  136. writeln(f,' const');
  137. writeln(f,' gtkdll=''gtk.so'';');
  138. writeln(f,' {$linklib c}');
  139. writeln(f,' {$endif}');
  140. writeln(f,'');
  141. writeln(f,' Type');
  142. writeln(f,' PLongint = ^Longint;');
  143. writeln(f,' PByte = ^Byte;');
  144. writeln(f,' PWord = ^Word;');
  145. writeln(f,' PINteger = ^Integer;');
  146. writeln(f,' PCardinal = ^Cardinal;');
  147. writeln(f,' PReal = ^Real;');
  148. writeln(f,' PDouble = ^Double;');
  149. writeln(f,'');
  150. writeln(f,'{$endif not gtk_include_files}');
  151. writeln(f,'');
  152. writeln(f,'{$ifdef read_interface}');
  153. writeln(f,'');
  154. while not eof(t) do
  155. begin
  156. read(t,ssmall);
  157. fixreplace(ssmall);
  158. if (not impl) and (copy(trimspace(ssmall),1,14)='implementation') then
  159. begin
  160. impl:=true;
  161. readln(t,s);
  162. writeln(f,'{$endif read_interface}');
  163. writeln(f,'');
  164. writeln(f,'');
  165. writeln(f,'{$ifndef gtk_include_files}');
  166. writeln(f,' implementation');
  167. writeln(f,'{$endif not gtk_include_files}');
  168. writeln(f,'');
  169. writeln(f,'{$ifdef read_implementation}');
  170. writeln(f,'');
  171. continue;
  172. end;
  173. if (impl) and (copy(trimspace(ssmall),1,4)='end.') then
  174. begin
  175. writeln(f,'{$endif read_implementation}');
  176. writeln(f,'');
  177. writeln(f,'');
  178. writeln(f,'{$ifndef gtk_include_files}');
  179. writeln(f,'end.');
  180. writeln(f,'{$endif not gtk_include_files}');
  181. writeln(f,'');
  182. writeln(f,'{');
  183. writeln(f,' $Log: fixgtk.pp,v $
  184. writeln(f,' Revision 1.2 1999/05/10 09:02:33 peter
  185. writeln(f,' * gtk 1.2 port working
  186. writeln(f,'');
  187. writeln(f,'}');
  188. continue;
  189. end;
  190. readln(t,s);
  191. fixreplace(s);
  192. func:=false;
  193. if lower(copy(trimspace(ssmall),1,8))='function' then
  194. begin
  195. func:=true;
  196. name:=trimspace(ssmall+s);
  197. delete(name,1,9);
  198. name:=trimspace(name);
  199. i:=1;
  200. while (name[i] in ['_','A'..'Z','a'..'z','0'..'9']) do
  201. inc(i);
  202. delete(name,i,255);
  203. hs:=trimbegin(ssmall);
  204. replace(hs,'FUNCTION','function ',true);
  205. write(f,hs);
  206. end
  207. else
  208. if lower(copy(trimspace(ssmall),1,9))='procedure' then
  209. begin
  210. func:=true;
  211. name:=trimspace(ssmall+s);
  212. delete(name,1,10);
  213. name:=trimspace(name);
  214. i:=1;
  215. while (name[i] in ['_','A'..'Z','a'..'z','0'..'9']) do
  216. inc(i);
  217. delete(name,i,255);
  218. write(f,trimbegin(ssmall));
  219. end
  220. else
  221. write(f,ssmall);
  222. if func and (copy(name,1,3)='gtk') then
  223. begin
  224. if pos('cdecl;',s)=0 then
  225. begin
  226. write(f,s);
  227. readln(t,s);
  228. end;
  229. replace(s,'CDECL;','{$ifndef win32}cdecl;{$endif}',true);
  230. writeln(f,s);
  231. end
  232. else
  233. writeln(f,s);
  234. end;
  235. close(f);
  236. close(t);
  237. erase(t);
  238. rename(f,paramstr(1));
  239. end.