version 1.6, 2002/07/15 17:20:36 |
version 1.7, 2003/04/06 20:39:20 |
|
|
static char *next_field(char *); |
static char *next_field(char *); |
static int scanint(char *, int *); |
static int scanint(char *, int *); |
static char *err_string(void); |
static char *err_string(void); |
static int str_adderr(char *, int, int); |
static size_t str_adderr(char *, size_t, int); |
static int str_addarg(char *, int, char *, int); |
static size_t str_addarg(char *, size_t, char *, int); |
static int err_compar(const void *, const void *); |
static int err_compar(const void *, const void *); |
|
|
/* |
/* |
|
|
int cnt = 0; |
int cnt = 0; |
int first = Yes; |
int first = Yes; |
int currerr = -1; |
int currerr = -1; |
int stringlen; /* characters still available in "string" */ |
|
static char string[STRMAX]; |
static char string[STRMAX]; |
|
|
/* if there are no errors, return NULL */ |
/* if there are no errors, return NULL */ |
|
|
/* need a space at the front of the error string */ |
/* need a space at the front of the error string */ |
string[0] = ' '; |
string[0] = ' '; |
string[1] = '\0'; |
string[1] = '\0'; |
stringlen = STRMAX - 2; |
|
|
|
/* loop thru the sorted list, building an error string */ |
/* loop thru the sorted list, building an error string */ |
while (cnt < errcnt) |
while (cnt < errcnt) |
|
|
{ |
{ |
if (currerr != -1) |
if (currerr != -1) |
{ |
{ |
if ((stringlen = str_adderr(string, stringlen, currerr)) < 2) |
if (str_adderr(string, sizeof string, currerr) > |
|
(sizeof string - 2)) |
{ |
{ |
return(err_listem); |
return(err_listem); |
} |
} |
|
|
currerr = errp->errno; |
currerr = errp->errno; |
first = Yes; |
first = Yes; |
} |
} |
if ((stringlen = str_addarg(string, stringlen, errp->arg, first)) ==0) |
if (str_addarg(string, sizeof string, errp->arg, first) >= |
|
sizeof string) |
{ |
{ |
return(err_listem); |
return(err_listem); |
} |
} |
|
|
} |
} |
|
|
/* add final message */ |
/* add final message */ |
stringlen = str_adderr(string, stringlen, currerr); |
if (str_adderr(string, sizeof string, currerr) >= sizeof string) |
|
return(err_listem); |
|
|
/* return the error string */ |
/* return the error string */ |
return(stringlen == 0 ? err_listem : string); |
return(string); |
} |
} |
|
|
/* |
/* |
|
|
* the string "str". |
* the string "str". |
*/ |
*/ |
|
|
static int str_adderr(str, len, err) |
static size_t str_adderr(str, len, err) |
|
|
char *str; |
char *str; |
int len; |
size_t len; |
int err; |
int err; |
|
|
{ |
{ |
char *msg; |
char *msg; |
int msglen; |
size_t msglen; |
|
|
msg = err == 0 ? "Not a number" : strerror(err); |
msg = err == 0 ? "Not a number" : strerror(err); |
msglen = strlen(msg) + 2; |
if ((msglen = strlcat(str, ": ", len)) >= len) |
if (len <= msglen) |
return(msglen); |
{ |
return(strlcat(str, msg, len)); |
return(0); |
|
} |
|
(void) strcat(str, ": "); |
|
(void) strcat(str, msg); |
|
return(len - msglen); |
|
} |
} |
|
|
/* |
/* |
|
|
* is set (indicating that a comma should NOT be added to the front). |
* is set (indicating that a comma should NOT be added to the front). |
*/ |
*/ |
|
|
static int str_addarg(str, len, arg, first) |
static size_t str_addarg(str, len, arg, first) |
|
|
char *str; |
char *str; |
int len; |
size_t len; |
char *arg; |
char *arg; |
int first; |
int first; |
|
|
{ |
{ |
int arglen; |
size_t msglen; |
|
|
arglen = strlen(arg); |
|
if (!first) |
if (!first) |
{ |
{ |
arglen += 2; |
if ((msglen = strlcat(str, ", ", len)) >= len) |
|
return(msglen); |
} |
} |
if (len <= arglen) |
return(strlcat(str, arg, len)); |
{ |
|
return(0); |
|
} |
|
if (!first) |
|
{ |
|
(void) strcat(str, ", "); |
|
} |
|
(void) strcat(str, arg); |
|
return(len - arglen); |
|
} |
} |
|
|
/* |
/* |