public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: root@jacob.remcomp.fr (root)
To: john.cooper@digitivity.com
Cc: gnu-win32@cygnus.com
Subject: Re: uudecode?
Date: Wed, 10 Sep 1997 10:28:00 -0000	[thread overview]
Message-ID: <m0x8ovv-000AK6C@jacob.remcomp.fr> (raw)
In-Reply-To: <19970909143204218.AAA362@TENDLE>

To satisfy popular demand, here is uudecode:
------------------------------------------------------------cut here
#include <stdio.h>
#include <string.h>
#define	DEC(c)	(((c) - ' ') & 077)
static char outname[200];
int ReadDataLine(FILE *f,char *buf)
{
	int c,i;

	i=0;
	while ((c=fgetc(f)) != EOF) {
		if (c == '\n') break;
		if (c != '\r') {
			buf[i++] = c;
		}
	}
	buf[i] = 0;
	return(c == EOF ? 0 : 1);
}

static char *uudecode (FILE *f)
{
  register int n;
  register char ch, *p;
  char buf[2 * BUFSIZ];
  FILE *out;

  do {
	  if (!ReadDataLine(f,buf)) return(NULL);
  }
  while (strncmp(buf,"begin",5));
  p = buf + 6;
  while (*p && (*p == ' '|| *p == '0' || *p == '6')) p++;
  strcpy(outname,p);
  /* Create output file and set mode.  */
  out = fopen(outname,"wb");
  /* For each input line:  */
  while (1)
    {
	if (!ReadDataLine(f,buf)) break;
	if (!strncmp(buf,"end\r\n",5)) break;
	  p = buf;

      /* N is used to avoid writing out all the characters at the end of
	 the file.  */

      n = DEC (*p);
      if (n <= 0)
	break;
      for (++p; n > 0; p += 4, n -= 3)
	{
	  if (n >= 3)
	    {
	      ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
	      fputc(ch,out);
	      ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
	      fputc (ch,out);
	      ch = DEC (p[2]) << 6 | DEC (p[3]);
	      fputc (ch,out);
	    }
	  else
	    {
	      if (n >= 1)
		{
		  ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
		  fputc (ch,out);
		}
	      if (n >= 2)
		{
		  ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
		  fputc (ch,out);
		}
	    }
	}
    }

  fclose(out);
  return outname;
}

int main(int argc,char *argv[])
{
	FILE *f;

	if (argc <= 1) {
		printf("Usage: %s <input file>\n",argv[0]);
		return(1);
	}
	f = fopen(argv[1],"rb");
	if (f == NULL) {
		printf("Impossible to open %s\n",argv[1]);
		return(1);
	}
	uudecode(f);
	fclose(f);
	printf("Result decoded into %s\n",outname);
	return(0);
}
----------------------------------------------------------------cut here

-- 
Jacob Navia	Logiciels/Informatique
41 rue Maurice Ravel			Tel 01 48.23.51.44
93430 Villetaneuse 			Fax 01 48.23.95.39
France
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

  reply	other threads:[~1997-09-10 10:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-09 23:33 uudecode? John Cooper
1997-09-10 10:28 ` root [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-01-31 23:52 uudecode? Bernard Dautrevaux
1999-01-31 23:52 uudecode? Earnie Boyd
1999-01-31 23:52 uudecode? John Cooper
1999-01-31 23:52 ` uudecode? Michael Hirmke
1999-01-31 23:52   ` uudecode? John Cooper
1999-01-31 23:52     ` uudecode? Glenn Spell
1999-01-31 23:52     ` uudecode? root
1999-01-31 23:52       ` uudecode? John Cooper
1999-01-31 23:52         ` uudecode? Pierre A. Humblet
1999-01-31 23:52       ` uudecode? John Cooper
1999-01-31 23:52         ` uudecode? John Cooper
1999-01-31 23:52 ` uudecode? Corinna Vinschen
1999-01-31 23:52 uudecode? Mark Newnham
1999-01-31 23:52 ` uudecode? $Bill Luebkert
1999-01-31 23:52 uudecode? Tom St Denis
1999-01-31 23:52 uudecode? N8TM
1999-01-31 23:52 uudecode? Lincoln, W. Terry
1999-01-31 23:52 uudecode? Bernard Dautrevaux
1999-01-31 23:52 ` uudecode? John Cooper
1999-01-31 23:52   ` uudecode? Benjamin Riefenstahl
1999-01-31 23:52   ` uudecode? Anil K Ruia
     [not found] <root@jacob.remcomp.fr's>
     [not found] ` <message>
     [not found]   ` <of>
     [not found]     ` <"Mon,>
     [not found]       ` <18>
     [not found]         ` <Jan>
     [not found]           ` <1999>
     [not found]             ` <19:42:30>
     [not found]               ` <+0100>

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0x8ovv-000AK6C@jacob.remcomp.fr \
    --to=root@jacob.remcomp.fr \
    --cc=gnu-win32@cygnus.com \
    --cc=john.cooper@digitivity.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).