//-------------------------------------------------------------------------- bool groupman_t::parse_line( psupergroup_t sg, char *line) { for (char *saved_ptr, *token = qstrtok(line, ";", &saved_ptr); token != NULL; token = qstrtok(NULL, ";", &saved_ptr)) { char *val = strchr(token, ':'); if (val == NULL) continue; // Kill separator and adjust value pointer *val++ = '\0'; val = skip_spaces(val); // Set key pointer char *key = skip_spaces(token); if (stricmp(key, STR_ID) == 0) { sg->id = val; } else if (stricmp(key, STR_GROUP_NAME) == 0) { sg->name = val; } else if (stricmp(key, STR_NODESET) == 0) { if (!parse_nodeset(sg, val)) return false; } } return true; }
bool split_chooser_caption(qstring *out_title, qstring *out_caption, const char *caption) const { if ( get_embedded() != NULL ) { // For embedded chooser, the "caption" will be overloaded to encode // the AskUsingForm's title, caption and embedded chooser id // Title:EmbeddedChooserID:Caption char title_buf[MAXSTR]; const char *ptitle; static const char delimiter[] = ":"; char temp[MAXSTR]; qstrncpy(temp, caption, sizeof(temp)); char *ctx; char *p = qstrtok(temp, delimiter, &ctx); if ( p == NULL ) return false; // Copy the title char title_str[MAXSTR]; qstrncpy(title_str, p, sizeof(title_str)); // Copy the echooser ID p = qstrtok(NULL, delimiter, &ctx); if ( p == NULL ) return false; char id_str[10]; qstrncpy(id_str, p, sizeof(id_str)); // Form the new title of the form: "AskUsingFormTitle:EchooserId" qsnprintf(title_buf, sizeof(title_buf), "%s:%s", title_str, id_str); // Adjust the title *out_title = title_buf; // Adjust the caption p = qstrtok(NULL, delimiter, &ctx); *out_caption = caption + (p - temp); } else { *out_title = title; *out_caption = caption; } return true; }
/** * String Tokenizer * * @param str source string * @param delimiters string that specifies a set of delimiters that may * surround the token being extracted * * @return qlist container pointer otherwise returns NULL. * * @code * qlist_t *tokens = qstr_tokenizer("a:b:c", ":"); * char *str; * while((str = tokens->popFirst(tokens, NULL)) != NULL) { * printf("%s\n", str); * } * tokens->free(tokens); * @endcode */ qlist_t *qstrtokenizer(const char *str, const char *delimiters) { qlist_t *list = qlist(); if (list == NULL) return NULL; int i; char *dupstr = strdup(str); char *token; int offset = 0; for (i = 1, token = qstrtok(dupstr, delimiters, NULL, &offset); token != NULL; token = qstrtok(dupstr, delimiters, NULL, &offset), i++) { list->addlast(list, token, strlen(token) + 1); } free(dupstr); return list; }
//-------------------------------------------------------------------------- bool groupman_t::parse_nodeset( psupergroup_t sg, char *grpstr) { // Find node group bounds for ( /*init*/ char *p_group_start = NULL, *p_group_end = NULL; /* cond*/(p_group_start = strchr(grpstr, '(')) != NULL && (p_group_start = skip_spaces(p_group_start+1), (p_group_end = strchr(p_group_start, ')')) != NULL); /*incr*/) { // Terminate the string with the closing parenthesis *p_group_end = '\0'; // Advance to next group grpstr = skip_spaces(p_group_end + 1); // Add a new group pnodegroup_t ng = sg->add_nodegroup(); for (/*init*/ char *saved_ptr, *p = p_group_start, *token = qstrtok(p, ",", &saved_ptr); /*cond*/ p != NULL; /*incr*/ p = qstrtok(NULL, ",", &saved_ptr)) { p = skip_spaces(p); int nid; ea_t start = 0, end = 0; if (qsscanf(p, "%d : %a : %a", &nid, &start, &end) <= 0) continue; // Create an ND nodedef_t *nd = ng->add_node(); nd->nid = nid; nd->start = start; nd->end = end; // Map this node map_nodedef(nid, nd); } } return true; }