int main(int argc, char *argv[]) { char *target_filename; char *output_filename; FILE *input, *output; DICT *dict; EDICT *edict; if (argc != 3) { printf("usage: %s target_text_file output_file\n", argv[0]); exit(1); } target_filename = argv[1]; output_filename = argv[2]; input = fopen(target_filename, "r"); output = fopen(output_filename, "wb"); if (input == NULL || output == NULL) { puts("File open error at the beginning."); exit(1); } dict = RunRepair(input); edict = convertDict(dict); EncodeCFG(edict, output); DestructEDict(edict); fclose(input); fclose(output); exit(0); }
int main(int argc, char *argv[]) { char *target_filename; //char output_filename[1024]; char *output_filename; FILE *input, *output; DICT *dict; EDICT *edict; USEDCHARTABLE ut; if (argc != 3) { printf("Usage: %s <input filename> <output filename>\n" "Compresses <input filename> with repair and creates " "<output filename> compressed files\n\n", argv[0]); exit(1); } target_filename = argv[1]; input = fopen(target_filename, "r"); if (input == NULL) { puts("File open error at the beginning."); exit(1); } //strcpy(output_filename, target_filename); //strcat(output_filename, ".rp"); output_filename = argv[2]; output = fopen(output_filename, "wb"); if (output == NULL) { puts("File open error at the beginning."); exit(1); } chartable_init(&ut); dict = RunRepair(input, &ut); edict = convertDict(dict, &ut); EncodeCFG(edict, output, &ut); DestructEDict(edict); fclose(input); fclose(output); exit(0); }
int main(int argc, char *argv[]) { char *target_filename, *output_filename; char cfg_filename[] = "cfg.tmp"; FILE *input, *output, *cfg; EDICT *edict; // analize options if (argc != 3) { printf("usage: %s target_text_file output_enc_file\n", argv[0]); exit(1); } target_filename = argv[1]; output_filename = argv[2]; // Run the algorithm procedure input = fopen(target_filename, "r"); cfg = fopen(cfg_filename, "wb"); if (input == NULL || cfg == NULL) { puts("File open error at the beginning."); exit(1); } GrammarTrans_LCA(input, cfg); fclose(input); fclose(cfg); cfg = fopen(cfg_filename, "rb"); output = fopen(output_filename, "wb"); if (cfg == NULL || output == NULL) { puts("File open error."); exit(1); } edict = ReadCFG(cfg); remove(cfg_filename); EncodeCFG(edict, output); DestructEDict(edict); exit(0); }
int main(int argc, char *argv[]) { FILE *input, *output; EDICT *dict; if (argc != 3) { printf("usage: %s target_cfg_file output_enc_file\n", argv[0]); exit(1); } input = fopen(argv[1], "rb"); output = fopen(argv[2], "wb"); if (input == NULL || output == NULL) { printf("File open error.\n"); exit(1); } dict = ReadCFG(input); EncodeCFG(dict, output); DestructEDict(dict); fclose(input); fclose(output); exit(0); }
// encode用のmain関数 int main(int argc, char *argv[]) { char *target_filename = NULL; //char output_filename[1024]; char *output_filename = NULL; char *dict_filename = NULL; unsigned int codewordlength = 0; unsigned int shared_dictsize = 0; unsigned int chunk_size = 0; unsigned long int block_length = 0; unsigned int length; char *rest; FILE *input, *output, *dictfile; DICT *dict; EDICT *edict; USEDCHARTABLE ut; int result; unsigned int b; unsigned char *buf; unsigned int *buf2 = NULL; OBITFS seqout, dicout; int header_output = 0; uint i; /* オプションの解析 */ while ((result = getopt(argc, argv, "r:w:b:l:d:s:c:")) != -1) { switch (result) { case 'r': target_filename = optarg; break; case 'w': output_filename = optarg; break; case 'd': dict_filename = optarg; break; case 'b': block_length = strtoul(optarg, &rest, 10); if (*rest != '\0') { help(argv); } break; case 'c': chunk_size = strtol(optarg, &rest, 10); if (*rest != '\0') { help(argv); } break; case 'l': codewordlength = strtoul(optarg, &rest, 10); if (*rest != '\0') { help(argv); } break; case 's': shared_dictsize = strtoul(optarg, &rest, 10); if (*rest != '\0') { help(argv); } break; case '?': help(argv); break; } } // 必要なオプションがそろっているかを確認する if (!(target_filename && output_filename && dict_filename && block_length && codewordlength && chunk_size)) { help(argv); } if (chunk_size > block_length) { fprintf(stderr, "chunk length should not exceed block length.\n"); exit(1); } // 入力ファイルをオープンする input = fopen(target_filename, "r"); if (input == NULL) { puts("Input file open error at the beginning."); exit(1); } // 圧縮データファイルをオープンする output = fopen(output_filename, "wb"); if (output == NULL) { puts("Output file open error at the beginning."); exit(1); } // 辞書ファイルをオープンする dictfile = fopen(dict_filename, "wb"); if (!dictfile) { puts("Dictionary file open error at the beginning."); exit(EXIT_FAILURE); } // if (NULL == (buf = (unsigned char*)malloc(sizeof(unsigned char) * block_length))) { // || NULL == (buf2 = (unsigned int*)malloc(sizeof(unsigned int) * block_length))) { // puts("malloc fault."); // exit(EXIT_FAILURE); // } chartable_init(&ut); fill_chartable(input, &ut); fseeko(input, 0, SEEK_END); dict = createDict(ftello(input)); fseeko(input, 0, SEEK_SET); b = 0; obitfs_init(&seqout, output); obitfs_init(&dicout, dictfile); if (shared_dictsize < ut.size) shared_dictsize = ut.size; printf("Generating CFG..."); fflush(stdout); outputHeader(&dicout, dict, (unsigned int) codewordlength, (unsigned int) block_length, &ut); dict = RunRepair(dict, input, block_length, shared_dictsize, codewordlength, &ut, chunk_size, 1); if (!dict) exit(1); edict = convertDict(dict, &ut); outputSharedDictionary(&dicout, edict, &ut, codewordlength, shared_dictsize, b); CleanEDict(edict); if (dict->num_rules < shared_dictsize + CHAR_SIZE - ut.size) shared_dictsize = dict->num_rules + ut.size - CHAR_SIZE; fseeko(input, 0, SEEK_SET); while (!feof(input)) { // printf("************ Block #%d ************\n", b); // length = fread(buf, sizeof(unsigned char), block_length, input); // if (!length) break; // for (i = 0; i < length; i++) { // buf2[i] = buf[i]; // } /* for (unsigned int i = 0; i < length; i++) { */ /* printf("%u ", buf2[i]); */ /* } */ /* puts(""); */ dict = RunRepair(dict, input, block_length, shared_dictsize, codewordlength, &ut, chunk_size, 0); edict = convertDict(dict, &ut); outputLocalDictionary(&dicout, edict, &ut, codewordlength, shared_dictsize, b); EncodeCFG(edict, &seqout, codewordlength); CleanEDict(edict); b++; } printf("Finished!\n"); fflush(stdout); if (dict) { free(dict->rule); free(dict->comp_seq); free(dict); } obitfs_finalize(&seqout); obitfs_finalize(&dicout); fclose(input); fclose(output); fclose(dictfile); exit(0); }