~ubuntu-branches/ubuntu/oneiric/valkyrie/oneiric

« back to all changes in this revision

Viewing changes to valkyrie/options/vk_popt.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-09-02 22:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110902220834-kigsixteppj9epp5
Tags: 2.0.0-0ubuntu1
* New upstream release. (LP: #635129, LP: #832886, LP: #721298)
* Standards bumped to 3.9.2, no changes required.
* d/control, d/rules: cdbs removed, dh minimal rule instead.
* d/control: build system is qmake not autotools
* d/control: bump required qt to qt4
* d/valkyrie.install: installing html docs manually as make install
  no longer does so.
* d/patches/valkyrie-2.0.0-fix-doc.dir.patch: Fix doc path to match
  policy. Also corrects LP: #588074 since the documentation link now
  works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* --------------------------------------------------------------------- 
2
 
 * Definition of Popt functions                                vk_popt.h
3
 
 * This is a seriously hacked version of the popt libraries.
4
 
 * No credit to me, all thanks and many apologies to the Red Hat team
5
 
 * ---------------------------------------------------------------------
6
 
 * popt is Copyright (C) 1998 Red Hat Software and distributed under
7
 
 * an X11-style license, which is in turn compatible the GNU GPL v.2.
8
 
 * See the file COPYING for the full license details.
9
 
*/
10
 
 
11
 
#ifndef __VK_POPT_H
12
 
#define __VK_POPT_H
13
 
 
14
 
#include <ctype.h>
15
 
#include <stdlib.h>
16
 
#include <string.h>
17
 
#include <stdio.h>
18
 
#include <vk_option.h>
19
 
 
20
 
#define OPTION_DEPTH  10
21
 
 
22
 
/* options can't follow args */
23
 
#define PCONTEXT_POSIXMEHARDER (1 << 2)
24
 
 
25
 
/* vkPoptOption can be: table of options | option | TABLE_END
26
 
   TABLE_END: none set of: shortFlag && longFlag && arg
27
 
   table:  arg = array of options, helptxt = table title
28
 
   option: arg = NULL
29
 
*/
30
 
typedef struct _vkPoptOption {
31
 
   int  optKey;                /* eg. VIEW-LOG                    */
32
 
   VkOPTION::ArgType argType;  /* option type: ARG_***            */
33
 
   char shortFlag;             /* '\0' || 'h'                     */
34
 
   const char* longFlag;       /* NULL || --help                  */
35
 
   struct _vkPoptOption* arg;  /* table holds ptr to  */
36
 
   const char* helptxt;        /* help text                       */
37
 
   const char* helpdesc;       /* eg. <file>                      */
38
 
   int objectId;               /* used to call obj->checkOptArg() */
39
 
} vkPoptOption;
40
 
 
41
 
#define TABLE_END { -1, VkOPTION::NOT_POPT, '\0', NULL, NULL, NULL, NULL, -1 }
42
 
vkPoptOption nullOpt();
43
 
 
44
 
 
45
 
typedef struct vkPoptContext_s* vkPoptContext;
46
 
 
47
 
#ifdef __cplusplus
48
 
extern "C" {
49
 
#endif
50
 
 
51
 
/* initialize popt context.
52
 
   - argc    no. of arguments
53
 
   - argv    argument array
54
 
   - options address of popt option table
55
 
   - returns initialized popt context */
56
 
vkPoptContext vkPoptGetContext( int argc, const char ** argv,
57
 
                                const vkPoptOption * options );
58
 
 
59
 
/* get next option opt_ret
60
 
   returns 1 on success, -1 on last item, PERROR_* on error */
61
 
int vkPoptGetNextOpt( vkPoptContext con, char *arg_val,
62
 
                      const vkPoptOption** opt/*OUT*/ );
63
 
 
64
 
/* return current option's argument, 
65
 
   or NULL if no more options are available */
66
 
const char * vkPoptGetArg( vkPoptContext con );
67
 
 
68
 
/* return remaining argument array, terminated with NULL */
69
 
const char ** vkPoptGetArgs( vkPoptContext con );
70
 
 
71
 
/* peek at current option's argument */
72
 
const char * vkPoptPeekArg( vkPoptContext con );
73
 
 
74
 
/* return the offending option which caused the most recent error */
75
 
const char * vkPoptBadOption( vkPoptContext con );
76
 
 
77
 
/* destroy context. return NULL always */
78
 
vkPoptContext vkPoptFreeContext( vkPoptContext con );
79
 
 
80
 
/* print detailed description of options.
81
 
   fp == ouput file handle */
82
 
void vkPoptPrintHelp( vkPoptContext con, FILE * fp,
83
 
                      const char * tableName );
84
 
 
85
 
#ifdef  __cplusplus
86
 
}
87
 
#endif
88
 
 
89
 
/*--------------------------------------------------*/
90
 
/* wrapper to free(3), hides const compilation noise,
91
 
   permit NULL, return NULL always */
92
 
static inline void * _free( const void * p )
93
 
{
94
 
   if ( p != NULL )  
95
 
      free((void *)p);
96
 
   return NULL;
97
 
}
98
 
 
99
 
 
100
 
struct optionStackEntry { 
101
 
   int argc;
102
 
   const char ** argv;
103
 
   int next;
104
 
   const char * nextArg;
105
 
   const char * nextCharArg;
106
 
};
107
 
 
108
 
 
109
 
struct vkPoptContext_s {
110
 
   struct optionStackEntry optionStack[OPTION_DEPTH];
111
 
   struct optionStackEntry * os;
112
 
   const char ** leftovers;
113
 
   int numLeftovers;
114
 
   int nextLeftover;
115
 
   const vkPoptOption * options;
116
 
   int restLeftover;
117
 
   int flags;
118
 
   const char ** finalArgv;
119
 
   int finalArgvCount;
120
 
   int finalArgvAlloced;
121
 
};
122
 
 
123
 
 
124
 
#endif