Exemplo n.º 1
0
/*
 * ----------------------------------------------------------------------
 * print_audit_common() - common routine for print_audit* functions.
 *
 *		   Parses the binary audit data, and formats as requested.
 *		   The context parameter defines whether the source of the
 *		   audit data is a buffer, or a file mapped to stdin, and
 *		   whether the output is to a buffer or a file mapped to
 *		   stdout.
 *
 *	inputs:
 *		   context -	defines the context of the request, including
 *				info about the source and output.
 *		   flags -	formatting flags as defined in praudit.h
 *		   separator -	field delimiter (or NULL if the default
 *				delimiter of comma is to be used).
 *
 * return codes:   -1 - error
 *		    0 - successful
 * ----------------------------------------------------------------------
 */
static int
print_audit_common(pr_context_t *context, const int flags,
    const char *separator)
{
	int	retstat = 0;

	if (!initdone) {
		init_tokens();
		initdone++;
	}

	context->format = flags;

	/* start with default delimiter of comma */
	(void) strlcpy(context->SEPARATOR, ",", SEP_SIZE);
	if (separator != NULL) {
		if (strlen(separator) < SEP_SIZE) {
			(void) strlcpy(context->SEPARATOR, separator, SEP_SIZE);
		}
	}

	while ((retstat == 0) && pr_input_remaining(context, 1)) {
		if (pr_adr_char(context, (char *)&(context->tokenid), 1) == 0) {
			retstat = token_processing(context);
		} else
			break;
	}

	/*
	 * For buffer processing, if the entire input buffer was processed
	 * successfully, but the last record in the buffer was incomplete
	 * (according to the length from its header), then reflect an
	 * "incomplete input" error (which will cause partial results to be
	 * returned).
	 */
	if ((context->data_mode == BUFMODE) && (retstat == 0) &&
	    (context->audit_adr->adr_now < (context->audit_rec_start +
	    context->audit_rec_len))) {
		retstat = -1;
		errno = EIO;
	}

	/*
	 * If there was a last record that didn't get officially closed
	 * off, do it now.
	 */
	if ((retstat == 0) && (context->format & PRF_XMLM) &&
	    (context->current_rec)) {
		retstat = do_newline(context, 1);
		if (retstat == 0)
			retstat = close_tag(context, context->current_rec);
	}

	return (retstat);
}
Exemplo n.º 2
0
static void newline(void)
{
    /*
     * Flush all pending stuff before doing the newline.
     */
    if (!using_primary_buf()) {
	merge_buffers();
    }
    do_newline(current_buf, "\n");
    eat_whitespace();
}
Exemplo n.º 3
0
/* Force newline after tag. Use lexer to get current character.  */
static void force_newline_after_tag(struct buffer * buffer)
{
    int current = input();

    do_unput(current);

    if (!is_newline(current)) {
        do_newline(buffer, "\n");
        eat_whitespace();
    }
}
Exemplo n.º 4
0
/* Force newline for wrapping line. Use lexer to get current character and
   do not eat whitespace from next line.  */
static void force_newline_for_wrap(struct buffer * buffer)
{
    int current = input();

    /*
     * Flush all pending stuff before doing the newline.
     */
    if (!using_primary_buf()) {
	merge_buffers();
    }
    do_newline(current_buf, "\n");

    if (!is_newline(current))
	do_unput(current);
}
Exemplo n.º 5
0
/* Force newline before tag. Use buffer for getting current character.  */
static void force_newline_before_tag(struct buffer * buffer)
{
    int current;

    if (buffer_size(buffer) == 0) {
	/*
	 * We just did a newline, no need to force it.
	 */
	return;
    }

    current = buffer_pop_char(buffer);
    buffer_push_char(buffer, current);

    if (!is_newline(current)) {
	do_newline(buffer, "\n");
	eat_whitespace();
    }
}
Exemplo n.º 6
0
/* Note: if len is < 0, entire string will be used.
 */
int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len)
{
   unsigned int nrows, ncols, crow, ccol;
   SLuchar_Type *u, *umax;
   int is_acs = 0;

   if ((w == NULL)
       || (str == NULL))
     return -1;

   w->modified = 1;
   nrows = w->nrows;
   ncols = w->ncols;
   crow = w->_cury;
   ccol = w->_curx;

   if (w->scroll_max <= nrows)
     nrows = w->scroll_max;

   if (crow >= nrows)
     crow = 0;			       /* wrap back to top */

   u = (SLuchar_Type *)str;
   umax = &u[len >= 0 ? (unsigned int)len : strlen(str)];
   while (u < umax)
     {
	SLwchar_Type ch;
	unsigned int nconsumed;
	int width = 1;

	if (SLsmg_is_utf8_mode () && SLutf8_decode (u, umax, &ch, &nconsumed))
	  {
	     u += nconsumed;
	     if ((ch & A_CHARTEXT) != ch)
	       {
		  ch = (SLwchar_Type)0xFFFDL;	/* Unicode replacement character */
		  width = 1;
	       }
	     else if (SLwchar_isprint (ch))
	       width = SLwchar_wcwidth (ch);
	     else
	       width = 0;	/* FIXME: cope with <%02X> printstrings. */
	  }
	else
	  {
	     ch = (SLwchar_Type)*u++;
	     if (ch < 0x20 || (ch >= 0x7f && ch < 0xa0))
	       width = 0;	/* FIXME: use display_8bit */
	  }
	if (ch == '\t')
	  width = 1;	/* HACK forcing linewrap if ccol==ncols */
	if (ch == 0)
	  continue;	/* Avoid adding a literal SLCURSES_NULLCHAR. */

	/* FIXME; should this function be defined in terms of waddch? */
	if (ch == '\n')
	  {
	     w->_cury = crow;
	     w->_curx = ccol;
	     SLcurses_wclrtoeol (w);
	     do_newline (w);
	     crow = w->_cury;
	     ccol = w->_curx;
	     continue;
	  }

	if (ccol + width > ncols)
	  {
	     w->_curx = ccol;
	     w->_cury = crow;
	     SLcurses_wclrtoeol(w);	/* no-op if width<=1 */
	     w->_curx = ccol = 0;
	     w->_cury = ++crow;
	     if (crow >= nrows)
	       {
		  do_newline (w);
		  crow = w->_cury;
		  ccol = w->_curx;
	       }
	  }

	if (ch == '\t')
	  {
	     /* assert (ccol < ncols); */
	     w->_curx = ccol;
	     w->_cury = crow;
	     do
	       {
		  SLcurses_placechar (w, (SLwchar_Type)' ', 1, w->color, is_acs);
		  w->_curx = ++ccol;
	       }
	     while (ccol < ncols && ccol % SLsmg_Tab_Width != 0);
	     continue;
	  }

	SLcurses_placechar (w, ch, width, w->color, is_acs);
	w->_curx = (ccol += width);
     }

   w->_curx = ccol;
   w->_cury = crow;

   return 0;
}
Exemplo n.º 7
0
int SLcurses_waddch (SLcurses_Window_Type *win, SLtt_Char_Type attr)
{
   SLtt_Char_Type ch;
   SLsmg_Color_Type color;
   int width;
   int is_acs;

   if (win == NULL) return -1;

   if (win->_cury >= win->nrows)
     {
	/* Curses seems to move current position to top of window. */
	win->_cury = win->_curx = 0;
	return -1;
     }

   win->modified = 1;

   ch = SLTT_EXTRACT_CHAR(attr);
   if (ch == 0) return -1;

   if (attr == ch)
     color = win->color;
   else
     {
	/* hack to pick up the default color for graphics chars */
	if (((attr & A_COLOR) == 0) && ((attr & A_ALTCHARSET) != 0))
	  {
	     SLCURSES_BUILD_CHAR(attr, attr, win->color);
	  }
	color = map_attr_to_object (attr);
     }

   is_acs = attr & A_ALTCHARSET;

   if (SLwchar_iscntrl((SLwchar_Type)ch))
     {
	if (ch == '\n')
	  {
	     SLcurses_wclrtoeol (win);
	     return do_newline (win);
	  }

	if (ch == '\r')
	  {
	     win->_curx = 0;
	     return 0;
	  }

	if (ch == '\b')
	  {
	     if (win->_curx > 0)
	       win->_curx--;

	     return 0;
	  }

	if (ch == '\t')
	  {
	     int err;
	     do
	       err = SLcurses_waddch (win, (SLtt_Char_Type)' ');
	     while (err == 0 && win->_curx % SLsmg_Tab_Width != 0);
	     return err;
	  }
     }

   width = SLwchar_isprint (ch)
	? (SLsmg_is_utf8_mode ()
		? SLwchar_wcwidth (ch)
		: 1)
	: 0;
   if (win->_curx + width > win->ncols)
     {
	SLcurses_wclrtoeol (win);
	do_newline (win);
     }

   SLcurses_placechar (win, ch, width, color, is_acs);
   win->_curx += width;

   return 0;
}
Exemplo n.º 8
0
/************************************************************************
 * NEWINPUT - A new input file is to be opened, saving the old.
 *
 * ARGUMENTS
 *	char *newname - the name of the file
 *
 * RETURNS  - none
 *
 * SIDE EFFECTS  
 *	- causes input stream to be switched
 *	- Linenumber is reset to 1
 *	- storage is allocated for the newname
 *	- Filename is set to the new name
 *
 * DESCRIPTION  
 *	The file is opened, and if successful, the current input stream is saved
 *	and the stream is switched to the new file. If the newname is NULL,
 *	then stdin is taken as the new input.
 *
 * AUTHOR - Ralph Ryan, Sept. 9, 1982
 *
 * MODIFICATIONS - none
 *
 ************************************************************************/
int newinput (char *newname, int m_open)
{
    filelist_t *pF;
    TEXT_TYPE	p;
    WCHAR	*pwch;

    if( newname == NULL ) {
	Fp = stdin;
    }
    else if((Fp = fopen(newname, "rb")) == NULL)
    {
	if(m_open == MUST_OPEN) {
	    Msg_Temp = GET_MSG (1013);
	    SET_MSG (Msg_Text, Msg_Temp, newname);
	    fatal(1013);
	}
	return(FALSE);
    }

    /* now push it onto the file stack */
    ++Findex;
    if(Findex >= LIMIT_NESTED_INCLUDES) {
	Msg_Temp = GET_MSG (1014);
	SET_MSG (Msg_Text, Msg_Temp);
	fatal(1014);
    }
    pF = &Fstack[Findex];
    if(Findex == 0) {
	p = &InputBuffer[(IO_BLOCK * 0) + PUSHBACK_BYTES];
	pwch = &wchInputBuffer[(IO_BLOCK * 0) + PUSHBACK_BYTES];
	pF->fl_bufsiz = SIX_K;
    }
    else {
	filelist_t	*pPrevF;

	pPrevF = pF - 1;
	if(Findex == 1) {			/* first level include */
	    p = &InputBuffer[(IO_BLOCK * 1) + PUSHBACK_BYTES];
	    pwch = &wchInputBuffer[(IO_BLOCK * 1) + PUSHBACK_BYTES];
	    pF->fl_bufsiz = FOUR_K;
	}
	else {		/* (Findex > 1) */
	    /* nested includes . . . */
	    p = &InputBuffer[(IO_BLOCK * 2) + PUSHBACK_BYTES];
	    pwch = &wchInputBuffer[(IO_BLOCK * 2) + PUSHBACK_BYTES];
	    pF->fl_bufsiz = TWO_K;
	}
	if((pPrevF->fl_numread > TWO_K) || (Findex > 2)) {
	    /*
		**  the parent file has read something into the upper section
		**  or this is a nested include at least 3 deep.
		**  the child will overwrite some parent info. we must take this
		**  into account for the parent to reread when the time comes.
		**  we also must stick in the eos char into the parents buffer.
		**  (this latter is the useless thing in deeply nested
		**  includes since we overwrite the thing we just put in. we'll
		**  handle this later when we fpop the child.)
		*/
	    TEXT_TYPE	pCurrC;
	    long		seek_posn;

	    seek_posn = pPrevF->fl_totalread;
	    if( Macro_depth != 0 ) {
		/*
		**  in a macro, the 'current char' we want is kept as the
		**  first thing in the macro structure.
		*/
		pCurrC = (TEXT_TYPE)Macro_expansion[1].exp_string;
	    }
	    else {
		pCurrC = (TEXT_TYPE)Current_char;
	    }
	    if(pCurrC >= p) {
		/*
		**  p is the start of the child section.
		**  current char is past it. ie, we've already read some
		**  from the upper section.
		**  current char - p = # of characters used in upper section.
		**  numread = 0 implies there are no chars left from the parent.
		**  since, this is really the 'end' of the parent's buffer,
		**  we'll have to update the info so that the next read from the
		**  parent (after the child is finished) will be the terminator
		**  and we want the io_eob handler to refill the buffer.
		**  we reset the parent's cur char ptr to the beginning of its
		**  buffer, and put the terminator there.
		*/
		seek_posn += (pCurrC - pPrevF->fl_buffer);
		pPrevF->fl_totalread += (pCurrC - pPrevF->fl_buffer);
		pPrevF->fl_numread = 0;
		if( Macro_depth != 0 ) {
		    Macro_expansion[1].exp_string = pPrevF->fl_buffer;
		}
		else {
		    Current_char = pPrevF->fl_buffer;
		}
		*(pPrevF->fl_buffer) = EOS_CHAR;
		*(pPrevF->fl_pwchBuffer) = EOS_CHAR;
	    }
	    else {
		/*
		**  the upper section has not been read from yet,
		**  but it has been read into.
		**  'p' is pointing to the start of the child's buffer.
		**  we add the terminator to the new end of the parent's buffer.
		*/
		seek_posn += TWO_K;
		pPrevF->fl_numread = TWO_K;
		*(pPrevF->fl_buffer + TWO_K) = EOS_CHAR;
		*(pPrevF->fl_pwchBuffer + TWO_K) = EOS_CHAR;
	    }

	    if (pPrevF->fl_fFileType == DFT_FILE_IS_8_BIT) {
		fseek(pPrevF->fl_file, seek_posn, SEEK_SET);
	    
	    } else {

		fseek(pPrevF->fl_file, seek_posn * sizeof (WCHAR), SEEK_SET);
	    }
	}
    }
    pF->fl_currc = Current_char;/*  previous file's current char */
    pF->fl_lineno = Linenumber;	/*  previous file's line number  */
    pF->fl_file = Fp;			/*  the new file descriptor  */
    pF->fl_buffer = p;
    pF->fl_pwchBuffer = pwch;
    pF->fl_numread = 0;
    pF->fl_totalread = 0;

    //- Added to support 16-bit files.
    //- 8-2-91 David Marsyla.
    pF->fl_fFileType = DetermineFileType (Fp);

    //- The file type is unknown, warn them and then take a stab at an
    //- 8-bit file.  8-2-91 David Marsyla.
    if (pF->fl_fFileType == DFT_FILE_IS_UNKNOWN) {
	Msg_Temp = GET_MSG (4413);
	SET_MSG (Msg_Text, Msg_Temp, newname);
	warning (4413);
	pF->fl_fFileType = DFT_FILE_IS_8_BIT;
    }

    vfCurrFileType = pF->fl_fFileType;

    Current_char = (ptext_t)p;
    io_eob();					/*  fill the buffer  */
    /*
	* Note that include filenames will live the entire compiland. This
	* puts the burden on the user with MANY include files.  Any other
	* scheme takes space out of static data.
	* Notice also, that we save the previous filename in the new file's
	* fl_name.
	*/
    pF->fl_name = pstrdup(Filename);
    strncpy(Filebuff,newname,sizeof(Filebuff));
    Linenumber = 0;	/*  do_newline() will increment to the first line */
    if(Eflag) {
	emit_line();
	fwrite("\n", 1, 1, OUTPUTFILE);		/* this line is inserted */
    }
    do_newline();	/*  a new file may have preproc cmd as first line  */
    return(TRUE);
}