summaryrefslogtreecommitdiff
path: root/support/db2tex/db_tex.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/db2tex/db_tex.c
Initial commit
Diffstat (limited to 'support/db2tex/db_tex.c')
-rw-r--r--support/db2tex/db_tex.c194
1 files changed, 194 insertions, 0 deletions
diff --git a/support/db2tex/db_tex.c b/support/db2tex/db_tex.c
new file mode 100644
index 0000000000..7e5e0d6469
--- /dev/null
+++ b/support/db2tex/db_tex.c
@@ -0,0 +1,194 @@
+/* db_tex.c - main-Routinen für dbtex; UKE/EDV, Bernd Paradies, 05.11.90 */
+
+/* db2tex.c: db2tex.h db_tex.c */
+
+#include "db2tex.h"
+
+/* -- importierte Variablen */
+
+IMPORT char SpTab[MAXSPALTEN][50];
+IMPORT int SpLen[MAXSPALTEN], SpNr;
+
+IMPORT char *prgname;
+
+IMPORT int TxtZeilen, GetRepZeilen, RepZeilen, DefZeilen, InpZeilen;
+IMPORT int MaxReport, OptQuiet, OptOutput, OptCompile;
+
+IMPORT BOOL BeginDocument, EndDocument;
+IMPORT FILE *InpFile, *DefFile, *ShFile, *stdlog;
+
+/* -- Funktions-Prototypen */
+
+PUBLIC int PutTexRep (); /* wird von GetReport ausgeführt */
+PRIVATE int GetTex(); /* bearbeitet die TeX-Datei */
+PUBLIC void do_tex(); /* main für dbtex */
+
+/* ---------------------------------------------------------------------- */
+
+PRIVATE int GetTex(Nr,Zeile)
+ int Nr;
+ char *Zeile;
+{
+char Spalte[MAXZEILE];
+char TmpZeile[MAXZEILE]; /* Zeile im printf-Format */
+char *Zptr; /* wandert durch Zeile */
+char *Tptr; /* zeigt auf den letzten Text */
+
+ if (Nr == 1) /* SQL-Zeile auswerten */
+ return (GetSQL (Zeile));
+
+ if (strncmp (ENDDOC, Zeile, strlen(ENDDOC)) == 0)
+ EndDocument = TRUE;
+
+ if (EndDocument) return (0); /* alles ab EndDoc. ignorieren */
+
+ if (!BeginDocument) /* noch im Definitions-Bereich */
+ {
+ if (strncmp (BEGINDOC, Zeile, strlen(BEGINDOC)) == 0)
+ BeginDocument = TRUE;
+ else
+ {
+ fprintf (DefFile, "%s", Zeile);
+ DefZeilen++;
+ }
+ return (0);
+ }
+
+ strcpy (TmpZeile, ""); /* Initialisierung */
+ Zptr = Tptr = Zeile;
+
+ while ( (Zptr=strchr(Zptr, '%')) != NULL) /* schnelle Vorprüfung */
+ if ( *(++Zptr) == '$' )
+ {
+ strncat (TmpZeile, Tptr, Zptr - Tptr - 1); /* kopiere bis % */
+ sscanf (++Zptr, "%[^, ]", Spalte); /* hole Spaltenname */
+
+ if ( ChkName(Spalte) == NULL )
+ warning ("Ungültiger Spaltenname ignoriert. Zeile", Nr);
+ else
+ {
+ strcat (TmpZeile, TEXMAC); /* Backslash */
+ strcat (TmpZeile, strtoupper(Spalte)); /* alles groß */
+ Zptr += strlen (Spalte); /* Spalte überspringen */
+ }
+ Tptr = Zptr; /* neuer Textbeginn */
+ }
+
+ strcat (TmpZeile, Tptr); /* kopiere den Rest der Zeile */
+ fprintf (InpFile, "%s", TmpZeile);
+ InpZeilen++;
+#ifdef __TEST__
+ printf ("IN : %s", Zeile);
+ printf (" >: %s\n", TmpZeile);
+#endif __TEST__
+}
+
+/* ---------------------------------------------------------------------- */
+
+PUBLIC int PutTexRep(Nr, Zeile)
+ int Nr;
+ char *Zeile;
+{
+char *Sptr;
+REG ii;
+
+ fprintf (DefFile, TEXLINE);
+ fprintf (DefFile, "%% --- Exemplar Nr. %i ---\n", Nr-2);
+ fprintf (DefFile, "\\newpage \\setcounter{page}{1}\n");
+ Zeile[strlen(Zeile)-1] = 0;
+ Sptr = Zeile;
+ for (ii=0; ii != SpNr; ii++)
+ {
+ *(Sptr + SpLen[ii]) = 0;
+ fprintf (DefFile, "\\def\\%s{%s \\ }\n", SpTab[ii], delblank(Sptr) );
+ Sptr += SpLen[ii] + 3;
+ }
+ fprintf (DefFile, "\\input {%s}\n", InpName);
+ DefZeilen += SpNr + 4;
+}
+
+/* ---------------------------------------------------------------------- */
+
+PUBLIC int do_tex(void)
+{
+char Command[100];
+char Temp[30];
+
+ DefFile = _fopen (DefName, "w");
+ InpFile = _fopen (InpName, "w");
+
+ fprintf (DefFile, "%% --- Definitions-Sektion von %s ---\n", TxtName );
+ fprintf (DefFile, TEXLINE);
+ TxtZeilen = WalkFile(TxtName, GetTex);
+
+ fprintf (DefFile, "%s\n", BEGINDOC);
+ RepZeilen = WalkFile(RepName, GetReport);
+
+ if (!EndDocument)
+ error ("syntax error in LaTeX file: missing \\end{document}");
+
+ fprintf (DefFile, TEXLINE);
+ fprintf (DefFile, "%s\n", ENDDOC);
+
+ fclose (InpFile);
+ fclose (DefFile);
+
+ if (OptCompile) /* RETURN !!! bei -c Option */
+ return (0);
+
+
+ if (!OptQuiet) printf ("TeX wird gestartet...\n");
+
+ /* -- 1) deutsche Umlaute in dbtex.def für LaTeX */
+ sprintf (Command, "%s < %s > out.tex", UMLT2TEX, DefName );
+ if (system(Command) != 0) error ("umlt2tex liefert Fehler zurück !");
+
+ /* -- 2) deutsche Umlaute in dbtex.inp für LaTeX */
+ sprintf (Command, "mv %s %s.tmp; %s < %s.tmp > %s",
+ InpName, prgname, UMLT2TEX, prgname, InpName);
+ if (system(Command) != 0) error ("umlt2tex liefert Fehler zurück !");
+
+ /* -- 3) TeX wird aufgerufen */
+ sprintf (Command, "%s out.tex > /dev/null", VIRTEX );
+ if (system(Command) != 0) error ("virtex liefert Fehler zurück !");
+
+ /* -- 4) Aufräumarbeiten */
+ sprintf (Command, "rm out.aux out.log out.tex %s.tmp; mv out.dvi %s",
+ prgname, DviName);
+ system (Command);
+
+ /* -- 5) Ausgabe (quiet, Dateiname, Drucker oder Bildschirm) */
+
+ if (OptQuiet || OptOutput)
+ {
+ if (!OptOutput)
+ sprintf (Command, "%s %s | lp -d%s", DVITPS, DviName, PRINTER );
+ else
+ sprintf (Command, "%s %s > %s", DVITTY, DviName, OutName);
+ return (system (Command)); /* RETURN !!! */
+ }
+
+ printf ("Zwischendateien erfolgreich angelegt !\n");
+
+ while (TRUE) /* Endlos-Schleife terminiert bei 'e' */
+ {
+ printf ("\nEnde oder Ausgabe auf den Drucker oder Bildschirm ? [e/d/b]: ");
+ switch ( getchar() )
+ {
+ case 'd' :
+ sprintf (Command, "%s %s | lp -d%s", DVITPS, DviName, PRINTER );
+ printf ("%s\n", Command);
+ system (Command);
+ break;
+ case 'b' :
+ sprintf (Command, "%s %s", DVITTY, DviName );
+ printf ("%s\n", Command);
+ system (Command);
+ break;
+ case 'e' : return (0); /* RETURN !!! */
+ }
+ getchar(); /* wg. return */
+ }
+} /* ENDE: do_tex() */
+
+/* ENDE: db_tex.c */