// SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2023 SASANO Takayoshi #include #include #include #include #include "convert_ngram.h" extern "C" { #include }; int main(int argc, char *argv[]) { FILE *fpi, *fpo; const char *kakasi_argv[] = {"kakasi", "-ieuc", "-KH", "-JH"}; int ngrams; convert_ngram cn; if (argc < 4) { fprintf(stderr, "%s: usage [ngrams] [infile] [outfile]\n", argv[0]); goto fin0; } if (kakasi_getopt_argv(sizeof(kakasi_argv) / sizeof(char *), (char **)kakasi_argv)) { fprintf(stderr, "kakasi_getopt_argv\n"); goto fin0; } ngrams = atoi(argv[1]); if (ngrams < 1 || ngrams > 3) { fprintf(stderr, "invalid ngram value\n"); goto fin0; } if ((fpi = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "file open error (in)\n"); goto fin0; } if ((fpo = fopen(argv[3], "w")) == NULL) { fprintf(stderr, "file open error (out)\n"); goto fin1; } setlocale(LC_ALL, "ja_JP.UTF-8"); cn.do_file(fpi, fpo, ngrams); fclose(fpo); fin1: fclose(fpi); fin0: return 0; }