/* encode.c (saitou.c helper program) - Don Yang (uguu.org) Generates template string 02/27/00 */ #include char format[3217]; char length[2][85][4]; int iFormat; int main(int argc, char **argv) { FILE *template; int i, s0, s, c, l; if( argc == 1 ) return puts("Need input file."); if( (template = fopen(argv[1], "rt")) == NULL ) return printf("Can not open %s.\n", argv[1]); for(i = 1; i < 85; i++) { if( i + ']' - 1 > '~' ) { if( i + ']' - 1 - ('~' - ']' + 1) > '~' ) sprintf(length[0][i], "~~%c", i + ']' - 1 - 2 * ('~' - ']' + 1)); else sprintf(length[0][i], "~%c", i + ']' - 1 - ('~' - ']' + 1)); } else sprintf(length[0][i], "%c", i + ']' - 1); if( i + '#' - 1 > '[' ) { if( i + '#' - 1 - ('[' - '#' + 1) > '[' ) sprintf(length[1][i], "[[%c", i + '#' - 1 - 2 * ('[' - '#' + 1)); else sprintf(length[1][i], "[%c", i + '#' - 1 - ('[' - '#' + 1)); } else sprintf(length[1][i], "%c", i + '#' - 1); } s0 = 1; l = 0; for(c = fgetc(template); !feof(template); c = fgetc(template)) { if( c == '\n' ) s = 0; else s = c == ' ' ? 2 : 1; if( s != s0 ) { if( s0 == 0 ) format[iFormat++] = '!'; else { if( s0 == 1 ) iFormat += sprintf(format + iFormat, "%s", length[1][l]); else iFormat += sprintf(format + iFormat, "%s", length[0][l]); } l = 1; s0 = s; } else l++; } if( s0 == 0 ) format[iFormat++] = '!'; else { if( s0 == 1 ) iFormat += sprintf(format + iFormat, "%s", length[1][l]); else iFormat += sprintf(format + iFormat, "%s", length[0][l]); } format[iFormat] = 0; puts(format); fclose(template); return 0; }