Ignore:
Timestamp:
Oct 6, 2007, 12:16:46 AM (18 years ago)
Author:
bird
Message:

Added --version and --help to all builtins.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/cmp.c

    r1117 r1183  
    6363#  define lseek _lseeki64
    6464# endif
    65 #endif 
     65#endif
    6666#include <locale.h>
    6767
    6868#ifndef O_BINARY
    6969# define O_BINARY 0
    70 #endif 
     70#endif
    7171
    7272/*#include "extern.h"*/
    7373
     74#include "kmkbuiltin.h"
     75
     76
    7477static int      lflag, sflag;
     78
     79static struct option long_options[] =
     80{
     81    { "help",                                           no_argument, 0, 261 },
     82    { "version",                                        no_argument, 0, 262 },
     83    { 0, 0,     0, 0 },
     84};
     85
    7586
    7687/* this is kind of ugly but its the simplest way to avoid namespace mess. */
     
    8192#else
    8293#include "cmp_regular_std.c"
    83 #endif 
    84 
    85 static int usage(void);
     94#endif
     95
     96static int usage(FILE *);
    8697
    8798int
    88 kmk_builtin_cmp(int argc, char *argv[])
     99kmk_builtin_cmp(int argc, char *argv[], char **envp)
    89100{
    90101        struct stat sb1, sb2;
     
    107118        optind = 0; /* init */
    108119
    109         while ((ch = getopt(argc, argv, "ls")) != -1)
     120        while ((ch = getopt_long(argc, argv, "ls", long_options, NULL)) != -1)
    110121                switch (ch) {
    111122                case 'l':               /* print all differences */
     
    115126                        sflag = 1;
    116127                        break;
     128                case 261:
     129                        usage(stdout);
     130                        return 0;
     131                case 262:
     132                        return kbuild_version(argv[0]);
    117133                case '?':
    118134                default:
    119                         return usage();
     135                        return usage(stderr);
    120136                }
    121137        argv += optind;
     
    126142
    127143        if (argc < 2 || argc > 4)
    128                 return usage();
     144                return usage(stderr);
    129145
    130146        /* Backward compatibility -- handle "-" meaning stdin. */
     
    161177                skip1 = strtoll(argv[2], &ep, 0);
    162178                if (errno || ep == argv[2]) {
    163                         rc = usage();
     179                        rc = usage(stderr);
    164180                        goto l_exit;
    165181                }
     
    168184                        skip2 = strtoll(argv[3], &ep, 0);
    169185                        if (errno || ep == argv[3]) {
    170                                 rc = usage();
     186                                rc = usage(stderr);
    171187                                goto l_exit;
    172188                        }
     
    203219
    204220static int
    205 usage(void)
     221usage(FILE *fp)
    206222{
    207 
    208         (void)fprintf(stderr,
    209             "usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n");
     223    fprintf(fp, "usage: %s [-l | -s] file1 file2 [skip1 [skip2]]\n"
     224                                "   or: %s --help\n"
     225                                "   or: %s --version\n",
     226                        g_progname, g_progname, g_progname);
    210227        return(ERR_EXIT);
    211228}
Note: See TracChangeset for help on using the changeset viewer.