c_linuxd.pp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {
  2. $Id$
  3. GL unit creation tool for Linux dynamic version
  4. (c) 1999 Sebastian Guenther, [email protected]
  5. }
  6. {$MODE objfpc}
  7. {$H+}
  8. program c_linuxd;
  9. uses SysUtils, Classes, buildgl;
  10. var
  11. f: Text;
  12. procedure PrintInterface(lines: TStringList; var dest: Text);
  13. var
  14. i: Integer;
  15. begin
  16. for i := 0 to lines.Count - 1 do
  17. WriteLn(dest, lines.Strings[i]);
  18. end;
  19. procedure PrintProcDecls(procs: TStringList);
  20. var
  21. i, j: Integer;
  22. s: String;
  23. begin
  24. for i := 0 to procs.Count - 1 do begin
  25. s := procs.Strings[i];
  26. j := Pos('//', s);
  27. if (Length(s) = 0) or ((j > 0) and (Trim(s)[1] = '/')) then
  28. WriteLn(f, s)
  29. else if j = 0 then
  30. WriteLn(f, s, ' cdecl;')
  31. else
  32. WriteLn(f, TrimRight(Copy(s, 1, j - 1)), ' cdecl; ', Copy(s, j, Length(s)));
  33. end;
  34. end;
  35. procedure PrintProcLoaders(procs: TStringList; const libname: String);
  36. var
  37. i, j: Integer;
  38. s: String;
  39. begin
  40. for i := 0 to procs.Count - 1 do begin
  41. s := Trim(procs.Strings[i]);
  42. j := Pos(':', s);
  43. s := Trim(Copy(s, 1, j - 1));
  44. if (Length(s) = 0) or (Pos('//', s) > 0) then continue;
  45. WriteLn(f, ' ', s, ' := GetProc(', libname, ', ''', s, ''');');
  46. end;
  47. end;
  48. procedure PrintCVSLogSection;
  49. begin
  50. WriteLn(f);
  51. WriteLn(f);
  52. WriteLn(f, '{');
  53. WriteLn(f, ' $', 'Log:$'); // needed because _this_ file might be in CVS, too
  54. WriteLn(f, '}');
  55. end;
  56. var
  57. DefGL, DefGLExt, DefGLU, DefGLX, DefGLUT: TDefReader;
  58. tpl: Text;
  59. s: String;
  60. j: Integer;
  61. begin
  62. // Load definition files
  63. DefGL := TDefReader.Create('gl.def');
  64. DefGLExt := TDefReader.Create('glext.def');
  65. DefGLU := TDefReader.Create('glu.def');
  66. DefGLX := TDefReader.Create('glx.def');
  67. DefGLUT := TDefReader.Create('glut.def');
  68. // Build GL unit
  69. Assign(f, 'linuxd/gl.pp');
  70. Rewrite(f);
  71. Assign(tpl, 'gl_linux.tpl');
  72. Reset(tpl);
  73. while not EOF(tpl) do begin
  74. ReadLn(tpl, s);
  75. if Copy(s, 1, 1) = '%' then begin
  76. if s = '%GLDecls' then
  77. PrintInterface(DefGL.InterfaceBlock, f)
  78. else if s = '%GLProcs1' then
  79. PrintProcDecls(DefGL.Procs)
  80. else if s = '%GLProcs2' then
  81. PrintProcLoaders(DefGL.Procs, 'libgl')
  82. else if s = '%GLExtDecls' then
  83. PrintInterface(DefGLExt.InterfaceBlock, f)
  84. else if s = '%GLExtProcs1' then
  85. PrintProcDecls(DefGLExt.Procs)
  86. else if s = '%GLExtProcs2' then
  87. PrintProcLoaders(DefGLExt.Procs, 'libgl')
  88. else if s = '%GLUDecls' then
  89. PrintInterface(DefGLU.InterfaceBlock, f)
  90. else if s = '%GLUProcs1' then
  91. PrintProcDecls(DefGLU.Procs)
  92. else if s = '%GLUProcs2' then
  93. PrintProcLoaders(DefGLU.Procs, 'libglu')
  94. else if s = '%GLXDecls' then
  95. PrintInterface(DefGLX.InterfaceBlock, f)
  96. else if s = '%GLXProcs1' then
  97. PrintProcDecls(DefGLX.Procs)
  98. else if s = '%GLXProcs2' then
  99. PrintProcLoaders(DefGLX.Procs, 'libglx')
  100. else
  101. WriteLn(f, '// ### c_linuxd: Don''t know what to insert here!: ', s);
  102. end else if Copy(s, 1, 1) <> '#' then
  103. WriteLn(f, s);
  104. end;
  105. PrintCVSLogSection;
  106. Close(f);
  107. // Build GLUT unit
  108. Assign(f, 'linuxd/glut.pp');
  109. Rewrite(f);
  110. Assign(tpl, 'glut_linux.tpl');
  111. Reset(tpl);
  112. while not EOF(tpl) do begin
  113. ReadLn(tpl, s);
  114. if Copy(s, 1, 1) = '%' then begin
  115. if s = '%GLUTDecls' then
  116. PrintInterface(DefGLUT.InterfaceBlock, f)
  117. else if s = '%GLUTProcs1' then
  118. PrintProcDecls(DefGLUT.Procs)
  119. else if s = '%GLUTProcs2' then
  120. PrintProcLoaders(DefGLUT.Procs, 'libglut')
  121. else
  122. WriteLn(f, '// ### c_linuxd: Don''t know what to insert here!: ', s);
  123. end else if Copy(s, 1, 1) <> '#' then begin
  124. j := Pos('#extdecl', s);
  125. if j = 0 then
  126. WriteLn(f, s)
  127. else
  128. WriteLn(f, Copy(s, 1, j - 1), 'cdecl', Copy(s, j + 8, Length(s)));
  129. end;
  130. end;
  131. PrintCVSLogSection;
  132. Close(f);
  133. end.
  134. {
  135. $Log$
  136. Revision 1.1 1999-11-28 17:55:22 sg
  137. * Added new unit generation tools and auto-generated GL units for Linux
  138. }