mdsshell.c File Reference

mds shell interface. More...

#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 MdsPutDescriptorlookupFormat (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 []


Detailed Description

mds shell interface.

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 Documentation

#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,*"

Definition at line 970 of file mdsshell.c.

Referenced by doMdsPut(), and MdsPutArray().

#define FVAL ( row,
col   )     (((float *)ans->ptr)[(row)*numcols + (col)])

Referenced by dumpOctaveBuf().

#define IMMEDIATE_IDENT   '['

Definition at line 295 of file mdsshell.c.

Referenced by getPipeData().

#define IS_COMMENT (  )     (s[0] == '#')

#define LIST_SEPS   ",;:"

Definition at line 296 of file mdsshell.c.

Referenced by getFileData(), and getImmediateData().

#define MAXARGS   40

Definition at line 557 of file mdsshell.c.

#define MAXDIMS   4

Definition at line 294 of file mdsshell.c.

Referenced by doMdsPut().

#define MAXFILE   256

Definition at line 298 of file mdsshell.c.

Referenced by getFileData().

#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))

Definition at line 1112 of file mdsshell.c.

Referenced by helpFormat(), and lookupFormat().

#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.


Enumeration Type Documentation

enum FORMAT_SEL

Enumerator:
FS_ERR 
FS_FLOAT 
FS_CSTRING 
FS_SHORT 
FS_LONG 
FS_ULONG 
FS_USHORT 
FS_ULL 

Definition at line 1079 of file mdsshell.c.


Function Documentation

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]

Definition at line 1356 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsConnect ( int  argc,
const char *  argv[],
struct Buf *  out 
) [static]

Definition at line 1332 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsDisconnect ( int  argc,
const char *  argv[],
struct Buf *  out 
) [static]

Definition at line 1348 of file mdsshell.c.

References iobPrintf(), and S_sock.

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]

Definition at line 1317 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsPut ( int  argc,
const char *  argv[],
struct Buf *  out 
) [static]

static int doMdsPutCString ( const char *  field,
const char *  value,
struct Buf *  out 
) [static]

Definition at line 923 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsPutError ( const char *  field,
const char *  value,
struct Buf *  out 
) [static]

Definition at line 846 of file mdsshell.c.

References iobPrintf().

static int doMdsPutFloat ( const char *  field,
const char *  value,
struct Buf *  out 
) [static]

Definition at line 852 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsPutLong ( const char *  field,
const char *  value,
struct Buf *  out 
) [static]

Definition at line 875 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsPutULL ( const char *  field,
const char *  value,
struct Buf *  out 
) [static]

Definition at line 897 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsSetDef ( int  argc,
const char *  argv[],
struct Buf *  out 
) [static]

Definition at line 1369 of file mdsshell.c.

References iobPrintf(), and S_sock.

static int doMdsSetEvent ( int  argc,
const char *  argv[],
struct Buf *  out 
) [static]

Definition at line 1302 of file mdsshell.c.

References S_sock, and SendMdsMsg().

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]

Definition at line 1383 of file mdsshell.c.

References iobPrintf().

static void dumpData ( FILE *  fp,
struct descrip *  ans,
int  elt_size 
) [static]

Definition at line 563 of file mdsshell.c.

Referenced by doMdsValue().

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]

Definition at line 614 of file mdsshell.c.

Referenced by doMdsValue().

int elt_size ( void   ) 

@WORKTODO

Definition at line 966 of file mdsshell.c.

Referenced by MdsPutArray().

static int fillData ( struct MdsPutDescriptor pd,
int(*)(struct MdsPutDescriptor *pd, const char *value)  getData,
const char *  value 
) [static]

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]

Definition at line 1057 of file mdsshell.c.

References setDim().

Referenced by doMdsPut().

static int getFileData ( struct MdsPutDescriptor pd,
const char *  filedef 
) [static]

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]

Definition at line 1390 of file mdsshell.c.

References iobPrintf().

Referenced by doMdsHelp().

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]

Definition at line 1010 of file mdsshell.c.

Referenced by fillData().

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  ) 

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]

Definition at line 529 of file mdsshell.c.

Referenced by doMdsPut(), and doMdsValue().

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]

Definition at line 1049 of file mdsshell.c.

Referenced by doMdsPut(), and getDims().

static int shuffle_up ( void *  ptr,
int  oldmajor,
int  offset,
int  newmajor,
int  old_len,
int  esize 
) [static]

Definition at line 946 of file mdsshell.c.

Referenced by MdsPutArray().


Variable Documentation

int acq200_debug = 0

Definition at line 270 of file mdsshell.c.

const char* froot [static]

Definition at line 273 of file mdsshell.c.

Referenced by doMdsPut(), and fname().

char* mds_put_expr = "$" [static]

Definition at line 642 of file mdsshell.c.

char* mdsshell_rev = BUILD

Definition at line 224 of file mdsshell.c.

Referenced by main(), and verid().

long S_sock [static]

struct CommandLut serverCommands[] [static]

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.


Generated on Wed Feb 3 08:08:33 2010 for mdsshell by  doxygen 1.5.7.1