diff options
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/interpreter.c | 19 | ||||
-rw-r--r-- | usr.bin/mg/log.c | 97 | ||||
-rw-r--r-- | usr.bin/mg/log.h | 22 |
3 files changed, 119 insertions, 19 deletions
diff --git a/usr.bin/mg/interpreter.c b/usr.bin/mg/interpreter.c index 19ed02ef4cb..82e79f7b83a 100644 --- a/usr.bin/mg/interpreter.c +++ b/usr.bin/mg/interpreter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interpreter.c,v 1.1 2019/07/18 05:57:48 lum Exp $ */ +/* $OpenBSD: interpreter.c,v 1.2 2019/07/18 10:50:24 lum Exp $ */ /* * This file is in the public domain. * @@ -48,6 +48,11 @@ #include "def.h" #include "funmap.h" +#ifdef MGLOG +#include "kbd.h" +#include "log.h" +#endif + static int multiarg(char *); static int isvar(char **, char **, int); static int foundvar(char *); @@ -142,6 +147,10 @@ multiarg(char *funstr) inlist = last = 0; for (p = argp; *p != '\0'; p++) { +#ifdef MGLOG + mglog_execbuf("", excbuf, argbuf, argp, last, inlist, cmdp, + p, contbuf); +#endif if (foundlst) { foundlst = 0; p--; /* otherwise 1st arg is missed from list. */ @@ -185,6 +194,10 @@ multiarg(char *funstr) return (dobeep_msg("strlcat error")); excline(excbuf); +#ifdef MGLOG + mglog_execbuf(" ", excbuf, argbuf, argp, + last, inlist, cmdp, p, contbuf); +#endif *p = ' '; /* so 'for' loop can continue */ if (last) { if (contbuf != NULL) { @@ -224,7 +237,9 @@ isvar(char **argp, char **tmpbuf, int sizof) if (SLIST_EMPTY(&varhead)) return (FALSE); - +#ifdef MGLOG + mglog_isvar(*tmpbuf, *argp, sizof); +#endif SLIST_FOREACH(v1, &varhead, entry) { if (strcmp(*argp, v1->name) == 0) { (void)(strlcpy(*tmpbuf, v1->vals, sizof) >= sizof); diff --git a/usr.bin/mg/log.c b/usr.bin/mg/log.c index 81a93e9282f..0b5a914f14a 100644 --- a/usr.bin/mg/log.c +++ b/usr.bin/mg/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.10 2019/06/28 13:35:02 deraadt Exp $ */ +/* $OpenBSD: log.c,v 1.11 2019/07/18 10:50:24 lum Exp $ */ /* * This file is in the public domain. @@ -55,17 +55,18 @@ #include "log.h" -char *mglogfiles_create(char *); -int mglog_lines(PF); -int mglog_undo(void); -int mglog_window(void); -int mglog_key(KEYMAP *map); +static char *mglogfiles_create(char *); +static int mglog_lines(PF); +static int mglog_undo(void); +static int mglog_window(void); +static int mglog_key(KEYMAP *map); char *mglogdir; extern char *mglogpath_lines; extern char *mglogpath_undo; extern char *mglogpath_window; extern char *mglogpath_key; +extern char *mglogpath_interpreter; int mgloglevel; int @@ -84,7 +85,7 @@ mglog(PF funct, KEYMAP *map) } -int +static int mglog_key(KEYMAP *map) { struct stat sb; @@ -127,7 +128,7 @@ mglog_key(KEYMAP *map) return (TRUE); } -int +static int mglog_window(void) { struct mgwin *wp; @@ -169,7 +170,7 @@ mglog_window(void) return (TRUE); } -int +static int mglog_undo(void) { struct undo_rec *rec; @@ -230,7 +231,7 @@ mglog_undo(void) return (TRUE); } -int +static int mglog_lines(PF funct) { struct line *lp; @@ -294,6 +295,70 @@ mglog_lines(PF funct) return (TRUE); } +/* + * See what the eval variable code is up to. + */ +int +mglog_isvar( + const char* const argbuf, + const char* const argp, + const int sizof +) +{ + FILE *fd; + + fd = fopen(mglogpath_interpreter, "a"); + + if (fprintf(fd, " argbuf:%s,argp:%s,sizof:%d<\n", + argbuf, + argp, + sizof + ) == -1) { + fclose(fd); + return (FALSE); + } + fclose(fd); + return (TRUE); +} + +/* + * See what the eval line code is up to. + */ +int +mglog_execbuf( + const char* const pre, + const char* const excbuf, + const char* const argbuf, + const char* const argp, + const int last, + const int inlist, + const char* const cmdp, + const char* const p, + const char* const contbuf +) +{ + FILE *fd; + + fd = fopen(mglogpath_interpreter, "a"); + + if (fprintf(fd, "%sexcbuf:%s,argbuf:%s,argp:%s,last:%d,inlist:%d,"\ + "cmdp:%s,p:%s,contbuf:%s<\n", + pre, + excbuf, + argbuf, + argp, + last, + inlist, + cmdp, + p, + contbuf + ) == -1) { + fclose(fd); + return (FALSE); + } + fclose(fd); + return (TRUE); +} /* * Make sure logging to log files can happen. @@ -304,13 +369,14 @@ mgloginit(void) struct stat sb; mode_t dir_mode, f_mode, oumask; char *mglogfile_lines, *mglogfile_undo, *mglogfile_window; - char *mglogfile_key; + char *mglogfile_key, *mglogfile_interpreter; mglogdir = "./log/"; mglogfile_lines = "line.log"; mglogfile_undo = "undo.log"; mglogfile_window = "window.log"; mglogfile_key = "key.log"; + mglogfile_interpreter = "interpreter.log"; /* * Change mgloglevel for desired level of logging. @@ -340,16 +406,19 @@ mgloginit(void) mglogpath_key = mglogfiles_create(mglogfile_key); if (mglogpath_key == NULL) return (FALSE); + mglogpath_interpreter = mglogfiles_create(mglogfile_interpreter); + if (mglogpath_interpreter == NULL) + return (FALSE); return (TRUE); } -char * +static char * mglogfiles_create(char *mglogfile) { struct stat sb; - char tmp[20], *tmp2; + char tmp[NFILEN], *tmp2; int fd; if (strlcpy(tmp, mglogdir, sizeof(tmp)) > @@ -358,7 +427,7 @@ mglogfiles_create(char *mglogfile) if (strlcat(tmp, mglogfile, sizeof(tmp)) > sizeof(tmp)) return (NULL); - if ((tmp2 = strndup(tmp, 20)) == NULL) + if ((tmp2 = strndup(tmp, NFILEN)) == NULL) return (NULL); if(stat(tmp2, &sb)) diff --git a/usr.bin/mg/log.h b/usr.bin/mg/log.h index e078e502148..75c41f08773 100644 --- a/usr.bin/mg/log.h +++ b/usr.bin/mg/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.4 2019/06/26 16:54:29 lum Exp $ */ +/* $OpenBSD: log.h,v 1.5 2019/07/18 10:50:24 lum Exp $ */ /* This file is in the public domain. */ @@ -6,10 +6,26 @@ * Specifically for mg logging functionality. * */ -int mglog(PF, KEYMAP *); -int mgloginit(void); +int mglog(PF, KEYMAP *); +int mgloginit(void); +int mglog_execbuf( const char* const, + const char* const, + const char* const, + const char* const, + const int, + const int, + const char* const, + const char* const, + const char* const + ); + +int mglog_isvar( const char* const, + const char* const, + const int + ); char *mglogpath_lines; char *mglogpath_undo; char *mglogpath_window; char *mglogpath_key; +char *mglogpath_interpreter; |