fixgdk.pp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 fixreplace(var s:string);
  70. begin
  71. replace(s,'P_GDK','PGdk',false);
  72. replace(s,'= ^T_GDK','= ^TGdk',false);
  73. replace(s,'^T_GDK','PGdk',false);
  74. replace(s,'T_GDK','TGdk',false);
  75. replace(s,'^GDK','PGdk',false);
  76. replace(s,'EXTERNAL_LIBRARY','gdkdll',false);
  77. end;
  78. var
  79. t,f : text;
  80. ssmall : string[20];
  81. hs,
  82. s : string;
  83. name : string;
  84. i : word;
  85. func,
  86. impl : boolean;
  87. begin
  88. impl:=false;
  89. assign(t,paramstr(1));
  90. assign(f,'fixgdk.tmp');
  91. reset(t);
  92. rewrite(f);
  93. writeln(f,'{');
  94. writeln(f,'}');
  95. writeln(f,'');
  96. writeln(f,'{$ifndef gdk_include_files}');
  97. writeln(f,' {$define read_interface}');
  98. writeln(f,' {$define read_implementation}');
  99. writeln(f,'{$endif not gdk_include_files}');
  100. writeln(f,'');
  101. writeln(f,'{$ifndef gdk_include_files}');
  102. writeln(f,'');
  103. writeln(f,' unit ',Copy(paramstr(1),1,pos('.',paramstr(1))-1),';');
  104. writeln(f,' interface');
  105. writeln(f,'');
  106. writeln(f,' uses');
  107. writeln(f,' glib,gdkmain,');
  108. writeln(f,' gtkobjects;');
  109. writeln(f,'');
  110. writeln(f,' {$ifdef win32}');
  111. writeln(f,' const');
  112. writeln(f,' gtkdll=''gdk-1.1.dll''; { leave the .dll else .1.1 -> .1 !! }');
  113. writeln(f,' {$else}');
  114. writeln(f,' const');
  115. writeln(f,' gtkdll=''gdk.so'';');
  116. writeln(f,' {$linklib c}');
  117. writeln(f,' {$endif}');
  118. writeln(f,'');
  119. writeln(f,' Type');
  120. writeln(f,' PLongint = ^Longint;');
  121. writeln(f,' PByte = ^Byte;');
  122. writeln(f,' PWord = ^Word;');
  123. writeln(f,' PINteger = ^Integer;');
  124. writeln(f,' PCardinal = ^Cardinal;');
  125. writeln(f,' PReal = ^Real;');
  126. writeln(f,' PDouble = ^Double;');
  127. writeln(f,'');
  128. writeln(f,'{$endif not gdk_include_files}');
  129. writeln(f,'');
  130. writeln(f,'{$ifdef read_interface}');
  131. writeln(f,'');
  132. while not eof(t) do
  133. begin
  134. read(t,ssmall);
  135. fixreplace(ssmall);
  136. if (not impl) and (copy(trimspace(ssmall),1,14)='implementation') then
  137. begin
  138. impl:=true;
  139. readln(t,s);
  140. writeln(f,'{$endif read_interface}');
  141. writeln(f,'');
  142. writeln(f,'');
  143. writeln(f,'{$ifndef gdk_include_files}');
  144. writeln(f,' implementation');
  145. writeln(f,'{$endif not gdk_include_files}');
  146. writeln(f,'');
  147. writeln(f,'{$ifdef read_implementation}');
  148. writeln(f,'');
  149. continue;
  150. end;
  151. if (impl) and (copy(trimspace(ssmall),1,4)='end.') then
  152. begin
  153. writeln(f,'{$endif read_implementation}');
  154. writeln(f,'');
  155. writeln(f,'');
  156. writeln(f,'{$ifndef gdk_include_files}');
  157. writeln(f,'end.');
  158. writeln(f,'{$endif not gdk_include_files}');
  159. writeln(f,'');
  160. writeln(f,'{');
  161. Revision 1.3 2005/02/14 17:13:20 peter
  162. * truncate log
  163. }