aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2011-04-03 23:59:38 -0400
committerJoseph Hunkeler <jhunk@stsci.edu>2011-04-03 23:59:38 -0400
commit5150ee8601c6ee78407a2a8cae96d6a07ece5f52 (patch)
treeaa8a60f8894b70a8205e3f1389a5221a7c53a51c
parente62a7775c4ba4d2d24fd5096f9e790c40e0a44f9 (diff)
downloadduser-5150ee8601c6ee78407a2a8cae96d6a07ece5f52.tar.gz
Fixed bug where (rec = NULL) caused user_del to flip out.
Adding code to add a user to a list
-rw-r--r--duser.c22
-rw-r--r--duser.h1
2 files changed, 21 insertions, 2 deletions
diff --git a/duser.c b/duser.c
index 7b1f64a..9a3b496 100644
--- a/duser.c
+++ b/duser.c
@@ -362,13 +362,14 @@ int user_list(const char* needle)
for(i = 0 ; list[i] != NULL ; i++)
{
char tmp[PATH_MAX];
- sprintf(tmp, "%s%s", list_path, list[i]);
+ snprintf(tmp, PATH_MAX, "%s%s", list_path, list[i]);
record_t *rp;
if((rp = find_in_file(tmp, needle)) != NULL)
{
printf("%20s\t%5d\n", basename(rp->file), rp->index);
processed.matches++;
}
+ rp = NULL;
}
free_file_list(list);
@@ -377,6 +378,18 @@ int user_list(const char* needle)
return 0;
}
+int user_add(const char* filename, const char* needle)
+{
+ if((access(filename, W_OK|F_OK)) == 0)
+ {
+ fprintf(stderr, "List '%s' already exists.\n", basename(filename));
+ return -1;
+ }
+
+ // add code to add a person to a file here
+ return 0;
+}
+
void usage(const char* progname)
{
printf("Domouser v0.1a - jhunk@stsci.edu\n");
@@ -518,13 +531,13 @@ int main(int argc, char* argv[])
printf("Record deleted\n");
COM(SELF, "Commmand: DELETE %s\n", CMD_FLAG_DEL_ALL ? "ALL" : "SINGLE");
COM(SELF, "'%s' deleted from '%s' at line %d\n", rec->name, basename(rec->file), rec->index);
- rec = NULL;
}
}
else
{
printf("Aborting...\n");
}
+ return 0;
}
if(CMD_FLAG_DEL_ALL)
@@ -552,6 +565,8 @@ int main(int argc, char* argv[])
printf("You must specify a list in which to add '%s' to\n", needle);
return -1;
}
+ user_add(filename, needle);
+ return 0;
}
if(CMD_FLAG_MOD)
{
@@ -566,6 +581,7 @@ int main(int argc, char* argv[])
printf("You must specify a list in which to modify '%s' in\n", needle);
return -1;
}
+ return 0;
}
if(CMD_FLAG_LIST)
{
@@ -575,6 +591,7 @@ int main(int argc, char* argv[])
return -1;
}
user_list(needle);
+ return 0;
}
if(CMD_FLAG_LOOK)
{
@@ -605,6 +622,7 @@ int main(int argc, char* argv[])
{
printf("Not found in '%s'\n", single_list);
}
+ return 0;
}
if(CMD_FLAG_HELP)
diff --git a/duser.h b/duser.h
index 600c96f..764ff76 100644
--- a/duser.h
+++ b/duser.h
@@ -44,5 +44,6 @@ int find_in_file_ex(record_t* rec);
int user_del(record_t* rec);
int user_cmd(const int argc, char* argv[]);
int user_choice(char c);
+int user_add(const char* filename, const char* needle);
#endif