--- Imakefile +++ Imakefile Tue Apr 27 11:16:00 2004 @@ -8,12 +8,14 @@ XCOMM XCOMM for Dell SVR4 XCOMM -EXTRA_LIBRARIES = -lc -lucb +EXTRA_LIBRARIES = -lXpm SRCS = mgdiff.c rundiff.c misc.c files.c spawn.c manual.c modal.c legend.c OBJS = mgdiff.o rundiff.o misc.o files.o spawn.o manual.o modal.o legend.o -LOCAL_LIBRARIES = $(XMLIB) $(XTOOLLIB) $(XMULIBONLY) $(XLIB) +LOCAL_LIBRARIES = $(XMLIB) $(XTOOLLIB) $(XMULIBONLY) $(XLIB) $(XPLIB) +INSTPGMFLAGS = -s +EXTRA_LOAD_FLAGS = -Wl,-rpath-link,$(SHLIBDIR) ComplexProgramTarget(mgdiff) InstallAppDefaults(Mgdiff) --- Makefile.Linux +++ Makefile.Linux Tue Apr 27 11:16:00 2004 @@ -0,0 +1,20 @@ +# +# +# +# Makefile.Linux to integrate package into source tree of S.u.S.E.-Linux. +# +# Copyright (c) 1995 S.u.S.E. Gmbh Fuerth, Germany. All rights reserved. +# +# + + +compile: + xmkmf -a + make + +install: + make install DESTDIR=$(DESTDIR) + make install.man DESTDIR=$(DESTDIR) + gzip -9f $(DESTDIR)/usr/X11R6/man/man1/mgdiff.1x + + --- Mgdiff.ad +++ Mgdiff.ad Tue Apr 27 11:16:00 2004 @@ -2,6 +2,8 @@ ! Mgdiff.ad,v 2.0 1994/05/19 02:01:03 dan Exp ! +*XmScrollBar*width: 15 + ! ! widget hierarchy: ! @@ -169,9 +171,11 @@ ! ! the overview area ! -*sbl.width: 16 -*sbr.width: 16 -*dam.width: 16 +*sbl.width: 15 +*sbl.Background: lightgreen +*sbr.width: 15 +*sbr.Background: lightgreen +*dam.width: 30 *dam.Foreground: black *dam.Background: cyan --- externs.h +++ externs.h Tue Apr 27 11:19:42 2004 @@ -29,7 +29,7 @@ */ #ifndef lint -static char rcsid_externs_h[] = "externs.h,v 2.0 1994/05/19 02:01:05 dan Exp"; +static char rcsid_externs_h[] __attribute__((unused)) = "externs.h,v 2.0 1994/05/19 02:01:05 dan Exp"; #endif extern int main (int argc, char *argv[]); --- files.c +++ files.c Tue Apr 27 12:00:38 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; +static char rcsid[] __attribute__((unused)) = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; #endif /* @@ -91,7 +91,7 @@ (void) close (fd); for (i = 0; i < bytes; i++) - if (!isascii (buffer[i])) + if (!isallowed(buffer[i])) return (0); return (1); } @@ -148,7 +148,8 @@ XtSetArg (args[0], XmNmessageString, xms); XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); dialog = XmCreateErrorDialog (parent, "werror", args, 2); - XmStringFree (xms); + if (xms) + XmStringFree (xms); XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); @@ -174,8 +175,10 @@ xms1 = xms4; else { xms2 = XmStringConcat (xms1, xms4); - XmStringFree (xms4); - XmStringFree (xms1); + if (xms4) + XmStringFree (xms4); + if (xms1) + XmStringFree (xms1); xms1 = xms2; } @@ -183,16 +186,19 @@ XmString xms3; xms3 = XmStringConcat (xms1, sep); - XmStringFree (xms1); + if (xms1) + XmStringFree (xms1); xms1 = xms3; } } - XmStringFree (sep); + if (sep) + XmStringFree (sep); XtSetArg (args[0], XmNmessageString, xms1); XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); dialog = XmCreateErrorDialog (parent, "werror", args, 2); - XmStringFree (xms1); + if (xms1) + XmStringFree (xms1); XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON)); @@ -318,7 +324,7 @@ Arg args[2]; int i; char *dir; - XmString xms; + XmString xms = (XmString)0; shell = XtVaCreatePopupShell ("openfiles", xmDialogShellWidgetClass, parent, XmNallowShellResize, True, @@ -349,7 +355,8 @@ fsb1 = XmCreateFileSelectionBox (frame1a, "files1", args, i); if (dir) { XtFree (dir); - XmStringFree (xms); + if (xms) + XmStringFree (xms); } i = 0; @@ -360,7 +367,8 @@ fsb2 = XmCreateFileSelectionBox (frame2a, "files2", args, i); if (dir) { XtFree (dir); - XmStringFree (xms); + if (xms) + XmStringFree (xms); } XtAddCallback (fsb1, XmNokCallback, filel_both_cb, shell); @@ -424,7 +432,7 @@ Arg args[2]; int i; char *dir; - XmString xms; + XmString xms = (XmString)0; i = 0; XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; @@ -435,7 +443,8 @@ dialog = XmCreateFileSelectionDialog (parent, "openfile", args, i); if (dir) { XtFree (dir); - XmStringFree (xms); + if (xms) + XmStringFree (xms); } XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); XtAddCallback (dialog, XmNokCallback, file_left_cb, dialog); @@ -477,7 +486,7 @@ Arg args[2]; int i; char *dir; - XmString xms; + XmString xms = (XmString)0; i = 0; XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; @@ -488,7 +497,8 @@ dialog = XmCreateFileSelectionDialog (parent, "openfile", args, XtNumber (args)); if (dir) { XtFree (dir); - XmStringFree (xms); + if (xms) + XmStringFree (xms); } XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); @@ -569,7 +579,7 @@ Arg args[3]; int i; char *dir; - XmString xms; + XmString xms = (XmString)0; i = 0; XtSetArg (args[i], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); i++; @@ -582,7 +592,8 @@ dialog = XmCreateFileSelectionDialog (parent, "savefile", args, i); if (dir) { XtFree (dir); - XmStringFree (xms); + if (xms) + XmStringFree (xms); } XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); --- legend.c +++ legend.c Tue Apr 27 11:19:52 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "legend.c,v 2.0 1994/05/19 02:01:08 dan Exp"; +static char rcsid[] __attribute__((unused)) = "legend.c,v 2.0 1994/05/19 02:01:08 dan Exp"; #endif /* --- manual.c +++ manual.c Tue Apr 27 11:19:57 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "manual.c,v 2.0 1994/05/19 02:01:09 dan Exp"; +static char rcsid[] __attribute__((unused)) = "manual.c,v 2.0 1994/05/19 02:01:09 dan Exp"; #endif /* --- mgdiff.c +++ mgdiff.c Tue Apr 27 11:50:29 2004 @@ -1,9 +1,9 @@ #ifndef lint -static char rcsid[] = "mgdiff.c,v 2.1 1994/09/29 01:56:53 dan Exp"; +static char rcsid[] __attribute__((unused)) = "mgdiff.c,v 2.1 1994/09/29 01:56:53 dan Exp"; #endif #ifndef lint -static char copyright[] = "Copyright (c) 1994, Daniel Williams"; +static char copyright[] __attribute__((unused)) = "Copyright (c) 1994, Daniel Williams"; #endif /* @@ -33,6 +33,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define _GNU_SOURCE + #include #include @@ -40,6 +42,7 @@ #include #include #include +#include #include #include @@ -109,7 +112,9 @@ static void unselect_all (void); static Boolean all_selected (void); static Dimension get_preferred_width (Widget w); +#if !(defined __GLIBC__ && __GLIBC__ >= 2) static char *basename (char *name); +#endif #define APP_DEFAULTS_VERSION 1 @@ -1020,6 +1025,9 @@ progname = basename (argv[0]); + XtSetLanguageProc (NULL, NULL, NULL); + setlocale (LC_ALL, ""); + setlocale (LC_CTYPE, "en"); toplevel = XtVaAppInitialize (&app, "Mgdiff", option_table, XtNumber (option_table), #if X11R5 &argc, @@ -1106,7 +1114,14 @@ */ case 3: if (strcmp (argv[1], "-") == 0) { - tempfname = tempnam (NULL, "mgdif"); + int fd; + char tmp[] = "mgdifXXXXXX"; + if ((fd = mkstemp(tmp)) < 0) { + perror("mkstemp"); + exit(1); + } + close(fd); + tempfname = tmp; str_fnamel = strdup (tempfname); str_snamel = strdup (user_filename); if (!copy_to_file (stdin, tempfname)) { @@ -1127,7 +1142,14 @@ } if (strcmp (argv[2], "-") == 0) { - tempfname = tempnam (NULL, "mgdif"); + int fd; + char tmp[] = "mgdifXXXXXX"; + if ((fd = mkstemp(tmp)) < 0) { + perror("mkstemp"); + exit(1); + } + close(fd); + tempfname = tmp; str_fnamer = strdup (tempfname); str_snamer = strdup (user_filename); if (!copy_to_file (stdin, tempfname)) { @@ -1487,6 +1509,7 @@ XtAppMainLoop (app); /* NOTREACHED */ + return -1; } static void redraw_partial_vert (Widget w) @@ -2387,6 +2410,7 @@ /* * delete any prefix ending in '/' and return a copy */ +#if !(defined __GLIBC__ && __GLIBC__ >= 2) static char *basename (char *path) { if (path) { @@ -2412,3 +2436,4 @@ else return (NULL); } +#endif --- mgdiff.h +++ mgdiff.h Tue Apr 27 11:55:10 2004 @@ -2,7 +2,7 @@ #define MXDIFF_H #ifndef lint -static char rcsid_mgdiff_h[] = "mgdiff.h,v 2.0 1994/05/19 02:01:15 dan Exp"; +static char rcsid_mgdiff_h[] __attribute__((unused)) = "mgdiff.h,v 2.0 1994/05/19 02:01:15 dan Exp"; #endif /* @@ -85,5 +85,20 @@ * True if we are compiling under Release 5 or above of the Intrinsics */ #define X11R5 (defined(XtSpecificationRelease) && (XtSpecificationRelease >= 5)) + +#define islatin(c) ((isprint((c)) || ((((unsigned int)(c)) >= 160) && (((unsigned int)(c)) <= 255)))) +#define isallowed(c) (isascii((c)) || islatin((c))) + +#include +#include +static inline char* xstrdup(const char *s) +{ + char *ret = strdup(s); + if (!ret) { + perror("strdup"); + exit (1); + } + return ret; +} #endif --- misc.c +++ misc.c Tue Apr 27 11:20:07 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "misc.c,v 2.0 1994/05/19 02:01:19 dan Exp"; +static char rcsid[] __attribute__((unused)) = "misc.c,v 2.0 1994/05/19 02:01:19 dan Exp"; #endif /* --- modal.c +++ modal.c Tue Apr 27 11:20:12 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "modal.c,v 2.0 1994/05/19 02:01:20 dan Exp"; +static char rcsid[] __attribute__((unused)) = "modal.c,v 2.0 1994/05/19 02:01:20 dan Exp"; #endif /* --- patchlevel.h +++ patchlevel.h Tue Apr 27 11:20:18 2004 @@ -29,7 +29,7 @@ */ #ifndef lint -static char rcsid_patchlevel_h[] = "patchlevel.h,v 2.0 1994/05/19 02:01:21 dan Exp"; +static char rcsid_patchlevel_h[] __attribute__((unused)) = "patchlevel.h,v 2.0 1994/05/19 02:01:21 dan Exp"; #endif #define VERSION "1.0" --- rundiff.c +++ rundiff.c Tue Apr 27 11:53:03 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "rundiff.c,v 2.0 1994/05/19 02:01:22 dan Exp"; +static char rcsid[] __attribute__((unused)) = "rundiff.c,v 2.0 1994/05/19 02:01:22 dan Exp"; #endif /* @@ -44,6 +44,16 @@ #include "mgdiff.h" #include "externs.h" +static inline void* xcalloc(size_t nmemb, size_t size) +{ + void *ret = calloc(nmemb, size); + if (!ret) { + perror("calloc"); + exit (1); + } + return ret; +} + /* * this is the maximum number of lines shown to the user if diff * returns an error @@ -170,22 +180,22 @@ Block *b; DiffInfo *di; - di = (DiffInfo *) calloc (1, sizeof (DiffInfo)); + di = (DiffInfo *) xcalloc (1, sizeof (DiffInfo)); di->longline = " "; di->maxcols = strlen (di->longline); di->status = 2; - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = SAME; b->sline = 0; b->ssize = 1; b->arr[LEFT].fline = b->arr[RIGHT].fline = 0; b->arr[LEFT].fsize = b->arr[RIGHT].fsize = 1; - b->arr[LEFT].text = (char **) calloc (1, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (1, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (1, sizeof (short)); - b->arr[LEFT].text[0] = strdup (" "); + b->arr[LEFT].text = (char **) xcalloc (1, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (1, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (1, sizeof (short)); + b->arr[LEFT].text[0] = xstrdup (" "); b->arr[LEFT].tlen[0] = strlen (b->arr[LEFT].text[0]); b->arr[RIGHT].text = NULL; @@ -209,7 +219,7 @@ FILE *diff, *file1, *file2; char buffer[BUFSIZ+1]; int sline, fline1, fline2; - Block *b; + Block *b = NULL; int i, lines, counter; int stat_loc; DiffInfo *di; @@ -220,7 +230,7 @@ file2 = fopen (path2, "r"); diff = spawn_diff (prog, args, path1, path2); - di = (DiffInfo *) calloc (1, sizeof (DiffInfo)); + di = (DiffInfo *) xcalloc (1, sizeof (DiffInfo)); di->longline = ""; XmUpdateDisplay (toplevel); @@ -244,21 +254,21 @@ if (di->errors == 0) { char cmdline[4096]; - di->etext = (char **) calloc (MAX_ERROR_LINES + 1, sizeof (char *)); + di->etext = (char **) xcalloc (MAX_ERROR_LINES + 1, sizeof (char *)); (void) sprintf (cmdline, " \"%s %s %s %s\"", prog, args, path1, path2); - di->etext[di->errors++] = strdup ("diff command line:"); - di->etext[di->errors++] = strdup (""); - di->etext[di->errors++] = strdup (cmdline); - di->etext[di->errors++] = strdup (""); - di->etext[di->errors++] = strdup ("produced this output:"); - di->etext[di->errors++] = strdup (""); + di->etext[di->errors++] = xstrdup ("diff command line:"); + di->etext[di->errors++] = xstrdup (""); + di->etext[di->errors++] = xstrdup (cmdline); + di->etext[di->errors++] = xstrdup (""); + di->etext[di->errors++] = xstrdup ("produced this output:"); + di->etext[di->errors++] = xstrdup (""); } if (di->errors < MAX_ERROR_LINES) - di->etext[di->errors++] = strdup (buffer); + di->etext[di->errors++] = xstrdup (buffer); break; case ADD: if (f2n1 != fline2) { - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = SAME; b->sline = sline; @@ -267,9 +277,9 @@ b->arr[LEFT].fsize = b->arr[RIGHT].fsize = f2n1 - fline2; b->ssize = f2n1 - fline2; - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file1, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -285,7 +295,7 @@ add_blist (b); } - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = BLANK; b->arr[RIGHT].type = INSERT; @@ -296,9 +306,9 @@ b->arr[RIGHT].fsize = f2n2 - f2n1 + 1; b->ssize = max (b->arr[LEFT].fsize, b->arr[RIGHT].fsize); - b->arr[RIGHT].text = (char **) calloc (b->arr[RIGHT].fsize, sizeof (char *)); - b->arr[RIGHT].wtext = (char **) calloc (b->arr[RIGHT].fsize, sizeof (char *)); - b->arr[RIGHT].tlen = (short *) calloc (b->arr[RIGHT].fsize, sizeof (short)); + b->arr[RIGHT].text = (char **) xcalloc (b->arr[RIGHT].fsize, sizeof (char *)); + b->arr[RIGHT].wtext = (char **) xcalloc (b->arr[RIGHT].fsize, sizeof (char *)); + b->arr[RIGHT].tlen = (short *) xcalloc (b->arr[RIGHT].fsize, sizeof (short)); for (i = 0; i < b->arr[RIGHT].fsize; i++) { getline (file2, &b->arr[RIGHT].text[i], &b->arr[RIGHT].wtext[i]); b->arr[RIGHT].tlen[i] = strlen (b->arr[RIGHT].text[i]); @@ -318,7 +328,7 @@ break; case CHANGE: if (f1n1 != fline1) { - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = SAME; b->sline = sline; @@ -327,9 +337,9 @@ b->arr[LEFT].fsize = b->arr[RIGHT].fsize = f1n1 - fline1; b->ssize = f1n1 - fline1; - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file1, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -344,7 +354,7 @@ sline += b->ssize; add_blist (b); } - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = DIFF; b->sline = sline; @@ -354,9 +364,9 @@ b->arr[RIGHT].fsize = f2n2 - f2n1 + 1; b->ssize = max (b->arr[LEFT].fsize, b->arr[RIGHT].fsize); - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file1, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -367,9 +377,9 @@ } fline1 += b->arr[LEFT].fsize; - b->arr[RIGHT].text = (char **) calloc (b->arr[RIGHT].fsize, sizeof (char *)); - b->arr[RIGHT].wtext = (char **) calloc (b->arr[RIGHT].fsize, sizeof (char *)); - b->arr[RIGHT].tlen = (short *) calloc (b->arr[RIGHT].fsize, sizeof (short)); + b->arr[RIGHT].text = (char **) xcalloc (b->arr[RIGHT].fsize, sizeof (char *)); + b->arr[RIGHT].wtext = (char **) xcalloc (b->arr[RIGHT].fsize, sizeof (char *)); + b->arr[RIGHT].tlen = (short *) xcalloc (b->arr[RIGHT].fsize, sizeof (short)); for (i = 0; i < b->arr[RIGHT].fsize; i++) { getline (file2, &b->arr[RIGHT].text[i], &b->arr[RIGHT].wtext[i]); b->arr[RIGHT].tlen[i] = strlen (b->arr[RIGHT].text[i]); @@ -386,7 +396,7 @@ break; case DELETE: if (f1n1 != fline1) { - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = SAME; b->sline = sline; @@ -395,9 +405,9 @@ b->arr[LEFT].fsize = b->arr[RIGHT].fsize = f1n1 - fline1; b->ssize = f1n1 - fline1; - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file1, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -413,7 +423,7 @@ add_blist (b); } - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = INSERT; b->arr[RIGHT].type = BLANK; @@ -424,9 +434,9 @@ b->arr[RIGHT].fsize = 0; b->ssize = max (b->arr[LEFT].fsize, b->arr[RIGHT].fsize); - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file1, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -478,7 +488,7 @@ ; if (lines > 0) { - b = (Block *) calloc (1, sizeof (Block)); + b = (Block *) xcalloc (1, sizeof (Block)); b->selected = NEITHER; b->arr[LEFT].type = b->arr[RIGHT].type = SAME; b->sline = sline; @@ -487,9 +497,9 @@ b->arr[LEFT].fsize = b->arr[RIGHT].fsize = lines; b->ssize = lines; - b->arr[LEFT].text = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].wtext = (char **) calloc (b->arr[LEFT].fsize, sizeof (char *)); - b->arr[LEFT].tlen = (short *) calloc (b->arr[LEFT].fsize, sizeof (short)); + b->arr[LEFT].text = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].wtext = (char **) xcalloc (b->arr[LEFT].fsize, sizeof (char *)); + b->arr[LEFT].tlen = (short *) xcalloc (b->arr[LEFT].fsize, sizeof (short)); for (i = 0; i < b->arr[LEFT].fsize; i++) { getline (file2, &b->arr[LEFT].text[i], &b->arr[LEFT].wtext[i]); b->arr[LEFT].tlen[i] = strlen (b->arr[LEFT].text[i]); @@ -522,21 +532,22 @@ */ static char *duplicate (char *s, int *flag) { - int len, i, tabs, ctrls; + int len, i, tabs, ctrls, latin; /* * compute length of new string, taking tabs and control * characters into account */ for (i = 0, len = 0, ctrls = tabs = 0; s[i] != '\0'; i++) { - if (isascii (s[i])) { + latin = islatin(s[i]); + if ((isascii(s[i]) || latin)) { if (s[i] == '\t') { tabs++; len += 8; len /= 8; len *= 8; } - else if (iscntrl (s[i])) { + else if (!latin && iscntrl (s[i])) { ctrls++; len += 2; } @@ -550,17 +561,18 @@ } if (tabs || ctrls) { - char *ret = (char *) calloc (1, len + 1); + char *ret = (char *) xcalloc (1, len + 1); int j; for (i = 0, j = 0; s[i] != '\0'; i++) { - if (isascii (s[i])) { + latin = islatin(s[i]); + if ((isascii(s[i]) || latin)) { if (s[i] == '\t') { ret[j++] = ' '; while ((j % 8) != 0) ret[j++] = ' '; } - else if (iscntrl (s[i])) { + else if (!latin && iscntrl (s[i])) { ret[j++] = '^'; ret[j++] = (s[i] + '@') & 0x7f; } @@ -585,7 +597,7 @@ } else { *flag = False; - return (strdup (s)); + return (xstrdup (s)); } } @@ -685,7 +697,7 @@ while (getc (f) != '\n') ; *cooked = s; - *raw = (flag) ? strdup (buffer) : NULL; + *raw = (flag) ? xstrdup (buffer) : NULL; } /* --- spawn.c +++ spawn.c Tue Apr 27 11:38:10 2004 @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "spawn.c,v 2.0 1994/05/19 02:01:23 dan Exp"; +static char rcsid[] __attribute__((unused)) = "spawn.c,v 2.0 1994/05/19 02:01:23 dan Exp"; #endif /* @@ -34,9 +34,29 @@ #include #include #include +#include "mgdiff.h" #define BLOCKSIZE 10 +static inline void* xmalloc(size_t size) +{ + void *ret = malloc(size); + if (!ret) { + perror("malloc"); + exit(1); + } + return ret; +} +static inline void* xrealloc(void *ptr, size_t size) +{ + void *ret = realloc(ptr, size); + if (!ret) { + perror("realloc"); + exit(1); + } + return ret; +} + /* * run a program with command line arguments and two pathname * arguments via fork/exec and return a pipe file descriptor into @@ -86,19 +106,19 @@ argc = 0; count = BLOCKSIZE; - argv = (char **) malloc (sizeof (char *) * BLOCKSIZE); + argv = (char **) xmalloc (sizeof (char *) * BLOCKSIZE); argv[argc++] = prog; for (ptr = strtok (args, " \t"); ptr; ptr = strtok (NULL, " \t")) { if (argc >= count) { - argv = (char **) realloc (argv, sizeof (char *) * BLOCKSIZE); + argv = (char **) xrealloc (argv, sizeof (char *) * BLOCKSIZE); count += BLOCKSIZE; } argv[argc++] = strdup (ptr); } if ((argc + 3) >= count) - argv = (char **) realloc (argv, sizeof (char *) * 3); + argv = (char **) xrealloc (argv, sizeof (char *) * 3); argv[argc++] = path1; argv[argc++] = path2; @@ -131,4 +151,5 @@ break; } /* NOTREACHED */ + exit(2); }