tm.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /* tm.c: split numerical fields */
  10. # include "t.h"
  11. char *
  12. maknew(char *str)
  13. {
  14. /* make two numerical fields */
  15. int c;
  16. char *p, *q, *ba, *dpoint;
  17. p = str;
  18. for (ba = 0; c = *str; str++)
  19. if (c == '\\' && *(str + 1) == '&')
  20. ba = str;
  21. str = p;
  22. if (ba == 0) {
  23. for (dpoint = 0; *str; str++) {
  24. if (*str == '.' && !ineqn(str, p) &&
  25. (str > p && digit(*(str - 1)) ||
  26. digit(*(str + 1))))
  27. dpoint = str;
  28. }
  29. if (dpoint == 0)
  30. for (; str > p; str--) {
  31. if (digit( *(str - 1) ) && !ineqn(str, p))
  32. break;
  33. }
  34. if (!dpoint && p == str) /* not numerical, don't split */
  35. return(0);
  36. if (dpoint)
  37. str = dpoint;
  38. } else
  39. str = ba;
  40. p = str;
  41. if (exstore == 0 || exstore > exlim) {
  42. exstore = exspace = chspace();
  43. exlim = exstore + MAXCHS;
  44. }
  45. q = exstore;
  46. while (*exstore++ = *str++)
  47. ;
  48. *p = 0;
  49. return(q);
  50. }
  51. int
  52. ineqn (char *s, char *p)
  53. {
  54. /* true if s is in a eqn within p */
  55. int ineq = 0, c;
  56. while (c = *p) {
  57. if (s == p)
  58. return(ineq);
  59. p++;
  60. if ((ineq == 0) && (c == delim1))
  61. ineq = 1;
  62. else if ((ineq == 1) && (c == delim2))
  63. ineq = 0;
  64. }
  65. return(0);
  66. }