8 #include <epicsGetopt.h>
9 #include <epicsString.h>
17 std::cerr <<
"Usage: jcaput [-h] [-v] [-s#] [-1] [-i] [-w] pv [value1] [value2] [value3]" << std::endl;
18 std::cerr <<
"Usage: -h this help page" << std::endl;
19 std::cerr <<
"Usage: -v verbose output" << std::endl;
20 std::cerr <<
"Usage: -s# use character # to split stdin into an array" << std::endl;
21 std::cerr <<
"Usage: -1 send one element array rather than a single number/string" << std::endl;
22 std::cerr <<
"Usage: -i ignore whitespace in the input rather than creating an array" << std::endl;
23 std::cerr <<
"Usage: -w# set timeout for channel access to #, default 1.0 sec" << std::endl;
24 std::cerr <<
"Usage: pv required: process variable to send output to" << std::endl;
25 std::cerr <<
"Usage: [value1] [value2] ... optional: values to form array from (default: stdin)" << std::endl;
26 std::cerr <<
" " << std::endl;
27 std::cerr <<
"Usage: if no values are specified, stdin is read and split on the character specified by -s (default: space)" << std::endl;
28 std::cerr <<
" " << std::endl;
29 std::cerr <<
"Usage: echo first,second,third|jcaput -v -s, SOME:PROCESS:VARIABLE" << std::endl;
30 std::cerr <<
"Usage: jcaput -v SOME:PROCESS:VARIABLE first second third" << std::endl;
31 std::cerr <<
" " << std::endl;
36 int main(
int argc,
char* argv[])
38 std::string comp_str, str;
39 std::list<std::string> items;
40 const char* delims =
" \t\r\n";
42 long double waittime = 1.0f;
43 bool single_element =
false;
45 bool no_whitespace =
false;
46 while ((opt = getopt(argc, argv,
"1vhiw:s:")) != -1)
58 delims = strdup(optarg);
62 single_element =
true;
70 waittime = atof(optarg);
77 int nargs = argc - optind;
78 const char* pv = argv[optind];
86 std::getline(std::cin, str);
87 char* buffer = strdup(str.c_str());
89 const char* item = epicsStrtok_r(buffer, delims, &saveptr);
92 items.push_back(item);
93 item = epicsStrtok_r(NULL, delims, &saveptr);
100 for(
int i=optind+1; i<argc; ++i)
102 items.push_back(argv[i]);
105 std::string input =
"";
106 for(
int i=optind+1; i<argc; ++i)
108 input.append(argv[i]);
111 items.push_back(input);
115 if (!single_element && (items.size() == 1))
117 json =
"\"" + items.front() +
"\"";
126 std::ostringstream command;
127 command <<
"caput -S -w" << waittime <<
" " << pv <<
" " << comp_str;
130 std::cout <<
"jcaput: JSON: " << json << std::endl;
131 std::cout <<
"jcaput: " << command.str() << std::endl;
133 system(command.str().c_str());
int main(int argc, char *argv[])
epicsShareFunc std::string json_list_to_array(std::list< std::string > &items)
epicsShareFunc int epicsShareAPI compressString(const std::string &str, std::string &comp_str)
compress a string usinf zlib and then convert compressed bytes into an ascii hex sequence suitable fo...