Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Config / Get_Opt.cpp
blob1e92a33a8c39d4a27bbcd5fd768892b6da924916
1 /**
2 * ACE_Get_Opt 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_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 // Example for a long option without a corresponding short option.
14 // Just put some context here so the following compiles and runs.
15 static const ACE_TCHAR options[] = ACE_TEXT (":f:");
16 ACE_Get_Opt cmd_opts (argc, argv, options);
18 // Listing 1 code/ch04
19 cmd_opts.long_option (ACE_TEXT ("cool_option"));
20 cmd_opts.long_option (ACE_TEXT ("the_answer"), 42);
21 // Listing 1
23 int option;
24 ACE_TCHAR config_file[MAXPATHLEN];
25 ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf"));
26 while ((option = cmd_opts ()) != EOF)
27 switch (option) {
28 case 'f':
29 ACE_OS::strncpy (config_file,
30 cmd_opts.opt_arg (),
31 MAXPATHLEN);
32 break;
34 // Listing 2 code/ch04
35 case 0:
36 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Yes, very cool.\n")));
37 break;
39 case 42:
40 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("the_answer is 42\n")));
41 break;
42 // Listing 2
44 case ':':
45 ACE_ERROR_RETURN
46 ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"),
47 cmd_opts.opt_opt ()), -1);
50 default:
51 ACE_ERROR_RETURN
52 ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1);
55 return 0;