summaryrefslogtreecommitdiffstats
path: root/tdecore/tests/kcmdlineargstest.cpp
blob: 8148e4208768951cfd129221b299daff081eb40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <tdecmdlineargs.h>
#include <klocale.h>
#include <tdeapplication.h>

#include <stdio.h>

// we use our own macro to not bother translators
// but still demonstrate the use. You would use I18N_NOOP
#define I18N_NOP(x) x

static const char version[] = "v0.0.2 1999 (c) Waldo Bastian";
static const char description[] = I18N_NOP("This is a test program.");

static TDECmdLineOptions options[] =
{
 { "test",		I18N_NOP("do a short test only, note that\n"
				  "this is rather long comment"), 0 },
 { "baud <baudrate>",	I18N_NOP("set baudrate"), "9600" },
 { "+file(s)",		I18N_NOP("Files to load"), 0 },
 TDECmdLineLastOption
};

#if 1
int
main(int argc, char *argv[])
{
   TDELocale::setMainCatalogue("tdelibs");
   TDECmdLineArgs::init( argc, argv, "testapp", description, version);

   TDECmdLineArgs::addCmdLineOptions( options ); // Add my own options.

   // MyWidget::addCmdLineOptions();

   TDEApplication k( false, false /*true, true*/ );

   // Get application specific arguments
   TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); 
   // Check if an option is set
   if (args->isSet("test"))
   {
      // Do stuff
      printf("Option 'test' is set.\n");
   }   

   if (args->isSet("baud"))
   {
      // Do stuff
      printf("Option 'baud' is set.\n");
   }   
   
   // Read the value of an option. 
   TQCString baudrate = args->getOption("baud"); // 9600 is the default value.
   
   printf("Baudrate = %s\n", baudrate.data());

   printf("Full list of baudrates:\n");
   QCStringList result = args->getOptionList("baud");
   for(QCStringList::ConstIterator it=result.begin();
       it != result.end();
       ++it)
   {
      printf("Baudrate = %s\n", (*it).data());
   }
   printf("End of list\n");

   for(int i = 0; i < args->count(); i++)
   {
      printf("%d: %s\n", i, args->arg(i));
      printf("%d: %s\n", i, args->url(i).url().ascii());
   }

   args->clear(); // Free up memory.
  
   
//   k.exec();
   return 0;
}
#else
int
main(int argc, char *argv[])
{
   TDECmdLineArgs::init( argc, argv, "testapp", description, version);

   TDEApplication k( true, true );

   k.exec();
   return 0;
}
#endif