⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.c

📁 ipp打印机服务器原代码 注意:请将ipp.gz改为ipp.tar.gz 然后使用tar zxvf ipp.tar.gz解压 站长注意
💻 C
📖 第 1 页 / 共 2 页
字号:
  * messages consisting of:  *  *    #### SP message text  *  * or:  *  *    message text  *  * If the line starts with a number, then message processing picks up  * where the number indicates.  Otherwise the last message number is  * incremented.  *  * All leading whitespace is deleted.  */  if (strcmp(real, "C"))    fp = fopen(filename, "r");  else    fp = NULL;  if (fp == NULL)    strlcpy(line, lang_default[0], sizeof(line));  else if (fgets(line, sizeof(line), fp) == NULL)  {   /*    * Can't read encoding!    */    fclose(fp);    return (NULL);  }  i = strlen(line) - 1;  if (line[i] == '\n')    line[i] = '\0';	/* Strip LF */ /*  * See if there is a free language available; if so, use that  * record...  */  for (lang = lang_cache; lang != NULL; lang = lang->next)    if (lang->used == 0)      break;  if (lang == NULL)  {   /*    * Allocate memory for the language and add it to the cache.    */    if ((lang = calloc(sizeof(cups_lang_t), 1)) == NULL)    {      fclose(fp);      return (NULL);    }    lang->next = lang_cache;    lang_cache = lang;  } /*  * Free all old strings as needed...  */  for (i = 0; i < CUPS_MSG_MAX; i ++)  {    if (lang->messages[i] != NULL && lang->messages[i] != lang_blank)      free(lang->messages[i]);    lang->messages[i] = (char*)lang_blank;  } /*  * Then assign the language and encoding fields...  */  lang->used ++;  strlcpy(lang->language, real, sizeof(lang->language));  if (encoding != CUPS_AUTO_ENCODING)    lang->encoding = encoding;  else  {    lang->encoding = CUPS_US_ASCII;    for (i = 0; i < (sizeof(lang_encodings) / sizeof(lang_encodings[0])); i ++)      if (strcmp(lang_encodings[i], line) == 0)      {	lang->encoding = (cups_encoding_t)i;	break;      }  } /*  * Read the strings from the file...  */  msg   = (cups_msg_t)-1;  count = 1;  for (;;)  {   /*    * Read a line from memory or from a file...    */    if (fp == NULL)    {      if (lang_default[count] == NULL)        break;      strlcpy(line, lang_default[count], sizeof(line));    }    else if (fgets(line, sizeof(line), fp) == NULL)      break;    count ++;   /*    * Ignore blank lines...    */    i = strlen(line) - 1;    if (line[i] == '\n')      line[i] = '\0';	/* Strip LF */    if (line[0] == '\0')      continue;   /*    * Grab the message number and text...    */    if (isdigit(line[0] & 255))      msg = (cups_msg_t)atoi(line);    else      msg ++;    if (msg < 0 || msg >= CUPS_MSG_MAX)      continue;    text = line;    while (isdigit(*text & 255))      text ++;    while (isspace(*text & 255))      text ++;        lang->messages[msg] = strdup(text);  } /*  * Close the file and return...  */  if (fp != NULL)    fclose(fp);  return (lang);}/* * '_cupsRestoreLocale()' - Restore the original locale... */void_cupsRestoreLocale(int  category,	/* I - Category */                   char *oldlocale)	/* I - Old locale or NULL */{  DEBUG_printf(("_cupsRestoreLocale(category=%d, oldlocale=\"%s\")\n",                category, oldlocale));  if (oldlocale)  {   /*    * Reset the locale and free the locale string...    */    setlocale(category, oldlocale);    free(oldlocale);  }}/* * '_cupsSaveLocale()' - Set the locale and save a copy of the old locale... */char *					/* O - Old locale or NULL */_cupsSaveLocale(int        category,	/* I - Category */                const char *locale)	/* I - New locale or NULL */{  char	*oldlocale;			/* Old locale */  DEBUG_printf(("_cupsSaveLocale(category=%d, locale=\"%s\")\n",                category, locale)); /*  * Get the old locale and copy it...  */  if ((oldlocale = setlocale(category, NULL)) != NULL)    oldlocale = strdup(oldlocale);  DEBUG_printf(("    oldlocale=\"%s\"\n", oldlocale ? oldlocale : "(null)")); /*  * Set the new locale...  */  setlocale(category, locale); /*  * Return a copy of the old locale...  */  return (oldlocale);}#ifdef __APPLE__/* * Code & data to translate OSX's language names to their ISO 639-1 locale. * * The first version uses the new CoreFoundation API added in 10.3 (Panther), * the second is for 10.2 (Jaguar). */#  ifdef HAVE_CF_LOCALE_ID/* * 'appleLangDefault()' - Get the default locale string. */static const char *			/* O - Locale string */appleLangDefault(void){  CFPropertyListRef 	localizationList;					/* List of localization data */  CFStringRef		languageName;	/* Current name */  CFStringRef		localeName;	/* Canonical from of name */  static char		language[32] = "";					/* Cached language */ /*  * Only do the lookup and translation the first time.  */  if (!language[0])  {    localizationList =        CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),                                  kCFPreferencesCurrentApplication);    if (localizationList != NULL)    {      if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&	  CFArrayGetCount(localizationList) > 0)      {        languageName = CFArrayGetValueAtIndex(localizationList, 0);        if (languageName != NULL &&            CFGetTypeID(languageName) == CFStringGetTypeID())        {	  localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(	                   kCFAllocatorDefault, languageName);	  if (localeName != NULL)	  {	    CFStringGetCString(localeName, language, sizeof(language),			       kCFStringEncodingASCII);	    CFRelease(localeName);	    if (!strcmp(language, "en"))	      strlcpy(language, "en_US.UTF-8", sizeof(language));	    else if (strchr(language, '.') == NULL)	      strlcat(language, ".UTF-8", sizeof(language));	  }        }      }      CFRelease(localizationList);    }     /*    * If we didn't find the language, default to en_US...    */    if (!language[0])      strlcpy(language, "en_US.UTF-8", sizeof(language));  } /*  * Return the cached locale...  */  return (language);}#  else/* * Code & data to translate OSX 10.2's language names to their ISO 639-1 * locale. */typedef struct{  const char * const name;		/* Language name */  const char * const locale;		/* Locale name */} apple_name_locale_t;static const apple_name_locale_t apple_name_locale[] ={  { "English"     , "en_US.UTF-8" },	{ "French"     , "fr.UTF-8" },  { "German"      , "de.UTF-8" },	{ "Italian"    , "it.UTF-8" },    { "Dutch"       , "nl.UTF-8" },	{ "Swedish"    , "sv.UTF-8" },  { "Spanish"     , "es.UTF-8" },	{ "Danish"     , "da.UTF-8" },    { "Portuguese"  , "pt.UTF-8" },	{ "Norwegian"  , "no.UTF-8" },  { "Hebrew"      , "he.UTF-8" },	{ "Japanese"   , "ja.UTF-8" },    { "Arabic"      , "ar.UTF-8" },	{ "Finnish"    , "fi.UTF-8" },  { "Greek"       , "el.UTF-8" },	{ "Icelandic"  , "is.UTF-8" },    { "Maltese"     , "mt.UTF-8" },	{ "Turkish"    , "tr.UTF-8" },  { "Croatian"    , "hr.UTF-8" },	{ "Chinese"    , "zh.UTF-8" },    { "Urdu"        , "ur.UTF-8" },	{ "Hindi"      , "hi.UTF-8" },  { "Thai"        , "th.UTF-8" },	{ "Korean"     , "ko.UTF-8" },    { "Lithuanian"  , "lt.UTF-8" },	{ "Polish"     , "pl.UTF-8" },  { "Hungarian"   , "hu.UTF-8" },	{ "Estonian"   , "et.UTF-8" },    { "Latvian"     , "lv.UTF-8" },	{ "Sami"       , "se.UTF-8" },  { "Faroese"     , "fo.UTF-8" },	{ "Farsi"      , "fa.UTF-8" },    { "Russian"     , "ru.UTF-8" },	{ "Chinese"    , "zh.UTF-8" },  { "Dutch"       , "nl.UTF-8" },	{ "Irish"      , "ga.UTF-8" },    { "Albanian"    , "sq.UTF-8" },	{ "Romanian"   , "ro.UTF-8" },  { "Czech"       , "cs.UTF-8" },	{ "Slovak"     , "sk.UTF-8" },    { "Slovenian"   , "sl.UTF-8" },	{ "Yiddish"    , "yi.UTF-8" },  { "Serbian"     , "sr.UTF-8" },	{ "Macedonian" , "mk.UTF-8" },    { "Bulgarian"   , "bg.UTF-8" },	{ "Ukrainian"  , "uk.UTF-8" },  { "Byelorussian", "be.UTF-8" },	{ "Uzbek"      , "uz.UTF-8" },    { "Kazakh"      , "kk.UTF-8" },	{ "Azerbaijani", "az.UTF-8" },  { "Azerbaijani" , "az.UTF-8" },	{ "Armenian"   , "hy.UTF-8" },    { "Georgian"    , "ka.UTF-8" },	{ "Moldavian"  , "mo.UTF-8" },  { "Kirghiz"     , "ky.UTF-8" },	{ "Tajiki"     , "tg.UTF-8" },    { "Turkmen"     , "tk.UTF-8" },	{ "Mongolian"  , "mn.UTF-8" },  { "Mongolian"   , "mn.UTF-8" },	{ "Pashto"     , "ps.UTF-8" },    { "Kurdish"     , "ku.UTF-8" },	{ "Kashmiri"   , "ks.UTF-8" },  { "Sindhi"      , "sd.UTF-8" },	{ "Tibetan"    , "bo.UTF-8" },    { "Nepali"      , "ne.UTF-8" },	{ "Sanskrit"   , "sa.UTF-8" },  { "Marathi"     , "mr.UTF-8" },	{ "Bengali"    , "bn.UTF-8" },    { "Assamese"    , "as.UTF-8" },	{ "Gujarati"   , "gu.UTF-8" },  { "Punjabi"     , "pa.UTF-8" },	{ "Oriya"      , "or.UTF-8" },    { "Malayalam"   , "ml.UTF-8" },	{ "Kannada"    , "kn.UTF-8" },  { "Tamil"       , "ta.UTF-8" },	{ "Telugu"     , "te.UTF-8" },    { "Sinhalese"   , "si.UTF-8" },	{ "Burmese"    , "my.UTF-8" },  { "Khmer"       , "km.UTF-8" },	{ "Lao"        , "lo.UTF-8" },    { "Vietnamese"  , "vi.UTF-8" },	{ "Indonesian" , "id.UTF-8" },  { "Tagalog"     , "tl.UTF-8" },	{ "Malay"      , "ms.UTF-8" },    { "Malay"       , "ms.UTF-8" },	{ "Amharic"    , "am.UTF-8" },  { "Tigrinya"    , "ti.UTF-8" },	{ "Oromo"      , "om.UTF-8" },    { "Somali"      , "so.UTF-8" },	{ "Swahili"    , "sw.UTF-8" },  { "Kinyarwanda" , "rw.UTF-8" },	{ "Rundi"      , "rn.UTF-8" },    { "Nyanja"      , "" },		{ "Malagasy"   , "mg.UTF-8" },  { "Esperanto"   , "eo.UTF-8" },	{ "Welsh"      , "cy.UTF-8" },    { "Basque"      , "eu.UTF-8" },	{ "Catalan"    , "ca.UTF-8" },  { "Latin"       , "la.UTF-8" },	{ "Quechua"    , "qu.UTF-8" },    { "Guarani"     , "gn.UTF-8" },	{ "Aymara"     , "ay.UTF-8" },  { "Tatar"       , "tt.UTF-8" },	{ "Uighur"     , "ug.UTF-8" },    { "Dzongkha"    , "dz.UTF-8" },	{ "Javanese"   , "jv.UTF-8" },  { "Sundanese"   , "su.UTF-8" },	{ "Galician"   , "gl.UTF-8" },    { "Afrikaans"   , "af.UTF-8" },	{ "Breton"     , "br.UTF-8" },  { "Inuktitut"   , "iu.UTF-8" },	{ "Scottish"   , "gd.UTF-8" },    { "Manx"        , "gv.UTF-8" },	{ "Irish"      , "ga.UTF-8" },  { "Tongan"      , "to.UTF-8" },	{ "Greek"      , "el.UTF-8" },    { "Greenlandic" , "kl.UTF-8" },	{ "Azerbaijani", "az.UTF-8" }};/* * 'appleLangDefault()' - Get the default locale string. */static const char *			/* O - Locale string */appleLangDefault(void){  int			i;		/* Looping var */  CFPropertyListRef 	localizationList;					/* List of localization data */  CFStringRef		localizationName;					/* Current name */  char			buff[256];	/* Temporary buffer */  static const char	*language = NULL;					/* Cached language */ /*  * Only do the lookup and translation the first time.  */  if (language == NULL)  {    localizationList =        CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),                                  kCFPreferencesCurrentApplication);    if (localizationList != NULL)    {      if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&	  CFArrayGetCount(localizationList) > 0)      {	localizationName = CFArrayGetValueAtIndex(localizationList, 0);	if (localizationName != NULL &&            CFGetTypeID(localizationName) == CFStringGetTypeID())	{	  CFIndex length = CFStringGetLength(localizationName);	  if (length <= sizeof(buff) &&	      CFStringGetCString(localizationName, buff, sizeof(buff),	                         kCFStringEncodingASCII))	  {	    buff[sizeof(buff) - 1] = '\0';	    for (i = 0;		 i < sizeof(apple_name_locale) / sizeof(apple_name_locale[0]);		 i++)	    {	      if (strcasecmp(buff, apple_name_locale[i].name) == 0)	      {		language = apple_name_locale[i].locale;		break;	      }	    }	  }	}      }      CFRelease(localizationList);    }     /*    * If we didn't find the language, default to en_US...    */    if (language == NULL)      language = apple_name_locale[0].locale;  } /*  * Return the cached locale...  */  return (language);}#  endif /* HAVE_CF_LOCALE_ID */#endif /* __APPLE__ *//* * 'cups_cache_lookup()' - Lookup a language in the cache... */static cups_lang_t *			/* O - Language data or NULL */cups_cache_lookup(const char      *name,/* I - Name of locale */                  cups_encoding_t encoding)					/* I - Encoding of locale */{  cups_lang_t	*lang;			/* Current language */  DEBUG_printf(("cups_cache_lookup(name=\"%s\", encoding=%d(%s))\n", name,                encoding, encoding == CUPS_AUTO_ENCODING ? "auto" :		              lang_encodings[encoding])); /*  * Loop through the cache and return a match if found...  */  for (lang = lang_cache; lang != NULL; lang = lang->next)    if (!strcmp(lang->language, name) &&        (encoding == CUPS_AUTO_ENCODING || encoding == lang->encoding))    {      lang->used ++;      DEBUG_puts("cups_cache_lookup: returning match!");      return (lang);    }  DEBUG_puts("cups_cache_lookup: returning NULL!");  return (NULL);}/* * End of "$Id: language.c,v 1.53 2005/01/03 19:29:45 mike Exp $". */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -