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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
/**
* SAMP.C -- Interface routines for the client and server side of the
* SAMP messaging commands.
*/
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.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
#define import_prstat
#define import_xwhen
#include <iraf.h>
#include "config.h" /* CL declarations */
#include "clmodes.h"
#include "operand.h"
#include "mem.h"
#include "grammar.h"
#include "opcodes.h"
#include "param.h"
#include "task.h"
#include "errs.h"
#include "clsamp.h"
extern pid_t cl_pid;
extern int samp_registered;
extern char samp_cmd[SZ_CMDBLK];
extern int optbl[];
extern char *ifnames[];
extern Handler userHandlers[];
extern int numHandlers;
extern XINT samp; /* SAMP handle */
extern pthread_mutex_t samp_mutex; /* global data mutex */
extern char *voGetStrArg ();
/*****************************************************************************/
/* SAMPDBG -- Toggle the XML-RPC tracing flag.
*
* Usage: cl> =sampDbg (ival) # explicitly set debug value
* cl> =sampDbg () # toggle debug value
*/
void
func_sampDbg (void)
{
register struct pfile *pfp;
struct operand o;
static int sampDebug = 0;
extern int nargs();
pfp = newtask->t_pfp;
if (nargs (pfp) > 0) {
pushbparams (pfp->pf_pp);
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);
o.o_type = OT_BOOL;
o.o_val.v_i = sampDebug;
pushop (&o);
}
/* SAMPSTATUS -- Print or set the status of the samp interface.
*/
void
func_sampStatus (int nargs)
{
char *arg = NULL;
int i, stat = samp_registered, len = 0;
struct operand o;
if (nargs > 0) {
arg = voGetStrArg ();
if (strcasecmp ("on", arg) == 0 ||
strcasecmp ("start", arg) == 0) {
if (!samp_hubActive (samp))
cmd_sampStart ();
if (samp_registered && samp_hubActive (samp))
stat = 1;
} else if (strcasecmp ("off", arg) == 0 ||
strcasecmp ("stop", arg) == 0) {
if (samp_registered)
cmd_sampStop ();
stat = samp_registered;
} else if (strcasecmp ("restart", arg) == 0) {
cmd_sampRestart ();
stat = samp_registered;
}
if (arg) free ((void *) arg);
}
o.o_type = OT_STRING;
o.o_val.v_s = (stat ? "on" : "off");
pushop (&o);
}
/* SAMPHUBACCESS -- Check to see if a Hub is running and available.
*/
void
func_sampHubAccess (int nargs)
{
struct operand o;
int found = 0, verb;
char *home = envget ("HOME");
char path[SZ_LINE];
if (samp >= 0) {
verb = sampVerbose (samp, -1);
sampVerbose (samp, 0);
memset (path, 0, SZ_LINE);
sprintf (path, "%s/.samp", home);
found = (c_access (path, 0, 0) == YES);
sampVerbose (samp, verb);
}
o.o_type = OT_BOOL;
o.o_val.v_i = found;
pushop (&o);
}
/* 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.
*/
void
func_sampAccess (int nargs)
{
char *appName = NULL, *app = NULL;
int i, found = 0, len = 0;
struct operand o;
if (nargs > 0) {
XINT clients;
char *pubId = NULL;
extern char *samp_getStringFromList(), *samp_app2id();
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);
} else
cl_error (E_UERR, "Application name must be specifified");
o.o_type = OT_BOOL;
o.o_val.v_i = found;
pushop (&o);
}
/* SAMPNAME -- Set (or print) a current SAMP application name.
*/
void
func_sampName (int nargs)
{
char *name = NULL, res[SZ_LINE];
struct operand o;
if (nargs == 1) {
name = voGetStrArg ();
samp_Metadata (samp, "samp.name", name);
samp_DeclareMetadata (samp);
/* Push the result operand on the stack.
*/
strcpy (res, name);
o.o_type = OT_STRING;
o.o_val.v_s = res;
pushop (&o);
if (name) free ((void *) name);
} else if (nargs == 0) { /* list currently defined metadata */
extern XINT samp;
char *v = NULL;
/* Push the result operand on the stack.
*/
v = samp_getMetadata(samp, "samp.name");
o.o_type = OT_STRING;
o.o_val.v_s = v;
pushop (&o);
} else
cl_error (E_UERR, "usage: sampName ([name])");
}
/* SAMPMETADATA -- Set (or print) a current SAMP metadata parameters.
*/
void
func_sampMetadata (int nargs)
{
char *param = NULL, *value = NULL;
struct operand o;
if (nargs == 2) {
value = voGetStrArg (); /* ars on stack in reverse order */
param = voGetStrArg ();
samp_Metadata (samp, param, value);
samp_DeclareMetadata (samp);
if (param) free ((void *) param);
if (value) free ((void *) value);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = "ok";
pushop (&o);
} else if (nargs == 1) { /* list currently defined metadata */
param = voGetStrArg ();
samp_printMetadata (samp, param);
} else
cl_error (E_UERR, "usage: sampMetadata ([ [name], [value] ])");
}
/* CL_SAMPRESTART -- Restart the SAMP connection.
*/
void
func_sampRestart (void)
{
cmd_sampStop ();
cmd_sampStart ();
}
/* SAMPSTART -- Register with the SAMP Hub and begin messaging.
*/
void
func_sampStart (void)
{
if (!samp_registered) {
cmd_sampStart ();
samp_registered = 1;
} else
cmd_sampRestart(); /* disconnect and restart */
}
/* SAMPSTOP -- UnRegister from the SAMP Hub and stop messaging.
*/
void
func_sampStop (void)
{
if (samp_registered) {
samp_registered = 0;
cmd_sampStop ();
}
}
/* 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
void
func_sampSend (void)
{
register struct pfile *pfp;
char *mtype = NULL, *to = "all", *nam = NULL, *val = NULL;
char *args[MAX_ARGS];
int i, stat, numArgs;
struct operand o;
extern int nargs();
pfp = newtask->t_pfp;
numArgs = nargs (pfp);
if (numArgs > 0) {
pushbparams (pfp->pf_pp);
/* 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 < numArgs; 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;
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 < (numArgs - 1); i++) {
if (args[i])
free ((void *) args[i]);
}
} else
cl_error (E_UERR, "sampSend: No message specified\n");
/* Push the result on the stack.
*/
o.o_type = OT_BOOL;
o.o_val.v_i = stat;
pushop (&o);
}
/*****************************************************************************
* SAMP builtin function definitions. These are client-side commands.
****************************************************************************/
/**
* SAMP_HANDLER -- Add a user-defined handler to a specific mtype.
*
* Usage: sampHandler (mtype, cmd)
*
* Examples:
*/
void
func_sampAddHandler (int nargs)
{
char *mtype, *cmd, *arg1, *arg2;
int i, res = -1;
struct operand o;
o.o_type = OT_STRING;
if (nargs == 2) {
arg2 = voGetStrArg (); /* args on stack in reverse order */
arg1 = voGetStrArg ();
if (strncasecmp (arg1, "del", 3) == 0) {
/* samp handler delete foo.bar
*/
mtype = arg2;
res = cl_delUserHandler (mtype); /* add the handler */
} else {
/* samp handler foo.bar "cmd $arg"
*/
cmd = arg2; /* args on stack in reverse order */
mtype = arg1;
res = cl_addUserHandler (mtype, cmd); /* add the handler */
}
if (arg1) free ((void *) arg1);
if (arg2) free ((void *) arg2);
o.o_val.v_s = (res < 0 ? "error" : "ok");
} else if (nargs == 1) {
arg1 = mtype = voGetStrArg ();
if (strncasecmp (arg1, "del", 3) == 0) {
int i;
for (i=0; i < numHandlers; i++) {
memset (userHandlers[i].mtype, 0, SZ_FNAME);
memset (userHandlers[i].cmd, 0, SZ_FNAME);
}
numHandlers = 0;
} else {
for (i=0; i < numHandlers; i++) {
/* See if a handler is already defined for the given mtype.
*/
if (strcmp (userHandlers[i].mtype, mtype) == 0) {
res = OK;
break;
}
}
}
o.o_val.v_s = (res < 0 ? "" : userHandlers[i].cmd);
} else { /* list currently defined handlers */
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);
}
o.o_val.v_s = "ok";
}
pushop (&o); /* push the result operand on the stack */
}
/**
* SAMP_LOADIMAGE -- Send a 'image.load.fits' message to other clients.
*
* Usage: sampLoadImage (file|url [, to [, name [, tag ]]])
*
* Examples:
*
* 1) Broadcast the message to all subscribed clients:
*
* cl> = sampLoadImage ("http://iraf.noao.edu/votest/sif.fits")
* ok
*
* 2) Send the message to a named client:
*
* cl> = sampLoadImage ("data$foo.fits", "aladin")
* ok
*
* 3) Load the image with a given name:
*
* cl> = sampLoadImage ("/data/image001.fits", "aladin", "image1")
* ok
*
* If a message is sent to a named client that either isn't connected or
* returns an error, our result is the error string. On success, the string
* "ok" will be returned. It is not considered an error if a broadcast
* results in no clients actually receiving the message.
*/
void
func_sampLoadImage (int nargs)
{
char *what=NULL, *name=NULL, *tag=NULL, *to=NULL;
char url[SZ_PATHNAME+1], osfn[SZ_PATHNAME+1];
struct operand o;
/* Parse any remaining (optional) arguments. Remember that the args are
* on the stack in the reverse order! The 1st arg is required and will
* be either an ivo: identifier or is presumed to be the ShortName.
*/
switch (nargs) {
case 4:
tag = voGetStrArg ();
/* fall thru */
case 3:
name = voGetStrArg ();
/* fall thru */
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
what = voGetStrArg ();
if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
strcpy (url, what);
} else {
c_fmapfn (what, osfn, SZ_PATHNAME);
if (c_access (osfn, READ_ONLY, 0) == NO) {
cl_error (E_UERR, "Cannot access image '%s'", what);
return;
}
sprintf (url, "file://%s", osfn);
}
break;
default:
cl_error (E_UERR, "sampImLoad: invalid number of arguments\n");
return;
}
if (name == NULL) name = strdup (what);
if (tag == NULL) tag = strdup ("foo");
if (to == NULL) to = strdup ("all");
/* Send the message.
*/
o.o_type = OT_STRING;
if (samp_imageLoadFITS (samp, to, url, tag, name) != 0)
o.o_val.v_s = "ok";
else
o.o_val.v_s = samp_getErr (samp);
/* Push the result operand on the stack.
*/
pushop (&o);
/* Clean up and return. FIXME
*/
if (tag) free ((char *) tag);
if (name) free ((char *) name);
if (what) free ((char *) what);
if (to) free ((char *) to);
}
/**
* SAMP_LOADFITS -- Send a 'table.load.fits' message to other clients.
*
* Usage: sampLoadFITS (file|url [, to [, name [, tag ]]])
*
* Examples:
*
* 1) Broadcast the message to all subscribed clients:
*
* cl> = sampLoadFITS ("http://iraf.noao.edu/votest/sif.fits")
* ok
*
* 2) Send the message to a named client:
*
* cl> = sampLoadFITS ("data$foo.fits", "aladin")
* ok
*
* 3) Load the image with a given name:
*
* cl> = sampLoadFITS ("/data/image001.fits", "aladin", "image1")
* ok
*
* If a message is sent to a named client that either isn't connected or
* returns an error, our result is the error string. On success, the string
* "ok" will be returned. It is not considered an error if a broadcast
* results in no clients actually receiving the message.
*/
void
func_sampLoadFITS (int nargs)
{
char *what=NULL, *name=NULL, *tag=NULL, *to=NULL;
char url[SZ_PATHNAME+1], osfn[SZ_PATHNAME+1];
struct operand o;
/* Parse any remaining (optional) arguments. Remember that the args are
* on the stack in the reverse order! The 1st arg is required and will
* be either an ivo: identifier or is presumed to be the ShortName.
*/
switch (nargs) {
case 4:
tag = voGetStrArg ();
/* fall thru */
case 3:
name = voGetStrArg ();
/* fall thru */
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
what = voGetStrArg ();
if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
strcpy (url, what);
} else {
c_fmapfn (what, osfn, SZ_PATHNAME);
if (c_access (osfn, READ_ONLY, 0) == NO) {
cl_error (E_UERR, "Cannot access image '%s'", what);
return;
}
sprintf (url, "file://%s", osfn);
}
break;
default:
cl_error (E_UERR, "sampImLoad: invalid number of arguments\n");
return;
}
if (name == NULL) name = strdup (what);
if (tag == NULL) tag = strdup ("foo");
if (to == NULL) to = strdup ("all");
/* Send the message.
*/
o.o_type = OT_STRING;
if (samp_tableLoadFITS (samp, to, url, tag, name) != 0)
o.o_val.v_s = "ok";
else
o.o_val.v_s = samp_getErr (samp);
/* Push the result operand on the stack.
*/
pushop (&o);
/* Clean up and return.
*/
if (tag) free ((char *) tag);
if (name) free ((char *) name);
if (what) free ((char *) what);
if (to) free ((char *) to);
}
/**
* SAMP_LOADVOTABLE -- Send a 'table.load.votable' message to other clients.
*
* Usage: sampLoadVOTable (file|url [, to [, name [, tag ]]])
*
* Examples:
*
* 1) Broadcast the message to all subscribed clients:
*
* cl> = sampLoadFITS ("http://iraf.noao.edu/votest/sif.fits")
* ok
*
* 2) Send the message to a named client:
*
* cl> = sampLoadFITS ("data$foo.fits", "aladin")
* ok
*
* 3) Load the image with a given name:
*
* cl> = sampLoadFITS ("/data/image001.fits", "aladin", "image1")
* ok
*
* If a message is sent to a named client that either isn't connected or
* returns an error, our result is the error string. On success, the string
* "ok" will be returned. It is not considered an error if a broadcast
* results in no clients actually receiving the message.
*/
void
func_sampLoadVOTable (int nargs)
{
char *what=NULL, *name=NULL, *tag=NULL, *to=NULL;
char url[SZ_PATHNAME+1], osfn[SZ_PATHNAME+1];
struct operand o;
/* Parse any remaining (optional) arguments. Remember that the args are
* on the stack in the reverse order! The 1st arg is required and will
* be either an ivo: identifier or is presumed to be the ShortName.
*/
switch (nargs) {
case 4:
tag = voGetStrArg ();
/* fall thru */
case 3:
name = voGetStrArg ();
/* fall thru */
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
what = voGetStrArg ();
if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
strcpy (url, what);
} else {
c_fmapfn (what, osfn, SZ_PATHNAME);
if (c_access (osfn, READ_ONLY, 0) == NO) {
cl_error (E_UERR, "Cannot access file '%s'", what);
return;
}
sprintf (url, "file://%s", osfn);
}
break;
default:
cl_error (E_UERR, "sampLoadVOTable: invalid number of arguments\n");
return;
}
if (name == NULL) name = strdup (what);
if (tag == NULL) tag = strdup ("foo");
if (to == NULL) to = strdup ("all");
/* Send the message.
*/
o.o_type = OT_STRING;
if (samp_tableLoadVOTable (samp, to, url, tag, name) != 0)
o.o_val.v_s = "ok";
else
o.o_val.v_s = samp_getErr (samp);
/* Push the result operand on the stack.
*/
pushop (&o);
/* Clean up and return.
*/
if (tag) free ((char *) tag);
if (name) free ((char *) name);
if (what) free ((char *) what);
if (to) free ((char *) to);
}
/**
* SAMP_SHOWROW -- Send a 'table.highlight.row' message to other clients.
*
* Usage: sampShowRow (url, id, row [, to])
*/
void
func_sampShowRow (int nargs)
{
register int i, row=0, stat = 0;
char *to=NULL, *srow=NULL, *what=NULL, *tblId=NULL;
char osfn[SZ_PATHNAME], url[SZ_URL];
struct operand o;
memset (url, 0, SZ_URL);
switch (nargs) {
case 4:
to = voGetStrArg ();
/* fall thru */
case 3:
row = atoi ((srow = voGetStrArg ()));
/* fall thru */
case 2:
tblId = voGetStrArg ();
/* fall thru */
case 1:
what = voGetStrArg ();
if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
strcpy (url, what);
} else {
c_fmapfn (what, osfn, SZ_PATHNAME);
if (c_access (osfn, READ_ONLY, 0) == NO) {
cl_error (E_UERR, "Cannot access file '%s'", what);
return;
}
sprintf (url, "file://%s", osfn);
}
break;
default:
cl_error (E_UERR, "usage: sampShowRow (url, tblId, row[, to])");
return;
}
if (!to) to = strdup ("all");
stat = samp_tableHighlightRow (samp, to, tblId, url, row);
if (to) free ((void *) to);
if (srow) free ((void *) srow);
if (tblId) free ((void *) tblId);
if (what) free ((void *) what);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
/**
* SAMP_SELECTROWLIST -- Send a 'table.select.rowList' message to other
* clients.
*
* Usage: sampSelectRowList (url, id, row [, to])
*/
#define MAX_ROWSELECT 1024
void
func_sampSelectRowList (int nargs)
{
int i, nrows = 0, stat = 0, rows[MAX_ROWSELECT];
char *to=NULL, *srow=NULL, *what=NULL, *tblId=NULL;
char osfn[SZ_PATHNAME], url[SZ_URL], *ip, *n;
struct operand o;
memset (url, 0, SZ_URL);
switch (nargs) {
case 4:
to = voGetStrArg ();
/* fall thru */
case 3:
srow = voGetStrArg ();
/* fall thru */
case 2:
tblId = voGetStrArg ();
/* fall thru */
case 1:
what = voGetStrArg ();
if (strncmp(what, "http:", 5) == 0 || strncmp(what, "file:", 5) == 0) {
strcpy (url, what);
} else {
c_fmapfn (what, osfn, SZ_PATHNAME);
if (c_access (osfn, READ_ONLY, 0) == NO) {
cl_error (E_UERR, "Cannot access file '%s'", what);
return;
}
sprintf (url, "file://%s", osfn);
}
break;
default:
cl_error (E_UERR, "usage: sampShowRow (url, tblId, row[, to])");
return;
}
if (!to) to = strdup ("all");
/* Convert the row list string into an int array.
*/
for (ip=srow, n=srow, nrows=0; n; ip=n ) {
if ( (n = strchr (ip, (int) ',')) )
*n++ = '\0';
rows[nrows++] = atoi (ip);
}
stat = samp_tableSelectRowList (samp, to, tblId, url, rows, nrows);
if (to) free ((void *) to);
if (srow) free ((void *) srow);
if (tblId) free ((void *) tblId);
if (what) free ((void *) what);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
/**
* SAMP_POINTAT -- Send a 'coords.pointAt.sky' message to other clients.
*
* Usage: sampPointAt (ra, dec[, to])
*/
void
func_sampPointAt (int nargs)
{
register int i, stat;
char *arg = NULL, to[SZ_LINE];
float ra = -1.0, dec = 0.0;
struct operand o;
if (nargs > 0) {
strcpy (to, "all");
for (i=0; i < nargs; i++) {
arg = voGetStrArg (); /* args on stack in reverse order */
if (isalpha ((int) arg[0])) /* recipient arg */
strcpy (to, arg);
else if (ra < 0) /* not initialized yet */
dec = atof (arg);
else
ra = atof (arg);
if (arg) free ((char *) arg);
}
stat = samp_coordPointAtSky (samp, to, ra, dec);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat < 0 ? "error" : "ok");
pushop (&o);
} else
cl_error (E_UERR, "usage: sampPointAt (ra_deg, dec_deg)");
}
/**
* SAMP_SPECLOAD -- Send a 'spec.load.ssa-generic' message to other clients.
*
* Usage: sampSpecLoad ()
*/
void
func_sampSpecLoad (int nargs)
{
}
/**
* SAMP_BIBCODELOAD -- Send a 'bibcode.load' message to other clients.
*
* Usage: sampBibcodeLoad (bibcode[, to])
*/
void
func_sampBibcodeLoad (int nargs)
{
register int stat = 0;
char *to=NULL, *bibcode=NULL;
struct operand o;
switch (nargs) {
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
bibcode = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampShowRow (tblId, url, row[, to])");
return;
}
if (!to) to = strdup ("all");
stat = samp_bibLoad (samp, to, bibcode);
if (to) free ((void *) to);
if (bibcode) free ((void *) bibcode);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
/**
* SAMP_CMDEXEC -- Send a 'client.cmd.exec' message to other clients.
*
* Usage: sampCmdExec (cmd[, to]))
*/
void
func_sampCmdExec (int nargs)
{
register int stat = 0;
char *to=NULL, *cmd=NULL;
struct operand o;
switch (nargs) {
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
cmd = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampCmdExec (cmd[, to])");
return;
}
if (!to) to = strdup ("all");
stat = samp_cmdExec (samp, to, cmd);
if (to) free ((void *) to);
if (cmd) free ((void *) cmd);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
/**
* SAMP_ENVGET -- Send a 'client.env.get' message to other clients.
*
* Usage: sampEnvGet (param[, to]))
*/
void
func_sampEnvGet (int nargs)
{
char *res=NULL, *to=NULL, *param=NULL;
struct operand o;
switch (nargs) {
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
param = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampEnvGet (param[, to])");
return;
}
if (!to) to = strdup ("all");
res = samp_envGet (samp, to, param);
if (to) free ((void *) to);
if (param) free ((void *) param);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = res;
pushop (&o);
}
/**
* SAMP_ENVSET -- Send a 'client.env.set' message to other clients.
*
* Usage: sampEnvSet (param, val[, to]))
*/
void
func_sampEnvSet (int nargs)
{
register int stat = 0;
char *res=NULL, *to=NULL, *param=NULL, *val=NULL;
struct operand o;
switch (nargs) {
case 3:
to = voGetStrArg ();
/* fall thru */
case 2:
val = voGetStrArg ();
/* fall thru */
case 1:
param = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampEnvSet (param, val[, to])");
return;
}
if (!to) to = strdup ("all");
stat = samp_envSet (samp, to, param, val);
if (to) free ((void *) to);
if (param) free ((void *) param);
if (val) free ((void *) val);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
/**
* SAMP_PARAMGET -- Send a 'client.param.get' message to other clients.
*
* Usage: sampParamGet (param[, to]))
*/
void
func_sampParamGet (int nargs)
{
char *res=NULL, *to=NULL, *param=NULL;
struct operand o;
switch (nargs) {
case 2:
to = voGetStrArg ();
/* fall thru */
case 1:
param = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampParamGet (param[, to])");
return;
}
if (!to) to = strdup ("all");
res = samp_paramGet (samp, to, param);
if (to) free ((void *) to);
if (param) free ((void *) param);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = res;
pushop (&o);
}
/**
* SAMP_PARAMSET -- Send a 'client.param.set' message to other clients.
*
* Usage: sampParamSet (param, val[, to]))
*/
void
func_sampParamSet (int nargs)
{
register int stat = 0;
char *res=NULL, *to=NULL, *param=NULL, *val=NULL;
struct operand o;
switch (nargs) {
case 3:
to = voGetStrArg ();
/* fall thru */
case 2:
val = voGetStrArg ();
/* fall thru */
case 1:
param = voGetStrArg ();
break;
default:
cl_error (E_UERR, "usage: sampParamSet (param, val[, to])");
return;
}
if (!to) to = strdup ("all");
stat = samp_paramSet (samp, to, param, val);
if (to) free ((void *) to);
if (param) free ((void *) param);
if (val) free ((void *) val);
/* Push the result operand on the stack.
*/
o.o_type = OT_STRING;
o.o_val.v_s = (stat != 0 ? "ok" : samp_getErr(samp));
pushop (&o);
}
|