PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/error.c

https://github.com/mloar/halibut
C | 365 lines | 295 code | 64 blank | 6 comment | 6 complexity | b72b3813f99a2f45a27977281330a5e6 MD5 | raw file
  1. /*
  2. * error.c: Halibut error handling
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include "halibut.h"
  8. /*
  9. * Error flags
  10. */
  11. #define PREFIX 0x0001 /* give `halibut:' prefix */
  12. #define FILEPOS 0x0002 /* give file position prefix */
  13. static void do_error(const filepos *fpos, const char *fmt, ...)
  14. {
  15. va_list ap;
  16. if (fpos) {
  17. fprintf(stderr, "%s:",
  18. fpos->filename ? fpos->filename : "<standard input>");
  19. if (fpos->line > 0)
  20. fprintf(stderr, "%d:", fpos->line);
  21. if (fpos->col > 0)
  22. fprintf(stderr, "%d:", fpos->col);
  23. fputc(' ', stderr);
  24. } else {
  25. fputs("halibut: ", stderr);
  26. }
  27. va_start(ap, fmt);
  28. vfprintf(stderr, fmt, ap);
  29. va_end(ap);
  30. fputc('\n', stderr);
  31. }
  32. void fatalerr_nomemory(void)
  33. {
  34. do_error(NULL, "out of memory");
  35. exit(EXIT_FAILURE);
  36. }
  37. void err_optnoarg(const char *sp)
  38. {
  39. do_error(NULL, "option `-%s' requires an argument", sp);
  40. }
  41. void err_nosuchopt(const char *sp)
  42. {
  43. do_error(NULL, "unrecognised option `-%s'", sp);
  44. }
  45. void err_cmdcharset(const char *sp)
  46. {
  47. do_error(NULL, "character set `%s' not recognised", sp);
  48. }
  49. void err_futileopt(const char *sp, const char *sp2)
  50. {
  51. do_error(NULL, "warning: option `-%s' has no effect%s", sp, sp2);
  52. }
  53. void err_noinput(void)
  54. {
  55. do_error(NULL, "no input files");
  56. }
  57. void err_cantopen(const char *sp)
  58. {
  59. do_error(NULL, "unable to open input file `%s'", sp);
  60. }
  61. void err_nodata(void)
  62. {
  63. do_error(NULL, "no data in input files");
  64. }
  65. void err_brokencodepara(const filepos *fpos)
  66. {
  67. do_error(fpos, "every line of a code paragraph should begin `\\c'");
  68. }
  69. void err_kwunclosed(const filepos *fpos)
  70. {
  71. do_error(fpos, "expected `}' after paragraph keyword");
  72. }
  73. void err_kwexpected(const filepos *fpos)
  74. {
  75. do_error(fpos, "expected a paragraph keyword");
  76. }
  77. void err_kwillegal(const filepos *fpos)
  78. {
  79. do_error(fpos, "expected no paragraph keyword");
  80. }
  81. void err_kwtoomany(const filepos *fpos)
  82. {
  83. do_error(fpos, "expected only one paragraph keyword");
  84. }
  85. void err_bodyillegal(const filepos *fpos)
  86. {
  87. do_error(fpos, "expected no text after paragraph keyword");
  88. }
  89. void err_badparatype(const wchar_t *wsp, const filepos *fpos)
  90. {
  91. char *sp = utoa_locale_dup(wsp);
  92. do_error(fpos, "command `%s' unrecognised at start of paragraph", sp);
  93. sfree(sp);
  94. }
  95. void err_badmidcmd(const wchar_t *wsp, const filepos *fpos)
  96. {
  97. char *sp = utoa_locale_dup(wsp);
  98. do_error(fpos, "command `%s' unexpected in mid-paragraph", sp);
  99. sfree(sp);
  100. }
  101. void err_unexbrace(const filepos *fpos)
  102. {
  103. do_error(fpos, "brace character unexpected in mid-paragraph");
  104. }
  105. void err_explbr(const filepos *fpos)
  106. {
  107. do_error(fpos, "expected `{' after command");
  108. }
  109. void err_commenteof(const filepos *fpos)
  110. {
  111. do_error(fpos, "end of file unexpected inside `\\#{...}' comment");
  112. }
  113. void err_kwexprbr(const filepos *fpos)
  114. {
  115. do_error(fpos, "expected `}' after cross-reference");
  116. }
  117. void err_codequote(const filepos *fpos)
  118. {
  119. do_error(fpos, "unable to nest \\q{...} within \\c{...} or \\cw{...}");
  120. }
  121. void err_missingrbrace(const filepos *fpos)
  122. {
  123. do_error(fpos, "unclosed braces at end of paragraph");
  124. }
  125. void err_missingrbrace2(const filepos *fpos)
  126. {
  127. do_error(fpos, "unclosed braces at end of input file");
  128. }
  129. void err_nestedstyles(const filepos *fpos)
  130. {
  131. do_error(fpos, "unable to nest text styles");
  132. }
  133. void err_nestedindex(const filepos *fpos)
  134. {
  135. do_error(fpos, "unable to nest index markings");
  136. }
  137. void err_indexcase(const filepos *fpos, const wchar_t *wsp,
  138. const filepos *fpos2, const wchar_t *wsp2)
  139. {
  140. char *sp = utoa_locale_dup(wsp), *sp2 = utoa_locale_dup(wsp2);
  141. do_error(fpos, "warning: index tag `%s' used with different "
  142. "case (`%s') at %s:%d",
  143. sp, sp2, fpos2->filename, fpos2->line);
  144. sfree(sp);
  145. sfree(sp2);
  146. }
  147. void err_nosuchkw(const filepos *fpos, const wchar_t *wsp)
  148. {
  149. char *sp = utoa_locale_dup(wsp);
  150. do_error(fpos, "unable to resolve cross-reference to `%s'", sp);
  151. sfree(sp);
  152. }
  153. void err_multiBR(const filepos *fpos, const wchar_t *wsp)
  154. {
  155. char *sp = utoa_locale_dup(wsp);
  156. do_error(fpos, "multiple `\\BR' entries given for `%s'", sp);
  157. sfree(sp);
  158. }
  159. void err_nosuchidxtag(const filepos *fpos, const wchar_t *wsp)
  160. {
  161. char *sp = utoa_locale_dup(wsp);
  162. do_error(fpos, "`\\IM' on unknown index tag `%s'", sp);
  163. sfree(sp);
  164. }
  165. void err_cantopenw(const char *sp)
  166. {
  167. do_error(NULL, "unable to open output file `%s'", sp);
  168. }
  169. void err_macroexists(const filepos *fpos, const wchar_t *wsp)
  170. {
  171. char *sp = utoa_locale_dup(wsp);
  172. do_error(fpos, "macro `%s' already defined", sp);
  173. sfree(sp);
  174. }
  175. void err_sectjump(const filepos *fpos)
  176. {
  177. do_error(fpos, "expected higher heading levels before this one");
  178. }
  179. void err_winhelp_ctxclash(const filepos *fpos, const char *sp, const char *sp2)
  180. {
  181. do_error(fpos, "Windows Help context id `%s' clashes with "
  182. "previously defined `%s'", sp, sp2);
  183. }
  184. void err_multikw(const filepos *fpos, const filepos *fpos2, const wchar_t *wsp)
  185. {
  186. char *sp = utoa_locale_dup(wsp);
  187. do_error(fpos, "paragraph keyword `%s' already defined at %s:%d",
  188. sp, fpos2->filename, fpos2->line);
  189. sfree(sp);
  190. }
  191. void err_misplacedlcont(const filepos *fpos)
  192. {
  193. do_error(fpos, "\\lcont is only expected after a list item");
  194. }
  195. void err_sectmarkerinblock(const filepos *fpos, const char *sp)
  196. {
  197. do_error(fpos, "section headings are not supported within \\%s", sp);
  198. }
  199. void err_cfginsufarg(const filepos *fpos, const char *sp, int i)
  200. {
  201. do_error(fpos, "\\cfg{%s} expects at least %d parameter%s",
  202. sp, i, (i==1)?"":"s");
  203. }
  204. void err_infonodechar(const filepos *fpos, char c) /* fpos might be NULL */
  205. {
  206. do_error(fpos, "info output format does not support '%c' in"
  207. " node names; removing", c);
  208. }
  209. void err_text_codeline(const filepos *fpos, int i, int j)
  210. {
  211. do_error(fpos, "warning: code paragraph line is %d chars wide, wider"
  212. " than body width %d", i, j);
  213. }
  214. void err_htmlver(const filepos *fpos, const wchar_t *wsp)
  215. {
  216. char *sp = utoa_locale_dup(wsp);
  217. do_error(fpos, "unrecognised HTML version keyword `%s'", sp);
  218. sfree(sp);
  219. }
  220. void err_charset(const filepos *fpos, const wchar_t *wsp)
  221. {
  222. char *sp = utoa_locale_dup(wsp);
  223. do_error(fpos, "character set `%s' not recognised", sp);
  224. sfree(sp);
  225. }
  226. void err_nofont(const filepos *fpos, const wchar_t *wsp)
  227. {
  228. char *sp = utoa_locale_dup(wsp);
  229. do_error(fpos, "font `%s' not recognised", sp);
  230. sfree(sp);
  231. }
  232. void err_afmeof(const filepos *fpos)
  233. {
  234. do_error(fpos, "AFM file ended unexpectedly");
  235. }
  236. void err_afmkey(const filepos *fpos, const char *sp)
  237. {
  238. do_error(fpos, "required AFM key '%s' missing", sp);
  239. }
  240. void err_afmvers(const filepos *fpos)
  241. {
  242. do_error(fpos, "unsupported AFM version");
  243. }
  244. void err_afmval(const filepos *fpos, const char *sp, int i)
  245. {
  246. if (i == 1)
  247. do_error(fpos, "AFM key '%s' requires a value", sp);
  248. else
  249. do_error(fpos, "AFM key '%s' requires %d values", sp, i);
  250. }
  251. void err_pfeof(const filepos *fpos)
  252. {
  253. do_error(fpos, "Type 1 font file ended unexpectedly");
  254. }
  255. void err_pfhead(const filepos *fpos)
  256. {
  257. do_error(fpos, "Type 1 font file header line invalid");
  258. }
  259. void err_pfbad(const filepos *fpos)
  260. {
  261. do_error(fpos, "Type 1 font file invalid");
  262. }
  263. void err_pfnoafm(const filepos *fpos, const char *sp)
  264. {
  265. do_error(fpos, "no metrics available for Type 1 font '%s'", sp);
  266. }
  267. void err_chmnames(void)
  268. {
  269. do_error(NULL, "only one of html-mshtmlhelp-chm and "
  270. "html-mshtmlhelp-hhp found");
  271. }
  272. void err_sfntnotable(const filepos *fpos, const char *sp)
  273. {
  274. do_error(fpos, "font has no '%s' table", sp);
  275. }
  276. void err_sfntnopsname(const filepos *fpos)
  277. {
  278. do_error(fpos, "font has no PostScript name");
  279. }
  280. void err_sfntbadtable(const filepos *fpos, const char *sp)
  281. {
  282. do_error(fpos, "font has an invalid '%s' table", sp);
  283. }
  284. void err_sfntnounicmap(const filepos *fpos)
  285. {
  286. do_error(fpos, "font has no UCS-2 character map");
  287. }
  288. void err_sfnttablevers(const filepos *fpos, const char *sp)
  289. {
  290. do_error(fpos, "font has an unsupported '%s' table version", sp);
  291. }
  292. void err_sfntbadhdr(const filepos *fpos)
  293. {
  294. do_error(fpos, "font has an invalid header");
  295. }
  296. void err_sfntbadglyph(const filepos *fpos, unsigned wc)
  297. {
  298. do_error(fpos,
  299. "warning: character U+%04X references a non-existent glyph",
  300. wc);
  301. }