All: run `clang-format` on code and makefile.

C source files use LLVM style, Makefile uses Google style.
master
Drake 3 years ago
parent d97207065f
commit 1ee035fe27

@ -4,7 +4,8 @@ CC = gcc
endif
target := $(shell ${CC} -dumpmachine)
ifndef CC_FLAGS
#guess we gotta define this if it no exist, but imagine not needing custom cxx flags
#guess we gotta define this if it no exist, \
but imagine not needing custom cxx flags
CC_FLAGS :=
endif
CC_FLAGS := -Ilib ${CC_FLAGS}

@ -2,40 +2,37 @@
#include <string.h>
#include <sys/utsname.h>
/*
arch - prints the current machine's architecture
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--help: show this help message
--version: show the version of the program (WIP)
*/
int main(int argc, char** argv) {
if (argc == 1) {
struct utsname e;
uname(&e);
printf("%s\n", e.machine);
return 0;
} else {
for (int i = 0; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"arch - prints the current machine's architecture\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
}
}
}
int main(int argc, char **argv) {
if (argc == 1) {
struct utsname e;
uname(&e);
printf("%s\n", e.machine);
return 0;
} else {
for (int i = 0; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"arch - prints the current machine's architecture\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
}
}
}
}

@ -1,49 +1,47 @@
#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <libgen.h>
/*
whoami - prints the working user's username (unless --uid is specified)
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
*/
int main(int argc, char** argv) {
char *wd;
char *upname = NULL;
if (argc == 1) {
char tmp[PATH_MAX];
getcwd(tmp, sizeof(tmp));
upname = tmp;
} else {
for (int i = 1; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"basename - prints the last component of the path\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else {
upname = arg;
break;
}
}
}
wd = basename(upname);
printf("%s\n", wd);
int main(int argc, char **argv) {
char *wd;
char *upname = NULL;
if (argc == 1) {
char tmp[PATH_MAX];
getcwd(tmp, sizeof(tmp));
upname = tmp;
} else {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"basename - prints the last component of the path\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else {
upname = arg;
break;
}
}
}
wd = basename(upname);
printf("%s\n", wd);
}

@ -1,10 +1,10 @@
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ansi-colour.h"
#include "file.h"
@ -12,139 +12,140 @@
/*
ls - print all files and directories in working directory
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--help: show this help message
--version: show the version of the program (WIP)
*/
//https://stackoverflow.com/questions/4770985/how-to-check-if-a-string-starts-with-another-string-in-c/4770992#4770992
// https://stackoverflow.com/questions/4770985/how-to-check-if-a-string-starts-with-another-string-in-c/4770992#4770992
/*static int printBool(bool cond) {
printf("%s\n", cond ? "true" : "false");
return 0;
printf("%s\n", cond ? "true" : "false");
return 0;
}*/
static bool startsWithChar(const char *pre, const char str) {
char *e;
int index;
e = strchr(pre, str);
index = (int)(e - pre);
return index == 0;
char *e;
int index;
e = strchr(pre, str);
index = (int)(e - pre);
return index == 0;
}
static int cmp(const void *a, const void *b){
return strcmp(*(char **)a, *(char **)b);
static int cmp(const void *a, const void *b) {
return strcmp(*(char **)a, *(char **)b);
}
//lots o' code ~~stolen~~ borrowed from https://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html
int main(int argc, char** argv) {
//define default options
bool colour = false;
bool showdot = false;
bool specpath = false;
int maxLen = 180;
char *thatpath;
for (int i = 1; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"ls - print all files and directories in working directory\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" --color: colour the output depending on whether there is a file or folder\n"
" --colour: same as --color, but for our Bri'ish folks\n"
" -C, --columns: print every entry on a seperate line";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--color") || !strcmp(arg, "--colour")) {
colour = true;
} else if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
showdot = true;
} else if (!strcmp(arg, "-C") || !strcmp(arg, "--columns")) {
maxLen = 0;
} else {
//TODO: interpret absolute *and* relative paths. can't be that hard, right?
specpath = true;
thatpath = arg;
}
}
char wd[PATH_MAX];
if (specpath == false) {
getcwd(wd, sizeof(wd));
} else if (specpath == true) {
char *e = realpath(thatpath, NULL);
strcpy(wd, e);
free(e);
}
//printf(wd);
DIR* dirp;
struct dirent *dp;
dirp = opendir(wd);
if (dirp == NULL) {
printf("couldn't open '%s'\n", wd);
return 1;
}
int len = sizeof(char);
char *out = malloc(len);
out = NULL;
dp = readdir(dirp);
do {
char* dirname = dp->d_name;
if (!startsWithChar(dirname, '.') || showdot == true) {
len += 1 + strlen(dirname) + strlen("§");
out = realloc(out, len);
strcat(out, dirname);
strcat(out, "§");
}
} while ((dp = readdir(dirp)) != NULL);
free(dirp);
char *word, *words[strlen(out)/2+1];
int i,n;
i=0;
word = strtok(out, "§");
while (word != NULL) {
words[i++] = word;
word = strtok(NULL, "§");
}
n = i;
qsort(words, n, sizeof(*words), cmp);
char oldwd[PATH_MAX];
strcpy(oldwd, wd);
int currLen = 0;
for (i = 0; i < n; i++) {
if (colour == false) {
printf("%s ", words[i]);
} else {
strcpy(wd, oldwd);
strcat(wd, "/");
strcat(wd, words[i]);
//printf(wd);
if (isSymlink(wd) == true) {
printf(ANSI_GREEN);
printf("%s ", words[i]);
printf(ANSI_RESET);
} else if (isDirectory(wd) == true) {
printf(ANSI_BLUE);
printf("%s ", words[i]);
printf(ANSI_RESET);
} else {
printf("%s ", words[i]);
}
}
currLen += strlen(words[i]);
if (currLen >= maxLen) {
printf("\n");
currLen = 0;
}
}
free(out);
printf("\n");
return 0;
// lots o' code ~~stolen~~ borrowed from
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html
int main(int argc, char **argv) {
// define default options
bool colour = false;
bool showdot = false;
bool specpath = false;
int maxLen = 180;
char *thatpath;
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"ls - print all files and directories in working directory\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" --color: colour the output depending on whether there is "
"a file or folder\n"
" --colour: same as --color, but for our Bri'ish folks\n"
" -C, --columns: print every entry on a seperate line";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--color") || !strcmp(arg, "--colour")) {
colour = true;
} else if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
showdot = true;
} else if (!strcmp(arg, "-C") || !strcmp(arg, "--columns")) {
maxLen = 0;
} else {
// TODO: interpret absolute *and* relative paths. can't be that hard,
// right?
specpath = true;
thatpath = arg;
}
}
char wd[PATH_MAX];
if (specpath == false) {
getcwd(wd, sizeof(wd));
} else if (specpath == true) {
char *e = realpath(thatpath, NULL);
strcpy(wd, e);
free(e);
}
// printf(wd);
DIR *dirp;
struct dirent *dp;
dirp = opendir(wd);
if (dirp == NULL) {
printf("couldn't open '%s'\n", wd);
return 1;
}
int len = sizeof(char);
char *out = malloc(len);
out = NULL;
dp = readdir(dirp);
do {
char *dirname = dp->d_name;
if (!startsWithChar(dirname, '.') || showdot == true) {
len += 1 + strlen(dirname) + strlen("§");
out = realloc(out, len);
strcat(out, dirname);
strcat(out, "§");
}
} while ((dp = readdir(dirp)) != NULL);
free(dirp);
char *word, *words[strlen(out) / 2 + 1];
int i, n;
i = 0;
word = strtok(out, "§");
while (word != NULL) {
words[i++] = word;
word = strtok(NULL, "§");
}
n = i;
qsort(words, n, sizeof(*words), cmp);
char oldwd[PATH_MAX];
strcpy(oldwd, wd);
int currLen = 0;
for (i = 0; i < n; i++) {
if (colour == false) {
printf("%s ", words[i]);
} else {
strcpy(wd, oldwd);
strcat(wd, "/");
strcat(wd, words[i]);
// printf(wd);
if (isSymlink(wd) == true) {
printf(ANSI_GREEN);
printf("%s ", words[i]);
printf(ANSI_RESET);
} else if (isDirectory(wd) == true) {
printf(ANSI_BLUE);
printf("%s ", words[i]);
printf(ANSI_RESET);
} else {
printf("%s ", words[i]);
}
}
currLen += strlen(words[i]);
if (currLen >= maxLen) {
printf("\n");
currLen = 0;
}
}
free(out);
printf("\n");
return 0;
}

@ -1,42 +1,39 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
/*
whoami - prints the working user's username (unless --uid is specified)
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
*/
int main(int argc, char** argv) {
char wd[PATH_MAX];
getcwd(wd, sizeof(wd));
if (argc == 1) {
printf("%s\n", wd);
} else {
for (int i = 0; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"pwd - prints the current working directory\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
}
}
}
int main(int argc, char **argv) {
char wd[PATH_MAX];
getcwd(wd, sizeof(wd));
if (argc == 1) {
printf("%s\n", wd);
} else {
for (int i = 0; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"pwd - prints the current working directory\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
}
}
}
}

@ -1,120 +1,118 @@
#include <bits/local_lim.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/utsname.h>
#include <bits/local_lim.h>
#include <unistd.h>
/*
whoami - prints the working user's username (unless --uid is specified)
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
*/
//https://stackoverflow.com/questions/4770985/how-to-check-if-a-string-starts-with-another-string-in-c/4770992#4770992
// https://stackoverflow.com/questions/4770985/how-to-check-if-a-string-starts-with-another-string-in-c/4770992#4770992
bool startsWithChar(const char *pre, const char str) {
char *e;
int index;
e = strchr(pre, str);
index = (int)(e - pre);
return index == 0;
char *e;
int index;
e = strchr(pre, str);
index = (int)(e - pre);
return index == 0;
}
int main(int argc, char** argv) {
struct utsname uts;
uname(&uts);
if (argc == 1) {
printf("%s\n", uts.sysname);
} else {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"uname - prints system information.\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" -a, --all: print all information (equivalent to -shrvm). \n"
" -s, --sysinfo: kernel type(?)\n"
" -h, --hostname: hostname\n"
" -r, --krelease: kernel version\n"
" -v, --kversion: verbose kernel build version info\n"
" -m, --arch: cpu architecture\n"
"Examples:\n"
" Command:\n"
" uname -srh\n"
" Example output (on my system):\n"
" Linux 5.12.14_1 ruthenic-void";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--hostname")) {
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
} else if (!strcmp(arg, "--sysinfo")) {
printf("%s ", uts.sysname);
} else if (!strcmp(arg, "--krelease")) {
printf("%s ", uts.release);
} else if (!strcmp(arg, "--kversion")) {
printf("%s ", uts.version);
} else if (!strcmp(arg, "--arch")) {
printf("%s ", uts.machine);
} else if (!strcmp(arg, "--all")) {
//equivalent to -shrvm
printf("%s ", uts.sysname);
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
printf("%s ", uts.release);
printf("%s ", uts.version);
printf("%s ", uts.machine);
} else if (startsWithChar(arg, '-')) {
char info;
for (unsigned long n = 1; n < strlen(arg); n++) {
info = arg[n];
//printf(info);
//printf("\n");
if (info == 'h') {
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
}
if (info == 's') {
printf("%s ", uts.sysname);
}
if (info == 'r') {
printf("%s ", uts.release);
}
if (info == 'v') {
printf("%s ", uts.version);
}
if (info == 'm') {
printf("%s ", uts.machine);
}
if (info == 'a') {
//equivalent to -shrvm
printf("%s ", uts.sysname);
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
printf("%s ", uts.release);
printf("%s ", uts.version);
printf("%s ", uts.machine);
}
}
}
}
printf("\n");
}
int main(int argc, char **argv) {
struct utsname uts;
uname(&uts);
if (argc == 1) {
printf("%s\n", uts.sysname);
} else {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"uname - prints system information.\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" -a, --all: print all information (equivalent to -shrvm). "
"\n"
" -s, --sysinfo: kernel type(?)\n"
" -h, --hostname: hostname\n"
" -r, --krelease: kernel version\n"
" -v, --kversion: verbose kernel build version info\n"
" -m, --arch: cpu architecture\n"
"Examples:\n"
" Command:\n"
" uname -srh\n"
" Example output (on my system):\n"
" Linux 5.12.14_1 ruthenic-void";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--hostname")) {
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
} else if (!strcmp(arg, "--sysinfo")) {
printf("%s ", uts.sysname);
} else if (!strcmp(arg, "--krelease")) {
printf("%s ", uts.release);
} else if (!strcmp(arg, "--kversion")) {
printf("%s ", uts.version);
} else if (!strcmp(arg, "--arch")) {
printf("%s ", uts.machine);
} else if (!strcmp(arg, "--all")) {
// equivalent to -shrvm
printf("%s ", uts.sysname);
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
printf("%s ", uts.release);
printf("%s ", uts.version);
printf("%s ", uts.machine);
} else if (startsWithChar(arg, '-')) {
char info;
for (unsigned long n = 1; n < strlen(arg); n++) {
info = arg[n];
// printf(info);
// printf("\n");
if (info == 'h') {
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
}
if (info == 's') {
printf("%s ", uts.sysname);
}
if (info == 'r') {
printf("%s ", uts.release);
}
if (info == 'v') {
printf("%s ", uts.version);
}
if (info == 'm') {
printf("%s ", uts.machine);
}
if (info == 'a') {
// equivalent to -shrvm
printf("%s ", uts.sysname);
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
printf("%s ", hostname);
printf("%s ", uts.release);
printf("%s ", uts.version);
printf("%s ", uts.machine);
}
}
}
}
printf("\n");
}
}

@ -1,46 +1,45 @@
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
/*
whoami - prints the working user's username (unless --uid is specified)
Available arguments:
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
--help: show this help message
--version: show the version of the program (WIP)
--uid: print the users numeric UID, instead of username
*/
int main(int argc, char** argv) {
uid_t userid = geteuid();
char * username = getpwuid(userid)->pw_name;
if (argc == 1) {
printf("%s\n", username);
return 0;
} else {
for (int i = 0; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"whoami - prints the working user's username (unless --uid is specified)\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" --uid: print the users numeric UID, instead of username";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--uid")) {
printf("%d\n", (int)userid);
return 0;
}
}
}
int main(int argc, char **argv) {
uid_t userid = geteuid();
char *username = getpwuid(userid)->pw_name;
if (argc == 1) {
printf("%s\n", username);
return 0;
} else {
for (int i = 0; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"whoami - prints the working user's username (unless --uid is "
"specified)\n"
"Available arguments:\n"
" --help: show this help message\n"
" --version: show the version of the program\n"
" --uid: print the users numeric UID, instead of username";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--uid")) {
printf("%d\n", (int)userid);
return 0;
}
}
}
}

@ -1,49 +1,47 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
/*
yes - spams a message (by default `y`) to stdout.
Available arguments:
--help: show this help message.
--version: show version of the program.
--help: show this help message.
--version: show version of the program.
Usage:
yes [--help] [--version] [message]
yes [--help] [--version] [message]
*/
int main(int argc, char** argv) {
char *spammy = malloc(sizeof(char) * 16);
if (argc == 1) {
spammy = "y";
} else {
for (int i = 1; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
DRAKECU_VERSION
"\n"
"yes - spams a message (by default `y`) to stdout.\n"
"Available arguments:\n"
" --help: show this help message.\n"
" --version: show version of the program.\n"
"Usage:\n"
" yes [--help] [--version] [message]";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else {
spammy = realloc(spammy, strlen(arg) + strlen(spammy) + 1);
strcat(spammy, arg);
strcat(spammy, " ");
}
}
}
do {
printf("%s\n", spammy);
} while (1);
int main(int argc, char **argv) {
char *spammy = malloc(sizeof(char) * 16);
if (argc == 1) {
spammy = "y";
} else {
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char *help =
"Drake's Epic Coreutils (working title) " DRAKECU_VERSION "\n"
"yes - spams a message (by default `y`) to stdout.\n"
"Available arguments:\n"
" --help: show this help message.\n"
" --version: show version of the program.\n"
"Usage:\n"
" yes [--help] [--version] [message]";
printf("%s\n", help);
return 0;
} else if (!strcmp(arg, "--version")) {
printf(DRAKECU_VERSION);
return 0;
} else {
spammy = realloc(spammy, strlen(arg) + strlen(spammy) + 1);
strcat(spammy, arg);
strcat(spammy, " ");
}
}
}
do {
printf("%s\n", spammy);
} while (1);
}

Loading…
Cancel
Save