File: afnio.c

package info (click to toggle)
glam2 1064-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 956 kB
  • sloc: ansic: 6,925; xml: 757; asm: 74; makefile: 54; sh: 11
file content (60 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (4)
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
#include "afnio.h"

FILE	*open_file(char *fstring,char *subfile,char *cmnd)
{
	FILE	*fptr;
	char	s[100];

	while(fstring[0] == ' ') fstring++;
	strcpy(s,fstring);
	strcat(s,subfile);
	if((fptr = fopen(s,cmnd)) == NULL) {
		fprintf(stderr,"Could not open file \"%s\"\n",s);
		print_error("File does not exist!\n");
	}
	return(fptr);
}

long     ParseReals(char *str, double *values, char *msg)
/** WARNING: index starts at 0 not 1 as for ParseIntegers() **/
{
        long	n;
	double	k;

	if(!isdigit(str[0])) print_error(msg);
        for(n=1; str[0] != 0; ){
           if(str[0] == ',') { n++; str++; }
           else if(isdigit(str[0])){
                if(sscanf(str,"%lf", &k) != 1){ print_error(msg); }
                else { 
		   values[n-1] = k; 
		   while(isdigit(str[0]) || str[0] == '.' ) str++; 
		}
           } else print_error(msg);
        }
        return n;
}

long     ParseIntegers(char *str, long *values, char *msg)
{
        long     n,k;

	if(!isdigit(str[0])) print_error(msg);
        for(n=1; str[0] != 0; ){
           if(str[0] == ',') { n++; str++; }
           else if(isdigit(str[0])){
                if(sscanf(str,"%ld", &k) != 1){ print_error(msg); }
                else { values[n] = k; while(isdigit(str[0])) str++; }
           } else print_error(msg);
        }
        return n;
}

char	*String(char *s)
{
	char *S;
	if((S=(char*) calloc((strlen(s)+1),sizeof(char)))==NULL)
		print_error("Out of Memory");
	strcpy(S,s); return S; 
}