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.
 
 
 
 

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