-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdline.h
More file actions
56 lines (47 loc) · 1.18 KB
/
Copy pathcmdline.h
File metadata and controls
56 lines (47 loc) · 1.18 KB
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
#ifndef CMDLINE_H
#define CMDLINE_H
#include <stddef.h>
#include <stdbool.h>
#define MAX_ARGS 16
#define MAX_CMDS 16
struct cmd {
char *args[MAX_ARGS + 1]; //+1 to have a NULL at the end if nargs = MAX_ARGS
size_t n_args;
};
struct line {
struct cmd cmds[MAX_CMDS];
size_t n_cmds;
char *file_input;
char *file_output;
bool file_output_append; // only used if file_output isn't NULL
bool background;
};
/**
* Init a struct line
*
* All bytes occupied by the structure are set to 0
*
* @param li pointer on the struct line to be initialized
*/
void line_init(struct line *li);
/**
* Parse the string "str" and construct the struct line pointed by "li"
*
* You must call line_init() or line_reset() before calling this function
*
* @param li pointer on the struct line to fill
* @param str pointer on the first char of string line entered by the user
*
* @return 0 on success, -1 on failure
*/
int line_parse(struct line *li, const char *str);
/**
* Reset a struct line
*
* Free dynamically allocated memory
* All bytes occupied by the structure are set to 0
*
* @param li pointer on the struct line to be reset
*/
void line_reset(struct line *li);
#endif