Added -l.. commandline options to catools (by Stephanie Allison)

This commit is contained in:
Ralph Lange
2009-12-15 22:05:55 +00:00
parent aeec8ffca2
commit c8470a2473
5 changed files with 84 additions and 18 deletions

View File

@@ -1280,6 +1280,18 @@ the output.</p>
<td>-s</td>
<td>Get value as string (may honour server-side precision)</td>
</tr>
<tr>
<td>-lx</td>
<td>Round to long integer and print as hex number</td>
</tr>
<tr>
<td>-lo</td>
<td>Round to long integer and print as octal number</td>
</tr>
<tr>
<td>-lb</td>
<td>Round to long integer and print as binary number</td>
</tr>
<tr>
<td></td>
<td><strong>Integer number format:</strong></td>
@@ -1412,6 +1424,18 @@ the output.</p>
<td>-s</td>
<td>Get value as string (may honour server-side precision)</td>
</tr>
<tr>
<td>-lx</td>
<td>Round to long integer and print as hex number</td>
</tr>
<tr>
<td>-lo</td>
<td>Round to long integer and print as octal number</td>
</tr>
<tr>
<td>-lb</td>
<td>Round to long integer and print as binary number</td>
</tr>
<tr>
<td></td>
<td><strong>Integer number format:</strong></td>

View File

@@ -88,6 +88,9 @@ static void usage (void)
" -f <nr>: Use %%f format, with a precision of <nr> digits\n"
" -g <nr>: Use %%g format, with a precision of <nr> digits\n"
" -s: Get value as string (may honour server-side precision)\n"
" -lx: Round to long integer and print as hex number\n"
" -lo: Round to long integer and print as octal number\n"
" -lb: Round to long integer and print as binary number\n"
"Integer number format:\n"
" Default: Print as decimal number\n"
" -0x: Print as hex number\n"
@@ -376,6 +379,7 @@ int main (int argc, char *argv[])
int result; /* CA result */
OutputT format = plain; /* User specified format */
RequestT request = get; /* User specified request type */
IntFormatT outType; /* Output type */
int count = 0; /* 0 = not specified by -# option */
int opt; /* getopt() current option */
@@ -387,7 +391,7 @@ int main (int argc, char *argv[])
setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */
while ((opt = getopt(argc, argv, ":taicnhsSe:f:g:#:d:0:w:p:F:")) != -1) {
while ((opt = getopt(argc, argv, ":taicnhsSe:f:g:l:#:d:0:w:p:F:")) != -1) {
switch (opt) {
case 'h': /* Print usage */
usage();
@@ -472,15 +476,24 @@ int main (int argc, char *argv[])
"out of range - ignored.\n", digits, opt);
}
break;
case 'l': /* Convert to long and use integer format */
case '0': /* Select integer format */
type = DBR_LONG;
switch ((char) *optarg) {
case 'x': outType = hex; break; /* 0x print Hex */
case 'b': outType = bin; break; /* 0b print Binary */
case 'o': outType = oct; break; /* 0o print Octal */
case 'x': outType = hex; break; /* x print Hex */
case 'b': outType = bin; break; /* b print Binary */
case 'o': outType = oct; break; /* o print Octal */
default :
outType = dec;
fprintf(stderr, "Invalid argument '%s' "
"for option '-0' - ignored.\n", optarg);
"for option '-%c' - ignored.\n", optarg, opt);
}
if (outType != dec) {
if (opt == '0') {
type = DBR_LONG;
outTypeI = outType;
} else {
outTypeF = outType;
}
}
break;
case 'F': /* Store this for output and tool_lib formatting */

View File

@@ -71,6 +71,9 @@ void usage (void)
" -f <nr>: Use %%f format, with a precision of <nr> digits\n"
" -g <nr>: Use %%g format, with a precision of <nr> digits\n"
" -s: Get value as string (may honour server-side precision)\n"
" -lx: Round to long integer and print as hex number\n"
" -lo: Round to long integer and print as octal number\n"
" -lb: Round to long integer and print as binary number\n"
"Integer number format:\n"
" Default: Print as decimal number\n"
" -0x: Print as hex number\n"
@@ -204,6 +207,7 @@ int main (int argc, char *argv[])
int returncode = 0;
int n = 0;
int result; /* CA result */
IntFormatT outType; /* Output type */
int opt; /* getopt() current option */
int digits = 0; /* getopt() no. of float digits */
@@ -213,7 +217,7 @@ int main (int argc, char *argv[])
setvbuf(stdout,NULL,_IOLBF,BUFSIZ); /* Set stdout to line buffering */
while ((opt = getopt(argc, argv, ":nhm:sSe:f:g:#:d:0:w:t:p:F:")) != -1) {
while ((opt = getopt(argc, argv, ":nhm:sSe:f:g:l:#:0:w:t:p:F:")) != -1) {
switch (opt) {
case 'h': /* Print usage */
usage();
@@ -307,14 +311,20 @@ int main (int argc, char *argv[])
"out of range - ignored.\n", digits, opt);
}
break;
case 'l': /* Convert to long and use integer format */
case '0': /* Select integer format */
switch ((char) *optarg) {
case 'x': outType = hex; break; /* 0x print Hex */
case 'b': outType = bin; break; /* 0b print Binary */
case 'o': outType = oct; break; /* 0o print Octal */
case 'x': outType = hex; break; /* x print Hex */
case 'b': outType = bin; break; /* b print Binary */
case 'o': outType = oct; break; /* o print Octal */
default :
outType = dec;
fprintf(stderr, "Invalid argument '%s' "
"for option '-0' - ignored.\n", optarg);
"for option '-%c' - ignored.\n", optarg, opt);
}
if (outType != dec) {
if (opt == '0') outTypeI = outType;
else outTypeF = outType;
}
break;
case 'F': /* Store this for output and tool_lib formatting */

View File

@@ -45,7 +45,8 @@ static int tsInitC = 0; /* Flag: Client timestamps init'd */
TimeT tsType = absolute; /* Timestamp type flag (-t option) */
int tsSrcServer = 1; /* Timestamp source flag (-t option) */
int tsSrcClient = 0; /* Timestamp source flag (-t option) */
IntFormatT outType = dec; /* For -0.. output format option */
IntFormatT outTypeI = dec; /* For -0.. output format option */
IntFormatT outTypeF = dec; /* For -l.. output format option */
char dblFormatStr[30] = "%g"; /* Format string to print doubles (-efg options) */
char timeFormatStr[30] = "%Y-%m-%d %H:%M:%S.%06f"; /* Time format string */
@@ -60,7 +61,7 @@ capri caPriority = DEFAULT_CA_PRIORITY; /* CA Priority */
void sprint_long (char *ret, long val)
void sprint_long (char *ret, long val, IntFormatT outType)
{
long i, bit, skip=-1L; /* used only for printing bits */
switch (outType) {
@@ -108,6 +109,7 @@ char *val2str (const void *v, unsigned type, int index)
char ch;
void *val_ptr;
unsigned base_type;
dbr_long_t val_long;
if (!dbr_type_is_valid(type)) {
strcpy (str, "*** invalid type");
@@ -126,20 +128,36 @@ char *val2str (const void *v, unsigned type, int index)
epicsStrnEscapedFromRaw(str, STR, ((dbr_string_t*) val_ptr)[index], strlen(((dbr_string_t*) val_ptr)[index]));
break;
case DBR_FLOAT:
sprintf(str, dblFormatStr, ((dbr_float_t*) val_ptr)[index]);
if (outTypeF == dec) {
sprintf(str, dblFormatStr, ((dbr_float_t*) val_ptr)[index]);
} else {
if (((dbr_float_t*) val_ptr)[index] > 0.0)
val_long = ((dbr_float_t*) val_ptr)[index] + 0.5;
else
val_long = ((dbr_float_t*) val_ptr)[index] - 0.5;
sprint_long(str, val_long, outTypeF);
}
break;
case DBR_DOUBLE:
sprintf(str, dblFormatStr, ((dbr_double_t*) val_ptr)[index]);
if (outTypeF == dec) {
sprintf(str, dblFormatStr, ((dbr_double_t*) val_ptr)[index]);
} else {
if (((dbr_double_t*) val_ptr)[index] > 0.0)
val_long = ((dbr_double_t*) val_ptr)[index] + 0.5;
else
val_long = ((dbr_double_t*) val_ptr)[index] - 0.5;
sprint_long(str, val_long, outTypeF);
}
break;
case DBR_CHAR:
ch = ((dbr_char_t*) val_ptr)[index];
sprintf(str, "%d", ch);
break;
case DBR_INT:
sprint_long(str, ((dbr_int_t*) val_ptr)[index]);
sprint_long(str, ((dbr_int_t*) val_ptr)[index], outTypeI);
break;
case DBR_LONG:
sprint_long(str, ((dbr_long_t*) val_ptr)[index]);
sprint_long(str, ((dbr_long_t*) val_ptr)[index], outTypeI);
break;
case DBR_ENUM:
{

View File

@@ -78,7 +78,8 @@ typedef struct
extern TimeT tsType; /* Timestamp type flag (-t option) */
extern int tsSrcServer; /* Timestamp source flag (-t option) */
extern int tsSrcClient; /* Timestamp source flag (-t option) */
extern IntFormatT outType; /* Flag used for -0.. output format option */
extern IntFormatT outTypeI; /* Flag used for -0.. output format option */
extern IntFormatT outTypeF; /* Flag used for -l.. output format option */
extern int enumAsNr; /* Used for -n option (get DBF_ENUM as number) */
extern int charArrAsStr; /* used for -S option - treat char array as (long) string */
extern double caTimeout; /* Wait time default (see -w option) */