|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T
Length: 2308 (0x904)
Types: TextFile
Names: »TeXExpand.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec1/textools/TeXExpand.c«
/* expand TeX and LaTeX's \input and \include */
#include <stdio.h>
TeXExpand(fp,big,maxlen)
FILE *fp;
char *big;
int maxlen;
{
char bigg[50000];
FILE *fpp;
int c,c1;
char w[100];
int i,j;
extern wflag;
while ((c = getc(fp)) != EOF)
{
if (c == '%' || c1 == '%')
{
while ((c =getc(fp)) != EOF)
if (c == '\n')
{
*big++=c;
break;
}
c1=c;
continue;
}
if (c != '\\')
*big++=c;
else /* detect TeX commands (backslash) */
{
/* see if \input or \include is the control sequence */
i=0;
c1=c; /* update last character */
while ((c = getc(fp)) != EOF)
{
if(c == ' ' || c=='\n' || c=='$' || c=='#' || c=='%'
|| c=='{' || c=='(' || c==')' || c == '\\') break;
w[i++]=c;
}
if(w[1]=='n' && w[2]=='p' && w[3]=='u' && w[4]=='t'
|| w[1]=='n' && w[2]=='c' && w[3]=='l' && w[4]=='u'
&& w[5]=='d' && w[6]=='e')
{
/* if it is \input or \include , get the file name */
i=0;
while (( c = getc(fp)) != EOF)
{
if (c==' ' || c=='\n' || c=='}')
break;
w[i++]=c;
}
w[i]='\0';
fpp=fopen(w, "r"); /* open the new file */
if( fpp == NULL )
{
/* if file is not found, try file.tex */
strcat(w,".tex");
fpp=fopen(w, "r");
if( fpp == NULL )
{
fprintf(stderr,
"TeXExpand: Cannot open %s\n",w);
bigg[0]='\0';
}
else
{
if (wflag != 1)
{
fprintf(stderr,"%s:\n",w);
TeXMatch(fpp);
fprintf(stderr,"\n");
fseek(fpp,0,0);
}
TeXExpand(fpp,bigg,maxlen);
fclose(fpp);
}
}
else
{
if (wflag != 1)
{
fprintf(stderr,"%s:\n",w);
TeXMatch(fpp);
fprintf(stderr,"\n");
fseek(fpp,0,0);
}
TeXExpand(fpp,bigg,maxlen);
fclose(fpp);
}
strcat(big,bigg);
big += strlen(bigg);
w[0]='\0';
}
else
/* if the control sequence is not \input or \include write it out */
{
*big++='\\';
for (j=0; j < i; j++)
*big++=w[j];
/* do not write commented text */
if (c1 != '\\' && c != '%')
*big++=c;
else
if (c1 == '\\')
{
*big++=c;
c=' ';
}
}
}
c1=c; /* update last character */
}
*big++ = '\0';
}