source: trunk/dll/internal/renum.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 18 years ago

Indentation cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1#include "stdlib.h"
2#include "stdio.h"
3#include "string.h"
4
5/*
6 * Renumbers a dialog .h include file so that the numbers begin at x
7 * (arbitrary starting number; see below) and increment by 1. If a
8 * blank line is encounted renumbering begins again at x + ((x % 100) + 100).
9 * skips #directives and blank lines (which act as above), but is too
10 * dumb to handle anything else. note lines are "broken" at column 40.
11 * handy when reusing (recombining) junk from other projects to form a
12 * new project.
13 *
14 * TEST BEFORE USING TO DETERMINE APPLICABILITY.
15 *
16 * public domain from M. Kimes.
17 */
18
19int main(int argc, char *argv[])
20{
21
22 static FILE *fpi, *fpo;
23 static int x = 20000; /* arbitrary starting number */
24 static char s[256];
25 static char filein[260], fileout[260];
26 register char *p;
27 register int z;
28
29 printf("\nUsage: renum dlg.h\n Produces new renumbered dlg.h & dlg.bak\n");
30
31 if (argc < 2)
32 strcpy(filein, "FM3DLG.H");
33 else
34 strcpy(filein, argv[1]);
35 strcpy(fileout, filein);
36 p = strrchr(filein, '.');
37 if (p)
38 strcpy(p, ".BAK");
39 else
40 strcat(p, ".BAK");
41 if (!stricmp(filein, fileout)) {
42 printf(" **Error: input file == output file -- \"%s\" == \"%s\"\n",
43 filein, fileout);
44 return 1;
45 }
46
47 remove(filein);
48 rename(fileout, filein);
49 fpi = fopen(filein, "r+");
50 if (fpi) {
51 fpo = fopen(fileout, "w");
52 if (fpo) {
53 while (!feof(fpi)) {
54 if (!fgets(s, 256, fpi))
55 break;
56 if (s[strlen(s) - 1] == '\n')
57 s[strlen(s) - 1] = 0;
58 p = s;
59 while (*p == ' ')
60 p++;
61 if (p != s)
62 memmove(s, p, strlen(p) + 1);
63 if (*s) {
64 p = &s[strlen(s) - 1];
65 while (*p == ' ' && p > s)
66 p--;
67 if (*p == ' ')
68 *p = 0;
69 }
70 if (!*s) {
71 fprintf(fpo, "\n");
72 x = (x - (x % 100)) + 100;
73 }
74 else if ((*s == '#' && strncmp(s, "#define ", 8)) ||
75 !strncmp(s, "/*", 2) || *s == '*')
76 fprintf(fpo, "%s%s\n", (*s == '*') ? " " : "", s);
77 else {
78 s[39] = 0;
79 p = &s[strlen(s) - 1];
80 while (*p == ' ' && p > s)
81 p--;
82 if (*p == ' ')
83 *p = 0;
84 if (*s) {
85 fprintf(fpo, "%s", s);
86 for (z = strlen(s); z < 40; z++)
87 fprintf(fpo, " ");
88 fprintf(fpo, "%d\n", x++);
89 }
90 else
91 fprintf(fpo, "\n");
92 }
93 }
94 fclose(fpo);
95 }
96 else {
97 fclose(fpi);
98 fpi = NULL;
99 rename(filein, fileout);
100 printf(" **Error: couldn't open output file \"%s\"\n", fileout);
101 return 1;
102 }
103 if (fpi)
104 fclose(fpi);
105 }
106 else {
107 rename(filein, fileout);
108 printf(" **Error: couldn't open input file \"%s\"\n", filein);
109 return 1;
110 }
111 printf(" Complete.\n");
112 return 0;
113}
Note: See TracBrowser for help on using the repository browser.