示例#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);
        }
    }
}
示例#2
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);
    }
}