Back to index

courier  0.68.2
Functions
comerrmsg.c File Reference
#include "courier.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Functions

char * makeerrmsgtext (int errnum, const char *errtext)

Function Documentation

char* makeerrmsgtext ( int  errnum,
const char *  errtext 
)

Definition at line 22 of file comerrmsg.c.

{
char   errnumbuf[4];
int    i;
const char *p;
char   *buf, *q, *r;
int    lastchar;

       if (!errtext || !*errtext)  errtext="Failed.";

       errnumbuf[3]=0;
       for (i=2; i >= 0; --i)
       {
              errnumbuf[i]= (errnum % 10)+'0';
              errnum /= 10;
       }

       /*
       ** Calculate size of buffer we'll need.  For each line, we
       ** add four bytes for the error number.
       ** One line errors may need \n appended.
       */

       i=6+strlen(errtext);
              /*
              ** First line's toll, plus optional trailing \r\n,
              ** and null byte.
              */

       for (p=errtext; *p; p++)
              if (*p == '\n')      i += 4;

       if ((buf=malloc(i)) == 0)   clog_msg_errno();
       for (q=r=buf, p=errtext; *p; )
       {
              r=q;
              strcpy(q, errnumbuf);
              q += 3;
              *q++ = '-';

              if (isdigit((int)(unsigned char)p[0]) &&
                     isdigit((int)(unsigned char)p[1]) &&
                     isdigit((int)(unsigned char)p[2]) &&
                     (p[3] == '-' || p[3] == ' '))
                     p += 4;       /* Remove old error message number */

              while (*p)
              {
                     lastchar=*q++ = *p++;

                     if (lastchar != '\n' && *p == '\0')
                     {
                            *q++='\n';
                     }
                     if (lastchar == '\n')       break;
              }
       }
       r[3]=' ';
       *q=0;
       return (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function: