input.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. *
  3. * debugger
  4. *
  5. */
  6. #include "defs.h"
  7. #include "fns.h"
  8. Rune line[LINSIZ];
  9. extern int infile;
  10. Rune *lp;
  11. int peekc,lastc = EOR;
  12. int eof;
  13. /* input routines */
  14. eol(int c)
  15. {
  16. return(c==EOR || c==';');
  17. }
  18. int
  19. rdc(void)
  20. {
  21. do {
  22. readchar();
  23. } while (lastc==SPC || lastc==TB);
  24. return(lastc);
  25. }
  26. void
  27. reread(void)
  28. {
  29. peekc = lastc;
  30. }
  31. void
  32. clrinp(void)
  33. {
  34. flush();
  35. lp = 0;
  36. peekc = 0;
  37. }
  38. int
  39. readrune(int fd, Rune *r)
  40. {
  41. char buf[UTFmax];
  42. int i;
  43. for(i=0; i<UTFmax && !fullrune(buf, i); i++)
  44. if(read(fd, buf+i, 1) <= 0)
  45. return -1;
  46. chartorune(r, buf);
  47. return 1;
  48. }
  49. int
  50. readchar(void)
  51. {
  52. Rune *p;
  53. if (eof)
  54. lastc=0;
  55. else if (peekc) {
  56. lastc = peekc;
  57. peekc = 0;
  58. }
  59. else {
  60. if (lp==0) {
  61. for (p = line; p < &line[LINSIZ-1]; p++) {
  62. eof = readrune(infile, p) <= 0;
  63. if (mkfault) {
  64. eof = 0;
  65. error(0);
  66. }
  67. if (eof) {
  68. p--;
  69. break;
  70. }
  71. if (*p == EOR) {
  72. if (p <= line)
  73. break;
  74. if (p[-1] != '\\')
  75. break;
  76. p -= 2;
  77. }
  78. }
  79. p[1] = 0;
  80. lp = line;
  81. }
  82. if ((lastc = *lp) != 0)
  83. lp++;
  84. }
  85. return(lastc);
  86. }
  87. nextchar(void)
  88. {
  89. if (eol(rdc())) {
  90. reread();
  91. return(0);
  92. }
  93. return(lastc);
  94. }
  95. quotchar(void)
  96. {
  97. if (readchar()=='\\')
  98. return(readchar());
  99. else if (lastc=='\'')
  100. return(0);
  101. else
  102. return(lastc);
  103. }
  104. void
  105. getformat(char *deformat)
  106. {
  107. char *fptr;
  108. BOOL quote;
  109. Rune r;
  110. fptr=deformat;
  111. quote=FALSE;
  112. while ((quote ? readchar()!=EOR : !eol(readchar()))){
  113. r = lastc;
  114. fptr += runetochar(fptr, &r);
  115. if (lastc == '"')
  116. quote = ~quote;
  117. }
  118. lp--;
  119. if (fptr!=deformat)
  120. *fptr = '\0';
  121. }
  122. /*
  123. * check if the input line if of the form:
  124. * <filename>:<digits><verb> ...
  125. *
  126. * we handle this case specially because we have to look ahead
  127. * at the token after the colon to decide if it is a file reference
  128. * or a colon-command with a symbol name prefix.
  129. */
  130. int
  131. isfileref(void)
  132. {
  133. Rune *cp;
  134. for (cp = lp-1; *cp && !strchr(CMD_VERBS, *cp); cp++)
  135. if (*cp == '\\' && cp[1]) /* escape next char */
  136. cp++;
  137. if (*cp && cp > lp-1) {
  138. while (*cp == ' ' || *cp == '\t')
  139. cp++;
  140. if (*cp++ == ':') {
  141. while (*cp == ' ' || *cp == '\t')
  142. cp++;
  143. if (isdigit(*cp))
  144. return 1;
  145. }
  146. }
  147. return 0;
  148. }