-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.h
58 lines (49 loc) · 917 Bytes
/
header.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
#ifndef __HEADER__
#define __HEADER__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CMD_SIZE 256
#define OUI 1
#define NON 0
void bar() {
printf("-----------\n");
}
typedef struct Token {
char *val;
struct Token *prev;
struct Token *next;
size_t len;
} Token;
Token *init(char *val) {
Token *ret = malloc(sizeof(Token));
ret->val = malloc(sizeof(val));
strcpy(ret->val, val);
ret->prev = NULL;
ret->next = NULL;
ret->len = 1;
return ret;
free(ret);
free(ret->val);
}
void updateLen(Token *tok, size_t len) {
while (tok != NULL) {
tok->len = len;
tok = tok->prev;
}
}
Token *add(Token *prev, char *val) {
Token *ret = init(val);
ret->prev = prev;
updateLen(ret, prev->len + 1);
prev->next = ret;
return ret;
free(ret);
}
void display(Token *tok) {
while (tok != NULL) {
printf("%s\n", tok->val);
tok = tok->next;
}
}
#endif