⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nutcomponent.c

📁 含有完整TCP/IP PPP协议的嵌入式操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	while (opts)	{		c = opts->nco_nxt;		if (opts->nco_name) free(opts->nco_name);        if (opts->nco_brief) free(opts->nco_brief);        if (opts->nco_description) free(opts->nco_description);        if (opts->nco_active_if) free(opts->nco_active_if);        if (opts->nco_requires) ReleaseStringArray(opts->nco_requires);        if (opts->nco_provides) ReleaseStringArray(opts->nco_provides);        if (opts->nco_flavor) free(opts->nco_flavor);        if (opts->nco_type) free(opts->nco_type);        if (opts->nco_choices) ReleaseStringArray(opts->nco_choices);        if (opts->nco_ctype) free(opts->nco_ctype);        if (opts->nco_default) free(opts->nco_default);        if (opts->nco_value) free(opts->nco_value);        if (opts->nco_file) free(opts->nco_file);        if (opts->nco_makedefs) ReleaseStringArray(opts->nco_makedefs);		free(opts);		opts = c;	}}void ReleaseComponents(NUTCOMPONENT *comp){	NUTCOMPONENT *child = comp->nc_child, *c;	while (child)	{		c = child->nc_nxt;		ReleaseComponents(child);		child = c;	}    if (comp->nc_name) free (comp->nc_name);	if (comp->nc_brief) free (comp->nc_brief);    if (comp->nc_description) free (comp->nc_description);    if (comp->nc_requires) ReleaseStringArray(comp->nc_requires);    if (comp->nc_provides) ReleaseStringArray(comp->nc_provides);    if (comp->nc_active_if) free(comp->nc_active_if);    if (comp->nc_subdir) free(comp->nc_subdir);    if (comp->nc_sources) ReleaseStringArray(comp->nc_sources);    if (comp->nc_targets) ReleaseStringArray(comp->nc_targets);    if (comp->nc_makedefs) ReleaseStringArray(comp->nc_makedefs);	if (comp->nc_opts) ReleaseComponentOptions(comp->nc_opts);	free (comp);}/*! * \brief Load Nut/OS repository components. * * \param repo Pointer to a NUTREPOSITORY structure. * * \return Root pointer to a linked tree of NUTCOMPONENT structures. */NUTCOMPONENT *LoadComponents(NUTREPOSITORY *repo){    lua_State *ls = (lua_State *)(repo->nr_ls);    NUTCOMPONENT *root;    /* Create a repository root component. */    root = calloc(1, sizeof(NUTCOMPONENT));    root->nc_name = strdup("repository");    /*     * Collect the components first. As a result we will have a tree     * structure of all components.     */    if(LoadComponentTree(ls, root, repo->nr_dir, repo->nr_name)) {        free(root->nc_name);        free(root);        root = NULL;    }    /*     * Now walk along the component tree and collect the options of     * all components incl. root itself.     */    if(root) {        LoadOptions(ls, root, root);    }    return root;}/*! * \brief Read Nut/OS component configuration values. * * \param repo Pointer to a NUTREPOSITORY structure. * \param root Pointer to a linked tree of NUTCOMPONENT structures. * \param pathname Pathname of the repository file. Use slashes, not backslashes. * * \return 0 on success or -1 otherwise. */int ConfigureComponents(NUTREPOSITORY *repo, NUTCOMPONENT *root, const char *pathname){    int rc;    lua_State *ls = (lua_State *)(repo->nr_ls);    if(ls == NULL || root == NULL || pathname == NULL || access(pathname, 0)) {        return -1;    }    /* Let the interpreter load the script file. */    if ((rc = luaL_loadfile(ls, pathname)) != 0) {        strcpy(errtxt, lua_tostring(ls, -1));        return -1;    }    if(lua_pcall(ls, 0, 0, 0)) {        strcpy(errtxt, lua_tostring(ls, -1));        return -1;    }    LoadConfigValues(ls, root);    return 0;}int IsProvided(NUTCOMPONENT *compo, char *requirement){    NUTCOMPONENTOPTION *opts;    int i;    while (compo) {        if(compo->nc_enabled) {            if(compo->nc_provides) {                for (i = 0; compo->nc_provides[i]; i++) {                    if(strcmp(compo->nc_provides[i], requirement) == 0) {                        return 1;                    }                }            }            opts = compo->nc_opts;            while (opts) {                if(opts->nco_enabled && opts->nco_active && opts->nco_provides) {                    for (i = 0; opts->nco_provides[i]; i++) {                        if(strcmp(opts->nco_provides[i], requirement) == 0) {                            return 1;                        }                    }                }                opts = opts->nco_nxt;            }            if (IsProvided(compo->nc_child, requirement)) {                return 1;            }        }        compo = compo->nc_nxt;    }    return 0;}void EnableSubComponents(NUTCOMPONENT *compo, int enable){    NUTCOMPONENTOPTION *opts;    while (compo) {        compo->nc_enabled = enable;        opts = compo->nc_opts;        while (opts) {            opts->nco_enabled = enable;            opts = opts->nco_nxt;        }        EnableSubComponents(compo->nc_child, enable);        compo = compo->nc_nxt;    }}void EnableComponentTree(NUTCOMPONENT *compo, int enable){    NUTCOMPONENTOPTION *opts;    compo->nc_enabled = enable;    opts = compo->nc_opts;    while (opts) {        opts->nco_enabled = enable;        opts = opts->nco_nxt;    }    EnableSubComponents(compo->nc_child, enable);}int RefreshComponentTree(NUTCOMPONENT *root, NUTCOMPONENT *compo){    int rc = 0;    int i;    NUTCOMPONENTOPTION *opts;    while (compo) {        if(compo->nc_requires) {            int provided = 1;            for (i = 0; compo->nc_requires[i]; i++) {                if((provided = IsProvided(root, compo->nc_requires[i])) == 0) {                    break;                }            }            if(provided != compo->nc_enabled) {                /* Update this component branch. */                //compo->nc_enabled = provided;                EnableComponentTree(compo, provided);                rc++;            }        }        opts = compo->nc_opts;        while (opts) {            if(opts->nco_requires) {                int provided = 1;                for (i = 0; opts->nco_requires[i]; i++) {                    if((provided = IsProvided(root, opts->nco_requires[i])) == 0) {                        break;                    }                }                if(provided != opts->nco_enabled) {                    opts->nco_enabled = provided;                    rc++;                }            }            opts = opts->nco_nxt;        }        rc += RefreshComponentTree(root, compo->nc_child);        compo = compo->nc_nxt;    }    return rc;}int RefreshComponents(NUTCOMPONENT *root){    int i;    /* Enable all components. */    EnableComponentTree(root, 1);    for(i = 0; i < 10; i++) {        if(RefreshComponentTree(root, root) == 0) {            return 0;        }    }    return -1;}/* * \brief Creates the complete directory path to a given pathname of a file. * * \param path The file's pathname. * * \return 0 on success, -1 if we failed to create any non existing subdirectoy. */static int CreateDirectoryPath(const char *path){    char subpath[255];    char *cp;    if(*path) {        /*         * Copy any optional WIN32 device/drive information.         */        if((cp = strchr(path, ':')) != 0) {            for(cp = subpath; *path != ':'; path++, cp++) {                *cp = *path;            }        }        else {            cp = subpath;        }        /*         * Copy the first character unchecked. This way we avoid to check the         * root directory.         */        if(*path) {            *cp++ = *path++;        }        /*         * Create the directory tree, processing path component by path component.         */        while(*path) {            if(*path == '/') {                *cp = 0;                if(access(subpath, 0)) {                    if(mkdir(subpath, S_IRWXU)) {                        sprintf(errtxt, "Failed to make %s", subpath);                        return -1;                    }                }            }            *cp++ = *path++;        }    }    return 0;}int AddMakeSources(FILE * fp, NUTCOMPONENT * compo, const char *sub_dir, int *lpos){    int rc = 0;    int i;    NUTCOMPONENT *cop = compo;    while (cop) {        if(cop->nc_enabled) {            if(cop->nc_sources) {                for (i = 0; cop->nc_sources[i]; i++) {                    /*                     * If sources are located in a subdirectory, make sure                     * the same directory exists in the build tree.                     */                    if(strchr(cop->nc_sources[i], '/')) {                        char path[255];                        sprintf(path, "%s/%s", sub_dir, cop->nc_sources[i]);                        CreateDirectoryPath(path);                    }                    /* Check if this source results in an explicit target. */                    if(cop->nc_targets && cop->nc_targets[i]) {                        rc++;                    }                    else {                        *lpos += strlen(cop->nc_sources[i]);                        if (*lpos > 72) {                            fprintf(fp, " \\\n\t");                            *lpos = 8;                        }                        fprintf(fp, " %s", cop->nc_sources[i]);                    }                }            }            if (cop->nc_child) {                rc += AddMakeSources(fp, cop->nc_child, sub_dir, lpos);            }        }        cop = cop->nc_nxt;    }    return rc;}int AddMakeTargets(FILE * fp, NUTCOMPONENT * compo, int cnt){    int i;    int rc = 0;    NUTCOMPONENT *cop = compo;    /*     * If explicit targets are specified, we list the objects and     * hope that Makerules will do it right.     */    while (rc < cnt && cop) {        if(cop->nc_enabled) {            if(cop->nc_sources) {                for (i = 0; cop->nc_sources[i]; i++) {                    if(cop->nc_targets && cop->nc_targets[i]) {                        rc++;                        fprintf(fp, "OBJ%d = %s\n", rc, cop->nc_targets[i]);                    }                }            }            if (cop->nc_child) {                rc += AddMakeTargets(fp, cop->nc_child, cnt);            }        }        cop = cop->nc_nxt;    }    return rc;}/*! * \brief Add the source file list to the Makefile. * * \param fp      Pointer to an opened file. * \param compo   Pointer to a library component. * \param sub_dir Component's subdirectory in the build tree. * * \return Number of explicit target files. */int WriteMakeSources(FILE * fp, NUTCOMPONENT * compo, const char *sub_dir){    int rc;    int lpos;    fprintf(fp, "SRCS =\t");    lpos = 8;    rc = AddMakeSources(fp, compo, sub_dir, &lpos);    fputc('\n', fp);    AddMakeTargets(fp, compo, rc);    fputc('\n', fp);    return rc;}/*! * \brief Add the configured lines to the Makefile. * * \param fp Pointer to an opened file. * \param compo Pointer to a library component. * * \todo This is not yet finished. All 'name=value' pairs should *       be collected and combined. */void WriteMakedefLines(FILE * fp, NUTCOMPONENT * compo){    NUTCOMPONENTOPTION *opts;    int i;    /*     * Loop through all components.     */    while (compo) {        /* If this component is enabled and contains Makefile macros,           then simply print them to the file. */        if(compo->nc_enabled && compo->nc_makedefs) {            for (i = 0; compo->nc_makedefs[i]; i++) {                fprintf(fp, "%s\n", compo->nc_makedefs[i]);            }        }        /*         * Loop through all options of this component.         */        opts = compo->nc_opts;        while (opts) {            if (opts->nco_enabled && opts->nco_active && opts->nco_makedefs) {                for (i = 0; opts->nco_makedefs[i]; i++) {                    fprintf(fp, "%s", opts->nco_makedefs[i]);                    if(strchr(opts->nco_makedefs[i], '=') || opts->nco_value == NULL) {                        fputc('\n', fp);                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -