"Fossies" - the Fresh Open Source Software Archive

Member "kydpdict-0.9.5/src/engine_ydp.cpp" (29 Mar 2009, 20541 Bytes) of package /linux/privat/old/kydpdict-0.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "engine_ydp.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2  *                                                                         *
    3  *   This program is free software; you can redistribute it and/or modify  *
    4  *   it under the terms of the GNU General Public License as published by  *
    5  *   the Free Software Foundation; either version 2 of the License, or     *
    6  *   (at your option) any later version.                                   *
    7  *                                                                         *
    8  ***************************************************************************/
    9 
   10 #include <qlistbox.h>
   11 #include <qmessagebox.h>
   12 #include <qtextcodec.h>
   13 #include <qregexp.h>
   14 
   15 #include <sys/mman.h>
   16 #include <fcntl.h>
   17 #include <unistd.h>
   18 
   19 #include "kydpconfig.h"
   20 #include "engine_ydp.h"
   21 #include "engine_ydp.moc"
   22 
   23 #define T_PL        0x00000001
   24 #define T_CM        0x00000002
   25 #define T_PN_L      0x00000004
   26 #define T_PN_R      0x00000008
   27 #define T_SL_L      0x00000010
   28 #define T_SL_R      0x00000020
   29 
   30 #define _native 0
   31 #define _foreign 1
   32 
   33 QString EngineYDP::GetTip(int index) {
   34     #include "ydp-tooltips.h"
   35     return tab[index];
   36 }
   37 
   38 EngineYDP::EngineYDP(kydpConfig *config, QListBox *listBox, ydpConverter *converter) : ydpDictionary(config, listBox, converter)
   39 {
   40     for (int i=0;i<4;i++) {
   41         dictCache_LL[i].indexes = NULL;
   42     }
   43 }
   44 
   45 EngineYDP::~EngineYDP()
   46 {
   47     int i;
   48 
   49     for (i=0;i<4;i++) {
   50     if (dictCache[i].wordCount>0) {
   51         if (dictCache_LL[i].indexes) delete [] dictCache_LL[i].indexes;
   52     }
   53     }
   54 }
   55 
   56 int EngineYDP::OpenDictionary(void)
   57 {
   58     int i;
   59 
   60     /* open index and definition files */
   61     UpdateFName();
   62     fIndex.setName( cnf->topPath + "/" + cnf->indexFName );
   63     if (!(fIndex.open(IO_ReadOnly))) {
   64     fIndex.setName( cnf->topPath + "/" + cnf->indexFName.upper());
   65     if (!(fIndex.open(IO_ReadOnly))) {
   66         QMessageBox::critical(0, "Kydpdict", tr( "Can't open index file!\n" ) + fIndex.name() );
   67         return 1;
   68     }
   69     }
   70 
   71     fData.setName( cnf->topPath + "/" + cnf->dataFName );
   72     if (!(fData.open(IO_ReadOnly))) {
   73     fData.setName( cnf->topPath + "/" + cnf->dataFName.upper());
   74     if (!(fData.open(IO_ReadOnly))) {
   75         QMessageBox::critical(0, "Kydpdict", tr( "Can't open data file!\n" ) + fData.name() );
   76         return 1;
   77     }
   78      }
   79 
   80     /* 0-english, eng->pol; 1-english, pol->eng; 2-german, ger->pol; 3-german, pol->ger */
   81     i = 0;
   82     if (cnf->language == LANG_DEUTSCH)
   83     i+=2;
   84     if (!(cnf->toPolish))
   85     i++;
   86     if (dictCache[i].wordCount>0) {
   87     indexes = dictCache_LL[i].indexes;
   88     } else {
   89     FillWordList();
   90     dictCache_LL[i].indexes = indexes;
   91     }
   92     return ydpDictionary::OpenDictionary(); // required call
   93 }
   94 
   95 int EngineYDP::CheckDictionary(void)
   96 {
   97     QFile f;
   98     unsigned int test = 0;
   99 
  100     UpdateFName();
  101     f.setName( cnf->topPath + "/" + cnf->indexFName );
  102     if ( !(f.exists()) ) {
  103     f.setName( cnf->topPath + "/" + cnf->indexFName.upper() );
  104         if ( !(f.exists()) )
  105             return 0;
  106     }
  107     f.open(IO_ReadOnly);
  108     f.readBlock((char*)&test, 4);       // read magic
  109     f.close();
  110     if (fix32(test) != 0x8d4e11d5)  // magic test
  111     return 0;
  112     f.setName( cnf->topPath + "/" + cnf->dataFName );
  113     if ( !(f.exists()) ) {
  114     f.setName( cnf->topPath + "/" + cnf->dataFName.upper() );
  115     if ( !(f.exists()) )
  116         return 0;
  117     }
  118     return 1;
  119 }
  120 
  121 void EngineYDP::CloseDictionary()
  122 {
  123     fIndex.close();
  124     fData.close();
  125     // free some stuff allocated elsewhere???
  126     ydpDictionary::CloseDictionary();   // required call
  127 }
  128 
  129 void EngineYDP::UpdateFName(void) {
  130     switch (cnf->language) {
  131     case LANG_ENGLISH:
  132         cnf->indexFName= cnf->toPolish ? "dict100.idx" : "dict101.idx";
  133         cnf->dataFName = cnf->toPolish ? "dict100.dat" : "dict101.dat";
  134         break;
  135     case LANG_DEUTSCH:
  136         cnf->indexFName= cnf->toPolish ? "dict200.idx" : "dict201.idx";
  137         cnf->dataFName = cnf->toPolish ? "dict200.dat" : "dict201.dat";
  138         break;
  139     }
  140 }
  141 
  142 void EngineYDP::FillWordList()
  143 {
  144     unsigned int pos;
  145     unsigned int index[2];
  146     unsigned short wcount;
  147     int current=0;
  148     /* for mmap */
  149     int f;
  150     char *filedata;
  151     size_t page_size;
  152     unsigned int length;
  153 
  154     /* read # of words */
  155     wordCount=0;
  156     fIndex.at(0x08);
  157     fIndex.readBlock((char*)&wcount,2);
  158     wordCount = (int)fix16(wcount);
  159 
  160     indexes = new unsigned int [wordCount+2];
  161 
  162     words = new char* [wordCount+1];
  163     words[wordCount] = 0;
  164 
  165     /* read index table offset */
  166     pos=0;
  167     fIndex.at(0x10);
  168     fIndex.readBlock((char*)&pos, 4);
  169     pos=fix32(pos);
  170 
  171     /* prepare mmap stuff */
  172     f = open(fIndex.name(), O_RDONLY);
  173     page_size = (size_t)sysconf(_SC_PAGESIZE);
  174     if (page_size==0) {
  175     printf("codename: yellow page!!! mail this to ytm@elysium.pl\n");
  176     page_size = 4096;
  177     }
  178     length = ((fIndex.size() / page_size)+1)*page_size;
  179     filedata = (char*)mmap(NULL, length, PROT_READ, MAP_PRIVATE, f, 0);
  180 
  181     if ((void *)filedata != MAP_FAILED) {
  182     do {
  183         indexes[current] = *(int*)&filedata[pos+4];
  184         indexes[current] = fix32(indexes[current]);
  185         words[current] = new char [(filedata[pos])];
  186         strcpy(words[current], &filedata[pos+8]);
  187         pos += 8+1+strlen(words[current]);
  188     } while (++current < wordCount);
  189     } else {
  190     fIndex.at(pos);
  191     do {
  192     //  trick - instead of fssek(cur+4), read ulong we read ulong twice
  193     //  and throw out first 4 bytes
  194         fIndex.readBlock((char*)&index[0], 8);
  195         indexes[current]=fix32(index[1]);
  196     //  and another trick
  197     //  we don't throw out first 4 bytes :)
  198         words[current] = new char [fix32(index[0]) & 0xff];
  199         fIndex.readBlock(words[current], fix32(index[0]) & 0xff);
  200     } while (++current < wordCount);
  201     }
  202     munmap((void*)filedata, length);
  203     close(f);
  204 
  205     topitem = 0;
  206 
  207     /* omijanie bledow w slowniku... */
  208     if ((cnf->language==LANG_ENGLISH) && (cnf->toPolish)) {
  209     current = FindWord(QString("Proven"));
  210     delete [] words[current];
  211     words[current] = new char [strlen("Provencial")];
  212     strcpy(words[current],"Provencial");
  213     broken_entry = current;
  214     }
  215 }
  216 
  217 int EngineYDP::ReadDefinition(int index)
  218 {
  219     unsigned int dsize, size;
  220     char *def;
  221 
  222     dsize=0;
  223     fData.at(indexes[index]);
  224     fData.readBlock((char*)&dsize, sizeof(unsigned int));
  225     dsize=fix32(dsize);
  226 
  227     def = new char[dsize+1];
  228     if ((size = fData.readBlock(def,dsize)) !=dsize) return -1;
  229     def[size] = 0;
  230     curDefinition=QString(def);
  231     if (index == broken_entry) {
  232     curDefinition.replace(QRegExp("Proven.al"),"Provencial");
  233     }
  234     delete [] def;
  235     return 0;
  236 }
  237 
  238 QString EngineYDP::SampleName(QString path, int index)
  239 {
  240     QFile fd;
  241     QString name, myname;
  242 
  243     name.sprintf("/s%.3d/%.6d.", (index+1)/1000, index+1);
  244 
  245     myname = name+"wav";
  246     fd.setName(path+myname);
  247     if (fd.exists())
  248     return fd.name();
  249     fd.setName(path+myname.upper());
  250     if (fd.exists())
  251     return fd.name();
  252 
  253     myname = name+"mp3";
  254     fd.setName(path+myname);
  255     if (fd.exists())
  256     return fd.name();
  257     fd.setName(path+myname.upper());
  258     if (fd.exists())
  259     return fd.name();
  260 
  261     myname = name+"ogg";
  262     fd.setName(path+myname);
  263     if (fd.exists())
  264     return fd.name();
  265     fd.setName(path+myname.upper());
  266     if (fd.exists())
  267     return fd.name();
  268 
  269     return QString("");
  270 }
  271 
  272 QString EngineYDP::rtf2html (QString definition)
  273 {
  274 char token[1024];
  275 int tp, level = 0;
  276 bool sa_tag = FALSE,br_tag = FALSE, italic_tag = FALSE, link_tag = TRUE;
  277 QString tag_on,tag_off;
  278 char *def = const_cast<char*>((const char*)definition);
  279 list.clear();
  280 list += "<qt><font color=\"" + color4 +"\" link=\"" + color4 + "\">";
  281 list += "</font></qt>";
  282 for(level=15;level>=0;level--) {
  283     tag_num[level] = 0;
  284     direction_tab[level] = 0;   
  285 }
  286 level = 0;
  287 direction_tab[level] = _native;
  288 it = list.begin();
  289 it++;
  290 
  291 
  292   while (*def) {
  293     switch(*def) {
  294         case '{':
  295             if (level < 16) tag_num[++level] = 0;
  296             direction_tab[level] = _native;
  297                 break;
  298         case '\\':
  299             def++; tp = 0;
  300             while((*def >= 'a' && *def <= 'z') || (*def >='0' && *def <= '9'))
  301                 token[tp++] = *def++;
  302             token[tp] = 0;
  303             if (*def == ' ') def++;
  304 
  305             if (!strcmp(token, "i")) { //   109891 -ilosc wystapien -  optymalizacja pod plik ang->pol :)))))))
  306                 if(cnf->italicFont) {
  307                     tag_on = "<i>";
  308                     tag_off = "</i>";
  309                     tag_num[level]++;
  310                 }
  311                 direction_tab[level] = _native;
  312             //  italic_tag = TRUE;
  313             } else
  314 
  315             if (!strcmp(token, "cf2")) { // 79850
  316                 tag_on = "<font color=" + color2 + ">";
  317                 tag_off = "</font>";
  318                 tag_num[level]++;
  319                 direction_tab[level] = _native; // vi - trzeba to przemyslec jeszcze
  320                 link_tag = TRUE;
  321             } else
  322 
  323             if (!strcmp(token, "par")) { //74442
  324                 tag_on = "<br>";
  325                 tag_off =  "";
  326             } else
  327 
  328             if (!strcmp(token, "line")) { //    61703
  329                 tag_on = "<br>";
  330                 tag_off = "";
  331                 if(br_tag)
  332                     tag_on="";
  333                 br_tag = FALSE;
  334             } else
  335 
  336             if (!strcmp(token, "cf1")) { // 55929
  337                 tag_on = "<font color=" + color1 + ">";
  338                 tag_off = "</font>";
  339                 tag_num[level]++;
  340                 direction_tab[level] = _foreign;
  341             } else
  342 
  343             if (!strcmp(token, "b")) { //   43737
  344                 tag_on = "<b>";
  345                 tag_off = "</b>";
  346                 tag_num[level]++;
  347             } else
  348 
  349             if (!strcmp(token, "cf0")) { // 22607
  350                 tag_on = "<font color=" + color3 + ">";
  351                 tag_off = "</font>";
  352                 tag_num[level]++;
  353                 direction_tab[level] = _native;
  354             } else
  355 
  356             if (!strcmp(token, "cf5")) { // 21478
  357                 tag_on = "<font color=" + color4 + ">";
  358                 tag_off = "</font>";
  359                 tag_num[level]++;
  360 //              direction_tab[level] = _native;
  361                 link_tag = FALSE;
  362             } else
  363             
  364             if (!strcmp(token, "f1")) { // ????
  365                 tag_on = "";
  366                 tag_off = "";
  367                 link_tag = FALSE;
  368             } else
  369             
  370             if (!strcmp(token, "f2")) { // ????
  371                 tag_on = "";
  372                 tag_off = "";
  373                 link_tag = TRUE;
  374             } else
  375 
  376             if (!strncmp(token, "sa", 2)) { // 19969
  377                 tag_on = "<table cellspacing=0><tr><td width=25></td><td>";
  378                 tag_off =  "</td></tr></table>";
  379                 sa_tag = TRUE;
  380                 tag_num[level]++;
  381             } else
  382 
  383             if (!strcmp(token, "b0")) { // 2130
  384                 tag_on = "";
  385                 tag_off = "";
  386                 disableTag (1, level);
  387 
  388             } else
  389 
  390             if (!strcmp(token, "super")) { // 92
  391                 tag_on = "<small>";
  392                 tag_off = "</small>";
  393                 tag_num[level]++;
  394 //              direction_tab[level] = _off;
  395             } else
  396 
  397             if (!strcmp(token, "i0")) { // 69
  398                 tag_on = "";
  399                 tag_off = "";
  400                 italic_tag = FALSE;
  401                 disableTag (2, level);
  402             } else
  403 
  404             if (!strcmp(token, "cf4")) {
  405                 tag_on = "<font color=" + color3 + ">";
  406                 tag_off = "</font>";
  407                 tag_num[level]++;
  408                 direction_tab[level] = _native;
  409             }
  410 
  411             def--;
  412 
  413             if(!tag_on.isEmpty()) {
  414                 it = list.insert(it, tag_on); it++;
  415                 tag_on = "";
  416                 if (!tag_off.isEmpty()) {
  417                     it = list.insert(it, tag_off);
  418                     tag_off = "";
  419                 }
  420             }
  421             break;
  422         case '}':
  423             while(tag_num[level] > 0) {
  424                 it++;
  425                 tag_num[level]--;
  426             }
  427             level--;
  428             italic_tag = FALSE;
  429             link_tag = TRUE;
  430             if(sa_tag) {
  431                 it++; //tabela ma tylko obejmowac 1 pozycje a nie do konca tekstu
  432                 sa_tag = FALSE;
  433                 br_tag = TRUE; //nie am linii za wcieciem bo qt samo to robi, czemu?
  434             }
  435             break;
  436         default:
  437             tp = 0;
  438             while(!(*def == '{' || *def == '}' || *def == '\\') && *def) {
  439                 if (*def == 0x7f) (*def )--;
  440                 if (*def == '<') {
  441                     token[tp++]='&'; //// paskudnie to wyglada - jak chcesz to zmien zapis :)
  442                     token[tp++]='l'; // takie sa uroki uzywania C w C++ :-P
  443                     token[tp++]='t';
  444                     *def=';';
  445                 }
  446                 if (*def == '>') {
  447                     token[tp++]='&';
  448                     token[tp++]='g';
  449                     token[tp++]='t';
  450                     *def = ';';
  451                 }
  452                     token[tp++] = *def++;
  453             }
  454                 token[tp] = '\0';
  455             def--;
  456             QString tmp = cvt->convertChunk(token, tp, cnf->unicodeFont);
  457 
  458             if((cnf->language == LANG_ENGLISH) && cnf->toolTips && link_tag) {
  459                 tmp = insertHyperText(tmp, level);
  460             }
  461             it = list.insert(it, tmp); it++;
  462             break;
  463     }
  464     def++;
  465   }
  466   return list.join("");
  467 }
  468 
  469 void EngineYDP::disableTag (int tag_code, int level)
  470 {
  471 
  472 QString a_on, a_off, p_on, p_off;
  473 int color_off=0, italic_off=0;
  474 QStringList::Iterator wsk;
  475 int wstawiono=0;
  476 
  477     if(tag_code == 1) {
  478         a_on = "<b>";
  479         a_off = "</b>";
  480         p_on = "<i>";
  481         p_off = "</i>";
  482     } else if(tag_code == 2) {
  483         a_on = "<i>";
  484         a_off = "</i>";
  485         p_on = "<b>";
  486         p_off = "</b>";
  487     } else return;
  488 
  489     for(wsk = it, wsk--; wsk != list.begin(); wsk--) {
  490         if(!strcmp(*wsk, a_on)) {
  491             it = list.insert(it, a_off); it++;
  492             break;
  493         } else if(!strcmp(*wsk, a_off)) {
  494             break;
  495         } else if(!strcmp(*wsk, "</font>")) {
  496             color_off++;
  497         } else if(!strcmp(*wsk, p_off)) {
  498             italic_off++;
  499         } else if(!strcmp((*wsk).left(5), "<font")) {
  500             if(color_off > 0) color_off--;
  501             else {
  502                 it = list.insert(it, *wsk);
  503                 it = list.insert(it, "</font>"); it++;
  504                 wstawiono++;
  505             }
  506         } else if(!strcmp(*wsk, p_on)) {
  507             if(italic_off > 0) italic_off--;
  508             else {
  509                 it = list.insert(it, *wsk);
  510                 it = list.insert(it, p_off); it++;
  511                 wstawiono++;
  512             }
  513         }
  514     }
  515 
  516     int j = wstawiono;
  517 
  518     while(j > 0) {
  519         it++;
  520         j--;
  521     }
  522 
  523     for(wsk = it; wsk != list.end(); wsk++) {
  524         if(!strcmp(*wsk, a_off)) {
  525             if(wstawiono > 0) {
  526                 j = wstawiono;
  527                 wsk = it;
  528                 wsk++;
  529                 while (j-- > 0 && strcmp(*wsk, a_off)) {
  530                     wsk ++;
  531                     tag_num[level]++;
  532                 }
  533                 list.insert(wsk, a_on);
  534             } else
  535                 it = list.insert(it, a_on);
  536 
  537             tag_num[level]++;
  538 
  539             break;
  540         } else if(!strcmp(*wsk, a_on)) {
  541             break;
  542         }
  543     }
  544 }
  545 
  546 QString EngineYDP::insertHyperText(QString raw_input, int level)
  547 {
  548 
  549     int tags = 0, pos = 0, pos2 = 0;
  550     bool result;
  551     QString output, output2, fullOutput, number, proposition;
  552 
  553     QString input = raw_input.simplifyWhiteSpace();
  554 
  555     while(TRUE) {
  556         QString tmp = input.section(' ', pos, pos);
  557 
  558         if(tmp.startsWith("(")) {
  559             tags |= T_PN_L;
  560             tmp = tmp.right(tmp.length()-1);
  561         }
  562 
  563         if(tmp.endsWith(")")) {
  564             tags |= T_PN_R;
  565             tmp = tmp.left(tmp.length()-1);
  566         }
  567 
  568         if(tmp.endsWith(",")) {
  569             tags |= T_CM;
  570             tmp = tmp.left(tmp.length()-1);
  571         }
  572 
  573         if(tmp.startsWith("+")) {
  574             tags |= T_PL;
  575             tmp = tmp.right(tmp.length()-1);
  576         }
  577 
  578         pos2 = 0;
  579         output2 = "";
  580         QString direction;
  581         direction_tab[level] == _native ? direction = "0" : direction = "1"; 
  582         result = FALSE;
  583 
  584         if(tmp.startsWith("/")) {
  585             tags |= T_SL_L;
  586             tmp = tmp.right(tmp.length()-1);
  587         }
  588 
  589         if(tmp.endsWith("/")) {
  590             tags |= T_SL_R;
  591             tmp = tmp.left(tmp.length()-1);
  592         }
  593 
  594         while(TRUE) {
  595             QString tmp2 = tmp.section('/', pos2, pos2);
  596 
  597             proposition = tmp2;
  598 
  599             for (int i=0; i<GetTipNumber(0); i++) {
  600                 if (!QString::compare(tmp2, GetInputTip(i))) {
  601                     proposition = "<a href=\""+GetInputTip(i)+"\">"+tmp2+"</a>";
  602                     result = TRUE;
  603                     break;
  604                 }
  605             }
  606             
  607 
  608             if(!result) {
  609                 proposition = "<a href="+ direction + tmp2+">"+tmp2+"</a>";
  610             }
  611 
  612             output2 += proposition;
  613 
  614             pos2++;
  615 
  616             if(tmp.section('/', pos2, pos2).isEmpty())
  617                 break;
  618             output2 += '/';
  619         }
  620 
  621         if(tags & T_SL_L)
  622             output2 = '/' + output2;
  623 
  624         if(tags & T_SL_R)
  625             output2 += '/';
  626 
  627         output += output2;
  628         output2 = "";
  629 
  630         if(tags & T_CM)
  631             output += ",";
  632 
  633         if(tags & T_PL)
  634             output = "+" + output;
  635 
  636         if(tags & T_PN_L)
  637             fullOutput += "(";
  638 
  639         fullOutput += output;
  640         output = "";
  641 
  642         if(tags & T_PN_R)
  643             fullOutput += ")";
  644 
  645         tags = 0;
  646         pos++;
  647 
  648         if( input.section(' ', pos, pos).isEmpty() )
  649             break;
  650         fullOutput +=" ";
  651     }
  652 
  653     if(raw_input.startsWith(" "))
  654         fullOutput = " " + fullOutput;
  655     if(raw_input.endsWith(" "))
  656         fullOutput += " ";
  657     return fullOutput;
  658 }
  659 
  660 /* converter class */
  661 
  662 ConvertYDP::ConvertYDP(void) {
  663     codec = QTextCodec::codecForName("CP1250");
  664 }
  665 
  666 ConvertYDP::~ConvertYDP() {
  667 
  668 }
  669 
  670 char ConvertYDP::toLower(const char c) {
  671     const static char upper_cp[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  672     const static char lower_cp[] = "abcdefghijklmnopqrstuvwxyz";
  673 
  674     unsigned int i;
  675     for (i=0;i<sizeof(upper_cp);i++)
  676     if (c == upper_cp[i])
  677         return lower_cp[i];
  678     return c;
  679 }
  680 
  681 int ConvertYDP::charIndex(const char c) {
  682     const static char lower_cp[] = "abcdefghijklmnopqrstuvwxyz";
  683     
  684     char lc = c;
  685     
  686     if (c == '')
  687         lc = 'a';
  688     else if (c == '')
  689         lc = 'o';
  690     else if (c == '')
  691         lc = 'u';
  692 
  693         unsigned int i;
  694     for (i=0;i<sizeof(lower_cp);i++)
  695     if (lc == lower_cp[i])
  696         return i;
  697     return sizeof(lower_cp)+1;
  698 }
  699 
  700 char *ConvertYDP::toLocal(const char *input) {
  701     int i, j = 0;
  702     int len = strlen(input);
  703     static char buffer[256];        // ugly? maybe
  704 
  705     memset(buffer,0,sizeof(buffer));
  706 
  707     for (i=0;i!=len;) {
  708     if ((input[i] != '\t') && (input[i] != '-') && (input[i] !=','))
  709         buffer[j++] = toLower(input[i++]);
  710     else
  711         ++i;
  712     }
  713     return buffer;
  714 }
  715 
  716 QString ConvertYDP::toUnicode(const char *input) {
  717     return codec->toUnicode(input);
  718 }
  719 
  720 QCString ConvertYDP::fromUnicode(QString input) {
  721     return codec->fromUnicode(input);
  722 }
  723 
  724 #define TABLE_PHONETIC_ISO { \
  725   ".", ".", "<img src=\"f2\">", "<img src=\"f3\">", ".", "<img src=\"f5\">", "e", "<img src=\"f6\">", \
  726   "<img src=\"f1\">", "<img src=\"f8\">", "<img src=\"f4\">", "<img src=\"f7\">", "", ":", "", "", \
  727   "&#331;", ".", ".", ".", ".", ".", ".", "&#240;", \
  728   "&#230;", ".", ".", ".", "", ".", ".", "", \
  729   "", "", "", "", "", "", "", "", \
  730   "", "", "", "", "", "", "", "", \
  731   "", "", "", "", "", "", "", "", \
  732   "", "", "", "", "", "", "", "", \
  733   "", "", "", "", "", "", "", "", \
  734   "", "", "", "", "", "", "", "", \
  735   "", "", "", "", "", "", "", "", \
  736   "", "", "", "", "", "", "", "", \
  737   "", "", "", "", "", "", "", "", \
  738   "", "", "", "", "", "", "", "", \
  739   "", "", "", "", "", "", "", "", \
  740   "", "", "", "", "", "", "", "" } \
  741 
  742 QString ConvertYDP::convertChunk(const char *inp, int size, bool unicodeFont)
  743 {
  744     QString out;
  745     unsigned char *input = (unsigned char *)inp;
  746     unsigned char ch;
  747     char a;
  748     int i;
  749 
  750     if (unicodeFont) {
  751     // prawdopodobnie jesli to jest wlaczone, to czesc zabaw z lokalami jest zbedna
  752     const static int table_cp_unicode[] = {
  753         0x002e, 0x002e, 0x0254, 0x0292, 0x002e, 0x0283, 0x0065, 0x028c, // 80-87
  754         0x0259, 0x03b8, 0x026a, 0x0251, 0x015a, 0x02d0, 0x00b4, 0x0179, // 88-8f
  755         0x014b, 0x002e, 0x002e, 0x002e, 0x002e, 0x002e, 0x002e, 0x00f0, // 90-97
  756         0x00e6, 0x002e, 0x002e, 0x002e, 0x015b, 0x002e, 0x002e, 0x017a, // 98-9f
  757         0x002e, 0x0104, 0x002e, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, // a0-a7
  758         0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, // a8-af
  759         0x00b0, 0x0105, 0x002e, 0x0142, 0x00b4, 0x013e, 0x015b, 0x002e, // b0-b7
  760         0x00b8, 0x0105, 0x015f, 0x0165, 0x017a, 0x002e, 0x017e, 0x017c, // b8-bf
  761         0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x013d, 0x0106, 0x00c7, // c0-c7
  762         0x010c, 0x00c9, 0x0118, 0x00cb, 0x0114, 0x00cd, 0x00ce, 0x010e, // c8-cf
  763         0x00d0, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0-d7
  764         0x0158, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0162, 0x00df, // d8-df
  765         0x0155, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x013e, 0x0107, 0x00e7, // e0-e7
  766         0x010d, 0x00e9, 0x0119, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x010f, // e8-ef
  767         0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0-f7
  768         0x0159, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0163, 0x002e, // f8-ff
  769         };
  770 
  771     for (i=0; i!=size; i++) {
  772         if (*input > 127) {
  773         // bierzemy z tabeli
  774         ch = *input;
  775             out += QChar(table_cp_unicode[*input-128]);
  776         } else {
  777         a = *input;
  778         out += a;
  779         }
  780         input++;
  781     }
  782     } else {
  783     const static char *table_cp_phonetic[]=TABLE_PHONETIC_ISO;
  784     int j;
  785 
  786     for (i=0; i!=size; i++) {
  787         if (*input > 127) {
  788         j=0;
  789         do {
  790             ch = table_cp_phonetic[*input-128][j];
  791             out += ch;
  792             j++;
  793         } while (table_cp_phonetic[*input-128][j]!='\0');
  794         } else {
  795         a = *input;
  796         out += a;
  797         }
  798         input++;
  799     }
  800     }
  801     return out;
  802 }
  803 
  804 int ConvertYDP::localeCompare(const char *w1, const char *w2) {
  805     char lw1[128];
  806     char lw2[128];
  807     
  808     expandSS(lw1, w1);
  809     expandSS(lw2, w2);
  810     
  811     int i = 0;
  812     int len1 = strlen(lw1);
  813     int len2 = strlen(lw2);
  814     int c1, c2;
  815     for (; ((i<len1) && (i<len2)); i++) {
  816         c1 = charIndex(lw1[i]); c2 = charIndex(lw2[i]);
  817         if (c1!=c2) {
  818             return c1-c2;
  819         }
  820     }
  821     
  822     if (len1 != len2) {
  823         // identical substrings so longer is bigger
  824         return len1-len2;
  825     } else {
  826         //there are problems with german words like 'zahlen' and 'zhlen' - 
  827         //the word with umlaut is smaller
  828         for (i=0; i<len1; ++i) {
  829             if (lw1[i] != lw2[i]) {
  830                 if (lw1[i] == '' || lw1[i] == '' || lw1[i] == '')
  831                     return -1;
  832                 else if (lw2[i] == '' || lw2[i] == '' || lw2[i] == '')
  833                     return 1;
  834             }
  835         }
  836     }
  837     
  838     return 0;
  839 }
  840 
  841 void ConvertYDP::expandSS(char *dst, const char *src)
  842 {
  843     for (; *src; ++src, ++dst) {
  844         if (*src == '') {
  845             *dst = 's';
  846             *(++dst) = 's';
  847         }
  848         else
  849             *dst = *src;
  850     }
  851     
  852     *dst = '\0';
  853 }