creumap.pp 2.3 KB

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