> utils/oh_utils is definitely a better place. Let me take a stab at that
> and send you another patch.
>
> Thanks,
> -- Shuah
>
Here is the refined patch based on the feedback. The following patch
does the following:
- Adds macro that takes pointers program name and program revision
strings to a new header file version_utils.h under utils. The original
code for this macro came from hpiel.c
- Changes oh_utils.h to add version_utils.h include.
- Changes all of the clients to call oh_version().
- Changes hpireset.c to print usage string and exit if it is run with no
arguments.
Patch is tested on RHEL 5.0 and Ubuntu 7.04
===========================Cut here=====================================
diff -urNp openhpi-2.10.0/clients/hpialarms.c
openhpi-2.10.0_version/clients/hpialarms.c
--- openhpi-2.10.0/clients/hpialarms.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpialarms.c 2007-10-02
12:10:50.000000000 -0600
@@ -47,7 +47,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
-#include "SaHpi.h"
+
+#include <SaHpi.h>
+#include <oh_utils.h>
+
#define uchar unsigned char
#define SAHPI_OEM_ALARM_LED 0x10
@@ -90,7 +93,7 @@ main(int argc, char **argv)
int j;
uchar b = 0;
- printf("%s ver %s\n", argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"rxa:b:c:m:n:p:i:d:o?")) != EOF )
switch(c) {
diff -urNp openhpi-2.10.0/clients/hpiel.c
openhpi-2.10.0_version/clients/hpiel.c
--- openhpi-2.10.0/clients/hpiel.c 2007-08-31 10:15:37.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpiel.c 2007-10-02 12:10:50.000000000
-0600
@@ -15,7 +15,6 @@
#include <SaHpi.h>
-#include <oHpi.h>
#include <oh_utils.h>
#define OH_SVN_REV "$Revision: 6418 $"
@@ -52,10 +51,6 @@ SaErrorT display_el(SaHpiSessionIdT sid,
int main(int argc, char **argv)
{
- SaHpiUint32T ohpi_major = oHpiVersionGet() >> 48;
- SaHpiUint32T ohpi_minor = (oHpiVersionGet() << 16) >> 48;
- SaHpiUint32T ohpi_patch = (oHpiVersionGet() << 32) >> 48;
- SaHpiVersionT hpiver;
SaErrorT error = SA_OK;
SaHpiSessionIdT sid;
SaHpiDomainInfoT dinfo;
@@ -65,14 +60,8 @@ int main(int argc, char **argv)
memset(svn_rev, 0, sizeof(SAHPI_MAX_TEXT_BUFFER_LENGTH));
strncpy(svn_rev, OH_SVN_REV, SAHPI_MAX_TEXT_BUFFER_LENGTH);
svn_rev[strlen(OH_SVN_REV)-2] = '\0';
- printf("%s - This program came with OpenHPI %u.%u.%u (%s)\n",
- argv[0], ohpi_major, ohpi_minor, ohpi_patch,
- svn_rev + 11);
- hpiver = saHpiVersionGet();
- printf("HPI Version is %x.0%d.0%d\n",
- (hpiver >> 16) + 9,
- (hpiver & 0x0000FF00) >> 8,
- hpiver & 0x000000FF);
+
+ oh_version(argv[0], svn_rev+11);
/* Parsing options */
if (parse_options(argc, &argv, &opts)) {
diff -urNp openhpi-2.10.0/clients/hpievents.c
openhpi-2.10.0_version/clients/hpievents.c
--- openhpi-2.10.0/clients/hpievents.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpievents.c 2007-10-02
12:10:50.000000000 -0600
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
memset(&rptentry, 0, sizeof(rptentry));
- printf("%s: version %s\n", argv[0], progver);
+ oh_version(argv[0], progver);
while ( (c = getopt( argc, argv,"t:xd?")) != EOF ) {
switch(c) {
diff -urNp openhpi-2.10.0/clients/hpifan.c
openhpi-2.10.0_version/clients/hpifan.c
--- openhpi-2.10.0/clients/hpifan.c 2007-08-31 10:15:37.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpifan.c 2007-10-02
12:10:50.000000000 -0600
@@ -27,6 +27,8 @@
static int fan_speed = -1;
+char progver[] = "1.0 HPI-B";
+char progname[] = "hpifan";
static int
usage( void )
@@ -251,6 +253,7 @@ main( int argc, char *argv[] )
int help = 0;
SaErrorT rv;
+ oh_version(argv[0],progver);
while( (c = getopt( argc, argv,"hs:") ) != -1 )
switch( c ) {
case 'h':
diff -urNp openhpi-2.10.0/clients/hpiinv.c
openhpi-2.10.0_version/clients/hpiinv.c
--- openhpi-2.10.0/clients/hpiinv.c 2007-08-31 10:15:37.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpiinv.c 2007-10-02
12:10:50.000000000 -0600
@@ -469,7 +469,7 @@ main(int argc, char **argv)
int invfound = 0;
int nloops = 0;
- printf("%s ver %s\n",progname,progver);
+ oh_version(progname,progver);
atag.tlen = 0;
while ( (c = getopt( argc, argv,"a:vxz?")) != EOF )
diff -urNp openhpi-2.10.0/clients/hpionIBMblade.c
openhpi-2.10.0_version/clients/hpionIBMblade.c
--- openhpi-2.10.0/clients/hpionIBMblade.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpionIBMblade.c 2007-10-02
12:10:50.000000000 -0600
@@ -68,7 +68,6 @@
#include <SaHpi.h>
#include <oh_utils.h>
#include <oh_config.h>
-#include <oHpi.h>
#define READ_BUF_SIZE 1024
#define MAX_BYTE_COUNT 128
@@ -897,7 +896,7 @@ int main(int argc, char **argv)
char buf[READ_BUF_SIZE];
char *S;
- printf("%s ver %s\n", argv[0], progver);
+ oh_version(argv[0], progver);
while ( (c = getopt( argc, argv,"x?")) != EOF )
switch(c) {
case 'x':
diff -urNp openhpi-2.10.0/clients/hpipower.c
openhpi-2.10.0_version/clients/hpipower.c
--- openhpi-2.10.0/clients/hpipower.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpipower.c 2007-10-02
12:10:50.000000000 -0600
@@ -24,7 +24,6 @@
char PrgVer[]="1.0";
char PrgName[] = "hpipower";
-#define PROGRAM_HEADER (printf("%s ver %s\n", PrgName,PrgVer))
#define MAX_MANAGED_SYSTEMS 80
#define HPI_POWER_DEBUG_PRINT(a) if(DebugPrints==TRUE)printf(a)
@@ -87,7 +86,7 @@ int main(int argc, char **argv)
/*
// Print out the Program name and Version
*/
- PROGRAM_HEADER;
+ oh_version(PrgName,PrgVer);
/* Set Program Defaults */
ComputerNumber = 0;
diff -urNp openhpi-2.10.0/clients/hpireset.c
openhpi-2.10.0_version/clients/hpireset.c
--- openhpi-2.10.0/clients/hpireset.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpireset.c 2007-10-02
13:56:54.000000000 -0600
@@ -18,7 +18,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
-#include "SaHpi.h"
+#include <SaHpi.h>
+#include <oh_utils.h>
#define uchar unsigned char
char *progver = "1.0";
@@ -54,7 +55,7 @@ main(int argc, char **argv)
uchar bopt;
uchar fshutdown = 0;
- printf("%s ver %s\n", argv[0],progver);
+ oh_version(argv[0],progver);
breset = 3; /* hard reset as default */
bopt = 0; /* Boot Options default */
while ( (c = getopt( argc, argv,"rdwconsx?")) != EOF )
@@ -76,6 +77,11 @@ main(int argc, char **argv)
Usage(argv[0]);
exit(1);
}
+ if(argc == 1) {
+ Usage(argv[0]);
+ exit(1);
+ }
+
if (fshutdown) breset = 5; /* soft shutdown option */
rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
diff -urNp openhpi-2.10.0/clients/hpisensor.c
openhpi-2.10.0_version/clients/hpisensor.c
--- openhpi-2.10.0/clients/hpisensor.c 2007-08-31 10:15:37.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpisensor.c 2007-10-02
12:10:50.000000000 -0600
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
SaHpiRdrT rdr;
SaHpiEntityPathT ep_target;
- printf("%s: version %s\n",argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"rtse:x?")) != EOF )
switch(c) {
diff -urNp openhpi-2.10.0/clients/hpisettime.c
openhpi-2.10.0_version/clients/hpisettime.c
--- openhpi-2.10.0/clients/hpisettime.c 2007-08-31 10:15:38.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpisettime.c 2007-10-02
12:10:50.000000000 -0600
@@ -81,7 +81,7 @@ int main(int argc, char **argv)
SaHpiTimeT readbacktime;
SaHpiTextBufferT buffer;
- printf("%s: version %s\n",argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"d:t:x")) != EOF )
{
diff -urNp openhpi-2.10.0/clients/hpithres.c
openhpi-2.10.0_version/clients/hpithres.c
--- openhpi-2.10.0/clients/hpithres.c 2007-08-31 10:15:38.000000000
-0600
+++ openhpi-2.10.0_version/clients/hpithres.c 2007-10-02
12:10:50.000000000 -0600
@@ -642,7 +642,7 @@ int main(int argc, char **argv)
char buf[READ_BUF_SIZE];
char *S;
- printf("%s ver %s\n", argv[0], progver);
+ oh_version(argv[0], progver);
while ( (c = getopt( argc, argv,"x?")) != EOF )
switch(c) {
case 'x':
diff -urNp openhpi-2.10.0/clients/hpitop.c
openhpi-2.10.0_version/clients/hpitop.c
--- openhpi-2.10.0/clients/hpitop.c 2007-08-31 10:15:38.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpitop.c 2007-10-02
12:10:50.000000000 -0600
@@ -99,13 +99,12 @@ main(int argc, char **argv)
{
SaErrorT rv = SA_OK;
- SaHpiVersionT hpiVer;
SaHpiSessionIdT sessionid;
SaHpiResourceIdT resourceid = all_resources;
int c;
- printf("\n\n%s ver %s\n",argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"rsicawn:x?")) != EOF ) {
switch(c) {
case 'r': f_rpt = 1; break;
@@ -138,14 +137,6 @@ main(int argc, char **argv)
if (argc == 1) f_overview = 1;
memset (previous_system, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
- /*
- * House keeping:
- * -- get (check?) hpi implementation version
- * -- open hpi session
- */
- if (fdebug) printf("saHpiVersionGet\n");
- hpiVer = saHpiVersionGet();
- printf("Hpi Version %d Implemented.\n", hpiVer);
if (fdebug) printf("saHpiSessionOpen\n");
rv =
saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
diff -urNp openhpi-2.10.0/clients/hpitree.c
openhpi-2.10.0_version/clients/hpitree.c
--- openhpi-2.10.0/clients/hpitree.c 2007-08-31 10:15:38.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpitree.c 2007-10-02
12:10:50.000000000 -0600
@@ -104,13 +104,12 @@ main(int argc, char **argv)
{
SaErrorT rv = SA_OK;
- SaHpiVersionT hpiVer;
SaHpiSessionIdT sessionid;
SaHpiResourceIdT resourceid = all_resources;
int c;
- printf("\n\n%s ver %s\n",argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"adrsoiwcn:x?")) != EOF ) {
switch(c) {
case 'a': f_listall = 1; break;
@@ -149,15 +148,6 @@ main(int argc, char **argv)
if (argc == 1) f_listall = 1;
- /*
- * House keeping:
- * -- get (check?) hpi implementation version
- * -- open hpi session
- */
- if (fdebug) printf("saHpiVersionGet\n");
- hpiVer = saHpiVersionGet();
- printf("Hpi Version %d Implemented.\n", hpiVer);
-
if (fdebug) printf("saHpiSessionOpen\n");
rv =
saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
if (rv != SA_OK) {
diff -urNp openhpi-2.10.0/clients/hpiwdt.c
openhpi-2.10.0_version/clients/hpiwdt.c
--- openhpi-2.10.0/clients/hpiwdt.c 2007-08-31 10:15:38.000000000 -0600
+++ openhpi-2.10.0_version/clients/hpiwdt.c 2007-10-02
12:10:50.000000000 -0600
@@ -31,7 +31,8 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
-#include "SaHpi.h"
+#include <SaHpi.h>
+#include <oh_utils.h>
#define uchar unsigned char
#ifdef HPI_A
@@ -109,7 +110,7 @@ main(int argc, char **argv)
char fenable = 0;
char fdisable = 0;
- printf("%s ver %s\n", argv[0],progver);
+ oh_version(argv[0],progver);
while ( (c = getopt( argc, argv,"dert:x?")) != EOF )
switch(c) {
case 'r': /* reset wdt */
diff -urNp openhpi-2.10.0/utils/Makefile.am
openhpi-2.10.0_version/utils/Makefile.am
--- openhpi-2.10.0/utils/Makefile.am 2007-08-31 10:16:06.000000000 -0600
+++ openhpi-2.10.0_version/utils/Makefile.am 2007-10-02
12:12:08.000000000 -0600
@@ -53,7 +53,8 @@ EXTRA_DIST = \
sahpi_event_utils.h \
sahpi_struct_utils.h \
sahpi_time_utils.h \
- uid_utils.h
+ uid_utils.h \
+ version_utils.h
MOSTLYCLEANFILES = @TEST_CLEAN@
# FIXME:: Add when we can auto-generate files for SMP systems
diff -urNp openhpi-2.10.0/utils/oh_utils.h
openhpi-2.10.0_version/utils/oh_utils.h
--- openhpi-2.10.0/utils/oh_utils.h 2007-08-31 10:16:06.000000000 -0600
+++ openhpi-2.10.0_version/utils/oh_utils.h 2007-10-02
12:11:20.000000000 -0600
@@ -30,5 +30,6 @@
#include <sahpi_time_utils.h>
#include <sahpiatca_enum_utils.h>
#include <uid_utils.h>
+#include <version_utils.h>
#endif
diff -urNp openhpi-2.10.0/utils/version_utils.h
openhpi-2.10.0_version/utils/version_utils.h
--- openhpi-2.10.0/utils/version_utils.h 1969-12-31 17:00:00.000000000
-0700
+++ openhpi-2.10.0_version/utils/version_utils.h 2007-10-02
12:11:47.000000000 -0600
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2007-2008, Hewlett-Packard Development Company, LLP
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
distribution.
+ *
+ * Neither the name of the Hewlett-Packard Corporation, nor the names
+ * of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author(s)
+ * Shuah Khan <[EMAIL PROTECTED]>
+*/
+/*
+ * This file contains a prototype for oh_version() defined in
version_utils.h
+*/
+#ifndef __VERSION_UTILS_H
+#define __VERSION_UTILS_H
+
+#include <oHpi.h>
+
+/**
+ * oh_version: generates and prints HPI and OpenHPI version strings.
+ * Input params: none
+ * Output params: none
+ * Return values: None
+ **/
+#define oh_version( prog_name, rev_str ) \
+ do { \
+ SaHpiUint32T ohpi_major = oHpiVersionGet() >> 48; \
+ SaHpiUint32T ohpi_minor = (oHpiVersionGet() << 16) >> 48; \
+ SaHpiUint32T ohpi_patch = (oHpiVersionGet() << 32) >> 48; \
+ SaHpiVersionT hpiver; \
+ printf("\n\n%s came with OpenHPI %u.%u.%u (%s)\n", \
+ prog_name, ohpi_major, ohpi_minor, ohpi_patch, \
+ rev_str); \
+ hpiver = saHpiVersionGet(); \
+ printf("HPI Version is %x.0%d.0%d\n", \
+ (hpiver >> 16) + 9, \
+ (hpiver & 0x0000FF00) >> 8, \
+ hpiver & 0x000000FF); \
+ } while(0)
+
+#endif
=============================Cut here============================
Thanks,
-- Shuah
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Openhpi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openhpi-devel