Exemple #1
0
void
focusprev(Arg *arg) {
    Client *c;

    if(!sel)
        return;
    if(!(c = getprev(sel->prev))) {
        for(c = clients; c && c->next; c = c->next);
        c = getprev(c);
    }
    if(c) {
        focus(c);
        restack();
    }
}
Exemple #2
0
static void post(Agraph_t * g)
{
    Agnode_t *v;
    Agnode_t *prev;
    char buf[256];
    char dflt[256];
    Agsym_t *sym;
    Agsym_t *psym;
    double dist, oldmax;
    double maxdist = 0.0;	/* maximum "finite" distance */

    sym = agattr(g, AGNODE, "dist", "");
    if (doPath)
	psym = agattr(g, AGNODE, "prev", "");

    if (setall)
	sprintf(dflt, "%.3lf", HUGE);

    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
	dist = getdist(v);
	if (dist) {
	    dist--;
	    sprintf(buf, "%.3lf", dist);
	    agxset(v, sym, buf);
	    if (doPath && (prev = getprev(v)))
		agxset(v, psym, agnameof(prev));
	    if (maxdist < dist)
		maxdist = dist;
	} else if (setall)
	    agxset(v, sym, dflt);
    }

    sym = agattrsym(g, "maxdist");
    if (sym) {
	if (!setall) {
	    /* if we are preserving distances in other components,
	     * check previous value of maxdist.
	     */
	    oldmax = atof(agxget(g, sym));
	    if (oldmax > maxdist)
		maxdist = oldmax;
	}
	sprintf(buf, "%.3lf", maxdist);
	agxset(g, sym, buf);
    } else {
	sprintf(buf, "%.3lf", maxdist);
	agattr(g, AGRAPH, "maxdist", buf);
    }

    agclean(g, AGNODE, "dijkstra");
    agclean(g, AGEDGE, "dijkstra");
}
Exemple #3
0
int
input_line(char *string, int length)
{
   char curline[2000];                /* edit buffer */
   int noline;
   unsigned c;
   int more;
   int i;

    if (first) {
       poolinit();                   /* build line pool */
       first = 0;
    }
    noline = 1;                       /* no line fetched yet */
    for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) {
       if (usrbrk()) {
          clrbrk();
          break;
       }
       switch (c=input_char()) {
       case F_RETURN:                /* CR */
           t_sendl("\r\n", 2);       /* yes, print it and */
           goto done;                /* get out */
       case F_CLRSCRN:               /* clear screen */
          asclrs();
          t_sendl(curline, cl);
          ascurs(0, cp);
          break;
       case F_CSRUP:
           if (noline) {             /* no line fetched yet */
               getnext();            /* getnext so getprev gets current */
               noline = 0;           /* we now have line */
           }
           bstrncpy(curline, getprev(), sizeof(curline));
           prtcur(curline);
           break;
       case F_CSRDWN:
           noline = 0;               /* mark line fetched */
           bstrncpy(curline, getnext(), sizeof(curline));
           prtcur(curline);
           break;
       case F_INSCHR:
           insert_space(curline, sizeof(curline));
           break;
       case F_DELCHR:
           delchr(1, curline, sizeof(curline));       /* delete one character */
           break;
       case F_CSRLFT:                /* Backspace */
           backup(curline);
           break;
       case F_CSRRGT:
           forward(curline, sizeof(curline));
           break;
       case F_ERSCHR:                /* Rubout */
           backup(curline);
           delchr(1, curline, sizeof(curline));
           if (cp == 0) {
              t_char(' ');
              t_char(0x8);
           }
           break;
       case F_DELEOL:
           t_clrline(0, t_width);
           if (cl > cp)
               cl = cp;
           break;
       case F_NXTWRD:
           i = next_word(curline);
           while (i--) {
              forward(curline, sizeof(curline));
           }
           break;
       case F_PRVWRD:
           i = prev_word(curline);
           while (i--) {
              backup(curline);
           }
           break;
       case F_DELWRD:
           delchr(next_word(curline), curline, sizeof(curline)); /* delete word */
           break;
       case F_NXTMCH:                /* Ctl-X */
           if (cl==0) {
               *string = EOS;        /* terminate string */
               return(c);            /* give it to him */
           }
           /* Note fall through */
       case F_DELLIN:
       case F_ERSLIN:
           while (cp > 0) {
              backup(curline);      /* backup to beginning of line */
           }
           t_clrline(0, t_width);     /* erase line */
           cp = 0;
           cl = 0;                   /* reset cursor counter */
           t_char(' ');
           t_char(0x8);
           break;
       case F_SOL:
           while (cp > 0) {
              backup(curline);
           }
           break;
       case F_EOL:
           while (cp < cl) {
               forward(curline, sizeof(curline));
           }
           while (cp > cl) {
               backup(curline);
           }
           break;
       case F_TINS:                  /* toggle insert mode */
           mode_insert = !mode_insert;  /* flip bit */
           break;
       default:
           if (c > 255) {            /* function key hit */
               if (cl==0) {          /* if first character then */
                  *string = EOS;     /* terminate string */
                  return c;          /* return it */
               }
               t_honk_horn();        /* complain */
           } else {
               if ((c & 0xC0) == 0xC0) {
                  if ((c & 0xFC) == 0xFC) {
                     more = 5;
                  } else if ((c & 0xF8) == 0xF8) {
                     more = 4;
                  } else if ((c & 0xF0) == 0xF0) {
                     more = 3;
                  } else if ((c & 0xE0) == 0xE0) {
                     more = 2;
                  } else {
                     more = 1;
                  }
               } else {
                  more = 0;
               }
               if (mode_insert) {
                  insert_space(curline, sizeof(curline));
               }
               curline[cp++] = c;    /* store character in line being built */
               t_char(c);      /* echo character to terminal */
               while (more--) {
                  c= input_char();
                  insert_hole(curline, sizeof(curline));
                  curline[cp++] = c;    /* store character in line being built */
                  t_char(c);      /* echo character to terminal */
               }
               if (cp > cl) {
                  cl = cp;           /* keep current length */
                  curline[cp] = 0;
               }
           }
           break;
       }                             /* end switch */
    }
/* If we fall through here rather than goto done, the line is too long
   simply return what we have now. */
done:
   curline[cl++] = EOS;              /* terminate */
   bstrncpy(string,curline,length);           /* return line to caller */
   /* Save non-blank lines. Note, put line zaps curline */
   if (curline[0] != EOS) {
      putline(curline,cl);            /* save line for posterity */
   }
   return 0;                         /* give it to him/her */
}
Exemple #4
0
int     bsolve(
	int m, 
	double *sy,
	int *iy,
	int *pny
)
{
        int i, j, jr, ny=*pny;
        int k, row, row2, consistent=TRUE;
        double beta;
        double eps;

	static double *y=NULL, *yy=NULL;
	static int    *tag=NULL;
	static int  currtag=1;

	double starttime, endtime;

	starttime = (double) clock();

	if (   y  == NULL) CALLOC(   y, m,   double);
	if (  yy  == NULL) CALLOC(  yy, m,   double);
	if ( tag  == NULL) CALLOC( tag, m,   int);

	if ( newcol == NULL) MALLOC(  newcol, m, double );
	if (inewcol == NULL) MALLOC( inewcol, m, int );

	for (k=0; k<ny; k++) {
	    i = irowperm[iy[k]];
	    y[i] = sy[k];
	    tag[i] = currtag;
	    addtree(i);
	}

        if (rank < m) eps = EPSSOL * maxv(sy,ny);

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  L  y                                    */

        for (i=getfirst(); i < rank && i != -1; i=getnext()) {
                beta = y[i];
                for (k=0; k<degL[i]; k++) {
                        row = L[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
                        y[row] -= L[i][k].d * beta;
                }
        }

        /*------------------------------------------------------+
        | Apply refactorization row operations.                */

	for (jr=0; jr<nr; jr++) {

            /*--------------------------------------------------+
            | Gather sparse vector.                            */

	    k=0;
            for (j=col_outs[jr]; j<=imaxs[jr]; j++) {
		if (tag[j] == currtag) {
		    sy[k] = y[j];
		    iy[k] =   j;
		    k++;
		    tag[j]--;
		    deltree(j); 
		}
	    }
	    ny = k;

            /*--------------------------------------------------+
            | Scatter and permute.                             */

	    for (k=0; k<ny; k++) {
		i = iperm[jr][iy[k]];
		y[i] = sy[k];
		tag[i] = currtag;
		addtree(i);
	    }

            /*--------------------------------------------------+
            | Apply row operations.                            */

	    row = rows[jr];
	    for (k=0; k<ngauss[jr]; k++) {
		row2 = row_list[jr][k];
		if (tag[row] != currtag) {
		    y[row] = 0.0;
		    tag[row] = currtag;
		    addtree(row);
		}
		if (tag[row2] == currtag) {
		    y[row] -= gauss[jr][k] * y[row2];
		}
	    }

	}

        /*------------------------------------------------------+
	|                                       -1              |
        | Set aside sparse intermediate vector L  P a  for      |
	|                                            j          |
        | refactorization routine.                             */

	nnewcol = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        newcol [nnewcol] = y[i];
	        inewcol[nnewcol] = i;
	        nnewcol++;
	    }
	}

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  U  y                                    */

        for (i=getlast(); i >= rank && i != -1; i=getprev()) {
                if ( ABS( y[i] ) > eps ) consistent = FALSE;
                y[i] = 0.0;
        }
        for ( ; i>=0; i=getprev()) {
                beta = y[i]/diag[i];
                for (k=0; k<degU[i]; k++) {
			row = U[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
			y[row] -= U[i][k].d * beta;
                }
                y[i] = beta;
        }

	ny = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        sy[ny] = y[i];
	        iy[ny] = colperm[i];
	        ny++;
	    }
	}
	*pny = ny;

	currtag++;
	killtree();

	endtime = (double) clock();
	cumtime += endtime - starttime;

        return consistent;
}