Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

336 lines
7.7 KiB

  1. #include "fmt.h"
  2. #include "scan.h"
  3. #include "str.h"
  4. #include "uint16.h"
  5. #include "uint32.h"
  6. #include "stralloc.h"
  7. #include "socket.h"
  8. #include "buffer.h"
  9. #include "ip4.h"
  10. #include "ip6.h"
  11. #include "mmap.h"
  12. #include "open.h"
  13. #include "byte.h"
  14. #include "textcode.h"
  15. #include "dns.h"
  16. #include "case.h"
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <string.h>
  21. #include <assert.h>
  22. #include "errmsg.h"
  23. #include "iob.h"
  24. #define rdtscl(low) \
  25. __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
  26. int64 writecb(int64 fd,const void* buf,uint64 n) {
  27. (void)fd;
  28. (void)buf;
  29. (void)n;
  30. #if 0
  31. int r;
  32. int todo=n>=65536?65536:n;
  33. r=write(fd,buf,todo);
  34. if (r==-1 && r!=EAGAIN) r=-3;
  35. return r;
  36. #endif
  37. return -1;
  38. }
  39. int main(int argc,char* argv[]) {
  40. (void)argc;
  41. (void)argv;
  42. #if 0
  43. io_batch* b=iob_new(1234);
  44. int64 fd=open("t.c",0);
  45. iob_addbuf(b,"fnord",5);
  46. iob_addfile_close(b,fd,0,7365);
  47. iob_write(1,b,writecb);
  48. #endif
  49. #if 0
  50. char dest[1024];
  51. unsigned long len;
  52. scan_urlencoded2("libstdc++.tar.gz",dest,&len);
  53. buffer_putmflush(buffer_1,dest,"\n");
  54. #endif
  55. #if 0
  56. static stralloc sa;
  57. stralloc_copym(&sa,"foo ","bar ","baz.\n");
  58. write(1,sa.s,sa.len);
  59. #endif
  60. #if 0
  61. buffer_putmflush(buffer_1,"foo ","bar ","baz.\n");
  62. #endif
  63. #if 0
  64. char* c="fnord";
  65. int fd=open_read(c);
  66. errmsg_iam(argv[0]);
  67. carp("could not open file `",c,"'");
  68. diesys(23,"could not open file `",c,"'");
  69. #endif
  70. #if 0
  71. errmsg_warn("could not open file `",c,"'",0);
  72. errmsg_warnsys("could not open file `",c,"'",0);
  73. #endif
  74. #if 0
  75. char buf[100]="/usr/bin/sh";
  76. int len=str_len(buf);
  77. assert(byte_rchr(buf,len,'/')==8);
  78. assert(byte_rchr(buf,len,'@')==len);
  79. assert(byte_rchr(buf,len,'h')==len-1);
  80. printf("%d\n",byte_rchr("x",1,'x'));
  81. #endif
  82. #if 0
  83. char buf[IP6_FMT+100];
  84. int i;
  85. char ip[16];
  86. uint32 scope_id;
  87. char* s="fec0::1:220:e0ff:fe69:ad92%eth0/64";
  88. char blubip[16]="\0\0\0\0\0\0\0\0\0\0\xff\xff\x7f\0\0\001";
  89. i=scan_ip6if(s,ip,&scope_id);
  90. assert(s[i]=='/');
  91. buffer_put(buffer_1,buf,fmt_ip6if(buf,ip,scope_id));
  92. buffer_putnlflush(buffer_1);
  93. buffer_put(buffer_1,buf,fmt_ip6ifc(buf,blubip,scope_id));
  94. buffer_putnlflush(buffer_1);
  95. scan_ip6("2001:7d0:0:f015:0:0:0:1",ip);
  96. buffer_put(buffer_1,buf,fmt_ip6(buf,ip));
  97. buffer_putnlflush(buffer_1);
  98. #endif
  99. #if 0
  100. char buf[100];
  101. int i;
  102. printf("%d\n",i=fmt_pad(buf,"fnord",5,7,10));
  103. buf[i]=0;
  104. puts(buf);
  105. #endif
  106. #if 0
  107. char ip[16];
  108. char buf[32];
  109. printf("%d (expect 2)\n",scan_ip6("::",ip));
  110. printf("%d (expect 3)\n",scan_ip6("::1",ip));
  111. printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip));
  112. printf("%.*s\n",fmt_ip6(buf,ip),buf);
  113. #endif
  114. #if 0
  115. static stralloc s,t;
  116. stralloc_copys(&s,"fnord");
  117. stralloc_copys(&t,"abc"); printf("%d\n",stralloc_diff(&s,&t));
  118. stralloc_copys(&t,"fnor"); printf("%d\n",stralloc_diff(&s,&t));
  119. stralloc_copys(&t,"fnord"); printf("%d\n",stralloc_diff(&s,&t));
  120. stralloc_copys(&t,"fnordh"); printf("%d\n",stralloc_diff(&s,&t));
  121. stralloc_copys(&t,"hausen"); printf("%d\n",stralloc_diff(&s,&t));
  122. #endif
  123. #if 0
  124. static stralloc s;
  125. stralloc_copys(&s,"fnord");
  126. printf("%d\n",stralloc_diffs(&s,"abc"));
  127. printf("%d\n",stralloc_diffs(&s,"fnor"));
  128. printf("%d\n",stralloc_diffs(&s,"fnord"));
  129. printf("%d\n",stralloc_diffs(&s,"fnordh"));
  130. printf("%d\n",stralloc_diffs(&s,"hausen"));
  131. #endif
  132. #if 0
  133. printf("%d\n",case_starts("fnordhausen","FnOrD"));
  134. printf("%d\n",case_starts("fnordhausen","blah"));
  135. #endif
  136. #if 0
  137. char buf[]="FnOrD";
  138. case_lowers(buf);
  139. puts(buf);
  140. #endif
  141. #if 0
  142. char buf[100]="foo bar baz";
  143. printf("%d (expect 7)\n",byte_rchr(buf,11,' '));
  144. #endif
  145. #if 0
  146. unsigned long size;
  147. char* buf=mmap_read(argv[1],&size);
  148. if (buf) {
  149. unsigned int x=fmt_yenc(0,buf,size);
  150. unsigned int y;
  151. char* tmp=malloc(x+1);
  152. y=fmt_yenc(tmp,buf,size);
  153. write(1,tmp,x);
  154. }
  155. #endif
  156. #if 0
  157. char buf[100];
  158. char buf2[100];
  159. unsigned int len,len2;
  160. buf[fmt_yenc(buf,"http://localhost/~fefe",22)]=0;
  161. buffer_puts(buffer_1,buf);
  162. buffer_putsflush(buffer_1,"\n");
  163. if ((buf[len2=scan_yenc(buf,buf2,&len)])!='\n') {
  164. buffer_putsflush(buffer_2,"parse error!\n");
  165. return 1;
  166. }
  167. buffer_put(buffer_1,buf2,len2);
  168. buffer_putsflush(buffer_1,"\n");
  169. return 0;
  170. #endif
  171. #if 0
  172. char buf[100];
  173. char buf2[100];
  174. unsigned int len,len2;
  175. buf[fmt_base64(buf,"foo:bar",7)]=0;
  176. buffer_puts(buffer_1,buf);
  177. buffer_putsflush(buffer_1,"\n");
  178. if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) {
  179. buffer_putsflush(buffer_2,"parse error!\n");
  180. return 1;
  181. }
  182. buffer_put(buffer_1,buf2,len2);
  183. buffer_putsflush(buffer_1,"\n");
  184. return 0;
  185. #endif
  186. #if 0
  187. unsigned long size;
  188. char* buf=mmap_read(argv[1],&size);
  189. if (buf) {
  190. unsigned int x=fmt_uuencoded(0,buf,size);
  191. unsigned int y;
  192. char* tmp=malloc(x+1);
  193. y=fmt_uuencoded(tmp,buf,size);
  194. write(1,tmp,x);
  195. }
  196. #endif
  197. #if 0
  198. char buf[]="00000000000000000000000000000001";
  199. char ip[16];
  200. if (scan_ip6_flat(buf,ip) != str_len(buf))
  201. buffer_putsflush(buffer_2,"parse error!\n");
  202. #endif
  203. #if 0
  204. int fd=open_read("t.c");
  205. buffer b;
  206. char buf[1024];
  207. char line[20];
  208. int i;
  209. buffer_init(&b,read,fd,buf,1024);
  210. i=buffer_getline(&b,line,19);
  211. buffer_puts(buffer_1,"getline returned ");
  212. buffer_putulong(buffer_1,i);
  213. buffer_puts(buffer_1,"\n");
  214. buffer_puts(buffer_1,line);
  215. buffer_flush(buffer_1);
  216. #endif
  217. #if 0
  218. buffer_putulong(buffer_1,23);
  219. // buffer_putspace(buffer_1);
  220. buffer_putsflush(buffer_1,"\n");
  221. // buffer_flush(buffer_1);
  222. #endif
  223. #if 0
  224. long a,b,c;
  225. char buf[4096];
  226. char buf2[4096];
  227. memcpy(buf,buf2,4096);
  228. byte_copy(buf,4096,buf2);
  229. rdtscl(a);
  230. memcpy(buf,buf2,4096);
  231. rdtscl(b);
  232. byte_copy(buf,4096,buf2);
  233. rdtscl(c);
  234. printf("memcpy: %d - byte_copy: %d\n",b-a,c-b);
  235. #endif
  236. #if 0
  237. char ip[16];
  238. int i;
  239. if ((i=scan_ip6(argv[1],ip))) {
  240. char buf[128];
  241. buf[fmt_ip6(buf,ip)]=0;
  242. puts(buf);
  243. }
  244. #endif
  245. #if 0
  246. char buf[100];
  247. strcpy(buf,"foobarbaz");
  248. buf[fmt_fill(buf,3,5,100)]=0;
  249. printf("\"%s\"\n",buf);
  250. #endif
  251. #if 0
  252. unsigned long len;
  253. char *c=mmap_read("/etc/passwd",&len);
  254. printf("got map %p of len %lu\n",c,len);
  255. #endif
  256. #if 0
  257. char c;
  258. printf("%d\n",buffer_getc(buffer_0,&c));
  259. printf("%c\n",c);
  260. #endif
  261. #if 0
  262. char buf[100]="01234567890123456789012345678901234567890123456789";
  263. long a,b,c;
  264. #endif
  265. #if 0
  266. buf[ip4_fmt(buf,ip4loopback)]=0;
  267. buffer_puts(buffer_1small,buf);
  268. buffer_flush(buffer_1small);
  269. #endif
  270. #if 0
  271. buf[0]=0;
  272. buf[fmt_8long(buf,0)]=0;
  273. puts(buf);
  274. rdtscl(a);
  275. c=str_len(buf);
  276. rdtscl(b);
  277. /*byte_zero_djb(buf,j); */
  278. // printf("\n%lu %d\n",b-a,c);
  279. #endif
  280. #if 0
  281. buffer_puts(buffer_1small,"hello, world\n");
  282. buffer_flush(buffer_1small);
  283. #endif
  284. #if 0
  285. int s=socket_tcp4();
  286. char ip[4]={127,0,0,1};
  287. int t=socket_connect4(s,ip,80);
  288. #endif
  289. #if 0
  290. char buf[100]="foo bar baz fnord ";
  291. char buf2[100]="foo braz fnord";
  292. long a,b,c;
  293. long i=0,j=0,k=0;
  294. double d;
  295. uint32 l,m,n;
  296. stralloc sa={0};
  297. stralloc_copys(&sa,"fnord");
  298. stralloc_catlong0(&sa,-23,5);
  299. stralloc_append(&sa,"\n");
  300. printf("%d %d\n",str_equal("fnord","fnord1"),str_equal("fnord1","fnord"));
  301. write(1,sa.s,sa.len);
  302. printf("%d %d\n",stralloc_starts(&sa,"fnord"),stralloc_starts(&sa,"fnord\na"));
  303. l=0xdeadbeef;
  304. uint32_pack_big((char*)&m,l);
  305. uint32_unpack_big((char*)&m,&n);
  306. printf("%x %x %x\n",l,m,n);
  307. rdtscl(a);
  308. /* i=scan_double("3.1415",&d); */
  309. rdtscl(b);
  310. /*byte_zero_djb(buf,j); */
  311. rdtscl(c);
  312. printf("%lu %lu\n",b-a,c-b);
  313. #endif
  314. #if 0
  315. unsigned long size;
  316. char* buf=mmap_read(argv[1],&size);
  317. if (buf) {
  318. unsigned int x=fmt_urlencoded2(0,buf,size,"x");
  319. unsigned int y;
  320. char* tmp=malloc(x+1);
  321. y=fmt_urlencoded2(tmp,buf,size,"x");
  322. write(1,tmp,x);
  323. }
  324. #endif
  325. printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar"));
  326. printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar"));
  327. return 0;
  328. }