[aklug] Re: safe output to terminal?

From: David M. Syzdek <david@syzdek.net>
Date: Sat Oct 16 2010 - 11:19:03 AKDT

You could pipe the output through something like sed to remove the
non-printable characters, or make a very simple C program such as the
following program which replaces the non-printable characters with a '.'
character. It should be able to process your data quickly enough. It
processed about 83MB of data from `cat /dev/random' in 11 seconds on my
laptop.
/** clean-stdin.c strips non-printable ASCII characters from STDIN */
/* gcc -W -Wall -o clean-stdin clean-stdin.c */
#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
int main(void);
int main(void)
{
   size_t count;
   size_t len;
   char buff[4095L];
   while((len = read(STDIN_FILENO, buff, 4095L)) > 0)
   {
      for(count = 0; count < len; count++)
         if ((buff[count] < 0x20)||(buff[count] > 0x7e))
            buff[count] = '.';
      write(STDOUT_FILENO, buff, len);
   };
   return(0);
}
/* end of source */

On Fri, Oct 15, 2010 at 8:16 PM, Christopher Howard <choward@indicium.us>wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Okay, lets say I'm one of those perverse individuals who loves to pour
> gigabytes of data directly into the terminal and watch it scroll by at
> lightning fast speeds. Eventually, however, it seems that some kind of
> escape code or command code comes along that messes up the terminal
> display. Is there a filter program or something that I can run the
> output through that would sanitize the output just enough for safe
> viewing in the terminal?
>
> (Reminder: I don't want to /page/ through the output, just dump it safely.)
>
> - --
> Christopher Howard
> frigidcode.com
> theologia.indicium.us
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.16 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAky5Jx0ACgkQQ5FLNdi0BcVI6gCfYgk3n3HXP3TPZe6wIZwJkyQf
> y5EAn3eRgDh12AxXav8fPpOTyBCUKfSM
> =wAVl
> -----END PGP SIGNATURE-----
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
>

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Sat Oct 16 11:19:16 2010

This archive was generated by hypermail 2.1.8 : Sat Oct 16 2010 - 11:19:16 AKDT