source: vendor/gawk/3.1.5/vms/vms_cli.c

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 3.2 KB
Line 
1/*
2 * vms_cli.c - command line interface routines.
3 * Pat Rankin, Nov'89
4 * Routines called from vms_gawk.c for DCL parsing.
5 */
6
7#define P(foo) ()
8#include "config.h" /* in case we want to suppress 'const' &c */
9#include "vms.h"
10#ifndef _STRING_H
11#include <string.h>
12#endif
13
14extern U_Long CLI$PRESENT(const Dsc *);
15extern U_Long CLI$GET_VALUE(const Dsc *, Dsc *, short *);
16extern U_Long CLI$DCL_PARSE(const Dsc *, const void *, ...);
17extern U_Long sys$cli(void *, ...);
18extern U_Long sys$filescan(const Dsc *, void *, long *);
19extern void *lib$establish(U_Long (*handler)(void *, void *));
20extern U_Long lib$sig_to_ret(void *, void *); /* condition handler */
21
22/* Cli_Present() - call CLI$PRESENT to determine whether a parameter or */
23/* qualifier is present on the [already parsed] command line */
24U_Long
25Cli_Present( const char *item )
26{
27 Dsc item_dsc;
28 (void)lib$establish(lib$sig_to_ret);
29
30 item_dsc.len = strlen(item_dsc.adr = (char *)item);
31 return CLI$PRESENT(&item_dsc);
32}
33
34/* Cli_Get_Value() - call CLI$GET_VALUE to retreive the value of a */
35/* parameter or qualifier from the command line */
36U_Long
37Cli_Get_Value( const char *item, char *result, int size )
38{
39 Dsc item_dsc, res_dsc;
40 U_Long sts;
41 short len = 0;
42 (void)lib$establish(lib$sig_to_ret);
43
44 item_dsc.len = strlen(item_dsc.adr = (char *)item);
45 res_dsc.len = size, res_dsc.adr = result;
46 sts = CLI$GET_VALUE(&item_dsc, &res_dsc, &len);
47 result[len] = '\0';
48 return sts;
49}
50
51/* Cli_Parse_Command() - use the $CLI system service (undocumented) to */
52/* retreive the actual command line (which might be */
53/* "run prog" or "mcr prog [params]") and then call */
54/* CLI$DCL_PARSE to parse it using specified tables */
55U_Long
56Cli_Parse_Command( const void *cmd_tables, const char *cmd_verb )
57{
58 struct { short len, code; void *adr; } fscn[2];
59 struct { char rqtype, rqindx, rqflags, rqstat; unsigned :32;
60 Dsc rdesc; unsigned :32; unsigned :32; unsigned :32; } cmd;
61 U_Long sts;
62 int ltmp;
63 char longbuf[8200];
64 (void)lib$establish(lib$sig_to_ret);
65
66 memset(&cmd, 0, sizeof cmd);
67 cmd.rqtype = CLI$K_GETCMD; /* command line minus the verb */
68 sts = sys$cli(&cmd, (void *)0, (void *)0); /* get actual command line */
69
70 if (vmswork(sts)) { /* ok => cli available & verb wasn't "RUN" */
71 /* invoked via symbol => have command line (which might be empty) */
72 /* [might also be invoked via mcr or dcl; that's ok] */
73 if (cmd.rqstat == CLI$K_VERB_MCR) {
74 /* need to strip image name from MCR invocation */
75 memset(fscn, 0, sizeof fscn);
76 fscn[0].code = FSCN$_FILESPEC; /* full file specification */
77 (void)sys$filescan(&cmd.rdesc, fscn, (long *)0);
78 cmd.rdesc.len -= fscn[0].len; /* shrink size */
79 cmd.rdesc.adr += fscn[0].len; /* advance ptr */
80 }
81 /* prepend verb and then parse the command line */
82 strcat(strcpy(longbuf, cmd_verb), " "), ltmp = strlen(longbuf);
83 if (cmd.rdesc.len + ltmp > sizeof longbuf)
84 cmd.rdesc.len = sizeof longbuf - ltmp;
85 strncpy(&longbuf[ltmp], cmd.rdesc.adr, cmd.rdesc.len);
86 cmd.rdesc.len += ltmp, cmd.rdesc.adr = longbuf;
87 sts = CLI$DCL_PARSE( &cmd.rdesc, cmd_tables);
88 }
89
90 return sts;
91}
Note: See TracBrowser for help on using the repository browser.