示例#1
0
	/***************************************************************
	 * make_entityString:
	 ***************************************************************/
static void  make_entityString(
    void  *entity		/* <r> dsc or cstring			*/
   ,char  entityString[]	/* <w> string to create			*/
   ,int   maxlen		/* <r> sizeof(entityString)		*/
   )
   {
    int   k;
    char  *p;
    struct descriptor  *dsc;

    if (is_cdescr(entity) || is_ddescr(entity))
       {
        dsc = entity;
        p = dsc->dscA_pointer;
        k = dsc->dscW_length;
       }
    else
       {
        p = entity;
        k = strlen(p);
       }
    if (k >= maxlen)
       {
        fprintf(stderr,"\n*ERR* entityString too long!\n\n");
        exit(0);
       }
    strncpy(entityString,p,k);
    entityString[k] = '\0';
    strtrim(entityString,0);
    l2u(entityString,0);

    return;
   }
示例#2
0
	/*****************************************************************
	 * cli_dcl_parse:
	 *****************************************************************/
int   cli_dcl_parse(		/* Returns: status			*/
    void  *command_string	/* <r:opt> descr or c-string		*/
   ,struct cduVerb  *table	/* <r> addr of command table		*/
   ,int   (*param_routine)()	/* <r:opt> routine to read req'd params	*/
   ,int   (*prompt_routine)()	/* <r:opt> routine to read command string*/
   ,void  *uprompt		/* <r:opt> descr or c-string		*/
   )
   {
    int   k;
    int   opt;
    int   sts;
    char  *p;
    char  prompt[48];
    struct cduParam  *prm;
    struct cduValue  *val;
    struct descriptor  *dsc;
    static DYNAMIC_DESCRIPTOR(dsc_parameter);

    if (USE_HYPHEN_CONTINUATION == -1)
      USE_HYPHEN_CONTINUATION = getenv("VMS_SEMANTICS") ? 0 : 1;


    clearCurrentSyntax();
    init_table(table);
    if (!uprompt)
        strcpy(prompt,"Command> ");
    else
       {
        if (is_cdescr(uprompt))
           {
            dsc = uprompt;
            p = dsc->dscA_pointer;
            k = dsc->dscW_length;
           }
        else if (is_ddescr(uprompt))
           {
            dsc = uprompt;
            p = dsc->dscA_pointer;
            k = dsc->dscW_length;
            if (!p && !k)
               {			/* null descriptor		*/
                p = "Command> ";
                k = strlen(p);
              }
           }
        else
           {
            p = uprompt;
            k = strlen(uprompt);
           }
        if (k >= sizeof(prompt))
            k = sizeof(prompt) - 1;
        strncpy(prompt,p,k);
        prompt[k] = '\0';
       }

		/*======================================================
		 * Set 'p' to start of command line ...
		 *=====================================================*/
    if (p = command_string)
       {
        if (is_cdescr(command_string) || is_ddescr(command_string))
           {
            dsc = command_string;
            p = dsc->dscA_pointer;
           }
       }
    if (!p)
       {
        sts = prompt_routine(prompt,&dsc_cmdline);
        if (~sts & 1)
            return(sts);		/*--------------------> return	*/
        p = nonblank(dsc_cmdline.dscA_pointer);
        if (!p)
            return(CLI_STS_NOCOMD);	/*---------> return: blank line	*/
       }

		/*=====================================================
		 * Get the command verb ...
		 *====================================================*/
    opt = cmd_lookup(&p,cmdVerb,0,NOMSG|NO_BEMORESPECIFIC,0);
    if (!opt)
        sts = CLI_STS_IVVERB;
    else
       {
        paramId = 0;
        setCurrentSyntax(TRUE,currentTable+(opt-1));
        sts = cli_process_verb(&p,prompt);
       }
    if (~sts & 1)
        return(sts);			/*---------------> return: err	*/

		/*======================================================
		 * "paramId" indicates number of parameters on line.
		 * Check that all required parameters are present ...
		 *=====================================================*/
    for ( ; (prm=currentParameters+paramId) && prm->prmA_value ; )
       {
        val = prm->prmA_value;
        if (!(val->valL_flags & VAL_M_REQUIRED))
            break;		/* done:  required params come first	*/
        sprintf(prompt,"_%s: ",
            prm->prmA_prompt ? prm->prmA_prompt :
            (prm->prmA_label ? prm->prmA_label : prm->prmA_name));

        for (p=0 ; !p ; )
           {
            sts = param_routine(prompt,&dsc_parameter);
            if (~sts & 1)
                return(sts);		/*--------------------> return	*/
            p = nonblank(dsc_parameter.dscA_pointer);
           }
        str_append(&dsc_cmdline," ");
        str_append(&dsc_cmdline,&dsc_parameter);
        sts = cli_process_verb(&p,"...");
       }
    return(sts);
   }
示例#3
0
/****************************************************************
 * mdsdcl_dcl_parse:
 *****************************************************************/
int   mdsdcl_dcl_parse(		/* Returns CLI_STS_xxx status	*/
    void  *command			/* <r:opt> command string	*/
    ,struct _mdsdcl_ctrl  *ctrl		/* <m> control structure	*/
    ,int   tabidx			/* <r> cmd table idx, 1-based	*/
)
{
    int   indirect_flag;
    int   nbytes;
    int   sts;
    char  *p;
    struct _mdsdcl_io  *io;
    struct descriptor  *dsc;
    static char  *cmd;			/* addr of private cmd string	*/
    static int   maxcmd;		/* current length of cmd[]	*/
    static char  doIndirect[16];
    static DYNAMIC_DESCRIPTOR(dsc_filename);
#ifdef vms
    extern mdsdcl$dcl_parse_handler();
#endif

#ifdef vms
    if (tabidx > 1)
        lib$establish(lib$sig_to_ret);
    else
        lib$establish(mdsdcl$dcl_parse_handler);
#endif

    if (!doIndirect[0])
    {   /* first time ...			*/
        sprintf(doIndirect,"DO %cINDIRECT",QUALIFIER_CHARACTER);
    }

    /*-------------------------------------------------------
     * Copy optional "command" to cmd, checking for '@' ...
     *------------------------------------------------------*/
    if (command && (is_cdescr(command) || is_ddescr(command)))
    {
        dsc = command;
        p = nonblank(dsc->dscA_pointer);
    }
    else
        p = nonblank(command);

    if (!p)
    {   /* command string is null ...			*/
        sts = cli_dcl_parse(0,ctrl->tbladr[tabidx-1],
                            mdsdcl_get_input,mdsdcl_get_input,&ctrl->prompt);

        dsc = cli_addr_cmdline_dsc();
        io = ctrl->ioLevel + ctrl->depth;
        str_copy_dx(&io->last_command,dsc);
    }
    else
    {   /* else, p is start of command string ...	*/
        nbytes = 0;
        if (indirect_flag = (*p == '@'))
        {
            p = nonblank(p+1);		/* skip the '@'			*/
            nbytes = sizeof(doIndirect) - 1;
            if (!ascFilename(&p,&dsc_filename,0))
                return(MdsMsg(MDSDCL_STS_INDIRECT_ERROR,
                              "Illegal filename: %s",p?p:""));
            nbytes += strlen(dsc_filename.dscA_pointer) + 3;
            /* 2 quotes + blank	*/
        }
        nbytes += p ? strlen(p) + 1 : 0;

        if (nbytes > maxcmd)
        {   /*----- allocate enough space for cmd[] ------*/
            maxcmd = (nbytes>79) ? nbytes : 79;
            if (cmd)
                free(cmd);
            cmd = malloc(maxcmd);
            if (!cmd)
            {
                fprintf(stderr,"mdsdcl_dcl_parse: Out of space!\n");
                exit(0);
            }
        }

        if (indirect_flag)
            sprintf(cmd,"%s \"%s\" %s",
                    doIndirect,dsc_filename.dscA_pointer,p?p:"");
        else
            strcpy(cmd,p?p:"");

        sts = cli_dcl_parse(cmd,ctrl->tbladr[tabidx-1],
                            mdsdcl_get_input,mdsdcl_get_input,&ctrl->prompt);
    }
    return(sts);
}