1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - - makelst
3 File: searcharg.c
4
5 Copyright 2006-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-11-12#$
14 $Rev: 9296 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <getopt.h>
21
22 #include "searcharg.h"
23
24
25
26 int modc;
27 char** modv;
28 char** dll_argv;
29 char** static_argv;
30 char** header_argv;
31 int dll_index = 0;
32 int static_index = 0;
33 int header_index = 0;
34 char* output_fname = NULL;
35
36
37
SA_Usage(void)38 void SA_Usage( void)
39 {
40 fprintf( stderr, "Development Tool - makelst - Make \"C\" source file\n");
41 fprintf( stderr, "Build %s\n\n", __DATE__);
42 fprintf( stderr, "Usage: makelst [-o output-file] [--static static-files ...] [--dll dll-files ...] [--header header-files ...]\n\n");
43 exit( 1);
44 }
45
46
47 /* Convert -dll A B C ... to -dll A -dll B -dll C ...*/
SA_modify(int argc,char * argv[])48 void SA_modify( int argc, char* argv[])
49 {
50 int i=0;
51 int j=0;
52 char* opt_name;
53 modv = malloc( 4 * (argc * 3));
54
55 for( ; i<argc; ) {
56 if( (strcmp( argv[i], "--dll") == 0) ||
57 (strcmp( argv[i], "--static") == 0) ||
58 (strcmp( argv[i], "--header") == 0)) { //Insert option
59
60 opt_name = argv[i++];
61 if( argc <= i) { break;}
62 while( strncmp( argv[i], "-", 1) != 0) {
63 modv[j++] = opt_name;
64 modv[j++] = argv[i++];
65 if( argc <= i) { break;}
66 }
67 }else{ //Ordinary support
68 modv[j++] = argv[i++];
69 }
70 }
71 modc = j;
72 // printf( "modc = %d\n", modc);
73 }
74
75
76 /*Parse the argument*/
SA_searchopt(int argc,char * argv[])77 void SA_searchopt( int argc, char* argv[])
78 {
79 int n;
80 struct option optionInfo[] = {
81 { "static" , required_argument, NULL, 's'},
82 { "dll" , required_argument, NULL, 'l'},
83 { "header" , required_argument, NULL, 'H'},
84 { NULL, 0, NULL, 0}
85 };
86
87 if( argc <= 1) {
88 SA_Usage();
89 }
90
91 /*Convert argument*/
92 SA_modify( argc, argv);
93
94 dll_argv = malloc( 4 * argc);
95 static_argv = malloc( 4 * argc);
96 header_argv = malloc( 4 * argc);
97
98 while( (n = getopt_long( modc, modv, "do:h", &optionInfo[0], NULL))
99 != -1)
100 {
101 switch( n) {
102 case 'd':
103 // dbg_print_flag = 1;
104 break;
105 case 'o':
106 if( output_fname != NULL) {
107 fprintf( stderr, "ERROR! redefined output filename.\n");
108 SA_Usage();
109 }
110 output_fname = optarg;
111 break;
112 case 's': // "--static"
113 static_argv[static_index++] = optarg;
114 break;
115 case 'l': // "--dll"
116 dll_argv[dll_index++] = optarg;
117 break;
118 case 'H': // "--header"
119 header_argv[header_index++] = optarg;
120 break;
121 case 'h':
122 SA_Usage();
123 break;
124 default: // '?'
125 SA_Usage();
126 break;
127 }
128 }
129
130 /* When the static file is not specified */
131 if( static_index == 0) {
132 fprintf( stderr, "ERROR! no input static file(s).\n");
133 SA_Usage();
134 }
135 /* When the DLL is not specified */
136 if( dll_index == 0) {
137 fprintf( stderr, "ERROR! no input dll file(s).\n");
138 SA_Usage();
139 }
140 /* When there are elements that are not options */
141 if( optind != modc) {
142 SA_Usage();
143 }
144 }
145