/* 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; }
cdiff_file cdiff_file_open (char* filename) { cdiff_file result = malloc(sizeof(struct cdiff_file_s)); /* Store current working directory in case the application using this * function changes the cwd before closing the file. */ corto_asprintf(&result->name, "%s/%s", corto_cwd(), filename); result->elements = NULL; result->legacyElements = NULL; result->isChanged = false; result->writeBuffer = CORTO_BUFFER_INIT; result->writeTo = 0; result->indent = 0; result->newLine = true; result->cur = NULL; char *source = corto_fileLoad(result->name); if (source) { result->isNew = false; /* Check for legacy */ if (strstr(source, "$CORTO_GENERATED")) { if (strstr(source, "$begin") || strstr(source, "$header")) { result->legacyElements = cdiff_parseLegacy(source); if (!result->legacyElements) { goto error; } result->isChanged = true; result->isNew = true; } } /* Parse file (only when not parsing legacy file) */ if (!result->legacyElements) { result->elements = cdiff_parse(source); if (!result->elements) { goto error; } } free(source); } else { corto_lasterr(); /* silence warning */ result->isNew = true; } return result; error: if (source) { free(source); } return NULL; }