Changeset 120

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/ChangeLog

    r118 r120  
     12007-06-01 Nick <nickishappy@gmail.com> 
     2        lswm 
     3        * reworked command-line options (added standard options, long options) 
     4 
     5        wminput 
     6        * reworked command-line options (added standard options, long options) 
     7 
    182007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
    29        python 
    310        * added Wiimote_FromC 
    411        * exported Wiimote_FromC and ConvertMesgArray as CObjects 
     12        * added get_acc_cal 
    513 
    614        wminput 
  • 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  
  • branches/dev/wminput/Makefile.in

    r118 r120  
    1010CFLAGS += -I@top_builddir@/libcwiid -I/usr/include/python@PYTHON_VERSION@ \ 
    1111        -DWMINPUT_CONFIG_DIR=\"$(WMINPUT_CONFIG_DIR)\" \ 
    12         -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" 
     12        -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" \ 
     13        -DCWIID_VERSION=\"${PACKAGE_VERSION}\" 
    1314LDLIBS += -lcwiid -ldl -lpython@PYTHON_VERSION@ 
    1415LDFLAGS += -L@top_builddir@/libcwiid -rdynamic 
  • branches/dev/wminput/main.c

    r118 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-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * added python plugin support 
     
    4649#include <stdio.h> 
    4750#include <stdlib.h> 
     51#include <getopt.h> 
    4852 
    4953#include <pthread.h> 
     
    6064 
    6165struct conf conf; 
    62  
    63 /* GetOpt */ 
    64 #define OPTSTRING       "hwc:" 
    65 extern char *optarg; 
    66 extern int optind, opterr, optopt; 
    6766 
    6867/* Prototypes */ 
     
    8382#define DEFAULT_CONFIG_FILE     "default" 
    8483 
    85 #define USAGE "usage:%s [-h] [-w] [-c config] [bdaddr]\n" 
    86  
    8784#define HOME_DIR_LEN    128 
     85 
     86void print_usage(void) 
     87{ 
     88        printf("wminput is a program that allows you to use a wiimote as a standard input device\n"); 
     89        printf("Usage: %s [OPTIONS]...\n\n", "wminput"); 
     90        printf("Options:\n"); 
     91        printf("\t-h, --help\t\tPrints this output.\n"); 
     92        printf("\t-v, --version\t\toutput version information and exit.\n"); 
     93        printf("\t-c, --config [file]\tChoose config file to use.\n"); 
     94        printf("\t-w, --wait\t\tWait indefinitely for wiimote to connect.\n"); 
     95} 
     96 
    8897int main(int argc, char *argv[]) 
    8998{ 
     
    107116 
    108117        /* Parse Options */ 
    109         while ((c = getopt(argc, argv, OPTSTRING)) != -1) { 
     118        while (1) { 
     119                int option_index = 0; 
     120 
     121                static struct option long_options[] = { 
     122                        {"help", 0, 0, 'h'}, 
     123                        {"wait", 0, 0, 'w'}, 
     124                        {"config", 1, 0, 'c'}, 
     125                        {"version", 0, 0, 'v'}, 
     126                        {0, 0, 0, 0} 
     127                }; 
     128 
     129                c = getopt_long (argc, argv, "hwc:v", long_options, &option_index); 
     130 
     131                if (c == -1) { 
     132                        break; 
     133                } 
     134 
    110135                switch (c) { 
    111136                case 'h': 
    112                         printf(USAGE, argv[0]); 
     137                        print_usage(); 
    113138                        return 0; 
    114139                        break; 
     
    119144                        config_filename = optarg; 
    120145                        break; 
     146                case 'v': 
     147                        printf("CWiid Version %s\n", CWIID_VERSION); 
     148                        return 0; 
     149                        break; 
    121150                case '?': 
     151                        printf("Try `wminput --help` for more information\n"); 
     152                        return 1; 
     153                        break; 
    122154                default: 
    123155                        return -1; 
     
    182214                if (optind < argc) { 
    183215                        wminput_err("invalid command-line"); 
    184                         printf(USAGE, argv[0]); 
     216                        print_usage(); 
    185217                        conf_unload(&conf); 
    186218                        return -1;