Elinks currently only support GB2312 as Chinese encoding, but GBK and
[elinks.git] / src / cookies / parsetst.c
blob9e294ce871f31b68c7786f61dea40ec2822affce
1 /* Tool for testing of cookies string parser */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "cookies/parser.h"
14 int
15 main(int argc, char *argv[])
17 struct cookie_str cstr;
18 unsigned char name[1024], value[1024], string[1024];
20 printf("This thing is for testing of cookies name-value pair parser.\n"
21 "You probably do not want to mess with it :).\n");
23 while (1) {
24 printf("Enter string (empty==quit): "); fflush(stdout);
26 fgets(string, 1024, stdin);
28 string[strlen(string) - 1] = '\0'; /* Strip newline. */
29 if (!*string) return 0;
31 if (!parse_cookie_str(&cstr, string)) {
32 printf("ERROR while parsing '%s'!\n", string);
33 continue;
36 memcpy(name, cstr.str, cstr.nam_end - cstr.str);
37 name[cstr.nam_end - cstr.str] = '\0';
38 memcpy(value, cstr.val_start, cstr.val_end - cstr.val_start);
39 value[cstr.val_end - cstr.val_start] = '\0';
41 printf("'%s' -> '%s' :: '%s'\n", string, name, value);