creumap.pp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000 by Florian Klaempfl
  4. It creates pascal units from unicode mapping files
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program creumap;
  12. uses
  13. charset;
  14. procedure doerror;
  15. begin
  16. writeln('Usage: creumap <cpname> <cpnumber>');
  17. writeln('cpname : A mapping file called <cpname>.txt must be present');
  18. writeln('cpnumber : the code page number');
  19. halt(1);
  20. end;
  21. var
  22. p : punicodemap;
  23. i : longint;
  24. t : text;
  25. e : word;
  26. begin
  27. if paramcount<>2 then
  28. doerror;
  29. Val(paramstr(2),i,e);
  30. if e<>0 then
  31. doerror;
  32. p:=loadunicodemapping(paramstr(1),paramstr(1)+'.txt',i);
  33. if p=nil then
  34. doerror;
  35. assign(t,paramstr(1)+'.pp');
  36. rewrite(t);
  37. writeln(t,'{ This is an automatically created file, so don''t edit it }');
  38. writeln(t,'unit ',p^.cpname,';');
  39. writeln(t);
  40. writeln(t,' interface');
  41. writeln(t);
  42. writeln(t,' implementation');
  43. writeln(t);
  44. writeln(t,' uses');
  45. writeln(t,' charset;');
  46. writeln(t);
  47. writeln(t,' const');
  48. writeln(t,' map : array[0..',p^.lastchar,'] of tunicodecharmapping = (');
  49. for i:=0 to p^.lastchar do
  50. begin
  51. write(t,' (unicode : ',p^.map[i].unicode,'; flag : ');
  52. case p^.map[i].flag of
  53. umf_noinfo : write(t,'umf_noinfo');
  54. umf_leadbyte : write(t,'umf_leadbyte');
  55. umf_undefined : write(t,'umf_undefined');
  56. umf_unused : write(t,'umf_unused');
  57. end;
  58. write(t,'; reserved: 0)');
  59. if i<>p^.lastchar then
  60. writeln(t,',')
  61. else
  62. writeln(t);
  63. end;
  64. writeln(t,' );');
  65. writeln(t);
  66. writeln(t,' unicodemap : tunicodemap = (');
  67. writeln(t,' cpname : ''',p^.cpname,''';');
  68. writeln(t,' cp : ',p^.cp,';');
  69. writeln(t,' map : @map;');
  70. writeln(t,' lastchar : ',p^.lastchar,';');
  71. writeln(t,' next : nil;');
  72. writeln(t,' internalmap : true');
  73. writeln(t,' );');
  74. writeln(t);
  75. writeln(t,' begin');
  76. writeln(t,' registermapping(@unicodemap)');
  77. writeln(t,' end.');
  78. close(t);
  79. end.