void print_version(char *);
void push(void);
char *pwd(void);
-char *r1bindex(char *, int);
+char *mhbasename(char *);
void readconfig(struct node **, FILE *, char *, int);
int refile(char **, char *);
void ruserpass(char *, char **, char **);
makedir.c mts.c norm_charmap.c \
path.c peekc.c pidwait.c pidstatus.c \
print_help.c print_sw.c print_version.c push.c \
- putenv.c refile.c r1bindex.c \
+ putenv.c refile.c mhbasename.c \
readconfig.c ruserpass.c seq_add.c seq_bits.c \
seq_del.c seq_getnum.c seq_list.c seq_nameok.c \
seq_print.c seq_read.c seq_save.c seq_setcur.c \
break;
case 0:
- vec[0] = r1bindex(hook, '/');
+ vec[0] = mhbasename(hook);
vec[1] = message_file_name_1;
vec[2] = message_file_name_2;
vec[3] = (char *)0;
vec[vecp] = NULL;
fflush(stdout);
- vec[0] = r1bindex(rmmproc, '/');
+ vec[0] = mhbasename(rmmproc);
switch (pid = vfork()) {
case -1:
char *cp;
static char buffer[BUFSIZ];
- if ((cp = r1bindex(file, '/')) == file)
+ if ((cp = mhbasename(file)) == file)
snprintf(buffer, sizeof(buffer), "%s%s", backup_prefix, cp);
else
snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file),
return m_mktemp(buffer, fd_ret, fp_ret);
}
- if ((cp = r1bindex((char *)dir_in, '/')) == dir_in) {
+ if ((cp = mhbasename((char *)dir_in)) == dir_in) {
/* No directory component */
return m_mktemp(pfx_in, fd_ret, fp_ret);
}
--- /dev/null
+/*
+** mhbasename.c -- Given a path name, return a pointer to the character
+** -- after the last slash. If none present, return the the
+** -- beginning of the path.
+**
+** This code is Copyright (c) 2002, by the authors of nmh. See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
+
+#include <h/mh.h>
+
+
+/*
+** Note: In contrast to POSIX basename(), we don't handle trailing
+** slashes special. If path has a trailing slash, we return a pointer
+** to a null byte (i.e. to an empty string). Also different: We don't
+** modify the original string neither do we return a pointer to static
+** memory.
+*/
+char *
+mhbasename(char *path)
+{
+ char *cp;
+
+ if (!path) {
+ return NULL;
+ }
+ cp = strrchr(path, '/');
+ return (!cp) ? path : ++cp;
+
+}
+++ /dev/null
-/*
-** r1bindex.c -- Given a string and a character, return a pointer
-** -- to the right of the rightmost occurrence of the
-** -- character. If the character doesn't occur, the
-** -- pointer will be at the beginning of the string.
-**
-** This code is Copyright (c) 2002, by the authors of nmh. See the
-** COPYRIGHT file in the root directory of the nmh distribution for
-** complete copyright information.
-*/
-
-#include <h/mh.h>
-
-
-char *
-r1bindex(char *str, int chr)
-{
- char *cp;
-
- /* find null at the end of the string */
- for (cp = str; *cp; cp++)
- continue;
-
- /* backup to the rightmost character */
- --cp;
-
- /* now search for the rightmost occurrence of the character */
- while (cp >= str && *cp != chr)
- --cp;
-
- /* now move one to the right */
- return (++cp);
-}
char *vec[MAXARGS];
vecp = 0;
- vec[vecp++] = r1bindex(fileproc, '/');
+ vec[vecp++] = mhbasename(fileproc);
vec[vecp++] = "-nolink"; /* override bad .mh_profile defaults */
vec[vecp++] = "-nopreserve";
vec[vecp++] = "-file";
** then really invoked the mhlproc instead
** (which is usually mhl anyway).
*/
- if (!strcmp(r1bindex(lproc, '/'), "mhl"))
+ if (!strcmp(mhbasename(lproc), "mhl"))
lproc = mhlproc;
switch (pid = vfork()) {
case 0:
/* child */
vecp = 0;
- vec[vecp++] = r1bindex(lproc, '/');
+ vec[vecp++] = mhbasename(lproc);
isdraft = 1;
if (arg) {
while (*arg) {
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
dup2(fd, 1);
close(fd);
}
- execlp(mailproc, r1bindex (mailproc, '/'),
+ execlp(mailproc, mhbasename(mailproc),
mail, "-subject", invo_name,
NULL);
adios(mailproc, "unable to exec ");
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
register char *cp, *dp;
static char buffer[BUFSIZ];
- if ((dp = strchr(cp = r1bindex(file, '/'), '.')) == NULL)
+ if ((dp = strchr(cp = mhbasename(file), '.')) == NULL)
dp = cp + strlen(cp);
if (cp == file)
snprintf(buffer, sizeof(buffer), ".%.*s%s",
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
if (pipe(pd) == NOTOK)
adios("pipe", "unable to create");
- vec[0] = r1bindex(mhlproc, '/');
+ vec[0] = mhbasename(mhlproc);
for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
sleep(5);
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
arguments = getarguments(invo_name, argc, argv, 0);
argp = arguments;
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
CI ci = &ct->c_ctinfo;
printf(toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ",
- atoi(r1bindex(empty(ct->c_file), '/')));
+ atoi(mhbasename(empty(ct->c_file))));
snprintf(buffer, sizeof(buffer), "%s/%s", empty(ci->ci_type),
empty(ci->ci_subtype));
printf(LSTFMT2b, empty(ct->c_partno), buffer);
char buf[BUFSIZ], *files[MAXARGS];
char **argp, **arguments;
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
close(pdo[1]);
}
vecp = 0;
- vec[vecp++] = r1bindex(faceproc, '/');
+ vec[vecp++] = mhbasename(faceproc);
vec[vecp++] = "-e";
if (sleepsw != NOTOK) {
vec[vecp++] = "-s";
dup2(pd[0], fileno(stdin));
close(pd[0]);
}
- execlp(name, r1bindex(name, '/'), NULL);
+ execlp(name, mhbasename(name), NULL);
fprintf(stderr, "unable to exec ");
perror(name);
_exit(-1);
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
/* If no arguments, just incorporate new mail */
if (argc == 1) {
- execlp(incproc, r1bindex(incproc, '/'), NULL);
+ execlp(incproc, mhbasename(incproc), NULL);
adios(incproc, "unable to exec");
}
fclose(out);
nvec = 0;
- vec[nvec++] = r1bindex(postproc, '/');
+ vec[nvec++] = mhbasename(postproc);
vec[nvec++] = tmpfil;
if (resent)
vec[nvec++] = "-dist";
char *cp, buf[BUFSIZ], **argp;
char **arguments, *comps[MAXARGS];
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
/*
** If there is a Content-Disposition header and
** it doesn't have a *filename=, extract it from
- ** the magic contents. The r1bindex call skips
+ ** the magic contents. The mhbasename call skips
** any leading directory components.
*/
if (ct->c_dispo)
- ct->c_dispo = incl_name_value(ct->c_dispo, "filename", r1bindex(extract_name_value("name", ci->ci_magic), '/'));
+ ct->c_dispo = incl_name_value(ct->c_dispo, "filename", mhbasename(extract_name_value("name", ci->ci_magic)));
} else
advise(NULL, "extraneous information in message %s's %s: field\n%*.*s(%s)", ct->c_file, TYPE_FIELD, i, i, "", cp);
}
char *vec[9];
vecp = 0;
- vec[vecp++] = r1bindex(ftp, '/');
+ vec[vecp++] = mhbasename(ftp);
vec[vecp++] = e->eb_site;
vec[vecp++] = user;
vec[vecp++] = pass;
return NOTOK;
vecp = 0;
- vec[vecp++] = r1bindex(mailproc, '/');
+ vec[vecp++] = mhbasename(mailproc);
vec[vecp++] = e->eb_server;
vec[vecp++] = "-subject";
vec[vecp++] = e->eb_subject ? e->eb_subject : "mail-server request";
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
char *vec[8];
vecp = 0;
- vec[vecp++] = r1bindex(mhlproc, '/');
+ vec[vecp++] = mhbasename(mhlproc);
vec[vecp++] = "-form";
vec[vecp++] = form;
vec[vecp++] = "-nobody";
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
case 'm':
/* insert message number */
- snprintf(bp, buflen, "%s", r1bindex(ct->c_file, '/'));
+ snprintf(bp, buflen, "%s", mhbasename(ct->c_file));
break;
case 'P':
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
if (!(invo_name = *argp++) || *invo_name == '-')
adios(NULL, "missing argument to %s",
argp[-2]);
- invo_name = r1bindex(invo_name, '/');
+ invo_name = mhbasename(invo_name);
continue;
}
}
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
if (distout(drft, tmpfil, backup) == NOTOK)
done(1);
- vec[0] = r1bindex(postproc, '/');
+ vec[0] = mhbasename(postproc);
vec[vecp++] = "-dist";
vec[vecp++] = drft;
vec[vecp] = NULL;
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
files[filep] = NULL; /* NULL terminate list */
fflush(stdout);
- vec[0] = r1bindex(rmmproc, '/');
+ vec[0] = mhbasename(rmmproc);
execvp(rmmproc, vec);
adios(rmmproc, "unable to exec");
}
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
if (access(filter, R_OK) == NOTOK)
adios(filter, "unable to read");
- mhl = r1bindex(mhlproc, '/');
+ mhl = mhbasename(mhlproc);
rewind(in);
lseek(fileno(in), (off_t) 0, SEEK_SET);
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
push();
status = 0;
- vec[0] = r1bindex(postproc, '/');
+ vec[0] = mhbasename(postproc);
closefds(3);
for (msgnum = 0; msgnum < msgp; msgnum++) {
snprintf(buf, sizeof(buf), "send failed on %s",
forwsw ? "enclosed draft" : file);
- execlp(mailproc, r1bindex(mailproc, '/'),
+ execlp(mailproc, mhbasename(mailproc),
getusername(), "-subject", buf, NULL);
fprintf(stderr, "unable to exec ");
perror(mailproc);
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
** then add "-show" option. Add "-file" if showing
** file.
*/
- if (strcmp(r1bindex(proc, '/'), "mhn") == 0) {
+ if (strcmp(mhbasename(proc), "mhn") == 0) {
if (file) {
vec[vecp] = vec[vecp - 1];
vec[vecp - 1] = "-file";
}
/* If the "proc" is "mhshow", add "-file" if showing file. */
- if (strcmp(r1bindex(proc, '/'), "mhshow") == 0 && file ) {
+ if (strcmp(mhbasename(proc), "mhshow") == 0 && file ) {
vec[vecp] = vec[vecp - 1];
vec[vecp - 1] = "-file";
vec[++vecp] = NULL;
** If "proc" is mhl, then run it internally
** rather than exec'ing it.
*/
- if (strcmp(r1bindex(proc, '/'), "mhl") == 0) {
+ if (strcmp(mhbasename(proc), "mhl") == 0) {
vec[0] = "mhl";
mhl(vecp, vec);
done(0);
** add the path to the message names. Currently, we are just
** checking for mhn here, since we've already taken care of mhl.
*/
- if (!strcmp(r1bindex(proc, '/'), "mhl")
+ if (!strcmp(mhbasename(proc), "mhl")
&& !file
&& chdir(maildir =
concat(m_maildir(""), "/", NULL)) != NOTOK) {
vec[msgnum] = concat(cp, vec[msgnum], NULL);
}
- vec[0] = r1bindex(proc, '/');
+ vec[0] = mhbasename(proc);
execvp(proc, vec);
adios(proc, "unable to exec");
return 0; /* dead code to satisfy the compiler */
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(*argv, '/');
+ invo_name = mhbasename(*argv);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
cpydgst(fd, fileno(out), tmpfil, bccfil);
close(fd);
} else {
- vec[0] = r1bindex(mhlproc, '/');
+ vec[0] = mhbasename(mhlproc);
for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
sleep(5);
case OK:
snprintf(fold, sizeof(fold), "%s%s",
*folder == '+' || *folder == '@' ? "" : "+", folder);
- execlp(fileproc, r1bindex(fileproc, '/'),
+ execlp(fileproc, mhbasename(fileproc),
"-link", "-file", file, fold, NULL);
_exit(-1);
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
adios("failed", "fstat of %s", tmpfil);
status = 0;
- vec[0] = r1bindex(postproc, '/');
+ vec[0] = mhbasename(postproc);
if (verbsw)
vec[vecp++] = "-verbose";
char buffer[BUFSIZ], *vec[MAXARGS];
vecp = 0;
- vec[vecp++] = r1bindex(whatnowproc, '/');
+ vec[vecp++] = mhbasename(whatnowproc);
vec[vecp] = NULL;
m_putenv("mhdraft", file);
char *l; /* set on -l to alist command */
int n; /* set on -n to alist command */
- invo_name = r1bindex(argv[0], '/');
+ invo_name = mhbasename(argv[0]);
/* read user profile/context */
context_read();
if (reedit) {
if (!*ed) { /* no explicit editor */
*ed = edsave; /* so use the previous one */
- if ((cp = r1bindex(*ed, '/')) == NULL)
+ if ((cp = mhbasename(*ed)) == NULL)
cp = *ed;
/* unless we've specified it via "editor-next" */
}
vecp = 0;
- vec[vecp++] = r1bindex(*ed, '/');
+ vec[vecp++] = mhbasename(*ed);
if (arg)
while (*arg)
vec[vecp++] = *arg++;
default:
if ((status = pidwait(pid, NOTOK))) {
#ifdef ATTVIBUG
- if ((cp = r1bindex(*ed, '/')) &&
+ if ((cp = mhbasename(*ed)) &&
strcmp(cp, "vi") == 0 &&
(status & 0x00ff) == 0)
status = 0;
** If the sendproc is the nmh command `send', then we call
** those routines directly rather than exec'ing the command.
*/
- if (strcmp(sp = r1bindex(sendproc, '/'), "send") == 0) {
+ if (strcmp(sp = mhbasename(sendproc), "send") == 0) {
cp = invo_name;
sendit(invo_name = sp, arg, file, pushsw);
invo_name = cp;
** if we are using mhn as buildmimeproc
*/
i = 0;
- if (strcmp(r1bindex(ed, '/'), "mhn") == 0)
+ if (strcmp(mhbasename(ed), "mhn") == 0)
args[i++] = "-build";
/* copy any other arguments */
if ((pushsw = pushed))
push();
- vec[0] = r1bindex(postproc, '/');
+ vec[0] = mhbasename(postproc);
closefds(3);
if (sendsbr(vec, vecp, file, &st, 1, attach, attachformat) == OK)