tm.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* tm.c: split numerical fields */
  2. # include "t.h"
  3. char *
  4. maknew(char *str)
  5. {
  6. /* make two numerical fields */
  7. int c;
  8. char *p, *q, *ba, *dpoint;
  9. p = str;
  10. for (ba = 0; c = *str; str++)
  11. if (c == '\\' && *(str + 1) == '&')
  12. ba = str;
  13. str = p;
  14. if (ba == 0) {
  15. for (dpoint = 0; *str; str++) {
  16. if (*str == '.' && !ineqn(str, p) &&
  17. (str > p && digit(*(str - 1)) ||
  18. digit(*(str + 1))))
  19. dpoint = str;
  20. }
  21. if (dpoint == 0)
  22. for (; str > p; str--) {
  23. if (digit( *(str - 1) ) && !ineqn(str, p))
  24. break;
  25. }
  26. if (!dpoint && p == str) /* not numerical, don't split */
  27. return(0);
  28. if (dpoint)
  29. str = dpoint;
  30. } else
  31. str = ba;
  32. p = str;
  33. if (exstore == 0 || exstore > exlim) {
  34. exstore = exspace = chspace();
  35. exlim = exstore + MAXCHS;
  36. }
  37. q = exstore;
  38. while (*exstore++ = *str++)
  39. ;
  40. *p = 0;
  41. return(q);
  42. }
  43. int
  44. ineqn (char *s, char *p)
  45. {
  46. /* true if s is in a eqn within p */
  47. int ineq = 0, c;
  48. while (c = *p) {
  49. if (s == p)
  50. return(ineq);
  51. p++;
  52. if ((ineq == 0) && (c == delim1))
  53. ineq = 1;
  54. else if ((ineq == 1) && (c == delim2))
  55. ineq = 0;
  56. }
  57. return(0);
  58. }