
/* 
 * $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: string.c 1.1 90/01/19 $@(#)string.c	1.1 89/12/01"
#include "xs.h"
#include "names.h"
#include "stack.h"
#include "types.h"
#include "anal.h"
#include "xdefs.h"
#include "catalog.h"

static int str_nr;

reset_string()
{
  str_nr = 0;
}

/*
 * Replace a string by a function call (for assignment)
 * 'complete' specifies whether the len address param can be defaulted
 * to (char *)0 or this will be done later (body.c)
 */
void
do_string(string, complete)
  TOKEN string;
  bool complete;
{
  if (complete)
    act_e_insert(string.t_off, " %s(%s, %d, 0, (char *)0, (int *)0, ", replace_strings,
                 var_set_nr, ++str_nr);
  else
    act_e_insert(string.t_off, " %s(%s, %d, 0, (char *)0, ", replace_strings,
                 var_set_nr, ++str_nr);
  act_e_append(string.t_off + string.t_len - 1, ")");
  msg_string(fd_msg, str_nr, string.t_name);
}

/*
 * Give a number to a string and output it to the msg_file
 */
string_size(string, len)
  TOKEN string;
  int len;
{
  msg_fixed(fd_msg, ++str_nr, string.t_name, len);
  return str_nr;
}

/*
 * replace a string in a statement by a function call.
 * Always complete
 */
void
stmt_string(string)
  TOKEN string;
{
  (void)do_string(string, TRUE);
}

/*
 * Generate a function call to init a sized array
 */
void
size_string(off, re)
  long off;
  TYPEP re;
{
  act_e_append(off, "(void)%s(%s, %d, %d, %s, (int *)0,", replace_strings,
  	       var_set_nr, re_nr(re), re_alen(re), re_na(re));
  act_i_append(off, re_off(re), re_len(re));
  act_e_append(off, ");\n");
}
