home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / extensions / PEX / SI / indexer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-15  |  3.4 KB  |  140 lines

  1. /* $XConsortium: indexer.c,v 5.1 91/02/16 09:46:02 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright (c) 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include "indexer.h"
  32.  
  33. struct index_entry    *root;
  34.  
  35. main(argc, argv)
  36. int    argc;
  37. char    *argv[];
  38. {
  39.     int    char_p;
  40.     char    line[MAXLINE];
  41.     int    index_type;
  42.     int    page_type;
  43.     struct index_entry    *entry;
  44.     struct page_entry    *page;
  45.  
  46.  
  47.     command_name = argv[0];
  48.     root = NULL;
  49.  
  50.     line_number = 0;
  51.     while (fgets(line, sizeof(line), stdin) != NULL) {
  52.         line_number++;
  53.         char_p = 0;
  54.                 /*  Skip over the start of the line  */
  55.         if (skip_start(line, &char_p) == FALSE)
  56.             continue;
  57.  
  58.                 /*  Obtain type of index entry  */
  59.                 /*  ENTRY or DOCUMENT  */
  60.         if ((index_type = get_index_type(line, &char_p)) == 0)
  61.             continue;
  62.         if (index_type == DOCUMENT)
  63.             continue;
  64.  
  65.                 /*  Read the index terms  */
  66.         entry = get_index_terms(line, &char_p);
  67.         entry->index_type = index_type;
  68.  
  69.         if (index_type == ENTRY) {
  70.                 /*  Obtain type of page entry or print entry  */
  71.             if ((page_type = get_page_type(line, &char_p)) == 0) {
  72.                 free(entry);
  73.                 continue;
  74.             }
  75.  
  76.             page = get_page_number(line, &char_p);
  77.             page->page_type = page_type;
  78.         
  79.             insert_page_entry(entry, page);
  80.         }
  81.  
  82.                 /*  Insert index entry into the tree  */
  83.         if (root == NULL)
  84.             root = entry;
  85.         else
  86.             entry = insert_index_entry(root, entry);
  87.     }
  88.                 /*  Print the index terms  */
  89.     previous_index_entry = NULL;
  90.     print_index(root);
  91.  
  92.     return(0);
  93. }
  94.  
  95. /*
  96.  * Read index entries from the index file.  Build a new index entry.
  97.  */
  98. struct    index_entry *
  99. get_index_terms(line, char_p)
  100.     char    *line;
  101.     int    *char_p;
  102. {
  103.     struct index_entry    *entry;
  104.     int    level;
  105.     char    *field;
  106.  
  107.     entry = new(struct index_entry);
  108.                 /*  Read the index terms  */
  109.     for (level = 0; level < LEVELS; level++) {
  110.         field = get_field(line, char_p);
  111.         entry->terms[level] = strdup(field);
  112.     }
  113.                 /*  Read the strings to print  */
  114.     for (level = 0; level < LEVELS; level++) {
  115.         field = get_field(line, char_p);
  116.         entry->print_field[level] = strdup(field);
  117.     }
  118.     return(entry);
  119. }
  120.  
  121.  
  122. /*
  123.  * Read page number from the index file.  Build a new page number entry.
  124.  */
  125. struct    page_entry *
  126. get_page_number(line, char_p)
  127.     char    *line;
  128.     int     *char_p;
  129. {
  130.     char    *page_number;
  131.     struct page_entry    *page;
  132.  
  133.  
  134.     page_number = get_field(line, char_p);
  135.  
  136.     page = new(struct page_entry);
  137.     page->page_number = strdup(page_number);
  138.     return(page);
  139. }
  140.