2 * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 static FILE *debug_fd = NULL;
34 /* Helper functions */
35 static void message(FILE *output_fd, const char *prefix, const char *fmt, va_list ap)
39 /* Log to standard out */
42 fprintf(output_fd, "%s: ", prefix);
43 vfprintf(output_fd, fmt, tmp);
44 fprintf(output_fd, "\n");
47 /* Log to debug file */
50 fprintf(debug_fd, "%s: ", prefix);
51 vfprintf(debug_fd, fmt, tmp);
52 fprintf(debug_fd, "\n");
55 /* Log to status bar */
56 if (&COMPACT && stdscr) {
57 int rev = COMPACT ? A_BOLD : 0;
60 mvhline(LINES-2, 0, ACS_HLINE, COLS);
62 attron(COLOR_PAIR(COLOR_ERROR) | rev);
63 vwprintw(stdscr, fmt, tmp);
64 attroff(COLOR_PAIR(COLOR_ERROR) | rev);
73 debug_fd = fopen("/tmp/lackey.log", "w+");
76 /* String functions */
77 void strsub(char *str, char find, char repl)
79 for (char *cur = str; *cur; cur++)
84 /* Memory functions */
85 void *alloc0(int size)
87 void *data = calloc(1, size);
89 error("memory allocation failed");
93 /* Debugging functions */
94 void debug(char *fmt, ...)
98 message(NULL, "debug", fmt, ap);
102 void error(char *fmt, ...)
108 message(stderr, "error", fmt, ap);