Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Config / Get_Opt_Long.cpp
blob0b5a70b618b0505dea90eb884fec6b3905dcfe46
1 /**
2 * ACE_Get_Opt long_only examples. Sample code from The ACE
3 * Programmer's Guide, Copyright 2003 Addison-Wesley. All Rights Reserved.
4 */
6 #include "ace/OS_NS_string.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Log_Msg.h"
10 int
11 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
13 static const ACE_TCHAR options[] = ACE_TEXT (":f:");
14 ACE_Get_Opt cmd_opts
15 (argc, argv, options, 1, 0, ACE_Get_Opt::PERMUTE_ARGS, 1);
16 if (cmd_opts.long_option
17 (ACE_TEXT ("config"), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1)
18 return -1;
20 int option;
21 ACE_TCHAR config_file[MAXPATHLEN];
22 ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf"));
23 while ((option = cmd_opts ()) != EOF)
24 switch (option) {
25 case 'f':
26 ACE_OS::strncpy (config_file,
27 cmd_opts.opt_arg (),
28 MAXPATHLEN);
29 break;
31 case ':':
32 ACE_ERROR_RETURN
33 ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"),
34 cmd_opts.opt_opt ()), -1);
37 default:
38 ACE_ERROR_RETURN
39 ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1);
42 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config file is %s\n"), config_file));
44 return 0;