From dc32e1a7ee7669b5dcb7b2b007fcd3606b323373 Mon Sep 17 00:00:00 2001 From: fredrik Date: Sun, 6 May 2007 18:11:27 +0000 Subject: [PATCH] Add baseconv as noinst. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@1000 959494ce-11ee-0310-bf91-de5d638817bd --- config/Makefile.am | 3 ++ config/baseconv.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 config/baseconv.c diff --git a/config/Makefile.am b/config/Makefile.am index e6586ca..17951d9 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -1,14 +1,17 @@ bin_PROGRAMS=locktouch tthsum dolconf +noinst_PROGRAMS=baseconv libexec_PROGRAMS=speedrec speedrec_SOURCES=speedrec.c locktouch_SOURCES=locktouch.c tthsum_SOURCES=tthsum.c dolconf_SOURCES=dolconf.c +baseconv_SOURCES=baseconv.c BUILT_SOURCES=dolconf-assistant.gtk dolconf-wnd.gtk AM_CPPFLAGS=-I$(top_srcdir)/include tthsum_LDADD=$(top_srcdir)/common/libcommon.a +baseconv_LDADD=$(top_srcdir)/common/libcommon.a dolconf.c: dolconf-assistant.desc dolconf-wnd.desc localedir=$(datadir)/locale diff --git a/config/baseconv.c b/config/baseconv.c new file mode 100644 index 0000000..360daad --- /dev/null +++ b/config/baseconv.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#include "utils.h" + +int main(int argc, char **argv) +{ + char buf[25]; + int ret, linelen; + char *decbuf, *encbuf; + size_t data, buflen; + char *(*decfn)(char *, size_t *); + char *(*encfn)(char *, size_t); + + data = 0; + if(!strcmp(argv[1], "4")) { + decfn = hexdecode; + } else if(!strcmp(argv[1], "5")) { + decfn = base32decode; + } else if(!strcmp(argv[1], "6")) { + decfn = base64decode; + } else if(!strcmp(argv[1], "8")) { + decfn = NULL; + } else { + fprintf(stderr, "unknown decoding: %s\n", argv[1]); + exit(1); + } + if(!strcmp(argv[2], "4")) { + encfn = hexencode; + } else if(!strcmp(argv[2], "5")) { + encfn = base32encode; + } else if(!strcmp(argv[2], "6")) { + encfn = base64encode; + } else if(!strcmp(argv[2], "8")) { + encfn = NULL; + } else { + fprintf(stderr, "unknown encoding: %s\n", argv[1]); + exit(1); + } + linelen = 0; + while((ret = read(0, buf + data, 24 - data)) >= 0) { + if(((data += ret) == 24) || (ret == 0)) { + if(decfn == NULL) { + decbuf = memcpy(smalloc(data), buf, data); + buflen = data; + } else { + buf[data] = 0; + if((decbuf = decfn(buf, &buflen)) == NULL) { + fprintf(stderr, "invalid input\n"); + exit(1); + } + } + if(encfn == NULL) { + encbuf = memcpy(smalloc(buflen), decbuf, buflen); + fwrite(encbuf, 1, buflen, stdout); + } else { + encbuf = encfn(decbuf, buflen); + buflen = strlen(encbuf); + if(linelen + buflen > 60) { + fwrite(encbuf, 1, 60 - linelen, stdout); + fwrite("\n", 1, 1, stdout); + buflen -= 60 - linelen; + } + fwrite(encbuf, 1, buflen, stdout); + linelen += buflen; + } + fflush(stdout); + free(encbuf); + free(decbuf); + data = 0; + } + if(ret == 0) + break; + } + if(ret < 0) { + perror("read"); + exit(1); + } + return(0); +} -- 2.11.0