Esempio n. 1
0
int indicate_vm_cmd(int argi, char *argx[],char *cmdline)
{
    char           *argn[MAX_ARGS+1];   // Our copy of pointers
    char          **argv = argn;        // Our copy of the ptr to pointers
    int             argc;               // Our copy
    CMDTAB*         pCmdTab;
    size_t          cmdlen, matchlen;
    int             rc;                 // Default to invalid command

    UNREFERENCED(argc);
    UNREFERENCED(argv);
    UNREFERENCED(cmdline);

    VERIFY( argi <= MAX_ARGS );                     // This should always be true
    argc = ( argi <= MAX_ARGS ? argi : MAX_ARGS );
    for( rc = 0; rc < argc; rc++ )
        argn[rc] = argx[rc];

    argc--;         // Decrement Count to skip past "QUERY"
    argv++;         // Move pointer forward past "QUERY"
    
    rc = HERRINVCMD;
    
    for (pCmdTab = cmdtab; pCmdTab->statement; pCmdTab++)
    {
        if (1
            && pCmdTab->function
            && (pCmdTab->type & sysblk.sysgroup)
            /* Commands issues through DIAG8 must NOT be part of the SYSNDIAG8 group */
            && (!(sysblk.diag8cmd & DIAG8CMD_RUNNING) || !(pCmdTab->type & SYSNDIAG8))
        )
        {
            cmdlen = pCmdTab->mincmdlen ? pCmdTab->mincmdlen : strlen( pCmdTab->statement );
            matchlen = MAX( strlen(argv[0]), cmdlen );

            if (!strncasecmp( argv[0], pCmdTab->statement, matchlen ))
            {
                char cmd[256]; /* (copy of command name) */

                /* Make full-length copy of the true command's name */
                strlcpy( cmd, pCmdTab->statement, sizeof(cmd) );
                argv[0] = cmd; /* (since theirs may be abbreviated) */

                 /* Process the Hercules command */
                rc = pCmdTab->function( CMDFUNC_ARGS );
                break;
            }
            /* end strncasecmp( table entry match ) */
        }
        /* end if ( valid table entry ) */
    }
    /* end for ( search table ) */
    return 0;
}
Esempio n. 2
0
File: query.c Progetto: Mayalinux/db
/*
 * query --
 *	Process a query.
 */
int
query(char *cmd, int *donep)
{
	CMDTAB *p;

	if (donep != NULL)
		*donep = 0;

	for (p = cmdtab; p->cmd != NULL; ++p)
		if (p->cmd != NULL &&
		    strncasecmp(cmd, p->cmd, strlen(p->cmd)) == 0)
			break;

	if (p->cmd == NULL)
		return (query_by_field(cmd));

	if (p->f == NULL) {
		if (donep != NULL)
			*donep = 1;
		return (0);
	}

	return (p->f(cmd));
}
Esempio n. 3
0
/*-------------------------------------------------------------------*/
int CallHercCmd ( CMDFUNC_ARGS_PROTO )
{
    CMDTAB* pCmdTab;
    size_t  cmdlen, matchlen;
    int     rc = HERRINVCMD;             /* Default to invalid command   */

    /* Let 'cscript' command run immediately in any context */
    if (argc >= 1 && strcasecmp( argv[0], "cscript" ) == 0)
        return cscript_cmd( CMDFUNC_ARGS );

    HERC_CMD_ENTRY();

    /* [ENTER] key by itself: either start the CPU or ignore
       it altogether when instruction stepping is not active. */
    if (0
            || !argc            /* (no args)    */
            || !argv[0]         /* (no cmd)     */
            || !cmdline         /* (no cmdline) */
            || !cmdline[0]      /* (empty cmd)  */
            || !argv[0][0]      /* (empty cmd)  */
       )
    {
        if (sysblk.inststep)
            rc = start_cmd( 0, NULL, NULL );
        else
            rc = 0;         /* ignore [ENTER] */

        HERC_CMD_EXIT();
        return rc;
    }

    /* (sanity check) */
    ASSERT( argc && cmdline && *cmdline && argv[0] && argv[0][0] );

#if defined( OPTION_DYNAMIC_LOAD )
    /* If a system command hook exists, let it try processing it first. */
    /* Only if it rejects it, will we then try processing it ourselves. */
    if(system_command)
        if((rc = system_command( CMDFUNC_ARGS )) != HERRINVCMD)
        {
            HERC_CMD_EXIT();
            return rc;
        }
#endif /* defined( OPTION_DYNAMIC_LOAD ) */

    /* Check for comment command. We need to test for this separately
       rather than scanning our COMAMND table since the first token
       of the "command" might not be a single '#' or '*'. That is to
       say, the first token might be "#comment" or "*comment" (with
       no blanks following the '#' or '*'), which would thus not match
       either of our "comment_cmd" COMMAND table entries. Note that
       this also means the COMMAND table entries for '*' and '#' are
       redundant since they will never be used (since we're processing
       comments here and not via our table search), but that's okay. */
    if (0
            || argv[0][0] == '#'       /* (comment command?) */
            || argv[0][0] == '*'       /* (comment command?) */
       )
    {
        /* PROGRAMMING NOTE: we ALWAYS call the "comment_cmd" function
           for comments even though today it does nothing. We might decide
           to do additional processing for comments in the future (such
           as simply counting them for example), so we should ALWAYS call
           our comment_cmd function here instead of just returning. */
        rc = comment_cmd( CMDFUNC_ARGS );
        HERC_CMD_EXIT();
        return rc;
    }

    /* Route standard formatted commands from our COMMAND routing table */

    /* PROGRAMMING NOTE: since our table is now sorted, the below could
       be converted to a more efficient binary search algorithm instead */

    for (pCmdTab = cmdtab; pCmdTab->statement; pCmdTab++)
    {
        if (1
                && pCmdTab->function
                && (pCmdTab->type & sysblk.sysgroup)
                /* Commands issues through DIAG8 must NOT be part of the SYSNDIAG8 group */
                && (!(sysblk.diag8cmd & DIAG8CMD_RUNNING) || !(pCmdTab->type & SYSNDIAG8))
           )
        {
            cmdlen = pCmdTab->mincmdlen ? pCmdTab->mincmdlen : strlen( pCmdTab->statement );
            matchlen = MAX( strlen(argv[0]), cmdlen );

            if (!strncasecmp( argv[0], pCmdTab->statement, matchlen ))
            {
                char cmd[256]; /* (copy of command name) */

                /* Make full-length copy of the true command's name */
                strlcpy( cmd, pCmdTab->statement, sizeof(cmd) );
                argv[0] = cmd; /* (since theirs may be abbreviated) */

                /* Run command in background? (last argument == '&') */
                if (strcmp(argv[argc-1],"&") == 0)
                {
                    BGCMD *bgcmd;
                    TID tid;
                    int i,len;

                    /* Calculate length of the command-line (all arguments
                       except the last one), including intervening blanks. */
                    for (len=0, i=0; i < argc-1; i++ )
                        len += (int) strlen( (char*) argv[i] ) + 1;

                    /* Build parameter to pass to background thread */
                    bgcmd = (BGCMD*) malloc( sizeof(BGCMD) + len );
                    bgcmd->func = pCmdTab->function;

                    /* Build private copy of cmdline for bgcmd_thread */
                    strlcpy( bgcmd->cmdline, argv[0], len );
                    for (i=1; i < argc-1; i++)
                    {
                        strlcat( bgcmd->cmdline,  " ",    len );
                        strlcat( bgcmd->cmdline, argv[i], len );
                    }

                    /* Process command asynchronously in the background */
                    rc = create_thread( &tid, DETACHED, bgcmd_thread, bgcmd, "bgcmd_thread" );
                }
                else /* (not a background command) */
                {
                    /* Does last argument start with two ampersands? */
                    if (strncmp( argv[argc-1], "&&", 2 ) == 0)
                        /* Yes, skip past the first one */
                        argv[argc-1]++; /* ("&&&" ==> "&&", "&&" ==> "&", etc) */

                    /* Process the Hercules command */
                    rc = pCmdTab->function( CMDFUNC_ARGS );
                }
                break;
            }
            /* end strncasecmp( table entry match ) */
        }
        /* end if ( valid table entry ) */
    }
    /* end for ( search table ) */

    /* If we didn't find an exact match in our table, check if
       this is maybe a special non-standard formatted command. */
    if (rc == HERRINVCMD && (sysblk.sysgroup & SYSCMDNOPER))
    {
        /* shadow file commands: add/remove/compress/display/check */
        if (0
                || !strncasecmp( cmdline, "sf+", 3 )
                || !strncasecmp( cmdline, "sf-", 3 )
                || !strncasecmp( cmdline, "sfc", 3 )
                || !strncasecmp( cmdline, "sfd", 3 )
                || !strncasecmp( cmdline, "sfk", 3 )
           )
            rc = ShadowFile_cmd( CMDFUNC_ARGS );
        else
            /* "x+" and "x-" commands: turn switch on or off */
            if (0
                    || '+' == cmdline[1]
                    || '-' == cmdline[1]
               )
                rc = OnOffCommand( CMDFUNC_ARGS );
    }

    HERC_CMD_EXIT();
    return rc;
}