📄 ucgendat.c
字号:
if (upper_used > 0) /* * Write the upper case table. */ fwrite((char *) upper, sizeof(_case_t), upper_used, out); if (lower_used > 0) /* * Write the lower case table. */ fwrite((char *) lower, sizeof(_case_t), lower_used, out); if (title_used > 0) /* * Write the title case table. */ fwrite((char *) title, sizeof(_case_t), title_used, out); fclose(out);#endif /***************************************************************** * * Generate the composition data. * *****************************************************************/ /* * Create compositions from decomposition data */ create_comps(); #if HARDCODE_DATA fprintf(out, PREF "ac_uint4 _uccomp_size = %ld;\n\n", comps_used * 4L); fprintf(out, PREF "ac_uint4 _uccomp_data[] = {"); /* * Now, if comps exist, write them out. */ if (comps_used > 0) { for (i=0; i<comps_used; i++) { if (i) fprintf(out, ","); fprintf(out, "\n\t0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx", (unsigned long) comps[i].comp, (unsigned long) comps[i].count, (unsigned long) comps[i].code1, (unsigned long) comps[i].code2); } } else { fprintf(out, "\t0"); } fprintf(out, "\n};\n\n");#else /* * Open the comp.dat file. */ snprintf(path, sizeof path, "%s" LDAP_DIRSEP "comp.dat", opath); if ((out = fopen(path, "wb")) == 0) return; /* * Write the header. */ hdr[1] = (ac_uint2) comps_used * 4; fwrite((char *) hdr, sizeof(ac_uint2), 2, out); /* * Write out the byte count to maintain header size. */ bytes = comps_used * sizeof(_comp_t); fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); /* * Now, if comps exist, write them out. */ if (comps_used > 0) fwrite((char *) comps, sizeof(_comp_t), comps_used, out); fclose(out);#endif /***************************************************************** * * Generate the decomposition data. * *****************************************************************/ /* * Fully expand all decompositions before generating the output file. */ expand_decomp();#if HARDCODE_DATA fprintf(out, PREF "ac_uint4 _ucdcmp_size = %ld;\n\n", decomps_used * 2L); fprintf(out, PREF "ac_uint4 _ucdcmp_nodes[] = {"); if (decomps_used) { /* * Write the list of decomp nodes. */ for (i = idx = 0; i < decomps_used; i++) { fprintf(out, "\n\t0x%08lx, 0x%08lx,", (unsigned long) decomps[i].code, (unsigned long) idx); idx += decomps[i].used; } /* * Write the sentinel index as the last decomp node. */ fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx); fprintf(out, PREF "ac_uint4 _ucdcmp_decomp[] = {"); /* * Write the decompositions themselves. */ k = 0; for (i = 0; i < decomps_used; i++) for (j=0; j<decomps[i].used; j++) { if (k) fprintf(out, ","); if (!(k&3)) fprintf(out,"\n\t"); else fprintf(out, " "); k++; fprintf(out, "0x%08lx", (unsigned long) decomps[i].decomp[j]); } fprintf(out, "\n};\n\n"); }#else /* * Open the decomp.dat file. */ snprintf(path, sizeof path, "%s" LDAP_DIRSEP "decomp.dat", opath); if ((out = fopen(path, "wb")) == 0) return; hdr[1] = decomps_used; /* * Write the header. */ fwrite((char *) hdr, sizeof(ac_uint2), 2, out); /* * Write a temporary byte count which will be calculated as the * decompositions are written out. */ bytes = 0; fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); if (decomps_used) { /* * Write the list of decomp nodes. */ for (i = idx = 0; i < decomps_used; i++) { fwrite((char *) &decomps[i].code, sizeof(ac_uint4), 1, out); fwrite((char *) &idx, sizeof(ac_uint4), 1, out); idx += decomps[i].used; } /* * Write the sentinel index as the last decomp node. */ fwrite((char *) &idx, sizeof(ac_uint4), 1, out); /* * Write the decompositions themselves. */ for (i = 0; i < decomps_used; i++) fwrite((char *) decomps[i].decomp, sizeof(ac_uint4), decomps[i].used, out); /* * Seek back to the beginning and write the byte count. */ bytes = (sizeof(ac_uint4) * idx) + (sizeof(ac_uint4) * ((hdr[1] << 1) + 1)); fseek(out, sizeof(ac_uint2) << 1, 0L); fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); fclose(out); }#endif#ifdef HARDCODE_DATA fprintf(out, PREF "ac_uint4 _uckdcmp_size = %ld;\n\n", kdecomps_used * 2L); fprintf(out, PREF "ac_uint4 _uckdcmp_nodes[] = {"); if (kdecomps_used) { /* * Write the list of kdecomp nodes. */ for (i = idx = 0; i < kdecomps_used; i++) { fprintf(out, "\n\t0x%08lx, 0x%08lx,", (unsigned long) kdecomps[i].code, (unsigned long) idx); idx += kdecomps[i].used; } /* * Write the sentinel index as the last decomp node. */ fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx); fprintf(out, PREF "ac_uint4 _uckdcmp_decomp[] = {"); /* * Write the decompositions themselves. */ k = 0; for (i = 0; i < kdecomps_used; i++) for (j=0; j<kdecomps[i].used; j++) { if (k) fprintf(out, ","); if (!(k&3)) fprintf(out,"\n\t"); else fprintf(out, " "); k++; fprintf(out, "0x%08lx", (unsigned long) kdecomps[i].decomp[j]); } fprintf(out, "\n};\n\n"); }#else /* * Open the kdecomp.dat file. */ snprintf(path, sizeof path, "%s" LDAP_DIRSEP "kdecomp.dat", opath); if ((out = fopen(path, "wb")) == 0) return; hdr[1] = kdecomps_used; /* * Write the header. */ fwrite((char *) hdr, sizeof(ac_uint2), 2, out); /* * Write a temporary byte count which will be calculated as the * decompositions are written out. */ bytes = 0; fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); if (kdecomps_used) { /* * Write the list of kdecomp nodes. */ for (i = idx = 0; i < kdecomps_used; i++) { fwrite((char *) &kdecomps[i].code, sizeof(ac_uint4), 1, out); fwrite((char *) &idx, sizeof(ac_uint4), 1, out); idx += kdecomps[i].used; } /* * Write the sentinel index as the last decomp node. */ fwrite((char *) &idx, sizeof(ac_uint4), 1, out); /* * Write the decompositions themselves. */ for (i = 0; i < kdecomps_used; i++) fwrite((char *) kdecomps[i].decomp, sizeof(ac_uint4), kdecomps[i].used, out); /* * Seek back to the beginning and write the byte count. */ bytes = (sizeof(ac_uint4) * idx) + (sizeof(ac_uint4) * ((hdr[1] << 1) + 1)); fseek(out, sizeof(ac_uint2) << 1, 0L); fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); fclose(out); }#endif /***************************************************************** * * Generate the combining class data. * *****************************************************************/#ifdef HARDCODE_DATA fprintf(out, PREF "ac_uint4 _uccmcl_size = %ld;\n\n", (long) ccl_used); fprintf(out, PREF "ac_uint4 _uccmcl_nodes[] = {"); if (ccl_used > 0) { /* * Write the combining class ranges out. */ for (i = 0; i<ccl_used; i++) { if (i) fprintf(out, ","); if (!(i&3)) fprintf(out, "\n\t"); else fprintf(out, " "); fprintf(out, "0x%08lx", (unsigned long) ccl[i]); } } else { fprintf(out, "\t0"); } fprintf(out, "\n};\n\n");#else /* * Open the cmbcl.dat file. */ snprintf(path, sizeof path, "%s" LDAP_DIRSEP "cmbcl.dat", opath); if ((out = fopen(path, "wb")) == 0) return; /* * Set the number of ranges used. Each range has a combining class which * means each entry is a 3-tuple. */ hdr[1] = ccl_used / 3; /* * Write the header. */ fwrite((char *) hdr, sizeof(ac_uint2), 2, out); /* * Write out the byte count to maintain header size. */ bytes = ccl_used * sizeof(ac_uint4); fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); if (ccl_used > 0) /* * Write the combining class ranges out. */ fwrite((char *) ccl, sizeof(ac_uint4), ccl_used, out); fclose(out);#endif /***************************************************************** * * Generate the number data. * *****************************************************************/#if HARDCODE_DATA fprintf(out, PREF "ac_uint4 _ucnum_size = %lu;\n\n", (unsigned long)ncodes_used<<1); fprintf(out, PREF "ac_uint4 _ucnum_nodes[] = {"); /* * Now, if number mappings exist, write them out. */ if (ncodes_used > 0) { for (i = 0; i<ncodes_used; i++) { if (i) fprintf(out, ","); if (!(i&1)) fprintf(out, "\n\t"); else fprintf(out, " "); fprintf(out, "0x%08lx, 0x%08lx", (unsigned long) ncodes[i].code, (unsigned long) ncodes[i].idx); } fprintf(out, "\n};\n\n"); fprintf(out, PREF "short _ucnum_vals[] = {"); for (i = 0; i<nums_used; i++) { if (i) fprintf(out, ","); if (!(i&3)) fprintf(out, "\n\t"); else fprintf(out, " "); if (nums[i].numerator < 0) { fprintf(out, "%6d, 0x%04x", nums[i].numerator, nums[i].denominator); } else { fprintf(out, "0x%04x, 0x%04x", nums[i].numerator, nums[i].denominator); } } fprintf(out, "\n};\n\n"); }#else /* * Open the num.dat file. */ snprintf(path, sizeof path, "%s" LDAP_DIRSEP "num.dat", opath); if ((out = fopen(path, "wb")) == 0) return; /* * The count part of the header will be the total number of codes that * have numbers. */ hdr[1] = (ac_uint2) (ncodes_used << 1); bytes = (ncodes_used * sizeof(_codeidx_t)) + (nums_used * sizeof(_num_t)); /* * Write the header. */ fwrite((char *) hdr, sizeof(ac_uint2), 2, out); /* * Write out the byte count to maintain header size. */ fwrite((char *) &bytes, sizeof(ac_uint4), 1, out); /* * Now, if number mappings exist, write them out. */ if (ncodes_used > 0) { fwrite((char *) ncodes, sizeof(_codeidx_t), ncodes_used, out); fwrite((char *) nums, sizeof(_num_t), nums_used, out); }#endif fclose(out);}static voidusage(char *prog){ fprintf(stderr, "Usage: %s [-o output-directory|-x composition-exclusions]", prog); fprintf(stderr, " datafile1 datafile2 ...\n\n"); fprintf(stderr, "-o output-directory\n\t\tWrite the output files to a different"); fprintf(stderr, " directory (default: .).\n"); fprintf(stderr, "-x composition-exclusion\n\t\tFile of composition codes"); fprintf(stderr, " that should be excluded.\n"); exit(1);}intmain(int argc, char *argv[]){ FILE *in; char *prog, *opath; prog = lutil_progname( "ucgendat", argc, argv ); opath = 0; in = stdin; argc--; argv++; while (argc > 0) { if (argv[0][0] == '-') { switch (argv[0][1]) { case 'o': argc--; argv++; opath = argv[0]; break; case 'x': argc--; argv++; if ((in = fopen(argv[0], "r")) == 0) fprintf(stderr, "%s: unable to open composition exclusion file %s\n", prog, argv[0]); else { read_compexdata(in); fclose(in); in = 0; } break; default: usage(prog); } } else { if (in != stdin && in != NULL) fclose(in); if ((in = fopen(argv[0], "r")) == 0) fprintf(stderr, "%s: unable to open ctype file %s\n", prog, argv[0]); else { read_cdata(in); fclose(in); in = 0; } } argc--; argv++; } if (opath == 0) opath = "."; write_cdata(opath); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -