rdi.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. *
  5. * This product is part of the Amsterdam Compiler Kit.
  6. *
  7. * Permission to use, sell, duplicate or disclose this software must be
  8. * obtained in writing. Requests for such permissions may be sent to
  9. *
  10. * Dr. Andrew S. Tanenbaum
  11. * Wiskundig Seminarium
  12. * Vrije Universiteit
  13. * Postbox 7161
  14. * 1007 MC Amsterdam
  15. * The Netherlands
  16. *
  17. */
  18. /* Author: J.W. Stevenson */
  19. #include <pc_file.h>
  20. #include <pc_err.h>
  21. extern _trp();
  22. extern _rf();
  23. extern _incpt();
  24. _skipsp(f) struct file *f; {
  25. while ((*f->ptr == ' ') || (*f->ptr == '\t'))
  26. _incpt(f);
  27. }
  28. int _getsig(f) struct file *f; {
  29. int sign;
  30. if ((sign = (*f->ptr == '-')) || *f->ptr == '+')
  31. _incpt(f);
  32. return(sign);
  33. }
  34. int _fstdig(f) struct file *f; {
  35. int ch;
  36. ch = *f->ptr - '0';
  37. if ((unsigned) ch > 9) {
  38. _trp(EDIGIT);
  39. ch = 0;
  40. }
  41. return(ch);
  42. }
  43. int _nxtdig(f) struct file *f; {
  44. int ch;
  45. _incpt(f);
  46. ch = *f->ptr - '0';
  47. if ((unsigned) ch > 9)
  48. return(-1);
  49. return(ch);
  50. }
  51. int _getint(f) struct file *f; {
  52. int is_signed,i,ch;
  53. is_signed = _getsig(f);
  54. ch = _fstdig(f);
  55. i = 0;
  56. do
  57. i = i*10 - ch;
  58. while ((ch = _nxtdig(f)) >= 0);
  59. return(is_signed ? i : -i);
  60. }
  61. int _rdi(f) struct file *f; {
  62. _rf(f);
  63. _skipsp(f);
  64. return(_getint(f));
  65. }