home *** CD-ROM | disk | FTP | other *** search
- (* ------------------------------------------------------ *)
- (* ASCI2TEX.PAS *)
- (* (c) 1990 Norbert Schmitt & TOOLBOX *)
- (* ------------------------------------------------------ *)
-
- PROGRAM ascii2tex;
- USES crt;
-
- CONST
- zeil_laenge = 100 ; (* max. Zeilenlänge *)
- (* Zeilenumbruch erfolgt ab Spalte 60 bei ' ' *)
-
- TYPE zeil_range = 1..zeil_laenge;
- zeile = PACKED ARRAY [zeil_range] OF CHAR ;
-
- VAR ausdruck : zeile ;
- ch : char;
- charset : SET OF char;
- eingabefile,
- ausgabefile : TEXT;
- datei,
- txtdatei,
- texdatei : STRING;
- pos_aus,i : integer;
- dt_Anf_z_Beg,
- einf_Anf_z_Beg,
- ok : Boolean;
-
- FUNCTION dateivorhanden (VAR xfile : TEXT;
- dateiname : STRING): Boolean;
- BEGIN
- assign (xfile, dateiname);
- {$I-}
- reset(xfile);
- {$I+}
- IF IOResult = 0 THEN
- dateivorhanden := TRUE
- ELSE
- dateivorhanden := FALSE;
- END;
-
- PROCEDURE Paramtest;
- BEGIN
- ok := FALSE;
- IF ParamCount = 0 THEN BEGIN
- GotoXY( 1, 5);
- write('Path und Dateiname(ohne .TXT) : ');
- readln(datei);
- FOR i := 1 TO Length(datei) DO
- datei[i] := UpCase(datei[i]);
- ok := TRUE;
- END;
- IF ParamCount = 1 THEN BEGIN
- datei := ParamStr(1);
- ok := TRUE;
- END;
- IF ok THEN BEGIN
- ok := FALSE;
- txtdatei := datei + '.TXT';
- IF NOT dateivorhanden(eingabefile, txtdatei) THEN
- BEGIN
- writeln;
- writeln('Fehler: Datei ',txtdatei,
- ' im Path nicht vorhanden.');
- writeln;
- writeln('Hinweis: Programm erneut aufrufen ',
- 'und den richtigen');
- writeln('Path und Dateinamen ohne .TXT angeben');
- writeln('Oder: Datei hat eine andere ',
- 'Endung als .TXT');
- writeln('Das Programm wird jetzt abgebrochen');
- writeln;
- Halt(1);
- ok := FALSE
- END ELSE
- ok := TRUE;
- END;
- END;
-
- PROCEDURE TxttoTex;
- (* Eröffnung einer TeX-Datei *)
- VAR antwort : char;
- BEGIN
- antwort := 'N';
- IF ok THEN BEGIN
- texdatei := datei + '.TEX';
- REPEAT
- IF NOT dateivorhanden(ausgabefile, texdatei) THEN
- BEGIN
- rewrite(ausgabefile);
- antwort := 'J';
- END ELSE
- BEGIN
- writeln('Datei ',texdatei, ' bereits vorhanden!');
- write('Überschreiben? (J/N) ');
- readln(antwort);
- IF antwort IN ['j', 'J'] THEN
- rewrite(ausgabefile)
- (* bestehende Datei überschreiben *)
- ELSE
- BEGIN
- writeln;
- write('gewünschten Dateinamen ',
- '(ohne Endung .TEX) eingeben: ');
- readln(datei);
- FOR i := 1 TO Length(datei) DO
- datei[i] := UpCase(datei[i]);
- texdatei := datei + '.TEX';
- END;
- END;
- UNTIL antwort IN ['j','J'];
- END;
- END;
-
- PROCEDURE einf_anf (ch : char;
- VAR ausd : zeile;
- VAR pos : integer);
- (* Auswertung der einfachen Anführungszeichen *)
- BEGIN
- ausd[pos] := '\'; inc(pos);
- IF einf_Anf_z_Beg THEN BEGIN
- ausd[pos] := 'g'; inc(pos);
- ausd[pos] := 'l'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- einf_anf_z_Beg := NOT einf_anf_z_Beg
- END ELSE BEGIN
- ausd[pos] := 'g'; inc(pos);
- ausd[pos] := 'r'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- einf_anf_z_Beg := NOT einf_anf_z_Beg
- END;
- inc(pos);
- END;
-
- PROCEDURE auswertung (ch : char;
- VAR ausd : zeile;
- VAR pos : integer);
- BEGIN
- IF ch IN charset THEN BEGIN
- CASE ch OF
- 'ä' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'a';
- END;
- 'Ä' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'A';
- END;
- 'ö' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'o';
- END;
- 'Ö' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'O';
- END;
- 'ü' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'u';
- END;
- 'Ü' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 'U';
- END;
- 'ß' : BEGIN
- ausd[pos] := '"'; inc(pos);
- ausd[pos] := 's';
- END;
- '"' : BEGIN
- ausd[pos] := '\'; inc(pos);
- IF dt_Anf_z_Beg THEN BEGIN
- ausd[pos] := 'g'; inc(pos);
- ausd[pos] := 'l'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- dt_anf_z_Beg := NOT dt_anf_z_Beg
- END ELSE BEGIN
- ausd[pos] := 'g'; inc(pos);
- ausd[pos] := 'r'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- ausd[pos] := 'q'; inc(pos);
- dt_anf_z_Beg := NOT dt_anf_z_Beg
- END;
- END;
- '%' : BEGIN
- ausd[pos] := '\'; inc(pos);
- ausd[pos] := '%';
- END;
- '&' : BEGIN
- ausd[pos] := '\'; inc(pos);
- ausd[pos] := '&';
- END;
- END;
- END
- ELSE
- ausd[pos] := ch;
- inc(pos);
- END; (* auswertung *)
-
- PROCEDURE lesen (VAR ausdruck : zeile);
- VAR
- ch : char;
- pos_aus, k : integer;
- dt_Anf_z_Beg,
- einf_Anf_z_Beg,
- umbruch : Boolean;
-
- BEGIN
- dt_anf_z_Beg := TRUE;
- einf_Anf_z_Beg := TRUE;
- umbruch := FALSE;
- FOR pos_aus := 1 TO zeil_laenge DO
- ausdruck[pos_aus]:=' ';
- (* Ausdruck initialisieren *)
- pos_aus := 1;
- WHILE (NOT eoln(eingabefile)) AND (NOT
- eof (EINGABEFILE)) DO
- BEGIN
- FOR pos_aus := 1 TO zeil_laenge DO
- ausdruck[pos_aus]:=' ';
- (* Ausdruck initialisieren *)
- pos_aus := 1; umbruch := FALSE;
- WHILE (NOT eoln(eingabefile)) AND (NOT
- eof (EINGABEFILE)) AND (pos_aus <= 60) DO
- BEGIN
- read(eingabefile,ch);
- IF ord(ch) > 31 THEN (* Steuerzeichen ignorieren *)
- IF ord(ch) = 39 THEN
- einf_anf(ch, ausdruck, pos_aus)
- (* ch = einfaches Anführungszeichen *)
- ELSE
- auswertung(ch, ausdruck, pos_aus)
- END;
- IF (pos_aus > 60) AND (NOT eoln(eingabefile)) THEN
- BEGIN (* Zeilenformatierung *)
- WHILE (NOT eoln(eingabefile)) AND (NOT
- eof (EINGABEFILE)) AND (NOT umbruch) DO
- BEGIN
- read(eingabefile,ch);
- IF ord(ch) > 31 THEN
- IF ch <> ' ' THEN
- IF ord(ch) = 39 THEN
- einf_anf(ch, ausdruck, pos_aus)
- ELSE
- auswertung(ch, ausdruck, pos_aus)
- ELSE
- umbruch := true;
- END;
- IF eoln(eingabefile) OR eof(eingabefile) THEN
- umbruch := true;
- FOR k := 1 TO pos_aus DO
- (* Zeile des Ausgabefiles schreiben *)
- write(ausgabefile,ausdruck[k]) ;
- writeln(ausgabefile);
- pos_aus := 1
- END;
- END;
- IF NOT umbruch THEN BEGIN
- FOR k := 1 TO pos_aus DO
- write(ausgabefile,ausdruck[k]) ;
- writeln(ausgabefile);
- END;
- END; (* lesen *)
-
- BEGIN (* Hauptprogramm *)
- charset := ['ö','Ö','ä','Ä','ü','Ü','ß','"','%','&'];
- ClrScr;
- Paramtest;
- TxttoTex;
- WHILE NOT eof(eingabefile) DO
- BEGIN
- lesen (ausdruck) ;
- IF NOT eof(eingabefile) THEN readln(eingabefile);
- END;
- close(eingabefile);
- close(ausgabefile);
- writeln;
- writeln('Datei ',texdatei,' wurde erzeugt');
- END.
-
-
-