示例#1
0
文件: prompt.c 项目: jackleaks/zsh
mod_export int
match_colour(const char **teststrp, int is_fg, int colour)
{
    int shft, on, named = 0, tc;

    if (teststrp) {
	if ((named = ialpha(**teststrp))) {
	    colour = match_named_colour(teststrp);
	    if (colour == 8) {
		/* default */
		return is_fg ? TXTNOFGCOLOUR : TXTNOBGCOLOUR;
	    }
	}
	else
	    colour = (int)zstrtol(*teststrp, (char **)teststrp, 10);
    }
    if (colour < 0 || colour >= 256)
	return -1;
    if (is_fg) {
	shft = TXT_ATTR_FG_COL_SHIFT;
	on = TXTFGCOLOUR;
	tc = TCFGCOLOUR;
    } else {
	shft = TXT_ATTR_BG_COL_SHIFT;
	on = TXTBGCOLOUR;
	tc = TCBGCOLOUR;
    }
    /*
     * Try termcap for numbered characters if posible.
     * Don't for named characters, since our best bet
     * of getting the names right is with ANSI sequences.
     */
    if (!named && tccan(tc)) {
	if (tccolours >= 0 && colour >= tccolours) {
	    /*
	     * Out of range of termcap colours.
	     * Can we assume ANSI colours work?
	     */
	    if (colour > 7)
		return -1; /* No. */
	} else {
	    /*
	     * We can handle termcap colours and the number
	     * is in range, so use termcap.
	     */
	    on |= is_fg ? TXT_ATTR_FG_TERMCAP :
		TXT_ATTR_BG_TERMCAP;
	}
    }
    return on | (colour << shft);
}
示例#2
0
文件: prompt.c 项目: jackleaks/zsh
static int
match_named_colour(const char **teststrp)
{
    const char *teststr = *teststrp, *end, **cptr;
    int len;

    for (end = teststr; ialpha(*end); end++)
	;
    len = end - teststr;
    *teststrp = end;

    for (cptr = ansi_colours; *cptr; cptr++) {
	if (!strncmp(teststr, *cptr, len))
	    return cptr - ansi_colours;
    }

    return -1;
}
示例#3
0
/**
 * Description not yet available.
 * \param
 */
d4_array orthpoly2(int d1,int d2, int n,int m)
{
  d4_array A(0,d1,0,d2,1,n,1,m);
  d4_array B(0,d1,0,d2,1,n,1,m);
  int alpha,beta,i,j,ii,jj;
  int N=(1+d1)*(1+d2);
  ivector ialpha(1,N);
  ivector ibeta(1,N);


  for (alpha=0;alpha<=d1;alpha++)
  {
    for (beta=0;beta<=d2;beta++)
    {
      for (i=1;i<=n;i++)
      {
        for (j=1;j<=m;j++)
        {
#if defined(USE_DDOUBLE)
#undef double
          A(alpha,beta,i,j)=pow(double(i-1)/double(n-1),alpha)*
            pow(double(j-1)/double(m-1),beta);
#define double dd_real
#else
          A(alpha,beta,i,j)=pow(double(i-1)/double(n-1),alpha)*
            pow(double(j-1)/double(m-1),beta);
#endif
        }
      }
    }
  }
  ii=1;
  for (alpha=0;alpha<=d1;alpha++)
  {
    for (beta=0;beta<=d2;beta++)
    {
      ialpha(ii)=alpha;
      ibeta(ii)=beta;
      ii++;
    }
  }
  for (ii=1;ii<=N;ii++)
  {
    //cout     << "X" << endl;
    if (ii>1)
    {
//cout << dot(B(ialpha(ii-1),ibeta(ii-1)),A(ialpha(ii),ibeta(ii))) << endl;
      //cout << dot(B(ialpha(ii-1),ibeta(ii-1)),
       //  A(ialpha(ii),ibeta(ii))/norm(A(ialpha(ii),ibeta(ii)))) << endl;
    }
    B(ialpha(ii),ibeta(ii))=A(ialpha(ii),ibeta(ii))/
      norm(A(ialpha(ii),ibeta(ii)));
    //if (ii>1)
// cout << dot(B(ialpha(ii-1),ibeta(ii-1)),B(ialpha(ii),ibeta(ii))) << endl;
    //cout     << "Y" << endl;
    for (jj=ii+1;jj<=N;jj++)
    {
      A(ialpha(jj),ibeta(jj))-=
        dot(B(ialpha(ii),ibeta(ii)),A(ialpha(jj),ibeta(jj)))*
        B(ialpha(ii),ibeta(ii));
      //cout << dot(B(ialpha(ii),ibeta(ii)),A(ialpha(jj),ibeta(jj))) << endl;
    }
    //cout     << "Z" << endl;
  }
  return B;
}