~ubuntu-branches/ubuntu/feisty/argtable2/feisty

« back to all changes in this revision

Viewing changes to example/argxxx.c

  • Committer: Bazaar Package Importer
  • Author(s): Shachar Shemesh
  • Date: 2006-11-14 16:13:36 UTC
  • mfrom: (2.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20061114161336-k2z40o650zfi7pjx
Tags: 6-3
* Update maintainer's email address (now a Debian Developer)
* Update the policy version to 3.7.2 (no changes required)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
argtable2 command line parser library. It shows how to make custom
4
4
arg_xxx data types with additional error checking capabilities.
5
5
 
6
 
Copyright (C) 1998,1999,2000,2001,2003,2004,2005 Stewart Heitmann
 
6
Copyright (C) 1998-2001,2003-2006 Stewart Heitmann
7
7
sheitmann@users.sourceforge.net
8
8
 
9
9
This is free software; you can redistribute it and/or
67
67
    int errorcode = 0;
68
68
    /*printf("%s:scanfn(%p,\"%s\")\n",__FILE__,parent,argval);*/
69
69
 
70
 
    /* if we havent exceeded our maximum argument count then... */
71
 
    if (parent->count < parent->hdr.maxcount )
 
70
    if (parent->count == parent->hdr.maxcount)
 
71
        {
 
72
        /* maximum number of arguments exceeded */
 
73
        errorcode = EMAXCOUNT;
 
74
        }
 
75
    else if (!argval)
 
76
        {
 
77
        /* an argument with no argument value was given. */
 
78
        /* This happens when an optional argument value was invoked. */
 
79
        /* leave parent argument value unaltered but still count the argument. */
 
80
        parent->count++;
 
81
        } 
 
82
    else 
72
83
        {
73
84
        double val;
74
85
        char *pend;
89
100
            /* failure; command line string was not a valid double */
90
101
            errorcode = EBADINT;
91
102
        }
92
 
    else
93
 
        errorcode = EMAXCOUNT;
94
103
 
95
104
    /*printf("%s:scanfn(%p) returns %d\n",__FILE__,parent,errorcode);*/
96
105
    return errorcode;
121
130
 *   struct arg_xxx *parent = ptr to the arg_xxx struct in the argtable.
122
131
 *   FILE *fp = output stream
123
132
 *   int errorcode = the error code returned by the scanfn routine
124
 
 *   const char *argval = ptr to the offending command line argv[] string   
 
133
 *   const char *argval = ptr to the offending command line argv[] string (may be NULL)   
125
134
 *   const char *progname = the same progname string passed to arg_print_errors()
126
135
 */
127
136
static void errorfn(struct arg_xxx *parent, FILE *fp, int errorcode, const char *argval, const char *progname)
130
139
    const char *longopts  = parent->hdr.longopts;
131
140
    const char *datatype  = parent->hdr.datatype;
132
141
 
 
142
    /* make argval NULL safe */
 
143
    argval = argval ? argval : "";
 
144
 
133
145
    fprintf(fp,"%s: ",progname);
134
146
    switch(errorcode)
135
147
        {