From: fredrik Date: Wed, 11 Apr 2007 02:43:20 +0000 (+0000) Subject: Make libdcui build against the same utils as the rest of the tree. X-Git-Tag: 0.3~58 X-Git-Url: http://git.dolda2000.com/gitweb/?p=doldaconnect.git;a=commitdiff_plain;h=31c700d16bc6161783befe07b6df5495577177f4 Make libdcui build against the same utils as the rest of the tree. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@879 959494ce-11ee-0310-bf91-de5d638817bd --- diff --git a/include/doldaconnect/Makefile.am b/include/doldaconnect/Makefile.am index 68c985e..f08b1cf 100644 --- a/include/doldaconnect/Makefile.am +++ b/include/doldaconnect/Makefile.am @@ -1 +1,8 @@ -pkginclude_HEADERS=uilib.h uimisc.h utils.h +# utils.h is copied from the parent directory, to ensure that in-tree +# built programs include the same path as out-of-tree programs. +BUILT_SOURCES = utils.h + +utils.h: ../utils.h + cp -f ../utils.h . + +pkginclude_HEADERS=uilib.h uimisc.h diff --git a/include/doldaconnect/utils.h b/include/doldaconnect/utils.h deleted file mode 100644 index 60e06ad..0000000 --- a/include/doldaconnect/utils.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _UTILS_H -#define _UTILS_H - -#include -#include - -/* "Safe" functions */ -#define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;}) -#define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;}) -#define swcsdup(wcs) ((wchar_t *)wcscpy(smalloc(sizeof(wchar_t) * (wcslen(wcs) + 1)), (wcs))) -#define sstrdup(str) ((char *)strcpy(smalloc(strlen(str) + 1), (str))) - -char *vsprintf2(char *format, va_list al); -char *sprintf2(char *format, ...); -wchar_t *vswprintf2(wchar_t *format, va_list al); -wchar_t *swprintf2(wchar_t *format, ...); -wchar_t *icmbstowcs(char *mbs, char *charset); -wchar_t *icsmbstowcs(char *mbs, char *charset, wchar_t *def); -char *icwcstombs(wchar_t *wcs, char *charset); -char *icswcstombs(wchar_t *wcs, char *charset, char *def); -wchar_t *wcstolower(wchar_t *wcs); -void _sizebuf(void **buf, size_t *bufsize, size_t reqsize, size_t elsize, int algo); - -#define sizebuf(b, bs, rs, es, a) _sizebuf((void **)(b), (bs), (rs), (es), (a)) -#define sizebuf2(b, rs, a) _sizebuf((void **)(&(b)), &(b ## size), (rs), sizeof(*(b)), (a)) -#define addtobuf(b, c) \ -do { \ - _sizebuf((void **)(&(b)), &(b ## size), (b ## data) + 1, sizeof(*(b)), 1); \ - (b)[(b ## data)++] = (c); \ -} while(0) -#define bufcat(d, s, n) \ -do { \ - size_t __bufcat_size__; \ - __bufcat_size__ = (n); \ - _sizebuf((void **)(&(d)), &(d ## size), (d ## data) + __bufcat_size__, sizeof(*(d)), 1); \ - memcpy((d) + (d ## data), (s), sizeof(*(d)) * __bufcat_size__); \ - (d ## data) += __bufcat_size__; \ -} while (0) - -#endif diff --git a/lib/Makefile.am b/lib/Makefile.am index 0c2b137..f003e5a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -5,8 +5,8 @@ DIST_SUBDIRS=guile lib_LTLIBRARIES = libdcui.la -libdcui_la_SOURCES = uilib.c uimisc.c utils.c -libdcui_la_LIBADD = @KRB5_LDADD@ +libdcui_la_SOURCES = uilib.c uimisc.c +libdcui_la_LIBADD = @KRB5_LDADD@ $(top_srcdir)/common/libcommon.a libdcui_la_LDFLAGS = -version-info 1:0:1 BUILT_SOURCES = initcmds.h diff --git a/lib/uilib.c b/lib/uilib.c index 2bd9575..c67410e 100644 --- a/lib/uilib.c +++ b/lib/uilib.c @@ -47,7 +47,7 @@ #endif #include -#include +#include #define RESP_END -1 #define RESP_DSC 0 diff --git a/lib/uimisc.c b/lib/uimisc.c index 4232453..249f8f8 100644 --- a/lib/uimisc.c +++ b/lib/uimisc.c @@ -34,7 +34,7 @@ #endif #include #include -#include +#include #ifdef HAVE_KRB5 #include @@ -205,77 +205,6 @@ struct krb5data int valid, fwd, fwded; }; -static char *hexencode(char *data, size_t datalen) -{ - char *buf, this; - size_t bufsize, bufdata; - int dig; - - buf = NULL; - bufsize = bufdata = 0; - for(; datalen > 0; datalen--, data++) - { - dig = (*data & 0xF0) >> 4; - if(dig > 9) - this = 'A' + dig - 10; - else - this = dig + '0'; - addtobuf(buf, this); - dig = *data & 0x0F; - if(dig > 9) - this = 'A' + dig - 10; - else - this = dig + '0'; - addtobuf(buf, this); - } - addtobuf(buf, 0); - return(buf); -} - -static char *hexdecode(char *data, size_t *len) -{ - char *buf, this; - size_t bufsize, bufdata; - - buf = NULL; - bufsize = bufdata = 0; - for(; *data; data++) - { - if((*data >= 'A') && (*data <= 'F')) - { - this = (this & 0x0F) | ((*data - 'A' + 10) << 4); - } else if((*data >= '0') && (*data <= '9')) { - this = (this & 0x0F) | ((*data - '0') << 4); - } else { - if(buf != NULL) - free(buf); - return(NULL); - } - data++; - if(!*data) - { - if(buf != NULL) - free(buf); - return(NULL); - } - if((*data >= 'A') && (*data <= 'F')) - { - this = (this & 0xF0) | (*data - 'A' + 10); - } else if((*data >= '0') && (*data <= '9')) { - this = (this & 0xF0) | (*data - '0'); - } else { - if(buf != NULL) - free(buf); - return(NULL); - } - addtobuf(buf, this); - } - addtobuf(buf, 0); - if(len != NULL) - *len = bufdata - 1; - return(buf); -} - static void process_krb5(struct dc_response *resp, struct logindata *data) { int ret; diff --git a/lib/utils.c b/lib/utils.c deleted file mode 100644 index e203a56..0000000 --- a/lib/utils.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include -#endif -#include - -extern int vswprintf (wchar_t *__restrict __s, size_t __n, - __const wchar_t *__restrict __format, - __gnuc_va_list __arg); - -char *vsprintf2(char *format, va_list al) -{ - int ret; - char *buf; - - ret = vsnprintf(NULL, 0, format, al); - if((buf = malloc(ret + 1)) == NULL) - { - return(NULL); - } - vsnprintf(buf, ret + 1, format, al); - return(buf); -} - -char *sprintf2(char *format, ...) -{ - va_list args; - char *buf; - - va_start(args, format); - buf = vsprintf2(format, args); - va_end(args); - return(buf); -} - -wchar_t *vswprintf2(wchar_t *format, va_list al) -{ - int ret; - wchar_t *buf; - size_t bufsize; - - buf = smalloc(sizeof(wchar_t) * (bufsize = 1024)); - while((ret = vswprintf(buf, bufsize, format, al)) < 0) - buf = srealloc(buf, sizeof(wchar_t) * (bufsize *= 2)); - if(bufsize > ret + 1) - buf = srealloc(buf, sizeof(wchar_t) * (ret + 1)); - return(buf); -} - -wchar_t *swprintf2(wchar_t *format, ...) -{ - va_list args; - wchar_t *buf; - - va_start(args, format); - buf = vswprintf2(format, args); - va_end(args); - return(buf); -} - -wchar_t *icmbstowcs(char *mbs, char *charset) -{ - int ret; - char *buf; - char *p, *p2; - size_t len1, len2, bufsize, data; - iconv_t cd; - - len1 = strlen(mbs) + 1; - bufsize = len2 = len1 * sizeof(wchar_t); - if((buf = malloc(bufsize)) == NULL) - { - return(NULL); - } - if(charset == NULL) - charset = nl_langinfo(CODESET); - if((cd = iconv_open("wchar_t", charset)) == (iconv_t)-1) - { - free(buf); - return(NULL); - } - p = buf; - while(len1 > 0) - { - ret = iconv(cd, &mbs, &len1, &p, &len2); - if(ret < 0) - { - if(errno == E2BIG) - { - data = p - buf; - len2 += 128; - bufsize += 128; - if((p2 = realloc(buf, bufsize)) == NULL) - { - free(buf); - return(NULL); - } - buf = p2; - p = buf + data; - } else { - free(buf); - return(NULL); - } - } - } - if(len2 > 0) - buf = realloc(buf, p - buf); - iconv_close(cd); - return((wchar_t *)buf); -} - -wchar_t *icsmbstowcs(char *mbs, char *charset, wchar_t *def) -{ - static wchar_t *buf = NULL; - - if(buf != NULL) - free(buf); - if((buf = icmbstowcs(mbs, charset)) == NULL) - return(def); - return(buf); -} - -char *icwcstombs(wchar_t *wcs, char *charset) -{ - int ret; - char *buf; - char *p, *p2; - size_t len1, len2, bufsize, data; - iconv_t cd; - - len1 = sizeof(wchar_t) * (wcslen(wcs) + 1); - bufsize = len2 = len1; - if((buf = malloc(bufsize)) == NULL) - { - return(NULL); - } - if(charset == NULL) - charset = nl_langinfo(CODESET); - if((cd = iconv_open(charset, "wchar_t")) == (iconv_t)-1) - { - free(buf); - return(NULL); - } - p = buf; - while(len1 > 0) - { - ret = iconv(cd, (char **)&wcs, &len1, &p, &len2); - if(ret < 0) - { - if(errno == E2BIG) - { - data = p - buf; - len2 += 128; - bufsize += 128; - if((p2 = realloc(buf, bufsize)) == NULL) - { - free(buf); - return(NULL); - } - buf = p2; - p = buf + data; - } else { - free(buf); - return(NULL); - } - } - } - if(len2 > 0) - buf = realloc(buf, p - buf); - iconv_close(cd); - return(buf); -} - -char *icswcstombs(wchar_t *wcs, char *charset, char *def) -{ - static char *buf = NULL; - - if(buf != NULL) - free(buf); - if((buf = icwcstombs(wcs, charset)) == NULL) - return(def); - return(buf); -} - -wchar_t *wcstolower(wchar_t *wcs) -{ - wchar_t *p; - - for(p = wcs; *p != L'\0'; p++) - *p = towlower(*p); - return(wcs); -} - -void _sizebuf(void **buf, size_t *bufsize, size_t reqsize, size_t elsize, int algo) -{ - if(*bufsize >= reqsize) - return; - switch(algo) - { - case 0: - *buf = srealloc(*buf, elsize * ((*bufsize) = reqsize)); - break; - case 1: - if(*bufsize == 0) - *bufsize = 1; - while(*bufsize < reqsize) - *bufsize *= 2; - *buf = srealloc(*buf, elsize * (*bufsize)); - break; - } -}