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.
 
 
 
 

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