Resolve many build warnings
[oweals/cde.git] / cde / programs / dtsearchpath / dtsp / Options.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Options.C /main/4 1996/01/25 15:55:11 rswiston $ */
24 /*******************************************************************
25  *
26  * (c) Copyright 1993, 1994 Hewlett-Packard Company
27  * (c) Copyright 1993, 1994 International Business Machines Corp.
28  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
29  * (c) Copyright 1993, 1994 Novell, Inc.
30  *
31  ********************************************************************
32  ****************************<+>*************************************/
33
34 #include "Options.h"
35 #include <stdlib.h>
36 #if defined(linux) || defined(CSRG_BASED)
37 #include <iostream>
38 #else
39 #include <iostream.h>
40 #endif
41 #include <stdio.h>
42 #include <pwd.h>
43
44 /**************************************************************
45  *
46  * Two options are available for dtsearchpath:
47  *
48  *      -v      Verbose    - prints the Search Path environment
49  *                           variables to standard output.
50  *      -u      Check User - determines the Search Path for a 
51  *                           particular user.
52  *      -a      AutoMount  - remove the autmounter's mount point
53  *
54  *      -csh    force Csh style environment set commands
55  *
56  *      -ksh    force Ksh style environment set commands
57  **************************************************************/
58
59 Options::Options
60         (
61         unsigned int argc,
62         char **      argv
63         ) : flags(0), user_id(0), home_dir(0), automountpoint(0)
64 {
65 CString Usage ("Usage: dtsearchpath [ -v | -T | -o | -a | -csh | -ksh ] "
66                "[ -u <login-name> ]");
67
68     if (argc > 1) {
69         for (int i = 1; i < argc; i++) {
70             if (strcmp(argv[i],"-v") == 0)
71                 flags |= 1;
72             else if (strcmp(argv[i],"-T") == 0)
73                 flags |= 4;
74             else if (strcmp(argv[i],"-o") == 0)
75                 flags |= 8;
76             else if (strcmp(argv[i],"-a") == 0)
77                 flags |= 16;
78             else if (strcmp(argv[i],"-csh") == 0)
79                 flags |= 32;
80             else if (strcmp(argv[i],"-c") == 0) // for bc with sun version
81                 flags |= 32;
82             else if (strcmp(argv[i],"-ksh") == 0)
83                 flags |= 64;
84             else if (strcmp(argv[i],"-u") == 0) {
85                 flags |= 2;
86                 if (++i < argc && argv[i][0] != '-') {
87                     user_id = new CString(argv[i]);
88                     struct passwd * pwd = getpwnam(user_id->data());
89                     home_dir = new CString(pwd->pw_dir);
90                 }
91                 else {
92                     fprintf(stderr, "%s\n",Usage.data());
93                     exit(1);
94                 }
95             }
96             else {
97                 fprintf(stderr, "%s\n",Usage.data());
98                 exit(1);
99             }
100         }
101     }
102 #if defined(hpux) || defined(hpV4)
103     flags |= 16;
104 #endif
105 }
106
107
108 Options::~Options()
109 {
110     delete user_id;
111     delete automountpoint;
112     delete home_dir;
113 }
114
115
116 void Options::setUserID
117         (
118         const CString & login
119         )
120 {
121     user_id = new CString(login);
122 }
123
124 void Options::setAutoMountPoint
125         (
126         const CString & mountpoint
127         )
128 {
129     if (mountpoint.isNull())
130         automountpoint = new CString("/tmp_mnt");
131     else
132         automountpoint = new CString(mountpoint);
133 }