1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - stripdebug
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-09-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <getopt.h>
21 #include "types.h"
22
23 #include "elf_loader.h"
24 #include "searcharg.h"
25
26 extern const unsigned long SDK_DATE_OF_LATEST_FILE;
27
28
29 /* getopt */
30 extern int optind, opterr, optopt;
31
32 /**/
33 extern u16 dbg_print_flag;
34 extern char* input_elf_fname;
35 extern char* stripped_elf_fname;
36 extern char* added_elf_fname;
37
38
39
SA_Usage(void)40 void SA_Usage( void)
41 {
42 fprintf( stderr,
43 "TWL-SDK Development Tool - stripdebug - strip debug-section from armelf.\n");
44 fprintf( stderr,
45 "Build %lu\n\n", SDK_DATE_OF_LATEST_FILE);
46 #if (SPECIAL_SECTION_ENABLE == 1) /*Add special section*/
47 fprintf( stderr,
48 "Usage: stripdebug [-o output-file] [-O output-debugger-file] dll-file\n\n");
49 #else
50 fprintf( stderr,
51 "Usage: stripdebug [-o output-file] dll-file\n\n");
52 #endif
53 exit( 1);
54 }
55
56
SA_searchopt(int argc,char * argv[])57 void SA_searchopt( int argc, char* argv[])
58 {
59 int n;
60
61 if( argc <= 1) {
62 SA_Usage();
63 }
64
65 while( (n = getopt( argc, argv, "hdo:O:")) != -1)
66 {
67 // printf( "%c = 0x%x\n", n, n);
68 switch( n) {
69 case 'd':
70 dbg_print_flag = 1;
71 break;
72 case 'o':
73 if( stripped_elf_fname != NULL) { //Prevent specifying duplications
74 fprintf( stderr, "ERROR! redefined output filename.\n");
75 SA_Usage();
76 }
77 //stripped_elf_fname = optarg;
78 stripped_elf_fname = malloc(strlen(optarg)+1);
79 strcpy(stripped_elf_fname, optarg);
80 break;
81 case 'O':
82 if( added_elf_fname != NULL) { //Prevent specifying duplications
83 fprintf( stderr, "ERROR! redefined output filename.\n");
84 SA_Usage();
85 }
86 //added_elf_fname = optarg;
87 added_elf_fname = malloc(strlen(optarg)+1);
88 strcpy(added_elf_fname, optarg);
89 break;
90 case 'h':
91 default: // '?'
92 SA_Usage();
93 break;
94 }
95 }
96
97 /* getopt sorts argv */
98 if( optind == (argc-1)) {
99 //input_elf_fname = argv[optind];
100 input_elf_fname = malloc(strlen(argv[optind])+1);
101 strcpy(input_elf_fname, argv[optind]);
102 }else{
103 SA_Usage(); //Up to one input file
104 }
105 }
106
portoption(void)107 void portoption( void)
108 {
109 // if( k != 2) {
110 printf( "error : too few input files.\n\n");
111 // }
112 }
113