Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
e79478d0
Commit
e79478d0
authored
Jul 10, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2457 from cremno/mruby-strip-rewrite
mruby-bin-strip rewrite
parents
835da83c
10bd78e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
48 deletions
+72
-48
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
+1
-1
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
+71
-47
No files found.
mrbgems/mruby-bin-strip/bintest/mruby-strip.rb
View file @
e79478d0
...
@@ -9,7 +9,7 @@ end
...
@@ -9,7 +9,7 @@ end
assert
(
'file not found'
)
do
assert
(
'file not found'
)
do
o
=
`bin/mruby-strip not_found.mrb 2>&1`
o
=
`bin/mruby-strip not_found.mrb 2>&1`
assert_equal
1
,
$?
.
exitstatus
assert_equal
1
,
$?
.
exitstatus
assert_equal
"can't open file not_found.mrb
\n
"
,
o
assert_equal
"can't open file
for reading
not_found.mrb
\n
"
,
o
end
end
assert
(
'not irep file'
)
do
assert
(
'not irep file'
)
do
...
...
mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c
View file @
e79478d0
...
@@ -6,6 +6,9 @@
...
@@ -6,6 +6,9 @@
#include "mruby/dump.h"
#include "mruby/dump.h"
struct
strip_args
{
struct
strip_args
{
int
argc_start
;
int
argc
;
char
**
argv
;
mrb_bool
lvar
;
mrb_bool
lvar
;
};
};
...
@@ -36,15 +39,17 @@ print_usage(const char *f)
...
@@ -36,15 +39,17 @@ print_usage(const char *f)
static
int
static
int
parse_args
(
int
argc
,
char
**
argv
,
struct
strip_args
*
args
)
parse_args
(
int
argc
,
char
**
argv
,
struct
strip_args
*
args
)
{
{
static
const
struct
strip_args
initial_args
=
{
0
};
int
i
;
int
i
;
*
args
=
initial_args
;
args
->
argc_start
=
0
;
args
->
argc
=
argc
;
args
->
argv
=
argv
;
args
->
lvar
=
FALSE
;
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
i
=
1
;
i
<
argc
;
++
i
)
{
size_t
cons
t
len
=
strlen
(
argv
[
i
]);
const
size_
t
len
=
strlen
(
argv
[
i
]);
if
(
len
>=
2
&&
argv
[
i
][
0
]
==
'-'
)
{
if
(
len
>=
2
&&
argv
[
i
][
0
]
==
'-'
)
{
switch
(
argv
[
i
][
1
])
{
switch
(
argv
[
i
][
1
])
{
case
'l'
:
case
'l'
:
args
->
lvar
=
TRUE
;
args
->
lvar
=
TRUE
;
break
;
break
;
...
@@ -56,22 +61,75 @@ parse_args(int argc, char **argv, struct strip_args *args)
...
@@ -56,22 +61,75 @@ parse_args(int argc, char **argv, struct strip_args *args)
default:
default:
return
-
1
;
return
-
1
;
}
}
}
else
{
}
else
{
break
;
break
;
}
}
}
}
args
->
argc_start
=
i
;
return
i
;
return
i
;
}
}
static
int
strip
(
mrb_state
*
mrb
,
struct
strip_args
*
args
)
{
int
i
;
for
(
i
=
args
->
argc_start
;
i
<
args
->
argc
;
++
i
)
{
char
*
filename
;
FILE
*
rfile
;
mrb_irep
*
irep
;
FILE
*
wfile
;
int
dump_result
;
filename
=
args
->
argv
[
i
];
rfile
=
fopen
(
filename
,
"rb"
);
if
(
rfile
==
NULL
)
{
fprintf
(
stderr
,
"can't open file for reading %s
\n
"
,
filename
);
return
EXIT_FAILURE
;
}
irep
=
mrb_read_irep_file
(
mrb
,
rfile
);
fclose
(
rfile
);
if
(
irep
==
NULL
)
{
fprintf
(
stderr
,
"can't read irep file %s
\n
"
,
filename
);
return
EXIT_FAILURE
;
}
/* clear lv if --lvar is enabled */
if
(
args
->
lvar
)
{
irep_remove_lv
(
mrb
,
irep
);
}
wfile
=
fopen
(
filename
,
"wb"
);
if
(
wfile
==
NULL
)
{
fprintf
(
stderr
,
"can't open file for writing %s
\n
"
,
filename
);
mrb_irep_decref
(
mrb
,
irep
);
return
EXIT_FAILURE
;
}
/* debug flag must always be false */
dump_result
=
mrb_dump_irep_binary
(
mrb
,
irep
,
FALSE
,
wfile
);
fclose
(
wfile
);
mrb_irep_decref
(
mrb
,
irep
);
if
(
dump_result
!=
MRB_DUMP_OK
)
{
fprintf
(
stderr
,
"error occurred during dumping %s
\n
"
,
filename
);
return
EXIT_FAILURE
;
}
}
return
EXIT_SUCCESS
;
}
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
struct
strip_args
args
;
struct
strip_args
args
;
int
args_result
,
i
,
dump_result
;
int
args_result
;
FILE
**
files
;
mrb_irep
**
ireps
;
mrb_state
*
mrb
;
mrb_state
*
mrb
;
int
ret
;
if
(
argc
<=
1
)
{
if
(
argc
<=
1
)
{
printf
(
"no files to strip
\n
"
);
printf
(
"no files to strip
\n
"
);
...
@@ -84,48 +142,14 @@ main(int argc, char **argv)
...
@@ -84,48 +142,14 @@ main(int argc, char **argv)
print_usage
(
argv
[
0
]);
print_usage
(
argv
[
0
]);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
files
=
(
FILE
**
)
malloc
(
sizeof
(
FILE
*
)
*
argc
);
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
files
[
i
]
=
fopen
(
argv
[
i
],
"rb"
);
if
(
!
files
[
i
])
{
fprintf
(
stderr
,
"can't open file %s
\n
"
,
argv
[
i
]);
return
EXIT_FAILURE
;
}
}
mrb
=
mrb_open
();
mrb
=
mrb_open
();
if
(
mrb
==
NULL
)
{
ireps
=
(
mrb_irep
**
)
malloc
(
sizeof
(
mrb_irep
*
)
*
argc
);
fputs
(
"Invalid mrb_state, exiting mruby-strip
\n
"
,
stderr
);
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
return
EXIT_FAILURE
;
ireps
[
i
]
=
mrb_read_irep_file
(
mrb
,
files
[
i
]);
if
(
!
ireps
[
i
])
{
fprintf
(
stderr
,
"can't read irep file %s
\n
"
,
argv
[
i
]);
return
EXIT_FAILURE
;
}
fclose
(
files
[
i
]);
files
[
i
]
=
fopen
(
argv
[
i
],
"wb"
);
if
(
!
ireps
[
i
])
{
fprintf
(
stderr
,
"can't reopen irep file %s
\n
"
,
argv
[
i
]);
return
EXIT_FAILURE
;
}
}
}
for
(
i
=
args_result
;
i
<
argc
;
++
i
)
{
ret
=
strip
(
mrb
,
&
args
);
/* clear lv if --lvar is enabled */
if
(
args
.
lvar
)
{
irep_remove_lv
(
mrb
,
ireps
[
i
]);
}
/* debug flag must be alway false */
dump_result
=
mrb_dump_irep_binary
(
mrb
,
ireps
[
i
],
FALSE
,
files
[
i
]);
if
(
dump_result
!=
MRB_DUMP_OK
)
{
fprintf
(
stderr
,
"error occur when dumping %s"
,
argv
[
i
]);
return
EXIT_FAILURE
;
}
}
mrb_close
(
mrb
);
mrb_close
(
mrb
);
return
EXIT_SUCCESS
;
return
ret
;
}
}
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