Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions | Variables
rlesplit.c File Reference
#include <stdio.h>
#include "rle.h"
#include "rle_raw.h"
Include dependency graph for rlesplit.c:

Go to the source code of this file.

Functions

void main (int argc, char **argv)
 

Variables

char rcsid [] = "$Header: /tmp_mnt/n/itn/hendrix/u/spencer/RCS/rlesplit.c,v 3.0.1.2 1992/04/30 14:13:55 spencer Exp spencer $"
 

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 60 of file rlesplit.c.

63 {
64  register CONST_DECL char * cp, * slashp;
65  int num = 1, oflag = 0, digits = 3, tflag = 0;
66  int rle_err;
67  CONST_DECL char *infname = NULL, *format = "%s%0*d.rle";
68  static char nullpref[] = "";
69  char *prefix = nullpref;
70  char *title;
71  char filebuf[BUFSIZ];
73 
74  in_hdr = *rle_hdr_init( NULL );
75  out_hdr = *rle_hdr_init( NULL );
76 
77  if ( scanargs( argc, argv,
78  "% n%-number!ddigits%d o%-prefix!s t%- infile%s\n(\
79 \tSplit a multi-image file into separate files.\n\
80 \t-n\tSpecify number assigned to first image, optionally specify\n\
81 \t\tnumber of digits used for numbering (default 3).\n\
82 \t-o\tSpecify output filename prefix. If not specified, input\n\
83 \t\tfile name (without .rle) will be used. Output file names are\n\
84 \t\tof the form prefix.number.rle.\n\
85 \t-t\tUse TITLE (or title) comment as file name. They should be distinct.)",
86  &num, &num, &digits, &oflag, &prefix, &tflag,
87  &infname ) == 0 )
88  exit( 1 );
89 
90  /* Open input file */
91  in_hdr.rle_file = rle_open_f(cmd_name( argv ), infname, "r");
92  rle_names( &in_hdr, cmd_name( argv ), infname, 0 );
93 
94  if ( oflag || infname )
95  {
96  format = "%s.%0*d.rle";
97  if ( !oflag )
98  {
99  /* Strip ".rle" suffix from input file name */
100  /* Avoid strrchr, rindex problem */
101  for ( cp = infname; *cp; cp++ )
102  ; /* find end of name */
103  /* Look for last slash */
104  for ( slashp = cp - 1; *slashp != '/' && slashp > infname; )
105  slashp--;
106  if ( *slashp == '/' )
107  slashp++;
108  /* Look for last dot */
109  while ( *--cp != '.' && cp > infname )
110  ; /* find last . */
111  if ( strcmp( cp, ".rle" ) != 0 )
112  cp = infname + strlen( infname );
113  /* Make null full string buffer */
114  prefix = (char *)calloc( cp - slashp + 1, 1 );
115  RLE_CHECK_ALLOC( in_hdr.cmd, prefix, 0 );
116  /* Copy everything but suffix */
117  strncpy( prefix, infname, cp - slashp );
118  }
119  }
120 
121  while ( (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS )
122  {
123  /* Copy input to output file */
124  if ( tflag &&
125  ( (title=rle_getcom( "TITLE", &in_hdr)) ||
126  (title=rle_getcom( "title", &in_hdr)) ) &&
127  *title != '\0' )
128  sprintf( filebuf, "%s%s", prefix, title );
129  else
130  sprintf( filebuf, format, prefix, digits, num++ );
131 
132  fprintf( stderr, "%s: Creating %s\n", cmd_name( argv ), filebuf );
133  (void)rle_hdr_cp( &in_hdr, &out_hdr );
134  rle_names( &out_hdr, out_hdr.cmd, filebuf, 0 );
135  out_hdr.rle_file = rle_open_f(out_hdr.cmd, filebuf, "w");
136  rle_addhist( argv, &in_hdr, &out_hdr );
137 
138  rle_put_setup( &out_hdr );
139 
140  /* Copy the image to the output file. */
141  rle_cp( &in_hdr, &out_hdr );
142 
143  rle_close_f( out_hdr.rle_file );
144  }
145 
146  if ( rle_err != RLE_EOF && rle_err != RLE_EMPTY )
147  rle_get_error( rle_err, cmd_name( argv ), infname );
148 
149  exit( 0 );
150 }
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static rle_hdr in_hdr
Definition: rletogif.c:37
char * rle_getcom(const char *name, rle_hdr *the_hdr)
#define RLE_EMPTY
Definition: rle.h:73
void rle_cp(rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_cp.c:69
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_SUCCESS
Definition: rle.h:70
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
Definition: rle.h:96
void rle_close_f(FILE *fd)
Definition: rle_open_f.c:244
int rle_get_error(int code, const char *pgmname, const char *fname)
#define RLE_EOF
Definition: rle.h:74
#define CONST_DECL
Definition: rle_config.h:42
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
int format
Definition: pgmtorle.c:50
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int oflag
Definition: painttorle.c:45
FILE * rle_file
Definition: rle.h:114
rle_hdr out_hdr
Definition: dvirle2.c:89
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267

Variable Documentation

char rcsid[] = "$Header: /tmp_mnt/n/itn/hendrix/u/spencer/RCS/rlesplit.c,v 3.0.1.2 1992/04/30 14:13:55 spencer Exp spencer $"

Definition at line 11 of file rlesplit.c.