mkdep.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* make dependencies; Date: jan 07, 1986; Author: Erik Baalbergen */
  7. #include <stdio.h>
  8. #define BSIZ 1024
  9. char *progname;
  10. struct namelist {
  11. struct namelist *next;
  12. char *name;
  13. };
  14. struct namelist *freelist;
  15. struct namelist *new_namelist();
  16. struct namelist *nl = 0;
  17. char *Malloc(u)
  18. unsigned u;
  19. {
  20. char *sp, *malloc();
  21. if ((sp = malloc(u)) == 0) {
  22. fprintf(stderr, "%s: out of space\n");
  23. exit(1);
  24. }
  25. return sp;
  26. }
  27. struct namelist *
  28. new_namelist()
  29. {
  30. register struct namelist *nlp = freelist;
  31. if (nlp) {
  32. freelist = nlp->next;
  33. return nlp;
  34. }
  35. return (struct namelist *) Malloc(sizeof(struct namelist));
  36. }
  37. free_namelist(nlp)
  38. struct namelist *nlp;
  39. {
  40. if (nlp) {
  41. free_namelist(nlp->next);
  42. nlp->next = freelist;
  43. freelist = nlp;
  44. }
  45. }
  46. add_name(nm)
  47. char *nm;
  48. {
  49. struct namelist *nlp = nl;
  50. struct namelist *lnlp = 0;
  51. struct namelist *nnlp;
  52. char *strcpy();
  53. while (nlp) {
  54. register i = strcmp(nm, nlp->name);
  55. if (i < 0)
  56. break;
  57. if (i == 0) /* already present */
  58. return;
  59. lnlp = nlp;
  60. nlp = nlp->next;
  61. }
  62. (nnlp = new_namelist())->name = strcpy(Malloc(strlen(nm) + 1), nm);
  63. if (lnlp) {
  64. nnlp->next = lnlp->next;
  65. lnlp->next = nnlp;
  66. }
  67. else {
  68. nnlp->next = nl;
  69. nl = nnlp;
  70. }
  71. }
  72. print_namelist(nm, nlp)
  73. char *nm;
  74. struct namelist *nlp;
  75. {
  76. if (nlp) {
  77. while (nlp) {
  78. printf("%s: %s\n", nm, nlp->name);
  79. nlp = nlp->next;
  80. }
  81. }
  82. }
  83. main(argc, argv)
  84. char *argv[];
  85. {
  86. int err = 0;
  87. progname = *argv++;
  88. while (--argc > 0) {
  89. free_namelist(nl);
  90. nl = 0;
  91. if (dofile(*argv) == 0)
  92. ++err;
  93. print_namelist(*argv++, nl);
  94. }
  95. exit(err ? 1 : 0);
  96. }
  97. int
  98. contains_slash(s)
  99. register char *s;
  100. {
  101. while (*s) {
  102. if (*s++ == '/') return 1;
  103. }
  104. return 0;
  105. }
  106. dofile(fn)
  107. char *fn;
  108. {
  109. char *fgets(), buf[BSIZ];
  110. FILE *fp;
  111. char *nm, *include_line();
  112. if ((fp = fopen(fn, "r")) == 0) {
  113. fprintf(stderr, "%s: cannot read %s\n", progname, fn);
  114. return 0;
  115. }
  116. if (contains_slash(fn)) {
  117. fprintf(stderr, "%s: (warning) %s not in current directory; not checked\n", progname, fn);
  118. fclose(fp);
  119. return 1;
  120. }
  121. while (fgets(buf, BSIZ, fp) != NULL)
  122. if (nm = include_line(buf)) {
  123. add_name(nm);
  124. dofile(nm);
  125. }
  126. fclose(fp);
  127. return 1;
  128. }
  129. char *
  130. include_line(s)
  131. char *s;
  132. {
  133. while ((*s == '\t') || (*s == ' '))
  134. s++;
  135. if (*s++ == '#') {
  136. while ((*s == '\t') || (*s == ' '))
  137. s++;
  138. if (
  139. (*s++ == 'i') &&
  140. (*s++ == 'n') &&
  141. (*s++ == 'c') &&
  142. (*s++ == 'l') &&
  143. (*s++ == 'u') &&
  144. (*s++ == 'd') &&
  145. (*s++ == 'e')
  146. ) {
  147. while ((*s == '\t') || (*s == ' '))
  148. s++;
  149. if (*s++ == '"') {
  150. register char *nm = s;
  151. while (*s != 0 && *s != '"')
  152. s++;
  153. *s = '\0';
  154. return nm;
  155. }
  156. }
  157. }
  158. return (char *) 0;
  159. }