コード例 #1
0
ファイル: commands.c プロジェクト: denishpatel/pg_top
char *
err_string()

{
	register struct errs *errp;
	register int cnt = 0;
	register int first = Yes;
	register int currerr = -1;
	int			stringlen;		/* characters still available in "string" */
	static char string[STRMAX];

	/* if there are no errors, return NULL */
	if (errcnt == 0)
	{
		return (NULL);
	}

	/* sort the errors */
	qsort((char *) errs, errcnt, sizeof(struct errs), err_compar);

	/* need a space at the front of the error string */
	string[0] = ' ';
	string[1] = '\0';
	stringlen = STRMAX - 2;

	/* loop thru the sorted list, building an error string */
	while (cnt < errcnt)
	{
		errp = &(errs[cnt++]);
		if (errp->errnum != currerr)
		{
			if (currerr != -1)
			{
				if ((stringlen = str_adderr(string, stringlen, currerr)) < 2)
				{
					return (err_listem);
				}
				(void) strcat(string, "; ");	/* we know there's more */
			}
			currerr = errp->errnum;
			first = Yes;
		}
		if ((stringlen = str_addarg(string, stringlen, errp->arg, first)) == 0)
		{
			return (err_listem);
		}
		first = No;
	}

	/* add final message */
	stringlen = str_adderr(string, stringlen, currerr);

	/* return the error string */
	return (stringlen == 0 ? err_listem : string);
}
コード例 #2
0
static void
err_string(void)

{
    register struct errs *errp;
    register int  cnt = 0;
    register int  first = Yes;
    register int  currerr = -1;
    int stringlen = 0;		/* characters still available in "string" */
    char string[STRMAX];

    /* if there are no errors, our job is easy */
    if (errcnt == 0)
    {
	return;
    }

    /* sort the errors */
    qsort((char *)errs, errcnt, sizeof(struct errs), err_compar);

    /* initialize the buffer (probably not necessary) */
    string[0] = '\0';
    stringlen = STRMAX - 1;

    /* loop thru the sorted list, logging errors */
    while (cnt < errcnt)
    {
	/* point to the current error */
	errp = &(errs[cnt++]);

	/* note that on overflow "stringlen" will become 0 and all
	   subsequent calls to str_addarg or str_adderr will return 0 */

	/* if the error number is different then add the error string */
	if (errp->errnum != currerr)
	{
	    if (currerr != -1)
	    {
		/* add error string and log the error */
		stringlen = str_adderr(string, stringlen, currerr);
		message_error(" %s", string);

	    }
	    /* reset the buffer */
	    string[0] = '\0';
	    stringlen = STRMAX - 1;

	    /* move to next error num */
	    currerr = errp->errnum;
	    first = Yes;
	}

	/* add this arg */
	stringlen = str_addarg(string, stringlen, errp->arg, first);
	first = No;
    }

    /* add final message */
    stringlen = str_adderr(string, stringlen, currerr);

    /* write the error string */
    message_error(" %s", string);
}