Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Config / ARGV_Example.cpp
blobe5b70b5f5f5897fe9a6b02d881f91d7d297cd5a0
1 /**
2 * ACE_ARGV examples not in a larger program. Sample code from The ACE
3 * Programmer's Guide, Copyright 2003 Addison-Wesley. All Rights Reserved.
4 */
6 #include "ace/os_include/os_netdb.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/Log_Msg.h"
10 // Listing 1 code/ch04
11 #include "ace/ARGV.h"
12 #include "ace/Get_Opt.h"
14 int ACE_TMAIN (int, ACE_TCHAR *[])
16 static const ACE_TCHAR options[] = ACE_TEXT (":f:h:");
17 static const ACE_TCHAR cmdline[] =
18 ACE_TEXT ("-f /home/managed.cfg -h $HOSTNAME");
19 ACE_ARGV cmdline_args (cmdline);
20 ACE_Get_Opt cmd_opts (cmdline_args.argc (),
21 cmdline_args.argv (),
22 options,
23 0); // Don't skip any args
25 // Listing 1
27 int option;
28 ACE_TCHAR config_file[MAXPATHLEN];
29 ACE_TCHAR hostname[MAXHOSTNAMELEN];
30 ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf"));
31 ACE_OS::strcpy (hostname, ACE_TEXT ("not set"));
32 while ((option = cmd_opts ()) != EOF)
33 switch (option) {
34 case 'f':
35 ACE_OS::strncpy (config_file,
36 cmd_opts.opt_arg (),
37 MAXPATHLEN);
38 break;
40 case 'h':
41 ACE_OS::strncpy (hostname,
42 cmd_opts.opt_arg (),
43 MAXHOSTNAMELEN);
44 break;
46 case ':':
47 ACE_ERROR_RETURN
48 ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"),
49 cmd_opts.opt_opt ()), -1);
52 default:
53 ACE_ERROR_RETURN
54 ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1);
57 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config file: %s\n"), config_file));
58 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Hostname: %s\n"), hostname));
59 return 0;