Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / drwho / Options.cpp
blob8984f52a6283aeae6b40f797b7f610ab276048c4
1 #include "ace/OS_NS_stdlib.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Log_Msg.h"
4 #include "Options.h"
5 #include "Multicast_Manager.h"
7 // Initialize all the static variables.
9 // Contains bit-mask for options.
10 u_int Options::option_word = 0;
12 // Which protocol are we using?
13 Options::Protocol_Types Options::protocol_type = Options::PROTO_FLO;
15 // User name for quick lookups.
16 char *Options::user_name = 0;
18 // Port number for client/server.
19 short Options::port_number = PORT_NUMBER;
21 // Maximum time the client waits for servers to timeout.
22 int Options::max_server_timeout = 5;
24 // Name of the program.
25 char *Options::program_name;
27 // Default name of file that stores friend info.
28 const char *Options::friend_file = FRIEND_FILE;
30 void
31 Options::print_usage_and_die (int long_msg)
33 ACE_DEBUG ((LM_DEBUG,
34 "usage: %s %s",
35 program_name,
36 long_msg
37 ? "\n"
38 "-?\tprints a short usage message\n"
39 "-A\tappend the following hostname to the list of predefined hostnames.\n"
40 "-a\treturn information on *all* users remotely logged in (uses yp passwd).\n"
41 "-b\trun the server in the background (i.e., as a daemon).\n"
42 "-d\tturn on debugging.\n"
43 "-F\tuse the following file contents to initialize the host list.\n"
44 "-f\tuse the following file contents to initialize the friends database.\n"
45 "-H\tuse the following hostname as part of the new list of hostnames.\n"
46 "\t(this option overwrites the existing default names).\n"
47 "-h\tprint a long usage message.\n"
48 "-L\tprint the login name rather than the real name (which is the default).\n"
49 "-l\tprint information in long format (works for all protocols).\n"
50 "-p\tset the port number (server must correspond).\n"
51 "-r\tdo the remote lookups (i.e., local operations are the default).\n"
52 "-R\tprint info using the rusers format.\n"
53 "-s\tsort the output by login name.\n"
54 "-S\tsort the output by real name.\n"
55 "-t\tset the amount of time we wait for servers to timeout.\n"
56 "-w\treturn information on just one user.\n"
57 : "[-?haAbdfFHhLlpRrtw]\n"));
58 ACE_OS::exit (1);
61 void
62 Options::set_opt (Option_Types opt)
64 Options::option_word |= opt;
67 int
68 Options::get_opt (Option_Types opt)
70 return (Options::option_word & opt) != 0;
73 void
74 Options::set_options (int argc, char *argv[])
76 int c;
77 int add_default_hosts = 1;
79 Options::program_name = argv[0];
81 //FUZZ: disable check_for_lack_ACE_OS
82 ACE_Get_Opt getopt (argc, argv, ACE_TEXT("?aA:bdF:f:hH:Llp:rRsSt:w:"));
84 while ((c = getopt ()) != -1)
86 //FUZZ: endable check_for_lack_ACE_OS
87 switch (c)
89 case '?':
90 Options::print_usage_and_die (0);
91 /* NOTREACHED */
92 case 'A':
93 Multicast_Manager::add_host (getopt.opt_arg ());
94 break;
95 case 'a':
96 Options::protocol_type = PROTO_ALL;
97 break;
98 case 'b':
99 Options::set_opt (Options::BE_A_DAEMON);
100 break;
101 case 'd':
102 Options::set_opt (Options::DEBUGGING);
103 break;
104 case 'f':
105 Options::friend_file = getopt.opt_arg ();
106 break;
107 case 'F':
108 if (Multicast_Manager::insert_hosts_from_file (getopt.opt_arg ()) < 0)
109 ACE_DEBUG ((LM_DEBUG,
110 "%p%a\n",
111 Options::program_name,
112 1));
113 add_default_hosts = 0;
114 break;
115 case 'H':
116 Multicast_Manager::add_host (getopt.opt_arg ());
117 add_default_hosts = 0;
118 break;
119 case 'h':
120 Options::print_usage_and_die (1);
121 /* NOTREACHED */
122 case 'L':
123 Options::set_opt (Options::PRINT_LOGIN_NAME);
124 break;
125 case 'l':
126 Options::set_opt (Options::USE_VERBOSE_FORMAT);
127 break;
128 case 'p':
129 Options::port_number = ACE_OS::atoi (getopt.opt_arg ());
130 break;
131 case 'R':
132 Options::protocol_type = PROTO_RUSER;
133 break;
134 case 'r':
135 Options::set_opt (Options::REMOTE_USAGE);
136 break;
137 case 's':
138 Options::set_opt (Options::SORT_BY_LOGIN_NAME);
139 break;
140 case 'S':
141 Options::set_opt (Options::SORT_BY_REAL_NAME);
142 break;
143 case 't':
144 Options::max_server_timeout = ACE_OS::atoi (getopt.opt_arg ());
145 break;
146 case 'w':
147 Options::user_name = getopt.opt_arg ();
148 Options::protocol_type = PROTO_USR;
149 break;
150 default:
151 break;
155 if (Options::get_opt (Options::REMOTE_USAGE) && add_default_hosts)
156 Multicast_Manager::insert_default_hosts ();