add base64 scanner
This commit is contained in:
parent
4f3f4ea52f
commit
4d0eca89fc
32
t.c
32
t.c
@ -17,30 +17,18 @@
|
|||||||
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
||||||
|
|
||||||
int main(int argc,char* argv[]) {
|
int main(int argc,char* argv[]) {
|
||||||
unsigned long size;
|
char buf[100];
|
||||||
char* buf=mmap_read(argv[1],&size);
|
char buf2[100];
|
||||||
if (buf) {
|
unsigned int len,len2;
|
||||||
const char* c=buf;
|
buf[fmt_base64(buf,"foo:bar",7)]=0;
|
||||||
const char* max=buf+size;
|
buffer_puts(buffer_1,buf);
|
||||||
while (c<max) {
|
buffer_putsflush(buffer_1,"\n");
|
||||||
char tmp[100];
|
if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) {
|
||||||
unsigned int scanned;
|
|
||||||
unsigned int x=scan_uuencoded(c,tmp,&scanned);
|
|
||||||
if (!x) {
|
|
||||||
if (!strncmp(c,"end\n",4))
|
|
||||||
return 0;
|
|
||||||
else {
|
|
||||||
parseerror:
|
|
||||||
buffer_putsflush(buffer_2,"parse error!\n");
|
buffer_putsflush(buffer_2,"parse error!\n");
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
write(1,tmp,scanned);
|
|
||||||
c+=x;
|
|
||||||
if (*c!='\n') goto parseerror;
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
buffer_put(buffer_1,buf2,len2);
|
||||||
|
buffer_putsflush(buffer_1,"\n");
|
||||||
return 0;
|
return 0;
|
||||||
#if 0
|
#if 0
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
#include "textcode.h"
|
#include "textcode.h"
|
||||||
#include "haveinline.h"
|
#include "haveinline.h"
|
||||||
|
|
||||||
static inline unsigned int enc(unsigned char x) {
|
|
||||||
return ((x-1)&077)+'!';
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int fmt_base64(char* dest,const char* src,unsigned int len) {
|
unsigned int fmt_base64(char* dest,const char* src,unsigned int len) {
|
||||||
register const unsigned char* s=(const unsigned char*) src;
|
register const unsigned char* s=(const unsigned char*) src;
|
||||||
unsigned short bits=0,temp=0;
|
unsigned short bits=0,temp=0;
|
||||||
|
34
textcode/scan_base64.c
Normal file
34
textcode/scan_base64.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "textcode.h"
|
||||||
|
#include "haveinline.h"
|
||||||
|
|
||||||
|
static inline int dec(unsigned char x) {
|
||||||
|
if (x>='A' && x<='Z') return x-'A';
|
||||||
|
if (x>='a' && x<='z') return x-'a'+26;
|
||||||
|
if (x>='0' && x<='9') return x-'0'+26+26;
|
||||||
|
switch (x) {
|
||||||
|
case '+': return 62;
|
||||||
|
case '/': return 63;
|
||||||
|
default: return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int scan_base64(const char *src,char *dest,unsigned int *destlen) {
|
||||||
|
unsigned short tmp=0,bits=0;
|
||||||
|
register const unsigned char* s=(const unsigned char*) src;
|
||||||
|
const char* orig=dest;
|
||||||
|
for (;;) {
|
||||||
|
int a=dec(*s);
|
||||||
|
if (a<0) {
|
||||||
|
while (*s=='=') ++s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tmp=(tmp<<6)|a; bits+=6;
|
||||||
|
++s;
|
||||||
|
if (bits>=8) {
|
||||||
|
*dest=(tmp>>(bits-=8));
|
||||||
|
++dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*destlen=dest-orig;
|
||||||
|
return (const char*)s-src;
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
#include "textcode.h"
|
#include "textcode.h"
|
||||||
#include "haveinline.h"
|
|
||||||
|
|
||||||
unsigned int scan_uuencoded(const char *src,char *dest,unsigned int *destlen) {
|
unsigned int scan_uuencoded(const char *src,char *dest,unsigned int *destlen) {
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user