2
0

c_linuxd.pp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. WriteLn('File Generator for OpenGL related Units');
  63. // Load definition files
  64. WriteLn('Loading definition files...');
  65. DefGL := TDefReader.Create('gl.def');
  66. DefGLExt := TDefReader.Create('glext.def');
  67. DefGLU := TDefReader.Create('glu.def');
  68. DefGLX := TDefReader.Create('glx.def');
  69. DefGLUT := TDefReader.Create('glut.def');
  70. // Build GL unit
  71. WriteLn('Generating GL unit for Linux...');
  72. Assign(f, '../linux/gl.pp');
  73. Rewrite(f);
  74. Assign(tpl, 'gl_linux.tpl');
  75. Reset(tpl);
  76. while not EOF(tpl) do begin
  77. ReadLn(tpl, s);
  78. if Copy(s, 1, 1) = '%' then begin
  79. if s = '%GLDecls' then
  80. PrintInterface(DefGL.InterfaceBlock, f)
  81. else if s = '%GLProcs1' then
  82. PrintProcDecls(DefGL.Procs)
  83. else if s = '%GLProcs2' then
  84. PrintProcLoaders(DefGL.Procs, 'libgl')
  85. else if s = '%GLExtDecls' then
  86. PrintInterface(DefGLExt.InterfaceBlock, f)
  87. else if s = '%GLExtProcs1' then
  88. PrintProcDecls(DefGLExt.Procs)
  89. else if s = '%GLExtProcs2' then
  90. PrintProcLoaders(DefGLExt.Procs, 'libgl')
  91. else if s = '%GLUDecls' then
  92. PrintInterface(DefGLU.InterfaceBlock, f)
  93. else if s = '%GLUProcs1' then
  94. PrintProcDecls(DefGLU.Procs)
  95. else if s = '%GLUProcs2' then
  96. PrintProcLoaders(DefGLU.Procs, 'libglu')
  97. else if s = '%GLXDecls' then
  98. PrintInterface(DefGLX.InterfaceBlock, f)
  99. else if s = '%GLXProcs1' then
  100. PrintProcDecls(DefGLX.Procs)
  101. else if s = '%GLXProcs2' then
  102. PrintProcLoaders(DefGLX.Procs, 'libglx')
  103. else
  104. WriteLn(f, '// ### c_linuxd: Don''t know what to insert here!: ', s);
  105. end else if Copy(s, 1, 1) <> '#' then
  106. WriteLn(f, s);
  107. end;
  108. PrintCVSLogSection;
  109. Close(f);
  110. // Build GLUT unit
  111. WriteLn('Generating GLut unit for Linux...');
  112. Assign(f, '../linux/glut.pp');
  113. Rewrite(f);
  114. Assign(tpl, 'glut_linux.tpl');
  115. Reset(tpl);
  116. while not EOF(tpl) do begin
  117. ReadLn(tpl, s);
  118. if Copy(s, 1, 1) = '%' then begin
  119. if s = '%GLUTDecls' then
  120. PrintInterface(DefGLUT.InterfaceBlock, f)
  121. else if s = '%GLUTProcs1' then
  122. PrintProcDecls(DefGLUT.Procs)
  123. else if s = '%GLUTProcs2' then
  124. PrintProcLoaders(DefGLUT.Procs, 'libglut')
  125. else
  126. WriteLn(f, '// ### c_linuxd: Don''t know what to insert here!: ', s);
  127. end else if Copy(s, 1, 1) <> '#' then begin
  128. j := Pos('#extdecl', s);
  129. if j = 0 then
  130. WriteLn(f, s)
  131. else
  132. WriteLn(f, Copy(s, 1, j - 1), 'cdecl', Copy(s, j + 8, Length(s)));
  133. end;
  134. end;
  135. PrintCVSLogSection;
  136. Close(f);
  137. WriteLn('Done...');
  138. end.
  139. {
  140. $Log$
  141. Revision 1.1 1999-12-23 13:51:50 peter
  142. * reorganized, it now doesn't depend on fcl anymore by default
  143. Revision 1.2 1999/12/01 00:55:44 alex
  144. Added info prints so that we know how far the program worked.
  145. Revision 1.1 1999/11/28 17:55:22 sg
  146. * Added new unit generation tools and auto-generated GL units for Linux
  147. }