w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

test.c (763B)


      1 
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include "wc.h"
      5 
      6 int
      7 main(int argc, char **argv)
      8 {
      9   Str s = Strnew();
     10   wc_ces old, from, to;
     11   FILE *f;
     12 
     13   if (argc < 3) {
     14     fprintf(stderr, "wctest <form> <to> [<file>]\n");
     15     exit(1);
     16   }
     17 
     18   from = wc_guess_charset_short(argv[1], 0);
     19   to = wc_guess_charset_short(argv[2], 0);
     20   if (argc > 3)
     21     f = fopen(argv[3], "r");
     22   else
     23     f = stdin;
     24   if (f == NULL) exit(2);
     25   
     26   fprintf(stderr, "%s -> %s\n", wc_ces_to_charset(from), wc_ces_to_charset(to));
     27   while (1) {
     28     s = Strfgets(f);
     29     if (!s->length)
     30       break;
     31     old = from;
     32     s = wc_Str_conv_with_detect(s, &from, from, to);
     33     if (from != old)
     34       fprintf(stderr, "%s ->\n", wc_ces_to_charset(from));
     35     printf("%s", s->ptr);
     36   }
     37   return 0;
     38 }