00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #ifdef __MSDOS__
00016 #include <alloc.h>
00017 #else
00018 #include <malloc.h>
00019 #endif
00020 #include <ctype.h>
00021 #include <string.h>
00022 #ifdef KEY
00023 #include <stdlib.h>
00024 #endif
00025
00026 typedef struct ENT
00027 {
00028 struct ENT *next;
00029 char *dos_name;
00030 char *full_name;
00031 char *path;
00032 int tagged;
00033 } ENT;
00034
00035 ENT *eroot = 0;
00036
00037 int first_inv = 1;
00038 int first_msg = 1;
00039
00040
00041
00042
00043
00044 void
00045 invalid_msg ()
00046 {
00047 if (first_inv)
00048 {
00049 if (first_msg)
00050 first_msg = 0;
00051 else
00052 putchar ('\n');
00053 printf ("The following files are not valid DOS file names:\n");
00054 first_inv = 0;
00055 }
00056 }
00057
00058 ENT *
00059 alloc_ent ()
00060 {
00061 ENT *rv = (ENT *)malloc (sizeof (ENT));
00062 if (rv == 0)
00063 {
00064 fprintf (stderr, "Unable to allocate memory for an ENT\n");
00065 exit (1);
00066 }
00067 memset (rv, 0, sizeof (ENT));
00068 return rv;
00069 }
00070
00071 void
00072 fill_ent (ent, path)
00073 ENT *ent;
00074 char *path;
00075 {
00076 char *first = path;
00077 char *null = path+strlen (path);
00078 char *last_slash = strrchr (path, '/');
00079 char *cp, *dp;
00080 int dots_seen, chars_seen;
00081
00082 if (last_slash+1 == null)
00083 {
00084 * --null = '\0';
00085 last_slash = strrchr (path, '/');
00086 }
00087
00088 if (!last_slash)
00089 {
00090 last_slash = first-1;
00091 }
00092
00093 if (null-last_slash < 13)
00094 ent->dos_name = (char *)malloc (null-last_slash);
00095 else
00096 ent->dos_name = (char *)malloc (13);
00097 ent->full_name = (char *)malloc (null-last_slash);
00098 ent->path = (char *)malloc (last_slash-first+1);
00099
00100 strcpy (ent->full_name, last_slash+1);
00101 if (last_slash > first)
00102 {
00103 strncpy (ent->path, first, last_slash-first);
00104 ent->path[last_slash-first] = '\0';
00105 }
00106 else
00107 *ent->path = '\0';
00108
00109 cp = last_slash+1;
00110 dp = ent->dos_name;
00111 dots_seen = 0;
00112 chars_seen = 0;
00113 while (1)
00114 {
00115 if (! *cp)
00116 break;
00117 switch (*cp)
00118 {
00119 case '.':
00120 if (cp == last_slash+1 && strcmp (last_slash+1, "."))
00121 {
00122 invalid_msg ();
00123 printf ("%s - file name cannot start with dot\n", path);
00124 *dp = 0;
00125 break;
00126 }
00127 if (dots_seen == 1)
00128 {
00129 invalid_msg ();
00130 printf ("%s - too many dots\n", path);
00131 *dp = '\0';
00132 break;
00133 }
00134 *dp++ = '.';
00135 chars_seen = 0;
00136 dots_seen++;
00137 break;
00138 case '"':
00139 case '*':
00140 case '+':
00141 case ',':
00142 case ';':
00143 case '<':
00144 case '=':
00145 case '>':
00146 case '?':
00147 case '[':
00148 case '\\':
00149 case ']':
00150 case '|':
00151 invalid_msg ();
00152 printf ("%s - invalid character `%c'\n", path, *cp);
00153 *dp++ = '?';
00154 chars_seen++;
00155 break;
00156 default:
00157 if (dots_seen)
00158 {
00159 if (chars_seen >= 3)
00160 break;
00161 }
00162 else
00163 if (chars_seen >= 8)
00164 break;
00165 if ((*cp <= ' ') || (*cp >= 0x7f))
00166 {
00167 invalid_msg ();
00168 printf ("%s - invalid character `%c'\n", path, *cp);
00169 *dp++ = '?';
00170 chars_seen++;
00171 break;
00172 }
00173 if (islower (*cp))
00174 *dp++ = toupper (*cp);
00175 else
00176 *dp++ = *cp;
00177 chars_seen++;
00178 break;
00179 }
00180 cp++;
00181 }
00182 *dp++ = '\0';
00183 }
00184
00185 int
00186 compare_ent_dosname (e1, e2)
00187 ENT **e1;
00188 ENT **e2;
00189 {
00190 int r = strcmp ((*e1)->dos_name, (*e2)->dos_name);
00191 if (r == 0)
00192 r = strcmp ((*e1)->path, (*e2)->path);
00193 if (r == 0)
00194 r = strcmp ((*e1)->full_name, (*e2)->full_name);
00195 return r;
00196 }
00197
00198 int
00199 compare_ent_fullname (e1, e2)
00200 ENT **e1;
00201 ENT **e2;
00202 {
00203 int r = strncmp ((*e1)->full_name, (*e2)->full_name, 14);
00204 if (r == 0)
00205 r = strcmp ((*e1)->path, (*e2)->path);
00206 if (r == 0)
00207 r = strcmp ((*e1)->full_name, (*e2)->full_name);
00208 return r;
00209 }
00210
00211 char *
00212 mpath (ent)
00213 ENT *ent;
00214 {
00215 static char buf[500];
00216 if (ent->path && ent->path[0])
00217 sprintf (buf, "%s/%s", ent->path, ent->full_name);
00218 else
00219 return ent->full_name;
00220 return buf;
00221 }
00222
00223
00224
00225
00226
00227 void
00228 add_ent (ent)
00229 ENT *ent;
00230 {
00231 ent->next = eroot;
00232 eroot = ent;
00233 }
00234
00235 void
00236 handle_input (line)
00237 char *line;
00238 {
00239 ENT *ent = alloc_ent ();
00240 fill_ent (ent, line);
00241 add_ent (ent);
00242 }
00243
00244 void
00245 display_problems ()
00246 {
00247 ENT **elist, *ent;
00248 int ecount, i, first, first_err;
00249
00250 for (ecount=0, ent=eroot; ent; ent=ent->next, ecount++);
00251 elist = (ENT **)malloc (sizeof (ENT *) * ecount);
00252 for (ecount=0, ent=eroot; ent; ent=ent->next, ecount++)
00253 elist[ecount] = ent;
00254
00255 qsort (elist, ecount, sizeof (ENT *), compare_ent_dosname);
00256
00257 first = 1;
00258 first_err = 1;
00259 for (i=0; i<ecount-1; i++)
00260 {
00261 if ((strcmp (elist[i]->dos_name, elist[i+1]->dos_name) == 0)
00262 && (strcmp (elist[i]->path, elist[i+1]->path) == 0))
00263 {
00264 if (first_err)
00265 {
00266 if (first_msg)
00267 first_msg = 0;
00268 else
00269 putchar ('\n');
00270 printf ("The following resolve to the same DOS file names:\n");
00271 first_err = 0;
00272 }
00273 if (first)
00274 {
00275 printf ("%14s : %s\n", elist[i]->dos_name, mpath (elist[i]));
00276 first = 0;
00277 }
00278 printf ("\t\t %s\n", mpath (elist[i+1]));
00279 }
00280 else
00281 first = 1;
00282 }
00283
00284 qsort (elist, ecount, sizeof (ENT *), compare_ent_fullname);
00285
00286 first = 1;
00287 first_err = 1;
00288 for (i=0; i<ecount-1; i++)
00289 {
00290 if ((strncmp (elist[i]->full_name, elist[i+1]->full_name, 14) == 0)
00291 && (strcmp (elist[i]->path, elist[i+1]->path) == 0))
00292 {
00293 if (first_err)
00294 {
00295 if (first_msg)
00296 first_msg = 0;
00297 else
00298 putchar ('\n');
00299 printf ("The following resolve to the same SysV file names:\n");
00300 first_err = 0;
00301 }
00302 if (first)
00303 {
00304 printf ("%.14s : %s\n", elist[i]->full_name, mpath (elist[i]));
00305 first = 0;
00306 elist[i]->tagged = 1;
00307 }
00308 printf ("\t\t %s\n", mpath (elist[i+1]));
00309 elist[i+1]->tagged = 1;
00310 }
00311 else
00312 first = 1;
00313 }
00314
00315 first_err = 1;
00316 for (i=0; i<ecount; i++)
00317 {
00318 if ((strlen (elist[i]->full_name) > 14) && !elist[i]->tagged)
00319 {
00320 if (first_err)
00321 {
00322 if (first_msg)
00323 first_msg = 0;
00324 else
00325 putchar ('\n');
00326 printf ("The following file names are too long for SysV:\n");
00327 first_err = 0;
00328 }
00329 printf ("%.14s : %s\n", elist[i]->full_name, mpath (elist[i]));
00330 }
00331 }
00332 }
00333
00334
00335
00336
00337
00338 int
00339 main (argc, argv)
00340 int argc;
00341 char **argv;
00342 {
00343 FILE *input = stdin;
00344 if (argc > 1)
00345 {
00346 input = fopen (argv[1], "r");
00347 if (!input)
00348 {
00349 perror (argv[1]);
00350 exit (1);
00351 }
00352 }
00353 while (1)
00354 {
00355 char line[500];
00356 char *lp;
00357 fgets (line, 500, input);
00358 if (feof (input))
00359 break;
00360 lp = line+strlen (line);
00361 while ((lp != line) && (*lp <= ' '))
00362 lp--;
00363 lp[1] = 0;
00364 handle_input (line);
00365 }
00366 display_problems ();
00367 }
00368