Пример #1
0
/*---------------------------------------------------------------------------
 * Description: Indent to at least the specified column.
 *
 * Programmer:  Robb Matzke
 *              Tuesday, June 27, 2000
 *
 * Modifications:
 *---------------------------------------------------------------------------
 */
void
out_column(out_t *f, int column, const char *separator)
{
    int oldlit = out_literal(f, true);
    
    while (f->col<column && !out_brokenpipe(f)) out_puts(f, " ");
    out_puts(f, separator);
    out_literal(f, oldlit);
}
Пример #2
0
/*-------------------------------------------------------------------------
 * Function:    ptr_print
 *
 * Purpose:     Prints a pointer type.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec  6 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
ptr_print (obj_t _self, out_t *f) {

   obj_ptr_t    *self = MYCLASS(_self);

   out_puts (f, "*");
   obj_print (self->sub, f);
}
Пример #3
0
void out_action
(
    char const * const action,
    char const * const target,
    char const * const command,
    char const * const out_d,
    char const * const err_d,
    int const exit_reason
)
{
    /* Print out the action + target line, if the action is quiet the action
     * should be null.
     */
    if ( action )
        out_printf( "%s %s\n", action, target );

    /* Print out the command executed if given -d+2. */
    if ( DEBUG_EXEC )
    {
        out_puts( command );
        out_putc( '\n' );
    }

    /* If the process expired, make user aware with an explicit message, but do
     * this only for non-quiet actions.
     */
    if ( exit_reason == EXIT_TIMEOUT && action )
        out_printf( "%ld second time limit exceeded\n", globs.timeout );

    /* Print out the command output, if requested, or if the program failed, but
     * only output for non-quiet actions.
     */
    if ( action || exit_reason != EXIT_OK )
    {
        if ( out_d &&
           ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) ||
             ( globs.pipe_action == 0 ) ) )
            out_data( out_d );
        if ( err_d && ( globs.pipe_action & 2 /* STDERR_FILENO */ ) )
            err_data( err_d );
    }

    out_flush();
    err_flush();
}
Пример #4
0
/*-------------------------------------------------------------------------
 * Function:    out_printf
 *
 * Purpose:     Formatted output.  The entire output is printed on the
 *              current line if it fits.  Otherwise the entire output is
 *              printed on the next line.  Linefeeds within the output
 *              string force line breaks.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec 11 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
void
out_printf (out_t *f, const char *fmt, ...) {

   va_list      ap;
   char         buf[4096], *s, *nextline;

   va_start (ap, fmt);
   vsprintf (buf, fmt, ap);
   va_end (ap);

   for (s=buf; s; s=nextline) {
      nextline = strchr (s, '\n');
      if (nextline) *nextline = '\0';
      out_puts (f, s);
      if (nextline) {
         *nextline++ = '\n';
         out_nl (f);
      }
   }
}
Пример #5
0
/*-------------------------------------------------------------------------
 * Function:    out_putw
 *
 * Purpose:     Similar to out_puts() except the string can be split on
 *              white space.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec 11 1996
 *
 * Modifications:
 *
 *      Robb Matzke, 3 Apr 1997
 *      Words can be split on `/', `-', or `_', and those characters appear
 *      at the end of the previous line.
 *
 *      Robb Matzke, 2000-06-02
 *      Only the first line of output gets the prefix.
 *-------------------------------------------------------------------------
 */
void
out_putw (out_t *f, const char *s) {

    const char  *t;
    char        buf[1024];
    int         nl, i;
    int         old_nfields = f->nfields;

    while (s && *s) {
        if (out_brokenpipe(f)) return;

        /* Find the edges of the next word. */
        for (t=s, nl=0; *t && strchr (" \t\n_-/", *t); t++) {
            if ('\n'==*t) nl++; /*skip leading seps, remember newlines*/
        }
        t = strpbrk (t, " \t\n_-/"); /*find next word separator*/
        while (t && *t && strchr("_-/",*t)) t++; /*these stay on current line*/
        if (!t) t = s+strlen(s);

        /* Extract the word. */
        strncpy (buf, s, t-s);
        buf[t-s] = '\0';

        /* Print empty lines */
        for (i=0; i<nl; i++) {
            out_nl(f);
            f->nfields=0;
        }

        /* Output the word including leading white space.  The out_puts()
         * function will strip leading whitespace at the beginning of
         * a line. */
        out_puts (f, buf);
        s = t;

        /* Turn off prefix for subsequent lines */
        f->nfields=0;
    }
    f->nfields = old_nfields; /*restore prefix*/
}
Пример #6
0
/*-------------------------------------------------------------------------
 * Function:    str_doprnt
 *
 * Purpose:     Prints a string with non-printable characters.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Jan 31 1997
 *
 * Modifications:
 *              Robb Matzke, 2000-10-19
 *              Understands formats of `b16', `b8', and `b2'.
 *
 *              Mark C. Miller, 03Jun08
 *              Made it properly handle strings longer than size of buf.
 *              Made it properly use truncate variable to control behavior.
 *
 *    Mark C. Miller, Wed Jan 14 10:13:50 PST 2009
 *    Eliminated extraneous blank line being output from browser as well
 *    as line breaking occuring on arrays of strings by removing out_nl
 *    call and using out_puts for string output and out_printf otherwise.
 *-------------------------------------------------------------------------
 */
void
str_doprnt (out_t *f, char *fmt, char *s)
{
    char        buf[1024], c;
    int         at, i, j, n, maxn;
    unsigned    mask;

    if (!s) {
        out_puts(f, "(null)");
        return;
    }

    i = 0;
    n = strlen(s);
    maxn = sym_bi_true("truncate");
    if (maxn <= 1) maxn = n;
    while (i < n && i < maxn)
    {
       buf[0] = '\0';
       for (at=0; i < n && i < maxn && s[i]; i++) {
           if (at+2>=sizeof(buf)) {
               buf[at] = '\0';
               break;
           }

           switch ((c=s[i])) {
           case '\\':
               buf[at++] = c;
               buf[at++] = c;
               break;

           case '\b':
               /* `b' is a valid hexadecimal digit */
               if (!strcmp(fmt, "b16")) {
                   sprintf(buf+at, "\\%02x", (unsigned char)c);
                   at += strlen(buf+at);
               } else {
                   buf[at++] = '\\';
                   buf[at++] = 'b';
               }
               break;

           case '\n':
               buf[at++] = '\\';
               buf[at++] = 'n';
               break;

           case '\r':
               buf[at++] = '\\';
               buf[at++] = 'r';
               break;

           case '\t':
               buf[at++] = '\\';
               buf[at++] = 't';
               break;

           case '"':
               buf[at++] = '\\';
               buf[at++] = '"';
               break;
            
           default:
               if (c>=' ' && c<='~') {
                   buf[at++] = c;
               } else if (!strcmp(fmt, "b16")) {
                   sprintf(buf+at, "\\%02x", (unsigned char)c);
                   at += strlen(buf+at);
               } else if (!strcmp(fmt, "b2")) {
                   buf[at++] = '\\';
                   for (j=0, mask=0x80; j<8; j++, mask>>=1) {
                       buf[at++] = (unsigned)c & mask ? '1':'0';
                   }
               } else {
                   /*default is octal*/
                   sprintf(buf+at, "\\%03o", (unsigned char)c);
                   at += strlen(buf+at);
               }
               break;
           }
       }
Пример #7
0
/*-------------------------------------------------------------------------
 * Function:    sym_print
 *
 * Purpose:     Prints a symbol to the specified file.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec  4 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
sym_print (obj_t _self, out_t *f) {

   out_puts (f, MYCLASS(_self)->sym->name);
}