/* Copyright (C)1995-2000 ASH multimedia lab. (http://ash.jp/) */ /**************************/ /* 文字コード判定コマンド */ /**************************/ #include #include #include #define MAXBUF 65535 char prog_name[64]; int dbg; /* 使用方法の表示 */ usage() { printf("Usage: %s files\n", prog_name); printf(" files: 判定ファイル名\n"); exit(-1); } /* メイン処理 */ main(argc, argv) int argc; char *argv[]; { FILE *fp; int rtn; /* デフォルトパラメータの設定 */ strcpy(prog_name, argv[0]); /* オプションの解析 */ while ((rtn = getopt(argc, argv, "x")) != -1) { switch(rtn) { /* オプション解析 */ case 'x': /* デバッグ情報表示 */ dbg = 1; break; default: /* 使用方法の表示 */ usage(); } } /* 入力ファイルのオープン */ if (argv[optind] != NULL) { for (; argv[optind]; optind++) { if (isdir(argv[optind])) {continue;} printf ("%s:\t", argv[optind]); fp = fopen (argv[optind], "r"); if (!fp) { printf("File open error.\n"); continue; } _getcode(fp); fclose(fp); } } else { /* 指定なしの場合、標準入力 */ _getcode(stdin); } } /* 文字コード判定サブルーチン */ _getcode(fp) FILE *fp; { char buf[MAXBUF+1]; int rtn, len; len = fread(buf, 1, MAXBUF, fp); rtn = getcode(buf, len); if (rtn == 0) { printf("ASCII text\n"); } else if (rtn == 1) { printf("JIS text\n"); } else if (rtn == 2) { printf("SJIS text\n"); } else if (rtn == 3) { printf("EUC text\n"); } else if (rtn == 4) { printf("Unknown(EUC/SJIS) text\n"); } else { printf("Binary file\n"); } }