/* * Get data from the APM catalogues server. * * This is a standalone program which makes a request of the * APM catalogues system based on command line arguments and returns * either a list or a postscript finding chart on standard output. * * VMS Notes: * This program assumes Multinet TCP/IP support. * This program expects to run as a foreign command. * If standard output (SYS$OUTPUT) is redirected to a file (using * ASSIGN or DEFINE) the resulting file will have control * characters before each record. * * This version should compile under Ultrix and VMS/Multinet. * * Created: 1-February-1995 by T. McGlynn * Goddard Space Flight Center * Universities Space Research Association * Code 668.1 * Modified by Geraint Lewis and Mike Irwin to support APM online catalogues * 1-April-1996 * */ /*#define APMCAT "131.111.68.247" - alternative form if name resolver is crap*/ #define APMCAT "www.ast.cam.ac.uk" #define PORT 80 #define ERROR -1 #ifdef VMS /* Assumes Multinet support */ #include "multinet_root:[multinet.include.sys]types.h" #include "multinet_root:[multinet.include.sys]socket.h" #include "multinet_root:[multinet.include.netinet]in.h" #include #include "multinet_root:[multinet.include]netdb.h" /* To use with the UCX TCPIP stack, replace the directories in multinet_root: in ALL FOUR CASES above with DISK$SYSTEM:[VMS$COMMON.DECC$LIB.REFERENCE.DECC$RTLDEF] where DISK$SYSTEM is the (logical) name of the disk where the files reside and compile with CC/STANDARD=VAXC. (Tested with UCX V4.1-12G and DEC C V5.5-002 on OpenVMS V7.1 Alpha) - Phillip Helbig */ #else #include #include #include #include #include #endif /* Define return types of functions */ char *mo_code(); char *form_request(); char *strchr(); void lowcase(); /* Request buffer */ char req_str[2048]; char *out_file = 0; /* Is this an informational request */ int info_req = 0; int main(argc, argv) int argc; char *argv[]; { int name_given=0; /* Name or lists? */ /* Request fields */ char survey[64], equinox[64], email[64]; char box[64], img[64], list[64]; char coords[1024], numbers[64]; int i; char *p; /* Initialize all fields to zero */ survey[0] = 0; equinox[0] = 0; email[0] = 0; box[0] = 0; img[0] = 0; list[0] = 0; coords[0] = 0; numbers[0] = 0; /* Check that there are enough arguments */ if (argc < 2) { printf("Usage: apmcat ra dec [optional arguments]\n"); printf("\n"); printf(" where the optional arguments are of the form\n"); printf(" keyword=value. Valid arguments include:\n"); printf(" survey=poss1 [ukst]\n"); printf(" box=5 [box size in arcmins]\n"); printf(" equinox=b1950 [j2000]\n"); printf(" ps=image.ps [name of postscript image]\n"); printf(" list=image.lis [name of list file]\n"); printf(" numbers=n [numbers on plot ? n/y]\n"); printf(" email=null [email address]\n"); printf(" The above values are the defaults.\n"); printf(" The default is to return a postscript \n"); printf(" image with the name image.ps \n\n"); printf(" Please specify either a list or a postscript image\n"); printf("\n"); printf("Examples:\n"); printf(" apmcat \"00 40 00.00\" \"11 41 00\" survey=poss1 ps=chart.ps\n"); printf(" apmcat \"10 31 21.3 -5 10 23\" survey=ukst list=chart.list\n"); printf("\n"); exit(); } /* Convert all arguments to lower case */ for (i=0; i= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') )) { sprintf(t, "%%%+2x", c); t += 3; } else { *t = c; t++; } c = *++s; } *t = 0; return buf; } /* Read from input until we can fill the buffer */ int getbuf(s, rbuf, qlen) int s; char *rbuf; int qlen; { static int left=0; static char bigbuf[32768]; int n; int len = qlen; int i; while (len > left) { n = recv(s, bigbuf+left, sizeof(bigbuf)-left, 0); if (n <= 0) { if (left <= 0) return( -1); else { len = left; break; } } else { left = left + n; } } memcpy(rbuf, bigbuf, len); left = left - len; if (left > 0) for (i = 0; i < left; i++) bigbuf[i] = bigbuf[i+len]; /* memmove(bigbuf, bigbuf+len, left); */ return len; } /* Transfer data from socket to standard output */ int ptrans(s) int s; { char line[16384]; int lcnt = 0; int scaling = 0; char lbuf[20]; char bigbuf[2880]; int nlset=0; char c; int fp=1; /* Look for a double newline to signal the beginning of the data */ while (1) { if (getbuf(s, &c, 1) < 0) return ERROR; if (c == '\012') { if (nlset) break; else nlset = 1; } else nlset = 0; } if (out_file) if (*out_file) { if (info_req) fp = creat(out_file, 0644); else { fp = creat(out_file, #ifdef VMS /* Use default file mode for VMS */ 0,"bls=2880","rfm=fix", "mrs=2880" #else 0644 #endif ); } if (fp <=0) { printf("ERROR: Unable to open output file %s\n", out_file); perror(" creat"); } } lcnt=getbuf(s, line, 1); while(1) { lcnt=getbuf(s, line, 2880); if (lcnt <= 0) break; write(fp, line, lcnt); } return 0; } void lowcase(s) char *s; { /* This procedure converts a string, s, to lower case */ char *p; p = s; while (*p) { if (isalpha(*p)) *p = tolower(*p); p++; } }