mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 01:56:53 +08:00
Cleanup & indent .h files
This commit is contained in:
@@ -31,45 +31,67 @@ extern "C" {
|
|||||||
#include "trex.h"
|
#include "trex.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TRexParseException{TRexParseException(const TRexChar *c):desc(c){}const TRexChar *desc;};
|
struct TRexParseException
|
||||||
|
{
|
||||||
|
TRexParseException(const TRexChar *c):desc(c) {} const TRexChar *desc;
|
||||||
|
};
|
||||||
|
|
||||||
class TRexpp {
|
class TRexpp
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
TRexpp() { _exp = (TRex *)0; }
|
TRexpp()
|
||||||
~TRexpp() { CleanUp(); }
|
{
|
||||||
|
_exp = (TRex *)0;
|
||||||
|
}
|
||||||
|
~TRexpp()
|
||||||
|
{
|
||||||
|
CleanUp();
|
||||||
|
}
|
||||||
// compiles a regular expression
|
// compiles a regular expression
|
||||||
void Compile(const TRexChar *pattern) {
|
void Compile(const TRexChar *pattern)
|
||||||
|
{
|
||||||
const TRexChar *error;
|
const TRexChar *error;
|
||||||
CleanUp();
|
CleanUp();
|
||||||
if(!(_exp = trex_compile(pattern,&error)))
|
if(!(_exp = trex_compile(pattern,&error)))
|
||||||
throw TRexParseException(error);
|
throw TRexParseException(error);
|
||||||
}
|
}
|
||||||
// return true if the given text match the expression
|
// return true if the given text match the expression
|
||||||
bool Match(const TRexChar* text) {
|
bool Match(const TRexChar* text)
|
||||||
|
{
|
||||||
return _exp?(trex_match(_exp,text) != 0):false;
|
return _exp?(trex_match(_exp,text) != 0):false;
|
||||||
}
|
}
|
||||||
// Searches for the first match of the expression in a zero terminated string
|
// Searches for the first match of the expression in a zero terminated string
|
||||||
bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end) {
|
bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end)
|
||||||
|
{
|
||||||
return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false;
|
return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false;
|
||||||
}
|
}
|
||||||
// Searches for the first match of the expression in a string sarting at text_begin and ending at text_end
|
// Searches for the first match of the expression in a string sarting at text_begin and ending at text_end
|
||||||
bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end) {
|
bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end)
|
||||||
|
{
|
||||||
return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false;
|
return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false;
|
||||||
}
|
}
|
||||||
bool GetSubExp(int n, const TRexChar** out_begin, int *out_len)
|
bool GetSubExp(int n, const TRexChar** out_begin, int *out_len)
|
||||||
{
|
{
|
||||||
TRexMatch match;
|
TRexMatch match;
|
||||||
TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False;
|
TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False;
|
||||||
if(res) {
|
if(res)
|
||||||
|
{
|
||||||
*out_begin = match.begin;
|
*out_begin = match.begin;
|
||||||
*out_len = match.len;
|
*out_len = match.len;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int GetSubExpCount() { return _exp?trex_getsubexpcount(_exp):0; }
|
int GetSubExpCount()
|
||||||
|
{
|
||||||
|
return _exp?trex_getsubexpcount(_exp):0;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void CleanUp() { if(_exp) trex_free(_exp); _exp = (TRex *)0; }
|
void CleanUp()
|
||||||
|
{
|
||||||
|
if(_exp) trex_free(_exp);
|
||||||
|
_exp = (TRex *)0;
|
||||||
|
}
|
||||||
TRex *_exp;
|
TRex *_exp;
|
||||||
};
|
};
|
||||||
#endif //_TREXPP_H_
|
#endif //_TREXPP_H_
|
||||||
|
@@ -24,8 +24,7 @@
|
|||||||
#define cJSON__h
|
#define cJSON__h
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* cJSON Types: */
|
/* cJSON Types: */
|
||||||
@@ -40,7 +39,8 @@ extern "C"
|
|||||||
#define cJSON_IsReference 256
|
#define cJSON_IsReference 256
|
||||||
|
|
||||||
/* The cJSON structure: */
|
/* The cJSON structure: */
|
||||||
typedef struct cJSON {
|
typedef struct cJSON
|
||||||
|
{
|
||||||
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||||
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||||
|
|
||||||
@@ -53,7 +53,8 @@ typedef struct cJSON {
|
|||||||
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||||
} cJSON;
|
} cJSON;
|
||||||
|
|
||||||
typedef struct cJSON_Hooks {
|
typedef struct cJSON_Hooks
|
||||||
|
{
|
||||||
void *(*malloc_fn)(size_t sz);
|
void *(*malloc_fn)(size_t sz);
|
||||||
void (*free_fn)(void *ptr);
|
void (*free_fn)(void *ptr);
|
||||||
} cJSON_Hooks;
|
} cJSON_Hooks;
|
||||||
|
@@ -38,7 +38,8 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct RecognitionResult {
|
struct RecognitionResult
|
||||||
|
{
|
||||||
bool haswinner;
|
bool haswinner;
|
||||||
string winner;
|
string winner;
|
||||||
int confidence;
|
int confidence;
|
||||||
|
@@ -99,14 +99,16 @@ typedef unsigned char Boolean; /* 0 or 1 */
|
|||||||
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
||||||
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
conversionOK, /* conversion successful */
|
conversionOK, /* conversion successful */
|
||||||
sourceExhausted, /* partial character in source, but hit end */
|
sourceExhausted, /* partial character in source, but hit end */
|
||||||
targetExhausted, /* insuff. room in target for conversion */
|
targetExhausted, /* insuff. room in target for conversion */
|
||||||
sourceIllegal /* source sequence is illegal/malformed */
|
sourceIllegal /* source sequence is illegal/malformed */
|
||||||
} ConversionResult;
|
} ConversionResult;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
strictConversion = 0,
|
strictConversion = 0,
|
||||||
lenientConversion
|
lenientConversion
|
||||||
} ConversionFlags;
|
} ConversionFlags;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -126,7 +126,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
|||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialise dir */
|
/* initialise dir */
|
||||||
dir->_files = NULL;
|
dir->_files = NULL;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -135,7 +134,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
|||||||
dir->_d = NULL;
|
dir->_d = NULL;
|
||||||
#endif
|
#endif
|
||||||
tinydir_close(dir);
|
tinydir_close(dir);
|
||||||
|
|
||||||
strcpy(dir->path, path);
|
strcpy(dir->path, path);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
strcat(dir->path, "\\*");
|
strcat(dir->path, "\\*");
|
||||||
@@ -150,7 +148,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read first file */
|
/* read first file */
|
||||||
dir->has_next = 1;
|
dir->has_next = 1;
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
@@ -160,9 +157,7 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
|||||||
dir->has_next = 0;
|
dir->has_next = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
tinydir_close(dir);
|
tinydir_close(dir);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -175,7 +170,6 @@ int tinydir_open_sorted(tinydir_dir *dir, const char *path)
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir->n_files = 0;
|
dir->n_files = 0;
|
||||||
while (dir->has_next)
|
while (dir->has_next)
|
||||||
{
|
{
|
||||||
@@ -187,23 +181,18 @@ int tinydir_open_sorted(tinydir_dir *dir, const char *path)
|
|||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_file = &dir->_files[dir->n_files - 1];
|
p_file = &dir->_files[dir->n_files - 1];
|
||||||
if (tinydir_readfile(dir, p_file) == -1)
|
if (tinydir_readfile(dir, p_file) == -1)
|
||||||
{
|
{
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tinydir_next(dir) == -1)
|
if (tinydir_next(dir) == -1)
|
||||||
{
|
{
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp);
|
qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
tinydir_close(dir);
|
tinydir_close(dir);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -216,7 +205,6 @@ void tinydir_close(tinydir_dir *dir)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(dir->path, 0, sizeof(dir->path));
|
memset(dir->path, 0, sizeof(dir->path));
|
||||||
dir->has_next = 0;
|
dir->has_next = 0;
|
||||||
dir->n_files = -1;
|
dir->n_files = -1;
|
||||||
@@ -254,7 +242,6 @@ int tinydir_next(tinydir_dir *dir)
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (FindNextFile(dir->_h, &dir->_f) == 0)
|
if (FindNextFile(dir->_h, &dir->_f) == 0)
|
||||||
#else
|
#else
|
||||||
@@ -273,7 +260,6 @@ int tinydir_next(tinydir_dir *dir)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +305,6 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
|||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(file->path, dir->path);
|
strcpy(file->path, dir->path);
|
||||||
strcat(file->path, "/");
|
strcat(file->path, "/");
|
||||||
strcpy(file->name,
|
strcpy(file->name,
|
||||||
@@ -360,7 +345,6 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
|||||||
#else
|
#else
|
||||||
S_ISREG(file->_s.st_mode);
|
S_ISREG(file->_s.st_mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,9 +361,7 @@ int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, int i)
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
|
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,14 +379,12 @@ int tinydir_open_subdir_n(tinydir_dir *dir, int i)
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(path, dir->_files[i].path);
|
strcpy(path, dir->_files[i].path);
|
||||||
tinydir_close(dir);
|
tinydir_close(dir);
|
||||||
if (tinydir_open_sorted(dir, path) == -1)
|
if (tinydir_open_sorted(dir, path) == -1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -219,7 +219,8 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
/* Wide-character version */
|
/* Wide-character version */
|
||||||
struct _wdirent {
|
struct _wdirent
|
||||||
|
{
|
||||||
long d_ino; /* Always zero */
|
long d_ino; /* Always zero */
|
||||||
unsigned short d_reclen; /* Structure size */
|
unsigned short d_reclen; /* Structure size */
|
||||||
size_t d_namlen; /* Length of name without \0 */
|
size_t d_namlen; /* Length of name without \0 */
|
||||||
@@ -228,7 +229,8 @@ struct _wdirent {
|
|||||||
};
|
};
|
||||||
typedef struct _wdirent _wdirent;
|
typedef struct _wdirent _wdirent;
|
||||||
|
|
||||||
struct _WDIR {
|
struct _WDIR
|
||||||
|
{
|
||||||
struct _wdirent ent; /* Current directory entry */
|
struct _wdirent ent; /* Current directory entry */
|
||||||
WIN32_FIND_DATAW data; /* Private file data */
|
WIN32_FIND_DATAW data; /* Private file data */
|
||||||
int cached; /* True if data is valid */
|
int cached; /* True if data is valid */
|
||||||
@@ -253,7 +255,8 @@ static void _wrewinddir (_WDIR* dirp);
|
|||||||
|
|
||||||
|
|
||||||
/* Multi-byte character versions */
|
/* Multi-byte character versions */
|
||||||
struct dirent {
|
struct dirent
|
||||||
|
{
|
||||||
long d_ino; /* Always zero */
|
long d_ino; /* Always zero */
|
||||||
unsigned short d_reclen; /* Structure size */
|
unsigned short d_reclen; /* Structure size */
|
||||||
size_t d_namlen; /* Length of name without \0 */
|
size_t d_namlen; /* Length of name without \0 */
|
||||||
@@ -262,7 +265,8 @@ struct dirent {
|
|||||||
};
|
};
|
||||||
typedef struct dirent dirent;
|
typedef struct dirent dirent;
|
||||||
|
|
||||||
struct DIR {
|
struct DIR
|
||||||
|
{
|
||||||
struct dirent ent;
|
struct dirent ent;
|
||||||
struct _WDIR *wdirp;
|
struct _WDIR *wdirp;
|
||||||
};
|
};
|
||||||
@@ -305,50 +309,49 @@ _wopendir(
|
|||||||
{
|
{
|
||||||
_WDIR *dirp = NULL;
|
_WDIR *dirp = NULL;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
/* Must have directory name */
|
/* Must have directory name */
|
||||||
if (dirname == NULL || dirname[0] == '\0') {
|
if (dirname == NULL || dirname[0] == '\0')
|
||||||
|
{
|
||||||
dirent_set_errno (ENOENT);
|
dirent_set_errno (ENOENT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate new _WDIR structure */
|
/* Allocate new _WDIR structure */
|
||||||
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
|
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
|
||||||
if (dirp != NULL) {
|
if (dirp != NULL)
|
||||||
|
{
|
||||||
DWORD n;
|
DWORD n;
|
||||||
|
|
||||||
/* Reset _WDIR structure */
|
/* Reset _WDIR structure */
|
||||||
dirp->handle = INVALID_HANDLE_VALUE;
|
dirp->handle = INVALID_HANDLE_VALUE;
|
||||||
dirp->patt = NULL;
|
dirp->patt = NULL;
|
||||||
dirp->cached = 0;
|
dirp->cached = 0;
|
||||||
|
|
||||||
/* Compute the length of full path plus zero terminator */
|
/* Compute the length of full path plus zero terminator */
|
||||||
n = GetFullPathNameW (dirname, 0, NULL, NULL);
|
n = GetFullPathNameW (dirname, 0, NULL, NULL);
|
||||||
|
|
||||||
/* Allocate room for absolute directory name and search pattern */
|
/* Allocate room for absolute directory name and search pattern */
|
||||||
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
|
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
|
||||||
if (dirp->patt) {
|
if (dirp->patt)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Convert relative directory name to an absolute one. This
|
* Convert relative directory name to an absolute one. This
|
||||||
* allows rewinddir() to function correctly even when current
|
* allows rewinddir() to function correctly even when current
|
||||||
* working directory is changed between opendir() and rewinddir().
|
* working directory is changed between opendir() and rewinddir().
|
||||||
*/
|
*/
|
||||||
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
|
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
|
||||||
if (n > 0) {
|
if (n > 0)
|
||||||
|
{
|
||||||
wchar_t *p;
|
wchar_t *p;
|
||||||
|
|
||||||
/* Append search pattern \* to the directory name */
|
/* Append search pattern \* to the directory name */
|
||||||
p = dirp->patt + n;
|
p = dirp->patt + n;
|
||||||
if (dirp->patt < p) {
|
if (dirp->patt < p)
|
||||||
switch (p[-1]) {
|
{
|
||||||
|
switch (p[-1])
|
||||||
|
{
|
||||||
case '\\':
|
case '\\':
|
||||||
case '/':
|
case '/':
|
||||||
case ':':
|
case ':':
|
||||||
/* Directory ends in path separator, e.g. c:\temp\ */
|
/* Directory ends in path separator, e.g. c:\temp\ */
|
||||||
/*NOP*/;
|
/*NOP*/
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Directory name doesn't end in path separator */
|
/* Directory name doesn't end in path separator */
|
||||||
*p++ = '\\';
|
*p++ = '\\';
|
||||||
@@ -356,39 +359,43 @@ _wopendir(
|
|||||||
}
|
}
|
||||||
*p++ = '*';
|
*p++ = '*';
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
/* Open directory stream and retrieve the first entry */
|
/* Open directory stream and retrieve the first entry */
|
||||||
if (dirent_first (dirp)) {
|
if (dirent_first (dirp))
|
||||||
|
{
|
||||||
/* Directory stream opened successfully */
|
/* Directory stream opened successfully */
|
||||||
error = 0;
|
error = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Cannot retrieve first entry */
|
/* Cannot retrieve first entry */
|
||||||
error = 1;
|
error = 1;
|
||||||
dirent_set_errno (ENOENT);
|
dirent_set_errno (ENOENT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Cannot retrieve full path name */
|
/* Cannot retrieve full path name */
|
||||||
dirent_set_errno (ENOENT);
|
dirent_set_errno (ENOENT);
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Cannot allocate memory for search pattern */
|
/* Cannot allocate memory for search pattern */
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Cannot allocate _WDIR structure */
|
/* Cannot allocate _WDIR structure */
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up in case of error */
|
/* Clean up in case of error */
|
||||||
if (error && dirp) {
|
if (error && dirp)
|
||||||
|
{
|
||||||
_wclosedir (dirp);
|
_wclosedir (dirp);
|
||||||
dirp = NULL;
|
dirp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirp;
|
return dirp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,47 +414,48 @@ _wreaddir(
|
|||||||
|
|
||||||
/* Read next directory entry */
|
/* Read next directory entry */
|
||||||
datap = dirent_next (dirp);
|
datap = dirent_next (dirp);
|
||||||
if (datap) {
|
if (datap)
|
||||||
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
DWORD attr;
|
DWORD attr;
|
||||||
|
|
||||||
/* Pointer to directory entry to return */
|
/* Pointer to directory entry to return */
|
||||||
entp = &dirp->ent;
|
entp = &dirp->ent;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy file name as wide-character string. If the file name is too
|
* Copy file name as wide-character string. If the file name is too
|
||||||
* long to fit in to the destination buffer, then truncate file name
|
* long to fit in to the destination buffer, then truncate file name
|
||||||
* to PATH_MAX characters and zero-terminate the buffer.
|
* to PATH_MAX characters and zero-terminate the buffer.
|
||||||
*/
|
*/
|
||||||
n = 0;
|
n = 0;
|
||||||
while (n < PATH_MAX && datap->cFileName[n] != 0) {
|
while (n < PATH_MAX && datap->cFileName[n] != 0)
|
||||||
|
{
|
||||||
entp->d_name[n] = datap->cFileName[n];
|
entp->d_name[n] = datap->cFileName[n];
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
dirp->ent.d_name[n] = 0;
|
dirp->ent.d_name[n] = 0;
|
||||||
|
|
||||||
/* Length of file name excluding zero terminator */
|
/* Length of file name excluding zero terminator */
|
||||||
entp->d_namlen = n;
|
entp->d_namlen = n;
|
||||||
|
|
||||||
/* File type */
|
/* File type */
|
||||||
attr = datap->dwFileAttributes;
|
attr = datap->dwFileAttributes;
|
||||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
|
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
|
||||||
|
{
|
||||||
entp->d_type = DT_CHR;
|
entp->d_type = DT_CHR;
|
||||||
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
}
|
||||||
|
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||||
|
{
|
||||||
entp->d_type = DT_DIR;
|
entp->d_type = DT_DIR;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
entp->d_type = DT_REG;
|
entp->d_type = DT_REG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset dummy fields */
|
/* Reset dummy fields */
|
||||||
entp->d_ino = 0;
|
entp->d_ino = 0;
|
||||||
entp->d_reclen = sizeof (struct _wdirent);
|
entp->d_reclen = sizeof (struct _wdirent);
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Last directory entry read */
|
/* Last directory entry read */
|
||||||
entp = NULL;
|
entp = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return entp;
|
return entp;
|
||||||
@@ -463,25 +471,26 @@ _wclosedir(
|
|||||||
_WDIR *dirp)
|
_WDIR *dirp)
|
||||||
{
|
{
|
||||||
int ok;
|
int ok;
|
||||||
if (dirp) {
|
if (dirp)
|
||||||
|
{
|
||||||
/* Release search handle */
|
/* Release search handle */
|
||||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
FindClose (dirp->handle);
|
FindClose (dirp->handle);
|
||||||
dirp->handle = INVALID_HANDLE_VALUE;
|
dirp->handle = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release search pattern */
|
/* Release search pattern */
|
||||||
if (dirp->patt) {
|
if (dirp->patt)
|
||||||
|
{
|
||||||
free (dirp->patt);
|
free (dirp->patt);
|
||||||
dirp->patt = NULL;
|
dirp->patt = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release directory structure */
|
/* Release directory structure */
|
||||||
free (dirp);
|
free (dirp);
|
||||||
ok = /*success*/0;
|
ok = /*success*/0;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Invalid directory stream */
|
/* Invalid directory stream */
|
||||||
dirent_set_errno (EBADF);
|
dirent_set_errno (EBADF);
|
||||||
ok = /*failure*/-1;
|
ok = /*failure*/-1;
|
||||||
@@ -497,12 +506,13 @@ static void
|
|||||||
_wrewinddir(
|
_wrewinddir(
|
||||||
_WDIR* dirp)
|
_WDIR* dirp)
|
||||||
{
|
{
|
||||||
if (dirp) {
|
if (dirp)
|
||||||
|
{
|
||||||
/* Release existing search handle */
|
/* Release existing search handle */
|
||||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
FindClose (dirp->handle);
|
FindClose (dirp->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open new search handle */
|
/* Open new search handle */
|
||||||
dirent_first (dirp);
|
dirent_first (dirp);
|
||||||
}
|
}
|
||||||
@@ -514,21 +524,19 @@ dirent_first(
|
|||||||
_WDIR *dirp)
|
_WDIR *dirp)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATAW *datap;
|
WIN32_FIND_DATAW *datap;
|
||||||
|
|
||||||
/* Open directory and retrieve the first entry */
|
/* Open directory and retrieve the first entry */
|
||||||
dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
|
dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
|
||||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
/* a directory entry is now waiting in memory */
|
/* a directory entry is now waiting in memory */
|
||||||
datap = &dirp->data;
|
datap = &dirp->data;
|
||||||
dirp->cached = 1;
|
dirp->cached = 1;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Failed to re-open directory: no directory entry in memory */
|
/* Failed to re-open directory: no directory entry in memory */
|
||||||
dirp->cached = 0;
|
dirp->cached = 0;
|
||||||
datap = NULL;
|
datap = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
return datap;
|
return datap;
|
||||||
}
|
}
|
||||||
@@ -539,34 +547,34 @@ dirent_next(
|
|||||||
_WDIR *dirp)
|
_WDIR *dirp)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATAW *p;
|
WIN32_FIND_DATAW *p;
|
||||||
|
|
||||||
/* Get next directory entry */
|
/* Get next directory entry */
|
||||||
if (dirp->cached != 0) {
|
if (dirp->cached != 0)
|
||||||
|
{
|
||||||
/* A valid directory entry already in memory */
|
/* A valid directory entry already in memory */
|
||||||
p = &dirp->data;
|
p = &dirp->data;
|
||||||
dirp->cached = 0;
|
dirp->cached = 0;
|
||||||
|
}
|
||||||
} else if (dirp->handle != INVALID_HANDLE_VALUE) {
|
else if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
/* Get the next directory entry from stream */
|
/* Get the next directory entry from stream */
|
||||||
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
|
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE)
|
||||||
|
{
|
||||||
/* Got a file */
|
/* Got a file */
|
||||||
p = &dirp->data;
|
p = &dirp->data;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* The very last entry has been processed or an error occured */
|
/* The very last entry has been processed or an error occured */
|
||||||
FindClose (dirp->handle);
|
FindClose (dirp->handle);
|
||||||
dirp->handle = INVALID_HANDLE_VALUE;
|
dirp->handle = INVALID_HANDLE_VALUE;
|
||||||
p = NULL;
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* End of directory stream reached */
|
/* End of directory stream reached */
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,35 +587,38 @@ opendir(
|
|||||||
{
|
{
|
||||||
struct DIR *dirp;
|
struct DIR *dirp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
/* Must have directory name */
|
/* Must have directory name */
|
||||||
if (dirname == NULL || dirname[0] == '\0') {
|
if (dirname == NULL || dirname[0] == '\0')
|
||||||
|
{
|
||||||
dirent_set_errno (ENOENT);
|
dirent_set_errno (ENOENT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for DIR structure */
|
/* Allocate memory for DIR structure */
|
||||||
dirp = (DIR*) malloc (sizeof (struct DIR));
|
dirp = (DIR*) malloc (sizeof (struct DIR));
|
||||||
if (dirp) {
|
if (dirp)
|
||||||
|
{
|
||||||
wchar_t wname[PATH_MAX + 1];
|
wchar_t wname[PATH_MAX + 1];
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
/* Convert directory name to wide-character string */
|
/* Convert directory name to wide-character string */
|
||||||
error = dirent_mbstowcs_s(
|
error = dirent_mbstowcs_s(
|
||||||
&n, wname, PATH_MAX + 1, dirname, PATH_MAX);
|
&n, wname, PATH_MAX + 1, dirname, PATH_MAX);
|
||||||
if (!error) {
|
if (!error)
|
||||||
|
{
|
||||||
/* Open directory stream using wide-character name */
|
/* Open directory stream using wide-character name */
|
||||||
dirp->wdirp = _wopendir (wname);
|
dirp->wdirp = _wopendir (wname);
|
||||||
if (dirp->wdirp) {
|
if (dirp->wdirp)
|
||||||
|
{
|
||||||
/* Directory stream opened */
|
/* Directory stream opened */
|
||||||
error = 0;
|
error = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Failed to open directory stream */
|
/* Failed to open directory stream */
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Cannot convert file name to wide-character string. This
|
* Cannot convert file name to wide-character string. This
|
||||||
* occurs if the string contains invalid multi-byte sequences or
|
* occurs if the string contains invalid multi-byte sequences or
|
||||||
@@ -616,18 +627,18 @@ opendir(
|
|||||||
*/
|
*/
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Cannot allocate DIR structure */
|
/* Cannot allocate DIR structure */
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up in case of error */
|
/* Clean up in case of error */
|
||||||
if (error && dirp) {
|
if (error && dirp)
|
||||||
|
{
|
||||||
free (dirp);
|
free (dirp);
|
||||||
dirp = NULL;
|
dirp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirp;
|
return dirp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,14 +664,13 @@ readdir(
|
|||||||
|
|
||||||
/* Read next directory entry */
|
/* Read next directory entry */
|
||||||
datap = dirent_next (dirp->wdirp);
|
datap = dirent_next (dirp->wdirp);
|
||||||
if (datap) {
|
if (datap)
|
||||||
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
/* Attempt to convert file name to multi-byte string */
|
/* Attempt to convert file name to multi-byte string */
|
||||||
error = dirent_wcstombs_s(
|
error = dirent_wcstombs_s(
|
||||||
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cFileName, MAX_PATH);
|
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cFileName, MAX_PATH);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file name cannot be represented by a multi-byte string,
|
* If the file name cannot be represented by a multi-byte string,
|
||||||
* then attempt to use old 8+3 file name. This allows traditional
|
* then attempt to use old 8+3 file name. This allows traditional
|
||||||
@@ -671,37 +681,40 @@ readdir(
|
|||||||
* name unless the file system provides one. At least
|
* name unless the file system provides one. At least
|
||||||
* VirtualBox shared folders fail to do this.
|
* VirtualBox shared folders fail to do this.
|
||||||
*/
|
*/
|
||||||
if (error && datap->cAlternateFileName[0] != '\0') {
|
if (error && datap->cAlternateFileName[0] != '\0')
|
||||||
|
{
|
||||||
error = dirent_wcstombs_s(
|
error = dirent_wcstombs_s(
|
||||||
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cAlternateFileName,
|
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cAlternateFileName,
|
||||||
sizeof (datap->cAlternateFileName) /
|
sizeof (datap->cAlternateFileName) /
|
||||||
sizeof (datap->cAlternateFileName[0]));
|
sizeof (datap->cAlternateFileName[0]));
|
||||||
}
|
}
|
||||||
|
if (!error)
|
||||||
if (!error) {
|
{
|
||||||
DWORD attr;
|
DWORD attr;
|
||||||
|
|
||||||
/* Initialize directory entry for return */
|
/* Initialize directory entry for return */
|
||||||
entp = &dirp->ent;
|
entp = &dirp->ent;
|
||||||
|
|
||||||
/* Length of file name excluding zero terminator */
|
/* Length of file name excluding zero terminator */
|
||||||
entp->d_namlen = n - 1;
|
entp->d_namlen = n - 1;
|
||||||
|
|
||||||
/* File attributes */
|
/* File attributes */
|
||||||
attr = datap->dwFileAttributes;
|
attr = datap->dwFileAttributes;
|
||||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
|
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
|
||||||
|
{
|
||||||
entp->d_type = DT_CHR;
|
entp->d_type = DT_CHR;
|
||||||
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
}
|
||||||
|
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||||
|
{
|
||||||
entp->d_type = DT_DIR;
|
entp->d_type = DT_DIR;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
entp->d_type = DT_REG;
|
entp->d_type = DT_REG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset dummy fields */
|
/* Reset dummy fields */
|
||||||
entp->d_ino = 0;
|
entp->d_ino = 0;
|
||||||
entp->d_reclen = sizeof (struct dirent);
|
entp->d_reclen = sizeof (struct dirent);
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Cannot convert file name to multi-byte string so construct
|
* Cannot convert file name to multi-byte string so construct
|
||||||
* an errornous directory entry and return that. Note that
|
* an errornous directory entry and return that. Note that
|
||||||
@@ -716,8 +729,9 @@ readdir(
|
|||||||
entp->d_ino = 0;
|
entp->d_ino = 0;
|
||||||
entp->d_reclen = 0;
|
entp->d_reclen = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* No more directory entries */
|
/* No more directory entries */
|
||||||
entp = NULL;
|
entp = NULL;
|
||||||
}
|
}
|
||||||
@@ -733,21 +747,19 @@ closedir(
|
|||||||
DIR *dirp)
|
DIR *dirp)
|
||||||
{
|
{
|
||||||
int ok;
|
int ok;
|
||||||
if (dirp) {
|
if (dirp)
|
||||||
|
{
|
||||||
/* Close wide-character directory stream */
|
/* Close wide-character directory stream */
|
||||||
ok = _wclosedir (dirp->wdirp);
|
ok = _wclosedir (dirp->wdirp);
|
||||||
dirp->wdirp = NULL;
|
dirp->wdirp = NULL;
|
||||||
|
|
||||||
/* Release multi-byte character version */
|
/* Release multi-byte character version */
|
||||||
free (dirp);
|
free (dirp);
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Invalid directory stream */
|
/* Invalid directory stream */
|
||||||
dirent_set_errno (EBADF);
|
dirent_set_errno (EBADF);
|
||||||
ok = /*failure*/-1;
|
ok = /*failure*/-1;
|
||||||
|
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -773,43 +785,35 @@ dirent_mbstowcs_s(
|
|||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
|
||||||
/* Microsoft Visual Studio 2005 or later */
|
/* Microsoft Visual Studio 2005 or later */
|
||||||
error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
|
error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Older Visual Studio or non-Microsoft compiler */
|
/* Older Visual Studio or non-Microsoft compiler */
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
/* Convert to wide-character string */
|
/* Convert to wide-character string */
|
||||||
n = mbstowcs (wcstr, mbstr, count);
|
n = mbstowcs (wcstr, mbstr, count);
|
||||||
if (n < sizeInWords) {
|
if (n < sizeInWords)
|
||||||
|
{
|
||||||
/* Zero-terminate output buffer */
|
/* Zero-terminate output buffer */
|
||||||
if (wcstr) {
|
if (wcstr)
|
||||||
|
{
|
||||||
wcstr[n] = 0;
|
wcstr[n] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Length of resuting multi-byte string WITH zero terminator */
|
/* Length of resuting multi-byte string WITH zero terminator */
|
||||||
if (pReturnValue) {
|
if (pReturnValue)
|
||||||
|
{
|
||||||
*pReturnValue = n + 1;
|
*pReturnValue = n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
error = 0;
|
error = 0;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Could not convert string */
|
/* Could not convert string */
|
||||||
error = 1;
|
error = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,43 +827,35 @@ dirent_wcstombs_s(
|
|||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
|
||||||
/* Microsoft Visual Studio 2005 or later */
|
/* Microsoft Visual Studio 2005 or later */
|
||||||
error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
|
error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Older Visual Studio or non-Microsoft compiler */
|
/* Older Visual Studio or non-Microsoft compiler */
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
/* Convert to multi-byte string */
|
/* Convert to multi-byte string */
|
||||||
n = wcstombs (mbstr, wcstr, count);
|
n = wcstombs (mbstr, wcstr, count);
|
||||||
if (n < sizeInBytes) {
|
if (n < sizeInBytes)
|
||||||
|
{
|
||||||
/* Zero-terminate output buffer */
|
/* Zero-terminate output buffer */
|
||||||
if (mbstr) {
|
if (mbstr)
|
||||||
|
{
|
||||||
mbstr[n] = '\0';
|
mbstr[n] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lenght of resulting multi-bytes string WITH zero-terminator */
|
/* Lenght of resulting multi-bytes string WITH zero-terminator */
|
||||||
if (pReturnValue) {
|
if (pReturnValue)
|
||||||
|
{
|
||||||
*pReturnValue = n + 1;
|
*pReturnValue = n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
error = 0;
|
error = 0;
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
/* Cannot convert string */
|
/* Cannot convert string */
|
||||||
error = 1;
|
error = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -869,15 +865,11 @@ dirent_set_errno(
|
|||||||
int error)
|
int error)
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
/* Microsoft Visual Studio */
|
/* Microsoft Visual Studio */
|
||||||
_set_errno (error);
|
_set_errno (error);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Non-Microsoft compiler */
|
/* Non-Microsoft compiler */
|
||||||
errno = error;
|
errno = error;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,7 +51,8 @@
|
|||||||
typedef unsigned int TRexBool;
|
typedef unsigned int TRexBool;
|
||||||
typedef struct TRex TRex;
|
typedef struct TRex TRex;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
const TRexChar *begin;
|
const TRexChar *begin;
|
||||||
int len;
|
int len;
|
||||||
} TRexMatch;
|
} TRexMatch;
|
||||||
|
116
src/tclap/Arg.h
116
src/tclap/Arg.h
@@ -54,7 +54,8 @@ typedef std::istrstream istringstream;
|
|||||||
#include "ArgTraits.h"
|
#include "ArgTraits.h"
|
||||||
#include "StandardTraits.h"
|
#include "StandardTraits.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A virtual base class that defines the essential data for all arguments.
|
* A virtual base class that defines the essential data for all arguments.
|
||||||
@@ -77,13 +78,21 @@ class Arg
|
|||||||
/**
|
/**
|
||||||
* Indicates whether the rest of the arguments should be ignored.
|
* Indicates whether the rest of the arguments should be ignored.
|
||||||
*/
|
*/
|
||||||
static bool& ignoreRestRef() { static bool ign = false; return ign; }
|
static bool& ignoreRestRef()
|
||||||
|
{
|
||||||
|
static bool ign = false;
|
||||||
|
return ign;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The delimiter that separates an argument flag/name from the
|
* The delimiter that separates an argument flag/name from the
|
||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
static char& delimiterRef() { static char delim = ' '; return delim; }
|
static char& delimiterRef()
|
||||||
|
{
|
||||||
|
static char delim = ' ';
|
||||||
|
return delim;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -197,24 +206,36 @@ class Arg
|
|||||||
/**
|
/**
|
||||||
* Begin ignoring arguments since the "--" argument was specified.
|
* Begin ignoring arguments since the "--" argument was specified.
|
||||||
*/
|
*/
|
||||||
static void beginIgnoring() { ignoreRestRef() = true; }
|
static void beginIgnoring()
|
||||||
|
{
|
||||||
|
ignoreRestRef() = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to ignore the rest.
|
* Whether to ignore the rest.
|
||||||
*/
|
*/
|
||||||
static bool ignoreRest() { return ignoreRestRef(); }
|
static bool ignoreRest()
|
||||||
|
{
|
||||||
|
return ignoreRestRef();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The delimiter that separates an argument flag/name from the
|
* The delimiter that separates an argument flag/name from the
|
||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
static char delimiter() { return delimiterRef(); }
|
static char delimiter()
|
||||||
|
{
|
||||||
|
return delimiterRef();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The char used as a place holder when SwitchArgs are combined.
|
* The char used as a place holder when SwitchArgs are combined.
|
||||||
* Currently set to the bell char (ASCII 7).
|
* Currently set to the bell char (ASCII 7).
|
||||||
*/
|
*/
|
||||||
static char blankChar() { return (char)7; }
|
static char blankChar()
|
||||||
|
{
|
||||||
|
return (char)7;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The char that indicates the beginning of a flag. Defaults to '-', but
|
* The char that indicates the beginning of a flag. Defaults to '-', but
|
||||||
@@ -223,7 +244,10 @@ class Arg
|
|||||||
#ifndef TCLAP_FLAGSTARTCHAR
|
#ifndef TCLAP_FLAGSTARTCHAR
|
||||||
#define TCLAP_FLAGSTARTCHAR '-'
|
#define TCLAP_FLAGSTARTCHAR '-'
|
||||||
#endif
|
#endif
|
||||||
static char flagStartChar() { return TCLAP_FLAGSTARTCHAR; }
|
static char flagStartChar()
|
||||||
|
{
|
||||||
|
return TCLAP_FLAGSTARTCHAR;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sting that indicates the beginning of a flag. Defaults to "-", but
|
* The sting that indicates the beginning of a flag. Defaults to "-", but
|
||||||
@@ -233,7 +257,10 @@ class Arg
|
|||||||
#ifndef TCLAP_FLAGSTARTSTRING
|
#ifndef TCLAP_FLAGSTARTSTRING
|
||||||
#define TCLAP_FLAGSTARTSTRING "-"
|
#define TCLAP_FLAGSTARTSTRING "-"
|
||||||
#endif
|
#endif
|
||||||
static const std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; }
|
static const std::string flagStartString()
|
||||||
|
{
|
||||||
|
return TCLAP_FLAGSTARTSTRING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sting that indicates the beginning of a name. Defaults to "--", but
|
* The sting that indicates the beginning of a name. Defaults to "--", but
|
||||||
@@ -242,18 +269,27 @@ class Arg
|
|||||||
#ifndef TCLAP_NAMESTARTSTRING
|
#ifndef TCLAP_NAMESTARTSTRING
|
||||||
#define TCLAP_NAMESTARTSTRING "--"
|
#define TCLAP_NAMESTARTSTRING "--"
|
||||||
#endif
|
#endif
|
||||||
static const std::string nameStartString() { return TCLAP_NAMESTARTSTRING; }
|
static const std::string nameStartString()
|
||||||
|
{
|
||||||
|
return TCLAP_NAMESTARTSTRING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name used to identify the ignore rest argument.
|
* The name used to identify the ignore rest argument.
|
||||||
*/
|
*/
|
||||||
static const std::string ignoreNameString() { return "ignore_rest"; }
|
static const std::string ignoreNameString()
|
||||||
|
{
|
||||||
|
return "ignore_rest";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the delimiter for all arguments.
|
* Sets the delimiter for all arguments.
|
||||||
* \param c - The character that delimits flags/names from values.
|
* \param c - The character that delimits flags/names from values.
|
||||||
*/
|
*/
|
||||||
static void setDelimiter( char c ) { delimiterRef() = c; }
|
static void setDelimiter( char c )
|
||||||
|
{
|
||||||
|
delimiterRef() = c;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure virtual method meant to handle the parsing and value assignment
|
* Pure virtual method meant to handle the parsing and value assignment
|
||||||
@@ -416,9 +452,9 @@ ExtractValue(T &destVal, const std::string& strVal, ValueLike vl)
|
|||||||
{
|
{
|
||||||
static_cast<void>(vl); // Avoid warning about unused vl
|
static_cast<void>(vl); // Avoid warning about unused vl
|
||||||
std::istringstream is(strVal);
|
std::istringstream is(strVal);
|
||||||
|
|
||||||
int valuesRead = 0;
|
int valuesRead = 0;
|
||||||
while ( is.good() ) {
|
while ( is.good() )
|
||||||
|
{
|
||||||
if ( is.peek() != EOF )
|
if ( is.peek() != EOF )
|
||||||
#ifdef TCLAP_SETBASE_ZERO
|
#ifdef TCLAP_SETBASE_ZERO
|
||||||
is >> std::setbase(0) >> destVal;
|
is >> std::setbase(0) >> destVal;
|
||||||
@@ -427,19 +463,14 @@ ExtractValue(T &destVal, const std::string& strVal, ValueLike vl)
|
|||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
valuesRead++;
|
valuesRead++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is.fail() )
|
if ( is.fail() )
|
||||||
throw( ArgParseException("Couldn't read argument value "
|
throw( ArgParseException("Couldn't read argument value "
|
||||||
"from string '" + strVal + "'"));
|
"from string '" + strVal + "'"));
|
||||||
|
|
||||||
|
|
||||||
if ( valuesRead > 1 )
|
if ( valuesRead > 1 )
|
||||||
throw( ArgParseException("More than one valid value parsed from "
|
throw( ArgParseException("More than one valid value parsed from "
|
||||||
"string '" + strVal + "'"));
|
"string '" + strVal + "'"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -480,7 +511,6 @@ inline Arg::Arg(const std::string& flag,
|
|||||||
if ( _flag.length() > 1 )
|
if ( _flag.length() > 1 )
|
||||||
throw(SpecificationException(
|
throw(SpecificationException(
|
||||||
"Argument flag can only be one character long", toString() ) );
|
"Argument flag can only be one character long", toString() ) );
|
||||||
|
|
||||||
if ( _name != ignoreNameString() &&
|
if ( _name != ignoreNameString() &&
|
||||||
( _flag == Arg::flagStartString() ||
|
( _flag == Arg::flagStartString() ||
|
||||||
_flag == Arg::nameStartString() ||
|
_flag == Arg::nameStartString() ||
|
||||||
@@ -489,7 +519,6 @@ inline Arg::Arg(const std::string& flag,
|
|||||||
Arg::flagStartString() + "' or '" +
|
Arg::flagStartString() + "' or '" +
|
||||||
Arg::nameStartString() + "' or a space.",
|
Arg::nameStartString() + "' or a space.",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
|
|
||||||
if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) ||
|
if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) ||
|
||||||
( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) ||
|
( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) ||
|
||||||
( _name.find( " ", 0 ) != std::string::npos ) )
|
( _name.find( " ", 0 ) != std::string::npos ) )
|
||||||
@@ -497,7 +526,6 @@ inline Arg::Arg(const std::string& flag,
|
|||||||
Arg::flagStartString() + "' or '" +
|
Arg::flagStartString() + "' or '" +
|
||||||
Arg::nameStartString() + "' or space.",
|
Arg::nameStartString() + "' or space.",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Arg::~Arg() { }
|
inline Arg::~Arg() { }
|
||||||
@@ -505,42 +533,31 @@ inline Arg::~Arg() { }
|
|||||||
inline std::string Arg::shortID( const std::string& valueId ) const
|
inline std::string Arg::shortID( const std::string& valueId ) const
|
||||||
{
|
{
|
||||||
std::string id = "";
|
std::string id = "";
|
||||||
|
|
||||||
if ( _flag != "" )
|
if ( _flag != "" )
|
||||||
id = Arg::flagStartString() + _flag;
|
id = Arg::flagStartString() + _flag;
|
||||||
else
|
else
|
||||||
id = Arg::nameStartString() + _name;
|
id = Arg::nameStartString() + _name;
|
||||||
|
|
||||||
if ( _valueRequired )
|
if ( _valueRequired )
|
||||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||||
|
|
||||||
if ( !_required )
|
if ( !_required )
|
||||||
id = "[" + id + "]";
|
id = "[" + id + "]";
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string Arg::longID( const std::string& valueId ) const
|
inline std::string Arg::longID( const std::string& valueId ) const
|
||||||
{
|
{
|
||||||
std::string id = "";
|
std::string id = "";
|
||||||
|
|
||||||
if ( _flag != "" )
|
if ( _flag != "" )
|
||||||
{
|
{
|
||||||
id += Arg::flagStartString() + _flag;
|
id += Arg::flagStartString() + _flag;
|
||||||
|
|
||||||
if ( _valueRequired )
|
if ( _valueRequired )
|
||||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||||
|
|
||||||
id += ", ";
|
id += ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
id += Arg::nameStartString() + _name;
|
id += Arg::nameStartString() + _name;
|
||||||
|
|
||||||
if ( _valueRequired )
|
if ( _valueRequired )
|
||||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Arg::operator==(const Arg& a) const
|
inline bool Arg::operator==(const Arg& a) const
|
||||||
@@ -556,21 +573,31 @@ inline std::string Arg::getDescription() const
|
|||||||
std::string desc = "";
|
std::string desc = "";
|
||||||
if ( _required )
|
if ( _required )
|
||||||
desc = "(" + _requireLabel + ") ";
|
desc = "(" + _requireLabel + ") ";
|
||||||
|
|
||||||
// if ( _valueRequired )
|
// if ( _valueRequired )
|
||||||
// desc += "(value required) ";
|
// desc += "(value required) ";
|
||||||
|
|
||||||
desc += _description;
|
desc += _description;
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string& Arg::getFlag() const { return _flag; }
|
inline const std::string& Arg::getFlag() const
|
||||||
|
{
|
||||||
|
return _flag;
|
||||||
|
}
|
||||||
|
|
||||||
inline const std::string& Arg::getName() const { return _name; }
|
inline const std::string& Arg::getName() const
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Arg::isRequired() const { return _required; }
|
inline bool Arg::isRequired() const
|
||||||
|
{
|
||||||
|
return _required;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Arg::isValueRequired() const { return _valueRequired; }
|
inline bool Arg::isValueRequired() const
|
||||||
|
{
|
||||||
|
return _valueRequired;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Arg::isSet() const
|
inline bool Arg::isSet() const
|
||||||
{
|
{
|
||||||
@@ -580,7 +607,10 @@ inline bool Arg::isSet() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Arg::isIgnoreable() const { return _ignoreable; }
|
inline bool Arg::isIgnoreable() const
|
||||||
|
{
|
||||||
|
return _ignoreable;
|
||||||
|
}
|
||||||
|
|
||||||
inline void Arg::setRequireLabel( const std::string& s)
|
inline void Arg::setRequireLabel( const std::string& s)
|
||||||
{
|
{
|
||||||
@@ -599,12 +629,9 @@ inline bool Arg::argMatches( const std::string& argFlag ) const
|
|||||||
inline std::string Arg::toString() const
|
inline std::string Arg::toString() const
|
||||||
{
|
{
|
||||||
std::string s = "";
|
std::string s = "";
|
||||||
|
|
||||||
if ( _flag != "" )
|
if ( _flag != "" )
|
||||||
s += Arg::flagStartString() + _flag + " ";
|
s += Arg::flagStartString() + _flag + " ";
|
||||||
|
|
||||||
s += "(" + Arg::nameStartString() + _name + ")";
|
s += "(" + Arg::nameStartString() + _name + ")";
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,13 +653,11 @@ inline void Arg::trimFlag(std::string& flag, std::string& value) const
|
|||||||
stop = i;
|
stop = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( stop > 1 )
|
if ( stop > 1 )
|
||||||
{
|
{
|
||||||
value = flag.substr(stop+1);
|
value = flag.substr(stop+1);
|
||||||
flag = flag.substr(0,stop);
|
flag = flag.substr(0,stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -643,7 +668,6 @@ inline bool Arg::_hasBlanks( const std::string& s ) const
|
|||||||
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
||||||
if ( s[i] == Arg::blankChar() )
|
if ( s[i] == Arg::blankChar() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple class that defines and argument exception. Should be caught
|
* A simple class that defines and argument exception. Should be caught
|
||||||
@@ -61,7 +62,10 @@ class ArgException : public std::exception
|
|||||||
/**
|
/**
|
||||||
* Returns the error text.
|
* Returns the error text.
|
||||||
*/
|
*/
|
||||||
std::string error() const { return ( _errorText ); }
|
std::string error() const
|
||||||
|
{
|
||||||
|
return ( _errorText );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the argument id.
|
* Returns the argument id.
|
||||||
@@ -184,11 +188,15 @@ class SpecificationException : public ArgException
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExitException {
|
class ExitException
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ExitException(int estat) : _estat(estat) {}
|
ExitException(int estat) : _estat(estat) {}
|
||||||
|
|
||||||
int getExitStatus() const { return _estat; }
|
int getExitStatus() const
|
||||||
|
{
|
||||||
|
return _estat;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _estat;
|
int _estat;
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
#ifndef TCLAP_ARGTRAITS_H
|
#ifndef TCLAP_ARGTRAITS_H
|
||||||
#define TCLAP_ARGTRAITS_H
|
#define TCLAP_ARGTRAITS_H
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
// We use two empty structs to get compile type specialization
|
// We use two empty structs to get compile type specialization
|
||||||
// function to work
|
// function to work
|
||||||
@@ -35,7 +36,8 @@ namespace TCLAP {
|
|||||||
* A value like argument value type is a value that can be set using
|
* A value like argument value type is a value that can be set using
|
||||||
* operator>>. This is the default value type.
|
* operator>>. This is the default value type.
|
||||||
*/
|
*/
|
||||||
struct ValueLike {
|
struct ValueLike
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
virtual ~ValueLike() {}
|
virtual ~ValueLike() {}
|
||||||
};
|
};
|
||||||
@@ -45,7 +47,8 @@ struct ValueLike {
|
|||||||
* operator=(string). Usefull if the value type contains spaces which
|
* operator=(string). Usefull if the value type contains spaces which
|
||||||
* will be broken up into individual tokens by operator>>.
|
* will be broken up into individual tokens by operator>>.
|
||||||
*/
|
*/
|
||||||
struct StringLike {
|
struct StringLike
|
||||||
|
{
|
||||||
virtual ~StringLike() {}
|
virtual ~StringLike() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,7 +57,8 @@ struct StringLike {
|
|||||||
* traits. This is a compile time thing and does not add any overhead
|
* traits. This is a compile time thing and does not add any overhead
|
||||||
* to the inherenting class.
|
* to the inherenting class.
|
||||||
*/
|
*/
|
||||||
struct StringLikeTrait {
|
struct StringLikeTrait
|
||||||
|
{
|
||||||
typedef StringLike ValueCategory;
|
typedef StringLike ValueCategory;
|
||||||
virtual ~StringLikeTrait() {}
|
virtual ~StringLikeTrait() {}
|
||||||
};
|
};
|
||||||
@@ -64,7 +68,8 @@ struct StringLikeTrait {
|
|||||||
* traits. This is a compile time thing and does not add any overhead
|
* traits. This is a compile time thing and does not add any overhead
|
||||||
* to the inherenting class.
|
* to the inherenting class.
|
||||||
*/
|
*/
|
||||||
struct ValueLikeTrait {
|
struct ValueLikeTrait
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
virtual ~ValueLikeTrait() {}
|
virtual ~ValueLikeTrait() {}
|
||||||
};
|
};
|
||||||
@@ -76,7 +81,8 @@ struct ValueLikeTrait {
|
|||||||
* supported types are StringLike and ValueLike.
|
* supported types are StringLike and ValueLike.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ArgTraits {
|
struct ArgTraits
|
||||||
|
{
|
||||||
typedef typename T::ValueCategory ValueCategory;
|
typedef typename T::ValueCategory ValueCategory;
|
||||||
virtual ~ArgTraits() {}
|
virtual ~ArgTraits() {}
|
||||||
//typedef ValueLike ValueCategory;
|
//typedef ValueLike ValueCategory;
|
||||||
|
@@ -48,7 +48,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdlib.h> // Needed for exit(), which isn't defined in some envs.
|
#include <stdlib.h> // Needed for exit(), which isn't defined in some envs.
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
template<typename T> void DelPtr(T ptr)
|
template<typename T> void DelPtr(T ptr)
|
||||||
{
|
{
|
||||||
@@ -346,8 +347,8 @@ inline CmdLine::~CmdLine()
|
|||||||
{
|
{
|
||||||
ClearContainer(_argDeleteOnExitList);
|
ClearContainer(_argDeleteOnExitList);
|
||||||
ClearContainer(_visitorDeleteOnExitList);
|
ClearContainer(_visitorDeleteOnExitList);
|
||||||
|
if ( !_userSetOutput )
|
||||||
if ( !_userSetOutput ) {
|
{
|
||||||
delete _output;
|
delete _output;
|
||||||
_output = 0;
|
_output = 0;
|
||||||
}
|
}
|
||||||
@@ -356,11 +357,8 @@ inline CmdLine::~CmdLine()
|
|||||||
inline void CmdLine::_constructor()
|
inline void CmdLine::_constructor()
|
||||||
{
|
{
|
||||||
_output = new StdOutput;
|
_output = new StdOutput;
|
||||||
|
|
||||||
Arg::setDelimiter( _delimiter );
|
Arg::setDelimiter( _delimiter );
|
||||||
|
|
||||||
Visitor* v;
|
Visitor* v;
|
||||||
|
|
||||||
if ( _helpAndVersion )
|
if ( _helpAndVersion )
|
||||||
{
|
{
|
||||||
v = new HelpVisitor( this, &_output );
|
v = new HelpVisitor( this, &_output );
|
||||||
@@ -370,7 +368,6 @@ inline void CmdLine::_constructor()
|
|||||||
add( help );
|
add( help );
|
||||||
deleteOnExit(help);
|
deleteOnExit(help);
|
||||||
deleteOnExit(v);
|
deleteOnExit(v);
|
||||||
|
|
||||||
v = new VersionVisitor( this, &_output );
|
v = new VersionVisitor( this, &_output );
|
||||||
SwitchArg* vers = new SwitchArg("","version",
|
SwitchArg* vers = new SwitchArg("","version",
|
||||||
"Displays version information and exits.",
|
"Displays version information and exits.",
|
||||||
@@ -379,7 +376,6 @@ inline void CmdLine::_constructor()
|
|||||||
deleteOnExit(vers);
|
deleteOnExit(vers);
|
||||||
deleteOnExit(v);
|
deleteOnExit(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
v = new IgnoreRestVisitor();
|
v = new IgnoreRestVisitor();
|
||||||
SwitchArg* ignore = new SwitchArg(Arg::flagStartString(),
|
SwitchArg* ignore = new SwitchArg(Arg::flagStartString(),
|
||||||
Arg::ignoreNameString(),
|
Arg::ignoreNameString(),
|
||||||
@@ -393,7 +389,6 @@ inline void CmdLine::_constructor()
|
|||||||
inline void CmdLine::xorAdd( std::vector<Arg*>& ors )
|
inline void CmdLine::xorAdd( std::vector<Arg*>& ors )
|
||||||
{
|
{
|
||||||
_xorHandler.add( ors );
|
_xorHandler.add( ors );
|
||||||
|
|
||||||
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++)
|
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++)
|
||||||
{
|
{
|
||||||
(*it)->forceRequired();
|
(*it)->forceRequired();
|
||||||
@@ -422,9 +417,7 @@ inline void CmdLine::add( Arg* a )
|
|||||||
throw( SpecificationException(
|
throw( SpecificationException(
|
||||||
"Argument with same flag/name already exists!",
|
"Argument with same flag/name already exists!",
|
||||||
a->longID() ) );
|
a->longID() ) );
|
||||||
|
|
||||||
a->addToList( _argList );
|
a->addToList( _argList );
|
||||||
|
|
||||||
if ( a->isRequired() )
|
if ( a->isRequired() )
|
||||||
_numRequired++;
|
_numRequired++;
|
||||||
}
|
}
|
||||||
@@ -437,7 +430,6 @@ inline void CmdLine::parse(int argc, const char * const * argv)
|
|||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
args.push_back(argv[i]);
|
args.push_back(argv[i]);
|
||||||
|
|
||||||
parse(args);
|
parse(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,18 +437,17 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
|||||||
{
|
{
|
||||||
bool shouldExit = false;
|
bool shouldExit = false;
|
||||||
int estat = 0;
|
int estat = 0;
|
||||||
|
try
|
||||||
try {
|
{
|
||||||
_progName = args.front();
|
_progName = args.front();
|
||||||
args.erase(args.begin());
|
args.erase(args.begin());
|
||||||
|
|
||||||
int requiredCount = 0;
|
int requiredCount = 0;
|
||||||
|
|
||||||
for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++)
|
for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++)
|
||||||
{
|
{
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
for (ArgListIterator it = _argList.begin();
|
for (ArgListIterator it = _argList.begin();
|
||||||
it != _argList.end(); it++) {
|
it != _argList.end(); it++)
|
||||||
|
{
|
||||||
if ( (*it)->processArg( &i, args ) )
|
if ( (*it)->processArg( &i, args ) )
|
||||||
{
|
{
|
||||||
requiredCount += _xorHandler.check( *it );
|
requiredCount += _xorHandler.check( *it );
|
||||||
@@ -464,46 +455,47 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks to see if the argument is an empty combined
|
// checks to see if the argument is an empty combined
|
||||||
// switch and if so, then we've actually matched it
|
// switch and if so, then we've actually matched it
|
||||||
if ( !matched && _emptyCombined( args[i] ) )
|
if ( !matched && _emptyCombined( args[i] ) )
|
||||||
matched = true;
|
matched = true;
|
||||||
|
|
||||||
if ( !matched && !Arg::ignoreRest() )
|
if ( !matched && !Arg::ignoreRest() )
|
||||||
throw(CmdLineParseException("Couldn't find match "
|
throw(CmdLineParseException("Couldn't find match "
|
||||||
"for argument",
|
"for argument",
|
||||||
args[i]));
|
args[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( requiredCount < _numRequired )
|
if ( requiredCount < _numRequired )
|
||||||
missingArgsException();
|
missingArgsException();
|
||||||
|
|
||||||
if ( requiredCount > _numRequired )
|
if ( requiredCount > _numRequired )
|
||||||
throw(CmdLineParseException("Too many arguments!"));
|
throw(CmdLineParseException("Too many arguments!"));
|
||||||
|
}
|
||||||
} catch ( ArgException& e ) {
|
catch ( ArgException& e )
|
||||||
|
{
|
||||||
// If we're not handling the exceptions, rethrow.
|
// If we're not handling the exceptions, rethrow.
|
||||||
if ( !_handleExceptions) {
|
if ( !_handleExceptions)
|
||||||
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
try
|
||||||
try {
|
{
|
||||||
_output->failure(*this,e);
|
_output->failure(*this,e);
|
||||||
} catch ( ExitException &ee ) {
|
}
|
||||||
|
catch ( ExitException &ee )
|
||||||
|
{
|
||||||
estat = ee.getExitStatus();
|
estat = ee.getExitStatus();
|
||||||
shouldExit = true;
|
shouldExit = true;
|
||||||
}
|
}
|
||||||
} catch (ExitException &ee) {
|
}
|
||||||
|
catch (ExitException &ee)
|
||||||
|
{
|
||||||
// If we're not handling the exceptions, rethrow.
|
// If we're not handling the exceptions, rethrow.
|
||||||
if ( !_handleExceptions) {
|
if ( !_handleExceptions)
|
||||||
|
{
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
estat = ee.getExitStatus();
|
estat = ee.getExitStatus();
|
||||||
shouldExit = true;
|
shouldExit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldExit)
|
if (shouldExit)
|
||||||
exit(estat);
|
exit(estat);
|
||||||
}
|
}
|
||||||
@@ -512,18 +504,15 @@ inline bool CmdLine::_emptyCombined(const std::string& s)
|
|||||||
{
|
{
|
||||||
if ( s.length() > 0 && s[0] != Arg::flagStartChar() )
|
if ( s.length() > 0 && s[0] != Arg::flagStartChar() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
||||||
if ( s[i] != Arg::blankChar() )
|
if ( s[i] != Arg::blankChar() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CmdLine::missingArgsException()
|
inline void CmdLine::missingArgsException()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
std::string missingArgList;
|
std::string missingArgList;
|
||||||
for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
|
for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
|
||||||
{
|
{
|
||||||
@@ -535,15 +524,12 @@ inline void CmdLine::missingArgsException()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
missingArgList = missingArgList.substr(0,missingArgList.length()-2);
|
missingArgList = missingArgList.substr(0,missingArgList.length()-2);
|
||||||
|
|
||||||
std::string msg;
|
std::string msg;
|
||||||
if ( count > 1 )
|
if ( count > 1 )
|
||||||
msg = "Required arguments missing: ";
|
msg = "Required arguments missing: ";
|
||||||
else
|
else
|
||||||
msg = "Required argument missing: ";
|
msg = "Required argument missing: ";
|
||||||
|
|
||||||
msg += missingArgList;
|
msg += missingArgList;
|
||||||
|
|
||||||
throw(CmdLineParseException(msg));
|
throw(CmdLineParseException(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +605,6 @@ inline void CmdLine::reset()
|
|||||||
{
|
{
|
||||||
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
||||||
(*it)->reset();
|
(*it)->reset();
|
||||||
|
|
||||||
_progName.clear();
|
_progName.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
class Arg;
|
class Arg;
|
||||||
class CmdLineOutput;
|
class CmdLineOutput;
|
||||||
|
@@ -30,7 +30,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
class CmdLineInterface;
|
class CmdLineInterface;
|
||||||
class ArgException;
|
class ArgException;
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface that defines the interaction between the Arg and Constraint.
|
* The interface that defines the interaction between the Arg and Constraint.
|
||||||
@@ -61,7 +62,10 @@ class Constraint
|
|||||||
* Silences warnings about Constraint being a base class with virtual
|
* Silences warnings about Constraint being a base class with virtual
|
||||||
* functions but without a virtual destructor.
|
* functions but without a virtual destructor.
|
||||||
*/
|
*/
|
||||||
virtual ~Constraint() { ; }
|
virtual ~Constraint()
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace TCLAP
|
} //namespace TCLAP
|
||||||
|
@@ -34,7 +34,8 @@
|
|||||||
#include <tclap/XorHandler.h>
|
#include <tclap/XorHandler.h>
|
||||||
#include <tclap/Arg.h>
|
#include <tclap/Arg.h>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that generates DocBook output for usage() method for the
|
* A class that generates DocBook output for usage() method for the
|
||||||
@@ -101,28 +102,21 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd )
|
|||||||
XorHandler xorHandler = _cmd.getXorHandler();
|
XorHandler xorHandler = _cmd.getXorHandler();
|
||||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||||
basename(progName);
|
basename(progName);
|
||||||
|
|
||||||
std::cout << "<?xml version='1.0'?>" << std::endl;
|
std::cout << "<?xml version='1.0'?>" << std::endl;
|
||||||
std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
|
std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
|
||||||
std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
|
std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
|
||||||
|
|
||||||
std::cout << "<refentry>" << std::endl;
|
std::cout << "<refentry>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refmeta>" << std::endl;
|
std::cout << "<refmeta>" << std::endl;
|
||||||
std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl;
|
std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl;
|
||||||
std::cout << "<manvolnum>1</manvolnum>" << std::endl;
|
std::cout << "<manvolnum>1</manvolnum>" << std::endl;
|
||||||
std::cout << "</refmeta>" << std::endl;
|
std::cout << "</refmeta>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refnamediv>" << std::endl;
|
std::cout << "<refnamediv>" << std::endl;
|
||||||
std::cout << "<refname>" << progName << "</refname>" << std::endl;
|
std::cout << "<refname>" << progName << "</refname>" << std::endl;
|
||||||
std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl;
|
std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl;
|
||||||
std::cout << "</refnamediv>" << std::endl;
|
std::cout << "</refnamediv>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refsynopsisdiv>" << std::endl;
|
std::cout << "<refsynopsisdiv>" << std::endl;
|
||||||
std::cout << "<cmdsynopsis>" << std::endl;
|
std::cout << "<cmdsynopsis>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<command>" << progName << "</command>" << std::endl;
|
std::cout << "<command>" << progName << "</command>" << std::endl;
|
||||||
|
|
||||||
// xor
|
// xor
|
||||||
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
||||||
{
|
{
|
||||||
@@ -130,45 +124,34 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd )
|
|||||||
for ( ArgVectorIterator it = xorList[i].begin();
|
for ( ArgVectorIterator it = xorList[i].begin();
|
||||||
it != xorList[i].end(); it++ )
|
it != xorList[i].end(); it++ )
|
||||||
printShortArg((*it));
|
printShortArg((*it));
|
||||||
|
|
||||||
std::cout << "</group>" << std::endl;
|
std::cout << "</group>" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rest of args
|
// rest of args
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
if ( !xorHandler.contains( (*it) ) )
|
if ( !xorHandler.contains( (*it) ) )
|
||||||
printShortArg((*it));
|
printShortArg((*it));
|
||||||
|
|
||||||
std::cout << "</cmdsynopsis>" << std::endl;
|
std::cout << "</cmdsynopsis>" << std::endl;
|
||||||
std::cout << "</refsynopsisdiv>" << std::endl;
|
std::cout << "</refsynopsisdiv>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refsect1>" << std::endl;
|
std::cout << "<refsect1>" << std::endl;
|
||||||
std::cout << "<title>Description</title>" << std::endl;
|
std::cout << "<title>Description</title>" << std::endl;
|
||||||
std::cout << "<para>" << std::endl;
|
std::cout << "<para>" << std::endl;
|
||||||
std::cout << _cmd.getMessage() << std::endl;
|
std::cout << _cmd.getMessage() << std::endl;
|
||||||
std::cout << "</para>" << std::endl;
|
std::cout << "</para>" << std::endl;
|
||||||
std::cout << "</refsect1>" << std::endl;
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refsect1>" << std::endl;
|
std::cout << "<refsect1>" << std::endl;
|
||||||
std::cout << "<title>Options</title>" << std::endl;
|
std::cout << "<title>Options</title>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<variablelist>" << std::endl;
|
std::cout << "<variablelist>" << std::endl;
|
||||||
|
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
printLongArg((*it));
|
printLongArg((*it));
|
||||||
|
|
||||||
std::cout << "</variablelist>" << std::endl;
|
std::cout << "</variablelist>" << std::endl;
|
||||||
std::cout << "</refsect1>" << std::endl;
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<refsect1>" << std::endl;
|
std::cout << "<refsect1>" << std::endl;
|
||||||
std::cout << "<title>Version</title>" << std::endl;
|
std::cout << "<title>Version</title>" << std::endl;
|
||||||
std::cout << "<para>" << std::endl;
|
std::cout << "<para>" << std::endl;
|
||||||
std::cout << xversion << std::endl;
|
std::cout << xversion << std::endl;
|
||||||
std::cout << "</para>" << std::endl;
|
std::cout << "</para>" << std::endl;
|
||||||
std::cout << "</refsect1>" << std::endl;
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
std::cout << "</refentry>" << std::endl;
|
std::cout << "</refentry>" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DocBookOutput::failure( CmdLineInterface& _cmd,
|
inline void DocBookOutput::failure( CmdLineInterface& _cmd,
|
||||||
@@ -213,22 +196,17 @@ inline void DocBookOutput::printShortArg(Arg* a)
|
|||||||
{
|
{
|
||||||
std::string lt = "<";
|
std::string lt = "<";
|
||||||
std::string gt = ">";
|
std::string gt = ">";
|
||||||
|
|
||||||
std::string id = a->shortID();
|
std::string id = a->shortID();
|
||||||
substituteSpecialChars(id,'<',lt);
|
substituteSpecialChars(id,'<',lt);
|
||||||
substituteSpecialChars(id,'>',gt);
|
substituteSpecialChars(id,'>',gt);
|
||||||
removeChar(id,'[');
|
removeChar(id,'[');
|
||||||
removeChar(id,']');
|
removeChar(id,']');
|
||||||
|
|
||||||
std::string choice = "opt";
|
std::string choice = "opt";
|
||||||
if ( a->isRequired() )
|
if ( a->isRequired() )
|
||||||
choice = "plain";
|
choice = "plain";
|
||||||
|
|
||||||
std::cout << "<arg choice='" << choice << '\'';
|
std::cout << "<arg choice='" << choice << '\'';
|
||||||
if ( a->acceptsMultipleValues() )
|
if ( a->acceptsMultipleValues() )
|
||||||
std::cout << " rep='repeat'";
|
std::cout << " rep='repeat'";
|
||||||
|
|
||||||
|
|
||||||
std::cout << '>';
|
std::cout << '>';
|
||||||
if ( !a->getFlag().empty() )
|
if ( !a->getFlag().empty() )
|
||||||
std::cout << a->flagStartChar() << a->getFlag();
|
std::cout << a->flagStartChar() << a->getFlag();
|
||||||
@@ -246,20 +224,16 @@ inline void DocBookOutput::printShortArg(Arg* a)
|
|||||||
std::cout << "<replaceable>" << arg << "</replaceable>";
|
std::cout << "<replaceable>" << arg << "</replaceable>";
|
||||||
}
|
}
|
||||||
std::cout << "</arg>" << std::endl;
|
std::cout << "</arg>" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DocBookOutput::printLongArg(Arg* a)
|
inline void DocBookOutput::printLongArg(Arg* a)
|
||||||
{
|
{
|
||||||
std::string lt = "<";
|
std::string lt = "<";
|
||||||
std::string gt = ">";
|
std::string gt = ">";
|
||||||
|
|
||||||
std::string desc = a->getDescription();
|
std::string desc = a->getDescription();
|
||||||
substituteSpecialChars(desc,'<',lt);
|
substituteSpecialChars(desc,'<',lt);
|
||||||
substituteSpecialChars(desc,'>',gt);
|
substituteSpecialChars(desc,'>',gt);
|
||||||
|
|
||||||
std::cout << "<varlistentry>" << std::endl;
|
std::cout << "<varlistentry>" << std::endl;
|
||||||
|
|
||||||
if ( !a->getFlag().empty() )
|
if ( !a->getFlag().empty() )
|
||||||
{
|
{
|
||||||
std::cout << "<term>" << std::endl;
|
std::cout << "<term>" << std::endl;
|
||||||
@@ -268,7 +242,6 @@ inline void DocBookOutput::printLongArg(Arg* a)
|
|||||||
std::cout << "</option>" << std::endl;
|
std::cout << "</option>" << std::endl;
|
||||||
std::cout << "</term>" << std::endl;
|
std::cout << "</term>" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "<term>" << std::endl;
|
std::cout << "<term>" << std::endl;
|
||||||
std::cout << "<option>";
|
std::cout << "<option>";
|
||||||
std::cout << a->nameStartString() << a->getName();
|
std::cout << a->nameStartString() << a->getName();
|
||||||
@@ -285,13 +258,11 @@ inline void DocBookOutput::printLongArg(Arg* a)
|
|||||||
}
|
}
|
||||||
std::cout << "</option>" << std::endl;
|
std::cout << "</option>" << std::endl;
|
||||||
std::cout << "</term>" << std::endl;
|
std::cout << "</term>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<listitem>" << std::endl;
|
std::cout << "<listitem>" << std::endl;
|
||||||
std::cout << "<para>" << std::endl;
|
std::cout << "<para>" << std::endl;
|
||||||
std::cout << desc << std::endl;
|
std::cout << desc << std::endl;
|
||||||
std::cout << "</para>" << std::endl;
|
std::cout << "</para>" << std::endl;
|
||||||
std::cout << "</listitem>" << std::endl;
|
std::cout << "</listitem>" << std::endl;
|
||||||
|
|
||||||
std::cout << "</varlistentry>" << std::endl;
|
std::cout << "</varlistentry>" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
#include "CmdLineOutput.h"
|
#include "CmdLineOutput.h"
|
||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Visitor object that calls the usage method of the given CmdLineOutput
|
* A Visitor object that calls the usage method of the given CmdLineOutput
|
||||||
@@ -67,7 +68,11 @@ class HelpVisitor: public Visitor
|
|||||||
* Calls the usage method of the CmdLineOutput for the
|
* Calls the usage method of the CmdLineOutput for the
|
||||||
* specified CmdLine.
|
* specified CmdLine.
|
||||||
*/
|
*/
|
||||||
void visit() { (*_out)->usage(*_cmd); throw ExitException(0); }
|
void visit()
|
||||||
|
{
|
||||||
|
(*_out)->usage(*_cmd);
|
||||||
|
throw ExitException(0);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
#include "Arg.h"
|
#include "Arg.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Vistor that tells the CmdLine to begin ignoring arguments after
|
* A Vistor that tells the CmdLine to begin ignoring arguments after
|
||||||
@@ -44,7 +45,10 @@ class IgnoreRestVisitor: public Visitor
|
|||||||
/**
|
/**
|
||||||
* Sets Arg::_ignoreRest.
|
* Sets Arg::_ignoreRest.
|
||||||
*/
|
*/
|
||||||
void visit() { Arg::beginIgnoring(); }
|
void visit()
|
||||||
|
{
|
||||||
|
Arg::beginIgnoring();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
#include "Arg.h"
|
#include "Arg.h"
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* An argument that allows multiple values of type T to be specified. Very
|
* An argument that allows multiple values of type T to be specified. Very
|
||||||
* similar to a ValueArg, except a vector of values will be returned
|
* similar to a ValueArg, except a vector of values will be returned
|
||||||
@@ -191,13 +192,19 @@ public:
|
|||||||
* Returns an iterator over the values parsed from the command
|
* Returns an iterator over the values parsed from the command
|
||||||
* line.
|
* line.
|
||||||
*/
|
*/
|
||||||
const_iterator begin() const { return _values.begin(); }
|
const_iterator begin() const
|
||||||
|
{
|
||||||
|
return _values.begin();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the end of the values parsed from the command
|
* Returns the end of the values parsed from the command
|
||||||
* line.
|
* line.
|
||||||
*/
|
*/
|
||||||
const_iterator end() const { return _values.end(); }
|
const_iterator end() const
|
||||||
|
{
|
||||||
|
return _values.end();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the a short id string. Used in the usage.
|
* Returns the a short id string. Used in the usage.
|
||||||
@@ -302,29 +309,27 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
const std::vector<T>& MultiArg<T>::getValue() { return _values; }
|
const std::vector<T>& MultiArg<T>::getValue()
|
||||||
|
{
|
||||||
|
return _values;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( _hasBlanks( args[*i] ) )
|
if ( _hasBlanks( args[*i] ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string flag = args[*i];
|
std::string flag = args[*i];
|
||||||
std::string value = "";
|
std::string value = "";
|
||||||
|
|
||||||
trimFlag( flag, value );
|
trimFlag( flag, value );
|
||||||
|
|
||||||
if ( argMatches( flag ) )
|
if ( argMatches( flag ) )
|
||||||
{
|
{
|
||||||
if ( Arg::delimiter() != ' ' && value == "" )
|
if ( Arg::delimiter() != ' ' && value == "" )
|
||||||
throw( ArgParseException(
|
throw( ArgParseException(
|
||||||
"Couldn't find delimiter for this argument!",
|
"Couldn't find delimiter for this argument!",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
|
|
||||||
// always take the first one, regardless of start string
|
// always take the first one, regardless of start string
|
||||||
if ( value == "" )
|
if ( value == "" )
|
||||||
{
|
{
|
||||||
@@ -337,7 +342,6 @@ bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
_extractValue( value );
|
_extractValue( value );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// continuing taking the args until we hit one with a start string
|
// continuing taking the args until we hit one with a start string
|
||||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||||
@@ -345,10 +349,8 @@ bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||||
_extractValue( args[++(*i)] );
|
_extractValue( args[++(*i)] );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -391,20 +393,21 @@ bool MultiArg<T>::isRequired() const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void MultiArg<T>::_extractValue( const std::string& val )
|
void MultiArg<T>::_extractValue( const std::string& val )
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
T tmp;
|
T tmp;
|
||||||
ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory());
|
ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory());
|
||||||
_values.push_back(tmp);
|
_values.push_back(tmp);
|
||||||
} catch( ArgParseException &e) {
|
}
|
||||||
|
catch( ArgParseException &e)
|
||||||
|
{
|
||||||
throw ArgParseException(e.error(), toString());
|
throw ArgParseException(e.error(), toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _constraint != NULL )
|
if ( _constraint != NULL )
|
||||||
if ( ! _constraint->check( _values.back() ) )
|
if ( ! _constraint->check( _values.back() ) )
|
||||||
throw( CmdLineParseException( "Value '" + val +
|
throw( CmdLineParseException( "Value '" + val +
|
||||||
|
@@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
#include "SwitchArg.h"
|
#include "SwitchArg.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A multiple switch argument. If the switch is set on the command line, then
|
* A multiple switch argument. If the switch is set on the command line, then
|
||||||
@@ -150,39 +151,34 @@ _default( init )
|
|||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int MultiSwitchArg::getValue() { return _value; }
|
inline int MultiSwitchArg::getValue()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
|
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( argMatches( args[*i] ))
|
if ( argMatches( args[*i] ))
|
||||||
{
|
{
|
||||||
// so the isSet() method will work
|
// so the isSet() method will work
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
|
|
||||||
// Matched argument: increment value.
|
// Matched argument: increment value.
|
||||||
++_value;
|
++_value;
|
||||||
|
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ( combinedSwitchesMatch( args[*i] ) )
|
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||||
{
|
{
|
||||||
// so the isSet() method will work
|
// so the isSet() method will work
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
|
|
||||||
// Matched argument: increment value.
|
// Matched argument: increment value.
|
||||||
++_value;
|
++_value;
|
||||||
|
|
||||||
// Check for more in argument and increment value.
|
// Check for more in argument and increment value.
|
||||||
while ( combinedSwitchesMatch( args[*i] ) )
|
while ( combinedSwitchesMatch( args[*i] ) )
|
||||||
++_value;
|
++_value;
|
||||||
|
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
class OptionalUnlabeledTracker
|
class OptionalUnlabeledTracker
|
||||||
{
|
{
|
||||||
@@ -35,13 +36,23 @@ class OptionalUnlabeledTracker
|
|||||||
|
|
||||||
static void check( bool req, const std::string& argName );
|
static void check( bool req, const std::string& argName );
|
||||||
|
|
||||||
static void gotOptional() { alreadyOptionalRef() = true; }
|
static void gotOptional()
|
||||||
|
{
|
||||||
|
alreadyOptionalRef() = true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool& alreadyOptional() { return alreadyOptionalRef(); }
|
static bool& alreadyOptional()
|
||||||
|
{
|
||||||
|
return alreadyOptionalRef();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static bool& alreadyOptionalRef() { static bool ct = false; return ct; }
|
static bool& alreadyOptionalRef()
|
||||||
|
{
|
||||||
|
static bool ct = false;
|
||||||
|
return ct;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +62,6 @@ inline void OptionalUnlabeledTracker::check( bool req, const std::string& argNam
|
|||||||
throw( SpecificationException(
|
throw( SpecificationException(
|
||||||
"You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
|
"You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
|
||||||
argName ) );
|
argName ) );
|
||||||
|
|
||||||
if ( !req )
|
if ( !req )
|
||||||
OptionalUnlabeledTracker::gotOptional();
|
OptionalUnlabeledTracker::gotOptional();
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
// Integer types
|
// Integer types
|
||||||
@@ -49,7 +50,8 @@ namespace TCLAP {
|
|||||||
* longs have value-like semantics.
|
* longs have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<long> {
|
struct ArgTraits<long>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,7 +59,8 @@ struct ArgTraits<long> {
|
|||||||
* ints have value-like semantics.
|
* ints have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<int> {
|
struct ArgTraits<int>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +68,8 @@ struct ArgTraits<int> {
|
|||||||
* shorts have value-like semantics.
|
* shorts have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<short> {
|
struct ArgTraits<short>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +77,8 @@ struct ArgTraits<short> {
|
|||||||
* chars have value-like semantics.
|
* chars have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<char> {
|
struct ArgTraits<char>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,7 +87,8 @@ struct ArgTraits<char> {
|
|||||||
* long longs have value-like semantics.
|
* long longs have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<long long> {
|
struct ArgTraits<long long>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -95,7 +101,8 @@ struct ArgTraits<long long> {
|
|||||||
* unsigned longs have value-like semantics.
|
* unsigned longs have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<unsigned long> {
|
struct ArgTraits<unsigned long>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,7 +110,8 @@ struct ArgTraits<unsigned long> {
|
|||||||
* unsigned ints have value-like semantics.
|
* unsigned ints have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<unsigned int> {
|
struct ArgTraits<unsigned int>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,7 +119,8 @@ struct ArgTraits<unsigned int> {
|
|||||||
* unsigned shorts have value-like semantics.
|
* unsigned shorts have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<unsigned short> {
|
struct ArgTraits<unsigned short>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,7 +128,8 @@ struct ArgTraits<unsigned short> {
|
|||||||
* unsigned chars have value-like semantics.
|
* unsigned chars have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<unsigned char> {
|
struct ArgTraits<unsigned char>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,7 +139,8 @@ struct ArgTraits<unsigned char> {
|
|||||||
* size_ts have value-like semantics.
|
* size_ts have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<size_t> {
|
struct ArgTraits<size_t>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -140,7 +151,8 @@ struct ArgTraits<size_t> {
|
|||||||
* unsigned long longs have value-like semantics.
|
* unsigned long longs have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<unsigned long long> {
|
struct ArgTraits<unsigned long long>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -153,7 +165,8 @@ struct ArgTraits<unsigned long long> {
|
|||||||
* floats have value-like semantics.
|
* floats have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<float> {
|
struct ArgTraits<float>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -161,7 +174,8 @@ struct ArgTraits<float> {
|
|||||||
* doubles have value-like semantics.
|
* doubles have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<double> {
|
struct ArgTraits<double>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,7 +187,8 @@ struct ArgTraits<double> {
|
|||||||
* bools have value-like semantics.
|
* bools have value-like semantics.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<bool> {
|
struct ArgTraits<bool>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -183,7 +198,8 @@ struct ArgTraits<bool> {
|
|||||||
*/
|
*/
|
||||||
#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
|
#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<wchar_t> {
|
struct ArgTraits<wchar_t>
|
||||||
|
{
|
||||||
typedef ValueLike ValueCategory;
|
typedef ValueLike ValueCategory;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -192,7 +208,8 @@ struct ArgTraits<wchar_t> {
|
|||||||
* Strings have string like argument traits.
|
* Strings have string like argument traits.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct ArgTraits<std::string> {
|
struct ArgTraits<std::string>
|
||||||
|
{
|
||||||
typedef StringLike ValueCategory;
|
typedef StringLike ValueCategory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -34,7 +34,8 @@
|
|||||||
#include "XorHandler.h"
|
#include "XorHandler.h"
|
||||||
#include "Arg.h"
|
#include "Arg.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that isolates any output from the CmdLine object so that it
|
* A class that isolates any output from the CmdLine object so that it
|
||||||
@@ -109,7 +110,6 @@ inline void StdOutput::version(CmdLineInterface& _cmd)
|
|||||||
{
|
{
|
||||||
std::string progName = _cmd.getProgramName();
|
std::string progName = _cmd.getProgramName();
|
||||||
std::string xversion = _cmd.getVersion();
|
std::string xversion = _cmd.getVersion();
|
||||||
|
|
||||||
std::cout << std::endl << progName << " version: "
|
std::cout << std::endl << progName << " version: "
|
||||||
<< xversion << std::endl << std::endl;
|
<< xversion << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
@@ -117,38 +117,28 @@ inline void StdOutput::version(CmdLineInterface& _cmd)
|
|||||||
inline void StdOutput::usage(CmdLineInterface& _cmd )
|
inline void StdOutput::usage(CmdLineInterface& _cmd )
|
||||||
{
|
{
|
||||||
std::cout << std::endl << "USAGE: " << std::endl << std::endl;
|
std::cout << std::endl << "USAGE: " << std::endl << std::endl;
|
||||||
|
|
||||||
_shortUsage( _cmd, std::cout );
|
_shortUsage( _cmd, std::cout );
|
||||||
|
|
||||||
std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl;
|
std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl;
|
||||||
|
|
||||||
_longUsage( _cmd, std::cout );
|
_longUsage( _cmd, std::cout );
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void StdOutput::failure( CmdLineInterface& _cmd,
|
inline void StdOutput::failure( CmdLineInterface& _cmd,
|
||||||
ArgException& e )
|
ArgException& e )
|
||||||
{
|
{
|
||||||
std::string progName = _cmd.getProgramName();
|
std::string progName = _cmd.getProgramName();
|
||||||
|
|
||||||
std::cerr << "PARSE ERROR: " << e.argId() << std::endl
|
std::cerr << "PARSE ERROR: " << e.argId() << std::endl
|
||||||
<< " " << e.error() << std::endl << std::endl;
|
<< " " << e.error() << std::endl << std::endl;
|
||||||
|
|
||||||
if ( _cmd.hasHelpAndVersion() )
|
if ( _cmd.hasHelpAndVersion() )
|
||||||
{
|
{
|
||||||
std::cerr << "Brief USAGE: " << std::endl;
|
std::cerr << "Brief USAGE: " << std::endl;
|
||||||
|
|
||||||
_shortUsage( _cmd, std::cerr );
|
_shortUsage( _cmd, std::cerr );
|
||||||
|
|
||||||
std::cerr << std::endl << "For complete USAGE and HELP type: "
|
std::cerr << std::endl << "For complete USAGE and HELP type: "
|
||||||
<< std::endl << " " << progName << " --help"
|
<< std::endl << " " << progName << " --help"
|
||||||
<< std::endl << std::endl;
|
<< std::endl << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
usage(_cmd);
|
usage(_cmd);
|
||||||
|
|
||||||
throw ExitException(1);
|
throw ExitException(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,9 +150,7 @@ StdOutput::_shortUsage( CmdLineInterface& _cmd,
|
|||||||
std::string progName = _cmd.getProgramName();
|
std::string progName = _cmd.getProgramName();
|
||||||
XorHandler xorHandler = _cmd.getXorHandler();
|
XorHandler xorHandler = _cmd.getXorHandler();
|
||||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||||
|
|
||||||
std::string s = progName + " ";
|
std::string s = progName + " ";
|
||||||
|
|
||||||
// first the xor
|
// first the xor
|
||||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||||
{
|
{
|
||||||
@@ -170,20 +158,16 @@ StdOutput::_shortUsage( CmdLineInterface& _cmd,
|
|||||||
for ( ArgVectorIterator it = xorList[i].begin();
|
for ( ArgVectorIterator it = xorList[i].begin();
|
||||||
it != xorList[i].end(); it++ )
|
it != xorList[i].end(); it++ )
|
||||||
s += (*it)->shortID() + "|";
|
s += (*it)->shortID() + "|";
|
||||||
|
|
||||||
s[s.length()-1] = '}';
|
s[s.length()-1] = '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
// then the rest
|
// then the rest
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
if ( !xorHandler.contains( (*it) ) )
|
if ( !xorHandler.contains( (*it) ) )
|
||||||
s += " " + (*it)->shortID();
|
s += " " + (*it)->shortID();
|
||||||
|
|
||||||
// if the program name is too long, then adjust the second line offset
|
// if the program name is too long, then adjust the second line offset
|
||||||
int secondLineOffset = static_cast<int>(progName.length()) + 2;
|
int secondLineOffset = static_cast<int>(progName.length()) + 2;
|
||||||
if ( secondLineOffset > 75/2 )
|
if ( secondLineOffset > 75/2 )
|
||||||
secondLineOffset = static_cast<int>(75/2);
|
secondLineOffset = static_cast<int>(75/2);
|
||||||
|
|
||||||
spacePrint( os, s, 75, 3, secondLineOffset );
|
spacePrint( os, s, 75, 3, secondLineOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +179,6 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
|||||||
std::string message = _cmd.getMessage();
|
std::string message = _cmd.getMessage();
|
||||||
XorHandler xorHandler = _cmd.getXorHandler();
|
XorHandler xorHandler = _cmd.getXorHandler();
|
||||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||||
|
|
||||||
// first the xor
|
// first the xor
|
||||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||||
{
|
{
|
||||||
@@ -205,13 +188,11 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
|||||||
{
|
{
|
||||||
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
||||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||||
|
|
||||||
if ( it+1 != xorList[i].end() )
|
if ( it+1 != xorList[i].end() )
|
||||||
spacePrint(os, "-- OR --", 75, 9, 0);
|
spacePrint(os, "-- OR --", 75, 9, 0);
|
||||||
}
|
}
|
||||||
os << std::endl << std::endl;
|
os << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then the rest
|
// then the rest
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
if ( !xorHandler.contains( (*it) ) )
|
if ( !xorHandler.contains( (*it) ) )
|
||||||
@@ -220,9 +201,7 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
|||||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
spacePrint( os, message, 75, 3, 0 );
|
spacePrint( os, message, 75, 3, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +212,6 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
|||||||
int secondLineOffset ) const
|
int secondLineOffset ) const
|
||||||
{
|
{
|
||||||
int len = static_cast<int>(s.length());
|
int len = static_cast<int>(s.length());
|
||||||
|
|
||||||
if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
|
if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
|
||||||
{
|
{
|
||||||
int allowedLen = maxWidth - indentSpaces;
|
int allowedLen = maxWidth - indentSpaces;
|
||||||
@@ -245,7 +223,6 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
|||||||
// doing it this way to support a VisualC++ 2005 bug
|
// doing it this way to support a VisualC++ 2005 bug
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int stringLen = min<int>( len - start, allowedLen );
|
int stringLen = min<int>( len - start, allowedLen );
|
||||||
|
|
||||||
// trim the length so it doesn't end in middle of a word
|
// trim the length so it doesn't end in middle of a word
|
||||||
if ( stringLen == allowedLen )
|
if ( stringLen == allowedLen )
|
||||||
while ( stringLen >= 0 &&
|
while ( stringLen >= 0 &&
|
||||||
@@ -253,36 +230,28 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
|||||||
s[stringLen+start] != ',' &&
|
s[stringLen+start] != ',' &&
|
||||||
s[stringLen+start] != '|' )
|
s[stringLen+start] != '|' )
|
||||||
stringLen--;
|
stringLen--;
|
||||||
|
|
||||||
// ok, the word is longer than the line, so just split
|
// ok, the word is longer than the line, so just split
|
||||||
// wherever the line ends
|
// wherever the line ends
|
||||||
if ( stringLen <= 0 )
|
if ( stringLen <= 0 )
|
||||||
stringLen = allowedLen;
|
stringLen = allowedLen;
|
||||||
|
|
||||||
// check for newlines
|
// check for newlines
|
||||||
for ( int i = 0; i < stringLen; i++ )
|
for ( int i = 0; i < stringLen; i++ )
|
||||||
if ( s[start+i] == '\n' )
|
if ( s[start+i] == '\n' )
|
||||||
stringLen = i+1;
|
stringLen = i+1;
|
||||||
|
|
||||||
// print the indent
|
// print the indent
|
||||||
for ( int i = 0; i < indentSpaces; i++ )
|
for ( int i = 0; i < indentSpaces; i++ )
|
||||||
os << " ";
|
os << " ";
|
||||||
|
|
||||||
if ( start == 0 )
|
if ( start == 0 )
|
||||||
{
|
{
|
||||||
// handle second line offsets
|
// handle second line offsets
|
||||||
indentSpaces += secondLineOffset;
|
indentSpaces += secondLineOffset;
|
||||||
|
|
||||||
// adjust allowed len
|
// adjust allowed len
|
||||||
allowedLen -= secondLineOffset;
|
allowedLen -= secondLineOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << s.substr(start,stringLen) << std::endl;
|
os << s.substr(start,stringLen) << std::endl;
|
||||||
|
|
||||||
// so we don't start a line with a space
|
// so we don't start a line with a space
|
||||||
while ( s[stringLen+start] == ' ' && start < len )
|
while ( s[stringLen+start] == ' ' && start < len )
|
||||||
start++;
|
start++;
|
||||||
|
|
||||||
start += stringLen;
|
start += stringLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
|
|
||||||
#include "Arg.h"
|
#include "Arg.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple switch argument. If the switch is set on the command line, then
|
* A simple switch argument. If the switch is set on the command line, then
|
||||||
@@ -155,14 +156,16 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
|||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool SwitchArg::getValue() { return _value; }
|
inline bool SwitchArg::getValue()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||||
if ( combinedSwitches[i] != Arg::blankChar() )
|
if ( combinedSwitches[i] != Arg::blankChar() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,16 +175,13 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
|||||||
if ( combinedSwitches.length() > 0 &&
|
if ( combinedSwitches.length() > 0 &&
|
||||||
combinedSwitches[0] != Arg::flagStartString()[0] )
|
combinedSwitches[0] != Arg::flagStartString()[0] )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// make sure it isn't a long name
|
// make sure it isn't a long name
|
||||||
if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
|
if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
|
||||||
Arg::nameStartString() )
|
Arg::nameStartString() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// make sure the delimiter isn't in the string
|
// make sure the delimiter isn't in the string
|
||||||
if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos )
|
if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ok, we're not specifying a ValueArg, so we know that we have
|
// ok, we're not specifying a ValueArg, so we know that we have
|
||||||
// a combined switch list.
|
// a combined switch list.
|
||||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||||
@@ -196,7 +196,6 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
|||||||
combinedSwitches[i] = Arg::blankChar();
|
combinedSwitches[i] = Arg::blankChar();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// none of the switches passed in the list match.
|
// none of the switches passed in the list match.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -206,17 +205,13 @@ inline void SwitchArg::commonProcessing()
|
|||||||
if ( _xorSet )
|
if ( _xorSet )
|
||||||
throw(CmdLineParseException(
|
throw(CmdLineParseException(
|
||||||
"Mutually exclusive argument already set!", toString()));
|
"Mutually exclusive argument already set!", toString()));
|
||||||
|
|
||||||
if ( _alreadySet )
|
if ( _alreadySet )
|
||||||
throw(CmdLineParseException("Argument already set!", toString()));
|
throw(CmdLineParseException("Argument already set!", toString()));
|
||||||
|
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
|
|
||||||
if ( _value == true )
|
if ( _value == true )
|
||||||
_value = false;
|
_value = false;
|
||||||
else
|
else
|
||||||
_value = true;
|
_value = true;
|
||||||
|
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,12 +219,10 @@ inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
|||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if the whole string matches the flag or name string
|
// if the whole string matches the flag or name string
|
||||||
if ( argMatches( args[*i] ) )
|
if ( argMatches( args[*i] ) )
|
||||||
{
|
{
|
||||||
commonProcessing();
|
commonProcessing();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if a substring matches the flag as part of a combination
|
// if a substring matches the flag as part of a combination
|
||||||
@@ -240,9 +233,7 @@ inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
|||||||
if ( combinedSwitchesMatch( args[*i] ) )
|
if ( combinedSwitchesMatch( args[*i] ) )
|
||||||
throw(CmdLineParseException("Argument already set!",
|
throw(CmdLineParseException("Argument already set!",
|
||||||
toString()));
|
toString()));
|
||||||
|
|
||||||
commonProcessing();
|
commonProcessing();
|
||||||
|
|
||||||
// We only want to return true if we've found the last combined
|
// We only want to return true if we've found the last combined
|
||||||
// match in the string, otherwise we return true so that other
|
// match in the string, otherwise we return true so that other
|
||||||
// switches in the combination will have a chance to match.
|
// switches in the combination will have a chance to match.
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
#include "MultiArg.h"
|
#include "MultiArg.h"
|
||||||
#include "OptionalUnlabeledTracker.h"
|
#include "OptionalUnlabeledTracker.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just like a MultiArg, except that the arguments are unlabeled. Basically,
|
* Just like a MultiArg, except that the arguments are unlabeled. Basically,
|
||||||
@@ -244,16 +245,11 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
|||||||
template<class T>
|
template<class T>
|
||||||
bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( _hasBlanks( args[*i] ) )
|
if ( _hasBlanks( args[*i] ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// never ignore an unlabeled multi arg
|
// never ignore an unlabeled multi arg
|
||||||
|
|
||||||
|
|
||||||
// always take the first value, regardless of the start string
|
// always take the first value, regardless of the start string
|
||||||
_extractValue( args[(*i)] );
|
_extractValue( args[(*i)] );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// continue taking args until we hit the end or a start string
|
// continue taking args until we hit the end or a start string
|
||||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||||
@@ -261,9 +257,7 @@ bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||||
_extractValue( args[++(*i)] );
|
_extractValue( args[++(*i)] );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,8 @@
|
|||||||
#include "OptionalUnlabeledTracker.h"
|
#include "OptionalUnlabeledTracker.h"
|
||||||
|
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The basic unlabeled argument that parses a value.
|
* The basic unlabeled argument that parses a value.
|
||||||
@@ -220,9 +221,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
|
||||||
OptionalUnlabeledTracker::check(req, toString());
|
OptionalUnlabeledTracker::check(req, toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -280,15 +279,11 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
template<class T>
|
template<class T>
|
||||||
bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( _alreadySet )
|
if ( _alreadySet )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( _hasBlanks( args[*i] ) )
|
if ( _hasBlanks( args[*i] ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// never ignore an unlabeled arg
|
// never ignore an unlabeled arg
|
||||||
|
|
||||||
_extractValue( args[*i] );
|
_extractValue( args[*i] );
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -311,7 +306,6 @@ template<class T>
|
|||||||
std::string UnlabeledValueArg<T>::longID(const std::string& val) const
|
std::string UnlabeledValueArg<T>::longID(const std::string& val) const
|
||||||
{
|
{
|
||||||
static_cast<void>(val); // Ignore input, don't warn
|
static_cast<void>(val); // Ignore input, don't warn
|
||||||
|
|
||||||
// Ideally we would like to be able to use RTTI to return the name
|
// Ideally we would like to be able to use RTTI to return the name
|
||||||
// of the type required for this argument. However, g++ at least,
|
// of the type required for this argument. However, g++ at least,
|
||||||
// doesn't appear to return terribly useful "names" of the types.
|
// doesn't appear to return terribly useful "names" of the types.
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
#include "Arg.h"
|
#include "Arg.h"
|
||||||
#include "Constraint.h"
|
#include "Constraint.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The basic labeled argument that parses a value.
|
* The basic labeled argument that parses a value.
|
||||||
@@ -319,7 +320,10 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
|||||||
* Implementation of getValue().
|
* Implementation of getValue().
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
T& ValueArg<T>::getValue() { return _value; }
|
T& ValueArg<T>::getValue()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of processArg().
|
* Implementation of processArg().
|
||||||
@@ -329,15 +333,11 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( _hasBlanks( args[*i] ) )
|
if ( _hasBlanks( args[*i] ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string flag = args[*i];
|
std::string flag = args[*i];
|
||||||
|
|
||||||
std::string value = "";
|
std::string value = "";
|
||||||
trimFlag( flag, value );
|
trimFlag( flag, value );
|
||||||
|
|
||||||
if ( argMatches( flag ) )
|
if ( argMatches( flag ) )
|
||||||
{
|
{
|
||||||
if ( _alreadySet )
|
if ( _alreadySet )
|
||||||
@@ -350,12 +350,10 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
throw( CmdLineParseException("Argument already set!",
|
throw( CmdLineParseException("Argument already set!",
|
||||||
toString()) );
|
toString()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Arg::delimiter() != ' ' && value == "" )
|
if ( Arg::delimiter() != ' ' && value == "" )
|
||||||
throw( ArgParseException(
|
throw( ArgParseException(
|
||||||
"Couldn't find delimiter for this argument!",
|
"Couldn't find delimiter for this argument!",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
|
|
||||||
if ( value == "" )
|
if ( value == "" )
|
||||||
{
|
{
|
||||||
(*i)++;
|
(*i)++;
|
||||||
@@ -367,7 +365,6 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
_extractValue( value );
|
_extractValue( value );
|
||||||
|
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
return true;
|
return true;
|
||||||
@@ -399,12 +396,14 @@ std::string ValueArg<T>::longID(const std::string& val) const
|
|||||||
template<class T>
|
template<class T>
|
||||||
void ValueArg<T>::_extractValue( const std::string& val )
|
void ValueArg<T>::_extractValue( const std::string& val )
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
|
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
|
||||||
} catch( ArgParseException &e) {
|
}
|
||||||
|
catch( ArgParseException &e)
|
||||||
|
{
|
||||||
throw ArgParseException(e.error(), toString());
|
throw ArgParseException(e.error(), toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _constraint != NULL )
|
if ( _constraint != NULL )
|
||||||
if ( ! _constraint->check( _value ) )
|
if ( ! _constraint->check( _value ) )
|
||||||
throw( CmdLineParseException( "Value '" + val +
|
throw( CmdLineParseException( "Value '" + val +
|
||||||
|
@@ -41,7 +41,8 @@
|
|||||||
#error "Need a stringstream (sstream or strstream) to compile!"
|
#error "Need a stringstream (sstream or strstream) to compile!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Constraint that constrains the Arg to only those values specified
|
* A Constraint that constrains the Arg to only those values specified
|
||||||
@@ -102,7 +103,6 @@ ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
|
|||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < _allowed.size(); i++ )
|
for ( unsigned int i = 0; i < _allowed.size(); i++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
#if defined(HAVE_SSTREAM)
|
#if defined(HAVE_SSTREAM)
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#elif defined(HAVE_STRSTREAM)
|
#elif defined(HAVE_STRSTREAM)
|
||||||
@@ -110,11 +110,8 @@ ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
|
|||||||
#else
|
#else
|
||||||
#error "Need a stringstream (sstream or strstream) to compile!"
|
#error "Need a stringstream (sstream or strstream) to compile!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
os << _allowed[i];
|
os << _allowed[i];
|
||||||
|
|
||||||
std::string temp( os.str() );
|
std::string temp( os.str() );
|
||||||
|
|
||||||
if ( i > 0 )
|
if ( i > 0 )
|
||||||
_typeDesc += "|";
|
_typeDesc += "|";
|
||||||
_typeDesc += temp;
|
_typeDesc += temp;
|
||||||
|
@@ -28,7 +28,8 @@
|
|||||||
#include "CmdLineOutput.h"
|
#include "CmdLineOutput.h"
|
||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Vistor that will call the version method of the given CmdLineOutput
|
* A Vistor that will call the version method of the given CmdLineOutput
|
||||||
@@ -69,7 +70,8 @@ class VersionVisitor: public Visitor
|
|||||||
* Calls the version method of the output object using the
|
* Calls the version method of the output object using the
|
||||||
* specified CmdLine.
|
* specified CmdLine.
|
||||||
*/
|
*/
|
||||||
void visit() {
|
void visit()
|
||||||
|
{
|
||||||
(*_out)->version(*_cmd);
|
(*_out)->version(*_cmd);
|
||||||
throw ExitException(0);
|
throw ExitException(0);
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,8 @@
|
|||||||
#ifndef TCLAP_VISITOR_H
|
#ifndef TCLAP_VISITOR_H
|
||||||
#define TCLAP_VISITOR_H
|
#define TCLAP_VISITOR_H
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base class that defines the interface for visitors.
|
* A base class that defines the interface for visitors.
|
||||||
|
@@ -29,7 +29,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handles lists of Arg's that are to be XOR'd on the command
|
* This class handles lists of Arg's that are to be XOR'd on the command
|
||||||
@@ -116,14 +117,12 @@ inline int XorHandler::check( const Arg* a )
|
|||||||
throw(CmdLineParseException(
|
throw(CmdLineParseException(
|
||||||
"Mutually exclusive argument already set!",
|
"Mutually exclusive argument already set!",
|
||||||
(*it)->toString()));
|
(*it)->toString()));
|
||||||
|
|
||||||
// go through and set each arg that is not a
|
// go through and set each arg that is not a
|
||||||
for ( ArgVectorIterator it = _orList[i].begin();
|
for ( ArgVectorIterator it = _orList[i].begin();
|
||||||
it != _orList[i].end();
|
it != _orList[i].end();
|
||||||
it++ )
|
it++ )
|
||||||
if ( a != (*it) )
|
if ( a != (*it) )
|
||||||
(*it)->xorSet();
|
(*it)->xorSet();
|
||||||
|
|
||||||
// return the number of required args that have now been set
|
// return the number of required args that have now been set
|
||||||
if ( (*ait)->allowMore() )
|
if ( (*ait)->allowMore() )
|
||||||
return 0;
|
return 0;
|
||||||
@@ -131,7 +130,6 @@ inline int XorHandler::check( const Arg* a )
|
|||||||
return static_cast<int>(_orList[i].size());
|
return static_cast<int>(_orList[i].size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( a->isRequired() )
|
if ( a->isRequired() )
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
@@ -146,7 +144,6 @@ inline bool XorHandler::contains( const Arg* a )
|
|||||||
it++ )
|
it++ )
|
||||||
if ( a == (*it) )
|
if ( a == (*it) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,8 @@
|
|||||||
#include <tclap/XorHandler.h>
|
#include <tclap/XorHandler.h>
|
||||||
#include <tclap/Arg.h>
|
#include <tclap/Arg.h>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that generates a Zsh completion function as output from the usage()
|
* A class that generates a Zsh completion function as output from the usage()
|
||||||
@@ -110,11 +111,9 @@ inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd )
|
|||||||
std::string xversion = _cmd.getVersion();
|
std::string xversion = _cmd.getVersion();
|
||||||
theDelimiter = _cmd.getDelimiter();
|
theDelimiter = _cmd.getDelimiter();
|
||||||
basename(progName);
|
basename(progName);
|
||||||
|
|
||||||
std::cout << "#compdef " << progName << std::endl << std::endl <<
|
std::cout << "#compdef " << progName << std::endl << std::endl <<
|
||||||
"# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl <<
|
"# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl <<
|
||||||
"_arguments -s -S";
|
"_arguments -s -S";
|
||||||
|
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
{
|
{
|
||||||
if ( (*it)->shortID().at(0) == '<' )
|
if ( (*it)->shortID().at(0) == '<' )
|
||||||
@@ -122,7 +121,6 @@ inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd )
|
|||||||
else if ( (*it)->getFlag() != "-" )
|
else if ( (*it)->getFlag() != "-" )
|
||||||
printOption((*it), getMutexList(_cmd, *it));
|
printOption((*it), getMutexList(_cmd, *it));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +162,6 @@ inline void ZshCompletionOutput::basename( std::string& s )
|
|||||||
inline void ZshCompletionOutput::printArg(Arg* a)
|
inline void ZshCompletionOutput::printArg(Arg* a)
|
||||||
{
|
{
|
||||||
static int count = 1;
|
static int count = 1;
|
||||||
|
|
||||||
std::cout << " \\" << std::endl << " '";
|
std::cout << " \\" << std::endl << " '";
|
||||||
if ( a->acceptsMultipleValues() )
|
if ( a->acceptsMultipleValues() )
|
||||||
std::cout << '*';
|
std::cout << '*';
|
||||||
@@ -173,7 +170,6 @@ inline void ZshCompletionOutput::printArg(Arg* a)
|
|||||||
std::cout << ':';
|
std::cout << ':';
|
||||||
if ( !a->isRequired() )
|
if ( !a->isRequired() )
|
||||||
std::cout << ':';
|
std::cout << ':';
|
||||||
|
|
||||||
std::cout << a->getName() << ':';
|
std::cout << a->getName() << ':';
|
||||||
std::map<std::string, std::string>::iterator compArg = common.find(a->getName());
|
std::map<std::string, std::string>::iterator compArg = common.find(a->getName());
|
||||||
if ( compArg != common.end() )
|
if ( compArg != common.end() )
|
||||||
@@ -192,7 +188,6 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
|||||||
std::string flag = a->flagStartChar() + a->getFlag();
|
std::string flag = a->flagStartChar() + a->getFlag();
|
||||||
std::string name = a->nameStartString() + a->getName();
|
std::string name = a->nameStartString() + a->getName();
|
||||||
std::string desc = a->getDescription();
|
std::string desc = a->getDescription();
|
||||||
|
|
||||||
// remove full stop and capitalisation from description as
|
// remove full stop and capitalisation from description as
|
||||||
// this is the convention for zsh function
|
// this is the convention for zsh function
|
||||||
if (!desc.compare(0, 12, "(required) "))
|
if (!desc.compare(0, 12, "(required) "))
|
||||||
@@ -212,9 +207,7 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
|||||||
{
|
{
|
||||||
desc.replace(0, 1, 1, tolower(desc.at(0)));
|
desc.replace(0, 1, 1, tolower(desc.at(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << " \\" << std::endl << " '" << mutex;
|
std::cout << " \\" << std::endl << " '" << mutex;
|
||||||
|
|
||||||
if ( a->getFlag().empty() )
|
if ( a->getFlag().empty() )
|
||||||
{
|
{
|
||||||
std::cout << name;
|
std::cout << name;
|
||||||
@@ -227,7 +220,6 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
|||||||
std::cout << "=-";
|
std::cout << "=-";
|
||||||
quoteSpecialChars(desc);
|
quoteSpecialChars(desc);
|
||||||
std::cout << '[' << desc << ']';
|
std::cout << '[' << desc << ']';
|
||||||
|
|
||||||
if ( a->isValueRequired() )
|
if ( a->isValueRequired() )
|
||||||
{
|
{
|
||||||
std::string arg = a->shortID();
|
std::string arg = a->shortID();
|
||||||
@@ -264,7 +256,6 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << '\'';
|
std::cout << '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,18 +263,15 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar
|
|||||||
{
|
{
|
||||||
XorHandler xorHandler = _cmd.getXorHandler();
|
XorHandler xorHandler = _cmd.getXorHandler();
|
||||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||||
|
|
||||||
if (a->getName() == "help" || a->getName() == "version")
|
if (a->getName() == "help" || a->getName() == "version")
|
||||||
{
|
{
|
||||||
return "(-)";
|
return "(-)";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream list;
|
std::ostringstream list;
|
||||||
if ( a->acceptsMultipleValues() )
|
if ( a->acceptsMultipleValues() )
|
||||||
{
|
{
|
||||||
list << '*';
|
list << '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||||
{
|
{
|
||||||
for ( ArgVectorIterator it = xorList[i].begin();
|
for ( ArgVectorIterator it = xorList[i].begin();
|
||||||
@@ -309,13 +297,12 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar
|
|||||||
return list.str();
|
return list.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wasn't found in xor list
|
// wasn't found in xor list
|
||||||
if (!a->getFlag().empty()) {
|
if (!a->getFlag().empty())
|
||||||
|
{
|
||||||
list << "(" << a->flagStartChar() << a->getFlag() << ' ' <<
|
list << "(" << a->flagStartChar() << a->getFlag() << ' ' <<
|
||||||
a->nameStartString() << a->getName() << ')';
|
a->nameStartString() << a->getName() << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
return list.str();
|
return list.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user