home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / os2 / pgp263.arj / PGP263I.SRC / PGP263II.ZIP / contrib / langtool / charconv.c next >
C/C++ Source or Header  |  1994-05-06  |  2KB  |  50 lines

  1. #include <stdio.h>
  2.  
  3. static unsigned char
  4. intern2cp850[] = {  /* ISO 8859-1 Latin Alphabet 1 (Latin-1) to IBM Code Page 850 */
  5. 186, 205, 201, 187, 200, 188, 204, 185, 203, 202, 206, 223, 220, 219, 254, 242,
  6. 179, 196, 218, 191, 192, 217, 195, 180, 194, 193, 197, 176, 177, 178, 213, 159,
  7. 255, 173, 189, 156, 207, 190, 221, 245, 249, 184, 166, 174, 170, 240, 169, 238,
  8. 248, 241, 253, 252, 239, 230, 244, 250, 247, 251, 167, 175, 172, 171, 243, 168,
  9. 183, 181, 182, 199, 142, 143, 146, 128, 212, 144, 210, 211, 222, 214, 215, 216,
  10. 209, 165, 227, 224, 226, 229, 153, 158, 157, 235, 233, 234, 154, 237, 232, 225,
  11. 133, 160, 131, 198, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161, 140, 139,
  12. 208, 164, 149, 162, 147, 228, 148, 246, 155, 151, 163, 150, 129, 236, 231, 152
  13. };
  14.  
  15. static unsigned char
  16. cp8502intern[] = {  /* IBM Code Page 850 to Latin-1 */
  17. 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197,
  18. 201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 248, 163, 216, 215, 159,
  19. 225, 237, 243, 250, 241, 209, 170, 186, 191, 174, 172, 189, 188, 161, 171, 187,
  20. 155, 156, 157, 144, 151, 193, 194, 192, 169, 135, 128, 131, 133, 162, 165, 147,
  21. 148, 153, 152, 150, 145, 154, 227, 195, 132, 130, 137, 136, 134, 129, 138, 164,
  22. 240, 208, 202, 203, 200, 158, 205, 206, 207, 149, 146, 141, 140, 166, 204, 139,
  23. 211, 223, 212, 210, 245, 213, 181, 254, 222, 218, 219, 217, 253, 221, 175, 180,
  24. 173, 177, 143, 190, 182, 167, 247, 184, 176, 168, 183, 185, 179, 178, 142, 160
  25. };
  26.  
  27. main(argc, argv)
  28. char **argv;
  29. {
  30.     int c;
  31.  
  32.     if (argc < 2 || strcmp(argv[1], "int") && strcmp(argv[1], "ext")) {
  33.         fprintf(stderr, "usage: convert [int|ext] [file]\n");
  34.         exit(1);
  35.     }
  36.     if (argc > 2) {
  37.         if (freopen(argv[2], "r", stdin) == NULL) {
  38.             perror(argv[2]);
  39.             exit(1);
  40.         }
  41.     }
  42.     if (strcmp(argv[1], "int"))
  43.         while ((c = getchar()) != EOF)
  44.             putchar(c & 0x80 ? intern2cp850[c&0x7f] : c);
  45.     else
  46.         while ((c = getchar()) != EOF)
  47.             putchar(c & 0x80 ? cp8502intern[c&0x7f] : c);
  48.     exit(0);
  49. }
  50.