Ver código fonte

Remove the need for makeres

Bryan Drewery 11 anos atrás
pai
commit
a9041a7492
9 arquivos alterados com 90 adições e 139 exclusões
  1. 4 23
      Makefile.in
  2. 4 0
      build/autotools/configure.ac
  3. 33 0
      build/makeres.sh
  4. 4 0
      configure
  5. 1 3
      src/.gitignore
  6. 7 5
      src/Makefile.in
  7. 0 107
      src/makeres.cc
  8. 1 1
      src/response.cc
  9. 36 0
      src/response.h

+ 4 - 23
Makefile.in

@@ -26,7 +26,6 @@ VERSION 	:= $(shell git describe)
 DISTRIB = wraith-$(VERSION)
 
 HELPFILE = doc/help.txt
-RESPONSESFILE = doc/responses.txt
 
 # defaults
 CXX = @CCACHE@ @DISTCC@ @CXX@ @STATIC@
@@ -74,14 +73,14 @@ MAKE_UTILS_NR = $(MAKE) 'CXX=$(CXX)' 'STRIP=touch' 'INCLUDES=$(INCLUDES)' \
 
 MAKE_CONFIG = $(MAKE) 'MAKE=$(MAKE)'
 
-.PHONY: checkclean.static checkclean.dynamic checkclean.debug lib wraith dwraith lib.debug debug test general crypto utils sorthelp makehelp makeres stringfix res help sort indent tar distrib distclean clean cleanutils test all dynamic static tags
+.PHONY: checkclean.static checkclean.dynamic checkclean.debug lib wraith dwraith lib.debug debug test general crypto utils sorthelp makehelp stringfix help sort indent tar distrib distclean clean cleanutils test all dynamic static tags
 
 all: dynamic
 
 test:
 
 cleanutils:
-	@rm -f $(STRINGFIX) src/sorthelp@EXEEXT@ src/makehelp@EXEEXT@ src/makeres@EXEEXT@
+	@rm -f $(STRINGFIX) src/sorthelp@EXEEXT@ src/makehelp@EXEEXT@
 
 clean:  cleanutils
 	+@cd src && $(MAKE) clean
@@ -90,7 +89,7 @@ clean:  cleanutils
 	+@cd src/mod && $(MAKE) clean
 	-+@cd lib && $(MAKE) clean
 	@rm -f $(BINEXEC) build/stamp.* *~ src/*~ configure.temp .mangled stamp.*
-	@rm -f src/help.h src/response.h src/responses.h utctime@EXEEXT@ ts@EXEEXT@
+	@rm -f src/help.h utctime@EXEEXT@ ts@EXEEXT@
 
 distclean: clean
 	@rm -rf *-$(VERSION)/ autom4te.cache/ autoscan.log configure.scan
@@ -154,27 +153,9 @@ help: makehelp
 	cp -f src/help.h~ src/help.h; \
 	fi)
 
-res: makeres
-	@src/makeres@EXEEXT@ $(RESPONSESFILE) src/ 1
-	@(if [ ! -f src/response.h ]; then \
-	touch src/response.h; \
-	fi)
-	@(if [ ! -f src/responses.h ]; then \
-	touch src/responses.h; \
-	fi)
-	@(if test "x`$(DIFF) -qurN src/response.h~ src/response.h`" != "x"; then \
-	cp -f src/response.h~ src/response.h; \
-	fi)
-	@(if test "x`$(DIFF) -qurN src/responses.h~ src/responses.h`" != "x"; then \
-	cp -f src/responses.h~ src/responses.h; \
-	fi)
-
 stringfix: src/stringfix.cc src/config.h
 	+@cd src && ${MAKE_UTILS} stringfix
 
-makeres: src/makeres.cc
-	+@cd src && ${MAKE_UTILS} makeres
-
 makehelp: src/makehelp.cc
 	+@cd src && ${MAKE_UTILS} makehelp
 
@@ -186,7 +167,7 @@ utils: stringfix makehelp
 crypto:
 	+@cd src/crypto && ${MAKE_UTILS} crypto
 
-general: help res stringfix
+general: help stringfix
 
 .NOTPARALLEL: checkclean.static checkclean.dynamic checkclean.debug
 

+ 4 - 0
build/autotools/configure.ac

@@ -257,6 +257,10 @@ if test -d .git; then
   git submodule init
   git submodule update
   git submodule foreach --recursive git clean -fdx
+  # Restore as it may have been removed by an older 'make distclean'
+  if ! test -f src/response.h; then
+    git checkout src/response.h
+  fi
 fi
 ]
 

+ 33 - 0
build/makeres.sh

@@ -0,0 +1,33 @@
+#! /bin/sh
+
+echo "/* Generated by $0 */"
+needcomma=0
+types=
+echo "typedef const char * res_t;"
+echo
+while read -r line; do
+	[ -z "${line%%#*}" ] && continue # skip comments
+	if [ -z "${line%%:*}" ]; then
+		[ ${needcomma} -eq 1 ] && printf ",\n\tNULL\n};\n\n"
+		type="${line#:}"
+		[ "${type}" = "end" ] && break
+		printf "static res_t res_%s[] = {\n" "${type}"
+		needcomma=0
+		types="${types}${types:+ }${type}"
+	else
+		[ ${needcomma} -eq 1 ] && printf ",\n"
+		printf "\t\"%s\"" "${line}"
+		needcomma=1
+	fi
+done
+
+echo "static res_t *res[] = {"
+printf "\tNULL,\n"
+needcomma=0
+for type in ${types}; do
+	[ ${needcomma} -eq 1 ] && printf ",\n"
+	printf "\tres_%s" "${type}"
+	needcomma=1
+done
+echo
+echo "};"

+ 4 - 0
configure

@@ -10207,6 +10207,10 @@ if test -d .git; then
   git submodule init
   git submodule update
   git submodule foreach --recursive git clean -fdx
+  # Restore as it may have been removed by an older 'make distclean'
+  if ! test -f src/response.h; then
+    git checkout src/response.h
+  fi
 fi
 
 

+ 1 - 3
src/.gitignore

@@ -4,14 +4,12 @@
 /_*.cc
 /*~
 /help.h
-/response.h
-/responses.h
+/responses.cc
 /.deps
 /.defs
 /stringfix
 /makehelp
 /sorthelp
-/makeres
 /set_default.h
 *.o
 *.So

+ 7 - 5
src/Makefile.in

@@ -12,6 +12,7 @@ CFLAGS = $(CFLGS)
 CPPFLAGS = @CPPFLAGS@ -I. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/pack @DEFS@ $(INCLUDES) '-DCOMMIT="$(COMMIT)"' '-DBRANCH="$(BRANCH)"' -DBUILDTS=$(BUILDTS) '-DVERSION="$(VERSION)"'
 LDFLAGS = @LDFLAGS@
 SETTINGSFILE = $(top_srcdir)/doc/settings.txt
+RESPONSESFILE = $(top_srcdir)/doc/responses.txt
 
 include $(top_srcdir)/build/build.mk
 
@@ -83,10 +84,11 @@ set_default.h: $(SETTINGSFILE) $(top_srcdir)/build/makeset.sh
 	@echo -e "[H]	\033[1m$*\033[0m"
 	@$(top_srcdir)/build/makeset.sh < $(SETTINGSFILE) > $@
 
-makeres: makeres.cc ../lib/bdlib/src/libbdlib.a
-	@echo -e "Compiling: \033[1mmakeres\033[0m"
-	@$(CXX) $(CPPFLAGS) -I$(top_srcdir)/src -I$(top_srcdir)/pack $(CXXFLAGS) $< ../lib/bdlib/src/libbdlib.a $(LDFLAGS) -o $@
-	@$(STRIP) $@@EXEEXT@
+response.cc: responses.cc
+
+responses.cc: $(RESPONSESFILE) $(top_srcdir)/build/makeres.sh
+	@echo -e "[CC]	\033[1m$*\033[0m"
+	@$(top_srcdir)/build/makeres.sh < $(RESPONSESFILE) > $@
 
 makehelp: makehelp.cc ../lib/bdlib/src/libbdlib.a
 	@echo -e "Compiling: \033[1mmakehelp\033[0m"
@@ -118,7 +120,7 @@ stringfix: stringfix.cc common.h config.h eggdrop.h
 $(EGGEXEC): stringfix ../$(EGGEXEC)
 
 clean:
-	@rm -f .depend *.o *.So *~ _*.c _*.cc *.ii *.i set_default.h
+	@rm -f .depend *.o *.So *~ _*.c _*.cc *.ii *.i set_default.h responses.cc
 
 build_msg:
 	@echo "[*] Compiling core components"

+ 0 - 107
src/makeres.cc

@@ -1,107 +0,0 @@
-
-#include <bdlib/src/String.h>
-#include <bdlib/src/Stream.h>
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <algorithm>
-
-int skipline (const char *line, int *skip) {
-  static int multi = 0;
-  if ((!strncmp(line, "//", 2))) {
-    (*skip)++;
-  } else if ( (strstr(line, "/*")) && (strstr(line, "*/")) ) {
-    multi = 0;
-    (*skip)++;
-  } else if ( (strstr(line, "/*")) ) {
-    (*skip)++;
-    multi = 1;
-  } else if ( (strstr(line, "*/")) ) {
-    multi = 0;
-  } else {
-    if (!multi) (*skip) = 0;
-  }
-  return (*skip);
-}
-
-int parse_res(const bd::String& inFile, const bd::String& outFile, const bd::String& outsFile) {
-  bd::Stream in, out, outs;
-  bd::String buffer, cmd, buf, lower_resps;
-
-  int skip = 0, total_responses = 0;
-
-  in.loadFile(inFile);
-  printf("Parsing res file '%s'", inFile.c_str());
-
-  out << bd::String::printf( "/* DO NOT EDIT THIS FILE. */\n\
-#ifndef _RESPONSE_H\n\
-#define _RESPONSE_H\n\
-\n\
-typedef unsigned int response_t;\n\n\
-enum {\n");
-
-  outs << bd::String::printf("/* DO NOT EDIT THIS FILE. */\n\
-#ifndef _RESPONSES_H\n\
-#define _RESPONSES_H\n\
-\n\
-typedef const char * res_t;\n\n");
-
-  while (in.tell() < in.length()) {
-    buffer = in.getline().chomp();
-    if ((skipline(buffer.c_str(), &skip))) continue;
-    if (buffer[0] == ':') { /* New cmd */
-      if (cmd.length()) {		/* CLOSE LAST RES */
-        out << ",\n";	/* for enum */
-        outs << "\tNULL\n};\n\n";
-        cmd.clear();
-      }
-
-      cmd = buffer(1);
-      if (cmd != "end") {		/* NEXT RES */
-        ++total_responses;
-        printf(".");
-
-        bd::String cmdUpper(cmd);
-        std::transform(cmdUpper.begin(), cmdUpper.end(), cmdUpper.mdata(), (int(*)(int)) toupper);
-        out << bd::String::printf("\tRES_%s", cmdUpper.c_str());
-        if (total_responses == 1)
-          out << " = 1";
-        outs << bd::String::printf("static res_t res_%s[] = {\n", cmd.c_str());
-        lower_resps += bd::String::printf(",\n\tres_%s", cmd.c_str());
-      } else {			/* END */
-        out << bd::String::printf("\tRES_END\n};\n\n#define RES_TYPES %d\n", total_responses);
-        out << bd::String::printf("const char *response(response_t);\nvoid init_responses();\nconst char *r_banned(struct chanset_t* chan);\n\n#endif /* !_RESPONSE_H */\n");
-        outs << bd::String::printf("static res_t *res[] = {\n\tNULL%s\n};\n#endif /* !_RESPONSES_H */\n", lower_resps.c_str());
-      }
-    } else {				/* NEXT RES TEXT */
-      ++buffer;
-      outs << bd::String::printf("\t\"%s\",\n", buffer.c_str());
-    }
-  }
-
-  if (out.writeFile(outFile)) {
-    fprintf(stderr, "Failure writing %s\n", outFile.c_str());
-    return 1;
-  }
-
-  if (outs.writeFile(outsFile)) {
-    fprintf(stderr, "Failure writing %s\n", outsFile.c_str());
-    return 1;
-  }
-
-  printf(" Success\n");
-
-  return 0;
-}
-
-int main(int argc, char **argv) {
-  if (argc < 3) return 1;
-
-  bd::String in(argv[1]), out, outs;
-
-  out = bd::String::printf("%s/response.h%s", argv[2], argc == 4 ? "~" : "");
-  outs = bd::String::printf("%s/responses.h%s", argv[2], argc == 4 ? "~" : "");
-  return parse_res(in, out, outs);
-}
-/* vim: set sts=2 sw=2 ts=8 et: */

+ 1 - 1
src/response.cc

@@ -9,7 +9,7 @@
 #include "common.h"
 #include "response.h"
 #include "main.h"
-#include "responses.h"
+#include "responses.cc"
 
 static response_t response_totals[RES_TYPES + 1];
 

+ 36 - 0
src/response.h

@@ -0,0 +1,36 @@
+#ifndef _RESPONSE_H
+#define _RESPONSE_H
+
+typedef unsigned int response_t;
+
+enum {
+	RES_BANNED = 1,
+	RES_KICKBAN,
+	RES_MASSDEOP,
+	RES_BADOP,
+	RES_BADOPPED,
+	RES_BITCHOP,
+	RES_BITCHOPPED,
+	RES_MANUALOP,
+	RES_MANUALOPPED,
+	RES_CLOSED,
+	RES_FLOOD,
+	RES_NICKFLOOD,
+	RES_KICKFLOOD,
+	RES_REVENGE,
+	RES_USERNAME,
+	RES_PASSWORD,
+	RES_BADUSERPASS,
+	RES_MIRCVER,
+	RES_MIRCSCRIPT,
+	RES_OTHERSCRIPT,
+	RES_END
+};
+
+#define RES_TYPES 20
+
+const char *response(response_t);
+void init_responses();
+const char *r_banned(struct chanset_t* chan);
+
+#endif /* !_RESPONSE_H */