Example #1
0
/*
 * Returns 1 if bootenv.rc was modified, 0 otherwise.
 */
static int
set_var(char *name, char *val, eplist_t *list)
{
	benv_ent_t *p;

	if (strcmp(name, "bootcmd") == 0)
		return (0);

	if (verbose) {
		(void) printf("old:");
		print_var(name, list);
	}

	if ((p = get_var(name, list)) != NULL) {
		free(p->val);
		p->val = strdup(val);
	} else
		add_bent(list, NULL, "setprop", name, val);

	if (verbose) {
		(void) printf("new:");
		print_var(name, list);
	}
	return (1);
}
Example #2
0
void
Var_Dump(void)
{
	Var **t;

	unsigned int i;
	const char *banner;
	bool first = true;

	t = sort_ohash_by_name(&global_variables);
/* somewhat dirty, but does the trick */

#define LOOP(mask, value, do_stuff) \
	for (i = 0; t[i] != NULL; i++) \
		if ((t[i]->flags & (mask)) == (value)) { \
			if (banner) { \
				if (first) \
					first = false; \
				else \
					putchar('\n'); \
				fputs(banner, stdout); \
				banner = NULL; \
			} \
		    do_stuff; \
		}

	banner = "#variables from command line:\n";
	LOOP(VAR_FROM_CMD | VAR_DUMMY, VAR_FROM_CMD, print_var(t[i]));

	banner = "#global variables:\n";
	LOOP(VAR_FROM_ENV| VAR_FROM_CMD | VAR_DUMMY, 0, print_var(t[i]));

	banner = "#variables from env:\n";
	LOOP(VAR_FROM_ENV|VAR_DUMMY, VAR_FROM_ENV, print_var(t[i]));

	banner = "#variable name seen, but not defined:";
	LOOP(VAR_DUMMY|POISONS, VAR_DUMMY, printf(" %s", t[i]->name));

#undef LOOP

	printf("\n\n");

	for (i = 0; t[i] != NULL; i++)
		switch(t[i]->flags & POISONS) {
		case POISON_NORMAL:
			printf(".poison %s\n", t[i]->name);
			break;
		case POISON_EMPTY:
			printf(".poison empty(%s)\n", t[i]->name);
			break;
		case POISON_NOT_DEFINED:
			printf(".poison !defined(%s)\n", t[i]->name);
			break;
		default:
			break;
		}
	free(t);
	printf("\n");
}
Example #3
0
int main (int argc, char *argv[])
{
	print_var(&testclass::a);
	print_var(&testclass::b);

	run_method(&testclass::m1);
	run_method(&testclass::m2);

	return 0;
}
Example #4
0
int main(int argc, char **argv)
{
	int fd = 0;
	struct fb_var_screeninfo vinfo;
    int ret = 0;
	int just_read = 0;

	int hbp, hfp, hsw;
	int vbp, vfp, vsw;

	if (argc == 1) {
		just_read = 1;
	} else if (argc != 7) {
        printf("usage: ./setfb HBP HFP HSW VBP VFP VSW\n");
        return 1;
    }

	fd = open("/dev/fb0", O_RDWR);
	if (fd < 0) {
		printf("Error: cannot open framebuffer device.\n");
		exit(3);
	}

	/* Get variable screen information */
	if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
		printf("Error reading variable information.\n");
		close(fd);
		exit(4);
	}
	print_var(&vinfo);

	if (just_read)
		goto L_OUT;

	hbp = atoi(argv[1]);
	hfp = atoi(argv[2]);
	hsw = atoi(argv[3]);
	vbp = atoi(argv[4]);
	vfp = atoi(argv[5]);
	vsw = atoi(argv[6]);

	set_var(&vinfo, hbp, hfp, hsw, vbp, vfp, vsw);
	ret = ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo);
	if (ret) {
		perror("set to vga failed");
	} else
		print_var(&vinfo);

L_OUT:
	close(fd);
	return ret;
}
Example #5
0
void
tools_show_used( void ) {
/*  SV *sva; */
  hash_iter i;
  const void *k;
  size_t kl;

#ifdef BRUTE_FORCE
  fprintf( stderr, "Leaks found by free list snooping:\n" );
#endif

  k = hash_get_first_key( var_map, &i, &kl );
  while ( k ) {
    const where *w =
        ( const where * ) hash_GETNULL( hash_get( var_map, k, kl ) );
    if ( w ) {
      print_var( *( SV ** ) k, w );
    }
    k = hash_get_next_key( var_map, &i, &kl );
  }

#if 0
  for ( sva = PL_sv_arenaroot; sva; sva = ( SV * ) SvANY( sva ) ) {
    SV *sv = sva + 1;
    SV *svend = &sva[SvREFCNT( sva )];

    while ( sv < svend ) {
      if ( live_sv( sv ) ) {
        fprintf( stderr, "var in pool at %p\n", sv );
      }
      ++sv;
    }
  }
#endif

#ifdef BRUTE_FORCE
  if ( brute ) {

    fprintf( stderr, "Leaks found by brute force:\n" );
    k = hash_get_first_key( brute, &i, &kl );
    while ( k ) {
      const where *w =
          ( const where * ) hash_GETNULL( hash_get( brute, k, kl ) );
      if ( w ) {
        print_var( *( SV ** ) k, w );
      }
      k = hash_get_next_key( brute, &i, &kl );
    }
  }
#endif
}
Example #6
0
File: task2.c Project: liranr23/C
int choose_action(cmdLine *pCmdLine, linked_list *head, var_list *var_head){
  if(strcmp(pCmdLine->arguments[0], "quit") == 0){
    return 1;
  }
  else if(strcmp(pCmdLine->arguments[0], "cd") == 0){
    if((chdir(pCmdLine->arguments[1])) < 0){
      perror("Error changing a dir: ");
    }
    return 0;
  }
  else if(strcmp(pCmdLine->arguments[0], "history") == 0){
    if(head == 0){
      perror("Error-no history");
      return 0;
    }
    list_print(head);
    return 0;
  }
  else if(strcmp(pCmdLine->arguments[0], "env") == 0){
    print_var(var_head);
    return 0;
  }
  else if(strcmp(pCmdLine->arguments[0], "rename") == 0){
    rename_var(var_head, pCmdLine->arguments[1], pCmdLine->arguments[2]);
    return 0;
  }
  else{
    execute(pCmdLine);
    return 0;
  }
}
Example #7
0
INT multipole_map(INT elemi[], FLOAT elemf[], INT elemid, INT parti[], FLOAT partf[], INT partid, INT partn){
    ELEMINIT;
    INITPARTF;
    // printf("%s\n", "C multipole");
    GETATTRI(multipole,Knlen);
    GETATTRI(multipole,Kslen);
    GETATTRF(multipole,Hxl);
    GETATTRF(multipole,Hyl);
    GETATTRF(multipole,L);
    GETATTRF(multipole,Rel);

    GETCONSTF(partf,beta0);
    GETCOORDF(partf,x);
    GETCOORDF(partf,px);
    GETCOORDF(partf,y);
    GETCOORDF(partf,py);
    GETCOORDF(partf,delta);
    GETCOORDF(partf,tau);
    GETCOORDF(partf,pt);
    GETCOORDF(partf,chi);
    GETCOORDF(partf,s);
    for(;partid<partn;partid++){
      multipole_track(beta0, x, px, y, py, delta, tau, pt, chi, s, Knlen, Kslen, &elemf[elem_floatid],
                                    &elemf[elem_floatid+Knlen], Hxl, Hyl, L, Rel, GETPARTF(partid));
    };
    print_var(elemi,elemf,parti,partf,multipole_TYPE);
    return 1;
}
Example #8
0
int main( void )
{
	int var = 27;

	print_var( var );

	return 0;
}
Example #9
0
void
_clip_print_dbg(ClipMachine * ClipMachineMemory, ClipVar * vp)
{
   const char *nm = _clip_type_name(vp);

   if (_clip_dbg_out)
      fprintf(_clip_dbg_out, "%s; ", nm);
   print_var(ClipMachineMemory, vp, 0, DEV_DBG, 0);
}
Example #10
0
static void
print_variable(char *name)
{
	char *vname;
	efi_guid_t guid;

	breakdown_name(name, &guid, &vname);
	print_var(&guid, vname);
}
Example #11
0
void print_vars(void)
{
	pgxc_ctl_var *cur;

	lockLogFile();
	for(cur = var_head; cur; cur=cur->next)
		print_var(cur->varname);
	unlockLogFile();
}
Example #12
0
static void
print_table_var(lua_State *state, int si, int depth) {
    int pos_si = si > 0 ? si : (si - 1);
    ldb_output("{");
    int top = lua_gettop(state);
    lua_pushnil(state);
    int empty = 1;
    while(lua_next(state, pos_si ) !=0) {
        if(empty) {
            ldb_output("\n");
            empty = 0;
        }

        int i;
        for(i = 0; i < depth; i++) {
            ldb_output("\t");
        }

        ldb_output( "[" );
        print_var(state, -2, -1);
        ldb_output( "] = " );
        if(depth > 5) {
            ldb_output("{...}");
        } else {
            print_var(state, -1, depth + 1);
        }
        lua_pop(state, 1);
        ldb_output(",\n");
    }

    if (empty) {
        ldb_output(" }");
    } else {
        int i;
        for (i = 0; i < depth - 1; i++) {
            ldb_output("\t");
        }
        ldb_output("}");
    }
    lua_settop(state, top);
}
Example #13
0
File: var.c Project: aharri/base
void
Var_Dump(void)
{
	Var *v;
	unsigned int i;

	printf("#*** Global Variables:\n");

	for (v = ohash_first(&global_variables, &i); v != NULL;
	    v = ohash_next(&global_variables, &i))
		print_var(v);
}
Example #14
0
/*
 * Returns 1 if bootenv.rc is modified or 0 if no modification was
 * necessary.  This allows us to implement non super-user look-up of
 * variables by name without the user being yelled at for trying to
 * modify the bootenv.rc file.
 */
static int
proc_var(char *name, eplist_t *list)
{
	register char *val;

	if ((val = strchr(name, '=')) == NULL) {
		print_var(name, list);
		return (0);
	} else {
		*val++ = '\0';
		return (set_var(name, val, list));
	}
}
Example #15
0
static void
print_variables(void)
{
	int rv;
	char *name = NULL;
	efi_guid_t *guid = NULL;

	while ((rv = efi_get_next_variable_name(&guid, &name)) > 0)
		print_var(guid, name);

	if (rv < 0)
		err(1, "Error listing names");
}
Example #16
0
int
main (void)
{
  print_var ();

  printf ("We see var = %d\n", var);
  printf ("Setting var = 456\n");

  var = 456;

  print_var ();
  printf ("We see var = %d\n\n", var);

  var = 90;
  print_var ();
  printf ("We see var = %d\n\n", var);

  print_foo ();
  printf ("We see foo = %d\n", foo);
  printf ("Setting foo = 19\n");
  foo = 19;
  print_foo ();
  printf ("We see foo = %d\n\n", foo);
  fflush (stdout);

  printf ("Calling dllimported function pointer\n");
  func_ptr ();

  printf ("Calling functions using global structure\n"); 
  xyz.func_ptr ();
  * xyz.var = 40;
  xyz.func_ptr ();

  printf ("We see var2[0] = %d\n\n", var2[0]);

  printf ("We see const xyz %x %x\n", const_xyz.var, const_xyz.var_with_offset);

  return 0;
}
Example #17
0
void print_token(stoken_t *t) {
    printf("%c ", t->type);
    switch (t->type) {
    case 's':
        print_string(t);
        break;
    case 'v':
        print_var(t);
        break;
    default:
        printf("%s", t->val);
    }
    printf("%s", "\n");
}
Example #18
0
size_t print_token(char* buf, size_t len, stoken_t *t) {
    len += sprintf(buf + len, "%c ", t->type);
    switch (t->type) {
    case 's':
        len = print_string(buf, len, t);
        break;
    case 'v':
        len = print_var(buf, len, t);
        break;
    default:
        len += sprintf(buf + len, "%s", t->val);
    }
    len += sprintf(buf + len, "%c", '\n');
    return len;
}
Example #19
0
int
clip_DEVOUT(ClipMachine * ClipMachineMemory)
{
   ClipVar *vp = _clip_par(ClipMachineMemory, 1);

   _clip_fullscreen(ClipMachineMemory);

   if (!vp)
      return 0;

   print_var(ClipMachineMemory, vp, get_color(ClipMachineMemory, _clip_parc(ClipMachineMemory, 2)), DEV_DEV, 0);
   sync_mp(ClipMachineMemory);

   return 0;
}
Example #20
0
int
clip_OUTERR(ClipMachine * ClipMachineMemory)
{
   int i;

   for (i = 1; i <= ClipMachineMemory->argc; ++i)
   {
      ClipVar *vp = _clip_par(ClipMachineMemory, i);

      if (i > 1)
	 out_any(ClipMachineMemory, " ", 1, _clip_colorSelect(ClipMachineMemory), DEV_ERR);
      print_var(ClipMachineMemory, vp, _clip_colorSelect(ClipMachineMemory), DEV_ERR, 0);
   }
   return 0;
}
Example #21
0
static int
print_handler(lua_State *state, ldb_t *ldb,
              lua_Debug *ar, input_t *input) {
    if (input->num < 2) {
        ldb_output("usage: p <varname>\n");
        return 0;
    }

    if (search_local_var(state, ar, input->buffer[1])) {
        ldb_output("local %s = ", input->buffer[1]);
        print_var(state, -1, -1);
        lua_pop(state, 1);
        ldb_output("\n");
    } else if (search_global_var(state, ar, input->buffer[1])) {
        ldb_output("global %s = ", input->buffer[1]);
        print_var(state, -1, -1);
        lua_pop(state, 1);
        ldb_output("\n");
    } else {
        ldb_output("not found var %s\n",  input->buffer[1]);
    }

    return 0;
}
Example #22
0
INT kick2d_map(INT elemi[], FLOAT elemf[], INT elemid, INT parti[], FLOAT partf[], INT partid, INT partn){
    FLOAT k;
    INT elem_floatid,ndf,stf,o,i,j,pfstart;
    ELEMINIT;
    GETPARTF;    
    i=elemi[elemid+2];
    j=elemi[elemid+3];
    o=elemi[elemid+4];
    k=elemf[elem_floatid];
    for(partid=0;partid<partn;partid++){
      kick2d_calc(i,j,k,o,&partf[pfstart]);
    };
    printf("KICK2D:\n");
    print_var(elemi, elemf, parti, partf);
    return 1;
}
Example #23
0
/* dispoutat(nRow,nCol,var[,cColor]) */
int
clip_DISPOUTAT(ClipMachine * ClipMachineMemory)
{
   ClipVar *vp = _clip_par(ClipMachineMemory, 3);

   clip_DISPPOS(ClipMachineMemory);

   _clip_fullscreen(ClipMachineMemory);

   if (!vp)
      return 0;

   print_var(ClipMachineMemory, vp, get_color(ClipMachineMemory, _clip_parc(ClipMachineMemory, 4)), DEV_SCR, 0);
   sync_mp(ClipMachineMemory);

   return 0;
}
Example #24
0
/* create env vars in malloc memory */
static int create_vars(struct hf_wrapper *list, int offset)
{
	int var_cnt;
	struct hf_wrapper *w;

	/* create variables now */
	var_cnt=0;
	for(w=list;w;w=w->next_other) {
		if (!print_var(w, offset)) {
			LOG(L_ERR, "ERROR: build_hf_struct: create_vars failed\n");
			return 0;
		}
		var_cnt++;
	}

	return var_cnt;
}
Example #25
0
int
clip_QQOUT(ClipMachine * ClipMachineMemory)
{
    int i;

    for (i = 1; i <= ClipMachineMemory->argc; ++i)
    {
        ClipVar *vp = _clip_par(ClipMachineMemory, i);

        if (i > 1)
            out_any(ClipMachineMemory, " ", 1, _clip_colorSelect(ClipMachineMemory), DEV_DEVS);
        if (!vp)
            continue;
        print_var(ClipMachineMemory, vp, _clip_colorSelect(ClipMachineMemory), DEV_DEVS, 0);
    }
    sync_mp(ClipMachineMemory);

    return 0;
}
Example #26
0
INT drift_map(INT elemi[], FLOAT elemf[], INT elemid, INT parti[], FLOAT partf[], INT partid, INT partn){
    // INT cntexactdrift=0;
    ELEMINIT;
    INITPARTF;
    GETCOORDF(partf,x);
    GETCOORDF(partf,y);
    GETCOORDF(partf,px);
    GETCOORDF(partf,py);
    GETCOORDF(partf,tau);
    GETCOORDF(partf,delta);
    GETCOORDF(partf,pt);
    GETCOORDF(partf,s);
    GETCONSTF(partf,beta0);
    GETATTRF(drift,L);
    for(;partid<partn;partid++){
      drift_track(beta0, x, px, y, py, tau, delta, pt, s, L, GETPARTF(partid));
    };
    print_var(elemi,elemf,parti,partf,drift_TYPE);
    // if( cntexactdrift++ == 0 ) printf("thin6d exact drift \n");
    return 1;
}
Example #27
0
int main(int argc, char** argv) {

    globalLexTable = new LexemTable();
    globalTypeTable = new TypeTable();
    globalValueTable = new ValueTable();

    try {
        while ( (curr_tok = yylex()) != 0 ) {
            switch ( curr_tok ) {
            case TYPE:
                def_var();
                break;
            case ID:
                expr(false);
                break;
            case PRINT:
                print_var();
                break;
            }

            if ( curr_tok != SEMICOLON ) {
                curr_tok = yylex();
                if ( curr_tok != SEMICOLON ) {
                    std::cout << curr_tok << std::endl;
                    throw "; expected";
                }
            }
        }
    } catch(const char* s) {
        std::cout << s << std::endl;
    }

    delete globalLexTable;
    delete globalTypeTable;

    return 0;
}
Example #28
0
static void
print_var(ClipMachine * ClipMachineMemory, ClipVar * vp, int attr, int dev, int level)
{
   if (level >= ClipMachineMemory->print_max_deep)
   {
      char b[64];

      int l;

      sprintf(b, "Max print level reached: %d ", level);
      l = strlen(b);
      if (dev != DEV_LOG)
	 out_dev(ClipMachineMemory, b, l, attr, dev);
      _clip_out_log(b, l);
      return;
   }

   vp = _clip_vptr(vp);

   switch (vp->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType)
   {
   case UNDEF_type_of_ClipVarType:
      out_any(ClipMachineMemory, "NIL", 3, attr, dev);
      break;
   case NUMERIC_type_of_ClipVarType:
      {
	 if (vp->ClipType_t_of_ClipVar.memo_of_ClipType)
	 {
	    char *buf;

	    if (vp->ClipType_t_of_ClipVar.dec_of_ClipType)
	       buf = rational_toString(vp->ClipRationalVar_r_of_ClipVar.Struc_rational_of_ClipRationalVar, 10, vp->ClipType_t_of_ClipVar.dec_of_ClipType, 0);
	    else
	       buf = rational_toString(vp->ClipRationalVar_r_of_ClipVar.Struc_rational_of_ClipRationalVar, 10, ClipMachineMemory->decimals, 0);
	    out_any(ClipMachineMemory, buf, strlen(buf), attr, dev);
	    free(buf);
	 }
	 else
	 {
	    char buf[48];

	    char *s;

	    if (vp->ClipType_t_of_ClipVar.len_of_ClipType < sizeof(buf))
	       snprintf(buf, sizeof(buf), "%*.*f", vp->ClipType_t_of_ClipVar.len_of_ClipType, vp->ClipType_t_of_ClipVar.dec_of_ClipType, vp->ClipNumVar_n_of_ClipVar.double_of_ClipNumVar);
	    else
	       _clip_dtos(vp->ClipNumVar_n_of_ClipVar.double_of_ClipNumVar, buf, sizeof(buf), 0);
	    for (s = buf + strlen(buf); s > buf; --s)
	       if ((*s) == ',')
		  (*s) = '.';
	    out_any(ClipMachineMemory, buf, strlen(buf), attr, dev);
	 }
      }
      break;
   case CHARACTER_type_of_ClipVarType:
      out_any(ClipMachineMemory, vp->ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf, vp->ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.len_of_ClipBuf, attr, dev);
      break;
   case LOGICAL_type_of_ClipVarType:
      if (vp->ClipLogVar_l_of_ClipVar.value_of_ClipLogVar)
	 out_any(ClipMachineMemory, ".T.", 3, attr, dev);
      else
	 out_any(ClipMachineMemory, ".F.", 3, attr, dev);
      break;
   case DATE_type_of_ClipVarType:
      {
	 char *s = _clip_date_to_str(vp->ClipDateVar_d_of_ClipVar.julian_of_ClipDateVar, ClipMachineMemory->date_format);

	 out_any(ClipMachineMemory, s, strlen(s), attr, dev);
	 free(s);
      }
      break;
   case DATETIME_type_of_ClipVarType:
      {
	 int len;

	 char *s = _clip_ttoc(ClipMachineMemory, vp->ClipDateTimeVar_dt_of_ClipVar.julian_of_ClipDateTimeVar,
			      vp->ClipDateTimeVar_dt_of_ClipVar.time_of_ClipDateTimeVar, &len,
			      ClipMachineMemory->date_format, ClipMachineMemory->hours,
			      ClipMachineMemory->seconds);

	 out_any(ClipMachineMemory, s, len, attr, dev);
	 free(s);
      }
      break;
   case OBJECT_type_of_ClipVarType:
      vp->ClipObjVar_o_of_ClipVar.rtti_of_ClipObjVar->print_of_ClipObjRtti(ClipMachineMemory,
									   vp->ClipObjVar_o_of_ClipVar.obj_of_ClipObjVar,
									   vp->ClipObjVar_o_of_ClipVar.rtti_of_ClipObjVar, &ClipMachineMemory->buf, &ClipMachineMemory->buflen);
      out_any(ClipMachineMemory, ClipMachineMemory->buf, ClipMachineMemory->buflen, attr, dev);
      break;
   case PCODE_type_of_ClipVarType:
   case CCODE_type_of_ClipVarType:
      out_any(ClipMachineMemory, "CODE", 4, attr, dev);
      break;
   case ARRAY_type_of_ClipVarType:
      {
	 int i;

	 out_any(ClipMachineMemory, "{", 1, attr, dev);
	 for (i = 0; i < vp->ClipArrVar_a_of_ClipVar.count_of_ClipArrVar; ++i)
	 {
	    if (i)
	       out_any(ClipMachineMemory, ", ", 2, attr, dev);
	    print_var(ClipMachineMemory, vp->ClipArrVar_a_of_ClipVar.ClipVar_items_of_ClipArrVar + i, attr, dev, level + 1);
	 }
	 out_any(ClipMachineMemory, "}", 1, attr, dev);
      }
      break;
   case MAP_type_of_ClipVarType:
      {
	 int i;

	 out_any(ClipMachineMemory, "{", 1, attr, dev);
	 for (i = 0; i < vp->ClipMapVar_m_of_ClipVar.count_of_ClipMapVar; ++i)
	 {
	    char buf[64];

	    int l;

	    if (i)
	       out_any(ClipMachineMemory, ", ", 2, attr, dev);
	    _clip_hash_name(ClipMachineMemory, vp->ClipMapVar_m_of_ClipVar.ClipVarEl_items_of_ClipMapVar[i].no_of_ClipVarEl, buf, sizeof(buf));
	    l = strlen(buf);
	    snprintf(buf + l, sizeof(buf) - l, ":");
	    l += 1;
	    out_any(ClipMachineMemory, buf, l, attr, dev);
	    print_var(ClipMachineMemory, &vp->ClipMapVar_m_of_ClipVar.ClipVarEl_items_of_ClipMapVar[i].ClipVar_var_of_ClipVarEl, attr, dev, level + 1);
	 }
	 out_any(ClipMachineMemory, "}", 1, attr, dev);
      }
      break;
   default:
      break;
   }
}
Example #29
0
int calc_main()
{
    char cmd[1005];
    char history[HIST][1005];
    char einfo[20][30]={
"",
"",
"矩阵太大",
"矩阵宽度不一致",
"矩阵长度不一致",
"矩阵大小不一致",
"除数不能为0",
"底数必须为正数",
"必须为正方矩阵",
"越界错",
"矩阵长度必须为1",
"表达式出错",
"操作数必须不为矩阵",
"该矩阵无法求逆",
"变量名称错",
"变量数目过多",
"矩阵输入错误",
"单步值不能为0",
"表达式出错",
""};
    int y,x,res,i,ch,hi,oldmode;
    oldmode=uinfo.mode;
    modify_user_mode(CALC);
    for(i=0;i<HIST;i++) history[i][0]=0;
    res = get_var("res");
    set_var(vars+get_var("%pi"), Pi);
    set_var(vars+get_var("%e"), exp(1));
    clear();
    outline("欢迎使用超级计算器1.0        作者:[email protected]\n");
    outline("输入exit退出,输入help帮助\n\n");
    while(1) {
        hi=0;
        getyx(&y, &x);
        cmd[0]=0;
        do{
            UPDOWN = true;
            ch = multi_getdata(y, x, scr_cols-1, "> ", cmd, 995, 13, 0,0 );
            UPDOWN = false;
            if(ch==-KEY_UP) {
                if(hi==HIST) cmd[0]=0;
                else strncpy(cmd, history[hi], 1000);
                hi++; if(hi>HIST) hi=0;
            } else if(ch==-KEY_DOWN) {
                hi--; if(hi<0) hi=HIST;
                if(hi==HIST) cmd[0]=0;
                else strncpy(cmd, history[hi], 1000);
            }
        } while(ch<0);
        y = y-1+ch;
        if(y>=scr_lns) y = scr_lns-1;
        move(y, 0);
        outline("\n");
        if(!cmd[0]) continue;
        if(!strncasecmp(cmd, "exit", 5)) break;
        if(!strncasecmp(cmd, "quit", 5)) break;
        for(i=HIST-1;i>0;i--)
            strncpy(history[i],history[i-1],1000);
        strncpy(history[0],cmd,1000);
        if(!strncasecmp(cmd, "help", 5)||!strncasecmp(cmd, "?", 2)) {
            outline("变量: 1到6个字母,例如x=3\n");
            outline("常量: %pi, %e\n");
            outline("矩阵: [3,4;5,6] a(3:4,1:5:2) 1:5:0.5\n");
            outline("函数: sin,cos,tan,asin,acos,atan,log,exp,ln,fact,\n");
            outline("      sinh,cosh,tanh,asinh,acosh,atanh\n");
            outline("      abs,sign,sqr,sqrt,round,floor,ceil\n");
            outline("      det,inv\n");
            outline("操作: + - * / ^ '(转置) .*(矩阵乘) ./(矩阵除) \n");
            continue;
        }
        if(strchr(cmd, '=')) {
            i=strchr(cmd, '=')-cmd;
            if(i<=0||!check_var_name(cmd, i)) {
                calcerr=19;
                goto checkcalcerr;
            }
            cmd[i]=0;
            res = get_var(cmd);
            i++;
        }
        else {
            res = get_var("res");
            i=0;
        }
        eval(vars+res, cmd+i, 0, strlen(cmd+i)-1);
checkcalcerr:
        if(calcerr) {
            outline(einfo[calcerr]);
            outline("\n");
            calcerr=0;
            continue;
        }
        else
            print_var(vars+res);
    }
    for(i=0;i<vart;i++)
        del(vars+i);
    modify_user_mode(oldmode);
    return 0;
}
Example #30
0
void log_var(char *varname)
{
	if (logFile)
		print_var(varname);
}