c_linuxd.pp 3.9 KB

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