static sixtp* get_parser1_1_parser2(void) { sixtp *ret; sixtp *foobarer; ret = simple_parser(); foobarer = simple_parser(); sixtp_add_sub_parser(ret, "foobar", foobarer); sixtp_add_sub_parser(foobarer, "blah", sixtp_dom_parser_new(print_dom_tree, NULL, NULL)); sixtp_add_sub_parser(foobarer, "you", sixtp_dom_parser_new(print_dom_tree, NULL, NULL)); return ret; }
/* * process project file */ int process_project (int noconfig) { char projfile[sizeof(cnf.myhome)+SHORTNAME]; int pline=0, ret=0; FILE *fp; char str[CMDLINESIZE]; char *ptr; int section = 0; /* 1 for project config, 2 for project files */ int len, length[3]; /* prefix patterns */ int focus; if (noconfig) { return 0; } strncpy(projfile, cnf.myhome, sizeof(projfile)); strncat(projfile, cnf.project, SHORTNAME-6); strncat(projfile, ".proj", 6); length[0] = strlen(PROJECT_HEADER); length[1] = strlen(PROJECT_FILES); length[2] = strlen(PROJECT_CHDIR); if ((fp = fopen(projfile, "r")) == NULL) { fprintf(stderr, "eda: cannot open project file [%s]\n", projfile); return 1; } pline = 0; while (ret==0) { if (fgets (str, CMDLINESIZE, fp) == NULL) { if (ferror(fp)) { ERRLOG(0xE093); ret = 8; } break; } ++pline; len = strlen(str); if (len > 0 && str[len-1] == '\n') str[--len] = '\0'; strip_blanks (STRIP_BLANKS_FROM_END|STRIP_BLANKS_FROM_BEGIN, str, &len); if (section == 0) { if ((len >= length[0]) && (strncmp(str, PROJECT_HEADER, (size_t)length[0]) == 0)) { section = 1; continue; } } else if (section == 1) { if ((len >= length[1]) && (strncmp(str, PROJECT_FILES, (size_t)length[1]) == 0)) { section = 2; continue; } else if ((len > length[2]) && (strncmp(str, PROJECT_CHDIR, (size_t)length[2]) == 0)) { ptr = str+length[2]; len -= length[2]; if (len > 1) strip_blanks (STRIP_BLANKS_FROM_BEGIN, ptr, &len); if (len > 1) { if (chdir(ptr)) { ret = 2; break; } } else { ret = 1; break; } /* after chdir(ptr) ... save current workdir */ if (getcwd(cnf._pwd, sizeof(cnf._pwd)-1) == NULL) { /* fallback */ strncpy(cnf._pwd, ptr, sizeof(cnf._pwd)); cnf._pwd[sizeof(cnf._pwd)-1] = '\0'; } cnf.l1_pwd = strlen(cnf._pwd); /**/ if (read_extcmd_line ("pwd", 1, cnf._altpwd, sizeof(cnf._altpwd))) { /* fallback */ cnf._altpwd[0] = '\0'; cnf.l2_altpwd = 0; } else { cnf.l2_altpwd = strlen(cnf._altpwd); if (cnf.l1_pwd == cnf.l2_altpwd && strncmp(cnf._pwd, cnf._altpwd, cnf.l1_pwd) == 0) { cnf._altpwd[0] = '\0'; cnf.l2_altpwd = 0; } } /* do not call set() */ continue; } } if (len == 0 || str[0] == '#') { continue; } if (section == 1) { ret = set (str); if (ret) ret += 100; } else if (section == 2) { /* settings after a filename: focus */ if (strncmp(str, "focus=", 6) == 0) { if (cnf.ring_size > 0 && CURR_FILE.fflag & FSTAT_OPEN) { focus = strtol(str+6, NULL, 10); if (focus > 0) /* cnf.maxy is undefined at this point! */ CURR_FILE.focus = focus; } continue; } /**/ ret = simple_parser(str, SIMPLE_PARSER_JUMP); if (ret) ret += 200; } } fclose(fp); if (ret) { fprintf(stderr, "eda: processing [%s] failed (ret=%d), line=%d\n", projfile, ret, pline); } return (ret); }/* process_project */