You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(19) |
Nov
(45) |
Dec
(80) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(58) |
Feb
(127) |
Mar
(74) |
Apr
(34) |
May
(117) |
Jun
(14) |
Jul
(26) |
Aug
(13) |
Sep
(1) |
Oct
(38) |
Nov
(13) |
Dec
(5) |
| 2005 |
Jan
(108) |
Feb
(134) |
Mar
(54) |
Apr
(133) |
May
(16) |
Jun
(54) |
Jul
(128) |
Aug
(99) |
Sep
(157) |
Oct
(182) |
Nov
(236) |
Dec
(212) |
| 2006 |
Jan
(86) |
Feb
(76) |
Mar
(121) |
Apr
(27) |
May
(7) |
Jun
(1) |
Jul
(6) |
Aug
(28) |
Sep
(1) |
Oct
(27) |
Nov
(5) |
Dec
|
| 2007 |
Jan
(32) |
Feb
(22) |
Mar
(22) |
Apr
(11) |
May
(3) |
Jun
(12) |
Jul
(11) |
Aug
(9) |
Sep
(37) |
Oct
(4) |
Nov
(9) |
Dec
(51) |
| 2008 |
Jan
(7) |
Feb
(31) |
Mar
(46) |
Apr
(31) |
May
(5) |
Jun
(27) |
Jul
(12) |
Aug
(5) |
Sep
(13) |
Oct
(24) |
Nov
(112) |
Dec
(15) |
| 2009 |
Jan
(6) |
Feb
(103) |
Mar
(66) |
Apr
(9) |
May
(8) |
Jun
(1) |
Jul
(20) |
Aug
(9) |
Sep
(2) |
Oct
(81) |
Nov
(88) |
Dec
(30) |
| 2010 |
Jan
(65) |
Feb
(57) |
Mar
(22) |
Apr
(12) |
May
(4) |
Jun
(12) |
Jul
(43) |
Aug
(6) |
Sep
(6) |
Oct
(4) |
Nov
(6) |
Dec
(3) |
| 2011 |
Jan
(10) |
Feb
(27) |
Mar
(11) |
Apr
(9) |
May
(69) |
Jun
(73) |
Jul
(67) |
Aug
(116) |
Sep
(40) |
Oct
(11) |
Nov
(34) |
Dec
(19) |
| 2012 |
Jan
|
Feb
(4) |
Mar
(28) |
Apr
(18) |
May
(9) |
Jun
(7) |
Jul
(4) |
Aug
(155) |
Sep
(264) |
Oct
(172) |
Nov
(15) |
Dec
(40) |
| 2013 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
(20) |
Jul
(76) |
Aug
(67) |
Sep
(49) |
Oct
(27) |
Nov
(3) |
Dec
(3) |
| 2014 |
Jan
(7) |
Feb
(7) |
Mar
(16) |
Apr
|
May
(4) |
Jun
(1) |
Jul
(18) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2015 |
Jan
(6) |
Feb
(5) |
Mar
(3) |
Apr
(23) |
May
(5) |
Jun
|
Jul
(2) |
Aug
(4) |
Sep
|
Oct
|
Nov
(2) |
Dec
(4) |
| 2016 |
Jan
(2) |
Feb
(7) |
Mar
(2) |
Apr
(1) |
May
(14) |
Jun
(3) |
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(1) |
Dec
(3) |
| 2017 |
Jan
(6) |
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(12) |
Sep
(6) |
Oct
|
Nov
(3) |
Dec
|
| 2018 |
Jan
(4) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(8) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2019 |
Jan
|
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
(8) |
Oct
|
Nov
(2) |
Dec
(25) |
| 2020 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
(53) |
Nov
(33) |
Dec
|
| 2021 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
(5) |
| 2022 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
(93) |
Aug
(206) |
Sep
(39) |
Oct
(19) |
Nov
(11) |
Dec
|
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
(150) |
Jul
(124) |
Aug
(14) |
Sep
(5) |
Oct
|
Nov
(1) |
Dec
|
| 2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(12) |
Jul
(62) |
Aug
|
Sep
(7) |
Oct
|
Nov
(7) |
Dec
|
| 2025 |
Jan
|
Feb
|
Mar
|
Apr
(14) |
May
(3) |
Jun
|
Jul
|
Aug
(76) |
Sep
(214) |
Oct
(6) |
Nov
|
Dec
|
|
From: <kin...@us...> - 2023-07-07 20:26:42
|
Revision: 7036
http://sourceforge.net/p/teem/code/7036
Author: kindlmann
Date: 2023-07-07 20:26:40 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
hestOpt->parmStr was added recently
Modified Paths:
--------------
teem/trunk/src/hest/TODO.txt
Modified: teem/trunk/src/hest/TODO.txt
===================================================================
--- teem/trunk/src/hest/TODO.txt 2023-07-07 20:24:42 UTC (rev 7035)
+++ teem/trunk/src/hest/TODO.txt 2023-07-07 20:26:40 UTC (rev 7036)
@@ -1,11 +1,3 @@
-How is it that, once the command-line has been parsed, there isn't an
-easy way to see (or print, for an error message) the parameter (or
-concatenation of parameters) that was passed for a given option?
-Want to be able to have error messages like "you passed %s to the -i
-option but that has a problem: ..."
-Should add a new output field in hestOpt, alongside "source",
-to store this new single string.
-
for super long things like "tend glyph", it would be nice to have
seperator lines between the long versions of options, to visually
group them somewhat.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 20:24:44
|
Revision: 7035
http://sourceforge.net/p/teem/code/7035
Author: kindlmann
Date: 2023-07-07 20:24:42 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
more work on type-checked adders, and, propagating AIR_STRLEN change
Modified Paths:
--------------
teem/trunk/src/hest/adders.c
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/parseHest.c
teem/trunk/src/hest/test/ex6.c
teem/trunk/src/hest/usage.c
Modified: teem/trunk/src/hest/adders.c
===================================================================
--- teem/trunk/src/hest/adders.c 2023-07-07 20:01:09 UTC (rev 7034)
+++ teem/trunk/src/hest/adders.c 2023-07-07 20:24:42 UTC (rev 7035)
@@ -34,73 +34,92 @@
/* --------------------------------------------------------------- 2 == kind */
unsigned int
hestOptAdd_1_Bool(hestOpt **optP, const char *flag, const char *name, /* */
- int *valueP, const char *dflt, const char *info) {
+ int *valueP, int dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%s", airEnumStr(airBool, !!dflt));
return hestOptAdd_nva(optP, flag, name, airTypeBool, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_Int(hestOpt **optP, const char *flag, const char *name, /* */
- int *valueP, const char *dflt, const char *info) {
+ int *valueP, int dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%d", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeInt, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_UInt(hestOpt **optP, const char *flag, const char *name, /* */
- unsigned int *valueP, const char *dflt, const char *info) {
+ unsigned int *valueP, unsigned int dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%u", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeUInt, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_LongInt(hestOpt **optP, const char *flag, const char *name, /* */
- long int *valueP, const char *dflt, const char *info) {
+ long int *valueP, long int dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%ld", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeLongInt, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_ULongInt(hestOpt **optP, const char *flag, const char *name, /* */
- unsigned long int *valueP, const char *dflt, const char *info) {
+ unsigned long int *valueP, unsigned long int dflt,
+ const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%lu", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeULongInt, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_Size_t(hestOpt **optP, const char *flag, const char *name, /* */
- size_t *valueP, const char *dflt, const char *info) {
+ size_t *valueP, size_t dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ airSprintSize_t(dfltStr, dflt);
return hestOptAdd_nva(optP, flag, name, airTypeSize_t, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_Float(hestOpt **optP, const char *flag, const char *name, /* */
- float *valueP, const char *dflt, const char *info) {
+ float *valueP, float dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ airSinglePrintf(NULL, dfltStr, "%g", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeFloat, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_Double(hestOpt **optP, const char *flag, const char *name, /* */
- double *valueP, const char *dflt, const char *info) {
+ double *valueP, double dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ airSinglePrintf(NULL, dfltStr, "%lg", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeDouble, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
unsigned int
hestOptAdd_1_Char(hestOpt **optP, const char *flag, const char *name, /* */
- char *valueP, const char *dflt, const char *info) {
+ char *valueP, char dflt, const char *info) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ sprintf(dfltStr, "%c", dflt);
return hestOptAdd_nva(optP, flag, name, airTypeChar, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, NULL, NULL);
}
@@ -114,10 +133,12 @@
unsigned int
hestOptAdd_1_Enum(hestOpt **optP, const char *flag, const char *name, /* */
- int *valueP, const char *dflt, const char *info, /* */
+ int *valueP, int dflt, const char *info, /* */
const airEnum *enm) {
+ char dfltStr[AIR_STRLEN_SMALL + 1];
+ airStrcpy(dfltStr, AIR_STRLEN_SMALL + 1, airEnumStr(enm, dflt));
return hestOptAdd_nva(optP, flag, name, airTypeEnum, 1, 1, /* */
- valueP, dflt, info, /* */
+ valueP, dfltStr, info, /* */
NULL, enm, NULL);
}
@@ -129,7 +150,107 @@
valueP, dflt, info, /* */
NULL, NULL, CB);
}
+#if 0
+/* --------------------------------------------------------------- 2 == kind */
+unsigned int
+hestOptAdd_2_Bool(hestOpt **optP, const char *flag, const char *name, /* */
+ int valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeBool, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+unsigned int
+hestOptAdd_2_Int(hestOpt **optP, const char *flag, const char *name, /* */
+ int valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeInt, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_UInt(hestOpt **optP, const char *flag, const char *name, /* */
+ unsigned int valueP[3], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeUInt, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_LongInt(hestOpt **optP, const char *flag, const char *name, /* */
+ long int valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeLongInt, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_ULongInt(hestOpt **optP, const char *flag, const char *name, /* */
+ unsigned long int valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeULongInt, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Size_t(hestOpt **optP, const char *flag, const char *name, /* */
+ size_t valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeSize_t, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Float(hestOpt **optP, const char *flag, const char *name, /* */
+ float valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeFloat, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Double(hestOpt **optP, const char *flag, const char *name, /* */
+ double valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeDouble, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Char(hestOpt **optP, const char *flag, const char *name, /* */
+ char valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeChar, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_String(hestOpt **optP, const char *flag, const char *name, /* */
+ char *valueP[2], const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeString, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Enum(hestOpt **optP, const char *flag, const char *name, /* */
+ int valueP[2], const char *dflt, const char *info, /* */
+ const airEnum *enm) {
+ return hestOptAdd_nva(optP, flag, name, airTypeEnum, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, enm, NULL);
+}
+
+unsigned int
+hestOptAdd_2_Other(hestOpt **optP, const char *flag, const char *name, /* */
+ void *valueP[2], const char *dflt, const char *info, /* */
+ const hestCB *CB) {
+ return hestOptAdd_nva(optP, flag, name, airTypeOther, 2, 2, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, CB);
+}
+
+#endif
/*
hestOptSetXX(hestOpt *opt, )
1<T>, 2<T>, 3<T>, 4<T>, N<T>
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-07 20:01:09 UTC (rev 7034)
+++ teem/trunk/src/hest/hest.h 2023-07-07 20:24:42 UTC (rev 7035)
@@ -71,7 +71,7 @@
typedef struct {
size_t size; /* sizeof() one thing */
const char *type; /* used by hestGlossary() to describe the type */
- int (*parse)(void *ptr, const char *str, char err[AIR_STRLEN_HUGE]);
+ int (*parse)(void *ptr, const char *str, char err[AIR_STRLEN_HUGE + 1]);
/* how to parse one thing from a string. This will be called multiple times for
multiple parameter options. A non-zero return value is considered an error. Error
message goes in the err string */
@@ -290,40 +290,39 @@
HEST_EXPORT unsigned int hestOptAdd_Flag(hestOpt **optP, const char *flag, int *valueP,
const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Bool(hestOpt **optP, const char *flag,
- const char *name, int *valueP,
- const char *dflt, const char *info);
+ const char *name, int *valueP, int dflt,
+ const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Int(hestOpt **optP, const char *flag,
- const char *name, int *valueP,
- const char *dflt, const char *info);
+ const char *name, int *valueP, int dflt,
+ const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_UInt(hestOpt **optP, const char *flag,
const char *name, unsigned int *valueP,
- const char *dflt, const char *info);
+ unsigned int dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_LongInt(hestOpt **optP, const char *flag,
const char *name, long int *valueP,
- const char *dflt, const char *info);
+ long int dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_ULongInt(hestOpt **optP, const char *flag,
const char *name,
unsigned long int *valueP,
- const char *dflt, const char *info);
+ unsigned long int dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Size_t(hestOpt **optP, const char *flag,
const char *name, size_t *valueP,
- const char *dflt, const char *info);
+ size_t dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Float(hestOpt **optP, const char *flag,
- const char *name, float *valueP,
- const char *dflt, const char *info);
+ const char *name, float *valueP, float dflt,
+ const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Double(hestOpt **optP, const char *flag,
const char *name, double *valueP,
- const char *dflt, const char *info);
+ double dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Char(hestOpt **optP, const char *flag,
- const char *name, char *valueP,
- const char *dflt, const char *info);
+ const char *name, char *valueP, char dflt,
+ const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_String(hestOpt **optP, const char *flag,
const char *name, char **valueP,
const char *dflt, const char *info);
HEST_EXPORT unsigned int hestOptAdd_1_Enum(hestOpt **optP, const char *flag,
- const char *name, int *valueP,
- const char *dflt, const char *info,
- const airEnum *enm);
+ const char *name, int *valueP, int dflt,
+ const char *info, const airEnum *enm);
HEST_EXPORT unsigned int hestOptAdd_1_Other(hestOpt **optP, const char *flag,
const char *name, void *valueP,
const char *dflt, const char *info,
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-07 20:01:09 UTC (rev 7034)
+++ teem/trunk/src/hest/parseHest.c 2023-07-07 20:24:42 UTC (rev 7035)
@@ -41,7 +41,7 @@
const hestParm *parm) {
FILE *file;
static const char me[] = "_hestArgsInResponseFiles: ";
- char line[AIR_STRLEN_HUGE], *pound;
+ char line[AIR_STRLEN_HUGE + 1], *pound;
int ai, len;
*argcP = 0;
@@ -65,7 +65,7 @@
*nrfP = 0;
return 1;
}
- len = airOneLine(file, line, AIR_STRLEN_HUGE);
+ len = airOneLine(file, line, AIR_STRLEN_HUGE + 1);
while (len > 0) {
if ((pound = strchr(line, parm->respFileComment))) {
*pound = '\0';
@@ -72,7 +72,7 @@
}
airOneLinify(line);
*argcP += airStrntok(line, AIR_WHITESPACE);
- len = airOneLine(file, line, AIR_STRLEN_HUGE);
+ len = airOneLine(file, line, AIR_STRLEN_HUGE + 1);
}
fclose(file); /* ok because file != stdin, see above */
(*nrfP)++;
@@ -132,7 +132,7 @@
copyArgv(int *sawHelp, char **newArgv, const char **oldArgv, const hestParm *parm,
airArray *pmop) {
static const char me[] = "copyArgv";
- char line[AIR_STRLEN_HUGE], *pound;
+ char line[AIR_STRLEN_HUGE + 1], *pound;
int len, newArgc, oldArgc, incr, ai;
FILE *file;
@@ -158,7 +158,7 @@
/* It is a response file. Error checking on open-ability
should have been done by _hestArgsInResponseFiles() */
file = fopen(oldArgv[oldArgc] + 1, "rb");
- len = airOneLine(file, line, AIR_STRLEN_HUGE);
+ len = airOneLine(file, line, AIR_STRLEN_HUGE + 1);
while (len > 0) {
if (parm->verbosity) printf("%s: line: |%s|\n", me, line);
/* HEY HEY too bad for you if you put # inside a string */
@@ -173,7 +173,7 @@
not airFreeP because these will not be reset before mopping */
airMopAdd(pmop, newArgv[newArgc + ai], airFree, airMopAlways);
}
- len = airOneLine(file, line, AIR_STRLEN_HUGE);
+ len = airOneLine(file, line, AIR_STRLEN_HUGE + 1);
newArgc += incr;
}
fclose(file);
@@ -199,7 +199,7 @@
int
_hestPanic(hestOpt *opt, char *err, const hestParm *parm) {
static const char me[] = "_hestPanic: ";
- char tbuff[AIR_STRLEN_HUGE], *sep;
+ char tbuff[AIR_STRLEN_HUGE + 1], *sep;
int numvar, op, numOpts;
numOpts = hestOptNum(opt);
@@ -424,8 +424,8 @@
}
if (other) {
/* the callback's error() function may sprintf an error message
- into a buffer which is size AIR_STRLEN_HUGE */
- ret += AIR_STRLEN_HUGE;
+ into a buffer which is size AIR_STRLEN_HUGE+1 */
+ ret += AIR_STRLEN_HUGE + 1;
}
ret += 4 * 12; /* as many as 4 ints per error message */
ret += 257; /* function name and text of hest's error message */
@@ -439,7 +439,7 @@
*/
static char *
identStr(char *ident, hestOpt *opt, const hestParm *parm, int brief) {
- char copy[AIR_STRLEN_HUGE], *sep;
+ char copy[AIR_STRLEN_HUGE + 1], *sep;
if (opt->flag && (sep = strchr(opt->flag, parm->multiFlagSep))) {
strcpy(copy, opt->flag);
@@ -467,7 +467,7 @@
static int
whichFlag(hestOpt *opt, char *flag, const hestParm *parm) {
static const char me[] = "whichFlag";
- char buff[2 * AIR_STRLEN_HUGE], copy[AIR_STRLEN_HUGE], *sep;
+ char buff[2 * AIR_STRLEN_HUGE + 1], copy[AIR_STRLEN_HUGE + 1], *sep;
int op, numOpts;
numOpts = hestOptNum(opt);
@@ -591,7 +591,7 @@
extractFlagged(char **prms, unsigned int *nprm, int *appr, int *argcP, char **argv,
hestOpt *opt, char *err, const hestParm *parm, airArray *pmop) {
static const char me[] = "extractFlagged: ";
- char ident1[AIR_STRLEN_HUGE], ident2[AIR_STRLEN_HUGE];
+ char ident1[AIR_STRLEN_HUGE + 1], ident2[AIR_STRLEN_HUGE + 1];
int a, np, flag, endflag, numOpts, op;
a = 0;
@@ -702,7 +702,7 @@
extractUnflagged(char **prms, unsigned int *nprm, int *argcP, char **argv, hestOpt *opt,
char *err, const hestParm *parm, airArray *pmop) {
static const char me[] = "extractUnflagged: ";
- char ident[AIR_STRLEN_HUGE];
+ char ident[AIR_STRLEN_HUGE + 1];
int nvp, np, op, unflag1st, unflagVar, numOpts;
numOpts = hestOptNum(opt);
@@ -810,7 +810,7 @@
_hestDefaults(char **prms, int *udflt, unsigned int *nprm, int *appr, hestOpt *opt,
char *err, const hestParm *parm, airArray *mop) {
static const char me[] = "_hestDefaults: ";
- char *tmpS, ident[AIR_STRLEN_HUGE];
+ char *tmpS, ident[AIR_STRLEN_HUGE + 1];
int op, numOpts;
numOpts = hestOptNum(opt);
@@ -984,7 +984,7 @@
setValues(char **prms, int *udflt, unsigned int *nprm, int *appr, hestOpt *opt,
char *err, const hestParm *parm, airArray *pmop) {
static const char me[] = "setValues: ";
- char ident[AIR_STRLEN_HUGE], cberr[AIR_STRLEN_HUGE], *tok, *last, *prmsCopy;
+ char ident[AIR_STRLEN_HUGE + 1], cberr[AIR_STRLEN_HUGE + 1], *tok, *last, *prmsCopy;
double tmpD;
int op, type, numOpts, p, ret;
void *vP;
@@ -1661,7 +1661,7 @@
why not check first? */
if (argv[0] && !strcmp(argv[0], "--version")) {
/* print version info and bail */
- char vbuff[AIR_STRLEN_LARGE];
+ char vbuff[AIR_STRLEN_LARGE + 1];
airTeemVersionSprint(vbuff);
printf("%s\n", vbuff);
hestParmFree(parm);
Modified: teem/trunk/src/hest/test/ex6.c
===================================================================
--- teem/trunk/src/hest/test/ex6.c 2023-07-07 20:01:09 UTC (rev 7034)
+++ teem/trunk/src/hest/test/ex6.c 2023-07-07 20:24:42 UTC (rev 7035)
@@ -22,6 +22,22 @@
#include "../hest.h"
int
+parse(void *_ptr, const char *str, char *err) {
+ double *ptr;
+ int ret;
+
+ ptr = _ptr;
+ ret = sscanf(str, "%lf,%lf", ptr + 0, ptr + 1);
+ if (2 != ret) {
+ sprintf(err, "parsed %d (not 2) doubles", ret);
+ return 1;
+ }
+ return 0;
+}
+
+hestCB posCB = {2 * sizeof(double), "location", parse, NULL};
+
+int
main(int argc, const char **argv) {
hestOpt *opt = NULL;
hestParm *parm;
@@ -41,37 +57,33 @@
int flag;
hestOptAdd_Flag(&opt, "f,flag", &flag, "a flag created via hestOptAdd_Flag");
int b1;
- hestOptAdd_1_Bool(&opt, "b1", "bool1", &b1, "false", "test of hestOptAdd_1_Bool");
+ hestOptAdd_1_Bool(&opt, "b1", "bool1", &b1, AIR_FALSE, "test of hestOptAdd_1_Bool");
int i1;
- hestOptAdd_1_Int(&opt, "i1", "int1", &i1, "42", "test of hestOptAdd_1_Int");
+ hestOptAdd_1_Int(&opt, "i1", "int1", &i1, 42, "test of hestOptAdd_1_Int");
unsigned int ui1;
- hestOptAdd_1_UInt(&opt, "ui1", "uint1", &ui1, "42", "test of hestOptAdd_1_UInt");
+ hestOptAdd_1_UInt(&opt, "ui1", "uint1", &ui1, 42, "test of hestOptAdd_1_UInt");
long int li1;
- hestOptAdd_1_LongInt(&opt, "li1", "lint1", &li1, "42", "test of hestOptAdd_1_LongInt");
+ hestOptAdd_1_LongInt(&opt, "li1", "lint1", &li1, 42, "test of hestOptAdd_1_LongInt");
unsigned long int uli1;
- hestOptAdd_1_ULongInt(&opt, "uli1", "ulint1", &uli1, "42",
+ hestOptAdd_1_ULongInt(&opt, "uli1", "ulint1", &uli1, 42,
"test of hestOptAdd_1_ULongInt");
size_t sz1;
- hestOptAdd_1_Size_t(&opt, "sz1", "size1", &sz1, "42", "test of hestOptAdd_1_Size_t");
+ hestOptAdd_1_Size_t(&opt, "sz1", "size1", &sz1, 42, "test of hestOptAdd_1_Size_t");
float fl1;
- hestOptAdd_1_Float(&opt, "fl1", "float1", &fl1, "4.2", "test of hestOptAdd_1_Float");
+ hestOptAdd_1_Float(&opt, "fl1", "float1", &fl1, 4.2f, "test of hestOptAdd_1_Float");
double db1;
- hestOptAdd_1_Double(&opt, "db1", "double1", &db1, "4.2",
- "test of hestOptAdd_1_Double");
+ hestOptAdd_1_Double(&opt, "db1", "double1", &db1, 4.2, "test of hestOptAdd_1_Double");
char c1;
- hestOptAdd_1_Char(&opt, "c1", "char1", &c1, "x", "test of hestOptAdd_1_Char");
+ hestOptAdd_1_Char(&opt, "c1", "char1", &c1, 'x', "test of hestOptAdd_1_Char");
char *s1;
- hestOptAdd_1_String(&opt, "s1", "string1", &s1, "bingo",
+ hestOptAdd_1_String(&opt, "s1", "string1", &s1, "bingo bob",
"test of hestOptAdd_1_String");
int e1;
- hestOptAdd_1_Enum(&opt, "e1", "enum1", &e1, "little", "test of hestOptAdd_1_Enum",
- airEndian);
- /*
-HEST_EXPORT unsigned int hestOptAdd_1_Other(hestOpt * *optP, const char *flag,
- const char *name, void *valueP,
- const char *dflt, const char *info,
- const hestCB *CB);
-*/
+ hestOptAdd_1_Enum(&opt, "e1", "enum1", &e1, airEndianLittle,
+ "test of hestOptAdd_1_Enum", airEndian);
+ double p1[2];
+ hestOptAdd_1_Other(&opt, "p1", "pos", &p1, "1.5,5.25", "test of hestOptAdd_1_Other",
+ &posCB);
if (1 == argc) {
/* didn't get anything at all on command line */
@@ -131,6 +143,7 @@
printf("c1 = %c\n", c1);
printf("s1 = %s\n", s1);
printf("e1 = %d\n", e1);
+ printf("p1 = %g,%g\n", p1[0], p1[1]);
/* free the memory allocated by parsing ... */
hestParseFree(opt);
Modified: teem/trunk/src/hest/usage.c
===================================================================
--- teem/trunk/src/hest/usage.c 2023-07-07 20:01:09 UTC (rev 7034)
+++ teem/trunk/src/hest/usage.c 2023-07-07 20:24:42 UTC (rev 7035)
@@ -27,7 +27,7 @@
*/
static void
_hestSetBuff(char *B, const hestOpt *O, const hestParm *P, int showshort, int showlong) {
- char copy[AIR_STRLEN_HUGE], *sep;
+ char copy[AIR_STRLEN_HUGE + 1], *sep;
int max;
unsigned int len;
@@ -230,7 +230,7 @@
void
hestUsage(FILE *f, hestOpt *opt, const char *argv0, const hestParm *_parm) {
int i, numOpts;
- char buff[2 * AIR_STRLEN_HUGE], tmpS[AIR_STRLEN_HUGE];
+ char buff[2 * AIR_STRLEN_HUGE + 1], tmpS[AIR_STRLEN_HUGE + 1];
hestParm *parm;
parm = _parm ? NULL : hestParmNew();
@@ -271,7 +271,7 @@
hestGlossary(FILE *f, hestOpt *opt, const hestParm *_parm) {
int i, j, maxlen, numOpts;
unsigned int len;
- char buff[2 * AIR_STRLEN_HUGE], tmpS[AIR_STRLEN_HUGE];
+ char buff[2 * AIR_STRLEN_HUGE + 1], tmpS[AIR_STRLEN_HUGE + 1];
hestParm *parm;
parm = _parm ? NULL : hestParmNew();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 20:01:12
|
Revision: 7034
http://sourceforge.net/p/teem/code/7034
Author: kindlmann
Date: 2023-07-07 20:01:09 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
Since r4961 2011-07-18, GLK has noted that the AIR_STRLEN #defines are illogical: they contain STRLEN but are not consistent with the results of strlen(). This was noted as something that would be fixed for Teem v2, so here we are. This is an API CHANGE: you will likely have to modify code that uses the AIR_STRLEN #defines (but because how the values are adjusted, it might just manage to not be an ABI change, but lets not get too clever). This change has yet to be propagated to other Teem libraries
Modified Paths:
--------------
teem/trunk/src/TODO.txt
teem/trunk/src/air/air.h
teem/trunk/src/air/dio.c
teem/trunk/src/air/enum.c
teem/trunk/src/air/miscAir.c
teem/trunk/src/air/sane.c
teem/trunk/src/air/string.c
teem/trunk/src/air/test/tdio.c
teem/trunk/src/air/test/tprint.c
Modified: teem/trunk/src/TODO.txt
===================================================================
--- teem/trunk/src/TODO.txt 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/TODO.txt 2023-07-07 20:01:09 UTC (rev 7034)
@@ -72,11 +72,8 @@
* consider changing airIndexULL and airIndexClampULL to work with
size_t instead of unsigned long long, or at least adding versions that
work with size_t
-* either change AIR_STRLEN_* to AIR_BUFFSIZE_* (or something similar,
-or take out the +1 from their definition and it into usage: the
-STRLEN is misleading as is.
******* consider terminating airEnum->strEqv with NULL (just like argv)
-instead of with empty string ""
+instead of with empty string "" (or allowing either NULL or "")
* make airOneLine return number of bytes read; current return
of string length is entirely redundant with return of strlen()
and then enable the ftell() check after PNG magic read
Modified: teem/trunk/src/air/air.h
===================================================================
--- teem/trunk/src/air/air.h 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/air.h 2023-07-07 20:01:09 UTC (rev 7034)
@@ -103,25 +103,16 @@
* but in many contexts the implementation complexity of handling them reliably is
* distracts from more urgent implementation goals. In the mean time, these can be used
* safely as long as the lengths are used consistently.
- *
- * The possibly unfortunate convention that has become established in Teem is code using
- * these tends to NOT add the +1 to explicitly indicate the space for 0-termination, and
- * instead assumes it is part of the numbers below, even though this is at the cost of
- * confusion about how the maximal strlen() will be less than each of
- * these numbers. This will be addressed in Teem 2.0.
- *
- * (NOTE: The +1 has been done manually here to assist the modest C parser used in
- * (Python module) cffi's FFI.cdef())
*/
-#define AIR_STRLEN_SMALL 129
+#define AIR_STRLEN_SMALL 128
/* SMALL has to be big enough to hold:
- printed value of size_t and
- ptrdiff_t, line of text that
- should contain file format "magic"
*/
-#define AIR_STRLEN_MED 257
-#define AIR_STRLEN_LARGE 513
-#define AIR_STRLEN_HUGE 1025
+#define AIR_STRLEN_MED 256
+#define AIR_STRLEN_LARGE 512
+#define AIR_STRLEN_HUGE 1024
/* HUGE has to be big enough to hold one line of biff error message */
/*
@@ -196,7 +187,7 @@
AIR_EXPORT char *airEnumFmtDesc(const airEnum *enm, int val, int canon, const char *fmt);
AIR_EXPORT void airEnumPrint(FILE *file, const airEnum *enm);
/* ---- BEGIN non-NrrdIO */
-AIR_EXPORT int airEnumCheck(char err[AIR_STRLEN_LARGE], const airEnum *enm);
+AIR_EXPORT int airEnumCheck(char err[AIR_STRLEN_LARGE + 1], const airEnum *enm);
/* ---- END non-NrrdIO */
/*
@@ -558,7 +549,7 @@
AIR_EXPORT const char *const airTeemVersion;
AIR_EXPORT const int airTeemReleaseDone;
AIR_EXPORT const char *const airTeemReleaseDate;
-AIR_EXPORT void airTeemVersionSprint(char buff[AIR_STRLEN_LARGE]);
+AIR_EXPORT void airTeemVersionSprint(char buff[AIR_STRLEN_LARGE + 1]);
AIR_EXPORT void *airNull(void);
AIR_EXPORT void *airSetNull(void **ptrP);
AIR_EXPORT void *airFree(void *ptr);
@@ -565,11 +556,11 @@
AIR_EXPORT FILE *airFopen(const char *name, FILE *std, const char *mode);
AIR_EXPORT FILE *airFclose(FILE *file);
AIR_EXPORT int airSinglePrintf(FILE *file, char *str, const char *fmt, ...);
-AIR_EXPORT char *airSprintSize_t(char str[AIR_STRLEN_SMALL], size_t val);
+AIR_EXPORT char *airSprintSize_t(char str[AIR_STRLEN_SMALL + 1], size_t val);
/* ---- BEGIN non-NrrdIO */
AIR_EXPORT char *airSprintVecSize_t(char *str, const size_t *vec, unsigned int len);
-AIR_EXPORT char *airPrettySprintSize_t(char str[AIR_STRLEN_SMALL], size_t v);
-AIR_EXPORT char *airSprintPtrdiff_t(char str[AIR_STRLEN_SMALL], ptrdiff_t v);
+AIR_EXPORT char *airPrettySprintSize_t(char str[AIR_STRLEN_SMALL + 1], size_t v);
+AIR_EXPORT char *airSprintPtrdiff_t(char str[AIR_STRLEN_SMALL + 1], ptrdiff_t v);
AIR_EXPORT const int airPresent;
AIR_EXPORT FILE *airStderr(void);
AIR_EXPORT FILE *airStdout(void);
@@ -582,7 +573,7 @@
AIR_EXPORT airULLong airIndexClampULL(double min, double val, double max, airULLong N);
AIR_EXPORT char *airDoneStr(double start, double here, double end, char *str);
AIR_EXPORT double airTime(void);
-AIR_EXPORT const char airTypeStr[AIR_TYPE_MAX + 1][AIR_STRLEN_SMALL];
+AIR_EXPORT const char airTypeStr[AIR_TYPE_MAX + 1][AIR_STRLEN_SMALL + 1];
AIR_EXPORT const size_t airTypeSize[AIR_TYPE_MAX + 1];
AIR_EXPORT void airEqvAdd(airArray *eqvArr, unsigned int j, unsigned int k);
AIR_EXPORT unsigned int airEqvMap(airArray *eqvArr, unsigned int *map, unsigned int len);
Modified: teem/trunk/src/air/dio.c
===================================================================
--- teem/trunk/src/air/dio.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/dio.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -38,7 +38,7 @@
int airDisableDio = AIR_FALSE;
-static const char _airNoDioErr[AIR_NODIO_MAX + 2][AIR_STRLEN_SMALL]
+static const char _airNoDioErr[AIR_NODIO_MAX + 2][AIR_STRLEN_SMALL + 1]
= {"(invalid noDio value)",
"CAN TOO do direct I/O!",
"direct I/O apparently not available on this architecture",
Modified: teem/trunk/src/air/enum.c
===================================================================
--- teem/trunk/src/air/enum.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/enum.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -99,7 +99,7 @@
int
airEnumVal(const airEnum *enm, const char *str) {
- char *strCpy, test[AIR_STRLEN_SMALL];
+ char *strCpy, test[AIR_STRLEN_SMALL + 1];
unsigned int ii;
if (!str) {
@@ -115,7 +115,7 @@
/* want strlen and not airStrlen here because the strEqv array
should be terminated by a non-null empty string */
for (ii = 0; strlen(enm->strEqv[ii]); ii++) {
- airStrcpy(test, AIR_STRLEN_SMALL, enm->strEqv[ii]);
+ airStrcpy(test, AIR_STRLEN_SMALL + 1, enm->strEqv[ii]);
if (!enm->sense) {
airToLower(test);
}
@@ -127,7 +127,7 @@
} else {
/* enm->strEqv NULL */
for (ii = 1; ii <= enm->M; ii++) {
- airStrcpy(test, AIR_STRLEN_SMALL, enm->str[ii]);
+ airStrcpy(test, AIR_STRLEN_SMALL + 1, enm->str[ii]);
if (!enm->sense) {
airToLower(test);
}
@@ -159,7 +159,7 @@
char *
airEnumFmtDesc(const airEnum *enm, int val, int canon, const char *fmt) {
const char *desc;
- char *buff, ident[AIR_STRLEN_SMALL];
+ char *buff, ident[AIR_STRLEN_SMALL + 1];
const char *_ident;
int i;
size_t len;
@@ -185,7 +185,7 @@
}
}
}
- airStrcpy(ident, AIR_STRLEN_SMALL, _ident);
+ airStrcpy(ident, AIR_STRLEN_SMALL + 1, _ident);
if (!enm->sense) {
airToLower(ident);
}
@@ -263,18 +263,17 @@
** if all is well. we're in air, so there's no biff, but we sprintf a
** description of the error into "err", if given
**
-** The requirement that the strings have strlen <= AIR_STRLEN_SMALL-1
+** The requirement that the strings have strlen <= AIR_STRLEN_SMALL
** is a reflection of the cheap implementation of the airEnum
** functions in this file, rather than an actual restriction on what an
** airEnum could be.
*/
int
-airEnumCheck(char err[AIR_STRLEN_LARGE], const airEnum *enm) {
+airEnumCheck(char err[AIR_STRLEN_LARGE + 1], const airEnum *enm) {
static const char me[] = "airEnumCheck";
unsigned int ii, jj;
- size_t slen, ASL;
+ size_t slen, ASL = AIR_STRLEN_LARGE + 1;
- ASL = AIR_STRLEN_LARGE;
if (!enm) {
if (err) {
snprintf(err, ASL, "%s: got NULL enm", me);
@@ -301,14 +300,14 @@
return 1;
}
slen = airStrlen(enm->str[ii]);
- if (!(slen >= 1 && slen <= AIR_STRLEN_SMALL - 1)) {
+ if (!(slen >= 1 && slen <= AIR_STRLEN_SMALL)) {
if (err) {
- char stmp[AIR_STRLEN_SMALL];
+ char stmp[AIR_STRLEN_SMALL + 1];
snprintf(err, ASL,
"%s(%s): strlen(enm->str[%u] \"%s\") "
"%s not in range [1,%u]",
me, enm->name, ii, enm->str[ii], airSprintSize_t(stmp, slen),
- AIR_STRLEN_SMALL - 1);
+ AIR_STRLEN_SMALL);
}
return 1;
}
@@ -329,7 +328,7 @@
return 1;
}
if (!enm->sense) {
- char bb1[AIR_STRLEN_SMALL], bb2[AIR_STRLEN_SMALL];
+ char bb1[AIR_STRLEN_SMALL + 1], bb2[AIR_STRLEN_SMALL + 1];
strcpy(bb1, enm->str[ii]);
airToLower(bb1);
strcpy(bb2, enm->str[jj]);
@@ -404,14 +403,14 @@
}
/* check length and see if any string maps to an invalid value */
for (ii = 0; (slen = strlen(enm->strEqv[ii])); ii++) {
- if (!(slen <= AIR_STRLEN_SMALL - 1)) {
+ if (!(slen <= AIR_STRLEN_SMALL)) {
if (err) {
- char stmp[AIR_STRLEN_SMALL];
+ char stmp[AIR_STRLEN_SMALL + 1];
snprintf(err, ASL,
"%s(%s): strlen(enm->strEqv[%u] \"%s\") "
"%s not <= %u",
me, enm->name, ii, enm->strEqv[ii], airSprintSize_t(stmp, slen),
- AIR_STRLEN_SMALL - 1);
+ AIR_STRLEN_SMALL);
}
return 1;
}
@@ -453,7 +452,7 @@
return 1;
}
if (!enm->sense) {
- char bb1[AIR_STRLEN_SMALL], bb2[AIR_STRLEN_SMALL];
+ char bb1[AIR_STRLEN_SMALL + 1], bb2[AIR_STRLEN_SMALL + 1];
strcpy(bb1, enm->strEqv[ii]);
airToLower(bb1);
strcpy(bb2, enm->strEqv[jj]);
Modified: teem/trunk/src/air/miscAir.c
===================================================================
--- teem/trunk/src/air/miscAir.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/miscAir.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -49,7 +49,7 @@
** uniform way of printing information about the Teem version
*/
void
-airTeemVersionSprint(char buff[AIR_STRLEN_LARGE]) {
+airTeemVersionSprint(char buff[AIR_STRLEN_LARGE + 1]) {
sprintf(buff, "Teem version %s, %s%s%s", airTeemVersion,
airTeemReleaseDone ? "released on " : "", airTeemReleaseDate,
airTeemReleaseDone ? "" : " (not yet released)");
@@ -165,7 +165,7 @@
*/
int
airSinglePrintf(FILE *file, char *str, const char *_fmt, ...) {
- char *fmt, buff[AIR_STRLEN_LARGE];
+ char *fmt, buff[AIR_STRLEN_LARGE + 1];
double val = 0, gVal, fVal;
int ret, isF, isD, cls;
char *conv = NULL, *p0, *p1, *p2, *p3, *p4, *p5;
@@ -260,14 +260,14 @@
** non-standardized format specifier confusion with printf
*/
char *
-airSprintSize_t(char _str[AIR_STRLEN_SMALL], size_t val) {
- char str[AIR_STRLEN_SMALL];
+airSprintSize_t(char _str[AIR_STRLEN_SMALL + 1], size_t val) {
+ char str[AIR_STRLEN_SMALL + 1];
unsigned int si;
if (!_str) {
return NULL;
}
- si = AIR_STRLEN_SMALL - 1;
+ si = AIR_STRLEN_SMALL;
str[si] = '\0';
do {
str[--si] = AIR_CAST(char, (val % 10) + '0');
@@ -284,8 +284,8 @@
** non-standardized format specifier confusion with printf
*/
char *
-airSprintPtrdiff_t(char _str[AIR_STRLEN_SMALL], ptrdiff_t val) {
- char str[AIR_STRLEN_SMALL];
+airSprintPtrdiff_t(char _str[AIR_STRLEN_SMALL + 1], ptrdiff_t val) {
+ char str[AIR_STRLEN_SMALL + 1];
unsigned int si;
int sign;
@@ -292,7 +292,7 @@
if (!_str) {
return NULL;
}
- si = AIR_STRLEN_SMALL - 1;
+ si = AIR_STRLEN_SMALL;
str[si] = '\0';
sign = (val < 0 ? -1 : 1);
do {
@@ -319,7 +319,7 @@
*/
char *
airSprintVecSize_t(char *dst, const size_t *vec, unsigned int len) {
- char stmp[AIR_STRLEN_SMALL];
+ char stmp[AIR_STRLEN_SMALL + 1];
unsigned int axi;
/* if we got NULL to sprint into, there's nothing to do but return it */
@@ -345,7 +345,7 @@
** bytes, kilobytes (KB), etc
*/
char *
-airPrettySprintSize_t(char str[AIR_STRLEN_SMALL], size_t val) {
+airPrettySprintSize_t(char str[AIR_STRLEN_SMALL + 1], size_t val) {
static const char suff[][7] = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB"};
unsigned int suffIdx, suffNum;
double dval;
@@ -622,7 +622,7 @@
/* clang-format off */
const char
-airTypeStr[AIR_TYPE_MAX+1][AIR_STRLEN_SMALL] = {
+airTypeStr[AIR_TYPE_MAX+1][AIR_STRLEN_SMALL+1] = {
"(unknown)",
"bool",
"int",
Modified: teem/trunk/src/air/sane.c
===================================================================
--- teem/trunk/src/air/sane.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/sane.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -198,7 +198,7 @@
return airInsane_not;
}
-static const char _airInsaneErr[AIR_INSANE_MAX + 1][AIR_STRLEN_MED] = {
+static const char _airInsaneErr[AIR_INSANE_MAX + 1][AIR_STRLEN_MED + 1] = {
"sanity checked PASSED!", /* 0: airInsane_not */
"airMyEndian() is wrong", /* 1: airInsane_endian */
"AIR_EXISTS(+inf) was true", /* 2: airInsane_pInfExists */
Modified: teem/trunk/src/air/string.c
===================================================================
--- teem/trunk/src/air/string.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/string.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -184,10 +184,9 @@
** instead of strncpy's "Copy at most n characters, blah blah blah,
** and you still have to 0-terminate the rest yourself".
**
-** E.g. with declaration buff[AIR_STRLEN_SMALL], you call
-** airStrcpy(buff, AIR_STRLEN_SMALL, src), and know that then
-** strlen(buff) <= AIR_STRLEN_SMALL-1. (see note in air.h about
-** the meaning of the STRLEN #defines).
+** E.g. with declaration buff[AIR_STRLEN_SMALL+1], you call
+** airStrcpy(buff, AIR_STRLEN_SMALL+1, src), and know that then
+** strlen(buff) <= AIR_STRLEN_SMALL.
**
** Returns NULL if there was a problem (NULL dst or dstSize zero),
** otherwise returns dst
Modified: teem/trunk/src/air/test/tdio.c
===================================================================
--- teem/trunk/src/air/test/tdio.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/test/tdio.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -19,15 +19,14 @@
Fifth Floor, Boston, MA 02110-1301 USA
*/
-
#include "../air.h"
#if TEEM_DIO == 0
#else
/* HEY: these may be SGI-specific */
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
+# include <sys/types.h>
+# include <unistd.h>
+# include <fcntl.h>
#endif
int
@@ -61,13 +60,15 @@
mop = airMopNew();
if (!(file = fopen(fname, "w"))) {
fprintf(stderr, "%s: couldn't open %s for writing\n", me, fname);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
fd = fileno(file);
if (-1 == fd) {
fprintf(stderr, "%s: couldn't get underlying descriptor\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
fprintf(stderr, "%s: fd(%s) = %d\n", me, fname, fd);
@@ -74,35 +75,36 @@
ret = airDioTest(fd, NULL, 0);
if (airNoDio_okay != ret) {
fprintf(stderr, "%s: no good: \"%s\"\n", me, airNoDioErr(ret));
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
airDioInfo(&align, &min, &max, fd);
fprintf(stderr, "%s: --> align=%d, min=%d, max=%d\n", me, align, min, max);
- size = (size_t)max*mult;
+ size = (size_t)max * mult;
data = airDioMalloc(size, fd);
if (!data) {
- char stmp[AIR_STRLEN_SMALL];
- fprintf(stderr, "%s: airDioMalloc(%s) failed\n", me,
- airSprintSize_t(stmp, size));
- airMopError(mop); return 1;
+ char stmp[AIR_STRLEN_SMALL + 1];
+ fprintf(stderr, "%s: airDioMalloc(%s) failed\n", me, airSprintSize_t(stmp, size));
+ airMopError(mop);
+ return 1;
}
airMopAdd(mop, data, airFree, airMopAlways);
- fprintf(stderr, "\ndata size = %g MB\n", (double)size/(1024*1024));
+ fprintf(stderr, "\ndata size = %g MB\n", (double)size / (1024 * 1024));
/* -------------------------------------------------------------- */
fprintf(stderr, "(1) non-aligned memory, regular write:\n");
time0 = airTime();
- if (size-1 != write(fd, data+1, size-1)) {
+ if (size - 1 != write(fd, data + 1, size - 1)) {
fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
time1 = airTime();
fsync(fd);
time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n",
- time1 - time0, time2 - time1, time2 - time0,
- (size/(1024*1024)) / (time2 - time0));
+ fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
+ time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
airMopSub(mop, file, (airMopper)airFclose);
fclose(file);
/* -------------------------------------------------------------- */
@@ -115,14 +117,14 @@
time0 = airTime();
if (size != write(fd, data, size)) {
fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
time1 = airTime();
fsync(fd);
time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n",
- time1 - time0, time2 - time1, time2 - time0,
- (size/(1024*1024)) / (time2 - time0));
+ fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
+ time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
airMopSub(mop, file, (airMopper)airFclose);
fclose(file);
/* -------------------------------------------------------------- */
@@ -135,14 +137,14 @@
time0 = airTime();
if (size != airDioWrite(fd, data, size)) {
fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
time1 = airTime();
fsync(fd);
time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n",
- time1 - time0, time2 - time1, time2 - time0,
- (size/(1024*1024)) / (time2 - time0));
+ fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
+ time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
airMopSub(mop, file, (airMopper)airFclose);
fclose(file);
/* -------------------------------------------------------------- */
@@ -158,7 +160,8 @@
file = fopen(fname, "w");
if (-1 == (fd = fileno(file))) {
fprintf(stderr, "%s: couldn't get underlying descriptor\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
@@ -165,11 +168,13 @@
flags = fcntl(fd, F_GETFL);
if (-1 == fcntl(fd, F_SETFL, flags | FDIRECT)) {
fprintf(stderr, "%s: couldn't turn on direct IO\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
if (0 != fcntl(fd, F_DIOINFO, &dio)) {
fprintf(stderr, "%s: couldn't learn direct IO specifics", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
remain = size;
@@ -181,7 +186,8 @@
rit = write(fd, ptr, part);
if (rit != part) {
fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop); return 1;
+ airMopError(mop);
+ return 1;
}
totalrit += rit;
ptr += rit;
@@ -190,9 +196,8 @@
time1 = airTime();
fsync(fd);
time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n",
- time1 - time0, time2 - time1, time2 - time0,
- (size/(1024*1024)) / (time2 - time0));
+ fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
+ time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
airMopSub(mop, file, (airMopper)airFclose);
fclose(file);
}
Modified: teem/trunk/src/air/test/tprint.c
===================================================================
--- teem/trunk/src/air/test/tprint.c 2023-07-07 17:11:13 UTC (rev 7033)
+++ teem/trunk/src/air/test/tprint.c 2023-07-07 20:01:09 UTC (rev 7034)
@@ -19,13 +19,12 @@
Fifth Floor, Boston, MA 02110-1301 USA
*/
-
#include "../air.h"
int
main(int argc, char *argv[]) {
char *me;
- char str[AIR_STRLEN_SMALL];
+ char str[AIR_STRLEN_SMALL + 1];
size_t sz;
ptrdiff_t pd;
int change;
@@ -33,49 +32,69 @@
AIR_UNUSED(argc);
me = argv[0];
-#define PRINT printf("%s: %lu %s\n", me, AIR_CAST(unsigned long, sz), airSprintSize_t(str, sz))
+#define PRINT \
+ printf("%s: %lu %s\n", me, AIR_CAST(unsigned long, sz), airSprintSize_t(str, sz))
- sz = 1; PRINT;
+ sz = 1;
+ PRINT;
do {
- sz = 2.4*sz; PRINT;
+ sz = 2.4 * sz;
+ PRINT;
} while (sz);
- *((long int *)(&sz)) = -1; PRINT;
- sz += 1; PRINT;
- sz -= 1; PRINT;
- sz -= 1; PRINT;
- sz -= 1; PRINT;
+ *((long int *)(&sz)) = -1;
+ PRINT;
+ sz += 1;
+ PRINT;
+ sz -= 1;
+ PRINT;
+ sz -= 1;
+ PRINT;
+ sz -= 1;
+ PRINT;
#undef PRINT
-#define PRINT printf("%s: %ld %s\n", me, AIR_CAST(long, pd), airSprintPtrdiff_t(str, pd))
+#define PRINT printf("%s: %ld %s\n", me, AIR_CAST(long, pd), airSprintPtrdiff_t(str, pd))
- pd = 1; PRINT;
+ pd = 1;
+ PRINT;
do {
ptrdiff_t od;
od = pd;
- pd = 2.4*pd; PRINT;
+ pd = 2.4 * pd;
+ PRINT;
change = (od != pd);
} while (change);
-
- pd = -1; PRINT;
+ pd = -1;
+ PRINT;
do {
ptrdiff_t od;
od = pd;
- pd = 2.4*pd; PRINT;
+ pd = 2.4 * pd;
+ PRINT;
change = (od != pd);
} while (change);
pd -= 5;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
- pd += 1; PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
+ pd += 1;
+ PRINT;
exit(0);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 17:11:15
|
Revision: 7033
http://sourceforge.net/p/teem/code/7033
Author: kindlmann
Date: 2023-07-07 17:11:13 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
adding more adders
Modified Paths:
--------------
teem/trunk/src/hest/GNUmakefile
teem/trunk/src/hest/adders.c
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/test/ex3.c
Added Paths:
-----------
teem/trunk/src/hest/test/ex6.c
Modified: teem/trunk/src/hest/GNUmakefile
===================================================================
--- teem/trunk/src/hest/GNUmakefile 2023-07-07 15:49:44 UTC (rev 7032)
+++ teem/trunk/src/hest/GNUmakefile 2023-07-07 17:11:13 UTC (rev 7033)
@@ -48,7 +48,7 @@
$(L).PUBLIC_HEADERS = hest.h
$(L).PRIVATE_HEADERS = privateHest.h
$(L).OBJS = defaultsHest.o methodsHest.o usage.o parseHest.o adders.o
-$(L).TESTS = test/ex1 test/ex2 test/ex3 test/ex4 test/ex5 \
+$(L).TESTS = test/ex1 test/ex2 test/ex3 test/ex4 test/ex5 test/ex6 \
test/strings test/bday test/tmpl
####
####
Modified: teem/trunk/src/hest/adders.c
===================================================================
--- teem/trunk/src/hest/adders.c 2023-07-07 15:49:44 UTC (rev 7032)
+++ teem/trunk/src/hest/adders.c 2023-07-07 17:11:13 UTC (rev 7033)
@@ -22,35 +22,122 @@
#include "hest.h"
#include "privateHest.h"
+/* --------------------------------------------------------------- 1 == kind */
unsigned int
-hestOptAddFlag(hestOpt **optP, const char *flag, int *valueP, const char *info) {
+hestOptAdd_Flag(hestOpt **optP, const char *flag, int *valueP, const char *info) {
return hestOptAdd_nva(optP, flag, NULL /* name */, airTypeInt /* actually moot */,
- 0 /* min */, 0 /* max */, valueP, NULL /* default */, info, NULL,
- NULL, NULL);
+ 0 /* min */, 0 /* max */, valueP, NULL /* default */, info, /* */
+ NULL, NULL, NULL);
}
+/* --------------------------------------------------------------- 2 == kind */
+unsigned int
+hestOptAdd_1_Bool(hestOpt **optP, const char *flag, const char *name, /* */
+ int *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeBool, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Int(hestOpt **optP, const char *flag, const char *name, /* */
+ int *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeInt, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_UInt(hestOpt **optP, const char *flag, const char *name, /* */
+ unsigned int *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeUInt, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_LongInt(hestOpt **optP, const char *flag, const char *name, /* */
+ long int *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeLongInt, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_ULongInt(hestOpt **optP, const char *flag, const char *name, /* */
+ unsigned long int *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeULongInt, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Size_t(hestOpt **optP, const char *flag, const char *name, /* */
+ size_t *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeSize_t, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Float(hestOpt **optP, const char *flag, const char *name, /* */
+ float *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeFloat, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Double(hestOpt **optP, const char *flag, const char *name, /* */
+ double *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeDouble, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Char(hestOpt **optP, const char *flag, const char *name, /* */
+ char *valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeChar, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_String(hestOpt **optP, const char *flag, const char *name, /* */
+ char **valueP, const char *dflt, const char *info) {
+ return hestOptAdd_nva(optP, flag, name, airTypeString, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Enum(hestOpt **optP, const char *flag, const char *name, /* */
+ int *valueP, const char *dflt, const char *info, /* */
+ const airEnum *enm) {
+ return hestOptAdd_nva(optP, flag, name, airTypeEnum, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, enm, NULL);
+}
+
+unsigned int
+hestOptAdd_1_Other(hestOpt **optP, const char *flag, const char *name, /* */
+ void *valueP, const char *dflt, const char *info, /* */
+ const hestCB *CB) {
+ return hestOptAdd_nva(optP, flag, name, airTypeOther, 1, 1, /* */
+ valueP, dflt, info, /* */
+ NULL, NULL, CB);
+}
+
/*
hestOptSetXX(hestOpt *opt, )
-1<T>
-1v<T>
-2<T>
-3<T>
-4<T>
-N<T>
-Nv<T> need sawP
+1<T>, 2<T>, 3<T>, 4<T>, N<T>
+1v<T>, Nv<T> need sawP
<T>=
-Bool,
-Int,
-UInt,
-LongInt,
-ULongInt,
-Size_t,
-Float,
-Double,
-Char,
-String,
+Bool, Int, UInt, LongInt, ULongInt, Size_t,
+Float, Double, Char, String,
Enum, need Enum
Other, need CB
-*/
\ No newline at end of file
+*/
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-07 15:49:44 UTC (rev 7032)
+++ teem/trunk/src/hest/hest.h 2023-07-07 17:11:13 UTC (rev 7033)
@@ -287,8 +287,47 @@
const hestParm *parm);
/* adders.c */
-HEST_EXPORT unsigned int hestOptAddFlag(hestOpt **optP, const char *flag, int *valueP,
- const char *info);
+HEST_EXPORT unsigned int hestOptAdd_Flag(hestOpt **optP, const char *flag, int *valueP,
+ const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Bool(hestOpt **optP, const char *flag,
+ const char *name, int *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Int(hestOpt **optP, const char *flag,
+ const char *name, int *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_UInt(hestOpt **optP, const char *flag,
+ const char *name, unsigned int *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_LongInt(hestOpt **optP, const char *flag,
+ const char *name, long int *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_ULongInt(hestOpt **optP, const char *flag,
+ const char *name,
+ unsigned long int *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Size_t(hestOpt **optP, const char *flag,
+ const char *name, size_t *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Float(hestOpt **optP, const char *flag,
+ const char *name, float *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Double(hestOpt **optP, const char *flag,
+ const char *name, double *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Char(hestOpt **optP, const char *flag,
+ const char *name, char *valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_String(hestOpt **optP, const char *flag,
+ const char *name, char **valueP,
+ const char *dflt, const char *info);
+HEST_EXPORT unsigned int hestOptAdd_1_Enum(hestOpt **optP, const char *flag,
+ const char *name, int *valueP,
+ const char *dflt, const char *info,
+ const airEnum *enm);
+HEST_EXPORT unsigned int hestOptAdd_1_Other(hestOpt **optP, const char *flag,
+ const char *name, void *valueP,
+ const char *dflt, const char *info,
+ const hestCB *CB);
#ifdef __cplusplus
}
Modified: teem/trunk/src/hest/test/ex3.c
===================================================================
--- teem/trunk/src/hest/test/ex3.c 2023-07-07 15:49:44 UTC (rev 7032)
+++ teem/trunk/src/hest/test/ex3.c 2023-07-07 17:11:13 UTC (rev 7033)
@@ -42,7 +42,7 @@
opt = NULL;
hestOptAdd(&opt, "f,flag", NULL, airTypeInt, 0, 0, &flag, NULL,
"a flag created via hestOptAdd");
- hestOptAddFlag(&opt, "g,glag", &glag, "a flag created via hestOptAddFlag");
+ hestOptAdd_Flag(&opt, "g,glag", &glag, "a flag created via hestOptAdd_Flag");
hestOptAdd(&opt, "v,verbose", "level", airTypeInt, 0, 1, &v, "0", "verbosity level");
hestOptAdd(&opt, "out", "file", airTypeString, 1, 1, &out, "output.ppm",
"PPM image output");
Added: teem/trunk/src/hest/test/ex6.c
===================================================================
--- teem/trunk/src/hest/test/ex6.c (rev 0)
+++ teem/trunk/src/hest/test/ex6.c 2023-07-07 17:11:13 UTC (rev 7033)
@@ -0,0 +1,141 @@
+/*
+ Teem: Tools to process and visualize scientific data and images
+ Copyright (C) 2009--2023 University of Chicago
+ Copyright (C) 2005--2008 Gordon Kindlmann
+ Copyright (C) 1998--2004 University of Utah
+
+ This library is free software; you can redistribute it and/or modify it under the terms
+ of the GNU Lesser General Public License (LGPL) as published by the Free Software
+ Foundation; either version 2.1 of the License, or (at your option) any later version.
+ The terms of redistributing and/or modifying this software also include exceptions to
+ the LGPL that facilitate static linking.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with
+ this library; if not, write to Free Software Foundation, Inc., 51 Franklin Street,
+ Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "../hest.h"
+
+int
+main(int argc, const char **argv) {
+ hestOpt *opt = NULL;
+ hestParm *parm;
+ char *err = NULL,
+ info[] = "This program does nothing in particular, though it does attempt "
+ "to pose as some sort of command-line image processing program. "
+ "As usual, any implied functionality is purely coincidental, "
+ "especially since this is the output of a gray-haired unicyclist.";
+
+ parm = hestParmNew();
+ parm->respFileEnable = AIR_TRUE;
+ parm->respectDashDashHelp = AIR_TRUE;
+ parm->verbosity = 0;
+
+ opt = NULL;
+ /* going past C89 to have declarations here */
+ int flag;
+ hestOptAdd_Flag(&opt, "f,flag", &flag, "a flag created via hestOptAdd_Flag");
+ int b1;
+ hestOptAdd_1_Bool(&opt, "b1", "bool1", &b1, "false", "test of hestOptAdd_1_Bool");
+ int i1;
+ hestOptAdd_1_Int(&opt, "i1", "int1", &i1, "42", "test of hestOptAdd_1_Int");
+ unsigned int ui1;
+ hestOptAdd_1_UInt(&opt, "ui1", "uint1", &ui1, "42", "test of hestOptAdd_1_UInt");
+ long int li1;
+ hestOptAdd_1_LongInt(&opt, "li1", "lint1", &li1, "42", "test of hestOptAdd_1_LongInt");
+ unsigned long int uli1;
+ hestOptAdd_1_ULongInt(&opt, "uli1", "ulint1", &uli1, "42",
+ "test of hestOptAdd_1_ULongInt");
+ size_t sz1;
+ hestOptAdd_1_Size_t(&opt, "sz1", "size1", &sz1, "42", "test of hestOptAdd_1_Size_t");
+ float fl1;
+ hestOptAdd_1_Float(&opt, "fl1", "float1", &fl1, "4.2", "test of hestOptAdd_1_Float");
+ double db1;
+ hestOptAdd_1_Double(&opt, "db1", "double1", &db1, "4.2",
+ "test of hestOptAdd_1_Double");
+ char c1;
+ hestOptAdd_1_Char(&opt, "c1", "char1", &c1, "x", "test of hestOptAdd_1_Char");
+ char *s1;
+ hestOptAdd_1_String(&opt, "s1", "string1", &s1, "bingo",
+ "test of hestOptAdd_1_String");
+ int e1;
+ hestOptAdd_1_Enum(&opt, "e1", "enum1", &e1, "little", "test of hestOptAdd_1_Enum",
+ airEndian);
+ /*
+HEST_EXPORT unsigned int hestOptAdd_1_Other(hestOpt * *optP, const char *flag,
+ const char *name, void *valueP,
+ const char *dflt, const char *info,
+ const hestCB *CB);
+*/
+
+ if (1 == argc) {
+ /* didn't get anything at all on command line */
+ /* print program information ... */
+ hestInfo(stderr, argv[0], info, parm);
+ /* ... and usage information ... */
+ hestUsage(stderr, opt, argv[0], parm);
+ hestGlossary(stderr, opt, parm);
+ /* ... and avoid memory leaks */
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(1);
+ }
+
+ /* else we got something, see if we can parse it */
+ if (hestParse(opt, argc - 1, argv + 1, &err, parm)) {
+ fprintf(stderr, "ERROR: %s\n", err);
+ free(err);
+ /* print usage information ... */
+ hestUsage(stderr, opt, argv[0], parm);
+ hestGlossary(stderr, opt, parm);
+ /* ... and then avoid memory leaks */
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(1);
+ } else if (opt->helpWanted) {
+ hestUsage(stdout, opt, argv[0], parm);
+ hestGlossary(stdout, opt, parm);
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(1);
+ }
+
+ {
+ unsigned int opi, numO;
+ numO = hestOptNum(opt);
+ for (opi = 0; opi < numO; opi++) {
+ printf("opt %u/%u:\n", opi, numO);
+ printf(" flag=%s; ", opt[opi].flag ? opt[opi].flag : "(null)");
+ printf(" name=%s\n", opt[opi].name ? opt[opi].name : "(null)");
+ printf(" source=%s; ", hestSourceDefault == opt[opi].source
+ ? "default"
+ : (hestSourceUser == opt[opi].source ? "user" : "???"));
+ printf(" parmStr=|%s|\n", opt[opi].parmStr ? opt[opi].parmStr : "(null)");
+ }
+ }
+ printf("(err = %s)\n", err ? err : "(null)");
+ printf("flag = %d\n", flag);
+ printf("b1 = %d\n", b1);
+ printf("i1 = %d\n", i1);
+ printf("ui1 = %u\n", ui1);
+ printf("li1 = %ld\n", li1);
+ printf("uli1 = %lu\n", uli1);
+ printf("sz1 = %zu\n", sz1);
+ printf("fl1 = %g\n", fl1);
+ printf("db1 = %g\n", db1);
+ printf("c1 = %c\n", c1);
+ printf("s1 = %s\n", s1);
+ printf("e1 = %d\n", e1);
+
+ /* free the memory allocated by parsing ... */
+ hestParseFree(opt);
+ /* ... and the other stuff */
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(0);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 15:49:47
|
Revision: 7032
http://sourceforge.net/p/teem/code/7032
Author: kindlmann
Date: 2023-07-07 15:49:44 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
clarifying info about Teem versions in comment
Modified Paths:
--------------
teem/trunk/src/nrrd/convertNrrd.c
Modified: teem/trunk/src/nrrd/convertNrrd.c
===================================================================
--- teem/trunk/src/nrrd/convertNrrd.c 2023-07-07 15:47:27 UTC (rev 7031)
+++ teem/trunk/src/nrrd/convertNrrd.c 2023-07-07 15:49:44 UTC (rev 7032)
@@ -181,16 +181,16 @@
** The rationale for this has been: "for integral types, clamps a given float to the
** range representable by that type; for floating point types, just return the given
** number, since every float must fit in a double". However, thinking for the v1.13
-** release finally recognized the fact that INT_MAX is not representable as a float,
-** so you could have: int 2147483584, passed through nrrdFClamp[nrrdTypeInt] to get
-** float 2.14748365e+09 > INT_MAX==2147483647, which when cast back to int gives you
-** -2147483648, which completely violates the intent of these functions! So, now the
-** rationale is just "clamps given float to a range that won't create big surprises
-** due to integer overflow upon casting to that type". There could still be small
-** suprises, as in from negative input generating output that is less than the input
-** (but still negative). The solution adopted here is possibly too slow, but we'll
-** let profiling tell us that, rather than trying to cleverly use bounds known at
-** compile-time when valid.
+** release (which became the v2 release) finally recognized the fact that INT_MAX is
+** not representable as a float, so you could have: int 2147483584, passed through
+** nrrdFClamp[nrrdTypeInt] to get float 2.14748365e+09 > INT_MAX==2147483647, which
+** when cast back to int gives you -2147483648, which completely violates the intent
+** of these functions! So, now the rationale is just "clamps given float to a range
+** that won't create big surprises due to integer overflow upon casting to that type".
+** There could still be small surprises, as in from negative input generating output
+** that is less than the input (but still negative). The solution adopted here is
+** possibly too slow, but we'll let profiling tell us that, rather than trying to
+** cleverly use bounds known at compile-time when valid.
**
** Btw, this is a good example of where warnings about implicit floating-point
** conversion warnings highlighted actual bugs in code.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 15:47:28
|
Revision: 7031
http://sourceforge.net/p/teem/code/7031
Author: kindlmann
Date: 2023-07-07 15:47:27 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
adding adders.c, the new place for option type-specific and kind-specific versions of hestOptAdd
Modified Paths:
--------------
teem/trunk/src/hest/CMakeLists.txt
teem/trunk/src/hest/GNUmakefile
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/test/ex3.c
Added Paths:
-----------
teem/trunk/src/hest/adders.c
Modified: teem/trunk/src/hest/CMakeLists.txt
===================================================================
--- teem/trunk/src/hest/CMakeLists.txt 2023-07-07 15:39:09 UTC (rev 7030)
+++ teem/trunk/src/hest/CMakeLists.txt 2023-07-07 15:47:27 UTC (rev 7031)
@@ -7,6 +7,7 @@
parseHest.c
privateHest.h
usage.c
+ adders.c
)
target_sources(teem PRIVATE ${HEST_SOURCES})
Modified: teem/trunk/src/hest/GNUmakefile
===================================================================
--- teem/trunk/src/hest/GNUmakefile 2023-07-07 15:39:09 UTC (rev 7030)
+++ teem/trunk/src/hest/GNUmakefile 2023-07-07 15:47:27 UTC (rev 7031)
@@ -47,7 +47,7 @@
$(L).NEED = air
$(L).PUBLIC_HEADERS = hest.h
$(L).PRIVATE_HEADERS = privateHest.h
-$(L).OBJS = defaultsHest.o methodsHest.o usage.o parseHest.o
+$(L).OBJS = defaultsHest.o methodsHest.o usage.o parseHest.o adders.o
$(L).TESTS = test/ex1 test/ex2 test/ex3 test/ex4 test/ex5 \
test/strings test/bday test/tmpl
####
Added: teem/trunk/src/hest/adders.c
===================================================================
--- teem/trunk/src/hest/adders.c (rev 0)
+++ teem/trunk/src/hest/adders.c 2023-07-07 15:47:27 UTC (rev 7031)
@@ -0,0 +1,56 @@
+/*
+ Teem: Tools to process and visualize scientific data and images
+ Copyright (C) 2009--2023 University of Chicago
+ Copyright (C) 2005--2008 Gordon Kindlmann
+ Copyright (C) 1998--2004 University of Utah
+
+ This library is free software; you can redistribute it and/or modify it under the terms
+ of the GNU Lesser General Public License (LGPL) as published by the Free Software
+ Foundation; either version 2.1 of the License, or (at your option) any later version.
+ The terms of redistributing and/or modifying this software also include exceptions to
+ the LGPL that facilitate static linking.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with
+ this library; if not, write to Free Software Foundation, Inc., 51 Franklin Street,
+ Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "hest.h"
+#include "privateHest.h"
+
+unsigned int
+hestOptAddFlag(hestOpt **optP, const char *flag, int *valueP, const char *info) {
+
+ return hestOptAdd_nva(optP, flag, NULL /* name */, airTypeInt /* actually moot */,
+ 0 /* min */, 0 /* max */, valueP, NULL /* default */, info, NULL,
+ NULL, NULL);
+}
+
+/*
+hestOptSetXX(hestOpt *opt, )
+1<T>
+1v<T>
+2<T>
+3<T>
+4<T>
+N<T>
+Nv<T> need sawP
+
+<T>=
+Bool,
+Int,
+UInt,
+LongInt,
+ULongInt,
+Size_t,
+Float,
+Double,
+Char,
+String,
+Enum, need Enum
+Other, need CB
+*/
\ No newline at end of file
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-07 15:39:09 UTC (rev 7030)
+++ teem/trunk/src/hest/hest.h 2023-07-07 15:47:27 UTC (rev 7031)
@@ -262,6 +262,7 @@
... /* unsigned int *sawP,
const airEnum *enm,
const hestCB *CB */);
+/* see also all the special-purpose and type-checked versions in adders.c, below */
HEST_EXPORT unsigned int hestOptNum(const hestOpt *opt);
HEST_EXPORT hestOpt *hestOptFree(hestOpt *opt);
HEST_EXPORT void *hestOptFree_vp(void *opt);
@@ -285,6 +286,10 @@
HEST_EXPORT void hestInfo(FILE *file, const char *argv0, const char *info,
const hestParm *parm);
+/* adders.c */
+HEST_EXPORT unsigned int hestOptAddFlag(hestOpt **optP, const char *flag, int *valueP,
+ const char *info);
+
#ifdef __cplusplus
}
#endif
Modified: teem/trunk/src/hest/test/ex3.c
===================================================================
--- teem/trunk/src/hest/test/ex3.c 2023-07-07 15:39:09 UTC (rev 7030)
+++ teem/trunk/src/hest/test/ex3.c 2023-07-07 15:47:27 UTC (rev 7031)
@@ -25,7 +25,7 @@
main(int argc, const char **argv) {
int res[2], v, numIn;
char **in, *out, *blah[3], *option = NULL;
- int n, *ints, numN;
+ int n, *ints, numN, flag, glag;
hestOpt *opt = NULL;
hestParm *parm;
char *err = NULL,
@@ -40,6 +40,9 @@
parm->verbosity = 3;
opt = NULL;
+ hestOptAdd(&opt, "f,flag", NULL, airTypeInt, 0, 0, &flag, NULL,
+ "a flag created via hestOptAdd");
+ hestOptAddFlag(&opt, "g,glag", &glag, "a flag created via hestOptAddFlag");
hestOptAdd(&opt, "v,verbose", "level", airTypeInt, 0, 1, &v, "0", "verbosity level");
hestOptAdd(&opt, "out", "file", airTypeString, 1, 1, &out, "output.ppm",
"PPM image output");
@@ -100,6 +103,7 @@
}
printf("(err = %s)\n", err ? err : "(null)");
printf(" v = %d\n", v);
+ printf(" flag glag = %d %d\n", flag, glag);
printf("out = \"%s\"\n", out ? out : "(null)");
printf("blah = \"%s\" \"%s\" \"%s\"\n", blah[0], blah[1], blah[2]);
printf("option = \"%s\"\n", option ? option : "(null)");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 15:39:11
|
Revision: 7030
http://sourceforge.net/p/teem/code/7030
Author: kindlmann
Date: 2023-07-07 15:39:09 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
adding informative comment, and improving specificity of comment
Modified Paths:
--------------
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-07 15:37:58 UTC (rev 7029)
+++ teem/trunk/src/hest/parseHest.c 2023-07-07 15:39:09 UTC (rev 7030)
@@ -1022,6 +1022,7 @@
switch (opt[op].kind) {
case 1:
/* -------- parameter-less boolean flags -------- */
+ /* the value pointer is always assumed to be an int* */
if (vP) *((int *)vP) = appr[op];
break;
case 2:
@@ -1486,8 +1487,8 @@
('-' == argv[0][0] ? " (or unrecognized flag)" : ""), argv[0]);
} else {
sprintf(err,
- "%sunexpected end-of-parameters flag %s "
- "not ending a variable-parameter option",
+ "%sunexpected end-of-parameters flag \"%s\": "
+ "not ending a flagged variable-parameter option",
ME, stops);
}
airMopError(mop);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 15:37:59
|
Revision: 7029
http://sourceforge.net/p/teem/code/7029
Author: kindlmann
Date: 2023-07-07 15:37:58 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
fixing typo in comment
Modified Paths:
--------------
teem/trunk/src/hest/test/ex1.c
Modified: teem/trunk/src/hest/test/ex1.c
===================================================================
--- teem/trunk/src/hest/test/ex1.c 2023-07-07 09:49:20 UTC (rev 7028)
+++ teem/trunk/src/hest/test/ex1.c 2023-07-07 15:37:58 UTC (rev 7029)
@@ -31,7 +31,7 @@
../hest/test/ex1.c:36: warning: missing initializer
../hest/test/ex1.c:36: warning: (near initialization for 'opt[1].sawP')
-Fri Jun 23 07:25:52 CDT 2023 GLK see that its because the hestOpt
+Fri Jun 23 07:25:52 CDT 2023 GLK sees that its because the hestOpt
grew from the initial minimal set of parameters that made it like argtable,
to a much larger set, while at the same time hestOptAdd became the standard
way of using hest. Incomplete initializing of struct members has always
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-07 09:49:22
|
Revision: 7028
http://sourceforge.net/p/teem/code/7028
Author: kindlmann
Date: 2023-07-07 09:49:20 +0000 (Fri, 07 Jul 2023)
Log Message:
-----------
Now that we've already done an API CHANGE with hestOpt->helpWanted,
another API CHANGE added two more things to hestOpt:
unsigned int arrAlloc and arrLen.
(also reformatted many comments in hest.h)
These allow the hestOpt array to be managed like an airArray: it knows its own
allocated size (arrAlloc) as well as the logical length (arrLen), so that
re-allocation happens when the requested length exceeds some multiplement of
an allocation increment. hestOptAdd() used to do clever things to manage the
hestOpt array with a terminator hestOpt, but was totally inscrutable; now it
is nicely explicit. The new private methods optarr_init() and optarr_incr()
do the work.
API NEW: hestOptSingleSet sets a single hestOpt struct, with no var-args
And now hestOptAdd_nva relies on hestOptSingleSet for setting hestOpt members.
Thanks to this rethink, hestOpt->kind is no longer set by hestParse,
but as a side-effect of hestOptAdd.
Also, added some assert()s which simplify error handling of heap allocations
that are unlikely to fail.
Modified Paths:
--------------
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/methodsHest.c
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-06 20:37:55 UTC (rev 7027)
+++ teem/trunk/src/hest/hest.h 2023-07-07 09:49:20 UTC (rev 7028)
@@ -85,9 +85,13 @@
/*
******** hestOpt struct
**
-** information which specifies one command-line option
+** information which specifies one command-line option,
+** and describes it how it was parsed
*/
typedef struct {
+ /* --------------------- "input" fields
+ set by user, possibly directly, more likely indirectly via one of the various
+ functions (like hestOptAdd or hestOptAdd_nva or hestOptSingleSet ... ) */
char *flag, /* how the option is identified on the cmd line */
*name; /* simple description of option's parameter(s) */
int type; /* type of option (from airType enum) */
@@ -102,20 +106,23 @@
const airEnum *enm; /* used ONLY for airTypeEnum options */
const hestCB *CB; /* used ONLY for airTypeOther options */
- /* --------------------- end of user-defined fields; the following fields must be set
- by hestParse() as part of its operation. This does prevent adding const to much
- usage of the hestOpt */
-
- int kind, /* what kind of option is this, based on min and max,set by hestParse()
- (actually _hestPanic()), later used by hestFree():
+ /* --------------------- end of user-defined fields
+ These are set by hest functions to remember state for the sake of other hest functions.
+ It is probably a drawback of the simple design of hest that this internal state ends
+ up in the same struct as the input parameters above, because it blocks some
+ const-correctness opportunities that would otherwise make sense. */
+ int kind, /* What kind of option is this, based on min and max:
+ 0: (invalid; unset)
1: min == max == 0 stand-alone flag; no parameters
2: min == max == 1 single fixed parameter
3: min == max >= 2 multiple fixed parameters
4: min == 0; max == 1; single variable parameter
- 5: min < max; max >= 2 multiple variable parameters */
- alloc; /* information about whether flag is non-NULL, and what parameters were used,
- that determines whether or not memory was allocated by hestParse(); info
- later used by hestParseFree():
+ 5: min < max; max >= 2 multiple variable parameters
+ This is set by hest functions as part of building up an array of hestOpt,
+ and informs the later action of hestOptFree */
+ alloc; /* Information (set by hestParse) about whether flag is non-NULL, and what
+ parameters were used, that determines whether or not memory was allocated
+ by hestParse(). Informs later action of hestParseFree():
0: no free()ing needed
1: free(*valueP), either because it is a single string, or because was a
dynamically allocated array of non-strings
@@ -123,27 +130,40 @@
array of strings
3: free((*valueP)[i]) and free(*valueP), because it is a dynamically
allocated array of strings */
+ /* Since hest's beginning, the basic container for a set of options was an array of
+ hestOpt structs (not pointers to them, which rules out argv-style NULL-termination of
+ the array), also unfortunately with no other top-level container (which is why
+ helpWanted below is set only in the first hestOpt of the array). hestOptAdd has
+ historically reallocated the entire array, incrementing the length only by one with
+ each call, while maintaining a single terminating hestOpt, wherein some fields were set
+ to special values to indicate termination. With the 2023 code revisit, that was deemed
+ even uglier than this hack: the first hestOpt now stores here in arrAlloc the allocated
+ length of the hestOpt array, and in arrLen the number of hestOpts actually used and
+ set. This facilitates implementing something much like an airArray, but without the
+ burden of extra calls for the user (like airArrayLenIncr), nor new kinds of containers
+ for hest and its users to manage: just same same array of hestOpt structs */
+ unsigned int arrAlloc, arrLen;
- /* --------------------- Output */
+ /* --------------------- Output
+ Things set/allocated by hestParse. */
int source; /* from the hestSource* enum; from whence was this information learned,
- else hestSourceUnknown if not */
- char *parmStr; /* if non-NULL: a string (allocated by hestParse, and freed by
- hestParseFree) from which hestParse ultimately parsed whatever values
- were set in *valueP. All the parameters associated with this option
- are joined (with " " separation) into this single string. hestParse
- has always formed this string internally as part of its operation,
- but only belatedly (in 2023) is a copy of that string being made
- available here to the caller. Note that in the case of single
- variable parameter options used without a parameter, the value
- stored will be "inverted" from the string here. */
+ else hestSourceUnknown if not */
+ char *parmStr; /* if non-NULL: a string (freed by hestParseFree) from which hestParse
+ ultimately parsed whatever values were set in *valueP. All the
+ parameters associated with this option are joined (with " " separation)
+ into this single string. hestParse has always formed this string
+ internally as part of its operation, but only belatedly (in 2023) is a
+ copy of that string being made available here to the caller. Note that
+ in the case of single variable parameter options used without a
+ parameter, the value stored will be "inverted" from the string here. */
int helpWanted; /* hestParse() saw something (like "--help") in one of the given
- arguments that looks like a call for help (and respectDashDashHelp
- is set in the hestParm), so it recorded that here. There is
- unfortunately no other top-level output container for info generated
- by hestParse(), so this field is going to be set only in the *first*
- hestOpt passed to hestParse(), even though that hestOpt has no
- particular relation to where hestParse() saw the call for help. */
+ arguments that looks like a call for help (and respectDashDashHelp is
+ set in the hestParm), so it recorded that here. There is unfortunately
+ no other top-level output container for info generated by hestParse(),
+ so this field is going to be set only in the *first* hestOpt passed to
+ hestParse(), even though that hestOpt has no particular relation to
+ where hestParse() saw the call for help. */
} hestOpt;
/*
@@ -225,6 +245,10 @@
HEST_EXPORT hestParm *hestParmNew(void);
HEST_EXPORT hestParm *hestParmFree(hestParm *parm);
HEST_EXPORT void *hestParmFree_vp(void *parm);
+HEST_EXPORT void hestOptSingleSet(hestOpt *opt, const char *flag, const char *name,
+ int type, int min, int max, void *valueP,
+ const char *dflt, const char *info, unsigned int *sawP,
+ const airEnum *enm, const hestCB *CB);
HEST_EXPORT unsigned int hestOptAdd_nva(hestOpt **optP, const char *flag,
const char *name, int type, int min, int max,
void *valueP, const char *dflt, const char *info,
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2023-07-06 20:37:55 UTC (rev 7027)
+++ teem/trunk/src/hest/methodsHest.c 2023-07-07 09:49:20 UTC (rev 7028)
@@ -22,53 +22,57 @@
#include "hest.h"
#include "privateHest.h"
#include <limits.h>
+#include <assert.h>
const int hestPresent = 42;
+/* INCR is like airArray->incr: granularity with which we (linearly) reallocate the
+hestOpt array. Very few uses of hest within Teem use more than 32 options. Hopefully
+this avoids all the reallocations in the past action of hestOptAdd and the like. */
+#define INCR 32
+
hestParm *
hestParmNew() {
hestParm *parm;
parm = AIR_CALLOC(1, hestParm);
- if (parm) {
- parm->verbosity = hestDefaultVerbosity;
- parm->respFileEnable = hestDefaultRespFileEnable;
- parm->elideSingleEnumType = hestDefaultElideSingleEnumType;
- parm->elideSingleOtherType = hestDefaultElideSingleOtherType;
- parm->elideSingleOtherDefault = hestDefaultElideSingleOtherDefault;
- parm->greedySingleString = hestDefaultGreedySingleString;
- parm->elideSingleNonExistFloatDefault = hestDefaultElideSingleNonExistFloatDefault;
- parm->elideMultipleNonExistFloatDefault
- = hestDefaultElideMultipleNonExistFloatDefault;
- parm->elideSingleEmptyStringDefault = hestDefaultElideSingleEmptyStringDefault;
- parm->elideMultipleEmptyStringDefault = hestDefaultElideMultipleEmptyStringDefault;
- parm->cleverPluralizeOtherY = hestDefaultCleverPluralizeOtherY;
- parm->columns = hestDefaultColumns;
- parm->respFileFlag = hestDefaultRespFileFlag;
- parm->respFileComment = hestDefaultRespFileComment;
- parm->varParamStopFlag = hestDefaultVarParamStopFlag;
- parm->multiFlagSep = hestDefaultMultiFlagSep;
- /* for these most recent addition to the hestParm,
- abstaining from added yet another default global variable */
- parm->dieLessVerbose = AIR_FALSE;
- parm->noBlankLineBeforeUsage = AIR_FALSE;
- /* It would be really nice for parm->respectDashDashHelp to default to true:
- widespread conventions say what "--help" should mean e.g. https://clig.dev/#help
- HOWEVER, the problem is with how hestParse is called and how the return
- is interpreted as a boolean:
- - zero has meant that hestParse could set values for all the options (either
- from the command-line or from supplied defaults), and
- - non-zero has meant that there was an error parsing the command-line arguments
- But seeing and recognizing "--help" means that options have NOT had values
- set, and, that's not an error, which is outside that binary. But that binary
- is the precedent, so we have to work with it by default.
- Now, with parm->respectDashDashHelp, upon seeing "--help", hestParse returns 0,
- and sets helpWanted in the first hestOpt, and the caller will have to know
- to check for that. This logic is handled by hestParseOrDie, but maybe in
- the future there can be a different top-level parser function that turns on
- parm->respectDashDashHelp and knows how to check the results */
- parm->respectDashDashHelp = AIR_FALSE;
- }
+ assert(parm);
+ parm->verbosity = hestDefaultVerbosity;
+ parm->respFileEnable = hestDefaultRespFileEnable;
+ parm->elideSingleEnumType = hestDefaultElideSingleEnumType;
+ parm->elideSingleOtherType = hestDefaultElideSingleOtherType;
+ parm->elideSingleOtherDefault = hestDefaultElideSingleOtherDefault;
+ parm->greedySingleString = hestDefaultGreedySingleString;
+ parm->elideSingleNonExistFloatDefault = hestDefaultElideSingleNonExistFloatDefault;
+ parm->elideMultipleNonExistFloatDefault = hestDefaultElideMultipleNonExistFloatDefault;
+ parm->elideSingleEmptyStringDefault = hestDefaultElideSingleEmptyStringDefault;
+ parm->elideMultipleEmptyStringDefault = hestDefaultElideMultipleEmptyStringDefault;
+ parm->cleverPluralizeOtherY = hestDefaultCleverPluralizeOtherY;
+ parm->columns = hestDefaultColumns;
+ parm->respFileFlag = hestDefaultRespFileFlag;
+ parm->respFileComment = hestDefaultRespFileComment;
+ parm->varParamStopFlag = hestDefaultVarParamStopFlag;
+ parm->multiFlagSep = hestDefaultMultiFlagSep;
+ /* for these most recent addition to the hestParm,
+ abstaining from added yet another default global variable */
+ parm->dieLessVerbose = AIR_FALSE;
+ parm->noBlankLineBeforeUsage = AIR_FALSE;
+ /* It would be really nice for parm->respectDashDashHelp to default to true:
+ widespread conventions say what "--help" should mean e.g. https://clig.dev/#help
+ HOWEVER, the problem is with how hestParse is called and how the return
+ is interpreted as a boolean:
+ - zero has meant that hestParse could set values for all the options (either
+ from the command-line or from supplied defaults), and
+ - non-zero has meant that there was an error parsing the command-line arguments
+ But seeing and recognizing "--help" means that options have NOT had values
+ set, and, that's not an error, which is outside that binary. But that binary
+ is the precedent, so we have to work with it by default.
+ Now, with parm->respectDashDashHelp, upon seeing "--help", hestParse returns 0,
+ and sets helpWanted in the first hestOpt, and the caller will have to know
+ to check for that. This logic is handled by hestParseOrDie, but maybe in
+ the future there can be a different top-level parser function that turns on
+ parm->respectDashDashHelp and knows how to check the results */
+ parm->respectDashDashHelp = AIR_FALSE;
return parm;
}
@@ -138,11 +142,12 @@
return opt_kind(opt->min, opt->max);
}
+/* opt_init initializes all of a hestOpt, even arrAlloc and arrLen */
static void
opt_init(hestOpt *opt) {
opt->flag = opt->name = NULL;
- opt->type = 0;
+ opt->type = airTypeUnknown; /* == 0 */
opt->min = 0;
opt->max = 0;
opt->valueP = NULL;
@@ -151,7 +156,9 @@
opt->enm = NULL;
opt->CB = NULL;
opt->sawP = NULL;
- opt->kind = opt->alloc = 0;
+ opt->kind = 0; /* means that this hestOpt has not been set */
+ opt->alloc = 0;
+ opt->arrAlloc = opt->arrLen = 0;
opt->source = hestSourceUnknown;
opt->parmStr = NULL;
opt->helpWanted = AIR_FALSE;
@@ -158,9 +165,100 @@
}
/*
-hestOptAdd_nva: A new (as of 2023) non-var-args ("_nva") version of hestOptAdd, which now
-contains its main functionality (and it has become just a wrapper around this).
+hestOptNum: returns the number of elements in the given hestOpt array
+Unfortunately, unlike argv itself, there is no sense in which the hestOpt array can be
+NULL-terminated, mainly because "opt" is an array of hestOpt structs, not an array of
+pointers to hestOpt structs. Pre-2023, this function did clever things to detect the
+terminating hestOpt, but with the introduction of arrAlloc and arrLen that is moot.
+*/
+unsigned int
+hestOptNum(const hestOpt *opt) {
+ return opt ? opt->arrLen : 0;
+}
+
+/* like airArrayNew: create an initial segment of the hestOpt array */
+static void
+optarr_new(hestOpt **optP) {
+ unsigned int opi;
+ hestOpt *ret = AIR_CALLOC(INCR, hestOpt);
+ assert(ret);
+ for (opi = 0; opi < INCR; opi++) {
+ opt_init(ret + opi);
+ }
+ ret->arrAlloc = INCR;
+ ret->arrLen = 0;
+ *optP = ret;
+ return;
+}
+
+/* line airArrayLenIncr(1): increments logical length by 1,
+and returns index of newly-available element */
+unsigned int
+optarr_incr(hestOpt **optP) {
+ unsigned int olen, nlen;
+ olen = (*optP)->arrLen; /* == index of new element */
+ nlen = olen + 1;
+ if (nlen > (*optP)->arrAlloc) {
+ unsigned int opi;
+ /* just walked off end of allocated length: reallocate */
+ hestOpt *nopt = AIR_CALLOC((*optP)->arrAlloc + INCR, hestOpt);
+ assert(nopt);
+ memcpy(nopt, *optP, olen * sizeof(hestOpt));
+ nopt->arrAlloc = (*optP)->arrAlloc + INCR;
+ for (opi = olen; opi < nopt->arrAlloc; opi++) {
+ opt_init(nopt + opi);
+ }
+ free(*optP);
+ *optP = nopt;
+ }
+ (*optP)->arrLen = nlen;
+ return olen;
+}
+
+/*
+hestOptSingleSet: a completely generic setter for a single hestOpt
+Note that this makes no attempt at error-checking; that is all in hestOptCheck
+*/
+void
+hestOptSingleSet(hestOpt *opt, const char *flag, const char *name, int type, int min,
+ int max, void *valueP, const char *dflt, const char *info,
+ unsigned int *sawP, const airEnum *enm, const hestCB *CB) {
+
+ if (!opt) return;
+ opt->flag = airStrdup(flag);
+ opt->name = airStrdup(name);
+ opt->type = type;
+ opt->min = min;
+ opt->max = max;
+ opt->valueP = valueP;
+ opt->dflt = airStrdup(dflt);
+ opt->info = airStrdup(info);
+ opt->kind = opt_kind(min, max);
+ /* deal with (what used to be) var args */
+ opt->sawP = (5 == opt->kind /* */
+ ? sawP
+ : NULL);
+ opt->enm = (airTypeEnum == type /* */
+ ? enm
+ : NULL);
+ opt->CB = (airTypeOther == type /* */
+ ? CB
+ : NULL);
+ /* alloc set by hestParse */
+ /* leave arrAlloc, arrLen untouched: managed by caller */
+ /* yes, redundant with opt_init() */
+ opt->source = hestSourceUnknown;
+ opt->parmStr = NULL;
+ opt->helpWanted = AIR_FALSE;
+ return;
+}
+
+/*
+hestOptAdd_nva: A new (as of 2023) non-var-args ("_nva") version of hestOptAdd;
+now hestOptAdd is a wrapper around this. And, the per-hestOpt logic has now
+been moved to hestOptSingleSet.
+
Like hestOptAdd has done since 2013: returns UINT_MAX in case of error.
*/
unsigned int
@@ -167,48 +265,20 @@
hestOptAdd_nva(hestOpt **optP, const char *flag, const char *name, int type, int min,
int max, void *valueP, const char *dflt, const char *info,
unsigned int *sawP, const airEnum *enm, const hestCB *CB) {
- hestOpt *ret = NULL; /* not the function return; but what *optP is set to */
- int num;
unsigned int retIdx;
+ /* NULL address of opt array: can't proceed */
if (!optP) return UINT_MAX;
-
- num = *optP ? hestOptNum(*optP) : 0;
- if (!(ret = AIR_CALLOC(num + 2, hestOpt))) {
- return UINT_MAX;
+ /* initialize hestOpt array if necessary */
+ if (!(*optP)) {
+ optarr_new(optP);
}
- if (num) memcpy(ret, *optP, num * sizeof(hestOpt));
- retIdx = AIR_UINT(num);
- ret[num].flag = airStrdup(flag);
- ret[num].name = airStrdup(name);
- ret[num].type = type;
- ret[num].min = min;
- ret[num].max = max;
- ret[num].valueP = valueP;
- ret[num].dflt = airStrdup(dflt);
- ret[num].info = airStrdup(info);
- /* initialize the things that may be set below */
- ret[num].sawP = NULL;
- ret[num].enm = NULL;
- ret[num].CB = NULL;
- /* yes, redundant with opt_init() */
- ret[num].source = hestSourceUnknown;
- ret[num].parmStr = NULL;
- ret[num].helpWanted = AIR_FALSE;
- /* deal with (what used to be) var args */
- if (5 == opt_kind(min, max)) {
- ret[num].sawP = sawP;
- }
- if (airTypeEnum == type) {
- ret[num].enm = enm;
- }
- if (airTypeOther == type) {
- ret[num].CB = CB;
- }
- opt_init(&(ret[num + 1]));
- ret[num + 1].min = 1;
- if (*optP) free(*optP);
- *optP = ret;
+ /* increment logical length of hestOpt array; return index of opt being set here */
+ retIdx = optarr_incr(optP);
+ /* set all elements of the opt */
+ hestOptSingleSet(*optP + retIdx, flag, name, type, min, max, /* */
+ valueP, dflt, info, /* */
+ sawP, enm, CB);
return retIdx;
}
@@ -261,19 +331,15 @@
hestOpt *
hestOptFree(hestOpt *opt) {
- int op, num;
+ int opi, num;
if (!opt) return NULL;
- num = hestOptNum(opt);
- if (opt[num].min) {
- /* we only try to free this array if it looks like something we allocated;
- this is leveraging how opt_init leaves things */
- for (op = 0; op < num; op++) {
- _hestOptFree(opt + op);
- }
- free(opt);
+ num = opt->arrLen;
+ for (opi = 0; opi < num; opi++) {
+ _hestOptFree(opt + opi);
}
+ free(opt);
return NULL;
}
@@ -323,21 +389,3 @@
hestParmFree(parm);
return 0;
}
-
-/*
-hestOptNum: returns the number of elements in the given hestOpt array, *assuming* it is
-set up like hestOptAdd does it.
-
-Unfortunately, unlike argv itself, there is no sense in which the hestOpt array can be
-NULL-terminated, mainly because "opt" is an array of hestOpt structs, not an array of
-pointers to hestOpt structs.
-*/
-unsigned int
-hestOptNum(const hestOpt *opt) {
- unsigned int num = 0;
-
- while (opt[num].flag || opt[num].name || opt[num].type) {
- num++;
- }
- return num;
-}
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-06 20:37:55 UTC (rev 7027)
+++ teem/trunk/src/hest/parseHest.c 2023-07-07 09:49:20 UTC (rev 7028)
@@ -205,7 +205,6 @@
numOpts = hestOptNum(opt);
numvar = 0;
for (op = 0; op < numOpts; op++) {
- opt[op].kind = _hestKind(opt + op);
if (!(AIR_IN_OP(airTypeUnknown, opt[op].type, airTypeLast))) {
if (err)
sprintf(err, "%s!!!!!! opt[%d].type (%d) not in valid range [%d,%d]", ME, op,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-06 20:37:57
|
Revision: 7027
http://sourceforge.net/p/teem/code/7027
Author: kindlmann
Date: 2023-07-06 20:37:55 +0000 (Thu, 06 Jul 2023)
Log Message:
-----------
fixing comment
Modified Paths:
--------------
teem/trunk/src/hest/methodsHest.c
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2023-07-06 07:29:30 UTC (rev 7026)
+++ teem/trunk/src/hest/methodsHest.c 2023-07-06 20:37:55 UTC (rev 7027)
@@ -195,7 +195,7 @@
ret[num].source = hestSourceUnknown;
ret[num].parmStr = NULL;
ret[num].helpWanted = AIR_FALSE;
- /* deal with var args */
+ /* deal with (what used to be) var args */
if (5 == opt_kind(min, max)) {
ret[num].sawP = sawP;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-06 07:29:32
|
Revision: 7026
http://sourceforge.net/p/teem/code/7026
Author: kindlmann
Date: 2023-07-06 07:29:30 +0000 (Thu, 06 Jul 2023)
Log Message:
-----------
Two changes in preparation for non-var-arg alternatives to hestOptAdd:
(1) (a change in the API but not a breaking API change)
The hestOpt struct gains some long-overdue const-correctness; these fields
airEnum *enm; /* used ONLY for airTypeEnum options */
hestCB *CB; /* used ONLY for airTypeOther options */
are now:
const airEnum *enm;
const hestCB *CB;
This isn't actually related to non-var-arg alternatives to hestOptAdd, but
was noticed as a drawback.
(2) API NEW: A new non-var-args version of hestOptAdd:
unsigned int hestOptAdd_nva(hestOpt **optP, const char *flag,
const char *name, int type, int min, int max,
void *valueP, const char *dflt, const char *info,
unsigned int *sawP, const airEnum *enm,
const hestCB *CB);
In fact, now hestOptAdd is implemented as a wrapper around this.
and the internals of methodsHest.c have been re-organized to facilitate this.
Modified Paths:
--------------
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/methodsHest.c
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-04 10:36:53 UTC (rev 7025)
+++ teem/trunk/src/hest/hest.h 2023-07-06 07:29:30 UTC (rev 7026)
@@ -99,8 +99,8 @@
*info; /* description to be printed with "glossary" info */
unsigned int *sawP; /* used ONLY for multiple variable parameter options
(min < max >= 2): storage of # of parsed values */
- airEnum *enm; /* used ONLY for airTypeEnum options */
- hestCB *CB; /* used ONLY for airTypeOther options */
+ const airEnum *enm; /* used ONLY for airTypeEnum options */
+ const hestCB *CB; /* used ONLY for airTypeOther options */
/* --------------------- end of user-defined fields; the following fields must be set
by hestParse() as part of its operation. This does prevent adding const to much
@@ -225,6 +225,11 @@
HEST_EXPORT hestParm *hestParmNew(void);
HEST_EXPORT hestParm *hestParmFree(hestParm *parm);
HEST_EXPORT void *hestParmFree_vp(void *parm);
+HEST_EXPORT unsigned int hestOptAdd_nva(hestOpt **optP, const char *flag,
+ const char *name, int type, int min, int max,
+ void *valueP, const char *dflt, const char *info,
+ unsigned int *sawP, const airEnum *enm,
+ const hestCB *CB);
HEST_EXPORT unsigned int hestOptAdd(hestOpt **optP,
const char *flag, const char *name,
int type, int min, int max,
@@ -231,7 +236,7 @@
void *valueP, const char *dflt,
const char *info,
... /* unsigned int *sawP,
- airEnum *enm,
+ const airEnum *enm,
const hestCB *CB */);
HEST_EXPORT unsigned int hestOptNum(const hestOpt *opt);
HEST_EXPORT hestOpt *hestOptFree(hestOpt *opt);
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2023-07-04 10:36:53 UTC (rev 7025)
+++ teem/trunk/src/hest/methodsHest.c 2023-07-06 07:29:30 UTC (rev 7026)
@@ -79,8 +79,67 @@
return NULL;
}
+/* _hestMax(-1) == INT_MAX, otherwise _hestMax(m) == m */
+int
+_hestMax(int max) {
+
+ if (-1 == max) {
+ max = INT_MAX;
+ }
+ return max;
+}
+
+/* opt_kind determines the kind (1,2,3,4, or 5) of an opt,
+ from being passed its min and max fields */
+static int
+opt_kind(unsigned int _min, int _max) {
+ int min, max;
+
+ min = AIR_CAST(int, _min);
+ if (min < 0) {
+ /* invalid */
+ return -1;
+ }
+
+ max = _hestMax(_max);
+ if (!(min <= max)) {
+ /* invalid */
+ return -1;
+ }
+
+ if (0 == min && 0 == max) {
+ /* flag */
+ return 1;
+ }
+
+ if (1 == min && 1 == max) {
+ /* single fixed parameter */
+ return 2;
+ }
+
+ if (2 <= min && 2 <= max && min == max) {
+ /* multiple fixed parameters */
+ return 3;
+ }
+
+ if (0 == min && 1 == max) {
+ /* single optional parameter */
+ return 4;
+ }
+
+ /* else multiple variable parameters */
+ return 5;
+}
+
+/* "private" wrapper around opt_kind, taking a hestOpt pointer */
+int
+_hestKind(const hestOpt *opt) {
+
+ return opt_kind(opt->min, opt->max);
+}
+
static void
-optInit(hestOpt *opt) {
+opt_init(hestOpt *opt) {
opt->flag = opt->name = NULL;
opt->type = 0;
@@ -99,29 +158,17 @@
}
/*
-hestOpt *
-hestOptNew(void) {
- hestOpt *opt;
+hestOptAdd_nva: A new (as of 2023) non-var-args ("_nva") version of hestOptAdd, which now
+contains its main functionality (and it has become just a wrapper around this).
- opt = AIR_CALLOC(1, hestOpt);
- if (opt) {
- _hestOptInit(opt);
- opt->min = 1;
- }
- return opt;
-}
+Like hestOptAdd has done since 2013: returns UINT_MAX in case of error.
*/
-
-/*
-** as of Sept 2013 this returns information: the index of the
-** option just added. Returns UINT_MAX in case of error.
-*/
unsigned int
-hestOptAdd(hestOpt **optP, const char *flag, const char *name, int type, int min,
- int max, void *valueP, const char *dflt, const char *info, ...) {
+hestOptAdd_nva(hestOpt **optP, const char *flag, const char *name, int type, int min,
+ int max, void *valueP, const char *dflt, const char *info,
+ unsigned int *sawP, const airEnum *enm, const hestCB *CB) {
hestOpt *ret = NULL; /* not the function return; but what *optP is set to */
int num;
- va_list ap;
unsigned int retIdx;
if (!optP) return UINT_MAX;
@@ -144,20 +191,50 @@
ret[num].sawP = NULL;
ret[num].enm = NULL;
ret[num].CB = NULL;
- /* yes, redundant with optInit() */
+ /* yes, redundant with opt_init() */
ret[num].source = hestSourceUnknown;
ret[num].parmStr = NULL;
ret[num].helpWanted = AIR_FALSE;
/* deal with var args */
- if (5 == _hestKind(&(ret[num]))) {
+ if (5 == opt_kind(min, max)) {
+ ret[num].sawP = sawP;
+ }
+ if (airTypeEnum == type) {
+ ret[num].enm = enm;
+ }
+ if (airTypeOther == type) {
+ ret[num].CB = CB;
+ }
+ opt_init(&(ret[num + 1]));
+ ret[num + 1].min = 1;
+ if (*optP) free(*optP);
+ *optP = ret;
+ return retIdx;
+}
+
+/*
+** as of Sept 2013 this returns information: the index of the
+** option just added. Returns UINT_MAX in case of error.
+*/
+unsigned int
+hestOptAdd(hestOpt **optP, const char *flag, const char *name, int type, int min,
+ int max, void *valueP, const char *dflt, const char *info, ...) {
+ unsigned int *sawP = NULL;
+ const airEnum *enm = NULL;
+ const hestCB *CB = NULL;
+ va_list ap;
+
+ if (!optP) return UINT_MAX;
+ /* deal with var args */
+ if (5 == opt_kind(min, max)) {
va_start(ap, info);
- ret[num].sawP = va_arg(ap, unsigned int *);
+ sawP = va_arg(ap, unsigned int *);
va_end(ap);
}
if (airTypeEnum == type) {
va_start(ap, info);
va_arg(ap, unsigned int *); /* skip sawP */
- ret[num].enm = va_arg(ap, airEnum *);
+ enm = va_arg(ap, const airEnum *);
va_end(ap);
}
if (airTypeOther == type) {
@@ -164,14 +241,12 @@
va_start(ap, info);
va_arg(ap, unsigned int *); /* skip sawP */
va_arg(ap, airEnum *); /* skip enm */
- ret[num].CB = va_arg(ap, hestCB *);
+ CB = va_arg(ap, hestCB *);
va_end(ap);
}
- optInit(&(ret[num + 1]));
- ret[num + 1].min = 1;
- if (*optP) free(*optP);
- *optP = ret;
- return retIdx;
+ return hestOptAdd_nva(optP, flag, name, type, min, max, /* */
+ valueP, dflt, info, /* */
+ sawP, enm, CB);
}
static void
@@ -193,7 +268,7 @@
num = hestOptNum(opt);
if (opt[num].min) {
/* we only try to free this array if it looks like something we allocated;
- this is leveraging how _hestOptInit leaves things */
+ this is leveraging how opt_init leaves things */
for (op = 0; op < num; op++) {
_hestOptFree(opt + op);
}
@@ -249,58 +324,6 @@
return 0;
}
-/* _hestMax(-1) == INT_MAX, otherwise _hestMax(m) == m */
-int
-_hestMax(int max) {
-
- if (-1 == max) {
- max = INT_MAX;
- }
- return max;
-}
-
-/* _hestKind determines the kind (1,2,3,4, or 5) of given opt,
- from its min and max fields */
-int
-_hestKind(const hestOpt *opt) {
- int min, max;
-
- min = AIR_CAST(int, opt->min);
- if (min < 0) {
- /* invalid */
- return -1;
- }
-
- max = _hestMax(opt->max);
- if (!(min <= max)) {
- /* invalid */
- return -1;
- }
-
- if (0 == min && 0 == max) {
- /* flag */
- return 1;
- }
-
- if (1 == min && 1 == max) {
- /* single fixed parameter */
- return 2;
- }
-
- if (2 <= min && 2 <= max && min == max) {
- /* multiple fixed parameters */
- return 3;
- }
-
- if (0 == min && 1 == max) {
- /* single optional parameter */
- return 4;
- }
-
- /* else multiple variable parameters */
- return 5;
-}
-
/*
hestOptNum: returns the number of elements in the given hestOpt array, *assuming* it is
set up like hestOptAdd does it.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-04 10:36:56
|
Revision: 7025
http://sourceforge.net/p/teem/code/7025
Author: kindlmann
Date: 2023-07-04 10:36:53 +0000 (Tue, 04 Jul 2023)
Log Message:
-----------
if hestParm->respectDashDashHelp, disallow --help being an explicit option
Modified Paths:
--------------
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-04 09:56:51 UTC (rev 7024)
+++ teem/trunk/src/hest/parseHest.c 2023-07-04 10:36:53 UTC (rev 7025)
@@ -311,6 +311,16 @@
fprintf(stderr, "%s: panic 9\n", me);
return 1;
}
+ if (parm->respectDashDashHelp && !strcmp("help", sep + 1)) {
+ if (err)
+ sprintf(err,
+ "%s!!!!!! long \"--%s\" flag of opt[%d] is same as \"--help\" "
+ "that requested hparm->respectDashDashHelp handles separately",
+ ME, sep + 1, op);
+ else
+ fprintf(stderr, "%s: panic 9.5\n", me);
+ return 1;
+ }
} else {
if (!strlen(opt[op].flag)) {
if (err)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-04 09:57:02
|
Revision: 7024
http://sourceforge.net/p/teem/code/7024
Author: kindlmann
Date: 2023-07-04 09:56:51 +0000 (Tue, 04 Jul 2023)
Log Message:
-----------
hestParseOrDie: make handling of stdout vs stderr for output more consistent
Modified Paths:
--------------
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-04 09:02:14 UTC (rev 7023)
+++ teem/trunk/src/hest/parseHest.c 2023-07-04 09:56:51 UTC (rev 7024)
@@ -1699,14 +1699,15 @@
airFree(errS);
/* but no return or exit; there's more to say */
}
+#define STDWUT (parseErr ? stderr : stdout)
if (parm && parm->dieLessVerbose) {
/* newer logic for when to print which things */
- if (wantHelp && info) hestInfo(stdout, me ? me : "", info, parm);
- if (doUsage) hestUsage(parseErr ? stderr : stdout, opt, me ? me : "", parm);
+ if (wantHelp && info) hestInfo(STDWUT, me ? me : "", info, parm);
+ if (doUsage) hestUsage(STDWUT, opt, me ? me : "", parm);
if (wantHelp && doGlossary) {
- hestGlossary(parseErr ? stderr : stdout, opt, parm);
+ hestGlossary(STDWUT, opt, parm);
} else if ((!argc || parseErr) && me) {
- printf("\"%s --help\" for more information\n", me);
+ fprintf(STDWUT, "\"%s --help\" for more information\n", me);
}
} else {
/* leave older (pre-dieLessVerbose) logic as is */
@@ -1714,9 +1715,10 @@
/* no error, just !argc */
if (doInfo && info) hestInfo(stdout, me ? me : "", info, parm);
}
- if (doUsage) hestUsage(parseErr ? stderr : stdout, opt, me ? me : "", parm);
- if (doGlossary) hestGlossary(parseErr ? stderr : stdout, opt, parm);
+ if (doUsage) hestUsage(STDWUT, opt, me ? me : "", parm);
+ if (doGlossary) hestGlossary(STDWUT, opt, parm);
}
+#undef STDWUT
hestParmFree(parm);
hestOptFree(opt);
exit(!!parseErr);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-04 09:02:17
|
Revision: 7023
http://sourceforge.net/p/teem/code/7023
Author: kindlmann
Date: 2023-07-04 09:02:14 +0000 (Tue, 04 Jul 2023)
Log Message:
-----------
in hestParseOrDie, backing off change from ERROR: to ERROR parsing command-line: (not just ERROR:, like before); in extractFlagged removing extraneous quotes in describing parse error; other comment re-word
Modified Paths:
--------------
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-03 12:18:51 UTC (rev 7022)
+++ teem/trunk/src/hest/parseHest.c 2023-07-04 09:02:14 UTC (rev 7023)
@@ -628,7 +628,7 @@
ME, opt[flag].min, opt[flag].min > 1 ? "s" : "",
identStr(ident1, opt + flag, parm, AIR_TRUE), np);
} else if (-2 != endflag) {
- sprintf(err, "%shit \"%s\" before getting %d parameter%s for %s (got %d)", ME,
+ sprintf(err, "%shit %s before getting %d parameter%s for %s (got %d)", ME,
identStr(ident1, opt + endflag, parm, AIR_FALSE), opt[flag].min,
opt[flag].min > 1 ? "s" : "",
identStr(ident2, opt + flag, parm, AIR_FALSE), np);
@@ -1202,7 +1202,7 @@
return 1;
}
opt[op].alloc = 0;
- /* HEY sorry about confusion about hestOpt->parmStr versus and the value set
+ /* HEY sorry about confusion about hestOpt->parmStr versus the value set
here, due to this "inversion" */
if (1 == whichCase(opt, udflt, nprm, appr, op)) {
/* we just parsed the default, but now we want to "invert" it */
@@ -1695,7 +1695,7 @@
/* whether by argcWanting or wantHelp or parseErr, from here on out we are not
returning to caller */
if (parseErr) {
- fprintf(stderr, "ERROR parsing command-line: %s\n", errS);
+ fprintf(stderr, "ERROR: %s\n", errS);
airFree(errS);
/* but no return or exit; there's more to say */
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-03 12:18:53
|
Revision: 7022
http://sourceforge.net/p/teem/code/7022
Author: kindlmann
Date: 2023-07-03 12:18:51 +0000 (Mon, 03 Jul 2023)
Log Message:
-----------
fixing whitespace
Modified Paths:
--------------
teem/trunk/src/hest/hest.h
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-02 11:56:00 UTC (rev 7021)
+++ teem/trunk/src/hest/hest.h 2023-07-03 12:18:51 UTC (rev 7022)
@@ -135,8 +135,8 @@
has always formed this string internally as part of its operation,
but only belatedly (in 2023) is a copy of that string being made
available here to the caller. Note that in the case of single
- variable parameter options used without a parameter, the value
- stored will be "inverted" from the string here. */
+ variable parameter options used without a parameter, the value
+ stored will be "inverted" from the string here. */
int helpWanted; /* hestParse() saw something (like "--help") in one of the given
arguments that looks like a call for help (and respectDashDashHelp
is set in the hestParm), so it recorded that here. There is
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-02 11:56:03
|
Revision: 7021
http://sourceforge.net/p/teem/code/7021
Author: kindlmann
Date: 2023-07-02 11:56:00 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
Two changes:
- "private" _hestNumOpts renamed to hestOptNum
(not an api change since _hestNumOpts was private)
- API CHANGE: add char *parmStr to hestOpt, as a place to keep a copy of the string
that was used by hestParse to set values for the option. The want of this was noted
in 2020-05-14 with r6388, but the simplicity of adding this was not appararent until
GLK re-acquainted himself with the workings of hest.
Allocated by hestParse, and freed by hestParseFree
Not perfectly debugged, but good enough to commit and then try using elsewhere in Teem
Modified Paths:
--------------
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/methodsHest.c
teem/trunk/src/hest/parseHest.c
teem/trunk/src/hest/privateHest.h
teem/trunk/src/hest/test/ex3.c
teem/trunk/src/hest/usage.c
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/hest.h 2023-07-02 11:56:00 UTC (rev 7021)
@@ -114,7 +114,7 @@
4: min == 0; max == 1; single variable parameter
5: min < max; max >= 2 multiple variable parameters */
alloc; /* information about whether flag is non-NULL, and what parameters were used,
- that determines whether or not memory was allocated by hestParse(); info
+ that determines whether or not memory was allocated by hestParse(); info
later used by hestParseFree():
0: no free()ing needed
1: free(*valueP), either because it is a single string, or because was a
@@ -128,6 +128,15 @@
int source; /* from the hestSource* enum; from whence was this information learned,
else hestSourceUnknown if not */
+ char *parmStr; /* if non-NULL: a string (allocated by hestParse, and freed by
+ hestParseFree) from which hestParse ultimately parsed whatever values
+ were set in *valueP. All the parameters associated with this option
+ are joined (with " " separation) into this single string. hestParse
+ has always formed this string internally as part of its operation,
+ but only belatedly (in 2023) is a copy of that string being made
+ available here to the caller. Note that in the case of single
+ variable parameter options used without a parameter, the value
+ stored will be "inverted" from the string here. */
int helpWanted; /* hestParse() saw something (like "--help") in one of the given
arguments that looks like a call for help (and respectDashDashHelp
is set in the hestParm), so it recorded that here. There is
@@ -224,6 +233,7 @@
... /* unsigned int *sawP,
airEnum *enm,
const hestCB *CB */);
+HEST_EXPORT unsigned int hestOptNum(const hestOpt *opt);
HEST_EXPORT hestOpt *hestOptFree(hestOpt *opt);
HEST_EXPORT void *hestOptFree_vp(void *opt);
HEST_EXPORT int hestOptCheck(hestOpt *opt, char **errP);
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/methodsHest.c 2023-07-02 11:56:00 UTC (rev 7021)
@@ -80,7 +80,7 @@
}
static void
-_hestOptInit(hestOpt *opt) {
+optInit(hestOpt *opt) {
opt->flag = opt->name = NULL;
opt->type = 0;
@@ -94,6 +94,7 @@
opt->sawP = NULL;
opt->kind = opt->alloc = 0;
opt->source = hestSourceUnknown;
+ opt->parmStr = NULL;
opt->helpWanted = AIR_FALSE;
}
@@ -125,7 +126,7 @@
if (!optP) return UINT_MAX;
- num = *optP ? _hestNumOpts(*optP) : 0;
+ num = *optP ? hestOptNum(*optP) : 0;
if (!(ret = AIR_CALLOC(num + 2, hestOpt))) {
return UINT_MAX;
}
@@ -143,8 +144,10 @@
ret[num].sawP = NULL;
ret[num].enm = NULL;
ret[num].CB = NULL;
- /* seems to be redundant with _hestOptInit() below */
+ /* yes, redundant with optInit() */
ret[num].source = hestSourceUnknown;
+ ret[num].parmStr = NULL;
+ ret[num].helpWanted = AIR_FALSE;
/* deal with var args */
if (5 == _hestKind(&(ret[num]))) {
va_start(ap, info);
@@ -164,7 +167,7 @@
ret[num].CB = va_arg(ap, hestCB *);
va_end(ap);
}
- _hestOptInit(&(ret[num + 1]));
+ optInit(&(ret[num + 1]));
ret[num + 1].min = 1;
if (*optP) free(*optP);
*optP = ret;
@@ -187,7 +190,7 @@
if (!opt) return NULL;
- num = _hestNumOpts(opt);
+ num = hestOptNum(opt);
if (opt[num].min) {
/* we only try to free this array if it looks like something we allocated;
this is leveraging how _hestOptInit leaves things */
@@ -299,14 +302,16 @@
}
/*
-_hestNumOpts: returns the length of the given hestOpt array
-Unlike argv itself, the hestOpt array is not NULL-terminated, mainly because
-(though this is GLK pondering this in June 2023), "opt" is an array of
-hestOpt structs, not an array of pointers to hestOpt structs.
+hestOptNum: returns the number of elements in the given hestOpt array, *assuming* it is
+set up like hestOptAdd does it.
+
+Unfortunately, unlike argv itself, there is no sense in which the hestOpt array can be
+NULL-terminated, mainly because "opt" is an array of hestOpt structs, not an array of
+pointers to hestOpt structs.
*/
-int
-_hestNumOpts(const hestOpt *opt) {
- int num = 0;
+unsigned int
+hestOptNum(const hestOpt *opt) {
+ unsigned int num = 0;
while (opt[num].flag || opt[num].name || opt[num].type) {
num++;
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/parseHest.c 2023-07-02 11:56:00 UTC (rev 7021)
@@ -202,7 +202,7 @@
char tbuff[AIR_STRLEN_HUGE], *sep;
int numvar, op, numOpts;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
numvar = 0;
for (op = 0; op < numOpts; op++) {
opt[op].kind = _hestKind(opt + op);
@@ -398,7 +398,7 @@
int a, numOpts, ret, other;
ret = 0;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
other = AIR_FALSE;
if (argv) {
for (a = 0; a < argc; a++) {
@@ -461,7 +461,7 @@
char buff[2 * AIR_STRLEN_HUGE], copy[AIR_STRLEN_HUGE], *sep;
int op, numOpts;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
if (parm->verbosity)
printf("!%s: (a) looking for flag |%s| in numOpts=%d options\n", me, flag, numOpts);
for (op = 0; op < numOpts; op++) {
@@ -668,7 +668,7 @@
}
/* make sure that flagged options without default were given */
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
for (op = 0; op < numOpts; op++) {
if (1 != opt[op].kind && opt[op].flag && !opt[op].dflt && !appr[op]) {
sprintf(err, "%sdidn't get required %s", ME,
@@ -696,7 +696,7 @@
char ident[AIR_STRLEN_HUGE];
int nvp, np, op, unflag1st, unflagVar, numOpts;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
unflag1st = _hestNextUnflagged(0, opt, numOpts);
if (numOpts == unflag1st) {
/* no unflagged options; we're done */
@@ -804,7 +804,7 @@
char *tmpS, ident[AIR_STRLEN_HUGE];
int op, numOpts;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
for (op = 0; op < numOpts; op++) {
if (parm->verbosity)
printf("%s op=%d/%d: \"%s\" --> kind=%d, nprm=%u, appr=%d\n", me, op, numOpts - 1,
@@ -982,10 +982,18 @@
char *cP;
size_t size;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
for (op = 0; op < numOpts; op++) {
identStr(ident, opt + op, parm, AIR_TRUE);
opt[op].source = udflt[op] ? hestSourceDefault : hestSourceUser;
+ /* 2023 GLK notes that r6388 2020-05-14 GLK was asking:
+ How is it that, once the command-line has been parsed, there isn't an
+ easy way to see (or print, for an error message) the parameter (or
+ concatenation of parameters) that was passed for a given option?
+ and it turns out that adding this was as simple as adding this one following
+ line. The inscrutability of the hest code (or more acutely the self-reinforcing
+ learned fear of working with the hest code) seems to have been the barrier. */
+ opt[op].parmStr = airStrdup(prms[op]);
type = opt[op].type;
size = (airTypeEnum == type /* */
? sizeof(int)
@@ -994,8 +1002,8 @@
: airTypeSize[type]));
cP = (char *)(vP = opt[op].valueP);
if (parm->verbosity) {
- printf("%s %d of %d: \"%s\": |%s| --> kind=%d, type=%d, size=%d\n", me, op,
- numOpts - 1, prms[op], ident, opt[op].kind, type, (int)size);
+ printf("%s %d of %d: \"%s\": |%s| --> kind=%d, type=%d, size=%u\n", me, op,
+ numOpts - 1, prms[op], ident, opt[op].kind, type, (unsigned int)size);
}
/* we may over-write these */
opt[op].alloc = 0;
@@ -1009,6 +1017,8 @@
break;
case 2:
/* -------- one required parameter -------- */
+ /* 2023 GLK is really curious why "if (prms[op] && vP) {" is (repeatedly)
+ guarding all the work in these blocks, and why that wasn't factored out */
if (prms[op] && vP) {
switch (type) {
case airTypeEnum:
@@ -1192,6 +1202,8 @@
return 1;
}
opt[op].alloc = 0;
+ /* HEY sorry about confusion about hestOpt->parmStr versus and the value set
+ here, due to this "inversion" */
if (1 == whichCase(opt, udflt, nprm, appr, op)) {
/* we just parsed the default, but now we want to "invert" it */
tmpD = airDLoad(vP, type);
@@ -1202,7 +1214,7 @@
}
break;
case 5:
- /* -------- multiple optional parameters -------- */
+ /* -------- multiple variable parameters -------- */
if (prms[op] && vP) {
if (1 == whichCase(opt, udflt, nprm, appr, op)) {
*((void **)vP) = NULL;
@@ -1343,7 +1355,7 @@
hestParm *parm;
size_t start_index, end_index;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
/* -------- initialize the mop! */
mop = airMopNew();
@@ -1504,6 +1516,7 @@
/* -------- now, the actual parsing of values */
if (PARM->verbosity) printf("%s: #### calling hestSetValues\n", me);
+ /* this will also set hestOpt->parmStr */
ret = setValues(prms, udflt, nprm, appr, opt, err, PARM, mop);
if (ret) {
airMopError(mop);
@@ -1535,8 +1548,9 @@
char **str;
char ***strP;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
for (op = 0; op < numOpts; op++) {
+ opt[op].parmStr = airFree(opt[op].parmStr);
/*
printf("!hestParseFree: op = %d/%d -> kind = %d; type = %d; alloc = %d\n",
op, numOpts-1, opt[op].kind, opt[op].type, opt[op].alloc);
Modified: teem/trunk/src/hest/privateHest.h
===================================================================
--- teem/trunk/src/hest/privateHest.h 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/privateHest.h 2023-07-02 11:56:00 UTC (rev 7021)
@@ -25,7 +25,6 @@
/* methodsHest.c */
extern int _hestKind(const hestOpt *opt);
-extern int _hestNumOpts(const hestOpt *opt);
extern int _hestMax(int max);
/* parseHest.c */
Modified: teem/trunk/src/hest/test/ex3.c
===================================================================
--- teem/trunk/src/hest/test/ex3.c 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/test/ex3.c 2023-07-02 11:56:00 UTC (rev 7021)
@@ -85,6 +85,19 @@
exit(1);
}
+ {
+ unsigned int opi, numO;
+ numO = hestOptNum(opt);
+ for (opi = 0; opi < numO; opi++) {
+ printf("opt %u/%u:\n", opi, numO);
+ printf(" flag=%s; ", opt[opi].flag ? opt[opi].flag : "(null)");
+ printf(" name=%s\n", opt[opi].name ? opt[opi].name : "(null)");
+ printf(" source=%s; ", hestSourceDefault == opt[opi].source
+ ? "default"
+ : (hestSourceUser == opt[opi].source ? "user" : "???"));
+ printf(" parmStr=|%s|\n", opt[opi].parmStr ? opt[opi].parmStr : "(null)");
+ }
+ }
printf("(err = %s)\n", err ? err : "(null)");
printf(" v = %d\n", v);
printf("out = \"%s\"\n", out ? out : "(null)");
Modified: teem/trunk/src/hest/usage.c
===================================================================
--- teem/trunk/src/hest/usage.c 2023-07-02 11:49:10 UTC (rev 7020)
+++ teem/trunk/src/hest/usage.c 2023-07-02 11:56:00 UTC (rev 7021)
@@ -188,7 +188,7 @@
return _hestMax(-1);
}
count = 0;
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
for (i = 0; i < numOpts; i++) {
if (!opt[i].dflt) {
count += opt[i].min;
@@ -243,7 +243,7 @@
return;
}
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
if (!(PARM->noBlankLineBeforeUsage)) {
fprintf(f, "\n");
}
@@ -284,7 +284,7 @@
return;
}
- numOpts = _hestNumOpts(opt);
+ numOpts = hestOptNum(opt);
maxlen = 0;
if (numOpts) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-02 11:49:11
|
Revision: 7020
http://sourceforge.net/p/teem/code/7020
Author: kindlmann
Date: 2023-07-02 11:49:10 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
trying to clarify wording
Modified Paths:
--------------
teem/trunk/src/hest/TODO.txt
Modified: teem/trunk/src/hest/TODO.txt
===================================================================
--- teem/trunk/src/hest/TODO.txt 2023-07-02 10:26:10 UTC (rev 7019)
+++ teem/trunk/src/hest/TODO.txt 2023-07-02 11:49:10 UTC (rev 7020)
@@ -35,7 +35,7 @@
max | | |
min > 0 1 2
-The kind of option is independent of whether is flagged or unflagged,
-optional (default given) or mandatory (no default given).
+The kind of option is independent of whether it is flagged or unflagged,
+and of being optional (default given) or required (no default given).
??? What is relationship between parseHest.c/whichCase() and hestOpt.alloc ???
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-02 10:26:11
|
Revision: 7019
http://sourceforge.net/p/teem/code/7019
Author: kindlmann
Date: 2023-07-02 10:26:10 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
why were type size_t values cast to int before being stored in a size_t variable? scrutinize casts indeed
Modified Paths:
--------------
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-02 10:18:00 UTC (rev 7018)
+++ teem/trunk/src/hest/parseHest.c 2023-07-02 10:26:10 UTC (rev 7019)
@@ -987,11 +987,11 @@
identStr(ident, opt + op, parm, AIR_TRUE);
opt[op].source = udflt[op] ? hestSourceDefault : hestSourceUser;
type = opt[op].type;
- size = (airTypeEnum == type
- ? (int)sizeof(int) /* HEY scrutinize casts */
- : (airTypeOther == type
- ? (int)opt[op].CB->size /* HEY scrutinize casts */
- : (int)airTypeSize[type])); /* HEY scrutinize casts */
+ size = (airTypeEnum == type /* */
+ ? sizeof(int)
+ : (airTypeOther == type /* */
+ ? opt[op].CB->size
+ : airTypeSize[type]));
cP = (char *)(vP = opt[op].valueP);
if (parm->verbosity) {
printf("%s %d of %d: \"%s\": |%s| --> kind=%d, type=%d, size=%d\n", me, op,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-02 10:18:01
|
Revision: 7018
http://sourceforge.net/p/teem/code/7018
Author: kindlmann
Date: 2023-07-02 10:18:00 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
backing off the previous under-considered change that turned -- into a brick wall for hestParse's operation; now -- is only for terminating the parameters of a *flagged* option, because that is more in keeping with how the world uses --. Wrote a long comment explaining rationale
Modified Paths:
--------------
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/parseHest.c
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2023-07-02 10:15:01 UTC (rev 7017)
+++ teem/trunk/src/hest/hest.h 2023-07-02 10:18:00 UTC (rev 7018)
@@ -181,10 +181,12 @@
char respFileFlag, /* the character at the beginning of an argument
indicating that this is a response file name */
respFileComment, /* comment character for the response files */
- varParamStopFlag, /* prefixed by '-' to form the flag which signals the end of a
- variable parameter option (single or multiple), flagged or
- unflagged. Originally imagined as most useful for flagged
- options, but also works in unflagged. */
+ varParamStopFlag, /* prefixed by '-' to form the flag (usually "--") that signals the
+ end of a *flagged* variable parameter option (single or
+ multiple). This is important to use if there is a flagged
+ variable parameter option preceeding an unflagged variable
+ parameter option, because otherwise how will you know where the
+ first stops and the second begins */
multiFlagSep; /* character in flag which signifies that there is a long and short
version, and which separates the two. Or, can be set to '\0' to
disable this behavior entirely. */
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2023-07-02 10:15:01 UTC (rev 7017)
+++ teem/trunk/src/hest/parseHest.c 2023-07-02 10:18:00 UTC (rev 7018)
@@ -98,29 +98,47 @@
copyArgv()
Copies given oldArgv to newArgv, including (if they are enabled) injecting the contents
-of response files. BUT: this stops upon seeing "--", or upon seeing "--help" if
-parm->respectDashDashHelp. Allocations of the strings in newArgv are remembered (to be
-airFree'd later) in the given pmop. Returns the number of args set in newArgv, and sets
-sawStop or sawHelp if saw "--" or "--help", respectively.
+of response files. BUT: this stops upon seeing "--help" if parm->respectDashDashHelp.
+Allocations of the strings in newArgv are remembered (to be airFree'd later) in the given
+pmop. Returns the number of args set in newArgv, and sets sawHelp if saw "--help".
+
+For a brief moment prior to the 2.0.0 release, this also stopped if it saw "--" (or
+whatever parm->varParamStopFlag implies), but that meant "--" is a brick wall that
+hestParse could never see past. But that misunderstands the relationship between how
+hestParse works and how the world uses "--". According to POSIX guidelines:
+https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_01
+the elements of argv can be first "options" and then "operands", where "options" are
+indicated by something starting with '-', and may have 0 or more "option-arguments".
+Then, according to Guideline 10:
+ The first -- argument that is not an option-argument should be accepted as a
+ delimiter indicating the end of options. Any following arguments should be treated
+ as operands, even if they begin with the '-' character.
+So "--" marks the end of some "option-arguments".
+
+But hestParse does not know or care about "operands": *every* element of the given argv
+will be interpreted as the argument to some option, including an unflagged option (a
+variable unflagged option is how hest would support something like "cksum *.txt"). For
+hest to implement the expected behavior for
+"--", hest has to care about "--" only in the context of collecting parameters to
+*flagged* options. But copyArgv() is upstream of that awareness (of flagged vs
+unflagged), so we do not act on "--" here.
+
+Note that there are lots of ways that hest does NOT conform to these POSIX guidelines
+(such as: currently single-character flags cannot be grouped together, and options can
+have their arguments be optional), but those guidelines are used here to help documenting
+what "--" should mean.
*/
static int
-copyArgv(int *sawStop, int *sawHelp, char **newArgv, const char **oldArgv,
- const hestParm *parm, airArray *pmop) {
+copyArgv(int *sawHelp, char **newArgv, const char **oldArgv, const hestParm *parm,
+ airArray *pmop) {
static const char me[] = "copyArgv";
- char line[AIR_STRLEN_HUGE], *pound, stops[3];
+ char line[AIR_STRLEN_HUGE], *pound;
int len, newArgc, oldArgc, incr, ai;
FILE *file;
- stops[0] = '-';
- stops[1] = parm->varParamStopFlag;
- stops[2] = '\0';
newArgc = oldArgc = 0;
- *sawStop = *sawHelp = AIR_FALSE;
+ *sawHelp = AIR_FALSE;
while (oldArgv[oldArgc]) {
- if (!strcmp(stops, oldArgv[oldArgc])) {
- *sawStop = AIR_TRUE;
- break;
- }
if (parm->respectDashDashHelp && !strcmp("--help", oldArgv[oldArgc])) {
*sawHelp = AIR_TRUE;
break;
@@ -143,6 +161,7 @@
len = airOneLine(file, line, AIR_STRLEN_HUGE);
while (len > 0) {
if (parm->verbosity) printf("%s: line: |%s|\n", me, line);
+ /* HEY HEY too bad for you if you put # inside a string */
if ((pound = strchr(line, parm->respFileComment))) *pound = '\0';
if (parm->verbosity) printf("%s: -0-> line: |%s|\n", me, line);
airOneLinify(line);
@@ -433,8 +452,8 @@
given a string in "flag" (with the hypen prefix) finds which of the flags in the given
array of options matches that. Returns the index of the matching option, or -1 if
-there is no match, but returns -2 if the flag is the end-of-options
-marker (according to parm->varParamStopFlag)
+there is no match, but returns -2 if the flag is the end-of-parameters
+marker "--" (or whatever parm->varParamStopFlag implies)
*/
static int
whichFlag(hestOpt *opt, char *flag, const hestParm *parm) {
@@ -482,9 +501,6 @@
extractToStr: takes "pnum" parameters, starting at "base", out of the given argv, and
puts them into a string WHICH THIS FUNCTION ALLOCATES, and also adjusts the argc value
given as "*argcP".
-
-HEY HEY: GLK added the logic of using the stops string ("--") here before realizing that
-that logic really belongs upstream, in copyArgv, so it should be needed here, right?
*/
static char *
extractToStr(int *argcP, char **argv, unsigned int base, unsigned int pnum,
@@ -495,12 +511,14 @@
if (!pnum) return NULL;
- len = 0;
if (parm) {
stops[0] = '-';
stops[1] = parm->varParamStopFlag;
stops[2] = '\0';
} /* else stops stays as empty string */
+
+ /* find length of buffer we'll have to allocate */
+ len = 0;
for (pidx = 0; pidx < pnum; pidx++) {
if (base + pidx == AIR_UINT(*argcP)) {
/* ran up against end of argv array */
@@ -510,7 +528,9 @@
/* saw something like "--", so that's the end */
break;
}
+ /* increment by strlen of current arg */
len += AIR_UINT(strlen(argv[base + pidx]));
+ /* and by 2, for 2 '"'s around quoted parm */
if (strstr(argv[base + pidx], " ")) {
len += 2;
}
@@ -522,11 +542,10 @@
strcpy(ret, "");
for (pidx = 0; pidx < true_pnum; pidx++) {
if (strstr(argv[base + pidx], " ")) {
- /* if a single element of argv has spaces in it, someone went
- to the trouble of putting it in quotes, and we perpetuate
- the favor by quoting it when we concatenate all the argv
- elements together, so that airParseStrS will recover it as a
- single string again */
+ /* if a single element of argv has spaces in it, someone went to the trouble of
+ putting it in quotes or escaping the space, and we perpetuate the favor by quoting
+ it when we concatenate all the argv elements together, so that airParseStrS will
+ recover it as a single string again */
strcat(ret, "\"");
}
/* HEY: if there is a '\"' character in this string, quoted or
@@ -535,6 +554,7 @@
if (strstr(argv[base + pidx], " ")) {
strcat(ret, "\"");
}
+ /* add space prior to anticipated next parm */
if (pidx < true_pnum - 1) strcat(ret, " ");
}
for (pidx = base + true_pnum; pidx <= AIR_UINT(*argcP); pidx++) {
@@ -545,27 +565,26 @@
}
/*
-** extractFlagged()
-**
-** extracts the parameters associated with all flagged options from the
-** given argc and argv, storing them in prms[], recording the number
-** of parameters in nprm[], and whether or not the flagged option appeared
-** in appr[].
-**
-** The "saw" information is not set here, since it is better set
-** at value parsing time, which happens after defaults are enstated.
+extractFlagged()
+
+extracts the parameters associated with all flagged options from the given argc and argv,
+storing them in prms[], recording the number of parameters in nprm[], and whether or not
+the flagged option appeared in appr[].
+
+The sawP information is not set here, since it is better set at value parsing time, which
+happens after defaults are enstated.
+
+This is where, thanks to the action of whichFlag(), "--" (or whatever
+parm->varParamStopFlag implies) is used as a marker for the end of a *flagged* variable
+parameter option. AND, the "--" marker is removed from the argv.
*/
static int
extractFlagged(char **prms, unsigned int *nprm, int *appr, int *argcP, char **argv,
- hestOpt *opt, char *err, int hitStop, const hestParm *parm,
- airArray *pmop) {
+ hestOpt *opt, char *err, const hestParm *parm, airArray *pmop) {
static const char me[] = "extractFlagged: ";
- char ident1[AIR_STRLEN_HUGE], ident2[AIR_STRLEN_HUGE], stops[3];
+ char ident1[AIR_STRLEN_HUGE], ident2[AIR_STRLEN_HUGE];
int a, np, flag, endflag, numOpts, op;
- stops[0] = '-';
- stops[1] = parm->varParamStopFlag;
- stops[2] = '\0';
a = 0;
if (parm->verbosity) printf("!%s: *argcP = %d\n", me, *argcP);
while (a <= *argcP - 1) {
@@ -604,12 +623,9 @@
/* didn't get minimum number of parameters */
if (!(a + np + 1 <= *argcP - 1)) {
sprintf(err,
- "%shit %s%s before getting %d parameter%s "
+ "%shit end of line before getting %d parameter%s "
"for %s (got %d)",
- ME, /* */
- hitStop ? "end-of-options flag " : "end of line", /* */
- hitStop ? "--" : "", /* */
- opt[flag].min, opt[flag].min > 1 ? "s" : "",
+ ME, opt[flag].min, opt[flag].min > 1 ? "s" : "",
identStr(ident1, opt + flag, parm, AIR_TRUE), np);
} else if (-2 != endflag) {
sprintf(err, "%shit \"%s\" before getting %d parameter%s for %s (got %d)", ME,
@@ -618,8 +634,8 @@
identStr(ident2, opt + flag, parm, AIR_FALSE), np);
} else {
sprintf(err,
- "%shit \"-%c\" (option-stop flag) before getting %d parameter%s for %s "
- "(got %d)",
+ "%shit \"-%c\" (option-parameter-stop flag) before getting %d "
+ "parameter%s for %s (got %d)",
ME, parm->varParamStopFlag, opt[flag].min, opt[flag].min > 1 ? "s" : "",
identStr(ident2, opt + flag, parm, AIR_FALSE), np);
}
@@ -641,7 +657,7 @@
airMopAdd(pmop, prms[flag], airFree, airMopAlways);
appr[flag] = AIR_TRUE;
if (-2 == endflag) {
- /* we should lose the end-of-options marker ??? ??? */
+ /* we drop the option-parameter-stop flag */
free(extractToStr(argcP, argv, a, 1, NULL, NULL));
}
if (parm->verbosity) {
@@ -830,6 +846,7 @@
udflt[op] = opt[op].flag && !appr[op];
break;
}
+ /* if not using the default, we're done with this option */
if (!udflt[op]) continue;
prms[op] = airStrdup(opt[op].dflt);
/* fprintf(stderr, "%s: prms[%d] = |%s|\n", me, op, prms[op]); */
@@ -955,9 +972,9 @@
}
static int
-_hestSetValues(char **prms, int *udflt, unsigned int *nprm, int *appr, hestOpt *opt,
- char *err, const hestParm *parm, airArray *pmop) {
- static const char me[] = "_hestSetValues: ";
+setValues(char **prms, int *udflt, unsigned int *nprm, int *appr, hestOpt *opt,
+ char *err, const hestParm *parm, airArray *pmop) {
+ static const char me[] = "setValues: ";
char ident[AIR_STRLEN_HUGE], cberr[AIR_STRLEN_HUGE], *tok, *last, *prmsCopy;
double tmpD;
int op, type, numOpts, p, ret;
@@ -1320,8 +1337,7 @@
static const char me[] = "hestParse: ";
char *param, *param_copy;
char **argv, **prms, *err;
- int a, argc, argc_used, argr, *appr, *udflt, nrf, numOpts, big, ret, i, sawStop,
- sawHelp;
+ int a, argc, argc_used, argr, *appr, *udflt, nrf, numOpts, big, ret, i, sawHelp;
unsigned int *nprm;
airArray *mop;
hestParm *parm;
@@ -1406,22 +1422,21 @@
elements of argv */
opt->helpWanted = AIR_FALSE;
if (PARM->verbosity) printf("%s: #### calling copyArgv\n", me);
- argc_used = copyArgv(&sawStop, &sawHelp, argv, _argv, PARM, mop);
+ argc_used = copyArgv(&sawHelp, argv, _argv, PARM, mop);
if (PARM->verbosity) {
- printf("%s: #### copyArgv done (%d args copied; sawStop=%d sawHelp=%d)\n", me,
- argc_used, sawStop, sawHelp);
+ printf("%s: #### copyArgv done (%d args copied; sawHelp=%d)\n", me, argc_used,
+ sawHelp);
}
if (sawHelp) {
/* saw "--help", which is not error, but is a show-stopper */
opt->helpWanted = AIR_TRUE;
- /* this functionality has been grafted onto this code, 20 years after it was first
- written. Until it is more completely re-written, a goto does the job */
+ /* the --help functionality has been grafted onto this code, >20 years after it was
+ first written. Until it is more completely re-written, a goto does the job */
goto parseEnd;
}
- /* else !sawHelp; do sanity check on argc_used, argc, sawStop */
- if (argc_used < argc && !sawStop) {
- sprintf(err, "%sargc_used %d < argc %d but didn't see -%c? sorry, confused", ME,
- argc_used, argc, parm->varParamStopFlag);
+ /* else !sawHelp; do sanity check on argc_used vs argc */
+ if (argc_used < argc) {
+ sprintf(err, "%sargc_used %d < argc %d; sorry, confused", ME, argc_used, argc);
airMopError(mop);
return 1;
}
@@ -1428,7 +1443,7 @@
/* -------- extract flags and their associated parameters from argv */
if (PARM->verbosity) printf("%s: #### calling extractFlagged\n", me);
- if (extractFlagged(prms, nprm, appr, &argc_used, argv, opt, err, sawStop, PARM, mop)) {
+ if (extractFlagged(prms, nprm, appr, &argc_used, argv, opt, err, PARM, mop)) {
airMopError(mop);
return 1;
}
@@ -1442,10 +1457,18 @@
}
if (PARM->verbosity) printf("%s: #### extractUnflagged done!\n", me);
- /* currently, any left over arguments indicate error */
+ /* currently, any left-over arguments indicate error */
if (argc_used) {
- sprintf(err, "%sunexpected arg%s: \"%s\"", ME,
- ('-' == argv[0][0] ? " (or unrecognized flag)" : ""), argv[0]);
+ char stops[3] = {'-', PARM->varParamStopFlag, '\0'};
+ if (strcmp(stops, argv[0])) {
+ sprintf(err, "%sunexpected arg%s: \"%s\"", ME,
+ ('-' == argv[0][0] ? " (or unrecognized flag)" : ""), argv[0]);
+ } else {
+ sprintf(err,
+ "%sunexpected end-of-parameters flag %s "
+ "not ending a variable-parameter option",
+ ME, stops);
+ }
airMopError(mop);
return 1;
}
@@ -1481,7 +1504,7 @@
/* -------- now, the actual parsing of values */
if (PARM->verbosity) printf("%s: #### calling hestSetValues\n", me);
- ret = _hestSetValues(prms, udflt, nprm, appr, opt, err, PARM, mop);
+ ret = setValues(prms, udflt, nprm, appr, opt, err, PARM, mop);
if (ret) {
airMopError(mop);
return ret;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-07-02 10:15:06
|
Revision: 7017
http://sourceforge.net/p/teem/code/7017
Author: kindlmann
Date: 2023-07-02 10:15:01 +0000 (Sun, 02 Jul 2023)
Log Message:
-----------
re-ordered options, simplified else logic
Modified Paths:
--------------
teem/trunk/src/hest/test/ex3.c
Modified: teem/trunk/src/hest/test/ex3.c
===================================================================
--- teem/trunk/src/hest/test/ex3.c 2023-06-29 12:28:03 UTC (rev 7016)
+++ teem/trunk/src/hest/test/ex3.c 2023-07-02 10:15:01 UTC (rev 7017)
@@ -47,11 +47,11 @@
"input image file(s)");
hestOptAdd(&opt, "option", "opt", airTypeString, 0, 1, &option, "default",
"this is just a test");
- hestOptAdd(&opt, NULL, "input", airTypeString, 1, -1, &in, NULL, "input image file(s)",
- &numIn);
hestOptAdd(&opt, "ints", "N", airTypeInt, 1, -1, &ints, "10 20 30",
"a list of integers", &numN);
hestOptAdd(&opt, "res", "sx sy", airTypeInt, 2, 2, res, NULL, "image resolution");
+ hestOptAdd(&opt, NULL, "input", airTypeString, 1, -1, &in, NULL, "input image file(s)",
+ &numIn);
if (1 == argc) {
/* didn't get anything at all on command line */
@@ -77,15 +77,12 @@
opt = hestOptFree(opt);
parm = hestParmFree(parm);
exit(1);
- } else {
- /* maybe got --help */
- if (opt->helpWanted) {
- hestUsage(stdout, opt, argv[0], parm);
- hestGlossary(stdout, opt, parm);
- opt = hestOptFree(opt);
- parm = hestParmFree(parm);
- exit(1);
- }
+ } else if (opt->helpWanted) {
+ hestUsage(stdout, opt, argv[0], parm);
+ hestGlossary(stdout, opt, parm);
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(1);
}
printf("(err = %s)\n", err ? err : "(null)");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-06-29 12:28:06
|
Revision: 7016
http://sourceforge.net/p/teem/code/7016
Author: kindlmann
Date: 2023-06-29 12:28:03 +0000 (Thu, 29 Jun 2023)
Log Message:
-----------
more consistent formatting
Modified Paths:
--------------
teem/trunk/src/TODO.txt
Modified: teem/trunk/src/TODO.txt
===================================================================
--- teem/trunk/src/TODO.txt 2023-06-29 11:55:37 UTC (rev 7015)
+++ teem/trunk/src/TODO.txt 2023-06-29 12:28:03 UTC (rev 7016)
@@ -72,7 +72,7 @@
* consider changing airIndexULL and airIndexClampULL to work with
size_t instead of unsigned long long, or at least adding versions that
work with size_t
-******* either change AIR_STRLEN_* to AIR_BUFFSIZE_* (or something similar,
+* either change AIR_STRLEN_* to AIR_BUFFSIZE_* (or something similar,
or take out the +1 from their definition and it into usage: the
STRLEN is misleading as is.
******* consider terminating airEnum->strEqv with NULL (just like argv)
@@ -188,13 +188,12 @@
weird global nature of reading/writing wisdom? Should "rigor" be an
argument to nrrdFFT? Is there really no error reporting on fftw_execute,
fftw_export_wisdom_to_file?
-******** make the verbosity level a field in NrrdIoState, remove nrrdStateVerboseIO
+******* make the verbosity level a field in NrrdIoState, remove nrrdStateVerboseIO
* add support for 16-bit float "half" (start with Milan's patch)
* rename nrrd<Func>_nva() --> nrrd<Func>()
-******** rename nrrdResampleNrrdSet --> nrrdResampleInputSet ?
+******* rename nrrdResampleNrrdSet --> nrrdResampleInputSet ?
* permit replacements for malloc/free (e.g. fftw_malloc, fftw_free) of data
-******** rename NRRD_KERNEL_PARMS_NUM --> NRRD_KERNEL_PARM_MAXNUM
-* remove "minsm" as synonym for nrrdTernaryOpMinSmooth
+******* rename NRRD_KERNEL_PARMS_NUM --> NRRD_KERNEL_PARM_MAXNUM
* resampler: why can't you set a kernel prior to setting input?
[nrrd] nrrdDeringExecute: trouble on setup
[nrrd] deringPtxfAlloc: couldn't set up resampler
@@ -232,7 +231,7 @@
a small Gaussian)
gage:
-******** use new NrrdBoundarySpec whenever possible; for example remove
+******* use new NrrdBoundarySpec whenever possible; for example remove
gageStackBlurParmBoundarySet()
* clean up gageVolumeCheck vs gageKindVolumeCheck mess
* in a gageKinds, the airEnum for the items, and the associated table of
@@ -247,10 +246,10 @@
* tend helix and tend satin should not generate physically implausible
diffusivity values (i.e. not exceeding 0.003 mm^2/sec)
-******** dye: convert all float to double
-******** see if dyeColorParse should allocate the thing and return it
-******** hest callbacks
-******** make quantitatively same as what D3 says
+******* dye: convert all float to double
+******* see if dyeColorParse should allocate the thing and return it
+******* hest callbacks
+******* make quantitatively same as what D3 says
push:
* remove it, assuming its smarts have been moved into pull
@@ -275,7 +274,7 @@
[ten] _tenEstimate1Tensor_WLS: trying to improve on first WLS
[ten] _tenEstimate1TensorSimulateSingle
-******* gage: re-modularize to facilitate probing bricked data
+******* gage: re-modularize (or at least plan it) to facilitate probing bricked data
******* bin/unu: valgrind parsing of encoding stuff
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-06-29 11:55:38
|
Revision: 7015
http://sourceforge.net/p/teem/code/7015
Author: kindlmann
Date: 2023-06-29 11:55:37 +0000 (Thu, 29 Jun 2023)
Log Message:
-----------
now that there will be an increment to the major version number, prioritizing some things that have long been annoying
Modified Paths:
--------------
teem/trunk/src/TODO.txt
Modified: teem/trunk/src/TODO.txt
===================================================================
--- teem/trunk/src/TODO.txt 2023-06-29 11:34:53 UTC (rev 7014)
+++ teem/trunk/src/TODO.txt 2023-06-29 11:55:37 UTC (rev 7015)
@@ -1,25 +1,4 @@
-** Compared to what's in HELP.txt, these are more generally more
-** fine-grained and nit-picky; some of them are only sensibly done by
-** GLK. The things listed for Teem 2.0 involve significant API
-** changes, or significantly thoughtful redesign of how functional
-** components of Teem are implemented.
-
-revisit ctypes with new ctypeslib2:
- https://github.com/trolldbois/ctypeslib
- https://pypi.org/project/ctypeslib2/
-to make new python wrappers
- didthis:
- sudo -H pip install --upgrade pip
- sudo -H pip install clang
- sudo pip install ctypeslib2
-working from https://github.com/kindlmann/Eglib.jl.git
-in /Users/gk/julia/Eglib.jl/eglib
-based on https://github.com/jessevdk/cldoc/issues/87
-did in /usr/local/lib: ln -s /Library/Developer/CommandLineTools/usr/lib/libclang.dylib .
-and that worked!
-
-
-Figure out what is going on with parsing spaces in hest:
+******* Figure out what is going on with parsing spaces in hest:
this doesn't work:
unu basinfo -i tmp.nrrd -kv space:=RGB "novalue:=0.3 0 0" -o tmp2.nrrd
and instead it sees:
@@ -27,8 +6,23 @@
!unu basinfo: kvpstring[1/2] = |"novalue:=0.3|
where the hell is the " coming from?
+(Actually maybe ctypes is not important, now that the CFFI stuff is solid with exult.py)
+ revisit ctypes with new ctypeslib2:
+ https://github.com/trolldbois/ctypeslib
+ https://pypi.org/project/ctypeslib2/
+ to make new python wrappers
+ didthis:
+ sudo -H pip install --upgrade pip
+ sudo -H pip install clang
+ sudo pip install ctypeslib2
+ working from https://github.com/kindlmann/Eglib.jl.git
+ in /Users/gk/julia/Eglib.jl/eglib
+ based on https://github.com/jessevdk/cldoc/issues/87
+ did in /usr/local/lib: ln -s /Library/Developer/CommandLineTools/usr/lib/libclang.dylib .
+ and that worked!
+
========
-for Teem 2.0:
+more significant (API-changing) changes:
decide on a uniform way of indicating if a given external is available
(e.g. airThreadCapable vs nrrdFFTWEnabled vs #if TEEM_LEVMAR: not uniform).
@@ -42,9 +36,6 @@
especially when it means that it would mean two different python
wrappings.
-Consider inserting SVN revision numbers in code itself:
-http://addisu.taddese.com/blog/inserting-svn-revision-number-in-your-cc-code/
-
Consider extending const-correctness of function input not just to
pointers, but to all values as well.
@@ -53,8 +44,6 @@
investigate application of Herbie http://herbie.uwplse.org
http://herbie.uwplse.org/pldi15.html
(section 3 covers mundane quadratic formula)
-* remove '_'s from enum value names in non-elf non-tijk libraries
-* decide if <LIB>_EXPORT should just be TEEM_EXPORT
* enforce consistent use of AIR_CALLOC/AIR_MALLOC
* decide consistent API of Copy() functions, or if consistency is needed, eg:
nrrdCopy() vs gageContextCopy()
@@ -76,7 +65,7 @@
place to handle setlocale weirness. However, the "Single"
restriction is too cumbersome.
* consider nixing AIR_ENDIAN, AIR_QNANHIBIT, and AIR_DIO
-* Hey, what does airSinglePrintf do with the common "%.17g" for a double?
+******* Hey, what does airSinglePrintf do with the common "%.17g" for a double?
It seems to not have the smarts to see that it is fact for a double.
* airArray->len should probably be size_t, not unsigned int. Along with
this is biffMsgErrNum and nrrdKeyValueSize.
@@ -83,10 +72,10 @@
* consider changing airIndexULL and airIndexClampULL to work with
size_t instead of unsigned long long, or at least adding versions that
work with size_t
-* either change AIR_STRLEN_* to AIR_BUFFSIZE_* (or something similar,
+******* either change AIR_STRLEN_* to AIR_BUFFSIZE_* (or something similar,
or take out the +1 from their definition and it into usage: the
STRLEN is misleading as is.
-* consider terminating airEnum->strEqv with NULL (just like argv)
+******* consider terminating airEnum->strEqv with NULL (just like argv)
instead of with empty string ""
* make airOneLine return number of bytes read; current return
of string length is entirely redundant with return of strlen()
@@ -104,8 +93,6 @@
hest:
* consider renaming hestParmFree --> hestParmNix
-* all the hest defaults (hestVerbosity, hestRespFileEnable), etc,
-should start with hestDef, not just hest
* air/hest: remove the airType* enum. The following sort of code looks
correct but is completely wrong
if (nrrdAlloc(nout, airTypeFloat, 3, size[0], size[1], size[2])) { ...
@@ -119,12 +106,12 @@
optional parameters is why things like "unu make" learn centerings via
strings: the string can be given or not, and if its given, then the
information is used.
-* There's no way to access the string that was parsed to get the
+******* There's no way to access the string that was parsed to get the
information for an option (could be from default, or command-line,
or response file)
-* (from tendGlyph.c): there needs to be an alternative API for hest
+******* (from tendGlyph.c): there needs to be an alternative API for hest
that is not var-args based (as is hestOptAdd). You can't tell when
-you've based multiple strings for the detailed usage information by
+you've passed multiple strings for the detailed usage information by
accident. GLK had accidentally inserted a comma into my multi-line
string for the "info" arg, relying on the automatic string
concatenation, and ended up passing total garbage to hestOptAdd for
@@ -136,7 +123,7 @@
so that it matches biffMovef
* rename biffCheck --> biffErrNum
* consider biffGetStrlen --> biffStrlenGet, biffSetStr --> biffStrSet
-* a few biff functions are never used in Teem, is that ok?
+******* a few biff functions are never used in Teem, is that ok?
nrrd:
* allow the API for median filtering to be more flexible about boundaries
@@ -164,23 +151,22 @@
just like nrrdDefaultWriteCharsPerLine and nrrdDefaultWriteValsPerLine)
and argument to nrrdIoStateSet.
* with NrrdKernel:
- - debug apparent precision problems worked-around in nrrdKernelCheck
- add fields for "what is my derivative" or "what is my integral", but
- how to do that at compile time?
- - add field for "parm[0] controls the scaling that the old resampling code
+ how to do both at compile time? Can have kernels K' prior to kernel K,
+ so K knows its derivative is K' but not also other way around
+*******- add field for "parm[0] controls the scaling that the old resampling code
(e.g. unu resample) has always assumed" vs "parm[0] isn't used". The
assumption by the resampling code that all kernels use parm[0] was a big
longstanding bug; "bspln3" doesn't work that way
- - consider nixing nrrdDefaultKernelParm0, nrrdEnvVarDefaultKernelParm0
- - consider nixing nrrdDefaultSpacing and nrrdEnvVarDefaultSpacing
- - "when parsing from string, parm[0] is needed" vs "parm[0] defaults to 1.0"
- OR, maybe simplify things by saying that all parameters are always needed
+******* - consider nixing nrrdDefaultKernelParm0, nrrdEnvVarDefaultKernelParm0
+******* ?? "when parsing from string, parm[0] is needed" vs "parm[0] defaults to 1.0"
+******* - consider nixing nrrdDefaultSpacing and nrrdEnvVarDefaultSpacing
- add method for answering "do I interpolate?"
- add fields for "if I don't interpolate, what's my approximate inverse?"
- add statement of accuracy (in a Taylor series sense)
- add: am I an odd or even function
- - rename numParm --> parmNum
- - fix the kernels that meetNrrdKernelAllCheck revealed to be broken
+******* - rename numParm --> parmNum
+******* - fix the kernels that meetNrrdKernelAllCheck revealed to be broken
* with NrrdFormat:
- There is now an available() method, but this is incomplete - EPS is
something that can be written for images, but not read in general.
@@ -202,12 +188,12 @@
weird global nature of reading/writing wisdom? Should "rigor" be an
argument to nrrdFFT? Is there really no error reporting on fftw_execute,
fftw_export_wisdom_to_file?
-* make the verbosity level a field in NrrdIoState, remove nrrdStateVerboseIO
+******** make the verbosity level a field in NrrdIoState, remove nrrdStateVerboseIO
* add support for 16-bit float "half" (start with Milan's patch)
* rename nrrd<Func>_nva() --> nrrd<Func>()
-* rename nrrdResampleNrrdSet --> nrrdResampleInputSet ?
+******** rename nrrdResampleNrrdSet --> nrrdResampleInputSet ?
* permit replacements for malloc/free (e.g. fftw_malloc, fftw_free) of data
-* rename NRRD_KERNEL_PARMS_NUM --> NRRD_KERNEL_PARM_MAXNUM
+******** rename NRRD_KERNEL_PARMS_NUM --> NRRD_KERNEL_PARM_MAXNUM
* remove "minsm" as synonym for nrrdTernaryOpMinSmooth
* resampler: why can't you set a kernel prior to setting input?
[nrrd] nrrdDeringExecute: trouble on setup
@@ -246,7 +232,7 @@
a small Gaussian)
gage:
-* use new NrrdBoundarySpec whenever possible; for example remove
+******** use new NrrdBoundarySpec whenever possible; for example remove
gageStackBlurParmBoundarySet()
* clean up gageVolumeCheck vs gageKindVolumeCheck mess
* in a gageKinds, the airEnum for the items, and the associated table of
@@ -261,8 +247,10 @@
* tend helix and tend satin should not generate physically implausible
diffusivity values (i.e. not exceeding 0.003 mm^2/sec)
-dye:
-* remove it, assuming its smarts have been copied into nrrd
+******** dye: convert all float to double
+******** see if dyeColorParse should allocate the thing and return it
+******** hest callbacks
+******** make quantitatively same as what D3 says
push:
* remove it, assuming its smarts have been moved into pull
@@ -270,7 +258,7 @@
========
** The items below have accumulated over time, but the importance of them
-** for Teem 2.0 or any other release should be re-evaluated.
+** should be re-evaluated.
for cmake:
- build pv on windows
@@ -287,9 +275,9 @@
[ten] _tenEstimate1Tensor_WLS: trying to improve on first WLS
[ten] _tenEstimate1TensorSimulateSingle
-gage: re-modularize to facilitate probing bricked data
+******* gage: re-modularize to facilitate probing bricked data
-bin/unu: valgrind parsing of encoding stuff
+******* bin/unu: valgrind parsing of encoding stuff
gage changes into bane:
- try gkms hvol with three explicit ranges
@@ -308,16 +296,10 @@
limn: make it smarter- so that joining parts together is possible in a
way that facilitates transformations and correct drawing. This really
-requires general data structures for 2-D graphics primatives...
+requires general data structures for 2-D graphics primitives...
limn: either debug or remove limnQN16border1
-dye: see if dyeColorParse should allocate the thing and return it
-
-dye: colormaps
-
-dye: hest callbacks
-
air: think about implementing a fabs() and dabs() with bitmasking
write a paper about nrrd!
@@ -355,4 +337,3 @@
and fails at link-time with "<new macro> symbol undefined"
- want seperate directories for static and shared libraries
- want bin/dev and bin/install targets
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-06-29 11:35:02
|
Revision: 7014
http://sourceforge.net/p/teem/code/7014
Author: kindlmann
Date: 2023-06-29 11:34:53 +0000 (Thu, 29 Jun 2023)
Log Message:
-----------
now that there will be an increment to the major version number, prioritizing some things that have long been annoying
Modified Paths:
--------------
teem/trunk/src/nrrd/TODO.txt
Modified: teem/trunk/src/nrrd/TODO.txt
===================================================================
--- teem/trunk/src/nrrd/TODO.txt 2023-06-29 11:33:22 UTC (rev 7013)
+++ teem/trunk/src/nrrd/TODO.txt 2023-06-29 11:34:53 UTC (rev 7014)
@@ -1,9 +1,9 @@
all IO-related things:
-* why on earth is code in, say, formatText.c looking at nrrdStateVerboseIO,
+******** why on earth is code in, say, formatText.c looking at nrrdStateVerboseIO,
instead of a field for verbosity in the NrrdIoState?
+******** enable imagemagick-style format flagging on filenames ("PNM:-"),
+ thereby obviating "unu save -f pnm" steps in pipes to standard out
* get back verbose IO messages about fread-vs-directIO
-* enable imagemagick-style format flagging on filenames ("PNM:-"),
-thereby obviating "unu save -f pnm" steps in pipes to standard out
* to expand multiple-format handling: in nrrdRead(), generalize
_nrrdOneLine to some more generation _nrrdReadStart, which puts some
portion of the read file into nio. The various formats' readTest()
@@ -17,7 +17,6 @@
ordering on the formats.
* generalize I/O so that magic needn't be on line by itself
* support Analyze/NIFTI format (relies on better buffering, above)
-* support DICOM, using as much of something like DCMTK as needed
* clarify and document all IO stuff
* debug and scrutinize current implementation of all "nhdr" related behavior
* support TIFF format
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-06-29 11:33:23
|
Revision: 7013
http://sourceforge.net/p/teem/code/7013
Author: kindlmann
Date: 2023-06-29 11:33:22 +0000 (Thu, 29 Jun 2023)
Log Message:
-----------
demonstrate anticipating and handling --help
Modified Paths:
--------------
teem/trunk/src/hest/test/ex3.c
Modified: teem/trunk/src/hest/test/ex3.c
===================================================================
--- teem/trunk/src/hest/test/ex3.c 2023-06-29 11:27:52 UTC (rev 7012)
+++ teem/trunk/src/hest/test/ex3.c 2023-06-29 11:33:22 UTC (rev 7013)
@@ -36,6 +36,7 @@
parm = hestParmNew();
parm->respFileEnable = AIR_TRUE;
+ parm->respectDashDashHelp = AIR_TRUE;
parm->verbosity = 3;
opt = NULL;
@@ -76,6 +77,15 @@
opt = hestOptFree(opt);
parm = hestParmFree(parm);
exit(1);
+ } else {
+ /* maybe got --help */
+ if (opt->helpWanted) {
+ hestUsage(stdout, opt, argv[0], parm);
+ hestGlossary(stdout, opt, parm);
+ opt = hestOptFree(opt);
+ parm = hestParmFree(parm);
+ exit(1);
+ }
}
printf("(err = %s)\n", err ? err : "(null)");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kin...@us...> - 2023-06-29 11:27:54
|
Revision: 7012
http://sourceforge.net/p/teem/code/7012
Author: kindlmann
Date: 2023-06-29 11:27:52 +0000 (Thu, 29 Jun 2023)
Log Message:
-----------
missing final newline
Modified Paths:
--------------
teem/trunk/src/hest/TODO.txt
Modified: teem/trunk/src/hest/TODO.txt
===================================================================
--- teem/trunk/src/hest/TODO.txt 2023-06-29 10:44:05 UTC (rev 7011)
+++ teem/trunk/src/hest/TODO.txt 2023-06-29 11:27:52 UTC (rev 7012)
@@ -38,4 +38,4 @@
The kind of option is independent of whether is flagged or unflagged,
optional (default given) or mandatory (no default given).
-??? What is relationship between parseHest.c/whichCase() and hestOpt.alloc ???
\ No newline at end of file
+??? What is relationship between parseHest.c/whichCase() and hestOpt.alloc ???
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|