diff options
Diffstat (limited to 'Build/source/texk/mendexk/pageread.c')
-rw-r--r-- | Build/source/texk/mendexk/pageread.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Build/source/texk/mendexk/pageread.c b/Build/source/texk/mendexk/pageread.c new file mode 100644 index 00000000000..9c231690621 --- /dev/null +++ b/Build/source/texk/mendexk/pageread.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* checking last page */ +int lastpage(char *filename) +{ + int i,cc,num= -1; + char logfile[32],numbuff[16]; + FILE *fp; + + for (i=strlen(filename);i>=0;i--) { + if (filename[i]=='.') { + strncpy(logfile,filename,i); + sprintf(&logfile[i],".log"); + break; + } + } + if (i==-1) sprintf(logfile,"%s.log",filename); + + fp=fopen(logfile,"r"); + if (fp==NULL) { + fprintf(stderr,"No log file, %s.\n",logfile); + exit(0); + } + + while (1) { + cc=fgetc(fp); + if (cc==EOF) break; + else if (cc=='[') { + for (i=0;;i++) { + cc=fgetc(fp); + if (((i==0)&&(cc=='-'))||((cc>='0')&&(cc<='9'))) numbuff[i]=cc; + else { + numbuff[i]='\0'; + break; + } + } + if (strlen(numbuff)>0) num=atoi(numbuff); + } + } + + fclose(fp); + + return num; +} |