aboutsummaryrefslogtreecommitdiffstats
path: root/irc_parse.h
blob: 6366064a15e5f5cde3eb39de209f7362b5c32663 (plain) (blame)
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
#ifndef __IRC_PARSE_H
#define __IRC_PARSE_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>

#include "util.h"

//points to one token in da string
#define IRC_TKT_NONE  0
#define IRC_TKT_HOST  1
#define IRC_TKT_CMD   2
#define IRC_TKT_PARAM 3
typedef struct irc_token_el
{
	int type;
	int size;
	char *token;
} irc_token_el;

#define IRC_TK_MAX_SIZE 100
typedef struct irc_token
{
	int size; //how many tokens
	int max_size; //allocate token spaces
	irc_token_el **tk_list;
} irc_token;



//create default token list, with prealocated, token structures
irc_token* token_create();
//create new string(with extra byte that have NULL at the end), for token andd to list
int token_add(irc_token *tk, char *s, char *e);
//compare token by index with string
int token_cmp(irc_token *tk, int idx, char *str);
//return new string that could be freed
char* token_new_str(irc_token *tk, int idx);
//number of tokens
int token_len(irc_token *tk);
//create new instance of token structure
irc_token* token_cpy_new(irc_token *tk);
//clean all tokens
void token_destroy(irc_token *tk);

//return number of parse tokens
irc_token* irc_parse(char *str, int sz);


#endif