/* * splithub.c * * Split a Hub file into two component files: * - a Ref file containing Hub markup and entity references * to localizable strings; * - an Ent file containing the localizable strings as entities; * Version 1, release 4 - May 1997 * * Designed and written by Laurent Sabarthez * at I&G Com (Boulogne, France). * * This software has been put in the public domain by * I&G Com, as a contribution to the Open Tag initiative. * * I&G Com does not provide any type of support or * liability for this software. Use it at your own risks. * * Bug reports should be sent to: * * * * */ #include #include int split(FILE *hub, FILE *ref, FILE *ent) { int c, k, s; s = 0; c = 1; while ((k = fgetc(hub)) != EOF) { switch (s) { case 0: switch (k) { case '<': fputc(k, ref); s = 1; break; case '\n': s = 0; break; default: fputc('\n', ref); fprintf(ref, "&ENT-%06d;\n", c); fprintf(ent, "': fputc(k, ref); s = 0; break; case '\n': s = 1; break; default: fputc(k, ref); s = 1; break; } break; case 2: switch (k) { case '<': fputc(k, ref); fprintf(ent, "\">\n"); s = 1; break; case '\n': s = 2; break; default: fputc(k, ent); s = 2; break; } break; default: fprintf(stderr, "Krtojofr??\n"); return -1; } } return 0; } int main(int argc, char **argv) { FILE *hub; FILE *ref; FILE *ent; char hubFilename[FILENAME_MAX]; char refFilename[FILENAME_MAX]; char entFilename[FILENAME_MAX]; if (argc != 2) { fprintf(stderr, "Invalid command line.\n"); fprintf(stderr, "Usage: splithub \n"); return -1; } strcpy(hubFilename, argv[1]); strcpy(refFilename, argv[1]); strcpy(entFilename, argv[1]); strcat(hubFilename, ".HUB"); strcat(refFilename, ".REF"); strcat(entFilename, ".ENT"); if ((hub = fopen(hubFilename, "r")) == NULL) { fprintf(stderr, "Cannot open Hub file %s\n", hubFilename); return -1; } if ((ref = fopen(refFilename, "w")) == NULL) { fprintf(stderr, "Cannot open Ref file %s\n", refFilename); fclose(hub); return -1; } if ((ent = fopen(entFilename, "w")) == NULL) { fprintf(stderr, "Cannot open Ent file %s\n", entFilename); fclose(hub); fclose(ref); return -1; } if (split(hub, ref, ent) != 0) { fprintf(stderr, "splithub %s: Hub splitting failed.\n", hubFilename); fclose(hub); fclose(ref); fclose(ent); return -1; } fprintf(stderr, "splithub %s: Hub splitting done.\n", hubFilename); fclose(hub); fclose(ref); fclose(ent); return 0; }