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/>.
29 static FILE *debug_fd = NULL;
31 /* Helper functions */
32 static void message(FILE *output_fd, const char *prefix, const char *fmt, va_list ap)
36 /* Log to standard out */
39 fprintf(output_fd, "%s: ", prefix);
40 vfprintf(output_fd, fmt, tmp);
41 fprintf(output_fd, "\n");
44 /* Log to debug file */
47 fprintf(debug_fd, "%s: ", prefix);
48 vfprintf(debug_fd, fmt, tmp);
49 fprintf(debug_fd, "\n");
52 /* Log to status bar */
55 mvhline(LINES-2, 0, ACS_HLINE, COLS);
57 attron(COLOR_PAIR(COLOR_ERROR));
58 vwprintw(stdscr, fmt, tmp);
59 attroff(COLOR_PAIR(COLOR_ERROR));
67 debug_fd = fopen("/tmp/lackey.log", "w+");
70 /* String functions */
71 void strsub(char *str, char find, char repl)
73 for (char *cur = str; *cur; cur++)
78 /* Memory functions */
79 void *alloc0(int size)
81 void *data = calloc(1, size);
83 error("memory allocation failed");
87 /* Debugging functions */
88 void debug(char *fmt, ...)
92 message(NULL, "debug", fmt, ap);
96 void error(char *fmt, ...)
102 message(stderr, "error", fmt, ap);