JSBool getElementsByTagName(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval) { nsCOMPtr<nsIDOMNode> mNode = (nsIDOMNode*)JS_GetPrivate(cx, obj); nsresult rv; nsCOMPtr<nsIDOMElement> mElement = do_QueryInterface(mNode, &rv); if(NS_FAILED(rv)) { *rval = JSVAL_FALSE; return JS_TRUE; } LPWSTR tagName; JS_BeginRequest(cx); if(!JS_ConvertArguments(cx, argc, argv, "W", &tagName)) { JS_ReportError(cx, "error parsing arguments in getelements by tagname"); JS_EndRequest(cx); return JS_FALSE; } nsDependentString aTagName(tagName); nsIDOMNodeList * mNodeList; mElement->GetElementsByTagName(aTagName, &mNodeList); buildNodeList(mNodeList, cx, obj, rval); mNodeList->Release(); JS_EndRequest(cx); return JS_TRUE; }
JSBool childGetter(JSContext * cx, JSObject * obj, jsval idval, jsval * vp) { JS_BeginRequest(cx); nsCOMPtr<nsIDOMNode> mNode = (nsIDOMNode*)JS_GetPrivate(cx, obj); JSString * idvalStr = JS_ValueToString(cx, idval); jschar * idvalChars = JS_GetStringChars(idvalStr); if(_wcsicmp(idvalChars, TEXT("childNodes")) == 0) { nsIDOMNodeList * nodeList; mNode->GetChildNodes(&nodeList); buildNodeList(nodeList, cx, obj, vp); nodeList->Release(); } else *vp = JSVAL_NULL; JS_EndRequest(cx); return JS_TRUE; }
void Compression::huffmanEncode(const char* inputFile) { FILE * src = fopen(inputFile, "rb"); char outputPath[1000]; const char * fileExtension = ".bin"; outputFilePath(inputFile, outputPath, fileExtension); FILE * dest = fopen(outputPath, "wb"); if (src == NULL || dest == NULL) { printf("Не удается найти файл."); exit(EXIT_FAILURE); } unsigned int fileSize; fileSize = getFileSize(src); unsigned int * freqList; freqList = (unsigned int *)calloc(CHARS_LIMIT, sizeof(unsigned int)); calcCharFreq(src, freqList); unsigned int numOfFreq; numOfFreq = calcNumOfFreq(freqList); HuffNode * nodeList = NULL; buildNodeList(&nodeList, freqList); buildHuffTree(&nodeList); HuffNode * treeRoot = nodeList; unsigned int i; HuffCode newCode; HuffCode * huffCodeTable; huffCodeTable = (HuffCode *)calloc(CHARS_LIMIT, sizeof(HuffCode)); for(i=0; i<CHARS_LIMIT; i++) { if(freqList[i] > 0) { newCode.length = 0; buildHuffCode(treeRoot, &newCode, i); huffCodeTable[i] = newCode; } } HuffHeader hHeader; writeHeader(dest, hHeader, numOfFreq, fileSize); HuffFreq hFreq; writeFreq(dest, freqList, hFreq); writeEncodedData(src, dest, huffCodeTable, fileSize); freeHuffTree(treeRoot); treeRoot = NULL; free(huffCodeTable); free(freqList); fclose(src); fclose(dest); }