-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.h
73 lines (53 loc) · 2.02 KB
/
parse.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _PARSE_H_
#define _PARSE_H_
#include <string.h>
#define BUF_SIZE 512
#define MAX_CMDS 100
#define MAX_ARGC 100
#define WHITE_CHARS " \f\n\r\t\v"
#define SEP_CHARS " \f\n\r\t\v,()"
#define CAT_CONST_STR(STR1, STR2) (STR1 STR2)
typedef int bool;
#define true (1)
#define false (0)
/* This macro are useful to suppress the unsued variable warnings */
#define UNUSED(VAR) (void)(VAR)
/******************************************************************************
* String Utilities
*****************************************************************************/
char* strltrim(char* src, const char* chars);
char* strrtrim(char* src, const char* chars);
char* strtrim(char* src, const char* chars);
bool strstartswith(const char* str, const char* tar);
bool strendswith(const char* str, const char* tar);
int strjoin(char* dest, char* strv[], int strc, const char* sep);
/******************************************************************************
* Path Utilities
*****************************************************************************/
char* path_cat(char* dest, char* src);
char* path_change_directory(char* path, char* parent, char* target);
char* path_eliminate_begin_slash(char* path);
char* path_eliminate_tail_slash(char* path);
char* path_ensure_tail_slash(char* path);
bool path_file_exists(const char* path);
/******************************************************************************
* Command Utilities
*****************************************************************************/
typedef struct
{
int argc;
char* argv[MAX_ARGC];
char* input;
char* output;
bool append;
} Command;
typedef struct
{
int cmdc;
Command* cmdv;
bool bg;
} CommandLine;
void parse_command_line(CommandLine* command_line, char* line);
void free_command_line(CommandLine* command_line);
int format_command_line(char* dest, CommandLine* command_line, bool bg);
#endif /* _PARSE_H_ */