error.c 2.2 KB

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