Example #1
0
void display_help(CMDENTRY cmds[])
{
    const int maxdescwidth = 47;
    int i;
    char desc[MAXDESCSZ+1];
    char* cp;
    char* ed;

    fprintf(stdout,"%-20s %-10s %s\n","Command,Abbrev","Args","Description");
    for ( i=0 ; !STREMP(cmds[i].cmd); i++ ) {
        char s[MAXBUFSZ+1];
        /* ignore commands with no description (probably hidden) */
        if (strlen(cmds[i].description) == 0) continue;
        snprintf(s,MAXBUFSZ,"%s,%s",cmds[i].cmd,cmds[i].abbrev);
        strncpy(desc,cmds[i].description,MAXDESCSZ);
        ed = desc+strlen(desc);
        cp = strbrk(desc,maxdescwidth);
        *cp = '\0';cp++;
        fprintf(stdout,"%-20s %-10s %s\n",s,cmds[i].args,desc);
        while (cp < ed) {
            char* scp = cp;
            cp = strbrk(scp,maxdescwidth);
            *cp = '\0'; cp++;
            fprintf(stdout,"%20s %10s %s\n","","",scp);
        }
    }
}
Example #2
0
void find_cmd(char* cmdbuf,CMDENTRY cmds[])
{
    int i;
    char* cp;
    
    cp = non_ws(cmdbuf); /* locate first non-whitespace character */

    cblk.nargs = tokenise(cmdbuf,cmd,arg,qual,all);
    cblk.arg = arg;
    cblk.qualifier = qual;
    cblk.qual_int = atoi(qual);
    cblk.all = all;
    cblk.cmd = cmd;
    cblk.function = NULL;
    cblk.unknown_cmd = FALSE;
    for ( i=0 ; !STREMP(cmds[i].cmd); i++ ) {
        if (strlen(cmds[i].abbrev) == 1 && /* look for special command */
            cmds[i].abbrev[0] < 'A' &&
            *cp == cmds[i].abbrev[0]) {
            cblk.function = cmds[i].function;
            cblk.all = cp+1;
            return;
        }
        else if (strncmp(cmd,cmds[i].cmd,MAXBUFSZ) == 0 ||
                 strncmp(cmd,cmds[i].abbrev,MAXBUFSZ) == 0) {
            cblk.function = cmds[i].function;
            strncpy(cblk.cmd,cmds[i].cmd,MAXBUFSZ);
            cblk.cmd[MAXBUFSZ-1] = '\0';
            /* does # args match that required? */
            if (cmds[i].nargs != 0 &&
                cmds[i].nargs != cblk.nargs) {
                    cblk.nargs = -1;
            }
            return;
        }
    }
    /* empty sentinal command should invoke unknown command handler */
    if (!STREMP(cblk.cmd)) {
        cblk.function = cmds[i].function;
        cblk.unknown_cmd = TRUE;
    }
    return;
}
Example #3
0
void display_help(CMDENTRY cmds[],char* cmd)
{
    const int maxdescwidth = 47;
    int i;
    char desc[MAXDESCSZ+1];
    char* cp;
    char* ed;
    
    if (STREMP(cmd)) {
        fprintf(stdout,"%-20s %-10s %s\n","Command,Abbrev","Args",
                "Description");
    }
    for ( i=0 ; !STREMP(cmds[i].cmd); i++ ) {
        char s[MAXBUFSZ+1];
        /* ignore commands with no description (probably hidden) */
        if (strlen(cmds[i].description) == 0) continue;
        if (STREMP(cmd) || (strncmp(cmds[i].cmd,cmd,MAXBUFSZ) == 0) ||
            (strncmp(cmds[i].abbrev,cmd,MAXBUFSZ) == 0)) {
            snprintf(s,MAXBUFSZ,"%s,%s",cmds[i].cmd,cmds[i].abbrev);
            strncpy(desc,cmds[i].description,MAXDESCSZ);
            ed = desc+strlen(desc);
            cp = strbrk(desc,maxdescwidth);
            *cp = '\0';cp++;
            fprintf(stdout,"%-20s %-10s %s\n",s,cmds[i].args,desc);
            while (cp < ed) {
                char* scp = cp;
                cp = strbrk(scp,maxdescwidth);
                *cp = '\0'; cp++;
                fprintf(stdout,"%20s %10s %s\n","","",scp);
            }
            if (!STREMP(cmd)) return;
        }
    }
    if (!STREMP(cmd)) {
        strncpy(cblk.cmd,cmd,MAXBUFSZ);  /* copy cmd to correct loc in
                                          * cblk */
        cblk.cmd[MAXBUFSZ-1] = '\0';
        (cmds[i].function)(&cblk);
    }
}