예제 #1
0
파일: sltermin.c 프로젝트: DrakXtools/drakx
SLterminfo_Type *_pSLtt_tigetent (SLCONST char *term)
{
   SLCONST char **tidirs, *tidir;
   FILE *fp = NULL;
   char file[1024];
   static char home_ti [1024];
   char *env;
   SLterminfo_Type *ti;

   if (
       (term == NULL)
#ifdef SLANG_UNTIC
       && (SLang_Untic_Terminfo_File == NULL)
#endif
       )
     return NULL;

   if (_pSLsecure_issetugid ()
       && ((term[0] == '.') || (NULL != strchr (term, '/'))))
     return NULL;

   if (NULL == (ti = (SLterminfo_Type *) SLmalloc (sizeof (SLterminfo_Type))))
     {
	return NULL;
     }
   memset ((char *)ti, 0, sizeof (SLterminfo_Type));

#ifdef SLANG_UNTIC
   if (SLang_Untic_Terminfo_File != NULL)
     {
	fp = open_terminfo (SLang_Untic_Terminfo_File, ti);
	goto fp_open_label;
     }
   else
#endif
   /* If we are on a termcap based system, use termcap */
   if (0 == tcap_getent (term, ti)) return ti;

   if (NULL != (env = _pSLsecure_getenv ("TERMINFO")))
     Terminfo_Dirs[0] = env;

   if (NULL != (env = _pSLsecure_getenv ("HOME")))
     {
	strncpy (home_ti, env, sizeof (home_ti) - 11);
	home_ti [sizeof(home_ti) - 11] = 0;
	strcat (home_ti, "/.terminfo");
	Terminfo_Dirs [1] = home_ti;
     }

   tidirs = Terminfo_Dirs;
   while (NULL != (tidir = *tidirs++))
     {
	if (*tidir == 0)
	  continue;

	if (sizeof (file) > strlen (tidir) + 5 + strlen (term))
	  {
	     sprintf (file, "%s/%c/%s", tidir, *term, term);
	     if (NULL != (fp = open_terminfo (file, ti)))
	       break;
	     sprintf (file, "%s/%02x/%s", tidir, (unsigned char)*term, term);
	     if (NULL != (fp = open_terminfo (file, ti)))
	       break;
	  }
     }

#ifdef SLANG_UNTIC
   fp_open_label:
#endif

   if (fp == NULL)
     {
	SLfree ((char *) ti);
	return NULL;
     }

   ti->flags = SLTERMINFO;
   if ((NULL == read_terminal_names (fp, ti))
       || (NULL == read_boolean_flags (fp, ti))
       || (NULL == read_numbers (fp, ti))
       || (NULL == read_string_offsets (fp, ti))
       || (NULL == read_string_table (fp, ti)))
     {
	_pSLtt_tifreeent (ti);
	ti = NULL;
     }
   (void) fclose (fp);
   return ti;
}
예제 #2
0
파일: sltermin.c 프로젝트: dborca/mc
SLterminfo_Type *_pSLtt_tigetent (char *term)
{
   char *tidir;
   int i;
   FILE *fp = NULL;
   char file[1024];
   static char home_ti [1024];
   char *home;
   SLterminfo_Type *ti;

   if (
       (term == NULL)
#ifdef SLANG_UNTIC
       && (SLang_Untic_Terminfo_File == NULL)
#endif
       )
     return NULL;

   if (_pSLsecure_issetugid ()
       && ((term[0] == '.') || (NULL != strchr (term, '/'))))
     return NULL;

   if (NULL == (ti = (SLterminfo_Type *) SLmalloc (sizeof (SLterminfo_Type))))
     {
	return NULL;
     }

#ifdef SLANG_UNTIC
   if (SLang_Untic_Terminfo_File != NULL)
     {
	fp = open_terminfo (SLang_Untic_Terminfo_File, ti);
	goto fp_open_label;
     }
   else
#endif
   /* If we are on a termcap based system, use termcap */
   if (0 == tcap_getent (term, ti)) return ti;

   if (NULL != (home = _pSLsecure_getenv ("HOME")))
     {
	size_t len = strlen (home);
    
	if (len > sizeof (home_ti) - sizeof ("/.terminfo"))
	    len = sizeof (home_ti) - sizeof ("/.terminfo");
	memcpy (home_ti, home, len);
	memcpy (home_ti + len, "/.terminfo", sizeof ("/.terminfo"));
	Terminfo_Dirs [0] = home_ti;
     }

   Terminfo_Dirs[1] = _pSLsecure_getenv ("TERMINFO");
   i = 0;
   while (1)
     {
	tidir = Terminfo_Dirs[i];
	if (tidir != NULL)
	  {
	     if (*tidir == 0)
	       break;		       /* last one */

	     if (sizeof (file) >= strlen (tidir) + 4 + strlen (term))
	       {
		  sprintf (file, "%s/%c/%s", tidir, *term, term);
		  if (NULL != (fp = open_terminfo (file, ti)))
		    break;
	       }
	  }
	i++;
     }

#ifdef SLANG_UNTIC
   fp_open_label:
#endif

   if (fp != NULL)
     {
	if (NULL != read_terminal_names (fp, ti))
	  {
	     if (NULL != read_boolean_flags (fp, ti))
	       {
		  if (NULL != read_numbers (fp, ti))
		    {
		       if (NULL != read_string_offsets (fp, ti))
			 {
			    if (NULL != read_string_table (fp, ti))
			      {
				 /* success */
				 fclose (fp);
				 ti->flags = SLTERMINFO;
				 return ti;
			      }
			    SLfree ((char *)ti->string_offsets);
			 }
		       SLfree ((char *)ti->numbers);
		    }
		  SLfree ((char *)ti->boolean_flags);
	       }
	     SLfree ((char *)ti->terminal_names);
	  }
	fclose (fp);
     }

   SLfree ((char *)ti);
   return NULL;
}