fixexmcdecl.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {$mode objfpc}
  2. {$H+}
  3. uses
  4. sysutils;
  5. Function PosIdx (Const Substr : AnsiString; Const Source : AnsiString;i:longint) : Longint;
  6. var
  7. S : String;
  8. begin
  9. PosIdx:=0;
  10. if Length(SubStr)=0 then
  11. exit;
  12. while (i <= length (Source) - length (substr)) do
  13. begin
  14. inc (i);
  15. S:=copy(Source,i,length(Substr));
  16. if S=SubStr then
  17. exit(i);
  18. end;
  19. end;
  20. function trimspace(const s:string):string;
  21. var
  22. i,j : longint;
  23. begin
  24. i:=length(s);
  25. while (i>0) and (s[i] in [#9,' ']) do
  26. dec(i);
  27. j:=1;
  28. while (j<i) and (s[j] in [#9,' ']) do
  29. inc(j);
  30. trimspace:=Copy(s,j,i-j+1);
  31. end;
  32. function trimbegin(const s:string):string;
  33. var
  34. i,j : longint;
  35. begin
  36. i:=length(s);
  37. j:=1;
  38. while (j<i) and (s[j] in [#9,' ']) do
  39. inc(j);
  40. trimbegin:=Copy(s,j,i-j+1);
  41. end;
  42. procedure Replace(var s:string;const s1,s2:string);
  43. var
  44. last,
  45. i : longint;
  46. begin
  47. last:=0;
  48. repeat
  49. i:=posidx(s1,uppercase(s),last);
  50. if (i>0) then
  51. begin
  52. Delete(s,i,length(s1));
  53. Insert(s2,s,i);
  54. last:=i+1;
  55. end;
  56. until (i=0);
  57. end;
  58. procedure Conv(const fn: string);
  59. var
  60. t,f : text;
  61. lasts,funcname,
  62. s,ups : string;
  63. k,i,j : integer;
  64. gotisfunc,
  65. impl : boolean;
  66. begin
  67. writeln('processing ',fn);
  68. assign(t,fn);
  69. assign(f,'fixgdk.tmp');
  70. reset(t);
  71. rewrite(f);
  72. funcname:='';
  73. gotisfunc:=false;
  74. impl:=false;
  75. while not eof(t) do
  76. begin
  77. readln(t,s);
  78. Replace(s,'PROCEDURE','procedure');
  79. Replace(s,'FUNCTION','function');
  80. Replace(s,'FUNCTION ','function ');
  81. Replace(s,'PPG','PPG');
  82. Replace(s,'PG','PG');
  83. Replace(s,'GCHAR','gchar');
  84. Replace(s,'GUCHAR','guchar');
  85. Replace(s,'GINT','gint');
  86. Replace(s,'GUINT','guint');
  87. Replace(s,'GBOOL','gbool');
  88. Replace(s,'GSHORT','gshort');
  89. Replace(s,'GUSHORT','gushort');
  90. Replace(s,'GLONG','glong');
  91. Replace(s,'GULONG','gulong');
  92. Replace(s,'GFLOAT','gfloat');
  93. Replace(s,'GDOUBLE','gdouble');
  94. Replace(s,'GPOINTER','gpointer');
  95. Replace(s,'GCONSTPOINTER','gconstpointer');
  96. Replace(s,'GDK','Gdk');
  97. Replace(s,'GDK_','gdk_');
  98. Replace(s,'GTK','Gtk');
  99. Replace(s,'GTK_','gtk_');
  100. ups:=UpperCase(s);
  101. if Pos('IMPLEMENTATION',ups)>0 then
  102. impl:=true;
  103. i:=Pos('PROCEDURE',ups);
  104. if i>0 then
  105. if Pos('_PROCEDURE',ups)>0 then
  106. i:=0;
  107. if i=0 then
  108. begin
  109. i:=Pos('FUNCTION',ups);
  110. if Pos('_FUNCTION',ups)>0 then
  111. i:=0;
  112. end;
  113. if i<>0 then
  114. begin
  115. { Remove Spaces }
  116. j:=PosIdx(' ',s,i);
  117. while (j>0) do
  118. begin
  119. Delete(s,j,1);
  120. i:=j-1;
  121. j:=PosIdx(' ',s,i);
  122. end;
  123. ups:=UpperCase(s);
  124. { Fix Cdecl }
  125. if (Pos('g_',s)<>0) or
  126. ((i>2) and (s[i-2] in [':','='])) then
  127. begin
  128. j:=Pos('CDECL;',ups);
  129. if j=0 then
  130. j:=Length(s)+1
  131. else
  132. begin
  133. k:=Pos('{$IFNDEF WIN32}CDECL;{$ENDIF}',ups);
  134. if k>0 then
  135. begin
  136. j:=k;
  137. k:=29;
  138. end
  139. else
  140. begin
  141. k:=Pos('{$IFDEF WIN32}STDCALL;{$ELSE}CDECL;{$ENDIF}',ups);
  142. if k>0 then
  143. begin
  144. j:=k;
  145. k:=43;
  146. end
  147. else
  148. k:=6;
  149. end;
  150. Delete(s,j,k);
  151. end;
  152. Insert('cdecl;',s,j);
  153. end;
  154. ups:=UpperCase(s);
  155. end;
  156. { Align function with procedure }
  157. if Copy(s,1,8)='function' then
  158. Insert(' ',s,9);
  159. lasts:=s;
  160. writeln(f,s);
  161. end;
  162. close(f);
  163. close(t);
  164. erase(t);
  165. rename(f,fn);
  166. end;
  167. var
  168. i : integer;
  169. dir : tsearchrec;
  170. begin
  171. for i:=1to paramcount do
  172. begin
  173. if findfirst(paramstr(i),$20,dir)=0 then
  174. repeat
  175. Conv(dir.name);
  176. until findnext(dir)<>0;
  177. findclose(dir);
  178. end;
  179. end.
  180. $Log$
  181. Revision 1.2 2000-07-13 11:33:18 michael
  182. + removed logs
  183. }