Changeset 257

Show
Ignore:
Timestamp:
12/05/05 22:47:59 (3 years ago)
Author:
athomas
Message:
  • If a 'help' parameter does not exist, use the actual command to be run for the help.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • op/trunk/main.c

    r256 r257  
    138138                        char *help = FindOpt(new, "help"); 
    139139 
    140                                 if (!help || !*help) help = "(no help available)"; 
     140                                if (!help || !*help) { 
     141                                int j, len = 0; 
     142                                         
     143                                        for (j = 0; j < cmd->nargs; ++j) 
     144                                                len += strlen(cmd->args[j]) + 1; 
     145                                        help = (char*)malloc(len); 
     146                                        strcpy(help, cmd->args[0]); 
     147                                        for (j = 1; j < cmd->nargs; ++j) { 
     148                                                strcat(help, " "); 
     149                                                if (strchr(cmd->args[j], ' ') || strchr(cmd->args[j], '\t')) { 
     150                                                        strcat(help, "'"); 
     151                                                        strcat(help, cmd->args[j]); 
     152                                                        strcat(help, "'"); 
     153                                                } else 
     154                                                        strcat(help, cmd->args[j]); 
     155                                        } 
     156                                } 
    141157                                printf("%-*s", length + 2, new->name); 
    142                                 while (*help) { 
    143                                 int j; 
    144  
    145                                         printf("%-*.*s\n", 77 - length, 77 - length, help); 
    146                                         for (j = 0; j < 77 - length && *help; ++j, ++help) ; 
    147                                         if (j == 77 - length) 
    148                                                 printf("%-*s", length + 2, ""); 
    149                                 } 
     158                                printf("%-*.*s", 77 - length, 77 - length, help); 
     159                                if (strlen(help) > 77 - length) 
     160                                        printf("...\n"); 
     161                                else 
     162                                        printf("\n"); 
    150163                        } 
    151164                }