[comp.sources.misc] Uudecode fixer

jvc@mirror.COM (Jim Champeaux) (05/18/87)

It seems that some uuencoded postings are being stripped of trailing
spaces.  This program was posted in comp.sys.ibm.pc  but apparently most
people missed it.  I've used it on a couple of files that were altered
and it seems to work.
Please consider posting it here.

-------------------------------------------------------------------------
Jim Champeaux	jvc@mirror.TMC.COM
		{mit-eddie, ihnp4, wjh12, cca, cbosgd, seismo}!mirror!jvc
Mirror Systems,	2067 Massachusetts Avenue, Cambridge, MA 02140
Telephone:	(617) 661-0777

==========================================================================
>Uudecode reports "short file" and the resulting arc520.com does not 
>unarc itself.
>I used UNIX uudecode on a pyramid 90x.

The reason is that some mailer, somewhere, removed all of the trailing space.
Uudecode don't like it (at least here).  So, I wrote a little program to put
it back.  I have tried the resulting arc520.com, and it seems to work. 

uucp:		mcvax!cernvax!cui!Fisch / Fisch@cui.uucp
X400/ean:	Fisch@cui.unige.chunet
bitnet/earn:	Fisch%cui.unige.chunet@cernvax

__________________________________ CUT HERE __________________________________
/*
    Try to repair uuencoded files when trailing space has been removed.
    It pads short lines with spaces whenever needed.
    It reads from stdin and writes to stdout.

	use: pgm <uuencoded > repaired
	     uudecode repaired

	or:  pgm <uuencoded | uudecode

    If it doesn't work, I can't help you.
*/

#include <stdio.h>

main()
  {
    char c;
    int tab, len;

    tab = 0;
    while ((c = getchar()) != EOF)
      {
	if (tab == 0)
	  {
	    if (' '<=c && c<='Z') len = ((c-' '+2)/3)*4+1;
	    else len = 1;
	  }
	if (c == '\n')
	  {
	    while (tab++<len) putchar(' ');
	    tab = 0;
	  }
	else tab++;
	putchar (c);
      }
  }
/* End of text from mirror:comp.sys.ibm.pc */