~ubuntu-branches/debian/squeeze/aptitude/squeeze

« back to all changes in this revision

Viewing changes to src/cmdline_parse.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Burrows
  • Date: 2007-03-13 20:49:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070313204958-l7040344gthwxlvj
Tags: 0.4.4-4
In addition to the bugfix for ssprintf, the last release included
a new test case to ensure that the bug did not recur.  As it turned
out, this test case revealed that both the old and the new code
were buggy on amd64!  vssnprintf now handles its variable argument
list properly, using va_copy in case it has to access the list a
second time. (Closes: #414617)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// cmdline_parse.h
 
2
//
 
3
//  Copyright 2002 Daniel Burrows
 
4
//
 
5
//  Mad?  They said I was mad.  But I didn't listen.  I didn't have to...
 
6
//
 
7
//  Behold...the living horror of the object-oriented command-line parser!
 
8
 
 
9
#ifndef CMDLINE_PARSE_H
 
10
#define CMDLINE_PARSE_H
 
11
 
 
12
#include <vector>
 
13
#include <std::string>
 
14
 
 
15
#include <sigc++/trackable.h>
 
16
 
 
17
// I'll parse arguments My Way, thank you.
 
18
//
 
19
// This provides a callback to parse the head of an input option stream.
 
20
//
 
21
// It should either:
 
22
//   (a) Consume some number of arguments and return true (if there are
 
23
//      appropriate arguments), or
 
24
//   (b) Return false.
 
25
class arg_parser:public sigc::trackable
 
26
{
 
27
public:
 
28
  virtual bool parse_arg(int argc, char *argv[], int &loc)=0;
 
29
};
 
30
 
 
31
// Caller is responsible for deleting the arg_parsers
 
32
bool parse_cmdline(std::vector<arg_parser *> parsers, int argc, char *argv[]);
 
33
 
 
34
// Factories for interesting basic arg_parsers.  These generally take either
 
35
// a slot to call or a value to set.
 
36
 
 
37
// The standard '-x', '--blah' option.  (no value)  If longopt is NULL, there
 
38
// is no long option; if shortopt is \0, same.
 
39
arg_parser *dashopt(char shortopt, char *longopt,
 
40
                    sigc::slot0<void> callback);
 
41
 
 
42
// Same, sets "flag" to true if the option is seen.
 
43
arg_parser *dashopt(char shortopt, char *longopt, bool &flag);
 
44
 
 
45
// The general callback-based version; the multiple forms allow
 
46
// implicit conversions.
 
47
arg_parser *dashopt_witharg(char shortopt, char *longopt,
 
48
                            sigc::slot1<void, std::string> callback);
 
49
arg_parser *dashopt_witharg(char shortopt, char *longopt,
 
50
                            std::string &val);
 
51
arg_parser *dashopt_witharg(char shortopt, char *longopt,
 
52
                            int &val);
 
53
 
 
54
// This one just accumulates its arguments in the given vector.
 
55
// Useful as a "default rule".
 
56
arg_parser *arg_accumulate();
 
57
 
 
58
#endif