/* * CHECKVER.CMD - C.Langanke 2006 * * Syntax: checkver * * This program checks for certain version information in source files * and patches it. Please see stem variable Info. for data being maintained. */ /* ***** BEGIN LICENSE BLOCK ***** * Version: CDDL 1.0 * * The contents of this file are subject to the COMMON DEVELOPMENT AND * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at http://www.sun.com/cddl/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is * "netlabs.org Open Source Archive Administrator/Client" * * The Original Distribution Package is named * "netlabs.org Open Source Archive Administrator/Client" * and maintained and distributed by the Initial Developer * and/or netlabs.org only. * * In addition to the CDDL the following applies: * If you modify the Original Code, you may distribute it only * as a part of a distribution package where * - the name of the package, created directories or * OS2.INI entries do not contain any of the terms * - "netlabs.org Open Source Archive" * - "NOSA" * - "NOSAC" * - "NOSAADM" * - neither netlabs.org nor the Initial Developer is stated as * the vendor or originator of the resulting Distribution Package, * which contains the Modified Code. * * The Initial Developer of the Original Code is * netlabs.org: Christian Langanke . * Portions created by the Initial Developer are Copyright (C) 1999-2008 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ env = 'OS2ENVIRONMENT'; TRUE = (1 = 1); FALSE = (0 = 1); CrLf = '0d0a'x; Redirection = '> NUL 2>&1'; '@ECHO OFF'; GlobalVars = 'env TRUE FALSE CrLf Redirection TmpDir'; /* defaults */ TmpDir = VALUE('TMP',,env); fDebug = FALSE; GlobalVars = GlobalVars 'Info. CDDLLineStart'; /* control values */ SearchTags = 'CHECKVER (CDDL)' SkipDirs = 'compile debug release'; /* specify SED search term in two strings, otherwise it gets modified ;-) */ CDDLLineStart1 = 'Portions created by the'; CDDLLineStart2 = 'Initial Developer are Copyright'; CDDLLineStart = CDDLLineStart1 CDDLLineStart2; Info.Year = '1999-2008'; Info.Email = 'cla@clanganke.de'; Info.Vendor = 'NETLABS'; Info.Version = 'V1.10'; Info.Release = '1001'; DO 1 ProjectDir = VALUE( 'TOOLENV_PRJDIR',,env); rcx = DIRECTORY( ProjectDir'\WORK'); ModifyCount = 0; DO WHILE (SearchTags \= '') PARSE VAR SearchTags ThisTag SearchTags; FileList = GetCmdOutput( 'grep -sl' ThisTag '*'); IF (fDebug) THEN DO SAY; SAY 'Search:' ThisTag SAY FileList END; ModifyCount = ModifyFiles( ThisTag, SkipDirs, FileList); END; /* display stats */ IF (ModifyCount > 0) THEN DO SAY; SAY ModifyCount 'files modified'; END; END; RETURN(0); /* ============================================================== */ IGNORE: PROCEDURE RETURN(''); /* ============================================================== */ GetCmdOutput: PROCEDURE PARSE ARG Cmd; ResultStr = ''; DO 1 /* read grep output */ QueueName = RXQUEUE('CREATE'); rc = RXQUEUE('SET', QueueName); '' Cmd '| rxqueue' QueueName; DO WHILE (QUEUED() > 0) PARSE PULL Line; ResultStr = ResultStr Line; END; rc = RXQUEUE('DELETE', QueueName); rc = RXQUEUE('SET', 'SESSION'); END; RETURN( ResultStr); /* ============================================================== */ ModifyFiles: PROCEDURE EXPOSE (GlobalVars) PARSE ARG SearchTag, SkipDirs, Filelist; ModifyCount = 0; DO 1 SkipDirs = TRANSLATE( SkipDirs); DO WHILE (FileList \= '') PARSE VAR FileList ThisFile FileList; /* file may not be compied */ PARSE VALUE TRANSLATE( ThisFile) WITH FirstDir'\'.; IF (WORDPOS( FirstDir, SkipDirs) > 0) THEN ITERATE; Filename = TRANSLATE( FILESPEC( 'N', ThisFile)); CheckFile = TmpDir'\'TRANSLATE( ThisFile, '_', '\'); BldLevel = ''; IF (ThisVersion \= '') THEN BldLevel = Info.Vendor':'SUBSTR( Info.Version, 2)'.'Info.Release; EditCmd = ''; SELECT WHEN (SearchTag = '(CDDL)') THEN EditCmd = ' -e "s/\('CDDLLineStart'\).*/\1 \(C\)' Info.Year'/"'; /* don't modify myself */ WHEN (Filename = 'CHECKVER.CMD') THEN NOP; WHEN (POS( 'CMD', Filename) > 0) THEN EditCmd = '-e "s/\('Filename' - \)\([^V]*\).*/\1\2'Info.Version' - 'Info.Email' - 'Info.Year'/"' WHEN (POS( '.DEF', Filename) > 0) THEN EditCmd = '-e "s/\(DESCRIPTION.*@#\).*\(#@.*\) .*@.*/\1'BldLevel'\2 'Info.Email' - 'Info.Year'''/"'; OTHERWISE DO SAY 'error: cannot handle' ThisFile; EditCmd = ''; END; END; /* perform modification */ IF (EditCmd \= '') THEN DO 'sed' EditCmd ThisFile'>' CheckFile; 'rem call gfc' ThisFile CheckFile 'ECHO n|comp' ThisFile CheckFile '>NUL 2>&1'; IF (rc > 0) THEN DO 'COPY' CheckFile ThisFile '>NUL 2>&1'; IF (rc = 0) THEN DO SAY '-' ThisFile; ModifyCount = ModifyCount + 1; END; ELSE SAY '>>> error updating' ThisFile; END; 'DEL' CheckFile '>NUL 2>&1'; END; END; END; RETURN( ModifyCount);