File: pageread.c

package info (click to toggle)
texlive-bin 2016.20160513.41080.dfsg-2+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 155,060 kB
  • sloc: ansic: 702,862; cpp: 222,090; perl: 76,014; sh: 23,402; makefile: 8,078; lex: 4,710; pascal: 3,782; python: 3,614; java: 3,569; yacc: 2,905; exp: 2,031; xml: 800; tcl: 670; ruby: 620; lisp: 397; sed: 351; asm: 140; csh: 48; awk: 30
file content (64 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mendex.h"

#include <kpathsea/tex-file.h>

static inline int
bfgetc (FILE *stream)
{
	int cc = getc (stream);
	if (cc == '\r') {
		cc = getc (stream);
		if (cc != '\n') {
			ungetc (cc, stream);
			cc = '\r';
		}
	}
	return cc;
}
#define fgetc bfgetc

/*   checking last page   */
int lastpage(const 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);

	if(kpse_in_name_ok(logfile))
		fp=fopen(logfile,"r");
	else
		fp=NULL;
	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;
}