fixglibcdecl.pp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. ups:=UpperCase(s);
  97. if Pos('IMPLEMENTATION',ups)>0 then
  98. impl:=true;
  99. i:=Pos('PROCEDURE',ups);
  100. if i>0 then
  101. if Pos('_PROCEDURE',ups)>0 then
  102. i:=0;
  103. if i=0 then
  104. begin
  105. i:=Pos('FUNCTION',ups);
  106. if Pos('_FUNCTION',ups)>0 then
  107. i:=0;
  108. end;
  109. if i<>0 then
  110. begin
  111. { Remove Spaces }
  112. j:=PosIdx(' ',s,i);
  113. while (j>0) do
  114. begin
  115. Delete(s,j,1);
  116. i:=j-1;
  117. j:=PosIdx(' ',s,i);
  118. end;
  119. ups:=UpperCase(s);
  120. { Fix Cdecl }
  121. if (Pos('g_',s)<>0) or
  122. ((i>2) and (s[i-2] in [':','='])) then
  123. begin
  124. j:=Pos('CDECL;',ups);
  125. if j=0 then
  126. j:=Length(s)+1
  127. else
  128. begin
  129. k:=Pos('{$IFNDEF WIN32}CDECL;{$ENDIF}',ups);
  130. if k>0 then
  131. begin
  132. j:=k;
  133. k:=29;
  134. end
  135. else
  136. begin
  137. k:=Pos('{$IFDEF WIN32}STDCALL;{$ELSE}CDECL;{$ENDIF}',ups);
  138. if k>0 then
  139. begin
  140. j:=k;
  141. k:=43;
  142. end
  143. else
  144. k:=6;
  145. end;
  146. Delete(s,j,k);
  147. end;
  148. Insert('cdecl;',s,j);
  149. end;
  150. ups:=UpperCase(s);
  151. end;
  152. { Align function with procedure }
  153. if Copy(s,1,8)='function' then
  154. Insert(' ',s,9);
  155. lasts:=s;
  156. writeln(f,s);
  157. end;
  158. close(f);
  159. close(t);
  160. erase(t);
  161. rename(f,fn);
  162. end;
  163. var
  164. i : integer;
  165. dir : tsearchrec;
  166. begin
  167. for i:=1to paramcount do
  168. begin
  169. if findfirst(paramstr(i),$20,dir)=0 then
  170. repeat
  171. Conv(dir.name);
  172. until findnext(dir)<>0;
  173. findclose(dir);
  174. end;
  175. end.
  176. $Log$
  177. Revision 1.2 2000-07-13 11:33:18 michael
  178. + removed logs
  179. }