input.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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+1];
  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. buf[i] = 0;
  47. chartorune(r, buf);
  48. return 1;
  49. }
  50. int
  51. readchar(void)
  52. {
  53. Rune *p;
  54. if (eof)
  55. lastc=0;
  56. else if (peekc) {
  57. lastc = peekc;
  58. peekc = 0;
  59. }
  60. else {
  61. if (lp==0) {
  62. for (p = line; p < &line[LINSIZ-1]; p++) {
  63. eof = readrune(infile, p) <= 0;
  64. if (mkfault) {
  65. eof = 0;
  66. error(0);
  67. }
  68. if (eof) {
  69. p--;
  70. break;
  71. }
  72. if (*p == EOR) {
  73. if (p <= line)
  74. break;
  75. if (p[-1] != '\\')
  76. break;
  77. p -= 2;
  78. }
  79. }
  80. p[1] = 0;
  81. lp = line;
  82. }
  83. if ((lastc = *lp) != 0)
  84. lp++;
  85. }
  86. return(lastc);
  87. }
  88. nextchar(void)
  89. {
  90. if (eol(rdc())) {
  91. reread();
  92. return(0);
  93. }
  94. return(lastc);
  95. }
  96. quotchar(void)
  97. {
  98. if (readchar()=='\\')
  99. return(readchar());
  100. else if (lastc=='\'')
  101. return(0);
  102. else
  103. return(lastc);
  104. }
  105. void
  106. getformat(char *deformat)
  107. {
  108. char *fptr;
  109. BOOL quote;
  110. Rune r;
  111. fptr=deformat;
  112. quote=FALSE;
  113. while ((quote ? readchar()!=EOR : !eol(readchar()))){
  114. r = lastc;
  115. fptr += runetochar(fptr, &r);
  116. if (lastc == '"')
  117. quote = ~quote;
  118. }
  119. lp--;
  120. if (fptr!=deformat)
  121. *fptr = '\0';
  122. }
  123. /*
  124. * check if the input line if of the form:
  125. * <filename>:<digits><verb> ...
  126. *
  127. * we handle this case specially because we have to look ahead
  128. * at the token after the colon to decide if it is a file reference
  129. * or a colon-command with a symbol name prefix.
  130. */
  131. int
  132. isfileref(void)
  133. {
  134. Rune *cp;
  135. for (cp = lp-1; *cp && !strchr(CMD_VERBS, *cp); cp++)
  136. if (*cp == '\\' && cp[1]) /* escape next char */
  137. cp++;
  138. if (*cp && cp > lp-1) {
  139. while (*cp == ' ' || *cp == '\t')
  140. cp++;
  141. if (*cp++ == ':') {
  142. while (*cp == ' ' || *cp == '\t')
  143. cp++;
  144. if (isdigit(*cp))
  145. return 1;
  146. }
  147. }
  148. return 0;
  149. }