Exemple #1
0
void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
  int pc = codeptr - bc->code;
  printf("%04d ", pc);
  const struct opcode_description* op = opcode_describe(bc->code[pc++]);
  printf("%s", op->name);
  if (op->length > 1) {
    uint16_t imm = bc->code[pc++];
    if (op->op == CALL_JQ || op->op == TAIL_CALL_JQ) {
      for (int i=0; i<imm+1; i++) {
        uint16_t level = bc->code[pc++];
        uint16_t idx = bc->code[pc++];
        jv name;
        if (idx & ARG_NEWCLOSURE) {
          idx &= ~ARG_NEWCLOSURE;
          name = jv_object_get(jv_copy(getlevel(bc,level)->subfunctions[idx]->debuginfo),
                               jv_string("name"));
        } else {
          name = jv_array_get(jv_object_get(jv_copy(getlevel(bc,level)->debuginfo),
                                            jv_string("params")), idx);
        }
        printf(" %s:%d",
               jv_string_value(name),
               idx);
        jv_free(name);
        if (level) {
          printf("^%d", level);
        }
      }
    } else if (op->op == CALL_BUILTIN) {
      int func = bc->code[pc++];
      jv name = jv_array_get(jv_copy(bc->globals->cfunc_names), func);
      printf(" %s", jv_string_value(name));
      jv_free(name);
    } else if (op->flags & OP_HAS_BRANCH) {
      printf(" %04d", pc + imm);
    } else if (op->flags & OP_HAS_CONSTANT) {
      printf(" ");
      jv_dump(jv_array_get(jv_copy(bc->constants), imm), 0);
    } else if (op->flags & OP_HAS_VARIABLE) {
      uint16_t v = bc->code[pc++];
      jv name = jv_array_get(jv_object_get(jv_copy(getlevel(bc,imm)->debuginfo), jv_string("locals")), v);
      printf(" $%s:%d",
             jv_string_value(name),
             v);
      jv_free(name);
      if (imm) {
        printf("^%d", imm);
      }
    } else {
      printf(" %d", imm);
    }
  }
}
Exemple #2
0
int			main()
{
  t_board		board;
  SDL_Surface		*ecran;
  char			*levelname;

  if (SDL_Init(SDL_INIT_VIDEO) == -1)
    {
      xwrite(2, "SDL_INIT Error\n", 15);
      exit(EXIT_FAILURE);
    }
  if ((levelname = getlevel()) != NULL)
    get_map(&board, levelname);
  else
    return (1);
  board.mobs = create_mobs(&board);
  init_player(&board.player.ix, &board.player.iy, &board);
  board.player.nb_life = 3;
  ecran = xSDL_SetVideoMode(board.size * 30 , board.h * 30, 32,
			   SDL_HWSURFACE | SDL_DOUBLEBUF);
  SDL_WM_SetCaption("Epikong", NULL);
  board.ecran = ecran;
  aff_board(&board, ecran);
  play_the_game(&board);
  return (0);
}
Exemple #3
0
int
main(int argc, char **argv)
{
    int             ups_fd, stat_fd, ch;
    int             flags;
    int             pstatus, poldstat = 1;
    int             bstatus, boldstat = 1;
    int             count = 0;
    int             bcount = 0;
    int             tries = 0;
    int             ikill = 0;
    int             ioctlbit;
    char           *self = argv[0];
    char            killchar = ' ';
    struct upsdef  *pups;

    while ((ch = getopt(argc, argv, "kc:d:r:s:t:")) != -1)
	switch (ch) {
	  case 'k':
	    ikill = 1;
	    break;
	  case 'c':
	    config_file = optarg;
	    break;
	  case 'd':
	    upsport = optarg;
	    break;
	  case 'r':
	    rcpowerfail = optarg;
	    break;
	  case 's':
	    upsstat = optarg;
	    break;
	  case 't':
	    upstype = optarg;
	    break;
	  case '?':
	  default:
	    usage(self);
	}
    argc -= optind;
    argv += optind;
    if (argc > 0)
	usage(self);

    parse_config(config_file);

    if (upsport == NULL || upstype == NULL || upsstat == NULL) {
	usage(self);
    }
    for (pups = ups; pups; pups = pups->next) {
	if (strcmp(pups->tag, upstype) == 0)
	    break;
    }
    if (!pups) {
	fprintf(stderr, "Error: %s: UPS <%s> unknown\n", self, argv[2]);
	exit(1);
    }
    /* Start syslog. */
    openlog(self, LOG_CONS | LOG_PERROR, LOG_DAEMON);

    if ((ups_fd = open(upsport, O_RDWR | O_NDELAY)) < 0) {
	syslog(LOG_ERR, "%s: %s", upsport, strerror(errno));
	closelog();
	exit(1);
    }
    /* Kill the inverter and close out if inverter kill was selected */
    if (ikill) {
	if (pups->killtime) {

	    /* Explicitly clear both DTR and RTS as soon as possible  */
	    ioctlbit = TIOCM_RTS;
	    ioctl(ups_fd, TIOCMBIC, &ioctlbit);
	    ioctlbit = TIOCM_DTR;
	    ioctl(ups_fd, TIOCMBIC, &ioctlbit);

	    /* clear killpower, apply cablepower to enable monitoring */
	    setlevel(ups_fd, pups->kill.line, !pups->kill.inverted);
	    setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted);

	    if (pups->kill.line == TIOCM_ST) {
		/* Send BREAK (TX high) to kill the UPS inverter. */
		tcsendbreak(ups_fd, 1000 * pups->killtime);
	    } else {
		/* Force high to send the UPS the inverter kill signal. */
		setlevel(ups_fd, pups->kill.line, pups->kill.inverted);
		sleep(pups->killtime);
	    }
	    ioctl(ups_fd, TIOCMGET, &flags);

	    /*
	     * Feb/05/2001 Added support for Tripplite Omnismart 450PNP, this
	     * UPS shutdowns inverter when data is sent over the Tx line
	     * (jhcaiced)
	     */
	    if (pups->flags & UPS_TXD_KILL_INVERTER) {
		sleep(2);
		write(ups_fd, &killchar, 1);
	    }
	    close(ups_fd);

	    /************************************************************/
	    /* We never should have gotten here.                        */
	    /* The inverter kill has failed for one reason or another.  */
	    /* If still in powerfail mode, exit with an error.          */
	    /* If power is ok (power has returned) let rc.0 finish the  */
	    /* reboot.                                                  */
	    /************************************************************/
	    if (getlevel(&pups->powerok, flags) == 0) {
		fprintf(stderr, "%s: UPS inverter kill failed.\n", self);
		exit(1);
	    }			/* if (getlevel(&pups->powerok,flags) == 0) */
	    /* Otherwise, exit normaly, power has returned. */
	    exit(0);
	} else {
	    fprintf(stderr, "Error: %s: UPS <%s> has no support for killing the inverter.\n",
		    self, pups->tag);
	    exit(1);
	}			/* if (pups->kill) */
    }				/* if (ikill) */
    /****************************************/
    /* If no kill signal, monitor the line. */
    /****************************************/
    /* Explicitly clear both DTR and RTS as soon as possible  */
    ioctl(ups_fd, TIOCMBIC, TIOCM_RTS);
    ioctl(ups_fd, TIOCMBIC, TIOCM_DTR);

    /* clear killpower, apply cablepower to enable monitoring */
    setlevel(ups_fd, pups->kill.line, !pups->kill.inverted);
    setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted);

    /* Daemonize. */
#ifdef DEBUG
    closelog();
    setsid();
#else
    switch (fork()) {
      case 0:			/* Child */
	closelog();
	setsid();
	break;
      case -1:			/* Error */
	syslog(LOG_ERR, "can't fork.");
	closelog();
	exit(1);
      default:			/* Parent */
	closelog();
	exit(0);
    }
#endif				/* switch(fork()) */

    /* Restart syslog. */
    openlog(self, LOG_CONS, LOG_DAEMON);

    /* Create an info file for powerfail scripts. */
    unlink(upsstat);
    if ((stat_fd = open(upsstat, O_CREAT | O_WRONLY, 0644)) >= 0) {
	write(stat_fd, "OK\n", 3);
	close(stat_fd);
    }
    /* Give the UPS a chance to reach a stable state. */
    sleep(2);

    /* Now sample the line. */
    while (1) {
	/* Get the status. */
	ioctl(ups_fd, TIOCMGET, &flags);

	/* Calculate present status. */
	pstatus = getlevel(&pups->powerok, flags);
	bstatus = getlevel(&pups->battok, flags);

	if (pups->cableok.line) {
	    /* Check the connection. */
	    tries = 0;
	    while (getlevel(&pups->cableok, flags) == 0) {
		/* Keep on trying, and warn every two minutes. */
		if ((tries % 60) == 0)
		    syslog(LOG_ALERT, "UPS connection error");
		sleep(2);
		tries++;
		ioctl(ups_fd, TIOCMGET, &flags);
	    }			/* while(getlevel(&pups->cableok,flags) */
	    if (tries > 0)
		syslog(LOG_ALERT, "UPS connection OK");
	} else {
	    /*
	     * Do pseudo-cable check, bad power on startup == possible bad
	     * cable
	     */
	    if (tries < 1) {
		tries++;

		/* Do startup failure check */
		if (!pstatus) {
		    /*
		     * Power is out: assume bad cable, but semi-scram to be
		     * safe
		     */
		    syslog(LOG_ALERT, "No power on startup; UPS connection error?");

		    /*
		     * Set status registers to prevent further processing
		     * until
		     */
		    /* the status of the cable is changed.                      */
		    poldstat = pstatus;
		    boldstat = bstatus;

		    powerfail(PFM_CABLE);
		}		/* if (!pstatus) */
	    }			/* if (tries < 1) */
	}			/* if (pups->cableok.line) */

	/* If anything has changed, process the change */
	if (pstatus != poldstat || bstatus != boldstat) {
	    count++;
	    if (count < 4) {
		/* Wait a little to ride out short brown-outs */
		sleep(1);
		continue;
	    }			/* if (count < 4) */
	    if (pstatus != poldstat) {
		if (pstatus) {
		    /* Power is OK */
		    syslog(LOG_ALERT, "Line power restored");
		    powerfail(PFM_OK);
		} else {
		    /* Power has FAILED */
		    if (bstatus) {
			/* Battery OK, normal shutdown */
			syslog(LOG_ALERT, "Line power has failed");
			powerfail(PFM_FAIL);
		    } else {
			/* Low Battery, SCRAM! */
			syslog(LOG_ALERT, "UPS battery power is low!");
			powerfail(PFM_SCRAM);
		    }		/* if (bstatus) */
		}		/* if (pstatus) */
	    }			/* if (pstatus != poldstat) */
	    if (bstatus != boldstat) {
		if (!bstatus && !pstatus) {
		    /* Power is out and Battery is now low, SCRAM! */
		    syslog(LOG_ALERT, "UPS battery power is low!");
		    powerfail(PFM_SCRAM);
		} else {
		    /* Battery status has changed */
		    if (bstatus) {
			/* Battery power is back */
			syslog(LOG_ALERT, "UPS battery power is now OK");
		    }		/* if (!bstatus) */
		}		/* if (!bstatus && !pstatus) */
	    }			/* if (bstatus != boldstat) */
	}			/* if (pstatus != poldstat || bstatus !=
				 * boldstat) */

	if (!bstatus && pstatus) {
	    /* Line power is OK and UPS signals battery is low */
	    /* Log a message to the syslog every 10 minutes */
	    if ((bcount % 300) == 0)
		syslog(LOG_ALERT, "UPS battery power is low!");
	    bcount++;
	} else {
	    /* Reset count */
	    bcount = 0;
	}			/* if (!bstatus && pstatus) */

	/* Reset count, remember status and sleep 2 seconds. */
	count = 0;
	poldstat = pstatus;
	boldstat = bstatus;
	sleep(2);
    }				/* while(1) */
    /* Never happens */
    return (0);
}
Exemple #4
0
void diag(void)
{
	int	i, j;

	if ((dfile = fopen(diagfile, "w")) == (FILE *)NULL)
		return;

	lprcat("\nDiagnosing . . .\n");
	lflush();

	fprintf(dfile,"\n-------- Beginning of DIAG diagnostics ---------\n\n");

	fprintf(dfile, "Hit points: %2ld(%2ld)\n", c[HP], c[HPMAX]);

	fprintf(dfile, "gold: %ld  Experience: %ld  Character level: %ld  Level in caverns: %d\n",
	(long) c[GOLD],
	(long) c[EXPERIENCE],
	(long) c[LEVEL],
	level);

	fprintf(dfile, "\nFor the c[] array:\n");
	fflush(dfile);

	for( j=0; j<100; j++)
		fprintf(dfile, "c[%d]\t%-20s\t= %ld\n", j, cdef[j], c[j]);
	fprintf(dfile, "\n\n");
	fflush(dfile);

	fprintf(dfile, "Inventory\n");
	for (j=0; j<IVENSIZE; j++) {
		fprintf (dfile, "iven[%d] %-12s = %d", 
		j, ivendef[iven[j]], iven[j] );
		fprintf (dfile, "\t%s", objectname[iven[j]] );
		fprintf (dfile, "\t+ %d\n", ivenarg[j] );
	}

	fprintf(dfile, "\nHere are the maps:\n\n");
	monstnamelist[DEMONLORD] = '1';
	monstnamelist[DEMONLORD+1] = '2';
	monstnamelist[DEMONLORD+2] = '3';
	monstnamelist[DEMONLORD+3] = '4';
	monstnamelist[DEMONLORD+4] = '5';
	monstnamelist[DEMONLORD+5] = '6';
	monstnamelist[DEMONLORD+6] = '7';
	monstnamelist[DEMONPRINCE] = '9';
	monstnamelist[LUCIFER] = '0';
	i = level;
	for (j = 0; j < NLEVELS; j++) {
		newcavelevel(j);
		fprintf(dfile, "\n-------------------------------------------------------------------\n");
		fprintf(dfile, "Map %s    level %d\n", 
		levelname[level], level);
		fprintf(dfile, "-------------------------------------------------------------------\n");
		diagdrawscreen();
		fflush(dfile);
	}
	level = i;
	getlevel();

	fprintf(dfile, "\n\nNow for the monster data:\n\n");
	fprintf(dfile, "\nTotal types of monsters: %d\n\n", MAXMONST + 8);
	fprintf(dfile, "   Monster Name      LEV  AC   DAM  ATT  GOLD   HP     EXP\n");
	fprintf(dfile, "-----------------------------------------------------------------\n");
	fflush(dfile);

	for (i = 0; i <= MAXMONST + 8; i++) {
		fprintf(dfile, "%19s  %2d  %3d ", 
		monster[i].name, 
		monster[i].level, 
		monster[i].armorclass);
		fprintf(dfile, " %3d  %3d ", 
		monster[i].damage, 
		monster[i].attack); 
		fprintf(dfile, "%6d  %3d   %6ld\n", 
		monster[i].gold, 
		monster[i].hitpoints,
		(long) monster[i].experience);
		fflush(dfile);
	}

	fprintf(dfile, "\nAvailable potions:\n\n");
	for (i = 0; i < MAXPOTION; i++)
		fprintf(dfile, "%20s\n", &potionname[i][1]);
	fflush(dfile);

	fprintf(dfile, "\nAvailable scrolls:\n\n");
	for (i = 0; i < MAXSCROLL; i++)
		fprintf(dfile, "%20s\n", &scrollname[i][1]);
	fflush(dfile);

	fprintf(dfile, "\nSpell list:\n\n");
	fprintf(dfile, "spell#  name           description\n");
	fprintf(dfile, "-------------------------------------------------\n\n");

	for (j = 0; j < SPNUM; j++) {
		fprintf(dfile, "%-10s", spelcode[j]);
		fprintf(dfile," %21s\n", spelname[j]);
		fprintf(dfile,"%s\n", speldescript[j]);
	}
	fflush(dfile);

	fprintf(dfile, "\nObject list\n\n");
	fprintf(dfile, "\nj \tObject \tName\n");
	fprintf(dfile, "---------------------------------\n");
	for (j = 0; j < MAXOBJ; j++)
		fprintf(dfile, "%d \t%c \t%s\n",
		j,
		objnamelist[j],
		objectname[j] );
	fflush(dfile);

	fprintf(dfile,"\n-------- End of DIAG diagnostics ---------\n");
	fflush(dfile);
	fclose(dfile);

	lprcat("\nDone Diagnosing.\n");
	lflush();
}
int ExpCalAmt(char *num_exp,double *out_amt)
{
	bool error=0;
	point=0;bracket=0;stacknum=0;error=0;
	strcpy(string,num_exp);
	STRLEN=strlen(string);
		if(!check()) 
		{
			return -1;
		}
		result=getnumber();
		while(point<=STRLEN-1){
			switch(string[point++]){//哪个运算符?
			case '+':
				if(getnextopsign()>ADDLEVEL){
					push(ADD);
					result=getnumber();
				}
				else result+=getnumber();
				break;
			case '-':
				if(getnextopsign()>SUBLEVEL){
					push(SUB);
					result=getnumber();
				}
				else result-=getnumber();
				break;
			case '*':
				if(getnextopsign()>MULLEVEL){
					push(MUL);
					result=getnumber();
				}
				else
				{
					result*=getnumber();
					result=d4u5(result,2);
					if(stacknum>0 && getnextopsign()<MULLEVEL && getstack(stacknum)->bracket>=bracket)
						pop();
				}
				break;
			case '/':
				if(getnextopsign()>DIVLEVEL){
					push(DIV);
					result=getnumber();
				}
				else
				{
					result/=getnumber();
					if(stacknum>0 && getnextopsign()<DIVLEVEL && getstack(stacknum)->bracket>=bracket)
						pop();
				}
				break;
			case ')'://右括号
				--bracket;
				if(getstack(stacknum)->opsign==0){//括号前面为空
					pop();
					break;
				}
				while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket && getstack(stacknum)->opsign!=0)
						//将本层括号内可以pop的都pop
						pop();
				break;
			case '^':
				if(getnextopsign()>POWLEVEL){
					push(POW);
					result=getnumber();
				}
				else
				{
					result=(float)pow((double)result,(double)getnumber());
					while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket) pop();
				}
				break;
			case '!':
				if(getnextopsign()>FACTLEVEL){
					push(FACT);
					result=getnumber();
				}
				else
				{
					result=fact((long)result);
					while(stacknum>0 && getnextopsign()<getlevel(getstack(stacknum)->opsign)
						&& getstack(stacknum)->bracket>=bracket) pop();
				}
				break;
			}
		}
		//if(!error) printf("计算结果:%g\n",result);
	*out_amt=result;
	return 0;
}
Exemple #6
0
string expr_to_str(Node * node,int level)
{
	string str="";
	int thislevel=0;
	switch(node->type)
	{
		case t_expr_func:
		{
			Expr_func * funcnode=(Expr_func *)node;
			if(strcmp(funcnode->funname,"CASE3")==0)
			{
				str="case ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" end";
			}
			else if(strcmp(funcnode->funname,"CASE4")==0)
			{
				str="case ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" else ";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+" end";
			}
			else if(strcmp(funcnode->funname,"WHEN1")==0)
			{
				str="when ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" then ";
				str=str+expr_to_str(funcnode->parameter2,0);
			}
			else if(strcmp(funcnode->funname,"WHEN2")==0)
			{
				str="when ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" then ";
				str=str+expr_to_str(funcnode->parameter2,0);
			}
			else if(strcmp(funcnode->funname,"FSUBSTRING0")==0)
			{
				str="substr(";
				str=str+expr_to_str(funcnode->args,0);
				str=str+",";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FSUBSTRING1")==0)
			{
				str="substr(";
				str=str+expr_to_str(funcnode->args,0);
				str=str+",";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+",";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FTRIM0")==0)
			{
				str="trim(";
				str=str+"both ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+"from ";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FTRIM1")==0)
			{
				str="trim(";
				str=str+"trailing ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+"from ";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FTRIM2")==0)
			{
				str="trim(";
				str=str+"leading ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+"from ";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+")";

			}
			else if(strcmp(funcnode->funname,"FTRIM3")==0)
			{
				str="trim(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FUPPER")==0)
			{
				str="upper(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FCAST")==0)
			{
				str="case(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" as ";
				str=str+expr_to_str(funcnode->parameter2,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FCOALESCE")==0)
			{

			}
			else if(strcmp(funcnode->funname,"FCOUNTALL")==0)
			{
				str="count(*)";
			}
			else if(strcmp(funcnode->funname,"FCOUNT")==0)
			{
				str="count(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FSUM")==0)
			{
				str="sum(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FAVG")==0)
			{
				str="avg(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FMIN")==0)
			{
				str="min(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FMAX")==0)
			{
				str="max(";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+")";
			}
			else if(strcmp(funcnode->funname,"FDATE_ADD")==0)
			{
				Expr_func *datefunc=(Expr_func *)funcnode->parameter1;
				str="date_add(";
				str=str+expr_to_str(funcnode->args,0);
				str=str+",interval ";
				str=str+expr_to_str(datefunc->args,0);
				if(strcmp(datefunc->funname,"INTERVAL_DAY")==0)
				{
					str=str+" day)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_WEEK")==0)
				{
					str=str+" week)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_MONTH")==0)
				{
					str=str+" month)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_YEAR")==0)
				{
					str=str+" year)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_QUARTER")==0)
				{
					str=str+" quarter)";
				}

			}
			else if(strcmp(funcnode->funname,"FDATE_SUB")==0)
			{
				Expr_func *datefunc=(Expr_func *)funcnode->parameter1;
				str="date_sub(";
				str=str+expr_to_str(funcnode->args,0);
				str=str+",interval ";
				str=str+expr_to_str(datefunc->args,0);
				if(strcmp(datefunc->funname,"INTERVAL_DAY")==0)
				{
					str=str+" day)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_WEEK")==0)
				{
					str=str+" week)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_MONTH")==0)
				{
					str=str+" month)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_YEAR")==0)
				{
					str=str+" year)";
				}
				else if(strcmp(datefunc->funname,"INTERVAL_QUARTER")==0)
				{
					str=str+" quarter)";
				}
			}
			else if(strcmp(funcnode->funname,"BA")==0)
			{
				str=expr_to_str(funcnode->args,0);
				str=str+" between ";
				str=str+expr_to_str(funcnode->parameter1,0);
				str=str+" and ";
				str=str+expr_to_str(funcnode->parameter2,0);
			}
			else
			{
				SQLParse_elog("expr_to_str doesn't exist this function !!!");
			}
			funcnode->str=(char *)malloc(str.size()+1);
			strcpy(funcnode->str,str.c_str());
		}break;
		case t_expr_cal:
		{
			Expr_cal * calnode=(Expr_cal *)node;
			thislevel=getlevel(calnode);
			if(strcmp(calnode->sign,"--")==0)
			{
				str="-";
			}
			else if(strcmp(calnode->sign,"++")==0)
			{
				str="+";
			}
			else if(strcmp(calnode->sign,"!")==0)
			{
				str="!";
			}
			else if(strcmp(calnode->sign,"NOT")==0)
			{
				str="not";
			}
			else
			{
				str=expr_to_str(calnode->lnext,thislevel);
				if(strcmp(calnode->sign,"CMP")==0)
				{
					switch(calnode->cmp)
					{
						case 1://"<"
						{
							str=str+"<";
						}break;
						case 2://">"
						{
							str=str+">";
						}break;
						case 3://"<>"
						{
							str=str+"!=";
						}break;
						case 4://"="
						{
							str=str+"=";
						}break;
						case 5://"<="
						{
							str=str+"<=";
						}break;
						case 6://">="
						{
							str=str+">=";
						}break;
						default:
						{
						}
					}
				}
				else if(strcmp(calnode->sign,"ANDOP")==0)
				{
					str=str+"and";
				}
				else if(strcmp(calnode->sign,"OR")==0)
				{
					str=str+"or";
				}
				else
				{
					str=str+calnode->sign;
				}
			}

	    	str=str+expr_to_str(calnode->rnext,thislevel);
			calnode->str=(char *)malloc(str.size()+1);
			strcpy(calnode->str,str.c_str());
			if(thislevel<level)
			{
				str="("+str+")";
			}
//			memcpy(calnode->str,str.c_str(),str.size());
		}break;
		case t_name:
		case t_name_name:
		{
			Columns *col=(Columns *)node;
			if(col->parameter1==NULL)
			{
				str=str+string(col->parameter2);
			}
			else
			{
				str=str+string(col->parameter2);
			}
		}break;
		case t_stringval:
		{
			Expr * exprval=(Expr *)node;
			str=str+string(exprval->data);
		}break;
		case t_intnum:
		{
			Expr * exprval=(Expr *)node;
			str=str+string(exprval->data);
		}break;
		case t_approxnum:
		{
			Expr * exprval=(Expr *)node;
			str=str+string(exprval->data);
		}break;
		case t_bool:
		{

		}break;
		default:
		{

		}
	}
	return str;
}