Пример #1
0
static
addcol (tty, n) {
  curX (tty) += n;

    /*
     * If cursor hit edge of screen, what happened?
     * N.B.: DO NOT!! write past edge of screen.  If you do, you
     * deserve what you get.  Furthermore, on terminals with
     * autowrap (but not magicwrap), don't write in the last column
     * of the last line.
     */

  if (curX (tty) == tty->Wcm->cm_cols) {
	/*
	 * Well, if magicwrap, still there, past the edge of the
	 * screen (!).  If autowrap, on the col 0 of the next line.
	 * Otherwise on last column.
	 */

	if (tty->Wcm->cm_magicwrap)
	    ;			/* "limbo" */
	else if (tty->Wcm->cm_autowrap) {
          curX (tty) = 0;
          curY (tty) ++;		/* Beware end of screen! */
	}
	else
          curX (tty)--;
    }
}
Пример #2
0
/*
 * Terminals with magicwrap (xn) don't all behave identically.
 * The VT100 leaves the cursor in the last column but will wrap before
 * printing the next character.  I hear that the Concept terminal does
 * the wrap immediately but ignores the next newline it sees.  And some
 * terminals just have buggy firmware, and think that the cursor is still
 * in limbo if we use direct cursor addressing from the phantom column.
 * The only guaranteed safe thing to do is to emit a CRLF immediately
 * after we reach the last column; this takes us to a known state.
 */
void
cmcheckmagic (struct tty_display_info *tty)
{
  if (curX (tty) == FrameCols (tty))
    {
      if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1)
	emacs_abort ();
      if (tty->termscript)
	putc ('\r', tty->termscript);
      putc ('\r', tty->output);
      if (tty->termscript)
	putc ('\n', tty->termscript);
      putc ('\n', tty->output);
      curX (tty) = 0;
      curY (tty)++;
    }
}
Пример #3
0
void Foam::sixDOFqODE::derivatives
(
    const scalar x,
    const scalarField& y,
    scalarField& dydx
) const
{
    // Set the derivatives for displacement
    dydx[0] = y[3];
    dydx[1] = y[4];
    dydx[2] = y[5];

    dimensionedVector curX("curX", dimLength, vector(y[0], y[1], y[2]));
    dimensionedVector curU("curU", dimVelocity, vector(y[3], y[4], y[5]));
    const HamiltonRodriguezRot curRotation
    (
        y[9],
        y[10],
        y[11],
        y[12]
    );

    const vector accel = A(curX, curU, curRotation).value();

    dydx[3] = accel.x();
    dydx[4] = accel.y();
    dydx[5] = accel.z();

    // Set the derivatives for rotation
    dimensionedVector curOmega
    (
        "curOmega",
        dimless/dimTime,
        vector(y[6], y[7], y[8])
    );

    const vector omegaDot = OmegaDot(curRotation, curOmega).value();

    dydx[6]  = omegaDot.x();
    dydx[7] = omegaDot.y();
    dydx[8] = omegaDot.z();

    dydx[9] = curRotation.eDot(curOmega.value(), 0);
    dydx[10] = curRotation.eDot(curOmega.value(), 1);
    dydx[11] = curRotation.eDot(curOmega.value(), 2);
    dydx[12] = curRotation.eDot(curOmega.value(), 3);
}
Пример #4
0
static
at (tty, row, col) {
  curY (tty) = row;
  curX (tty)  = col;
}
Пример #5
0
void
cmgoto (struct tty_display_info *tty, int row, int col)
{
    int     homecost,
            crcost,
            llcost,
            relcost,
            directcost;
    int     use IF_LINT (= 0);
    char *p;
    const char *dcm;

  /* First the degenerate case */
    if (row == curY (tty) && col == curX (tty)) /* already there */
    return;

    if (curY (tty) >= 0 && curX (tty) >= 0)
    {
      /* We may have quick ways to go to the upper-left, bottom-left,
       * start-of-line, or start-of-next-line.  Or it might be best to
       * start where we are.  Examine the options, and pick the cheapest.
       */

      relcost = calccost (tty, curY (tty), curX (tty), row, col, 0);
      use = USEREL;
      if ((homecost = tty->Wcm->cc_home) < BIG)
          homecost += calccost (tty, 0, 0, row, col, 0);
      if (homecost < relcost)
          relcost = homecost, use = USEHOME;
      if ((llcost = tty->Wcm->cc_ll) < BIG)
          llcost += calccost (tty, tty->Wcm->cm_rows - 1, 0, row, col, 0);
      if (llcost < relcost)
          relcost = llcost, use = USELL;
      if ((crcost = tty->Wcm->cc_cr) < BIG) {
	  if (tty->Wcm->cm_autolf)
            if (curY (tty) + 1 >= tty->Wcm->cm_rows)
                crcost = BIG;
	      else
                crcost += calccost (tty, curY (tty) + 1, 0, row, col, 0);
	  else
            crcost += calccost (tty, curY (tty), 0, row, col, 0);
      }
      if (crcost < relcost)
	  relcost = crcost, use = USECR;
      directcost = tty->Wcm->cc_abs, dcm = tty->Wcm->cm_abs;
      if (row == curY (tty) && tty->Wcm->cc_habs < BIG)
	  directcost = tty->Wcm->cc_habs, dcm = tty->Wcm->cm_habs;
      else if (col == curX (tty) && tty->Wcm->cc_vabs < BIG)
	  directcost = tty->Wcm->cc_vabs, dcm = tty->Wcm->cm_vabs;
    }
  else
    {
      directcost = 0, relcost = 100000;
      dcm = tty->Wcm->cm_abs;
    }

  /*
   * In the following comparison, the = in <= is because when the costs
   * are the same, it looks nicer (I think) to move directly there.
   */
  if (directcost <= relcost)
    {
      /* compute REAL direct cost */
      cost = 0;
      p = (dcm == tty->Wcm->cm_habs
           ? tgoto (dcm, row, col)
           : tgoto (dcm, col, row));
      emacs_tputs (tty, p, 1, evalcost);
      if (cost <= relcost)
	{	/* really is cheaper */
	  emacs_tputs (tty, p, 1, cmputc);
	  curY (tty) = row, curX (tty) = col;
	  return;
	}
    }

  switch (use)
    {
    case USEHOME:
      emacs_tputs (tty, tty->Wcm->cm_home, 1, cmputc);
      curY (tty) = 0, curX (tty) = 0;
      break;

    case USELL:
      emacs_tputs (tty, tty->Wcm->cm_ll, 1, cmputc);
      curY (tty) = tty->Wcm->cm_rows - 1, curX (tty) = 0;
      break;

    case USECR:
      emacs_tputs (tty, tty->Wcm->cm_cr, 1, cmputc);
      if (tty->Wcm->cm_autolf)
	curY (tty)++;
      curX (tty) = 0;
      break;
    }

  (void) calccost (tty, curY (tty), curX (tty), row, col, 1);
  curY (tty) = row, curX (tty) = col;
}
Пример #6
0
static int
calccost (struct tty_display_info *tty,
          int srcy, int srcx, int dsty, int dstx, int doit)
{
    register int    deltay,
                    deltax,
                    c,
                    totalcost;
    int     ntabs,
            n2tabs,
            tabx,
            tab2x,
            tabcost;
    register const char *p;

    /* If have just wrapped on a terminal with xn,
       don't believe the cursor position: give up here
       and force use of absolute positioning.  */

    if (curX (tty) == tty->Wcm->cm_cols)
      goto fail;

    totalcost = 0;
    if ((deltay = dsty - srcy) == 0)
	goto x;
    if (deltay < 0)
	p = tty->Wcm->cm_up, c = tty->Wcm->cc_up, deltay = -deltay;
    else
	p = tty->Wcm->cm_down, c = tty->Wcm->cc_down;
    if (c == BIG) {		/* caint get thar from here */
	if (doit)
	    printf ("OOPS");
	return c;
    }
    totalcost = c * deltay;
    if (doit)
      do
          emacs_tputs (tty, p, 1, cmputc);
      while (--deltay > 0);
x:
    if ((deltax = dstx - srcx) == 0)
	goto done;
    if (deltax < 0) {
	p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax;
	goto dodelta;		/* skip all the tab junk */
    }
    /* Tabs (the toughie) */
    if (tty->Wcm->cc_tab >= BIG || !tty->Wcm->cm_usetabs)
	goto olddelta;		/* forget it! */

    /*
     * ntabs is # tabs towards but not past dstx; n2tabs is one more
     * (ie past dstx), but this is only valid if that is not past the
     * right edge of the screen.  We can check that at the same time
     * as we figure out where we would be if we use the tabs (which
     * we will put into tabx (for ntabs) and tab2x (for n2tabs)).
     */

    ntabs = (deltax + srcx % tty->Wcm->cm_tabwidth) / tty->Wcm->cm_tabwidth;
    n2tabs = ntabs + 1;
    tabx = (srcx / tty->Wcm->cm_tabwidth + ntabs) * tty->Wcm->cm_tabwidth;
    tab2x = tabx + tty->Wcm->cm_tabwidth;

    if (tab2x >= tty->Wcm->cm_cols)	/* too far (past edge) */
	n2tabs = 0;

    /*
     * Now set tabcost to the cost for using ntabs, and c to the cost
     * for using n2tabs, then pick the minimum.
     */

		   /* cost for ntabs           +    cost for right motion */
    tabcost = ntabs ? ntabs * tty->Wcm->cc_tab + (dstx - tabx) * tty->Wcm->cc_right
		    : BIG;

		   /* cost for n2tabs          +    cost for left motion */
    c = n2tabs  ?    n2tabs * tty->Wcm->cc_tab + (tab2x - dstx) * tty->Wcm->cc_left
		: BIG;

    if (c < tabcost)		/* then cheaper to overshoot & back up */
	ntabs = n2tabs, tabcost = c, tabx = tab2x;

    if (tabcost >= BIG)		/* caint use tabs */
	goto newdelta;

    /*
     * See if tabcost is less than just moving right
     */

    if (tabcost < (deltax * tty->Wcm->cc_right)) {
	totalcost += tabcost;	/* use the tabs */
	if (doit)
	    while (--ntabs >= 0)
              emacs_tputs (tty, tty->Wcm->cm_tab, 1, cmputc);
	srcx = tabx;
    }

    /*
     * Now might as well just recompute the delta.
     */

newdelta:
    if ((deltax = dstx - srcx) == 0)
	goto done;
olddelta:
    if (deltax > 0)
	p = tty->Wcm->cm_right, c = tty->Wcm->cc_right;
    else
	p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax;

dodelta:
    if (c == BIG) {		/* caint get thar from here */
fail:
	if (doit)
	    printf ("OOPS");
	return BIG;
    }
    totalcost += c * deltax;
    if (doit)
      do
          emacs_tputs (tty, p, 1, cmputc);
      while (--deltax > 0);
done:
    return totalcost;
}