/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: xstr.c 1.2 90/01/09 $@(#)xstr.c	1.1 :/src/ctix/lib/libintl/s.xstr.c 9/7/89 13:27:32"

#include <stdio.h>
#include <nl_types.h>

/*
 * Function called to get a string at run time according to its msg_number.
 * extern var cmd_name contains the command name which is initialized 
 * at program start
 */

static nl_catd catd;

char *
strings_replace(set_num, msg_num, msg_len, msg_buf, addr_len, default_message)
  int set_num, msg_num, msg_len;
  char *default_message, *msg_buf;
  int *addr_len;
{
  if (msg_len == 0){
    char *ptr;
    ptr =  catgets(catd, set_num, msg_num, default_message);
    if (*ptr == '\0')
      ptr = default_message;
    if (addr_len != 0)
      *addr_len = strlen(ptr) + 1;
    return ptr;
  } else {
    if (*catgetmsg(catd, set_num, msg_num, msg_buf, msg_len) == '\0')
      memcpy(msg_buf, default_message, msg_len);
    return 0;
  }
}

/*
 * Initial function. Called at program start.
 * _string_init is generated by the string extractor to replace initial
 * strings values.
 * mode parameter to catopen is 1 to force use of sbrk instead of malloc
 */
void strings_init(name)
  char *name;
{
  char *s;

  for(s = name ; *s != '\0' ; )
	if( *s++ == '/' )
		name = s;
  catd = catopen(name, 1);
  (void) _string_init();
}
