/** * For converting the decomposition mappings field and similar. * * @returns Mapping array or NULL if none. * @param psz The string to convert. Can be empty. * @param pcEntries Where to store the number of entries. * @param cMax The max number of entries. */ static PRTUNICP ToMapping(char *psz, unsigned *pcEntries, unsigned cMax) { PRTUNICP paCps = NULL; unsigned cAlloc = 0; unsigned i = 0; /* Convert the code points. */ while (psz) { /* skip leading spaces */ while (RT_C_IS_BLANK(*psz)) psz++; /* the end? */ if (!*psz) break; /* room left? */ if (i >= cMax) { ParseError("Too many mappings.\n"); break; } if (i >= cAlloc) { cAlloc += 4; paCps = (PRTUNICP)realloc(paCps, cAlloc * sizeof(paCps[0])); if (!paCps) { fprintf(stderr, "out of memory (%u)\n", (unsigned)(cAlloc * sizeof(paCps[0]))); exit(1); } } /* Find the end. */ char *pszThis = psz; while (RT_C_IS_XDIGIT(*psz)) psz++; if (*psz && !RT_C_IS_BLANK(*psz)) ParseError("Malformed mappings.\n"); if (*psz) *psz++ = '\0'; /* Convert to number and add it. */ paCps[i++] = ToNum(pszThis); } *pcEntries = i; return paCps; }
/** * Converts an encoded number to a interger. * @returns The decoded number (positiv integer). * -1 on error. * @param pszNum Pointer to the string. * @param cchNum Size of the string part which is to be converted. * If <= 0 then we'll convert the entrie string. * @status Completely implemented. * @author knut st. osmundsen ([email protected]) * @remark Suitble for ProgId size and rev numbers. */ int BindToNum(const char *pszNum, int cchNum) { int iNum = 0; const char *psz = pszNum + (cchNum <= 0 ? strlen(pszNum) : cchNum); while (pszNum < psz--) { int j = ToNum(*psz); if (j < 0) return -1; iNum *= 62; iNum += j; } return iNum; }
void MobileApp::downloadStart() { downloadsList.clear(); hashs.clear(); for (int i=0; i<ui->downloadListWidget->count(); i++) { QListWidgetItem *item = ui->downloadListWidget->item(i); if (item->checkState() == Qt::Checked) { //Generate download urls int n; if (ToNum(item->whatsThis(), &n)) { if (groups.size() > n) { for (int j=0; j<groups[n].books.size(); j++) { if (groups[n].books[j].needToDownload) { QString url = groups[n].books[j].URL; downloadsList << url; hashs << groups[n].books[j].hash; } } } } } } downloadNum = downloadsList.size(); ui->downloadInfo->toolTip() = ""; ui->downloadListWidget->setEnabled(false); ui->downloadBTN->setEnabled(false); // download the next file in downloadsList. downloadNext(); }
/** * Converts a DB2 Bind timestamp to a human readable date. * @returns 0 on success. * -1 on error.(invalid timestamp) * @param pszTimeStamp Input timestamp string. Assumes it is 8 chars long. * @param pTS Output structure. * @sketch * @status Completely implemented. * @author knut st. osmundsen ([email protected]) * @remark Let's hope this don't change for later releases of DB2. */ int BindCvtTS(const char *pszTimeStamp, PTIMESTAMP pTS) { int i; int rc = 0; pTS->iYear = (i= ToNum(pszTimeStamp[7])) + 1984; if (i < 0) rc = -1; pTS->iMonth = i = ToNum(pszTimeStamp[6]); if (i < 0) rc = -1; pTS->iDay = i = ToNum(pszTimeStamp[5]); if (i < 0) rc = -1; pTS->iHour = i = ToNum(pszTimeStamp[4]); if (i < 0) rc = -1; pTS->iMinutte= i = ToNum(pszTimeStamp[3]); if (i < 0) rc = -1; pTS->iSecond = i = ToNum(pszTimeStamp[2]); if (i < 0) rc = -1; pTS->i100 = i = ToNum(pszTimeStamp[1]) * 62; if (i < 0) rc = -1; pTS->i100 += (i= ToNum(pszTimeStamp[0])); if (i < 0) rc = -1; return rc; }
/** * Read the UnicodeData.txt file. * @returns 0 on success. * @returns !0 on failure. * @param pszBasePath The base path, can be NULL. * @param pszFilename The name of the file. */ static int ReadUnicodeData(const char *pszBasePath, const char *pszFilename) { /* * Open input. */ FILE *pFile = OpenFile(pszBasePath, pszFilename); if (!pFile) return 1; /* * Parse the input and spit out the output. */ char szLine[4096]; RTUNICP i = 0; while (GetLineFromFile(szLine, sizeof(szLine), pFile) != NULL) { if (IsCommentOrBlankLine(szLine)) continue; char *pszCurField; char *pszCodePoint = FirstField(&pszCurField, StripLine(szLine)); /* 0 */ char *pszName = NextField(&pszCurField); /* 1 */ char *pszGeneralCategory = NextField(&pszCurField); /* 2 */ char *pszCanonicalCombiningClass = NextField(&pszCurField); /* 3 */ char *pszBidiClass = NextField(&pszCurField); /* 4 */ char *pszDecompositionType = NextField(&pszCurField); /* 5 */ char *pszDecompositionMapping = SplitDecompField(&pszDecompositionType); char *pszNumericType = NextField(&pszCurField); /* 6 */ char *pszNumericValueD = NextField(&pszCurField); /* 7 */ char *pszNumericValueN = NextField(&pszCurField); /* 8 */ char *pszBidiMirrored = NextField(&pszCurField); /* 9 */ char *pszUnicode1Name = NextField(&pszCurField); /* 10 */ char *pszISOComment = NextField(&pszCurField); /* 11 */ char *pszSimpleUpperCaseMapping = NextField(&pszCurField); /* 12 */ char *pszSimpleLowerCaseMapping = NextField(&pszCurField); /* 13 */ char *pszSimpleTitleCaseMapping = NextField(&pszCurField); /* 14 */ RTUNICP CodePoint = ToNum(pszCodePoint); if (CodePoint >= RT_ELEMENTS(g_aCPInfo)) { ParseError("U+05X is out of range\n", CodePoint); continue; } /* catchup? */ while (i < CodePoint) NullEntry(i++); if (i != CodePoint) { ParseError("i=%d CodePoint=%u\n", i, CodePoint); CloseFile(pFile); return 1; } /* this one */ g_aCPInfo[i].CodePoint = i; g_aCPInfo[i].fNullEntry = 0; g_aCPInfo[i].pszName = DupStr(pszName); g_aCPInfo[i].SimpleUpperCaseMapping = ToNumDefault(pszSimpleUpperCaseMapping, CodePoint); g_aCPInfo[i].SimpleLowerCaseMapping = ToNumDefault(pszSimpleLowerCaseMapping, CodePoint); g_aCPInfo[i].SimpleTitleCaseMapping = ToNumDefault(pszSimpleTitleCaseMapping, CodePoint); g_aCPInfo[i].CanonicalCombiningClass = ToNum(pszCanonicalCombiningClass); g_aCPInfo[i].pszDecompositionType = DupStr(pszDecompositionType); g_aCPInfo[i].paDecompositionMapping = ToMapping(pszDecompositionMapping, &g_aCPInfo[i].cDecompositionMapping, 20); g_aCPInfo[i].pszGeneralCategory = DupStr(pszGeneralCategory); g_aCPInfo[i].pszBidiClass = DupStr(pszBidiClass); g_aCPInfo[i].pszNumericType = DupStr(pszNumericType); g_aCPInfo[i].pszNumericValueD = DupStr(pszNumericValueD); g_aCPInfo[i].pszNumericValueN = DupStr(pszNumericValueN); g_aCPInfo[i].pszBidiMirrored = DupStr(pszBidiMirrored); g_aCPInfo[i].pszUnicode1Name = DupStr(pszUnicode1Name); g_aCPInfo[i].pszISOComment = DupStr(pszISOComment); i++; } /* catchup? */ while (i < RT_ELEMENTS(g_aCPInfo)) NullEntry(i++); CloseFile(pFile); return 0; }
/** * Same as ToNum except that if the field is empty the Default is returned. */ static RTUNICP ToNumDefault(const char *psz, RTUNICP Default) { if (*psz) return ToNum(psz); return Default; }
// Parse the booklist file void MobileApp::parseDLFile(QList <QString> dl) { for (int i=0; i<dl.size(); i++) { //Comment, ignore if (dl[i].startsWith("#")) {} //Group name else if (dl[i].startsWith("@")) { //Create new group DownloadbleBookGroup g; g.name = dl[i].mid(2); g.hidden=false; groups.append(g); } else if (dl[i].startsWith("./")) { if (groups.size() < 1) { qDebug() << "Error! Book with no group... Aborting download list"; return ; } DownloadbleBookObject bo; bo.hash = ""; QStringList sl = dl[i].split(", "); if (sl.size() < 3) { qDebug() << "Error! Invalid book entry! Skipping."; break ; } QString t = sl[0]; bo.URL = t.replace("./", "http://orayta.googlecode.com/svn/books/"); bo.UnpackPath = sl[0].replace("./", BOOKPATH); int n; if (ToNum(sl[1], &n)) bo.fileSize = n / 1000000.0; bo.dateModified = QDate::fromString(sl[2].simplified(), "dd/MM/yy"); //Because QT thinks '12' is 1912 and not 2012... bo.dateModified.setDate(100 + bo.dateModified.year(), bo.dateModified.month(), bo.dateModified.day()); //If a hash is present for this line if(sl.size() > 3) { bo.hash = sl[3]; } groups.last().books.append(bo); } } for (int i=0; i<groups.size(); i++) { //qDebug() << "#" << groups[i].name << groups[i].groupSize; bool hasAll = true; bool hasNone = true; for (int j=0; j<groups[i].books.size(); j++) { Book * b = bookList.FindBookByPath(groups[i].books[j].UnpackPath); bool needToDownload; if (b) { if (b->modificationDate() >= QDateTime(groups[i].books[j].dateModified)) { needToDownload = false; } else needToDownload = true; } else needToDownload = true; if (!needToDownload) { groups[i].books[j].needToDownload = false; hasNone = false; } else { groups[i].books[j].needToDownload = true; hasAll = false; } } //Calculate size of download double fs = 0, ds = 0; for (int k=0; k < groups[i].books.size(); k++) { if (groups[i].books[k].needToDownload) ds += groups[i].books[k].fileSize; fs += groups[i].books[k].fileSize; } groups[i].fullSize = int (fs * 10) / 10.0; groups[i].downloadSize = int (ds * 10) / 10.0; if (hasAll) groups[i].downloadState = 0; //All installed else if (hasNone) groups[i].downloadState = 2; //None installed else groups[i].downloadState = 1; //Needs update //qDebug() << groups[i].name << groups[i].downloadState << groups[i].fullSize << groups[i].downloadSize; } }
//Add the book's confs, from it's conf file void BookList::AddBookConfs(Book *book, QList<QString> text) { vector<QString> linesplit; for(int i=0; i<text.size() ; i++) { if (text[i].indexOf("Comments") != -1) { book->Comments = text[i].mid(9); } else if (text[i].indexOf("GroupId") != -1) { book->GroupId = text[i].mid(8); } else if (text[i].indexOf("DisplayName") != -1) { book->setNormallDisplayName(text[i].mid(12).replace(QRegExp("^ *"), "")); } //field for the display name of the directory else if (text[i].indexOf("BranchName") != -1) { linesplit.clear(); splittotwo(text[i],linesplit ,"="); if (linesplit[1]!="") { book->setTreeDisplayName(linesplit[1]); } } else if (text[i].indexOf("LastLevelIndex") != -1) { int n; if(ToNum(text[i].mid(15),&n)) book->LastLevelIndex = n; } else if (text[i].indexOf("PutNewLinesAsIs") != -1) { if(text[i].mid(16) != "1") book->PutNewLinesAsIs=false; else book->PutNewLinesAsIs=true; } else if (text[i].indexOf("TextSource") != -1) { qDebug() << "(C)" + text[i].mid(11); book->setCopyrightInfo(text[i].mid(11)); } else if (text[i].indexOf("ForcedBookName") != -1) { linesplit.clear(); splittotwo(text[i],linesplit ,"="); if (linesplit[1]!="") book->setTreeDisplayName(linesplit[1]); } else if (text[i].indexOf("HiddenFromIndex") != -1) { int t; GetIntValue(text[i], &t); if (t==1) { book->setIsHidden(true); book->setIsInSearch(false); } } else if (text[i].indexOf("WeaveLevel") != -1) { QString wl = text[i].mid(text[i].size()-1); book->WeaveLevel = wl; } else if (text[i].indexOf("AddSource") != -1) { if ( book->mWeavedSources.size() == 0) { //Add the book it self as the first source weavedSource base; base.FilePath = book->getPath(); base.Zoom = 0; base.id = 0; base.show = true; book->mWeavedSources.append(base); } QStringList p = text[i].mid(10).split(":"); if (p.size() > 1) { weavedSource src; src.FilePath = BOOKPATH + (BOOKPATH.endsWith("/") ? "" : "/") + p[0]; src.Title = p[1]; src.Zoom = 0; src.id = book->mWeavedSources.size(); src.show = false; book->mWeavedSources.append(src); } else { qDebug() << "Invalid weaved source in:" << book->getPath(); qDebug() << "Bad path:" << text[i]; } } // code from yoch to add new commentaries by id else if (text[i].indexOf("MixedSources") != -1) { QString srcLst = text[i].mid(12); srcLst = srcLst.mid(srcLst.indexOf("(") + 1); srcLst = srcLst.mid(0, srcLst.indexOf(")")); QList<int> wsrc; QStringList srcId = srcLst.split(',', QString::SkipEmptyParts); for (QStringList::const_iterator it = srcId.begin(); it != srcId.end(); ++it) { int id; if(ToNum(*it, &id)) { weavedSource src; src.show = false; src.id = id; // mWeavedSources.push_back(src); book->mWeavedSources.append(src); } } } else if (text[i].indexOf("CosmeticsType") != -1) { book->setCosmetics(text[i]); } else if (text[i].indexOf("UniqueId") != -1) { int id; if(ToNum(text[i].mid(9), &id) == true) book->setUniqueId(id); } else if (text[i].indexOf("Nikud") != -1) { book->hasNikud=true; } else if (text[i].indexOf("Teamim") != -1) { book->hasTeamim=true; } else if (text[i].indexOf("Kukayta") != -1) { book->isEncrypted=true; } } }