web/neg_lang.c

説明を見る。
00001 /*
00002    Unix SMB/CIFS implementation.
00003    SWAT language handling
00004    
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019    Created by Ryo Kawahara <rkawa@lbe.co.jp> 
00020 */
00021 
00022 #include "includes.h"
00023 #include "web/swat_proto.h"
00024 
00025 /*
00026   during a file download we first check to see if there is a language
00027   specific file available. If there is then use that, otherwise 
00028   just open the specified file
00029 */
00030 int web_open(const char *fname, int flags, mode_t mode)
00031 {
00032         char *p = NULL;
00033         char *lang = lang_tdb_current();
00034         int fd;
00035         if (lang) {
00036                 asprintf(&p, "lang/%s/%s", lang, fname);
00037                 if (p) {
00038                         fd = sys_open(p, flags, mode);
00039                         free(p);
00040                         if (fd != -1) {
00041                                 return fd;
00042                         }
00043                 }
00044         }
00045 
00046         /* fall through to default name */
00047         return sys_open(fname, flags, mode);
00048 }
00049 
00050 
00051 struct pri_list {
00052         float pri;
00053         char *string;
00054 };
00055 
00056 static int qsort_cmp_list(const void *x, const void *y) {
00057         struct pri_list *a = (struct pri_list *)x;
00058         struct pri_list *b = (struct pri_list *)y;
00059         if (a->pri > b->pri) return -1;
00060         if (a->pri < b->pri) return 1;
00061         return 0;
00062 }
00063 
00064 /*
00065   choose from a list of languages. The list can be comma or space
00066   separated
00067   Keep choosing until we get a hit 
00068   Changed to habdle priority -- Simo
00069 */
00070 
00071 void web_set_lang(const char *lang_string)
00072 {
00073         char **lang_list, **count;
00074         struct pri_list *pl;
00075         int lang_num, i;
00076 
00077         /* build the lang list */
00078         lang_list = str_list_make(lang_string, ", \t\r\n");
00079         if (!lang_list) return;
00080         
00081         /* sort the list by priority */
00082         lang_num = 0;
00083         count = lang_list;
00084         while (*count && **count) {
00085                 count++;
00086                 lang_num++;
00087         }
00088         pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
00089         if (!pl) {
00090                 return;
00091         }
00092 
00093         for (i = 0; i < lang_num; i++) {
00094                 char *pri_code;
00095                 if ((pri_code=strstr(lang_list[i], ";q="))) {
00096                         *pri_code = '\0';
00097                         pri_code += 3;
00098                         sscanf(pri_code, "%f", &(pl[i].pri));
00099                 } else {
00100                         pl[i].pri = 1;
00101                 }
00102                 pl[i].string = SMB_STRDUP(lang_list[i]);
00103         }
00104         str_list_free(&lang_list);
00105 
00106         qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list);
00107 
00108         /* it's not an error to not initialise - we just fall back to 
00109            the default */
00110 
00111         for (i = 0; i < lang_num; i++) {
00112                 if (lang_tdb_init(pl[i].string)) break;
00113         }
00114 
00115         for (i = 0; i < lang_num; i++) {
00116                 SAFE_FREE(pl[i].string);
00117         }
00118         SAFE_FREE(pl);
00119 
00120         return;
00121 }

Sambaに対してSat Aug 29 21:23:30 2009に生成されました。  doxygen 1.4.7