1 /* $Id: ncbisort.h,v 6.1 2006/05/10 20:47:17 camacho Exp $
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name:  $RCSfile: ncbisort.h,v $
27 *
28 * Author:  Sergei Shavirin
29 *
30 * Initial Version Creation Date: 03/24/1997
31 *
32 * $Revision: 6.1 $
33 *
34 * File Description:
35 *         External include file for SORTing library
36 *
37 * $Log: ncbisort.h,v $
38 * Revision 6.1  2006/05/10 20:47:17  camacho
39 * From Ilya Dondoshansky: SORTFiles: added output parameter for total number of lines processed
40 *
41 * Revision 6.0  1997/08/25 18:53:37  madden
42 * Revision changed to 6.0
43 *
44 * Revision 1.2  1997/05/01 17:23:35  shavirin
45 * Added definition for the function SORTObjectFree()
46 *
47  * Revision 1.1  1997/03/13  21:52:27  shavirin
48  * Initial revision
49  *
50 *
51 * ==========================================================================
52 */
53 
54 #ifndef _NCBISORT_H_
55 #define _NCBISORT_H_ ncbisort_h
56 
57 /****************************************************************************/
58 /* INCLUDES */
59 /****************************************************************************/
60 
61 #ifndef _NCBI_
62 #include <ncbi.h>
63 #endif
64 
65 /****************************************************************************/
66 /* DEFINES */
67 /****************************************************************************/
68 
69 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
70 
71 typedef enum {
72   SORTNoError         =  0,
73   SORTNoSpace         =  -2,
74   SORTBadFileName     =  -3,
75   SORTNotImplemented  =  -4,
76   SORTReadError       =  -5,
77   SORTNoOrder         =  -6,
78   SORTWriteError      =  -7,
79   SORTBadParameter    =  -8,
80   SORTNoMemory        =  -9,
81   SORTMiscError       =  -99
82 } SORTErrorCode;
83 
84 /****************************************************************************/
85 /* TYPEDEFS */
86 /****************************************************************************/
87 typedef VoidPtr SORTObjectPtr;
88 
89 /* Lists of key field comparisons to be tried. */
90 typedef struct SORTKeyField
91 {
92   Int4 sword;			/* Zero-origin 'word' to start at. */
93   Int4 schar;			/* Additional characters to skip. */
94   Int4 skipsblanks;		/* Skip leading white space at start. */
95   Int4 eword;			/* Zero-origin first word after field. */
96   Int4 echar;			/* Additional characters in field. */
97   Int4 skipeblanks;		/* Skip trailing white space at finish. */
98   Int4Ptr  ignore;              /* Boolean array of characters to ignore. */
99   UcharPtr translate;	        /* Translation applied to characters. */
100   Int4 numeric;			/* Flag for numeric comparison. */
101   Int4 month;			/* Flag for comparison by month name. */
102   Int4 reverse;			/* Reverse the sense of comparison. */
103   struct SORTKeyField *next;	/* Next keyfield to try. */
104 } SORTKeyField, PNTR SORTKeyFieldPtr;
105 
106 /****************************************************************************/
107 /* FINCTION DEFINITIONS */
108 /****************************************************************************/
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 /* ----------------------  SORTObjectNew --------------------------
114    Purpose:     Creates SORT object structure with given/default
115                 parameters
116 
117    Parameters:  listed below
118    Returns:     Poiner to created object structure
119    NOTE:        All settings may be overwriten later
120 
121   ------------------------------------------------------------------*/
122 SORTObjectPtr SORTObjectNew(
123                 CharPtr prefix,  /* Prefix for TEMP files */
124                 Uchar tab,       /* Default delimiter for strings */
125                 Int4 linelength, /* Average line length (try to guess!) */
126                 Boolean reverse, /* If TRUE sorted in reverce order */
127                 Boolean unique); /* If TRUE resulted file has unique lines */
128 
129 /* ----------------------  SORTObjectFree --------------------------
130    Purpose:     Free SORT object structure
131 
132    Parameters:  SORT Object
133   ------------------------------------------------------------------*/
134 void SORTObjectFree(SORTObjectPtr object);
135 
136 
137 /* ---------------------- SORTMergeFiles --------------------------
138    Purpose:     Merge list of sorted files into single
139                 sorted file.
140 
141    Parameters:  listed below
142    Returns:     SORTErrorCode number
143    NOTE:
144   ------------------------------------------------------------------*/
145 SORTErrorCode SORTMergeFiles(
146                 CharPtr PNTR files, /* Pointer to list of filename strings */
147                 Int4 nfiles,        /* Number of files to merge */
148                 FILE *ofp,          /* Output FILE* */
149                 SORTObjectPtr sop   /* Sort options */
150                 );
151 
152 /* ---------------------- SORTFiles --------------------------
153    Purpose:     Sort list of files into single sorted file.
154 
155    Parameters:  listed below
156    Returns:     SORTErrorCode number
157    NOTE:        This may sort just sinngle file
158   ------------------------------------------------------------------*/
159 SORTErrorCode SORTFiles (
160                 CharPtr PNTR files, /* Pointer to list of filename strings */
161                 Int4 nfiles,        /* Number of files to merge */
162                 FILE *ofp,          /* Output FILE* */
163                 SORTObjectPtr sop,  /* Sort options */
164                 Int4* line_count);  /* Total number of lines processed. */
165 
166 /* ---------------------- SORTCheckOrderS --------------------------
167    Purpose:     Check, that all passed files are in order
168 
169    Parameters:  listed below
170    Returns:     Number NON-sorted files (0 mean all sorted)
171    NOTE:        This may sort just sinngle file
172   ------------------------------------------------------------------*/
173 Int4 SORTCheckOrderS(
174                 CharPtr PNTR files, /* Pointer to list of filename strings */
175                 Int4 nfiles,        /* Number of files to merge */
176                 SORTObjectPtr sop   /* Sort options */
177                 );
178 
179 /* ---------------------- SORTSet.. functions -----------------------
180    Purpose:     These functions override initial settings in
181                 SORTObjectPtr structure
182    Parameters:  various
183    Returns:     SORTErrorCode
184    NOTE:        Be careful with function SORTInserKey()!
185   ------------------------------------------------------------------*/
186 SORTErrorCode SORTSetReverse(Boolean reverse, SORTObjectPtr sop);
187 SORTErrorCode SORTSetUnique(Boolean unique, SORTObjectPtr sop);
188 SORTErrorCode SORTSetLineLength(Int4 linelength, SORTObjectPtr sop);
189 SORTErrorCode SORTSetTab(Uchar tab, SORTObjectPtr sop);
190 SORTErrorCode SORTSetPrefix(CharPtr prefix, SORTObjectPtr sop);
191 SORTKeyFieldPtr SORTGetKeyHead(SORTObjectPtr sop);
192 SORTErrorCode SORTInsertKey(SORTKeyFieldPtr key, SORTKeyFieldPtr keyhead);
193 
194 /* ---------------------- SORTAddTempName --------------------------
195    Purpose:     To add one more entry to teporary file table to
196                 be deleted in the end
197    Parameters:  SORTObjectPtr
198    Returns:     Pointer to created filename string
199    NOTE:        Created filenamed platform-dependent
200   ------------------------------------------------------------------*/
201 CharPtr SORTAddTempName(SORTObjectPtr sop);
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif
208