aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2011-04-21 09:29:55 -0400
committerJoseph Hunkeler <jhunk@stsci.edu>2011-04-21 09:29:55 -0400
commita6f2224a0da2955452f5640c00058aade6e7be0b (patch)
treee05f5fee174e55ddcf369afd39ba01e9c7d74352
parent7f5d9b7e41abdb98f699520d3a9464b360f7c8b9 (diff)
downloadduser-a6f2224a0da2955452f5640c00058aade6e7be0b.tar.gz
Utilizing static progname variable. Local variables removed from functions that used it. Added version().
-rw-r--r--duser.c17
-rw-r--r--duser.h9
2 files changed, 20 insertions, 6 deletions
diff --git a/duser.c b/duser.c
index 7c7d11f..8f5603f 100644
--- a/duser.c
+++ b/duser.c
@@ -33,6 +33,7 @@
#include <fcntl.h>
#include <libgen.h>
+#include "version.h"
#include "cfg.h"
#include "duser.h"
@@ -52,9 +53,15 @@ int CMD_FLAG_LOOK = 0;
int CMD_FLAG_NEW = 0;
int CMD_FLAG_NULL = 0;
-void usage(const char* progname)
+void version()
{
- printf("Domouser v0.1a - jhunk@stsci.edu\n");
+ printf("%s v%s.%s%s (%s %s)\n",
+ progname, VER_MAJOR, VER_MINOR, VER_OTH, __DATE__, __TIME__);
+}
+
+void usage()
+{
+ version();
printf("Usage: %s command [address [list]]\n", progname);
printf("Commands:\n");
printf(" help This usage statement\n");
@@ -72,6 +79,7 @@ void usage(const char* progname)
int main(int argc, char* argv[])
{
+ strncpy(progname, argv[0], strlen(argv[0]));
if((cfg_open(CFG_PATH)) == 0)
{
cfg_get_key(list_path, "path");
@@ -86,7 +94,6 @@ int main(int argc, char* argv[])
char filename[PATH_MAX];
record_t *rec;
- strncpy(progname, argv[0], strlen(argv[0]));
const char* needle = argv[2];
const char* single_list = argv[3];
@@ -95,7 +102,7 @@ int main(int argc, char* argv[])
if(argc < 3)
{
- usage(progname);
+ usage();
return 0;
}
@@ -288,7 +295,7 @@ int main(int argc, char* argv[])
}
if(CMD_FLAG_HELP)
{
- usage(progname);
+ usage();
}
if(CMD_FLAG_NULL)
{
diff --git a/duser.h b/duser.h
index 326a1d2..2101e4b 100644
--- a/duser.h
+++ b/duser.h
@@ -25,6 +25,12 @@
#define REGEX_MAX 255
#define CFG_PATH "/usr/local/etc/duser"
#define SELF __FUNCTION__
+#ifndef _NLINUX_
+# define FMTLIST "%20s\t%5d%23s\n"
+#else
+# define FMTLIST "%20s\t%5d%16s\n"
+#endif
+
typedef struct stats_t
{
int lines;
@@ -34,6 +40,7 @@ typedef struct stats_t
int deleted;
int modified;
} stats_t;
+
//Global statistics struct
stats_t processed;
@@ -48,7 +55,7 @@ typedef struct record_t
int pad3;
} record_t;
-void usage(const char* progname);
+void usage();
int strval(const char* str);
int strfind(const char* str1, const char* str2);
int logcleanup();