creumap.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. c : longint;
  27. begin
  28. if paramcount<>2 then
  29. doerror;
  30. Val(paramstr(2),i,e);
  31. if e<>0 then
  32. doerror;
  33. p:=loadunicodemapping(paramstr(1),paramstr(1)+'.txt',i);
  34. if p=nil then
  35. doerror;
  36. assign(t,paramstr(1)+'.pp');
  37. rewrite(t);
  38. writeln(t,'{ This is an automatically created file, so don''t edit it }');
  39. writeln(t,'unit ',p^.cpname,';');
  40. writeln(t);
  41. writeln(t,' interface');
  42. writeln(t);
  43. writeln(t,' implementation');
  44. writeln(t);
  45. writeln(t,' uses');
  46. writeln(t,' charset;');
  47. writeln(t);
  48. writeln(t,' const');
  49. writeln(t,' map : array[0..',p^.lastchar,'] of tunicodecharmapping = (');
  50. for i:=0 to p^.lastchar do
  51. begin
  52. write(t,' (unicode : ',p^.map[i].unicode,'; flag : ');
  53. case p^.map[i].flag of
  54. umf_noinfo : write(t,'umf_noinfo');
  55. umf_leadbyte : write(t,'umf_leadbyte');
  56. umf_undefined : write(t,'umf_undefined');
  57. umf_unused : write(t,'umf_unused');
  58. end;
  59. write(t,'; reserved: 0)');
  60. if i<>p^.lastchar then
  61. writeln(t,',')
  62. else
  63. writeln(t);
  64. end;
  65. writeln(t,' );');
  66. writeln(t);
  67. c:=p^.reversemaplength-1;
  68. writeln(t,' reversemap : array[0..',c,'] of treversecharmapping = (');
  69. for i:=0 to c do
  70. begin
  71. write(t,' (',
  72. 'unicode : ',p^.reversemap[i].unicode,
  73. '; char1 : ',p^.reversemap[i].char1,
  74. '; char2 : ',p^.reversemap[i].char2,
  75. ')'
  76. );
  77. if i<>c then
  78. writeln(t,',')
  79. else
  80. writeln(t);
  81. end;
  82. writeln(t,' );');
  83. writeln(t);
  84. writeln(t,' unicodemap : tunicodemap = (');
  85. writeln(t,' cpname : ''',p^.cpname,''';');
  86. writeln(t,' cp : ',p^.cp,';');
  87. writeln(t,' map : @map;');
  88. writeln(t,' lastchar : ',p^.lastchar,';');
  89. writeln(t,' reversemap : @reversemap;');
  90. writeln(t,' reversemaplength : ',p^.reversemaplength,';');
  91. writeln(t,' next : nil;');
  92. writeln(t,' internalmap : true');
  93. writeln(t,' );');
  94. writeln(t);
  95. writeln(t,' begin');
  96. writeln(t,' registermapping(@unicodemap)');
  97. writeln(t,' end.');
  98. close(t);
  99. end.