2 *** SetRev.c Set revision number due to the Amiga guidelines
4 *** This is a small BumpRev replacement (yes, yet another :-).
5 *** Unlike BumpRev, UpRev and others this doesn't need to use
6 *** a special revision file. Instead it scans a source file for
7 *** certain patterns which are replaced.
10 *** Author: Jochen Wiedmann
15 *** Phone: (49)7123 / 14881
16 *** Internet: jochen.wiedmann@zdv.uni-tuebingen.de
19 *** This program is in the public domain; use it as you want,
20 *** but WITHOUT ANY WARRANTY!
25 *** These are the patterns that will be replaced.
29 #define DATE "11.05.2011"
30 #define VERS "SetRev 1.4"
31 #define VSTRING "SetRev 1.4 (11.05.2011)"
32 #define VERSTAG "\0$VER: SetRev 1.4 (11.05.2011)"
33 const char *const VersionString
=VERSTAG
;
48 #define stricmp strcasecmp
49 #define strnicmp strncasecmp
65 *** SetRev cannot scan files with lines longer than MAXLINE character.
75 int CurrentVersion
= 1;
76 int CurrentRevision
= 1;
87 *** This function determines the current name, version
90 void FirstScan(char *file
)
96 if (!(fh
= fopen(file
, "r")))
101 *** File doesn't exist, create it.
103 if (!(fh
= fopen(file
, "w")))
110 "#define VERSION %d\n",
111 CurrentVersion
) < 0 ||
113 "#define REVISION %d\n",
114 CurrentRevision
) < 0 ||
116 "#define DATE \"%s\"\n",
119 "#define VERS \"%s %d.%d\"\n",
120 CurrentName
, CurrentVersion
,
121 CurrentRevision
) < 0 ||
123 "#define VSTRING \"%s %d.%d (%s)\\r\\n\"\n",
124 CurrentName
, CurrentVersion
,
125 CurrentRevision
, CurrentDate
) < 0 ||
127 "#define VERSTAG \"\\0%sVER: %s %d.%d (%s)\"\n",
128 "$", /* Prevent "version" command from using the */
130 CurrentName
, CurrentVersion
,
131 CurrentRevision
, CurrentDate
) < 0 ||
147 while(fgets(line
, MAXLINE
, fh
) && !errno
)
149 int len
= strlen(line
);
151 if (len
+1 == MAXLINE
&& line
[MAXLINE
-2] != '\n')
154 "SetRev warning: Line %d exceeds %d characters\n",
158 if (strncmp(line
, "#define", 7) == 0)
162 while (*ptr
== ' ' || *ptr
== '\t')
167 if (strncmp(ptr
, "VERSION", 7) == 0 &&
168 (ptr
[7] == ' ' || ptr
[7] == '\t'))
170 CurrentVersion
= atoi(&ptr
[7]);
172 else if (strncmp(ptr
, "REVISION", 8) == 0 &&
173 (ptr
[8] == ' ' || ptr
[8] == '\t'))
175 CurrentRevision
= atoi(&ptr
[8]);
179 if (line
[len
-1] == '\n')
192 *** This function inserts the new version, revision,
193 *** projectname and other stuff in a second scan.
195 void SecondScan(char *file
)
202 if (!(bakfile
= malloc(strlen(file
)+5)))
207 strcpy(bakfile
, file
);
208 strcat(bakfile
, ".bak");
210 if (!(fh
= fopen(file
, "r")) || !(bfh
= fopen(bakfile
, "w")))
217 while(fgets(line
, MAXLINE
, fh
) && !errno
)
219 int len
= strlen(line
);
221 if (len
+1 == MAXLINE
&& line
[MAXLINE
-2] != '\n')
224 "SetRev warning: Line %d exceeds %d characters\n",
228 if (strncmp(line
, "#define", 7) == 0)
232 while (*ptr
== ' ' || *ptr
== '\t')
237 if (strncmp(ptr
, "VERSION", 7) == 0 &&
238 (ptr
[7] == ' ' || ptr
[7] == '\t'))
241 while (*ptr
== ' ' || *ptr
== '\t')
245 sprintf(ptr
, "%d\n", CurrentVersion
);
247 else if (strncmp(ptr
, "REVISION", 8) == 0 &&
248 (ptr
[8] == ' ' || ptr
[8] == '\t'))
251 while (*ptr
== ' ' || *ptr
== '\t')
255 sprintf(ptr
, "%d\n", CurrentRevision
);
257 else if (strncmp(ptr
, "DATE", 4) == 0 &&
258 (ptr
[4] == ' ' || ptr
[4] == '\t'))
261 while (*ptr
== ' ' || *ptr
== '\t')
265 sprintf(ptr
, "\"%s\"\n", CurrentDate
);
267 else if (strncmp(ptr
, "VERS", 4) == 0 &&
268 (ptr
[4] == ' ' || ptr
[4] == '\t'))
271 while (*ptr
== ' ' || *ptr
== '\t')
275 sprintf(ptr
, "\"%s %d.%d\"\n", CurrentName
,
276 CurrentVersion
, CurrentRevision
);
278 else if (strncmp(ptr
, "VSTRING", 7) == 0 &&
279 (ptr
[7] == ' ' || ptr
[7] == '\t'))
282 while (*ptr
== ' ' || *ptr
== '\t')
286 sprintf(ptr
, "\"%s %d.%d (%s)\"\n",
287 CurrentName
, CurrentVersion
,
288 CurrentRevision
, CurrentDate
);
290 else if (strncmp(ptr
, "VERSTAG", 7) == 0 &&
291 (ptr
[7] == ' ' || ptr
[7] == '\t'))
294 while (*ptr
== ' ' || *ptr
== '\t')
298 sprintf(ptr
, "\"\\0%sVER: %s %d.%d (%s)\"\n",
300 CurrentName
, CurrentVersion
,
301 CurrentRevision
, CurrentDate
);
310 rename(bakfile
, file
);
318 *** This prints out the Usage: message.
323 printf("Usage: SetRev PROJECT/A,VERSION/N,FILE/K\n\n");
324 printf("The given FILE (default: PROJECT_rev.h) will be searched for\n");
325 printf("version and revision definitions and bumped to the next\n");
326 printf("revision number.\n\n");
327 printf("%s %c 1994 by Jochen Wiedmann\n\n", VSTRING
, 0xa9);
328 printf("This program is in the public domain, use it as you want, but\n");
329 printf("WITHOUT ANY WARRANTY.\n");
340 int main(int argc
, char *argv
[])
345 int versionseen
, version
= 0;
346 time_t currenttime
= time(NULL
);
347 struct tm
*localtm
= localtime(¤ttime
);
352 currenttime
= time(NULL
);
353 localtm
= localtime(¤ttime
);
354 strftime(CurrentDate
, sizeof(CurrentDate
), "%d.%m.%Y", localtm
);
357 strcmp(argv
[1], "?") == 0 ||
358 strcmp(argv
[1], "-h") == 0 ||
359 strcmp(argv
[1], "--help") == 0)
367 for (i
= 1; i
< argc
; i
++)
369 if (stricmp(argv
[i
], "file") == 0 && i
+1 < argc
)
377 else if (strnicmp(argv
[i
], "file=", 5) == 0)
385 else if (!CurrentName
)
387 CurrentName
= argv
[i
];
389 else if (!versionseen
)
391 if ((version
= atoi(argv
[i
])) == 0)
409 if (!(file
= malloc(strlen(CurrentName
) + 7)))
415 strcpy(file
, CurrentName
);
416 strcat(file
, "_rev.h");
421 CurrentVersion
= version
;
428 if (versionseen
&& version
!= CurrentVersion
)
439 CurrentVersion
= version
;