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.
 
 
 
 

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