|
|
@@ -105,8 +105,15 @@ static inline int check_hist_enabled(void) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-int m4_write_predef(int fd) {
|
|
|
- struct history *hist;
|
|
|
+/* this causes a infinite recursion, which is the thing m4 programmers are afraid of. */
|
|
|
+
|
|
|
+int m4_write_predef(char *buf) {
|
|
|
+ (void) buf;
|
|
|
+
|
|
|
+#if 0
|
|
|
+ struct history *hist;
|
|
|
+ char *p;
|
|
|
+ char s[128];
|
|
|
|
|
|
if (!check_hist_enabled()) {
|
|
|
fprintf(stderr, _("the history plugin (hist) doesn't insert so m4 preder can't work. \n"));
|
|
|
@@ -117,30 +124,44 @@ int m4_write_predef(int fd) {
|
|
|
hist = hist_getmsg(1);
|
|
|
|
|
|
if (!hist)
|
|
|
- return 0;
|
|
|
+ p = "\n";
|
|
|
+ else
|
|
|
+ p = hist->msg;
|
|
|
|
|
|
- dprintf(fd, "divert(-1)define(`LAST_MSG', `%s'\n)divert(0)dnl\n", hist->msg);
|
|
|
+ sprintf(s, "divert(-1)define(`LAST_MSG', `%s'\n)divert(0)dnl\n", p);
|
|
|
+ strcat(buf, s);
|
|
|
|
|
|
+#endif
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
char *m4_hook(struct hook_info *hi) {
|
|
|
- int fdt, size;
|
|
|
+ int fdt;
|
|
|
FILE *fp;
|
|
|
char *p;
|
|
|
|
|
|
- if (unlikely((fdt = open("/tmp/.vcc-tmp", O_WRONLY | O_TRUNC | O_CREAT, 0666)) < 0)) {
|
|
|
+ if (unlikely((fdt = open("/tmp/.vcc-tmp", O_WRONLY | O_TRUNC | O_CREAT | O_APPEND, 0666)) < 0)) {
|
|
|
perror("open");
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
+
|
|
|
+ if (unlikely(!(p = malloc(8192)))) {
|
|
|
+ fprintf(stderr, "*** malloc() failed\n");
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(p, 0, 8192);
|
|
|
|
|
|
- write(fdt, m4cachep, m4cache_size);
|
|
|
- m4_write_predef(fdt);
|
|
|
+ if (m4cachep)
|
|
|
+ strcat(p, m4cachep);
|
|
|
|
|
|
- size = strlen(hi->msg) + 1;
|
|
|
- write(fdt, hi->msg, size);
|
|
|
+ m4_write_predef(p);
|
|
|
+ strcat(p, hi->msg);
|
|
|
+
|
|
|
+ write(fdt, p, strlen(p));
|
|
|
close(fdt);
|
|
|
|
|
|
if (unlikely(!(fp = popen("/bin/m4 /tmp/.vcc-tmp", "r")))) {
|
|
|
@@ -166,6 +187,12 @@ int m4_init(void) {
|
|
|
m4cachep = NULL;
|
|
|
m4cache_size = 0;
|
|
|
|
|
|
+ if (check_hist_enabled()) {
|
|
|
+ fprintf(stderr, "*** fatal: enable m4 after the hist enabled will cause a RECURSION when try to use LAST_MSG! \n");
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
register_hook(HOOK_SEND, m4_hook);
|
|
|
return 0;
|
|
|
}
|