Esempio n. 1
0
 void getd(node * u,int dep)
 {
  if(u == nil)
   return;
  h = max(dep,h);
  getd(u->L,dep+1);
  getd(u->R,dep+1);
 }
Esempio n. 2
0
void rotate(int p)
{
	int d=getd(p),Fa=fa[p];
	isrt(Fa)? (void)(fa[p]=fa[Fa]): sets(getd(Fa),p,fa[Fa]);
	sets(d,son[p][d^1],Fa);
	sets(d^1,Fa,p);
	update(Fa);
}
Esempio n. 3
0
void splay(int p)
{
	int pt;tops=0;
	for(pt=p;!isrt(pt);pt=fa[pt]) stk[++tops]=pt;
	stk[++tops]=pt;
	for(pt=tops;pt>0;pt--) pushdown(stk[pt]);
	while(!isrt(p))
	{
		if(!isrt(fa[p]))
			getd(p)==getd(fa[p])? rotate(fa[p]): rotate(p);
		rotate(p);
	}
	update(p);
}
Esempio n. 4
0
int main(void) {
    int nice_value;

    printf("nice> ");
    nice_value = nice(getd());

    if (nice_value == -1) {
        perror("nice");
        exit(EXIT_FAILURE);
    }

    printf("nice value = %d\n", nice_value);

    exit(EXIT_SUCCESS);
}
Esempio n. 5
0
void service_server(u32 n, u32 c)
{
	u32 j;

	// FIXME, assumes 2 masters only
	master[n] = c;
	master[1 - n] = getd(c);

	ready = 1;

	for (j = 0; j < N_SERVICES; j++) {
		u32 what = in32(c);
		services[what] = in32(c);
		inend(c);
	}
printf("service init done\n");
}
Esempio n. 6
0
double LuaArgs::getd(int idx, const char *key, double Default)
{
	double ret;
	if (tbl > 0 && lua_checkstack(L, 1)) {
		lua_getfield(L, tbl, key);
		bool success = lua_isnumber(L, -1) != 0;
		if (!success && idx > 0) {
			lua_pop(L, 1);
			lua_pushinteger(L, idx);
			lua_gettable(L, tbl);
			success = lua_isnumber(L, -1) != 0;
		}
		ret = success? lua_tonumber(L, -1) : Default;
		lua_pop(L, 1);
	} else {
		ret = getd(idx, Default);
	}
	return ret;
}
Esempio n. 7
0
//--------------------- Reads time and date information from RTC (PCF8563)
void rtc_r(void) 
{
  unsigned char tmp;

  i2c_start();
  i2c_wb(0xD0);
  i2c_wb(0);

  i2c_start();
  i2c_wb(0xD1);
  tmp= 0x7F & i2c_rb(1); //segundos
  time[5]=':';
  time[6]=getd(tmp);
  time[7]=getu(tmp);
  time[8]=0;

  tmp= 0x7F & i2c_rb(1); //minutos
  time[2]=':';
  time[3]=getd(tmp);
  time[4]=getu(tmp);

  tmp= 0x3F & i2c_rb(1); //horas
  time[0]=getd(tmp);
  time[1]=getu(tmp);

  i2c_rb(1); //dia semana

  tmp= 0x3F & i2c_rb(1); //dia
  date[0]=getd(tmp);
  date[1]=getu(tmp);


  tmp= 0x1F & i2c_rb(1); //mes
  date[2]='/'; 
  date[3]=getd(tmp);
  date[4]=getu(tmp);

  tmp=  i2c_rb(0); //ano
  date[5]='/';
  date[6]=getd(tmp);
  date[7]=getu(tmp);
  date[8]=0;

  i2c_stop();

}
Esempio n. 8
0
//--------------------- Reads time and date information from RTC (PCF8563)
void rtc_r(void) 
{
  unsigned char tmp;

  Soft_I2C_Start();
  Soft_I2C_Write(0xA2);
  Soft_I2C_Write(2);

  Soft_I2C_Start();
  Soft_I2C_Write(0xA3);
  tmp= 0x7F & Soft_I2C_Read(1); //segundos
  time[5]=':';
  time[6]=getd(tmp);
  time[7]=getu(tmp);
  time[8]=0;

  tmp= 0x7F & Soft_I2C_Read(1); //minutos
  time[2]=':';
  time[3]=getd(tmp);
  time[4]=getu(tmp);

  tmp= 0x3F & Soft_I2C_Read(1); //horas
  time[0]=getd(tmp);
  time[1]=getu(tmp);

  tmp= 0x3F & Soft_I2C_Read(1); //dia
  date[0]=getd(tmp);
  date[1]=getu(tmp);

  Soft_I2C_Read(1); //dia semana

  tmp= 0x1F & Soft_I2C_Read(1); //mes
  date[2]='/'; 
  date[3]=getd(tmp);
  date[4]=getu(tmp);

  tmp=  Soft_I2C_Read(1); //ano
  date[5]='/';
  date[6]=getd(tmp);
  date[7]=getu(tmp);
  date[8]=0;

  Soft_I2C_Stop();

}
Esempio n. 9
0
int main(
    int argc,
    char **argv)
{
    char *b;
    char *c;
    char **p;
    char *d;
    char *e;
    char *ee;
    int did;
    int fd = 0;
    int offset;
    int lth;
    int count;
    int little;
    long start;
    long pos;
    long left;
    union {
        short x;
        char y[2];
    } end_test;

    (void)argc;

    end_test.x = 1;
    little = (end_test.y[0] > 0);
    for (c = obuf; c < &obuf[66]; *c++ = ' ');
    *c++ = '\n';
    for (p = &argv[1], pos = left = 0; *p; p++)
    {
        b = &(c = *p)[1];
        if (*c == '-')
        {
            if (*b == 'a' || *b == 'A')
            {
                if (aflag)
                    FATAL(MSG_INVAL);
                aflag = (*b == 'a') ? 1 : -1;
            }
            else if (*b == 'l')
                little = 1;
            else if (*b == 'b')
                little = 0;
            else
                pos = -getd(&b, 0);
        }
        else if (*c == '+')
            pos = getd(&b, 0);
        else if (is_numeric(c))
            left = getd(&c, 0);
        else
            fname = c;
    }
    if (fname && (fd = open(fname, O_RDONLY)) < 0)
        FATAL(MSG_OPEN);
    if (aflag)
        dump_asn1(fd, pos);
    if (pos < 0)
        start = lseek(fd, 0L, 2);
    else
        start = 0;
    lseek(fd, ((start + pos) & ~(BSIZE - 1)), 0);
    c = &ibuf[((pos += start) & (BSIZE - 1))];
    if (!left)
        left = 1000000000;
    left += (c - ibuf);
    did = 16 - (offset = pos & 0xF);
    for (; left; c = ibuf)
    {
        for (lth = 0;
             (count =
              read(fd, &ibuf[lth],
                   (int)((left > BSIZE - lth) ? BSIZE - lth : left)));
             lth += count);
        if (!lth)
            break;
        if (c > ibuf)
        {
            lth -= (c - ibuf);
            left -= (c - ibuf);
        }
        if (lth > left)
            lth = left;
        for (e = &c[lth]; c < e && left;)       /* each input block */
        {
            if (!little)
                for (; lth > 0;)        /* each output line */
                {
                    for (*(b = &obuf[5]) = '0', start = pos; start;
                         start >>= 4)
                        *b-- = hex[start & 0xF];
                    b = &obuf[8];
                    d = &obuf[50];
                    if (offset)
                    {
                        b += (2 * offset + (offset / 2));
                        d += offset;
                        if (offset & 1)
                        {
                            b = hexit(b, *c);
                            *d++ = *c++;
                            *b++ = ' ';
                        }
                        offset = 0;
                    }
                    for (ee = &c[lth]; d < &obuf[66] && c < ee;)
                    {
                        b = hexit(b, *c);
                        *d++ = *c++;
                        if (c >= ee)
                            break;
                        b = hexit(b, *c);
                        *d++ = *c++;
                        *b++ = ' ';
                    }
                    while (b < &obuf[50])
                        *b++ = ' ';
                    for (b = &obuf[50]; b < d; b++)
                        if (*b < ' ' || (unsigned char)*b > '~')
                            *b = '.';
                    while (d < &obuf[66])
                        *d++ = ' ';
                    if (write(1, obuf, 67) != 67)
                        abort();
                    pos += did;
                    lth -= did;
                    left -= did;
                    did = (left > 16) ? 16 : left;
                }
            else
                for (; lth > 0;)        /* each output line */
                {
                    for (*(b = &obuf[47]) = '0', start = pos; start;
                         start >>= 4)
                        *b-- = hex[start & 0xF];
                    b = &obuf[38];
                    d = &obuf[50];
                    if (offset)
                    {
                        b -= (2 * offset + (offset / 2));
                        d += offset;
                        if (offset & 1)
                        {
                            b--;
                            b = &hexit(b, *c)[-4];
                            *d++ = *c++;
                        }
                        offset = 0;
                    }
                    for (ee = &c[lth]; d < &obuf[66] && c < ee;)
                    {
                        *b-- = ' ';
                        b = &hexit(b, *c)[-4];
                        *d++ = *c++;
                        if (c >= ee)
                            break;
                        b = &hexit(b, *c)[-4];
                        *d++ = *c++;
                    }
                    if (b > obuf)
                        b[1] = ' ';
                    while (b >= obuf)
                        *b-- = ' ';
                    for (b = &obuf[50]; b < d; b++)
                        if (*b < ' ' || (unsigned char)*b > '~')
                            *b = '.';
                    while (d < &obuf[66])
                        *d++ = ' ';
                    if (write(1, obuf, 67) != 67)
                        abort();
                    pos += did;
                    lth -= did;
                    left -= did;
                    did = (left > 16) ? 16 : left;
                }
        }
    }
Esempio n. 10
0
File: eps.c Progetto: EQ4/SPTK
static void bbox(FILE * fp, int *xmin, int *ymin, int *xmax, int *ymax,
                 float shrink, int xoffset, int yoffset, struct bbmargin bbm)
{
   char c;
   int n, x, y;
   int temp_xmin, temp_ymin, temp_xmax, temp_ymax;
   int temp_plot_xmin, temp_plot_ymin = 0, temp_plot_xmax, temp_plot_ymax;
   int plot_xmin, plot_ymin, plot_xmax, plot_ymax;
   double unit_length;
   int rotate = 0;
   int ch = 30, cw = 30;
   float mag = 0.875;           /*  7/8  */

   temp_xmin = temp_ymin = 9999;
   temp_xmax = temp_ymax = 0;
   plot_xmin = xleng;
   plot_ymin = yleng;
   plot_xmax = plot_ymax = 0;

   while ((c = getc(fp)) != (char) EOF) {
      switch (c) {
      case 'M':
         fscanf(fp, "%d %d", &x, &y);
         temp_xmin = (temp_xmin < x ? temp_xmin : x);
         temp_ymin = (temp_ymin < y ? temp_ymin : y);
         temp_xmax = (temp_xmax > x ? temp_xmax : x);
         temp_ymax = (temp_ymax > y ? temp_ymax : y);
         break;
      case 'D':
         while (getd(fp, &x, &y)) {
            temp_xmin = (temp_xmin < x ? temp_xmin : x);
            temp_ymin = (temp_ymin < y ? temp_ymin : y);
            temp_xmax = (temp_xmax > x ? temp_xmax : x);
            temp_ymax = (temp_ymax > y ? temp_ymax : y);
         }
         break;
      case '%':
         fscanf(fp, "%d %d %d", &n, &x, &y);
         while (getd(fp, &x, &y)) {
            temp_xmin = (temp_xmin < x ? temp_xmin : x);
            temp_ymin = (temp_ymin < y ? temp_ymin : y);
            temp_xmax = (temp_xmax > x ? temp_xmax : x);
            temp_ymax = (temp_ymax > y ? temp_ymax : y);
         }
         break;
      case 'S':
         fscanf(fp, "%d", &ch);
         ch += 3;
         break;
      case 'Q':
         fscanf(fp, "%d", &cw);
         cw += 3;
         break;
      case 'R':
         fscanf(fp, "%d", &rotate);
         break;
      case 'P':
         n = getstrlength(fp);
         if (!rotate) {
            x += n * cw * mag;
            temp_xmax = (temp_xmax > x ? temp_xmax : x);
            y -= ch * mag;
            temp_ymin = (temp_ymin < y ? temp_ymin : y);
         } else {
            y += n * cw * mag;
            temp_ymax = (temp_ymax > y ? temp_ymax : y);
            x -= ch * mag;
            temp_xmin = (temp_xmin < x ? temp_xmin : x);
         }
         rotate = 0;
         break;
      case '\\':
         fscanf(fp, "%d %d", &temp_plot_xmin, &temp_plot_xmin);
         if (plot_xmin > temp_plot_xmin)
            plot_xmin = temp_plot_xmin;
         if (plot_ymin > temp_plot_ymin)
            plot_ymin = temp_plot_ymin;
         if (plot_xmin < 0)
            plot_xmin = 0;
         if (plot_ymin < 0)
            plot_ymin = 0;
         break;
      case 'Z':
         fscanf(fp, "%d %d", &temp_plot_xmax, &temp_plot_ymax);
         if (plot_xmax < temp_plot_xmax)
            plot_xmax = temp_plot_xmax;
         if (plot_ymax < temp_plot_ymax)
            plot_ymax = temp_plot_ymax;
         if (plot_xmax > xleng)
            plot_xmax = xleng;
         if (plot_ymax > yleng)
            plot_ymax = yleng;
         break;
      default:
         break;
      }
   }

   *xmin = plot_min(temp_xmin, *xmin, plot_xmin);
   *xmax = plot_max(temp_xmax, *xmax, plot_xmax);
   *ymin = plot_min(temp_ymin, *ymin, plot_ymin);
   *ymax = plot_max(temp_ymax, *ymax, plot_ymax);

   unit_length = shrink * PU_PT;

   if (!landscape) {
      *xmin = norm((*xmin + xoffset - bbm.left) * unit_length + MIN_OFFSET);
      *ymin = norm((*ymin + yoffset - bbm.bottom) * unit_length + MIN_OFFSET);
      *xmax = norm((*xmax + xoffset + bbm.right) * unit_length + MAX_OFFSET);
      *ymax = norm((*ymax + yoffset + bbm.top) * unit_length + MAX_OFFSET);
   } else {
      x = *xmin;
      y = *xmax;

      loffset += yoffset;

      *xmin = norm((yleng * unit_length
                    - *ymax + loffset - bbm.bottom) * unit_length + MIN_OFFSET);
      *xmax = norm((yleng * unit_length
                    - *ymin + loffset + bbm.top) * unit_length + MAX_OFFSET);
      loffset = (loffset - yoffset) / 4 + xoffset;
      *ymin = norm((x + loffset - bbm.left) * unit_length + MIN_OFFSET);
      *ymax = norm((y + loffset + bbm.right) * unit_length + MAX_OFFSET);
   }
   rewind(fp);

   return;
}
Esempio n. 11
0
	in(wstring s){ 
		cwd=getd(); 
		if( !setd(s) ) 
		throw wstring()+L"cannot get into [" + s +L"]"; 
	}