home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * This is SetRev, a BumpRev replacement completely written in extended *
- * ANSI-C. *
- * *
- * Author: Alexander Sieb *
- * Date: 09-Oct-1992 *
- * Source Name: SetRev.c *
- * Object Name: SetRev *
- * Kickstart: 3.0 (39.106) *
- * Workbench: 3.0 (39.39) *
- * Copyright: 1992, 1993 by Alexander Sieb *
- * License: *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
- * *
- * For any help or bug reports contact the author by paper mail *
- * *
- * Alexander Sieb *
- * Karlstr. 5 *
- * 71638 Ludwigsburg *
- * Federal Republic of Germany *
- * *
- * *
- * PROGRAM HISTORY: *
- * *
- * Date Person Action *
- * ----------- ---------- ---------- *
- * 09-Oct-92 A. Sieb First Release v1.01 *
- * 18-Oct-92 A. Sieb Fully rewritten. Now using DOS intern buffered *
- * IO. *
- * Several minor bugs have been fixed *
- * 18-Oct-92 A. Sieb Second Release v1.34 *
- * 25-Oct-92 A. Sieb QUIET option added *
- * MAJOR CHANGE: Version is no longer optional *
- * All standard IO moved to main loop *
- * 26-Oct-92 A. Sieb DEPendency option added. Revision will only be *
- * increased if RevFile is older or has the same *
- * date than the by DEP specified file *
- * Third Release v1.36 *
- * 17-Nov-92 A. Sieb SHOWREV option added for BumpRev compatibility *
- * Error prints will not be affected by QUIET or *
- * SHOWREV option. *
- * QUIET option overrides SHOWREV option *
- * Fourth Release v1.37 *
- * 23-Nov-92 A. Sieb NoC and NoAsm options added. *
- * Fifth Release v1.38 *
- * 16-May-93 A. Sieb Sixth Release v1.39 *
- * VSTRING2 added for use with none ESC String *
- * 01-Aug-93 A. Sieb Seventh Release v1.40 *
- * ANSI C file genration added. *
- * TIME added for creation time output *
- * 12-Sep-93 A. Sieb Eighth Release v1.41 *
- * VersionString identifier added to ANSI C file *
- * generation. *
- * *
- * NOTES: *
- * Program will only run under Kickstart 37.175 and higher *
- * Don't compile this piece of code with resident startup, because *
- * no used global data is cleared. *
- ****************************************************************************/
-
- /* INCLUDEs */
-
- #include <exec/types.h>
- #include <proto/dos.h>
- #include <dos/rdargs.h>
- #include <dos/datetime.h>
- #include <stdlib.h>
- #include <string.h>
-
- /* DEFINEs */
-
- #define EOF (-1)
-
- #define VERSION "1.42"
- #define PRGNAME "SetRev"
- #define DATE "16.01.94"
- /* GLOBALs */
-
- const UBYTE VerTag[] = {"\0$VER: "PRGNAME" "VERSION" ("DATE")"};
-
- UBYTE ObjFile[33];
- UBYTE RevFile[33];
- UBYTE C_Header[33];
- UBYTE ASM_Header[33];
- UBYTE ANSI_C_File[33];
-
- LONG Revision;
- LONG Version;
-
- struct DateTime Date;
- UBYTE DateString[9];
- UBYTE TimeString[9];
-
- struct RDArgs *ShellArgs;
- STRPTR Template = {"REV/N/K,OBJ/K,QUIET/S,DEP/K,SHOWREV/S,NOASM/S,NOC/S,NOANSI/S,VER/N/A,FILE/A"};
- LONG ArgArray[10];
- LONG **Args;
- enum Arguments { revision, object, quiet, dependency, showrev, noasm, noc, noansi, version, file };
-
- /*
- * CompareFileDate().
- * -------------
- * Compare two file creation datestamp for DEPendency option.
- * Returns <0 if c1 is later than c2, 0 if they are equal, >0 if c2 is later
- * c1 than.
- */
-
- LONG CompareFileDate(char *c1, char *c2)
- {
- BPTR l1, l2;
- struct FileInfoBlock *fib1, *fib2;
- LONG res = NULL;
-
- if(l1 = Lock(c1, SHARED_LOCK)) {
- if(l2 = Lock(c2, SHARED_LOCK)) {
- if(fib1 = AllocDosObject(DOS_FIB, NULL)) {
- if(fib2 = AllocDosObject(DOS_FIB, NULL)) {
- if(Examine(l1, fib1)) {
- if(Examine(l2, fib2))
- res = CompareDates(&fib1->fib_Date, &fib2->fib_Date);
- }
- FreeDosObject(DOS_FIB, fib2);
- }
- FreeDosObject(DOS_FIB, fib1);
- }
- UnLock(l2);
- }
- UnLock(l1);
- }
- return(res);
- }
-
- /*
- * GetRevision().
- * -------------
- * Reads current revision number from specified file.
- */
-
- LONG GetRevision(UBYTE *c)
- {
- UBYTE buf[11] = {"\0"};
- UBYTE b = 0;
- UWORD i = 0;
- BPTR f;
- LONG rev = 0;
-
- if(f = Open(c,MODE_OLDFILE)) {
- while(i<11 && (b = FGetC(f))!=EOF)
- buf[i++] = b;
- Close(f);
- rev = atol(buf);
- }
- return(++rev);
- }
-
- /*
- * WriteRevision().
- * ---------------
- * Write revision as non-terminated ASCII string to file and output terminal.
- */
-
- BOOL WriteRevision(UBYTE *c)
- {
- BPTR f;
-
- if(f = Open(c, MODE_NEWFILE)) {
- FPrintf(f,"%ld", Revision);
- Close(f);
- return(TRUE);
- }
- else
- return(FALSE);
- }
-
- /*
- * WriteC().
- * --------
- * Writes the C header file.
- */
-
- BOOL WriteC(void)
- {
- BPTR f;
-
- if(f = Open(C_Header, MODE_NEWFILE)) {
- FPrintf(f,"/* C Headerfile created by "PRGNAME" "VERSION" on %ls at %ls */\n\n", DateString, TimeString);
- FPrintf(f,"#define VERSION %ld\n", Version);
- FPrintf(f,"#define REVISION %ld\n", Revision);
- FPrintf(f,"#define DATE %lc%ls%lc\n", '"', DateString, '"');
- FPrintf(f,"#define TIME %lc%ls%lc\n", '"', TimeString, '"');
- FPrintf(f,"#define VERS %lc%ls %ld.%ld%lc\n", '"', ObjFile, Version, Revision,'"');
- FPrintf(f,"#define VSTRING %lc%ls %ld.%ld (%ls)\\n\\r%lc\n", '"', ObjFile, Version, Revision, DateString,'"');
- FPrintf(f,"#define VSTRING2 %lc%ls %ld.%ld (%ls)%lc\n", '"', ObjFile, Version, Revision, DateString,'"');
- FPrintf(f,"#define VERSTAG %lc\\0$V",'"');
- FPrintf(f,"ER: %ls %ld.%ld (%ls)%lc\n", ObjFile, Version, Revision, DateString,'"');
- Close(f);
- return(TRUE);
- }
- else
- return(FALSE);
- }
-
- /*
- * WriteASM().
- * --------
- * Writes the ASM header file.
- */
-
- BOOL WriteASM(void)
- {
- BPTR f;
-
- if(f = Open(ASM_Header, MODE_NEWFILE)) {
- FPrintf(f,"; ASM Headerfile created by "PRGNAME" "VERSION" on %ls at %ls\n\n", DateString, TimeString);
- FPrintf(f,"VERSION\t\tEQU\t%ld\n", Version);
- FPrintf(f,"REVISION\tEQU\t%ld\n", Revision);
- FPrintf(f,"DATE\tMACRO\n\t\tdc.b\t'%ls'\n\tENDM\n", DateString);
- FPrintf(f,"TIME\tMACRO\n\t\tdc.b\t'%ls'\n\tENDM\n", TimeString);
- FPrintf(f,"VERS\tMACRO\n\t\tdc.b\t'%ls %ld.%ld'\n\tENDM\n", ObjFile, Version, Revision);
- FPrintf(f,"VSTRING\tMACRO\n\t\tdc.b\t'%ls %ld.%ld (%ls)',13,10,0\n\tENDM\n", ObjFile, Version, Revision, DateString);
- FPrintf(f,"VSTRING2\tMACRO\n\t\tdc.b\t'%ls %ld.%ld (%ls)',0\n\tENDM\n", ObjFile, Version, Revision, DateString);
- FPrintf(f,"VERSTAG\tMACRO\n\t\tdc.b\t0,'$VE",NULL);
- FPrintf(f,"R: %ls %ld.%ld (%ls)',0\n\tENDM\n", ObjFile, Version, Revision, DateString);
- Close(f);
- return(TRUE);
- }
- else
- return(FALSE);
- }
-
- /*
- * WriteANSI_C().
- * -------------
- * Writes an ANSI C source file.
- */
-
- BOOL WriteANSI_C(void)
- {
- BPTR f;
-
- if(f = Open(ANSI_C_File, MODE_NEWFILE)) {
- FPrintf(f,"/* ANSI C file created by "PRGNAME" "VERSION" on %ls at %ls */\n\n",DateString, TimeString);
- FPrintf(f,"const unsigned long Version = %ld;\n", Version);
- FPrintf(f,"const unsigned long Revision = %ld;\n", Revision);
- FPrintf(f,"const unsigned char CreationDate[] = {%lc%ls%lc};\n", '"', DateString, '"');
- FPrintf(f,"const unsigned char CreationTime[] = {%lc%ls%lc};\n", '"', TimeString, '"');
- FPrintf(f,"const unsigned char VersionString[] = {%lc%ls %ld.%ld (%ls)%lc};\n", '"', ObjFile, Version, Revision, DateString,'"');
- FPrintf(f,"const unsigned char VersionTag[] = {%lc\\0$V",'"');
- FPrintf(f,"ER: %ls %ld.%ld (%ls)%lc};\n", ObjFile, Version, Revision, DateString,'"');
- Close(f);
- return(TRUE);
- }
- else
- return(FALSE);
- }
-
-
- /*
- * _Main().
- * ------
- * Entry point of every C program. We don't call compilers' __main().
- */
-
- long main(char *c)
- {
- LONG i;
-
- if(DOSBase->dl_lib.lib_Version < 37L)
- return(20);
-
- // Be aware of those ugly compilers which don't clear global data.
-
- memset(ArgArray, 0, sizeof(ArgArray));
-
- // Read given inputs via ReadArgs DOS-call
-
- if(!(ShellArgs = ReadArgs(Template, ArgArray, NULL))) {
- PrintFault(IoErr(), PRGNAME);
- }
- else {
-
- // We have now the command line parsed. Go on generating the filenames.
-
- Args = (LONG **) ArgArray;
-
- if(!Args[quiet] && !Args[showrev])
- Printf(""PRGNAME" v%s written and © by Alexander Sieb on "DATE".\n\n",VERSION);
-
- strcpy(RevFile, (char *)Args[file]);
-
- i=strlen(RevFile);
- if(strcmpi(&RevFile[i-4], ".rev")) {
- strcpy(C_Header, RevFile);
- strcat(C_Header, ".h");
- strcpy(ASM_Header, RevFile);
- strcat(ASM_Header, ".i");
- strcpy(ANSI_C_File, RevFile);
- strcat(ANSI_C_File, ".c");
- strcat(RevFile, ".rev");
- }
- else {
- strncpy(C_Header, RevFile, (size_t)i-4);
- strcpy(ASM_Header, C_Header);
- strcpy(ANSI_C_File, C_Header);
- strcat(C_Header, ".h");
- strcat(ASM_Header, ".i");
- strcat(ANSI_C_File, ".c");
- }
-
- if(Args[dependency])
- i = CompareFileDate(RevFile, (char *)Args[dependency]);
- else
- i = 0;
- if(i<0) {
- if(!Args[quiet])
- Printf("File %s is up to date.\n", RevFile);
- }
- else {
-
- #ifdef DEBUG
- Printf("Generating files %s, %s, %s, %s.\n", RevFile, C_Header, ASM_Header, ANSI_C_File);
- #endif
-
- // We generate now the object name used in the header files
-
- if(Args[object])
- strcpy(ObjFile, (char *) Args[object]);
- else {
- i = strlen(RevFile);
- strncpy(ObjFile, RevFile, (size_t)i-4);
- }
-
- // Now, we do the same with our revision
-
- Version = Args[version][0];
-
- if(!Args[revision])
- Revision = GetRevision(RevFile);
- else
- Revision = Args[revision][0];
-
- // Ok, so far so good. We save now our revision to the specified file 'RevFile'
-
- if(!WriteRevision(RevFile))
- PrintFault(IoErr(), PRGNAME);
- else {
-
- // Write revision to standard output terminal
-
- if(!Args[quiet])
- Printf("Revision set to %ld.\n", Revision);
-
- // Get local date and time
-
- if(!DateStamp(&Date.dat_Stamp))
- PrintFault(IoErr(), PRGNAME);
- else {
- Date.dat_Format = FORMAT_CDN;
- Date.dat_StrDate = DateString;
- Date.dat_StrTime = TimeString;
-
- if(!DateToStr(&Date))
- PrintFault(IoErr(), PRGNAME);
- else {
- for(i=0;i<strlen(DateString);i++)
- if(DateString[i] == '-')
- DateString[i] = '.';
-
- // We got todays date, now we write our header files.
-
- if(!Args[noc])
- if(!WriteC())
- PrintFault(IoErr(), PRGNAME);
- if(!Args[noasm])
- if(!WriteASM())
- PrintFault(IoErr(), PRGNAME);
- if(!Args[noansi])
- if(!WriteANSI_C())
- PrintFault(IoErr(), PRGNAME);
- }
- }
- }
- }
- FreeArgs(ShellArgs);
- }
- return(NULL);
- }
-