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.
 
 
 
 

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