#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <assert.h>
#include <errno.h>
#include "local.h"
#include "usc.h"
#include "mdsip.h"
#include "mdsshell.h"
#include "popt.h"
Go to the source code of this file.
Data Structures | |
| struct | MdsPutDescriptor |
| struct | CommandLut |
Defines | |
| #define | BUILD |
| #define | PROCLOGNAME "mdsshell" |
| #define | USE_GCC_CONST |
| #define | MAXDIMS 4 |
| #define | IMMEDIATE_IDENT '[' |
| #define | LIST_SEPS ",;:" |
| #define | MAXFILE 256 |
| #define | MAXARGS 40 |
| #define | DUMP_SHORTS "/tmp/shorts" |
| #define | FVAL(row, col) (((float *)ans->ptr)[(row)*numcols + (col)]) |
| #define | FULL_ARRAY "0,*" |
| #define | PDI(_key, _fs, typ, siz, fmt, puts) |
| #define | NTEMPLATES (sizeof(templates)/sizeof(struct MdsPutDescriptor)) |
| #define | NCMDS (sizeof(serverCommands)/sizeof(struct CommandLut)) |
| #define | IS_COMMENT(s) (s[0] == '#') |
Enumerations | |
| enum | FORMAT_SEL { FS_ERR, FS_FLOAT, FS_CSTRING, FS_SHORT, FS_LONG, FS_ULONG, FS_USHORT, FS_ULL } |
Functions | |
| void | set_timeout (int timeout_secs, jmp_buf *env) |
| int | SendMdsMsg (SOCKET sock, Message *m, int oob) |
| int | descr (int *dtype, void *data, int *dim1,...) |
| const char * | fname (const char *fn) |
| static int | doMdsPutError (const char *field, const char *value, struct Buf *out) |
| static int | doMdsPutFloat (const char *field, const char *value, struct Buf *out) |
| static int | doMdsPutLong (const char *field, const char *value, struct Buf *out) |
| static int | doMdsPutULL (const char *field, const char *value, struct Buf *out) |
| static int | doMdsPutCString (const char *field, const char *value, struct Buf *out) |
| static void | makeDims (struct descrip *valss, int ndims, int dims[], int length) |
| static int | getImmediateData (struct MdsPutDescriptor *pd, const char *filedef) |
| static int | _getFileData (struct MdsPutDescriptor *pd, const char *filedef, void *dest, int nread) |
| static int | getFileData (struct MdsPutDescriptor *pd, const char *filedef) |
| returns # elements | |
| static int | getPipeData (struct MdsPutDescriptor *pd, const char *pipedef) |
| returns # elements | |
| static int | fillData (struct MdsPutDescriptor *pd, int(*getData)(struct MdsPutDescriptor *pd, const char *value), const char *value) |
| static void | freeData (struct MdsPutDescriptor *pd) |
| static int | serverHelp (poptContext opt_context, struct Buf *out, void(*poptHelp)(poptContext con, FILE *f, int flags)) |
| static void | dumpData (FILE *fp, struct descrip *ans, int elt_size) |
| static void | dumpOctaveBuf (struct Buf *out, struct descrip *ans, int numcols, int numrows) |
| static void | dumpOctaveFile (FILE *file, struct descrip *ans, int numcols, int numrows) |
| static int | doMdsValue (int argc, const char *argv[], struct Buf *out) |
| we confine ourselves to floats for the moment | |
| static int | shuffle_up (void *ptr, int oldmajor, int offset, int newmajor, int old_len, int esize) |
| int | elt_size (void) |
| static int | MdsPutArray (int sock, char *field, char *expr, struct descrip *descrip, const char *subdef) |
| static void | setDim (int dims[], int id, int len) |
| static int | getDims (const char *dimdef, int dims[], int maxdims) |
| static struct MdsPutDescriptor * | lookupFormat (const char *key, struct MdsPutDescriptor *putdesc) |
| static void | helpFormat (struct Buf *out) |
| static int | doMdsPut (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsSetEvent (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsOpen (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsConnect (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsDisconnect (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsClose (int argc, const char *argv[], struct Buf *out) |
| static int | doMdsSetDef (int argc, const char *argv[], struct Buf *out) |
| static int | doUnrecognizedCommand (int argc, const char *argv[], struct Buf *out) |
| static void | help_visitor (void *vobj, const char *command) |
| static int | doMdsHelp (int argc, const char *argv[], struct Buf *out) |
| void | mdsshell_help (void) |
| void | mdsshell_iterateCommands (void(*visitor)(void *vobj, const char *command), void *vobj) |
| int | mdsshell_doServerCommand (struct IoBuf *cmd) |
Variables | |
| char * | mdsshell_rev = BUILD |
| int | acq200_debug = 0 |
| static long | S_sock |
| static const char * | froot |
| static char * | mds_put_expr = "$" |
| static struct MdsPutDescriptor | templates [] |
| static struct CommandLut | serverCommands [] |
executable may be run as server or client
uses a busybox-style named link system, argv[0] defines command
Definition in file mdsshell.c.
| #define BUILD |
Value:
"$Id: mdsshell.c,v 1.50 2010/02/03 08:08:12 pgm Exp $"\ "$Revision: 1.50 $ B1039\n"
Definition at line 220 of file mdsshell.c.
| #define DUMP_SHORTS "/tmp/shorts" |
Definition at line 559 of file mdsshell.c.
| #define FULL_ARRAY "0,*" |
| #define FVAL | ( | row, | |||
| col | ) | (((float *)ans->ptr)[(row)*numcols + (col)]) |
Referenced by dumpOctaveBuf().
| #define IMMEDIATE_IDENT '[' |
| #define IS_COMMENT | ( | s | ) | (s[0] == '#') |
| #define LIST_SEPS ",;:" |
| #define MAXARGS 40 |
Definition at line 557 of file mdsshell.c.
| #define MAXDIMS 4 |
| #define MAXFILE 256 |
| #define NCMDS (sizeof(serverCommands)/sizeof(struct CommandLut)) |
Definition at line 1420 of file mdsshell.c.
Referenced by mdsshell_doServerCommand(), mdsshell_help(), and mdsshell_iterateCommands().
| #define NTEMPLATES (sizeof(templates)/sizeof(struct MdsPutDescriptor)) |
| #define PDI | ( | _key, | |||
| _fs, | |||||
| typ, | |||||
| siz, | |||||
| fmt, | |||||
| puts | ) |
Value:
{ \
.key = _key, \
.id = _fs, \
.desc.dtype = typ, \
.element_size = siz, \
.scanfmt = fmt, \
.putScalar = puts }
Definition at line 1083 of file mdsshell.c.
| #define PROCLOGNAME "mdsshell" |
Definition at line 246 of file mdsshell.c.
| #define USE_GCC_CONST |
Definition at line 252 of file mdsshell.c.
| enum FORMAT_SEL |
Definition at line 1079 of file mdsshell.c.
| static int _getFileData | ( | struct MdsPutDescriptor * | pd, | |
| const char * | filedef, | |||
| void * | dest, | |||
| int | nread | |||
| ) | [static] |
Definition at line 349 of file mdsshell.c.
References MdsPutDescriptor::element_size, iobPrintf(), and MdsPutDescriptor::out.
Referenced by getFileData().
| int descr | ( | int * | dtype, | |
| void * | data, | |||
| int * | dim1, | |||
| ... | ||||
| ) |
| static int doMdsClose | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsConnect | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsDisconnect | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsHelp | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
Definition at line 1396 of file mdsshell.c.
References help_visitor(), and mdsshell_iterateCommands().
| static int doMdsOpen | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsPut | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
Definition at line 1147 of file mdsshell.c.
References MdsPutDescriptor::desc, MdsPutDescriptor::dims, fillData(), freeData(), froot, FULL_ARRAY, getDims(), getFileData(), getPipeData(), helpFormat(), iobPrintf(), lookupFormat(), MAXDIMS, MdsPutArray(), MdsPutDescriptor::ndims, MdsPutDescriptor::out, S_sock, serverHelp(), and setDim().
| static int doMdsPutCString | ( | const char * | field, | |
| const char * | value, | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsPutError | ( | const char * | field, | |
| const char * | value, | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsPutFloat | ( | const char * | field, | |
| const char * | value, | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsPutLong | ( | const char * | field, | |
| const char * | value, | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsPutULL | ( | const char * | field, | |
| const char * | value, | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsSetDef | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsSetEvent | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static int doMdsValue | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
we confine ourselves to floats for the moment
uchar usually from setEvent ... point NOT valid
Definition at line 644 of file mdsshell.c.
References acq200_debug, dumpData(), dumpOctaveBuf(), dumpOctaveFile(), guard1, iobPrintf(), S_sock, serverHelp(), set_timeout(), and timeout().
| static int doUnrecognizedCommand | ( | int | argc, | |
| const char * | argv[], | |||
| struct Buf * | out | |||
| ) | [static] |
| static void dumpData | ( | FILE * | fp, | |
| struct descrip * | ans, | |||
| int | elt_size | |||
| ) | [static] |
| static void dumpOctaveBuf | ( | struct Buf * | out, | |
| struct descrip * | ans, | |||
| int | numcols, | |||
| int | numrows | |||
| ) | [static] |
Definition at line 577 of file mdsshell.c.
References FVAL, and iobPrintf().
Referenced by doMdsValue().
| static void dumpOctaveFile | ( | FILE * | file, | |
| struct descrip * | ans, | |||
| int | numcols, | |||
| int | numrows | |||
| ) | [static] |
| int elt_size | ( | void | ) |
| static int fillData | ( | struct MdsPutDescriptor * | pd, | |
| int(*)(struct MdsPutDescriptor *pd, const char *value) | getData, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 435 of file mdsshell.c.
References MdsPutDescriptor::desc, MdsPutDescriptor::dims, MdsPutDescriptor::element_size, iobPrintf(), MdsPutDescriptor::len, makeDims(), MdsPutDescriptor::max_nelems, MdsPutDescriptor::ndims, and MdsPutDescriptor::out.
Referenced by doMdsPut().
| const char* fname | ( | const char * | fn | ) |
Definition at line 276 of file mdsshell.c.
References froot.
Referenced by _getRoot(), and getFileData().
| static void freeData | ( | struct MdsPutDescriptor * | pd | ) | [static] |
Definition at line 521 of file mdsshell.c.
References MdsPutDescriptor::desc.
Referenced by doMdsPut().
| static int getDims | ( | const char * | dimdef, | |
| int | dims[], | |||
| int | maxdims | |||
| ) | [static] |
| static int getFileData | ( | struct MdsPutDescriptor * | pd, | |
| const char * | filedef | |||
| ) | [static] |
returns # elements
Definition at line 369 of file mdsshell.c.
References _getFileData(), MdsPutDescriptor::desc, MdsPutDescriptor::element_size, fname(), iobPrintf(), LIST_SEPS, MdsPutDescriptor::max_nelems, MAXFILE, and MdsPutDescriptor::out.
Referenced by doMdsPut().
| static int getImmediateData | ( | struct MdsPutDescriptor * | pd, | |
| const char * | filedef | |||
| ) | [static] |
example: "%ld%*[],; ]%n"
Definition at line 321 of file mdsshell.c.
References MdsPutDescriptor::desc, MdsPutDescriptor::dims, MdsPutDescriptor::element_size, LIST_SEPS, and MdsPutDescriptor::scanfmt.
Referenced by getPipeData().
| static int getPipeData | ( | struct MdsPutDescriptor * | pd, | |
| const char * | pipedef | |||
| ) | [static] |
returns # elements
if it's an immediate array decode it, else read from pipe
Definition at line 415 of file mdsshell.c.
References MdsPutDescriptor::desc, MdsPutDescriptor::element_size, getImmediateData(), IMMEDIATE_IDENT, iobPrintf(), MdsPutDescriptor::len, and MdsPutDescriptor::out.
Referenced by doMdsPut().
| static void help_visitor | ( | void * | vobj, | |
| const char * | command | |||
| ) | [static] |
| static void helpFormat | ( | struct Buf * | out | ) | [static] |
Definition at line 1139 of file mdsshell.c.
References MdsPutDescriptor::element_size, iobPrintf(), MdsPutDescriptor::key, and NTEMPLATES.
Referenced by doMdsPut().
| static struct MdsPutDescriptor* lookupFormat | ( | const char * | key, | |
| struct MdsPutDescriptor * | putdesc | |||
| ) | [static, read] |
Definition at line 1114 of file mdsshell.c.
References MdsPutDescriptor::key, and NTEMPLATES.
Referenced by doMdsPut().
| static void makeDims | ( | struct descrip * | valss, | |
| int | ndims, | |||
| int | dims[], | |||
| int | length | |||
| ) | [static] |
| static int MdsPutArray | ( | int | sock, | |
| char * | field, | |||
| char * | expr, | |||
| struct descrip * | descrip, | |||
| const char * | subdef | |||
| ) | [static] |
Definition at line 972 of file mdsshell.c.
References elt_size(), FULL_ARRAY, and shuffle_up().
Referenced by doMdsPut().
| int mdsshell_doServerCommand | ( | struct IoBuf * | cmd | ) |
Definition at line 1445 of file mdsshell.c.
References acq200_debug, IoBuf::Buf::buf, IoBuf::in, IS_COMMENT, MAXARGS, NCMDS, IoBuf::out, serverCommands, and split().
Referenced by batch_work(), interpreter(), and server_work().
| void mdsshell_help | ( | void | ) |
Definition at line 1422 of file mdsshell.c.
References BUILD, NCMDS, and serverCommands.
Referenced by server().
| void mdsshell_iterateCommands | ( | void(*)(void *vobj, const char *command) | visitor, | |
| void * | vobj | |||
| ) |
Definition at line 1434 of file mdsshell.c.
References NCMDS, and serverCommands.
Referenced by doMdsHelp(), and makelinks().
| int SendMdsMsg | ( | SOCKET | sock, | |
| Message * | m, | |||
| int | oob | |||
| ) |
Referenced by doMdsSetEvent().
| static int serverHelp | ( | poptContext | opt_context, | |
| struct Buf * | out, | |||
| void(*)(poptContext con, FILE *f, int flags) | poptHelp | |||
| ) | [static] |
| void set_timeout | ( | int | timeout_secs, | |
| jmp_buf * | env | |||
| ) |
Definition at line 35 of file timeout.c.
References install_handlers(), and S_env.
Referenced by doMdsValue().
| static void setDim | ( | int | dims[], | |
| int | id, | |||
| int | len | |||
| ) | [static] |
| static int shuffle_up | ( | void * | ptr, | |
| int | oldmajor, | |||
| int | offset, | |||
| int | newmajor, | |||
| int | old_len, | |||
| int | esize | |||
| ) | [static] |
| int acq200_debug = 0 |
Definition at line 270 of file mdsshell.c.
const char* froot [static] |
char* mds_put_expr = "$" [static] |
Definition at line 642 of file mdsshell.c.
| char* mdsshell_rev = BUILD |
long S_sock [static] |
Definition at line 272 of file mdsshell.c.
Referenced by doMdsClose(), doMdsConnect(), doMdsDisconnect(), doMdsOpen(), doMdsPut(), doMdsPutCString(), doMdsPutFloat(), doMdsPutLong(), doMdsPutULL(), doMdsSetDef(), doMdsSetEvent(), and doMdsValue().
struct CommandLut serverCommands[] [static] |
Referenced by mdsshell_doServerCommand(), mdsshell_help(), and mdsshell_iterateCommands().
struct MdsPutDescriptor templates[] [static] |
Initial value:
{
PDI("float", FS_FLOAT, DTYPE_FLOAT,
sizeof(float), "%f", doMdsPutFloat),
PDI("string", FS_CSTRING, DTYPE_CSTRING,
sizeof(char), "%c", doMdsPutCString),
PDI("short", FS_SHORT, DTYPE_SHORT,
sizeof(short), "%hd", doMdsPutError),
PDI("shorts", FS_SHORT, DTYPE_SHORT,
sizeof(short), "%hd", doMdsPutError),
PDI("long", FS_LONG, DTYPE_LONG,
sizeof(long), "%ld", doMdsPutLong),
PDI("ulong", FS_ULONG, DTYPE_ULONG,
sizeof(unsigned long), "%lu", doMdsPutError),
PDI("ushort", FS_USHORT, DTYPE_USHORT,
sizeof(short), "%hu", doMdsPutError),
PDI("ull", FS_ULL, DTYPE_ULONGLONG,
sizeof(unsigned long long), "%ull", doMdsPutULL)
}
Definition at line 1092 of file mdsshell.c.
1.5.7.1