summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/rcs/ci.c25
-rw-r--r--usr.bin/rcs/co.c20
-rw-r--r--usr.bin/rcs/ident.c8
-rw-r--r--usr.bin/rcs/rcsclean.c12
-rw-r--r--usr.bin/rcs/rcsdiff.c15
-rw-r--r--usr.bin/rcs/rcsprog.c82
-rw-r--r--usr.bin/rcs/rcsprog.h6
-rw-r--r--usr.bin/rcs/rlog.c8
8 files changed, 121 insertions, 55 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c
index f1d3c56a2b9..c2783d54829 100644
--- a/usr.bin/rcs/ci.c
+++ b/usr.bin/rcs/ci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ci.c,v 1.23 2005/10/12 22:57:26 niallo Exp $ */
+/* $OpenBSD: ci.c,v 1.24 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Niall O'Higgins <niallo@openbsd.org>
* All rights reserved.
@@ -89,10 +89,10 @@ checkin_main(int argc, char **argv)
exit(1);
}
- while ((ch = getopt(argc, argv, "j:l::M:N:qu::d:r::m:k:V")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "j:l::M:N:qu::d:r::m:k:V")) != -1) {
switch (ch) {
case 'd':
- if ((date = cvs_date_parse(optarg)) <= 0) {
+ if ((date = cvs_date_parse(rcs_optarg)) <= 0) {
cvs_log(LP_ERR, "invalide date");
exit(1);
}
@@ -101,7 +101,7 @@ checkin_main(int argc, char **argv)
(usage)();
exit(0);
case 'm':
- rcs_msg = optarg;
+ rcs_msg = rcs_optarg;
interactive = 0;
break;
case 'q':
@@ -111,8 +111,8 @@ checkin_main(int argc, char **argv)
printf("%s\n", rcs_version);
exit(0);
case 'l':
- if (optarg != NULL) {
- if ((newrev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((newrev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
@@ -120,8 +120,8 @@ checkin_main(int argc, char **argv)
lkmode = LOCK_LOCK;
break;
case 'u':
- if (optarg != NULL) {
- if ((newrev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((newrev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
@@ -130,8 +130,8 @@ checkin_main(int argc, char **argv)
break;
case 'r':
rflag = 1;
- if (optarg != NULL) {
- if ((newrev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((newrev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
@@ -143,8 +143,9 @@ checkin_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
+
if (argc == 0) {
cvs_log(LP_ERR, "no input file");
(usage)();
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c
index 50e910f8ec6..a2cb90d9024 100644
--- a/usr.bin/rcs/co.c
+++ b/usr.bin/rcs/co.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: co.c,v 1.12 2005/10/12 17:43:18 xsa Exp $ */
+/* $OpenBSD: co.c,v 1.13 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -61,14 +61,14 @@ checkout_main(int argc, char **argv)
exit (1);
}
- while ((ch = getopt(argc, argv, "l::qr::u::V")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "l::qr::u::V")) != -1) {
switch (ch) {
case 'l':
if (rev != RCS_HEAD_REV)
cvs_log(LP_WARN,
"redefinition of revision number");
- if (optarg != NULL) {
- if ((rev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit (1);
}
@@ -82,8 +82,8 @@ checkout_main(int argc, char **argv)
if (rev != RCS_HEAD_REV)
cvs_log(LP_WARN,
"redefinition of revision number");
- if (optarg != NULL) {
- if ((rev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit (1);
}
@@ -93,8 +93,8 @@ checkout_main(int argc, char **argv)
if (rev != RCS_HEAD_REV)
cvs_log(LP_WARN,
"redefinition of revision number");
- if (optarg != NULL) {
- if ((rev = rcsnum_parse(optarg)) == NULL) {
+ if (rcs_optarg != NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit (1);
}
@@ -110,8 +110,8 @@ checkout_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0) {
cvs_log(LP_ERR, "no input file");
diff --git a/usr.bin/rcs/ident.c b/usr.bin/rcs/ident.c
index 1e79d329e4c..44d00437363 100644
--- a/usr.bin/rcs/ident.c
+++ b/usr.bin/rcs/ident.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ident.c,v 1.4 2005/10/12 17:13:30 deraadt Exp $ */
+/* $OpenBSD: ident.c,v 1.5 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
@@ -50,7 +50,7 @@ ident_main(int argc, char **argv)
int i, ch;
FILE *fp;
- while ((ch = getopt(argc, argv, "qV")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "qV")) != -1) {
switch(ch) {
case 'q':
verbose = 0;
@@ -64,8 +64,8 @@ ident_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0)
ident_file(NULL, stdin);
diff --git a/usr.bin/rcs/rcsclean.c b/usr.bin/rcs/rcsclean.c
index 20af41e88ae..6642cd2855f 100644
--- a/usr.bin/rcs/rcsclean.c
+++ b/usr.bin/rcs/rcsclean.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsclean.c,v 1.6 2005/10/12 17:43:18 xsa Exp $ */
+/* $OpenBSD: rcsclean.c,v 1.7 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -52,10 +52,10 @@ rcsclean_main(int argc, char **argv)
rev = RCS_HEAD_REV;
- while ((ch = getopt(argc, argv, "k:nqr:V")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "k:nqr:V")) != -1) {
switch (ch) {
case 'k':
- kflag = rcs_kflag_get(optarg);
+ kflag = rcs_kflag_get(rcs_optarg);
if (RCS_KWEXP_INVAL(kflag)) {
cvs_log(LP_ERR,
"invalid RCS keyword expansion mode");
@@ -70,7 +70,7 @@ rcsclean_main(int argc, char **argv)
verbose = 0;
break;
case 'r':
- if ((rev = rcsnum_parse(optarg)) == NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
@@ -83,8 +83,8 @@ rcsclean_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0) {
if ((dirp = opendir(".")) == NULL) {
diff --git a/usr.bin/rcs/rcsdiff.c b/usr.bin/rcs/rcsdiff.c
index a2c3aed57ac..9ca3b650ad3 100644
--- a/usr.bin/rcs/rcsdiff.c
+++ b/usr.bin/rcs/rcsdiff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsdiff.c,v 1.10 2005/10/12 17:43:18 xsa Exp $ */
+/* $OpenBSD: rcsdiff.c,v 1.11 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -52,7 +52,7 @@ rcsdiff_main(int argc, char **argv)
rev2 = NULL;
status = 0;
- while ((ch = getopt(argc, argv, "cnqr:uV")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "cnqr:uV")) != -1) {
switch (ch) {
case 'c':
diff_format = D_CONTEXT;
@@ -71,24 +71,25 @@ rcsdiff_main(int argc, char **argv)
exit(0);
case 'r':
if (rev == RCS_HEAD_REV) {
- if ((rev = rcsnum_parse(optarg)) == NULL) {
+ if ((rev = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
} else {
- if ((rev2 = rcsnum_parse(optarg)) == NULL) {
+ if ((rev2 = rcsnum_parse(rcs_optarg)) == NULL) {
cvs_log(LP_ERR, "bad revision number");
exit(1);
}
}
break;
default:
- break;
+ (usage)();
+ exit (1);
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0) {
cvs_log(LP_ERR, "no input file");
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c
index 0bcacd92091..b259797a2d9 100644
--- a/usr.bin/rcs/rcsprog.c
+++ b/usr.bin/rcs/rcsprog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.c,v 1.27 2005/10/12 17:43:18 xsa Exp $ */
+/* $OpenBSD: rcsprog.c,v 1.28 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -45,6 +45,9 @@
const char rcs_version[] = "OpenCVS RCS version 3.6";
int verbose = 1;
+int rcs_optind;
+char *rcs_optarg;
+
struct rcs_prog {
char *prog_name;
int (*prog_hdlr)(int, char **);
@@ -60,6 +63,62 @@ struct rcs_prog {
};
int
+rcs_getopt(int argc, char **argv, const char *optstr)
+{
+ char *a;
+ const char *c;
+ static int i = 1;
+ int opt, hasargument, ret;
+
+ hasargument = 0;
+ rcs_optarg = NULL;
+
+ if (i >= argc)
+ return (-1);
+
+ a = argv[i++];
+ if (*a++ != '-')
+ return (-1);
+
+ ret = 0;
+ opt = *a;
+ for (c = optstr; *c != '\0'; c++) {
+ if (*c == opt) {
+ a++;
+ ret = opt;
+
+ if (*(c + 1) == ':') {
+ if (*(c + 2) == ':') {
+ if (*a != '\0')
+ hasargument = 1;
+ } else {
+ if (*a != '\0') {
+ hasargument = 1;
+ } else {
+ ret = 1;
+ break;
+ }
+ }
+ }
+
+ if (hasargument == 1)
+ rcs_optarg = a;
+
+ if (ret == opt)
+ rcs_optind++;
+ break;
+ }
+ }
+
+ if (ret == 0)
+ cvs_log(LP_ERR, "unknown option -%c", opt);
+ else if (ret == 1)
+ cvs_log(LP_ERR, "missing argument for option -%c", opt);
+
+ return (ret);
+}
+
+int
rcs_statfile(char *fname, char *out, size_t len)
{
int l;
@@ -108,6 +167,7 @@ main(int argc, char **argv)
int ret;
ret = -1;
+ rcs_optind = 1;
cvs_strtab_init();
cvs_log_init(LD_STD, 0);
@@ -154,19 +214,19 @@ rcs_main(int argc, char **argv)
flags = RCS_RDWR;
logstr = oldfile = alist = comment = elist = NULL;
- while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:Lm:MqUV")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "A:a:b::c:e::hik:Lm:MqUV")) != -1) {
switch (ch) {
case 'A':
- oldfile = optarg;
+ oldfile = rcs_optarg;
break;
case 'a':
- alist = optarg;
+ alist = rcs_optarg;
break;
case 'c':
- comment = optarg;
+ comment = rcs_optarg;
break;
case 'e':
- elist = optarg;
+ elist = rcs_optarg;
break;
case 'h':
(usage)();
@@ -175,11 +235,11 @@ rcs_main(int argc, char **argv)
flags |= RCS_CREATE;
break;
case 'k':
- kflag = rcs_kflag_get(optarg);
+ kflag = rcs_kflag_get(rcs_optarg);
if (RCS_KWEXP_INVAL(kflag)) {
cvs_log(LP_ERR,
"invalid keyword substitution mode `%s'",
- optarg);
+ rcs_optarg);
exit(1);
}
break;
@@ -189,7 +249,7 @@ rcs_main(int argc, char **argv)
lkmode = RCS_LOCK_STRICT;
break;
case 'm':
- if ((logstr = strdup(optarg)) == NULL) {
+ if ((logstr = strdup(rcs_optarg)) == NULL) {
cvs_log(LP_ERRNO, "failed to copy logstring");
exit(1);
}
@@ -214,8 +274,8 @@ rcs_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0) {
cvs_log(LP_ERR, "no input file");
(usage)();
diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h
index 84fb8596091..8eacd0d9290 100644
--- a/usr.bin/rcs/rcsprog.h
+++ b/usr.bin/rcs/rcsprog.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsprog.h,v 1.9 2005/10/11 15:50:25 niallo Exp $ */
+/* $OpenBSD: rcsprog.h,v 1.10 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -31,6 +31,9 @@ extern char *__progname;
extern const char rcs_version[];
extern int verbose;
+extern int rcs_optind;
+extern char *rcs_optarg;
+
/* date.y */
time_t cvs_date_parse(const char *);
@@ -43,6 +46,7 @@ void rlog_usage(void);
void ident_usage(void);
void (*usage)(void);
+int rcs_getopt(int, char **, const char *);
int rcs_statfile(char *, char *, size_t);
int checkout_main(int, char **);
int checkin_main(int, char **);
diff --git a/usr.bin/rcs/rlog.c b/usr.bin/rcs/rlog.c
index 767ec0871ce..8e312db9c15 100644
--- a/usr.bin/rcs/rlog.c
+++ b/usr.bin/rcs/rlog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rlog.c,v 1.4 2005/10/12 17:13:30 deraadt Exp $ */
+/* $OpenBSD: rlog.c,v 1.5 2005/10/13 12:35:30 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -57,7 +57,7 @@ rlog_main(int argc, char **argv)
RCSFILE *file;
hflag = Rflag = 0;
- while ((ch = getopt(argc, argv, "hNqRtV")) != -1) {
+ while ((ch = rcs_getopt(argc, argv, "hNqRtV")) != -1) {
switch (ch) {
case 'h':
hflag = 1;
@@ -82,8 +82,8 @@ rlog_main(int argc, char **argv)
}
}
- argc -= optind;
- argv += optind;
+ argc -= rcs_optind;
+ argv += rcs_optind;
if (argc == 0) {
cvs_log(LP_ERR, "no input file");