From 96d5b7878f70b93651106b19768edfba7ba3dafd Mon Sep 17 00:00:00 2001 From: louie Date: Tue, 16 Jun 2020 21:23:02 -0700 Subject: Printing group column --- entry.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 entry.c (limited to 'entry.c') diff --git a/entry.c b/entry.c new file mode 100644 index 0000000..d5f1425 --- /dev/null +++ b/entry.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include "entry.h" +#include "group.h" +#define BUF_LEN 1024 + +typedef struct entry{ + char name[BUF_LEN]; + char path[BUF_LEN]; + struct entry *next; +} ENTRY; + +ENTRY *create_entry(char *new_path, char *new_group); +ENTRY *entry_add_last(ENTRY *tail, ENTRY *add); +ENTRY **get_entries(ENTRY *head, int count); +char *get_ename(ENTRY *e); +char *get_epath(ENTRY *e); + +ENTRY *create_entry(char *new_path, char *new_group){ + ENTRY *new; + char full_path[BUF_LEN] = ""; + + if(new_group != NULL) strcat(full_path, new_group); + strcat(full_path, new_path); + + //check if file exists + if(access(full_path, F_OK) == -1){ + printf("Error: Invalid File Name \"%s\"\n", full_path); + return NULL; + } + + new = malloc(sizeof(ENTRY)); + + strcpy(new->name, new_path); + strcpy(new->path, full_path); + new->next = NULL; + + return new; +} + +ENTRY *entry_add_last(ENTRY *tail, ENTRY *add){ + assert(add != NULL); + + if(tail == NULL) tail = add; + else{ + tail->next = add; + tail = add; + } + + return tail; +} + +ENTRY **get_entries(ENTRY *head, int count){ + ENTRY **arr = malloc(sizeof(ENTRY *) * count); + ENTRY *trav = head; + int i; + + for(i = 0; i < count; i++){ + arr[i] = trav; + trav = trav->next; + } + + return arr; +} + +char *get_ename(ENTRY *e){ + assert(e != NULL); + return e->name; +} +char *get_epath(ENTRY *e){ + assert(e != NULL); + return e->name; + return e->path; +} + +void entry_debug(ENTRY *trav){ + + while(trav != NULL){ + printf("%s, \n", trav->name); + trav = trav->next; + } + + return; +} -- cgit