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.
 
 
 
 

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