Consistently rebuild version.c; optimize how it is generated.
authorMichael Poole <mdpoole@troilus.org>
Wed, 15 Aug 2007 01:15:53 +0000 (01:15 +0000)
committerMichael Poole <mdpoole@troilus.org>
Wed, 15 Aug 2007 01:15:53 +0000 (01:15 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1831 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ircd/Makefile.in
ircd/umkpasswd.c
ircd/version.c.SH

index 027fd6e99ab8acbc2740f979d4031d857a1c08f5..a75a218404215ea49e2ac3bda533a5e980c898ff 100644 (file)
@@ -242,18 +242,8 @@ ircd: ${OBJS} ../include/patchlevel.h version.o
 convert-conf: ${CONVERT_CONF_OBJS}
        ${PURIFY} ${CC} ${CONVERT_CONF_OBJS} ${LDFLAGS} -o convert-conf
 
-#
-# Make sure the anti hack checksums get included when things change
-# bleah
-#
-# Yeah, "bleah" is right.  These checksums don't cover even a fraction of
-# the "important" .c files...but are useful to determine whether someone
-# actually is running the version they claim to be running or not.  There
-# must be a better solution...perhaps sum all of the .c files and include
-# only that one sum?
-#
-version.c: ../include/patchlist.h version.c.SH umkpasswd \
-       ../include/version.h ../include/patchlevel.h ${SRC}
+.PHONY: version.c
+version.c: version.c.SH umkpasswd
        ${SHELL} ${srcdir}/version.c.SH ${top_srcdir}
 
 ../include/patchlist.h:
@@ -322,7 +312,7 @@ uninstall:
        @echo "Please remove the contents of ${DPATH} manually"
 
 clean:
-       ${RM} -f *.o *.bak ircd version.c umkpasswd convert-conf chattr.tab.c table_gen y.tab.* lex.yy.*
+       ${RM} -f *.o *.bak ircd umkpasswd convert-conf chattr.tab.c table_gen y.tab.* lex.yy.*
 
 distclean: clean
        ${RM} -f Makefile stamp-m
index d3ef4e5b2fa9e400963109f756ad6fe534628447..29014a16c28d8418724b96016831ced335d5a98c 100644 (file)
@@ -20,6 +20,7 @@
 */
 #include "config.h"
 #include <unistd.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <errno.h>
@@ -181,54 +182,46 @@ crypt_mechs_t* crypt_mech;
 return 0;
 }
 
-char *basename_into(char *tmp, char *target)
-{
-  unsigned int len, ii;
-
-  len = strlen(tmp);
-  for (ii = len; ii > 0; )
-    if (tmp[--ii] == '/')
-      break;
-  if (ii < len - 1)
-    return tmp + ii + (tmp[ii] == '/');
-  else if (tmp[ii] != '/')
-    return tmp;
-  else if (ii == 0)
-    return tmp;
-  else
-  {
-    while (ii > 0)
-      if (tmp[--ii] == '/')
-         break;
-    if (tmp[ii] == '/')
-        ii++;
-    for (len = 0; tmp[ii] != '/'; )
-      target[len++] = tmp[ii++];
-    target[len] = '\0';
-    return target;
-  }
-}
-
 void sum(char* tmp)
 {
+char* str;
 FILE* file;
 MD5_CTX context;
 int len;
-unsigned char buffer[1024], digest[16];
+unsigned char buffer[1024], digest[16], vstr[32];
 
+vstr[0] = '\0';
+ str = tmp + strlen(tmp);
+ while (str[-1] == '\r' || str[-1] == '\n') *--str = '\0';
  if (NULL == (file = fopen(tmp, "r")))
+ {
+  fprintf(stderr, "unable to open %s: %s", tmp, strerror(errno));
   exit(0);
+ }
  MD5Init(&context);
- while ((len = fread (buffer, 1, 1024, file)))
+ while ((fgets((char*)buffer, sizeof(buffer), file)) != NULL)
+ {
+  MD5Update(&context, buffer, strlen(buffer));
+  str = strstr((char*)buffer, "$Id: ");
+  if (str != NULL)
+  {
+   for (str += 5; !isspace(*str); ++str) {}
+   while (isspace(*++str)) {}
+   for (len = 0; !isspace(str[len]); ++len) vstr[len] = str[len];
+   vstr[len] = '\0';
+   break;
+  }
+ }
+ while ((len = fread (buffer, 1, sizeof(buffer), file)))
   MD5Update(&context, buffer, len);
  MD5Final(digest, &context);
  fclose(file);
 
- printf("%s: ", basename_into(tmp, (char*)buffer));
+ str = strrchr(tmp, '/');
+ printf("    \"[ %s: ", str ? (str + 1) : tmp);
  for (len = 0; len < 16; len++)
   printf ("%02x", digest[len]);
- printf("\n");
- exit(0);
+ printf(" %s ]\",\n", vstr);
 }
 
 /* dump the loaded mechs list */
@@ -321,7 +314,7 @@ return tagged;
 char* parse_arguments(int argc, char **argv)
 {
 int len = 0, c = 0;
-const char* options = "a:d:lm:u:y:5:";
+const char* options = "a:d:lm:u:y:5";
 
  umkpasswd_conf = (umkpasswd_conf_t*)MyMalloc(sizeof(umkpasswd_conf_t));
 
@@ -346,8 +339,11 @@ const char* options = "a:d:lm:u:y:5:";
   switch (c)
   {
    case '5':
-    sum(optarg);
-   break;
+   {
+    char t1[1024];
+    while (fgets(t1, sizeof(t1), stdin)) sum(t1);
+   }
+   exit(0);
 
    case 'y':
     umkpasswd_conf->operclass = atoi(optarg);
index 0e873703837ba052e120890bba99783d09f93684..03c02c332b045dabd137ac5768a07aea2ee3bcff 100644 (file)
@@ -85,24 +85,16 @@ const char *infotext[] = {
     "Sources:",
 !SUB!THIS!
 
-for file in ${srcdir}/ircd/*.[cly] ${srcdir}/ircd/version.c.SH ; do
- base=`basename $file`
- if [ $base != version.c -a $base != y.tab.c -a $base != lex.yy.c -a \
-      $base != chattr.tab.c ] ; then
-  vers=`grep '$Id' $file | sed -e 's/.*\$Id\://' -e 's/\$[^$]*//' | \
-       awk '{ print $2; exit; }'`
-  echo "    \"[" `./umkpasswd -5 $file` " $vers ]\"," >> version.c
- fi
-done
+( for file in ${srcdir}/ircd/*.[cly] ${srcdir}/ircd/version.c.SH ; do
+    case `basename $file` in
+      ( version.c | y.tab.c | lex.yy.c | chattr.tab.c ) ;;
+      ( * ) echo $file ;;
+    esac done ) | ./umkpasswd -5 >> version.c
 
 echo "    \"\"," >> version.c
 echo "    \"Headers:\"," >> version.c
 
-for file in ${srcdir}/include/*.h ; do
- vers=`grep '$Id' $file | sed -e 's/.*\$Id\://' -e 's/\$[^$]*//' | \
-       awk '{ print $2; exit; }'`
- echo "    \"[" `./umkpasswd -5 $file` " $vers ]\"," >> version.c
-done
+( for file in ${srcdir}/include/*.h ; do echo $file ; done ) | ./umkpasswd -5 >> version.c
 
 /bin/cat >>version.c <<!SUB!THIS!
     0,