tsort.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa/***********************************************************************
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner* This software is part of the ast package *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* Copyright (c) 1989-2011 AT&T Intellectual Property *
cacbb5e3100fb85d23d1614cace3a8662801f2e6Eugen Kuksa* and is licensed under the *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* Eclipse Public License, Version 1.0 *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* by AT&T Intellectual Property *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* A copy of the License is available at *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* http://www.eclipse.org/org/documents/epl-v10.html *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* Information and Software Systems Research *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* AT&T Research *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* Florham Park NJ *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa* Glenn Fowler <gsf@research.att.com> *
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa***********************************************************************/
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksastatic const char usage[] =
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"[-?\n@(#)$Id: tsort (AT&T Research) 2000-03-23 $\n]"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"[+NAME?tsort - topological sort]"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"[+DESCRIPTION?\btsort\b writes to the standard output a totally ordered"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa" list of items consistent with a partial ordering of items contained"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa" in the input \afile\a. If \afile\a is omitted then the standard"
a8ddb13beb092672c9f537ef1cf2e14f1f8a8f26Eugen Kuksa" input is read.]"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"[+?The input consists of pairs of items (non-empty strings) separated by"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa" blanks. Pairs of different items indicate ordering. Pairs of"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa" identical items indicate presence, but not ordering.]"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"\n[ file ]\n"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa"[+SEE ALSO?\bcomm\b(1), \bsort\b(1), \buniq\b(1)]"
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksatypedef struct Node_s
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksatypedef struct List_s
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa sfputr(sfstdout, hashname((Hash_bucket_t*)x), '\n');
1ea7fb6b0f66210bc0d3cb995f1b655277b33884Eugen Kuksa register int c;
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa register char* s;
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa register char* b;
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa if (!(tab = hashalloc(NiL, HASH_set, HASH_ALLOCATE, 0)))
a8ddb13beb092672c9f537ef1cf2e14f1f8a8f26Eugen Kuksa error(ERROR_exit(1), "out of space [hash table]");
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa if (*s == 0)
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa for (b = s; (c = *s) && c != ' ' && c != '\t'; s++);
1ea7fb6b0f66210bc0d3cb995f1b655277b33884Eugen Kuksa if (!(x = (Node_t*)hashlook(tab, b, HASH_CREATE|HASH_SIZE(sizeof(Node_t)), 0)))
c4b9911676ee4c9e8597ecb49efbf4abc69b4090Eugen Kuksa error(ERROR_exit(1), "out of space [hash entry]");
a8ddb13beb092672c9f537ef1cf2e14f1f8a8f26Eugen Kuksa error(ERROR_exit(1), "out of space [hash list]");
e3ed0ae47dd551ddd9d74c33fff11b19a23a1d97Eugen Kuksa } while (c);
d2d5606ab65ddf48599bd044416de07a205095f2Soeren D. Schulze error(ERROR_warn(1), "last line incomplete");