/*----------------------------------------------------------------------*/ /* rtftag.c Skifter ut RTF-formattering med SGML-tager i henhold til */ /* DOKUB.DTD. Gjelder kur og snavn + innledende/utledende. */ /* Feilmeldinger skrives til rtftag.err */ /* */ /* Ver. 1.0 1997-04-29 Øyvind Eide/Dokumentasjonsprosjektet */ /* */ /*----------------------------------------------------------------------*/ #include #include void main(argc, argv) int argc; char **argv; { FILE *innfil, *utfil, *feilfil; char tegn, tegn1, tegn2, tegn3, streng[1000]; int i, teller; printf("Innfil: %s utfil: %s OK?", argv[1], argv[2]); tegn= getchar(); if (tegn == 'J' || tegn == 'j') { innfil= fopen(argv[1], "r"); utfil= fopen(argv[2], "w"); feilfil= fopen("rtftag.err", "w"); teller= 0; printf("\n\nAvsnitt: %5d", teller); fprintf(utfil, ""); tegn= getc(innfil); while (tegn != EOF) { while (tegn != '{' && tegn != EOF) { putc(tegn, utfil); tegn= getc(innfil); } tegn1= getc(innfil); tegn2= getc(innfil); tegn3= getc(innfil); if (tegn1 == '\\' && tegn2 == 'i' && (tegn3 == ' ' || tegn3 == '\n')) { i= 0; tegn= getc(innfil); while (tegn != '}' && tegn != EOF) { if (tegn == ',') { tegn1= getc(innfil); streng[i]= 0; fprintf(utfil, "%s%c%c", &streng[0], tegn, tegn1); i= 0; } else if (tegn == '<') { while (tegn != '>' && tegn != EOF) { putc(tegn, utfil); tegn= getc(innfil); } putc(tegn, utfil); tegn= getc(innfil); } else streng[i++]= tegn; tegn= getc(innfil); } streng[i++]= getc(innfil); tegn= getc(innfil); while (tegn == '{') { tegn1= getc(innfil); tegn2= getc(innfil); tegn3= getc(innfil); if (tegn1 == '\\' && tegn2 == 'i' && (tegn3 == ' ' || tegn3 == '\n')) { tegn= getc(innfil); while (tegn != '}' && tegn != EOF) { if (tegn == ',') { tegn1= getc(innfil); streng[i]= 0; fprintf(utfil, "%s%c%c", &streng[0], tegn, tegn1); i= 0; } else streng[i++]= tegn; tegn= getc(innfil); } streng[i++]= getc(innfil); tegn= getc(innfil); } else { streng[--i]= 0; fprintf(feilfil, "Annet enn kursiv! Sted: %s\n", &streng[0]); } } tegn1= streng[--i]; streng[i]= 0; fprintf(utfil, "%s", &streng[0]); printf("\b\b\b\b\b%5d", ++teller); putc(tegn1, utfil); putc(tegn, utfil); } else fprintf(feilfil, "Annet enn kursiv! Forrige sted var %s, koden er %c.\n", &streng[0], tegn2); tegn= getc(innfil); } printf("\n\n"); fprintf(utfil, ""); fclose(innfil); fclose(utfil); fclose(feilfil); } }