예제 #1
0
파일: arg_file.c 프로젝트: BRAT-DEV/main
static void errorfn(struct arg_file *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    /* make argval NULL safe */
    argval = argval ? argval : "";

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            fputs("missing option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EMAXCOUNT:
            fputs("excess option ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;

        default:
            fprintf(fp,"unknown error at \"%s\"\n",argval);
        }
    }
예제 #2
0
static void errorfn(struct arg_uint *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    /* make argval NULL safe */
    argval = argval ? argval : "";

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            fputs("missing option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EMAXCOUNT:
            fputs("excess option ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;

        case EBADINT:
            fprintf(fp,"invalid argument \"%s\" to option ",argval);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EOVERFLOW:
            fputs("integer overflow at option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype," ");
            fprintf(fp,"(%s is too large)\n",argval);
            break;
        }
    }
예제 #3
0
파일: arg_lit.c 프로젝트: aegoroff/grok
static void errorfn(struct arg_lit *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    switch(errorcode)
        {
        case EMINCOUNT:
            lib_fprintf(fp,"%s: missing option ",progname);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            lib_fprintf(fp,"\n");
            break;

        case EMAXCOUNT:
            lib_fprintf(fp,"%s: extraneous option ",progname);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;
        }
    }
예제 #4
0
/* errorfn is called by arg_print_errors() for each error that was returned
 * by the scanfn defined above.
 * Parameters:
 *   struct arg_xxx *parent = ptr to the arg_xxx struct in the argtable.
 *   FILE *fp = output stream
 *   int errorcode = the error code returned by the scanfn routine
 *   const char *argval = ptr to the offending command line argv[] string (may be NULL)   
 *   const char *progname = the same progname string passed to arg_print_errors()
 */
static void errorfn(struct arg_xxx *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    /* make argval NULL safe */
    argval = argval ? argval : "";

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            /* We expected more arg_xxx arguments than we received. */
            fputs("missing option \"",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\"\n");
            break;

        case EMAXCOUNT:
            /* We received more arg_xxx arguments than we expected. */
            fputs("excess option \"",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\"\n");
            break;

        case EBADRANGE:
            /* An arg_xxx option was given a double value that   */ 
            /* exceeded our imposed [minval,maxval] range limit. */
            fprintf(fp,"value \"%s\" out of range for option ",argval);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EBADINT:
            /* An arg_xxx option was given with an invalid double value */
            fprintf(fp,"invalid argument \"%s\" to option ",argval);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;
        }
    }
예제 #5
0
파일: arg_date.c 프로젝트: mrG7/hpg-libs
static void errorfn(struct arg_date *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    /* make argval NULL safe */
    argval = argval ? argval : "";

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            fputs("missing option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EMAXCOUNT:
            fputs("excess option ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;

        case EBADDATE:
            {
            struct tm tm;
            char buff[200];           

            fprintf(fp,"illegal timestamp format \"%s\"\n",argval);
            bzero(&tm,sizeof(tm));
            strptime("1999-12-31 23:59:59","%F %H:%M:%S",&tm);
            strftime(buff, sizeof(buff), parent->format, &tm);
            printf("correct format is \"%s\"\n", buff);                        
            break;
            }
        }
    }
예제 #6
0
static void errorfn(struct arg_rex *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    /* make argval NULL safe */
    argval = argval ? argval : "";

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            fputs("missing option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EMAXCOUNT:
            fputs("excess option ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;

        case REG_NOMATCH:
            fputs("illegal value  ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;
        
        default:
            {
            char errbuff[256];
            regerror(errorcode, NULL, errbuff, sizeof(errbuff));
            printf("%s\n", errbuff);
            }
            break;
        }
    }
예제 #7
0
/* 
 * Argtable calls an arg_xxx structure's hdr.errorfn routine when arg_print_errors is executed.
 * The errorfn routine must print a meaningful error messages for the given error code.
 * The error codes are the same values returned by scanfn and checkfn.
 */
void myerrorfn(struct arg_int *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
    {
    const char *shortopts = parent->hdr.shortopts;
    const char *longopts  = parent->hdr.longopts;
    const char *datatype  = parent->hdr.datatype;

    fprintf(fp,"%s: ",progname);
    switch(errorcode)
        {
        case EMINCOUNT:
            fputs("missing option ",fp);
            arg_print_option(fp,shortopts,longopts,datatype,"\n");
            break;

        case EMAXCOUNT:
            fputs("excess option ",fp);
            arg_print_option(fp,shortopts,longopts,argval,"\n");
            break;

        case EBADINT:
            arg_print_option(fp,shortopts,longopts,argval," is not a valid <int>\n");
            break;

        case EZEROVAL:
            arg_print_option(fp,shortopts,longopts,datatype," values cannot be zero\n");
            break;

        case EODDCOUNT:
            arg_print_option(fp,shortopts,longopts,datatype," values must occur in even numbers\n");
            break;

        case EBADSUM:
            arg_print_option(fp,shortopts,longopts,datatype," values must sum to 100\n");
            break;
        }
    }