Previous 199869 Revisions Next

r26764 Thursday 26th December, 2013 at 19:24:09 UTC by Couriersud
Updated srcclean source following smf comments. No WN.
[src/tools]srcclean.c

trunk/src/tools/srcclean.c
r26763r26764
3131static UINT8 modified[MAX_FILE_SIZE];
3232
3333
34static int le_convert(char *buffer, int size)
35{
36    char *pos;
37    char *end = buffer + size;
3438
39    /* brute force */
40    *end = 0;
41    pos = strchr(buffer, 0x0d);
42    while (pos != NULL)
43    {
44        memmove(pos, pos+1,end - pos + 1);
45        size--;
46        buffer = pos + 1;
47        pos = strchr(buffer, 0x0d);
48    }
49    return size;
50}
51
3552/***************************************************************************
3653    MAIN
3754***************************************************************************/
r26763r26764
95112   bytes = fread(original, 1, MAX_FILE_SIZE, file);
96113   fclose(file);
97114
115   /* check whether we have dos line endings and are in unix mode */
116   if (unix_le && (strchr((char *) original, 0x0d) != NULL))
117       fixed_dos_style = 1;
118
98119   /* determine if we are a C file */
99120   ext = strrchr(argv[1], '.');
100121   is_c_file = (ext && (core_stricmp(ext, ".c") == 0 || core_stricmp(ext, ".h") == 0 || core_stricmp(ext, ".cpp") == 0 || core_stricmp(ext, ".inc") == 0 || core_stricmp(ext, ".lst") == 0));
r26763r26764
217238         }
218239
219240         /* insert a proper CR/LF */
220         if (!unix_le)
221             modified[dst++] = 0x0d;
241          modified[dst++] = 0x0d;
222242         modified[dst++] = 0x0a;
223243         col = 0;
224244
225245         /* skip over any LF in the source file */
226246         if (ch == 0x0d && original[src] == 0x0a)
227         {
228247                src++;
229                if (unix_le)
230                    fixed_dos_style = 1;
231         }
232248         else if (ch == 0x0a)
233249            fixed_nix_style = 1;
234250         else
r26763r26764
344360      }
345361   }
346362
363    /* convert to unix_le if requested */
364
365    if (unix_le)
366        dst = le_convert((char *) modified, dst);
367
347368   /* if the result == original, skip it */
348369   if (dst != bytes || memcmp(original, modified, bytes))
349370   {
r26763r26764
356377      if (removed_tabs) printf(" removed %d tab(s)", removed_tabs);
357378      if (added_tabs) printf(" added %d tab(s)", added_tabs);
358379      if (hichars) printf(" fixed %d high-ASCII char(s)", hichars);
359      if (fixed_nix_style) printf(" fixed *nix-style line-ends");
380      if (fixed_nix_style && !unix_le) printf(" fixed *nix-style line-ends");
360381      if (fixed_mac_style) printf(" fixed Mac-style line-ends");
361382        if (fixed_dos_style) printf(" fixed Dos-style line-ends");
362383      printf("\n");
363384
364385      /* write the file */
365386      file = fopen(argv[1], "wb");
366      fwrite(modified, 1, dst, file);
387        fwrite(modified, 1, dst, file);
367388      fclose(file);
368389   }
369390

Previous 199869 Revisions Next


© 1997-2024 The MAME Team