[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20050504: LDM: PIPE-ing to scripts



Scott,

Is the decoder a work-in-progress or not?  It, effectively, does just
what the FILE action does -- so if you're not going to modify it, then
you should use the FILE action, instead.

Regards,
Steve Emmerson

------- Original Message

Date:    Thu, 12 May 2005 11:31:52 -0800
From:    "Scott Swank" <address@hidden>To:      Steve Emmerson <steve@uni
          data.ucar.edu>
Subject: Re: 20050504: LDM: PIPE-ing to scripts

This is a multi-part message in MIME format.
--------------080401010309050006070501
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hey Steve,

> The above message contained the following:
> 
> The compiled decoders that handle non-textual data-products typically
> read the data from the standard-input stream using either the fread() or
> read() functions.
> 
> One can also write a perl(1) script that does something similar.
> 
> I take it you're not familiar with UNIX programs that read non-textual
> data from standard-input.  You might want to consult with a UNIX person
> at your site.

I could use a little help.  I've written the following program (in C 
since I don't know perl) and for some reason it isn't correctly reading 
the entire product when it is binary.  I've used the getc/putc method 
for years when dealing with binaries and this is the first time it's 
failed.  So, I commented that out and did the fread/fwrite combination 
and it has the same affect.  Depending on the binary, I'm only getting 
about 1/3 of it before the program thinks it has hit eof.

Suggestions?
Scott

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
FILE *fp;
int  c;
char filename[100];

   if (strlen(argv[1]) > 100) {
     printf ("Error: Filename %s over 100 characters in length. 
Exiting\n", argv[1]);
     return 1;
   }

   printf ("File to be processed is %s\n", argv[1]);
   strcpy(filename, argv[1]);

   if ((fp=fopen(filename, "wb"))==NULL) {
      printf ("Failed to open file %s for writing! Exiting.\n",filename);
      return 1;
   }
   printf ("Opened file %s for writing\n", filename);

   while(!feof(stdin)) {
     fread(&c, sizeof(c),1,stdin);
     fwrite(&c, sizeof(c),1,fp);
   }
// This does the same thing as above for some reason...
//  while ((c = getchar()) != EOF)
//    fputc(c, fp);

   fflush(fp);
   printf ("Finished Processing file %s\n", filename);
   fclose (fp);
   return 0;

}


--------------080401010309050006070501
Content-Type: text/x-vcard; charset=utf-8;
 name="scott.swank.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="scott.swank.vcf"

begin:vcard
fn:Scott Swank
n:Swank;Scott
email;internet:address@hidden
title:Computer Program Manager
tel;work:907-271-2466
version:2.1
end:vcard


--------------080401010309050006070501--

------- End of Original Message