From 8dc468316bf852cc77a5c0828b81b8c4f9ef71f7 Mon Sep 17 00:00:00 2001 From: Anthony Martin Date: Thu, 23 Mar 2006 02:34:00 -0800 Subject: [PATCH] cleaned up formatting in libcext, liblitz --- libcext/cext.h | 2 +- libcext/emallocz.c | 14 +++++----- libcext/estrdup.c | 8 +++--- libcext/strlcat.c | 40 ++++++++++++++-------------- libcext/strlcpy.c | 34 ++++++++++++------------ libcext/strtonum.c | 66 +++++++++++++++++++++++----------------------- libcext/tokenize.c | 40 ++++++++++++++-------------- liblitz/blitz.h | 10 +++---- liblitz/draw.c | 24 ++++++++--------- 9 files changed, 119 insertions(+), 119 deletions(-) diff --git a/libcext/cext.h b/libcext/cext.h index 1d21f6cd..c9588f64 100644 --- a/libcext/cext.h +++ b/libcext/cext.h @@ -27,7 +27,7 @@ unsigned int cext_strlcpy(char *dst, const char *src, unsigned int siz); /* strtonum.c */ long long cext_strtonum(const char *numstr, long long minval, - long long maxval, const char **errstrp); + long long maxval, const char **errstrp); /* tokenize.c */ unsigned int cext_tokenize(char **result, unsigned int reslen, char *str, char delim); diff --git a/libcext/emallocz.c b/libcext/emallocz.c index 88418402..076e6d5c 100644 --- a/libcext/emallocz.c +++ b/libcext/emallocz.c @@ -11,12 +11,12 @@ void * cext_emallocz(unsigned int size) { - void *res = calloc(1, size); + void *res = calloc(1, size); - if(!res) { - fprintf(stderr, "fatal: could not malloc() %d bytes\n", - (int) size); - exit(1); - } - return res; + if(!res) { + fprintf(stderr, "fatal: could not malloc() %d bytes\n", + (int) size); + exit(1); + } + return res; } diff --git a/libcext/estrdup.c b/libcext/estrdup.c index 25470c2c..bfddd04e 100644 --- a/libcext/estrdup.c +++ b/libcext/estrdup.c @@ -12,10 +12,10 @@ char * cext_estrdup(const char *s) { - char *tmp; + char *tmp; - tmp = (char *) cext_emallocz(strlen(s) + 1); - strcpy(tmp, (char *) s); + tmp = (char *) cext_emallocz(strlen(s) + 1); + strcpy(tmp, (char *) s); - return tmp; + return tmp; } diff --git a/libcext/strlcat.c b/libcext/strlcat.c index 31dab7a2..ef2ce993 100644 --- a/libcext/strlcat.c +++ b/libcext/strlcat.c @@ -29,27 +29,27 @@ unsigned int cext_strlcat(char *dst, const char *src, unsigned int siz) { - register char *d = dst; - register const char *s = src; - register unsigned int n = siz; - unsigned int dlen; + register char *d = dst; + register const char *s = src; + register unsigned int n = siz; + unsigned int dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while(n-- != 0 && *d != 0) - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end */ + while(n-- != 0 && *d != 0) + d++; + dlen = d - dst; + n = siz - dlen; - if(n == 0) - return (dlen + strlen(s)); - while(*s != 0) { - if(n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = 0; + if(n == 0) + return (dlen + strlen(s)); + while(*s != 0) { + if(n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = 0; - return (dlen + (s - src)); /* count does not include NUL */ + return (dlen + (s - src)); /* count does not include NUL */ } diff --git a/libcext/strlcpy.c b/libcext/strlcpy.c index 67f1f33e..df049d72 100644 --- a/libcext/strlcpy.c +++ b/libcext/strlcpy.c @@ -26,22 +26,22 @@ unsigned int cext_strlcpy(char *dst, const char *src, unsigned int siz) { - register char *d = dst; - register const char *s = src; - register unsigned int n = siz; + register char *d = dst; + register const char *s = src; + register unsigned int n = siz; - /* Copy as many bytes as will fit */ - if(n != 0 && --n != 0) { - do { - if((*d++ = *s++) == 0) - break; - } while(--n != 0); - } - /* Not enough room in dst, add NUL and traverse rest of src */ - if(n == 0) { - if(siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while(*s++); - } - return (s - src - 1); /* count does not include NUL */ + /* Copy as many bytes as will fit */ + if(n != 0 && --n != 0) { + do { + if((*d++ = *s++) == 0) + break; + } while(--n != 0); + } + /* Not enough room in dst, add NUL and traverse rest of src */ + if(n == 0) { + if(siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while(*s++); + } + return (s - src - 1); /* count does not include NUL */ } diff --git a/libcext/strtonum.c b/libcext/strtonum.c index 37933aa1..ba01e506 100644 --- a/libcext/strtonum.c +++ b/libcext/strtonum.c @@ -19,45 +19,45 @@ #include #include -#define INVALID 1 +#define INVALID 1 #define TOOSMALL 2 #define TOOLARGE 3 long long cext_strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) + const char **errstrp) { - long long ll = 0; - char *ep; - int error = 0; - struct errval { - const char *errstr; - int err; - } ev[4] = { - { - NULL, 0}, { - "invalid", EINVAL}, { - "too small", ERANGE}, { - "too large", ERANGE},}; + long long ll = 0; + char *ep; + int error = 0; + struct errval { + const char *errstr; + int err; + } ev[4] = { + {NULL, 0}, + {"invalid", EINVAL}, + {"too small", ERANGE}, + {"too large", ERANGE}, + }; - ev[0].err = errno; - errno = 0; - if(minval > maxval) - error = INVALID; - else { - ll = strtoll(numstr, &ep, 10); - if(numstr == ep || *ep != 0) - error = INVALID; - else if(errno == ERANGE || ll < minval) - error = TOOSMALL; - else if(errno == ERANGE || ll > maxval) - error = TOOLARGE; - } - if(errstrp != NULL) - *errstrp = ev[error].errstr; - errno = ev[error].err; - if(error) - ll = 0; + ev[0].err = errno; + errno = 0; + if(minval > maxval) + error = INVALID; + else { + ll = strtoll(numstr, &ep, 10); + if(numstr == ep || *ep != 0) + error = INVALID; + else if(errno == ERANGE || ll < minval) + error = TOOSMALL; + else if(errno == ERANGE || ll > maxval) + error = TOOLARGE; + } + if(errstrp != NULL) + *errstrp = ev[error].errstr; + errno = ev[error].err; + if(error) + ll = 0; - return (ll); + return (ll); } diff --git a/libcext/tokenize.c b/libcext/tokenize.c index d4c35fa7..9075cdd9 100644 --- a/libcext/tokenize.c +++ b/libcext/tokenize.c @@ -10,25 +10,25 @@ unsigned int cext_tokenize(char **result, unsigned int reslen, char *str, char delim) { - char *p, *n; - unsigned int i = 0; + char *p, *n; + unsigned int i = 0; - if(!str) - return 0; - for(n = str; *n == ' '; n++); - p = n; - for(i = 0; *n != 0;) { - if(i == reslen) - return i; - if(*n == delim) { - *n = 0; - if(strlen(p)) - result[i++] = p; - p = ++n; - } else - n++; - } - if((i < reslen) && (p < n) && strlen(p)) - result[i++] = p; - return i; /* number of tokens */ + if(!str) + return 0; + for(n = str; *n == ' '; n++); + p = n; + for(i = 0; *n != 0;) { + if(i == reslen) + return i; + if(*n == delim) { + *n = 0; + if(strlen(p)) + result[i++] = p; + p = ++n; + } else + n++; + } + if((i < reslen) && (p < n) && strlen(p)) + result[i++] = p; + return i; /* number of tokens */ } diff --git a/liblitz/blitz.h b/liblitz/blitz.h index 4fc8a02c..59877bb3 100644 --- a/liblitz/blitz.h +++ b/liblitz/blitz.h @@ -6,9 +6,9 @@ #include #include -#define BLITZ_FONT "fixed" -#define BLITZ_SELCOLORS "#ffffff #285577 #4c7899" -#define BLITZ_NORMCOLORS "#222222 #eeeeee #666666" +#define BLITZ_FONT "fixed" +#define BLITZ_SELCOLORS "#ffffff #285577 #4c7899" +#define BLITZ_NORMCOLORS "#222222 #eeeeee #666666" typedef enum { CENTER, WEST, NWEST, NORTH, NEAST, EAST, @@ -27,8 +27,8 @@ typedef struct { GC gc; Color color; XFontStruct *font; - XRectangle rect; /* relative rect */ - XRectangle *notch; /* relative notch rect */ + XRectangle rect; /* relative rect */ + XRectangle *notch; /* relative notch rect */ char *data; } Draw; diff --git a/liblitz/draw.c b/liblitz/draw.c index 7a94011a..5e373df6 100644 --- a/liblitz/draw.c +++ b/liblitz/draw.c @@ -39,9 +39,9 @@ blitz_loadcolor(Display *dpy, int mon, char *colstr, Color *c) { if(!colstr || strlen(colstr) != 23) return -1; - c->fg = xloadcolor(dpy, mon, &colstr[0]); - c->bg = xloadcolor(dpy, mon, &colstr[8]); - c->border = xloadcolor(dpy, mon, &colstr[16]); + c->fg = xloadcolor(dpy, mon, &colstr[0]); + c->bg = xloadcolor(dpy, mon, &colstr[8]); + c->border = xloadcolor(dpy, mon, &colstr[16]); return 0; } @@ -126,15 +126,15 @@ xdrawtext(Display *dpy, Draw *d) text[len - 1] = '.'; } switch (d->align) { - case EAST: - x = d->rect.x + d->rect.width - (h / 2 + w); - break; - case CENTER: - x = d->rect.x + (d->rect.width - w) / 2; - break; - default: - x = d->rect.x + h / 2; - break; + case EAST: + x = d->rect.x + d->rect.width - (h / 2 + w); + break; + case CENTER: + x = d->rect.x + (d->rect.width - w) / 2; + break; + default: + x = d->rect.x + h / 2; + break; } XSetBackground(dpy, d->gc, d->color.bg); XSetForeground(dpy, d->gc, d->color.fg);