summaryrefslogtreecommitdiff
path: root/gnu/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/binutils/gdb/29k-share/udi/udip2soc.c2
-rw-r--r--gnu/usr.bin/binutils/gdb/command.c4
-rw-r--r--gnu/usr.bin/cvs/diff/util.c185
-rw-r--r--gnu/usr.bin/diff/util.c2
-rw-r--r--gnu/usr.bin/gas/input-file.c8
-rw-r--r--gnu/usr.bin/ld/ldd/ldd.c4
6 files changed, 165 insertions, 40 deletions
diff --git a/gnu/usr.bin/binutils/gdb/29k-share/udi/udip2soc.c b/gnu/usr.bin/binutils/gdb/29k-share/udi/udip2soc.c
index aa25e00731d..e92dead8e3b 100644
--- a/gnu/usr.bin/binutils/gdb/29k-share/udi/udip2soc.c
+++ b/gnu/usr.bin/binutils/gdb/29k-share/udi/udip2soc.c
@@ -326,7 +326,7 @@ UDIConnect(Config, Session)
arg0,
soc_con[cnt].domain_string,
soc_con[cnt].tip_string,
- NULL);
+ (char *)NULL);
_exit(1);
}
diff --git a/gnu/usr.bin/binutils/gdb/command.c b/gnu/usr.bin/binutils/gdb/command.c
index 9afbf82e59a..c3c2b98a974 100644
--- a/gnu/usr.bin/binutils/gdb/command.c
+++ b/gnu/usr.bin/binutils/gdb/command.c
@@ -1369,9 +1369,9 @@ shell_escape (arg, from_tty)
if ((pid = fork()) == 0)
{
if (!arg)
- execl (user_shell, p, 0);
+ execl (user_shell, p, (char *)NULL);
else
- execl (user_shell, p, "-c", arg, 0);
+ execl (user_shell, p, "-c", arg, (char *)NULL);
fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
safe_strerror (errno));
diff --git a/gnu/usr.bin/cvs/diff/util.c b/gnu/usr.bin/cvs/diff/util.c
index 89cc2741786..28f163c9c4c 100644
--- a/gnu/usr.bin/cvs/diff/util.c
+++ b/gnu/usr.bin/cvs/diff/util.c
@@ -1,5 +1,5 @@
/* Support routines for GNU DIFF.
- Copyright (C) 1988, 1989, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1989, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This file is part of GNU DIFF.
@@ -13,12 +13,20 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with GNU DIFF; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+*/
#include "diff.h"
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#ifndef strerror
+extern char *strerror ();
+#endif
+
/* Queue up one-line messages to be printed at the end,
when -l is specified. Each message is recorded with a `struct msg'. */
@@ -48,9 +56,15 @@ perror_with_name (text)
char const *text;
{
int e = errno;
- fprintf (stderr, "%s: ", diff_program_name);
- errno = e;
- perror (text);
+
+ if (callbacks && callbacks->error)
+ (*callbacks->error) ("%s: %s", text, strerror (e));
+ else
+ {
+ fprintf (stderr, "%s: ", diff_program_name);
+ errno = e;
+ perror (text);
+ }
}
/* Use when a system call returns non-zero status and that is fatal. */
@@ -61,9 +75,14 @@ pfatal_with_name (text)
{
int e = errno;
print_message_queue ();
- fprintf (stderr, "%s: ", diff_program_name);
- errno = e;
- perror (text);
+ if (callbacks && callbacks->error)
+ (*callbacks->error) ("%s: %s", text, strerror (e));
+ else
+ {
+ fprintf (stderr, "%s: ", diff_program_name);
+ errno = e;
+ perror (text);
+ }
DIFF_ABORT (2);
}
@@ -74,9 +93,14 @@ void
diff_error (format, arg, arg1)
char const *format, *arg, *arg1;
{
- fprintf (stderr, "%s: ", diff_program_name);
- fprintf (stderr, format, arg, arg1);
- fprintf (stderr, "\n");
+ if (callbacks && callbacks->error)
+ (*callbacks->error) (format, arg, arg1);
+ else
+ {
+ fprintf (stderr, "%s: ", diff_program_name);
+ fprintf (stderr, format, arg, arg1);
+ fprintf (stderr, "\n");
+ }
}
/* Print an error message containing the string TEXT, then exit. */
@@ -119,8 +143,8 @@ message5 (format, arg1, arg2, arg3, arg4)
else
{
if (sdiff_help_sdiff)
- putc (' ', outfile);
- fprintf (outfile, format, arg1, arg2, arg3, arg4);
+ write_output (" ", 1);
+ printf_output (format, arg1, arg2, arg3, arg4);
}
}
@@ -132,7 +156,7 @@ print_message_queue ()
struct msg *m;
for (m = msg_chain; m; m = m->next)
- fprintf (outfile, m->format, m->arg1, m->arg2, m->arg3, m->arg4);
+ printf_output (m->format, m->arg1, m->arg2, m->arg3, m->arg4);
}
/* Call before outputting the results of comparing files NAME0 and NAME1
@@ -180,6 +204,9 @@ begin_output ()
This requirement is silly and does not match historical practice. */
sprintf (name, "diff%s %s %s", switch_string, current_name0, current_name1);
+ if (paginate_flag && callbacks && callbacks->write_output)
+ fatal ("can't paginate when using library callbacks");
+
if (paginate_flag)
{
/* Make OUTFILE a pipe to a subsidiary `pr'. */
@@ -208,7 +235,7 @@ begin_output ()
close (pipes[0]);
}
- execl (PR_PROGRAM, PR_PROGRAM, "-f", "-h", name, 0);
+ execl (PR_PROGRAM, PR_PROGRAM, "-f", "-h", name, (char *)NULL);
pfatal_with_name (PR_PROGRAM);
}
else
@@ -243,7 +270,7 @@ begin_output ()
/* If handling multiple files (because scanning a directory),
print which files the following output is about. */
if (current_depth > 0)
- fprintf (outfile, "%s\n", name);
+ printf_output ("%s\n", name);
}
free (name);
@@ -293,6 +320,102 @@ finish_output ()
output_in_progress = 0;
}
+
+/* Write something to the output file. */
+
+void
+write_output (text, len)
+ char const *text;
+ size_t len;
+{
+ if (callbacks && callbacks->write_output)
+ (*callbacks->write_output) (text, len);
+ else if (len == 1)
+ putc (*text, outfile);
+ else
+ fwrite (text, sizeof (char), len, outfile);
+}
+
+/* Printf something to the output file. */
+
+#if __STDC__
+#define VA_START(args, lastarg) va_start(args, lastarg)
+#else /* ! __STDC__ */
+#define VA_START(args, lastarg) va_start(args)
+#endif /* __STDC__ */
+
+void
+#if __STDC__
+printf_output (const char *format, ...)
+#else
+printf_output (format, va_alist)
+ char const *format;
+ va_dcl
+#endif
+{
+ va_list args;
+
+ VA_START (args, format);
+ if (callbacks && callbacks->write_output)
+ {
+ /* We implement our own limited printf-like functionality (%s, %d,
+ and %c only). Callers who want something fancier can use
+ sprintf. */
+ const char *p = format;
+ char *q;
+ char *str;
+ int num;
+ int ch;
+ char buf[100];
+
+ while ((q = strchr (p, '%')) != NULL)
+ {
+ static const char msg[] =
+ "\ninternal error: bad % in printf_output\n";
+ (*callbacks->write_output) (p, q - p);
+
+ switch (q[1])
+ {
+ case 's':
+ str = va_arg (args, char *);
+ (*callbacks->write_output) (str, strlen (str));
+ break;
+ case 'd':
+ num = va_arg (args, int);
+ sprintf (buf, "%d", num);
+ (*callbacks->write_output) (buf, strlen (buf));
+ break;
+ case 'c':
+ ch = va_arg (args, int);
+ buf[0] = ch;
+ (*callbacks->write_output) (buf, 1);
+ break;
+ default:
+ (*callbacks->write_output) (msg, sizeof (msg) - 1);
+ /* Don't just keep going, because q + 1 might point to the
+ terminating '\0'. */
+ goto out;
+ }
+ p = q + 2;
+ }
+ (*callbacks->write_output) (p, strlen (p));
+ }
+ else
+ vfprintf (outfile, format, args);
+ out:
+ va_end (args);
+}
+
+/* Flush the output file. */
+
+void
+flush_output ()
+{
+ if (callbacks && callbacks->flush_output)
+ (*callbacks->flush_output) ();
+ else
+ fflush (outfile);
+}
/* Compare two lines (typically one from each input file)
according to the command line options.
@@ -469,7 +592,6 @@ print_1_line (line_flag, line)
char const * const *line;
{
char const *text = line[0], *limit = line[1]; /* Help the compiler. */
- FILE *out = outfile; /* Help the compiler some more. */
char const *flag_format = 0;
/* If -T was specified, use a Tab between the line-flag and the text.
@@ -479,13 +601,13 @@ print_1_line (line_flag, line)
if (line_flag && *line_flag)
{
flag_format = tab_align_flag ? "%s\t" : "%s ";
- fprintf (out, flag_format, line_flag);
+ printf_output (flag_format, line_flag);
}
output_1_line (text, limit, flag_format, line_flag);
if ((!line_flag || line_flag[0]) && limit[-1] != '\n')
- fprintf (out, "\n\\ No newline at end of file\n");
+ printf_output ("\n\\ No newline at end of file\n");
}
/* Output a line from TEXT up to LIMIT. Without -t, output verbatim.
@@ -498,13 +620,15 @@ output_1_line (text, limit, flag_format, line_flag)
char const *text, *limit, *flag_format, *line_flag;
{
if (!tab_expand_flag)
- fwrite (text, sizeof (char), limit - text, outfile);
+ write_output (text, limit - text);
else
{
- register FILE *out = outfile;
register unsigned char c;
register char const *t = text;
register unsigned column = 0;
+ /* CC is used to avoid taking the address of the register
+ variable C. */
+ char cc;
while (t < limit)
switch ((c = *t++))
@@ -514,15 +638,15 @@ output_1_line (text, limit, flag_format, line_flag)
unsigned spaces = TAB_WIDTH - column % TAB_WIDTH;
column += spaces;
do
- putc (' ', out);
+ write_output (" ", 1);
while (--spaces);
}
break;
case '\r':
- putc (c, out);
+ write_output ("\r", 1);
if (flag_format && t < limit && *t != '\n')
- fprintf (out, flag_format, line_flag);
+ printf_output (flag_format, line_flag);
column = 0;
break;
@@ -530,13 +654,14 @@ output_1_line (text, limit, flag_format, line_flag)
if (column == 0)
continue;
column--;
- putc (c, out);
+ write_output ("\b", 1);
break;
default:
if (ISPRINT (c))
column++;
- putc (c, out);
+ cc = c;
+ write_output (&cc, 1);
break;
}
}
@@ -598,9 +723,9 @@ print_number_range (sepchar, file, a, b)
In this case, we should print the line number before the range,
which is B. */
if (trans_b > trans_a)
- fprintf (outfile, "%d%c%d", trans_a, sepchar, trans_b);
+ printf_output ("%d%c%d", trans_a, sepchar, trans_b);
else
- fprintf (outfile, "%d", trans_b);
+ printf_output ("%d", trans_b);
}
/* Look at a hunk of edit script and report the range of lines in each file
diff --git a/gnu/usr.bin/diff/util.c b/gnu/usr.bin/diff/util.c
index fd6cb1b5842..98de0d7d6b6 100644
--- a/gnu/usr.bin/diff/util.c
+++ b/gnu/usr.bin/diff/util.c
@@ -208,7 +208,7 @@ begin_output ()
close (pipes[0]);
}
- execl (PR_PROGRAM, PR_PROGRAM, "-F", "-h", name, 0);
+ execl (PR_PROGRAM, PR_PROGRAM, "-F", "-h", name, (char *)NULL);
pfatal_with_name (PR_PROGRAM);
}
else
diff --git a/gnu/usr.bin/gas/input-file.c b/gnu/usr.bin/gas/input-file.c
index ab5302d6ba8..f5401180e92 100644
--- a/gnu/usr.bin/gas/input-file.c
+++ b/gnu/usr.bin/gas/input-file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input-file.c,v 1.2 1998/02/15 18:48:51 niklas Exp $ */
+/* $OpenBSD: input-file.c,v 1.3 2001/07/09 07:04:35 deraadt Exp $ */
/* input_file.c - Deal with Input Files -
Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: input-file.c,v 1.2 1998/02/15 18:48:51 niklas Exp $";
+static char rcsid[] = "$OpenBSD: input-file.c,v 1.3 2001/07/09 07:04:35 deraadt Exp $";
#endif
#ifdef USG
@@ -175,8 +175,8 @@ int debugging; /* TRUE if we are debugging assembler. */
(void)dup2 (fd, fileno(stdout));
/* JF for testing #define PREPROCESSOR "/lib/app" */
#define PREPROCESSOR "./app"
- execl (PREPROCESSOR, PREPROCESSOR, 0);
- execl ("app","app",0);
+ execl (PREPROCESSOR, PREPROCESSOR, (char *)NULL);
+ execl ("app","app",(char *)NULL);
(void)write(2,"Exec of app failed. Get help.\n",31);
(void)unlink(temporary_file_name);
_exit (11);
diff --git a/gnu/usr.bin/ld/ldd/ldd.c b/gnu/usr.bin/ld/ldd/ldd.c
index cc03b36cefa..f578bc11a90 100644
--- a/gnu/usr.bin/ld/ldd/ldd.c
+++ b/gnu/usr.bin/ld/ldd/ldd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldd.c,v 1.7 2001/04/17 21:44:38 espie Exp $ */
+/* $OpenBSD: ldd.c,v 1.8 2001/07/09 07:04:36 deraadt Exp $ */
/* $NetBSD: ldd.c,v 1.12 1995/10/09 00:14:41 pk Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
@@ -163,7 +163,7 @@ char *argv[];
}
break;
case 0:
- rval |= execl(*argv, *argv, NULL) != 0;
+ rval |= execl(*argv, *argv, (char *)NULL) != 0;
perror(*argv);
_exit(1);
}