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.
 
 
 
 

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