Added options

This commit is contained in:
Emil 2023-09-28 06:14:17 +00:00
parent d1bfbd97b1
commit c1e5410850
No known key found for this signature in database
GPG Key ID: 5432DB986FDBCF8A

40
baked.c
View File

@ -167,7 +167,6 @@ static size_t
expand_size(char * buf, size_t len, int argc, char ** argv) expand_size(char * buf, size_t len, int argc, char ** argv)
{ {
size_t i, max = len; size_t i, max = len;
g_filename = argv[1];
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
{ {
if (buf[i] == '\\') if (buf[i] == '\\')
@ -181,7 +180,7 @@ expand_size(char * buf, size_t len, int argc, char ** argv)
break; break;
case '*': case '*':
if (!g_short) if (!g_short)
{ g_short = shorten(argv[1]); } { g_short = shorten(g_filename); }
max += strlen(g_short); max += strlen(g_short);
break; break;
case '+': case '+':
@ -229,22 +228,39 @@ expand(char * buf, size_t len)
return buf; return buf;
} }
static int
run(const char * buf)
{
fputs("Output:\n", stderr);
root(g_filename);
return system(buf);
}
int int
main(int argc, char ** argv) main(int argc, char ** argv)
{ {
int ret; int ret = 0;
size_t len;
char * buf; char * buf;
if (argc < 2)
if (argc < 2
|| !strcmp(argv[1], "-h"))
{ fprintf(stderr, "%s: %s", argv[0], HELP DESC); return 1; } { fprintf(stderr, "%s: %s", argv[0], HELP DESC); return 1; }
buf = find_region(argv[1]);
if (!buf g_filename = argv[1];
|| root(argv[1]))
if (!strcmp(argv[1], "-n"))
{ ret = 1; g_filename = argv[2]; }
buf = find_region(g_filename);
if (!buf)
{ if (errno) { perror(NULL); } return 1; } { if (errno) { perror(NULL); } return 1; }
len = expand_size(buf, strlen(buf), argc, argv) + 1;
buf = expand(buf, len); buf = expand(buf, expand_size(buf, strlen(buf), argc, argv) + 1);
fprintf(stderr, "Exec: %s\nOutput:\n", buf);
fprintf(stderr, "Result: %d\n", (ret = system(buf))); fprintf(stderr, "Exec: %s\n", buf);
if ((ret = ret ? 0 : run(buf)))
{ fprintf(stderr, "Result: %d\n", ret); }
free(buf); free(buf);
return ret; return ret;
} }