PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/cde/programs/dthelp/parser/canon1/util/error.c

https://bitbucket.org/tifan/cde
C | 439 lines | 338 code | 49 blank | 52 comment | 1 complexity | 33aabc83b863e78b55958113104f0621 MD5 | raw file
Possible License(s): LGPL-2.1, IPL-1.0, 0BSD
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: error.c /main/3 1995/11/08 09:50:44 rswiston $ */
  24. /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
  25. /* Error.c contains procedures for issuing error messages and warnings in
  26. BUILD and ELTDEF */
  27. #include <stdio.h>
  28. #include "basic.h"
  29. extern FILE *m_errfile ;
  30. extern int m_line ;
  31. extern LOGICAL errexit ;
  32. void eprefix(
  33. #if defined(M_PROTO)
  34. LOGICAL flag
  35. #endif
  36. ) ;
  37. void m_errline(
  38. #if defined(M_PROTO)
  39. char *text
  40. #endif
  41. ) ;
  42. void m_error(
  43. #if defined(M_PROTO)
  44. char *text
  45. #endif
  46. ) ;
  47. void m_err1(
  48. #if defined(M_PROTO)
  49. char *text, const M_WCHAR *arg
  50. #endif
  51. ) ;
  52. void m_mberr1(
  53. #if defined(M_PROTO)
  54. char *text, const char *arg
  55. #endif
  56. ) ;
  57. void m_err2(
  58. #if defined(M_PROTO)
  59. const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2
  60. #endif
  61. ) ;
  62. void m_err3(
  63. #if defined(M_PROTO)
  64. char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
  65. #endif
  66. ) ;
  67. void m_err5(
  68. #if defined(M_PROTO)
  69. char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4,
  70. M_WCHAR *arg5
  71. #endif
  72. ) ;
  73. void esuffix(
  74. #if defined(M_PROTO)
  75. void
  76. #endif
  77. ) ;
  78. void msgline(
  79. #if defined(M_PROTO)
  80. char *text
  81. #endif
  82. ) ;
  83. void msg1line(
  84. #if defined(M_PROTO)
  85. char *text, char *arg1
  86. #endif
  87. ) ;
  88. void skiptoend(
  89. #if defined(M_PROTO)
  90. M_NOPAR
  91. #endif
  92. ) ;
  93. void m_wctrace(
  94. #if defined(M_PROTO)
  95. M_WCHAR *text
  96. #endif
  97. ) ;
  98. void m_trace(
  99. #if defined(M_PROTO)
  100. char *text
  101. #endif
  102. ) ;
  103. void warning(
  104. #if defined(M_PROTO)
  105. char *text
  106. #endif
  107. ) ;
  108. void warning1(
  109. #if defined(M_PROTO)
  110. char *text, M_WCHAR *arg
  111. #endif
  112. ) ;
  113. void warning2(
  114. #if defined(M_PROTO)
  115. char *text, M_WCHAR *arg1, M_WCHAR *arg2
  116. #endif
  117. ) ;
  118. void warning3(
  119. #if defined(M_PROTO)
  120. char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3
  121. #endif
  122. ) ;
  123. void warning4(
  124. #if defined(M_PROTO)
  125. char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3, M_WCHAR *arg4
  126. #endif
  127. ) ;
  128. /* Write error message prefix */
  129. #if defined(M_PROTO)
  130. void eprefix(LOGICAL flag)
  131. #else
  132. void eprefix(flag)
  133. LOGICAL flag ;
  134. #endif
  135. {
  136. if (flag) errexit = TRUE ;
  137. fprintf(stderr, "\n**** ") ;
  138. fprintf(m_errfile, "\n**** ") ;
  139. }
  140. /* Writes part of an error message. Called from m_malloc instead of
  141. m_err1, since PARSER's version of m_err1 calls m_malloc and recursive
  142. calls are possible when the heap is exhausted */
  143. void m_errline(text)
  144. char *text ;
  145. {
  146. fputs(text, stderr) ;
  147. fputs(text, m_errfile) ;
  148. }
  149. /* Writes an error message to standard error and file "error" */
  150. void m_error(text)
  151. char *text ;
  152. {
  153. eprefix(TRUE) ;
  154. fprintf(stderr,"%s", text) ;
  155. fprintf(m_errfile,"%s", text) ;
  156. esuffix() ;
  157. skiptoend() ;
  158. }
  159. /* Writes an error message with one argument to standard error and file
  160. "error" */
  161. #if defined(M_PROTO)
  162. void m_err1(char *text, const M_WCHAR *arg)
  163. #else
  164. void m_err1(text, arg)
  165. char *text;
  166. M_WCHAR *arg ;
  167. #endif
  168. {
  169. char *mb_arg;
  170. mb_arg = MakeMByteString(arg);
  171. eprefix(TRUE) ;
  172. fprintf(stderr, text, mb_arg) ;
  173. fprintf(m_errfile, text, mb_arg) ;
  174. esuffix() ;
  175. skiptoend() ;
  176. m_free(mb_arg,"multi-byte string");
  177. }
  178. #if defined(M_PROTO)
  179. void m_mberr1(char *text, const char *arg)
  180. #else
  181. void m_err1(text, arg)
  182. char *text;
  183. char *arg ;
  184. #endif
  185. {
  186. eprefix(TRUE) ;
  187. fprintf(stderr, text, arg) ;
  188. fprintf(m_errfile, text, arg) ;
  189. esuffix() ;
  190. skiptoend() ;
  191. }
  192. /* Writes an error message with two arguments to standard error and file
  193. "error" */
  194. #if defined(M_PROTO)
  195. void m_err2( const char *text, const M_WCHAR *arg1, const M_WCHAR *arg2)
  196. #else
  197. void m_err2(text, arg1, arg2)
  198. char *text;
  199. M_WCHAR *arg1, *arg2 ;
  200. #endif
  201. {
  202. char *mb_arg1, *mb_arg2;
  203. mb_arg1 = MakeMByteString(arg1);
  204. mb_arg2 = MakeMByteString(arg2);
  205. eprefix(TRUE) ;
  206. fprintf(stderr, text, mb_arg1, mb_arg2) ;
  207. fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
  208. esuffix() ;
  209. skiptoend() ;
  210. m_free(mb_arg1,"multi-byte string");
  211. m_free(mb_arg2,"multi-byte string");
  212. }
  213. /* Writes an error message with three arguments to standard error and file
  214. "error" */
  215. #if defined(M_PROTO)
  216. void m_err3( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
  217. #else
  218. void m_err3(text, arg1, arg2, arg3)
  219. char *text;
  220. M_WCHAR *arg1, *arg2, *arg3 ;
  221. #endif
  222. {
  223. char *mb_arg1, *mb_arg2, *mb_arg3;
  224. mb_arg1 = MakeMByteString(arg1);
  225. mb_arg2 = MakeMByteString(arg2);
  226. mb_arg3 = MakeMByteString(arg3);
  227. eprefix(TRUE) ;
  228. fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
  229. fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
  230. esuffix() ;
  231. skiptoend() ;
  232. m_free(mb_arg1,"multi-byte string");
  233. m_free(mb_arg2,"multi-byte string");
  234. m_free(mb_arg3,"multi-byte string");
  235. }
  236. /* Writes an error message with five arguments to standard error and file
  237. "error" */
  238. #if defined(M_PROTO)
  239. void m_err5( char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
  240. M_WCHAR *arg4, M_WCHAR *arg5)
  241. #else
  242. void m_err5(text, arg1, arg2, arg3, arg4, arg5)
  243. char *text;
  244. M_WCHAR *arg1, *arg2, *arg3, *arg4, *arg5 ;
  245. #endif
  246. {
  247. char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4, *mb_arg5;
  248. mb_arg1 = MakeMByteString(arg1);
  249. mb_arg2 = MakeMByteString(arg2);
  250. mb_arg3 = MakeMByteString(arg3);
  251. mb_arg4 = MakeMByteString(arg4);
  252. mb_arg5 = MakeMByteString(arg5);
  253. fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
  254. fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4, mb_arg5) ;
  255. esuffix() ;
  256. skiptoend() ;
  257. m_free(mb_arg1,"multi-byte string");
  258. m_free(mb_arg2,"multi-byte string");
  259. m_free(mb_arg3,"multi-byte string");
  260. m_free(mb_arg4,"multi-byte string");
  261. m_free(mb_arg5,"multi-byte string");
  262. }
  263. /* Write error message suffix */
  264. void esuffix(M_NOPAR)
  265. {
  266. fprintf(stderr, " (line %d) ****\n", m_line) ;
  267. fprintf(m_errfile, " (line %d) ****\n", m_line) ;
  268. }
  269. /* Print something to both stderr and m_errfile */
  270. void msgline(text)
  271. char *text ;
  272. {
  273. fprintf(stderr, text) ;
  274. fprintf(m_errfile, text) ;
  275. }
  276. /* Print something to both stderr and m_errfile */
  277. void msg1line(text, arg1)
  278. char *text, *arg1 ;
  279. {
  280. fprintf(stderr, text, arg1) ;
  281. fprintf(m_errfile, text, arg1) ;
  282. }
  283. /* Trace used for m_malloc trace output */
  284. void m_trace(text)
  285. char *text ;
  286. {
  287. m_errline(text) ;
  288. }
  289. void m_wctrace(text)
  290. M_WCHAR *text ;
  291. {
  292. char *mb_text;
  293. mb_text = MakeMByteString(text);
  294. m_trace(mb_text);
  295. m_free(mb_text,"multi-byte string");
  296. }
  297. /* Writes a nonfatal error message to standard error and file "error" */
  298. void warning(text)
  299. char *text ;
  300. {
  301. eprefix(FALSE) ;
  302. fprintf(stderr,"%s", text) ;
  303. fprintf(m_errfile,"%s", text) ;
  304. esuffix() ;
  305. }
  306. /* Writes a nonfatal error message with one argument to standard error
  307. and file "error" */
  308. #if defined(M_PROTO)
  309. void warning1( char *text, M_WCHAR *arg)
  310. #else
  311. void warning1(text, arg)
  312. char *text;
  313. M_WCHAR *arg ;
  314. #endif
  315. {
  316. char *mb_arg;
  317. mb_arg = MakeMByteString(arg);
  318. eprefix(FALSE) ;
  319. fprintf(stderr, text, mb_arg) ;
  320. fprintf(m_errfile, text, mb_arg) ;
  321. esuffix() ;
  322. m_free(mb_arg,"multi-byte string");
  323. }
  324. /* Writes a nonfatal error message with two arguments to standard error
  325. and file "error" */
  326. #if defined(M_PROTO)
  327. void warning2(char *text, M_WCHAR *arg1, M_WCHAR *arg2)
  328. #else
  329. void warning2(text, arg1, arg2)
  330. char *text;
  331. M_WCHAR *arg1, *arg2 ;
  332. #endif
  333. {
  334. char *mb_arg1, *mb_arg2;
  335. mb_arg1 = MakeMByteString(arg1);
  336. mb_arg2 = MakeMByteString(arg2);
  337. eprefix(FALSE) ;
  338. fprintf(stderr, text, mb_arg1, mb_arg2) ;
  339. fprintf(m_errfile, text, mb_arg1, mb_arg2) ;
  340. esuffix() ;
  341. m_free(mb_arg1,"multi-byte string");
  342. m_free(mb_arg2,"multi-byte string");
  343. }
  344. /* Writes a nonfatal error message with three arguments to standard error
  345. and file "error" */
  346. #if defined(M_PROTO)
  347. void warning3(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3)
  348. #else
  349. void warning3(text, arg1, arg2, arg3)
  350. char *text;
  351. M_WCHAR *arg1, *arg2, *arg3 ;
  352. #endif
  353. {
  354. char *mb_arg1, *mb_arg2, *mb_arg3;
  355. mb_arg1 = MakeMByteString(arg1);
  356. mb_arg2 = MakeMByteString(arg2);
  357. mb_arg3 = MakeMByteString(arg3);
  358. eprefix(FALSE) ;
  359. fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3) ;
  360. fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3) ;
  361. esuffix() ;
  362. m_free(mb_arg1,"multi-byte string");
  363. m_free(mb_arg2,"multi-byte string");
  364. m_free(mb_arg3,"multi-byte string");
  365. }
  366. /* Writes a nonfatal error message with four arguments to standard error
  367. and file "error" */
  368. #if defined(M_PROTO)
  369. void warning4(char *text, M_WCHAR *arg1, M_WCHAR *arg2, M_WCHAR *arg3,
  370. M_WCHAR *arg4)
  371. #else
  372. void warning4(text, arg1, arg2, arg3, arg4)
  373. char *text;
  374. M_WCHAR *arg1, *arg2, *arg3, *arg4 ;
  375. #endif
  376. {
  377. char *mb_arg1, *mb_arg2, *mb_arg3, *mb_arg4;
  378. mb_arg1 = MakeMByteString(arg1);
  379. mb_arg2 = MakeMByteString(arg2);
  380. mb_arg3 = MakeMByteString(arg3);
  381. mb_arg4 = MakeMByteString(arg4);
  382. eprefix(FALSE) ;
  383. fprintf(stderr, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
  384. fprintf(m_errfile, text, mb_arg1, mb_arg2, mb_arg3, mb_arg4) ;
  385. esuffix() ;
  386. m_free(mb_arg1,"multi-byte string");
  387. m_free(mb_arg2,"multi-byte string");
  388. m_free(mb_arg3,"multi-byte string");
  389. m_free(mb_arg4,"multi-byte string");
  390. }