-
Notifications
You must be signed in to change notification settings - Fork 337
/
Copy pathmisc.c
145 lines (124 loc) · 5.27 KB
/
misc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * MISCELLANEOUS * */
/* * * */
/* * $Module: MISC * */
/* * * */
/* * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 * */
/* * MPI fuer Informatik * */
/* * * */
/* * This program 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 2 of the License, * */
/* * or (at your option) any later version. * */
/* * * */
/* * This program 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 this program; if not, write * */
/* * to the Free Software Foundation, Inc., 59 Temple * */
/* * Place, Suite 330, Boston, MA 02111-1307 USA * */
/* * * */
/* * * */
/* $Revision$ * */
/* $State$ * */
/* $Date$ * */
/* $Author$ * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: weidenb@mpi-sb.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* $RCSfile$ */
/**************************************************************/
/* Includes */
/**************************************************************/
#include "misc.h"
/**************************************************************/
/* Functions */
/**************************************************************/
void misc_ErrorReport(const char * Format, ...)
{
va_list args;
va_start(args,Format);
vfprintf(misc_ERROROUT,Format,args);
va_end(args);
}
void misc_UserErrorReport(const char * Format, ...)
{
va_list args;
va_start(args,Format);
vfprintf(misc_USERERROROUT,Format,args);
va_end(args);
}
void misc_DumpCoreOut(const char* String)
/**************************************************************
INPUT: A string.
RETURNS: Nothing.
EFFECT: Prints <String> and then dumps a core.
***************************************************************/
{
fprintf(stderr, "\n %s \n", String);
misc_DumpCore();
}
int misc_ReturnValue(void)
{
return 0;
}
int misc_Max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
FILE* misc_OpenFile(const char* Name, const char* Mode)
/**************************************************************
INPUT: The name of a file and a string containing the mode
for opening the file (see fopen(3)).
Examples for Mode are "r" for reading and "w" for writing.
RETURNS: The FILE pointer, if the file was successfully opened.
EFFECT: If it wasn't possible to open the file with the
requested mode, an error message is printed and the
program exits.
***************************************************************/
{
FILE* File;
File = fopen(Name,Mode);
if (File == (FILE*)NULL) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n\tError in opening file %s for %s !\n\n", Name,
(Mode[0] == 'r' ? "reading" :
(Mode[0] == 'w' ? "writing" : "i/o operations")));
misc_FinishUserErrorReport();
}
return File;
}
void misc_CloseFile(FILE* File, const char* Name)
/**************************************************************
INPUT: A FILE and its name.
RETURNS: Nothing.
EFFECT: Closes the file. If an error occurs, a message is
printed and the program exits.
***************************************************************/
{
int Result;
Result = fclose(File);
if (Result != 0) {
misc_StartUserErrorReport();
misc_UserErrorReport("\n\tError in closing file %s !\n\n", Name);
misc_FinishUserErrorReport();
}
}