static void pl_insert_test(void) { printsln((Any)__func__); List ac, ex; ac = sl_of_string("1, 2, 3, 4, 5"); pl_insert(ac, 0, s_create("9")); ex = sl_of_string("9, 1, 2, 3, 4, 5"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); ac = sl_of_string("1, 2, 3, 4, 5"); pl_insert(ac, 5, s_create("9")); ex = sl_of_string("1, 2, 3, 4, 5, 9"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); ac = sl_of_string("1, 2, 3, 4, 5"); pl_insert(ac, 3, s_create("9")); ex = sl_of_string("1, 2, 3, 9, 4, 5"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); ac = sl_of_string("1"); pl_insert(ac, -1, "9"); ex = sl_of_string("1"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); ac = sl_of_string("1"); pl_insert(ac, 1, s_create("9")); ex = sl_of_string("1, 9"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); ac = pl_create(); pl_insert(ac, 0, s_create("9")); ex = sl_of_string("9"); sl_check_expect(ac, ex); pl_free(ac); pl_free(ex); }
static void pl_contains_test(void) { printsln((Any)__func__); String l1 = "10"; String l2 = "20"; String l3 = s_create("20"); List list = pl_create(); pl_append(list, l1); pl_append(list, l2); check_expect_b(pl_contains(list, l1), true); check_expect_b(pl_contains(list, l2), true); check_expect_b(pl_contains(list, l3), false); l_free(list); s_free(l3); }
void copy_recursive() { struct Stack* paths; DIR *dir; struct dirent *entry; const String d_name; int dir_count; dir_count = 0; paths = malloc(sizeof (struct Stack)); s_create(paths); s_push(basename(src), paths); strcpy(src, dirname(src)); strcpy(dest, dirname(dest)); printf("Source: %s\nTarget: %s\n\n", src, dest); while(!s_isEmpty(paths)) { strcat(src, "/"); strcat(src, s_peek(paths)); s_pop(paths); if((dir = opendir(src))) { while((entry = readdir(dir))) { d_name = entry->d_name; if(entry->d_type & DT_DIR) { printf("Found FOLDER: %s\n", d_name); if (strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0) { s_push(d_name, paths); dir_count++; } } else if (entry->d_type & DT_REG) { printf("Found FILE: %s\n", d_name); } } if (!closedir(dir)) { printf("Time to copy\n"); } else { fprintf(stderr, "Could not close '%s': %s\n", src, strerror(errno)); exit(EXIT_FAILURE); } } else { fprintf(stderr, "Cannot open %s: %s\n", src, strerror(errno)); exit(EXIT_FAILURE); } if(dir_count) { strcpy(src, dirname(src)); dir_count--; } } }
static void pl_index_test(void) { printsln((Any)__func__); String l1 = "10"; String l2 = "20"; String l3 = s_create("20"); List list = pl_create(); pl_append(list, l1); pl_append(list, l2); int i = pl_index(list, l3); #if 1 if (i < 0) { printsln("value not found"); } else { printf("value found at index %d\n", i); } #endif check_expect_i(i, -1); check_expect_i(pl_index(list, l1), 0); check_expect_i(pl_index(list, l2), 1); l_free(list); s_free(l3); }
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) { Pos begin = pos; ParserWhitespaceOrComments ws; ParserKeyword s_exists("EXISTS"); ParserKeyword s_describe("DESCRIBE"); ParserKeyword s_desc("DESC"); ParserKeyword s_show("SHOW"); ParserKeyword s_create("CREATE"); ParserKeyword s_table("TABLE"); ParserString s_dot("."); ParserIdentifier name_p; ASTPtr database; ASTPtr table; std::shared_ptr<ASTQueryWithTableAndOutput> query; ws.ignore(pos, end); if (s_exists.ignore(pos, end, max_parsed_pos, expected)) { query = std::make_shared<ASTExistsQuery>(); } else if (s_describe.ignore(pos, end, max_parsed_pos, expected) || s_desc.ignore(pos, end, max_parsed_pos, expected)) { query = std::make_shared<ASTDescribeQuery>(); } else if (s_show.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!s_create.ignore(pos, end, max_parsed_pos, expected)) return false; query = std::make_shared<ASTShowCreateQuery>(); } else { return false; } ws.ignore(pos, end); s_table.ignore(pos, end, max_parsed_pos, expected); ws.ignore(pos, end); if (!name_p.parse(pos, end, table, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (s_dot.ignore(pos, end, max_parsed_pos, expected)) { database = table; if (!name_p.parse(pos, end, table, max_parsed_pos, expected)) return false; ws.ignore(pos, end); } ws.ignore(pos, end); query->range = StringRange(begin, pos); if (database) query->database = typeid_cast<ASTIdentifier &>(*database).name; if (table) query->table = typeid_cast<ASTIdentifier &>(*table).name; node = query; return true; }
int main(int argc, const char *const argv[]) { int ret = 1; lagopus_result_t r; null_thread_t nt; size_t i; a_obj_t o; (void)argc; (void)argv; o = a_obj_create(); if (o == NULL) { goto done; } for (i = 0; i < NTHDS; i++) { nt = &s_thds[i]; if ((r = s_create(&nt, o)) != LAGOPUS_RESULT_OK) { lagopus_perror(r); goto done; } } for (i = 0; i < NTHDS; i++) { nt = &s_thds[i]; if ((r = lagopus_thread_start((lagopus_thread_t *)&nt, false)) != LAGOPUS_RESULT_OK) { lagopus_perror(r); goto done; } } sleep(1); /* * Cancel all the thread. */ for (i = 0; i < NTHDS; i++) { nt = &s_thds[i]; if ((r = lagopus_thread_cancel((lagopus_thread_t *)&nt)) != LAGOPUS_RESULT_OK) { lagopus_perror(r); goto done; } } /* * Destroy all the thread. If any deadlocks occur, we failed. */ for (i = 0; i < NTHDS; i++) { nt = &s_thds[i]; lagopus_thread_destroy((lagopus_thread_t *)&nt); } /* * And destroy a_obj. If a deadlock occurs, we failed. */ a_obj_destroy(o); ret = 0; done: return ret; }
bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserKeyword s_exists("EXISTS"); ParserKeyword s_temporary("TEMPORARY"); ParserKeyword s_describe("DESCRIBE"); ParserKeyword s_desc("DESC"); ParserKeyword s_show("SHOW"); ParserKeyword s_create("CREATE"); ParserKeyword s_database("DATABASE"); ParserKeyword s_table("TABLE"); ParserToken s_dot(TokenType::Dot); ParserIdentifier name_p; ASTPtr database; ASTPtr table; std::shared_ptr<ASTQueryWithTableAndOutput> query; bool parse_only_database_name = false; if (s_exists.ignore(pos, expected)) { query = std::make_shared<ASTExistsQuery>(); } else if (s_show.ignore(pos, expected)) { if (!s_create.ignore(pos, expected)) return false; if (s_database.ignore(pos, expected)) { parse_only_database_name = true; query = std::make_shared<ASTShowCreateDatabaseQuery>(); } else query = std::make_shared<ASTShowCreateTableQuery>(); } else { return false; } if (parse_only_database_name) { if (!name_p.parse(pos, database, expected)) return false; } else { if (s_temporary.ignore(pos, expected)) query->temporary = true; s_table.ignore(pos, expected); if (!name_p.parse(pos, table, expected)) return false; if (s_dot.ignore(pos, expected)) { database = table; if (!name_p.parse(pos, table, expected)) return false; } } if (database) query->database = typeid_cast<ASTIdentifier &>(*database).name; if (table) query->table = typeid_cast<ASTIdentifier &>(*table).name; node = query; return true; }
bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserKeyword s_create("CREATE"); ParserKeyword s_temporary("TEMPORARY"); ParserKeyword s_attach("ATTACH"); ParserKeyword s_table("TABLE"); ParserKeyword s_database("DATABASE"); ParserKeyword s_if_not_exists("IF NOT EXISTS"); ParserKeyword s_as("AS"); ParserKeyword s_view("VIEW"); ParserKeyword s_materialized("MATERIALIZED"); ParserKeyword s_populate("POPULATE"); ParserToken s_dot(TokenType::Dot); ParserToken s_lparen(TokenType::OpeningRoundBracket); ParserToken s_rparen(TokenType::ClosingRoundBracket); ParserStorage storage_p; ParserIdentifier name_p; ParserColumnsOrIndicesDeclarationList columns_or_indices_p; ParserSelectWithUnionQuery select_p; ASTPtr database; ASTPtr table; ASTPtr columns_list; ASTPtr to_database; ASTPtr to_table; ASTPtr storage; ASTPtr as_database; ASTPtr as_table; ASTPtr select; String cluster_str; bool attach = false; bool if_not_exists = false; bool is_view = false; bool is_materialized_view = false; bool is_populate = false; bool is_temporary = false; if (!s_create.ignore(pos, expected)) { if (s_attach.ignore(pos, expected)) attach = true; else return false; } if (s_temporary.ignore(pos, expected)) { is_temporary = true; } if (s_table.ignore(pos, expected)) { if (s_if_not_exists.ignore(pos, expected)) if_not_exists = true; if (!name_p.parse(pos, table, expected)) return false; if (s_dot.ignore(pos, expected)) { database = table; if (!name_p.parse(pos, table, expected)) return false; } if (ParserKeyword{"ON"}.ignore(pos, expected)) { if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) return false; } // Shortcut for ATTACH a previously detached table if (attach && (!pos.isValid() || pos.get().type == TokenType::Semicolon)) { auto query = std::make_shared<ASTCreateQuery>(); node = query; query->attach = attach; query->if_not_exists = if_not_exists; query->cluster = cluster_str; getIdentifierName(database, query->database); getIdentifierName(table, query->table); return true; } /// List of columns. if (s_lparen.ignore(pos, expected)) { if (!columns_or_indices_p.parse(pos, columns_list, expected)) return false; if (!s_rparen.ignore(pos, expected)) return false; if (!storage_p.parse(pos, storage, expected) && !is_temporary) return false; } else { storage_p.parse(pos, storage, expected); if (!s_as.ignore(pos, expected)) return false; if (!select_p.parse(pos, select, expected)) /// AS SELECT ... { /// AS [db.]table if (!name_p.parse(pos, as_table, expected)) return false; if (s_dot.ignore(pos, expected)) { as_database = as_table; if (!name_p.parse(pos, as_table, expected)) return false; } /// Optional - ENGINE can be specified. if (!storage) storage_p.parse(pos, storage, expected); } } } else if (is_temporary) return false; else if (s_database.ignore(pos, expected)) { if (s_if_not_exists.ignore(pos, expected)) if_not_exists = true; if (!name_p.parse(pos, database, expected)) return false; if (ParserKeyword{"ON"}.ignore(pos, expected)) { if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) return false; } storage_p.parse(pos, storage, expected); } else { /// VIEW or MATERIALIZED VIEW if (s_materialized.ignore(pos, expected)) { is_materialized_view = true; } else is_view = true; if (!s_view.ignore(pos, expected)) return false; if (s_if_not_exists.ignore(pos, expected)) if_not_exists = true; if (!name_p.parse(pos, table, expected)) return false; if (s_dot.ignore(pos, expected)) { database = table; if (!name_p.parse(pos, table, expected)) return false; } if (ParserKeyword{"ON"}.ignore(pos, expected)) { if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) return false; } // TO [db.]table if (ParserKeyword{"TO"}.ignore(pos, expected)) { if (!name_p.parse(pos, to_table, expected)) return false; if (s_dot.ignore(pos, expected)) { to_database = to_table; if (!name_p.parse(pos, to_table, expected)) return false; } } /// Optional - a list of columns can be specified. It must fully comply with SELECT. if (s_lparen.ignore(pos, expected)) { if (!columns_or_indices_p.parse(pos, columns_list, expected)) return false; if (!s_rparen.ignore(pos, expected)) return false; } if (is_materialized_view && !to_table) { /// Internal ENGINE for MATERIALIZED VIEW must be specified. if (!storage_p.parse(pos, storage, expected)) return false; if (s_populate.ignore(pos, expected)) is_populate = true; } /// AS SELECT ... if (!s_as.ignore(pos, expected)) return false; if (!select_p.parse(pos, select, expected)) return false; } auto query = std::make_shared<ASTCreateQuery>(); node = query; query->attach = attach; query->if_not_exists = if_not_exists; query->is_view = is_view; query->is_materialized_view = is_materialized_view; query->is_populate = is_populate; query->temporary = is_temporary; getIdentifierName(database, query->database); getIdentifierName(table, query->table); query->cluster = cluster_str; getIdentifierName(to_database, query->to_database); getIdentifierName(to_table, query->to_table); query->set(query->columns_list, columns_list); query->set(query->storage, storage); getIdentifierName(as_database, query->as_database); getIdentifierName(as_table, query->as_table); query->set(query->select, select); return true; }
rt_public EIF_BOOLEAN spiso(register EIF_REFERENCE target, register EIF_REFERENCE source) { /* Compare two special objects in term of their structures. `source' * and `target' are refering two special objects. There is three cases: * 1- either the elements are direct instances: block comparison. * 2- either the elements are references: comparison of referenced * dynamic type. * 3- or the elements are expanded: call `eiso' (special objects * cannot be expanded). */ union overhead *s_zone; /* Source header */ uint32 s_flags; /* Source flags */ /*uint32 t_flags;*/ /* Target flags */ EIF_REFERENCE s_ref; EIF_REFERENCE t_ref; EIF_INTEGER count; /* Common count */ EIF_INTEGER elem_size; /* Common element size */ EIF_REFERENCE s_field, t_field; REQUIRE("special objects", (HEADER(target)->ov_flags & EO_SPEC) && (HEADER(source)->ov_flags & EO_SPEC)); if (source == target) return EIF_TRUE; s_zone = HEADER(source); #ifdef DEBUG dprintf(2)("spiso: source = 0x%lx [%d] target = 0x%lx [%d]\n", source, RT_SPECIAL_COUNT(source), target, RT_SPECIAL_COUNT(target)); #endif count = RT_SPECIAL_COUNT(source); if (count != RT_SPECIAL_COUNT(target)) return EIF_FALSE; /* Second condition: same element size */ elem_size = RT_SPECIAL_ELEM_SIZE(source); if (elem_size != RT_SPECIAL_ELEM_SIZE(target)) return EIF_FALSE; s_flags = s_zone->ov_flags; /* In final mode, we can do block comparison on special of basic types * or on special of expanded which have no references since they have no header. * In workbench mode, block comparison is only possible on special of basic types. */ #ifdef WORKBENCH if (!(s_flags & EO_REF) && !(s_flags & EO_COMP)) { #else if (!(s_flags & EO_REF)) { #endif /* Case 1: specials filled with direct instances: block comparison */ return EIF_TEST(!memcmp (source, target, (rt_uint_ptr) count * (rt_uint_ptr) elem_size)); } if (s_flags & EO_TUPLE) { EIF_TYPED_VALUE * l_source = (EIF_TYPED_VALUE *) source; EIF_TYPED_VALUE * l_target = (EIF_TYPED_VALUE *) target; /* Don't forget that first element of TUPLE is the BOOLEAN * `object_comparison' attribute. */ for (; count > 0; count--, l_source++, l_target++) { if (eif_is_reference_tuple_item(l_source) && eif_is_reference_tuple_item(l_target)) { s_field = eif_reference_tuple_item (l_source); t_field = eif_reference_tuple_item (l_target); if ((s_field == NULL) && (t_field == NULL)) { continue; } else if ((s_field) && (t_field) && (Dtype(s_field) == Dtype(t_field))) { continue; } else { return EIF_FALSE; } } } return EIF_TRUE; } else if ((s_flags & EO_REF) && !(s_flags & EO_COMP)) { /* Case 2: specials filled with references: we have to check fields * one by one. */ for( s_ref = (EIF_REFERENCE)source, t_ref = (EIF_REFERENCE) target; count > 0; count --, s_ref = (EIF_REFERENCE) ((EIF_REFERENCE *) s_ref + 1), t_ref = (EIF_REFERENCE) ((EIF_REFERENCE *) t_ref + 1) ) { /* Evaluation of two references */ s_field = *(EIF_REFERENCE *) s_ref; t_field = *(EIF_REFERENCE *) t_ref; if ((!s_field) && (!t_field)) /* Two void references */ continue; else if ( (((EIF_REFERENCE) 0) != s_field) && (((EIF_REFERENCE) 0) != t_field) && (Dtype(s_field) == Dtype(t_field)) ) /* Two non-void references on objects of same dynamic type */ continue; else /* No ismorphism */ return EIF_FALSE; } return EIF_TRUE; } /* Case 3: special objects filled with (non-special) expanded objects. * we call then standard isomorphism test on normal objects. */ for ( s_ref = source +OVERHEAD, t_ref = target+OVERHEAD; count >0; count--, s_ref += elem_size, t_ref += elem_size ) { /* Iteration on expanded elements */ if (!eiso(t_ref, s_ref)) return EIF_FALSE; } return EIF_TRUE; } rt_public EIF_BOOLEAN ediso(EIF_REFERENCE target, EIF_REFERENCE source) { /* Compare recursively the structure attached to `target' to the * one attached to `source'. This is the standard Eiffel feature * because it called recursively the standard isomorhic Eiffel * feature. * Return a boolean. */ RT_GET_CONTEXT EIF_BOOLEAN result; #ifdef ISE_GC char g_status; /* Save GC status */ g_status = eif_gc_ison(); if (g_status) eif_gc_stop(); /* Stop GC if enabled*/ #endif eif_equality_table = s_create(100); /* Create search table */ result = rdeepiso(target,source); /* Recursive isomorphism test */ #ifdef ISE_GC if (g_status) eif_gc_run(); /* Enabled GC it was previously enabled */ #endif eif_rt_xfree((EIF_REFERENCE) (eif_equality_table->s_keys)); /* Free search table keys */ eif_rt_xfree((EIF_REFERENCE) eif_equality_table); /* Free search table descriptor */ eif_equality_table = NULL; return result; }