示例#1
0
static void print_chains(struct pevent *pevent)
{
	struct chain *chain = chains;
	int pid;

	for (; chain; chain = chain->next) {
		pid = chain->pid_list->pid;
		if (chain != chains)
			printf("\n");
		if (compact)
			printf("  %%%3.2f <all pids> %30s #%d\n",
			       get_percent(total_counts, chain->count),
			       chain->func,
			       chain->count);
		else
			printf("  %%%3.2f  (%d) %s %30s #%d\n",
			       get_percent(total_counts, chain->count),
			       pid,
			       pevent_data_comm_from_pid(pevent, pid),
			       chain->func,
			       chain->count);
		printf(START);
		if (chain->event)
			printf(TICK "*%s*\n", chain->func);
		else
			printf(TICK "%s\n", chain->func);
		print_parents(pevent, chain, 0);
	}
}
static void twam_handler(struct twam_sig *twamsig)
{
	spm_crit("sig_high = %u%%  %u%%  %u%%  %u%%, r13 = 0x%x\n",
		 get_percent(twamsig->sig0,SPM_TWAM_MONITOR_TICK),
		 get_percent(twamsig->sig1,SPM_TWAM_MONITOR_TICK),
		 get_percent(twamsig->sig2,SPM_TWAM_MONITOR_TICK),
		 get_percent(twamsig->sig3,SPM_TWAM_MONITOR_TICK),
		 spm_read(SPM_PCM_REG13_DATA));
}
示例#3
0
 void BlockCmp::dump(BlockCmp& block_b, const int8_t type)
 {
   dump(type);
   block_b.dump(type);
   if (type & BLOCK_CMP_SERVER)
   {
     printf("!!!!!!Diff SERVER: (%zd/%zd = %.2lf%%) SERVER: (%zd/%zd = %.2lf%%)\n\n",
       flag_.count(), server_list_.size(), get_percent(flag_.count(), server_list_.size()),
       block_b.flag_.count(), block_b.server_list_.size(), get_percent(block_b.flag_.count(), block_b.server_list_.size())
         );
   }
 }
示例#4
0
int str_fuzzy_search (const QString &s, const QString &text_to_find, int start_pos, double q)
{
  int counter;
  int result = -1;

  bool jump = false;

  int end_pos = s.length() - 1;

  for (int i = start_pos; i < end_pos; i++)
      {
       if (jump)
	      break;

       counter = 0;
       for (int j = 0; j < text_to_find.length(); j++)
           {
            if (s[i + j] == text_to_find[j])
  	           counter++;

            if (get_percent ((double)text_to_find.length(), (double)counter) >= q)
	          {
	           result = i;
		       jump = true;
	           break;
	           }
           }
      }

  return result;
}
示例#5
0
string formatter::format_cumulated_percent_details(field_datum const & f)
{
	f.counts.cumulated_percent_details[f.pclass] += f.sample.counts[f.pclass];

	return get_percent(f.counts.cumulated_percent_details[f.pclass],
	                   f.counts.total[f.pclass]);
}
示例#6
0
string formatter::format_cumulated_percent(field_datum const & f)
{
	if (f.diff == -INFINITY)
		return "---";
	f.counts.cumulated_percent[f.pclass] += f.sample.counts[f.pclass];

	return get_percent(f.counts.cumulated_percent[f.pclass],
	                   f.counts.total[f.pclass]);
}
示例#7
0
int S2Status::skewed_percent(maxint_t n, maxint_t limit) const
{
  double exp = 0.96;
  double percent = get_percent((double) n, (double) limit);
  double base = exp + percent / (101 / (1 - exp));
  double min = pow(base, 100.0);
  percent = 100 - in_between(0, 100 * (pow(base, percent) - min) / (1 - min), 100);
  return max(old_, (int) percent);
}
示例#8
0
 void ServerCmp::dump(ServerCmp& server_b, const int8_t type)
 {
   dump(type, true);
   server_b.dump(type, false);
   if (type & SERVER_TYPE_BLOCK_LIST)
   {
     printf("!!!!!!Diff BLOCK: (%zd/%zd = %.2lf%%) BLOCK: (%zd/%zd = %.2lf%%)\n\n",
         flag_.count(), hold_.size(),
         get_percent(flag_.count(), hold_.size()),
         server_b.flag_.count(), server_b.hold_.size(),
         get_percent(server_b.flag_.count(), server_b.hold_.size()));
   }
   if (type & SERVER_TYPE_BLOCK_WRITABLE)
   {
     printf("!!!!!!Diff WRITABLE: (%zd/%zd = %.2lf%%) WRITALBE: (%zd/%zd = %.2lf%%)\n\n",
         flag_.count(), writable_.size(), get_percent(flag_.count(), writable_.size()),
         server_b.flag_.count(), server_b.writable_.size(), get_percent(server_b.flag_.count(), server_b.writable_.size())
         );
   }
   if (type & SERVER_TYPE_BLOCK_MASTER)
   {
     printf("!!!!!!Diff MASTER: (%zd/%zd = %.2lf%%) MASTER: (%zd/%zd = %.2lf%%)\n\n",
         flag_.count(), master_.size(), get_percent(flag_.count(), master_.size()),
         server_b.flag_.count(), server_b.master_.size(), get_percent(server_b.flag_.count(), server_b.master_.size())
         );
   }
 }
// Creates a bunch of particles. You pass a structure
// rather than a bunch of parameters.
void particle_emit( particle_emitter *pe, int type, int optional_data, float range )
{
	int i, n;

	if ( !Particles_enabled )
		return;

	int n1, n2;

	// Account for detail
	int percent = get_percent(Detail.num_particles);

	//Particle rendering drops out too soon.  Seems to be around 150 m.  Is it detail level controllable?  I'd like it to be 500-1000 
	float min_dist = 125.0f;
	float dist = vm_vec_dist_quick( &pe->pos, &Eye_position ) / range;
	if ( dist > min_dist )	{
		percent = fl2i( i2fl(percent)*min_dist / dist );
		if ( percent < 1 ) {
			return;
		}
	}
	//mprintf(( "Dist = %.1f, percent = %d%%\n", dist, percent ));

	n1 = (pe->num_low*percent)/100;
	n2 = (pe->num_high*percent)/100;

	// How many to emit?
	n = (rand() % (n2-n1+1)) + n1;
	
	if ( n < 1 ) return;


	for (i=0; i<n; i++ )	{
		// Create a particle
		vec3d tmp_vel;
		vec3d normal;				// What normal the particle emit arond

		float radius = (( pe->max_rad - pe->min_rad ) * frand()) + pe->min_rad;

		float speed = (( pe->max_vel - pe->min_vel ) * frand()) + pe->min_vel;

		float life = (( pe->max_life - pe->min_life ) * frand()) + pe->min_life;

		normal.xyz.x = pe->normal.xyz.x + (frand()*2.0f - 1.0f)*pe->normal_variance;
		normal.xyz.y = pe->normal.xyz.y + (frand()*2.0f - 1.0f)*pe->normal_variance;
		normal.xyz.z = pe->normal.xyz.z + (frand()*2.0f - 1.0f)*pe->normal_variance;
		vm_vec_normalize_safe( &normal );
		vm_vec_scale_add( &tmp_vel, &pe->vel, &normal, speed );

		particle_create( &pe->pos, &tmp_vel, life, radius, type, optional_data );
	}
}
示例#10
0
    void StatCmp::print_stat(const int8_t type)
    {
      const char* title = (type & BLOCK_TYPE) ? "BLOCK" : "DATASERVER";

      bitset<MAX_BITS_SIZE> flag_more;
      bitset<MAX_BITS_SIZE> flag_less;
      printf("\nIn More %s:\n", title);
      (type & BLOCK_TYPE) ? print_container(more_block_, flag_more, true, false) : print_container(more_server_, flag_more, true, true);
      printf("\nIn Less %s:\n", title);
      (type & BLOCK_TYPE) ? print_container(less_block_, flag_less, true, false) : print_container(less_server_, flag_less, true, true);

      //TBSYS_LOG(DEBUG, "block size: %d", more_block_.size());
      diff_count_ += (type & BLOCK_TYPE)? more_block_.size() : more_server_.size();
      printf("\n\n!!!!!!(MasterNs VS SlaveNs) %s Diff Count :  %"PRI64_PREFIX"d / %"PRI64_PREFIX"d = %.2lf%%\n\n", title, diff_count_, total_count_,
          get_percent(diff_count_, total_count_));
    }
示例#11
0
static void print_parents(struct pevent *pevent, struct chain *chain, int indent)
{
	struct chain *parent = chain->parents;
	int x;

	if (single_chain(chain)) {
		dump_chain(pevent, chain, indent);
		return;
	}

	line_mask |= 1ULL << (indent);

	for (x = 0; parent; x++, parent = parent->sibling) {
		struct chain *save_parent;

		make_indent(indent + 1);
		printf("\n");

		make_indent(indent + 1);

		printf("--%%%.2f-- %s  # %d\n",
		       get_percent(chain->count, parent->count),
		       parent->func, parent->count);

		if (x == chain->nr_parents - 1)
			line_mask &= (1ULL << indent) - 1;

		if (single_chain(parent))
			dump_chain(pevent, parent, indent + 1);
		else {
			save_parent = parent;

			while (parent && parent->parents && parent->nr_parents < 2 &&
			       parent->parents->count == parent->count) {
				print_single_parent(parent, indent + 1);
				parent = parent->parents;
			}
			if (parent)
				print_parents(pevent, parent, indent + 1);
			parent = save_parent;
		}
	}
}
示例#12
0
文件: copy.c 项目: marwatk/TivoTools
int
copy_main (int argc, char **argv)
{
	char source_a[PATH_MAX], source_b[PATH_MAX];
	char dest_a[PATH_MAX], dest_b[PATH_MAX];
	char *tmp;
	struct backup_info *info_b, *info_r;
	int opt, loop, thresh = 0, threshopt = 0;
	unsigned int varsize = 0, swapsize = 0;
	unsigned int bflags = BF_BACKUPVAR, rflags = 0;
	int quiet = 0;
	int bswap = 0;
	int expand = 0;
	int expandscale = 2;

	tivo_partition_direct ();

	while ((opt = getopt (argc, argv, "hqf:L:tTaspxr:v:S:lbBzE")) > 0)
	{
		switch (opt)
		{
		case 'q':
			quiet++;
			break;
		case 's':
			bflags |= BF_SHRINK;
			break;
		case 'E':
			bflags |= BF_TRUNCATED;
			break;
		case 'f':
			if (threshopt)
			{
				fprintf (stderr, "%s: -f and -%c cannot be used together\n", argv[0], threshopt);
				return 1;
			}
			threshopt = loop;
			thresh = strtoul (optarg, &tmp, 10);
			if (*tmp)
			{
				fprintf (stderr, "%s: Non integer argument to -f\n", argv[0]);
				return 1;
			}
			break;
		case 'L':
			if (threshopt)
			{
				fprintf (stderr, "%s: -l and -%c cannot be used together\n", argv[0], threshopt);
				return 1;
			}
			threshopt = loop;
			thresh = strtoul (optarg, &tmp, 10);
			thresh *= 1024 * 2;
			bflags |= BF_THRESHSIZE;
			if (*tmp)
			{
				fprintf (stderr, "%s: Non integer argument to -L\n", argv[0]);
				return 1;
			}
			break;
		case 't':
			bflags |= BF_THRESHTOT;
			break;
		case 'T':
			bflags |= BF_STREAMTOT;
			break;
		case 'a':
			if (threshopt)
			{
				fprintf (stderr, "%s: -a and -%c cannot be used together\n", argv[0], threshopt);
				return 1;
			}
			threshopt = loop;
			thresh = ~0;
			break;

		case 'v':
			bflags &= ~BF_BACKUPVAR;
			varsize = strtoul (optarg, &tmp, 10);
			varsize *= 1024 * 2;
			if (tmp && *tmp)
			{
				fprintf (stderr, "%s: Integer argument expected for -v.\n", argv[0]);
				return 1;
			}
			break;
		case 'S':
			swapsize = strtoul (optarg, &tmp, 10);
			swapsize *= 1024 * 2;
			if (tmp && *tmp)
			{
				fprintf (stderr, "%s: Integer argument expected for -s.\n", argv[0]);
				return 1;
			}
			break;
		case 'z':
			rflags |= RF_ZEROPART;
			break;
		case 'b':
			if (bswap != 0)
			{
				fprintf (stderr, "%s: Only one byte swapping option (-b/-B) allowed.\n", argv[0]);
				return 1;
			}
			bswap = -1;
			break;
		case 'B':
			if (bswap != 0)
			{
				fprintf (stderr, "%s: Only one byte swapping option (-b/-B) allowed.\n", argv[0]);
				return 1;
			}
			bswap = 1;
			break;
		case 'p':
			rflags |= RF_BALANCE;
			break;
		case 'l':
			rflags |= RF_NOFILL;
			break;
		case 'x':
			expand = 1;
			break;
		case 'r':
			expandscale = strtoul (optarg, &tmp, 10);
			if (tmp && *tmp)
			{
				fprintf (stderr, "%s: Integer argument expected for -r.\n", argv[0]);
				return 1;
			}
			if (expandscale < 0 || expandscale > 4)
			{
				fprintf (stderr, "%s: Scale value for -r must be in the range 0 to 4.\n", argv[0]);
				return 1;
			}
			break;
		default:
			copy_usage (argv[0]);
			return 1;
		}
	}

	// Split out the drive names
	source_a[0] = 0;
	source_b[0] = 0;
	dest_a[0] = 0;
	dest_b[0] = 0;

	if (argc - optind < 4)
	{
		if (optind < argc)
		{
			get_drives (argv[optind++], source_a, source_b);
		}
		if (optind < argc)
		{
			get_drives (argv[optind++], dest_a, dest_b);
		}
	}
	else
	{
// Special case for convenience - 2 source and 2 target named
		strcpy (source_a, argv[optind++]);
		strcpy (source_b, argv[optind++]);
		strcpy (dest_a, argv[optind++]);
		strcpy (dest_b, argv[optind++]);
	}

	if (optind < argc || !*source_a || !*dest_a)
	{
		copy_usage (argv[0]);
		return 1;
	}

	if (expand > 0)
		rflags |= RF_NOFILL;

	info_b = init_backup (source_a, source_b, bflags);

	// Try to continue anyway despite error.
	if (bflags & BF_TRUNCATED && backup_has_error (info_b))
	{
		backup_perror (info_b, "WARNING");
		fprintf (stderr, "Attempting copy anyway\n");
		backup_check_truncated_volume (info_b);
		if (info_b && backup_has_error (info_b))
		{
			backup_perror (info_b, "Copy source");
			return 1;
		}
	}

	if (info_b && backup_has_error (info_b))
	{
		backup_perror (info_b, "Copy source");

		fprintf (stderr, "To attempt copy anyway, try again with -E.  -s is implied by -E.\n");
		return 1;
	}

	info_r = init_restore (rflags);
	if (info_r && restore_has_error (info_r))
	{
		restore_perror (info_r, "Copy target");
		return 1;
	}

	if (!info_b || !info_r)
	{
		fprintf (stderr, "%s: Copy failed to start.  Make sure you specified the right\ndevices, and that the drives are not locked.\n", argv[0]);
		return 1;
	}
	else
	{
		unsigned starttime;
		char buf[BUFSIZE];
		unsigned int curcount = 0;
		int nread, nwrit;

		if (threshopt)
			backup_set_thresh (info_b, thresh);

		if (varsize)
			restore_set_varsize (info_r, varsize);
		if (swapsize)
			restore_set_swapsize (info_r, swapsize);
		if (bswap)
			restore_set_bswap (info_r, bswap);

		if (quiet < 2)
			fprintf (stderr, "Scanning source drive.  Please wait a moment.\n");

		if (backup_start (info_b) < 0)
		{
			if (backup_has_error (info_b))
				backup_perror (info_b, "Copy source");
			else
				fprintf (stderr, "Copy source failed.\n");
			return 1;
		}

// Fill the buffer up to start.  Restore needs some information to bootstrap
// the process.
		while (curcount < BUFSIZE && (nread = backup_read (info_b, buf, BUFSIZE - curcount)) > 0)
		{
			curcount += nread;
		}

		if (curcount < BUFSIZE)
		{
			if (backup_has_error (info_b))
				backup_perror (info_b, "Copy source");
			else
				fprintf (stderr, "Copy source failed.\n");
			return 1;
		}

		nread = curcount;

		nwrit = restore_write (info_r, buf, nread);
		if (nwrit < 0)
		{
			if (restore_has_error (info_r))
				restore_perror (info_r, "Copy target");
			else
				fprintf (stderr, "Copy target failed.\n");
			return 1;
		}

		if (restore_trydev (info_r, dest_a, dest_b) < 0)
		{
			if (restore_has_error (info_r))
				restore_perror (info_r, "Copy target");
			else
				fprintf (stderr, "Copy target failed.\n");
			return 1;
		}

		if (restore_start (info_r) < 0)
		{
			if (restore_has_error (info_r))
				restore_perror (info_r, "Copy target");
			else
				fprintf (stderr, "Copy target failed.\n");
			return 1;
		}

		if (restore_write (info_r, buf + nwrit, nread - nwrit) != nread - nwrit)
		{
			if (restore_has_error (info_r))
				restore_perror (info_r, "Copy target");
			else
				fprintf (stderr, "Copy target failed.\n");
			return 1;
		}

		starttime = time (NULL);

		fprintf (stderr, "Starting copy\nSize: %d megabytes\n", info_r->nsectors / 2048);
		while ((curcount = backup_read (info_b, buf, BUFSIZE)) > 0)
		{
			unsigned int prcnt, compr;
			if (restore_write (info_r, buf, curcount) != curcount)
			{
				if (quiet < 1)
					fprintf (stderr, "\n");
				if (restore_has_error (info_r))
					restore_perror (info_r, "Copy source");
				else
					fprintf (stderr, "Copy source failed.\n");
				return 1;
			}
			prcnt = get_percent (info_r->cursector, info_r->nsectors);
			if (quiet < 1)
			{
				unsigned timedelta = time(NULL) - starttime;

				fprintf (stderr, "\rCopying %d of %d mb (%d.%02d%%)", info_r->cursector / 2048, info_r->nsectors / 2048, prcnt / 100, prcnt % 100);

				if (prcnt > 100 && timedelta > 15)
				{
					unsigned ETA = timedelta * (10000 - prcnt) / prcnt;
					fprintf (stderr, " %d mb/sec (ETA %d:%02d:%02d)", info_r->cursector / timedelta / 2048, ETA / 3600, ETA / 60 % 60, ETA % 60);
				}
			}
		}

		if (quiet < 1)
			fprintf (stderr, "\n");

		if (backup_has_error (info_b))
		{
			backup_perror (info_b, "Copy source");
			return 1;
		}

		if (restore_has_error (info_r))
		{
			restore_perror (info_r, "Copy target");
			return 1;
		}
	}

	if (backup_finish (info_b) < 0)
	{
		if (backup_has_error (info_b))
			backup_perror (info_b, "Copy source");
		else
			fprintf (stderr, "Copy source failed.\n");
		return 1;
	}

	if (info_b->back_flags & BF_TRUNCATED)
	{
		fprintf (stderr, "***WARNING***\nCopy was made of an incomplete volume.  While the copy succeeded,\nit is possible there was some required data missing.  Verify your copy.\n");
	}

	if (quiet < 2)
		fprintf (stderr, "Cleaning up target.  Please wait a moment.\n");

	if (restore_finish (info_r) < 0)
	{
		if (restore_has_error (info_r))
			restore_perror (info_r, "Copy target");
		else
			fprintf (stderr, "Copy target failed.\n");
		return 1;
	}

	if (quiet < 2)
		fprintf (stderr, "Copy done!\n");

	if (expand > 0)
	{
		int blocksize = 0x800;
		struct mfs_handle *mfshnd;

		expand = 0;

		mfshnd = mfs_init (dest_a, dest_b, O_RDWR);
		if (!mfshnd)
		{
			fprintf (stderr, "Drive expansion failed.\n");
			return 1;
		}

		if (mfs_has_error (mfshnd))
		{
			mfs_perror (mfshnd, "Target expand");
			return 1;
		}

		while (expandscale-- > 0)
			blocksize *= 2;

		if (tivo_partition_largest_free (dest_a) > 1024 * 1024 * 2)
		{
			if (expand_drive (mfshnd, "/dev/hda", dest_a, blocksize) < 0)
			{
				if (mfs_has_error (mfshnd))
					mfs_perror (mfshnd, "Expand drive A");
				else
					fprintf (stderr, "Drive A expansion failed.\n");
				return 1;
			}
			expand++;
		}

		if (dest_b[0] && tivo_partition_largest_free (dest_b) > 1024 * 1024 * 2)
		{
			if (expand_drive (mfshnd, "/dev/hdb", dest_b, blocksize) < 0)
			{
				if (mfs_has_error (mfshnd))
					mfs_perror (mfshnd, "Expand drive B");
				else
					fprintf (stderr, "Drive B expansion failed.\n");
				return 1;
			}
			expand++;
		}

		if (!expand)
		{
			fprintf (stderr, "Not enough extra space to expand on A drive%s.\n", dest_b[0]? " or B drive": "");
		}
	}

	return 0;
}
示例#13
0
uint8_t get_percent_current(uint8_t index){
  return get_percent(get_value_current_abs(), MIN_CURRENTCENTER, MAX_CURRENTCENTER);
}
示例#14
0
文件: q_netem.c 项目: hajuuk/R7000
static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
                           struct nlmsghdr *n)
{
    size_t dist_size = 0;
    struct rtattr *tail;
    struct tc_netem_qopt opt;
    struct tc_netem_corr cor;
    struct tc_netem_reorder reorder;
    __s16 dist_data[MAXDIST];

    memset(&opt, 0, sizeof(opt));
    opt.limit = 1000;
    memset(&cor, 0, sizeof(cor));
    memset(&reorder, 0, sizeof(reorder));

    while (argc > 0) {
        if (matches(*argv, "limit") == 0) {
            NEXT_ARG();
            if (get_size(&opt.limit, *argv)) {
                explain1("limit");
                return -1;
            }
        } else if (matches(*argv, "latency") == 0 ||
                   matches(*argv, "delay") == 0) {
            NEXT_ARG();
            if (get_ticks(&opt.latency, *argv)) {
                explain1("latency");
                return -1;
            }

            if (NEXT_IS_NUMBER()) {
                NEXT_ARG();
                if (get_ticks(&opt.jitter, *argv)) {
                    explain1("latency");
                    return -1;
                }

                if (NEXT_IS_NUMBER()) {
                    NEXT_ARG();
                    if (get_percent(&cor.delay_corr,
                                    *argv)) {
                        explain1("latency");
                        return -1;
                    }
                }
            }
        } else if (matches(*argv, "loss") == 0 ||
                   matches(*argv, "drop") == 0) {
            NEXT_ARG();
            if (get_percent(&opt.loss, *argv)) {
                explain1("loss");
                return -1;
            }
            if (NEXT_IS_NUMBER()) {
                NEXT_ARG();
                if (get_percent(&cor.loss_corr, *argv)) {
                    explain1("loss");
                    return -1;
                }
            }
        } else if (matches(*argv, "reorder") == 0) {
            NEXT_ARG();
            if (get_percent(&reorder.probability, *argv)) {
                explain1("reorder");
                return -1;
            }
            if (NEXT_IS_NUMBER()) {
                NEXT_ARG();
                if (get_percent(&reorder.correlation, *argv)) {
                    explain1("reorder");
                    return -1;
                }
            }
        } else if (matches(*argv, "gap") == 0) {
            NEXT_ARG();
            if (get_u32(&opt.gap, *argv, 0)) {
                explain1("gap");
                return -1;
            }
        } else if (matches(*argv, "duplicate") == 0) {
            NEXT_ARG();
            if (get_percent(&opt.duplicate, *argv)) {
                explain1("duplicate");
                return -1;
            }
            if (NEXT_IS_NUMBER()) {
                NEXT_ARG();
                if (get_percent(&cor.dup_corr, *argv)) {
                    explain1("duplicate");
                    return -1;
                }
            }
        } else if (matches(*argv, "distribution") == 0) {
            NEXT_ARG();
            dist_size = get_distribution(*argv, dist_data);
            if (dist_size < 0)
                return -1;
        } else if (strcmp(*argv, "help") == 0) {
            explain();
            return -1;
        } else {
            fprintf(stderr, "What is \"%s\"?\n", *argv);
            explain();
            return -1;
        }
        argc--;
        argv++;
    }

    tail = NLMSG_TAIL(n);

    if (reorder.probability) {
        if (opt.latency == 0) {
            fprintf(stderr, "reordering not possible without specifying some delay\n");
        }
        if (opt.gap == 0)
            opt.gap = 1;
    } else if (opt.gap > 0) {
        fprintf(stderr, "gap specified without reorder probability\n");
        explain();
        return -1;
    }

    if (dist_size > 0 && (opt.latency == 0 || opt.jitter == 0)) {
        fprintf(stderr, "distribution specified but no latency and jitter values\n");
        explain();
        return -1;
    }

    addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
    addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor));
    addattr_l(n, 1024, TCA_NETEM_REORDER, &reorder, sizeof(reorder));

    if (dist_size > 0) {
        addattr_l(n, 32768, TCA_NETEM_DELAY_DIST,
                  dist_data, dist_size*sizeof(dist_data[0]));
    }
    tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
    return 0;
}
示例#15
0
uint8_t get_percent_cellvoltage(uint8_t index){
  return get_percent(get_can_value(index), MIN_CELLVOLTAGE, MAX_CELLVOLTAGE);
}
示例#16
0
uint8_t get_percent_fanspeed(uint8_t index){
  return get_percent(get_can_value(index), MIN_FANSPEED, MAX_FANSPEED);
}
示例#17
0
uint8_t get_percent_egas(uint8_t index){
  return get_percent(get_can_value(index), MIN_EGAS, MAX_EGAS);
}
示例#18
0
static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
			   struct nlmsghdr *n)
{
	int dist_size = 0;
	struct rtattr *tail;
	struct tc_netem_qopt opt = { .limit = 1000 };
	struct tc_netem_corr cor;
	struct tc_netem_reorder reorder;
	struct tc_netem_corrupt corrupt;
	struct tc_netem_gimodel gimodel;
	struct tc_netem_gemodel gemodel;
	struct tc_netem_rate rate;
	__s16 *dist_data = NULL;
	__u16 loss_type = NETEM_LOSS_UNSPEC;
	int present[__TCA_NETEM_MAX];
	__u64 rate64 = 0;

	memset(&cor, 0, sizeof(cor));
	memset(&reorder, 0, sizeof(reorder));
	memset(&corrupt, 0, sizeof(corrupt));
	memset(&rate, 0, sizeof(rate));
	memset(present, 0, sizeof(present));

	for( ; argc > 0; --argc, ++argv) {
		if (matches(*argv, "limit") == 0) {
			NEXT_ARG();
			if (get_size(&opt.limit, *argv)) {
				explain1("limit");
				return -1;
			}
		} else if (matches(*argv, "latency") == 0 ||
			   matches(*argv, "delay") == 0) {
			NEXT_ARG();
			if (get_ticks(&opt.latency, *argv)) {
				explain1("latency");
				return -1;
			}

			if (NEXT_IS_NUMBER()) {
				NEXT_ARG();
				if (get_ticks(&opt.jitter, *argv)) {
					explain1("latency");
					return -1;
				}

				if (NEXT_IS_NUMBER()) {
					NEXT_ARG();
					++present[TCA_NETEM_CORR];
					if (get_percent(&cor.delay_corr, *argv)) {
						explain1("latency");
						return -1;
					}
				}
			}
		} else if (matches(*argv, "loss") == 0 ||
			   matches(*argv, "drop") == 0) {
			if (opt.loss > 0 || loss_type != NETEM_LOSS_UNSPEC) {
				explain1("duplicate loss argument\n");
				return -1;
			}

			NEXT_ARG();
			/* Old (deprecated) random loss model syntax */
			if (isdigit(argv[0][0]))
				goto random_loss_model;

			if (!strcmp(*argv, "random")) {
				NEXT_ARG();
	random_loss_model:
				if (get_percent(&opt.loss, *argv)) {
					explain1("loss percent");
					return -1;
				}
				if (NEXT_IS_NUMBER()) {
					NEXT_ARG();
					++present[TCA_NETEM_CORR];
					if (get_percent(&cor.loss_corr, *argv)) {
						explain1("loss correllation");
						return -1;
					}
				}
			} else if (!strcmp(*argv, "state")) {
				double p13;

				NEXT_ARG();
				if (parse_percent(&p13, *argv)) {
					explain1("loss p13");
					return -1;
				}

				/* set defaults */
				set_percent(&gimodel.p13, p13);
				set_percent(&gimodel.p31, 1. - p13);
				set_percent(&gimodel.p32, 0);
				set_percent(&gimodel.p23, 1.);
				set_percent(&gimodel.p14, 0);
				loss_type = NETEM_LOSS_GI;

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gimodel.p31, *argv)) {
					explain1("loss p31");
					return -1;
				}

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gimodel.p32, *argv)) {
					explain1("loss p32");
					return -1;
				}

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gimodel.p23, *argv)) {
					explain1("loss p23");
					return -1;
				}
				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gimodel.p14, *argv)) {
					explain1("loss p14");
					return -1;
				}

			} else if (!strcmp(*argv, "gemodel")) {
				NEXT_ARG();
				if (get_percent(&gemodel.p, *argv)) {
					explain1("loss gemodel p");
					return -1;
				}

				/* set defaults */
				set_percent(&gemodel.r, 1.);
				set_percent(&gemodel.h, 0);
				set_percent(&gemodel.k1, 0);
				loss_type = NETEM_LOSS_GE;

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gemodel.r, *argv)) {
					explain1("loss gemodel r");
					return -1;
				}

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gemodel.h, *argv)) {
					explain1("loss gemodel h");
					return -1;
				}
				/* netem option is "1-h" but kernel
				 * expects "h".
				 */
				gemodel.h = max_percent_value - gemodel.h;

				if (!NEXT_IS_NUMBER())
					continue;
				NEXT_ARG();
				if (get_percent(&gemodel.k1, *argv)) {
					explain1("loss gemodel k");
					return -1;
				}
			} else {
				fprintf(stderr, "Unknown loss parameter: %s\n",
					*argv);
				return -1;
			}
		} else if (matches(*argv, "ecn") == 0) {
				present[TCA_NETEM_ECN] = 1;
		} else if (matches(*argv, "reorder") == 0) {
			NEXT_ARG();
			present[TCA_NETEM_REORDER] = 1;
			if (get_percent(&reorder.probability, *argv)) {
				explain1("reorder");
				return -1;
			}
			if (NEXT_IS_NUMBER()) {
				NEXT_ARG();
				++present[TCA_NETEM_CORR];
				if (get_percent(&reorder.correlation, *argv)) {
					explain1("reorder");
					return -1;
				}
			}
		} else if (matches(*argv, "corrupt") == 0) {
			NEXT_ARG();
			present[TCA_NETEM_CORRUPT] = 1;
			if (get_percent(&corrupt.probability, *argv)) {
				explain1("corrupt");
				return -1;
			}
			if (NEXT_IS_NUMBER()) {
				NEXT_ARG();
				++present[TCA_NETEM_CORR];
				if (get_percent(&corrupt.correlation, *argv)) {
					explain1("corrupt");
					return -1;
				}
			}
		} else if (matches(*argv, "gap") == 0) {
			NEXT_ARG();
			if (get_u32(&opt.gap, *argv, 0)) {
				explain1("gap");
				return -1;
			}
		} else if (matches(*argv, "duplicate") == 0) {
			NEXT_ARG();
			if (get_percent(&opt.duplicate, *argv)) {
				explain1("duplicate");
				return -1;
			}
			if (NEXT_IS_NUMBER()) {
				NEXT_ARG();
				if (get_percent(&cor.dup_corr, *argv)) {
					explain1("duplicate");
					return -1;
				}
			}
		} else if (matches(*argv, "distribution") == 0) {
			NEXT_ARG();
			dist_data = calloc(sizeof(dist_data[0]), MAX_DIST);
			dist_size = get_distribution(*argv, dist_data, MAX_DIST);
			if (dist_size <= 0) {
				free(dist_data);
				return -1;
			}
		} else if (matches(*argv, "rate") == 0) {
			++present[TCA_NETEM_RATE];
			NEXT_ARG();
			if (get_rate64(&rate64, *argv)) {
				explain1("rate");
				return -1;
			}
			if (NEXT_IS_SIGNED_NUMBER()) {
				NEXT_ARG();
				if (get_s32(&rate.packet_overhead, *argv, 0)) {
					explain1("rate");
					return -1;
				}
			}
			if (NEXT_IS_NUMBER()) {
				NEXT_ARG();
				if (get_u32(&rate.cell_size, *argv, 0)) {
					explain1("rate");
					return -1;
				}
			}
			if (NEXT_IS_SIGNED_NUMBER()) {
				NEXT_ARG();
				if (get_s32(&rate.cell_overhead, *argv, 0)) {
					explain1("rate");
					return -1;
				}
			}
		} else if (strcmp(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "What is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
	}

	tail = NLMSG_TAIL(n);

	if (reorder.probability) {
		if (opt.latency == 0) {
			fprintf(stderr, "reordering not possible without specifying some delay\n");
			explain();
			return -1;
		}
		if (opt.gap == 0)
			opt.gap = 1;
	} else if (opt.gap > 0) {
		fprintf(stderr, "gap specified without reorder probability\n");
		explain();
		return -1;
	}

	if (present[TCA_NETEM_ECN]) {
		if (opt.loss <= 0 && loss_type == NETEM_LOSS_UNSPEC) {
			fprintf(stderr, "ecn requested without loss model\n");
			explain();
			return -1;
		}
	}

	if (dist_data && (opt.latency == 0 || opt.jitter == 0)) {
		fprintf(stderr, "distribution specified but no latency and jitter values\n");
		explain();
		return -1;
	}

	if (addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)) < 0)
		return -1;

	if (present[TCA_NETEM_CORR] &&
	    addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0)
			return -1;

	if (present[TCA_NETEM_REORDER] &&
	    addattr_l(n, 1024, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0)
		return -1;

	if (present[TCA_NETEM_ECN] &&
	    addattr_l(n, 1024, TCA_NETEM_ECN, &present[TCA_NETEM_ECN],
		      sizeof(present[TCA_NETEM_ECN])) < 0)
			return -1;

	if (present[TCA_NETEM_CORRUPT] &&
	    addattr_l(n, 1024, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0)
		return -1;

	if (loss_type != NETEM_LOSS_UNSPEC) {
		struct rtattr *start;

		start = addattr_nest(n, 1024, TCA_NETEM_LOSS | NLA_F_NESTED);
		if (loss_type == NETEM_LOSS_GI) {
			if (addattr_l(n, 1024, NETEM_LOSS_GI,
				      &gimodel, sizeof(gimodel)) < 0)
			    return -1;
		} else if (loss_type == NETEM_LOSS_GE) {
			if (addattr_l(n, 1024, NETEM_LOSS_GE,
				      &gemodel, sizeof(gemodel)) < 0)
			    return -1;
		} else {
			fprintf(stderr, "loss in the weeds!\n");
			return -1;
		}
		
		addattr_nest_end(n, start);
	}

	if (present[TCA_NETEM_RATE]) {
		if (rate64 >= (1ULL << 32)) {
			if (addattr_l(n, 1024,
				      TCA_NETEM_RATE64, &rate64, sizeof(rate64)) < 0)
				return -1;
			rate.rate = ~0U;
		} else {
			rate.rate = rate64;
		}
		if (addattr_l(n, 1024, TCA_NETEM_RATE, &rate, sizeof(rate)) < 0)
			return -1;
	}

	if (dist_data) {
		if (addattr_l(n, MAX_DIST * sizeof(dist_data[0]),
			      TCA_NETEM_DELAY_DIST,
			      dist_data, dist_size * sizeof(dist_data[0])) < 0)
			return -1;
		free(dist_data);
	}
	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
	return 0;
}

static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	const struct tc_netem_corr *cor = NULL;
	const struct tc_netem_reorder *reorder = NULL;
	const struct tc_netem_corrupt *corrupt = NULL;
	const struct tc_netem_gimodel *gimodel = NULL;
	const struct tc_netem_gemodel *gemodel = NULL;
	int *ecn = NULL;
	struct tc_netem_qopt qopt;
	const struct tc_netem_rate *rate = NULL;
	int len = RTA_PAYLOAD(opt) - sizeof(qopt);
	__u64 rate64 = 0;
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	if (len < 0) {
		fprintf(stderr, "options size error\n");
		return -1;
	}
	memcpy(&qopt, RTA_DATA(opt), sizeof(qopt));

	if (len > 0) {
		struct rtattr *tb[TCA_NETEM_MAX+1];
		parse_rtattr(tb, TCA_NETEM_MAX, RTA_DATA(opt) + sizeof(qopt),
			     len);

		if (tb[TCA_NETEM_CORR]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_CORR]) < sizeof(*cor))
				return -1;
			cor = RTA_DATA(tb[TCA_NETEM_CORR]);
		}
		if (tb[TCA_NETEM_REORDER]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_REORDER]) < sizeof(*reorder))
				return -1;
			reorder = RTA_DATA(tb[TCA_NETEM_REORDER]);
		}
		if (tb[TCA_NETEM_CORRUPT]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_CORRUPT]) < sizeof(*corrupt))
				return -1;
			corrupt = RTA_DATA(tb[TCA_NETEM_CORRUPT]);
		}
		if (tb[TCA_NETEM_LOSS]) {
			struct rtattr *lb[NETEM_LOSS_MAX + 1];

			parse_rtattr_nested(lb, NETEM_LOSS_MAX, tb[TCA_NETEM_LOSS]);
			if (lb[NETEM_LOSS_GI])
				gimodel = RTA_DATA(lb[NETEM_LOSS_GI]);
			if (lb[NETEM_LOSS_GE])
				gemodel = RTA_DATA(lb[NETEM_LOSS_GE]);
		}			
		if (tb[TCA_NETEM_RATE]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_RATE]) < sizeof(*rate))
				return -1;
			rate = RTA_DATA(tb[TCA_NETEM_RATE]);
		}
		if (tb[TCA_NETEM_ECN]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_ECN]) < sizeof(*ecn))
				return -1;
			ecn = RTA_DATA(tb[TCA_NETEM_ECN]);
		}
		if (tb[TCA_NETEM_RATE64]) {
			if (RTA_PAYLOAD(tb[TCA_NETEM_RATE64]) < sizeof(rate64))
				return -1;
			rate64 = rta_getattr_u64(tb[TCA_NETEM_RATE64]);
		}
	}

	fprintf(f, "limit %d", qopt.limit);

	if (qopt.latency) {
		fprintf(f, " delay %s", sprint_ticks(qopt.latency, b1));

		if (qopt.jitter) {
			fprintf(f, "  %s", sprint_ticks(qopt.jitter, b1));
			if (cor && cor->delay_corr)
				fprintf(f, " %s", sprint_percent(cor->delay_corr, b1));
		}
	}

	if (qopt.loss) {
		fprintf(f, " loss %s", sprint_percent(qopt.loss, b1));
		if (cor && cor->loss_corr)
			fprintf(f, " %s", sprint_percent(cor->loss_corr, b1));
	}

	if (gimodel) {
		fprintf(f, " loss state p13 %s", sprint_percent(gimodel->p13, b1));
		fprintf(f, " p31 %s", sprint_percent(gimodel->p31, b1));
		fprintf(f, " p32 %s", sprint_percent(gimodel->p32, b1));
		fprintf(f, " p23 %s", sprint_percent(gimodel->p23, b1));
		fprintf(f, " p14 %s", sprint_percent(gimodel->p14, b1));
	}

	if (gemodel) {
		fprintf(f, " loss gemodel p %s",
			sprint_percent(gemodel->p, b1));
		fprintf(f, " r %s", sprint_percent(gemodel->r, b1));
		fprintf(f, " 1-h %s", sprint_percent(max_percent_value -
						     gemodel->h, b1));
		fprintf(f, " 1-k %s", sprint_percent(gemodel->k1, b1));
	}

	if (qopt.duplicate) {
		fprintf(f, " duplicate %s",
			sprint_percent(qopt.duplicate, b1));
		if (cor && cor->dup_corr)
			fprintf(f, " %s", sprint_percent(cor->dup_corr, b1));
	}

	if (reorder && reorder->probability) {
		fprintf(f, " reorder %s",
			sprint_percent(reorder->probability, b1));
		if (reorder->correlation)
			fprintf(f, " %s",
				sprint_percent(reorder->correlation, b1));
	}

	if (corrupt && corrupt->probability) {
		fprintf(f, " corrupt %s",
			sprint_percent(corrupt->probability, b1));
		if (corrupt->correlation)
			fprintf(f, " %s",
				sprint_percent(corrupt->correlation, b1));
	}

	if (rate && rate->rate) {
		if (rate64)
			fprintf(f, " rate %s", sprint_rate(rate64, b1));
		else
			fprintf(f, " rate %s", sprint_rate(rate->rate, b1));
		if (rate->packet_overhead)
			fprintf(f, " packetoverhead %d", rate->packet_overhead);
		if (rate->cell_size)
			fprintf(f, " cellsize %u", rate->cell_size);
		if (rate->cell_overhead)
			fprintf(f, " celloverhead %d", rate->cell_overhead);
	}

	if (ecn)
		fprintf(f, " ecn ");

	if (qopt.gap)
		fprintf(f, " gap %lu", (unsigned long)qopt.gap);


	return 0;
}

struct qdisc_util netem_qdisc_util = {
	.id	   	= "netem",
	.parse_qopt	= netem_parse_opt,
	.print_qopt	= netem_print_opt,
};
示例#19
0
        InputIterator get(
            iter_type b, iter_type e,
            std::ios_base& iob,
            std::ios_base::iostate& err,
            std::tm* tm,
            char fmt, char) const
        {
            err = std::ios_base::goodbit;
            const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc());

            switch (fmt)
            {
            case 'a':
            case 'A':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_weekday(b, e, iob, err, &tm2);
                //tm->tm_wday = tm2.tm_wday;
              }
              break;
            case 'b':
            case 'B':
            case 'h':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_monthname(b, e, iob, err, &tm2);
                //tm->tm_mon = tm2.tm_mon;
              }
              break;
//            case 'c':
//              {
//                const string_type& fm = c();
//                b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
            case 'd':
            case 'e':
              get_day(tm->tm_mday, b, e, err, ct);
              break;
            case 'D':
              {
                const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'F':
              {
                const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'H':
              get_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'I':
              get_12_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'j':
              get_day_year_num(tm->tm_yday, b, e, err, ct);
              break;
            case 'm':
              get_month(tm->tm_mon, b, e, err, ct);
              break;
            case 'M':
              get_minute(tm->tm_min, b, e, err, ct);
              break;
            case 'n':
            case 't':
              get_white_space(b, e, err, ct);
              break;
//            case 'p':
//              get_am_pm(tm->tm_hour, b, e, err, ct);
//              break;
            case 'r':
              {
                const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'R':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'S':
              get_second(tm->tm_sec, b, e, err, ct);
              break;
            case 'T':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'w':
              {
                get_weekday(tm->tm_wday, b, e, err, ct);
              }
              break;
            case 'x':
              return that_.get_date(b, e, iob, err, tm);
//            case 'X':
//              return that_.get_time(b, e, iob, err, tm);
//              {
//                const string_type& fm = X();
//                b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
//            case 'y':
//              get_year(tm->tm_year, b, e, err, ct);
                break;
            case 'Y':
              get_year4(tm->tm_year, b, e, err, ct);
              break;
            case '%':
              get_percent(b, e, err, ct);
              break;
            default:
                err |= std::ios_base::failbit;
            }
            return b;
        }
示例#20
0
int exec_menu(MENU menu)
{
 int i=0, cidx=0, fine;
 int off, ecnt=1;
 char tmp[MAXLEN];
 char output[MAXLEN];
 MENU tmenu = menu;
 int ret;
 int cpid;

 fine=1;
 while(cidx < tmenu.ncmd && fine)
 {
  off=1;
  switch(tmenu.cmd[cidx][0])
  {
   case '-':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	cpid = fork();
	if(cpid)
	{
	 waitpid(cpid,&ret,0);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	}
	else
	{
	 close(comport);
	 ret=system(tmp);
	 if(ret!=-1 && WIFEXITED(ret)) 
	  ret = WEXITSTATUS(ret);
	 exit(ret);
	}
	if(off==1) ret=1;
	break;
   case '+':
   	if(*(tmenu.cmd[cidx] + off)=='!') off++;
   	parsecmd(tmenu.cmd[cidx] +off, tmp);
	ret=execute(tmp, output, MAXLEN);
	sprintf(tmp, "$%d", ecnt++);
	setvar(tmp, output);
	if(off==1) ret=1;
	break;
   case '<':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"YesNo")==0 && argcnt==2)
	{
	 ret=get_yesno(args[1]);
	 sprintf(output,"%d",ret-1);
	 setvar("$YesNo",output);
	}
	if(strcmp(args[0],"OnOff")==0 && argcnt==3)
	{
	 ret=get_onoff(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret-1);
	 setvar("$OnOff",output);
	}
	if(strcmp(args[0],"Percent")==0 && argcnt==4)
	{
	 ret=get_percent(args[1], atoi(args[2]), atoi(args[3]));
	 sprintf(output,"%d",ret-1);
	 setvar("$Percent",output);
	}
	if(strcmp(args[0],"Choice")==0 && argcnt>=4)
	{
	 init_choice();
	 for(i=3; i<argcnt; i++)
	  addchoice(args[i]);
	 ret=get_choice(args[1], atoi(args[2]));
	 sprintf(output,"%d",ret);
	 setvar("$Choice",output);
	}
	if(strcmp(args[0],"Real")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_real(output, args[1], args[2], args[3], args[4]);
	 setvar("$Real",output);
	}
	if(strcmp(args[0],"Int")==0 && (argcnt==5 || argcnt==6))
	{
	 if(argcnt==5) strcpy(args[5],"0");
	 ret=get_integer(output, args[1], args[2], atoi(args[3]), atoi(args[4]), atoi(args[5]));
	 setvar("$Int",output);
	}
	if(strcmp(args[0],"Phone")==0 && (argcnt==3 || argcnt==4))
	{
	 if(argcnt==3) strcpy(args[3],"");
	 ret=get_phone(output, args[1], args[2], args[3]);
	 setvar("$Phone",output);
	}
	if(strcmp(args[0],"Date")==0 && argcnt==2)
	{
	 ret=get_date(output, args[1]);
	 setvar("$Date",output);
	}
	if(strcmp(args[0],"Text")==0 && (argcnt==4 || argcnt==5))
	{
	 if(argcnt==4) strcpy(args[4],"");
	 ret=get_text(output, args[1], args[2], atoi(args[3]), args[4]);
	 setvar("$Text",output);
	}
	if(strcmp(args[0],"Secret")==0 && argcnt==4)
	{
	 ret=get_secret(output, args[1], args[2], atoi(args[3]));
	 setvar("$Secret",output);
	}
	break;
   case '>':
	argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN);
	substvar(args[0], MAXARGS, MAXARGLEN);
  	/*for(i=0; i<argcnt; i++)
   	 printf("%d: --%s--\n",i,args[i]);*/
	if(strcmp(args[0],"MsgBox")==0 && (argcnt==2 || argcnt==3))
	{
	 if(argcnt==2) strcpy(args[2],"");
	 ret=msgbox(args[1], atoi(args[2]));
	}
	if(strcmp(args[0],"Info")==0 && argcnt>=3)
	 ret=info(args[1], args[2]);
	if(strcmp(args[0],"Status")==0 && argcnt>=2)
	 ret=status(args[1]);
	break;
   case ':':
   	for(i=0; i<fncnt; i++)
	 if(strcmp(tmenu.cmd[cidx]+1,flist[i].name)==0)
	  ret = flist[i].fn();
	break;
  }
  if(ret<=0) fine=0;
  cidx++;
 }
 return 0;
}