コード例 #1
12
ファイル: catgets.c プロジェクト: CivilPol/sdcboot
nl_catd (catopen) (const char *name, int oflag)
{
  _CAT_CATALOG_T *_kitten_catalog = 0;
  static STRING_T *catfile = 0;
  static STRING_T *nlspath = 0;
  size_t pos;

  /* According to the Posix definition, if name has a '/', the name is the
     entire path to the file. Expand that to include ':' and '\\' for 
     FreeDOS.  */
  if (strpbrk (name, ":/\\") != 0)
    _kitten_catalog = catread (name);
  else
    {
      /* Open the catalog file. */
      catfile = DScreate ();
      nlspath = DScreate ();
      get_name_from_nlspath (nlspath, (char *) name);
      while (_kitten_catalog == 0 && DSlength (nlspath) != 0)
	{
	  pos = DSfind (nlspath, ";", 0, 1);
	  DSassign (catfile, nlspath, 0, pos);
	  if (DSlength (catfile) == 0)
	    DSassigncstr (catfile, (char *) name, NPOS);
	  _kitten_catalog = catread (DScstr (catfile));
	  DSremove (nlspath, 0, (pos == NPOS) ? NPOS : pos + 1);
	}
      DSdestroy (nlspath);
      DSdestroy (catfile);
    }
  /* If we could not find it, return failure. Otherwise, install the
     catalog and return a cookie.  */
  return _kitten_catalog ? install_catalog (_kitten_catalog) : (nl_catd) (-1);
}
コード例 #2
0
ファイル: kitten.c プロジェクト: ErisBlastar/osfree
nl_catd kittenopen(char *name)
{
  /* catopen() returns a message _kitten_catalog descriptor  *
   * of type nl_catd on success.  On failure, it returns -1. */

  char catlang[3];                      /* from LANG environment var. */
  char *nlsptr;                         /* ptr to NLSPATH */
  char *lang;                           /* ptr to LANG */
  int i;

  /* Open the _kitten_catalog file */
  /* The value of `_kitten_catalog' will be set based on catread */


  if (_kitten_catalog) { /* Already one open */
    fprintf(stderr,"cat already open\r\n");
    return (-1);
  }


  for (i=0; i<128; i++)
    catpoints[i].text = NULL;


  if (strchr (name, '\\')) {
    /* unusual case: 'name' is a filename */
    fprintf(stderr,"found \\\r\n",9);
    _kitten_catalog = catread (name);
    if (_kitten_catalog)
      return (_kitten_catalog);
  }


  /* If the message _kitten_catalog file name does not contain a directory *
   * separator, then we need to try to locate the message _kitten_catalog. */

  /* We will need the value of LANG, and may need a 2-letter abbrev of
     LANG later on, so get it now. */

  lang = getenv ("LANG");


  if (lang == NULL) {
      /* printf("no lang= found\n"); */ /* not fatal, though */
      /* Return failure - we won't be able to locate the cat file */
      return (-1);
  }

  if ( ( strlen(lang) < 2 ) ) {
      /* Return failure - we won't be able to locate the cat file */
      return (-1);
  }


  memcpy(catlang, lang, 2);
  /* we copy the full LANG value or the part before "-" if "-" found */
  catlang[2] = '\0';

  /* step through NLSPATH */


  nlsptr = getenv ("NLSPATH");

  if (nlsptr == NULL) {
      /* printf("no NLSPATH= found\n"); */ /* not fatal either */
      /* Return failure - we won't be able to locate the cat file */
      return (-1);
   }

  catfile[0] = '\0';


  while (nlsptr != NULL) {
      char *tok = strchr(nlsptr, ';');
      int toklen;

      if (tok == NULL)
        toklen = strlen(nlsptr); /* last segment */
      else
        toklen = tok - nlsptr; /* segment terminated by ';' */

      /* catfile = malloc(toklen+1+strlen(name)+1+strlen(lang)+1); */
      /* Try to find the _kitten_catalog file in each path from NLSPATH */

      if ((toklen+6+strlen(name)) > sizeof(catfile)) {
        fprintf(stderr,"NLSPATH overflow\r\n");
        return 0; /* overflow in NLSPATH, should never happen */
      }

      /* Rule #1: %NLSPATH%\%LANG%\cat */

        memcpy(catfile, nlsptr, toklen);
        strcpy(catfile+toklen,"\\");
        strcat(catfile,catlang);
        strcat(catfile,"\\");
        strcat(catfile,name);

        _kitten_catalog = catread (catfile);
        if (_kitten_catalog)
          return (_kitten_catalog);

      /* Rule #2: %NLSPATH%\cat.%LANG% */

        /* memcpy(catfile, nlsptr, toklen); */
        strcpy(catfile+toklen,"\\");
        strcat(catfile,name);
        strcat(catfile,".");
        strcat(catfile,catlang);
        _kitten_catalog = catread (catfile);
        if (_kitten_catalog)
          return (_kitten_catalog);


      /* Grab next tok for the next while iteration */

        nlsptr = tok;
        if (nlsptr) nlsptr++;

    } /* while tok */

  /* We could not find it.  Return failure. */

  return (-1);
}
コード例 #3
0
ファイル: kitten.c プロジェクト: CivilPol/sdcboot
nl_catd
kittenopen(char *name)
{
  /* catopen() returns a message _kitten_catalog descriptor of type nl_catd on
     success.  On failure, it returns -1. */

  /* 'flag' is completely ignored here. */

  char *catfile;		        /* full path to the msg _kitten_catalog */
  char *nlsptr;				/* ptr to NLSPATH */
  char *lang;                           /* ptr to LANG */
  
  	
  /* Open the _kitten_catalog file */

  /* The value of `_kitten_catalog' will be set based on catread */

  if (_kitten_catalog)
    {
      /* Already one open */

      printf("cat already open\n");	
      return (-1);
    }

  /* If the message _kitten_catalog file name contains a directory separator,
     assume that this is a real path to the _kitten_catalog file.  Note that
     catread will return a true or false value based on its ability
     to read the catfile. */

  if (strchr (name, '\\'))
    {
      /* first approximation: 'name' is a filename */
      
      printf("found \\\n");

      _kitten_catalog = catread (name);
      return (_kitten_catalog);
    }

  /* If the message _kitten_catalog file name does not contain a directory
     separator, then we need to try to locate the message _kitten_catalog on
     our own.  We will use several methods to find it. */

  /* We will need the value of LANG, and may need a 2-letter abbrev of
     LANG later on, so get it now. */

  lang = getenv ("LANG");

  if (lang == NULL)
    {  
      /* printf("no lang= found\n"); */
    
      /* Return failure - we won't be able to locate the cat file */
      return (-1);
    }


  /* step through NLSPATH */

  nlsptr = getenv ("NLSPATH");
  

  if (nlsptr == NULL)
    {
      /* printf("no NLSPATH= found\n"); */

      /* Return failure - we won't be able to locate the cat file */
      return (-1);
    }

  while (nlsptr != NULL)
    {
      char *tok = strchr(nlsptr, ';');
      int toklen;

      if (tok == NULL) tok = nlsptr + strlen(nlsptr);
      toklen=tok-nlsptr;
      catfile = malloc(toklen+1+strlen(name)+1+strlen(lang)+1);
      /* Try to find the _kitten_catalog file in each path from NLSPATH */

      /* Rule #1: %NLSPATH%\%LANG%\cat */

      memcpy(catfile,nlsptr,toklen);
      sprintf(catfile+toklen,"\\%s\\%s",lang,name);

      _kitten_catalog = catread (catfile);
      if (_kitten_catalog)
	{
	  return (_kitten_catalog);
	}

      /* Rule #2: %NLSPATH%\cat.%LANG% */

      sprintf(catfile+toklen,"\\%s.%s",name, lang);

      _kitten_catalog = catread (catfile);

      if (_kitten_catalog)
	{
	  return (_kitten_catalog);
	}

      /* Rule #3: if LANG looks to be in format "en-UK" then
         %NLSPATH%\cat.EN */

      if (lang[2] == '-')
        {
	  lang[2] = 0;
	  sprintf(catfile+toklen,"\\%s.%s",name,lang);
	  lang[2] = '-';

	  _kitten_catalog = catread (catfile);
	  if (_kitten_catalog)
	    {
	      return (_kitten_catalog);
	    }
        }

      /* Grab next tok for the next while iteration */
      nlsptr = tok;
      if (nlsptr) nlsptr++;
      
    } /* while tok */

  /* We could not find it.  Return failure. */

  return (0);
}