fcmd.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "all.h"
  2. int
  3. fchar(void)
  4. {
  5. int n;
  6. n = BUFSIZE;
  7. if(n > MAXDAT)
  8. n = MAXDAT;
  9. if(uidgc.find >= uidgc.flen) {
  10. uidgc.find = 0;
  11. uidgc.flen = con_read(FID2, uidgc.uidbuf->iobuf, cons.offset, n);
  12. if(uidgc.flen <= 0)
  13. return -1;
  14. cons.offset += uidgc.flen;
  15. }
  16. return uidgc.uidbuf->iobuf[uidgc.find++] & 0xff;
  17. }
  18. int
  19. fread(void *buf, int len)
  20. {
  21. int n, c;
  22. char *b;
  23. b = buf;
  24. for(n = 0; n < len; n++) {
  25. c = fchar();
  26. if(c < 0)
  27. break;
  28. b[n] = c;
  29. }
  30. return n;
  31. }
  32. int
  33. fname(char *name)
  34. {
  35. int i, c;
  36. /*
  37. * read a name and return first char known not
  38. * to be in the name.
  39. */
  40. memset(name, 0, NAMELEN);
  41. for(i=0;; i++) {
  42. c = fchar();
  43. switch(c) {
  44. case '#':
  45. for(;;) {
  46. c = fchar();
  47. if(c == -1 || c == '\n')
  48. break;
  49. }
  50. case ' ':
  51. case '\n':
  52. case ':':
  53. case ',':
  54. case '=':
  55. case 0:
  56. return c;
  57. case -1:
  58. return 0;
  59. case '\t':
  60. return ' ';
  61. }
  62. if(i < NAMELEN-1)
  63. name[i] = c;
  64. }
  65. return 0;
  66. }
  67. int
  68. fpair(char *n1, char *n2)
  69. {
  70. int c;
  71. do {
  72. c = fname(n1);
  73. if(c == 0)
  74. return 1;
  75. } while(*n1 == 0);
  76. while(c != '=') {
  77. c = fname(n2);
  78. if(c == 0)
  79. return 1;
  80. if(*n2 != 0)
  81. memmove(n1, n2, NAMELEN);
  82. }
  83. do {
  84. c = fname(n2);
  85. if(c == 0)
  86. return 1;
  87. } while(*n2 == 0);
  88. return 0;
  89. }