summaryrefslogtreecommitdiffstats
path: root/tcpd/argparse.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /tcpd/argparse.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'tcpd/argparse.c')
-rw-r--r--tcpd/argparse.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tcpd/argparse.c b/tcpd/argparse.c
new file mode 100644
index 0000000..dcb56b4
--- /dev/null
+++ b/tcpd/argparse.c
@@ -0,0 +1,51 @@
+#include "argparse.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+** Copyright 2000 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+
+
+int argparse(int argc, char **argv, struct args *s)
+{
+int argn=1;
+int i;
+
+ while (argn < argc)
+ {
+ const char *p;
+ int l=0;
+
+ if ( argv[argn][0] != '-') break;
+ if ( argv[argn][1] == 0)
+ {
+ ++argn;
+ break;
+ }
+ for (i=0; s[i].name; i++)
+ {
+ l=strlen(s[i].name);
+ if (strncmp(s[i].name, argv[argn]+1, l) == 0 &&
+ (argv[argn][l+1] == 0 ||
+ argv[argn][l+1] == '=')) break;
+ }
+ if (s[i].name == 0)
+ {
+ fprintf(stderr, "%s: Invalid option: %s\n",
+ argv[0], argv[argn]);
+ exit(1);
+ }
+ p=argv[argn]+1+l;
+ if (*p) ++p;
+ if (s[i].valuep)
+ *s[i].valuep=p;
+ else
+ (*s[i].funcp)(p);
+ ++argn;
+ }
+ return (argn);
+}