-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer.h
More file actions
30 lines (24 loc) · 752 Bytes
/
tokenizer.h
File metadata and controls
30 lines (24 loc) · 752 Bytes
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
typedef struct token {
char *data;
struct token *next;
} token;
// constants for readability
#define BACKSLASH '\\'
#define TERMINATE '\0'
#define SINGLE_QUOTE '\''
#define DOUBLE_QUOTE '"'
// inserts a token into a linked list
token *insert(char *tok, token *head);
// prints a list of all tokens
// eg. [{a},{b},{c}]
void print_tokens(token *head);
// removes all occurences of a char from a string
char *remove_chars(char *p, char remove);
// formats a char pointer for insert()
token *make_token(int len, char *tok, token *head, char quote);
/*
* parses a char ptr and returns as a token
* splits tokens on "|;<>&", removes whitespace,
* handles escape chars and quotes
*/
token *tokenize_input(token *head, char *input, char quote);