Exemple #1
12
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);
}
Exemple #2
0
/* make_bakfile - make a backup file */
static void
make_bakfile (char *filename)
{
  STRING_T *s = 0;
  size_t pos, dotpos;
  static char dot[2] = { '.', '\0' };   /* to foil cstrings */
  static char bak[5] = { '.', 'b', 'a', 'k', '\0' };

  if (!file_exists (filename))
    return;
  s = DScreate ();
  DSassigncstr (s, filename, NPOS);
  pos = DSfind_last_of (s, FILENAME_DELIMITERS, NPOS, NPOS);
  dotpos = DSfind (s, dot, pos + 1, NPOS);
  if (dotpos != NPOS)
    DSresize (s, dotpos, 0);
  DSappendcstr (s, bak, NPOS);
  rename (filename, DScstr (s));
  DSdestroy (s);
}
Exemple #3
0
static STRING_T *
get_name_from_nlspath (STRING_T * r, char *name)
{
  char *nlspath = 0;
  char *lang = 0;
  size_t pos, oldpos, iter;
  STRING_T *language = 0, *territory = 0, *codeset = 0, *s = 0;

  nlspath = getenv ("NLSPATH");
  lang = get_language ();
  DSresize (r, 0, 0);
  if (nlspath == 0)
    {
      DSassigncstr (r, name, NPOS);
      return r;
    }
  DSassigncstr (r, nlspath, NPOS);
  /* set language, territory, codeset values */
  if (*lang != 0)
    {
      s = DScreate ();
      language = DScreate ();
      territory = DScreate ();
      codeset = DScreate ();
      DSassigncstr (s, lang, NPOS);
      for (iter = 3, oldpos = pos = 0;
	   iter != 0;
	   oldpos = pos, --iter, pos = DSfind (s, "@._", ++pos, iter))
	{
	  /* assign values */
	  if (oldpos == 0)
	    DSassign (language, s, 0, pos);
	  else
	    {
	      switch (DSget_at (s, oldpos))
		{
		case '_':	/* territory */
		  DSassign (territory, s, oldpos + 1, pos - oldpos - 1);
		  break;
		case '.':	/* codeset */
		  DSassign (codeset, s, oldpos + 1, pos - oldpos - 1);
		  break;
		default:	/*modifier? */
		  break;
		}
	      if (pos == NPOS)
		break;
	    }
	}
    }
  for (pos = 0; (pos = DSfind (r, "%", pos, 1)) != NPOS; ++pos)
    {
      switch (DSget_at (r, pos + 1))
	{
	case 'N':		/* name */
	  DSreplacecstr (r, pos, 2, name, NPOS);
	  pos += strlen (name) - 1;
	  break;
	case 'L':		/* language */
	  DSreplacecstr (r, pos, 2, lang, NPOS);
	  pos += strlen (lang) - 1;
	  break;
	case 'l':		/* language element from %L */
	  DSreplace (r, pos, 2, language, 0, NPOS);
	  pos += DSlength (language) - 1;
	  break;
	case 't':		/* territory element from %L */
	  if (territory != 0)
	    {
	      DSreplace (r, pos, 2, territory, 0, NPOS);
	      pos += DSlength (territory) - 1;
	    }
	  break;
	case 'c':		/* codeset element from %L */
	  if (codeset != 0)
	    {
	      DSreplace (r, pos, 2, codeset, 0, NPOS);
	      pos += DSlength (codeset) - 1;
	    }
	  break;
	case '%':		/* percent sign */
	  DSremove (r, pos, 1);
	  break;
	}
    }
  if (s != 0)
    DSdestroy (s);
  if (language != 0)
    DSdestroy (language);
  if (territory != 0)
    DSdestroy (territory);
  if (codeset != 0)
    DSdestroy (codeset);
  return r;
}