~ubuntu-branches/ubuntu/oneiric/popt/oneiric

« back to all changes in this revision

Viewing changes to popt.3

  • Committer: Bazaar Package Importer
  • Author(s): Paul Martin
  • Date: 2010-05-13 05:14:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100513051450-1qefp4e2if4hbkri
Tags: 1.16-1
* New upstream release (Closes: #581439)
* Switch to dpkg-source 3.0 (quilt) format
* Add a watch file.
* Update to standards version 3.8.4 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
POPT_ARG_NONE   No argument expected    int
127
127
POPT_ARG_STRING No type checking to be performed        char *
128
128
POPT_ARG_ARGV   No type checking to be performed        char **
 
129
POPT_ARG_SHORT  An short argument is expected   short
129
130
POPT_ARG_INT    An integer argument is expected int
130
131
POPT_ARG_LONG   A long integer is expected      long
131
132
POPT_ARG_LONGLONG       A long long integer is expected long long
164
165
an argument, the variable that 
165
166
.IR arg " points to is updated to reflect the value of the argument." 
166
167
.RB "Any string is acceptable for " POPT_ARG_STRING " and " POPT_ARG_ARGV " arguments, but "
167
 
.BR POPT_ARG_INT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", " POPT_ARG_FLOAT ", and "
 
168
.BR POPT_ARG_INT ", " POPT_ARG_SHORT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", " POPT_ARG_FLOAT ", and "
168
169
.BR POPT_ARG_DOUBLE " are converted to the appropriate type, and an "
169
170
error returned if the conversion fails.
170
171
.sp
199
200
.RB "This macro includes another option table (via " POPT_ARG_INCLUDE_TABLE
200
201
; see below) in the main one which provides the table entries for these
201
202
.RB "arguments. When " --usage " or " --help " are passed to programs which
202
 
use popt's automatical help, popt displays the appropriate message on 
 
203
use popt's automatic help, popt displays the appropriate message on 
203
204
stderr as soon as it finds the option, and exits the program with a
204
205
return code of 0. If you want to use popt's automatic help generation in
205
206
a different way, you need to explicitly add the option entries to your programs 
209
210
the argument will not be shown in help output.
210
211
.sp
211
212
If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_SHOW_DEFAULT\fR,
212
 
the inital value of the arg will be shown in help output.
 
213
the initial value of the arg will be shown in help output.
213
214
.sp
214
215
The final structure in the table should have all the pointer values set
215
216
.RB "to " NULL " and all the arithmetic values set to 0, marking the "
232
233
contain a overall description of the option table being included.
233
234
.sp
234
235
The other special option table entry type tells popt to call a function (a
235
 
callback) when any option in that table is found. This is especially usefull
 
236
callback) when any option in that table is found. This is especially useful
236
237
when included option tables are being used, as the program which provides
237
238
the top-level option table doesn't need to be aware of the other options
238
239
which are provided by the included table. When a callback is set for
474
475
A conversion from a string to a number (int or long) failed due
475
476
to the string containing nonnumeric characters. This occurs when
476
477
.BR poptGetNextOpt() " is processing an argument of type " 
477
 
.BR POPT_ARG_INT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", "
 
478
.BR POPT_ARG_INT ", " POPT_ARG_SHORT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", "
478
479
.RB POPT_ARG_FLOAT ", or " POPT_ARG_DOUBLE "."  
479
480
.sp
480
481
.TP
482
483
A string-to-number conversion failed because the number was too
483
484
.RB "large or too small. Like " POPT_ERROR_BADNUMBER ", this error 
484
485
.RB "can occur only when " poptGetNextOpt() " is processing an "
485
 
.RB "argument of type " POPT_ARG_INT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", "
 
486
.RB "argument of type " POPT_ARG_INT ", " POPT_ARG_SHORT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", "
486
487
.RB POPT_ARG_FLOAT ", or " POPT_ARG_DOUBLE "."  
487
488
.sp
488
489
.TP
516
517
applications. When an error is detected from most of the functions, 
517
518
an error message is printed along with the error string from 
518
519
.BR poptStrerror() ". When an error occurs during argument parsing, "
519
 
code similiar to the following displays a useful error message:
 
520
code similar to the following displays a useful error message:
520
521
.sp
521
522
.nf
522
523
fprintf(stderr, "%s: %s\\n",
607
608
.RI "an " argv "-style array, some programs need to parse strings that "
608
609
are formatted identically to command lines. To facilitate this, popt 
609
610
provides a function that parses a string into an array of strings, 
610
 
using rules similiar to normal shell parsing.
 
611
using rules similar to normal shell parsing.
611
612
.sp
612
613
.nf
613
614
.B "#include <popt.h>"
656
657
.nf
657
658
#include <popt.h>
658
659
#include <stdio.h>
 
660
#include <stdlib.h>
659
661
 
660
662
void usage(poptContext optCon, int exitcode, char *error, char *addl) {
661
663
    poptPrintUsage(optCon, stderr, 0);
662
 
    if (error) fprintf(stderr, "%s: %s\n", error, addl);
 
664
    if (error) fprintf(stderr, "%s: %s\\n", error, addl);
663
665
    exit(exitcode);
664
666
}
665
667
 
666
668
int main(int argc, char *argv[]) {
667
 
   char    c;            /* used for argument parsing */
 
669
   int     c;            /* used for argument parsing */
668
670
   int     i = 0;        /* used for tracking options */
669
 
   char    *portname;
670
671
   int     speed = 0;    /* used in argument parsing to set speed */
671
672
   int     raw = 0;      /* raw mode? */ 
672
673
   int     j;
673
674
   char    buf[BUFSIZ+1];
 
675
   const char *portname;
674
676
   poptContext optCon;   /* context for parsing command-line options */
675
677
 
676
678
   struct poptOption optionsTable[] = {