File: failpp.c

package info (click to toggle)
direvent 5.4-0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,336 kB
  • sloc: sh: 21,812; ansic: 15,962; lex: 2,398; yacc: 1,439; makefile: 387; perl: 286; awk: 55; sed: 16
file content (60 lines) | stat: -rw-r--r-- 908 bytes parent folder | download | duplicates (3)
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>

static char errmark[] = "stop+";
#define ERRLEN (sizeof(errmark)-1)

int
main(int argc, char **argv)
{
	int c;
	int i = 0;
	int bol = 1;
	int ex = 0;
	FILE *input;
	
	if (argc > 1) {
		input = fopen(argv[1], "r");
		if (!input) {
			perror("input");
			return 1;
		}
	}

	while ((c = fgetc(input)) != EOF) {
		if (bol) {
			if (i < ERRLEN) {
				if (c != errmark[i]) {
					if (i)
						fwrite(errmark, i, 1, stdout);
					fputc(c, stdout);
					bol = i = 0;
				}
			} else if (i == ERRLEN) {
				if (!isdigit(c)) {
					fwrite(errmark, i, 1, stdout);
					fputc(c, stdout);
					bol = i = 0;
				} 
				ex = c - '0';
			} else if (isdigit(c)) {
				ex = ex * 10 + c - '0';
			} else {
				return ex;
			}
			i++;
		} else {
			fputc(c, stdout);
			if (c == '\n') {
				bol = 1;
				i = 0;
			}
		}
	}
	return 0;
}