예제 #1
0
파일: parser.c 프로젝트: exalead/libinject
static bool testOptional(TestFeed data, TestFeed result) {
  bool ok;
  char* str;
  char* i = NULL;
  char* expected;
  Parser* parser;

  str = (char*)data.p;
  expected = (char*)result.p;

  parser = Parser_init();
  Parser_addSpacedConstant(parser, "host");
  Parser_add(parser, Parse_word, &i, NULL, NULL);
  ok = Parser_run(parser, str, PB_optional, true, NULL);
  if (expected == NULL) {
    ok = (expected == i);
  } else if (i == NULL) {
    ok = false;
  } else {
    ok = (strcmp(i, expected) == 0);
  }
  if (i) {
    free(i);
  }
  return ok;
}
예제 #2
0
static void loadMapData(MapData *m, const char *filename) {
    Parser the_parser;
    if(!Parser_init(&the_parser, filename))
        exit(EXIT_FAILURE); /* Le message d'erreur a été affiché. */
    Wall * current_wall = NULL;
    PARSER_BEGIN(&the_parser)
    PARSER_EXPECT_STRING(&the_parser, "name", m->name, MAP_NAME_LEN)
    PARSER_EXPECT_VEC2(&the_parser, "size", &m->size)
    PARSER_EXPECT_TEXTURE(&the_parser, "texture")
    PARSER_EXPECT_SPRITE(&the_parser, "artwork", &m->artwork)
    PARSER_EXPECT_SPRITE(&the_parser, "banner", &m->banner)
    PARSER_EXPECT_TILEDQUAD(&the_parser, "terrain_tile", &m->terrain, &m->size)
    PARSER_EXPECT_COLOR3(&the_parser, "color", &m->color)
    PARSER_EXPECT_FLOAT(&the_parser, "friction", &m->friction)
    PARSER_EXPECT_COLOR3(&the_parser, "checkpoint_color", &m->checkpoint_color)
    PARSER_EXPECT_COLOR3(&the_parser, "checkpoint_highlight", &m->checkpoint_highlight)
    PARSER_EXPECT_MAPSTARTS(&the_parser, "start", m->start)
    PARSER_EXPECT_CHECKPOINTS(&the_parser, "checkpoint", m)
    PARSER_EXPECT_OBSTACLE(&the_parser, "obstacle")
    PARSER_EXPECT_WALL(&the_parser, "wall", m)
    PARSER_EXPECT_MUSIC(&the_parser, "music", m)
    PARSER_END(&the_parser)
    Parser_deinit(&the_parser);
    if(current_wall) ConvexShape_free_content(&(current_wall->physic_obstacle.shape));
    free(current_wall);
}
예제 #3
0
void Game_loadMenus(Game *g, const char *dirname) {
    Util_pushd(dirname);
    Parser the_parser;
    if(!Parser_init(&the_parser, "menus.txt"))
        exit(EXIT_FAILURE); /* Le message d'erreur a été affiché. */    
    PARSER_BEGIN(&the_parser)
    PARSER_EXPECT_TEXTURE(&the_parser, "texture")
    PARSER_EXPECT_SPRITE(&the_parser, "sky", &g->main_menu.sky)
    PARSER_EXPECT_SPRITE(&the_parser, "bg0",  g->main_menu.bg)
    PARSER_EXPECT_SPRITE(&the_parser, "bg1",  g->main_menu.bg+1)
    PARSER_EXPECT_SPRITE(&the_parser, "bg2",  g->main_menu.bg+2)
    PARSER_EXPECT_SPRITE(&the_parser, "bg3",  g->main_menu.bg+3)
    PARSER_EXPECT_SPRITE(&the_parser, "title", &g->main_menu.title)
    PARSER_EXPECT_SPRITE(&the_parser, "oneplayer", &g->main_menu.oneplayer)
    PARSER_EXPECT_SPRITE(&the_parser, "twoplayers", &g->main_menu.twoplayers)
    PARSER_EXPECT_SPRITE(&the_parser, "ship_menu_title0",  g->ship_menu.titles)
    PARSER_EXPECT_SPRITE(&the_parser, "ship_menu_title1",  g->ship_menu.titles+1)
    PARSER_EXPECT_SPRITE(&the_parser, "ship_cell", &g->ship_menu.ship_cell)
    PARSER_EXPECT_SPRITE(&the_parser, "map_left_arrow", &g->map_menu.left_arrow)
    PARSER_EXPECT_SPRITE(&the_parser, "clap_top", &g->clap_transition.top)
    PARSER_EXPECT_SPRITE(&the_parser, "clap_bottom", &g->clap_transition.bottom)
    PARSER_END(&the_parser)
    Parser_deinit(&the_parser);
    Util_popd();
}
예제 #4
0
파일: parser.c 프로젝트: exalead/libinject
static bool testFalse(TestFeed data, TestFeed result) {
  int i;
  Parser* parser;

  parser = Parser_init();
  Parser_addInt(parser, &i);
  return ! Parser_run(parser, "1234", PB_false, true, NULL);
}
예제 #5
0
파일: parser.c 프로젝트: exalead/libinject
static bool testEOB(TestFeed data, TestFeed result) {
  char* str;
  Parser* parser;

  str = (char*)data.p;

  parser = Parser_init();
  Parser_checkEOB(parser);
  return Parser_run(parser, str, PB_suite, true, NULL);
}
예제 #6
0
파일: parser.c 프로젝트: exalead/libinject
static bool testNot(TestFeed data, TestFeed result) {
  Parser* parser;
  char* str;

  str = (char*)data.p;

  parser = Parser_init();
  Parser_add(parser, Parse_not, NULL, (void*)"]", NULL);
  Parser_addConstant(parser, "]");
  return Parser_run(parser, str, PB_suite, true, NULL);
}
예제 #7
0
파일: parser.c 프로젝트: exalead/libinject
static bool testConstant(TestFeed data, TestFeed result) {
  char* str;
  char* expected;
  Parser* parser;

  str = (char*)data.p;
  expected = (char*)result.p;

  parser = Parser_init();
  Parser_add(parser, Parse_word, NULL, expected, NULL);
  return Parser_run(parser, str, PB_suite, true, NULL);
}
예제 #8
0
파일: parser.c 프로젝트: exalead/libinject
static bool testInt(TestFeed data, TestFeed result) {
  int i;
  char* str;
  int expected;
  Parser* parser;

  str = (char*)data.p;
  expected = result.i;

  parser = Parser_init();
  Parser_addInt(parser, &i);
  return Parser_run(parser, str, PB_suite, true, NULL) && i == expected;
}
예제 #9
0
파일: parser.c 프로젝트: exalead/libinject
static bool testEnum(TestFeed data, TestFeed result) {
  Parser* parser;
  Parse_enumData* vals;
  int i;
  int res;

  vals = (Parse_enumData*)data.p;
  res = result.i;

  parser = Parser_init();
  Parser_add(parser, Parse_enum, &i, vals, NULL);
  return Parser_run(parser, "forty-two", PB_suite, true, NULL) && i == res;
}
예제 #10
0
파일: parser.c 프로젝트: exalead/libinject
static bool testFirst(TestFeed data, TestFeed result) {
  char* str;
  Parser* parser;

  str = (char*)data.p;

  parser = Parser_init();
  Parser_addConstant(parser, "coucou");
  Parser_addConstant(parser, "cou");
  Parser_addConstant(parser, "c");
  Parser_addConstant(parser, "coucouc");
  return Parser_run(parser, str, PB_first, true, NULL);
}
예제 #11
0
파일: parser.c 프로젝트: exalead/libinject
Parser* Parser_newSubParser(Parser* parser, ParserBehaviour behaviour) {
  Parser* subparser;
  ParserElement* element;
  switch (behaviour) {
    case PB_suite:    element = Parse_suite; break;
    case PB_first:    element = Parse_first; break;
    case PB_optional: element = Parse_optional; break;
    case PB_false:    element = Parse_false; break;
    default: return NULL;
  }
  subparser = Parser_init();
  Parser_add(parser, element, NULL, subparser, (ParserDestroyData*)Parser_destroy);
  return subparser;
}
예제 #12
0
파일: main.c 프로젝트: ooooak/c_impl
int main(int argc, char const *argv[])
{
    if (argc < 2){
        log_error("Input File is Missing.");
    }

    if (!Io_fileExists(argv[1])){
        log_error("Invalid file name.");
    }

    char* source = Io_readFile(argv[1]);
    Parser_init(source);

    return 0;
}
예제 #13
0
파일: parser.c 프로젝트: exalead/libinject
static bool testLine(TestFeed data, TestFeed result) {
  Parser* parser;
  int lines;
  char* str;

  str  = (char*)data.p;
  lines = result.i;

  parser = Parser_init();
  while (lines > 0) {
    if (lines > 1) {
      Parser_addSpaced(parser, Parse_line, NULL, NULL, NULL);
    } else {
      Parser_add(parser, Parse_line, NULL, NULL, NULL);
    }
    --lines;
  }
  return Parser_run(parser, str, PB_suite, true, NULL);
}
예제 #14
0
파일: parser.c 프로젝트: exalead/libinject
static bool testSuite(TestFeed data, TestFeed result) {
  bool ok;
  int  i;
  char* str = NULL;
  Parser* parser;

  parser = Parser_init();
  Parser_addSpacedConstant(parser, "on");
  Parser_addSpacedInt(parser, &i);
  Parser_addSpacedConstant(parser, "do");
  Parser_add(parser, Parse_word, &str, NULL, NULL);
  Parser_checkEOB(parser);
  ok = Parser_run(parser, "on 42 do BOUBOUBOUM", PB_suite, true, NULL);
  if (str) {
    ok = (ok && strcmp(str, "BOUBOUBOUM") == 0);
    free(str);
  }
  return ok && i == 42;
}
예제 #15
0
파일: parser.c 프로젝트: exalead/libinject
static bool testWord(TestFeed data, TestFeed result) {
  char* i = NULL;
  char* str;
  char* expected;
  bool ok;
  Parser* parser;

  str = (char*)data.p;
  expected = (char*)result.p;

  parser = Parser_init();
  Parser_add(parser, Parse_word, &i, NULL, NULL);
  ok = Parser_run(parser, str, PB_suite, true, NULL);
  if (i) {
    ok = (ok && strcmp(expected, i) == 0);
    free(i);
  }
  return ok;
}
예제 #16
0
파일: obdctl.c 프로젝트: DCteam/lustre
int main(int argc, char **argv)
{
        int rc;

        setlinebuf(stdout);

        if (obd_initialize(argc, argv) < 0)
                exit(1);

        Parser_init("obdctl > ", cmdlist);

        if (argc > 1) {
                rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
        } else {
                rc = Parser_commands();
        }

        obd_finalize(argc, argv);
        return rc;
}
예제 #17
0
파일: pdbtool.c 프로젝트: cmusatyalab/coda
int main(int argc, char **argv)
{
    int i;
    coda_assert_action = CODA_ASSERT_EXIT;

    ReadConfigFile();

    PDB_setupdb();
    Parser_init("pdbtool> ", pdbcmds);
    if (argc == 1)
        Parser_commands();
    else {
        char line[1024];
        strcpy(line, argv[1]);
        for (i = 2; i < argc; i++) {
            strcat(line, " ");
            strcat(line, argv[i]);
        }
        execute_line(line);
    }
    PDB_db_release();
    return 0;
}
예제 #18
0
int lctl_main(int argc, char **argv)
{
    int rc;

    setlinebuf(stdout);

    ptl_initialize(argc, argv);
    if (obd_initialize(argc, argv) < 0)
        exit(2);
    if (dbg_initialize(argc, argv) < 0)
        exit(3);

    Parser_init("lctl > ", cmdlist);

    if (argc > 1) {
        rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
    } else {
        rc = Parser_commands();
    }

    obd_finalize(argc, argv);
    return rc < 0 ? -rc : rc;
}
예제 #19
0
static void loadShipData(ShipData *s, const char *filename) {
    float width;
    Parser the_parser;
    if(!Parser_init(&the_parser, filename))
        exit(EXIT_FAILURE); /* Le message d'erreur a été affiché. */
    PARSER_BEGIN(&the_parser)
    PARSER_EXPECT_FLOAT(&the_parser, "friction", &s->friction)
    PARSER_EXPECT_FLOAT(&the_parser, "tilt_step", &s->tilt_step)
    PARSER_EXPECT_FLOAT(&the_parser, "accel_multiplier", &s->accel_multiplier)
    PARSER_EXPECT_FLOAT(&the_parser, "max_speed", &s->max_speed)
    PARSER_EXPECT_FLOAT(&the_parser, "width", &width)
    PARSER_EXPECT_TEXTURE(&the_parser, "texture")
    PARSER_EXPECT_PALETTE(&the_parser, "palette")
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "banner",  s->banner)
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "side",    s->side)
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "icon",    s->icon)
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "artwork", s->artwork)
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above0",  s->above[0])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above1",  s->above[1])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above2",  s->above[2])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above3",  s->above[3])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above4",  s->above[4])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above5",  s->above[5])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above6",  s->above[6])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above7",  s->above[7])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above8",  s->above[8])
    PARSER_EXPECT_PALETTED_SPRITES(&the_parser, "above9",  s->above[9])
    PARSER_EXPECT_VEC2(&the_parser, "reactor_position", &(s->reactor_position))
    PARSER_END(&the_parser)
    Parser_deinit(&the_parser);
    size_t i, p;
    for(i=0 ; i<10 ; ++i)
        for(p=0 ; p<MAX_PALETTES ; ++p)
            Sprite_resizeToWidth(&s->above[i][p], width);
    s->reactor_distance_to_center = sqrt(Scal2(s->reactor_position,
                                            s->reactor_position));
}
예제 #20
0
파일: ptlctl.c 프로젝트: Lezval/lustre
int main(int argc, char **argv)
{
        int rc = 0;

        rc = libcfs_arch_init();
        if (rc < 0)
                return rc;

        rc = ptl_initialize(argc, argv);
        if (rc < 0)
                goto errorout;

        Parser_init("ptlctl > ", list);
        if (argc > 1) {
                rc = Parser_execarg(argc - 1, &argv[1], list);
                goto errorout;
        }

        Parser_commands();

errorout:
        libcfs_arch_cleanup();
        return rc;
}