This is nt2text.c in view mode; [Download] [Up]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hippo.h"
#ifdef sun
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
#endif
#ifndef vms
extern int getopt(int, char **, char *);
#endif
int main(int argc, char **argv)
{
#ifndef vms
extern char *optarg;
extern int optind;
#else
int optind = 1;
#endif
int c;
int i;
int i_ntout=0;
int verbose = 0;
char filenm[80]; /* files and filenames */
FILE *ifile = stdin;
FILE *ofile = stdout;
#ifndef __STDC__
static
#endif
char outfilenm[80] = "";
ntuple *nt_list = NULL; /* hippo objects */
display *d_list = NULL;
#ifndef vms
while ((c = getopt( argc, argv, "vn:o:f:i:")) != -1)
{
switch (c)
{
case 'n':
sscanf(optarg,"%d",&i_ntout);
break;
case 'i':
case 'f':
sscanf(optarg,"%s",filenm);
if (verbose) fprintf(stderr,"Input text file = %s\n",filenm);
if ( (ifile = fopen(filenm,"r")) == NULL )
{
fprintf(stderr,"Error opening text input file %s\n",
filenm);
exit(EXIT_FAILURE);
}
break;
case 'o':
sscanf(optarg,"%s",outfilenm);
if (verbose) fprintf(stderr,"outfile = %s\n",outfilenm);
if ( (ofile = fopen(outfilenm,"w")) == NULL )
{
fprintf(stderr,"Error opening hippo output file %s\n",
outfilenm);
exit(EXIT_FAILURE);
}
break;
case 'v':
verbose = 1;
break;
default:
case '?':
fprintf(stderr,"Usage: [-v] [-a <appendfile>] [-f <inputfile>]\n");
fprintf(stderr,"[-o <outputfile>] [<inputfile> | stdin] [<outputfile> | stdout\n");
exit(EXIT_FAILURE);
}
}
#endif /* ifndef vms */
/*
* input file not in option form.
*/
if (optind < argc)
{
sscanf(argv[optind],"%s",filenm);
if (verbose) fprintf(stderr,"Input text file = %s\n",filenm);
if ( (ifile = fopen(filenm,"r")) == NULL )
{
fprintf(stderr,"Error opening text input file %s\n",
filenm);
exit(EXIT_FAILURE);
}
optind++;
}
/*
* output file not in option form.
*/
if (optind < argc)
{
sscanf(argv[optind],"%s",outfilenm);
if (verbose) fprintf(stderr,"outfile = %s\n",outfilenm);
if ( (ofile = fopen(outfilenm,"w")) == NULL )
{
fprintf(stderr,"Error opening hippo output file %s\n",
outfilenm);
exit(EXIT_FAILURE);
}
optind++;
}
/*
* handle appending ntuple to existing file.
*/
if (h_readStream(ifile,&d_list,&nt_list) != 0)
{
fprintf(stderr,"Could not read file\n");
exit(EXIT_FAILURE);
}
i = 0;
while (nt_list[i] != NULL) i++;
if (i_ntout >= i)
{
fprintf(stderr,"There are only %d ntuple in the input file\n",i);
fprintf(stderr,"Remember: ntuples are numbered from 0\n");
exit(EXIT_FAILURE);
}
/*
* all set. Do it!
*/
h_nt2text( ofile, nt_list[i_ntout] );
exit(EXIT_SUCCESS);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.