home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libi18n / unicode / tbltool / xlatgenutil.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.9 KB  |  148 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*
  19.     single filename1 filename2 
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. /*
  24. #define DEBUG 1
  25. */
  26. #ifdef DEBUG
  27. #define Trace(a)    {fprintf(stderr,"Trace: %s\n",a); fflush(stderr); }
  28. #else
  29. #define Trace(a)
  30. #endif
  31.  
  32. static char *name1;
  33. static char *name2;
  34.  
  35. static unsigned short array1[256],array2[256];
  36.  
  37. void TraceNum(int a)
  38. {
  39.     char buf[20];
  40.     sprintf(buf, "[%X]",a);
  41.     Trace(buf);
  42. }
  43. void usage()
  44. {
  45.     fprintf(stderr,"Usage: single filename1 filename2\n");
  46.     exit(-1);
  47. }
  48. void InitArray(unsigned short array[])
  49. {
  50.     int i;
  51.     for(i=0;i<32;i++)
  52.         array[i]= i;
  53.     for(i=32;i<256;i++)
  54.         array[i]= 0xFFFD;
  55.     array[0x7F]= 0x7F;
  56.     array[0xFF]= 0xFF;
  57. }
  58. void TraceArray(char* name,unsigned short array[])
  59. {
  60.     int i,j;
  61.     char buf[128];
  62.     Trace(name);
  63.     for(i=0;i<256;i+=16)
  64.     {
  65.         sprintf(buf,"0x%2X: ",i);
  66.         for(j=0;j<16;j++)
  67.         {
  68.             sprintf(buf,"%s %4X",buf, array[i+j]);
  69.         }
  70.         Trace(buf);
  71.     }
  72. }
  73. void Quit(char* str)
  74. {
  75.     Trace(str);
  76.     exit(-1);
  77. }
  78. void ReadArray(char* name,unsigned short array[])
  79. {
  80.     int i;
  81.     char buf[80];
  82.     FILE  *fd;
  83.     fd = fopen(name, "r");
  84.  
  85.     if(fd == NULL)
  86.         Quit("Cannot open file\n");
  87.     Trace("File open ok");
  88.     while(fgets(buf,80,fd))
  89.     {
  90.         if(buf[0] != '#')
  91.         {
  92.             int from;
  93.             int to;
  94.             sscanf(buf,"%x %x", &from, &to);
  95.             array[(from & 0x00FF)] = (to & 0x0000FFFF);
  96.         }
  97.     }
  98.     fclose(fd);
  99. }
  100. void ReportUnmap( unsigned short array1[], unsigned short array2[])
  101. {
  102.     int i,j,found;
  103.     int k;
  104.     k=0;
  105.     for(i=0;i<256;i++)
  106.     {
  107.         for(found=0,j=0;j<256;j++)
  108.         {
  109.             if(array1[i] == array2[j])
  110.             {    
  111.                 found = 1;
  112.                 break;
  113.             }
  114.         }
  115.         if(found == 0)
  116.         {
  117.             printf("/* %2X is unmap !!! */\n", i);
  118.             k++;
  119.         }
  120.     }
  121.     if(k!=0)
  122.     {
  123.         printf("/* There are total %d character unmap !! */\n",k);
  124.     }
  125. }
  126. extern void GenMap(char* name1, char* name2, 
  127.     unsigned short array1[], unsigned short array2[]);
  128. main(int argc, char* argv[])
  129. {
  130.  
  131.     if(argc!=3)
  132.         usage();
  133.  
  134.     InitArray(array1);
  135.     InitArray(array2);
  136.  
  137.     Trace(argv[1]);
  138.     ReadArray(argv[1],array1);
  139.     TraceArray(argv[1],array1);
  140.  
  141.     Trace(argv[2]);
  142.     ReadArray(argv[2],array2);
  143.     TraceArray(argv[2],array2);
  144.  
  145.     GenMap(argv[1], argv[2], array1,array2);
  146.     GenMap(argv[2], argv[1], array2,array1);
  147. }
  148.