more textcode stuff

master
leitner 23 years ago
parent a262056a41
commit 271b380cb3

@ -0,0 +1,16 @@
#include "buffer.h"
main() {
buffer_puts(buffer_1,"ulong: ");
buffer_putulong(buffer_1,23);
buffer_puts(buffer_1,"\nlong: ");
buffer_putlong(buffer_1,-23);
buffer_puts(buffer_1,"\n8long: ");
buffer_put8long(buffer_1,23);
buffer_puts(buffer_1,"\nxlong:");
buffer_putspace(buffer_1);
buffer_putxlong(buffer_1,23);
buffer_putsflush(buffer_1,"\n");
buffer_putsalign(buffer_1,"aligned\n");
buffer_flush(buffer_1);
}

@ -0,0 +1,45 @@
#include <unistd.h>
#include "textcode.h"
#include "str.h"
#include "buffer.h"
int main(int argc,char* argv[]) {
char buf[4096];
buffer filein;
int fd=1;
if (argc>1) {
fd=open_read(argv[1]);
if (fd<0) {
buffer_puts(buffer_2,"error: could not open \"");
buffer_puts(buffer_2,argv[1]);
buffer_putsflush(buffer_2,"\"\n");
return 1;
}
}
buffer_init(&filein,read,fd,buf,sizeof buf);
/* skip to "^begin " */
for (;;) {
char line[1000]; /* uuencoded lines can never be longer than 64 characters */
int l;
if ((l=buffer_getline(&filein,line,(sizeof line)-1))==0) {
buffer_putsflush(buffer_2,"warning: hit end of file without finding any uuencoded data!\n");
return 0;
}
if (l>0 && buf[l-1]=='\r') --l; /* kill DOS line endings */
buf[l]=0;
if (!str_diffn(line,"begin ",6)) break;
}
/* read uuencoded lines */
for (;;) {
char line[1000]; /* uuencoded lines can never be longer than 64 characters */
int l;
if ((l=buffer_getline(&filein,line,(sizeof line)-1))==0) {
buffer_putsflush(buffer_2,"warning: hit end of file without finding \"end\"!\n");
return 0;
}
if (l>0 && buf[l-1]=='\r') --l; /* kill DOS line endings */
buf[l]=0;
if (!str_diffn(line,"begin ",6)) break;
}
/* TODO */
}

@ -18,4 +18,6 @@ unsigned int scan_quotedprintable(const char *src,char *dest,unsigned int *destl
unsigned int scan_urlencode(const char *src,char *dest,unsigned int *destlen);
unsigned int scan_yenc(const char *src,char *dest,unsigned int *destlen);
extern const char base64[64];
#endif

@ -0,0 +1 @@
const char base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

@ -0,0 +1,27 @@
#include "fmt.h"
#include "textcode.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) {
register const unsigned char* s=(const unsigned char*) src;
unsigned short bits=0,temp=0;
unsigned long written=0,i;
for (i=0; i<len; ++i) {
temp<<=8; temp+=s[i]; bits+=8;
while (bits>6) {
if (dest) dest[written]=base64[((temp>>(bits-6))&63)];
++written; bits-=6;
}
}
if (bits) {
temp<<=(6-bits);
if (dest) dest[written]=base64[temp&63];
++written;
}
while (written&3) { if (dest) dest[written]='='; ++written; }
return written;
}
Loading…
Cancel
Save