~ubuntu-branches/ubuntu/karmic/ncbi-tools6/karmic

« back to all changes in this revision

Viewing changes to tools/ncbisort.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2006-10-22 19:32:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.4 dapper)
  • Revision ID: james.westby@ubuntu.com-20061022193202-6svrvb6l52n0uhe4
Tags: 6.1.20061015-1
* New upstream release.
* Don't bother linking against indirectly used system libraries.
* Update man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
static char const rcsid[] = "$Id: ncbisort.c,v 6.7 2003/07/15 20:17:39 coulouri Exp $";
 
1
static char const rcsid[] = "$Id: ncbisort.c,v 6.8 2006/05/10 20:47:17 camacho Exp $";
2
2
 
3
 
/* $Id: ncbisort.c,v 6.7 2003/07/15 20:17:39 coulouri Exp $
 
3
/* $Id: ncbisort.c,v 6.8 2006/05/10 20:47:17 camacho Exp $
4
4
* ===========================================================================
5
5
*
6
6
*                            PUBLIC DOMAIN NOTICE
31
31
*
32
32
* Initial Version Creation Date: 03/24/1997
33
33
*
34
 
* $Revision: 6.7 $
 
34
* $Revision: 6.8 $
35
35
*
36
36
* File Description:
37
37
*         Main file for SORTing library
38
38
*
39
39
* $Log: ncbisort.c,v $
 
40
* Revision 6.8  2006/05/10 20:47:17  camacho
 
41
* From Ilya Dondoshansky: SORTFiles: added output parameter for total number of lines processed
 
42
*
40
43
* Revision 6.7  2003/07/15 20:17:39  coulouri
41
44
* remove signal() and setrlimit() calls
42
45
*
234
237
 
235
238
/* Sort any number of FILES onto the given OFP. */
236
239
SORTErrorCode SORTFiles(CharPtr PNTR files, Int4 nfiles, FILE *ofp, 
237
 
               SORTObjectPtr sop)
 
240
               SORTObjectPtr sop, Int4* line_count)
238
241
{
239
242
  SORTBuffer   buf;
240
243
  SORTLines   lines;
247
250
  CharPtr PNTR tempfiles;
248
251
  CharPtr temp;
249
252
  SORTErrorCode error_code = SORTNoError;
 
253
 
 
254
  *line_count = 0;
250
255
  
251
256
  if((sdp = (SORTDataPtr) sop) == NULL) {
252
257
    error_code = SORTBadParameter;
267
272
      error_code = SORTBadFileName;
268
273
      goto return_from_function;
269
274
    }
270
 
    
 
275
 
271
276
    while (SORTFillBuf(&buf, fp)) {
272
277
      SORTFindLines(&buf, &lines, sdp);
 
278
      *line_count += lines.used;
273
279
      if (lines.used > ntmp) {
274
280
        while (lines.used > ntmp)
275
281
          ntmp *= 2;
280
286
        }
281
287
      }
282
288
      SORTArrayLines(lines.lines, lines.used, tmp, sdp);
283
 
 
284
289
      if (feof(fp) && !nfiles && !ntemp) {
285
290
        tfp = ofp;
286
291
      } else {
311
316
    }
312
317
    FileClose(fp);
313
318
  }
314
 
  
 
319
 
 
320
 
315
321
  MemFree(buf.buf);
316
322
  MemFree((CharPtr) lines.lines);
317
323
  MemFree((CharPtr) tmp);
543
549
    buf->buf[buf->used++] = '\n';
544
550
    ++total;
545
551
  }
 
552
 
546
553
  return total;
547
554
}
548
555