refactor cmd names
This commit is contained in:
parent
e735ad6710
commit
04150a407f
29 changed files with 84 additions and 81 deletions
|
@ -110,7 +110,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(cat) {
|
||||
COMMAND(cat_main) {
|
||||
|
||||
int start;
|
||||
int arg_len;
|
||||
|
|
|
@ -190,7 +190,7 @@ end:
|
|||
return mode;
|
||||
}
|
||||
|
||||
COMMAND(chmod_cmd) {
|
||||
COMMAND(chmod_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ group:
|
|||
}
|
||||
}
|
||||
|
||||
COMMAND(chown_cmd) {
|
||||
COMMAND(chown_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ static void cp_file(char* path) {
|
|||
pop_path_buffer_2(save2);
|
||||
}
|
||||
|
||||
COMMAND(cp) {
|
||||
COMMAND(cp_main) {
|
||||
|
||||
int start, i;
|
||||
struct stat s;
|
||||
|
|
|
@ -12,7 +12,7 @@ static void help(void) {
|
|||
printf("\tcount=N\t\tCopy only N input blocks\n");
|
||||
}
|
||||
|
||||
COMMAND(dd) {
|
||||
COMMAND(dd_main) {
|
||||
|
||||
FILE* in_file = stdin;
|
||||
FILE* out_file = stdout;
|
||||
|
|
|
@ -74,7 +74,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(echo) {
|
||||
COMMAND(echo_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
|
@ -903,7 +903,7 @@ static void help(void) {
|
|||
printf("\t\t=\t\tprint current line number\n");
|
||||
}
|
||||
|
||||
COMMAND(ed) {
|
||||
COMMAND(ed_main) {
|
||||
|
||||
parse_help(argc, argv, help);
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ static bool run_match(char* path, void* pattern, bool many) {
|
|||
}
|
||||
}
|
||||
|
||||
COMMAND(grep) {
|
||||
COMMAND(grep_main) {
|
||||
|
||||
int start, i;
|
||||
char* pattern;
|
||||
|
|
|
@ -13,7 +13,7 @@ static void help (void) {
|
|||
printf("Print the groups USER is in\n");
|
||||
}
|
||||
|
||||
COMMAND(groups) {
|
||||
COMMAND(groups_main) {
|
||||
|
||||
uid_t uid;
|
||||
int ngroups, i;
|
||||
|
|
|
@ -110,7 +110,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(head) {
|
||||
COMMAND(head_main) {
|
||||
|
||||
int start, count, i;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ static void help (void) {
|
|||
printf("Print information about the USER\n");
|
||||
}
|
||||
|
||||
COMMAND(user_id) {
|
||||
COMMAND(id_main) {
|
||||
|
||||
uid_t uid;
|
||||
gid_t gid, *groups;
|
||||
|
|
|
@ -533,7 +533,7 @@ static int long_arg(char* cur, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(ls) {
|
||||
COMMAND(ls_main) {
|
||||
|
||||
int start, i;
|
||||
bool titled;
|
||||
|
|
|
@ -46,7 +46,7 @@ static bool mkdir_parents(char* path) {
|
|||
return true;
|
||||
}
|
||||
|
||||
COMMAND(makedir) {
|
||||
COMMAND(mkdir_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ static void mv_dir(bool exists) {
|
|||
}
|
||||
}
|
||||
|
||||
COMMAND(mv) {
|
||||
COMMAND(mv_main) {
|
||||
|
||||
int start, dest, i;
|
||||
struct stat s;
|
||||
|
|
|
@ -97,7 +97,7 @@ static void help(void) {
|
|||
printf("Format and print ARG(s) according to FORMAT (a-la C prinf)\n");
|
||||
}
|
||||
|
||||
COMMAND(print) {
|
||||
COMMAND(printf_main) {
|
||||
|
||||
size_t index;
|
||||
int arg_index;
|
||||
|
|
|
@ -110,7 +110,7 @@ static void rm_file(char* path) {
|
|||
pop_path_buffer(save);
|
||||
}
|
||||
|
||||
COMMAND(rm) {
|
||||
COMMAND(rm_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
12
command/su.c
12
command/su.c
|
@ -14,7 +14,7 @@ static struct {
|
|||
|
||||
static bool restricted_shell(const char *shell) {
|
||||
char *line;
|
||||
int result = true;
|
||||
bool result = true;
|
||||
|
||||
while ((line = getusershell()) != NULL) {
|
||||
if (strcmp(line, shell) == 0) {
|
||||
|
@ -54,7 +54,7 @@ static int short_arg (char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND (su) {
|
||||
COMMAND (su_main) {
|
||||
|
||||
int start, res;
|
||||
uid_t cur_uid;
|
||||
|
@ -78,15 +78,13 @@ COMMAND (su) {
|
|||
pw = xgetpwnam(flags.user);
|
||||
cur_uid = getuid();
|
||||
|
||||
if (cur_uid != 0) {
|
||||
if (cur_uid != 0)
|
||||
res = prompt_password(pw, "Password: ");
|
||||
} else {
|
||||
else
|
||||
res = PASSWORD_VALID;
|
||||
}
|
||||
|
||||
if (res != PASSWORD_VALID) {
|
||||
if (res != PASSWORD_VALID)
|
||||
error("invalid password");
|
||||
}
|
||||
|
||||
if (flags.shell && cur_uid != 0 && pw->pw_shell && restricted_shell(pw->pw_shell)) {
|
||||
error_s("using restricted shell");
|
||||
|
|
|
@ -63,7 +63,7 @@ static bool sync_file(char* path) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
COMMAND(sync_cmd) {
|
||||
COMMAND(sync_main) {
|
||||
|
||||
int start, i, ret = EXIT_SUCCESS;
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ cleanup:
|
|||
stack_free(&stack);
|
||||
}
|
||||
|
||||
COMMAND(tac) {
|
||||
COMMAND(tac_main) {
|
||||
|
||||
FILE* in;
|
||||
int i;
|
||||
|
|
|
@ -210,7 +210,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(tail) {
|
||||
COMMAND(tail_main) {
|
||||
|
||||
int start, count, i;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(tee_cmd) {
|
||||
COMMAND(tee_main) {
|
||||
|
||||
int start, i;
|
||||
FILE** files;
|
||||
|
|
|
@ -120,7 +120,7 @@ static int short_arg(char c, char* next) {
|
|||
return ARG_UNUSED;
|
||||
}
|
||||
|
||||
COMMAND(wc) {
|
||||
COMMAND(wc_main) {
|
||||
|
||||
int start, i;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ static void help(void) {
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
COMMAND(whoami) {
|
||||
COMMAND(whoami_main) {
|
||||
|
||||
uid_t usr;
|
||||
struct passwd* passwd;
|
||||
|
|
|
@ -111,7 +111,7 @@ void read_args(FILE* file, char*** args, int* size, int* capacity) {
|
|||
}
|
||||
}
|
||||
|
||||
COMMAND(xargs) {
|
||||
COMMAND(xargs_main) {
|
||||
|
||||
int start, arg_start, arg_on_stack_count;
|
||||
int size, capacity, i;
|
||||
|
|
|
@ -6,7 +6,7 @@ static void help(void) {
|
|||
printf("Repeatedly output a line with all specified STRING(s), or 'y'.\n");
|
||||
}
|
||||
|
||||
COMMAND(yes) {
|
||||
COMMAND(yes_main) {
|
||||
const char* repeat;
|
||||
int i;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
-Isrc
|
||||
-Icommand
|
||||
-Ilib
|
||||
-Ihash
|
||||
-D_DEFAULT_SOURCE
|
||||
-DMAJOR=0
|
||||
-DMINOR=0
|
||||
|
|
|
@ -132,6 +132,10 @@ void xsetuid(uid_t uid);
|
|||
void xsetgid(gid_t gid);
|
||||
struct passwd* xgetpwnam(char* name);
|
||||
|
||||
|
||||
char* crypt(const char* plaintext, const char* pw_pass);
|
||||
|
||||
|
||||
#define PASSWORD_INVALID 0
|
||||
#define PASSWORD_VALID 1
|
||||
#define PASSWORD_EMPTY 2
|
||||
|
|
|
@ -5,30 +5,30 @@
|
|||
#define NEXT_ARGS argc - 1, &argv[1]
|
||||
#define COMMAND(name) int name (ARGUMENTS)
|
||||
|
||||
COMMAND(dd);
|
||||
COMMAND(cat);
|
||||
COMMAND(yes);
|
||||
COMMAND(echo);
|
||||
COMMAND(print);
|
||||
COMMAND(groups);
|
||||
COMMAND(user_id);
|
||||
COMMAND(ls);
|
||||
COMMAND(tail);
|
||||
COMMAND(head);
|
||||
COMMAND(ed);
|
||||
COMMAND(tee_cmd);
|
||||
COMMAND(whoami);
|
||||
COMMAND(wc);
|
||||
COMMAND(xargs);
|
||||
COMMAND(tac);
|
||||
COMMAND(rm);
|
||||
COMMAND(cp);
|
||||
COMMAND(makedir);
|
||||
COMMAND(mv);
|
||||
COMMAND(grep);
|
||||
COMMAND(chown_cmd);
|
||||
COMMAND(chmod_cmd);
|
||||
COMMAND(sync_cmd);
|
||||
COMMAND(su);
|
||||
COMMAND(dd_main);
|
||||
COMMAND(cat_main);
|
||||
COMMAND(yes_main);
|
||||
COMMAND(echo_main);
|
||||
COMMAND(printf_main);
|
||||
COMMAND(groups_main);
|
||||
COMMAND(id_main);
|
||||
COMMAND(ls_main);
|
||||
COMMAND(tail_main);
|
||||
COMMAND(head_main);
|
||||
COMMAND(ed_main);
|
||||
COMMAND(tee_main);
|
||||
COMMAND(whoami_main);
|
||||
COMMAND(wc_main);
|
||||
COMMAND(xargs_main);
|
||||
COMMAND(tac_main);
|
||||
COMMAND(rm_main);
|
||||
COMMAND(cp_main);
|
||||
COMMAND(mkdir_main);
|
||||
COMMAND(mv_main);
|
||||
COMMAND(grep_main);
|
||||
COMMAND(chown_main);
|
||||
COMMAND(chmod_main);
|
||||
COMMAND(sync_main);
|
||||
COMMAND(su_main);
|
||||
|
||||
#endif
|
||||
|
|
50
src/main.c
50
src/main.c
|
@ -37,61 +37,61 @@ int main (ARGUMENTS) {
|
|||
}
|
||||
|
||||
if (streql(cmd, "dd")) {
|
||||
return dd(NEXT_ARGS);
|
||||
return dd_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "cat")) {
|
||||
return cat(NEXT_ARGS);
|
||||
return cat_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "yes")) {
|
||||
return yes(NEXT_ARGS);
|
||||
return yes_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "echo")) {
|
||||
return echo(NEXT_ARGS);
|
||||
return echo_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "printf")) {
|
||||
return print(NEXT_ARGS);
|
||||
return printf_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "groups")) {
|
||||
return groups(NEXT_ARGS);
|
||||
return groups_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "id")) {
|
||||
return user_id(NEXT_ARGS);
|
||||
return id_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "ls") || streql(cmd, "dir")) {
|
||||
return ls(NEXT_ARGS);
|
||||
return ls_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "lsd")) {
|
||||
printf("look at all the funny colors\n");
|
||||
} else if (streql(cmd, "tail")) {
|
||||
return tail(NEXT_ARGS);
|
||||
return tail_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "head")) {
|
||||
return head(NEXT_ARGS);
|
||||
return head_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "ed")) {
|
||||
return ed(NEXT_ARGS);
|
||||
return ed_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "tee")) {
|
||||
return tee_cmd(NEXT_ARGS);
|
||||
return tee_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "true")) {
|
||||
return EXIT_SUCCESS;
|
||||
} else if (streql(cmd, "false")) {
|
||||
return EXIT_FAILURE;
|
||||
} else if (streql(cmd, "whoami")) {
|
||||
return whoami(NEXT_ARGS);
|
||||
return whoami_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "wc")) {
|
||||
return wc(NEXT_ARGS);
|
||||
return wc_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "xargs")) {
|
||||
return xargs(NEXT_ARGS);
|
||||
return xargs_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "tac")) {
|
||||
return tac(NEXT_ARGS);
|
||||
return tac_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "rm")) {
|
||||
return rm(NEXT_ARGS);
|
||||
return rm_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "cp")) {
|
||||
return cp(NEXT_ARGS);
|
||||
return cp_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "mkdir")) {
|
||||
return makedir(NEXT_ARGS);
|
||||
return mkdir_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "mv")) {
|
||||
return mv(NEXT_ARGS);
|
||||
return mv_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "grep")) {
|
||||
return grep(NEXT_ARGS);
|
||||
return grep_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "chown")) {
|
||||
return chown_cmd(NEXT_ARGS);
|
||||
return chown_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "chmod")) {
|
||||
return chmod_cmd(NEXT_ARGS);
|
||||
return chmod_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "sync")) {
|
||||
return sync_cmd(NEXT_ARGS);
|
||||
return sync_main(NEXT_ARGS);
|
||||
} else if (streql(cmd, "su")) {
|
||||
return su(NEXT_ARGS);
|
||||
return su_main(NEXT_ARGS);
|
||||
} else {
|
||||
fprintf(stderr, "lazysphere: invalid command %s\n", cmd);
|
||||
return EXIT_FAILURE;
|
||||
|
|
Loading…
Reference in a new issue