summaryrefslogtreecommitdiff
path: root/command
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--command/cat.c (renamed from src/commands/cat.c)4
-rw-r--r--command/cp.c (renamed from src/commands/cp.c)7
-rw-r--r--command/dd.c (renamed from src/commands/dd.c)5
-rw-r--r--command/echo.c (renamed from src/commands/echo.c)5
-rw-r--r--command/ed.c (renamed from src/commands/ed.c)7
-rw-r--r--command/grep.c (renamed from src/commands/grep.c)6
-rw-r--r--command/groups.c (renamed from src/commands/groups.c)31
-rw-r--r--command/head.c (renamed from src/commands/head.c)5
-rw-r--r--command/id.c (renamed from src/commands/id.c)35
-rw-r--r--command/ls.c (renamed from src/commands/ls.c)13
-rw-r--r--command/mkdir.c (renamed from src/commands/mkdir.c)7
-rw-r--r--command/mv.c (renamed from src/commands/mv.c)7
-rw-r--r--command/printf.c (renamed from src/commands/printf.c)5
-rw-r--r--command/rm.c (renamed from src/commands/rm.c)6
-rw-r--r--command/tac.c (renamed from src/commands/tac.c)4
-rw-r--r--command/tail.c (renamed from src/commands/tail.c)7
-rw-r--r--command/tee.c (renamed from src/commands/tee.c)4
-rw-r--r--command/wc.c (renamed from src/commands/wc.c)4
-rw-r--r--command/whoami.c (renamed from src/commands/whoami.c)5
-rw-r--r--command/xargs.c (renamed from src/commands/xargs.c)7
-rw-r--r--command/yes.c (renamed from src/commands/yes.c)3
21 files changed, 146 insertions, 31 deletions
diff --git a/src/commands/cat.c b/command/cat.c
index 0495fe3..c392a46 100644
--- a/src/commands/cat.c
+++ b/command/cat.c
@@ -1,6 +1,8 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <ctype.h>
+#include <stdlib.h>
static struct {
bool number_lines;
diff --git a/src/commands/cp.c b/command/cp.c
index df88155..ca80f69 100644
--- a/src/commands/cp.c
+++ b/command/cp.c
@@ -1,7 +1,12 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
#include <dirent.h>
+#include <errno.h>
#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
diff --git a/src/commands/dd.c b/command/dd.c
index 1387317..67f8be3 100644
--- a/src/commands/dd.c
+++ b/command/dd.c
@@ -1,4 +1,7 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
static void help(void) {
printf("Usage: dd [if=FILE] [of=FILE] [bs=N] [count=N]\n\n");
diff --git a/src/commands/echo.c b/command/echo.c
index fe70a6a..a0ab78d 100644
--- a/src/commands/echo.c
+++ b/command/echo.c
@@ -1,4 +1,7 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
static struct {
bool escape_codes;
diff --git a/src/commands/ed.c b/command/ed.c
index d7e8881..472473f 100644
--- a/src/commands/ed.c
+++ b/command/ed.c
@@ -1,5 +1,8 @@
-#include "../command.h"
-#include "../util//regex.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
+#include <string.h>
#define INPUT_LEN 1024
diff --git a/src/commands/grep.c b/command/grep.c
index 4062734..0dad094 100644
--- a/src/commands/grep.c
+++ b/command/grep.c
@@ -1,5 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
static struct {
bool filename_prefix;
diff --git a/src/commands/groups.c b/command/groups.c
index bd2e5f9..cb950be 100644
--- a/src/commands/groups.c
+++ b/command/groups.c
@@ -1,20 +1,41 @@
-#include "../command.h"
+#include "args.h"
+#include "command.h"
+#include "lslib.h"
+#include <errno.h>
#include <grp.h>
#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
-COMMAND_EMPTY(groups) {
+static void help (void) {
+ printf("Usage: groups [USER]\n\n");
+ printf("Print the groups USER is in\n");
+}
+
+COMMAND(groups) {
uid_t uid;
int ngroups, i;
gid_t* groups;
struct passwd* pw;
- uid = getuid();
+ parse_help(argc, argv, help);
- pw = getpwuid(uid);
+ if (argc < 1) {
+ uid = getuid();
+ pw = getpwuid(uid);
+ } else {
+ pw = getpwnam(argv[0]);
+ }
+
if(pw == NULL){
- error("failed to fetch groups: %s", strerror(errno));
+ if (errno == 0) {
+ error("user not found");
+ } else {
+ error("failed to fetch groups: %s", strerror(errno));
+ }
}
ngroups = 0;
diff --git a/src/commands/head.c b/command/head.c
index da8b9b3..c28a82c 100644
--- a/src/commands/head.c
+++ b/command/head.c
@@ -1,4 +1,7 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
static struct {
int count;
diff --git a/src/commands/id.c b/command/id.c
index 3bef4f6..3a63989 100644
--- a/src/commands/id.c
+++ b/command/id.c
@@ -1,9 +1,20 @@
-#include "../command.h"
+#include "args.h"
+#include "command.h"
+#include "lslib.h"
+#include <errno.h>
#include <grp.h>
#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
-COMMAND_EMPTY(user_id) {
+static void help (void) {
+ printf("Usage: id [USER]\n\n");
+ printf("Print information about the USER\n");
+}
+
+COMMAND(user_id) {
uid_t uid;
gid_t gid, *groups;
@@ -11,13 +22,24 @@ COMMAND_EMPTY(user_id) {
struct passwd* pw;
struct group* ugr;
- uid = getuid();
- gid = getgid();
+ parse_help(argc, argv, help);
- pw = getpwuid(uid);
+ if (argc < 1) {
+ uid = getuid();
+ pw = getpwuid(uid);
+ } else {
+ pw = getpwnam(argv[0]);
+ }
+
if(pw == NULL){
- error("failed to fetch groups: %s", strerror(errno));
+ if (errno == 0) {
+ error("user not found");
+ } else {
+ error("failed to fetch groups: %s", strerror(errno));
+ }
}
+
+ uid = pw->pw_uid;
ngroups = 0;
getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups);
@@ -25,6 +47,7 @@ COMMAND_EMPTY(user_id) {
groups = malloc(sizeof(gid_t) * ngroups);
getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups);
+ gid = pw->pw_gid;
ugr = getgrgid(gid);
printf("uid=%d(%s) gid=%d(%s) ",
uid, ugr->gr_name, gid, ugr->gr_name);
diff --git a/src/commands/ls.c b/command/ls.c
index e8d58d0..8ed796f 100644
--- a/src/commands/ls.c
+++ b/command/ls.c
@@ -1,11 +1,16 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <grp.h>
#include <pwd.h>
#include <dirent.h>
#include <ftw.h>
#include <limits.h>
+#include <stdlib.h>
#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
#define FILE_COLOR ANSCII BLACK COLOR
#define DIR_COLOR ANSCII BOLD NEXT NORMAL BLUE COLOR
@@ -17,6 +22,12 @@
#define BLK_COLOR ANSCII BOLD NEXT NORMAL YELLOW COLOR
#define SOCK_COLOR ANSCII BOLD NEXT NORMAL MAGENTA COLOR
+enum When {
+ YES,
+ NO,
+ AUTO
+};
+
static struct {
bool hidden;
bool hide_dot;
diff --git a/src/commands/mkdir.c b/command/mkdir.c
index 02fccca..0d3950d 100644
--- a/src/commands/mkdir.c
+++ b/command/mkdir.c
@@ -1,4 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
static struct {
bool make_parent;
diff --git a/src/commands/mv.c b/command/mv.c
index d203607..adce2b7 100644
--- a/src/commands/mv.c
+++ b/command/mv.c
@@ -1,4 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
static struct {
bool prompt;
diff --git a/src/commands/printf.c b/command/printf.c
index 519b8a2..99139d0 100644
--- a/src/commands/printf.c
+++ b/command/printf.c
@@ -1,4 +1,7 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
static long cast_long(const char* arg) {
char* end;
diff --git a/src/commands/rm.c b/command/rm.c
index 8ce3e1c..81a956a 100644
--- a/src/commands/rm.c
+++ b/command/rm.c
@@ -1,5 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
#include <string.h>
static struct {
diff --git a/src/commands/tac.c b/command/tac.c
index d188de9..9e9e48e 100644
--- a/src/commands/tac.c
+++ b/command/tac.c
@@ -1,8 +1,10 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
+#include <time.h>
static void help(void) {
printf("Usage: tac [FILE]...\n\n");
diff --git a/src/commands/tail.c b/command/tail.c
index 07b3d2b..8137eca 100644
--- a/src/commands/tail.c
+++ b/command/tail.c
@@ -1,4 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
static struct {
bool lines;
diff --git a/src/commands/tee.c b/command/tee.c
index b9b31be..0462517 100644
--- a/src/commands/tee.c
+++ b/command/tee.c
@@ -1,6 +1,8 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <signal.h>
+#include <stdlib.h>
static struct {
bool append;
diff --git a/src/commands/wc.c b/command/wc.c
index d8905a5..3150045 100644
--- a/src/commands/wc.c
+++ b/command/wc.c
@@ -1,6 +1,8 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <ctype.h>
+#include <stdlib.h>
static struct {
bool newlines;
diff --git a/src/commands/whoami.c b/command/whoami.c
index 7fd7c85..5823b8f 100644
--- a/src/commands/whoami.c
+++ b/command/whoami.c
@@ -1,6 +1,9 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
#include <pwd.h>
+#include <stdlib.h>
+#include <unistd.h>
static void help(void) {
printf("Usage: whoami\n\n");
diff --git a/src/commands/xargs.c b/command/xargs.c
index 3008c3c..2a41460 100644
--- a/src/commands/xargs.c
+++ b/command/xargs.c
@@ -1,6 +1,11 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
+
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
static struct {
bool null_seperated;
diff --git a/src/commands/yes.c b/command/yes.c
index 6a44789..f979a9f 100644
--- a/src/commands/yes.c
+++ b/command/yes.c
@@ -1,4 +1,5 @@
-#include "../command.h"
+#include "command.h"
+#include "lslib.h"
static void help(void) {
printf("Usage: yes [STRING]\n\n");