/contrib/groff/src/devices/xditview/lex.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 96 lines · 76 code · 10 blank · 10 comment · 35 complexity · eeb98e420bf842816139e7894ab09211 MD5 · raw file

  1. #include <X11/Xos.h>
  2. #include <X11/IntrinsicP.h>
  3. #include <X11/StringDefs.h>
  4. #include <stdio.h>
  5. #include "DviP.h"
  6. int
  7. DviGetAndPut(DviWidget dw, int *cp)
  8. {
  9. if (dw->dvi.ungot) {
  10. dw->dvi.ungot = 0;
  11. *cp = getc (dw->dvi.file);
  12. }
  13. else {
  14. *cp = getc (dw->dvi.file);
  15. if (*cp != EOF)
  16. putc (*cp, dw->dvi.tmpFile);
  17. }
  18. return *cp;
  19. }
  20. char *
  21. GetLine(DviWidget dw, char *Buffer, int Length)
  22. {
  23. int i = 0, c;
  24. Length--; /* Save room for final '\0' */
  25. while (DviGetC (dw, &c) != EOF) {
  26. if (Buffer && i < Length)
  27. Buffer[i++] = c;
  28. if (c == '\n') {
  29. DviUngetC(dw, c);
  30. break;
  31. }
  32. }
  33. if (Buffer)
  34. Buffer[i] = '\0';
  35. return Buffer;
  36. }
  37. char *
  38. GetWord(DviWidget dw, char *Buffer, int Length)
  39. {
  40. int i = 0, c;
  41. Length--; /* Save room for final '\0' */
  42. while (DviGetC(dw, &c) == ' ' || c == '\n')
  43. ;
  44. while (c != EOF) {
  45. if (Buffer && i < Length)
  46. Buffer[i++] = c;
  47. if (DviGetC(dw, &c) == ' ' || c == '\n') {
  48. DviUngetC(dw, c);
  49. break;
  50. }
  51. }
  52. if (Buffer)
  53. Buffer[i] = '\0';
  54. return Buffer;
  55. }
  56. int
  57. GetNumber(DviWidget dw)
  58. {
  59. int i = 0, c;
  60. int negative = 0;
  61. while (DviGetC(dw, &c) == ' ' || c == '\n')
  62. ;
  63. if (c == '-') {
  64. negative = 1;
  65. DviGetC(dw, &c);
  66. }
  67. for (; c >= '0' && c <= '9'; DviGetC(dw, &c)) {
  68. if (negative)
  69. i = i*10 - (c - '0');
  70. else
  71. i = i*10 + c - '0';
  72. }
  73. if (c != EOF)
  74. DviUngetC(dw, c);
  75. return i;
  76. }
  77. /*
  78. Local Variables:
  79. c-indent-level: 8
  80. c-continued-statement-offset: 8
  81. c-brace-offset: -8
  82. c-argdecl-indent: 8
  83. c-label-offset: -8
  84. c-tab-always-indent: nil
  85. End:
  86. */