/*----------------------------------------------------------------------*/ /* rtfhex.c Konverterer fra en RTF-fil alle spesialtegn, */ /* dvs. alle verdier nn i \'nn, til 8-bits tegn. */ /* Konverterer også spesialtegnene fra Fauske, [, ], \{, \}. */ /* For linjeskift settes inn. Dette betyr at følgende */ /* substitusjoner må gjøres: LF-->SPACE og -->LF */ /* Setter inn punkttagger for \par, \line, \page, \emash, */ /* mens \i beholdes. Alle andre \'er fjernes. */ /* */ /* */ /* */ /* Ver. 1.0 1997-04-28 Øyvind Eide/Dokumentasjonsprosjektet */ /* */ /*----------------------------------------------------------------------*/ #include #include void main(argc, argv) int argc; char **argv; { FILE *innfil, *utfil; char tegn, tegn2, streng[1000]; int verdi, 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"); teller= 0; printf("\n\nKode nummer: %5d", teller); tegn= getc(innfil); while (tegn != EOF) { if (tegn == '\\') { tegn2= getc(innfil); if (tegn2 == '\'') { fscanf(innfil, "%2x", &verdi); putc(verdi, utfil); tegn= getc(innfil); } else if (tegn2 == '{') { fprintf(utfil, "&Cstrek;"); tegn= getc(innfil); } else if (tegn2 == '}') { fprintf(utfil, "&cstrek;"); tegn= getc(innfil); } else { streng[0]= tegn; streng[1]= tegn2; tegn= getc(innfil); i=2; while (tegn != ' ' && tegn != '\n' && tegn != EOF) { streng[i++]= tegn; tegn= getc(innfil); } tegn= getc(innfil); streng[i]= 0; if (i > 7) ; else if (i == 2 && streng[1] == 'i') fprintf(utfil, "%s ", &streng[0]); else if (i == 4 && streng[1] == 'p' && streng[2] == 'a' && streng[3] == 'r') fprintf(utfil, ""); else if (i == 5 && streng[1] == 'l' && streng[2] == 'i' && streng[3] == 'n' && streng[4] == 'e') fprintf(utfil, ""); else if (i == 5 && streng[1] == 'p' && streng[2] == 'a' && streng[3] == 'g' && streng[4] == 'e') fprintf(utfil, ""); else if (i == 7 && streng[1] == 'e' && streng[2] == 'm' && streng[3] == 'd' && streng[4] == 'a' && streng[5] == 's' && streng[6] == 'h') fprintf(utfil, "—"); printf("\b\b\b\b\b%5d", ++teller); } } else if (tegn == '[') { fprintf(utfil, "&Sstrek;"); tegn= getc(innfil); } else if (tegn == ']') { fprintf(utfil, "&sstrek;"); tegn= getc(innfil); } else { putc(tegn, utfil); tegn= getc(innfil); } } } printf("\n\n"); fclose(innfil); fclose(utfil); }