예제 #1
0
static void process_options(int argc, char **argv)
{
	int c;

	while (1) {
		c = getopt_long(argc, argv, "hb:c:s:v", options, NULL);
		if (c == -1)
			break;

		switch (c) {
		case 'v':
			if (flags & FLAG_VERBOSE)
				goto failmulti;
			flags |= FLAG_VERBOSE;
			break;
		case 'b':
			if (peb >= 0)
				goto failmulti;
			peb = read_num(c, optarg);
			if (peb < 0)
				goto failarg;
			break;
		case 'c':
			if (count >= 0)
				goto failmulti;
			count = read_num(c, optarg);
			if (count < 0)
				goto failarg;
			break;
		case 's':
			if (skip >= 0)
				goto failmulti;
			skip = read_num(c, optarg);
			if (skip < 0)
				goto failarg;
			break;
		case 'h':
			usage(EXIT_SUCCESS);
		default:
			exit(EXIT_FAILURE);
		}
	}

	if (optind < argc)
		mtddev = argv[optind++];
	else
		errmsg_die("No device specified!\n");

	if (optind < argc)
		usage(EXIT_FAILURE);
	if (peb < 0)
		peb = 0;
	if (skip < 0)
		skip = 0;
	return;
failmulti:
	errmsg_die("'-%c' specified more than once!", c);
failarg:
	errmsg_die("Invalid argument for '-%c'!", c);
}
예제 #2
0
파일: incremen.c 프로젝트: Distrotech/tar
/* Read incremental snapshot format 2 */
static void
read_incr_db_2 (void)
{
  struct obstack stk;
  char offbuf[INT_BUFSIZE_BOUND (off_t)];

  obstack_init (&stk);

  read_timespec (listed_incremental_stream, &newer_mtime_option);

  for (;;)
    {
      intmax_t i;
      struct timespec mtime;
      dev_t dev;
      ino_t ino;
      bool nfs;
      char *name;
      char *content;
      size_t s;

      if (! read_num (listed_incremental_stream, "nfs", 0, 1, &i))
	return; /* Normal return */

      nfs = i;

      read_timespec (listed_incremental_stream, &mtime);

      if (! read_num (listed_incremental_stream, "dev",
		      TYPE_MINIMUM (dev_t), TYPE_MAXIMUM (dev_t), &i))
	break;
      dev = i;

      if (! read_num (listed_incremental_stream, "ino",
		      TYPE_MINIMUM (ino_t), TYPE_MAXIMUM (ino_t), &i))
	break;
      ino = i;

      if (read_obstack (listed_incremental_stream, &stk, &s))
	break;

      name = obstack_finish (&stk);

      while (read_obstack (listed_incremental_stream, &stk, &s) == 0 && s > 1)
	;
      if (getc (listed_incremental_stream) != 0)
	FATAL_ERROR ((0, 0, _("%s: byte %s: %s"),
		      quotearg_colon (listed_incremental_option),
		      offtostr (ftello (listed_incremental_stream), offbuf),
		      _("Missing record terminator")));

      content = obstack_finish (&stk);
      note_directory (name, mtime, dev, ino, nfs, false, content);
      obstack_free (&stk, content);
    }
  FATAL_ERROR ((0, 0, "%s: %s",
		quotearg_colon (listed_incremental_option),
		_("Unexpected EOF in snapshot file")));
}
예제 #3
0
/* Original serializer */
int lisp_compare1(DB *dbp, const DBT *a, const DBT *b) {
  int difference;
  double ddifference;
  unsigned char *ad, *bd, at, bt;
  ad = (unsigned char *)a->data;
  bd = (unsigned char *)b->data;

  /* Compare OIDs. */
  difference = read_int(ad, 0) - read_int(bd, 0);
  if (difference) return difference;
  
  /* Have a type tag? */
  if (a->size == 4) 
    if (b->size == 4)
      return 0;
    else
      return -1;
  else if (b->size == 4) 
    return 1;

  at = ad[4]; bt = bd[4];

  /* Compare numerics. */
  if (type_numeric1(at) && type_numeric1(bt)) {
    ddifference = read_num(ad+4) - read_num(bd+4);
    if (ddifference > 0) return 1;
    else if (ddifference < 0) return -1;
    return 0;
  }

  /* Compare types. */
  /* ISE: need extra conditional here...forget why, so research it */
  difference = at - bt;
  if (difference) return difference;

  /* Same type! */
  switch (at) {
  case S1_NIL: /* nil */
    return 0;
  case S_RESERVED:
    return ad[5] < bd[5]; /* different tags */
  case S1_UCS1_SYMBOL: /* 8-bit symbol */
  case S1_UCS1_STRING: /* 8-bit string */
  case S1_UCS1_PATHNAME: /* 8-bit pathname */
    return case_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case S1_UCS2_SYMBOL:  /* 16-bit symbol */
  case S1_UCS2_STRING: /* 16-bit string */
  case S1_UCS2_PATHNAME: /* 16-bit pathname */
    return utf16_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case S1_UCS4_SYMBOL:
  case S1_UCS4_STRING:
  case S1_UCS4_PATHNAME:
    return wcs_cmp((wchar_t*)ad+9, read_int(ad, 5), (wchar_t*)bd+9, read_int(bd, 5)); 
  default:
    return lex_cmp(ad+5, (a->size)-5, bd+5, (b->size)-5);
  }
}
예제 #4
0
/* Read incremental snapshot format 2 */
static void
read_incr_db_2 ()
{
  uintmax_t u;
  struct obstack stk;

  obstack_init (&stk);

  read_timespec (listed_incremental_stream, &newer_mtime_option);

  for (;;)
    {
      struct timespec mtime;
      dev_t dev;
      ino_t ino;
      bool nfs;
      char *name;
      char *content;
      size_t s;

      if (read_num (listed_incremental_stream, 1, &u))
	return; /* Normal return */

      nfs = u;

      read_timespec (listed_incremental_stream, &mtime);

      if (read_num (listed_incremental_stream, TYPE_MAXIMUM (dev_t), &u))
	break;
      dev = u;

      if (read_num (listed_incremental_stream, TYPE_MAXIMUM (ino_t), &u))
	break;
      ino = u;

      if (read_obstack (listed_incremental_stream, &stk, &s))
	break;

      name = obstack_finish (&stk);

      while (read_obstack (listed_incremental_stream, &stk, &s) == 0 && s > 1)
	;
      if (getc (listed_incremental_stream) != 0)
	FATAL_ERROR ((0, 0, "%s: %s",
		      quotearg_colon (listed_incremental_option),
		      _("Missing record terminator")));

      content = obstack_finish (&stk);
      note_directory (name, mtime, dev, ino, nfs, false, content);
      obstack_free (&stk, content);
    }
  FATAL_ERROR ((0, 0, "%s: %s",
		quotearg_colon (listed_incremental_option),
		_("Unexpected EOF in snapshot file")));
}
예제 #5
0
void print_bal(char *amount, char *AoM)
{
    //printf("%s\n",amount);
    //double a=atof(amount)*100;
    double a=atof(amount);
    //printf("%f\n",a);
    //long long amounttobal =(long long) (a/1);
    //printf("%llu\n",amounttobal);
    if(*AoM == '-')
        //balance=balance - amounttobal;
        balance=balance - a;
    else
        //balance=balance + amounttobal;
        balance=balance + a;

    if(balance > 1000000000)
    {
        char *Large = tooLarge;
        //if(balance < 0)
        //    printf(" (%s) ", Large);
        if(balance > 0)
            printf("  %s  ", Large);
    }
    else if(balance < -1000000000)
    {
        char *Large = tooLarge;
        printf(" (%s) ", Large);
    }
    else
    {
        //double printBalance = (double)balance/100;
        char tochange[14];
        char *toprint;
        //char printsign;
        if(balance <0)
        {
            //printBalance=balance*(-1);
            //printsign = '-';
            //sprintf(tochange,"%llu.%02llu",(balance*(-1))/100,(balance*(-1))%100);
            sprintf(tochange,"%.2f",balance*(-1));
            toprint=read_num(tochange);
            printf(" (%12s) ", toprint);
        }
        else
        {
            //printsign = '+';
            //sprintf(tochange,"%llu.%02llu",balance/100,balance%100);
            sprintf(tochange,"%.2f",balance);
            toprint=read_num(tochange);
            printf("  %12s  ", toprint);
        }
    }

}
예제 #6
0
파일: randfile.c 프로젝트: aurora/rzh
static void process_args(int argc, char **argv)
{
	while(1) {
		int c;
		int optidx = 0; 
		static struct option long_options[] = {
			// name, has_arg (1=reqd,2=opt), flag, val
			{"seed", 1, 0, 'r'},
			{"size", 1, 0, 's'},
			{"check", 0, 0, 'c'},
			{"help", 0, 0, 'h'},
			{"version", 0, 0, 'V'},
			{0, 0, 0, 0},
		};

		c = getopt_long(argc, argv, "hr:s:cV", long_options, &optidx);
		if(c == -1) break;

		switch(c) {
			case 'c':
				opt_check++;
				break;

			case 'r':
				opt_seed = read_num(optarg);
				break;

			case 's':
				opt_size = read_num(optarg);
				break;

			case 'h':
				usage();
				exit(0);

			case 'V':
				printf("randfile version %s\n", VERSION);
				exit(0);
		}
	}

	// but supplying more than one directory is an error.
	if(optind < argc) {
		fprintf(stderr, "Unrecognized arguments: ");
		while(optind < argc) {
			fprintf(stderr, "%s ", argv[optind++]);
		}
		fprintf(stderr, "\n");
		exit(exit_cmdline_error);
	}
}
예제 #7
0
static void
read_next(ParseInfo pi, const char *key) {
    VALUE	obj;

    if ((void*)&obj < pi->stack_min) {
	rb_raise(rb_eSysStackError, "JSON is too deeply nested");
    }
    next_non_white(pi);	/* skip white space */
    switch (*pi->s) {
    case '{':
	read_hash(pi, key);
	break;
    case '[':
	read_array(pi, key);
	break;
    case '"':
	read_str(pi, key);
	break;
    case '+':
    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
	read_num(pi, key);
	break;
    case 'I':
	read_num(pi, key);
	break;
    case 't':
	read_true(pi, key);
	break;
    case 'f':
	read_false(pi, key);
	break;
    case 'n':
	read_nil(pi, key);
	break;
    case '\0':
	return;
    default:
	return;
    }
}
예제 #8
0
/*
 *	x^3
 *	2x^2
 *	2x
 *	x
 *	2
 *
 */
void make_term(const char** str_p, poly_t* p)
{
	printf("Entering make_term...\n");

	signed char	sign;
	int		exp;
	int		coeff	= 1;
	const char*	str	= *str_p;

	sign = isminus(*str)
		? -1
		: +1;

	while (isspace(*str)) {
		str++;
	}

	if (isdigit(*str)) {
		coeff = sign * read_num(str);
	}

	if (isvar(*str)) {
		if (*(str + 1) == '^') {
			str++;
			str++;
		} else {
			str++;
		}
	}

	exp = read_num(str);

	*str_p = ++str;

	if (exp + 1 > p->size) {
		int old_size = p->size;
		p->size	= exp + 1;
		// TODO Check return value.
		int* new_coeffs = calloc(p->size, sizeof(int));
		memcpy(new_coeffs, p->coeffs, old_size * sizeof(int));
		free(p->coeffs);
		p->coeffs = new_coeffs;
	}

	p->coeffs[exp] = coeff;

	printf("    term: coeff = %d, exp = %d\n", coeff, exp);
}
예제 #9
0
파일: scanner.cpp 프로젝트: nlsynth/nli
int Scanner::GetToken(int *sub) {
  *sub = 0;
  skip_non_token();
  //
  char c = cur_char();
  if (is_dec(c)) {
    return read_num();
  }
  //
  struct OperatorTableEntry *op = lookup_op();
  if (op) {
    int r;
    r = read_op(op);
    *sub = op->sub_op;
    return r;
  }
  //
  if (c == '\"') {
    return read_str();
  }
  if (is_symhead(c)) {
    return read_sym();
  }
  return -1;
}
예제 #10
0
static void
read_timespec (FILE *fp, struct timespec *pval)
{
  int c = getc (fp);
  intmax_t i;
  uintmax_t u;

  if (c == '-')
    {
      read_negative_num (fp, TYPE_MINIMUM (time_t), &i);
      c = 0;
      pval->tv_sec = i;
    }
  else
    {
      c = read_unsigned_num (c, fp, TYPE_MAXIMUM (time_t), &u);
      pval->tv_sec = u;
    }

  if (c || read_num (fp, BILLION - 1, &u))
    FATAL_ERROR ((0, 0, "%s: %s",
		  quotearg_colon (listed_incremental_option),
		  _("Unexpected EOF in snapshot file")));
  pval->tv_nsec = u;
}
예제 #11
0
int main() {
    int n, m;
    while (EOF != scanf("%d%d", &n, &m)) {
        s[0] = 0;
        for (int i = 1; i <= n; ++i) {
            read_num(&s[i]);
            s[i] += s[i-1];
        }
        int fr = 0, ta = 1;
        f[0] = 0;
        q[0] = 0;
        for (int i = 1; i <= n; ++i) {
            while (fr+1<ta && (f[q[fr+1]]+SQ(s[q[fr+1]])-f[q[fr]]-SQ(s[q[fr]])) <= s[i]*2*(s[q[fr+1]]-s[q[fr]])) {
                ++fr;
            }
            f[i] = f[q[fr]] + m + SQ(s[i] - s[q[fr]]);
            while (fr<ta-1 &&
                    cross(
                        s[i]-s[q[ta-1]], f[i]+SQ(s[i])-f[q[ta-1]]-SQ(s[q[ta-1]]),
                        s[q[ta-2]]-s[q[ta-1]], f[q[ta-2]]+SQ(s[q[ta-2]])-f[q[ta-1]]-SQ(s[q[ta-1]])
                    ) <= 0)
            {
                --ta;
            }
            q[ta++] = i;
        }
        printf("%lld\n", f[n]);
    }
    return 0;
}
예제 #12
0
파일: parser.c 프로젝트: ma2rten/c2seq
int read_sequence(FILE* f, int** seq, int* len, int max_sequence, int EOS) {
    int i;
    int code = END_NUM;
    int X[max_sequence];

    for(i = 0; code == END_NUM; i++) {
        code = read_num(f, X + i);

        if(i == max_sequence) {
            fprintf(stderr, "ERROR: input too long\n");
            exit(-1);
        }
    }

    if(X[i-1] == -1) {
        i--;
    }

    if(code == END_PAIR && i == 0) {
        return 1;
    }

    *len = i;
    *seq = malloc(sizeof(int) * i);
    memcpy(*seq, X, sizeof(int) * i);

    if(code != EOS) {
        fprintf(stderr, "ERROR: invalid file format\n");
        exit(-1);
    }

    return 0;
}
예제 #13
0
AST_expr* readASTExpr(BufferedReader* reader) {
    uint8_t type = reader->readByte();
    if (VERBOSITY("parsing") >= 2)
        printf("type = %d\n", type);
    if (type == 0)
        return NULL;

    uint8_t checkbyte = reader->readByte();
    assert(checkbyte == 0xae);

    switch (type) {
        case AST_TYPE::Attribute:
            return read_attribute(reader);
        case AST_TYPE::BinOp:
            return read_binop(reader);
        case AST_TYPE::BoolOp:
            return read_boolop(reader);
        case AST_TYPE::Call:
            return read_call(reader);
        case AST_TYPE::Compare:
            return read_compare(reader);
        case AST_TYPE::Dict:
            return read_dict(reader);
        case AST_TYPE::DictComp:
            return read_dictcomp(reader);
        case AST_TYPE::IfExp:
            return read_ifexp(reader);
        case AST_TYPE::Index:
            return read_index(reader);
        case AST_TYPE::Lambda:
            return read_lambda(reader);
        case AST_TYPE::List:
            return read_list(reader);
        case AST_TYPE::ListComp:
            return read_listcomp(reader);
        case AST_TYPE::Name:
            return read_name(reader);
        case AST_TYPE::Num:
            return read_num(reader);
        case AST_TYPE::Repr:
            return read_repr(reader);
        case AST_TYPE::Slice:
            return read_slice(reader);
        case AST_TYPE::Str:
            return read_str(reader);
        case AST_TYPE::Subscript:
            return read_subscript(reader);
        case AST_TYPE::Tuple:
            return read_tuple(reader);
        case AST_TYPE::UnaryOp:
            return read_unaryop(reader);
        default:
            fprintf(stderr, "Unknown expr node type (parser.cpp:" STRINGIFY(__LINE__) "): %d\n", type);
            abort();
            break;
    }
}
예제 #14
0
파일: incremen.c 프로젝트: Distrotech/tar
static void
read_timespec (FILE *fp, struct timespec *pval)
{
  intmax_t s, ns;

  if (read_num (fp, "sec", TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t), &s)
      && read_num (fp, "nsec", 0, BILLION - 1, &ns))
    {
      pval->tv_sec = s;
      pval->tv_nsec = ns;
    }
  else
    {
      FATAL_ERROR ((0, 0, "%s: %s",
		    quotearg_colon (listed_incremental_option),
		    _("Unexpected EOF in snapshot file")));
    }
}
예제 #15
0
void print_TAm(char *amount, char *sgn)
{
    char *print_amount = read_num(amount);
    if(*sgn == '-')
        printf(" (%12s) ", print_amount);
    else
        printf("  %12s  ", print_amount);

}
예제 #16
0
/*
 * Parse a sequence into an array of sorted & merged ranges.
 */
EXPORTED struct seqset *seqset_parse(const char *sequence,
			    struct seqset *set,
			    unsigned maxval)
{
    unsigned start = 0, end = 0;

    /* short circuit no sequence */
    if (!sequence) return NULL;

    if (!set) set = seqset_init(maxval, SEQ_SPARSE);

    while (*sequence) {
	if (read_num(&sequence, maxval, &start))
	    fatal("invalid sequence", EC_SOFTWARE);
	if (*sequence == ':') {
	    sequence++;
	    if (read_num(&sequence, maxval, &end))
		fatal("invalid sequence", EC_SOFTWARE);
	}
	else 
	    end = start;
	if (start > end) {
	    unsigned i = end;
	    end = start;
	    start = i;
	}

	if (set->len == set->alloc) {
	    set->alloc += SETGROWSIZE;
	    set->set = xrealloc(set->set, set->alloc * sizeof(struct seq_range));
	}
	set->set[set->len].low = start;
	set->set[set->len].high = end;
	set->len++;

	if (*sequence == ',')
	    sequence++;
	/* could test for invalid chars here, but the number parser next
	 * time through will grab them, so no need */
    }

    seqset_simplify(set);
    return set;
}
예제 #17
0
char *str_ulong_vec(struct supersect *ss, const unsigned long *const *datap,
		    const unsigned long *sizep)
{
	struct supersect *data_ss;
	const unsigned long *data =
	    read_pointer(ss, (void *const *)datap, &data_ss);
	unsigned long size = read_num(ss, sizep);

	char *buf = NULL;
	size_t bufsize = 0;
	FILE *fp = open_memstream(&buf, &bufsize);
	fprintf(fp, "[ ");
	size_t i;
	for (i = 0; i < size; ++i)
		fprintf(fp, "%lx ", read_num(data_ss, &data[i]));
	fprintf(fp, "]");
	fclose(fp);
	return buf;
}
예제 #18
0
void show_ksplice_section(struct supersect *ss,
			  const struct ksplice_section *ksect)
{
	printf("  symbol: %s\n"
	       "  address: %s  size: %lx\n",
	       str_ksplice_symbolp(ss, &ksect->symbol),
	       str_pointer(ss, (void *const *)&ksect->address),
	       read_num(ss, &ksect->size));
	show_ksplice_section_flags(ksect);
	printf("\n");
}
예제 #19
0
static char *displ_picture(char *c)
  {
  char *d;
  int x,y,hn,z,ln,sl;
  short *sh;

  d = write_buff;
  while (*c !=':') *d++= *c++;
  *d++= 0;c++;
  hn = get_data_handle(write_buff,pcx_8bit_decomp);
  x = read_num(c,(z = 0,&z));c += z;
  y = read_num(c,(z = 0,&z));c += z;
  ln = read_num(c,(z = 0,&z));c += z;
  sl = read_num(c,(z = 0,&z));c += z;
  sh = ablock(hn);
  if (sh[1]+y>YMAX) return c;
  y += YLEFT;
  x += relpos;
  put_8bit_clipped(sh,GetScreenAdr()+x+scr_linelen2*y,ln,sh[0],sl);
  return c;
  }
image read_ppm(char *fn)
{
	FILE *fp = fopen(fn, "rb");
	int w, h, maxval;
	image im = 0;
	if (!fp) return 0;
 
	if (fgetc(fp) != 'P' || fgetc(fp) != '6' || !isspace(fgetc(fp)))
		goto bail;
 
	w = read_num(fp);
	h = read_num(fp);
	maxval = read_num(fp);
	if (!w || !h || !maxval) goto bail;
 
	im = img_new(w, h);
	fread(im->pix, 1, 3 * w * h, fp);
bail:
	if (fp) fclose(fp);
	return im;
}
예제 #21
0
int main(int argc, char *argv[]) {
    FILE *f = fopen(argv[1], "r");
    while (!feof(f)) {
        struct node *h = NULL;
        float n;
        while(read_num(f, &n))
            insert(&h, n);
        print(h);
        printf("\n");
        release(&h);
    }
    fclose(f);
    return 0;
}
예제 #22
0
static int
read_rat_nos(const char **s, int strict,
	     char **b)
{
    if (!read_num(s, strict, b))
	return 0;
    if (**s == '/') {
	**b = **s;
	(*s)++;
	(*b)++;
	if (!read_den(s, strict, b)) {
	    (*b)--;
	    return 0;
	}
    }
    return 1;
}
예제 #23
0
파일: main.c 프로젝트: rosedu/cspay
int 
read_num()
{
char *line;
char *endp;
long nr;
     //fflush(stdin);
     fflush(stdout);
     line=malloc(255);
     fgets(line,255,stdin);
     printf("%s",line);
     	if (line[0] == '\n')
		fgets(line,255,stdin);
  nr = strtol (line, &endp, 10);
  if (*endp != '\0' && *endp != '\n')
     {
      printf("Nu ati introdus un numar!");
      return read_num();
     }
  return (int)nr;
}
예제 #24
0
void show_ksplice_reloc(struct supersect *ss,
			const struct ksplice_reloc *kreloc)
{
	struct supersect *khowto_ss;
	const struct ksplice_reloc_howto *khowto =
	    read_pointer(ss, (void *const *)&kreloc->howto, &khowto_ss);
	printf("  blank_addr: %s  size: %x\n"
	       "  type: %s\n"
	       "  symbol: %s\n"
	       "  insn_addend: %lx\n"
	       "  target_addend: %lx\n"
	       "  pcrel: %x  dst_mask: %lx  rightshift: %x  signed_addend: %x\n"
	       "\n",
	       str_pointer(ss, (void *const *)&kreloc->blank_addr),
	       read_num(khowto_ss, &khowto->size),
	       str_howto_type(khowto),
	       str_ksplice_symbolp(ss, &kreloc->symbol),
	       read_num(ss, &kreloc->insn_addend),
	       read_num(ss, &kreloc->target_addend),
	       read_num(khowto_ss, &khowto->pcrel),
	       read_num(khowto_ss, &khowto->dst_mask),
	       read_num(khowto_ss, &khowto->rightshift),
	       read_num(khowto_ss, &khowto->signed_addend));
}
예제 #25
0
파일: core.cpp 프로젝트: dimiro1/TwisterVM
       void TwisterVM::dispatch ()
       {
             STRING s_aux1;
	 STRING s_aux2;
	 char *ch_aux1;
	 STRING input_s;
	 NUMBER input_d;
	 Instruction executing;

      static const void
      *label_targets[] = {
	     &&LOP_ABS_N, &&LOP_ACOS_N, &&LOP_ADD_N, &&LOP_ASIN_N, &&LOP_ATAN_N, &&LOP_CEIL_N, &&LOP_COS_N, &&LOP_DEC_N, &&LOP_DIV_N, &&LOP_FLOOR_N, &&LOP_INC_N, &&LOP_LOG_N, &&LOP_MOD_N, &&LOP_MULT_N, &&LOP_NEG_N, &&LOP_POW_N, &&LOP_SIN_N, &&LOP_SQRT_N, &&LOP_SUB_N, &&LOP_TAN_N, &&LOP_RAND_N, &&LOP_GOTO, &&LOP_HALT, &&LOP_NOP, &&LOP_SYSTEM_S, &&LOP_GETENV_S, &&LOP_INPUT_N, &&LOP_INPUT_S, &&LOP_PRINT_N, &&LOP_PRINT_S, &&LOP_PUT_N, &&LOP_PUT_S, &&LOP_MOV_N, &&LOP_MOV_S, &&LOP_STORE_N, &&LOP_STORE_S, &&LOP_CONCAT_S, &&LOP_CHARAT_S, &&LOP_LT_S, &&LOP_GT_S, &&LOP_LTE_S, &&LOP_GTE_S, &&LOP_EQ_S, &&LOP_LT_N, &&LOP_GT_N, &&LOP_LTE_N, &&LOP_GTE_N, &&LOP_EQ_N, &&LOP_NOT_LT_S, &&LOP_NOT_GT_S, &&LOP_NOT_LTE_S, &&LOP_NOT_GTE_S, &&LOP_NOT_EQ_S, &&LOP_NOT_LT_N, &&LOP_NOT_GT_N, &&LOP_NOT_LTE_N, &&LOP_NOT_GTE_N, &&LOP_NOT_EQ_N, &&LOP_ZERO_N, &&LOP_NOT_ZERO_N, 
      };
            executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];

LOP_ABS_N: {
	 #ifdef DEBUG
	 puts ("abs_n");
	 #endif
	 RN (executing.A, fabs (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_ACOS_N: {
	 #ifdef DEBUG
	 puts ("acos_n");
	 #endif
	 RN (executing.C, acos (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_ADD_N: {
	 #ifdef DEBUG
	 puts ("add_n");
	 #endif
	 RN (executing.C,
		 RN (executing.A) +
		 RN (executing.B));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_ASIN_N: {
	 #ifdef DEBUG
	 puts ("asin_n");
	 #endif
	 RN (executing.C, asin (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_ATAN_N: {
	 #ifdef DEBUG
	 puts ("atan_n");
	 #endif
	 RN (executing.C, atan (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_CEIL_N: {
	 #ifdef DEBUG
	 puts ("ceil_n");
	 #endif
	 RN (executing.C, ceil (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_COS_N: {
	 #ifdef DEBUG
	 puts ("cos_n");
	 #endif
	 RN (executing.C, cos (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_DEC_N: {
	 #ifdef DEBUG
	 puts ("dec_n");
	 #endif
	 RN (executing.A, (RN (executing.A) - 1));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_DIV_N: {
	 #ifdef DEBUG
	 puts ("div_n");
	 #endif
	 /* Colocar como exception */
	 if (RN (executing.B) == 0)
		{
		  error_emitter.emit (ZERO_DIVISION);
		  abort ();
		}
	 RN (executing.C,
		 RN (executing.A) /
		 RN (executing.B));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_FLOOR_N: {
	 #ifdef DEBUG
	 puts ("floor_n");
	 #endif
	 RN (executing.C, floor (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_INC_N: {
	 #ifdef DEBUG
	 puts ("inc_n");
	 #endif
	 RN (executing.A, (RN (executing.A) + 1));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_LOG_N: {
	 #ifdef DEBUG
	 puts ("log_n");
	 #endif
	 RN (executing.C, log (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_MOD_N: {
	 #ifdef DEBUG
	 puts ("mod_n");
	 #endif
	 RN (executing.C,
		 static_cast<int>(RN (executing.A)) %
		 static_cast<int>(RN (executing.B)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_MULT_N: {
	 #ifdef DEBUG
	 puts ("mult_n");
	 #endif
	 RN (executing.C,
		 RN (executing.A) *
		 RN (executing.B));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NEG_N: {
	 #ifdef DEBUG
	 puts ("neg_n");
	 #endif
	 RN (executing.A, -RN (executing.A));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_POW_N: {
	 #ifdef DEBUG
	 puts ("pow_n");
	 #endif
	 RN (executing.C, pow (RN (executing.A),
								 RN (executing.B)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_SIN_N: {
	 #ifdef DEBUG
	 puts ("sin_n");
	 #endif
	 RN (executing.C, sin (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_SQRT_N: {
	 #ifdef DEBUG
	 puts ("sqrt_n");
	 #endif
	 RN (executing.C, sqrt (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_SUB_N: {
	 #ifdef DEBUG
	 puts ("mult_n");
	 #endif
	 RN (executing.C,
		 RN (executing.A) -
		 RN (executing.B));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_TAN_N: {
	 #ifdef DEBUG
	 puts ("tan_n");
	 #endif
	 RN (executing.C, tan (RN (executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_RAND_N: {
	 #ifdef DEBUG
	 puts ("rand_n");
	 #endif
	 srand (time (0));
	 RN (executing.C, rand ());
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GOTO: {
	 #ifdef DEBUG
	 puts ("goto");
	 #endif
	 current_context->pc = executing.A;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_HALT: {
	 #ifdef DEBUG
	 puts ("halt");
	 #endif
	 exit (0);                /* sai normalmente */
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOP: {
	 #ifdef DEBUG
	 puts ("nop");
	 #endif
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_SYSTEM_S: {
	 #ifdef DEBUG
	 puts ("system_s");
	 #endif
	 system (RS (executing.A).c_str ());
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GETENV_S: {
	 #ifdef DEBUG
	 puts ("getenv_s");
	 #endif
	 ch_aux1 = getenv (RS (executing.A).c_str ());
	 if (ch_aux1 == NULL)
		error_emitter.emit (ENV_NOT_FOUND);
	 else
		RS (executing.C, STRING (ch_aux1));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_INPUT_N: {
	 #ifdef DEBUG
	 puts ("input_n");
	 #endif
	 read_num (input_d);
	 RN (executing.C, input_d);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_INPUT_S: {
	 #ifdef DEBUG
	 puts ("input_s");
	 #endif
	 read_string (input_s);
	 RS (executing.C, input_s);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_PRINT_N: {
	 #ifdef DEBUG
	 puts ("print_n");
	 #endif
	 print_num (RN (executing.A), false);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_PRINT_S: {
	 #ifdef DEBUG
	 puts ("print_s");
	 #endif
	 print_string (RS (executing.A), false);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_PUT_N: {
	 #ifdef DEBUG
	 puts ("put_n");
	 #endif
	 print_num (RN (executing.A), true);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_PUT_S: {
	 #ifdef DEBUG
	 puts ("put_s");
	 #endif
	 print_string (RS (executing.A), true);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_MOV_N: {
	 #ifdef DEBUG
	 puts ("mov_n");
	 #endif
	 RN (executing.C, RN (executing.A));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_MOV_S: {
	 #ifdef DEBUG
	 puts ("mov_s");
	 #endif
	 RS (executing.C, RS (executing.A));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_STORE_N: {
	 #ifdef DEBUG
	 puts ("store_n");
	 #endif
	 RN (executing.C,
		 current_context->get_num (executing.A));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_STORE_S: {
	 #ifdef DEBUG
	 puts ("store_s");
	 #endif
	 RS (executing.C,
		 STRING (current_context->get_string(executing.A)));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_CONCAT_S: {
	 #ifdef DEBUG
	 puts ("concat_s");
	 #endif
	 s_aux1 = RS (executing.A);
	 s_aux2 = RS (executing.B);
	 RS (executing.C, s_aux1 + s_aux2);
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_CHARAT_S: {
	 #ifdef DEBUG
	 puts ("charat_s");
	 #endif
	 s_aux1 = RS (executing.A);
	 ch_aux1 = new char[2];

	 try {
		/* converte caractere inteiro em char * */
		sprintf (ch_aux1, "%c", s_aux1.at(executing.B));
	 }
	 catch (out_of_range e) {
		error_emitter.emit (OUT_OF_RANGE);
		current_context->pc++;
	 }

	 RS (executing.C, STRING (ch_aux1));
	 current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_LT_S: {
	 #ifdef DEBUG
	 puts ("lt_s");
	 #endif
	 if (RS (executing.A) <
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GT_S: {
	 #ifdef DEBUG
	 puts ("gt_s");
	 #endif
	 if (RS (executing.A) >
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_LTE_S: {
	 #ifdef DEBUG
	 puts ("lte_s");
	 #endif
	 if (RS (executing.A) <=
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GTE_S: {
	 #ifdef DEBUG
	 puts ("gte_s");
	 #endif
	 if (RS (executing.A) >=
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_EQ_S: {
	 #ifdef DEBUG
	 puts ("eq_s");
	 #endif
	 if (RS (executing.A) ==
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_LT_N: {
	 #ifdef DEBUG
	 puts ("lt_n");
	 #endif
	 if (RN (executing.A) <
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GT_N: {
	 #ifdef DEBUG
	 puts ("gt_n");
	 #endif
	 if (RN (executing.A) >
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_LTE_N: {
	 #ifdef DEBUG
	 puts ("lte_n");
	 #endif
	 if (RN (executing.A) <=
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_GTE_N: {
	 #ifdef DEBUG
	 puts ("gte_n");
	 #endif
	 if (RN (executing.A) >=
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_EQ_N: {
	 #ifdef DEBUG
	 puts ("eq_n");
	 #endif
	 /* cout << RN (executing.A) << endl; */
	 /* cout << RN (4) << endl; */
	 /* cout << executing.B << endl; */
	 if (RN (executing.A) ==
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_LT_S: {
	 #ifdef DEBUG
	 puts ("not_lt_s");
	 #endif
	 if (RS (executing.A) >=
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_GT_S: {
	 #ifdef DEBUG
	 puts ("not_gt_s");
	 #endif
	 if (RS (executing.A) <=
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_LTE_S: {
	 #ifdef DEBUG
	 puts ("not_lte_s");
	 #endif
	 if (RS (executing.A) >
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_GTE_S: {
	 #ifdef DEBUG
	 puts ("not_gte_s");
	 #endif
	 if (RS (executing.A) <
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_EQ_S: {
	 #ifdef DEBUG
	 puts ("not_eq_s");
	 #endif
	 if (RS (executing.A) !=
		  RS (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_LT_N: {
	 #ifdef DEBUG
	 puts ("not_lt_n");
	 #endif
	 if (RN (executing.A) >=
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_GT_N: {
	 #ifdef DEBUG
	 puts ("not_gt_n");
	 #endif
	 if (RN (executing.A) <=
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_LTE_N: {
	 #ifdef DEBUG
	 puts ("not_lte_n");
	 #endif
	 if (RN (executing.A) >
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_GTE_N: {
	 #ifdef DEBUG
	 puts ("not_gte_n");
	 #endif
	 if (RN (executing.A) <
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_EQ_N: {
	 #ifdef DEBUG
	 puts ("not_eq_n");
	 #endif
	 if (RN (executing.A) !=
		  RN (executing.B))
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_ZERO_N: {
	 #ifdef DEBUG
	 puts ("zero_n");
	 #endif
	 if (RN (executing.A) == 0)
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
LOP_NOT_ZERO_N: {
	 #ifdef DEBUG
	 puts ("zero_n");
	 #endif
	 if (RN (executing.A) != 0)
		  current_context->pc = executing.C;
	 else
		  current_context->pc++;
      executing = current_context->code_section[current_context->pc];
      goto *label_targets[executing.opcode];
}
}
예제 #26
0
파일: mesh.cpp 프로젝트: alexgaiv/terrain
bool Mesh::LoadObj(const char *filename)
{
	ifstream file(filename);
	if (!file) return false;

	Vector3f v;
	Vector2f tc;

	vector<Vector3f> verts, norms;
	vector<Vector2f> texs;
	vector<int> iverts, inorms, itexs;

	Vector3f vmax, vmin;
	bool first = true;

	string line;
	while (getline(file, line))
	{
		if (line.size() < 2) continue;
		string prefix = line.substr(0, 2);
		line[0] = line[1] = ' ';

		int s = 2;
		while (isspace(line[s++]));
		line = line.substr(s - 1);

		if (prefix == "v ") {
			sscanf_s(line.c_str(), "%f %f %f", &v.x, &v.y, &v.z);
			verts.push_back(v);

			if (first) {
				vmax = vmin = v;
				first = false;
			}
			else {
				if (v.x > vmax.x) vmax.x = v.x;
				if (v.y > vmax.y) vmax.y = v.y;
				if (v.z > vmax.z) vmax.z = v.z;

				if (v.x < vmin.x) vmin.x = v.x;
				if (v.y < vmin.y) vmin.y = v.y;
				if (v.z < vmin.z) vmin.z = v.z;
			}
		}
		else if (prefix == "vn") {
			sscanf_s(line.c_str(), "%f %f %f", &v.x, &v.y, &v.z);
			norms.push_back(v);	 
		}
		else if (prefix == "vt") {
			sscanf_s(line.c_str(), "%f %f", &tc.x, &tc.y);
			texs.push_back(tc);
		}
		else if (prefix == "f ")
		{
			char c = 0;
			int i = 0;
			int n = 0;
			int vertsCount = verts.size();

			for (int k = 0; k < 3; k++) {
				read_num(line, c, i, n);
				iverts.push_back(n > 0 ? n - 1 : vertsCount + n);

				if (c == '/')
				{
					bool skip = line[i] == '/';
					if (skip) i++;
					read_num(line, c, i, n);

					if (skip)
						inorms.push_back(n > 0 ? n - 1 : vertsCount + n);
					else {
						itexs.push_back(n > 0 ? n - 1 : vertsCount + n);
						if (c == '/') {
							read_num(line, c, i, n);
							inorms.push_back(n > 0 ? n - 1 : vertsCount + n);
						}
					}
				}
			}
		}
	}

	file.close();

	int verticesCount = verts.size();
	if (verticesCount == 0) return false;
	this->indicesCount = iverts.size();
	bool hasNormals = norms.size() != 0;
	bool hasTexCoords = texs.size() != 0;

	if (hasNormals || hasTexCoords)
	{
		vector<Vector3f> norms_new;
		vector<Vector2f> texs_new;

		if (hasNormals) {
			norms_new.resize(verticesCount);
			memset(&norms_new[0], -1, verticesCount * sizeof(Vector3f));
		}
		if (hasTexCoords) {
			texs_new.resize(verticesCount);
			memset(&texs_new[0], -1, verticesCount * sizeof(Vector2f));
		}

		for (int i = 0, k = iverts.size(); i < k; i++) {
			int iv = iverts[i];
			int it = hasTexCoords ? itexs[i] : 0;
			int in = hasNormals ? inorms[i] : 0;

			if ((!hasNormals || *(int *)&norms_new[iv].x == -1) &&
				(!hasTexCoords || *(int *)&texs_new[iv].x == -1))
			{
				if (hasNormals) norms_new[iv] = norms[in];
				if (hasTexCoords) texs_new[iv] = texs[it];
			}
			else if (hasNormals && norms_new[iv] != norms[in] ||
				     hasTexCoords && texs_new[iv] != texs[it])
			{
 				int same = -1;
				for (int j = verticesCount, n = verts.size(); j < n; j++)
				{
					if (verts[j] == verts[iv] &&
						(!hasNormals || norms_new[j] == norms[in]) &&
						(!hasTexCoords || texs_new[j] == texs[it]))
					{
						same = j;
						break;
					}
				}

				if (same != -1) iverts[i] = same;
				else {
					iverts[i] = verts.size();
					verts.push_back(verts[iv]);
					if (hasNormals) norms_new.push_back(norms[in]);
					if (hasTexCoords) texs_new.push_back(texs[it]);
				}
			}
		}

		verticesCount = verts.size();

		if (hasNormals) {
			if (!normals) normals = new VertexBuffer(rc, GL_ARRAY_BUFFER);
			normals->SetData(norms_new.size()*sizeof(Vector3f), norms_new.data(), GL_STATIC_DRAW);
		}
		if (hasTexCoords) {
			if (!texCoords) texCoords = new VertexBuffer(rc, GL_ARRAY_BUFFER);
			texCoords->SetData(texs_new.size()*sizeof(Vector2f), texs_new.data(), GL_STATIC_DRAW);
		}
	}
	
	if (!vertices) vertices = new VertexBuffer(rc, GL_ARRAY_BUFFER);
	if (!indices) indices = new VertexBuffer(rc, GL_ELEMENT_ARRAY_BUFFER);
	vertices->SetData(verticesCount*sizeof(Vector3f), verts.data(), GL_STATIC_DRAW);
	indices->SetData(indicesCount*sizeof(int), iverts.data(), GL_STATIC_DRAW);

	boundingBox.front = Plane(0, 0, 1, -vmax.z);
	boundingBox.back = Plane(0, 0, -1, vmin.z);
	boundingBox.top = Plane(0, 1, 0, -vmax.y);
	boundingBox.bottom = Plane(0, -1, 0, vmin.y);
	boundingBox.left = Plane(-1, 0, 0, vmin.x);
	boundingBox.right = Plane(1, 0, 0, -vmax.x);

	boundingSphere.center = (vmax + vmin) / 2;
	boundingSphere.radius = max(max(vmax.x - vmin.x, vmax.y - vmin.y), vmax.z - vmin.z);
	
	return true;
}
예제 #27
0
void write_book(int page)
  {
  int i = 0,y = 0,z,zz,ps,pg;
  char *c;
  char space[] =" ";

  pg = page;
  if (all_text == NULL) return;
  set_font(H_FKNIHA,NOSHADOW(0));
  relpos = XLEFT;
  zz = str_count(all_text);
  if (--page)
  for(i = 0;i<zz && page;i++)
     {
     c = all_text[i];
     if (c != NULL && c[0] == 27 && c[1] == END_PAGE) page--;
     }
  if (page) return;
  for(ps = 0;ps<2;ps++)
     {
  position(relpos,YLEFT+y);
  do
     {
     if (i>zz) break;
     c = all_text[i];
     if (c == NULL) break;
     if (c[0] == 27 && c[1] == END_PAGE) break;
     while (*c)
        {
        z = 0;
        if (*c == 27)
           {
           c++;
           switch (*c++)
              {
              case SPACE:
                          rel_position_x(read_num(c,&z));
                          c += z;
                          break;
              case END_LINE:
                          y += read_num(c,&z);
                          position(relpos,YLEFT+y);
                          c += z;
                          break;
              case PICTURE:
                          c = displ_picture(c);
                          break;
              }
           }
        else
           {
           space[0] = *c++;
           outtext(space);
           }
        }
     i++;
     }
  while (1);
  i++;y = 0;
  relpos = XRIGHT;
  if (ps == 0)
     {
     char s[20];
     sprintf(s,texty[135],pg);
     set_aligned_position(XLEFT,YLEFT+YMAX,0,0,s);
     outtext(s);
     }
  if (ps == 1)
     {
     char s[20];
     sprintf(s,texty[136],pg+1);
     set_aligned_position(XRIGHT+XMAX,YLEFT+YMAX,2,0,s);
     outtext(s);
     }
     }
  }
예제 #28
0
파일: lexer.cpp 프로젝트: zwkno1/comp
TokenType Lexer::getToken()
{
	while(true)
	{
        next();
        switch(current_)
        {
        case EOF:
            return ENDFILE;
        case ' ' : case '\f' : case '\t' : case '\v' :
            break;
        case '\n' :
            increase_line();
            break;
        case '=' :
            if(check_next('='))
                return EQ;
            return ASSIGN;
        case '<' :
            if(check_next('='))
                return LE;
            return LT;
        case '+' :
            return ADD;
        case '-' :
            return SUB;
        case '*' :
            return MUL;
        case '(' :
            return LP;
        case ')' :
            return RP;
        case ';' :
            return SEMI;
        case '/' :
            if(check_next('/'))
            {
                if(skip_comment() == false)
                    return ERROR;
                break;
            }

            if(check_next('*'))
            {
                if(skip_comment2() == false)
                    return ERROR;
                break;
            }

            return DIV;
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
            read_num();
            return NUM;
        default :
            if(read_id())
            {
                auto iter = reserve_word.find(id_);
                if(iter != reserve_word.end())
                    return iter->second;
                return ID;
            }
            else
                return ERROR;
        }
    }
}
예제 #29
0
int main(int argc, char * const argv[])
{
    int option_index;
    char command[1024];

    /* Initialize default strings */
    strcpy(vmlinux, "--no-vmlinux");
    strcpy(kernel_range, "");

    while (1) {
        int c = getopt_long(argc, argv, "", long_options, &option_index);
        if (c == -1) {
            break;
        }
        switch (c) {
            case 0:
                break;
            /* --event */
            case 'e':   
                if (num_events == MAX_EVENTS) {
                    fprintf(stderr, "More than %d events specified\n",
                            MAX_EVENTS);
                    exit(1);
                }
                if (process_event(optarg)) {
                    exit(1);
                }
                break;
            /* --vmlinux */
            case 'v':
                sprintf(vmlinux, "-k %s", optarg);
                break;
            /* --kernel-range */
            case 'r':
                sprintf(kernel_range, "-r %s", optarg);
                break;
            /* --shutdown */
            case 'h': {
                int pid = read_num(OP_DATA_DIR"/lock");
                if (pid >= 0) {
                    kill(pid, SIGKILL);
                }   
                setup_session_dir();
                break;
            }
            /* --status */
            case 't':
                do_status();
                break;
            default:
                usage();
                exit(1);
        }
    }
    verbose("list_events = %d\n", list_events);
    verbose("setup = %d\n", setup);

    if (list_events) {
        do_list_events();
    }

    if (quick) {
        process_event("CPU_CYCLES");
        setup = 1;
    }

    if (reset) {
        do_reset();
    }

    if (show_usage) {
        usage();
    }

    if (setup) {
        if (do_setup()) {
            fprintf(stderr, "do_setup failed");
            exit(1);
        }
    }

    if (num_events != 0) {
        int i;

        strcpy(command, "oprofiled --session-dir="OP_DATA_DIR);

#if !defined(WITH_ARM_V7_A)
        /* Since counter #3 can only handle CPU_CYCLES, check and shuffle the 
         * order a bit so that the maximal number of events can be profiled
         * simultaneously
         */
        if (num_events == 3) {
            for (i = 0; i < num_events; i++) {
                int event_idx = selected_events[i];

                if (event_info[event_idx].id == 0xff) {
                    break;
                }
            }

            /* No CPU_CYCLES is found */
            if (i == 3) {
                fprintf(stderr, "You can only specify three events if one of "
                                "them is CPU_CYCLES\n");
                exit(1);
            }
            /* Swap CPU_CYCLES to counter #2 (starting from #0)*/
            else if (i != 2) {
                int temp;

                temp = selected_events[2];
                selected_events[2] = selected_events[i];
                selected_events[i] = temp;

                temp = selected_counts[2];
                selected_counts[2] = selected_counts[i];
                selected_counts[i] = temp;
            }
        }
#endif


        /* Configure the counters and enable them */
        for (i = 0; i < num_events; i++) {
            int event_idx = selected_events[i];
            int setup_result = 0;

            if (i == 0) {
                snprintf(command+strlen(command), 1024 - strlen(command), 
                         " --events=");
            }
            else {
                snprintf(command+strlen(command), 1024 - strlen(command), 
                         ",");
            }
            /* Compose name:id:count:unit_mask:kernel:user, something like
             * --events=CYCLES_DATA_STALL:2:0:200000:0:1:1,....
             */
            snprintf(command+strlen(command), 1024 - strlen(command), 
                     "%s:%d:%d:%d:0:1:1",
                     event_info[event_idx].name,
                     event_info[event_idx].id,
                     i,
                     selected_counts[i]);

            setup_result |= echo_dev("1", 0, "user", i);
            setup_result |= echo_dev("1", 0, "kernel", i);
            setup_result |= echo_dev("0", 0, "unit_mask", i);
            setup_result |= echo_dev("1", 0, "enabled", i);
            setup_result |= echo_dev(NULL, selected_counts[i], "count", i);
            setup_result |= echo_dev(NULL, event_info[event_idx].id, 
                                     "event", i);
            if (setup_result) {
                fprintf(stderr, "Counter configuration failed for %s\n",
                        event_info[event_idx].name);
                fprintf(stderr, "Did you do \"opcontrol --setup\" first?\n");
                exit(1);
            }
        }

        /* Disable the unused counters */
        for (i = num_events; i < MAX_EVENTS; i++) {
            echo_dev("0", 0, "enabled", i);
        }

        snprintf(command+strlen(command), 1024 - strlen(command), " %s",
                 vmlinux);
        if (kernel_range[0]) {
            snprintf(command+strlen(command), 1024 - strlen(command), " %s",
                     kernel_range);
        }
        verbose("command: %s\n", command);
        system(command);
    }

    if (start) {
        echo_dev("1", 0, "enable", -1);
    }

    if (stop) {
        echo_dev("1", 0, "dump", -1);
        echo_dev("0", 0, "enable", -1);
    }
}
예제 #30
0
void do_status()
{
    int num;
    char fullname[512];
    int i;

    printf("Driver directory: %s\n", OP_DRIVER_BASE);
    printf("Session directory: %s\n", OP_DATA_DIR);
    for (i = 0; i < MAX_EVENTS; i++) {
        sprintf(fullname, OP_DRIVER_BASE"/%d/enabled", i);
        num = read_num(fullname);
        if (num > 0) {
            printf("Counter %d:\n", i);

            /* event name */
            sprintf(fullname, OP_DRIVER_BASE"/%d/event", i);
            num = read_num(fullname);
            printf("    name: %s\n", find_event_name_from_id(num));

            /* profile interval */
            sprintf(fullname, OP_DRIVER_BASE"/%d/count", i);
            num = read_num(fullname);
            printf("    count: %d\n", num);
        }
        else {
            printf("Counter %d disabled\n", i);
        }
    }

    num = read_num(OP_DATA_DIR"/lock");
    if (num >= 0) {
        int fd;
        /* Still needs to check if this lock is left-over */
        sprintf(fullname, "/proc/%d", num);
        fd = open(fullname, O_RDONLY);
        if (fd == -1) {
            printf("Session directory is not clean - do \"opcontrol --setup\""
                   " before you continue\n");
            return;
        }
        else {
            close(fd);
            printf("oprofiled pid: %d\n", num);
            num = read_num(OP_DRIVER_BASE"/enable");
            printf("profiler is%s running\n", num == 0 ? " not" : "");
            num = read_num(OP_DRIVER_BASE"/stats/cpu0/sample_received");
            printf("  %9u samples received\n", num);
            num = read_num(OP_DRIVER_BASE"/stats/cpu0/sample_lost_overflow");
            printf("  %9u samples lost overflow\n", num);
#if 0
            /* FIXME - backtrace seems broken */
            num = read_num(OP_DRIVER_BASE"/stats/cpu0/backtrace_aborted");
            printf("  %9u backtrace aborted\n", num);
            num = read_num(OP_DRIVER_BASE"/backtrace_depth");
            printf("  %9u backtrace_depth\n", num);
#endif
        }
    }
    else {
        printf("oprofiled is not running\n");
    }
}