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.
 
 
 
 

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