diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-12-04 19:16:43 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-12-04 19:38:30 +0900 |
commit | fdcd72088371b3d8dfd31f2a5159861ce0be5535 (patch) | |
tree | 06c160cc34157344f62b6c19af297858a0e57157 /debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js | |
parent | a5d7db3b2c6171ea9e76b84155d2dfb66c243e5a (diff) | |
download | extra-dependencies-fdcd72088371b3d8dfd31f2a5159861ce0be5535.tar.gz extra-dependencies-fdcd72088371b3d8dfd31f2a5159861ce0be5535.zip |
uncrustify-trinity: updated based on upstream version 0.76.0
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js')
-rw-r--r-- | debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js b/debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js new file mode 100644 index 00000000..cbf8f57b --- /dev/null +++ b/debian/uncrustify-trinity/uncrustify-trinity-0.76.0/emscripten/postfix_module.js @@ -0,0 +1,141 @@ + //! auto initializes the module + Module["_initialize"](); //// execute this only one time, + Module["_initialize"] = Function.prototype; // and replace it with a noop + + /** + * Takes in a JS string with other params, converts it to UTF8 and + * passes it to the actual _uncrustify function while also managing the + * memory on the emscripten heap. + */ + Module["uncrustify"] = function(str, langIDX, frag, defer) + { + if( !str || typeof(str) !== "string" || str.length === 0 ) {return "";} + + var nDataBytes = lengthBytesUTF8(str)+1; // +1 for \0 + var stringInputPtr = Module._malloc(nDataBytes); + Module.stringToUTF8(str, stringInputPtr, nDataBytes); + + var retStringPointer = 0; + + switch(arguments.length) + { + // depending in the number of args the internal select_overload + // function resolves the appropriate internal _uncrustify function + case 2: + { + retStringPointer = Module["_uncrustify"](stringInputPtr, langIDX); + break; + } + case 3: + { + retStringPointer = Module["_uncrustify"](stringInputPtr, langIDX, frag); + break; + } +// case 4: +// { +// retStringPointer = Module["_uncrustify"](stringInputPtr, langIDX, frag, defer); +// break; +// } + default: + { + break; + } + } + + Module._free(stringInputPtr); + + + var retString = ""; + + if(retStringPointer !== 0) + { + retString = Module.UTF8ToString(retStringPointer); + Module._free(retStringPointer); + } + + return retString; + } + + /** + * Takes in a JS string with other params, converts it to UTF8 and + * passes it to the actual _debug function while also managing the + * memory on the emscripten heap. + */ + Module["debug"] = function(str, langIDX, frag) + { + if( !str || typeof(str) !== "string" || str.length === 0 ) {return "";} + + var nDataBytes = lengthBytesUTF8(str)+1; // +1 for \0 + var stringInputPtr = Module._malloc(nDataBytes); + Module.stringToUTF8(str, stringInputPtr, nDataBytes); + + var retStringPointer = 0; + + switch(arguments.length) + { + // depending in the number of args the internal select_overload + // function resolves the appropriate internal _uncrustify function + case 2: + { + retStringPointer = Module["_debug"](stringInputPtr, langIDX); + break; + } + case 3: + { + retStringPointer = Module["_debug"](stringInputPtr, langIDX, frag); + break; + } + default: + { + break; + } + } + + Module._free(stringInputPtr); + + + var retString = ""; + + if(retStringPointer !== 0) + { + retString = Module.UTF8ToString(retStringPointer); + Module._free(retStringPointer); + } + + return retString; + } + + /** + * Takes in a JS string, removes non ascii chars (only those are needed + * in a config) and passes it to the actual _loadConfig function while + * also managing the memory on the emscripten heap. + */ + Module.load_config = function(str) + { + // UTF8 functions return on empty string but they have to be accepted too + // to reset the current config + if( !str || typeof(str) !== "string" || str.length === 0) {str = " ";} + + //remove unneeded non asci chars in the config + str.replace(/[^\x00-\x7F]/g, ""); + + var nDataBytes = str.length+1; // +1 for \0 + var stringInputPtr = Module._malloc(nDataBytes); + Module.writeAsciiToMemory(str, stringInputPtr); + + + var retStringPointer = Module["_load_config"](stringInputPtr); + Module._free(stringInputPtr); + + + var retString = ""; + + if(retStringPointer !== 0) + { + retString = Module.Pointer_stringify(retStringPointer); + Module._free(retStringPointer); + } + + return retString; + } + |