4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * given a sort invocation, convert input files, and display sort collation
37 #define COLLATE_BUFSIZE 4096
42 stream_t
*convert_chain
= S
->m_input_streams
;
43 stream_t
*cur_streamp
= convert_chain
;
45 ssize_t (*coll_convert
)(field_t
*, line_rec_t
*, flag_t
, vchar_t
);
47 coll_convert
= S
->m_coll_convert
;
49 if (S
->m_field_options
& FIELD_REVERSE_COMPARISONS
)
50 coll_flags
= COLL_REVERSE
;
55 coll_flags
|= COLL_UNIQUE
;
57 while (cur_streamp
!= NULL
) {
58 u_longlong_t lineno
= 0;
60 stream_open_for_read(S
, cur_streamp
);
61 if (cur_streamp
->s_status
& STREAM_SINGLE
||
62 cur_streamp
->s_status
& STREAM_WIDE
)
63 stream_set(cur_streamp
, STREAM_INSTANT
);
65 SOP_PRIME(cur_streamp
);
67 cur_streamp
->s_current
.l_collate
.sp
= safe_realloc(NULL
,
69 cur_streamp
->s_current
.l_collate_bufsize
= COLLATE_BUFSIZE
;
72 (void) coll_convert(S
->m_fields_head
,
73 &cur_streamp
->s_current
, FCV_REALLOC
,
74 S
->m_field_separator
);
76 (void) fprintf(stdout
, "(%llu) ", lineno
++);
77 if (cur_streamp
->s_status
& STREAM_WIDE
)
78 (void) fprintf(stdout
, "%.*ws\n\n",
79 cur_streamp
->s_current
.l_data_length
,
80 cur_streamp
->s_current
.l_data
.wp
);
82 (void) fprintf(stdout
, "%.*s\n\n",
83 cur_streamp
->s_current
.l_data_length
,
84 cur_streamp
->s_current
.l_data
.usp
);
85 xdump(stdout
, cur_streamp
->s_current
.l_collate
.usp
,
86 cur_streamp
->s_current
.l_collate_length
,
87 cur_streamp
->s_status
& STREAM_WIDE
);
88 (void) fprintf(stdout
, "\n");
90 if (SOP_EOS(cur_streamp
))
93 SOP_FETCH(cur_streamp
);
96 (void) SOP_FREE(cur_streamp
);
97 (void) SOP_CLOSE(cur_streamp
);
99 cur_streamp
= cur_streamp
->s_next
;
104 main(int argc
, char *argv
[])
110 if (options(&S
, argc
, argv
))