]> git.neil.brown.name Git - wiggle.git/commitdiff
Make lots of functions "static".
authorNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 04:28:20 +0000 (14:28 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 22 Aug 2011 04:28:20 +0000 (14:28 +1000)
In particular isolate_conflicts() needs to be static to avoid a link
error with SUN's C compiler
Reported-by: Oliver Kiddle <oliver@kiddle.eu>
Also this shows that set_prefix() wasn't being used any more, so fix
that.

Signed-off-by: NeilBrown <neilb@suse.de>
bestmatch.c
extract.c
merge.c
merge2.c
vpatch.c
wiggle.c
wiggle.h

index 5ba047b787397ee4f98a439d99c140995cb5745f..89e8c2d14ad4ab35ae18c0f89f116b9960340359 100644 (file)
@@ -148,9 +148,9 @@ static inline int min(int a, int b) {
        return a < b ? a : b;
 }
 
-void find_best(struct file *a, struct file *b,
-             int alo, int ahi,
-             int blo, int bhi, struct best *best)
+static void find_best(struct file *a, struct file *b,
+                     int alo, int ahi,
+                     int blo, int bhi, struct best *best)
 {
        int klo, khi, k;
        int f;
@@ -254,7 +254,7 @@ void find_best(struct file *a, struct file *b,
        free(valloc);
 }
 
-struct csl *csl_join(struct csl *c1, struct csl *c2)
+static struct csl *csl_join(struct csl *c1, struct csl *c2)
 {
        struct csl *c,*cd,  *rv;
        int cnt;
@@ -306,7 +306,8 @@ static inline int is_skipped(struct elmnt e)
                  isalnum(e.start[0]) ||
                  e.start[0] == '_');
 }
-struct file reduce(struct file orig)
+
+static struct file reduce(struct file orig)
 {
        int cnt=0;
        int i;
@@ -333,9 +334,9 @@ struct file reduce(struct file orig)
  * When we find the location in a2/b2, we expand to include all
  * immediately surrounding words which were skipped
  */
-void remap(struct best *best, int cnt,
-          struct file a1, struct file b1,
-          struct file a2, struct file b2)
+static void remap(struct best *best, int cnt,
+                 struct file a1, struct file b1,
+                 struct file a2, struct file b2)
 {
        int b;
        int pa,pb;
index cf6f779ed1fcc92bed4ab04c028ceabf0146eda3..92d50a33a5f7197a5be46590602be2373e12db03 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -32,7 +32,7 @@
 #include       <malloc.h>
 #include       <stdlib.h>
 
-void skip_eol(char **cp, char *end)
+static void skip_eol(char **cp, char *end)
 {
        char *c = *cp;
        while (c < end && *c != '\n')
@@ -41,7 +41,7 @@ void skip_eol(char **cp, char *end)
        *cp = c;
 }
 
-void copyline(struct stream *s, char **cp, char *end)
+static void copyline(struct stream *s, char **cp, char *end)
 {
        char *from = *cp;
        char *to = s->body+s->len;
diff --git a/merge.c b/merge.c
index 3823417b8f347ae7aad3c08a163485844d778dfe..63a7d4701ee1272396a03eacf8ecb2f6870ae6d3 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -523,7 +523,7 @@ static void print_merger(FILE *out, struct file *a, struct file *c,
        }
 }
 
-static int inline at_sol(struct file *f, int i)
+static inline int at_sol(struct file *f, int i)
 {
        return i == 0 || i == f->elcnt ||
                ends_line(f->list[i-1]);
index 9c605eaa3094d3b8d23d8c6a771b691ba0960e34..b50bb0692d76e2957598eb5a13b1e728c486a938 100644 (file)
--- a/merge2.c
+++ b/merge2.c
@@ -55,8 +55,8 @@ static inline void assert(int a)
        if (!a) abort();
 }
 
-int check_alreadyapplied(struct file af, struct file cf,
-                         struct merge *m)
+static int check_alreadyapplied(struct file af, struct file cf,
+                               struct merge *m)
 {
        int i;
        if (m->al != m->cl)
@@ -79,9 +79,9 @@ int check_alreadyapplied(struct file af, struct file cf,
        return 1;
 }
 
-inline int isolate_conflicts(struct file af, struct file bf, struct file cf,
-                             struct csl *csl1, struct csl *csl2, int words,
-                             struct merge *m)
+static int isolate_conflicts(struct file af, struct file bf, struct file cf,
+                            struct csl *csl1, struct csl *csl2, int words,
+                            struct merge *m)
 {
        /* A conflict indicates that something is definitely wrong
         * and so we need to be a bit suspicious of nearby apparent matches.
@@ -341,7 +341,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
        return rv;
 }
 
-void printrange(FILE *out, struct file *f, int start, int len)
+static void printrange(FILE *out, struct file *f, int start, int len)
 {
        while (len> 0) {
                printword(out, f->list[start]);
index 4ad39c02be8ef26d352bf76455dd4751b0dbcdef..9f62baa2731e5fc310a4fe9cb79cd072c16453f4 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -105,7 +105,7 @@ char *help_help[] = {
        NULL
 };
 
-void help_window(char *page1[], char *page2[])
+static void help_window(char *page1[], char *page2[])
 {
        int rows, cols;
        int top, left;
@@ -236,7 +236,7 @@ void help_window(char *page1[], char *page2[])
 }
 
 
-char *typenames[] = {
+static char *typenames[] = {
        [End] = "End",
        [Unmatched] = "Unmatched",
        [Unchanged] = "Unchanged",
@@ -321,7 +321,7 @@ struct mpos {
 };
 
 /* used for checking location during search */
-int same_mpos(struct mpos a, struct mpos b)
+static int same_mpos(struct mpos a, struct mpos b)
 {
        return a.p.m == b.p.m &&
                a.p.s == b.p.s &&
@@ -334,7 +334,7 @@ int same_mpos(struct mpos a, struct mpos b)
  * original, is meaningful.  This is used to avoid walking down
  * pointless paths.
  */
-int stream_valid(int s, enum mergetype type)
+static int stream_valid(int s, enum mergetype type)
 {
        switch(type) {
        case End: return 1;
@@ -354,9 +354,9 @@ int stream_valid(int s, enum mergetype type)
  * This walks the merges in sequence, and the streams within
  * each merge.
  */
-struct elmnt next_melmnt(struct mp *pos,
-                        struct file fm, struct file fb, struct file fa,
-                        struct merge *m)
+static struct elmnt next_melmnt(struct mp *pos,
+                               struct file fm, struct file fb, struct file fa,
+                               struct merge *m)
 {
        pos->o++;
        while(1) {
@@ -401,9 +401,9 @@ struct elmnt next_melmnt(struct mp *pos,
 }
 
 /* step current position.p backwards */
-struct elmnt prev_melmnt(struct mp *pos,
-                        struct file fm, struct file fb, struct file fa,
-                        struct merge *m)
+static struct elmnt prev_melmnt(struct mp *pos,
+                               struct file fm, struct file fb, struct file fa,
+                               struct merge *m)
 {
        if (pos->s == 0) {
                if (ends_mline(fm.list[m[pos->m].a + pos->o]))
@@ -447,7 +447,7 @@ struct elmnt prev_melmnt(struct mp *pos,
  * visible in this mode, but also chooses which colour/highlight to use
  * to display it.
  */
-int visible(int mode, enum mergetype type, int stream)
+static int visible(int mode, enum mergetype type, int stream)
 {
        if (mode == 0) return -1;
        /* mode can be any combination of ORIG RESULT BEFORE AFTER */
@@ -519,8 +519,9 @@ int visible(int mode, enum mergetype type, int stream)
  *  WIGGLED
  *  CONFLICTED
  */
-int check_line(struct mpos pos, struct file fm, struct file fb, struct file fa,
-              struct merge *m, int mode)
+static int check_line(struct mpos pos, struct file fm, struct file fb,
+                     struct file fa,
+                     struct merge *m, int mode)
 {
        int rv = 0;
        struct elmnt e;
@@ -546,8 +547,9 @@ int check_line(struct mpos pos, struct file fm, struct file fb, struct file fa,
        return rv;
 }
 
-void next_mline(struct mpos *pos, struct file fm, struct file fb, struct file fa,
-             struct merge *m, int mode)
+static void next_mline(struct mpos *pos, struct file fm, struct file fb,
+                      struct file fa,
+                      struct merge *m, int mode)
 {
        int mask;
        do {
@@ -592,8 +594,9 @@ void next_mline(struct mpos *pos, struct file fm, struct file fb, struct file fa
 
 }
 
-void prev_mline(struct mpos *pos, struct file fm, struct file fb, struct file fa,
-               struct merge *m, int mode)
+static void prev_mline(struct mpos *pos, struct file fm, struct file fb,
+                      struct file fa,
+                      struct merge *m, int mode)
 {
        int mask;
        do {
@@ -640,7 +643,7 @@ void prev_mline(struct mpos *pos, struct file fm, struct file fb, struct file fa
 }
 
 /* blank a whole row of display */
-void blank(int row, int start, int cols, int attr)
+static void blank(int row, int start, int cols, int attr)
 {
        (void)attrset(attr);
        move(row,start);
@@ -650,9 +653,10 @@ void blank(int row, int start, int cols, int attr)
 
 /* search of a string on one display line - just report if found, not where */
 
-int mcontains(struct mpos pos,
-             struct file fm, struct file fb, struct file fa, struct merge *m,
-             int mode, char *search)
+static int mcontains(struct mpos pos,
+                    struct file fm, struct file fb, struct file fa,
+                    struct merge *m,
+                    int mode, char *search)
 {
        /* See if any of the files, between start of this line and here,
         * contain the search string
@@ -710,10 +714,11 @@ int mcontains(struct mpos pos,
  * It is one of ORIG RESULT BEFORE AFTER or ORIG|RESULT or BEFORE|AFTER
  * It may also have WIGGLED or CONFLICTED ored in
  */
-void draw_mside(int mode, int row, int offset, int start, int cols,
-               struct file fm, struct file fb, struct file fa, struct merge *m,
-               struct mpos pos,
-               int target, int *colp)
+static void draw_mside(int mode, int row, int offset, int start, int cols,
+                      struct file fm, struct file fb, struct file fa,
+                      struct merge *m,
+                      struct mpos pos,
+                      int target, int *colp)
 {
        struct elmnt e;
        int col = 0;
@@ -821,11 +826,11 @@ void draw_mside(int mode, int row, int offset, int start, int cols,
        }
 }
 
-void draw_mline(int mode, int row, int start, int cols,
-               struct file fm, struct file fb, struct file fa,
-               struct merge *m,
-               struct mpos pos,
-               int target, int *colp)
+static void draw_mline(int mode, int row, int start, int cols,
+                      struct file fm, struct file fb, struct file fa,
+                      struct merge *m,
+                      struct mpos pos,
+                      int target, int *colp)
 {
        /*
         * Draw the left and right images of this line
@@ -855,9 +860,7 @@ void draw_mline(int mode, int row, int start, int cols,
                           fm,fb,fa,m, pos, target, colp);
 }
 
-extern void cleanlist(struct file a, struct file b, struct csl *list);
-
-char *merge_help[] = {
+static char *merge_help[] = {
        "This view shows a the merge of the patch with the",
        "original file.  It is like a full-context diff showing",
        "removed lines with a '-' prefix and added lines with a",
@@ -876,7 +879,7 @@ char *merge_help[] = {
        "why there was a conflict",
        NULL
 };
-char *diff_help[] = {
+static char *diff_help[] = {
        "This is the 'diff' or 'patch' view.  It shows",
        "only the patch that is being applied without the",
        "original to which it is being applied.",
@@ -885,14 +888,14 @@ char *diff_help[] = {
        "original.",
        NULL
 };
-char *orig_help[] = {
+static char *orig_help[] = {
        "This is the 'original' view which simple shows",
        "the original file before applying the patch.",
        "Sections of code that would be changed by the patch",
        "are highlighted in red.",
        NULL
 };
-char *result_help[] = {
+static char *result_help[] = {
        "This is the 'result' view which show just the",
        "result of applying the patch.  When a conflict",
        "occurred this view does not show the full conflict",
@@ -901,7 +904,7 @@ char *result_help[] = {
        "views.",
        NULL
 };
-char *before_help[] = {
+static char *before_help[] = {
        "This view shows the 'before' section of a patch.",
        "It allows the expected match text to be seen uncluttered",
        "by text that is meant to replaced it."
@@ -909,7 +912,7 @@ char *before_help[] = {
        "removed by the patch",
        NULL
 };
-char *after_help[] = {
+static char *after_help[] = {
        "This view shows the 'after' section of a patch.",
        "It allows the intended result to be seen uncluttered",
        "by text that was meant to be matched and replaced."
@@ -918,7 +921,7 @@ char *after_help[] = {
        "part of the patch",
        NULL
 };
-char *sidebyside_help[] = {
+static char *sidebyside_help[] = {
        "This is the Side By Side view of a patched file.",
        "The left side shows the original and the result.",
        "The right side shows the patch which was applied",
@@ -930,7 +933,7 @@ char *sidebyside_help[] = {
        "yellow family (depending on your terminal window).",
        NULL
 };
-char *merge_window_help[] = {
+static char *merge_window_help[] = {
        "  Highlight Colours and Keystroke commands",
        "",
        "In all different views of a merge, highlight colours",
@@ -987,7 +990,8 @@ char *merge_window_help[] = {
        " |                   display side-by-side view",
        NULL
 };
-void merge_window(struct plist *p, FILE *f, int reverse)
+
+static void merge_window(struct plist *p, FILE *f, int reverse)
 {
        /* display the merge in two side-by-side
         * panes.
@@ -1585,8 +1589,8 @@ void merge_window(struct plist *p, FILE *f, int reverse)
        }
 }
 
-void show_merge(char *origname, FILE *patch, int reverse, int is_merge,
-               char *before, char *after)
+static void show_merge(char *origname, FILE *patch, int reverse,
+                      int is_merge, char *before, char *after)
 {
        struct plist p;
 
@@ -1605,8 +1609,8 @@ void show_merge(char *origname, FILE *patch, int reverse, int is_merge,
        merge_window(&p, patch, reverse);
 }
 
-struct plist *patch_add_file(struct plist *pl, int *np, char *file,
-              unsigned int start, unsigned int end)
+static struct plist *patch_add_file(struct plist *pl, int *np, char *file,
+                                   unsigned int start, unsigned int end)
 {
        /* size of pl is 0, 16, n^2 */
        int n = *np;
@@ -1648,7 +1652,7 @@ struct plist *patch_add_file(struct plist *pl, int *np, char *file,
        return pl;
 }
 
-struct plist *parse_patch(FILE *f, FILE *of, int *np)
+static struct plist *parse_patch(FILE *f, FILE *of, int *np)
 {
        /* read a multi-file patch from 'f' and record relevant
         * details in a plist.
@@ -1736,15 +1740,14 @@ static struct stream load_segment(FILE *f,
        return s;
 }
 
-
-int pl_cmp(const void *av, const void *bv)
+static int pl_cmp(const void *av, const void *bv)
 {
        const struct plist *a = av;
        const struct plist *b = bv;
        return strcmp(a->file, b->file);
 }
 
-int common_depth(char *a, char *b)
+static int common_depth(char *a, char *b)
 {
        /* find number of path segments that these two have
         * in common
@@ -1768,7 +1771,7 @@ int common_depth(char *a, char *b)
        }
 }
 
-struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr)
+static struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr)
 {
        /* any parent of file that is not a parent of curr
         * needs to be added to pl
@@ -1799,7 +1802,7 @@ struct plist *add_dir(struct plist *pl, int *np, char *file, char *curr)
        return pl;
 }
 
-struct plist *sort_patches(struct plist *pl, int *np)
+static struct plist *sort_patches(struct plist *pl, int *np)
 {
        /* sort the patches, add directory names, and re-sort */
        char curr[1024];
@@ -1843,7 +1846,7 @@ struct plist *sort_patches(struct plist *pl, int *np)
  * paths to find them from current directory.  This is
  * used to guess correct '-p' value.
  */
-int get_strip(char *file)
+static int get_strip(char *file)
 {
        int fd;
        int strip = 0;
@@ -1864,7 +1867,7 @@ int get_strip(char *file)
 
 }
 
-int set_prefix(struct plist *pl, int n, int strip)
+static int set_prefix(struct plist *pl, int n, int strip)
 {
        int i;
        for(i=0; i<4 && i<n  && strip < 0; i++)
@@ -1892,7 +1895,7 @@ int set_prefix(struct plist *pl, int n, int strip)
        return 1;
 }
 
-void calc_one(struct plist *pl, FILE *f, int reverse)
+static void calc_one(struct plist *pl, FILE *f, int reverse)
 {
        struct stream s1, s2;
        struct stream s = load_segment(f, pl->start, pl->end);
@@ -1941,7 +1944,7 @@ void calc_one(struct plist *pl, FILE *f, int reverse)
        pl->calced = 1;
 }
 
-int get_prev(int pos, struct plist *pl, int n, int mode)
+static int get_prev(int pos, struct plist *pl, int n, int mode)
 {
        int found = 0;
        if (pos == -1) return pos;
@@ -1965,7 +1968,7 @@ int get_prev(int pos, struct plist *pl, int n, int mode)
        return pos;
 }
 
-int get_next(int pos, struct plist *pl, int n, int mode,
+static int get_next(int pos, struct plist *pl, int n, int mode,
             FILE *f, int reverse)
 {
        int found = 0;
@@ -1997,8 +2000,7 @@ int get_next(int pos, struct plist *pl, int n, int mode,
        return pos;
 }
 
-
-void draw_one(int row, struct plist *pl, FILE *f, int reverse)
+static void draw_one(int row, struct plist *pl, FILE *f, int reverse)
 {
        char hdr[12];
        hdr[0] = 0;
@@ -2035,7 +2037,7 @@ void draw_one(int row, struct plist *pl, FILE *f, int reverse)
        clrtoeol();
 }
 
-char *main_help[] = {
+static char *main_help[] = {
        "   You are using the \"browse\" mode of wiggle.",
        "This page shows a list of files in a patch together with",
        "the directories that contain them.",
@@ -2066,7 +2068,8 @@ char *main_help[] = {
        "  C          only list files with a conflict",
        NULL
 };
-void main_window(struct plist *pl, int n, FILE *f, int reverse)
+
+static void main_window(struct plist *pl, int n, FILE *f, int reverse)
 {
        /* The main window lists all files together with summary information:
         * number of chunks, number of wiggles, number of conflicts.
@@ -2215,9 +2218,7 @@ void main_window(struct plist *pl, int n, FILE *f, int reverse)
        }
 }
 
-
-
-void catch(int sig)
+static void catch(int sig)
 {
        if (sig == SIGINT) {
                signal(sig, catch);
@@ -2321,6 +2322,10 @@ int vpatch(int argc, char *argv[], int patch, int strip,
                }
                /* use stderr for keyboard input */
                dup2(2,0);
+               if (set_prefix(pl, num_patches, strip) == 0) {
+                       fprintf(stderr, "%s: aborting\n", Cmd);
+                       exit(2);
+               }
                main_window(pl, num_patches, in, reverse);
                break;
 
@@ -2332,6 +2337,10 @@ int vpatch(int argc, char *argv[], int patch, int strip,
                }
                if (patch) {
                        pl = parse_patch(f, NULL, &num_patches);
+                       if (set_prefix(pl, num_patches, strip) == 0) {
+                               fprintf(stderr, "%s: aborting\n", Cmd);
+                               exit(2);
+                       }
                        main_window(pl, num_patches, f, reverse);
                } else if (strlen(argv[0]) > 4 &&
                         strcmp(argv[0]+strlen(argv[0])-4, ".rej") == 0) {
index 8615c1d1d2c59cc113f9175419ff4359854f49f6..b3ca73924b98bf6f0e198fb6815706c327c3a285 100644 (file)
--- a/wiggle.c
+++ b/wiggle.c
@@ -110,10 +110,11 @@ static void printsep(struct elmnt e1, struct elmnt e2)
 }
 
 
+#if 0
 /* Remove any entries from the common-sublist that are
  * just spaces, tabs, or newlines
  */
-void cleanlist(struct file a, struct file b, struct csl *list)
+static void cleanlist(struct file a, struct file b, struct csl *list)
 {
        struct csl *new = list;
 
@@ -136,6 +137,7 @@ void cleanlist(struct file a, struct file b, struct csl *list)
        }
        *new = *list;
 }
+#endif
 
 int main(int argc, char *argv[])
 {
index 7ce0a754488d05594aa51d3a55bbd37261bf330e..15a75b5d0c3124570f761ce7f4d9856af052dfcd 100644 (file)
--- a/wiggle.h
+++ b/wiggle.h
@@ -144,6 +144,7 @@ extern char HelpDiff[];
 extern char HelpMerge[];
 extern char HelpBrowse[];
 
+extern void cleanlist(struct file a, struct file b, struct csl *list);
 
 #define        ByLine  0
 #define        ByWord  1