- /* Strip out the weights; we don't use them. Also convert
- * hyphens to underscores.
- */
- for (j=0; j<strlen(lang); ++j) {
- if (lang[j] == '-') lang[j] = '_';
- if (lang[j] == ';') lang[j] = 0;
- }
-
- for (j=0; j<NUM_LANGS; ++j) {
- if (!strncasecmp(lang, AvailLang[j], strlen(lang))) {
- strcpy(selected_locale, AvailLang[j]);
+ extract_token(&buf[0],search, i,',',16);
+ /* we are searching, if this list item has something like ;q=n*/
+ if (num_tokens(&buf[0],'=')>1) {
+ int sbuflen, k;
+ extract_token(&sbuf[0],&buf[0], 1,'=',16);
+ sbuflen=strlen(&sbuf[0]);
+ for (k=0; k<sbuflen; k++) if (sbuf[k]=='.') sbuf[k]='0';
+ ls->priority=atol(&sbuf[0]);
+ }
+ else {
+ ls->priority=1000;
+ }
+ /* get the locale part */
+ extract_token(&sbuf[0],&buf[0],0,';',16);
+ /* get the lang part, which should be allways there */
+ extract_token(&ls->lang[0],&sbuf[0],0,'-',16);
+ /* get the area code if any. */
+ if (num_tokens(&sbuf[0],'-')>1) {
+ extract_token(&ls->region[0],&sbuf[0],1,'-',16);
+ }
+ else { /* no ara code? use lang code */
+ blen=strlen(&ls->lang[0]);
+ memcpy(&ls->region[0], ls->lang,blen);
+ ls->region[blen]='\0';
+ } /* area codes are uppercase */
+ blen=strlen(&ls->region[0]);
+ for (j=0; j<blen; j++)
+ {
+ int chars=toupper(ls->region[j]);
+ ls->region[j]=(char)chars;/*todo ?! */
+ }
+ sprintf(&lbuf[0],"%s_%s",&ls->lang[0],&ls->region[0]);
+
+ /* check if we have this lang */
+ ls->availability=1;
+ ls->selectedlang=-1;
+ for (j=0; j<NUM_LANGS; j++) {
+ int result;
+ /* match against the LANG part */
+ result=strcasecmp(&ls->lang[0], AvailLang[j]);
+ if ((result<0)&&(result<ls->availability)){
+ ls->availability=result;
+ ls->selectedlang=j;
+ }
+ /* match against lang and locale */
+ if (0==strcasecmp(&lbuf[0], AvailLang[j])){
+ ls->availability=0;
+ ls->selectedlang=j;
+ j=NUM_LANGS;
+ }
+ }
+ }
+
+ prio=0;
+ av=-1000;
+ nBest=-1;
+ for (i=0; ((i<nParts)&&(i<SEARCH_LANG)); i++)
+ {
+ ls=&wanted_locales[i];
+ if ((ls->availability<=0)&&
+ (av<ls->availability)&&
+ (prio<ls->priority)&&
+ (ls->selectedlang!=-1)){
+ nBest=ls->selectedlang;
+ av=ls->availability;
+ prio=ls->priority;