head 1.15; access; symbols HWGRCSP12F:1.15 HWGRCSP11F:1.13 HWGRCSP10F:1.12 HWGRCSP9:1.12 HWGRCSP8F:1.11 HWGRCSP7F:1.7 C_15:1.7 HWGRCSP6F:1.5 HWGRCSP5F:1.5 HWGRCSp4:1.4; locks; strict; comment @ * @; 1.15 date 95.01.21.18.01.02; author heinz; state Exp; branches; next 1.14; 1.14 date 94.12.31.13.41.14; author heinz; state Exp; branches; next 1.13; 1.13 date 94.08.25.19.04.38; author heinz; state Exp; branches; next 1.12; 1.12 date 94.04.13.10.58.16; author heinz; state Exp; branches; next 1.11; 1.11 date 94.03.14.09.20.06; author heinz; state Exp; branches; next 1.10; 1.10 date 94.02.13.10.32.33; author heinz; state Exp; branches; next 1.9; 1.9 date 94.02.13.10.30.42; author heinz; state Exp; branches; next 1.8; 1.8 date 94.02.13.08.59.48; author heinz; state Exp; branches; next 1.7; 1.7 date 94.01.08.12.34.21; author heinz; state Exp; branches; next 1.6; 1.6 date 94.01.08.12.01.17; author heinz; state Exp; branches; next 1.5; 1.5 date 93.07.07.20.32.39; author heinz; state Exp; branches; next 1.4; 1.4 date 93.06.13.15.31.55; author heinz; state Exp; branches; next 1.3; 1.3 date 93.06.13.15.28.21; author heinz; state Exp; branches; next 1.2; 1.2 date 93.06.13.14.41.53; author heinz; state Exp; branches; next 1.1; 1.1 date 93.06.13.14.15.15; author heinz; state Exp; branches; next ; desc @This is an AmigaOS SAS/C version of the rcsfreeze scripts. @ 1.15 log @Fixed buffer size that was too small. @ text @/*------------------------------------------------------------------------*/ /* * * $Id: rcsfreeze.c,v 1.14 1994/12/31 13:41:14 heinz Exp heinz $ * */ /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ /* This is a SAS/C 6.x replacement for my AmigaOS shell script rcsfreeze. It should work a lot better for branches. Hopefully it won't freeze the branch number anymore, but the highest revision number on that branch as it should have done in the first place. It is a hack and duplicates the shell script functionality just about 1:1. I needed it in C to make parsing of the revision number possible! This program uses the fact that "rlog -b" gives us the revision entry we want. To be sure that we don't read a fake revision line in the file description that just happens to be suitable, we check for the "----[...]" line first, that comes before every revision entry. There is one thing though, that is pretty nasty. We need to make a list of all the filenames first, because if we process the files while reading through the directory, the MatchXX() routines will loose track of the current position. No startup code! sc $* nostkchk optimize link nostartup strmerge */ /*------------------------------------------------------------------------*/ #ifndef USE_BUILTIN_MATH #define USE_BUILTIN_MATH #endif #ifndef __USE_SYSBASE #define __USE_SYSBASE #endif /*------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include /*------------------------------------------------------------------------*/ #undef VOID #include "conf.h" #undef VOID #define VOID void /*------------------------------------------------------------------------*/ #define VERSIONFILE ".rcsfreeze.ver" #define LOGFILE ".rcsfreeze.log" struct FileList { struct FileList *Next; UBYTE Name[0]; /* Here follows the name! */ }; /*------------------------------------------------------------------------*/ static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...); static LONG freeze_revs(struct Library *SysBase, struct Library *DOSBase, STRPTR symrevname, BPTR rcsdir); /*------------------------------------------------------------------------*/ #define PRGVER "$" "VER: "PRGPREFIX "rcsfreeze " PRGVERSION "." PRGREVISION " (" PRGDATE ")" PRGVERTEXT /*------------------------------------------------------------------------*/ int main(int argc, char **argv) { struct Library *SysBase = *((struct Library **)4); struct Library *DOSBase = OpenLibrary("dos.library", 37); if(DOSBase) { BPTR olddir = CurrentDir(NULL); BPTR rcsdir, fh; UBYTE buf[BUFSIZ], symrevbuf[BUFSIZ]; STRPTR symrev = NULL, symrevname; LONG versionnumber; struct RDArgs *rd; UBYTE datebuf[3][20]; LONG error = 0; /* Just to get the version string into the code segment ... */ strcpy(buf, PRGVER); /* First we duplicate the currentdir. So we can restore it later */ CurrentDir(DupLock(olddir)); if(rd = ReadArgs("SYMREV", (LONG *)&symrev, NULL)) { BPTR curdir; /* Do we have an RCS_link around? */ buf[0] = 0; fh = Open("RCS_link", MODE_OLDFILE); if(fh) { LONG len; /* What's in the link? */ if(!FGets(fh, buf, BUFSIZ - 1)) { buf[0] = 0; } /* if */ len = strlen(buf); if(len && buf[len - 1] == '\n') { buf[--len] = 0; } /* if */ Close(fh); } /* if */ if(!buf[0]) { strcpy(buf, "RCS"); } /* if */ /* Too lazy to check for a dirname. We just try it. */ rcsdir = Lock(buf, ACCESS_READ); if(rcsdir) { curdir = CurrentDir(rcsdir); } /* if */ /* Create the version and revision files if necessary */ fh = Open(VERSIONFILE, MODE_OLDFILE); if(!fh) { fh = Open(VERSIONFILE, MODE_NEWFILE); if(fh) { FPuts(fh, "0\n"); Close(fh); } /* if */ fh = Open(LOGFILE, MODE_NEWFILE); if(fh) { Close(fh); } /* if */ fh = Open(VERSIONFILE, MODE_OLDFILE); } /* if */ /* Lets advance the version number! */ versionnumber = 1; if(fh) { if(!FGets(fh, buf, BUFSIZ - 1)) { buf[0] = 0; } /* if */ StrToLong(buf, &versionnumber); versionnumber++; Close(fh); fh = Open(VERSIONFILE, MODE_NEWFILE); if(fh) { FPrintf(fh, "%ld\n", versionnumber); Close(fh); } else { error = IoErr(); } /* if */ } else { error = IoErr(); } /* if */ if(!error) { SPrintf(SysBase, symrevbuf, "C_%ld", versionnumber); symrevname = (symrev) ? symrev : symrevbuf; Printf("rcsfreeze: symbolic revision number computed: '%s'\n", symrevbuf); Printf(" symbolic revision number used: '%s'\n", symrevname); PutStr("\n The two differ only when rcsfreeze was invoked with an argument.\n\n"); PutStr("Give a log message, summarizing changes (end with EOF, CTRL-\\, or single '.')\n"); /* We need the date for the freeze */ { struct DateTime dt; DateStamp(&dt.dat_Stamp); dt.dat_Format = FORMAT_DOS; /* Compatibility to the old script */ dt.dat_Flags = 0; dt.dat_StrDay = datebuf[0]; dt.dat_StrDate = datebuf[1]; dt.dat_StrTime = datebuf[2]; DateToStr(&dt); } /* Let us append the revision freeze text */ fh = Open(LOGFILE, MODE_OLDFILE); if(fh) { Seek(fh, 0, OFFSET_END); FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n\n", symrevname, symrevbuf, datebuf[0], datebuf[1], datebuf[2]); while(FGets(Input(), buf, BUFSIZ - 1)) { if(buf[0] == '.' && (!buf[1] || buf[1] == '\n')) { break; } /* if */ FPuts(fh, buf); } /* while */ Close(fh); } else { error = IoErr(); } /* if */ } /* if */ if(rcsdir) { CurrentDir(curdir); } /* if */ if(!error) { error = freeze_revs(SysBase, DOSBase, symrevname, rcsdir); } /* if */ UnLock(rcsdir); FreeArgs(rd); } else { error = IoErr(); } /* if */ UnLock(CurrentDir(olddir)); if(error) { PrintFault(error, NULL); } /* if */ CloseLibrary(DOSBase); } /* if */ return(0); } /* main */ /*------------------------------------------------------------------------*/ static void SPutC(void) { __emit(0x16c0); /* MOVE.B d0,(a3)+ */ } /* SPutC */ /*------------------------------------------------------------------------*/ static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...) { RawDoFmt(format, (APTR) ((&format)+1), SPutC, buf); } /* SPrintf */ /*------------------------------------------------------------------------*/ static STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template) { STRPTR cp; ULONG val; BPTR lock; cp = template; cp += strlen(cp); for (val = (ULONG) FindTask(NULL) ; ; ) { if (*--cp == 'X') { *cp = (val & 0x0f) + '0'; if(*cp > '9') { *cp += 7; } /* if */ val >>= 4; } else if (*cp != '.') { break; } /* if */ } /* for */ if (*++cp != 0) { *cp = 'A'; while (lock = Lock(template, ACCESS_READ)) { UnLock(lock); if (*cp == 'Z') { *template = 0; break; } /* if */ ++*cp; } /* while */ } else { if (lock = Lock(template, ACCESS_READ)) { UnLock(lock); *template = 0; } /* if */ } /* if */ return template; } /* mktemp */ /*------------------------------------------------------------------------*/ static struct FileList *GetFileList(struct Library *SysBase, struct Library *DOSBase, LONG *errorp) { struct AnchorPath __aligned ap; LONG error; struct FileList *head = NULL; memset(&ap, 0, sizeof(ap)); ap.ap_BreakBits = SIGBREAKF_CTRL_C; error = MatchFirst("#?", &ap); if(!error) { for(; !error; error = MatchNext(&ap)) { LONG len; struct FileList *fl; /* We ignore directories or the log files for rcsfreeze */ if(ap.ap_Info.fib_DirEntryType >= 0 || stricmp(ap.ap_Info.fib_FileName, VERSIONFILE) == 0 || stricmp(ap.ap_Info.fib_FileName, LOGFILE) == 0) { continue; } /* if */ len = strlen(ap.ap_Info.fib_FileName); fl = AllocVec(sizeof(*fl) + len + 1, MEMF_ANY); if(fl) { fl->Next = head; strcpy(fl->Name, ap.ap_Info.fib_FileName); head = fl; } else { error = ERROR_NO_FREE_STORE; break; } /* if */ } /* for */ MatchEnd(&ap); } /* if */ if(error == ERROR_NO_MORE_ENTRIES) { error = 0; } /* if */ *errorp = error; return(head); } /* GetFileList */ /*------------------------------------------------------------------------*/ static void FreeFileList(struct Library *SysBase, struct FileList *fl) { struct FileList *flnext; for(; fl; fl = flnext) { flnext = fl->Next; FreeVec(fl); } /* for */ } /* FreeFileList */ /*------------------------------------------------------------------------*/ static LONG freeze_revs(struct Library *SysBase, struct Library *DOSBase, STRPTR symrevname, BPTR rcsdir) { LONG error; UBYTE buf[BUFSIZ]; struct FileList *head, *fl; BPTR olddir; if(rcsdir) { olddir = CurrentDir(rcsdir); } /* if */ head = GetFileList(SysBase, DOSBase, &error); if(rcsdir) { CurrentDir(olddir); } /* if */ if(!error) { for(fl = head; !error && fl; fl = fl->Next) { BPTR fh; char tmpbuf[40],cmdbuf[BUFSIZ]; strcpy(tmpbuf, "PIPE:rcsfreezeXXXXXXXX"); if(mktemp(SysBase, DOSBase, tmpbuf)) { #ifdef ASYNC BPTR nilfh1, nilfh2; #endif /* ASYNC */ strcat(tmpbuf, "//0"); SPrintf(SysBase, cmdbuf, "rlog >%s -b \"%s\"\n", tmpbuf, fl->Name); #ifdef ASYNC nilfh1 = Open("NIL:", MODE_OLDFILE); nilfh2 = Open("NIL:", MODE_NEWFILE); #endif /* ASYNC */ if(!(error = SystemTags(cmdbuf, SYS_UserShell, TRUE, #ifdef ASYNC SYS_Asynch, TRUE, SYS_Input, nilfh1, SYS_Output, nilfh2, #endif /* ASYNC */ TAG_END))) { fh = Open(tmpbuf, MODE_OLDFILE); if(fh) { while(FGets(fh, buf, BUFSIZ - 1) && !error) { if(strlen(buf) > 10 && !memcmp(buf, "----------", 10)) { if(FGets(fh, buf, BUFSIZ - 1)) { if(strlen(buf) > 10 && !memcmp(buf, "revision ", 9)) { /* This is the version number we are looking for!! */ STRPTR version = &buf[9]; ULONG len = strlen(version); if(version[len - 1] == '\n') { version[--len] = 0; } /* if */ if(len > 2) { Printf("rcsfreeze: '%s' %s\n", version, fl->Name); SPrintf(SysBase, cmdbuf, "rcs -q \"-n%s:%s\" \"%s\"\n", symrevname, version, fl->Name); error = SystemTags(cmdbuf, SYS_UserShell, TRUE, TAG_END); } /* if */ break; } /* if */ } /* if */ } /* if */ } /* while */ Close(fh); } else { error = ERROR_OBJECT_NOT_FOUND; } /* if */ } else { /* We ignore log errors */ Printf("rcsfreeze: rlog failed on %s, file ignored.\n", fl->Name); error = 0; } /* if */ } else { error = ERROR_BAD_TEMPLATE; } /* if */ if(error) { break; } /* if */ } /* for */ } /* if */ FreeFileList(SysBase, head); return(error); } /* freeze_revs */ /*------------------------------------------------------------------------*/ /* Ende des Quelltextes */ @ 1.14 log @Pipename generation should work again. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.13 1994/08/25 19:04:38 heinz Exp heinz $ d451 1 a451 1 char tmpbuf[20],cmdbuf[BUFSIZ]; d456 4 d464 5 d471 5 @ 1.13 log @The PIPE did not handle unlimited histories. Now it should not block unless one runs out of memory. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.12 1994/04/13 10:58:16 heinz Exp heinz $ d453 1 a453 1 strcpy(tmpbuf, "PIPE:rfXXX.XXX//0"); d456 1 @ 1.12 log @Fixed wrong handling of empty directory line in RCS_link @ text @d3 1 a3 38 * $Id: rcsfreeze.c,v 1.11 1994/03/14 09:20:06 heinz Exp heinz $ * * $Log: rcsfreeze.c,v $ * Revision 1.11 1994/03/14 09:20:06 heinz * Changes to version string setup. * * Revision 1.10 1994/02/13 10:32:33 heinz * *** empty log message *** * * Revision 1.9 1994/02/13 10:30:42 heinz * Version change. * * Revision 1.8 1994/02/13 08:59:48 heinz * Changed version string handling. * * Revision 1.7 1994/01/08 12:34:21 heinz * rcsfreeze ignores directories and its own logfiles now. * CurrentDir handling is a little better now for rlog. * * Revision 1.6 1994/01/08 12:01:17 heinz * Now checks all the files, not just files ending in ",v" * * Revision 1.5 1993/07/07 20:32:39 heinz * It now uses the standard version string set in the smakefile * * Revision 1.4 1993/06/13 15:31:55 heinz * An extra \n to make the log file compatible. * * Revision 1.3 1993/06/13 15:28:21 heinz * Now makes the file list first and then does the freeze. * The MatchXXX routines barf on me if I try to do it "on the fly" * * Revision 1.2 1993/06/13 14:41:53 heinz * Argh! I forgot to remove the trailing \n in the RCS_link. * * Revision 1.1 1993/06/13 14:15:15 heinz * Initial revision * d453 1 a453 1 strcpy(tmpbuf, "PIPE:rfXXX.XXX"); @ 1.11 log @Changes to version string setup. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.10 1994/02/13 10:32:33 heinz Exp heinz $ d6 3 d147 1 d166 3 a168 2 } else d170 1 a170 1 strcpy(buf, "rcs"); d172 2 a173 2 /* Too laze to check for a dirname. We just try it. */ @ 1.10 log @*** empty log message *** @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.9 1994/02/13 10:30:42 heinz Exp heinz $ d6 3 a81 2 #define BUFSIZ 256 d90 6 d114 1 a114 1 #define VERSION "$VER: HWGRCS_rcsfreeze 1.7 (13.02.94)" d134 1 a134 1 strcpy(buf, VERSION PRGVERSIONTEXT); @ 1.9 log @Version change. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.8 1994/02/13 08:59:48 heinz Exp heinz $ d6 3 @ 1.8 log @Changed version string handling. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.7 1994/01/08 12:34:21 heinz Exp heinz $ d6 3 d104 1 a104 1 #define VERSION "$VER: rcsfreeze 1.7 (13.02.94)" @ 1.7 log @rcsfreeze ignores directories and its own logfiles now. CurrentDir handling is a little better now for rlog. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.6 1994/01/08 12:01:17 heinz Exp heinz $ d6 4 d101 3 d121 1 a121 1 strcpy(buf, PRGVERSION); @ 1.6 log @Now checks all the files, not just files ending in ",v" @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.5 1993/07/07 20:32:39 heinz Exp heinz $ d6 3 d93 2 a94 1 STRPTR symrevname); d121 2 d145 1 a145 1 strcpy(buf, "RCS"); d148 4 a151 1 if(buf[0]) d153 1 a153 7 /* Too laze to check for a dirname. We just try it. */ rcsdir = Lock(buf, ACCESS_READ); if(rcsdir) { UnLock(CurrentDir(rcsdir)); } /* if */ d215 1 a215 1 PutStr("Give a log message, summarizing changes (end with EOF, CTRL-\, or single '.')\n"); a259 4 if(!error) { error = freeze_revs(SysBase, DOSBase, symrevname); } /* if */ d262 12 d382 13 a394 2 LONG len = strlen(ap.ap_Info.fib_FileName); struct FileList *fl = AllocVec(sizeof(*fl) + len + 1, MEMF_ANY); d440 2 a441 1 STRPTR symrevname) d446 1 d448 4 d453 4 d523 6 @ 1.5 log @It now uses the standard version string set in the smakefile @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.4 1993/06/13 15:31:55 heinz Exp heinz $ d6 3 d366 1 a366 1 error = MatchFirst("#?,v", &ap); @ 1.4 log @An extra \n to make the log file compatible. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.3 1993/06/13 15:28:21 heinz Exp heinz $ d6 3 d107 1 a107 1 strcpy(buf, "$VER: rcsfreeze 1.0 (13.6.93) For Joan"); @ 1.3 log @Now makes the file list first and then does the freeze. The MatchXXX routines barf on me if I try to do it "on the fly" @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.2 1993/06/13 14:41:53 heinz Exp heinz $ d6 4 d228 1 a228 1 FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n", @ 1.2 log @Argh! I forgot to remove the trailing \n in the RCS_link. @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.1 1993/06/13 14:15:15 heinz Exp heinz $ d6 3 d30 5 d59 1 d69 7 d77 4 a80 4 void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...); LONG freeze_revs(struct Library *SysBase, struct Library *DOSBase, STRPTR symrevname); d283 1 a283 1 void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...) d290 1 a290 1 STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template) d344 3 a346 3 LONG freeze_revs(struct Library *SysBase, struct Library *DOSBase, STRPTR symrevname) d350 1 a350 1 UBYTE buf[BUFSIZ]; d361 59 d427 1 a427 1 tmpbuf, ap.ap_Info.fib_FileName); d459 1 a459 1 version, ap.ap_Info.fib_FileName); d464 1 a464 1 ap.ap_Info.fib_FileName); a492 2 MatchEnd(&ap); d495 1 a495 4 if(error == ERROR_NO_MORE_ENTRIES) { error = 0; } /* if */ @ 1.1 log @Initial revision @ text @d3 1 a3 1 * $Id: rcsfreeze.c,v 1.1 1993/06/13 13:52:23 heinz Exp $ d6 1 a6 1 * Revision 1.1 1993/06/13 13:52:23 heinz a8 1 * d95 1 d101 6 @