28 char rcsid[] =
"$Header: /l/spencer/src/urt/tools/RCS/rleselect.c,v 3.0.1.2 1992/04/30 14:13:31 spencer Exp $";
88 int *image_list = NULL;
96 FILE *outfile = stdout;
98 rle_hdr in_hdr, out_hdr;
108 "% i%-infile%s o%-outfile!s v%- image-numbers!*d\n(\
109 \tSelect images from a file.\n\
110 \t-v\tEcho list of images selected.\n\
111 \tPositive numbers (1,...) select individual images. A negative\n\
112 \tnumber indicates a range from the previous number (or from 1 if \n\
113 \tat the beginning of the list), thus 3 -8 selects images 3, 4, 5,\n\
114 \t6, 7, 8. Zero means \"through the last\", so 5 0 selects images\n\
115 \t5 through the last one in the file. Image selections may be given in\n\
116 \tany order, they will be sorted and merged by the program.)",
117 &iflag
, &infname
, &oflag
, &outfname
, &verbose
,
118 &nimage
, &image_list
) == 0 )
123 fprintf( stderr,
"%s: No images selected.\n",
my_name );
131 for ( i = 0; i < nimage; i++ )
133 if ( image_list[i] < 0 )
135 image_list[i] = abs( image_list[i] );
139 j = image_list[i-1] + 1;
140 for ( ; j <= image_list[i]; j++ )
143 else if ( image_list[i] == 0 )
148 thrulast = image_list[i-1];
151 insert( &sorted_list
, image_list[i]
, nsorted++
);
156 for ( i = nsorted - 1; i >= 0 && sorted_list[i] >= thrulast; i-- )
163 fprintf( stderr,
"%s: Selecting images",
my_name );
164 for ( i = 0; i < nsorted; i++ )
167 fprintf( stderr,
"\n\t" );
168 fprintf( stderr,
"%d%s", sorted_list[i],
169 ((i < nsorted - 1) || thrulast >= 0) ?
", " :
"" );
172 fprintf( stderr,
"%s%d - last", i % 14 == 0 ?
"\n\t" :
"",
174 putc(
'\n', stderr );
203 while ( i < nsorted && rle_cnt > sorted_list[i] )
206 if ( thrulast < 0 && i >= nsorted )
209 if ( ! (thrulast >= 0 && rle_cnt >= thrulast) &&
210 (i >= nsorted || rle_cnt < sorted_list[i]) )
248 register int *sorted_list = *sorted_list_p;
253 sorted_list = (
int *)malloc(
sizeof(
int) );
259 sorted_list = (
int *)realloc( sorted_list, (n + 1) *
sizeof(
int) );
262 for ( j = n - 1; j >= 0 && sorted_list[j] > i; j-- )
263 sorted_list[j+1] = sorted_list[j];
264 sorted_list[j+1] = i;
267 *sorted_list_p = sorted_list;
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_cp(rle_hdr *in_hdr, rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
static const char * my_name
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
int scanargs(int argc, char **argv, const char *format,...)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
unsigned int rle_getskip(rle_hdr *the_hdr)
static void insert(int **sorted_list_p, int i, int n)
void rle_put_setup(rle_hdr *the_hdr)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)