~ubuntu-branches/ubuntu/karmic/pilot-link/karmic

« back to all changes in this revision

Viewing changes to src/plu_args.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Rousseau
  • Date: 2006-09-22 11:51:36 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20060922115136-qqmy17bx8j5x0y72
Tags: 0.12.1-5
* urgency medium since libpisock-dev was not usable to build any package
* libpisock-dev now depends on libusb-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * plu_args.c: common popt argument processing routines
 
3
 *
 
4
 * Copyright (C) 2004 by Adriaan de Groot <groot@kde.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by the
 
8
 * Free Software Foundation; either version 2 of the License, or (at your
 
9
 * option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 
14
 * Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
18
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 *
 
20
 */
 
21
 
 
22
#include "pi-userland.h"
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
 
 
27
#include "pi-header.h"
 
28
 
 
29
char *plu_port = NULL;
 
30
int plu_timeout = 0;
 
31
int plu_quiet = 0;
 
32
static char *badoption_help = NULL;
 
33
 
 
34
 
 
35
#define ARGUMENT_BAD_OPTION     17227
 
36
 
 
37
static void callback(poptContext pc,
 
38
        int reason,
 
39
        const struct poptOption *opt,
 
40
        const char *arg,
 
41
        void *data)
 
42
{
 
43
        static int have_complained_already = 0;
 
44
        switch(opt->val) {
 
45
        case 'v' :
 
46
                print_splash(poptGetInvocationName(pc));
 
47
                exit(0);
 
48
                break;
 
49
        case ARGUMENT_BAD_OPTION:
 
50
                if (!have_complained_already) {
 
51
                        fprintf(stderr,"   WARNING: You are using deprecated options. %s\n\n", badoption_help ? "Use these instead:" : "See --help for more.");
 
52
                        if (badoption_help) fprintf(stderr,"%s",badoption_help);
 
53
                        have_complained_already=1;
 
54
                }
 
55
                break;
 
56
        }
 
57
}
 
58
 
 
59
struct poptOption plu_common_options[] = {
 
60
        { NULL, 0, POPT_ARG_CALLBACK, callback, 0, NULL, NULL},
 
61
        { "port",    'p', POPT_ARG_STRING, &plu_port,  0 , "Use device <port> to communicate with Palm", "<port>"},
 
62
        { "timeout",    't', POPT_ARG_INT, &plu_timeout,  0 , "Use timeout <timeout> seconds", "<timeout>"},
 
63
        { "version",  0 , POPT_ARG_NONE,    NULL, 'v', "Display version information", NULL},
 
64
        { "quiet",   'q', POPT_ARG_NONE,  &plu_quiet,  0 , "Suppress 'Hit HotSync button' message", NULL},
 
65
        { "bad-option",0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, NULL, ARGUMENT_BAD_OPTION, NULL, NULL },
 
66
        POPT_TABLEEND
 
67
} ;
 
68
 
 
69
 
 
70
void plu_badoption(poptContext pc, int optc)
 
71
{
 
72
        fprintf(stderr, "%s: %s\n",
 
73
                poptBadOption(pc, POPT_BADOPTION_NOALIAS),
 
74
                poptStrerror(optc));
 
75
 
 
76
        poptPrintUsage(pc, stderr, 0);
 
77
        exit(1);
 
78
}
 
79
 
 
80
 
 
81
void plu_popt_alias(poptContext pc,
 
82
        const char *alias_long,
 
83
        char alias_short,
 
84
        const char *expansion)
 
85
{
 
86
        struct poptAlias alias = {
 
87
                alias_long,
 
88
                alias_short,
 
89
                0,
 
90
                NULL
 
91
        } ;
 
92
 
 
93
        poptParseArgvString(expansion,&alias.argc,&alias.argv);
 
94
        poptAddAlias(pc,alias,0);
 
95
}
 
96
 
 
97
 
 
98
void plu_set_badoption_help(const char *h)
 
99
{
 
100
        if (badoption_help) free(badoption_help);
 
101
        badoption_help = NULL;
 
102
        if (h) badoption_help = strdup(h);
 
103
}
 
104
 
 
105
/* vi: set ts=8 sw=4 sts=4 noexpandtab: cin */
 
106
/* Local Variables: */
 
107
/* indent-tabs-mode: t */
 
108
/* c-basic-offset: 8 */
 
109
/* End: */