1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* output.c - functions for message and error output
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 * (at your option) any later version.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 * GNU General Public License for more details.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 /*
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 * $Id: output.c,v 1.11 2007/03/23 05:49:48 jason Exp $
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 #include <stdio.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 #ifdef HAVE_CONFIG_H
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 #include "config.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 void print_lines(char *prefix,char *message)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 char *head, *tail;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 head = tail = message;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 while (*head != '\0') {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 if (*head == '\n') {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 *head = '\0';
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 fprintf(stderr,"%s%s\n",prefix,tail);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 tail = head + 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 head++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 fprintf(stderr,"%s%s\n",prefix,tail);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 void shn_error(char *msg, ...)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 va_list args;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 char msgbuf[BUF_SIZE];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 va_start(args,msg);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 shn_vsnprintf(msgbuf,BUF_SIZE,msg,args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 switch (shn_cfg.error_output_method) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 case ERROR_OUTPUT_STDERR:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 print_lines(PACKAGE ": ",msgbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60 case ERROR_OUTPUT_WINDOW:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 shn_message_box(msgbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64 if (0 != shn_cfg.verbose)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 print_lines(PACKAGE " [error]: ",msgbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 va_end(args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 void shn_debug(char *msg, ...)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 va_list args;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 char msgbuf[BUF_SIZE];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 va_start(args,msg);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78 shn_vsnprintf(msgbuf,BUF_SIZE,msg,args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80 if (0 != shn_cfg.verbose)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81 print_lines(PACKAGE " [debug]: ",msgbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 va_end(args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 void shn_error_fatal(shn_file *this_shn,char *complaint, ...)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88 va_list args;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 va_start(args,complaint);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 if (NULL != this_shn) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 if (0 == this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 this_shn->vars.fatal_error = 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 this_shn->vars.going = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 shn_vsnprintf(this_shn->vars.fatal_error_msg,BUF_SIZE,complaint,args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 va_end(args);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 }
|