summaryrefslogtreecommitdiff
path: root/comsat/action.c
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-11-13 14:08:35 +0000
committerAlain Magloire <alainm@gnu.org>2001-11-13 14:08:35 +0000
commit8ccd48fd24ee193c02dd13d65f4bd4981293ddb1 (patch)
tree990bf4e714b8840c9bc85b983f530222fd8fdb64 /comsat/action.c
parent9bcb4c72fbd5d9da96da87feaf705d4ed6f8f33f (diff)
downloadmailutils-8ccd48fd24ee193c02dd13d65f4bd4981293ddb1.tar.gz
mailutils-8ccd48fd24ee193c02dd13d65f4bd4981293ddb1.tar.bz2
Try to use const whenever appropriate to make it clear
that a string should not be modified. Nuke some trailing spaces, thanks to emacs. Reduce the scope of functions with static. GNU ident style for switch() promote a empty line after the break; * comsat/action.c (expand_escape): size and lncount could have been use uninitialized. (expand_escape): const char *cr. (expand_line): cr == "\n\r" make it const. variable i and size unneeded. variable c initialize to zero. (expand_line): obstack_1grow() pass *p instead of c. (defaul_action): const char*. (run_user_action): fprintf () missing argument. (open_rc): const char *filename. * comsat/comsat.c (username): const char *username. (mailbox_path): const prototype. (change_user): const prototype. (notify_user): const prototype. body and header unneeded variables. (find_user): const prototype. * comsat/comsat.h: Prototype updates.
Diffstat (limited to 'comsat/action.c')
-rw-r--r--comsat/action.c73
1 files changed, 39 insertions, 34 deletions
diff --git a/comsat/action.c b/comsat/action.c
index bb5bcd34c..fa674d8cd 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -27,7 +27,7 @@
beep -- Produce audible signal
echo STRING -- Output STRING to the user's tty
exec PROG ARGS... -- Execute given program (absolute pathname
- required)
+ required)
Following metacharacters are accepted in strings:
@@ -38,13 +38,13 @@
number of characters and line in the expansion.
When omitted, they default to 400, 5. */
-int
+static int
act_getline (FILE *fp, char **sptr, size_t *size)
{
char buf[256];
int cont = 1;
size_t used = 0;
-
+
while (cont && fgets (buf, sizeof buf, fp))
{
int len = strlen (buf);
@@ -71,22 +71,22 @@ act_getline (FILE *fp, char **sptr, size_t *size)
}
memcpy (*sptr + used, buf, len);
used += len;
- }
+ }
if (*sptr)
(*sptr)[used] = 0;
-
+
return used;
}
/* Convert second character of a backslash sequence to its ASCII
value: */
-int
+static int
backslash(int c)
{
static char transtab[] = "a\ab\bf\fn\nr\rt\t";
char *p;
-
+
for (p = transtab; *p; p += 2)
{
if (*p == c)
@@ -95,8 +95,8 @@ backslash(int c)
return c;
}
-int
-expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
+static int
+expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk)
{
char *p = *pp;
char *start, *sval, *namep;
@@ -105,8 +105,8 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
body_t body;
stream_t stream;
int rc = 1;
- size_t size, lncount;
-
+ size_t size = 0, lncount = 0;
+
switch (*++p) /* skip past $ */
{
case 'u':
@@ -115,12 +115,14 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
*pp = p;
rc = 0;
break;
+
case 'h':
len = strlen (hostname);
obstack_grow (stk, hostname, len);
*pp = p;
rc = 0;
break;
+
case 'H':
/* Header field */
if (*++p != '{')
@@ -145,6 +147,7 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
*pp = p;
rc = 0;
break;
+
case 'B':
/* Message body */
if (*++p == '(')
@@ -164,7 +167,7 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
{
size_t nread;
char *buf = malloc (size+1);
-
+
if (!buf)
break;
if (stream_read (stream, buf, size, 0, &nread) == 0)
@@ -193,14 +196,13 @@ expand_escape (char **pp, message_t msg, char *cr, struct obstack *stk)
return rc;
}
-char *
-expand_line (char *str, char *cr, message_t msg)
+static char *
+expand_line (const char *str, const char *cr, message_t msg)
{
- char *p;
- int i, c, len;
- size_t size;
+ const char *p;
+ int c = 0, len;
struct obstack stk;
-
+
if (!*str)
return NULL;
obstack_init (&stk);
@@ -212,25 +214,30 @@ expand_line (char *str, char *cr, message_t msg)
len = strlen (cr);
obstack_grow (&stk, cr, len);
break;
+
case '\\':
p++;
switch (*p)
{
case 0:
- obstack_1grow (&stk, c);
+ obstack_1grow (&stk, *p);
break;
+
case 'n':
len = strlen (cr);
obstack_grow (&stk, cr, len);
break;
+
default:
c = backslash (*p);
obstack_1grow (&stk, c);
}
break;
+
case '$':
if (expand_escape (&p, msg, cr, &stk) == 0)
break;
+
/*FALLTHRU*/
default:
obstack_1grow (&stk, *p);
@@ -239,10 +246,10 @@ expand_line (char *str, char *cr, message_t msg)
obstack_1grow (&stk, 0);
str = strdup (obstack_finish (&stk));
obstack_free (&stk, NULL);
- return str;
+ return (char *)str;
}
-char *default_action =
+const char *default_action =
"Mail to \a$u@$h\a\n"
"---\n"
"From: $H{from}\n"
@@ -253,18 +260,18 @@ char *default_action =
/* Take care to clear eighth bit, so we won't upset some stupid terminals */
#define LB(c) ((c)&0x7f)
-
-void
+
+static void
action_beep (FILE *tty)
{
fprintf (tty, "\a\a");
}
-void
+static void
action_echo (FILE *tty, char *str)
{
char *p;
-
+
if (!str)
return;
for (p = str; *p; p++)
@@ -272,7 +279,7 @@ action_echo (FILE *tty, char *str)
fprintf (tty, "%s", str);
}
-void
+static void
action_exec (FILE *tty, int line, int argc, char **argv)
{
pid_t pid;
@@ -319,8 +326,8 @@ action_exec (FILE *tty, int line, int argc, char **argv)
}
}
-FILE *
-open_rc (char *filename, FILE *tty)
+static FILE *
+open_rc (const char *filename, FILE *tty)
{
struct stat stb;
struct passwd *pw = getpwnam (username);
@@ -348,7 +355,7 @@ open_rc (char *filename, FILE *tty)
}
void
-run_user_action (FILE *tty, char *cr, message_t msg)
+run_user_action (FILE *tty, const char *cr, message_t msg)
{
FILE *fp;
int nact = 0;
@@ -359,7 +366,7 @@ run_user_action (FILE *tty, char *cr, message_t msg)
if (fp)
{
int line = 0;
-
+
while (act_getline (fp, &stmt, &size))
{
char *str;
@@ -396,7 +403,7 @@ run_user_action (FILE *tty, char *cr, message_t msg)
}
else
{
- fprintf (tty, ".biffrc:%d: unknown keyword\r\n");
+ fprintf (tty, ".biffrc:%d: unknown keyword\r\n", line);
syslog (LOG_ERR, "%s:.biffrc:%d: unknown keyword %s",
username, line, argv[0]);
break;
@@ -404,12 +411,10 @@ run_user_action (FILE *tty, char *cr, message_t msg)
}
fclose (fp);
}
-
+
if (nact == 0)
{
char *str = expand_line (default_action, cr, msg);
action_echo (tty, str);
}
}
-
-

Return to:

Send suggestions and report system problems to the System administrator.