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.
 
 
 
 

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