|
|
@@ -0,0 +1,97 @@
|
|
|
+/* vcc/plugins/hist/hist.c
|
|
|
+ *
|
|
|
+ * This file is part of vcc.
|
|
|
+ *
|
|
|
+ * vcc is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * vcc is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <fcntl.h>
|
|
|
+#include <string.h>
|
|
|
+#include <limits.h>
|
|
|
+
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/times.h>
|
|
|
+
|
|
|
+#include <vcc/vcc.h>
|
|
|
+#include <vcc/pretty.h>
|
|
|
+#include <vcc/plugin.h>
|
|
|
+#include <vcc/version.h>
|
|
|
+
|
|
|
+#include <readconf/readconf.h>
|
|
|
+
|
|
|
+
|
|
|
+int hist_init(void);
|
|
|
+int hist_fd;
|
|
|
+
|
|
|
+struct cmdtable hist_cmdtab[] = {
|
|
|
+ { NULL, NULL, NULL }
|
|
|
+};
|
|
|
+
|
|
|
+struct plugin plg_hist = {
|
|
|
+ .state = 0,
|
|
|
+ .name = "hist",
|
|
|
+ .descr = "Show history. ",
|
|
|
+ .init = hist_init,
|
|
|
+ .cmdtab = hist_cmdtab
|
|
|
+};
|
|
|
+
|
|
|
+#define this_plg (&plg_hist)
|
|
|
+#define DEFAULT_HISTFILE ".vcc_history"
|
|
|
+
|
|
|
+char *hist_recvhook(char *s, char *usr) {
|
|
|
+ dprintf(hist_fd, "[%ld] %s: %s", times(NULL), usr, s);
|
|
|
+ return strdup(s);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int open_hist_file(void) {
|
|
|
+ struct readconf_strconf *conf;
|
|
|
+ char *p;
|
|
|
+ char buf[PATH_MAX];
|
|
|
+
|
|
|
+ if (!(conf = readconf_find_strname("histfile"))) {
|
|
|
+ p = getenv("HOME");
|
|
|
+ sprintf(buf, "%s/" DEFAULT_HISTFILE, p);
|
|
|
+ p = buf;
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ p = conf->conf_value;
|
|
|
+
|
|
|
+ printf("using history file %s\n", p);
|
|
|
+
|
|
|
+ if (unlikely((hist_fd = open(p, O_WRONLY | O_APPEND | O_CREAT)) < 0)) {
|
|
|
+ perror("open()");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hist_fd;
|
|
|
+}
|
|
|
+
|
|
|
+int hist_init(void) {
|
|
|
+ if (unlikely((hist_fd = open_hist_file()) < 0)) {
|
|
|
+ fprintf(stderr, "*** unable to open history file. \n");
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return register_recvhook(hist_recvhook, this_plg);
|
|
|
+}
|
|
|
+
|