/* ÀÚ¸ð ºóµµ Á¶»ç ÇÁ·Î±×·¥ ÀÔ·Â ÆÄÀÏ : KS ¿Ï¼ºÇü ÅؽºÆ® ÆÄÀÏ ±¹¹Î´ëÇб³ ÄÄÇ»ÅÍÇкΠ°­½Â½Ä */ #include #include "ksc2kssm.h" #include "kssm2ksc.h" char *ch[] = { "", "@", "¤¡", "¤¢", "¤¤", "¤§", "¤¨", "¤©", "¤±", "¤²", "¤³", "¤µ", "¤¶", "¤·", "¤¸", "¤¹", "¤º", "¤»", "¤¼", "¤½", "¤¾" }; char *ju[30] = { "", "", "@", "¤¿", "¤À", "¤Á", "¤Â", "¤Ã", "", "", "¤Ä", "¤Å", "¤Æ", "¤Ç", "¤È", "¤É", "", "", "¤Ê", "¤Ë", "¤Ì", "¤Í", "¤Î", "¤Ï", "", "", "¤Ð", "¤Ñ", "¤Ò", "¤Ó" }; char *jo[30] = { "", "@", "¤¡", "¤¢", "¤£", "¤¤", "¤¥", "¤¦", "¤§", "¤©", "¤ª", "¤«", "¤¬", "¤­", "¤®", "¤¯", "¤°", "¤±", "", "¤²", "¤´", "¤µ", "¤¶", "¤·", "¤¸", "¤º", "¤»", "¤¼", "¤½", "¤¾" }; unsigned short ksc2kssm(unsigned char c, unsigned char d) { if (c < 0xB0 || c > 0xC8 || d < 0xA1 || d == 0xFF) return 0; return KSSMCODE[c-0xB0][d-0xA1]; } unsigned short kssm2ksc(unsigned kssm) { if (kssm < 0x8861) return 0; return KSC_CODE[kssm-0x8861]; } /* data[]ÀÇ °íºóµµ ¼øÀ¸·Î ¼ÒÆÃµÈ ¼ø¼­¸¦ index[]¿¡ ÀúÀå */ void set_sort_index(int data[], int index[], int n) { int i, j, temp; for (i = 0; i < n; i++) index[i] = i; for (i = 0; i < n-1; i++) { /* °íºóµµ ¼øÀ¸·Î sorting */ for (j = i+1; j < n; j++) { if (data[index[i]] < data[index[j]]) { temp = index[i]; index[i] = index[j]; index[j] = temp; } } } } int main(int argc, char *argv[]) { FILE *ifp, *ofp=stdout; int c1, c2, cnext1=0, cnext2=0; unsigned syl; // Á¶ÇÕÇü À½Àý long sum, nSyl = 0; // ÃÑ À½Àý °³¼ö long nSyl2 = 0; // ÃÑ ¿¬¼ÓÀ½Àý °³¼ö -- Á¾¼º-Ãʼº ºóµµ °è»ê¿ë long cho[21] = {0}; long jung[30]= {0}; long jong[30]= {0}; long chojung[21*30] = {0}; long jungjong[30*30]= {0}; long jongcho[30*21] = {0}; int i, i1, i2, i3, j; int si[999]; // ºóµµº° sorting¿ë index ÀúÀå ifp = (argc > 1) ? fopen(argv[1], "r") : stdin; if (!ifp) { fprintf(stderr, "File <%s> open failed.\n", argv[1]); return 0; } if (argc > 2) { if (ofp = fopen(argv[2], "r")) { fprintf(stderr, "File <%s> exists. Overwrite it? ", argv[2]); fclose(ofp); if (getchar() != 'y') return 0; } ofp = fopen(argv[2], "w"); if (!ofp) { fprintf(stderr, "File <%s> open failed.\n", argv[2]); return 0; } } while (!feof(ifp)) { c1 = cnext1 ? cnext1 : fgetc(ifp); if (feof(ifp)) break; cnext1 = 0; if (c1 & 0x80) { c2 = cnext2 ? cnext2 : fgetc(ifp); if (feof(ifp)) break; cnext2 = 0; if (!(syl = ksc2kssm((unsigned char) c1, (unsigned char) c2))) continue; i1 = (syl >> 10) & 0x1f; // Ãʼº i2 = (syl >> 5) & 0x1f; // Áß¼º i3 = syl & 0x1f; // Á¾¼º nSyl++; cho[i1]++; // Ãʼº ºóµµ jung[i2]++; // Áß¼º ºóµµ jong[i3]++; // Á¾¼º ºóµµ chojung[i1*30 + i2]++; // Ãʼº-Áß¼º ºóµµ jungjong[i2*30 + i3]++; // Áß¼º-Á¾¼º ºóµµ cnext1 = fgetc(ifp); if (feof(ifp)) break; if (!(cnext1 & 0x80)) { cnext1 = 0; continue; } cnext2 = fgetc(ifp); //if (feof(ifp)) break; if (!(cnext2 & 0x80)) { cnext2 = 0; continue; } if (syl = ksc2kssm((unsigned char) cnext1, (unsigned char) cnext2)) { nSyl2++; // Á¾¼º-Ãʼº ¿¬¼Ó À½Àý °³¼ö jongcho[i3*21 + ((syl >> 10) & 0x1f)]++; // Á¾¼º-Ãʼº ºóµµ } else { cnext1 = cnext2 = 0; } } } fprintf(ofp, "ÀÚ¸ð ºóµµ Á¶»ç : ÃÑ À½Àý¼ö = %ld", nSyl); fprintf(ofp, " ( @ : ÀÚ¸ð ¾øÀ½ Ç¥½Ã )\n"); // Ãʼº fprintf(ofp, "\n***Ãʼº ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 21; i++) { sum += cho[i]; if (cho[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", ch[i], cho[i], (double) cho[i] / nSyl * 100., (double) sum / nSyl * 100.); } fprintf(ofp, "\n***Ãʼº ºóµµ : °íºóµµ ¼ø***\n"); set_sort_index(cho, si, 21); // °íºóµµ ¼øÀ¸·Î sorting for (j = sum = 0; j < 21; j++) { i = si[j]; sum += cho[i]; if (cho[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", ch[i], cho[i], (double) cho[i] / nSyl * 100., (double) sum / nSyl * 100.); } // Áß¼º fprintf(ofp, "\n***Áß¼º ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 30; i++) { sum += jung[i]; if (jung[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", ju[i], jung[i], (double) jung[i] / nSyl * 100., (double) sum / nSyl * 100.); } fprintf(ofp, "\n***Áß¼º ºóµµ : °íºóµµ ¼ø***\n"); set_sort_index(jung, si, 30); // °íºóµµ ¼øÀ¸·Î sorting for (j = sum = 0; j < 30; j++) { i = si[j]; sum += jung[i]; if (jung[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", ju[i], jung[i], (double) jung[i] / nSyl * 100., (double) sum / nSyl * 100.); } // Á¾¼º fprintf(ofp, "\n***Á¾¼º ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 30; i++) { sum += jong[i]; if (jong[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", jo[i], jong[i], (double) jong[i] / nSyl * 100., (double) sum / nSyl * 100.); } fprintf(ofp, "\n***Á¾¼º ºóµµ : °íºóµµ ¼ø***\n"); set_sort_index(jong, si, 30); // °íºóµµ ¼øÀ¸·Î sorting for (j = sum = 0; j < 30; j++) { i = si[j]; sum += jong[i]; if (jong[i]) fprintf(ofp, "%s\t:%8d\t%6.2f\t%6.2f\n", jo[i], jong[i], (double) jong[i] / nSyl * 100., (double) sum / nSyl * 100.); } // Ãʼº-Áß¼º fprintf(ofp, "\n¿¬¼Ó ÀÚÀ½-¸ðÀ½ ºóµµ Á¶»ç\n"); fprintf(ofp, "\n***Ãʼº-Áß¼º ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 21*30; i++) { sum += chojung[i]; syl = kssm2ksc(0x8000 | (i/30) << 10 | (i%30) << 5 | 0x01); if (chojung[i]) fprintf(ofp, "[%s%s:%c%c]\t:%8d\t%6.2f\t%6.2f\n", ch[i/30], ju[i%30], syl >> 8 & 0xff, syl & 0xff, chojung[i], (double) chojung[i] / nSyl * 100., (double) sum / nSyl * 100.); } set_sort_index(chojung, si, 21*30); // °íºóµµ ¼øÀ¸·Î sorting fprintf(ofp, "\n***Ãʼº-Áß¼º ºóµµ : °íºóµµ ¼ø***\n"); for (j = sum = 0; j < 21*30; j++) { i = si[j]; sum += chojung[i]; syl = kssm2ksc(0x8000 | (i/30) << 10 | (i%30) << 5 | 0x01); if (chojung[i]) fprintf(ofp, "[%s%s:%c%c]\t:%8d\t%6.2f\t%6.2f\n", ch[i/30], ju[i%30], syl >> 8 & 0xff, syl & 0xff, chojung[i], (double) chojung[i] / nSyl * 100., (double) sum / nSyl * 100.); } // Áß¼º-Á¾¼º fprintf(ofp, "\n***Áß¼º-Á¾¼º ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 30*30; i++) { sum += jungjong[i]; if (jungjong[i]) fprintf(ofp, "[%s%s]\t:%8d\t%6.2f\t%6.2f\n", ju[i/30], jo[i%30], jungjong[i], (double) jungjong[i] / nSyl * 100., (double) sum / nSyl * 100.); } set_sort_index(jungjong, si, 30*30); // °íºóµµ ¼øÀ¸·Î sorting fprintf(ofp, "\n***Áß¼º-Á¾¼º ºóµµ : °íºóµµ ¼ø***\n"); for (j = sum = 0; j < 30*30; j++) { i = si[j]; sum += jungjong[i]; if (jungjong[i]) fprintf(ofp, "[%s%s]\t:%8d\t%6.2f\t%6.2f\n", ju[i/30], jo[i%30], jungjong[i], (double) jungjong[i] / nSyl * 100., (double) sum / nSyl * 100.); } // Á¾¼º-Ãʼº fprintf(ofp, "\nÃÑ ¿¬¼Ó À½Àý °³¼ö : %d\n", nSyl2); fprintf(ofp, "\n***Á¾¼º-Ãʼº ºóµµ : °¡³ª´Ù ¼ø***\n"); for (i = sum = 0; i < 30*21; i++) { sum += jongcho[i]; if (jongcho[i]) fprintf(ofp, "[%s%s]\t:%8d\t%6.2f\t%6.2f\n", jo[i/21], ch[i%21], jongcho[i], (double) jongcho[i] / nSyl2 * 100., (double) sum / nSyl2 * 100.); } set_sort_index(jongcho, si, 30*21); // °íºóµµ ¼øÀ¸·Î sorting fprintf(ofp, "\n***Á¾¼º-Ãʼº ºóµµ : °íºóµµ ¼ø***\n"); for (j = sum = 0; j < 30*21; j++) { i = si[j]; sum += jongcho[i]; if (jongcho[i]) fprintf(ofp, "[%s%s]\t:%8d\t%6.2f\t%6.2f\n", jo[i/21], ch[i%21], jongcho[i], (double) jongcho[i] / nSyl2 * 100., (double) sum / nSyl2 * 100.); } if (ifp != stdin) fclose(ifp); if (ofp != stdout) fclose(ofp); return 0; }