dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sort / common / convert.c
blob964e45697f7fa6e5fdb401fef59a7fd80b3ebd2d
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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"
30 * convert
31 * given a sort invocation, convert input files, and display sort collation
32 * vectors to stdout.
35 #include "main.h"
37 #define COLLATE_BUFSIZE 4096
39 static void
40 convert(sort_t *S)
42 stream_t *convert_chain = S->m_input_streams;
43 stream_t *cur_streamp = convert_chain;
44 flag_t coll_flags;
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;
51 else
52 coll_flags = 0;
54 if (S->m_entire_line)
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,
68 COLLATE_BUFSIZE);
69 cur_streamp->s_current.l_collate_bufsize = COLLATE_BUFSIZE;
71 for (;;) {
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);
81 else
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))
91 break;
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[])
106 sort_t S;
108 initialize_pre(&S);
110 if (options(&S, argc, argv))
111 return (E_ERROR);
113 initialize_post(&S);
115 convert(&S);
117 return (E_SUCCESS);