cleaned up formatting in libcext, liblitz

This commit is contained in:
Anthony Martin 2006-03-23 02:34:00 -08:00
parent 9e6e5f389e
commit 8dc468316b
9 changed files with 119 additions and 119 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 */
}

View File

@ -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 */
}

View File

@ -19,45 +19,45 @@
#include <limits.h>
#include <stdlib.h>
#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);
}

View File

@ -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 */
}

View File

@ -6,9 +6,9 @@
#include <X11/Xlib.h>
#include <cext.h>
#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;

View File

@ -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);