+/*
+ * Expand arithmetic expression. Backup to start of expression,
+ * evaluate, place result in (backed up) result, adjust string position.
+ */
+expari()
+{
+ char *p, *start = stackblock();
+ int result;
+
+ /*
+ * This routine is slightly over-compilcated for
+ * efficiency. First we make sure there is
+ * enough space for the result, which may be bigger
+ * than the expression if we add exponentation. Next we
+ * scan backwards looking for the start of arithmetic. If the
+ * next previous character is a CTLESC character, then we
+ * have to rescan starting from the beginning since CTLESC
+ * characters have to be processed left to right.
+ */
+ CHECKSTRSPACE(8, expdest);
+ USTPUTC('\0', expdest);
+ p = expdest;
+ while (*p != CTLARI && p >= start)
+ --p;
+ if (*p != CTLARI)
+ error("missing CTLARI (shouldn't happen)");
+ if (p > start && *(p-1) == CTLESC)
+ for (p = start; *p != CTLARI; p++)
+ if (*p == CTLESC)
+ p++;
+ rmescapes(p+1);
+ result = arith(p+1);
+ fmtstr(p, 10, "%d", result);
+ while (*p++)
+ ;
+ result = expdest - p + 1;
+ STADJUST(-result, expdest);
+}
+