Changeset 120 for branches/dev/lswm

Show
Ignore:
Timestamp:
06/01/07 00:38:37 (2 years ago)
Author:
dsmith
Message:

command-line rework (lswm, wminput) - Nick <nickishappy@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dev/lswm/Makefile.in

    r83 r120  
    77SOURCES = lswm.c 
    88 
    9 CFLAGS += -I@top_builddir@/libcwiid 
     9CFLAGS += -I@top_builddir@/libcwiid -DCWIID_VERSION=\"${PACKAGE_VERSION}\" 
    1010LDFLAGS += -L@top_builddir@/libcwiid 
    1111LDLIBS += -lcwiid 
  • branches/dev/lswm/lswm.c

    r83 r120  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-06-01 Nick <nickishappy@gmail.com> 
     19 *  * reworked command-line options (added standard options, long options) 
     20 * 
    1821 *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * updated for libcwiid rename 
     
    3235#include <bluetooth/bluetooth.h> 
    3336#include <cwiid.h> 
     37#include <getopt.h> 
    3438 
    35 #define OPTSTRING       "ahlq" 
    36  
    37 #define USAGE \ 
    38         "%s [OPTIONS]\n" \ 
    39         "  -a  list all bluetooth devices (not just wiimotes)\n" \ 
    40         "  -h  print this help message\n" \ 
    41         "  -l  long format (device details)\n" \ 
    42         "  -q  quiet mode\n" 
     39void print_usage(void) 
     40
     41        printf("lswm lists availiable wiimotes\n"); 
     42        printf("Usage: %s [OPTIONS]...\n\n", "lswm"); 
     43        printf("Options:\n"); 
     44        printf("\t-h, --help\t\tPrints this output.\n"); 
     45        printf("\t-v, --version\t\toutput version information and exit.\n"); 
     46        printf("\t-l, --long\t\tlong format (device details).\n"); 
     47        printf("\t-q, --quiet\t\tquiet mode (less verbose).\n"); 
     48        printf("\t-a, --all\t\tlist all bluetooth devices (not just wiimotes).\n"); 
     49
    4350 
    4451int main(int argc, char *argv[]) 
     
    5461 
    5562        /* Parse options */ 
    56         while ((c = getopt(argc, argv, OPTSTRING)) != -1) { 
     63        while (1) { 
     64                int option_index = 0; 
     65 
     66                static struct option long_options[] = { 
     67                        {"help", 0, 0, 'h'}, 
     68                        {"all", 0, 0, 'a'}, 
     69                        {"long", 0, 0, 'l'}, 
     70                        {"version", 0, 0, 'v'}, 
     71                        {"quiet", 0, 0, 'q'}, 
     72                        {0, 0, 0, 0} 
     73                }; 
     74 
     75                c = getopt_long(argc, argv, "halvq", long_options, &option_index); 
     76 
     77                if (c == -1) { 
     78                        break; 
     79                } 
     80 
    5781                switch (c) { 
    5882                case 'h': 
    59                         printf(USAGE, argv[0]); 
     83                        print_usage(); 
    6084                        return 0; 
    6185                        break; 
     
    6690                        long_format = 1; 
    6791                        break; 
     92                case 'v': 
     93                        printf("CWiid Version %s\n", CWIID_VERSION); 
     94                        return 0; 
     95                        break; 
    6896                case 'q': 
    6997                        quiet = 1; 
     
    7199                case '?': 
    72100                default: 
    73                         fprintf(stderr, "Try '%s -h' for more information\n", argv[0]); 
     101                        fprintf(stderr, "Try '%s --help' for more information\n", argv[0]); 
    74102                        return -1; 
    75103                        break; 
    76104                } 
    77105        } 
    78  
    79         /* TODO: check for other stuff on the command-line? */ 
    80106 
    81107        /* Handle quiet mode */ 
     
    112138        return 0; 
    113139} 
    114