Example #1
0
Application::~Application()
{
    //
    // Allocated using strdup, so free using free.
    //
    free((void*) _applicationClass);
    delete []_windows;

#ifdef CDExc21492
  #if defined(__hpux) || defined(USL) || defined(__uxp__)
    this->BasicComponent::~BasicComponent();
  #elif  __osf__
    BasicComponent * The_End = this;
    The_End->BasicComponent::~BasicComponent();
  #else
    BasicComponent::~BasicComponent();
  #endif
#endif

    catclose(catd);

    // In an MT environment, calling exit() causes threads to
    // hang and a deadlock results.
    // Call _exit() instead

    _exit(0);
}
Example #2
0
/******************************************************************************
 * Function:	_DtHelpLoadMultiInfo
 *
 * Returns:	Loads the multi-byte formatting table for the current locale.
 *
 *****************************************************************************/
void
_DtHelpLoadMultiInfo (
    wchar_t  **cant_begin_chars,
    wchar_t  **cant_end_chars,
    short     *nl_to_space)
{
#ifndef NO_MESSAGE_CATALOG
    int       len;
    char     *ptr;
    nl_catd   cat_fd;

    cat_fd = catopen ("fmt_tbl", NL_CAT_LOCALE);
    if (cat_fd != ((nl_catd) -1))
      {
	/*
	 * Get the list of characters that can't begin a line.
	 */
	ptr = catgets (cat_fd, 1, 1, "");
	len = strlen (ptr) + 1;
	*cant_begin_chars = (wchar_t *) malloc (len * sizeof (wchar_t));
	if (NULL != *cant_begin_chars &&
				mbstowcs(*cant_begin_chars, ptr, len) == -1)
	  {
	    free (*cant_begin_chars);
	    *cant_begin_chars = NULL;
	  }

	/*
	 * Get the list of characters that can't end a line.
	 */
	ptr = catgets (cat_fd, 1, 2, "");
	len = strlen (ptr) + 1;
	*cant_end_chars = (wchar_t *) malloc (len * sizeof (wchar_t));
	if (*cant_end_chars != NULL &&
				mbstowcs(*cant_end_chars, ptr, len) == -1)
	  {
	    free (*cant_end_chars);
	    *cant_end_chars = NULL;
	  }

	/*
	 * Get the spacing flag. I.E. when does a internal newline
	 * get turned into a space.
	 *      1 means all the time.
	 *      0 means only between a multibyte string and
	 *        a singlebyte string.
	 */
	ptr = catgets (cat_fd, 1, 3, "1");
	*nl_to_space = atoi(ptr);

	catclose (cat_fd);
      }
    else
#endif
      {
	*cant_begin_chars = NULL;
	*cant_end_chars   = NULL;
	*nl_to_space      = 1;
      }
}
Example #3
0
void ldap_int_error_init( void ) {
#ifdef LDAP_NLS
#define LDAP_NLS_SDK_CAT "openldap_sdk"
#define LDAP_NLS_LIBLDAP_SET (0)

	int	i;
	nl_catd catd = catopen( LDAP_NLS_SDK_CAT, NL_CAT_LOCALE );

	if( catd == -1 ) {
		return;
	}

	for ( i=0; ldap_errlist[i].e_reason != NULL; i++ ) {
		char *msg = catgets( catd,
			LDAP_NLS_LIBLDAP_SET,
			ldap_errlist[i].e_code, NULL );

		if( msg != NULL ) {
			msg = LDAP_STRDUP( msg );

			if( msg != NULL ) {
				ldap_errlist[i].e_reason = msg;
			}
		}
	}

	catclose( catd );
#endif
}
Example #4
0
XalanNLSMessageLoader::~XalanNLSMessageLoader()
{
    if ((int)m_catalogHandle != -1)
    {
        catclose(m_catalogHandle);
    }
}
Example #5
0
/*
 * msgcat_open - open a message catalog
 *   return: message catalog descriptor MSG_CATD or NULL
 *   name(in): message catalog file name
 *
 * Note: File name will be converted to a full path name with the the root
 *       directory prefix.
 *       The returned MSG_CATD is allocated with malloc(). It will be freed in
 *       msgcat_close().
 */
MSG_CATD
msgcat_open (const char *name)
{
  nl_catd catd;
  MSG_CATD msg_catd;
  char path[PATH_MAX];

  /* $CUBRID/msg/$CUBRID_MSG_LANG/'name' */
  envvar_localedir_file (path, PATH_MAX, lang_get_msg_Loc_name (), name);
  catd = catopen (path, 0);
  if (catd == NULL)
    {
      /* try once more as default language */
      envvar_localedir_file (path, PATH_MAX, LANG_NAME_DEFAULT, name);
      catd = catopen (path, 0);
      if (catd == NULL)
	{
	  return NULL;
	}
    }

  msg_catd = (MSG_CATD) malloc (sizeof (*msg_catd));
  if (msg_catd == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, sizeof (*msg_catd));
      catclose (catd);
      return NULL;
    }

  msg_catd->file = strdup (path);
  msg_catd->catd = (void *) catd;

  return msg_catd;
}
Example #6
0
File: 7-1.c Project: 1587/ltp
int main(void)
{
	int ret, status;
	pid_t child, ctl;
	nl_catd messcat;

	output_init();

	/* Generate the message catalog file from the text sourcefile */
	if (system(NULL)) {

		if (create_catalog() != 0)
			UNRESOLVED(errno, "Can't create " MESSCAT_IN);

		ret = system("gencat " MESSCAT_OUT " " MESSCAT_IN);

		if (ret != 0)
			output
			    ("Could not find the source file for message catalog.\n"
			     "You may need to execute gencat yourself.\n");
	}

	messcat = catopen("./" MESSCAT_OUT, 0);

	if (messcat == (nl_catd) - 1)
		UNRESOLVED(errno, "Could not open ./" MESSCAT_OUT);

	read_catalog(messcat, "parent");

	child = fork();

	if (child == -1)
		UNRESOLVED(errno, "Failed to fork");

	if (child == 0) {
		read_catalog(messcat, "child");
		exit(PTS_PASS);
	}

	ctl = waitpid(child, &status, 0);

	if (ctl != child)
		UNRESOLVED(errno, "Waitpid returned the wrong PID");

	if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != PTS_PASS))
		FAILED("Child exited abnormally");

	ret = catclose(messcat);

	if (ret != 0)
		UNRESOLVED(errno, "Failed to close the message catalog");

	system("rm -f " MESSCAT_IN " " MESSCAT_OUT);

#if VERBOSE > 0
	output("Test passed\n");
#endif
	PASSED;
}
Example #7
0
File: xcopy.c Project: FDOS/xcopy
/*-------------------------------------------------------------------------*/
void exit_fn(void) {
  if (switch_verify) {
    /* restore value of verify flag */
    setverify(bak_verify);
  }

  printf("%d %s\n", file_counter, catgets(cat, 1, 19, "file(s) copied"));
  catclose(cat);
}
Example #8
0
void
__kmp_i18n_catclose(
) {
    if ( status == KMP_I18N_OPENED ) {
        KMP_DEBUG_ASSERT( cat != KMP_I18N_NULLCAT );
        catclose( cat );
        cat = KMP_I18N_NULLCAT;
    }; // if
    status = KMP_I18N_CLOSED;
} // func __kmp_i18n_catclose
Example #9
0
static void
catopen_verify(boolean_t find)
{
	nl_catd cat;

	cat = catopen("TEST", NL_CAT_LOCALE);
	if (find == B_TRUE) {
		assert(cat != INVALID_CAT);
		(void) catclose(cat);
	} else {
		assert(cat == INVALID_CAT);
	}
}
Example #10
0
int
main (void)
{
  int rnd;
  int result = 0;

  mtrace ();

  /* We do this a few times to stress the memory handling.  */
  for (rnd = 0; rnd < ROUNDS; ++rnd)
    {
      nl_catd cd = catopen ("libc", 0);
      size_t cnt;

      if (cd == (nl_catd) -1)
	{
	  printf ("cannot load catalog: %m\n");
	  result = 1;
	  break;
	}

      /* Go through all the messages and compare the result.  */
      for (cnt = 0; cnt < nmsgs; ++cnt)
	{
	  char *trans;

	  trans = catgets (cd, 1, 1 + cnt,
			   "+#+# if this comes backs it's an error");

	  if (trans == NULL)
	    {
	      printf ("catgets return NULL for %zd\n", cnt);
	      result = 1;
	    }
	  else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0')
	    {
	      printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans);
	      result = 1;
	    }
	}

      if (catclose (cd) != 0)
	{
	  printf ("catclose failed: %m\n");
	  result = 1;
	}
    }

  result += do_bz17905 ();
  return result;
}
Example #11
0
char * device_description(struct CuDv *cudv) {
	char *desc= NULL;
	struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */
	nl_catd cat;

	cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE);
	if ((int)cat == -1)
		return NULL;

	desc = strdup(catgets(cat, pddv->setno, pddv->msgno, "N/A") );
	catclose(cat);

	return desc;
}
Example #12
0
/*
 * msgcat_close - close a message catalog
 *   return: NO_ERROR or ER_FAILED
 *   msg_catd(in): message catalog descriptor MSG_CATD
 *
 * Note:
 */
int
msgcat_close (MSG_CATD msg_catd)
{
  nl_catd catd;

  catd = (nl_catd) msg_catd->catd;
  free ((void *) msg_catd->file);
  free (msg_catd);
  if (catclose (catd) < 0)
    {
      return ER_FAILED;
    }

  return NO_ERROR;
}
Example #13
0
int
main(int argc, char **argv)
{	
	int ch;
	const char *t;

#ifdef ENABLE_NLS
	setlocale(LC_ALL, "");
	msgcat = catopen("UXunlink", NL_CAT_LOCALE);
#endif
	if(argv[0])
	{
		if(NULL != (t = strrchr(argv[0], '/')))
		{
			short_program_name = t + 1;
		}
		else
		{
			short_program_name = argv[0];
		}
		argv[0] = (char *) short_program_name;
	}
	while(-1 != (ch = getopt(argc, argv, "")))
	{
		/* No options are permitted */
		usage();
		exit(EXIT_FAILURE);
	}
	if(argc - optind != 1)
	{
		usage();
		exit(EXIT_FAILURE);
	}
	if(unlink(argv[optind]))
	{
		perror(argv[optind]);
		exit(EXIT_FAILURE);
	}
#ifdef ENABLE_NLS
	if(msgcat)
	{
		catclose(msgcat);
	}
#endif
	return 0;
}
Example #14
0
/* ARGSUSED */
const char *
__strsignal(int num, char *buf, size_t buflen)
{
#define	UPREFIX	"Unknown signal: %u"
#define RPREFIX "Real time signal %u"
	unsigned int signum;

#ifdef NLS
	nl_catd catd ;
	catd = catopen("libc", NL_CAT_LOCALE);
#endif

	_DIAGASSERT(buf != NULL);

	signum = num;				/* convert to unsigned */
	if (signum < (unsigned int) sys_nsig) {
#ifdef NLS
		(void)strlcpy(buf, catgets(catd, 2, (int)signum,
		    sys_siglist[signum]), buflen); 
#else
		return((char *)sys_siglist[signum]);
#endif
	} else if (signum >= SIGRTMIN && signum <= SIGRTMAX) {
#ifdef NLS
		(void)snprintf(buf, buflen, 
	            catgets(catd, 2, SIGRTMIN, RPREFIX), signum);
#else
		(void)snprintf(buf, buflen, RPREFIX, signum);
#endif
	} else {
#ifdef NLS
		(void)snprintf(buf, buflen, 
	            catgets(catd, 1, 0xffff, UPREFIX), signum);
#else
		(void)snprintf(buf, buflen, UPREFIX, signum);
#endif
	}

#ifdef NLS
	catclose(catd);
#endif

	return buf;
}
Example #15
0
static int
__num2string(int num, int sign, int setid, char *buf, size_t buflen,
    char * list[], size_t max, const char *def)
{
	int ret = 0;
	size_t len;

#ifdef NLS
	nl_catd catd;
	catd = catopen("libc", NL_CAT_LOCALE);
#endif

	if (0 <= num && num < max) {
#ifdef NLS
		len = strlcpy(buf, catgets(catd, setid, num, list[num]),
		    buflen);
#else
		len = strlcpy(buf, list[num], buflen);
#endif
		if (len >= buflen)
			ret = ERANGE;
	} else {
#ifdef NLS
		len = strlcpy(buf, catgets(catd, setid, 0xffff, def), buflen);
#else
		len = strlcpy(buf, def, buflen);
#endif
		if (len >= buflen)
			ret = ERANGE;
		else {
			ret = __itoa(num, sign, buf, len, buflen);
			if (ret == 0)
				ret = EINVAL;
		}
	}

#ifdef NLS
	catclose(catd);
#endif

	return ret;
}
Example #16
0
const char *
gai_strerror(int ecode)
{
#if defined(NLS)
	nl_catd catd;
	char *buf;

	if (thr_main() != 0)
		buf = gai_buf;
	else {
		if (thr_once(&gai_init_once, gai_keycreate) != 0 ||
		    !gai_keycreated)
			goto thr_err;
		if ((buf = thr_getspecific(gai_key)) == NULL) {
			if ((buf = malloc(sizeof(gai_buf))) == NULL)
				goto thr_err;
			if (thr_setspecific(gai_key, buf) != 0) {
				free(buf);
				goto thr_err;
			}
		}
	}

	catd = catopen("libc", NL_CAT_LOCALE);
	if (ecode > 0 && ecode < EAI_MAX)
		strlcpy(buf, catgets(catd, 3, ecode, ai_errlist[ecode]),
		    sizeof(gai_buf));
	else if (ecode == 0)
		strlcpy(buf, catgets(catd, 3, NL_MSGMAX - 1, "Success"),
		    sizeof(gai_buf));
	else
		strlcpy(buf, catgets(catd, 3, NL_MSGMAX, "Unknown error"),
		    sizeof(gai_buf));
	catclose(catd);
	return buf;

thr_err:
#endif
	if (ecode >= 0 && ecode < EAI_MAX)
		return ai_errlist[ecode];
	return "Unknown error";
}
Example #17
0
int
_strerror_lr(int num, char *buf, size_t buflen, locale_t loc)
{
#define	UPREFIX	"Unknown error: %u"
	unsigned int errnum = num;
	int retval = 0;
	size_t slen;
#ifdef NLS
	int saved_errno = errno;
	nl_catd catd;
	catd = catopen_l("libc", NL_CAT_LOCALE, loc);
#endif
	_DIAGASSERT(buf != NULL);

	if (errnum < (unsigned int) sys_nerr) {
#ifdef NLS
		slen = strlcpy(buf, catgets(catd, 1, (int)errnum,
		    sys_errlist[errnum]), buflen); 
#else
		slen = strlcpy(buf, sys_errlist[errnum], buflen); 
#endif
	} else {
#ifdef NLS
		slen = snprintf_l(buf, buflen, loc,
		    catgets(catd, 1, 0xffff, UPREFIX), errnum);
#else
		slen = snprintf(buf, buflen, UPREFIX, errnum);
#endif
		retval = EINVAL;
	}

	if (slen >= buflen)
		retval = ERANGE;

#ifdef NLS
	catclose(catd);
	errno = saved_errno;
#endif

	return retval;
}
Example #18
0
void
isc_msgcat_close(isc_msgcat_t **msgcatp) {
	isc_msgcat_t *msgcat;

	/*
	 * Close a message catalog.
	 */

	REQUIRE(msgcatp != NULL);
	msgcat = *msgcatp;
	REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);

	if (msgcat != NULL) {
#ifdef HAVE_CATGETS
		if (msgcat->catalog != (nl_catd)(-1))
			(void)catclose(msgcat->catalog);
#endif
		msgcat->magic = 0;
		free(msgcat);
	}

	*msgcatp = NULL;
}
Example #19
0
/*
 * Open the message catalog for the current locale or
 * /usr/lib/locale/C/LC_MESSAGES/SUNWsamfs in the C locale.
 */
static void
samCatopen(void)
{
	(void) setlocale(LC_ALL, LOCALE);
	ourCatFd = catopen(NL_CAT_NAME, NL_CAT_LOCALE);

	/*
	 * catopen() gives us a null catalog in the C locale;
	 * we need the real one.
	 */
#ifdef linux
	if (ourCatFd == (nl_catd)-1) {
		ourCatFd = catopen(DEFCAT NL_CAT_NAME, NL_CAT_LOCALE);
	}
#else
	if ((ourCatFd == (nl_catd)-1) || (ourCatFd->__content == NULL)) {
		catclose(ourCatFd);
		ourCatFd = catopen(DEFCAT NL_CAT_NAME, NL_CAT_LOCALE);
	}
#endif /* linux */

	catfd = ourCatFd;
}
Example #20
0
int
strerror_r(int errnum, char *strerrbuf, size_t buflen)
{
	int retval = 0;
#if defined(NLS)
	int saved_errno = errno;
	nl_catd catd;
	catd = catopen("libc", NL_CAT_LOCALE);
#endif

	if (errnum < 0 || errnum >= __hidden_sys_nerr) {
		errstr(errnum,
#if defined(NLS)
			catgets(catd, 1, 0xffff, UPREFIX),
#else
			UPREFIX,
#endif
			strerrbuf, buflen);
		retval = EINVAL;
	} else {
		if (strlcpy(strerrbuf,
#if defined(NLS)
			catgets(catd, 1, errnum, __hidden_sys_errlist[errnum]),
#else
			__hidden_sys_errlist[errnum],
#endif
			buflen) >= buflen)
		retval = ERANGE;
	}

#if defined(NLS)
	catclose(catd);
	errno = saved_errno;
#endif

	return (retval);
}
int main (void)
{
	nl_catd catalogue;
	char * chaine;

	setlocale(LC_ALL, "");
	if ((catalogue = catopen("msg-catgets", NL_CAT_LOCALE)) == (nl_catd) -1) {
		perror("catopen");
	}
	chaine = catgets(catalogue, premier_Set, premier_chaine_1, 
			"This is the first string in the first set");
	fprintf(stdout, "%s \n", chaine);
	chaine = catgets(catalogue, premier_Set, premier_chaine_2, 
			"and here is the second string in the first set.");
	fprintf(stdout, "%s \n", chaine);
	chaine = catgets(catalogue, second_Set, second_chaine_1, 
			"Now let's have a look at the 1st string in 2nd set,");
	fprintf(stdout, "%s \n", chaine);
	chaine = catgets(catalogue, second_Set, second_chaine_2, 
			"and finaly the second string in the second set.");
	fprintf(stdout, "%s \n", chaine);
	catclose(catalogue);
	return EXIT_SUCCESS;
}
Example #22
0
int
main(int argc, char *argv[])
{
	char **aargv, **eargv, *eopts;
	char *ep;
	const char *pn;
	long long l;
	unsigned int aargc, eargc, i;
	int c, lastc, needpattern, newarg, prevoptind;

	setlocale(LC_ALL, "");

#ifndef WITHOUT_NLS
	catalog = catopen("grep", NL_CAT_LOCALE);
#endif

	/* Check what is the program name of the binary.  In this
	   way we can have all the funcionalities in one binary
	   without the need of scripting and using ugly hacks. */
	pn = getprogname();
	if (pn[0] == 'b' && pn[1] == 'z') {
		filebehave = FILE_BZIP;
		pn += 2;
	} else if (pn[0] == 'x' && pn[1] == 'z') {
		filebehave = FILE_XZ;
		pn += 2;
	} else if (pn[0] == 'l' && pn[1] == 'z') {
		filebehave = FILE_LZMA;
		pn += 2;
	} else if (pn[0] == 'r') {
		dirbehave = DIR_RECURSE;
		Hflag = true;
	} else if (pn[0] == 'z') {
		filebehave = FILE_GZIP;
		pn += 1;
	}
	switch (pn[0]) {
	case 'e':
		grepbehave = GREP_EXTENDED;
		break;
	case 'f':
		grepbehave = GREP_FIXED;
		break;
	}

	lastc = '\0';
	newarg = 1;
	prevoptind = 1;
	needpattern = 1;
	fileeol = '\n';

	eopts = getenv("GREP_OPTIONS");

	/* support for extra arguments in GREP_OPTIONS */
	eargc = 0;
	if (eopts != NULL && eopts[0] != '\0') {
		char *str;

		/* make an estimation of how many extra arguments we have */
		for (unsigned int j = 0; j < strlen(eopts); j++)
			if (eopts[j] == ' ')
				eargc++;

		eargv = (char **)grep_malloc(sizeof(char *) * (eargc + 1));

		eargc = 0;
		/* parse extra arguments */
		while ((str = strsep(&eopts, " ")) != NULL)
			if (str[0] != '\0')
				eargv[eargc++] = grep_strdup(str);

		aargv = (char **)grep_calloc(eargc + argc + 1,
		    sizeof(char *));

		aargv[0] = argv[0];
		for (i = 0; i < eargc; i++)
			aargv[i + 1] = eargv[i];
		for (int j = 1; j < argc; j++, i++)
			aargv[i + 1] = argv[j];

		aargc = eargc + argc;
	} else {
		aargv = argv;
		aargc = argc;
	}

	while (((c = getopt_long(aargc, aargv, optstr, long_options, NULL)) !=
	    -1)) {
		switch (c) {
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			if (newarg || !isdigit(lastc))
				Aflag = 0;
			else if (Aflag > LLONG_MAX / 10 - 1) {
				errno = ERANGE;
				err(2, NULL);
			}

			Aflag = Bflag = (Aflag * 10) + (c - '0');
			break;
		case 'C':
			if (optarg == NULL) {
				Aflag = Bflag = 2;
				break;
			}
			/* FALLTHROUGH */
		case 'A':
			/* FALLTHROUGH */
		case 'B':
			errno = 0;
			l = strtoll(optarg, &ep, 10);
			if (errno == ERANGE || errno == EINVAL)
				err(2, NULL);
			else if (ep[0] != '\0') {
				errno = EINVAL;
				err(2, NULL);
			} else if (l < 0) {
				errno = EINVAL;
				err(2, "context argument must be non-negative");
			}

			if (c == 'A')
				Aflag = l;
			else if (c == 'B')
				Bflag = l;
			else
				Aflag = Bflag = l;
			break;
		case 'a':
			binbehave = BINFILE_TEXT;
			break;
		case 'b':
			bflag = true;
			break;
		case 'c':
			cflag = true;
			break;
		case 'D':
			if (strcasecmp(optarg, "skip") == 0)
				devbehave = DEV_SKIP;
			else if (strcasecmp(optarg, "read") == 0)
				devbehave = DEV_READ;
			else
				errx(2, getstr(3), "--devices");
			break;
		case 'd':
			if (strcasecmp("recurse", optarg) == 0) {
				Hflag = true;
				dirbehave = DIR_RECURSE;
			} else if (strcasecmp("skip", optarg) == 0)
				dirbehave = DIR_SKIP;
			else if (strcasecmp("read", optarg) == 0)
				dirbehave = DIR_READ;
			else
				errx(2, getstr(3), "--directories");
			break;
		case 'E':
			grepbehave = GREP_EXTENDED;
			break;
		case 'e':
			{
				char *token;
				char *string = optarg;

				while ((token = strsep(&string, "\n")) != NULL)
					add_pattern(token, strlen(token));
			}
			needpattern = 0;
			break;
		case 'F':
			grepbehave = GREP_FIXED;
			break;
		case 'f':
			read_patterns(optarg);
			needpattern = 0;
			break;
		case 'G':
			grepbehave = GREP_BASIC;
			break;
		case 'H':
			Hflag = true;
			break;
		case 'h':
			Hflag = false;
			hflag = true;
			break;
		case 'I':
			binbehave = BINFILE_SKIP;
			break;
		case 'i':
		case 'y':
			iflag =  true;
			cflags |= REG_ICASE;
			break;
		case 'J':
#ifdef WITHOUT_BZIP2
			errno = EOPNOTSUPP;
			err(2, "bzip2 support was disabled at compile-time");
#endif
			filebehave = FILE_BZIP;
			break;
		case 'L':
			lflag = false;
			Lflag = true;
			break;
		case 'l':
			Lflag = false;
			lflag = true;
			break;
		case 'm':
			mflag = true;
			errno = 0;
			mlimit = mcount = strtoll(optarg, &ep, 10);
			if (((errno == ERANGE) && (mcount == LLONG_MAX)) ||
			    ((errno == EINVAL) && (mcount == 0)))
				err(2, NULL);
			else if (ep[0] != '\0') {
				errno = EINVAL;
				err(2, NULL);
			}
			break;
		case 'M':
			filebehave = FILE_LZMA;
			break;
		case 'n':
			nflag = true;
			break;
		case 'O':
			linkbehave = LINK_EXPLICIT;
			break;
		case 'o':
			oflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'p':
			linkbehave = LINK_SKIP;
			break;
		case 'q':
			qflag = true;
			break;
		case 'S':
			linkbehave = LINK_READ;
			break;
		case 'R':
		case 'r':
			dirbehave = DIR_RECURSE;
			Hflag = true;
			break;
		case 's':
			sflag = true;
			break;
		case 'U':
			binbehave = BINFILE_BIN;
			break;
		case 'u':
		case MMAP_OPT:
			filebehave = FILE_MMAP;
			break;
		case 'V':
#ifdef WITH_GNU
			printf(getstr(10), getprogname(), VERSION);
#else
			printf(getstr(9), getprogname(), VERSION);
#endif
			exit(0);
		case 'v':
			vflag = true;
			break;
		case 'w':
			wflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'x':
			xflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'X':
			filebehave = FILE_XZ;
			break;
		case 'z':
			fileeol = '\0';
			break;
		case 'Z':
			filebehave = FILE_GZIP;
			break;
		case BIN_OPT:
			if (strcasecmp("binary", optarg) == 0)
				binbehave = BINFILE_BIN;
			else if (strcasecmp("without-match", optarg) == 0)
				binbehave = BINFILE_SKIP;
			else if (strcasecmp("text", optarg) == 0)
				binbehave = BINFILE_TEXT;
			else
				errx(2, getstr(3), "--binary-files");
			break;
		case COLOR_OPT:
			color = NULL;
			if (optarg == NULL || strcasecmp("auto", optarg) == 0 ||
			    strcasecmp("tty", optarg) == 0 ||
			    strcasecmp("if-tty", optarg) == 0) {
				char *term;

				term = getenv("TERM");
				if (isatty(STDOUT_FILENO) && term != NULL &&
				    strcasecmp(term, "dumb") != 0)
					color = init_color("01;31");
			} else if (strcasecmp("always", optarg) == 0 ||
			    strcasecmp("yes", optarg) == 0 ||
			    strcasecmp("force", optarg) == 0) {
				color = init_color("01;31");
			} else if (strcasecmp("never", optarg) != 0 &&
			    strcasecmp("none", optarg) != 0 &&
			    strcasecmp("no", optarg) != 0)
				errx(2, getstr(3), "--color");
			cflags &= ~REG_NOSUB;
			break;
		case LABEL_OPT:
			label = optarg;
			break;
		case LINEBUF_OPT:
			lbflag = true;
			break;
		case NULL_OPT:
			nullflag = true;
			break;
		case R_INCLUDE_OPT:
			finclude = true;
			add_fpattern(optarg, INCL_PAT);
			break;
		case R_EXCLUDE_OPT:
			fexclude = true;
			add_fpattern(optarg, EXCL_PAT);
			break;
		case R_DINCLUDE_OPT:
			dinclude = true;
			add_dpattern(optarg, INCL_PAT);
			break;
		case R_DEXCLUDE_OPT:
			dexclude = true;
			add_dpattern(optarg, EXCL_PAT);
			break;
		case HELP_OPT:
		default:
			usage();
		}
		lastc = c;
		newarg = optind != prevoptind;
		prevoptind = optind;
	}
	aargc -= optind;
	aargv += optind;

	/* Empty pattern file matches nothing */
	if (!needpattern && (patterns == 0))
		exit(1);

	/* Fail if we don't have any pattern */
	if (aargc == 0 && needpattern)
		usage();

	/* Process patterns from command line */
	if (aargc != 0 && needpattern) {
		char *token;
		char *string = *aargv;

		while ((token = strsep(&string, "\n")) != NULL)
			add_pattern(token, strlen(token));
		--aargc;
		++aargv;
	}

	switch (grepbehave) {
	case GREP_BASIC:
		break;
	case GREP_FIXED:
		/*
		 * regex(3) implementations that support fixed-string searches generally
		 * define either REG_NOSPEC or REG_LITERAL. Set the appropriate flag
		 * here. If neither are defined, GREP_FIXED later implies that the
		 * internal literal matcher should be used. Other cflags that have
		 * the same interpretation as REG_NOSPEC and REG_LITERAL should be
		 * similarly added here, and grep.h should be amended to take this into
		 * consideration when defining WITH_INTERNAL_NOSPEC.
		 */
#if defined(REG_NOSPEC)
		cflags |= REG_NOSPEC;
#elif defined(REG_LITERAL)
		cflags |= REG_LITERAL;
#endif
		break;
	case GREP_EXTENDED:
		cflags |= REG_EXTENDED;
		break;
	default:
		/* NOTREACHED */
		usage();
	}

#ifndef WITHOUT_FASTMATCH
	fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern));
#endif
	r_pattern = grep_calloc(patterns, sizeof(*r_pattern));

	/* Don't process any patterns if we have a blank one */
#ifdef WITH_INTERNAL_NOSPEC
	if (!matchall && grepbehave != GREP_FIXED) {
#else
	if (!matchall) {
#endif
		/* Check if cheating is allowed (always is for fgrep). */
		for (i = 0; i < patterns; ++i) {
#ifndef WITHOUT_FASTMATCH
			/*
			 * Attempt compilation with fastmatch regex and
			 * fallback to regex(3) if it fails.
			 */
			if (fastncomp(&fg_pattern[i], pattern[i].pat,
			    pattern[i].len, cflags) == 0)
				continue;
#endif
			c = regcomp(&r_pattern[i], pattern[i].pat, cflags);
			if (c != 0) {
				regerror(c, &r_pattern[i], re_error,
				    RE_ERROR_BUF);
				errx(2, "%s", re_error);
			}
		}
	}

	if (lbflag)
		setlinebuf(stdout);

	if ((aargc == 0 || aargc == 1) && !Hflag)
		hflag = true;

	if (aargc == 0 && dirbehave != DIR_RECURSE)
		exit(!procfile("-"));

	if (dirbehave == DIR_RECURSE)
		c = grep_tree(aargv);
	else
		for (c = 0; aargc--; ++aargv) {
			if ((finclude || fexclude) && !file_matching(*aargv))
				continue;
			c+= procfile(*aargv);
		}

#ifndef WITHOUT_NLS
	catclose(catalog);
#endif

	/* Find out the correct return value according to the
	   results and the command line option. */
	exit(c ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
}
Example #23
0
void _Locale_catclose(struct _Locale_messages *__loc, nl_catd_type __cat )
{
  catclose( __cat );
}
Example #24
0
File: msg.c Project: 2asoft/freebsd
/*
 * msg_close --
 *	Close the message catalogs.
 *
 * PUBLIC: void msg_close(GS *);
 */
void
msg_close(GS *gp)
{
	if (gp->catd != (nl_catd)-1)
		(void)catclose(gp->catd);
}
Example #25
0
char*
translate(const char* loc, const char* cmd, const char* cat, const char* msg)
{
	register char*	r;
	char*		t;
	int		p;
	int		oerrno;
	Catalog_t*	cp;
	Message_t*	mp;

	oerrno = errno;
	r = (char*)msg;

	/*
	 * quick out
	 */

	if (!cmd && !cat)
		goto done;
	if (cmd && (t = strrchr(cmd, '/')))
		cmd = (const char*)(t + 1);

	/*
	 * initialize the catalogs dictionary
	 */

	if (!state.catalogs)
	{
		if (state.error)
			goto done;
		if (!(state.tmp = sfstropen()))
		{
			state.error = 1;
			goto done;
		}
		if (!(state.catalogs = dtopen(&state.catalog_disc, Dtset)))
		{
			sfclose(state.tmp);
			state.error = 1;
			goto done;
		}
		if (streq(loc, "debug"))
			state.debug = loc;
	}

	/*
	 * get the message
	 * or do we have to spell it out for you
	 */

	if ((!cmd || !(mp = match(cmd, msg))) &&
	    (!cat || !(mp = match(cat, msg))) &&
	    (!error_info.catalog || !(mp = match(error_info.catalog, msg))) &&
	    (!ast.id || !(mp = match(ast.id, msg))) ||
	     !(cp = mp->cat))
	{
#if DEBUG_trace > 1
sfprintf(sfstderr, "AHA#%d:%s cmd %s cat %s:%s id %s msg `%s'\n", __LINE__, __FILE__, cmd, cat, error_info.catalog, ast.id, msg);
#endif
		goto done;
	}

	/*
	 * adjust for the current locale
	 */

#if DEBUG_trace
sfprintf(sfstderr, "AHA#%d:%s cp->locale `%s' %p loc `%s' %p\n", __LINE__, __FILE__, cp->locale, cp->locale, loc, loc);
#endif
	if (cp->locale != loc)
	{
		cp->locale = loc;
		if (cp->cat != NOCAT)
			catclose(cp->cat);
		if ((cp->cat = find(cp->locale, cp->name)) == NOCAT)
			cp->debug = streq(cp->locale, "debug");
		else
			cp->debug = 0;
#if DEBUG_trace
sfprintf(sfstderr, "AHA#%d:%s cp->cat %p cp->debug %d NOCAT %p\n", __LINE__, __FILE__, cp->cat, cp->debug, NOCAT);
#endif
	}
	if (cp->cat == NOCAT)
	{
		if (cp->debug)
		{
			p = tempget(state.tmp);
			sfprintf(state.tmp, "(%s,%d,%d)", cp->name, mp->set, mp->seq);
			r = tempuse(state.tmp, p);
		}
		else if (ast.locale.set & AST_LC_debug)
		{
			p = tempget(state.tmp);
			sfprintf(state.tmp, "(%s,%d,%d)%s", cp->name, mp->set, mp->seq, r);
			r = tempuse(state.tmp, p);
		}
		goto done;
	}

	/*
	 * get the translated message
	 */

	r = catgets(cp->cat, mp->set, mp->seq, msg);
	if (ast.locale.set & AST_LC_translate)
		sfprintf(sfstderr, "translate locale=%s catalog=%s set=%d seq=%d \"%s\" => \"%s\"\n", cp->locale, cp->name, mp->set, mp->seq, msg, r == (char*)msg ? "NOPE" : r);
	if (r != (char*)msg)
	{
		if (streq(r, (char*)msg))
			r = (char*)msg;
		else if (strcmp(fmtfmt(r), fmtfmt(msg)))
		{
			sfprintf(sfstderr, "locale %s catalog %s message %d.%d \"%s\" does not match \"%s\"\n", cp->locale, cp->name, mp->set, mp->seq, r, msg);
			r = (char*)msg;
		}
	}
	if (ast.locale.set & AST_LC_debug)
	{
		p = tempget(state.tmp);
		sfprintf(state.tmp, "(%s,%d,%d)%s", cp->name, mp->set, mp->seq, r);
		r = tempuse(state.tmp, p);
	}
 done:
	if (r == (char*)msg && loc == state.debug)
	{
		p = tempget(state.tmp);
		sfprintf(state.tmp, "(%s,%s,%s,\"%s\")", loc, cmd, cat, r);
		r = tempuse(state.tmp, p);
	}
	errno = oerrno;
	return r;
}
Example #26
0
/**
 * Retrieve the message text for a give error code.
 *
 * @param code   The Rexx error code
 *
 * @return The error message associated with that code.
 */
RexxString *SystemInterpreter::getMessageText(wholenumber_t code )
{
#if defined( HAVE_NL_TYPES_H )
    nl_catd        catd;                  /* catalog descriptor from catopen() */
#endif
    int            set_num = 1;           /* message set 1 from catalog        */
    ERROR_MESSAGE *p;                     /* message table scan pointer        */
    int            msgid;                 /* message number                    */
    char           DataArea[256];         /* buf to return message             */
    const char *   message;
    /* loop through looking for the      */
    /* error code                        */
#if defined( HAVE_CATOPEN )
    for (p = Message_table; p->code != 0; p++)
    {
        if (p->code == code)
        {              /* found the target code?            */

            msgid = p->msgid;                 /* get msg number associated w/ error*/
                                              /* open message catalog in NLSPATH   */
            if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
            {
                sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
                if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
                {
                    sprintf(DataArea, "Cannot open REXX message catalog %s.  Not in NLSPATH or %s.",
                            REXXMESSAGEFILE, ORX_CATDIR);
                    return new_string(DataArea);
                }
            }                                   /* retrieve message from repository  */
            message = catgets(catd, set_num, msgid, NULL);
            if (!message)                    /* got a message ?                   */
            {
#if defined(OPSYS_LINUX) && !defined(OPSYS_SUN)
                sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE);
                if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR)
                {
                    sprintf(DataArea, "Cannot open REXX message catalog %s.  Not in NLSPATH or %s.",
                            REXXMESSAGEFILE, ORX_CATDIR);
                    return new_string(DataArea);
                }
                else
                {
                    message = catgets(catd, set_num, msgid, NULL);
                    if (!message)                    /* got a message ?                   */
                    {
                        strcpy(DataArea,"Error message not found!");
                    }
                    else
                    {
                        strcpy(DataArea, message);
                    }
                }
#else
                strcpy(DataArea,"Error message not found!");
#endif
            }
            else
            {
                strcpy(DataArea, message);
            }
            catclose(catd);                 /* close the catalog                 */
                                            /* convert and return the message    */
            return new_string(DataArea);
        }
    }
    return OREF_NULL;                     /* no message retrieved              */
#else
    sprintf(DataArea,"Cannot get description for error %d",msgid);
    return new_string(&DataArea);
#endif
}
Example #27
0
int
main (int argc, char **argv)
{
  int dat_count;                    /* size of the dat array */
  int i;
  int mono = 0;                     /* running on monochrome monitor */

  dat_t *dat_ary;                   /* the dat file array */
  inst_t ret;                       /* no. of errors, warnings */

  struct text_info ti;              /* (borland) for gettextinfo */
 

  /* Open the language catalog */
  cat = catopen ("install", 0);

  /* Check command line */

  for (i = 1; i < argc; i++)
  {
    if (strcmpi(argv[i], "/mono") == 0)
      mono = 1;
    else if (strcmpi(argv[i], "/nopause") == 0)
      nopauseflag = 1;
    else if (strcmpi(argv[i], "/nolog") == 0)
      wantlog = 0;
    else if ( (strcmpi(argv[i], "/src") == 0) && (i+1 < argc))
    {
      fromdirflag = 1;
      i++;
      strcpy(fromdir+2, argv[i]);
    }
    else if ( (strcmpi(argv[i], "/dst") == 0) && (i+1 < argc))
    {
      destdirflag = 1;
      i++;
      strcpy(destdir+2, argv[i]);
    }
    else
    {
      fprintf (stderr, catgets (cat, SET_USAGE, MSG_USAGE, MSG_USAGE_STR));
      exit (1);
    }
  }

  /* unzip overwrites screen with warning if TZ not set, so check    */
  /* and if not set, then set for us to GMT0, which means no offsets */
  if (getenv("TZ") == NULL) putenv("TZ=GMT0");


  /* Read dat file */

  dat_ary = dat_read ("INSTALL.DAT", &dat_count);
  if (dat_ary == NULL)
  {
    if (dat_count > 0)
    {
      fprintf (stderr, catgets (cat, SET_ERRORS, MSG_ERRALLOCMEMDF, MSG_ERRALLOCMEMDF_STR));
      exit (2);
    }
    else /* Either error reading file, eg no file, or file has no entries */
    {
      fprintf (stderr, catgets (cat, SET_ERRORS, MSG_ERREMPTYDATAFILE, MSG_ERREMPTYDATAFILE_STR));
      exit (3);
    }
  }

  /* Get localized "Yes" and "No" strings */
  getLocalizedYesNo();

  /* register our SIGINT handler (Ctrl-C) */
  registerSIGINTHandler();

  /* Start the install */

  /* save current setting so we can restore them */
  gettextinfo (&ti);

  /* setup screen colors then draw the screen */
  if (mono)
  {
    textbackground (BLACK);
    textcolor (LIGHTGRAY);
  }
  else
  {
    textbackground (BLUE);
    textcolor (WHITE);
  }

  repaint_empty();
  gotoxy (2, 3);
  cat_file ("COPYR", 18);
  pause();

  repaint_empty();
  gotoxy (2, 3);
  cat_file ("OEM", 18);
  pause();

  ret.errors = 0;
  ret.warnings = 0;

  ret = install_top (dat_ary, dat_count);

  /* Finished with install */

  textattr (ti.attribute); /* restore user's screen */
  clrscr();

  if ((ret.errors == 0) && (ret.warnings == 0))
      printf (catgets (cat, SET_GENERAL, MSG_INSTALLOK, MSG_INSTALLOK_STR));
  else
      printf (catgets (cat, SET_GENERAL, MSG_INSTALLERRORS, MSG_INSTALLERRORS_STR), ret.errors, ret.warnings);

  /* Done */

  free (dat_ary);
  free (yes);
  free (no);
  catclose (cat);

  /* restore original SIGINT handler */
  unregisterSIGINTHandler();

  return (0);
}
Example #28
0
MsgCatalogLoader::~MsgCatalogLoader()
{
    catclose(fCatalogHandle);	
}
Example #29
0
/* XXX: negative 'num' ? (REGR) */
char *
strsignal(int num)
{
	static char ebuf[NL_TEXTMAX];
	char tmp[20];
	size_t n;
	int signum;
	char *t, *p;

#if defined(NLS)
	int saved_errno = errno;
	nl_catd catd;
	catd = catopen("libc", NL_CAT_LOCALE);
#endif

	if (num > 0 && num < sys_nsig) {
		n = strlcpy(ebuf,
#if defined(NLS)
			catgets(catd, 2, num, sys_siglist[num]),
#else
			sys_siglist[num],
#endif
			sizeof(ebuf));
	} else {
		n = strlcpy(ebuf,
#if defined(NLS)
			catgets(catd, 2, 0xffff, UPREFIX),
#else
			UPREFIX,
#endif
			sizeof(ebuf));
	}

	signum = num;
	if (num < 0)
		signum = -signum;

	t = tmp;
	do {
		*t++ = "0123456789"[signum % 10];
	} while (signum /= 10);
	if (num < 0)
		*t++ = '-';

	p = (ebuf + n);
	*p++ = ':';
	*p++ = ' ';

	for (;;) {
		*p++ = *--t;
		if (t <= tmp)
			break;
	}
	*p = '\0';

#if defined(NLS)
	catclose(catd);
	errno = saved_errno;
#endif
	return (ebuf);
}
Example #30
0
void _Locale_catclose(struct _Locale_messages*l, nl_catd_type catalog) {
  catclose((nl_catd)catalog);
}