add --no-extend option + rename --help-lxsh-commands to --help-extend-fcts
This commit is contained in:
parent
baadd1d927
commit
a1b2d74940
4 changed files with 51 additions and 45 deletions
9
include/errcodes.h
Normal file
9
include/errcodes.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef ERRCODES_H
|
||||
#define ERRCODES_H
|
||||
|
||||
#define ERR_HELP 1001
|
||||
#define ERR_OPT 1002
|
||||
#define ERR_PARSE 1003
|
||||
#define ERR_RUNTIME 1004
|
||||
|
||||
#endif //ERRCODES_H
|
||||
|
|
@ -11,7 +11,7 @@ extern bool g_include;
|
|||
extern bool g_resolve;
|
||||
extern bool g_shebang;
|
||||
|
||||
void print_lxsh_cmd_help();
|
||||
void print_lxsh_extension_help();
|
||||
|
||||
void get_opts();
|
||||
|
||||
|
|
@ -39,4 +39,6 @@ options:
|
|||
*/
|
||||
ztd::option_set create_resolve_opts();
|
||||
|
||||
void oneshot_opt_process(const char* arg0);
|
||||
|
||||
#endif //OPTIONS_HPP
|
||||
|
|
|
|||
45
src/main.cpp
45
src/main.cpp
|
|
@ -19,40 +19,7 @@
|
|||
#include "exec.hpp"
|
||||
#include "shellcode.hpp"
|
||||
|
||||
#include "version.h"
|
||||
#include "g_version.h"
|
||||
|
||||
#define ERR_HELP 1001
|
||||
#define ERR_OPT 1002
|
||||
#define ERR_PARSE 1003
|
||||
#define ERR_RUNTIME 1004
|
||||
|
||||
void oneshot_opt_process(const char* arg0)
|
||||
{
|
||||
if(options['h'])
|
||||
{
|
||||
print_help(arg0);
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
else if(options["version"])
|
||||
{
|
||||
printf("%s %s%s\n", arg0, VERSION_STRING, VERSION_SUFFIX);
|
||||
printf("%s\n", VERSION_SHA);
|
||||
exit(0);
|
||||
}
|
||||
else if(options["help-link-commands"])
|
||||
{
|
||||
print_include_help();
|
||||
printf("\n\n");
|
||||
print_resolve_help();
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
else if(options["help-lxsh-commands"])
|
||||
{
|
||||
print_lxsh_cmd_help();
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
}
|
||||
#include "errcodes.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
|
@ -160,13 +127,9 @@ int main(int argc, char* argv[])
|
|||
if(is_exec)
|
||||
{
|
||||
if(options["debashify"])
|
||||
{
|
||||
shebang = "#!/bin/sh";
|
||||
}
|
||||
if(options["debashify"] || basename(shebang) == "bash")
|
||||
{
|
||||
g_bash = true;
|
||||
}
|
||||
args.erase(args.begin());
|
||||
return exec_process(shebang.substr(2), args, filecontents, file);
|
||||
}
|
||||
|
|
@ -213,7 +176,7 @@ int main(int argc, char* argv[])
|
|||
// post-listing modifiers
|
||||
// implement commands
|
||||
std::set<std::string> req_fcts;
|
||||
if(shebang_is_bin)
|
||||
if(shebang_is_bin && !options["no-extend"])
|
||||
req_fcts = find_lxsh_commands(sh);
|
||||
if(options["debashify"])
|
||||
concat_sets(req_fcts, debashify(sh) );
|
||||
|
|
@ -239,12 +202,12 @@ int main(int argc, char* argv[])
|
|||
std::string destfile=options['o'];
|
||||
// resolve - to stdout
|
||||
if(destfile == "-")
|
||||
destfile = "/dev/stdout";
|
||||
destfile = "/dev/stdout";
|
||||
// output
|
||||
std::ofstream(destfile) << sh->generate(g_shebang, 0);
|
||||
// don't chmod on /dev/
|
||||
if(destfile.substr(0,5) != "/dev/")
|
||||
ztd::exec("chmod", "+x", destfile);
|
||||
ztd::exec("chmod", "+x", destfile);
|
||||
}
|
||||
else // to console
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
#include "processing.hpp"
|
||||
#include "shellcode.hpp"
|
||||
|
||||
#include "errcodes.h"
|
||||
#include "version.h"
|
||||
#include "g_version.h"
|
||||
|
||||
ztd::option_set options = gen_options();
|
||||
bool opt_minify=false;
|
||||
|
||||
|
|
@ -18,8 +22,8 @@ ztd::option_set gen_options()
|
|||
ztd::option("\r [Help]"),
|
||||
ztd::option('h', "help", false, "Display this help message"),
|
||||
ztd::option("version", false, "Display version"),
|
||||
ztd::option("help-link-commands", false, "Print help for special lxsh commands"),
|
||||
ztd::option("help-lxsh-commands", false, "Print help for linker commands"),
|
||||
ztd::option("help-link-commands", false, "Print help for linker commands"),
|
||||
ztd::option("help-extend-fcts", false, "Print help for lxsh extension functions"),
|
||||
ztd::option("\r [Output]"),
|
||||
ztd::option('o', "output", true , "Output result script to file", "file"),
|
||||
ztd::option('c', "stdout", false, "Output result script to stdout"),
|
||||
|
|
@ -33,6 +37,7 @@ ztd::option_set gen_options()
|
|||
ztd::option('C', "no-cd", false, "Don't cd when doing %include and %resolve"),
|
||||
ztd::option('I', "no-include", false, "Don't resolve %include commands"),
|
||||
ztd::option('R', "no-resolve", false, "Don't resolve %resolve commands"),
|
||||
ztd::option("no-extend", false, "Don't add lxsh extension functions"),
|
||||
ztd::option("debashify", false, "Attempt to turn a bash-specific script into a POSIX shell script"),
|
||||
ztd::option("\r [var/fct processing]"),
|
||||
ztd::option("minify-var", false, "Minify variable names"),
|
||||
|
|
@ -133,10 +138,37 @@ void print_resolve_help()
|
|||
opts.print_help(3,7);
|
||||
}
|
||||
|
||||
void print_lxsh_cmd_help()
|
||||
void print_lxsh_extension_help()
|
||||
{
|
||||
for(auto it: lxsh_extend_fcts)
|
||||
{
|
||||
printf("%s %s\n%s\n\n", it.first.c_str(), it.second.arguments.c_str(), it.second.description.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void oneshot_opt_process(const char* arg0)
|
||||
{
|
||||
if(options['h'])
|
||||
{
|
||||
print_help(arg0);
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
else if(options["version"])
|
||||
{
|
||||
printf("%s %s%s\n", arg0, VERSION_STRING, VERSION_SUFFIX);
|
||||
printf("%s\n", VERSION_SHA);
|
||||
exit(0);
|
||||
}
|
||||
else if(options["help-link-commands"])
|
||||
{
|
||||
print_include_help();
|
||||
printf("\n\n");
|
||||
print_resolve_help();
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
else if(options["help-extend-fcts"])
|
||||
{
|
||||
print_lxsh_extension_help();
|
||||
exit(ERR_HELP);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue