From bd544df8c1b3e0916f26641896acfe4372dd3808 Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Thu, 16 Jan 2003 15:51:10 +0000
Subject: [PATCH] Housekeeping -- moved functions to utility.[hc]

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@451 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/Makefile     |  6 ++---
 sm5/VERSION      |  2 +-
 sm5/atacmds.c    | 59 +-----------------------------------------------
 sm5/atacmds.cpp  | 59 +-----------------------------------------------
 sm5/atacmds.h    |  8 +------
 sm5/smartctl.c   |  5 ++--
 sm5/smartctl.cpp |  5 ++--
 sm5/smartd.c     |  5 ++--
 sm5/smartd.cpp   |  5 ++--
 sm5/utility.c    | 59 +++++++++++++++++++++++++++++++++++++++++++++++-
 sm5/utility.cpp  | 59 +++++++++++++++++++++++++++++++++++++++++++++++-
 sm5/utility.h    |  6 ++++-
 12 files changed, 140 insertions(+), 138 deletions(-)

diff --git a/sm5/Makefile b/sm5/Makefile
index 9322316a8..6fe07357c 100644
--- a/sm5/Makefile
+++ b/sm5/Makefile
@@ -2,7 +2,7 @@
 #
 # Home page: http://smartmontools.sourceforge.net
 #
-# $Id: Makefile,v 1.46 2003/01/16 15:30:33 ballen4705 Exp $
+# $Id: Makefile,v 1.47 2003/01/16 15:51:09 ballen4705 Exp $
 #
 # Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 # 
@@ -53,12 +53,12 @@ all: smartd smartctl
 	@echo -e "to read the manual pages now.  Unless you do a \"make install\" the manual pages won't be installed.\n"
 
 smartctl: smartctl.c atacmds.o ataprint.o scsicmds.o scsiprint.o utility.o\
-          smartctl.h atacmds.h ataprint.h scsicmds.h scsiprint.h extern.h VERSION Makefile
+          smartctl.h atacmds.h ataprint.h scsicmds.h scsiprint.h utility.h extern.h VERSION Makefile
 	$(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartctl $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) smartctl.c \
                                       atacmds.o ataprint.o scsicmds.o scsiprint.o utility.o
 
 smartd:  smartd.c atacmds.o ataprint.o scsicmds.o utility.o\
-         smartd.h atacmds.h ataprint.h scsicmds.h extern.h VERSION Makefile
+         smartd.h atacmds.h ataprint.h scsicmds.h utility.h extern.h VERSION Makefile
 	$(CC) -DSMARTMONTOOLS_VERSION=$(counter) -o smartd $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) smartd.c \
                                       atacmds.o ataprint.o scsicmds.o utility.o
 
diff --git a/sm5/VERSION b/sm5/VERSION
index 0cfbf0888..00750edc0 100644
--- a/sm5/VERSION
+++ b/sm5/VERSION
@@ -1 +1 @@
-2
+3
diff --git a/sm5/atacmds.c b/sm5/atacmds.c
index c18b0ffce..b16e49dc6 100644
--- a/sm5/atacmds.c
+++ b/sm5/atacmds.c
@@ -29,7 +29,7 @@
 #include <stdlib.h>
 #include "atacmds.h"
 
-const char *atacmds_c_cvsid="$Id: atacmds.c,v 1.51 2003/01/16 15:28:57 ballen4705 Exp $" ATACMDS_H_CVSID;
+const char *atacmds_c_cvsid="$Id: atacmds.c,v 1.52 2003/01/16 15:51:09 ballen4705 Exp $" ATACMDS_H_CVSID;
 
 // These Drive Identity tables are taken from hdparm 5.2, and are also
 // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command.  Note
@@ -932,60 +932,3 @@ void ataPrintSmartAttribName(char *out, unsigned char id, unsigned char *defs){
   sprintf(out,"%3hhu %s",id,name);
   return;
 }
-
-
-// These are two utility functions for printing CVS IDs. They don't
-// really belong here.  But it's the only common source file included
-// in both smartd and smartctl.  returns distance that it has moved
-// ahead in the input string
-int massagecvs(char *out, const char *cvsid){
-  char *copy,*filename,*date,*version;
-  const char delimiters[] = " ,$";
-
-  // make a copy on stack, go to first token,
-  if (!(copy=strdup(cvsid)) || !(filename=strtok(copy, delimiters))) 
-    return 0;
-
-  // move to first instance of "Id:"
-  while (strcmp(filename,"Id:"))
-    if (!(filename=strtok(NULL, delimiters)))
-      return 0;
-
-  // get filename, skip "v", get version and date
-  if (!(  filename=strtok(NULL, delimiters)  ) ||
-      !(           strtok(NULL, delimiters)  ) ||
-      !(   version=strtok(NULL, delimiters)  ) ||
-      !(      date=strtok(NULL, delimiters)  ) )
-    return 0;
-
-   sprintf(out,"%-13s revision: %-6s date: %-15s", filename, version, date);
-   free(copy);
-   return  (date-copy)+strlen(date);
-}
-
-// prints a single set of CVS ids
-void printone(char *block, const char *cvsid){
-  char strings[CVSMAXLEN];
-  const char *here=cvsid;
-  int line=1,len=strlen(cvsid)+1;
-
-  // check that the size of the output block is sufficient
-  if (len>=CVSMAXLEN) {
-    fprintf(stderr,"CVSMAXLEN=%d must be at least %d\n",CVSMAXLEN,len+1);
-    exit(1);
-  }
-
-  // loop through the different strings
-  while ((len=massagecvs(strings,here))){
-    switch (line++){
-    case 1:
-      block+=snprintf(block,CVSMAXLEN,"Module:");
-      break;
-    default:
-      block+=snprintf(block,CVSMAXLEN,"  uses:");
-    } 
-    block+=snprintf(block,CVSMAXLEN," %s\n",strings);
-    here+=len;
-  }
-  return;
-}
diff --git a/sm5/atacmds.cpp b/sm5/atacmds.cpp
index b4e763ab0..282dff7d8 100644
--- a/sm5/atacmds.cpp
+++ b/sm5/atacmds.cpp
@@ -29,7 +29,7 @@
 #include <stdlib.h>
 #include "atacmds.h"
 
-const char *atacmds_c_cvsid="$Id: atacmds.cpp,v 1.51 2003/01/16 15:28:57 ballen4705 Exp $" ATACMDS_H_CVSID;
+const char *atacmds_c_cvsid="$Id: atacmds.cpp,v 1.52 2003/01/16 15:51:09 ballen4705 Exp $" ATACMDS_H_CVSID;
 
 // These Drive Identity tables are taken from hdparm 5.2, and are also
 // given in the ATA/ATAPI specs for the IDENTIFY DEVICE command.  Note
@@ -932,60 +932,3 @@ void ataPrintSmartAttribName(char *out, unsigned char id, unsigned char *defs){
   sprintf(out,"%3hhu %s",id,name);
   return;
 }
-
-
-// These are two utility functions for printing CVS IDs. They don't
-// really belong here.  But it's the only common source file included
-// in both smartd and smartctl.  returns distance that it has moved
-// ahead in the input string
-int massagecvs(char *out, const char *cvsid){
-  char *copy,*filename,*date,*version;
-  const char delimiters[] = " ,$";
-
-  // make a copy on stack, go to first token,
-  if (!(copy=strdup(cvsid)) || !(filename=strtok(copy, delimiters))) 
-    return 0;
-
-  // move to first instance of "Id:"
-  while (strcmp(filename,"Id:"))
-    if (!(filename=strtok(NULL, delimiters)))
-      return 0;
-
-  // get filename, skip "v", get version and date
-  if (!(  filename=strtok(NULL, delimiters)  ) ||
-      !(           strtok(NULL, delimiters)  ) ||
-      !(   version=strtok(NULL, delimiters)  ) ||
-      !(      date=strtok(NULL, delimiters)  ) )
-    return 0;
-
-   sprintf(out,"%-13s revision: %-6s date: %-15s", filename, version, date);
-   free(copy);
-   return  (date-copy)+strlen(date);
-}
-
-// prints a single set of CVS ids
-void printone(char *block, const char *cvsid){
-  char strings[CVSMAXLEN];
-  const char *here=cvsid;
-  int line=1,len=strlen(cvsid)+1;
-
-  // check that the size of the output block is sufficient
-  if (len>=CVSMAXLEN) {
-    fprintf(stderr,"CVSMAXLEN=%d must be at least %d\n",CVSMAXLEN,len+1);
-    exit(1);
-  }
-
-  // loop through the different strings
-  while ((len=massagecvs(strings,here))){
-    switch (line++){
-    case 1:
-      block+=snprintf(block,CVSMAXLEN,"Module:");
-      break;
-    default:
-      block+=snprintf(block,CVSMAXLEN,"  uses:");
-    } 
-    block+=snprintf(block,CVSMAXLEN," %s\n",strings);
-    here+=len;
-  }
-  return;
-}
diff --git a/sm5/atacmds.h b/sm5/atacmds.h
index 5f277887b..541279547 100644
--- a/sm5/atacmds.h
+++ b/sm5/atacmds.h
@@ -26,7 +26,7 @@
 #define _ATACMDS_H_
 
 #ifndef ATACMDS_H_CVSID
-#define ATACMDS_H_CVSID "$Id: atacmds.h,v 1.31 2003/01/16 15:28:57 ballen4705 Exp $\n"
+#define ATACMDS_H_CVSID "$Id: atacmds.h,v 1.32 2003/01/16 15:51:09 ballen4705 Exp $\n"
 #endif
 
 // These are the major and minor versions for smartd and smartctl
@@ -349,12 +349,6 @@ void ataPrintSmartAttribName(char *output, unsigned char id, unsigned char *defs
 void pout(char *fmt, ...)  
      __attribute__ ((format (printf, 1, 2)));
 
-
-
-// utility function for printing out CVS strings
-#define CVSMAXLEN 512
-void printone(char *block, const char *cvsid);
-
 // replacement for perror() with redirected output.
 void syserror(const char *message);
 
diff --git a/sm5/smartctl.c b/sm5/smartctl.c
index a5e45d0c9..9ebd83d36 100644
--- a/sm5/smartctl.c
+++ b/sm5/smartctl.c
@@ -40,10 +40,11 @@
 #include "scsicmds.h"
 #include "scsiprint.h"
 #include "smartctl.h"
+#include "utility.h"
 
 extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *scsiprint_c_cvsid, *utility_c_cvsid; 
-const char* smartctl_c_cvsid="$Id: smartctl.c,v 1.48 2003/01/16 15:28:57 ballen4705 Exp $"
-ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SCSIPRINT_H_CVSID SMARTCTL_H_CVSID;
+const char* smartctl_c_cvsid="$Id: smartctl.c,v 1.49 2003/01/16 15:51:09 ballen4705 Exp $"
+ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SCSIPRINT_H_CVSID SMARTCTL_H_CVSID UTILITY_H_CVSID;
 
 // This is a block containing all the "control variables".  We declare
 // this globally in this file, and externally in other files.
diff --git a/sm5/smartctl.cpp b/sm5/smartctl.cpp
index 6a821acfa..833fcc915 100644
--- a/sm5/smartctl.cpp
+++ b/sm5/smartctl.cpp
@@ -40,10 +40,11 @@
 #include "scsicmds.h"
 #include "scsiprint.h"
 #include "smartctl.h"
+#include "utility.h"
 
 extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *scsiprint_c_cvsid, *utility_c_cvsid; 
-const char* smartctl_c_cvsid="$Id: smartctl.cpp,v 1.48 2003/01/16 15:28:57 ballen4705 Exp $"
-ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SCSIPRINT_H_CVSID SMARTCTL_H_CVSID;
+const char* smartctl_c_cvsid="$Id: smartctl.cpp,v 1.49 2003/01/16 15:51:09 ballen4705 Exp $"
+ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SCSIPRINT_H_CVSID SMARTCTL_H_CVSID UTILITY_H_CVSID;
 
 // This is a block containing all the "control variables".  We declare
 // this globally in this file, and externally in other files.
diff --git a/sm5/smartd.c b/sm5/smartd.c
index e05e2e73d..eeb44afbe 100644
--- a/sm5/smartd.c
+++ b/sm5/smartd.c
@@ -46,11 +46,12 @@
 #include "extern.h"
 #include "scsicmds.h"
 #include "smartd.h"
+#include "utility.h"
 
 // CVS ID strings
 extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid;
-const char *smartd_c_cvsid="$Id: smartd.c,v 1.97 2003/01/16 15:28:57 ballen4705 Exp $" 
-ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID; 
+const char *smartd_c_cvsid="$Id: smartd.c,v 1.98 2003/01/16 15:51:09 ballen4705 Exp $" 
+ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; 
 
 // global variable used for control of printing, passing arguments, etc.
 atamainctrl *con=NULL;
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index 4e5cdde3a..0fa3b6b81 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -46,11 +46,12 @@
 #include "extern.h"
 #include "scsicmds.h"
 #include "smartd.h"
+#include "utility.h"
 
 // CVS ID strings
 extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid;
-const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.97 2003/01/16 15:28:57 ballen4705 Exp $" 
-ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID; 
+const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.98 2003/01/16 15:51:09 ballen4705 Exp $" 
+ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; 
 
 // global variable used for control of printing, passing arguments, etc.
 atamainctrl *con=NULL;
diff --git a/sm5/utility.c b/sm5/utility.c
index bc70d4819..22016c101 100644
--- a/sm5/utility.c
+++ b/sm5/utility.c
@@ -31,9 +31,10 @@
 #include <string.h>
 #include <time.h>
 #include "utility.h"
+#include "stdlib.h"
 
 // Any local header files should be represented by a CVSIDX just below.
-const char* utility_c_cvsid="$Id: utility.c,v 1.1 2003/01/16 15:28:58 ballen4705 Exp $" UTILITY_H_CVSID;
+const char* utility_c_cvsid="$Id: utility.c,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $" UTILITY_H_CVSID;
 
 // Utility function prints date and time and timezone into a character
 // buffer of length>=64.  All the fuss is needed to get the right
@@ -73,3 +74,59 @@ void dateandtimezone(char *buffer){
   
   return;
 }
+
+
+// These are two utility functions for printing CVS IDs. Massagecvs()
+// returns distance that it has moved ahead in the input string
+int massagecvs(char *out, const char *cvsid){
+  char *copy,*filename,*date,*version;
+  const char delimiters[] = " ,$";
+
+  // make a copy on stack, go to first token,
+  if (!(copy=strdup(cvsid)) || !(filename=strtok(copy, delimiters))) 
+    return 0;
+
+  // move to first instance of "Id:"
+  while (strcmp(filename,"Id:"))
+    if (!(filename=strtok(NULL, delimiters)))
+      return 0;
+
+  // get filename, skip "v", get version and date
+  if (!(  filename=strtok(NULL, delimiters)  ) ||
+      !(           strtok(NULL, delimiters)  ) ||
+      !(   version=strtok(NULL, delimiters)  ) ||
+      !(      date=strtok(NULL, delimiters)  ) )
+    return 0;
+
+   sprintf(out,"%-13s revision: %-6s date: %-15s", filename, version, date);
+   free(copy);
+   return  (date-copy)+strlen(date);
+}
+
+// prints a single set of CVS ids
+void printone(char *block, const char *cvsid){
+  char strings[CVSMAXLEN];
+  const char *here=cvsid;
+  int line=1,len=strlen(cvsid)+1;
+
+  // check that the size of the output block is sufficient
+  if (len>=CVSMAXLEN) {
+    fprintf(stderr,"CVSMAXLEN=%d must be at least %d\n",CVSMAXLEN,len+1);
+    exit(1);
+  }
+
+  // loop through the different strings
+  while ((len=massagecvs(strings,here))){
+    switch (line++){
+    case 1:
+      block+=snprintf(block,CVSMAXLEN,"Module:");
+      break;
+    default:
+      block+=snprintf(block,CVSMAXLEN,"  uses:");
+    } 
+    block+=snprintf(block,CVSMAXLEN," %s\n",strings);
+    here+=len;
+  }
+  return;
+}
+
diff --git a/sm5/utility.cpp b/sm5/utility.cpp
index 97ba0350f..0bab41622 100644
--- a/sm5/utility.cpp
+++ b/sm5/utility.cpp
@@ -31,9 +31,10 @@
 #include <string.h>
 #include <time.h>
 #include "utility.h"
+#include "stdlib.h"
 
 // Any local header files should be represented by a CVSIDX just below.
-const char* utility_c_cvsid="$Id: utility.cpp,v 1.1 2003/01/16 15:28:58 ballen4705 Exp $" UTILITY_H_CVSID;
+const char* utility_c_cvsid="$Id: utility.cpp,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $" UTILITY_H_CVSID;
 
 // Utility function prints date and time and timezone into a character
 // buffer of length>=64.  All the fuss is needed to get the right
@@ -73,3 +74,59 @@ void dateandtimezone(char *buffer){
   
   return;
 }
+
+
+// These are two utility functions for printing CVS IDs. Massagecvs()
+// returns distance that it has moved ahead in the input string
+int massagecvs(char *out, const char *cvsid){
+  char *copy,*filename,*date,*version;
+  const char delimiters[] = " ,$";
+
+  // make a copy on stack, go to first token,
+  if (!(copy=strdup(cvsid)) || !(filename=strtok(copy, delimiters))) 
+    return 0;
+
+  // move to first instance of "Id:"
+  while (strcmp(filename,"Id:"))
+    if (!(filename=strtok(NULL, delimiters)))
+      return 0;
+
+  // get filename, skip "v", get version and date
+  if (!(  filename=strtok(NULL, delimiters)  ) ||
+      !(           strtok(NULL, delimiters)  ) ||
+      !(   version=strtok(NULL, delimiters)  ) ||
+      !(      date=strtok(NULL, delimiters)  ) )
+    return 0;
+
+   sprintf(out,"%-13s revision: %-6s date: %-15s", filename, version, date);
+   free(copy);
+   return  (date-copy)+strlen(date);
+}
+
+// prints a single set of CVS ids
+void printone(char *block, const char *cvsid){
+  char strings[CVSMAXLEN];
+  const char *here=cvsid;
+  int line=1,len=strlen(cvsid)+1;
+
+  // check that the size of the output block is sufficient
+  if (len>=CVSMAXLEN) {
+    fprintf(stderr,"CVSMAXLEN=%d must be at least %d\n",CVSMAXLEN,len+1);
+    exit(1);
+  }
+
+  // loop through the different strings
+  while ((len=massagecvs(strings,here))){
+    switch (line++){
+    case 1:
+      block+=snprintf(block,CVSMAXLEN,"Module:");
+      break;
+    default:
+      block+=snprintf(block,CVSMAXLEN,"  uses:");
+    } 
+    block+=snprintf(block,CVSMAXLEN," %s\n",strings);
+    here+=len;
+  }
+  return;
+}
+
diff --git a/sm5/utility.h b/sm5/utility.h
index 1d1d216a6..da875041c 100644
--- a/sm5/utility.h
+++ b/sm5/utility.h
@@ -26,7 +26,7 @@
 #define __UTILITY_H_
 
 #ifndef UTILITY_H_CVSID
-#define UTILITY_H_CVSID "$Id: utility.h,v 1.1 2003/01/16 15:28:58 ballen4705 Exp $\n"
+#define UTILITY_H_CVSID "$Id: utility.h,v 1.2 2003/01/16 15:51:10 ballen4705 Exp $\n"
 #endif
 
 // Utility function prints date and time and timezone into a character
@@ -34,4 +34,8 @@
 // timezone info (sigh).
 void dateandtimezone(char *buffer);
 
+// utility function for printing out CVS strings
+#define CVSMAXLEN 512
+void printone(char *block, const char *cvsid);
+
 #endif
-- 
GitLab