error.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "sam.h"
  10. static char *emsg[]={
  11. /* error_s */
  12. "can't open",
  13. "can't create",
  14. "not in menu:",
  15. "changes to",
  16. "I/O error:",
  17. "can't write while changing:",
  18. /* error_c */
  19. "unknown command",
  20. "no operand for",
  21. "bad delimiter",
  22. /* error */
  23. "can't fork",
  24. "interrupt",
  25. "address",
  26. "search",
  27. "pattern",
  28. "newline expected",
  29. "blank expected",
  30. "pattern expected",
  31. "can't nest X or Y",
  32. "unmatched `}'",
  33. "command takes no address",
  34. "addresses overlap",
  35. "substitution",
  36. "& match too long",
  37. "bad \\ in rhs",
  38. "address range",
  39. "changes not in sequence",
  40. "addresses out of order",
  41. "no file name",
  42. "unmatched `('",
  43. "unmatched `)'",
  44. "malformed `[]'",
  45. "malformed regexp",
  46. "reg. exp. list overflow",
  47. "plan 9 command",
  48. "can't pipe",
  49. "no current file",
  50. "string too long",
  51. "changed files",
  52. "empty string",
  53. "file search",
  54. "non-unique match for \"\"",
  55. "tag match too long",
  56. "too many subexpressions",
  57. "temporary file too large",
  58. "file is append-only",
  59. "no destination for plumb message",
  60. "internal read error in buffer load",
  61. };
  62. static char *wmsg[]={
  63. /* warn_s */
  64. "duplicate file name",
  65. "no such file",
  66. "write might change good version of",
  67. /* warn_S */
  68. "files might be aliased",
  69. /* warn */
  70. "null characters elided",
  71. "can't run pwd",
  72. "last char not newline",
  73. "exit status",
  74. };
  75. void
  76. error(Err s)
  77. {
  78. char buf[512];
  79. sprint(buf, "?%s", emsg[s]);
  80. hiccough(buf);
  81. }
  82. void
  83. error_s(Err s, char *a)
  84. {
  85. char buf[512];
  86. sprint(buf, "?%s \"%s\"", emsg[s], a);
  87. hiccough(buf);
  88. }
  89. void
  90. error_r(Err s, char *a)
  91. {
  92. char buf[512];
  93. sprint(buf, "?%s \"%s\": %r", emsg[s], a);
  94. hiccough(buf);
  95. }
  96. void
  97. error_c(Err s, int c)
  98. {
  99. char buf[512];
  100. sprint(buf, "?%s `%C'", emsg[s], c);
  101. hiccough(buf);
  102. }
  103. void
  104. warn(Warn s)
  105. {
  106. dprint("?warning: %s\n", wmsg[s]);
  107. }
  108. void
  109. warn_S(Warn s, String *a)
  110. {
  111. print_s(wmsg[s], a);
  112. }
  113. void
  114. warn_SS(Warn s, String *a, String *b)
  115. {
  116. print_ss(wmsg[s], a, b);
  117. }
  118. void
  119. warn_s(Warn s, char *a)
  120. {
  121. dprint("?warning: %s `%s'\n", wmsg[s], a);
  122. }
  123. void
  124. termwrite(char *s)
  125. {
  126. String *p;
  127. if(downloaded){
  128. p = tmpcstr(s);
  129. if(cmd)
  130. loginsert(cmd, cmdpt, p->s, p->n);
  131. else
  132. Strinsert(&cmdstr, p, cmdstr.n);
  133. cmdptadv += p->n;
  134. free(p);
  135. }else
  136. Write(2, s, strlen(s));
  137. }