=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sdiff/sdiff.c,v retrieving revision 1.13 retrieving revision 1.14 diff -c -r1.13 -r1.14 *** src/usr.bin/sdiff/sdiff.c 2006/02/14 08:26:20 1.13 --- src/usr.bin/sdiff/sdiff.c 2006/02/15 06:58:06 1.14 *************** *** 1,4 **** ! /* $OpenBSD: sdiff.c,v 1.13 2006/02/14 08:26:20 otto Exp $ */ /* * Written by Raymond Lai . --- 1,4 ---- ! /* $OpenBSD: sdiff.c,v 1.14 2006/02/15 06:58:06 otto Exp $ */ /* * Written by Raymond Lai . *************** *** 32,45 **** /* A single diff line. */ struct diffline { SIMPLEQ_ENTRY(diffline) diffentries; ! const char *left; ! char div; ! const char *right; }; static void astrcat(char **, const char *); ! static void enqueue(const char *, const char, const char *); ! static void freediff(const struct diffline *); static void int_usage(void); static int parsecmd(FILE *, FILE *, FILE *); static void printa(FILE *, size_t); --- 32,45 ---- /* A single diff line. */ struct diffline { SIMPLEQ_ENTRY(diffline) diffentries; ! char *left; ! char div; ! char *right; }; static void astrcat(char **, const char *); ! static void enqueue(char *, char, char *); ! static void freediff(struct diffline *); static void int_usage(void); static int parsecmd(FILE *, FILE *, FILE *); static void printa(FILE *, size_t); *************** *** 87,93 **** size_t diffargc = 0, wflag = WIDTH; int ch, fd[2], status; pid_t pid; ! const char **diffargv, *diffprog = "diff", *s1, *s2; /* * Process diff flags. --- 87,93 ---- size_t diffargc = 0, wflag = WIDTH; int ch, fd[2], status; pid_t pid; ! char **diffargv, *diffprog = "diff", *s1, *s2; /* * Process diff flags. *************** *** 206,212 **** /* Free unused descriptor. */ close(fd[1]); ! execvp(diffprog, (char *const *)diffargv); err(2, "could not execute diff: %s", diffprog); case -1: err(2, "could not fork"); --- 206,212 ---- /* Free unused descriptor. */ close(fd[1]); ! execvp(diffprog, diffargv); err(2, "could not execute diff: %s", diffprog); case -1: err(2, "could not fork"); *************** *** 316,328 **** static void prompt(const char *s1, const char *s2) { ! const char *cmd; /* Print command prompt. */ putchar('%'); /* Get user input. */ ! for (; (cmd = xfgets(stdin)); free((void *)cmd)) { const char *p; /* Skip leading whitespace. */ --- 316,328 ---- static void prompt(const char *s1, const char *s2) { ! char *cmd; /* Print command prompt. */ putchar('%'); /* Get user input. */ ! for (; (cmd = xfgets(stdin)); free(cmd)) { const char *p; /* Skip leading whitespace. */ *************** *** 376,382 **** continue; } ! free((void *)cmd); return; } --- 376,382 ---- continue; } ! free(cmd); return; } *************** *** 568,574 **** */ for (; file1ln < file1start && file2ln < file2start; ++file1ln, ++file2ln) { ! const char *s1, *s2; if (!(s1 = xfgets(file1))) errx(2, "file1 shorter than expected"); --- 568,574 ---- */ for (; file1ln < file1start && file2ln < file2start; ++file1ln, ++file2ln) { ! char *s1, *s2; if (!(s1 = xfgets(file1))) errx(2, "file1 shorter than expected"); *************** *** 577,583 **** /* If the -l flag was specified, print only left column. */ if (lflag) { ! free((void *)s2); /* * XXX - If -l and -I are both specified, all * unchanged or ignored lines are shown with a --- 577,583 ---- /* If the -l flag was specified, print only left column. */ if (lflag) { ! free(s2); /* * XXX - If -l and -I are both specified, all * unchanged or ignored lines are shown with a *************** *** 594,600 **** } /* Ignore deleted lines. */ for (; file1ln < file1start; ++file1ln) { ! const char *s; if (!(s = xfgets(file1))) errx(2, "file1 shorter than expected"); --- 594,600 ---- } /* Ignore deleted lines. */ for (; file1ln < file1start; ++file1ln) { ! char *s; if (!(s = xfgets(file1))) errx(2, "file1 shorter than expected"); *************** *** 603,616 **** } /* Ignore added lines. */ for (; file2ln < file2start; ++file2ln) { ! const char *s; if (!(s = xfgets(file2))) errx(2, "file2 shorter than expected"); /* If -l flag was given, don't print right column. */ if (lflag) ! free((void *)s); else enqueue(NULL, ')', s); } --- 603,616 ---- } /* Ignore added lines. */ for (; file2ln < file2start; ++file2ln) { ! char *s; if (!(s = xfgets(file2))) errx(2, "file2 shorter than expected"); /* If -l flag was given, don't print right column. */ if (lflag) ! free(s); else enqueue(NULL, ')', s); } *************** *** 650,656 **** * Queues up a diff line. */ static void ! enqueue(const char *left, const char div, const char *right) { struct diffline *diffp; --- 650,656 ---- * Queues up a diff line. */ static void ! enqueue(char *left, char div, char *right) { struct diffline *diffp; *************** *** 666,678 **** * Free a diffline structure and its elements. */ static void ! freediff(const struct diffline *diffp) { ! if (diffp->left) ! free((void *)diffp->left); ! if (diffp->right) ! free((void *)diffp->right); ! free((void *)diffp); } /* --- 666,676 ---- * Free a diffline structure and its elements. */ static void ! freediff(struct diffline *diffp) { ! free(diffp->left); ! free(diffp->right); ! free(diffp); } /* *************** *** 684,695 **** { /* Length of string in previous run. */ static size_t offset = 0; ! size_t copied, newlen; /* * String from previous run. Compared to *s to see if we are * dealing with the same string. If so, we can use offset. */ ! const static char *oldstr = NULL; char *newstr; --- 682,693 ---- { /* Length of string in previous run. */ static size_t offset = 0; ! size_t newlen; /* * String from previous run. Compared to *s to see if we are * dealing with the same string. If so, we can use offset. */ ! static const char *oldstr = NULL; char *newstr; *************** *** 732,738 **** /* Concatenate. */ strlcpy(*s + offset, "\n", newlen - offset); - copied = strlcat(*s + offset, append, newlen - offset); /* Store generated string's values. */ offset = newlen - 1; --- 730,735 ---- *************** *** 747,759 **** processq(void) { struct diffline *diffp; ! char div, *left, *right; /* Don't process empty queue. */ if (SIMPLEQ_EMPTY(&diffhead)) return; ! div = '\0'; left = NULL; right = NULL; /* --- 744,756 ---- processq(void) { struct diffline *diffp; ! char divc, *left, *right; /* Don't process empty queue. */ if (SIMPLEQ_EMPTY(&diffhead)) return; ! divc = '\0'; left = NULL; right = NULL; /* *************** *** 762,780 **** */ SIMPLEQ_FOREACH(diffp, &diffhead, diffentries) { /* ! * Make sure that div is consistent throughout set. ! * If div is set, compare to next entry's div. They ! * should be the same. If div is not set, then store ! * this as this set's div. */ ! if (!div) ! div = diffp->div; /* * Print changed lines if -s was given, * print all lines if -s was not given. */ ! if (!sflag || div == '|' || div == '<' || div == '>') println(diffp->left, diffp->div, diffp->right); /* Append new lines to diff set. */ --- 759,777 ---- */ SIMPLEQ_FOREACH(diffp, &diffhead, diffentries) { /* ! * Make sure that divc is consistent throughout set. ! * If divc is set, compare to next entry's divc. They ! * should be the same. If divc is not set, then store ! * this as this set's divc. */ ! if (divc == '\0') ! divc = diffp->div; /* * Print changed lines if -s was given, * print all lines if -s was not given. */ ! if (!sflag || divc == '|' || divc == '<' || divc == '>') println(diffp->left, diffp->div, diffp->right); /* Append new lines to diff set. */ *************** *** 793,799 **** /* Write to outfile, prompting user if lines are different. */ if (outfile) ! switch (div) { case ' ': case '(': case ')': fprintf(outfile, "%s\n", left); break; --- 790,796 ---- /* Write to outfile, prompting user if lines are different. */ if (outfile) ! switch (divc) { case ' ': case '(': case ')': fprintf(outfile, "%s\n", left); break; *************** *** 801,814 **** prompt(left, right); break; default: ! errx(2, "invalid divider: %c", div); } /* Free left and right. */ ! if (left) ! free(left); ! if (right) ! free(right); } /* --- 798,809 ---- prompt(left, right); break; default: ! errx(2, "invalid divider: %c", divc); } /* Free left and right. */ ! free(left); ! free(right); } /* *************** *** 836,850 **** printc(FILE *file1, size_t file1end, FILE *file2, size_t file2end) { struct fileline { ! SIMPLEQ_ENTRY(fileline) fileentries; ! const char *line; }; SIMPLEQ_HEAD(, fileline) delqhead = SIMPLEQ_HEAD_INITIALIZER(delqhead); /* Read lines to be deleted. */ for (; file1ln <= file1end; ++file1ln) { struct fileline *linep; ! const char *line1; /* Read lines from both. */ if (!(line1 = xfgets(file1))) --- 831,845 ---- printc(FILE *file1, size_t file1end, FILE *file2, size_t file2end) { struct fileline { ! SIMPLEQ_ENTRY(fileline) fileentries; ! char *line; }; SIMPLEQ_HEAD(, fileline) delqhead = SIMPLEQ_HEAD_INITIALIZER(delqhead); /* Read lines to be deleted. */ for (; file1ln <= file1end; ++file1ln) { struct fileline *linep; ! char *line1; /* Read lines from both. */ if (!(line1 = xfgets(file1))) *************** *** 889,895 **** enqueue(NULL, '>', add); } processq(); - #undef getaddln /* Process remaining lines to delete. */ while (!SIMPLEQ_EMPTY(&delqhead)) { --- 884,889 ---- *************** *** 909,915 **** static void printd(FILE *file1, size_t file1end) { ! const char *line1; /* Print out lines file1ln to line2. */ for (; file1ln <= file1end; ++file1ln) { --- 903,909 ---- static void printd(FILE *file1, size_t file1end) { ! char *line1; /* Print out lines file1ln to line2. */ for (; file1ln <= file1end; ++file1ln) {