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
|
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
void scan_for_begin(int *m_p, int *n_p, char **type_p){
char buf[BUFSIZ];
char *cursor;
int m,n;
while ( fgets(buf,BUFSIZ,stdin) !=NULL ) {
fputs(buf,stdout);
for (cursor=buf; isblank(*cursor); cursor++);
if (strncmp(cursor,"begin",5)==0) break;
}
if (fgets(buf,BUFSIZ,stdin)==NULL) {
fprintf(stderr,"No parameter line");
exit(1);
}
m=strtol(buf,&cursor,10);
if (errno==ERANGE || m==0){
fprintf(stderr,"Missing or absurd row count");
exit(1);
}
*m_p=m;
n=strtol(cursor,&cursor,10);
if (errno==ERANGE || m==0){
fprintf(stderr,"Missing or absurd column count");
exit(1);
}
*n_p=n;
while (isblank(*cursor)){
cursor++;
}
*type_p=cursor;
}
void check_type( char *type, char *ok[], int count){
int i;
for (i=0; i< count; i++){
if (strncmp(type,ok[i],strlen(ok[i]))==0)
return;
}
fprintf(stderr,"Type %s not permitted\n",
type);
exit(1);
}
|