[BACK]Return to tsort.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tsort

Diff for /src/usr.bin/tsort/tsort.c between version 1.6 and 1.7

version 1.6, 2001/04/07 14:17:38 version 1.7, 2001/04/18 17:57:28
Line 96 
Line 96 
         struct node *node;          struct node *node;
 };  };
   
   #define NO_ORDER        UINT_MAX
   
 struct node {  struct node {
         unsigned int refs;      /* Number of arcs left, coming into this node .          unsigned int refs;      /* Number of arcs left, coming into this node .
                                  * Note that nodes with a null count can't                                   * Note that nodes with a null count can't
Line 124 
Line 126 
 static void usage __P((void));  static void usage __P((void));
 static struct node *new_node __P((const char *, const char *));  static struct node *new_node __P((const char *, const char *));
   
 static void read_pairs __P((FILE *, struct ohash *, int, const char *));  static unsigned int read_pairs __P((FILE *, struct ohash *, int,
       const char *, unsigned int));
 static void split_nodes __P((struct ohash *, struct array *, struct array *));  static void split_nodes __P((struct ohash *, struct array *, struct array *));
 static void insert_arc __P((struct node *, struct node *));  static void insert_arc __P((struct node *, struct node *));
   
Line 133 
Line 136 
 static void dump_array __P((struct array *));  static void dump_array __P((struct array *));
 static void dump_hash __P((struct ohash *));  static void dump_hash __P((struct ohash *));
 #endif  #endif
 static void read_hints __P((FILE *, struct ohash *, int, const char *));  static unsigned int read_hints __P((FILE *, struct ohash *, int,
       const char *, unsigned int));
 static struct node *find_smallest_node __P((struct array *));  static struct node *find_smallest_node __P((struct array *));
 static struct node *find_good_cycle_break __P((struct array *));  static struct node *find_good_cycle_break __P((struct array *));
 static void print_cycle __P((struct array *));  static void print_cycle __P((struct array *));
Line 228 
Line 232 
         n->arcs = NULL;          n->arcs = NULL;
         n->refs = 0;          n->refs = 0;
         n->mark = 0;          n->mark = 0;
         n->order = 0;          n->order = NO_ORDER;
         n->traverse = NULL;          n->traverse = NULL;
         return n;          return n;
 }  }
Line 319 
Line 323 
         a->arcs = l;          a->arcs = l;
 }  }
   
 static void  static unsigned int
 read_pairs(f, h, reverse, name)  read_pairs(f, h, reverse, name, order)
         FILE            *f;          FILE            *f;
         struct ohash    *h;          struct ohash    *h;
         int             reverse;          int             reverse;
         const char      *name;          const char      *name;
           unsigned int    order;
 {  {
         int             toggle;          int             toggle;
         struct node     *a;          struct node     *a;
         size_t          size;          size_t          size;
         char            *str;          char            *str;
         unsigned int    o;  
   
         o = 1;  
         toggle = 1;          toggle = 1;
         a = NULL;          a = NULL;
   
Line 351 
Line 354 
                                 continue;                                  continue;
                         if (toggle) {                          if (toggle) {
                                 a = node_lookup(h, str, e);                                  a = node_lookup(h, str, e);
                                 if (a->order == 0)                                  if (a->order == NO_ORDER)
                                         a->order = o++;                                          a->order = order++;
                         } else {                          } else {
                                 struct node *b;                                  struct node *b;
   
Line 373 
Line 376 
                 errx(EX_DATAERR, "odd number of pairs in %s", name);                  errx(EX_DATAERR, "odd number of pairs in %s", name);
         if (!feof(f))          if (!feof(f))
                 err(EX_IOERR, "error reading %s", name);                  err(EX_IOERR, "error reading %s", name);
           return order;
 }  }
   
 static void  static unsigned int
 read_hints(f, h, quiet, name)  read_hints(f, h, quiet, name, order)
         FILE            *f;          FILE            *f;
         struct ohash    *h;          struct ohash    *h;
         int             quiet;          int             quiet;
         const char      *name;          const char      *name;
           unsigned int    order;
 {  {
         char            *str;          char            *str;
         size_t          size;          size_t          size;
         unsigned int    i;  
   
         i = 1;  
   
         while ((str = fgetln(f, &size)) != NULL) {          while ((str = fgetln(f, &size)) != NULL) {
                 char *sentinel;                  char *sentinel;
   
Line 403 
Line 405 
                         for (e = str; !isspace(*e) && e < sentinel; e++)                          for (e = str; !isspace(*e) && e < sentinel; e++)
                                 continue;                                  continue;
                         a = node_lookup(h, str, e);                          a = node_lookup(h, str, e);
                         if (a->order != 0)                          if (a->order != NO_ORDER) {
                                 if (!quiet)                                  if (!quiet)
                                     warnx(                                      warnx(
                                         "duplicate node %s in hints file %s",                                          "duplicate node %s in hints file %s",
                                         a->k, name);                                          a->k, name);
                         else                          } else
                                 a->order = i++;                                  a->order = order++;
                         str = e;                          str = e;
                 }                  }
         }          }
           return order;
 }  }
   
   
Line 802 
Line 805 
         struct ohash    pairs;          struct ohash    pairs;
         int             reverse_flag, quiet_flag, long_flag,          int             reverse_flag, quiet_flag, long_flag,
                             warn_flag, hints_flag, verbose_flag;                              warn_flag, hints_flag, verbose_flag;
           unsigned int    order;
   
           order = 1;
   
         reverse_flag = quiet_flag = long_flag =          reverse_flag = quiet_flag = long_flag =
                 warn_flag = hints_flag = verbose_flag = 0;                  warn_flag = hints_flag = verbose_flag = 0;
         nodes_init(&pairs);          nodes_init(&pairs);
Line 819 
Line 825 
                             if (f == NULL)                              if (f == NULL)
                                     err(EX_NOINPUT, "Can't open hint file %s",                                      err(EX_NOINPUT, "Can't open hint file %s",
                                         optarg);                                          optarg);
                             read_hints(f, &pairs, quiet_flag, optarg);                              order = read_hints(f, &pairs, quiet_flag,
                                   optarg, order);
                             fclose(f);                              fclose(f);
                     }                      }
                             /*FALLTHRU*/                              /*FALLTHRU*/
Line 859 
Line 866 
                 f = fopen(argv[0], "r");                  f = fopen(argv[0], "r");
                 if (f == NULL)                  if (f == NULL)
                         err(EX_NOINPUT, "Can't open file %s", argv[1]);                          err(EX_NOINPUT, "Can't open file %s", argv[1]);
                 read_pairs(f, &pairs, reverse_flag, argv[1]);                  order = read_pairs(f, &pairs, reverse_flag, argv[1], order);
                 fclose(f);                  fclose(f);
                 break;                  break;
         }          }
         case 0:          case 0:
                 read_pairs(stdin, &pairs, reverse_flag, "stdin");                  order = read_pairs(stdin, &pairs, reverse_flag, "stdin", order);
                 break;                  break;
         default:          default:
                 usage();                  usage();

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7