Skip to content

Commit

Permalink
Update to be conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwer-TeX committed Aug 23, 2024
1 parent 3e56df8 commit effa9d9
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 7 deletions.
108 changes: 107 additions & 1 deletion src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,165 @@ int help(int argc, char *argv[]) {
"\n"
"Current implementations include (in chronological order from 1st to "
"recently developed):\n"
#ifdef CONFIG_WC
"wc: Print newline, word, and byte counts\n"
#endif
#ifdef CONFIG_CAT
"cat: Concatenate files\n"
#endif
#ifdef CONFIG_CP
"cp: Copy files\n"
#endif
#ifdef CONFIG_SYNC
"sync: Sync filesystem caches to disk\n"
#endif
#ifdef CONFIG_YES
"yes: Output y or a character repeatedly until killed\n"
#endif
#ifdef CONFIG_UPDATE
"update: Sync filesystem caches every 30 seconds\n"
#endif
#ifdef CONFIG_SLEEP
"sleep: Sleep for the specified amount of seconds\n"
#endif
#ifdef CONFIG_WHOAMI
"whoami: Print current effective username\n"
#endif
#ifdef CONFIG_TRUE
"true: Return true\n"
#endif
#ifdef CONFIG_FALSE
"false: Return false\n"
#endif
#ifdef CONFIG_LS
"ls: List directory contents\n"
#endif
#ifdef CONFIG_ECHO
"echo: Display a line of text\n"
#endif
#ifdef CONFIG_INIT
"init: Initialize system\n"
#endif
#ifdef CONFIG_CMP
"cmp: Compare two files\n"
#endif
#ifdef CONFIG_RM
"rm: Remove files or directories\n"
#endif
#ifdef CONFIG_RMDIR
"rmdir: Remove empty directories\n"
#endif
#ifdef CONFIG_MKDIR
"mkdir: Create directories\n"
#endif
#ifdef CONFIG_MKNOD
"mknod: Create special files\n"
#endif
#ifdef CONFIG_HOSTNAME
"hostname: Print hostname\n"
#endif
#ifdef CONFIG_FREE
"free: Display memory stats (shared & used probably broken)\n"
#endif
#ifdef CONFIG_XXD
"xxd: Make a hex dump\n"
#endif
#ifdef CONFIG_OD
"od: Dump files in octal format\n"
#endif
#ifdef CONFIG_HEXDUMP
"hexdump: Display a file in hexadecimal\n"
#endif
#ifdef CONFIG_W
"w: Display info about current users on machine (output "
"broken)\n"
#endif
#ifdef CONFIG_VMSTAT
"vmstat: Report virtual memory statistics (output broken)\n"
#endif
#ifdef CONFIG_CUT
"cut: Exclude sections of lines in files and print to stdout\n"
#endif
#ifdef CONFIG_GREP
"grep: Print lines that match the pattern in files\n"
#endif
#ifdef CONFIG_TR
"tr: Translate characters\n"
#endif
#ifdef CONFIG_SORT
"sort: Sort lines of text\n"
#endif
#ifdef CONFIG_UNIQ
"uniq: Report or omit duplicate lines\n"
#endif
#ifdef CONFIG_UPTIME
"uptime: Display how long the system has been running\n"
#endif
#ifdef CONFIG_PS
"ps: Print current running processes snapshot\n"
#endif
#ifdef CONFIG_KILL
"kill: Send a signal to a process\n"
#endif
#ifdef CONFIG_TTY
"tty: Print the terminal connected to stdin\n"
#endif
#ifdef CONFIG_LINK
"link: Call link() to create a link to a file\n"
#endif
#ifdef CONFIG_UNLINK
"unlink: Call unlink() to remove a link to a file\n"
#endif
#ifdef CONFIG_NOHUP
"nohup: Run command immune to SIGHUP and all output to file\n"
#endif
#ifdef CONFIG_DIRNAME
"dirname: Strip last component from filename\n"
#endif
#ifdef CONFIG_BASENAME
"basename: Strip directory and suffix from filenames\n"
#endif
#ifdef CONFIG_CAL
"cal: Display calendar\n"
#endif
#ifdef CONFIG_CLEAR
"clear: Clear the terminal screen\n"
#endif
#ifdef CONFIG_ENV
"env: Run a program in a custom environment\n"
#endif
#ifdef CONFIG_EXPAND
"expand: Convert tabs to spaces\n"
#endif
#ifdef CONFIG_UNEXPAND
"unexpand: Convert spaces to tabs\n"
#endif
#ifdef CONFIG_FOLD
"fold: Wrap lines in input files to stdout\n"
#endif
#ifdef CONFIG_FACTOR
"factor: Display prime factors of a number\n"
#endif
#ifdef CONFIG_TOUCH
"touch: Create or change file timestamps\n"
#endif
#ifdef CONFIG_HEAD
"head: Output the first part of a file\n"
#endif
#ifdef CONFIG_TAIL
"tail: Output the last part of a file\n"
#endif
#ifdef CONFIG_PASTE
"paste: Merge lines from files\n"
#endif
#ifdef CONFIG_ARCH
"arch: Print machine hardware architecture\n"
"date: print/set system time and date\n",
#endif
#ifdef CONFIG_DATE
"date: Print/set system time and date\n"
#endif
// Add more commands here as needed
"\n",
VERSION);
return 0;
}
116 changes: 110 additions & 6 deletions src/minibox.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,165 @@ typedef struct {
CommandFunc cmd_func;
} Command;

// Create command table
// Create command table conditionally
Command commands[] = {
{"wc", (CommandFunc)wc},
#ifdef CONFIG_WC
{"wc", wc},
#endif
#ifdef CONFIG_CAT
{"cat", cat},
#endif
#ifdef CONFIG_CP
{"cp", cp},
#endif
#ifdef CONFIG_SYNC
{"sync", _sync},
#endif
#ifdef CONFIG_YES
{"yes", yes},
#endif
#ifdef CONFIG_UPDATE
{"update", update},
#endif
#ifdef CONFIG_SLEEP
{"sleep", _sleep},
#endif
#ifdef CONFIG_WHOAMI
{"whoami", whoami},
#endif
#ifdef CONFIG_TRUE
{"true", _true},
#endif
#ifdef CONFIG_FALSE
{"false", _false},
#endif
#ifdef CONFIG_LS
{"ls", ls},
#endif
#ifdef CONFIG_ECHO
{"echo", echo},
#endif
#ifdef CONFIG_INIT
{"init", init},
{"cmp", (CommandFunc)cmp},
#endif
#ifdef CONFIG_CMP
{"cmp", cmp},
#endif
#ifdef CONFIG_RM
{"rm", rm},
#endif
#ifdef CONFIG_RMDIR
{"rmdir", rmdir_cmd},
#endif
#ifdef CONFIG_MKDIR
{"mkdir", mkdir_cmd},
#endif
#ifdef CONFIG_MKNOD
{"mknod", mknod_command},
#endif
#ifdef CONFIG_HOSTNAME
{"hostname", hostname},
#endif
#ifdef CONFIG_FREE
{"free", free_cmd},
#endif
#ifdef CONFIG_XXD
{"xxd", xxd},
#endif
#ifdef CONFIG_OD
{"od", od},
#endif
#ifdef CONFIG_HEXDUMP
{"hexdump", hexdump},
#endif
#ifdef CONFIG_W
{"w", w},
#endif
#ifdef CONFIG_VMSTAT
{"vmstat", vmstat},
#endif
#ifdef CONFIG_CUT
{"cut", cut},
#endif
#ifdef CONFIG_GREP
{"grep", grep},
#endif
#ifdef CONFIG_TR
{"tr", tr},
#endif
#ifdef CONFIG_SORT
{"sort", sort},
#endif
#ifdef CONFIG_UNIQ
{"uniq", uniq},
#endif
#ifdef CONFIG_UPTIME
{"uptime", uptime},
#endif
#ifdef CONFIG_PS
{"ps", ps},
#endif
#ifdef CONFIG_KILL
{"kill", kill_process},
#endif
#ifdef CONFIG_TTY
{"tty", tty},
#endif
#ifdef CONFIG_LINK
{"link", create_link},
#endif
#ifdef CONFIG_UNLINK
{"unlink", remove_link},
#endif
#ifdef CONFIG_NOHUP
{"nohup", nohup},
#endif
#ifdef CONFIG_DIRNAME
{"dirname", print_dirname},
#endif
#ifdef CONFIG_BASENAME
{"basename", print_basename},
#endif
#ifdef CONFIG_CAL
{"cal", cal},
#endif
#ifdef CONFIG_CLEAR
{"clear", clear},
#endif
#ifdef CONFIG_ENV
{"env", env},
#endif
#ifdef CONFIG_EXPAND
{"expand", expand},
#endif
#ifdef CONFIG_UNEXPAND
{"unexpand", unexpand},
#endif
#ifdef CONFIG_FOLD
{"fold", fold},
#endif
#ifdef CONFIG_FACTOR
{"factor", factor},
#endif
#ifdef CONFIG_TOUCH
{"touch", touch},
#endif
#ifdef CONFIG_HEAD
{"head", head},
#endif
#ifdef CONFIG_TAIL
{"tail", tail},
#endif
#ifdef CONFIG_PASTE
{"paste", paste},
#endif
#ifdef CONFIG_ARCH
{"arch", arch},
{"date", date}
// Add more commands here
#endif
#ifdef CONFIG_DATE
{"date", date},
#endif
// Add more commands here as needed
};

size_t num_commands = sizeof(commands) / sizeof(commands[0]);
Expand All @@ -102,7 +206,7 @@ int execute_command(const char *cmd, int argc, char *argv[]) {
return commands[i].cmd_func(argc, argv);
}
}
fprintf(stderr, "Unknown command or option specifed: %s\n", cmd);
fprintf(stderr, "Unknown command or option specified: %s\n", cmd);
return 1;
}

Expand Down

0 comments on commit effa9d9

Please sign in to comment.