home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / telix / tlx3sort.zip / TLXSORT.C < prev    next >
C/C++ Source or Header  |  1988-07-13  |  2KB  |  120 lines

  1. /**
  2.  *
  3.  *  Module:       tlxsort.c
  4.  *  Version:      1.0
  5.  *  Description:  sort Telix 3.0 phone directories
  6.  *  Author:       Paul Roub
  7.  *
  8.  *  Revision History:
  9.  *     7-13-88 : created
  10.  *
  11.  *      This program and its sources are Copyright (C) 1988 by Paul Roub
  12.  *      and may not be sold for profit without the express written
  13.  *      consent of the author.  Redistribute them (in their entirety) as
  14.  *      you wish,  provided no fee is charged and all materials are
  15.  *      present and unmodified.
  16.  *
  17. **/
  18.  
  19. /*<f>*/
  20. #include  <malloc.h>
  21. #include  <stdio.h>
  22. #include  <stdlib.h>
  23. #include  <string.h>
  24.  
  25. #include  "tlx30.h"
  26. #include  "tlxsort.h"
  27.  
  28.  
  29. void      main( int argc, char **argv );
  30. int       fon_compare(const void *elem1, const void *elem2);
  31.  
  32. static  char      *InName  = "telix.fon";
  33. static  char      *OutName = "telix.fon";
  34.  
  35.  
  36. /*<f>*/
  37. /**
  38.  *
  39.  *  Function:     void main()
  40.  *  Description:  tlxsort main routine
  41.  *  Returns:      nothing
  42.  *
  43. **/
  44. void main(argc, argv)
  45. int       argc;
  46. char      **argv;
  47. {
  48.   fon_header *th;
  49.   fon_entry *te;
  50.  
  51.   printf("TlxSort v1.0 -- Copyright (C) 1988 by Paul Roub\n\n");
  52.  
  53.   if (argc > 3)
  54.     quitf("usage: tlxsort [input file name] [output file name]");
  55.  
  56.   --argc;
  57.   ++argv;
  58.  
  59.   if (argc)
  60.   {
  61.     InName = *argv;
  62.     argc--;
  63.     argv++;
  64.   }
  65.  
  66.   if (argc)
  67.   {
  68.     OutName = *argv;
  69.     argc--;
  70.     argv++;
  71.   }
  72.  
  73.   printf("Sorting %s to %s...\n", InName, OutName);
  74.  
  75.     ReadFonFile(InName, &th, &te);
  76.  
  77.   qsort(te, (size_t)th->num_entries, sizeof(fon_entry), fon_compare);
  78.  
  79.   WriteFonFile(OutName, th, te);
  80.  
  81.   free(th);
  82.   free(te);
  83.  
  84.   printf("%u entries sorted.\n", th->num_entries);
  85.  
  86.   exit(0);
  87. }
  88.  
  89.  
  90. /*<f>*/
  91. /**
  92.  *
  93.  *  Function:     int fon_compare()
  94.  *  Description:  comparison routines used by qsort - sorts files by
  95.  *                name - not the exception:  if a one file has a
  96.  *                blank name (""),  it goes after the other,
  97.  *                regardless
  98.  *  Returns:      -1 if first should come before second
  99.  *                0 if first and second sort the same
  100.  *                1 if first should come after second
  101.  *
  102. **/
  103. int fon_compare(elem1, elem2)
  104. const void *elem1, *elem2;
  105. {
  106.   const fon_entry *te1, *te2;
  107.  
  108.   te1 = elem1;
  109.   te2 = elem2;
  110.  
  111.   if (! te1->name[0])
  112.     return(1);
  113.  
  114.   if (! te2->name[0])
  115.     return(2);
  116.  
  117.   return(strnicmp(te1->name, te2->name, 25));
  118. }
  119.  
  120.