Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Sunxi Tools
Commits
90e67cba
Commit
90e67cba
authored
May 10, 2012
by
Alejandro Mery
Browse files
fexc: prepare for multitool support and validate input and output format options
parent
020f001c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
90e67cba
CC
=
gcc
CFLAGS
=
-g
-O2
-Wall
-Wextra
-std
=
c99
CFLAGS
=
-g
-O2
-Wall
-Wextra
CFLAGS
+=
-std
=
c99
-D_POSIX_C_SOURCE
=
200112L
TOOLS
=
fexc bin2fex fex2bin
...
...
fexc.c
View file @
90e67cba
...
...
@@ -17,7 +17,83 @@
#include "fexc.h"
int
main
(
int
UNUSED
(
argc
),
char
*
UNUSED
(
argv
[]))
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
*/
static
inline
void
app_usage
(
const
char
*
arg0
,
int
mode
)
{
errf
(
"Usage: %s [-vq]%s[<input> [<output>]]
\n
"
,
arg0
,
mode
?
" "
:
" [-I <infmt>] [-O <outfmt>] "
);
if
(
mode
==
0
)
fputs
(
"
\n
infmt: fex, bin (default:fex)"
"
\n
outfmt: fex, bin (default:bin)
\n
"
,
stderr
);
}
static
inline
int
app_choose_mode
(
char
*
arg0
)
{
const
char
*
name
=
basename
(
arg0
);
if
(
strcmp
(
name
,
"fex2bin"
)
==
0
)
return
1
;
else
if
(
strcmp
(
name
,
"bin2fex"
)
==
0
)
return
2
;
else
return
0
;
}
/*
*/
int
main
(
int
argc
,
char
*
argv
[])
{
static
const
char
*
formats
[]
=
{
"fex"
,
"bin"
,
NULL
};
int
infmt
=
0
,
outfmt
=
1
;
int
app_mode
=
app_choose_mode
(
argv
[
0
]);
const
char
*
opt_string
=
"I:O:vq?"
+
((
app_mode
==
0
)
?
0
:
4
);
int
opt
;
int
verbose
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
opt_string
))
!=
-
1
)
{
switch
(
opt
)
{
case
'I'
:
infmt
=
0
;
for
(
const
char
**
f
=
formats
;
*
f
;
f
++
,
infmt
++
)
{
if
(
strcmp
(
*
f
,
optarg
)
==
0
)
break
;
}
if
(
!
formats
[
infmt
])
{
errf
(
"%s: invalid format --
\"
%s
\"\n
"
,
argv
[
0
],
optarg
);
goto
show_usage
;
}
break
;
case
'O'
:
outfmt
=
0
;
for
(
const
char
**
f
=
formats
;
*
f
;
f
++
,
outfmt
++
)
{
if
(
strcmp
(
*
f
,
optarg
)
==
0
)
break
;
}
if
(
!
formats
[
outfmt
])
{
errf
(
"%s: invalid format --
\"
%s
\"\n
"
,
argv
[
0
],
optarg
);
goto
show_usage
;
}
break
;
case
'v'
:
verbose
++
;
break
;
default:
show_usage:
app_usage
(
argv
[
0
],
app_mode
);
exit
(
1
);
}
}
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment