Beispiel #1
0
/* done with all structures along the way to deepest*/
PRIVATE int
update_deepest(Encoded *Enc, struct_en *str, struct_en *min){

  /* apply move + get its energy*/
  int tmp_en;
  tmp_en = str->energy + energy_of_move_pt(str->structure, Enc->s0, Enc->s1, Enc->bp_left, Enc->bp_right);
  do_move(str->structure, Enc->bp_left, Enc->bp_right);
  if (Enc->bp_left2 != 0) {
    tmp_en += energy_of_move_pt(str->structure, Enc->s0, Enc->s1, Enc->bp_left2, Enc->bp_right2);
    do_move(str->structure, Enc->bp_left2, Enc->bp_right2);
  }
  int last_en = str->energy;
  str->energy = tmp_en;

  /* use f_point if we have it */
  if (Enc->funct) {
    int end = Enc->funct(str, min);

    // undo moves
    if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2);
    do_move(str->structure, -Enc->bp_left, -Enc->bp_right);
    str->energy = last_en;
    Enc->bp_left=0;
    Enc->bp_right=0;
    Enc->bp_left2=0;
    Enc->bp_right2=0;

    return (end?1:0);
  }

  if (Enc->verbose_lvl>1) { fprintf(stderr, "  "); print_str(stderr, str->structure); fprintf(stderr, " %5d D\n", tmp_en); }

  /* better deepest*/
  if (str->energy < min->energy || (!deal_deg && str->energy == min->energy && compare(str->structure, min->structure))) {
    min->energy = tmp_en;
    copy_arr(min->structure, str->structure);

    /* delete degeneracy*/
    free_degen(Enc);

    /* undo moves*/
    if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2);
    do_move(str->structure, -Enc->bp_left, -Enc->bp_right);
    str->energy = last_en;
    Enc->bp_left=0;
    Enc->bp_right=0;
    Enc->bp_left2=0;
    Enc->bp_right2=0;
    return 1;
  }

  /* degeneracy*/
  if (deal_deg &&(str->energy == min->energy) && (Enc->current_en == min->energy)) {
    int found = 0;
    int i;
    for (i=Enc->begin_pr; i<Enc->end_pr; i++) {
      if (equals(Enc->processed[i], str->structure)) {
        found = 1;
        break;
      }
    }
    for (i=Enc->begin_unpr; !found && i<Enc->end_unpr; i++) {
      if (equals(Enc->unprocessed[i], str->structure)) {
        found = 1;
        break;
      }
    }

    if (!found) {
      //print_stren(stderr, str); // fprintf(stderr, " %6.2f\n", str->energy);
      Enc->unprocessed[Enc->end_unpr]=allocopy(str->structure);
      Enc->end_unpr++;
    }
  }

  /* undo moves*/
  if (Enc->bp_left2!=0) do_move(str->structure, -Enc->bp_left2, -Enc->bp_right2);
  do_move(str->structure, -Enc->bp_left, -Enc->bp_right);
  str->energy = last_en;
  Enc->bp_left=0;
  Enc->bp_right=0;
  Enc->bp_left2=0;
  Enc->bp_right2=0;
  return 0;
}
Beispiel #2
0
static int print_uns(FILE * stream, unsigned int num) {
	return print_str(stream, (char *)utoa(num, 10));
} 
Beispiel #3
0
char	*get_out_map_file_name( char *s )
{
	long	i;
	const long	max_i = LOOP_MAX_1000;
	static char	fname[FILE_NAME_MAX_LEN + 1];
	static char	num_s[10 + 1];
	long	y;
	ask_t	ask;

	set_map_total( 0, 0, MAP_MAX_X, MAP_MAX_Y );
	wipe_all();

	/* デフォルトのファイル名を生成 */
	for( i = 0; i < max_i; i++ ){
		sn_printf( num_s, 10, STR_EXT_NAME_OUT_MAP, i );

		str_nz_cpy( fname, dir_name_game, FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_SLASH,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_DIR_NAME_OUT_MAP,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_SLASH,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_FILE_NAME_OUT_MAP,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, num_s,
				FILE_NAME_MAX_LEN );

		if( !chk_exist_file( fname ) )
			break;
	}
	if( i >= max_i )
		return NULL;

	y = 0;
	print_str( 0, y, MSG_OUT_MAP_FILE_1 );
	y++;
	print_str( 0, y, MSG_OUT_MAP_FILE_2, fname );
	y++;

	/* ファイル名を入力 */
	str_nz_cpy( s, fname, FILE_NAME_MAX_LEN );
	game_gets( -1, -1, MSG_OUT_MAP_FILE_1,
			s, FILE_NAME_MAX_LEN, TRUE );

	if( s[0] == '\0' ){
		str_nz_cpy( s, fname, FILE_NAME_MAX_LEN );
	} else if( (s[0] == '/') || (s[0] == '~') ){
		str_nz_cpy( fname, s, FILE_NAME_MAX_LEN );
	} else {
		str_nz_cpy( fname, dir_name_game, FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_SLASH,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_DIR_NAME_OUT_MAP,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, STR_SLASH,
				FILE_NAME_MAX_LEN );
		str_max_n_cat( fname, s,
				FILE_NAME_MAX_LEN );

		str_nz_cpy( s, fname, FILE_NAME_MAX_LEN );
	}

	print_str( 0, y, MSG_OUT_MAP_FILE_3, fname );
	y++;

	/* 本当に出力するか確認をとる */
	ask = exec_menu_ask( MSG_OUT_MAP_FILE_ASK_OK, ASK_NO, FALSE );

	wipe_menu();

	switch( ask ){
	case ASK_YES:
		return s;
	case ASK_NO:
	case ASK_CANCEL:
	case ASK_ERR:
		break;
	}

	return NULL;
}
Beispiel #4
0
/* ==== */
static void
wl_montecarlo(char *struc)
{
  short *pt=NULL;
  move_str m;
  int e,enew,emove,eval_me,status,debug=1;
  long int crosscheck=1000000; /* used for convergence checks */
  long int crosscheck_limit = 100000000000000000;
  double g_b1,g_b2,prob,lnf = 1.;  /* log modification parameter f */
  size_t b1,b2;                    /* indices in g/h corresponding to
				      old/new energies */
  gsl_histogram *gcp=NULL; /* clone of g used during crosscheck output */ 

  eval_me = 1; /* paranoid checking of neighbors against RNAeval */
  if (wanglandau_opt.verbose){
    printf("[[wl_montecarlo()]]\n");
  }
  pt = vrna_pt_get(struc);
  //mtw_dump_pt(pt);
  //char *str = vrna_pt_to_db(pt);
  //printf(">%s<\n",str);
  e = vrna_eval_structure_pt(wanglandau_opt.sequence,pt,P);
  
  /* determine bin where the start structure goes */
  status = gsl_histogram_find(g,(float)e/100,&b1);
  if (status) {
    if (status == GSL_EDOM){
      printf ("error: %s\n", gsl_strerror (status));
    }
    else {fprintf(stderr, "GSL error: gsl_errno=%d\n",status);}
    exit(EXIT_FAILURE);
  }
  printf("%s\n", wanglandau_opt.sequence);
  print_str(stderr,pt);
  printf(" (%6.2f) bin:%d\n",(float)e/100,b1);
  if (wanglandau_opt.verbose){
    fprintf(stderr,"\nStarting MC loop ...\n");
  }
  while (lnf > wanglandau_opt.ffinal) {
    if(wanglandau_opt.debug){
      fprintf(stderr,"\n==================\n");
      fprintf(stderr,"in while: lnf=%8.6f\n",lnf);
      fprintf(stderr,"steps: %d\n",steps);
      fprintf(stderr,"current histogram g:\n");
      gsl_histogram_fprintf(stderr,g,"%6.2f","%30.6f");
      fprintf(stderr,"\n");
      print_str(stderr,pt);
      fprintf(stderr, " (%6.2f) bin:%d\n",(float)e/100,b1);
      /*  mtw_dump_pt(pt); */
    }
    /* make a random move */
    m = get_random_move_pt(wanglandau_opt.sequence,pt);
    /* compute energy difference for this move */
    emove = vrna_eval_move_pt(pt,s0,s1,m.left,m.right,P);
    /* evaluate energy of the new structure */
    enew = e + emove;
    if(wanglandau_opt.debug){
      fprintf(stderr,
	      "random move: left %i right %i enew(%6.4f)=e(%6.4f)+emove(%6.4f)\n",
	      m.left,m.right,(float)enew/100,(float)e/100,(float)emove/100);
    }

    /* ensure the new energy is within sampling range */
    if ((float)enew/100 >= wanglandau_opt.max){
      fprintf(stderr,
	      "New structure has energy %6.2f >= %6.2f (upper energy bound)\n",
	      (float)enew/100,wanglandau_opt.max);
      fprintf(stderr,"Please increase --bins or adjust --max! Exiting ...\n");
      exit(EXIT_FAILURE);
    }
    /* determine bin where the new structure goes */
    status = gsl_histogram_find(g,(float)enew/100,&b2);
    if (status) {
      if (status == GSL_EDOM){
	printf ("error: %s\n", gsl_strerror (status));
      }
      else {fprintf(stderr, "GSL error: gsl_errno=%d\n",status);}
      exit(EXIT_FAILURE);
    }

    steps++;  /* # of MC steps performed so far */

    /* lookup current values for bins b1 and b2 */
    g_b1 = gsl_histogram_get(g,b1);
    g_b2 = gsl_histogram_get(g,b2);
      
    /* core MC steps */
    prob = MIN2(exp(g_b1 - g_b2), 1.0);
    rnum =  gsl_rng_uniform (r);
    
    if ((prob == 1 || (rnum <= prob)) ) { /* accept & apply the move */
      apply_move_pt(pt,m);
      if(wanglandau_opt.debug){
	print_str(stderr,pt);
	fprintf(stderr, " %6.2f bin:%d [A]\n", (float)enew/100,b2);
      }
      b1 = b2;
      e = enew;
    }
    else { /* reject the move */
      if(wanglandau_opt.debug){
	print_str(stderr,pt);
	fprintf(stderr, " (%6.2f) bin:%d [R]\n", (float)enew/100,b2);
       }
    }
    
    /* update histograms g and h */
    if(wanglandau_opt.truedosbins_given && b2 <= wanglandau_opt.truedosbins){
      /* do not update if b2 <= truedosbins, i.e. keep true DOS values
	 in those bins */
      if (wanglandau_opt.debug){
	fprintf(stderr, "NOT UPDATING bin %d\n",b1);
      }
    } else{
      if(wanglandau_opt.debug){
	fprintf(stderr, "UPDATING bin %d\n",b1); 
      }
      status = gsl_histogram_increment(h,(float)e/100);
      status = gsl_histogram_accumulate(g,(float)e/100,lnf);
    }
    maxbin = MAX2(maxbin,(int)b1);
   
    // stuff that can be skipped 
    /*
      printf ("performed move l:%4d r:%4d\t Energy +/- %6.2f\n",m.left,m.right,(float)emove/100);
      print_str(stderr,pt);printf(" %6.2f bin:%d\n",(float)enew/100,b2);
      e = vrna_eval_structure_pt(wanglandau_opt.sequence,pt,P);
      if (eval_me == 1 && e != enew){
      fprintf(stderr, "energy evaluation against vrna_eval_structure_pt() mismatch... HAVE %6.2f != %6.2f (SHOULD BE)\n",(float)enew/100, (float)e/100);
      exit(EXIT_FAILURE);
      }
      print_str(stderr,pt);printf(" %6.2f\n",(float)e/100);
    */
    // end of stuff that can be skipped

    /* output DoS every x*10^(1/4) steps, starting with x=10^6 (we
       used this fopr comparing perfomance and convergence of
       different DoS sampling methods */
    if((steps % crosscheck == 0) && (crosscheck <= crosscheck_limit)){
      fprintf(stderr,"# crosscheck reached %li steps ",crosscheck);
      gcp = gsl_histogram_clone(g);
      if(wanglandau_opt.verbose){
	fprintf(stderr,"## gcp before scaling\n");
	gsl_histogram_fprintf(stderr,gcp,"%6.2f","%30.6f");
      }
      scale_dos(gcp); /* scale estimated g; make ln(g[0])=0 */
      if(wanglandau_opt.verbose){
	fprintf(stderr,"## gcp after scaling\n");
	gsl_histogram_fprintf(stderr,gcp,"%6.2f","%30.6f");
      }
      double Z = partition_function(gcp);
      output_dos(gcp,'s');
      fprintf(stderr, "Z=%10.4g\n", Z);
      crosscheck *= (pow(10, 1.0/4.0));
      gsl_histogram_free(gcp);
      fprintf(stderr,"->  new crosscheck will be performed at %li steps\n", crosscheck);
    }
    
    if(steps % wanglandau_opt.checksteps == 0) {
      if( histogram_is_flat(h) ) {
	lnf /= 2;
	fprintf(stderr,"# steps=%20li | f=%12g | histogram is FLAT\n",
		steps,lnf);
	gsl_histogram_reset(h);
      }
      else {
	fprintf(stderr, "# steps=%20li | f=%12g | histogram is NOT FLAT\n",
		steps,lnf);
      }
      output_dos(g,'l');
    }
    
    /* stop criterion */
    if(steps % wanglandau_opt.steplimit == 0){
      fprintf(stderr,"maximun number of MC steps (%li) reached, exiting ...",
	      wanglandau_opt.steplimit);
      break;
    }

  } /* end while */
  free(pt); 
  return;
}
Beispiel #5
0
static int print_hex(FILE * stream, int num) {
	return print_str(stream, (char *)itoa(num, 16));
} 
Beispiel #6
0
int
parse_args_n (int argc, char **argv, _gg_opt fref_t[], char ***la,
	      uint32_t flags)
{
  argv++;

  int carg = 1;
  while (argv[0])
    {
      char *p_iseq = strchr (argv[0], 0x3D);
      void *arg;
      int m;

      if ( NULL == p_iseq)
	{
	  p_iseq = argv[0];
	  m = 0;
	  arg = (void*) &argv[1];
	}
      else
	{
	  p_iseq++;
	  m = 2;
	  arg = (void*) p_iseq;
	}

      __gg_opt pe_opt = proc_option (p_iseq);

      if (pe_opt)
	{
	  int ret;
	  if (pe_opt->ac > 0)
	    {
	      if (carg + pe_opt->ac == argc)
		{
		  print_str ("ERROR: insufficient arguments (%s), need %d\n",
			     p_iseq, pe_opt->ac);
		  return -1;
		}

	      ret = pe_opt->op (arg, m, NULL);

	      argv += pe_opt->ac;
	      carg += pe_opt->ac;

	    }
	  else
	    {
	      ret = pe_opt->op (arg, m, NULL);
	    }

	  if (ret > 0)
	    {
	      print_str ("ERROR: [%d] '%s': bad option argument\n", ret,
			 argv[1]);

	      if (!(flags & F_PARSE_ARG_IGNORE_ERRORS))
		{

		  return -1;
		}
	    }

	}
      else
	{
	  if (!(flags & F_PARSE_ARG_SILENT))
	    {
	      print_str ("ERROR: invalid option '%s'\n", argv[0]);
	    }
	  if (!(flags & F_PARSE_ARG_IGNORE_NOT_FOUND))
	    {
	      return -2;
	    }
	}

      argv++;
      carg++;
    }

  return 0;
}
Beispiel #7
0
void			print_nbrbase10l(int nb, int fildes, enum e_priority p)
{
	print_nbrbase10(nb, fildes, p);
	print_str("\n", fildes, p);
	return ;
}
Beispiel #8
0
int printk(const char *fmt, ...)
{
	//上一次遍历到的字符是不是%,normal表示不是%,fmt表示是%。该标记决定了当前遍历到的字符是格式符还是正常字符
	enum {
		NORMAL, //非'%'
		FMT, //'%'
	} FMT_FLG;

	int count = 0; //统计最终打印的字符数量
	int cur_count = 0;

	FMT_FLG = NORMAL;

	va_list ap;
	va_start(ap, fmt);

	for (; *fmt; ++fmt) {
		switch (*fmt) {
		case '%':
			if (FMT_FLG == NORMAL) {
				FMT_FLG = FMT;
			} else { //连续两个%
				print_ch(*fmt);
				++count;
				FMT_FLG = NORMAL;
			}
			break;
		case 'c':
			//排除普通的字符
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
			} else {
				print_ch((char)va_arg(ap, int));
				FMT_FLG = NORMAL;
			}
			++count;
			break;
		case 's':
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				char *str = va_arg(ap, char*);
				print_str(str);
				for (; *str; str++) {
					++count;
				}
				FMT_FLG = NORMAL;
			}
			break;
		case 'd':
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				cur_count = itoa(va_arg(ap, int), 10, SIGNED);
				count += cur_count;
				FMT_FLG = NORMAL;
			}
			break;
		case 'u':
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				cur_count = itoa(va_arg(ap, int), 10, UNSIGNED);
				count += cur_count;
				FMT_FLG = NORMAL;
			}
			break;
		case 'b':
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				cur_count = itoa(va_arg(ap, int), 2, UNSIGNED);
				count += cur_count;
				FMT_FLG = NORMAL;
			}
			break;
		case 'x':
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				cur_count = itoa(va_arg(ap, int), 16, UNSIGNED);
				count += cur_count;
				FMT_FLG = NORMAL;
			}
			break;
		default:
			if (FMT_FLG == NORMAL) {
				print_ch(*fmt);
				++count;
			} else {
				FMT_FLG = NORMAL;
			}
			break;
		}
	}

	va_end(ap);

	return count;
}
Beispiel #9
0
/*
 * Print the individual types if verbose mode was specified.
 * If verbose-verbose then print types along with respective values.
 */
static void
print_attr(kdbe_val_t *val, int vverbose)
{
    switch (val->av_type) {
    case AT_ATTRFLAGS:
        (void) printf(_("\t\tAttribute flags\n"));
        if (vverbose) {
            print_flags(val->kdbe_val_t_u.av_attrflags);
        }
        break;
    case AT_MAX_LIFE:
        (void) printf(_("\t\tMaximum ticket life\n"));
        if (vverbose) {
            print_deltat(&val->kdbe_val_t_u.av_max_life);
        }
        break;
    case AT_MAX_RENEW_LIFE:
        (void) printf(_("\t\tMaximum renewable life\n"));
        if (vverbose) {
            print_deltat(&val->kdbe_val_t_u.av_max_renew_life);
        }
        break;
    case AT_EXP:
        (void) printf(_("\t\tPrincipal expiration\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_exp);
        }
        break;
    case AT_PW_EXP:
        (void) printf(_("\t\tPassword expiration\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_pw_exp);
        }
        break;
    case AT_LAST_SUCCESS:
        (void) printf(_("\t\tLast successful auth\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_last_success);
        }
        break;
    case AT_LAST_FAILED:
        (void) printf(_("\t\tLast failed auth\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_last_failed);
        }
        break;
    case AT_FAIL_AUTH_COUNT:
        (void) printf(_("\t\tFailed passwd attempt\n"));
        if (vverbose) {
            (void) printf("\t\t\t%d\n",
                          val->kdbe_val_t_u.av_fail_auth_count);
        }
        break;
    case AT_PRINC:
        (void) printf(_("\t\tPrincipal\n"));
        if (vverbose) {
            print_princ(&val->kdbe_val_t_u.av_princ);
        }
        break;
    case AT_KEYDATA:
        (void) printf(_("\t\tKey data\n"));
        if (vverbose) {
            print_keydata(
                val->kdbe_val_t_u.av_keydata.av_keydata_val,
                val->kdbe_val_t_u.av_keydata.av_keydata_len);
        }
        break;
    case AT_TL_DATA:
        (void) printf(_("\t\tTL data\n"));
        if (vverbose) {
            print_tldata(
                val->kdbe_val_t_u.av_tldata.av_tldata_val,
                val->kdbe_val_t_u.av_tldata.av_tldata_len);
        }
        break;
    case AT_LEN:
        (void) printf(_("\t\tLength\n"));
        if (vverbose) {
            (void) printf("\t\t\t%d\n",
                          val->kdbe_val_t_u.av_len);
        }
        break;
    case AT_PW_LAST_CHANGE:
        (void) printf(_("\t\tPassword last changed\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_pw_last_change);
        }
        break;
    case AT_MOD_PRINC:
        (void) printf(_("\t\tModifying principal\n"));
        if (vverbose) {
            print_princ(&val->kdbe_val_t_u.av_mod_princ);
        }
        break;
    case AT_MOD_TIME:
        (void) printf(_("\t\tModification time\n"));
        if (vverbose) {
            print_time(&val->kdbe_val_t_u.av_mod_time);
        }
        break;
    case AT_MOD_WHERE:
        (void) printf(_("\t\tModified where\n"));
        if (vverbose) {
            print_str("where",
                      &val->kdbe_val_t_u.av_mod_where);
        }
        break;
    case AT_PW_POLICY:
        (void) printf(_("\t\tPassword policy\n"));
        if (vverbose) {
            print_str("policy",
                      &val->kdbe_val_t_u.av_pw_policy);
        }
        break;
    case AT_PW_POLICY_SWITCH:
        (void) printf(_("\t\tPassword policy switch\n"));
        if (vverbose) {
            (void) printf("\t\t\t%d\n",
                          val->kdbe_val_t_u.av_pw_policy_switch);
        }
        break;
    case AT_PW_HIST_KVNO:
        (void) printf(_("\t\tPassword history KVNO\n"));
        if (vverbose) {
            (void) printf("\t\t\t%d\n",
                          val->kdbe_val_t_u.av_pw_hist_kvno);
        }
        break;
    case AT_PW_HIST:
        (void) printf(_("\t\tPassword history\n"));
        if (vverbose) {
            (void) printf("\t\t\tPW history elided\n");
        }
        break;
    } /* switch */

}
Beispiel #10
0
void printf(const char *fmt, ...)
{
    va_list ap;
    uint64_t val;
    char *str;
    int base;
    int has_long;
    int alt_form;

    va_start(ap, fmt);

    for (; *fmt; fmt++) {
        if (*fmt != '%') {
            print_char(*fmt);
            continue;
        }
        fmt++;

        if (*fmt == '#') {
            fmt++;
            alt_form = 1;
        } else {
            alt_form = 0;
        }

        if (*fmt == 'l') {
            fmt++;
            if (*fmt == 'l') {
                fmt++;
                has_long = 2;
            } else {
                has_long = 1;
            }
        } else {
            has_long = 0;
        }

        switch (*fmt) {
        case 'x':
        case 'p':
            base = 16;
            goto convert_number;
        case 'd':
        case 'i':
        case 'u':
            base = 10;
            goto convert_number;
        case 'o':
            base = 8;
            goto convert_number;

        convert_number:
            switch (has_long) {
            case 0:
                val = va_arg(ap, unsigned int);
                break;
            case 1:
                val = va_arg(ap, unsigned long);
                break;
            case 2:
                val = va_arg(ap, unsigned long long);
                break;
            }

            if (alt_form && base == 16) {
                print_str("0x");
            }

            print_num(val, base);
            break;

        case 's':
            str = va_arg(ap, char*);
            print_str(str);
            break;
        case '%':
            print_char(*fmt);
            break;
        default:
            print_char('%');
            print_char(*fmt);
            break;
        }
    }

    va_end(ap);
}
Beispiel #11
0
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	bd_t *bd = gd->bd;
	char buf[32];

#ifdef DEBUG
	print_num ("bd address",    (ulong)bd		);
#endif
	print_num ("memstart",	    bd->bi_memstart	);
	print_lnum ("memsize", 	    bd->bi_memsize	);
	print_num ("flashstart",    bd->bi_flashstart	);
	print_num ("flashsize",	    bd->bi_flashsize	);
	print_num ("flashoffset",   bd->bi_flashoffset	);
	print_num ("sramstart",	    bd->bi_sramstart	);
	print_num ("sramsize",	    bd->bi_sramsize	);
#if defined(CONFIG_5xx)  || defined(CONFIG_8xx) || \
    defined(CONFIG_8260) || defined(CONFIG_E500)
	print_num ("immr_base",	    bd->bi_immr_base	);
#endif
	print_num ("bootflags",	    bd->bi_bootflags	);
#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
    defined(CONFIG_405EP) || defined(CONFIG_XILINX_405) || \
    defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
    defined(CONFIG_440EPX) || defined(CONFIG_440GRX) ||	\
    defined(CONFIG_440SP) || defined(CONFIG_440SPE)
	print_str ("procfreq",	    strmhz(buf, bd->bi_procfreq));
	print_str ("plb_busfreq",   strmhz(buf, bd->bi_plb_busfreq));
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || defined(CONFIG_XILINX_405) || \
    defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SPE) || \
    defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
	print_str ("pci_busfreq",   strmhz(buf, bd->bi_pci_busfreq));
#endif
#else	/* ! CONFIG_405GP, CONFIG_405CR, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
#if defined(CONFIG_CPM2)
	print_str ("vco",	    strmhz(buf, bd->bi_vco));
	print_str ("sccfreq",	    strmhz(buf, bd->bi_sccfreq));
	print_str ("brgfreq",	    strmhz(buf, bd->bi_brgfreq));
#endif
	print_str ("intfreq",	    strmhz(buf, bd->bi_intfreq));
#if defined(CONFIG_CPM2)
	print_str ("cpmfreq",	    strmhz(buf, bd->bi_cpmfreq));
#endif
	print_str ("busfreq",	    strmhz(buf, bd->bi_busfreq));
#endif /* CONFIG_405GP, CONFIG_405CR, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */
#if defined(CONFIG_MPC8220)
	print_str ("inpfreq",	    strmhz(buf, bd->bi_inpfreq));
	print_str ("flbfreq",	    strmhz(buf, bd->bi_flbfreq));
	print_str ("pcifreq",	    strmhz(buf, bd->bi_pcifreq));
	print_str ("vcofreq",	    strmhz(buf, bd->bi_vcofreq));
	print_str ("pevfreq",	    strmhz(buf, bd->bi_pevfreq));
#endif

	print_eth(0);
#if defined(CONFIG_HAS_ETH1)
	print_eth(1);
#endif
#if defined(CONFIG_HAS_ETH2)
	print_eth(2);
#endif
#if defined(CONFIG_HAS_ETH3)
	print_eth(3);
#endif
#if defined(CONFIG_HAS_ETH4)
	print_eth(4);
#endif
#if defined(CONFIG_HAS_ETH5)
	print_eth(5);
#endif

#ifdef CONFIG_HERMES
	print_str ("ethspeed",	    strmhz(buf, bd->bi_ethspeed));
#endif
	printf ("IP addr     = %pI4\n", &bd->bi_ip_addr);
	printf ("baudrate    = %6ld bps\n", bd->bi_baudrate   );
	print_num ("relocaddr", gd->relocaddr);
	return 0;
}
Beispiel #12
0
void main()
{ 
	set_to_42(&x);
	print_int(x);
	print_str("\n");
}
Beispiel #13
0
void handle_user_int(u32 index)
{
	print_str("user int\n");
}
Beispiel #14
0
/* move to deepest (or first) neighbour*/
PRIVATE int
move_set(Encoded *Enc, struct_en *str){

  /* count better neighbours*/
  int cnt = 0;

  /* deepest descent*/
  struct_en min;
  min.structure = allocopy(str->structure);
  min.energy = str->energy;
  Enc->current_en = str->energy;

  if (Enc->verbose_lvl>0) { fprintf(stderr, "  start of MS:\n  "); print_str(stderr, str->structure); fprintf(stderr, " %d\n\n", str->energy); }

  /* if using first dont do all of them*/
  bool end = false;
  /* insertions*/
  if (!end) cnt += insertions(Enc, str, &min);
  if (Enc->first && cnt>0) end = true;
  if (Enc->verbose_lvl>1) fprintf(stderr, "\n");

  /* deletions*/
  if (!end) cnt += deletions(Enc, str, &min);
  if (Enc->first && cnt>0) end = true;

  /* shifts (only if enabled + noLP disabled)*/
  if (!end && Enc->shift && !Enc->noLP) {
    cnt += shifts(Enc, str, &min);
    if (Enc->first && cnt>0) end = true;
  }

  /* if degeneracy occurs, solve it!*/
  if (deal_deg && !end && (Enc->end_unpr - Enc->begin_unpr)>0) {
    Enc->processed[Enc->end_pr] = str->structure;
    Enc->end_pr++;
    str->structure = Enc->unprocessed[Enc->begin_unpr];
    Enc->unprocessed[Enc->begin_unpr]=NULL;
    Enc->begin_unpr++;
    cnt += move_set(Enc, str);
  } else {
    /* write output to str*/
    copy_arr(str->structure, min.structure);
    str->energy = min.energy;
  }
  /* release minimal*/
  free(min.structure);

  /* resolve degeneracy in local minima*/
  if (deal_deg && (Enc->end_pr - Enc->begin_pr)>0) {
    Enc->processed[Enc->end_pr]=str->structure;
    Enc->end_pr++;

    int min = find_min(Enc->processed, Enc->begin_pr, Enc->end_pr);
    short *tmp = Enc->processed[min];
    Enc->processed[min] = Enc->processed[Enc->begin_pr];
    Enc->processed[Enc->begin_pr] = tmp;
    str->structure = Enc->processed[Enc->begin_pr];
    Enc->begin_pr++;
    free_degen(Enc);
  }

  if (Enc->verbose_lvl>1 && !(Enc->first)) { fprintf(stderr, "\n  end of MS:\n  "); print_str(stderr, str->structure); fprintf(stderr, " %d\n\n", str->energy); }

  return cnt;
}
unsigned char menu_input(unsigned char cmd)
{
	static unsigned char state = 'q';
	static unsigned char substate = 0;
	static unsigned char input_idx=0;
	static unsigned char cyl_counter =0;
	unsigned int tmpi = 0;
	float tmpf = 0;

	unsigned char i = 0;
	static unsigned char subst = 0;
	
	//just dump the menu if we're at the top level
	//and user hit enter
	if(state == 'q' || state == 'm' )
	{
	switch( cmd )
		{	
			//set rpm points for knock table
			case 'r':	state = 'r'; cyl_counter = 0; substate = 0; break;
			//set voltage points for knock table
			//will be dumped to eeprom when done
			case 'v':	state = 'v'; cyl_counter = 0; substate = 0; break;
			//get the current engine settings
			case 'g':	state = 'g'; break;
			//configure the engine settings 
			//will be dumped to eeprom when done
			case 'c':	state = 'c'; break;
			//dump the status of internal variables
			case 'd':	state = 'd'; break;
			//if we get a 'q' shut down the menu
			case 'q':  return 0;
			//set the state to main menu
			default:	state = 'm'; print_main_menu(); break;
		}

	return 1;
	}
	else
	{

		switch(state)
		{
		
			case 'g':
			dump_config();
			newline();
			print_main_menu();
			state = 'm';
			break;

			case 'd':
			dump_variables();
			newline();
			print_main_menu();
			state = 'm';
			break;

			case 'r':
			switch(substate)
			{
				case 0:
				newline();
				snprintf_P(output, OUTPUT_LEN, cylinder_prompt, cfg.firing_order[cyl_counter]);
				print_str(output);
				substate++;
				input_idx = 0;
				break;

				case 1:
				//set value from substate 0 query
				//if \r\n our work here is done
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{

						output[input_idx] = '\0';
						subst = 0;
						input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
						{
								if(output[i] == ',')
								{
									output[i] = '\0';
									//this is actually stored in timer ticks to avoid division in code
									//introduces +/- 8 rpm error around 10k rpm
									cfg.rpm_points[cyl_counter][input_idx++] = (TICKS_PER_MIN / atoi( (output+subst) ) );
									subst = i+1;
								}	
	
						}
						cfg.rpm_points[cyl_counter][input_idx] = (TICKS_PER_MIN / atoi( (output+subst) ) );
					} 
					if(++cyl_counter == cfg.num_cyls )
					{
						print_str_P(table_layout);
						for(i = 0; i < cfg.num_cyls; i++)
						{
							calculate_fslopes(i);
							newline();
							newline();
							snprintf_P(output, OUTPUT_LEN, table_header, cfg.firing_order[i]);
							print_str(output);
							newline();
							dump_rpm_table(i);
							newline();
							dump_voltage_table(i);
							newline();
							dump_fslopes(i);
						}
						print_str_P(prompt);
						substate++;
						input_idx = 0;
					}
					else
					{
						newline();
						input_idx = 0;
						snprintf_P(output, OUTPUT_LEN, cylinder_prompt, cfg.firing_order[cyl_counter]);
						print_str(output);
					}
				}
				else if( input_idx < OUTPUT_LEN -1  && (isdigit(cmd) || cmd == ',' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;

				break;

				case 2:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else
				{ 
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate =0; input_idx = 0; cyl_counter = 0; break;
			}	
			break;
		

			case 'v':
			switch(substate)
			{
				case 0:
				newline();
				snprintf_P(output, OUTPUT_LEN, voltage_prompt , cfg.firing_order[cyl_counter]);
				print_str(output);
				substate++;
				break;
				
				
				case 1:
				//set value from substate 0 query
				//if \n our work here is done
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						subst = 0;
						input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
						{
								if(output[i] == ',')
								{
									output[i] = '\0';
									cfg.knock_voltage[cyl_counter][input_idx++] = (unsigned int ) (atof((output+subst)) /TEN_BIT_LSB) ;
									subst = i+1;
								}	
						} 
							cfg.knock_voltage[cyl_counter][input_idx] = (unsigned int ) (atof((output+subst)) /TEN_BIT_LSB) ;
					}
					if(++cyl_counter == cfg.num_cyls)
					{
						print_str_P(table_layout);
						for(i = 0; i < cfg.num_cyls; i++)
						{
							calculate_fslopes(i);
							newline();
							newline();
							snprintf_P(output, OUTPUT_LEN, table_header, cfg.firing_order[i]);
							print_str(output);
							newline();
							dump_rpm_table(i);
							newline();
							dump_voltage_table(i);
							newline();
							dump_fslopes(i);
						}
						print_str_P(prompt);
						substate++;
						input_idx = 0;
					}
					else
					{
						newline();
						snprintf_P(output, OUTPUT_LEN, voltage_prompt, cfg.firing_order[cyl_counter]);
						print_str(output);
						input_idx = 0;
					}
				}
				else if( input_idx < OUTPUT_LEN -1  && (isdigit(cmd) || cmd == ','|| cmd == '.' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;

				
				break;

				case 2:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else 
				{
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate = 0; input_idx = 0; cyl_counter = 0; break;					

			}	
			break;

			case 'c':
			switch(substate)
			{
				case 0:
				newline();
				print_str_P(dump_cfg[substate++] );
				break;

				case 1:
				if(cmd == '\n' || cmd == '\r')
				{   
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.num_cyls = (unsigned char)atoi(output);
                        			input_idx=0;    
                    			}   
					newline();
					print_str_P(dump_cfg[substate++]);
				}
               			else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
               			 	output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 2:
                                if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.window_length_deg = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 3:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.window_open_deg_atdc = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 4:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.mech_advance_deg_btdc = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 5:
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
					cfg.window_integ_div = (unsigned char)atoi(output);
       		             		input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                			output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                		break;


				case 6:
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
					tmpi = (unsigned int)atoi(output);
					//search for the next largest bandpass frequenc and 
					//set the index of the current center frequency in the cfg section
					for(i = 0; i < NUM_BANDPASS_FREQS && pgm_read_word(&bandpass_freq_value[i]) < tmpi ; i++);
					cfg.tpic_freq = i;
					input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN	&& isdigit(cmd) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 7:
				if(cmd == '\n' || cmd == '\r' )
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						tmpf = (float)atof(output);
						//search for the next smallest gain
						//set the index of the gain in the cfg section
						for(i = 0; i < NUM_GAIN && pgm_read_float(&gain_value[i]) > tmpf ; i++);
						cfg.tpic_gain = i;
						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN && (isdigit(cmd) || cmd == '.' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 8:
				if(cmd == '\n' || cmd == '\r')
				{	
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						subst = 0;
					input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
					{
							if(output[i] == ',')
						{
								output[i] = '\0';
								cfg.firing_order[input_idx++] = atoi( (output+subst) );
								subst = i+1;
						}

					}
						cfg.firing_order[input_idx] = atoi( (output+subst) );
                    			input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN  && (isdigit(cmd) || cmd == ',' ) )
                			output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
              			break;
				case 9:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.datalog_frequency = MAX_DATALOGS_PER_SEC/(unsigned char)atoi(output);
										if(cfg.datalog_frequency < 2)
											cfg.datalog_frequency = 1;
										else
											cfg.datalog_frequency--;
                                        input_idx=0;
	                                }
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 10:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.datalog_header_count = (unsigned char)atoi(output);

						if(cfg.datalog_header_count == 0)
							cfg.datalog_header_count = 1;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 11:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.wheelmode = (unsigned char)atoi(output);
						if(cfg.wheelmode != HEP && cfg.wheelmode != FOURTWENTYA )
							cfg.wheelmode = 0;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 12:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.tpic_chan = ( (unsigned char)atoi(output) -1 );
						if(cfg.tpic_chan != 1 )
							cfg.tpic_chan = 0;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 13:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                        cfg.datalogmode = ( (unsigned char)atoi(output)  );
						if( cfg.datalogmode )
							cfg.datalogmode = 1;

                        input_idx=0;
                    }
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
				break;

				case 14:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						strncpy(cfg.seperator, output, MAX_SEP_LEN-1);
						cfg.seperator[MAX_SEP_LEN - 1] = '\0';
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 15:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_events = (unsigned char) atoi(output);
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 16:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_tenms = (unsigned char) atoi(output);
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 17:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_timer_select = (unsigned char) atoi(output);
						if(cfg.pulse_timer_select)
							cfg.pulse_timer_select = 1;
 						input_idx=0;
					}
					print_str_P(config_done);
					dump_config();
					print_str_P(prompt);
					newline();
					substate++;
				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;



				case 18:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else
				{
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate = 0; input_idx = 0; cyl_counter = 0; break;					

			}//switch(substate)
			
		}//switch(state)

	}//else
return 1;
}//void menu_input()
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int i;
	bd_t *bd = gd->bd;
	char buf[32];

	print_num ("memstart",		(ulong)bd->bi_memstart);
	print_num ("memsize",		(ulong)bd->bi_memsize);
	print_num ("flashstart",	(ulong)bd->bi_flashstart);
	print_num ("flashsize",		(ulong)bd->bi_flashsize);
	print_num ("flashoffset",	(ulong)bd->bi_flashoffset);
#if defined(CFG_INIT_RAM_ADDR)
	print_num ("sramstart",		(ulong)bd->bi_sramstart);
	print_num ("sramsize",		(ulong)bd->bi_sramsize);
#endif
#if defined(CFG_MBAR)
	print_num ("mbar",		bd->bi_mbar_base);
#endif
	print_str ("busfreq",		strmhz(buf, bd->bi_busfreq));
#ifdef CONFIG_PCI
	print_str ("pcifreq",		strmhz(buf, bd->bi_pcifreq));
#endif
#ifdef CONFIG_EXTRA_CLOCK
	print_str ("flbfreq",		strmhz(buf, bd->bi_flbfreq));
	print_str ("inpfreq",		strmhz(buf, bd->bi_inpfreq));
	print_str ("vcofreq",		strmhz(buf, bd->bi_vcofreq));
#endif
#if defined(CONFIG_CMD_NET)
	puts ("ethaddr     =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
	}

#if defined(CONFIG_HAS_ETH1)
	puts ("\neth1addr    =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]);
	}
#endif

#if defined(CONFIG_HAS_ETH2)
	puts ("\neth2addr    =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]);
	}
#endif

#if defined(CONFIG_HAS_ETH3)
	puts ("\neth3addr    =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]);
	}
#endif

	puts ("\nip_addr     = ");
	print_IPaddr (bd->bi_ip_addr);
#endif
	printf ("\nbaudrate    = %d bps\n", bd->bi_baudrate);

	return 0;
}
void seperator()
{
		print_str(cfg.seperator);
}
Beispiel #18
0
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	DECLARE_GLOBAL_DATA_PTR;

	int i;
	bd_t *bd = gd->bd;
	char buf[32];

#ifdef DEBUG
	print_num ("bd address",    (ulong)bd		);
#endif
	print_num ("memstart",	    bd->bi_memstart	);
	print_num ("memsize",	    bd->bi_memsize	);
	print_num ("flashstart",    bd->bi_flashstart	);
	print_num ("flashsize",	    bd->bi_flashsize	);
	print_num ("flashoffset",   bd->bi_flashoffset	);
	print_num ("sramstart",	    bd->bi_sramstart	);
	print_num ("sramsize",	    bd->bi_sramsize	);
#if defined(CONFIG_5xx)  || defined(CONFIG_8xx) || \
    defined(CONFIG_8260) || defined(CONFIG_E500)
	print_num ("immr_base",	    bd->bi_immr_base	);
#endif
	print_num ("bootflags",	    bd->bi_bootflags	);
#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
    defined(CONFIG_405EP) || defined(CONFIG_XILINX_ML300)
	print_str ("procfreq",	    strmhz(buf, bd->bi_procfreq));
	print_str ("plb_busfreq",   strmhz(buf, bd->bi_plb_busfreq));
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || defined(CONFIG_XILINX_ML300)
	print_str ("pci_busfreq",   strmhz(buf, bd->bi_pci_busfreq));
#endif
#else	/* ! CONFIG_405GP, CONFIG_405CR, CONFIG_405EP, CONFIG_XILINX_ML300 */
#if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
	print_str ("vco",	    strmhz(buf, bd->bi_vco));
	print_str ("sccfreq",	    strmhz(buf, bd->bi_sccfreq));
	print_str ("brgfreq",	    strmhz(buf, bd->bi_brgfreq));
#endif
	print_str ("intfreq",	    strmhz(buf, bd->bi_intfreq));
#if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
	print_str ("cpmfreq",	    strmhz(buf, bd->bi_cpmfreq));
#endif
	print_str ("busfreq",	    strmhz(buf, bd->bi_busfreq));
#endif /* CONFIG_405GP, CONFIG_405CR, CONFIG_405EP, CONFIG_XILINX_ML300 */
#if defined(CONFIG_MPC8220)
	print_str ("inpfreq",	    strmhz(buf, bd->bi_inpfreq));
	print_str ("flbfreq",	    strmhz(buf, bd->bi_flbfreq));
	print_str ("pcifreq",	    strmhz(buf, bd->bi_pcifreq));
	print_str ("vcofreq",	    strmhz(buf, bd->bi_vcofreq));
	print_str ("pevfreq",	    strmhz(buf, bd->bi_pevfreq));
#endif

	puts ("ethaddr     =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
	}

#if defined(CONFIG_HAS_ETH1)
	puts ("\neth1addr    =");
	for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]);
	}
#endif

#if defined(CONFIG_HAS_ETH2)
       puts ("\neth2addr    =");
       for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]);
	}
#endif

#if defined(CONFIG_HAS_ETH3)
       puts ("\neth3addr    =");
       for (i=0; i<6; ++i) {
		printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]);
	}
#endif

#ifdef CONFIG_HERMES
	print_str ("ethspeed",	    strmhz(buf, bd->bi_ethspeed));
#endif
	puts ("\nIP addr     = ");	print_IPaddr (bd->bi_ip_addr);
	printf ("\nbaudrate    = %6ld bps\n", bd->bi_baudrate   );
	return 0;
}
Beispiel #19
0
int
parse_args (int argc, char **argv, _gg_opt fref_t[], char ***la, uint32_t flags)
{
  g_setjmp (0, "parse_args", NULL, NULL);
  int vi, ret, c = 0;

  if (ar_vref.count)
    {
      md_free (&ar_vref);
    }

  md_init (&ar_vref, 8);

  int i;

  char *c_arg = NULL;
  char **c_argv = NULL;

  __gg_opt ora = (__gg_opt) fref_t;

  _g_vop vop =
    { 0 };

  for (i = 1, ret = 0, vi = -1; i < argc; i++, vi = -1)
    {
      c_arg = argv[i];
      c_argv = &argv[i];

      char *p_iseq = strchr (c_arg, 0x3D);

      if (p_iseq)
	{
	  char bp_opt[64];
	  size_t p_isl = p_iseq - c_arg;
	  p_isl > 63 ? p_isl = 63 : 0;
	  strncpy (bp_opt, c_arg, p_isl);
	  bp_opt[p_isl] = 0x0;
	  p_iseq++;

	  ret = process_opt_n (bp_opt, p_iseq, fref_t, 2, &vi, (void*) &vop);
	}
      else
	{
	  ret = process_opt_n (c_arg, (char*) &argv[i + 1], fref_t, 0, &vi,
			       (void*) &vop);
	}

      ar_check_ttl_expired (&ar_vref);
      ar_mod_ttl (&ar_vref, -1);

      if (ret == -2)
	{
	  if (flags & F_PARSE_ARG_IGNORE_NOT_FOUND)
	    {
	      continue;
	    }
	}
      if (0 != ret)
	{
	  if (!(flags & F_PARSE_ARG_SILENT))
	    {
	      if (ret == -2)
		{
		  print_str ("ERROR: [%d] invalid option '%s'\n", ret, c_arg);
		}
	      else if (ret == -4)
		{
		  print_str (
		      "ERROR: [%d] CRITICAL: improperly configured option ref table, report this! [ '%s' ]\n",
		      ret, c_arg);
		  abort();
		}
	      else if (ret > 0)
		{
		  print_str ("ERROR: [%d] '%s': bad option argument\n", ret,
			     c_arg);
		}

	    }
	  if (!(flags & F_PARSE_ARG_IGNORE_ERRORS))
	    {
	      c = -2;
	      break;
	    }
	}
      else
	{
	  c++;
	}

      if (NULL == p_iseq && vi > -1)
	{
	  uint8_t ac = ora[vi].ac;
	  if (0 != vop.ac_s)
	    {
	      ac += vop.ac_s;
	      vop.ac_s = 0;
	    }
	  i += (int) ac;
	}
    }

  if (!(flags & F_PARSE_ARG_IGNORE_ERRORS) && !c)
    {
      return -1;
    }

  if ( NULL != la)
    {
      *la = (char**) c_argv;
    }

  return ret;
}
Beispiel #20
0
int getone()
{
	print_str("getone() got executed -- ");
	return 1;
}
Beispiel #21
0
static int
print_format(char **buffer, size_t bufsize, const char *format, void *var)
{
	char *start;
	unsigned int i = 0, length_mod = sizeof(int);
	unsigned long value = 0;
	unsigned long signBit;
	char *form, sizec[32];
	char sign = ' ';
	bool upper = false;

	form  = (char *) format;
	start = *buffer;

	form++;
	if(*form == '0' || *form == '.') {
		sign = '0';
		form++;
	}

	while ((*form != '\0') && ((*buffer - start) < bufsize)) {
		switch(*form) {
			case 'u':
			case 'd':
			case 'i':
				sizec[i] = '\0';
				value = (unsigned long) var;
				signBit = 0x1ULL << (length_mod * 8 - 1);
				if ((*form != 'u') && (signBit & value)) {
					**buffer = '-';
					*buffer += 1;
					value = (-(unsigned long)value) & convert[length_mod];
				}
				print_fill(buffer, bufsize - (*buffer - start),
						sizec, value, 10, sign, 0);
				print_itoa(buffer, bufsize - (*buffer - start),
							value, 10, upper);
				break;
			case 'X':
				upper = true;
			case 'x':
				sizec[i] = '\0';
				value = (unsigned long) var & convert[length_mod];
				print_fill(buffer, bufsize - (*buffer - start),
						sizec, value, 16, sign, 0);
				print_itoa(buffer, bufsize - (*buffer - start),
							value, 16, upper);
				break;
			case 'O':
			case 'o':
				sizec[i] = '\0';
				value = (long int) var & convert[length_mod];
				print_fill(buffer, bufsize - (*buffer - start),
						sizec, value, 8, sign, 0);
				print_itoa(buffer, bufsize - (*buffer - start),
							value, 8, upper);
				break;
			case 'p':
				sizec[i] = '\0';
				print_fill(buffer, bufsize - (*buffer - start),
					sizec, (unsigned long) var, 16, ' ', 2);
				print_str(buffer, bufsize - (*buffer - start),
									"0x");
				print_itoa(buffer, bufsize - (*buffer - start),
						(unsigned long) var, 16, upper);
				break;
			case 'c':
				sizec[i] = '\0';
				print_fill(buffer, bufsize - (*buffer - start),
							sizec, 1, 10, ' ', 0);
				**buffer = (unsigned long) var;
				*buffer += 1;
				break;
			case 's':
				sizec[i] = '\0';
				print_str_fill(buffer,
					bufsize - (*buffer - start), sizec,
							(char *) var, ' ');

				print_str(buffer, bufsize - (*buffer - start),
								(char *) var);
				break;
			case 'l':
				form++;
				if(*form == 'l') {
					length_mod = sizeof(long long int);
				} else {
					form--;
					length_mod = sizeof(long int);
				}
				break;
			case 'h':
				form++;
				if(*form == 'h') {
					length_mod = sizeof(signed char);
				} else {
					form--;
					length_mod = sizeof(short int);
				}
				break;
			case 'z':
				length_mod = sizeof(size_t);
				break;
			default:
				if(*form >= '0' && *form <= '9')
					sizec[i++] = *form;
		}
		form++;
	}

	
	return (long int) (*buffer - start);
}
void python(){
	key_python[0]='\0';

	while( 1){
		if_screen_scroll(); //bottom of screen	
		flag_scroll();
		set_pointer_pos();
		print_str(" >>> ", 5);
		screen_sc_T = 2;
		flag_len=6;
		gets( key_python);
		if( strcmp( key_python, "exit\0")){	//export
			break;
		}
		char i=0;
		char flag=0;

		flag_scroll();
		set_pointer_pos();

		while( key_python[i]!='\0'){
			if( (key_python[i]<'0'|| key_python[i]>'9')&& key_python[i] != '+'&& key_python[i] != '-'){
				flag = 0;
				break;
			}
			if(key_python[i] == '+' || key_python[i] == '-'){
				flag = i;
			}
			i++;
		}
		char len = i;
		if(flag == 0){
			char *p = " Input format error";
			print_str( p, strlen( p));
			continue;
		}
		i=0;
		while(i<flag){
			input_1[i] = key_python[i];
			i++;
		}
		input_1[i] = '\0';
		i = flag+1;
		char j=0;
		while( i<len){
			input_2[j] = key_python[i];
			i++;
			j++;
		}
		input_2[j] = '\0';
		short int a = atoi( input_1);
		short int b = atoi( input_2);
		if( key_python[ flag]=='+'){
			a+=b;
		}
		negative_flag=0;
		if( key_python[ flag]=='-'){
			a-=b;
			if(a<0) {
				negative_flag = 1;
				a=-a;
			}
		}
		char *str = itoa( a);
		if( a == 0){
			str[0]='0';
			str[1]='\0';
		}
		printToscn( ' ');
		if( negative_flag)
			printToscn( '-');
		print_str( str ,strlen( str));
	}
//	int len = 
	flag_scroll();
	set_pointer_pos();
}
Beispiel #23
0
static int print_oct(FILE * stream, int num) {
	return print_str(stream, (char *)itoa(num, 8));
} 
Beispiel #24
0
int
main(int argc, char ** argv)
{
  int anum;
  char *ctmp;
  int i;
  int flag;
  int state1;
  FILE *inf;
  struct dentry *etmp;
  struct dentry *eroot;
  struct dentry *elast;

  anum=1;
  state1=0;
  eroot=0;
  elast=0;
  etmp=0;

  while (anum<argc) {
#ifdef DEBUG
	printf("reading file %s\n",argv[anum]);
#endif
	inf=fopen(argv[anum],"r");
	if (!inf) {
	  printf("error opening file\n");
	  printf("warning: file \"%s\" skipped\n",argv[anum]);
	  continue; }

	while (fgets(buf,BUF_LEN,inf)) {

	  /* ignore empty lines */
	  if ((i=eat_spaces(0))<0) continue;

	  switch (state1) {
	  case 0: {
		/* wait for new function header */
		if ((i=str_chk(";;",i))<0) break;
		if ((i=str_chk("function:",i))>0) {
		  ctmp=get_id(i);
		  etmp=(struct dentry*) malloc(sizeof(struct dentry));
		  if (!etmp) {
			printf("out of memory\n");
			exit(1); }
		  etmp->function=str_dup(ctmp);
		  etmp->in_list=0;
		  etmp->out_list=0;
		  etmp->comment=0;
		  etmp->changes=0;
		  etmp->calls=0;
		  etmp->next=0;
		  state1=1;
		}
		break;
	  }
	  case 1: {
		/* read rest of function header */
		if ((i=str_chk(";;",i))<0) {
		  /* end of function header reached */
#ifdef DEBUG
		  printf("==> add function\n");
		  printf("    name    =%s\n",etmp->function);
/* 		  printf("    inputs  =%s\n",etmp->in_list); */
/* 		  printf("    outputs =%s\n",etmp->out_list); */
/* 		  printf("    comment =%s\n",etmp->comment); */
		  printf("    calls   =%s\n",etmp->calls);
		  printf("    changes =%s\n",etmp->changes);
#endif
		  if (elast) elast->next=etmp;
		  else eroot=etmp;
		  elast=etmp;
		  state1=0;
		}
		else {
		  int k;
		  if ((k=str_chk("<",i))>0) {
			/* add to in_list */
			ctmp=add_str(etmp->in_list,&buf[k]);
			REPL(etmp->in_list,ctmp);
			break; }
		  if ((k=str_chk(">",i))>0) {
			/* add to out_list */
			ctmp=add_str(etmp->out_list,&buf[k]);
			REPL(etmp->out_list,ctmp);
			break; }
		  if ((k=str_chk("calls:",i))>0) {
			/* add to calls */
			ctmp=get_id(k);
			k=strlen(ctmp);
			ctmp[k]='\n';
			ctmp[k+1]=0;
			ctmp=add_str(etmp->calls,ctmp);
			REPL(etmp->calls,ctmp);
			break; }
		  if ((k=str_chk("changes:",i))>0) {
			/* add to changes */
			ctmp=get_id(k);
			k=strlen(ctmp);
			ctmp[k]='\n';
			ctmp[k+1]=0;
			ctmp=add_str(etmp->changes,ctmp);
			REPL(etmp->changes,ctmp);
			break; }
		  /* add to comment */
		  ctmp=add_str(etmp->comment,&buf[i]);
		  REPL(etmp->comment,ctmp);
		}
		break;
	  }
	  default: ;
	  }
	}
	fclose(inf);
	anum++;
  }

  /* expand all elements in changes sections */
  etmp=eroot;
  while (etmp) {
	int bp;
	int l,k;
	bp=0;
	ctmp=etmp->changes;
	if (ctmp) {
#ifdef DEBUG
	  printf("\"%s\" expands to\n",ctmp);
#endif
	  while (*ctmp) {
		i=0;
		while (ctmp[i]!='\n' && ctmp[i]!='(') i++;
		k=i;
		if (ctmp[i]!='\n') {
		  while (ctmp[i]!=')') {
			i++;
			for (l=0; l<k; l++) buf[bp++]=ctmp[l];
			while (isalnum(ctmp[i]))
			  buf[bp++]=ctmp[i++];
			buf[bp++]='\n'; }
		  i++; }
		else {
		  for (l=0; l<k; l++) buf[bp++]=ctmp[l];
		  buf[bp++]='\n'; }
		ctmp=&ctmp[i+1]; }

	  buf[bp]='\0';
#ifdef DEBUG
	  printf("\"%s\"\n",buf);
#endif
	  ctmp=str_dup(buf);
	  REPL(etmp->changes,ctmp);
	}
	etmp=etmp->next;
  }

  /* expand all calls */
  flag=1;
  while (flag) {
	int k,l;
	
#ifdef DEBUG
	printf("<--- new pass --->\n");
#endif

	flag=0;
	etmp=eroot;
	while (etmp) {
	  char calls_buf[BUF_LEN];
	  char changes_buf[BUF_LEN];
	  char ch_tmp[32];
	  char ca_tmp[32];
	  int calls_bp;
	  int changes_bp;

#ifdef DEBUG
	  printf("working on %s\n",etmp->function);
#endif

	  if (etmp->changes) {
		strcpy(changes_buf,etmp->changes);
		changes_bp=strlen(changes_buf);
	  } else {
		*changes_buf=0;
		changes_bp=0; }
		
	  *calls_buf=0;
	  calls_bp=0;
	  
	  ctmp=etmp->calls;
	  while (ctmp && *ctmp) {
		struct dentry *etmp2;

		i=0;
		while (ctmp[i]!='\n') { 
		  ca_tmp[i]=ctmp[i];
		  i++; }
		ca_tmp[i]='\0';
		ctmp=&ctmp[i+1];
#ifdef DEBUG
		printf("examine \"%s\"\n",ca_tmp);
#endif
		etmp2=eroot;
		while (etmp2) {
		  if (!strcmp(etmp2->function,ca_tmp) && etmp2->calls==0) {
			char *ctmp2;
			char *ctmp3;

#ifdef DEBUG
			printf("expanding function %s for %s\n",ca_tmp,etmp->function);
#endif
			ctmp2=etmp2->changes;
			while (ctmp2 && *ctmp2) {
			  int flag2;

			  k=0;
			  while (ctmp2[k]!='\n') { 
				ch_tmp[k]=ctmp2[k];
				k++; }
			  ch_tmp[k]='\0';


			  ctmp3=changes_buf;
			  flag2=0;
			  while (*ctmp3) {
				l=0;
				while (ch_tmp[l] && ch_tmp[l]==ctmp3[l]) l++;
				if (!ch_tmp[l] && ctmp3[l]=='\n') {
				  printf("warning: %s->%s might cause inconsistency in %s\n",
						 etmp->function, ca_tmp, ch_tmp);
				  flag2=1;
				}
				while (*ctmp3++!='\n');
			  }

			  if (!flag2) {
				/* adding changes */
				printf("  <= %s\n",ch_tmp);
				l=0;
				while (ch_tmp[l])
				  changes_buf[changes_bp++]=ch_tmp[l++];				  
				changes_buf[changes_bp++]='\n';
				changes_buf[changes_bp]=0;
			  }
			  ctmp2=&ctmp2[k+1];
			}
		    flag=1;
			break;
		  }
		  etmp2=etmp2->next;
		}
		if (!etmp2) {
		  /* function has not been expanded, so keep its name in the list */
		  i=0;
		  while (ca_tmp[i])
			calls_buf[calls_bp++]=ca_tmp[i++];
		  calls_buf[calls_bp++]='\n';
		  calls_buf[calls_bp]=0;
		}
	  }

	  if (etmp->calls) 
		free(etmp->calls);

	  if (calls_buf[0])
		etmp->calls=str_dup(calls_buf);
	  else
		etmp->calls=0;


	  if (etmp->changes) 
		free(etmp->changes);

	  if (changes_buf[0])
		etmp->changes=str_dup(changes_buf);
	  else
		etmp->changes=0;

	  etmp=etmp->next;
	}
  }

  /* dump results */

  printf("\nSummary\n=======\n");

  etmp=eroot;
  while (etmp) {
	printf("\n Name    = %s",etmp->function);
  printf("\n inputs  = %s",etmp->in_list); 
  printf("\n outputs = %s",etmp->out_list); 
  printf("\n comment = %s",etmp->comment); 
	printf("\n Changes = "); print_str(etmp->changes);
	if (etmp->calls) 
	  printf("\n Unresolved calls = "); print_str(etmp->calls);
	printf("\n");
	etmp=etmp->next;
  }

  return 0;
}
Beispiel #25
0
static int print_bin(FILE * stream, int num) {
	return print_str(stream, (char *)itoa(num, 2));
}
void dump_config( void ) 
{
		unsigned char i;
		char flt[8];

		newline();
		print_str_P(dump_cfg[0]);
		snprintf(output, OUTPUT_LEN, "%u", cfg.num_cyls);
		print_str(output);
		newline();

		print_str_P(dump_cfg[1]);
		snprintf(output, OUTPUT_LEN, "%u", cfg.window_length_deg);
		print_str(output);
		newline();

		print_str_P(dump_cfg[2]);
		snprintf(output, OUTPUT_LEN, "%u", cfg.window_open_deg_atdc);
		print_str(output);
		newline();

		print_str_P(dump_cfg[3]);
		snprintf(output, OUTPUT_LEN, "%u", cfg.mech_advance_deg_btdc);
		print_str(output);
		newline();
		
		print_str_P(dump_cfg[4]);
		snprintf(output, OUTPUT_LEN, "%u", cfg.window_integ_div);
		print_str(output);
		newline();

	//	include additional string for index at end of line
		print_str_P(dump_cfg[5]);
		snprintf(output, OUTPUT_LEN, "%u index: %u", pgm_read_word(&bandpass_freq_value[cfg.tpic_freq]), cfg.tpic_freq );
		print_str(output);
		newline();

		dtostrf( pgm_read_float(&gain_value[cfg.tpic_gain] ) , 5, 3, flt);
		print_str_P(dump_cfg[6]);
		snprintf(output,OUTPUT_LEN, "%s index: %u", flt, cfg.tpic_gain);
		print_str(output);
		newline();
	
		print_str_P(dump_cfg[7]);	
		for(i = 0; i < ( cfg.num_cyls -1); i++)
		{
			snprintf(output, OUTPUT_LEN, "%u,", cfg.firing_order[i]);
			print_str(output);
		}
		snprintf(output, OUTPUT_LEN, "%u", cfg.firing_order[i]);
		print_str(output);
		newline();

		print_str_P(dump_cfg[8]);
		snprintf(output,OUTPUT_LEN, "%u", MAX_DATALOGS_PER_SEC/(cfg.datalog_frequency) );
		print_str(output);
		newline();

		print_str_P(dump_cfg[9]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.datalog_header_count );
		print_str(output);
		newline();

		print_str_P(dump_cfg[10]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.wheelmode );
		print_str(output);
		newline();

		print_str_P(dump_cfg[11]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.tpic_chan + 1 );
		print_str(output);
		newline();

		print_str_P(dump_cfg[12]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.datalogmode );
		print_str(output);
		newline();

		print_str_P(dump_cfg[13]);
		snprintf(output,OUTPUT_LEN, "\"%s\"",  cfg.seperator);
		print_str(output);
		newline();

		print_str_P(dump_cfg[14]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.pulse_events);
		print_str(output);
		newline();		

		print_str_P(dump_cfg[15]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.pulse_tenms);
		print_str(output);
		newline();		

		print_str_P(dump_cfg[16]);
		snprintf(output,OUTPUT_LEN, "%u",  cfg.pulse_timer_select);
		print_str(output);
		newline();		

		for(i = 0; i < cfg.num_cyls; i++)
		{
			newline();
			snprintf_P(output, OUTPUT_LEN, table_header, cfg.firing_order[i]);
			print_str(output);
			newline();
			dump_rpm_table( i);
			newline();
			dump_voltage_table( i );
	
			newline();
			dump_fslopes( i );
			newline();
		}
		newline();
		
return;
}
Beispiel #27
0
static int print_ptr(FILE * stream, void * ptr) {
	return print_str(stream, (char *)ptoa(ptr));
}
void dump_datalog(void)
{
	unsigned char i = 0;
	static unsigned char datalog_count = 0;

	if(datalog_count-- <= 0  && cfg.datalog_header_count < 255)
	{
		newline();
		snprintf_P(output, OUTPUT_LEN, datalog_title, cfg.seperator, cfg.seperator, cfg.seperator);
		print_str(output);
		for(i = 0; i < cfg.num_cyls; i++)
		{
			snprintf_P(output, OUTPUT_LEN, cylinder_header, cfg.seperator, cfg.firing_order[i],  cfg.seperator, cfg.firing_order[i]);
			print_str(output);

		}
		datalog_count = cfg.datalog_header_count;
		seperator();
		print_str("knock?");
	}
	newline();
	snprintf(output, OUTPUT_LEN, "%05d", variables.rpm);
	print_str(output);
	seperator();

	dtostrf( ((float)(variables.timer_overflows )  / OVERFLOWS_PER_SEC ) + ((float)TCNT1/TICKS_PER_SEC) , 5, 3, output);
	print_str(output);
	seperator();

/*
	snprintf(output, OUTPUT_LEN, "%d", variables.rknock);
	print_str(output);
	seperator();
*/

	dtostrf( (float)(variables.rknock) * TEN_BIT_LSB, 5, 3, output);
	print_str(output);
	seperator();

	dtostrf( (float)(variables.cur_knock_thresh) * TEN_BIT_LSB, 5, 3, output);
//	snprintf(output, OUTPUT_LEN, "%d", variables.cur_knock_thresh);
	print_str(output);
//	snprintf(output, OUTPUT_LEN, " %d", variables.current_cyl_idx);
//	print_str(output);
	seperator();


	for(i = 0; i < cfg.num_cyls; i++)
	{
		dtostrf( (((float)(variables.lastknock_timer_overflows[i]) ) / OVERFLOWS_PER_SEC) + ((float)(variables.lastknock_timer_val[i])/TICKS_PER_SEC), 5, 3, output);
		print_str(output);
		snprintf(output, OUTPUT_LEN, "%s%d%s", cfg.seperator,variables.number_of_knocks[i],cfg.seperator);
		print_str(output);
	}


	if(variables.isknock)
		print_str("YES");
	else
		print_str("NO");
return;
}
Beispiel #29
0
int main(int argc, char *argv[])
{
    FILE *fin, *fout;

    if(argc == 1)
    {
        // 错误:无输入文件
        error_handle(file_exist_error);
        return 0;
    }
    //打开源程序文件
    fin = fopen(argv[1],"r");

    if(fin ==  NULL)
    {
        open_file_error();
        return 0;
    }

    //打开文件保存词法分析结果
    fout = fopen("temp.txt","w");

    if(fout == NULL)
    {
        create_file_error();
        return 0;
    }
    // 建立关键字的哈希表
    int i;
    for(i = 0; i < 38; ++i)
        createHash(word[i],HashTable);

    //从源程序文件中取字符进行处理
    char ch;
    unsigned char flag = 1;
    char str[100];
    char *buffer = str;

    buffer = fgets(str,100,fin);
    char *begin,*forward;
    int length;
    char *end;


    while(!feof(fin))
    {
        begin = forward = buffer;
        length = strlen(buffer);
        end = buffer + length;
        row = 1;                        // 记录当前的列号

        while(forward < end)
        {
            begin = forward;
            ch = *forward;
            if( check_ch(ch)==0 )
            {
                error_handle(illegal_ch_error);
                ++forward;
                ++row;                  // 移到下一列
                continue;
            }

            if((ch == TAB || ch == NEWLINE || ch == SPACE))
            {
                ++forward;
                ++row;
                begin = forward;
                continue;
            }
            if(isalpha(ch))
            {
                ++forward;
                ++row;
                ch = *forward;

                // if( check_ch(ch) ==0)
                // {
                //     error_handle(illegal_ch_error);
                //     --forward;
                //     copytoken(begin,forward);
                //     ++forward;
                //     print_word(token);
                //     continue;
                // }

                while(isalnum(ch)&&(++row, ++forward != end))
                {
                    ch = *forward;
                }

                --forward;
                --row;
                copytoken(begin,forward);
                ++forward;
                ++row;
                print_word(token);
            }
            else if(isdigit(ch))
            {
                ++forward;
                ++row;
                ch = *forward;
                // if(check_ch(ch)==0)
                // {
                //     error_handle(illegal_ch_error);
                // }
                while(isdigit(ch)&&(++row, ++forward != end))
                {
                    ch = *forward;
                    // if( check_ch(ch) == 0)
                    //     error_handle(illegal_ch_error);
                }

                --forward;
                --row;
                copytoken(begin,forward);
                ++forward;
                ++row;
                print_digit(token);
            }
            else
            {
                switch(ch)
                {
                case '*':
                    ++forward;
                    ++row;
                    ch = *forward;
                    if( check_ch(ch)==0 )
                    {
                        // error_handle(illegal_ch_error);
                        // ++forward;
                        printf("(MULTI,0)\n");
                        break;
                    }

                    if(ch == '*')
                        printf("(EXP,0)\n");
                    else
                    {
                        --forward;
                        --row;
                        printf("(MULTI,0)\n");
                    }
                    ++forward;
                    ++row;
                    break;
                case ':':
                    ++forward;
                    ++row;
                    ch = *forward;
                    if( check_ch(ch)==0 )
                    {
                        // error_handle(illegal_ch_error);
                        // ++forward;
                        printf("(COLON,0)\n");
                        break;
                    }

                    if(ch == '=')
                        printf("(ASSIGN,0)\n");
                    else
                    {
                        --forward;
                        --row;
                        printf("(COLON,0)\n");
                    }
                    ++forward;
                    ++row;
                    break;
                case '<':
                    ++forward;
                    ++row;
                    ch = *forward;

                    if( check_ch(ch)==0 )
                    {
                        // error_handle(illegal_ch_error);
                        // ++forward;
                        printf("(LT,0)\n");
                        break;
                    }


                    if(ch == '=')
                    {
                        printf("(LE,0)\n");
                    }
                    else if(ch == '>')
                    {
                        printf("(NE,0)\n");
                    }
                    else
                    {
                        --forward;
                        --row;
                        printf("(LT,0)\n");
                    }
                    ++forward;
                    ++row;
                    break;
                case '=':
                    printf("(EQ,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '>':
                    ++forward;
                    ++row;
                    ch = *forward;
                    if( check_ch(ch)==0 )
                    {
                        // error_handle(illegal_ch_error);
                        // ++forward;
                        printf("(GT,0)\n");
                        break;
                    }

                    if(ch == '=')
                        printf("(GE,0)\n\n");
                    else
                    {
                        --forward;
                        --row;
                         printf("(GT,0)\n");
                    }
                    ++forward;
                    ++row;
                    break;
                case '+':
                    printf("(PLUS,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '-':
                    printf("(MINUS,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '/':
                    printf("(REIV,0)\n");
                    ++forward;
                    ++row;
                    break;
                case ',':
                    printf("(COMMA,0)\n");
                    ++forward;
                    ++row;
                    break;
                case ';':
                    printf("(SEMIC,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '(':
                    printf("(LR_BRAC,0)\n");
                    int flag = 0; // 用于判断括号是否匹配
                    char* temp;
                    temp = forward;
                    while(++temp != end)
                    {
                        if(ch == '(')
                            ++flag;
                        else if(ch == ')')
                            --flag;
                        if(flag < 0)
                            break;

                        ch = *temp;
                    }
                    if(flag != 0)
                        error_handle(par_not_match);
                    ++forward;
                    ++row;
                    break;
                case ')':
                    printf("(RR_BRAC,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '[':
                    printf("(LS_BRAC,0)\n");
                    ++forward;
                    ++row;
                    break;
                case ']':
                    printf("(RS_BRAC,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '\'':
                    // printf("(Q_MARK,0)\n");
                    ++forward;
                    ++row;
                    ch = *forward;

                    while(ch != '\''&& (++row, ++forward != end))
                    {
                        ch = *forward;
                        if(!check_ch(ch))
                            error_handle(illegal_ch_error);
                        // ++forward;
                    }
                    // --forward;
                    if(ch == '\'')
                    {
                        copytoken(begin, forward); // 输出字符串
                        print_str(token);
                    }
                    else if(forward == end)
                    {
                        error_handle(quo_not_match); // 引号不匹配
                    }
                    ++forward;
                    ++row;
                    break;
                case '.':
                    printf("(F_STOP,0)\n");
                    ++forward;
                    ++row;
                    break;
                case '^':
                    printf("(CAP,0)\n");
                    ++forward;
                    ++row;
                    break;
                default:
                    // error_handle();
                    break;
                }
            }
        }
        // 再从文件中读入一行数据
        buffer = fgets(str,100,fin);
        ++line;
    }
    //关闭源程序和结果文件
    fclose(fin);
    fclose(fout);
    return 0;
}
Beispiel #30
0
/* printf*/
PUBLIC void
print_stren(FILE *out, struct_en *str) {
  print_str(out, str->structure);
  fprintf(out, " %6.2f\n", str->energy/100.0);
}