-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathparse_input.h
50 lines (40 loc) · 1.4 KB
/
parse_input.h
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
#ifndef PARSE_INPUT_H_
#define PARSE_INPUT_H_
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define UNPARSED 0
#define PARSED 1
#define ERROR 2
#define OPT_MAX_LENGTH 256
#define KEY_NOT_FOUND -1
#define KEY_FOUND 0
typedef char input_string[OPT_MAX_LENGTH];
typedef struct input_file {
int state;
int N_opts;
int N_alloc;
int N_unread_keys;
input_string *keys;
input_string *values;
int *reads;
input_string *unread_keys;
} input_file;
void loadInputFile(input_file *inp, const char *filename);
void loadInput(input_file *inp, FILE * desc);
int getInputKeyIndex(input_file *inp, const char *skey, int mandatory);
int getInputString(input_file *inp, const char *skey, char *dest, int mandatory);
int getInputInt(input_file *inp, const char *skey, int *dest, int mandatory);
int getInputUInt(input_file *inp, const char *skey, unsigned int *dest, int mandatory);
int getInputLLInt(input_file *inp, const char *skey, long long int *dest, int mandatory);
int getInputDouble(input_file *inp, const char *skey, double *dest, int mandatory);
int getInputFloat(input_file *inp, const char *skey, float *dest, int mandatory);
int getInputChar(input_file *inp, const char *skey, char *dest, int mandatory);
void getTrimmedString(const char *src, char *dest);
void setUnreadKeys(input_file *inp);
void cleanInputFile(input_file *inp);
#endif