#Author: Raven0 @ buxville.net *:/generate_AC_xml = >>> /* Create file to write into */ @file = "MethodScript.xml"; try(read(@file),chd_create(@file)); /* Prepare start of the file */ @file_Write = array( "", "", "", " ", " " ); /* Prepare JSON file, as we will use it to quickly get rid of some escapes */ @file_JSON_prep = array(); @file_JSON_prep["functions"] = array(); @file_JSON_prep["events"] = array(); /* Grab extensions */ @CH_extensions = extension_info(); /* START OF THE PROCESSING TO JSON FILE */ for(@x = 0, @x < array_size(@CH_extensions),@x++){ /* Define extension name and version */ @extension_Name = array_keys(@CH_extensions)[@x]; @extension_Version = @CH_extensions[@extension_Name]['version']; /* Define extension functions and events */ @functions = @CH_extensions[@extension_Name]['functions']; @events = @CH_extensions[@extension_Name]['events']; /* Catch all functions and prepare for JSON */ for(@y = 0, @y < array_size(@functions), @y++){ @function_Name = @functions[@y]; if(!string_starts_with(@function_Name,"_")){ try { /* Declare function and it's arguments */ @file_JSON_prep["functions"][@function_Name] = array(); @file_JSON_prep["functions"][@function_Name]['args'] = reflect_docs(@function_Name,"args"); @file_JSON_prep["functions"][@function_Name]['return'] = reflect_docs(@function_Name,"return"); @file_JSON_prep["functions"][@function_Name]['description'] = reflect_docs(@function_Name,"description"); } catch(FormatException @ex) {console(colorize("&eCould not show information for function: &a".@function_Name."&r"),false);} } } /* Catch all events and prepare for JSON */ for(@z = 0, @z < array_size(@events), @z++){ @event_Name = @events[@z]; if(!string_starts_with(@event_Name,"_")){ try { /* Declare event and it's arguments */ @file_JSON_prep["events"][] = @event_Name; } catch(FormatException @ex) {console(colorize("&eCould not show information for event: &a".@event_Name."&r"),false);} } } } /* ENCODE TO JSON FORMAT */ @file_JSON_prep1 = json_encode(@file_JSON_prep); @file_JSON = json_decode(@file_JSON_prep1); /* Start of the processing from JSON to XML */ /* FUNCTIONS */ @process_Functions = @file_JSON["functions"]; foreach(@function: @function_Args in @process_Functions){ /* FUNCTION NAME */ /* Process function name and write to XML */ @process_Function_Name = @function; @file_Write[] = " "; /* FUNCTION RETURNS & DESCRIPTION */ /* RETURNS */ @process_Function_Return = @function_Args["return"]; /* DESCRIPTION */ @process_Function_Description = @function_Args["description"]; /* REMOVE UNNECESSARY CHARACTERS/TAGS/ETC FROM DESCRIPTION */ # List of unwanted onesin order of removal: <\/code> \u0003
  • <\/li>
     <\/pre> 
      <\/ul> @process_Function_Description_prep_1 = replace(replace(replace(replace(replace(replace(replace(replace(replace(@process_Function_Description,"",""),"<\\//code>",""),"\u0003",""),"
    • ",""),"<\\//li>",""),"
      ",""),"<\\//pre>",""),"
        ",""),"<\\//ul>",""); /* REPLACE end of line and escape some characters */ # List in order of replacement: \n -> , @ -> \@, \/ -> \//, < -> <, > -> >, ' -> ', " -> " @process_Function_Description_prep_2 = replace(replace(replace(replace(replace(replace(@process_Function_Description_prep_1,"\n"," "),"\@","\\@"),">",">"),"<","<"),"'","'"),'"',"""); /* REPLACE all {{function|some_name}} description tags meant for forum links */ @find_Code_prep = reg_match('\\{\\{function\\|.+\\}\\}',@process_Function_Description_prep_2) if(array_index_exists(@find_Code_prep,0)){ @find_Code = @find_Code_prep[0]; @find_CodeValue = reg_match('(?<=\\|)(.*)(?=.\\})',@find_Code)[0]; @process_Function_Description_prep_3 = replace(@process_Function_Description_prep_2,@find_Code,@find_CodeValue); } else{ @process_Function_Description_prep_3 = @process_Function_Description_prep_2; } /* GET RID of all way too long descriptions, which may have html tables/tags in them */ /* Long descriptions that start with ---- */ if(string_position(@process_Function_Description_prep_3,"----") != -1){ @newString = substr(@process_Function_Description_prep_3,0,string_position(@process_Function_Description_prep_3,"----")); @process_Function_Description_prep_4 = @newString; } else{ @process_Function_Description_prep_4 = @process_Function_Description_prep_3; } /* HTML bb codes for table */ if(string_position(@process_Function_Description_prep_4,"{|") != -1 && string_position(@process_Function_Description_prep_4,"|}") != -1){ @newString2 = substr(@process_Function_Description_prep_4,0,string_position(@process_Function_Description_prep_4,"{|")).substr(@process_Function_Description_prep_4,(string_position(@process_Function_Description_prep_4,"|}") + 1)); @process_Function_Description_prep_5 = @newString2; } else{ @process_Function_Description_prep_5 = @process_Function_Description_prep_4; } /* Simply aesthetic, but replace single dot as end of line */ @process_Function_Description_prep_6 = replace(@process_Function_Description_prep_5,". ",". "); /* Replace next line triggers with nothing if on the end of description */ if(string_ends_with(@process_Function_Description_prep_6," ")){ @process_Function_Description_prepared = replace(@process_Function_Description_prep_6," ",""); } else { @process_Function_Description_prepared = @process_Function_Description_prep_6;} /* WRITE TO XML */ @file_Write[] = " "; /* FUNCTION ARGS */ /* Process function arguments and write to XML */ @process_Function_Args = @function_Args["args"]; /* Prepare counters, as we will split parentheses from other arguments */ @open_parentheses = 0; @closed_parentheses = 0; @word = 0; @arguments = array(); /* Process arguments */ @processArgs = @process_Function_Args; for(@countChar = 0, @countChar < length(@processArgs), @countChar++){ @character = @processArgs[@countChar]; if(@character == ","){ if(@open_parentheses != @closed_parentheses){ @skipWrite = false; } else{ @word++; @skipWrite = true;} } else if(@character == "[") { @open_parentheses++; @skipWrite = false; } else if(@character == "]") { @closed_parentheses++; @skipWrite = false; } else { @skipWrite = false; } if(@skipWrite == false) { if(!array_index_exists(@arguments,@word)){ array_set(@arguments,@word,@character); } else{ @arguments[@word] .= @character; } } } /* Push arguments into XML */ foreach(@argument in @arguments){ @file_Write[] = " "; } /* WRITE REST OF XML PORTION for function */ @file_Write[] = " " @file_Write[] = " " } /* EVENTS */ @process_Events = @file_JSON["events"]; foreach(@event in @process_Events){ /* EVENT NAME */ /* Process event name and write to XML */ @process_Event_Name = @event; @file_Write[] = " "; /* WRITE REST OF XML PORTION for event */ @file_Write[] = " "; @file_Write[] = " "; @file_Write[] = " " @file_Write[] = " " } /* Finish XML writing */ @file_Write[] = " "; @file_Write[] = ""; /* Write XML file */ @writeFile = ""; foreach(@stringLine in @file_Write){ @writeFile .= @stringLine."\n"; } chd_write(@file,@writeFile,"OVERWRITE"); console(colorize("All done! AutoComplete XML file is generated!"),false); <<<