/* We are single threaded now, hence it's ok to use strtok() */ static int do_ls(struct AffReader_s *r, const char *name, const char *kp) { // char *pp = xstrdup(kp); // char *p = pp; struct AffNode_s *root = aff_reader_root(r); struct AffNode_s *node; struct arg arg; node = lookup_path(r, root, kp); if (NULL == node) { fprintf(stderr, "lhpc-aff: %s[%s]: cannot read node\n", name, kp); return 0; // FIXME print error and proceed } // for (node = root, p = strtok(p, "/"); p; p = strtok(NULL, "/")) { // node = aff_reader_chdir(r, node, p); // if (node == 0) { // fprintf(stderr, "lhpc-aff: error accesing %s:%s at %s\n", // name, kp, p); // free(pp); // return 0; // FIXME print error and proceed // } // } // free(pp); arg.r = r; arg.fname = name; arg.kpath = kp; arg.root = root; do_node(node, &arg); return (aff_reader_errstr(r) != 0); }
void HLParser::do_node(HLNode *host, int entry_level) { // Get next saveable line: while (read_line() && !cur_line_is_node()) ; while (file_ready()) { if (cur_line_is_node()) { int diff = level() - entry_level; // If at level() is higher than @p level, the current line // is a child of @p host. Add a node as a child, and pass the // child as a host to a recursive call to do_node(). do_node() // will return when level() <= @p level, meaning the pending // node is either a sibling or ancestor. if (diff > 0) { do_node(host->direct_add_child(tag(), value()), level()); // Return to top of loop without a new read_line() in order // to determine where to put the pending node: continue; } // If lower level, return to process the pending ancestor node: else if (diff < 0) break; // If at same level, add node as a sibling, then // fall through to read next line: else // if (diff==0) host = host->direct_add_sibling(tag(), value()); } read_line(); } }
HLParser::HLParser(FILE *f, HLNode *root) : m_file(f), m_cur_level(0), m_cur_tag(nullptr), m_cur_value(nullptr), m_hyphenated_tags(false), m_case_insensitive(false) { do_node(root, -1); }