~ubuntu-branches/ubuntu/oneiric/likewise-open/oneiric

« back to all changes in this revision

Viewing changes to krb5/src/ccapi/common/win/OldCC/opts.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Scott Salley
  • Date: 2010-11-22 12:06:00 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122120600-8lba1fpceot71wlb
Tags: 6.0.0.53010-1
Likewise Open 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header$
 
3
 *
 
4
 * Copyright 2008 Massachusetts Institute of Technology.
 
5
 * All Rights Reserved.
 
6
 *
 
7
 * Export of this software from the United States of America may
 
8
 * require a specific license from the United States Government.
 
9
 * It is the responsibility of any person or organization contemplating
 
10
 * export to obtain such a license before exporting.
 
11
 *
 
12
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 
13
 * distribute this software and its documentation for any purpose and
 
14
 * without fee is hereby granted, provided that the above copyright
 
15
 * notice appear in all copies and that both that copyright notice and
 
16
 * this permission notice appear in supporting documentation, and that
 
17
 * the name of M.I.T. not be used in advertising or publicity pertaining
 
18
 * to distribution of the software without specific, written prior
 
19
 * permission.  Furthermore if you modify this software you must label
 
20
 * your software as modified software and not distribute it in such a
 
21
 * fashion that it might be confused with the original M.I.T. software.
 
22
 * M.I.T. makes no representations about the suitability of
 
23
 * this software for any purpose.  It is provided "as is" without express
 
24
 * or implied warranty.
 
25
 */
 
26
 
 
27
#include <windows.h>
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
#include <opts.hxx>
 
31
 
 
32
#if 0
 
33
const struct Opts*
 
34
GetOpts(
 
35
    )
 
36
{
 
37
    bool done = false;
 
38
    struct Opts* o;
 
39
    if (!(o = new Opts))
 
40
        goto cleanup;
 
41
    if (!(o->pszString = new char[lstrlenA(opts.pszString) + 1]))
 
42
        goto cleanup;
 
43
    if (!(o->pszEndpoint = new char[lstrlenA(opts.pszEndpoint) + 1]))
 
44
        goto cleanup;
 
45
    strcpy(o->pszString, opts.pszString);
 
46
    strcpy(o->pszEndpoint, opts.pszEndpoint);
 
47
    done = true;
 
48
 cleanup:
 
49
    if (!done) {
 
50
        FreeOpts(o);
 
51
        o = 0;
 
52
    }
 
53
    return o;
 
54
}
 
55
 
 
56
void
 
57
FreeOpts(
 
58
    struct Opts* o
 
59
    )
 
60
{
 
61
    if (o) {
 
62
        if (o->pszString)
 
63
            delete [] o->pszString;
 
64
        if (o->pszEndpoint)
 
65
            delete [] o->pszEndpoint;
 
66
        delete o;
 
67
    }
 
68
}
 
69
#endif
 
70
 
 
71
bool
 
72
ParseOpts::IsValidOpt(
 
73
    char ch
 
74
    )
 
75
{
 
76
    return (m_ValidOpts[ch % 256] != 0);
 
77
}
 
78
 
 
79
void
 
80
ParseOpts::PrintOpt(
 
81
    char ch,
 
82
    char* text
 
83
    )
 
84
{
 
85
    if (IsValidOpt(ch))
 
86
        fprintf(stderr, "  -%c %s\n", ch, text);
 
87
}
 
88
 
 
89
void
 
90
ParseOpts::UsageOpts(
 
91
    char * program,
 
92
    int code
 
93
    )
 
94
{
 
95
    fprintf(stderr, "Usage: %s [options]\n", program);
 
96
    PrintOpt('k', "stop server");
 
97
#ifdef CCAPI_TEST_OPTIONS
 
98
    PrintOpt('s', "string");
 
99
    PrintOpt('e', "endpoint");
 
100
    PrintOpt('m', "maxcalls");
 
101
    PrintOpt('n', "mincalls");
 
102
    PrintOpt('f', "flag_wait_op");
 
103
    PrintOpt('u', "unprotected");
 
104
    PrintOpt('b', "use security callback");
 
105
#endif
 
106
    PrintOpt('c', "output debug info to console");
 
107
    exit(code);
 
108
}
 
109
 
 
110
void
 
111
ParseOpts::SetValidOpts(
 
112
    char* valid_opts
 
113
    )
 
114
{
 
115
    memset(m_ValidOpts, 0, sizeof(m_ValidOpts));
 
116
    char *p = valid_opts;
 
117
    for (p = valid_opts; *p; p++) {
 
118
        m_ValidOpts[*p % sizeof(m_ValidOpts)] = 1;
 
119
    }
 
120
}
 
121
 
 
122
void
 
123
ParseOpts::Parse(
 
124
    Opts& opts,
 
125
    int argc,
 
126
    char **argv
 
127
    )
 
128
{
 
129
    int i;
 
130
    for (i = 1; i < argc; i++) {
 
131
        if ((*argv[i] == '-') || (*argv[i] == '/')) {
 
132
            char ch = tolower(*(argv[i]+1));
 
133
            if (!IsValidOpt(ch))
 
134
                UsageOpts(argv[0]);
 
135
            switch (ch) {
 
136
            case 'k':
 
137
                opts.bShutdown = TRUE;
 
138
                break;
 
139
#ifdef CCAPI_TEST_OPTIONS
 
140
            case 's':
 
141
                opts.pszString = argv[++i];
 
142
                break;
 
143
            case 'e':
 
144
                opts.pszEndpoint = argv[++i];
 
145
                break;
 
146
            case 'm':
 
147
                opts.cMaxCalls = (unsigned int) atoi(argv[++i]);
 
148
                break;
 
149
            case 'n':
 
150
                opts.cMinCalls = (unsigned int) atoi(argv[++i]);
 
151
                break;
 
152
            case 'f':
 
153
                opts.fDontWait = (unsigned int) atoi(argv[++i]);
 
154
                break;
 
155
            case 'u':
 
156
                opts.bDontProtect = TRUE;
 
157
                break;
 
158
            case 'b':
 
159
                opts.bSecCallback = TRUE;
 
160
                break;
 
161
#endif
 
162
            case 'c':
 
163
                opts.bConsole = TRUE;
 
164
                break;
 
165
            case 'h':
 
166
            case '?':
 
167
            default:
 
168
                UsageOpts(argv[0]);
 
169
            }
 
170
        }
 
171
        else
 
172
            UsageOpts(argv[0]);
 
173
    }
 
174
 
 
175
}
 
176
 
 
177
ParseOpts::ParseOpts(char* valid_opts)
 
178
{
 
179
    SetValidOpts(valid_opts);
 
180
}
 
181
 
 
182
ParseOpts::ParseOpts()
 
183
{
 
184
}
 
185
 
 
186
ParseOpts::~ParseOpts()
 
187
{
 
188
}