PageRenderTime 72ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/usr.bin/window/error.c

http://github.com/davshao/dflygsocdrm
C | 100 lines | 58 code | 9 blank | 33 comment | 20 complexity | 7d643017ff5a121704db5398e3f20871 MD5 | raw file
Possible License(s): AGPL-1.0, CC-BY-SA-3.0, LGPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception, 0BSD, BSD-3-Clause, GPL-2.0
  1. /* @(#)error.c 8.1 (Berkeley) 6/6/93 */
  2. /* $NetBSD: error.c,v 1.6 2003/08/07 11:17:25 agc Exp $ */
  3. /*
  4. * Copyright (c) 1983, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley by
  8. * Edward Wang at The University of California, Berkeley.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. */
  34. #include "defs.h"
  35. #include "context.h"
  36. #include "char.h"
  37. #define ERRLINES 10 /* number of lines for errwin */
  38. void
  39. error(const char *fmt, ...)
  40. {
  41. va_list ap;
  42. va_start(ap, fmt);
  43. verror(fmt, ap);
  44. va_end(ap);
  45. }
  46. void
  47. verror(const char *fmt, va_list ap)
  48. {
  49. struct context *x;
  50. struct ww *w;
  51. for (x = &cx; x != NULL && x->x_type != X_FILE; x = x->x_link)
  52. ;
  53. if (x == NULL) {
  54. if (terse)
  55. wwbell();
  56. else {
  57. wwvprintf(cmdwin, fmt, ap);
  58. wwputs(" ", cmdwin);
  59. }
  60. return;
  61. }
  62. if (x->x_noerr)
  63. return;
  64. if ((w = x->x_errwin) == NULL) {
  65. char buf[512];
  66. (void) snprintf(buf, sizeof(buf), "Errors from %s",
  67. x->x_filename);
  68. if ((w = x->x_errwin = openiwin(ERRLINES, buf)) == NULL) {
  69. wwputs("Can't open error window. ", cmdwin);
  70. x->x_noerr = 1;
  71. return;
  72. }
  73. }
  74. if (more(w, 0) == 2) {
  75. x->x_noerr = 1;
  76. return;
  77. }
  78. wwprintf(w, "line %d: ", x->x_lineno);
  79. wwvprintf(w, fmt, ap);
  80. wwputc('\n', w);
  81. }
  82. void
  83. err_end(void)
  84. {
  85. if (cx.x_type == X_FILE && cx.x_errwin != 0) {
  86. if (!cx.x_noerr)
  87. waitnl(cx.x_errwin);
  88. closeiwin(cx.x_errwin);
  89. cx.x_errwin = 0;
  90. }
  91. }