aboutsummaryrefslogtreecommitdiff
path: root/pkg/vocl/sampCmd.c
blob: 79d39e0d2ed2a223de4628e97908d04f8015cd70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

/**
 *  SAMPCMD.C -- Procedures for the 'samp' user command.
 */

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <ctype.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <readline/readline.h>		/* to install rl_event_hook	*/

#define import_spp
#define import_libc
#define import_stdio
#include <iraf.h>

#include "config.h"			/* CL declarations		*/
#include "operand.h"
#include "task.h"
#include "errs.h"
#include "param.h"
#include "clsamp.h"


extern pid_t   cl_pid;
extern char    samp_cmd[SZ_CMDBLK];
extern char   *ifnames[];
extern Handler userHandlers[];
extern int     numHandlers;
extern int     samp_registered;
extern int     optbl[];

extern	XINT	samp;				/* SAMP handle 		*/
extern  pthread_mutex_t samp_mutex;		/* global data mutex	*/

extern	char   *voGetStrArg ();

int 	cl_sampStart (void);
int 	cl_sampStop (void);




/*****************************************************************************/



/* SAMPDBG -- Toggle the XML-RPC tracing flag.
 */
int
cmd_sampDbg (int nargs)
{
    struct operand o;
    static int sampDebug = 0;
    extern int samp_trace;


    if (nargs  > 0) {
        popop();                            	/* discard the $1       */
        o = popop();
        if (o.o_type != OT_INT)
            cl_error (E_UERR, "samp trace arg should be an integer");
        sampDebug = o.o_val.v_i;

    } else					/* toggle it		*/
        sampDebug = (sampDebug+1) % 2;

    unsetenv ("XMLRPC_TRACE_XML");
    if (sampDebug) {
	  setenv ("XMLRPC_TRACE_XML", "1", 1);
    }
    samp_trace = sampDebug;

    return (sampDebug);
}


/* CMD_SAMPADDHANDLER -- Set (or print) the user-defined handlers.
 */
int
cmd_sampAddHandler (int nargs)
{
    if (nargs > 0) {
	static char m[SZ_LINE], c[SZ_LINE];
        char  *mtype = m, *cmd = c, *arg1 = NULL, *arg2 = NULL;
        int    i, res = -1;

	memset (mtype, 0, SZ_LINE);
	memset (cmd, 0, SZ_LINE);

        popop();                            	/* discard the $1       */
        arg1 = mtype = voGetStrArg ();
	if (nargs > 1) {
            popop();                            /* discard the $2       */
            arg2 = cmd   = voGetStrArg ();
	}

	if (strncasecmp (arg1, "del", 3) == 0) {
            /*  Delete the handler, return (0 = OK, -1 = Error)
	     */
            return ((res = cl_delUserHandler (arg2)));

	} else {
            /*  Add the handler, return (0 = OK, -1 = Error)
	     */
            return ((res = cl_addUserHandler (mtype, cmd)));
	}

    } else { 			/*  list currently defined handlers  	*/
        int    i;

	if (numHandlers == 0)
	    oprintf ("No SAMP handlers defined\n");
	else {
	    for (i=0; i < numHandlers; i++)
	        oprintf ("%-20.20s %s\n", 
		    userHandlers[i].mtype, userHandlers[i].cmd);
	}
        return (0);				/* 0 = OK, -1 = Error	*/
    }
}


/* CMD_SAMPDELHANDLER -- Delete a user-defined handler.
 */
int
cmd_sampDelHandler (int nargs)
{
    if (nargs > 0) {
	static char m[SZ_LINE];
        char  *mtype = m;
        int    res = -1;

	memset (mtype, 0, SZ_LINE);

        popop();                            	/* discard the $1       */
        mtype = voGetStrArg ();

        /*  Delete the handler.
	 */
        return ((res = cl_delUserHandler (mtype)));

    } else { 			/*  list currently defined handlers  	*/
	int  i;

	for (i=0; i < numHandlers; i++) {
            memset (userHandlers[i].mtype, 0, SZ_FNAME);
            memset (userHandlers[i].cmd, 0, SZ_FNAME);
	}
	numHandlers = 0;

        return (0);				/* 0 = OK, -1 = Error	*/
    }
}


/* CMD_SAMPACCESS -- Require an external application to be registered.  We 
 * don't attempt to start the application ourselves, we simply report on 
 * whether it is currently available.
 */
int
cmd_sampAccess (int nargs)
{
    char   *appName = NULL, *app = NULL;
    int     i, found = 0, len = 0;


    if (nargs > 0) {
	extern XINT  samp;
        XINT clients;
	char   *pubId = NULL;
	extern char *samp_getStringFromList(), *samp_app2id();

        popop();                            	/* discard the $1       */
        appName = voGetStrArg ();
	if (strcasecmp ("hub", appName) == 0) 
	    pubId = "hub";
	else 
	    pubId =  samp_app2id (samp, appName);

	/*  Search the list for a matching appName
	 */
        clients = samp_GetRegisteredClients (samp);
        for (i=0; i < samp_listLen (clients); i++) {
	    app = samp_getStringFromList (clients, i);
	    len = min (strlen (pubId), strlen (app));
            if (strncasecmp (pubId, app, len) == 0) {
		found = 1;
		break;
	    }
	}
        samp_freeList (clients);

	if (appName)  
	    free ((void *) appName);
    } else 
	samp_listClients (samp);

    return (found);
}


/* CMD_SAMPNAME -- Set (or print) a current SAMP application name.
 */
int
cmd_sampName (int nargs)
{
    char   *name = NULL;
    extern  XINT  samp;


    if (nargs > 0) {
        popop();                            	/* discard the $1       */
        name = voGetStrArg ();

        samp_Metadata (samp, "samp.name", name);
	samp_DeclareMetadata (samp);

	if (name)  
	    free ((void *) name);
	return (1);

    } else {			/*  list currently defined metadata  	*/
	samp_printMetadata (samp, "samp.name");
	oprintf ("\n");
	return (0);
    }
}


/* CMD_SAMPMETADATA -- Set (or print) a current SAMP metadata parameters.
 */
int
cmd_sampMetadata (int nargs)
{
    char   *param = NULL, *value = NULL;
    extern  XINT  samp;


    if (nargs > 0) {
        popop();                            	/* discard the $1       */
        param = voGetStrArg ();
        popop();                            	/* discard the $2       */
        value   = voGetStrArg ();

        samp_Metadata (samp, param, value);
	samp_DeclareMetadata (samp);

	if (param)  
	    free ((void *) param);
	if (value)  
	    free ((void *) value);
	return (1);

    } else {			/*  list currently defined metadata  	*/
	samp_printMetadata (samp, NULL);
	return (0);
    }
}


/* CMD_SAMPRESTART -- Restart the SAMP connection.
 */
void
cmd_sampRestart (void)
{
    cmd_sampStop ();
    cmd_sampStart ();
}


/* CMD_SAMPSTART -- Register with the SAMP Hub and begin messaging.
 */
void
cmd_sampStart (void)
{
    extern XINT  samp;

    if (samp >= 0 && !samp_registered)
	cl_sampStart ();
    else
	cmd_sampRestart();			/*  disconnect and restart  */
}


/* CMD_SAMPSTOP -- UnRegister from the SAMP Hub and stop messaging.
 */
void
cmd_sampStop (void)
{
    extern  XINT  samp;

    if (samp >= 0 && samp_registered) {
        samp_registered = 0;
	cl_sampStop ();
    }
}


/*  CMD_SAMPSEND -- Send a generic message.  The format of a message on the 
 *  cmdline must be:
 *
 *	cl> sampSend <mtype> [to=<appName>] [<param>=<value> .....]
 *
 *  If there is no 'to' argument the message will be broadcast to all
 *  recipients, otherwise this is expected to be the name of the receiving
 *  application.  The mtype and parameters may correspond to well-known
 *  message type, in which case this is a low-level interface to sending
 *  those messages.  However, this method can also be used to send arbitrary
 *  messages using private mtypes.
 */
#define	MAX_ARGS	32

int
cmd_sampSend (int nargs)
{
    char   *mtype = NULL, *to = "all", *nam = NULL, *val = NULL;
    char   *args[MAX_ARGS];
    int    i, stat = -1;
    struct operand o;


    if (nargs > 0) {
	/*  Simple, first argument has to be the mtype.
	 */
        o = popop();                           	/* discard the $1           */
        mtype = voGetStrArg ();

	memset (args, 0, (MAX_ARGS * sizeof(char *)));
	for (i=1; i < nargs; i++) {
            o = popop();                       	/* param nam  or $N	    */
	    nam = o.o_val.v_s;

            o = popop();                       	/* param nam  or $N	    */
            val = o.o_val.v_s;

	    if (strcmp (nam, "to") == 0)
		to = val;		/* special case for recipient       */
	    else {
		args[i-1] = calloc (1, SZ_LINE);;
		sprintf (args[i-1], "%s=%s", nam, val);
	    }
	}

	stat = samp_sendGeneric (samp, to, mtype, args);

	for (i=0; i < (nargs - 1); i++)
	    if (args[i]) 
		free ((void *) args[i]);

	if (stat < 0)				/* error return		 */
            cl_error (E_UERR, samp_getErr (samp));

    } else
        cl_error (E_UERR, "sampSend: No message specified\n");

    return (stat);
}


/*****************************************************************************
 *  SAMP builtin function definitions.  These are client-side commands.
 ****************************************************************************/

/**
 *  SAMP_LOADIMAGE -- Send a 'image.load.fits' message to other clients.
 */

int
cmd_sampLoadImage (int nargs)
{
    char   to[SZ_LINE], url[SZ_LINE], name[SZ_LINE], id[SZ_LINE], *arg;
    char   what[SZ_LINE], osfn[SZ_PATHNAME], *ip, *op;
    int    i, stat = ERR;
    struct operand o;
    extern XINT samp;


    if (nargs > 0) {
	strcpy (to, "all");
	memset (url,  0, SZ_LINE);
	memset (name, 0, SZ_LINE);
	memset (id,   0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                      	/* discard the $N       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
		strcpy (to, arg);
	    else if (strcmp (o.o_val.v_s, "id") == 0)
		strcpy (id, arg);
	    else if (strcmp (o.o_val.v_s, "name") == 0)
		strcpy (name, arg);
	    else
		strcpy (what, arg);

	    if (arg) free ((void *) arg);
	}

	/*  Convert logical paths (e.g. dev$foo.fits) to host file URIs.
	 */
        if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
            strcpy (url, what);
        } else {
	    /* Need to construct a complete path name here.
	     */
            c_fpathname (what, osfn, SZ_PATHNAME);
	    if ((ip = strchr (osfn, (int) '!'))) {
		for (op = osfn, ip++; *ip; ) 	/* skip 'node!' prefix	*/
		    *op++ = *ip++;
		*op = '\0';
	    }
            sprintf (url, "file://%s", osfn);
        }

        stat = samp_imageLoadFITS (samp, to, url, id, name);
	if (stat < 0)				/* error return		 */
            cl_error (E_UERR, samp_getErr (samp));

    } else
        cl_error (E_UERR, "imageLoad: invalid number of arguments\n");

    return (stat);
}


/**
 *  SAMP_LOADFITS -- Send a 'table.load.fits' message to other clients.
 */

int
cmd_sampLoadFITS (int nargs)
{
    char   to[SZ_LINE], url[SZ_LINE], name[SZ_LINE], id[SZ_LINE], *arg;
    char   what[SZ_LINE], osfn[SZ_PATHNAME], *ip, *op;
    int    i, stat = ERR;
    struct operand o;
    extern XINT samp;


    if (nargs > 0) {
	strcpy (to, "all");
	memset (url,  0, SZ_LINE);
	memset (name, 0, SZ_LINE);
	memset (id,   0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                      	/* discard the $N       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
		strcpy (to, arg);
	    else if (strcmp (o.o_val.v_s, "id") == 0)
		strcpy (id, arg);
	    else if (strcmp (o.o_val.v_s, "name") == 0)
		strcpy (name, arg);
	    else
		strcpy (what, arg);

	    if (arg) free ((void *) arg);
	}

	/*  Convert logical paths (e.g. dev$foo.fits) to host file URIs.
	 */
        if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
            strcpy (url, what);
        } else {
	    /* Need to construct a complete path name here.
	     */
            c_fpathname (what, osfn, SZ_PATHNAME);
	    if ((ip = strchr (osfn, (int) '!'))) {
		for (op = osfn, ip++; *ip; ) 	/* skip 'node!' prefix	*/
		    *op++ = *ip++;
		*op = '\0';
	    }
            sprintf (url, "file://%s", osfn);
        }

        stat = samp_tableLoadFITS (samp, to, url, id, name);
	if (stat < 0)				/* error return		 */
            cl_error (E_UERR, samp_getErr (samp));

    } else
        cl_error (E_UERR, "loadFITS: invalid number of arguments\n");

    return (stat);
}


/**
 *  SAMP_LOADVOTABLE -- Send a 'table.load.votable' message to other clients.
 */

int
cmd_sampLoadVOTable (int nargs)
{
    char   to[SZ_LINE], url[SZ_LINE], name[SZ_LINE], id[SZ_LINE], *arg;
    char   what[SZ_LINE], osfn[SZ_PATHNAME], *ip, *op;
    int    i, stat = ERR;
    struct operand o;
    extern XINT samp;


    if (nargs > 0) {
	strcpy (to, "all");
	memset (url,  0, SZ_LINE);
	memset (name, 0, SZ_LINE);
	memset (id,   0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                      	/* discard the $N       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
		strcpy (to, arg);
	    else if (strcmp (o.o_val.v_s, "id") == 0)
		strcpy (id, arg);
	    else if (strcmp (o.o_val.v_s, "name") == 0)
		strcpy (name, arg);
	    else
		strcpy (what, arg);

	    if (arg) free ((void *) arg);
	}

	/*  Convert logical paths (e.g. dev$foo.fits) to host file URIs.
	 */
        if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
            strcpy (url, what);
        } else {
	    /* Need to construct a complete path name here.
	     */
            c_fpathname (what, osfn, SZ_PATHNAME);
	    if ((ip = strchr (osfn, (int) '!'))) {
		for (op = osfn, ip++; *ip; ) 	/* skip 'node!' prefix	*/
		    *op++ = *ip++;
		*op = '\0';
	    }
            sprintf (url, "file://%s", osfn);
        }

        stat = samp_tableLoadVOTable (samp, to, url, id, name);
	if (stat < 0)				/* error return		 */
            cl_error (E_UERR, samp_getErr (samp));

    } else
        cl_error (E_UERR, "loadVOTable: invalid number of arguments\n");

    return (stat);
}


/**
 *  SAMP_EXEC -- Send a 'client.cmd.exec' message to other clients.
 *
 *  Usage:   sampExec ()
 *
 *  Examples:
 */

int
cmd_sampExec (int nargs)
{
    char   *nam=NULL, *val=NULL, cmd[SZ_CMDBLK], to[SZ_LINE];
    int    i, stat = OK;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	for (i=0; i < nargs; i++) {
            o = popop ();
            val = voGetStrArg ();

	    if (o.o_val.v_s[0] == '$')
	        strcpy (cmd, val);
	    else
		strcpy (to, val);

	    if (val) free ((void *) val);
	}

	stat = samp_cmdExec (samp, to, cmd);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampExec: no command specified\n");
	stat = ERR;
    }

    return (stat);
}


/**
 *  SAMP_ENVSET -- Send a 'client.env.set' message to other clients.
 *
 *  Usage:   sampEnvSet ()
 *
 *  Examples:
 */

int
cmd_sampEnvSet (int nargs)
{
    char   name[SZ_LINE], val[SZ_LINE], to[SZ_LINE], *arg = NULL;
    int    i, stat = OK;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (name, 0, SZ_LINE);
	memset (val, 0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                            /* discard the $1       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (name[0] == NULL)
                strcpy (name, arg);
	    else {
		if (val[0]) 
		    strcat (val, "\\ ");
                strcat (val, arg);
	    }

	    if (arg)  free ((void *) arg);
	}

	if (!name[0] || !val[0]) {
            cl_error (E_UERR, "sampEnvSet: no variable or value specified\n");
	    stat = ERR;
	} else 
	    stat = samp_envSet (samp, to, name, val);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampEnvSet: no param or value specified\n");
	stat = ERR;
    }

    return (stat);
}


/**
 *  SAMP_ENVGET -- Send a 'client.env.get' message to other clients.
 *
 *  Usage:   sampEnvGet ()
 *
 *  Examples:
 */

char *
cmd_sampEnvGet (int nargs)
{
    char   name[SZ_LINE], to[SZ_LINE], *val = NULL, *arg = NULL;
    int    i;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (name, 0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                            /* discard the $1       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (name[0] == NULL)
                strcpy (name, arg);

	    if (arg)  free ((void *) arg);
	}

	val = samp_envGet (samp, to, name);

    } else 			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampEnvGet: no name specified\n");

    return (val);
}


/**
 *  SAMP_PARAMSET -- Send a 'client.param.set' message to other clients.
 *
 *  Usage:   sampParamSet ()
 *
 *  Examples:
 */

int
cmd_sampParamSet (int nargs)
{
    char   name[SZ_LINE], val[SZ_LINE], to[SZ_LINE], *arg = NULL;
    int    i, stat = OK;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (name, 0, SZ_LINE);
	memset (val, 0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                            /* discard the $1       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (name[0] == NULL)
                strcpy (name, arg);
	    else {
		if (val[0]) 
		    strcat (val, "\\ ");
                strcat (val, arg);
	    }

	    if (arg)  free ((void *) arg);
	}

	if (!name[0] || !val[0]) {
            cl_error (E_UERR, "sampParamSet: no param or value specified\n");
	    stat = ERR;
	} else 
	    stat = samp_paramSet (samp, to, name, val);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampParamSet: no param or value specified\n");
	stat = ERR;
    }

    return (stat);
}


/**
 *  SAMP_PARAMGET -- Send a 'client.param.get' message to other clients.
 *
 *  Usage:   sampParamGet ()
 *
 *  Examples:
 */

char *
cmd_sampParamGet (int nargs)
{
    char   name[SZ_LINE], to[SZ_LINE], *val = NULL, *arg = NULL;
    int    i;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (name, 0, SZ_LINE);

	for (i=0; i < nargs; i++) {
            o = popop();                            /* discard the $1       */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (name[0] == NULL)
                strcpy (name, arg);

	    if (arg)  free ((void *) arg);
	}

	val = samp_paramGet (samp, to, name);

    } else 			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampParamGet: no name specified\n");

    return (val);
}


/**
 *  SAMP_SHOWROW -- Send a 'table.highlight.row' message to other clients.
 *
 *  Usage:   sampShowRow ()
 *
 *  Examples:
 */

int
cmd_sampShowRow (int nargs)
{
    char   tblid[SZ_LINE], url[SZ_LINE], to[SZ_LINE], *arg = NULL;
    int    i, stat = OK, row = -1;
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (tblid, 0, SZ_LINE);
	memset (url, 0, SZ_LINE);
	for (i=0; i < nargs; i++) {
            o = popop();                       /* discard the $1        */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (isdigit(arg[0]))
		row = atoi (arg);
	    else if (strstr (arg, "://"))		/* url		*/
                strcpy (url, arg);
	    else if (tblid[0] == NULL && url[0])
                strcpy (tblid, arg);
	    else
                strcpy (url, arg);

	    if (arg) free ((void *) arg);
	}

	stat = samp_tableHighlightRow (samp, to, tblid, url, row);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampShowRow: no command specified\n");
	stat = ERR;
    }

    return (stat);
}


/**
 *  SAMP_SELECTROWLIST -- Send a 'table.select.rowList' message to other 
 *  clients.
 *
 *  Usage:   sampSelectRowList ()
 *
 *  Examples:
 */

#define	MAX_ROWSELECT		1024

int
cmd_sampSelectRowList (int nargs)
{
    char   tblid[SZ_LINE], url[SZ_LINE], to[SZ_LINE], *arg = NULL;
    int    i, nrows = 0, stat = OK, rows[MAX_ROWSELECT];
    struct operand o;
    extern XINT  samp;

    if (nargs > 0) {
	strcpy (to, "all");
	memset (tblid, 0, SZ_LINE);
	memset (url, 0, SZ_LINE);
	for (i=0; i < nargs; i++) {
            o = popop();                       /* discard the $1        */
            arg = voGetStrArg ();

	    if (strcmp (o.o_val.v_s, "to") == 0)
                strcpy (to, arg);
	    else if (isdigit(arg[0])) {
		/*  Need to decode array/range strings here.     -- FIXME --
		 */
		char *ip, *n;

		for (ip=arg, n=arg, nrows=0; n; ip=n ) {
		    if ( (n = strchr (ip, (int) ',')) )
			*n++ = '\0';
		    rows[nrows++] = atoi (ip);
		}

	    } else if (strstr (arg, "://"))		/* url		*/
                strcpy (url, arg);
	    else if (tblid[0] == NULL && url[0])
                strcpy (tblid, arg);
	    else
                strcpy (url, arg);

	    if (arg) free ((void *) arg);
	}

	stat = samp_tableSelectRowList (samp, to, tblid, url, rows, nrows);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampShowRow: no command specified\n");
	stat = ERR;
    }

    return (stat);
}


/**
 *  SAMP_POINTAT -- Send a 'coords.pointAt.sky' message to other clients.
 *
 *  Usage:   sampPointAt ()
 *
 *  Examples:
 *    samp pointat 187.5 33.4				# args in degrees
 *    samp pointat (12:30:00 * 15) 33:24		# sexagesimal hms
 *    samp pointat 187.5 33.4 to=aladin			# directed msg
 *
 */

int
cmd_sampPointAt (int nargs)
{
    char   *arg = NULL, to[SZ_LINE];
    int    i, stat = OK;
    float  ra=-1.0, dec=0.0;
    extern XINT  samp;

    if (nargs > 0) {
        strcpy (to, "all");
	for (i=0; i < nargs; i++) {
            popop();                            /* discard the $N       */
            arg = voGetStrArg ();

	    if (isalpha ((int) arg[0]))		/* recipient arg	*/
        	strcpy (to, arg);
	    else if (ra < 0)			/* not initialized yts	*/
	        ra = atof (arg);
	    else
	        dec = atof (arg);

	    if (arg) free ((char *) arg);
	}

	stat = samp_coordPointAtSky (samp, to, ra, dec);

    } else {			/*  list currently defined metadata  	*/
        cl_error (E_UERR, "sampPointAt: no command specified\n");
	stat = ERR;
    }

    return (stat);
}




/******************************************************************************
 **
 **  			    Not Yet Implemented
 **
 *****************************************************************************/
/**
 *  SAMP_SPECLOAD -- Send a 'spec.load.ssa-generic' message to other clients.
 */

int
cmd_sampSpecLoad (int nargs)
{
    return (0);
}


/**
 *  SAMP_BIBCODELOAD -- Send a 'bibcode.load' message to other clients.
 */

int
cmd_sampBibcodeLoad (int nargs)
{
    return (0);
}