~ubuntu-branches/ubuntu/raring/whichman/raring

« back to all changes in this revision

Viewing changes to debian/patches/10_skip_duplicates.patch

  • Committer: Package Import Robot
  • Author(s): Robert Luberda
  • Date: 2012-02-19 16:05:46 UTC
  • Revision ID: package-import@ubuntu.com-20120219160546-nd61zqumiov4zvbl
Tags: 2.4-7
* Switch to debhelper v9 and tiny rules file.
* Rename & refresh patches with gbp-pq import/export.
* Fix lintian's `spelling-error-in-copyright'.
* debian/rules: remove .pc/.dpkg-source-unapply file in rules.
  This fixes broken behaviour of dpkg-buildpackage (see Bug#649521).
* debian/control:
  + Standards-Version: 3.9.2 (no changes);
  + add VCS fields;
  + sort dependency fields with wrap-and-sort.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Patch for #452068: wanted: 'ftwhich' option to not print links or symlinks 
2
 
 
3
 
diff -Nur whichman-2.4.old/ftwhich.c whichman-2.4/ftwhich.c
4
 
--- whichman-2.4.old/ftwhich.c  2001-05-04 22:56:04.000000000 +0200
5
 
+++ whichman-2.4/ftwhich.c      2008-01-27 14:46:54.000000000 +0100
6
 
@@ -11,6 +11,7 @@
7
 
 #include <ctype.h>
8
 
 #include <stdlib.h>
9
 
 #include "levdist.h"
10
 
+#include "statduplcheck.h"
11
 
 
12
 
 static void help();
13
 
 static char **splitpath();
14
 
@@ -125,6 +126,9 @@
15
 
                matchfilename(*pathcomp, searchkey);
16
 
                pathcomp++;
17
 
        }
18
 
+
19
 
+        free_statduplicates();
20
 
+
21
 
        return (nomatchfound);
22
 
 }
23
 
 /*__END OF MAIN__*/
24
 
@@ -161,8 +165,9 @@
25
 
         if ((stbuf.st_mode & S_IFREG)==0) return(0);
26
 
         /* test if executable for user or grp or others */
27
 
         if ((stbuf.st_mode & S_IXUSR) || (stbuf.st_mode & S_IXGRP)\
28
 
-                ||(stbuf.st_mode & S_IXOTH)) return(1);
29
 
-        return(0);
30
 
+                ||(stbuf.st_mode & S_IXOTH))
31
 
+                if (is_statduplicate(&stbuf)) return(0); 
32
 
+        return(1);
33
 
 }
34
 
 /*
35
 
  * match all entries in the directory variable path points to
36
 
diff -Nur whichman-2.4.old/Makefile whichman-2.4/Makefile
37
 
--- whichman-2.4.old/Makefile   2008-01-27 14:45:55.000000000 +0100
38
 
+++ whichman-2.4/Makefile       2008-01-27 14:46:54.000000000 +0100
39
 
@@ -14,11 +14,11 @@
40
 
 
41
 
 all:whichman ftff ftwhich
42
 
 
43
 
-whichman: whichman.o levdist.o
44
 
-       $(CC) -o $@ whichman.o levdist.o
45
 
+whichman: whichman.o levdist.o statduplcheck.o
46
 
+       $(CC) -o $@ whichman.o levdist.o statduplcheck.o
47
 
 
48
 
-ftwhich: ftwhich.o levdist.o
49
 
-       $(CC) -o $@ ftwhich.o levdist.o
50
 
+ftwhich: ftwhich.o levdist.o statduplcheck.o
51
 
+       $(CC) -o $@ ftwhich.o levdist.o statduplcheck.o
52
 
 
53
 
 ftff: ftff.o levdist.o 
54
 
        $(CC) -o $@ ftff.o levdist.o
55
 
@@ -31,6 +31,8 @@
56
 
        $(CC) $(CFLAGS) -c ftff.c
57
 
 levdist.o: levdist.c levdist.h
58
 
        $(CC) $(CFLAGS) -c levdist.c
59
 
+statduplcheck.o: statduplcheck.c statduplcheck.h       
60
 
+       $(CC) $(CFLAGS) -c statduplcheck.c
61
 
 
62
 
 install: whichman ftff ftwhich $(MANP)
63
 
        $(STRIP) whichman
64
 
diff -Nur whichman-2.4.old/statduplcheck.c whichman-2.4/statduplcheck.c
65
 
--- whichman-2.4.old/statduplcheck.c    1970-01-01 01:00:00.000000000 +0100
66
 
+++ whichman-2.4/statduplcheck.c        2008-01-27 14:46:54.000000000 +0100
67
 
@@ -0,0 +1,84 @@
68
 
+#define _GNU_SOURCE   /* for tdestroy */
69
 
+#include "statduplcheck.h"
70
 
+#include <malloc.h>
71
 
+#include <stdio.h>
72
 
+#include <stdlib.h>
73
 
+#include <string.h>
74
 
+#include <search.h>
75
 
+
76
 
+struct stat_info {
77
 
+       dev_t     st_dev;   
78
 
+       ino_t     st_ino;
79
 
+};
80
 
+
81
 
+static void * info_root = NULL;
82
 
+
83
 
+/* compare function passed to tsearch */
84
 
+static int stat_info_compare(const void *si1, const void * si2)
85
 
+{
86
 
+       int res;
87
 
+       
88
 
+       res = ((struct stat_info*)si1)->st_dev - ((struct stat_info*)si2)->st_dev;
89
 
+       if (!res)
90
 
+               res = ((struct stat_info*)si1)->st_ino - ((struct stat_info*)si2)->st_ino;
91
 
+       return res;
92
 
+}
93
 
+
94
 
+int is_statduplicate(const struct stat *st) {
95
 
+       static struct stat_info * stinfo = NULL;
96
 
+       struct stat_info ** res;
97
 
+
98
 
+       if (!stinfo) {
99
 
+               stinfo = (struct stat_info*) malloc (sizeof(*stinfo));
100
 
+
101
 
+               if (!stinfo) {
102
 
+                       fprintf(stderr, "cannot allocate memory\n");
103
 
+                       exit(1);
104
 
+               }
105
 
+
106
 
+       }
107
 
+
108
 
+       stinfo->st_dev = st->st_dev;
109
 
+       stinfo->st_ino = st->st_ino;
110
 
+
111
 
+       if (!(res = tsearch(stinfo, &info_root, stat_info_compare))) {
112
 
+               fprintf(stderr, "cannot allocate memory\n");
113
 
+               exit(1);
114
 
+       }
115
 
+
116
 
+       if (*res == stinfo) {
117
 
+               // new record
118
 
+               stinfo = NULL;
119
 
+               return 0;
120
 
+       }               
121
 
+
122
 
+       return 1;
123
 
+}
124
 
+
125
 
+int is_fileduplicate(const char *dir, const char *name) {
126
 
+       static struct stat stbuf;
127
 
+       static char fullpath[255];
128
 
+
129
 
+       if (strlen(dir) + strlen(name) + 2 > sizeof(fullpath)) return (-1);
130
 
+       strcpy(fullpath, dir);
131
 
+       strcat(fullpath, "/");
132
 
+       strcat(fullpath, name);
133
 
+
134
 
+        if (stat(fullpath,&stbuf)!=0) return(-1); /* file does not exists */
135
 
+       
136
 
+       return is_statduplicate(&stbuf);
137
 
+
138
 
+}
139
 
+
140
 
+void free_statduplicates(void) {
141
 
+       
142
 
+       if (!info_root) return;
143
 
+
144
 
+       tdestroy(info_root, free);
145
 
+       info_root = NULL;
146
 
+
147
 
+}
148
 
+
149
 
+
150
 
+
151
 
+
152
 
diff -Nur whichman-2.4.old/statduplcheck.h whichman-2.4/statduplcheck.h
153
 
--- whichman-2.4.old/statduplcheck.h    1970-01-01 01:00:00.000000000 +0100
154
 
+++ whichman-2.4/statduplcheck.h        2008-01-27 14:46:54.000000000 +0100
155
 
@@ -0,0 +1,11 @@
156
 
+#ifndef STATDUPLCHECK_H
157
 
+#define STATDUPLCHECK_H
158
 
+
159
 
+#include <sys/stat.h>
160
 
+
161
 
+extern int is_statduplicate(const struct stat *st); 
162
 
+extern int is_fileduplicate(const char *dir, const char *name); 
163
 
+extern void free_statduplicates(void);
164
 
+
165
 
+
166
 
+#endif
167
 
diff -Nur whichman-2.4.old/whichman.c whichman-2.4/whichman.c
168
 
--- whichman-2.4.old/whichman.c 2008-01-27 14:45:55.000000000 +0100
169
 
+++ whichman-2.4/whichman.c     2008-01-27 14:46:54.000000000 +0100
170
 
@@ -11,6 +11,7 @@
171
 
 #include <ctype.h>
172
 
 #include <stdlib.h>
173
 
 #include "levdist.h"
174
 
+#include "statduplcheck.h"
175
 
 
176
 
 static void help();
177
 
 static char **splitman();
178
 
@@ -143,6 +144,8 @@
179
 
                findmandir(*pathcomp, searchkey);
180
 
                pathcomp++;
181
 
        }
182
 
+
183
 
+        free_statduplicates();
184
 
        return (nomanfilefound);
185
 
 }
186
 
 /*__END OF MAIN__*/
187
 
@@ -249,7 +252,7 @@
188
 
                         /* xxxxx.1.gz ->xxxxx :*/
189
 
                         manname=removemanextesions(entry->d_name); 
190
 
                         d=stringmatch(manname,key);
191
 
-                        if (d != -1){
192
 
+                        if (d != -1 && !is_fileduplicate(path, entry->d_name) ){
193
 
                                 if (printdist) printf("%03d ",d);
194
 
                                 printf("%s/%s\n", path, entry->d_name);
195
 
                                 nomanfilefound = 0;