Exemplo n.º 1
0
void printt(struct syntax_tree* t, int n){
	int i;
	if(t == 0)
		return;
	if(t->type == 1 && t->leftson != 0){
		for(i = 0; i < n; i++)
			printf("  ");
		printf("%s (%d)\n", t->name, t->line);
	}
	else if(t->type == 0){
		for(i = 0; i < n; i++)
			printf("  ");
		printf("%s", t->name);
		if(strcmp(t->name, "INT") == 0){
			printf(": %d", t->value.intval);
		}
		else if(strcmp(t->name, "FLOAT") == 0){
			printf(": %f", t->value.floval);
		}
		else if(strcmp(t->name, "ID") == 0){
			printf(": %s", t->value.idval);
		}
		else if(strcmp(t->name, "TYPE") == 0){
			if(t->value.intval == 1)
				printf(": int");
			else
				printf(": float");
		}
		printf("\n");
	}
	printt(t->leftson, n+1);
	printt(t->rightbrother, n);
}
Exemplo n.º 2
0
void printt(TreeNode* t) {
  if (t == NULL) {
    printf("N ");
    return;
  }
  printt(t->left);
  printf("%d ", t->val);
  printt(t->right);
}
Exemplo n.º 3
0
void printt(TreeNode* t) {
  if (t) {
    printf("%d ", t->val);
    printt(t->left);
    printt(t->right);
  } else {
    printf("N ");
  }
}
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
	struct cryptostats stats;
	size_t slen;

	slen = sizeof (stats);
	if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
		err(1, "kern.cryptostats");

	if (argc > 1 && strcmp(argv[1], "-z") == 0) {
		bzero(&stats.cs_invoke, sizeof (stats.cs_invoke));
		bzero(&stats.cs_done, sizeof (stats.cs_done));
		bzero(&stats.cs_cb, sizeof (stats.cs_cb));
		bzero(&stats.cs_finis, sizeof (stats.cs_finis));
		stats.cs_invoke.min.tv_sec = 10000;
		stats.cs_done.min.tv_sec = 10000;
		stats.cs_cb.min.tv_sec = 10000;
		stats.cs_finis.min.tv_sec = 10000;
		if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
			err(1, "kern.cryptostats");
		exit(0);
	}
	if (argc > 1 && strcmp(argv[1], "-Z") == 0) {
		bzero(&stats, sizeof (stats));
		stats.cs_invoke.min.tv_sec = 10000;
		stats.cs_done.min.tv_sec = 10000;
		stats.cs_cb.min.tv_sec = 10000;
		stats.cs_finis.min.tv_sec = 10000;
		if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
			err(1, "kern.cryptostats");
		exit(0);
	}


	printf("%u symmetric crypto ops (%u errors, %u times driver blocked)\n"
		, stats.cs_ops, stats.cs_errs, stats.cs_blocks);
	printf("%u key ops (%u errors, %u times driver blocked)\n"
		, stats.cs_kops, stats.cs_kerrs, stats.cs_kblocks);
	printf("%u crypto dispatch thread activations\n", stats.cs_intrs);
	printf("%u crypto return thread activations\n", stats.cs_rets);
	if (stats.cs_invoke.count) {
		printf("\n");
		printt("dispatch->invoke", &stats.cs_invoke);
		printt("invoke->done", &stats.cs_done);
		printt("done->cb", &stats.cs_cb);
		printt("cb->finis", &stats.cs_finis);
	}
	return 0;
}
Exemplo n.º 5
0
void lower_case(char s[]) {
	double op1,op2;
	if(strcmp(s, "pow") == 0) {
		push(pow(pop(), pop()));
	}
	if(strcmp(s, "sin") == 0) {
		push(sin(pop()));
	}
	if(strcmp(s, "cos") == 0) {
		push(cos(pop()));
	}
	if(strcmp(s, "tan") == 0) {
		push(tan(pop()));
	}
	if(strcmp(s, "p") == 0) {
		printt();
	}
	if(strcmp(s, "c") == 0) {
		my_clear();
	}
	if(strcmp(s, "s") == 0) {
		op2 = pop();
		op1 = pop();
		push(op2);
		push(op1);
	}
	if(strcmp(s, "d") == 0) {
		op2 = pop();
		push(op2);
		push(op2);
	}
}
Exemplo n.º 6
0
int cls_loop(struct __sk_buff *skb)
{
	printt("cb: %u\n", skb->cb[0]++);
	tail_call(skb, &jmp_tc, 0);

	skb->tc_classid = TC_H_MAKE(1, 42);
	return TC_ACT_OK;
}
int main()
{

    srand(time(NULL));
    int count =25;
    for(int i=0;i<5;i++){
        for(int j=4;j!=-1;j--){
            array[i][j]=count--;
        }
    }
    printt();
    selectionsort();
    printf("after selection sort\n");
    printt();
    spiral();
    printf("after spiral\n");
    printtt();
    return 0;
}
Exemplo n.º 8
0
int main() {
  ListNode* h = new ListNode(-10, new ListNode(-3, new ListNode(0, new ListNode(5, new ListNode(9)))));

  Solution s;
  TreeNode* t = s.sortedListToBST(h);

  printt(t);
  printf("\n");
  
  return 0;
}
Exemplo n.º 9
0
int imain(struct __sk_buff *skb)
{
	struct bpf_elf_map *map_inner;
	int key = 0, *val;

	map_inner = map_lookup_elem(&map_outer, &key);
	if (map_inner) {
		val = map_lookup_elem(map_inner, &key);
		if (val)
			printt("map val: %d\n", *val);
	}

	return BPF_H_DEFAULT;
}
Exemplo n.º 10
0
int main() {
  TreeNode* t = new TreeNode(
      5,
      new TreeNode(
          3,
          new TreeNode(2),
          new TreeNode(4)),
      new TreeNode(
          6, NULL,
          new TreeNode(7)));
  Solution sln;
  t = sln.deleteNode(t, 3);
  printt(t);
  printf("\n");
  return 0;
}
Exemplo n.º 11
0
int main(void)
{
    int t;

    t = 0;
    if (t) printt(t, "failure"); else printt(t, "success");
    t = 1;
    if (t) printt(t, "success"); else printt(t, "failure");
    t = 8;
    if (t) printt(t, "success"); else printt(t, "failure");
    t = -2;
    if (t) printt(t, "success"); else printt(t, "failure");
    printf("\n");

    t = 4;
    printf("switch test: ");
    switch (t) {
    case 3:
        printf("failure");
        break;
    case 4:
        printf("success");
        break;
    case 5:
        printf("failure");
        break;
    }
    printf("\n");

    printf("switch fallthrough test: ");
    switch (t) {
    case 3:
        printf("failure");
        break;
    case 4:
        printf("OKSOFAR: ");
    case 5:
        printf("success if oksofar printed before this in caps");
        break;
    }
    printf("\n");
}
Exemplo n.º 12
0
static void
runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int profile)
{
    int i, status;
    double t;
    void *region;
    struct timeval *tvp;
    struct timeval total;
    int otiming;

    if (size % alg->blocksize) {
        if (verbose)
            printf("skipping blocksize %u 'cuz not a multiple of "
                   "%s blocksize %u\n",
                   size, alg->name, alg->blocksize);
        return;
    }

    region = mmap(NULL, threads * sizeof (struct timeval),
                  PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
    if (region == MAP_FAILED) {
        perror("mmap");
        return;
    }
    tvp = (struct timeval *) region;
#ifdef __FreeBSD__
    if (profile) {
        size_t tlen = sizeof (otiming);
        int timing = 1;

        resetstats();
        if (sysctlbyname("debug.crypto_timing", &otiming, &tlen,
                         &timing, sizeof (timing)) < 0)
            perror("debug.crypto_timing");
    }
#endif

    if (threads > 1) {
        for (i = 0; i < threads; i++)
            if (fork() == 0) {
                runtest(alg, count, size, cmd, &tvp[i]);
                exit(0);
            }
        while (waitpid(WAIT_MYPGRP, &status, 0) != -1)
            ;
    } else
        runtest(alg, count, size, cmd, tvp);

    t = 0;
    for (i = 0; i < threads; i++)
        t += (((double)tvp[i].tv_sec * 1000000 + tvp[i].tv_usec) / 1000000);
    if (t) {
        int nops = alg->ishash ? count : 2*count;

#if 0
        t /= threads;
        printf("%6.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
               t, nops, alg->name, size, (double)nops*size / t,
               (double)nops*size / t * 8 / 1024 / 1024);
#else
        nops *= threads;
        printf("%8.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
               t, nops, alg->name, size, (double)nops*size / t,
               (double)nops*size / t * 8 / 1024 / 1024);
#endif
    }
#ifdef __FreeBSD__
    if (profile) {
        struct cryptostats stats;
        size_t slen = sizeof (stats);

        if (sysctlbyname("debug.crypto_timing", NULL, NULL,
                         &otiming, sizeof (otiming)) < 0)
            perror("debug.crypto_timing");
        if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
            perror("kern.cryptostats");
        if (stats.cs_invoke.count) {
            printt("dispatch->invoke", &stats.cs_invoke);
            printt("invoke->done", &stats.cs_done);
            printt("done->cb", &stats.cs_cb);
            printt("cb->finis", &stats.cs_finis);
        }
    }
#endif
    fflush(stdout);
}
Exemplo n.º 13
0
int
main(int argc, char **argv)
{
	struct	tms buffer, obuffer;
	int	status;
	register pid_t	p;
	int	c;
	hrtime_t before, after, timediff;
	char	stime[9], etime[9];
	char	cmd[80];
	int	pflg = 0, sflg = 0, oflg = 0;
	char	aopt[25];
	FILE	*pipin;
	char	ttyid[12], line[150];
	char	eol;
	char	fld[20][12];
	int	iline = 0, i, nfld;
	int	ichar, iblok;
	long	chars = 0, bloks = 0;

	aopt[0] = '\0';

	hz = sysconf(_SC_CLK_TCK);
	nsec_per_tick = NANOSEC / hz;

	/* check options; */
	while ((c = getopt(argc, argv, "sopfhkmrt")) != EOF)
		switch (c)  {
		case 's':  sflg++;  break;
		case 'o':  oflg++;  break;
		case 'p':  pflg++;  break;

		case 'f':  strcat(aopt, "-f ");  break;
		case 'h':  strcat(aopt, "-h ");  break;
		case 'k':  strcat(aopt, "-k ");  break;
		case 'm':  strcat(aopt, "-m ");  break;
		case 'r':  strcat(aopt, "-r ");  break;
		case 't':  strcat(aopt, "-t ");  break;

		case '?':  usage();
				break;
		}
	if (optind >= argc) {
		fprintf(stderr, "timex: Missing command\n");
		usage();
	}

	/*
	 * Check to see if accounting is installed and print a somewhat
	 * meaninful message if not.
	 */
	if (((oflg+pflg) != 0) && (access("/usr/bin/acctcom", 01) == -1)) {
		oflg = 0;
		pflg = 0;
		fprintf(stderr,
		    "Information from -p and -o options not available\n");
		fprintf(stderr,
		    " because process accounting is not operational.\n");
	}

	if (sflg) {
		sprintf(fname, "/tmp/tmx%ld", getpid());
		sprintf(cmd, "/usr/lib/sa/sadc 1 1 %s", fname);
		system(cmd);
	}
	if (pflg + oflg) hmstime(stime);
	before = gethrtime();
	(void) times(&obuffer);
	if ((p = fork()) == (pid_t)-1) {
		perror("Fork Failed");
		(void) unlink(fname);
		exit(EXIT_FAILURE);
	}
	if (p == 0) {
		setgid(getgid());
		execvp(*(argv+optind), (argv+optind));
		fprintf(stderr, "%s: %s\n", *(argv+optind), strerror(errno));
		exit(EXIT_FAILURE);
	}
	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	while (wait(&status) != p)
		;
	if ((status&0377) != 0)
		fprintf(stderr, "Command terminated abnormally.\n");
	signal(SIGINT, SIG_DFL);
	signal(SIGQUIT, SIG_DFL);
	(void) times(&buffer);
	after = gethrtime();
	timediff = after - before;
	if (pflg + oflg) hmstime(etime);
	if (sflg) system(cmd);

	fprintf(stderr, "\n");
	printt("real", NSEC_TO_TICK_ROUNDUP(timediff));
	printt("user", buffer.tms_cutime - obuffer.tms_cutime);
	printt("sys ", buffer.tms_cstime - obuffer.tms_cstime);
	fprintf(stderr, "\n");

	if (oflg+pflg) {
		if (isatty(0))
			sprintf(ttyid, "-l %s", ttyname(0)+5);
		sprintf(cmd, "acctcom -S %s -E %s -u %s %s -i %s",
		    stime, etime, getpwuid(getuid())->pw_name, ttyid, aopt);
		pipin = popen(cmd, "r");
		while (fscanf(pipin, "%[^\n]%1c", line, &eol) > 1) {
			if (pflg)
				fprintf(stderr, "%s\n", line);
			if (oflg)  {
				nfld = sscanf(line,
				    "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
				    fld[0], fld[1], fld[2], fld[3], fld[4],
				    fld[5], fld[6], fld[7], fld[8], fld[9],
				    fld[10], fld[11], fld[12], fld[13], fld[14],
				    fld[15], fld[16], fld[17], fld[18],
				    fld[19]);
				if (++iline == 3)
					for (i = 0; i < nfld; i++)  {
						if (strcmp(fld[i], "CHARS")
						    == 0)
							ichar = i+2;
						if (strcmp(fld[i], "BLOCKS")
						    == 0)
							iblok = i+2;
					}
				if (iline > 4)  {
					chars += atol(fld[ichar]);
					bloks += atol(fld[iblok]);
				}
			}
		}
		pclose(pipin);

		if (oflg)
			if (iline > 4)
				fprintf(stderr,
				    "\nCHARS TRNSFD = %ld\n"
				    "BLOCKS READ  = %ld\n", chars, bloks);
			else
				fprintf(stderr,
				    "\nNo process records found!\n");
	}

	if (sflg)  {
		sprintf(cmd, "/usr/bin/sar -ubdycwaqvmpgrk -f %s 1>&2", fname);
		system(cmd);
		unlink(fname);
	}
	exit(WEXITSTATUS(status));
}
Exemplo n.º 14
0
void print_tree(){
	printt(root, 0);
}