cvs: pecl /bbcode/lib bbcode2.c bbcode2.h

From: Date: Thu, 13 Sep 2007 16:30:58 +0000
Subject: cvs: pecl /bbcode/lib bbcode2.c bbcode2.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-8564@lists.php.net to get a copy of this message
void Thu Sep 13 16:30:58 2007 UTC Modified files: /pecl/bbcode/lib bbcode2.c bbcode2.h Log: Added Smiley handling, almost Finished BBCode Lib 2.0 \o/

http://cvs.php.net/viewvc.cgi/pecl/bbcode/lib/bbcode2.c?r1=1.3&r2=1.4&diff_format=u Index: pecl/bbcode/lib/bbcode2.c diff -u pecl/bbcode/lib/bbcode2.c:1.3 pecl/bbcode/lib/bbcode2.c:1.4 --- pecl/bbcode/lib/bbcode2.c:1.3 Tue Sep 11 13:07:12 2007 +++ pecl/bbcode/lib/bbcode2.c Thu Sep 13 16:30:57 2007 @@ -17,7 +17,7 @@ /*---------------------------* * Public API * *---------------------------*/ -/* Create and init a parser */ +/* Create and init a parser */ bbcode_parser_p bbcode_parser_create() { bbcode_parser_p parser; parser=(bbcode_parser_p)malloc(sizeof(bbcode_parser)); @@ -80,50 +80,50 @@ bstring to_parse; bstring parsed; if (parser->options&BBCODE_DISABLE_TREE_BUILD) { - // No BBCode Parsing + /* No BBCode Parsing */ if (parser->options&BBCODE_FORCE_SMILEYS_OFF) { - // No Smiley Treatment + /* No Smiley Treatment */ *result_size=string_size; char *return_value=(char *)malloc(string_size * sizeof(char)); return memcpy(return_value, string, string_size); } - // Prepare Datas for smiley + /* Prepare Datas for smiley */ balloc(to_parse, string_size+5); to_parse->slen=string_size; to_parse->data=memcpy(to_parse->data, string, string_size); - // Smiley Parsing - bbcode_parse_smileys(to_parse); - // Getting Treated Datas + /* Smiley Parsing */ + bbcode_parse_smileys(to_parse, parser->smileys); + /* Getting Treated Datas */ *result_size=to_parse->slen; char *return_value; return_value=(char *)malloc((*result_size*sizeof(char))); return_value=memcpy(return_value, to_parse->data, to_parse->slen); bdestroy(to_parse); - // Returning Value + /* Returning Value */ return return_value; } else { - // Prepare Datas for parsing + /* Prepare Datas for parsing */ balloc(to_parse, string_size+5); to_parse->slen=string_size; to_parse->data=memcpy(to_parse->data, string, string_size); - // starting the tree + /* starting the tree */ bbcode_parse_tree_p tree=bbcode_tree_create(); - // Preparing tag_list if needed + /* Preparing tag_list if needed */ bbcode_prepare_tag_list(parser); - // Build the BBCode Tree from the string + /* Build the BBCode Tree from the string */ bbcode_build_tree(parser, to_parse, tree); - // Correct Tree to match restrictions + /* Correct Tree to match restrictions */ bbcode_correct_tree(parser, tree, -1, 0); - // Reset the working string + /* Reset the working string */ bassigncstr(to_parse, ""); - // Apply the Output Rules + /* Apply the Output Rules */ bbcode_apply_rules(parser, tree, to_parse); - // Getting the return string + /* Getting the return string */ *result_size=to_parse->slen; char *return_value=(char *)malloc(*result_size * sizeof(char)); return_value=memcpy(return_value, to_parse->data, to_parse->slen); bdestroy(to_parse); - // Return Value + /* Return Value */ return return_value; } } @@ -138,9 +138,9 @@ parser->options=flags; } -/*--------------------------- - Internal API - ---------------------------*/ +/* ----------------------------* + * Internal API * + * ----------------------------*/ /* Parse nesting rules and optimize datas */ void bbcode_prepare_tag_list(bbcode_parser_p parser) { bbcode_list_p list; @@ -187,7 +187,7 @@ bbcode->childs->size=0; if (blength(bbcode->parent_list)) { if (biseqcstr(bbcode->parent_list, "all")) { - // All Accepted + /* All Accepted */ bbcode->parents->type=BBCODE_ALLOW_LIST_TYPE_ALL; } else { if (bchar(bbcode->parent_list, 0)=='!') { @@ -208,11 +208,10 @@ bstrListDestroy(bsplited); } } else { - // None Accepted + /* None Accepted */ bbcode->parents->type=BBCODE_ALLOW_LIST_TYPE_NONE; } } - /* TODO: INDEX Creation */ if (list->bbcode_max_size !=0) { for (i=0; i<list->bbcode_max_size; i++) { if (list->search_cache[i] !=NULL) { @@ -254,7 +253,7 @@ /* This reparse nesting rules and optimize datas */ void bbcode_build_tree(bbcode_parser_p parser, bstring string, bbcode_parse_tree_p tree) { - //INIT + /* INIT */ bstring end_quote, end_double, end_single, end_html, html_quote, argument, tag; char no_quote; @@ -269,7 +268,7 @@ end_single=bfromcstr("\']"); end_html=bfromcstr("&quot;]"); html_quote=bfromcstr("&quot;"); - // END INIT + /* END INIT */ offset=bstrchr(string, '['); bbcode_tree_push_string_child(tree, bmidstr(string, 0, offset)); bbcode_parse_tree_array_p work_stack, close_stack; @@ -279,12 +278,12 @@ added=0; if (bchar(string, offset)=='[') { if (bchar(string, offset+1)!='/') { - //Open + /* Open */ bbcode_find_next(next_equal, string, offset, '='); - // Equal + /* Equal */ bbcode_find_next(next_close, string, offset, ']'); if (next_close<string_length) { - // With Arg + /* With Arg */ if (next_equal<next_close) { tag = bmidstr(string, offset+1, next_equal-offset-1); if (BBCODE_ERR==(tag_id=bbcode_get_tag_id(parser, tag, @@ -336,7 +335,7 @@ end=next_close; } } else { - // Without Args + /* Without Args */ tag=bmidstr(string, offset+1, next_close-offset-1); end=next_close; if (BBCODE_ERR!=(tag_id=bbcode_get_tag_id(parser, tag, @@ -356,7 +355,7 @@ } } else { bbcode_find_next(next_close, string, offset, ']'); - //Close + /* Close */ tag=bmidstr(string, offset+2, next_close-offset-2); end=next_close; if (BBCODE_ERR!=(tag_id=bbcode_get_tag_id(parser, tag, -1))) { @@ -379,7 +378,7 @@ } offset=end+1; } while (offset<string_length); - // Freeing ressources + /* Freeing ressources */ bdestroy(end_html); bdestroy(end_double); bdestroy(end_single); @@ -393,7 +392,7 @@ int tag_id, bstring close_string, int true_close) { int i; char in_close=0; - // Check if on close List + /* Check if on close List */ for (i=0; i<bbcode_array_length(close); i++) { if (bbcode_array_element(close,i)->tag_id==tag_id) { in_close=1; @@ -401,12 +400,12 @@ } } if (in_close) { - // Mark Element as closed + /* Mark Element as closed */ bbcode_tree_mark_element_closed((close->element[i])); - // Tag Allready closed, droping silently + /* Tag Allready closed, droping silently */ bbcode_parse_drop_element_at(close, i); } else { - // Check If Opened + /* Check If Opened */ char opened=0; for (i=0; i<work->size; i++) { if (bbcode_array_element(work,i)->tag_id==tag_id) { @@ -432,9 +431,9 @@ /* It's not the searched tag */ /* Is this tag putting conditions on tag_id nesting ? */ if (bbcode_allow_list_check_access(bbcode_get_bbcode(parser, bbcode_get_cn(parser)->tag_id)->childs, tag_id)) { - // Fixme - //conditions[cond_size]=bbcode_get_cn(parser); - //cond_size++; + /* Fixme + * conditions[cond_size]=bbcode_get_cn(parser); + * cond_size++; */ } parser->current_node->close_string=NULL; if (bbcode_get_bbcode(parser,bbcode_get_cn(parser)->tag_id)->flags @@ -454,18 +453,18 @@ bbcode_parse_tree_p tmp_tree; bbcode_parse_tree_array_p first; for (i=close->size-1; i>=0; --i) { - // First Multipart Element + /* First Multipart Element */ if (!bbcode_array_element(close,i)->flags&BBCODE_TREE_FLAGS_MULTIPART) { if (bbcode_array_element(close,i)->flags &BBCODE_TREE_FLAGS_MULTIPART_FIRST_NODE) { } else { - // The multipart Tree is common to all multipart elements of a set + /* The multipart Tree is common to all multipart elements of a set */ } } tmp_tree=bbcode_tree_create(); tmp_tree->flags=BBCODE_TREE_FLAGS_MULTIPART; - //tmp_tree->multiparts=*bbcode_array_element(close,i); + /* tmp_tree->multiparts=*bbcode_array_element(close,i); */ tmp_tree->open_string=NULL; tmp_tree->close_string=NULL; tmp_tree->parent_node=bbcode_get_cn(parser); @@ -484,12 +483,13 @@ void bbcode_correct_tree(bbcode_parser_p parser, bbcode_parse_tree_p tree, int parent_id, char force_false) { char autocorrect; + /* TODO: Implement */ } /* This apply the BBCode rules to generate the final string */ void bbcode_apply_rules(bbcode_parser_p parser, bbcode_parse_tree_p tree, bstring parsed) { - + /* TODO: Implement */ } /* Search a tag_id from the string */ @@ -574,7 +574,11 @@ } /* Translate Smileys */ -void bbcode_parse_smileys(bstring string) { +void bbcode_parse_smileys(bstring string, bbcode_smiley_list_p list) { + int i; + for (i=0; i<list->size; i++){ + bfindreplace(string, list->smileys[i].search, list->smileys[i].replace, 0); + } } /*--------------------------- @@ -711,12 +715,12 @@ bbcode_p bbcode_entry_create() { bbcode_p bbcode; bbcode=malloc(sizeof(bbcode)); - // Init values + /* Init values */ bbcode->type = bbcode->speed_cache = bbcode->flags = 0; bbcode->open_tag = bbcode->close_tag = bbcode->default_arg = bbcode->child_list = bbcode->parent_list = NULL; bbcode->param_handling_func_data = bbcode->content_handling_func_data = NULL; bbcode->param_handling_func = bbcode->content_handling_func = NULL; - // Starting Up allow_lists + /* Starting Up allow_lists */ bbcode->parents=bbcode_allow_list_create(); bbcode->childs=bbcode_allow_list_create(); return bbcode; @@ -724,8 +728,8 @@ /* Free a bbcode entry ressources */ void bbcode_entry_free(bbcode *entry) { - // Freeing automaticaly started datas; - // All other stored datas must be freed by user + /* Freeing automaticaly started datas; */ + /* All other stored datas must be freed by user */ bbcode_allow_list_free(entry->parents); bbcode_allow_list_free(entry->childs); free(entry); @@ -767,18 +771,18 @@ /* Check if a given id is autorized */ int bbcode_allow_list_check_access(bbcode_allow_list_p list, int tag_id) { - // The easy ones + /* The easy ones */ if (list->type==BBCODE_ALLOW_LIST_TYPE_ALL) { return 1; } else if (list->type==BBCODE_ALLOW_LIST_TYPE_NONE) { return 0; } - // And Now, We run + /* And Now, We run */ else { int i; for (i=0; i<list->size; i++) { if (list->id_list[i]==tag_id) { - //Found, we check if its a include or exclude list + /* Found, we check if its a include or exclude list */ if (list->type==BBCODE_ALLOW_LIST_TYPE_LISTED) { return 1; } else { @@ -786,7 +790,7 @@ } } } - // Not Found, checking if we're on include or exclude list + /* Not Found, checking if we're on include or exclude list */ if (list->type==BBCODE_ALLOW_LIST_TYPE_LISTED) { return 0; } else { @@ -797,17 +801,17 @@ /* return 1 if no_childs are accepted return 0 oterwise */ int bbcode_allow_list_no_child(bbcode_allow_list_p list) { - // Most of tags have no restrictions so exit ASAP + /* Most of tags have no restrictions so exit ASAP */ if (list->type==BBCODE_ALLOW_LIST_TYPE_ALL) { return 0; - } else if (list->type==BBCODE_ALLOW_LIST_TYPE_NONE) { // No childs + } else if (list->type==BBCODE_ALLOW_LIST_TYPE_NONE) { /* No childs */ return 1; - } else if (list->type==BBCODE_ALLOW_LIST_TYPE_LISTED) { // Only Listed Childs and size=0 + } else if (list->type==BBCODE_ALLOW_LIST_TYPE_LISTED) { /* Only Listed Childs and size=0 */ if (list->size=0) { return 1; } } - // Undetermined Case: If exclude list with everything in it, (people using it must be considered insane -_-") + /* Undetermined Case: If exclude list with everything in it, (people using it must be considered insane -_-") */ return 0; } @@ -830,12 +834,31 @@ /* Free the ressources taken by a tree */ void bbcode_tree_free(bbcode_parse_tree_p tree) { - + int i; + for (i=0; i < tree->childs.size; i++) { + if (tree->childs.element[i]->type==BBCODE_TREE_CHILD_TYPE_TREE) { + bbcode_tree_free(tree->childs.element[i]->tree); + } else { + bdestroy(tree->childs.element[i]->string); + } + } + free(tree->childs.element); + if (tree->open_string != NULL) { + bdestroy(tree->open_string); + } + if (tree->close_string != NULL) { + bdestroy(tree->close_string); + } } /* Check if there is sufficient space in child array */ void bbcode_tree_check_child_size(bbcode_parse_tree_p tree, int size) { - + if (tree->childs.msize<size) { + tree->childs.element=(bbcode_parse_tree_child_pp) realloc( + tree->childs.element, sizeof(bbcode_parse_tree_child_p)*(size + +BBCODE_BUFFER)); + tree->childs.msize=size+BBCODE_BUFFER; + } } /* adds a child to the current list (sub_tree) */ @@ -843,41 +866,68 @@ bbcode_parse_tree_p tree, bbcode_parse_tree_array_p work, bbcode_parse_tree_array_p close, bstring open_string, int tagId, bstring argument) { - + /* TODO Implement */ } /* adds a child to the current list (string_leaf) */ void bbcode_tree_push_string_child(bbcode_parse_tree_p tree, bstring string) { - + bbcode_tree_check_child_size(tree, tree->childs.size+1); + tree->childs.element[tree->childs.size]->string=string; + tree->childs.size++; } /* adds a tree to the current list (raw) */ void bbcode_tree_push_tree_raw(bbcode_parse_tree_p tree, bbcode_parse_tree_p tmp_tree, bbcode_parse_tree_array_p work) { - + bbcode_tree_check_child_size(tree, tree->childs.size+1); + tree->childs.element[tree->childs.size]->tree=tmp_tree; + bbcode_parse_stack_push_element(work, tmp_tree); + tree->childs.size++; } /* Get the last child and removes it from the list */ void bbcode_tree_pop_child(bbcode_parse_tree_p tree, bbcode_parse_tree_child_p bbcode_parse_tree_child) { - + bbcode_parse_tree_child=tree->childs.element[tree->childs.size]; + tree->childs.size--; } /* Insert a given child on a given position */ void bbcode_tree_insert_child_at(bbcode_parse_tree_p tree, bbcode_parse_tree_child_p bbcode_parse_tree_child, int pos) { - + bbcode_tree_check_child_size(tree, tree->childs.size+1); + int size=sizeof(bbcode_parse_tree_child_p); + memmove(tree->childs.element+(size*(pos+1)), tree->childs.element + +(size*pos), size*(tree->childs.size-pos)); + tree->childs.element[pos]=bbcode_parse_tree_child; } /* Mark an element closed, (and also multipart elements) */ void bbcode_tree_mark_element_closed(bbcode_parse_tree_p tree) { - + tree->flags |=BBCODE_TREE_FLAGS_PAIRED; + if (tree->flags & BBCODE_TREE_FLAGS_MULTIPART) { + /* TODO Multipart Code */ + } } /* Move a child set from a parent to another */ void bbcode_tree_move_childs(bbcode_parse_tree_p from, bbcode_parse_tree_p to, int offset_from, int count, int offset_to) { - + bbcode_parse_child_p start, stop; + bbcode_tree_check_child_size(to, to->childs.size+count); + /* We First Move the current childs to leave space */ + memmove(to->childs.element[offset_to+count], to->childs.element[offset_to], + sizeof(bbcode_parse_child_p)*(to->childs.size-offset_to)); + /* Copying Childs From Old Position to new */ + memcpy(to->childs.element[offset_to], from->childs.element[offset_from], + count * sizeof(bbcode_parse_child_p)); + /* Reducing Child Set In From Elements */ + memmove(from->childs.element[offset_from], + from->childs.element[offset_from+count], + sizeof(bbcode_parse_child_p) * (from->childs.size-offset_from)); + /* Setting the sizes to correct values */ + to->childs.size+=count; + from->childs.size-=count; } /*--------------------------- http://cvs.php.net/viewvc.cgi/pecl/bbcode/lib/bbcode2.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/bbcode/lib/bbcode2.h diff -u pecl/bbcode/lib/bbcode2.h:1.3 pecl/bbcode/lib/bbcode2.h:1.4 --- pecl/bbcode/lib/bbcode2.h:1.3 Tue Sep 11 13:07:12 2007 +++ pecl/bbcode/lib/bbcode2.h Thu Sep 13 16:30:57 2007 @@ -85,146 +85,147 @@ bdestroy(close_tag); \ } -typedef struct _bbcode_smiley bbcode_smiley; -typedef struct _bbcode_smiley * bbcode_smiley_p; -typedef struct _bbcode_smiley_array bbcode_smiley_list; -typedef struct _bbcode_smiley_array * bbcode_smiley_list_p; -typedef struct _bbcode_allow_list bbcode_allow_list; -typedef struct _bbcode_allow_list * bbcode_allow_list_p; -typedef struct _bbcode bbcode; -typedef struct _bbcode * bbcode_p; -typedef struct _bbcode ** bbcode_pp; -typedef struct _bbcode_search bbcode_search; -typedef struct _bbcode_search * bbcode_search_p; -typedef struct _bbcode_search ** bbcode_search_pp; -typedef struct _bbcode_array bbcode_array; -typedef struct _bbcode_array * bbcode_array_p; -typedef struct _bbcode_list bbcode_list; -typedef struct _bbcode_list * bbcode_list_p; -typedef struct _bbcode_parser bbcode_parser; -typedef struct _bbcode_parser * bbcode_parser_p; -typedef struct _bbcode_parse_tree bbcode_parse_tree; -typedef struct _bbcode_parse_tree * bbcode_parse_tree_p; -typedef struct _bbcode_parse_tree ** bbcode_parse_tree_pp; -typedef struct _bbcode_parse_tree_array bbcode_parse_tree_array; -typedef struct _bbcode_parse_tree_array* bbcode_parse_tree_array_p; -typedef struct _bbcode_parse_tree_child bbcode_parse_tree_child; -typedef struct _bbcode_parse_tree_child * bbcode_parse_tree_child_p; -typedef struct _bbcode_parse_tree_child ** bbcode_parse_tree_child_pp; -typedef struct _bbcode_parse_tree_child_array bbcode_parse_tree_child_array; -typedef struct _bbcode_tag_id_search bbcode_tag_id_search; -typedef struct _bbcode_tag_id_search * bbcode_tag_id_search_p; +typedef struct _bbcode_smiley bbcode_smiley; +typedef struct _bbcode_smiley * bbcode_smiley_p; +typedef struct _bbcode_smiley_array bbcode_smiley_list; +typedef struct _bbcode_smiley_array * bbcode_smiley_list_p; +typedef struct _bbcode_allow_list bbcode_allow_list; +typedef struct _bbcode_allow_list * bbcode_allow_list_p; +typedef struct _bbcode bbcode; +typedef struct _bbcode * bbcode_p; +typedef struct _bbcode ** bbcode_pp; +typedef struct _bbcode_search bbcode_search; +typedef struct _bbcode_search * bbcode_search_p; +typedef struct _bbcode_search ** bbcode_search_pp; +typedef struct _bbcode_array bbcode_array; +typedef struct _bbcode_array * bbcode_array_p; +typedef struct _bbcode_list bbcode_list; +typedef struct _bbcode_list * bbcode_list_p; +typedef struct _bbcode_parser bbcode_parser; +typedef struct _bbcode_parser * bbcode_parser_p; +typedef struct _bbcode_parse_tree bbcode_parse_tree; +typedef struct _bbcode_parse_tree * bbcode_parse_tree_p; +typedef struct _bbcode_parse_tree ** bbcode_parse_tree_pp; +typedef struct _bbcode_parse_tree_array bbcode_parse_tree_array; +typedef struct _bbcode_parse_tree_array* bbcode_parse_tree_array_p; +typedef struct _bbcode_parse_tree_child bbcode_parse_tree_child; +typedef struct _bbcode_parse_tree_child * bbcode_parse_tree_child_p; +typedef struct _bbcode_parse_tree_child ** bbcode_parse_tree_child_pp; +typedef struct _bbcode_parse_tree_child_array bbcode_parse_tree_child_array; +typedef struct _bbcode_tag_id_search bbcode_tag_id_search; +typedef struct _bbcode_tag_id_search * bbcode_tag_id_search_p; /* This represent a smiley list */ -struct _bbcode_smiley_array{ - int size; - int msize; - bbcode_smiley_p smileys; +struct _bbcode_smiley_array { + int size; + int msize; + bbcode_smiley_p smileys; }; /* Represents a set of bbcode rules */ -struct _bbcode_array{ - int size; - int msize; - bbcode_pp element; +struct _bbcode_array { + int size; + int msize; + bbcode_pp element; }; /* Represent an array of parse tree */ -struct _bbcode_parse_tree_array{ - int size; - int msize; - bbcode_parse_tree_pp element; +struct _bbcode_parse_tree_array { + int size; + int msize; + bbcode_parse_tree_pp element; }; /* Represents an array of parse_tree_child */ -struct _bbcode_parse_tree_child_array{ - int size; - int msize; - bbcode_parse_tree_child_pp element; +struct _bbcode_parse_tree_child_array { + int size; + int msize; + bbcode_parse_tree_child_pp element; }; /* This represent a single smiley with search / replace */ -struct _bbcode_smiley{ - bstring search; - bstring replace; +struct _bbcode_smiley { + bstring search; + bstring replace; }; /* This represent a list of allowed tags */ -struct _bbcode_allow_list{ - int *id_list; - char type; - int size; - int msize; +struct _bbcode_allow_list { + int *id_list; + char type; + int size; + int msize; }; /* This represent a BBCode Tag Rule Set */ -struct _bbcode{ - char type; - char flags; - char speed_cache; - bstring tag; - bstring open_tag; - bstring close_tag; - bstring default_arg; - bstring parent_list; - bstring child_list; - bbcode_allow_list_p parents; - bbcode_allow_list_p childs; - void *param_handling_func_data; - void *content_handling_func_data; - int (*param_handling_func)(bstring content, bstring param, void *func_data); - int (*content_handling_func)(bstring content, bstring param, void *func_data); +struct _bbcode { + char type; + char flags; + char speed_cache; + bstring tag; + bstring open_tag; + bstring close_tag; + bstring default_arg; + bstring parent_list; + bstring child_list; + bbcode_allow_list_p parents; + bbcode_allow_list_p childs; + void *param_handling_func_data; + void *content_handling_func_data; + int (*param_handling_func)(bstring content, bstring param, void *func_data); + int (*content_handling_func)(bstring content, bstring param, + void *func_data); }; /* This represent a complete BBCode Parsing Rule Set */ -struct _bbcode_list{ - int options; - int bbcode_max_size; - bbcode_array_p bbcodes; - bbcode_p root; - bbcode_search_pp search_cache; - int *num_cache; +struct _bbcode_list { + int options; + int bbcode_max_size; + bbcode_array_p bbcodes; + bbcode_p root; + bbcode_search_pp search_cache; + int *num_cache; }; /* This is the bbcode parser */ -struct _bbcode_parser{ - bbcode_parser_p argument_parser; - bbcode_smiley_list_p smileys; - bbcode_list_p bbcodes; - bbcode_parse_tree_p current_node; - int options; +struct _bbcode_parser { + bbcode_parser_p argument_parser; + bbcode_smiley_list_p smileys; + bbcode_list_p bbcodes; + bbcode_parse_tree_p current_node; + int options; }; /* This is the parse tree temporary data store */ -struct _bbcode_parse_tree{ - int tag_id; - int flags; - bbcode_parse_tree_child_array childs; - bbcode_parse_tree_array_p multiparts; - bbcode_parse_tree_array_p conditions; - bbcode_parse_tree_p parent_node; - bstring open_string; - bstring close_string; +struct _bbcode_parse_tree { + int tag_id; + int flags; + bbcode_parse_tree_child_array childs; + bbcode_parse_tree_array_p multiparts; + bbcode_parse_tree_array_p conditions; + bbcode_parse_tree_p parent_node; + bstring open_string; + bstring close_string; }; /* This is a single token found by parsing (in fact a token is often splitted with partial matches) */ -struct _bbcode_parse_tree_child{ - union { - bbcode_parse_tree_p tree; - bstring string; - }; - char type; +struct _bbcode_parse_tree_child { + union { + bbcode_parse_tree_p tree; + bstring string; + }; + char type; }; /* The tagId search cache */ -struct _bbcode_search{ - bstring tag_name; - int tag_id; +struct _bbcode_search { + bstring tag_name; + int tag_id; }; /*--------------------------- - Public API ----------------------------*/ + Public API + ---------------------------*/ /* Create and init a parser */ bbcode_parser_p bbcode_parser_create(); @@ -232,23 +233,23 @@ void bbcode_parser_free(bbcode_parser_p parser); /* Destroy a parser and associated ressources */ -void bbcode_parser_set_arg_parser(bbcode_parser_p parser, bbcode_parser_p arg_parser); +void bbcode_parser_set_arg_parser(bbcode_parser_p parser, + bbcode_parser_p arg_parser); /* Constructs and add a bbcode_element to the parser */ -void bbcode_parser_add_ruleset(bbcode_parser_p parser, char type, char flags, char *open_tag, - int open_tag_size, char *close_tag, int close_tag_size, char *default_arg, - int default_arg_size, char *parent_list, int parent_list_size, - char *child_list, int child_list_size, - int (*param_handling_func)(bstring content, bstring param, void *func_data), - int (*content_handling_func)(bstring content, bstring param, void *func_data), - void *param_handling_func_data, void *content_handling_func_data); +void bbcode_parser_add_ruleset(bbcode_parser_p parser, char type, char flags, + char *open_tag, int open_tag_size, char *close_tag, int close_tag_size, + char *default_arg, int default_arg_size, char *parent_list, + int parent_list_size, char *child_list, int child_list_size, int (*param_handling_func)(bstring content, bstring param, void *func_data), int (*content_handling_func)(bstring content, bstring param, void *func_data), + void *param_handling_func_data, void *content_handling_func_data); /* Construct and add a smiley to the parser */ -void bbcode_parser_add_smiley(bbcode_parser_p parser, char *smiley_search, int smiley_search_size, - char *smiley_replace, int smiley_replace_size); +void bbcode_parser_add_smiley(bbcode_parser_p parser, char *smiley_search, + int smiley_search_size, char *smiley_replace, int smiley_replace_size); /* Parse a BBCoded string to is treated equivalent */ -char *bbcode_parse (bbcode_parser_p parser, char *string, int string_size, int *result_size); +char *bbcode_parse(bbcode_parser_p parser, char *string, int string_size, + int *result_size); /* Get current options of the bbcode_parser */ int bbcode_parser_get_flags(bbcode_parser_p parser); @@ -257,47 +258,53 @@ void bbcode_parser_set_flags(bbcode_parser_p parser, int flags); /*--------------------------- - Internal API ----------------------------*/ + Internal API + ---------------------------*/ /* Parse nesting rules and optimize datas */ void bbcode_prepare_tag_list(bbcode_parser_p parser); /* This reparse nesting rules and optimize datas */ -void bbcode_build_tree (bbcode_parser_p parser, bstring string, bbcode_parse_tree_p tree); +void bbcode_build_tree(bbcode_parser_p parser, bstring string, + bbcode_parse_tree_p tree); /* This closes an active tag */ -void bbcode_close_tag (bbcode_parser_p parser, bbcode_parse_tree_p tree, bbcode_parse_tree_array_p work, bbcode_parse_tree_array_p close, int tag_id, bstring close_string, int true_close); +void bbcode_close_tag(bbcode_parser_p parser, bbcode_parse_tree_p tree, + bbcode_parse_tree_array_p work, bbcode_parse_tree_array_p close, + int tag_id, bstring close_string, int true_close); /* This make some basic corrections to a given tree */ -void bbcode_correct_tree (bbcode_parser_p parser, bbcode_parse_tree_p tree, int parent_id, char force_false); +void bbcode_correct_tree(bbcode_parser_p parser, bbcode_parse_tree_p tree, + int parent_id, char force_false); /* This apply the BBCode rules to generate the final string */ -void bbcode_apply_rules (bbcode_parser_p parser, bbcode_parse_tree_p tree, bstring parsed); +void bbcode_apply_rules(bbcode_parser_p parser, bbcode_parse_tree_p tree, + bstring parsed); /* Search a tag_id from the string */ -int bbcode_get_tag_id (bbcode_parser_p parser, bstring value, int has_arg); +int bbcode_get_tag_id(bbcode_parser_p parser, bstring value, int has_arg); /* Translate Smileys */ -void bbcode_parse_smileys(bstring string); +void void bbcode_parse_smileys(bstring string, bbcode_smiley_list_p list); /*--------------------------- - Smiley Manipulation API ----------------------------*/ + Smiley Manipulation API + ---------------------------*/ /* Initialize a smiley list */ -bbcode_smiley_list_p bbcode_smileys_list_create (); +bbcode_smiley_list_p bbcode_smileys_list_create(); /* Free a smiley list */ -void bbcode_smileys_list_free (bbcode_smiley_list_p list); +void bbcode_smileys_list_free(bbcode_smiley_list_p list); /* Check if we can add an entry */ -void bbcode_smiley_list_check_size (bbcode_smiley_list_p list, int size); +void bbcode_smiley_list_check_size(bbcode_smiley_list_p list, int size); /* adds a smiley to the list */ -void bbcode_smileys_add (bbcode_smiley_list_p list, bstring search, bstring replacement); +void bbcode_smileys_add(bbcode_smiley_list_p list, bstring search, + bstring replacement); /*--------------------------- BBCode List Manipulation API ----------------------------*/ + ---------------------------*/ /* creates a BBcode list and init it */ bbcode_list_p bbcode_list_create(); @@ -314,23 +321,23 @@ void bbcode_list_add(bbcode_list_p list, bbcode_p to_add); /*--------------------------- -BBCode Array Manipulation API ----------------------------*/ + BBCode Array Manipulation API + ---------------------------*/ /* creates a BBcode array and init it */ bbcode_array_p bbcode_array_create(); /* Free a BBCode array */ -void bbcode_array_free (bbcode_array_p array); +void bbcode_array_free(bbcode_array_p array); /* Check if we can add an entry */ -void bbcode_array_check_size (bbcode_array_p array, int size); +void bbcode_array_check_size(bbcode_array_p array, int size); /* adds a bbcode_rule to the list */ -void bbcode_array_add (bbcode_array_p array, bbcode_p bbcode); +void bbcode_array_add(bbcode_array_p array, bbcode_p bbcode); /*--------------------------- -BBCode Entry Manipulation API ----------------------------*/ + BBCode Entry Manipulation API + ---------------------------*/ /* Malloc a bbcode entry and init it */ bbcode_p bbcode_entry_create(); @@ -338,8 +345,8 @@ void bbcode_entry_free(bbcode_p entry); /*--------------------------- -BBCode Allow Manipulation API ----------------------------*/ + BBCode Allow Manipulation API + ---------------------------*/ /* Malloc a bbcode_allow_list and init it */ bbcode_allow_list_p bbcode_allow_list_create(); @@ -359,8 +366,8 @@ int bbcode_allow_list_no_child(bbcode_allow_list_p list); /*--------------------------- - Tree Manipulation API ----------------------------*/ + Tree Manipulation API + ---------------------------*/ /* Malloc and init a bbcode tree */ bbcode_parse_tree_p bbcode_tree_create(); @@ -371,29 +378,36 @@ void bbcode_tree_check_child_size(bbcode_parse_tree_p tree, int size); /* adds a child to the current list (sub_tree) */ -void bbcode_tree_push_tree_child (bbcode_parser_p parser, bbcode_parse_tree_p tree, bbcode_parse_tree_array_p work, bbcode_parse_tree_array_p close, bstring open_string, int tagId, bstring argument); +void bbcode_tree_push_tree_child(bbcode_parser_p parser, + bbcode_parse_tree_p tree, bbcode_parse_tree_array_p work, + bbcode_parse_tree_array_p close, bstring open_string, int tagId, + bstring argument); /* adds a child to the current list (string_leaf) */ -void bbcode_tree_push_string_child (bbcode_parse_tree_p tree, bstring string); +void bbcode_tree_push_string_child(bbcode_parse_tree_p tree, bstring string); /* adds a tree to the current list (raw) */ -void bbcode_tree_push_tree_raw (bbcode_parse_tree_p tree, bbcode_parse_tree_p tmp_tree, bbcode_parse_tree_array_p work); +void bbcode_tree_push_tree_raw(bbcode_parse_tree_p tree, + bbcode_parse_tree_p tmp_tree, bbcode_parse_tree_array_p work); /* Get the last child and removes it from the list */ -void bbcode_tree_pop_child(bbcode_parse_tree_p tree, bbcode_parse_tree_child_p bbcode_parse_tree_child); +void bbcode_tree_pop_child(bbcode_parse_tree_p tree, + bbcode_parse_tree_child_p bbcode_parse_tree_child); /* Insert a given child on a given position */ -void bbcode_tree_insert_child_at(bbcode_parse_tree_p tree, bbcode_parse_tree_child_p bbcode_parse_tree_child, int pos); +void bbcode_tree_insert_child_at(bbcode_parse_tree_p tree, + bbcode_parse_tree_child_p bbcode_parse_tree_child, int pos); /* Mark an element closed, (and also multipart elements) */ void bbcode_tree_mark_element_closed(bbcode_parse_tree_p tree); /* Move a child set from a parent to another */ -void bbcode_tree_move_childs(bbcode_parse_tree_p from, bbcode_parse_tree_p to, int offset_from, int count, int offset_to); +void bbcode_tree_move_childs(bbcode_parse_tree_p from, bbcode_parse_tree_p to, + int offset_from, int count, int offset_to); /*--------------------------- -Parse Stack Manipulation API ----------------------------*/ + Parse Stack Manipulation API + ---------------------------*/ /* Create a Tree array */ bbcode_parse_tree_array_p bbcode_parse_stack_create(); @@ -404,7 +418,8 @@ void bbcode_parse_stack_check_size(bbcode_parse_tree_array_p stack, int size); /* Add element to the Tree array */ -void bbcode_parse_stack_push_element(bbcode_parse_tree_array_p stack, bbcode_parse_tree_p element); +void bbcode_parse_stack_push_element(bbcode_parse_tree_array_p stack, + bbcode_parse_tree_p element); /* Remove element from the Tree array without giving it back */ void bbcode_parse_stack_pop_element_loose(bbcode_parse_tree_array_p stack); @@ -413,6 +428,6 @@ void bbcode_parse_drop_element_at(bbcode_parse_tree_array_p stack, int index); /*--------------------------- - Built-in callbacks ----------------------------*/ + Built-in callbacks + ---------------------------*/ #endif /*BBCODE_H_*/
« previous php.pecl.cvs (#8564) next »