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.
 
 
 
 

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