1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - demos - argument-1
3   File:     main.c
4 
5   Copyright 2007-2008 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-07-09#$
14   $Rev: 7146 $
15   $Author: yada $
16  *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18 
19 //================================================================================
20 /*---------------------------------------------------------------------------*
21   Name:         NitroMain
22 
23   Description:  main
24 
25   Arguments:    None
26 
27   Returns:      None
28  *---------------------------------------------------------------------------*/
NitroMain(void)29 void NitroMain(void)
30 {
31     int     argc;
32     int     n, c;
33     BOOL    opt_b = FALSE;
34     const char *opt_s = NULL;
35     const char *opt_t = NULL;
36 
37     OS_Init();
38 
39     //---- display argc
40     OS_Printf("---------------- display value of OS_GetArgc()\n" );
41     argc = OS_GetArgc();
42     OS_Printf("argc = %d\n", argc);
43 
44     //---- display argv
45     OS_Printf("---------------- display value of OS_GetArgv()\n" );
46     for (n = 0; n < argc+1; n++)
47     {
48         const char *argv = OS_GetArgv(n);
49 		OS_Printf("[%d] address=0x%08x string=[%s]\n",
50 				  n,
51 				  argv? argv: 0,
52 				  argv? argv: "(null)" );
53     }
54     OS_Printf("\n");
55 
56     //---- get option
57     OS_Printf("---------------- try OS_GetOpt(\"bs:t::\")\n");
58     while ((c = OS_GetOpt("bs:t::")) > 0)
59     {
60         switch (c)
61         {
62         case 'b':
63             opt_b = TRUE;
64             break;
65 
66         case 's':
67             opt_s = OS_GetOptArg();
68             break;
69 
70         case 't':
71             opt_t = OS_GetOptArg();
72             break;
73 
74         case '?':
75         default:
76             OS_Printf("Error --- option '%c'\n", OS_GetOptOpt());
77             break;
78         }
79     }
80 
81     OS_Printf("OPTION-b: %s\n", opt_b ? "TRUE" : "FALSE");
82     OS_Printf("OPTION-s: %s\n", opt_s ? opt_s : "(null)");
83     OS_Printf("OPTION-t: %s\n", opt_t ? opt_t : "(null)");
84 	{
85 		const char* arg = OS_GetOptArg();
86 		OS_Printf("OS_GetOptArg(): %s\n", arg? arg: "(null)" );
87 	}
88 
89     for (n = OS_GetOptInd(); n < argc; n++)
90     {
91         OS_Printf("ARGV[%d] : %s\n", n, OS_GetArgv(n));
92     }
93     OS_Printf("\n");
94 
95 	//---- get option
96     OS_Printf("---------------- try OS_GetOpt(\"-bs:t::\")\n");
97 
98     opt_b = FALSE;
99     opt_s = NULL;
100     opt_t = NULL;
101     (void)OS_GetOpt(NULL);             // Rewind
102 
103     while ((c = OS_GetOpt("-bs:t::")) > 0)
104     {
105         switch (c)
106         {
107         case 1:
108             OS_Printf("----found string. OS_GetOptArg(): %s\n", OS_GetOptArg());
109             OS_Printf("OPTION-b: %s\n", opt_b ? "TRUE" : "FALSE");
110             OS_Printf("OPTION-s: %s\n", opt_s ? opt_s : "(null)");
111             OS_Printf("OPTION-t: %s\n", opt_t ? opt_t : "(null)");
112             break;
113 
114         case 'b':
115             opt_b = TRUE;
116             break;
117 
118         case 's':
119             opt_s = OS_GetOptArg();
120             break;
121 
122         case 't':
123             opt_t = OS_GetOptArg();
124             break;
125 
126         case '?':
127         default:
128             OS_Printf("Error --- option '%c'\n", OS_GetOptOpt());
129             break;
130         }
131     }
132 
133     OS_Printf("==== Finish sample.\n");
134     OS_Terminate();
135 }
136 
137 /*====== End of main.c ======*/
138