Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rleaddeof.c
Go to the documentation of this file.
1 /*
2  * rleaddeof.c - Add an EOF opcode to RLE files without one.
3  *
4  * Author: Spencer W. Thomas
5  * Computer Science Dept.
6  * University of Michigan
7  * Date: February, 1990
8  * Copyright (c) 1990, The Regents of the University of Michigan
9  */
10 
11 #include <stdio.h>
12 #include "rle.h"
13 #include "rle_raw.h"
14 
15 /*****************************************************************
16  * TAG( main )
17  *
18  * Usage:
19  * rleaddeof [-o outfile] [infile]
20  * Inputs:
21  * infile: If specified, input will be read from here,
22  * otherwise, input will be read from stdin.
23  * Outputs:
24  * -o outfile: Writes the output image to this file with an
25  * EOF opcode appended. Default is stdout.
26  * Assumptions:
27  * [None]
28  * Algorithm:
29  * [None]
30  */
31 void
33 int argc;
34 char **argv;
35 {
36  char * infname = NULL, *outfname = NULL;
37  int oflag = 0;
38  FILE *outfile = stdout;
39  rle_hdr in_hdr, out_hdr;
40  int rle_cnt, rle_err;
41 
42  in_hdr = *rle_hdr_init( NULL );
43  out_hdr = *rle_hdr_init( NULL );
44 
45  if ( scanargs( argc, argv, "% o%-outfile!s infile%s",
46  &oflag, &outfname, &infname ) == 0 )
47  exit( 1 );
48 
49  /* Open input file */
50  in_hdr.rle_file = rle_open_f( cmd_name( argv ), infname, "r" );
51  rle_names( &in_hdr, cmd_name( argv ), infname, 0 );
52  rle_names( &out_hdr, out_hdr.cmd, outfname, 0 );
53  for ( rle_cnt = 0;
54  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
55  rle_cnt++ )
56  {
57  /* Open output after first successful read. */
58  if ( rle_cnt == 0 )
59  outfile = rle_open_f( "rleaddeof", outfname, "w" );
60 
61  /* Copy input to output file */
62  (void)rle_hdr_cp( &in_hdr, &out_hdr );
63  out_hdr.rle_file = outfile;
64  rle_put_setup( &out_hdr );
65 
66  rle_cp( &in_hdr, &out_hdr );
67  }
68 
69  /* Check for an error. EOF or EMPTY is ok if at least one image
70  * has been read. Otherwise, print an error message.
71  */
72  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
73  rle_get_error( rle_err, cmd_name( argv ), infname );
74 
75 
76  exit( 0 );
77 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
void rle_cp(rle_hdr *in_hdr, rle_hdr *the_hdr)
Definition: rle_cp.c:69
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
#define RLE_EMPTY
Definition: rle.h:73
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
#define RLE_SUCCESS
Definition: rle.h:70
int rle_get_error(int code, const char *pgmname, const char *fname)
Definition: rle_error.c:76
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
#define RLE_EOF
Definition: rle.h:74
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114