summaryrefslogtreecommitdiff
path: root/sys-apps/darwin-miscutils/files/darwin-miscutils-12-md-modern-c.patch
blob: 2e6dcdb50d4b6e3f451eafd9a1c9c1e7fc623878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
md: bring up to date for modern C to allow Clang and recent GCC to compile

Authors:
Michael Weiser, https://bugs.gentoo.org/642666
Alexey Sokolov, https://bugs.gentoo.org/758167
Fabian Groffen

--- adv_cmds-147/md/md.c
+++ adv_cmds-147/md/md.c
@@ -78,6 +78,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #define LINESIZE 65536  //  NeXT_MOD
 
@@ -100,6 +102,7 @@
 } dep_files[1000];
 int dep_file_index;
 
+static int
 qsort_strcmp(a, b)
 struct dep *a, *b;
 {
@@ -137,9 +140,15 @@
 
 static void scan_mak(FILE *, FILE *, char *);
 static void finish_mak(FILE *, FILE *);
+static int read_dep(char *);
+static void expunge_mak(FILE *, FILE *);
+static void skip_mak(FILE *, FILE *);
+static void output_dep(FILE *);
+static void parse_dep();
+static void save_dot_o();
 
-main(argc,argv)
-register char **argv;
+int
+main(int argc, char** argv)
 {
 int size;
 
@@ -152,7 +161,7 @@
                 if (*token++ != '-' || !*token)
                         break;
                 else { register int flag;
-                        for ( ; flag = *token++ ; ) {
+                        for ( ; (flag = *token++) ; ) {
                                 switch (flag) {
                                 case 'd':
                                         delete++;
@@ -177,7 +186,7 @@
                                         expunge++;
                                         break;
                                 case 'D':
-                                        for ( ; flag = *token++ ; )
+                                        for ( ; (flag = *token++) ; )
                                                 switch (flag) {
                                                 case 'c':
                                                         D_contents++;
@@ -211,10 +220,10 @@
         }
 
         if (!expunge && argc < 1) goto usage;
-        if ((int) outfile && (int) makefile)    /* not both */
+        if (outfile && makefile)    /* not both */
                 goto usage;
 
-        if ((int) outfile) {
+        if (outfile) {
                 /*
                  * NeXT_MOD, For SGS stuff, in case still linked to master version
                  */
@@ -227,7 +236,7 @@
                         exit(1);
                 } else if (D_open)
                         printf("%s: opened outfile \"%s\"\n", name, outfile);
-        } else if (mak = find_mak(makefile)) {
+        } else if ((mak = find_mak(makefile))) {
                 makout = temp_mak();
                 out = makout;
                 if (expunge)
@@ -235,7 +244,7 @@
                 else
                         skip_mak(mak, makout);
         } else if (mak_eof &&  /* non existent file == mt file */
-                   (int)(makout = temp_mak())) { /* but we need to be able */
+                   (makout = temp_mak()) != NULL) { /* but we need to be able */
                 out = makout;                    /* to write here */
         } else if (makefile) {
                 fprintf(stderr, "%s: makefile \"%s\" can not be opened or stat'ed\n",
@@ -246,7 +255,7 @@
         for (; argc--; argv++) {
                 dep_file_index = 0;
 
-                if (size = read_dep(*argv)) {
+                if ((size = read_dep(*argv))) {
 
                         save_dot_o();
                         if (D_depend) printf("%s: dot_o = \"%s\"\n", name, dot_o);
@@ -269,8 +278,8 @@
 }
 
 
-read_dep(file)
-register char *file;
+int
+read_dep(char *file)
 {
 register int fd;
 register int size;
@@ -294,7 +303,7 @@
         switch(statbuf.st_mode & S_IFMT) {
         case S_IFREG:
                 if (D_time)
-                        printf("%s: file time = %d\n", name, statbuf.st_mtime);
+                        printf("%s: file time = %ld\n", name, statbuf.st_mtime);
 
                 if (statbuf.st_size > IObuffer) {
                         fprintf(stderr, "%s: file \"%s\" tooo big for IObuffer\n",
@@ -302,9 +311,9 @@
                         goto out;
                 } else if (force)
                         break;
-                else if ((int) mak && statbuf.st_mtime < makstat.st_mtime) {
+                else if (mak && statbuf.st_mtime < makstat.st_mtime) {
                         if (verbose || D_time)
-                                fprintf(stderr, "%s: skipping \"%s\" %d < %d \"%s\"\n",
+                                fprintf(stderr, "%s: skipping \"%s\" %ld < %ld \"%s\"\n",
                                         name, file, statbuf.st_mtime, makstat.st_mtime,
                                         real_mak_name);
                         goto out;
@@ -345,6 +354,7 @@
         return 0;
 }
 
+static void
 save_dot_o()
 {
 register char *cp = file_array;
@@ -355,6 +365,7 @@
         *svp = 0;
 }
 
+static void
 parse_dep()
 {
 register char *lp = file_array;
@@ -381,7 +392,8 @@
                 cp = dep_line;
                 lp[-1] = 0;
                         /* skip .o file name */
-                while ((c = *cp++) && c != ':'); if (!c) continue;
+                while ((c = *cp++) && c != ':');
+		if (!c) continue;
 next_filename:
                 i = 0;
                 abspath = 0;
@@ -415,7 +427,7 @@
                 if (abspath)
                         *cp++ = '/';
                 for (c=0; c<i; c++) {register char *ccp = path_component[c];
-                        while (*cp++ = *ccp++);
+                        while ((*cp++ = *ccp++));
                         *--cp = '/';
                         cp++;
                 }
@@ -425,7 +437,7 @@
                 dep_files[c].str = tlp;
                 dep_files[c].len = cp - tlp;
                 if (D_depend)
-                        printf("%s: dep_file[%d] = \"%s\" Len %d\n",
+                        printf("%s: dep_file[%d] = \"%s\" Len %ld\n",
                                 name, dep_file_index - 1, tlp, cp - tlp);
                 tlp = cp + 1;
                 if (oldc)
@@ -436,8 +448,8 @@
         }
 }
 
-output_dep(out)
-FILE *out;
+static void
+output_dep(FILE *out)
 {
 register int j;
 register int size = 1000;
@@ -479,12 +491,11 @@
 
                 /* process makefile */
 FILE *
-find_mak(file)
-char *file;
+find_mak(char *file)
 {
 FILE *mak;
 
-        if ((int) file) {
+        if (file) {
                 if ((mak = fopen(file, "r")) != NULL) {
                         real_mak_name = file;
                 } else if (update) {
@@ -514,7 +525,7 @@
         if (D_open)
                 printf("%s: opened makefile \"%s\"\n", name, real_mak_name);
         if (D_time)
-                printf("%s: makefile time = %d\n", name, makstat.st_mtime);
+                printf("%s: makefile time = %ld\n", name, makstat.st_mtime);
 
         return mak;
 }
@@ -543,8 +554,8 @@
         return mak;
 }
 
-skip_mak(makin, makout)
-register FILE *makin, *makout;
+static void
+skip_mak(FILE *makin, FILE *makout)
 {
 register int len = SALUTATIONLEN;
 
@@ -566,8 +577,8 @@
                 printf("eof = %d str = \"%s\"", mak_eof, makbuf);
 }
 
-expunge_mak(makin, makout)
-register FILE *makin, *makout;
+static void
+expunge_mak(FILE *makin, FILE *makout)
 {
 register int len = SALUTATIONLEN;
 register int oldlen = OLDSALUTATIONLEN;