/* Resolve cycles. * * If there are cycles, the only cycles that can be broken are the DECLARED | DEFINED dependencies, which * are stored as dependency objects with the 'weak' flag set to TRUE. */ static int g_itemResolveCycles(g_item item, struct corto_depresolver_s* data) { corto_iter iter; g_dependency dep; corto_uint32 sp; sp = data->sp; /* If item has not yet been declared, search onDeclared list. If the item is already declared, the * dependencies in this list have already been resolved, thus need not to be evaluated again. */ if (!item->declared && item->onDeclared) { /* Walk dependencies */ iter = corto_llIter(item->onDeclared); while((corto_iterHasNext(&iter))) { dep = corto_iterNext(&iter); g_itemResolveDependencyCycles(dep, data); } } /* Walk onDefined list if item is not yet defined. */ if (!item->defined && item->onDefined) { /* Walk dependencies */ iter = corto_llIter(item->onDefined); while((corto_iterHasNext(&iter))) { dep = corto_iterNext(&iter); g_itemResolveDependencyCycles(dep, data); } } data->sp = sp; return 0; }
static corto_int16 html_copyFiles(htmlData_t *data) { corto_string doc; corto_asprintf(&doc, "%s/doc", CORTO_GEN_DOC_HTML_ETC); corto_ll files = corto_opendir(doc); if (!files) { goto error; } corto_iter it = corto_llIter(files); while (corto_iterHasNext(&it)) { corto_string f = corto_iterNext(&it); corto_id file; sprintf(file, "%s/%s", doc, f); if (corto_cp(file, data->output)) { goto error; } } corto_closedir(files); corto_dealloc(doc); return 0; error: return -1; }
static corto_bool corto_iterator_next_list(void* iterator) { iteratorType *iter = iterator; corto_bool result = FALSE; if ((result = corto_iterHasNext(&iter->is.ll.iter))) { iter->current = corto_iterNext(&iter->is.ll.iter); result = TRUE; } return result; }
/* Run a command for multiple projects */ corto_int16 cortotool_runcmd( corto_ll dirs, char *argv[], corto_bool silent, corto_bool mute) { corto_iter iter; corto_id cwd; corto_int8 ret = 0; strcpy(cwd, corto_cwd()); if (dirs) { iter = corto_llIter(dirs); } do { corto_pid pid = 0; corto_int32 sig = 0; if (dirs) { corto_string dir = corto_iterNext(&iter); /* Change working directory to project */ if (corto_chdir(dir)) { goto error; } } if (mute) { pid = corto_procrunRedirect(argv[0], argv, stdin, NULL, NULL); } else if (silent) { pid = corto_procrunRedirect(argv[0], argv, stdin, NULL, stderr); } else { pid = corto_procrun(argv[0], argv); } if (!pid) { corto_seterr("failed to start process %s", argv[0]); goto error; } if ((sig = corto_procwait(pid, &ret)) || ret) { corto_seterr("%s failed (%s %d)", argv[0], sig ? "signal" : "returncode", sig ? sig : ret); goto error; } /* Reset to previous CWD if there is more than one project to build */ corto_chdir(cwd); } while (dirs && corto_iterHasNext(&iter)); return 0; error: return -1; }
void* corto_llIterMove(corto_iter* iter, unsigned int index) { void* result; result = NULL; if (corto_iterData(*iter)->list->size <= index) { corto_critical("iterMove exceeds list-bound (%d >= %d).", index, (corto_iterData(*iter)->list)->size); } corto_iterMoveFirst(iter); while(index) { result = corto_iterNext(iter); index--; } return result; }
/* Lookup item in administration */ g_item g_itemLookup(corto_object o, corto_depresolver data) { corto_iter iter; g_item item; /* Lookup item for 'o' in items list */ item = NULL; iter = corto_llIter(data->items); while(!item && corto_iterHasNext(&iter)) { item = corto_iterNext(&iter); if (item->o != o) { item = NULL; } } /* If item did not yet exist, insert it in data */ if (!item) { item = g_itemNew(o, data); } return item; }
int select_contentTypeMain(int argc, char *argv[]) { /* Create a Point type, so we have something to serialize to JSON */ corto_struct Point = corto_declareChild(root_o, "Point", corto_struct_o); if (!Point) { goto error; } /* Create x member */ corto_member x = corto_declareChild(Point, "x", corto_member_o); if (!x) { goto error; } if (!corto_checkState(x, CORTO_DEFINED)) { corto_setref(&x->type, corto_int32_o); if (corto_define(x)) { goto error; } } /* Create y member */ corto_member y = corto_declareChild(Point, "y", corto_member_o); if (!y) { goto error; } if (!corto_checkState(y, CORTO_DEFINED)) { corto_setref(&y->type, corto_int32_o); if (corto_define(y)) { goto error; } } /* Finalize Point struct */ if (corto_define(Point)) { goto error; } /* Create two instances of Point. */ corto_object p1 = corto_declareChild(root_o, "p1", Point); if (!p1) { goto error; } if (!corto_checkState(p1, CORTO_DEFINED)) { *(corto_int32*)CORTO_OFFSET(p1, x->offset) = 10; *(corto_int32*)CORTO_OFFSET(p1, y->offset) = 10; if (corto_define(p1)) { goto error; } } corto_object p2 = corto_declareChild(root_o, "p2", Point); if (!p2) { goto error; } if (!corto_checkState(p2, CORTO_DEFINED)) { *(corto_int32*)CORTO_OFFSET(p2, x->offset) = 20; *(corto_int32*)CORTO_OFFSET(p2, y->offset) = 30; if (corto_define(p2)) { goto error; } } /* Select all instances of type Point, get value in JSON */ corto_iter it; corto_int16 ret = corto_select("/", "*") .contentType("text/json") .type("/Point") .iter(&it); if (ret) { goto error; } while (corto_iterHasNext(&it)) { corto_result *r = corto_iterNext(&it); printf("id: %s, value: %s\n", r->id, corto_result_getText(r)); } return 0; error: corto_error("error: %s", corto_lasterr()); return -1; }