/*** graphic - Editor <graphic> function * * Purpose: * Inserts character in text at current cursor position. Delete * previously selected text if any. * * Input: * the usual * * Output: * TRUE if character successfully inserted (FALSE means line too long) * * Notes: * *************************************************************************/ flagType graphic ( CMDDATA argData, ARG * pArg, flagType fMeta ) { delarg (pArg); return edit ( ((KEY_DATA *)&argData)->Ascii ); fMeta; }
/*** quote - Editor <quote> function * * Purpose: * Inserts character in text at current cursor position. Delete * previously selected text if any. * * Input: * the usual * * Output: * TRUE if character successfully inserted (FALSE means line too long) * *************************************************************************/ flagType quote ( CMDDATA argData, ARG * pArg, flagType fMeta ) { char c; delarg (pArg); while ((c = (char)(ReadCmd()->arg)) == 0) { ; } return edit (c); argData; fMeta; }
HlExprList *HlExprList::simp_plus() { HlExprList *a, *b; if (First()->NumberQ()) { // 2+3+u -> 5+u while (Length() > 1 && Second()->NumberQ()) { changed = true; First()->setDoubleVal(First()->getDoubleVal() + Second()->getDoubleVal()); delarg(Second()); } // 0+u -> u if (Length() > 1 && First()->Is(0.0)) { changed = true; delarg(First()); } } int found = false; do { found = false; for (int i = 0; i < Length(); i++) { for (int k = 0; k < Length(); k++) { if (i != k) { switch (arg(i)->is_times_of(arg(k))) { case 0: // Nichts dergleichen break; case 1: // a + n*a -> (n+1)*a arg(k)->First()->setDoubleVal(arg(k)->First()->getDoubleVal() + 1); delarg(arg(i)); found = true; changed = true; break; case 2: // m*a + n*a -> (m+n)*a arg(k)->First()->setDoubleVal( arg(k)->First()->getDoubleVal() + arg(i)->First()->getDoubleVal()); delarg(arg(i)); found = true; changed = true; break; } if (!found) { if (arg(i)->SameQ(arg(k))) // a + a -> 2*a { a = arg(i); b = arg(k); apparg(C(N(TIMES), N(2.0), N(a))); delarg(a); delarg(b); found = true; changed = true; } } } if (found) break; } if (found) break; } } while (found); // Plus(u) -> u if (Length() == 1) { changed = true; return (HlExprList *)onlyFirstArg(); } return this; }
HlExprList *HlExprList::simp_times() { HlExprList *a, *b; if (First()->NumberQ()) { // 2*3*u -> 6*u while (Length() > 1 && Second()->NumberQ()) { changed = true; First()->setDoubleVal(First()->getDoubleVal() * Second()->getDoubleVal()); delarg(Second()); } // 0*u -> 0 if (Length() > 0 && First()->Is(0.0)) { changed = true; delete this; return N(0.0); } // 1*u -> u if (Length() > 1 && First()->Is(1.0)) { changed = true; delarg(First()); } } int found = false; do { found = false; for (int i = 0; i < Length(); i++) { for (int k = 0; k < Length(); k++) { if (i != k) { switch (arg(i)->is_power_of(arg(k))) { case 0: // Nichts dergleichen break; case 1: // a * a^n -> a^(n+1) arg(k)->Second()->setDoubleVal( arg(k)->Second()->getDoubleVal() + 1); delarg(arg(i)); found = true; changed = true; break; case 2: // a^m * a^n -> a^(m+n) arg(k)->Second()->setDoubleVal( arg(k)->Second()->getDoubleVal() + arg(i)->Second()->getDoubleVal()); delarg(arg(i)); found = true; changed = true; break; } if (!found) { if (arg(i)->SameQ(arg(k))) // a * a -> a^2 { a = arg(i); b = arg(k); apparg(C(N(POWER), N(a), N(2.0))); delarg(a); delarg(b); found = true; changed = true; } } } if (found) break; } if (found) break; } } while (found); // Times(u) -> u if (Length() == 1) { changed = true; return (HlExprList *)onlyFirstArg(); } return this; }