long VFSPlugin_LWO::ReadSubChunk(void)
{
	long	id	= ReadLong();
	short	len	= ReadShort();

	switch(id)
	{
		case ID_STIL:	{	read_unkn(id,len);	}break;
		case ID_COLR:	{	read_colr(len);			}break;
		case ID_DIFF:	{	read_diff(len);			}break;
		case ID_LUMI:	{	read_lumi(len);			}break;
		case ID_SPEC:	{	read_spec(len);			}break;
		case ID_REFL:	{	read_refl(len);			}break;
		case ID_TRAN:	{	read_tran(len);			}break;
		case ID_TRNL:	{	read_trnl(len);			}break;
		case ID_GLOS:	{	read_glos(len);			}break;
		case ID_SHRP:	{	read_shrp(len);			}break;
		case ID_SMAN:	{	read_sman(len);			}break;
		case ID_BUMP:	{	read_bump(len);			}break;
		case ID_SIDE:	{	read_unkn(id,len);	}break;
		case ID_BLOK:	{	read_unkn(id,len);	}break;
		case ID_IMAP:	{	read_unkn(id,len);	}break;
		case ID_TMAP:	{	read_unkn(id,len);	}break;
		case ID_IMAG:	{	read_unkn(id,len);	}break;
		case ID_CHAN:	{	read_unkn(id,len);	}break;
		default:			{	read_unkn(id,len);	}break;

	};

	return len + 6;
}
Example #2
0
void my_setup(int argc, char **argv){
	
	firstPersonView = 1;
	bogus = 1;
	num_objects = num_lights = 0;
	
	// initialize global shape defaults and mode for drawing
	crt_render_mode = GL_POLYGON;
	crt_shape = 0;
	
	crt_rs = 90;
	crt_vs = 90; 
	
	my_assert(argc >1, "need to supply a spec file");
	read_spec(argv[1]);
	return;
}
Example #3
0
void my_setup(int argc, char **argv){

  firstPersonView = 1;
  num_objects = num_lights = 0;

  // initialize global shape defaults and mode for drawing
  crt_render_mode = GL_POLYGON;
  crt_shape = 0;

  crt_rs = 40;
  crt_vs = 40; 
 
  //If you want to allow the user to type in the spec file
  //then modify the following code.
  //Otherwise, the program will attempt to load the file as specified
  //on the command line:
  //EX: ./glmain spec3
  my_assert(argc >1, "need to supply a spec file");
  read_spec(argv[1]);
  return;
}
static int
parse_line(struct mtree_reader *r, char *s)
{
	char	*p, *ep;
	int	 ret, esc;

	/* First get rid of comment part and blanks at the end of the line. */
	for (p = s; (p = strchr(p, '#')) != NULL; p++) {
		esc = 0;
		/* Make sure the comment char is not escaped. */
		if (p != s) {
			ep = p - 1;
			do {
				if (*ep != '\\')
					break;
				esc++;
			} while (ep-- != s);
		}
		if ((esc % 2) == 0) {
			*p = '\0';
			break;
		}
	}

	switch (*s) {
	case '\0':              /* empty line */
		ret = 0;
		break;
	case '/':               /* special commands */
		ret = read_command(r, s);
		break;
	default:                /* specification */
		ret = read_spec(r, s);
		break;
	}
	return (ret);
}
Example #5
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	// depth buffer not really needed, but whatever
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

	glutCreateWindow("Ray Tracer");
	
	
	my_assert(argc >1, "need to supply a spec file");
	read_spec(argv[1]);
	
	initGL();

	glutDisplayFunc(displayScene);
	glutReshapeFunc(resizeWindow);
	glutIdleFunc(idle);

	glutMainLoop();

	return 0;
}
Example #6
0
static enum node_which read_spec(enum spec_move *move, size_t *repeat,
                                 size_t *indent, const char *s) {
  static __thread struct idents_map map;
  init_read_spec_map(&map);

  size_t whites = 0;
  while (s[0] == ' ') {
    whites += 1;
    s += 1;
  }

  ssize_t d = whites - *indent;
  if (d == +1) {
    *move = DOWN;
    *repeat = 1;
  } else if (d == 0) {
    *move = NEXT;
    *repeat = 1;
  } else if (d < 0) {
    *move = UP;
    *repeat = - d;
  }

  *indent = whites;

  const char *end = s;
  while (end[0] != '\0') {
    end += 1;
  }

  struct token tok = { .t = IDENT, .value = s, .len = end - s, };
  ident *code = idents_map_get(&map, tok);
  assert(code != NULL);
  return (enum node_which) *code;
}

void check_structure(struct node *node, ...) {
  va_list ap;
  va_start(ap, node);

  struct node *n = node;
  size_t indent = 0;
  bool first = true;

  while (true) {
    const char *s = va_arg(ap, const char *);
    if (s == NULL) {
      break;
    }

    enum spec_move move = 0;
    size_t repeat = 0;
    enum node_which which = read_spec(&move, &repeat, &indent, s);

    if (!first) {
      switch (move) {
      case DOWN:
        n = subs_first(n);
        break;
      case UP:
        while (repeat > 0) {
          n = parent(n);
          repeat -= 1;
        }
        n = next(n);
        break;
      case NEXT:
        n = next(n);
        break;
      }
    }
    first = false;

    assert(n != NULL && which == n->which && "Failed structure check");
  }

  va_end(ap);
}
Example #7
0
/** This function creates a series of spec files with typos in the standard 
  * keys and checks to see whether the number of typos returned by \
  * check_levenshtein_distances() (run through read_spec()) is as expected.
  */
void levenshtein_tests(){

char *spec1;
asprintf(&spec1, "1.spec");

char *spec2;
asprintf(&spec2, "2.spec");

char *spec3;
asprintf(&spec3, "3.spec");
        
char *spec4;
asprintf(&spec4, "4.spec");
        
char *spec5;
asprintf(&spec5, "5.spec");

     write_a_file(spec1,
     "\n"
     "database: demo.db\n"
     "\n"
     "input {\n"
     "    input file: dc_pums_08.csv\n"
     "    output table: dc \n "
     "    overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "}\n"
     "impute { \n"
     "  min group size: 3\n"
     "  draw count: 3\n"
     "  seed: 2332\n"
     "}\n"
     );

     write_a_file(spec2,
     "\n"
     "database: demo.db\n"
     "\n"
     "input {\n"
     "inpt file: dc_pums_08.csv\n"
     "output table: dc \n "
     "overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "AGEP: int 0-116} \n"
     "\n"
     "recodes{\n"
     "CATAGE {\n"
     "1|AGEP between 0 and 15\n"
     "2|AGEP between 16 and 64\n"
     "3|} \n"
     "}"
     );

     write_a_file(spec3,
     "\n"
     "database: demo.db\n"
     "\n"
     "input{\n"
     "input file: dc_pums_08.csv\n"
     "outpt table: dc \n "
     "ovewrite: y} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "}\n"
     "impute {\n"
     "  sed: 2332:\n"
     "  min gruop size: 3\n"
     "  draw count: 3\n"
     "}\n"
     );


     write_a_file(spec4,
     "\n"
     "databas: demo.db\n"
     "\n"
     "input {\n"
     "input file: dc_pums_08.csv\n"
     "output table: dc \n "
     "ovewrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "AGEP: int 0-116} \n"
     "\n"
     "checks {\n"
     "AGEP < 0 \n"
     "\n"
     "AGEP > 95 => AGEP = 95 }\n"
     );


     write_a_file(spec5,
     "database: demo.db\n"
     "\n"
     "database: demo.db\n"
     "impute {\n"
     "inupt tabl: dc \n"
     "draw counn: 3\n"
     "seed:2332\n"
     "methd: hot deck\n}"
     );

    
char *db_dummy;

     read_spec(&spec1, &db_dummy);
     int num_typos_spec1 = get_num_typos();
     printf("There were %d typos when reading %s\n", num_typos_spec1, spec1);
     assert_equals(get_num_typos(), 0);

     read_spec(&spec2, &db_dummy);
     int num_typos_spec2 = get_num_typos();
     printf("There were %d typos when reading %s\n", num_typos_spec2, spec2);
     assert_equals(get_num_typos(), 1);

     read_spec(&spec3, &db_dummy);
     int num_typos_spec3 = get_num_typos();
     printf("There were %d typos when reading %s\n", num_typos_spec3, spec3);
     assert_equals(get_num_typos(), 4);
     
     read_spec(&spec4, &db_dummy);
     int num_typos_spec4 = get_num_typos();
     printf("There were %d typos when reading %s\n", num_typos_spec4, spec4);
     assert_equals(get_num_typos(), 1);

     read_spec(&spec5, &db_dummy);
     int num_typos_spec5 = get_num_typos();
     printf("There were %d typos when reading %s\n", num_typos_spec5, spec5);
     assert_equals(get_num_typos(), 3);
}
Example #8
0
/** This function creates a series of spec files with paste in macros used
  * instead of normal keys. The tests will ensure that the correct keys are 
  * getting written to the keys table by running read_spec() and then using 
  * apop functions to verify that the keys are indeed in the spec file
  */
void pastein_tests(){

char *spec1;
asprintf(&spec1, "1.spec");

char *spec2;
asprintf(&spec2, "2.spec");

char *spec3;
asprintf(&spec3, "3.spec");
        
char *spec4;
asprintf(&spec4, "4.spec");

char *spec5;
asprintf(&spec5, "5.spec");
        
    /* Standard test here: creating a macro with a few sub keys and calling it on its own
     * in the impute key. If something goes wrong here it's because there's something
     * fundamentally wrong with the paste in macro (because there's only one so there's
     * nothing too complex going on).
     */
     write_a_file(spec1,
     "\n"
     "database: demo.db\n"
     "verbose: 2\n"
     "catagesex{\n"
     "  min group size: 3\n"
     "  draw count: 3\n"
     "  seed: 2332\n"
     "  categories {\n"
     "      CATAGE\n"
     "      SEX\n"
     "  }\n"
     "}\n"
     "\n"
     "input {\n"
     "    input file: dc_pums_08.csv\n"
     "    output table: dc \n "
     "    overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "\n}"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: SCHL\n"
     "}\n"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: WAGP\n"
     "}\n"
     );

     /* Creating test here that uses two macros that are used concurrently but that do not
      * call each other. tables{...} and catagesex{...} are each used in impute{...} but
      * they do not "paste each other in". This will be tested in spec 3.
      */
     write_a_file(spec2,
     "\n"
     "database: demo.db\n"
     "verbose: 2\n"
     "catagesex{\n"
     "  min group size: 3\n"
     "  draw count: 3\n"
     "  seed: 2332\n"
     "  categories {\n"
     "      CATAGE\n"
     "      SEX\n"
     "  }\n"
     "}\n"
     "tables{\n"
     "  input table: viewdc\n"
     "  output table: impuTable\n" //To account for analysts who like camel case
     "}\n"
     "\n"
     "input {\n"
     "    paste in: tables\n"
     "    input file: dc_pums_08.csv\n"
     "    output table: dc \n "
     "    overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "\n}"
     "impute{\n"
     "  paste in: tables\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: SCHL\n"
     "}\n"
     "impute{\n"
     "  paste in: tables\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: WAGP\n"
     "}\n"
     );

    /* More complicated test that tests the ability of a macro to use another macro in its
     * own definition. For instance, it tests something along the lines of
     * catagesex{paste in: impute stuff \n paste in: categories}
     */
     write_a_file(spec3,
     "\n"
     "database: demo.db\n"
     "verbose: 2\n"
     "imputestuff{\n"
     "  min group size: 3\n"
     "  draw count: 3\n"
     "  seed: 2332\n"
     "}\n"
     "categoriesstuff {\n"
     "  categories{\n"
     "      CATAGE\n"
     "      SEX\n"
     "  }\n"
     "}\n"
     "catagesex{\n"
     "  paste in: imputestuff\n"
     "  paste in: categoriesstuff\n"
     "}\n"
     "\n"
     "input {\n"
     "    input file: dc_pums_08.csv\n"
     "    output table: dc \n "
     "    overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "\n}"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: SCHL\n"
     "}\n"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: WAGP\n"
     "}\n"
     );

    /* Tests whether it's possible to create a macro that comprises the entire spec file
     * (which, of course, is then pasted in on its own). This includes other macros that
     * are written within the overarching macro itself. Possibly overkill? But I think
     * it's worth it to test given that different analysts might include big portions of
     * the spec file separately and could decide to use a macro to do so.
     */
     write_a_file(spec4,
     "\n"
     "database: demo.db\n"
     "wholeSpec{\n"
     "verbose: 2\n"
     "catagesex{\n"
     "  min group size: 3\n"
     "  draw count: 3\n"
     "  seed: 2332\n"
     "  categories {\n"
     "      CATAGE\n"
     "      SEX\n"
     "  }\n"
     "}\n"
     "\n"
     "input {\n"
     "    input file: dc_pums_08.csv\n"
     "    output table: dc \n "
     "    overwrite: y \n "
     "} \n "
     " \n"
     "fields { \n"
     "SCHL: int 0-24 \n"
     "WAGP: real\n"
     "\n}"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: SCHL\n"
     "}\n"
     "impute{\n"
     "  input table: viewdc\n"
     "  output table: imputes\n"
     "  paste in: catagesex\n"
     "  method: hot deck\n"
     "  output vars: WAGP\n"
     "}\n"
     "}\n"
     "paste in: wholeSpec\n"
     );

char *db_dummy;

     char *imp_min_grp, *imp_drw_cnt, *imp_seed, *imp_categories;

     read_spec(&spec1, &db_dummy);
     asprintf(&imp_min_grp, "impute/min group size");
     asprintf(&imp_drw_cnt, "impute/draw count");
     asprintf(&imp_seed, "impute/seed");
     asprintf(&imp_categories, "impute/categories");

     apop_data *spec1_keys1 = apop_query_to_text("select * from keys where key like "
             "'impute/m%%'");
     printf("spec1_keys1->text[0][0] is given by: %s.\n", spec1_keys1->text[0][0]);
     assert(!strcmp(imp_min_grp, spec1_keys1->text[0][0]));


     apop_data *spec1_keys2 = apop_query_to_text("select * from keys where key like "
             "'impute/d%%'");
     printf("spec1_keys2->text[0][0] is given by: %s.\n", spec1_keys2->text[0][0]);
     assert(!strcmp(imp_drw_cnt, spec1_keys2->text[0][0]));


     apop_data *spec1_keys3 = apop_query_to_text("select * from keys where key like "
             "'impute/s%%'");
     printf("spec1_keys3->text[0][0] is given by: %s.\n", spec1_keys3->text[0][0]);
     assert(!strcmp(imp_seed, spec1_keys3->text[0][0]));

     
     apop_data *spec1_keys4 = apop_query_to_text("select * from keys where key like "
             "'impute/c%%'");
     printf("spec1_keys4->text[0][0] is given by: %s.\n", spec1_keys4->text[0][0]);
     assert(!strcmp(imp_categories, spec1_keys4->text[0][0]));
     
     apop_data_free(spec1_keys1);
     apop_data_free(spec1_keys2);
     apop_data_free(spec1_keys3);
     apop_data_free(spec1_keys4);
      

     read_spec(&spec2, &db_dummy);
     char *inpt_inpt_table;
     char *inpt_otpt_table;

     asprintf(&inpt_inpt_table, "input/input table");
     asprintf(&inpt_otpt_table, "input/output table");

     apop_data *spec2_keys1 = apop_query_to_text("select * from keys where key like "
             "'impute/m%%'");
     printf("spec2_keys1->text[0][0] is given by: %s.\n", spec2_keys1->text[0][0]);
     assert(!strcmp(imp_min_grp, spec2_keys1->text[0][0]));


     apop_data *spec2_keys2 = apop_query_to_text("select * from keys where key like "
             "'impute/d%%'");
     printf("spec2_keys2->text[0][0] is given by: %s.\n", spec2_keys2->text[0][0]);
     assert(!strcmp(imp_drw_cnt, spec2_keys2->text[0][0]));


     apop_data *spec2_keys3 = apop_query_to_text("select * from keys where key like "
             "'impute/s%%'");
     printf("spec2_keys3->text[0][0] is given by: %s.\n", spec2_keys3->text[0][0]);
     assert(!strcmp(imp_seed, spec2_keys3->text[0][0]));

     
     apop_data *spec2_keys4 = apop_query_to_text("select * from keys where key like "
             "'impute/c%%'");
     printf("spec2_keys4->text[0][0] is given by: %s.\n", spec2_keys4->text[0][0]);
     assert(!strcmp(imp_categories, spec2_keys4->text[0][0]));
     
     apop_data *spec2_keys5 = apop_query_to_text("select * from keys where key like "
             "'input/input t%%'");
     printf("spec2_keys5->text[0][0] is given by: %s.\n", spec2_keys5->text[0][0]);
     assert(!strcmp(inpt_inpt_table, spec2_keys5->text[0][0]));


     apop_data *spec2_keys6 = apop_query_to_text("select * from keys where key like "
             "'input/output t%%'");
     printf("spec2_keys6->text[0][0] is given by: %s.\n", spec2_keys6->text[0][0]);
     assert(!strcmp(inpt_otpt_table, spec2_keys6->text[0][0]));

     apop_data_free(spec2_keys1);
     apop_data_free(spec2_keys2);
     apop_data_free(spec2_keys3);
     apop_data_free(spec2_keys4);
     apop_data_free(spec2_keys5);
     apop_data_free(spec2_keys6);

     read_spec(&spec3, &db_dummy);
     
     apop_data *spec3_keys1 = apop_query_to_text("select * from keys where key like "
             "'impute/m%%'");
     printf("spec3_keys1->text[0][0] is given by: %s.\n", spec3_keys1->text[0][0]);
     assert(!strcmp(imp_min_grp, spec3_keys1->text[0][0]));


     apop_data *spec3_keys2 = apop_query_to_text("select * from keys where key like "
             "'impute/d%%'");
     printf("spec3_keys2->text[0][0] is given by: %s.\n", spec3_keys2->text[0][0]);
     assert(!strcmp(imp_drw_cnt, spec3_keys2->text[0][0]));


     apop_data *spec3_keys3 = apop_query_to_text("select * from keys where key like "
             "'impute/s%%'");
     printf("spec3_keys3->text[0][0] is given by: %s.\n", spec3_keys3->text[0][0]);
     assert(!strcmp(imp_seed, spec3_keys3->text[0][0]));

     
     apop_data *spec3_keys4 = apop_query_to_text("select * from keys where key like "
             "'impute/c%%'");
     printf("spec3_keys4->text[0][0] is given by: %s.\n", spec3_keys4->text[0][0]);
     assert(!strcmp(imp_categories, spec3_keys4->text[0][0]));

     apop_data_free(spec3_keys1);
     apop_data_free(spec3_keys2);
     apop_data_free(spec3_keys3);
     apop_data_free(spec3_keys4);

     /* This is spec file that tests whether paste in works for pasting in the entire spec
      * file (without the database -- pasting in database has not been tested yet). spec 4
      * paste in stuff is tested by just testing for an assortment of keys.
      */
     read_spec(&spec4, &db_dummy);


     /* DV - ATTENTION:
      * This test is failing right now so I've put in an if statement below to exit when
      * there's no impute key to avoid a segfault in the testing. We need to fix the bug
      * that is preventing paste in from allowing an entire spec file (minus the database)
      * to be pasted in.
      */


     apop_data *spec4_keys1 = apop_query_to_text("select * from keys where key like "
             "'impute/m%%'");

     if(get_key_word("impute", NULL) == NULL) return;
     printf("spec4_keys1->text[0][0] is given by: %s.\n", spec4_keys1->text[0][0]);
     assert(!strcmp(imp_min_grp, spec4_keys1->text[0][0]));


     apop_data *spec4_keys2 = apop_query_to_text("select * from keys where key like "
             "'impute/d%%'");
     printf("spec4_keys2->text[0][0] is given by: %s.\n", spec4_keys2->text[0][0]);
     assert(!strcmp(imp_drw_cnt, spec4_keys2->text[0][0]));


     apop_data *spec4_keys3 = apop_query_to_text("select * from keys where key like "
             "'impute/s%%'");
     printf("spec4_keys3->text[0][0] is given by: %s.\n", spec4_keys3->text[0][0]);
     assert(!strcmp(imp_seed, spec4_keys3->text[0][0]));

     
     apop_data *spec4_keys4 = apop_query_to_text("select * from keys where key like "
             "'impute/c%%'");
     printf("spec4_keys4->text[0][0] is given by: %s.\n", spec4_keys4->text[0][0]);
     assert(!strcmp(imp_categories, spec4_keys4->text[0][0]));
     
     apop_data *spec4_keys5 = apop_query_to_text("select * from keys where key like "
             "'input/input t%%'");
     printf("spec4_keys5->text[0][0] is given by: %s.\n", spec4_keys5->text[0][0]);
     assert(!strcmp(inpt_inpt_table, spec4_keys5->text[0][0]));


     apop_data *spec4_keys6 = apop_query_to_text("select * from keys where key like "
             "'input/output t%%'");
     printf("spec4_keys6->text[0][0] is given by: %s.\n", spec4_keys6->text[0][0]);
     assert(!strcmp(inpt_otpt_table, spec4_keys6->text[0][0]));

     apop_data_free(spec4_keys1);
     apop_data_free(spec4_keys2);
     apop_data_free(spec4_keys3);
     apop_data_free(spec4_keys4);
     apop_data_free(spec4_keys5);
     apop_data_free(spec4_keys6);

     free(imp_min_grp);
     free(imp_drw_cnt);
     free(imp_seed);
     free(imp_categories);
     free(inpt_inpt_table);
     free(inpt_otpt_table);
     free(spec1);
     free(spec2);
     free(spec3);
     free(spec4);
     free(spec5);

     printf("Reached end of test.\n");

}