/* Das Programm ASC2TeX dient zum Konvertieren von Text-Bildschirm-
Hardcopies. Das "Bild" mu� als ASCII-Datei vorliegen und den
Suffix ".SCR" haben.
Aufruf: ASC2TEX Datei_ohne_Suffix */
struct tFlaeche { long int x1, y1, x2, y2, flaeche; };
struct tzeile { unsigned char zeile[256]; };
struct tzeile bild[101];
long int breite;
long int hoehe;
int BildLaden ( char *name )
{
long int x = -1;
long int y = 0;
char dateiname[255];
FILE *datei;
long int zeichen;
strcpy (dateiname, name); strcat (dateiname, ".SCR");
if ( (datei = fopen (dateiname, "rb")) == NULL ) {
printf ("Fehler beim �ffnen der Quelldatei %s", dateiname);
return -1;
};
do {
zeichen = getc (datei);
if (zeichen == 13 || zeichen == EOF) {
x++;
bild[y].zeile[x] = '\0';
x = -1; y++;
}
else if (zeichen != 10) {
x++;
bild[y].zeile[x] = (unsigned char) zeichen;
};
} while ( zeichen != EOF );
bild[y].zeile[0] = (unsigned char) 255;
/* Ist ein eof-Zeichen (26) am Ende der Datei gewesen ? */
y--;
if ( y >= 0 ) {
for ( x = 0; bild[y].zeile[x] != '\0'; x++ );
x--;
if ( x >= 0 && bild[y].zeile[x] == (unsigned char) 26 ) {
bild[y].zeile[x] = '\0';
};
};
return 0;
};
int RechtsLoeschen ()
{
long int y = 0;
while ( bild[y].zeile[0] != 255 ) {
strcut ( bild[y].zeile );
y++;
};
return 0;
};
int LinksLoeschen ()
{
long int x = 0;
long int y = 0;
long int minleer = 256;
while ( bild[y].zeile[0] != 255 ) {
if ( bild[y].zeile[0] != '\0' ) {
for ( x = 0; bild[y].zeile[x] == 32; x++ );
if ( x < minleer )
minleer = x;
};
y++;
};
y = 0;
while ( bild[y].zeile[0] != 255 ) {
if ( bild[y].zeile[0] != '\0' ) {
for ( x = 0; x < minleer; x++ )
strdel ( bild[y].zeile );
};
y++;
};
return 0;
};
int UntenLoeschen ()
{
long int y = 0;
while ( bild[y].zeile[0] != 255 ) {
y++;
};
y--;
while ( bild[y].zeile[0] == '\0' && y >= 0 ) {
bild[y].zeile[0] = 255;
y--;
};
return 0;
};
int ObenLoeschen ()
{
long int y = 0;
while ( bild[0].zeile[0] == '\0' ) {
y = 0;
while ( bild[y].zeile[0] != 255 ) {
strcpy (bild[y].zeile, bild[y+1].zeile);
y++;
};
};
return 0;
};
int HorLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int start, long int ziel, long int y,
long int offsetZaehlerStart, long int offsetTeilerStart,
long int offsetZaehlerEnd, long int offsetTeilerEnd,
long int offsetZaehlerY, long int offsetTeilerY )
{
fprintf ( datei, " \\put(%4.2f, %4.2f)",
((float) ((start * ZeiBrei)
+ ((ZeiBrei * offsetZaehlerStart) / offsetTeilerStart))) / 100.0,
((float) (((hoehe - y) * ZeiHoe)
- ((ZeiHoe * offsetZaehlerY) / offsetTeilerY))) / 100.0 );
fprintf ( datei, "{\\line(1,0){%4.2f}}\n",
((float) (((ziel - start) * ZeiBrei)
- ((ZeiBrei * offsetZaehlerStart) / offsetTeilerStart)
+ ((ZeiBrei * offsetZaehlerEnd) / offsetTeilerEnd))) / 100.0 );
return 0;
};
int VerLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x, long int start, long int ziel,
long int offsetZaehlerX, long int offsetTeilerX,
long int offsetZaehlerStart, long int offsetTeilerStart,
long int offsetZaehlerEnd, long int offsetTeilerEnd )
{
fprintf ( datei, " \\put(%4.2f, %4.2f)",
((float) ((x * ZeiBrei)
+ ((ZeiBrei * offsetZaehlerX) / offsetTeilerX))) / 100.0,
((float) (((hoehe - start) * ZeiHoe)
- ((ZeiHoe * offsetZaehlerStart) / offsetTeilerStart))) / 100.0 );
fprintf ( datei, "{\\line(0,-1){%4.2f}}\n",
((float) (((ziel - start) * ZeiHoe)
- ((ZeiHoe * offsetZaehlerStart) / offsetTeilerStart)
+ ((ZeiHoe * offsetZaehlerEnd) / offsetTeilerEnd))) / 100.0 );
return 0;
};
int EinfHorLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int *x, long int *y,
long int offsetZaehler, long int offsetTeiler )
{
long int start;
int EinfVerLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int *x, long int *y,
long int offsetZaehler, long int offsetTeiler )
{
long int start;
long int offsetZaehlerEnd;
long int offsetTeilerEnd;
int DoppHorLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int *x, long int *y,
long int offsetZaehler1, long int offsetTeiler1,
long int offsetZaehler2, long int offsetTeiler2 )
{
long int start1;
long int start2;
int DoppVerLinie ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int *x, long int *y,
long int offsetZaehler1, long int offsetTeiler1,
long int offsetZaehler2, long int offsetTeiler2 )
{
long int start1;
long int start2;
int UnterstricheScannen ( FILE *datei,
long int ZeiBrei, long int ZeiHoe )
{
long int y;
long int x;
long int start;
start = -1;
for ( y = 0; y < hoehe; y++ ) {
for ( x = 0; x <= breite; x++ ) {
if ( bild[y].zeile[x] == Unterstrich ) {
if ( start == -1 )
start = x;
}
else if ( start > -1 ) {
HorLinie ( datei, ZeiBrei, ZeiHoe, start, x, y,
(long) 0, (long) 1, (long) 0, (long) 1,
(long) 9, (long) 10 );
start = -1;
};
}; /* for ( x = 0...) */
}; /* for ( y = 0...) */
return 0;
};
int LinienScannen ( FILE *datei,
long int ZeiBrei, long int ZeiHoe )
{
long int y;
long int x;
for ( y = 0; y < hoehe; y++ )
strextend ( bild[y].zeile, (short) breite );
for ( x = 0; x <= breite; x++ )
bild[y].zeile[x] = (unsigned char) 255;
EinfHorLinienScannen ( datei, ZeiBrei, ZeiHoe );
EinfVerLinienScannen ( datei, ZeiBrei, ZeiHoe );
DoppHorLinienScannen ( datei, ZeiBrei, ZeiHoe );
DoppVerLinienScannen ( datei, ZeiBrei, ZeiHoe );
UnterstricheScannen ( datei, ZeiBrei, ZeiHoe );
return 0;
};
/* -------------------------------------------------------------------- */
/* Bl�cke Scannen (Punktmuster und Vollbl�cke) */
int DotsSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2,
float xBrei, float yHoe )
/* Schreibt die geeigneten TeX-Befehle in die datei, so da�
ein Punktemuster auf der Fl�che lo=(x1,y1) bis ru=(x2,y2)
entsteht. Einschl. lu und ro */
{
float yLauf;
float yDistanz;
float xLauf;
float xDistanz;
int xAnzahl;
int yAnzahl;
int i;
int DuennBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
return DotsSchreiben
(datei, ZeiBrei, ZeiHoe, x1, y1, x2, y2, (float) 0.15, (float) 0.2);
};
int MittelBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
return DotsSchreiben
(datei, ZeiBrei, ZeiHoe, x1, y1, x2, y2, (float) 0.2, (float) 0.3);
};
int DickBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
return DotsSchreiben
(datei, ZeiBrei, ZeiHoe, x1, y1, x2, y2, (float) 0.25, (float) 0.4);
};
int VollBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
fprintf ( datei,
" \\put(%6.4f, %6.4f){\\rule{%4.2f\\unitlength}{%4.2f\\unitlength}}\n",
((float) x1 * ZeiBrei) / 100.0,
((float) ((hoehe - y2) * ZeiHoe)) / 100.0,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
((float) (y2 - y1 + 1) * ZeiHoe) / 100.0 );
return 0;
};
/* Nur f�r Debugging-Zwecke :
int RahmenBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
static int i = 0;
i++;
fprintf ( datei,
" \\put(%6.4f, %6.4f){\\framebox(%4.2f, %4.2f){%2d}}\n",
((float) x1 * ZeiBrei) / 100.0,
((float) ((hoehe - y2) * ZeiHoe)) / 100.0,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
((float) (y2 - y1 + 1) * ZeiHoe) / 100.0,
i );
return 0;
};
*/
int TopBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
if (y1 == y2) {
fprintf ( datei,
" \\put(%6.4f, %6.4f){\\rule{%4.2f\\unitlength}{%4.2f\\unitlength}}\n",
((float) x1 * ZeiBrei) / 100.0,
(((float) ((hoehe - y2) * ZeiHoe))
+ (float) ZeiHoe / 2.0)
/ 100.0,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
(float) ZeiHoe / 200.0 );
}
else {
fprintf ( datei,
" \\multiput(%6.4f, %6.4f)(0.00, %6.4f){%2d}{\\rule{%4.2f\\unitlength}{%4.2f\\unitlength}}\n",
((float) x1 * ZeiBrei) / 100.0,
(((float) ((hoehe - y2) * ZeiHoe))
+ (float) ZeiHoe / 2.0)
/ 100.0,
(float) ZeiHoe / 100.0,
(int) y2 - (int) y1 + 1,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
(float) ZeiHoe / 200.0 );
};
return 0;
};
int ButtomBlockSchreiben
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int x1, long int y1, long int x2, long int y2 )
{
if (y1 == y2) {
fprintf ( datei,
" \\put(%6.4f, %6.4f){\\rule{%4.2f\\unitlength}{%4.2f\\unitlength}}\n",
((float) x1 * ZeiBrei) / 100.0,
((float) ((hoehe - y2) * ZeiHoe)) / 100.0,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
(float) ZeiHoe / 200.0 );
}
else {
fprintf ( datei,
" \\multiput(%6.4f, %6.4f)(0.00, %6.4f){%2d}{\\rule{%4.2f\\unitlength}{%4.2f\\unitlength}}\n",
((float) x1 * ZeiBrei) / 100.0,
((float) ((hoehe - y2) * ZeiHoe)) / 100.0,
(float) ZeiHoe / 100.0,
(int) y2 - (int) y1 + 1,
((float) (x2 - x1 + 1) * ZeiBrei) / 100.0,
(float) ZeiHoe / 200.0 );
};
return 0;
};
int EinBlockScannen
( unsigned char Zeichen, long int x, long int y,
struct tFlaeche *flaeche )
{
struct tFlaeche flaeche1, flaeche2;
long int br1, br2, i;
int ende;
flaeche1.x1 = x;
flaeche1.y1 = y;
flaeche2.x1 = -1; /* Um zu erkennen, ob beschreiben */
/* potentielle Breite feststellen: */
for (br1 = 0 ; bild[y].zeile[x+br1] == Zeichen; br1++ );
ende = 0;
do {
y++;
for (br2 = 0 ; bild[y].zeile[x+br2] == Zeichen; br2++ );
/* Nimmt man die neue Zeile dazu, darf die Fl�che nicht
kleiner werden: */
if ( (y - flaeche1.y1 + 1) * br2 < (y - flaeche1.y1) * br1 ) {
flaeche1.y2 = y - 1;
flaeche1.x2 = flaeche1.x1 + br1 - 1;
flaeche1.flaeche = (y - flaeche1.y1) * br1;
ende = 1;
}
else {
if ( br2 < br1 )
br1 = br2;
};
/* Einen Tip feststellen */
if ( flaeche2.x1 == -1 && bild[y].zeile[x] == Zeichen ) {
i = x;
for (; i >= 0 && bild[y].zeile[i] == Zeichen; i-- );
i++;
for (br2 = 0 ; bild[y].zeile[i+br2] == Zeichen; br2++ );
if ( br2 > br1 ) {
/* Dann ist's ein Tip f�r eine gr��ere Fl�che */
flaeche2.x1 = i;
flaeche2.y1 = y;
};
};
} while (!ende);
if ( flaeche2.x1 == -1 ) { /* kein (weiterer) Tip, also vorbei */
*flaeche = flaeche1;
}
else {
EinBlockScannen ( Zeichen,flaeche2.x1,flaeche2.y1,&flaeche2 );
if (flaeche1.flaeche >= flaeche2.flaeche)
*flaeche = flaeche1;
else
*flaeche = flaeche2;
};
return 0;
};
int BlockRausnehmen ( struct tFlaeche flaeche )
{
long int x, y;
for ( y = flaeche.y1; y <= flaeche.y2; y++ ) {
for ( x = flaeche.x1; x <= flaeche.x2; x++ ) {
bild[y].zeile[x] = ' ';
};
};
return 0;
};
int BlockZeichenScannen
( FILE *datei, long int ZeiBrei, long int ZeiHoe,
unsigned char Zeichen, int Schreiben() )
{
long int x, y;
struct tFlaeche flaeche;
do {
y = 0; x = 0;
while ( y < hoehe && bild[y].zeile[x] != Zeichen ) {
x++;
if ( x == breite ) {
y++; x = 0;
};
};
if ( y < hoehe ) { /* Was gefunden */
EinBlockScannen ( Zeichen, x, y, &flaeche );
Schreiben ( datei, ZeiBrei, ZeiHoe, flaeche.x1, flaeche.y1+1,
flaeche.x2, flaeche.y2+1 );
BlockRausnehmen ( flaeche );
};
} while ( y < hoehe );
return 0;
};
/* -------------------------------------------------------------------- */
/* Text Scannen */
int WortScannen ( FILE *datei, long int ZeiBrei, long int ZeiHoe,
long int *x, long int *y )
{
long int start;
unsigned char zeile [2048];
int zeichen;