home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume19 / dmake / part07 < prev    next >
Encoding:
Text File  |  1991-05-11  |  40.1 KB  |  1,381 lines

  1. Newsgroups: comp.sources.misc
  2. From: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  3. Subject:  v19i028:  dmake - dmake version 3.7, Part07/37
  4. Message-ID: <1991May10.185524.21550@sparky.IMD.Sterling.COM>
  5. Date: Fri, 10 May 1991 18:55:24 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7.  
  8. Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  9. Posting-number: Volume 19, Issue 28
  10. Archive-name: dmake/part07
  11. Supersedes: dmake-3.6: Volume 15, Issue 52-77
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # this is dmake.shar.07 (part 7 of a multipart archive)
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file dmake/dbug/malloc/testmem.c continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 7; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test -f _shar_wnt_.tmp; then
  32. sed 's/^X//' << 'SHAR_EOF' >> 'dmake/dbug/malloc/testmem.c' &&
  33. X    (void) strncat(one, "cdef", 2);
  34. X    equal(one, "abcd", 10);            /* Count-limited. */
  35. X
  36. X    (void) strncat(one, "gh", 0);
  37. X    equal(one, "abcd", 11);            /* Zero count. */
  38. X
  39. X    (void) strncat(one, "gh", 2);
  40. X    equal(one, "abcdgh", 12);        /* Count and length equal. */
  41. X
  42. X    /*
  43. X     * strncmp - first test as strcmp with big counts, then test
  44. X     * count code.
  45. X     */
  46. X    it = "strncmp";
  47. X    check(strncmp("", "", 99) == 0, 1);    /* Trivial case. */
  48. X    check(strncmp("a", "a", 99) == 0, 2);    /* Identity. */
  49. X    check(strncmp("abc", "abc", 99) == 0, 3);    /* Multicharacter. */
  50. X    check(strncmp("abc", "abcd", 99) < 0, 4);    /* Length unequal. */
  51. X    check(strncmp("abcd", "abc", 99) > 0, 5);
  52. X    check(strncmp("abcd", "abce", 99) < 0, 6);    /* Honestly unequal. */
  53. X    check(strncmp("abce", "abcd", 99) > 0, 7);
  54. X    check(strncmp("a\203", "a", 2) > 0, 8);    /* Tricky if '\203' < 0 */
  55. X    if (charsigned)                /* Sign-bit comparison. */
  56. X        check(strncmp("a\203", "a\003", 2) < 0, 9);
  57. X    else
  58. X        check(strncmp("a\203", "a\003", 2) > 0, 9);
  59. X    check(strncmp("abce", "abcd", 3) == 0, 10);    /* Count limited. */
  60. X    check(strncmp("abce", "abc", 3) == 0, 11);    /* Count == length. */
  61. X    check(strncmp("abcd", "abce", 4) < 0, 12);    /* Nudging limit. */
  62. X    check(strncmp("abc", "def", 0) == 0, 13);    /* Zero count. */
  63. X
  64. X    /*
  65. X     * strncpy - testing is a bit different because of odd semantics
  66. X     */
  67. X    it = "strncpy";
  68. X    check(strncpy(one, "abc", 4) == one, 1);    /* Returned value. */
  69. X    equal(one, "abc", 2);            /* Did the copy go right? */
  70. X
  71. X    (void) strcpy(one, "abcdefgh");
  72. X    (void) strncpy(one, "xyz", 2);
  73. X    equal(one, "xycdefgh", 3);        /* Copy cut by count. */
  74. X
  75. X    (void) strcpy(one, "abcdefgh");
  76. X    (void) strncpy(one, "xyz", 3);        /* Copy cut just before NUL. */
  77. X    equal(one, "xyzdefgh", 4);
  78. X
  79. X    (void) strcpy(one, "abcdefgh");
  80. X    (void) strncpy(one, "xyz", 4);        /* Copy just includes NUL. */
  81. X    equal(one, "xyz", 5);
  82. X    equal(one+4, "efgh", 6);        /* Wrote too much? */
  83. X
  84. X    (void) strcpy(one, "abcdefgh");
  85. X    (void) strncpy(one, "xyz", 5);        /* Copy includes padding. */
  86. X    equal(one, "xyz", 7);
  87. X    equal(one+4, "", 8);
  88. X    equal(one+5, "fgh", 9);
  89. X
  90. X    (void) strcpy(one, "abc");
  91. X    (void) strncpy(one, "xyz", 0);        /* Zero-length copy. */
  92. X    equal(one, "abc", 10);    
  93. X
  94. X    (void) strncpy(one, "", 2);        /* Zero-length source. */
  95. X    equal(one, "", 11);
  96. X    equal(one+1, "", 12);    
  97. X    equal(one+2, "c", 13);
  98. X
  99. X    (void) strcpy(one, "hi there");
  100. X    (void) strncpy(two, one, 9);
  101. X    equal(two, "hi there", 14);        /* Just paranoia. */
  102. X    equal(one, "hi there", 15);        /* Stomped on source? */
  103. X
  104. X    /*
  105. X     * strlen
  106. X     */
  107. X    it = "strlen";
  108. X    check(strlen("") == 0, 1);        /* Empty. */
  109. X    check(strlen("a") == 1, 2);        /* Single char. */
  110. X    check(strlen("abcd") == 4, 3);        /* Multiple chars. */
  111. X
  112. X    /*
  113. X     * strchr
  114. X     */
  115. X    it = "strchr";
  116. X    check(strchr("abcd", 'z') == NULL, 1);    /* Not found. */
  117. X    (void) strcpy(one, "abcd");
  118. X    check(strchr(one, 'c') == one+2, 2);    /* Basic test. */
  119. X    check(strchr(one, 'd') == one+3, 3);    /* End of string. */
  120. X    check(strchr(one, 'a') == one, 4);    /* Beginning. */
  121. X    check(strchr(one, '\0') == one+4, 5);    /* Finding NUL. */
  122. X    (void) strcpy(one, "ababa");
  123. X    check(strchr(one, 'b') == one+1, 6);    /* Finding first. */
  124. X    (void) strcpy(one, "");
  125. X    check(strchr(one, 'b') == NULL, 7);    /* Empty string. */
  126. X    check(strchr(one, '\0') == one, 8);    /* NUL in empty string. */
  127. X
  128. X    /*
  129. X     * index - just like strchr
  130. X     */
  131. X    it = "index";
  132. X    check(index("abcd", 'z') == NULL, 1);    /* Not found. */
  133. X    (void) strcpy(one, "abcd");
  134. X    check(index(one, 'c') == one+2, 2);    /* Basic test. */
  135. X    check(index(one, 'd') == one+3, 3);    /* End of string. */
  136. X    check(index(one, 'a') == one, 4);    /* Beginning. */
  137. X    check(index(one, '\0') == one+4, 5);    /* Finding NUL. */
  138. X    (void) strcpy(one, "ababa");
  139. X    check(index(one, 'b') == one+1, 6);    /* Finding first. */
  140. X    (void) strcpy(one, "");
  141. X    check(index(one, 'b') == NULL, 7);    /* Empty string. */
  142. X    check(index(one, '\0') == one, 8);    /* NUL in empty string. */
  143. X
  144. X    /*
  145. X     * strrchr
  146. X     */
  147. X    it = "strrchr";
  148. X    check(strrchr("abcd", 'z') == NULL, 1);    /* Not found. */
  149. X    (void) strcpy(one, "abcd");
  150. X    check(strrchr(one, 'c') == one+2, 2);    /* Basic test. */
  151. X    check(strrchr(one, 'd') == one+3, 3);    /* End of string. */
  152. X    check(strrchr(one, 'a') == one, 4);    /* Beginning. */
  153. X    check(strrchr(one, '\0') == one+4, 5);    /* Finding NUL. */
  154. X    (void) strcpy(one, "ababa");
  155. X    check(strrchr(one, 'b') == one+3, 6);    /* Finding last. */
  156. X    (void) strcpy(one, "");
  157. X    check(strrchr(one, 'b') == NULL, 7);    /* Empty string. */
  158. X    check(strrchr(one, '\0') == one, 8);    /* NUL in empty string. */
  159. X
  160. X    /*
  161. X     * rindex - just like strrchr
  162. X     */
  163. X    it = "rindex";
  164. X    check(rindex("abcd", 'z') == NULL, 1);    /* Not found. */
  165. X    (void) strcpy(one, "abcd");
  166. X    check(rindex(one, 'c') == one+2, 2);    /* Basic test. */
  167. X    check(rindex(one, 'd') == one+3, 3);    /* End of string. */
  168. X    check(rindex(one, 'a') == one, 4);    /* Beginning. */
  169. X    check(rindex(one, '\0') == one+4, 5);    /* Finding NUL. */
  170. X    (void) strcpy(one, "ababa");
  171. X    check(rindex(one, 'b') == one+3, 6);    /* Finding last. */
  172. X    (void) strcpy(one, "");
  173. X    check(rindex(one, 'b') == NULL, 7);    /* Empty string. */
  174. X    check(rindex(one, '\0') == one, 8);    /* NUL in empty string. */
  175. }
  176. X
  177. second()
  178. {
  179. X    /*
  180. X     * strpbrk - somewhat like strchr
  181. X     */
  182. X    it = "strpbrk";
  183. X    check(strpbrk("abcd", "z") == NULL, 1);    /* Not found. */
  184. X    (void) strcpy(one, "abcd");
  185. X    check(strpbrk(one, "c") == one+2, 2);    /* Basic test. */
  186. X    check(strpbrk(one, "d") == one+3, 3);    /* End of string. */
  187. X    check(strpbrk(one, "a") == one, 4);    /* Beginning. */
  188. X    check(strpbrk(one, "") == NULL, 5);    /* Empty search list. */
  189. X    check(strpbrk(one, "cb") == one+1, 6);    /* Multiple search. */
  190. X    (void) strcpy(one, "abcabdea");
  191. X    check(strpbrk(one, "b") == one+1, 7);    /* Finding first. */
  192. X    check(strpbrk(one, "cb") == one+1, 8);    /* With multiple search. */
  193. X    check(strpbrk(one, "db") == one+1, 9);    /* Another variant. */
  194. X    (void) strcpy(one, "");
  195. X    check(strpbrk(one, "bc") == NULL, 10);    /* Empty string. */
  196. X    check(strpbrk(one, "") == NULL, 11);    /* Both strings empty. */
  197. X
  198. #if 0
  199. X    /*
  200. X     * strstr - somewhat like strchr
  201. X     */
  202. X    it = "strstr";
  203. X    check(strstr("abcd", "z") == NULL, 1);    /* Not found. */
  204. X    check(strstr("abcd", "abx") == NULL, 2);    /* Dead end. */
  205. X    (void) strcpy(one, "abcd");
  206. X    check(strstr(one, "c") == one+2, 3);    /* Basic test. */
  207. X    check(strstr(one, "bc") == one+1, 4);    /* Multichar. */
  208. X    check(strstr(one, "d") == one+3, 5);    /* End of string. */
  209. X    check(strstr(one, "cd") == one+2, 6);    /* Tail of string. */
  210. X    check(strstr(one, "abc") == one, 7);    /* Beginning. */
  211. X    check(strstr(one, "abcd") == one, 8);    /* Exact match. */
  212. X    check(strstr(one, "abcde") == NULL, 9);    /* Too long. */
  213. X    check(strstr(one, "de") == NULL, 10);    /* Past end. */
  214. X    check(strstr(one, "") == one+4, 11);    /* Finding empty. */
  215. X    (void) strcpy(one, "ababa");
  216. X    check(strstr(one, "ba") == one+1, 12);    /* Finding first. */
  217. X    (void) strcpy(one, "");
  218. X    check(strstr(one, "b") == NULL, 13);    /* Empty string. */
  219. X    check(strstr(one, "") == one, 14);    /* Empty in empty string. */
  220. X    (void) strcpy(one, "bcbca");
  221. X    check(strstr(one, "bca") == one+2, 15);    /* False start. */
  222. X    (void) strcpy(one, "bbbcabbca");
  223. X    check(strstr(one, "bbca") == one+1, 16);    /* With overlap. */
  224. #endif
  225. X
  226. X    /*
  227. X     * strspn
  228. X     */
  229. X    it = "strspn";
  230. X    check(strspn("abcba", "abc") == 5, 1);    /* Whole string. */
  231. X    check(strspn("abcba", "ab") == 2, 2);    /* Partial. */
  232. X    check(strspn("abc", "qx") == 0, 3);    /* None. */
  233. X    check(strspn("", "ab") == 0, 4);    /* Null string. */
  234. X    check(strspn("abc", "") == 0, 5);    /* Null search list. */
  235. X
  236. X    /*
  237. X     * strcspn
  238. X     */
  239. X    it = "strcspn";
  240. X    check(strcspn("abcba", "qx") == 5, 1);    /* Whole string. */
  241. X    check(strcspn("abcba", "cx") == 2, 2);    /* Partial. */
  242. X    check(strcspn("abc", "abc") == 0, 3);    /* None. */
  243. X    check(strcspn("", "ab") == 0, 4);    /* Null string. */
  244. X    check(strcspn("abc", "") == 3, 5);    /* Null search list. */
  245. X
  246. X    /*
  247. X     * strtok - the hard one
  248. X     */
  249. X    it = "strtok";
  250. X    (void) strcpy(one, "first, second, third");
  251. X    equal(strtok(one, ", "), "first", 1);    /* Basic test. */
  252. X    equal(one, "first", 2);
  253. X    equal(strtok((char *)NULL, ", "), "second", 3);
  254. X    equal(strtok((char *)NULL, ", "), "third", 4);
  255. X    check(strtok((char *)NULL, ", ") == NULL, 5);
  256. X    (void) strcpy(one, ", first, ");
  257. X    equal(strtok(one, ", "), "first", 6);    /* Extra delims, 1 tok. */
  258. X    check(strtok((char *)NULL, ", ") == NULL, 7);
  259. X    (void) strcpy(one, "1a, 1b; 2a, 2b");
  260. X    equal(strtok(one, ", "), "1a", 8);    /* Changing delim lists. */
  261. X    equal(strtok((char *)NULL, "; "), "1b", 9);
  262. X    equal(strtok((char *)NULL, ", "), "2a", 10);
  263. X    (void) strcpy(two, "x-y");
  264. X    equal(strtok(two, "-"), "x", 11);    /* New string before done. */
  265. X    equal(strtok((char *)NULL, "-"), "y", 12);
  266. X    check(strtok((char *)NULL, "-") == NULL, 13);
  267. X    (void) strcpy(one, "a,b, c,, ,d");
  268. X    equal(strtok(one, ", "), "a", 14);    /* Different separators. */
  269. X    equal(strtok((char *)NULL, ", "), "b", 15);
  270. X    equal(strtok((char *)NULL, " ,"), "c", 16);    /* Permute list too. */
  271. X    equal(strtok((char *)NULL, " ,"), "d", 17);
  272. X    check(strtok((char *)NULL, ", ") == NULL, 18);
  273. X    check(strtok((char *)NULL, ", ") == NULL, 19);    /* Persistence. */
  274. X    (void) strcpy(one, ", ");
  275. X    check(strtok(one, ", ") == NULL, 20);    /* No tokens. */
  276. X    (void) strcpy(one, "");
  277. X    check(strtok(one, ", ") == NULL, 21);    /* Empty string. */
  278. X    (void) strcpy(one, "abc");
  279. X    equal(strtok(one, ", "), "abc", 22);    /* No delimiters. */
  280. X    check(strtok((char *)NULL, ", ") == NULL, 23);
  281. X    (void) strcpy(one, "abc");
  282. X    equal(strtok(one, ""), "abc", 24);    /* Empty delimiter list. */
  283. X    check(strtok((char *)NULL, "") == NULL, 25);
  284. X    (void) strcpy(one, "abcdefgh");
  285. X    (void) strcpy(one, "a,b,c");
  286. X    equal(strtok(one, ","), "a", 26);    /* Basics again... */
  287. X    equal(strtok((char *)NULL, ","), "b", 27);
  288. X    equal(strtok((char *)NULL, ","), "c", 28);
  289. X    check(strtok((char *)NULL, ",") == NULL, 29);
  290. X    equal(one+6, "gh", 30);            /* Stomped past end? */
  291. X    equal(one, "a", 31);            /* Stomped old tokens? */
  292. X    equal(one+2, "b", 32);
  293. X    equal(one+4, "c", 33);
  294. X
  295. X    /*
  296. X     * memcmp
  297. X     */
  298. X    it = "memcmp";
  299. X    check(memcmp("a", "a", 1) == 0, 1);    /* Identity. */
  300. X    check(memcmp("abc", "abc", 3) == 0, 2);    /* Multicharacter. */
  301. X    check(memcmp("abcd", "abce", 4) < 0, 3);    /* Honestly unequal. */
  302. X    check(memcmp("abce", "abcd", 4) > 0, 4);
  303. X    check(memcmp("alph", "beta", 4) < 0, 5);
  304. X    if (charsigned)                /* Sign-bit comparison. */
  305. X        check(memcmp("a\203", "a\003", 2) < 0, 6);
  306. X    else
  307. X        check(memcmp("a\203", "a\003", 2) > 0, 6);
  308. X    check(memcmp("abce", "abcd", 3) == 0, 7);    /* Count limited. */
  309. X    check(memcmp("abc", "def", 0) == 0, 8);    /* Zero count. */
  310. X
  311. X    /*
  312. X     * memchr
  313. X     */
  314. X    it = "memchr";
  315. X    check(memchr("abcd", 'z', 4) == NULL, 1);    /* Not found. */
  316. X    (void) strcpy(one, "abcd");
  317. X    check(memchr(one, 'c', 4) == one+2, 2);    /* Basic test. */
  318. X    check(memchr(one, 'd', 4) == one+3, 3);    /* End of string. */
  319. X    check(memchr(one, 'a', 4) == one, 4);    /* Beginning. */
  320. X    check(memchr(one, '\0', 5) == one+4, 5);    /* Finding NUL. */
  321. X    (void) strcpy(one, "ababa");
  322. X    check(memchr(one, 'b', 5) == one+1, 6);    /* Finding first. */
  323. X    check(memchr(one, 'b', 0) == NULL, 7);    /* Zero count. */
  324. X    check(memchr(one, 'a', 1) == one, 8);    /* Singleton case. */
  325. X    (void) strcpy(one, "a\203b");
  326. X    check(memchr(one, 0203, 3) == one+1, 9);    /* Unsignedness. */
  327. X
  328. X    /*
  329. X     * memcpy
  330. X     *
  331. X     * Note that X3J11 says memcpy must work regardless of overlap.
  332. X     * The SVID says it might fail.
  333. X     */
  334. X    it = "memcpy";
  335. X    check(memcpy(one, "abc", 4) == one, 1);    /* Returned value. */
  336. X    equal(one, "abc", 2);            /* Did the copy go right? */
  337. X
  338. X    (void) strcpy(one, "abcdefgh");
  339. X    (void) memcpy(one+1, "xyz", 2);
  340. X    equal(one, "axydefgh", 3);        /* Basic test. */
  341. X
  342. X    (void) strcpy(one, "abc");
  343. X    (void) memcpy(one, "xyz", 0);
  344. X    equal(one, "abc", 4);            /* Zero-length copy. */
  345. X
  346. X    (void) strcpy(one, "hi there");
  347. X    (void) strcpy(two, "foo");
  348. X    (void) memcpy(two, one, 9);
  349. X    equal(two, "hi there", 5);        /* Just paranoia. */
  350. X    equal(one, "hi there", 6);        /* Stomped on source? */
  351. X
  352. X    (void) strcpy(one, "abcdefgh");
  353. X    (void) memcpy(one+1, one, 9);
  354. X    equal(one, "aabcdefgh", 7);        /* Overlap, right-to-left. */
  355. X
  356. X    (void) strcpy(one, "abcdefgh");
  357. X    (void) memcpy(one+1, one+2, 7);
  358. X    equal(one, "acdefgh", 8);        /* Overlap, left-to-right. */
  359. X
  360. X    (void) strcpy(one, "abcdefgh");
  361. X    (void) memcpy(one, one, 9);
  362. X    equal(one, "abcdefgh", 9);        /* 100% overlap. */
  363. X
  364. X    /*
  365. X     * memccpy - first test like memcpy, then the search part
  366. X     *
  367. X     * The SVID, the only place where memccpy is mentioned, says
  368. X     * overlap might fail, so we don't try it.  Besides, it's hard
  369. X     * to see the rationale for a non-left-to-right memccpy.
  370. X     */
  371. X    it = "memccpy";
  372. X    check(memccpy(one, "abc", 'q', 4) == NULL, 1);    /* Returned value. */
  373. X    equal(one, "abc", 2);            /* Did the copy go right? */
  374. X
  375. X    (void) strcpy(one, "abcdefgh");
  376. X    (void) memccpy(one+1, "xyz", 'q', 2);
  377. X    equal(one, "axydefgh", 3);        /* Basic test. */
  378. X
  379. X    (void) strcpy(one, "abc");
  380. X    (void) memccpy(one, "xyz", 'q', 0);
  381. X    equal(one, "abc", 4);            /* Zero-length copy. */
  382. X
  383. X    (void) strcpy(one, "hi there");
  384. X    (void) strcpy(two, "foo");
  385. X    (void) memccpy(two, one, 'q', 9);
  386. X    equal(two, "hi there", 5);        /* Just paranoia. */
  387. X    equal(one, "hi there", 6);        /* Stomped on source? */
  388. X
  389. X    (void) strcpy(one, "abcdefgh");
  390. X    (void) strcpy(two, "horsefeathers");
  391. X    check(memccpy(two, one, 'f', 9) == two+6, 7);    /* Returned value. */
  392. X    equal(one, "abcdefgh", 8);        /* Source intact? */
  393. X    equal(two, "abcdefeathers", 9);        /* Copy correct? */
  394. X
  395. X    (void) strcpy(one, "abcd");
  396. X    (void) strcpy(two, "bumblebee");
  397. X    check(memccpy(two, one, 'a', 4) == two+1, 10);    /* First char. */
  398. X    equal(two, "aumblebee", 11);
  399. X    check(memccpy(two, one, 'd', 4) == two+4, 12);    /* Last char. */
  400. X    equal(two, "abcdlebee", 13);
  401. X    (void) strcpy(one, "xyz");
  402. X    check(memccpy(two, one, 'x', 1) == two+1, 14);    /* Singleton. */
  403. X    equal(two, "xbcdlebee", 15);
  404. X
  405. X    /*
  406. X     * memset
  407. X     */
  408. X    it = "memset";
  409. X    (void) strcpy(one, "abcdefgh");
  410. X    check(memset(one+1, 'x', 3) == one+1, 1);    /* Return value. */
  411. X    equal(one, "axxxefgh", 2);        /* Basic test. */
  412. X
  413. X    (void) memset(one+2, 'y', 0);
  414. X    equal(one, "axxxefgh", 3);        /* Zero-length set. */
  415. X
  416. X    (void) memset(one+5, 0, 1);
  417. X    equal(one, "axxxe", 4);            /* Zero fill. */
  418. X    equal(one+6, "gh", 5);            /* And the leftover. */
  419. X
  420. X    (void) memset(one+2, 010045, 1);
  421. X    equal(one, "ax\045xe", 6);        /* Unsigned char convert. */
  422. X
  423. X    /*
  424. X     * bcopy - much like memcpy
  425. X     *
  426. X     * Berklix manual is silent about overlap, so don't test it.
  427. X     */
  428. X    it = "bcopy";
  429. X    (void) bcopy("abc", one, 4);
  430. X    equal(one, "abc", 1);            /* Simple copy. */
  431. X
  432. X    (void) strcpy(one, "abcdefgh");
  433. X    (void) bcopy("xyz", one+1, 2);
  434. X    equal(one, "axydefgh", 2);        /* Basic test. */
  435. X
  436. X    (void) strcpy(one, "abc");
  437. X    (void) bcopy("xyz", one, 0);
  438. X    equal(one, "abc", 3);            /* Zero-length copy. */
  439. X
  440. X    (void) strcpy(one, "hi there");
  441. X    (void) strcpy(two, "foo");
  442. X    (void) bcopy(one, two, 9);
  443. X    equal(two, "hi there", 4);        /* Just paranoia. */
  444. X    equal(one, "hi there", 5);        /* Stomped on source? */
  445. X
  446. X    /*
  447. X     * bzero
  448. X     */
  449. X    it = "bzero";
  450. X    (void) strcpy(one, "abcdef");
  451. X    bzero(one+2, 2);
  452. X    equal(one, "ab", 1);            /* Basic test. */
  453. X    equal(one+3, "", 2);
  454. X    equal(one+4, "ef", 3);
  455. X
  456. X    (void) strcpy(one, "abcdef");
  457. X    bzero(one+2, 0);
  458. X    equal(one, "abcdef", 4);        /* Zero-length copy. */
  459. X
  460. X    /*
  461. X     * bcmp - somewhat like memcmp
  462. X     */
  463. X    it = "bcmp";
  464. X    check(bcmp("a", "a", 1) == 0, 1);    /* Identity. */
  465. X    check(bcmp("abc", "abc", 3) == 0, 2);    /* Multicharacter. */
  466. X    check(bcmp("abcd", "abce", 4) != 0, 3);    /* Honestly unequal. */
  467. X    check(bcmp("abce", "abcd", 4) != 0, 4);
  468. X    check(bcmp("alph", "beta", 4) != 0, 5);
  469. X    check(bcmp("abce", "abcd", 3) == 0, 6);    /* Count limited. */
  470. X    check(bcmp("abc", "def", 0) == 0, 8);    /* Zero count. */
  471. X
  472. #ifdef ERR
  473. X    /*
  474. X     * strerror - VERY system-dependent
  475. X     */
  476. X    it = "strerror";
  477. X    f = open("/", 1);    /* Should always fail. */
  478. X    check(f < 0 && errno > 0 && errno < sys_nerr, 1);
  479. X    equal(strerror(errno), sys_errlist[errno], 2);
  480. #ifdef UNIXERR
  481. X    equal(strerror(errno), "Is a directory", 3);
  482. #endif
  483. #ifdef BERKERR
  484. X    equal(strerror(errno), "Permission denied", 3);
  485. #endif
  486. #endif
  487. }
  488. SHAR_EOF
  489. chmod 0640 dmake/dbug/malloc/testmem.c ||
  490. echo 'restore of dmake/dbug/malloc/testmem.c failed'
  491. Wc_c="`wc -c < 'dmake/dbug/malloc/testmem.c'`"
  492. test 20192 -eq "$Wc_c" ||
  493.     echo 'dmake/dbug/malloc/testmem.c: original size 20192, current size' "$Wc_c"
  494. rm -f _shar_wnt_.tmp
  495. fi
  496. # ============= dmake/dbug/malloc/testmlc.c ==============
  497. if test -f 'dmake/dbug/malloc/testmlc.c' -a X"$1" != X"-c"; then
  498.     echo 'x - skipping dmake/dbug/malloc/testmlc.c (File already exists)'
  499.     rm -f _shar_wnt_.tmp
  500. else
  501. > _shar_wnt_.tmp
  502. sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/testmlc.c' &&
  503. /* NOT copyright by SoftQuad Inc. -- msb, 1988 */
  504. #ifndef lint
  505. static char *SQ_SccsId = "@(#)mtest3.c    1.2 88/08/25";
  506. #endif
  507. #include <stdio.h>
  508. /*
  509. ** looptest.c -- intensive allocator tester 
  510. **
  511. ** Usage:  looptest
  512. **
  513. ** History:
  514. **    4-Feb-1987 rtech!daveb 
  515. */
  516. X
  517. # ifdef SYS5
  518. # define random    rand
  519. # else
  520. # include <sys/vadvise.h>
  521. # endif
  522. X
  523. # include <stdio.h>
  524. # include <signal.h>
  525. # include <setjmp.h>
  526. X
  527. # define MAXITER    1000000        /* main loop iterations */
  528. # define MAXOBJS    1000        /* objects in pool */
  529. # define BIGOBJ        90000        /* max size of a big object */
  530. # define TINYOBJ    80        /* max size of a small object */
  531. # define BIGMOD        100        /* 1 in BIGMOD is a BIGOBJ */
  532. # define STATMOD    10000        /* interation interval for status */
  533. X
  534. main( argc, argv )
  535. int argc;
  536. char **argv;
  537. {
  538. X    register int **objs;        /* array of objects */
  539. X    register int *sizes;        /* array of object sizes */
  540. X    register int n;            /* iteration counter */
  541. X    register int i;            /* object index */
  542. X    register int size;        /* object size */
  543. X    register int r;            /* random number */
  544. X
  545. X    int objmax;            /* max size this iteration */
  546. X    int cnt;            /* number of allocated objects */
  547. X    int nm = 0;            /* number of mallocs */
  548. X    int nre = 0;            /* number of reallocs */
  549. X    int nal;            /* number of allocated objects */
  550. X    int nfre;            /* number of free list objects */
  551. X    long alm;            /* memory in allocated objects */
  552. X    long frem;            /* memory in free list */
  553. X    long startsize;            /* size at loop start */
  554. X    long endsize;            /* size at loop exit */
  555. X    long maxiter = 0;        /* real max # iterations */
  556. X
  557. X    extern char end;        /* memory before heap */
  558. X    char *calloc();
  559. X    char *malloc();
  560. X    char *sbrk();
  561. X    long atol();
  562. X
  563. # ifndef SYS5
  564. X    /* your milage may vary... */
  565. X    vadvise( VA_ANOM );
  566. # endif
  567. X
  568. X    if (argc > 1)
  569. X        maxiter = atol (argv[1]);
  570. X    if (maxiter <= 0)
  571. X        maxiter = MAXITER;
  572. X
  573. X    printf("MAXITER %d MAXOBJS %d ", maxiter, MAXOBJS );
  574. X    printf("BIGOBJ %d, TINYOBJ %d, nbig/ntiny 1/%d\n",
  575. X    BIGOBJ, TINYOBJ, BIGMOD );
  576. X    fflush( stdout );
  577. X
  578. X    if( NULL == (objs = (int **)calloc( MAXOBJS, sizeof( *objs ) ) ) )
  579. X    {
  580. X        fprintf(stderr, "Can't allocate memory for objs array\n");
  581. X        exit(1);
  582. X    }
  583. X
  584. X    if( NULL == ( sizes = (int *)calloc( MAXOBJS, sizeof( *sizes ) ) ) )
  585. X    {
  586. X        fprintf(stderr, "Can't allocate memory for sizes array\n");
  587. X        exit(1);
  588. X    }
  589. X
  590. X    /* as per recent discussion on net.lang.c, calloc does not 
  591. X    ** necessarily fill in NULL pointers...
  592. X    */
  593. X    for( i = 0; i < MAXOBJS; i++ )
  594. X        objs[ i ] = NULL;
  595. X
  596. X    startsize = sbrk(0) - &end;
  597. X    printf( "Memory use at start: %d bytes\n", startsize );
  598. X    fflush(stdout);
  599. X
  600. X    printf("Starting the test...\n");
  601. X    fflush(stdout);
  602. X    for( n = 0; n < maxiter ; n++ )
  603. X    {
  604. X        if( !(n % STATMOD) )
  605. X        {
  606. X            printf("%d iterations\n", n);
  607. X            fflush(stdout);
  608. X        }
  609. X
  610. X        /* determine object of interst and it's size */
  611. X
  612. X        r = random();
  613. X        objmax = ( r % BIGMOD ) ? TINYOBJ : BIGOBJ;
  614. X        size = r % objmax;
  615. X        i = r % (MAXOBJS - 1);
  616. X
  617. X        /* either replace the object of get a new one */
  618. X
  619. X        if( objs[ i ] == NULL )
  620. X        {
  621. X            objs[ i ] = (int *)malloc( size );
  622. X            nm++;
  623. X        }
  624. X        else
  625. X        {
  626. X            /* don't keep bigger objects around */
  627. X            if( size > sizes[ i ] )
  628. X            {
  629. X                objs[ i ] = (int *)realloc( objs[ i ], size );
  630. X                nre++;
  631. X            }
  632. X            else
  633. X            {
  634. X                free( objs[ i ] );
  635. X                objs[ i ] = (int *)malloc( size );
  636. X                nm++;
  637. X            }
  638. X        }
  639. X
  640. X        sizes[ i ] = size;
  641. X        if( objs[ i ] == NULL )
  642. X        {
  643. X            printf("\nCouldn't allocate %d byte object!\n", 
  644. X                size );
  645. X            break;
  646. X        }
  647. X    } /* for() */
  648. X
  649. X    printf( "\n" );
  650. X    cnt = 0;
  651. X    for( i = 0; i < MAXOBJS; i++ )
  652. X        if( objs[ i ] )
  653. X            cnt++;
  654. X
  655. X    printf( "Did %d iterations, %d objects, %d mallocs, %d reallocs\n",
  656. X        n, cnt, nm, nre );
  657. X    printf( "Memory use at end: %d bytes\n", sbrk(0) - &end );
  658. X    fflush( stdout );
  659. X
  660. X    /* free all the objects */
  661. X    for( i = 0; i < MAXOBJS; i++ )
  662. X        if( objs[ i ] != NULL )
  663. X            free( objs[ i ] );
  664. X
  665. X    endsize = sbrk(0) - &end;
  666. X    printf( "Memory use after free: %d bytes\n", endsize );
  667. X    fflush( stdout );
  668. X
  669. X    if( startsize != endsize )
  670. X        printf("startsize %d != endsize %d\n", startsize, endsize );
  671. X
  672. X    free( objs );
  673. X    free( sizes );
  674. X
  675. X    malloc_dump(2);
  676. X    exit( 0 );
  677. }
  678. X
  679. SHAR_EOF
  680. chmod 0640 dmake/dbug/malloc/testmlc.c ||
  681. echo 'restore of dmake/dbug/malloc/testmlc.c failed'
  682. Wc_c="`wc -c < 'dmake/dbug/malloc/testmlc.c'`"
  683. test 3971 -eq "$Wc_c" ||
  684.     echo 'dmake/dbug/malloc/testmlc.c: original size 3971, current size' "$Wc_c"
  685. rm -f _shar_wnt_.tmp
  686. fi
  687. # ============= dmake/dbug/malloc/tostring.c ==============
  688. if test -f 'dmake/dbug/malloc/tostring.c' -a X"$1" != X"-c"; then
  689.     echo 'x - skipping dmake/dbug/malloc/tostring.c (File already exists)'
  690.     rm -f _shar_wnt_.tmp
  691. else
  692. > _shar_wnt_.tmp
  693. sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/tostring.c' &&
  694. /*
  695. X * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  696. X * You may copy, distribute, and use this software as long as this
  697. X * copyright statement is not removed.
  698. X */
  699. #include "tostring.h"
  700. X
  701. /*
  702. X * Function:    tostring()
  703. X *
  704. X * Purpose:    to convert an integer to an ascii display string
  705. X *
  706. X * Arguments:    buf    - place to put the 
  707. X *        val    - integer to convert
  708. X *        len    - length of output field (0 if just enough to hold data)
  709. X *        base    - base for number conversion (only works for base <= 16)
  710. X *        fill    - fill char when len > # digits
  711. X *
  712. X * Returns:    length of string
  713. X *
  714. X * Narrative:    IF fill character is non-blank
  715. X *            Determine base
  716. X *                If base is HEX
  717. X *                    add "0x" to begining of string
  718. X *                IF base is OCTAL
  719. X *                    add "0" to begining of string
  720. X *
  721. X *        While value is greater than zero
  722. X *            use val % base as index into xlation str to get cur char
  723. X *            divide val by base
  724. X *
  725. X *        Determine fill-in length
  726. X *
  727. X *        Fill in fill chars
  728. X *
  729. X *        Copy in number
  730. X *        
  731. X *
  732. X * Mod History:    
  733. X *   90/01/24    cpcahil        Initial revision.
  734. X */
  735. X
  736. #ifndef lint
  737. static
  738. char rcs_hdr[] = "$Id: tostring.c,v 1.4 90/05/11 00:13:11 cpcahil Exp $";
  739. #endif
  740. X
  741. #define T_LEN 10
  742. X
  743. int
  744. tostring(buf,val,len,base,fill)
  745. X    int      base;
  746. X    char    * buf;
  747. X    char      fill;
  748. X    int      len;
  749. X    int      val;
  750. X    
  751. {
  752. X    char    * bufstart = buf;
  753. X    int      i = T_LEN;
  754. X    char    * xbuf = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  755. X    char      tbuf[T_LEN];
  756. X
  757. X    /*
  758. X     * if we are filling with non-blanks, make sure the
  759. X     * proper start string is added
  760. X     */
  761. X    if( fill != ' ' )
  762. X    {
  763. X        switch(base)
  764. X        {
  765. X            case B_HEX:
  766. X                *(buf++) = '0';
  767. X                *(buf++) = 'x';
  768. X                if( len )
  769. X                {
  770. X                    len -= 2;
  771. X                }
  772. X                break;
  773. X            case B_OCTAL:
  774. X                *(buf++) = fill;
  775. X                if( len )
  776. X                {
  777. X                    len--;
  778. X                }
  779. X                break;
  780. X            default:
  781. X                break;
  782. X        }
  783. X    }
  784. X
  785. X    while( val > 0 )
  786. X    {
  787. X        tbuf[--i] = xbuf[val % base];
  788. X        val = val / base;
  789. X    }
  790. X
  791. X    if( len )
  792. X    {
  793. X        len -= (T_LEN - i);
  794. X
  795. X        if( len > 0 )
  796. X        {
  797. X            while(len-- > 0)
  798. X            {
  799. X                *(buf++) = fill;
  800. X            }
  801. X        }
  802. X        else
  803. X        {
  804. X            /* 
  805. X             * string is too long so we must truncate
  806. X             * off some characters.  We do this the easiest
  807. X             * way by just incrementing i.  This means the
  808. X             * most significant digits are lost.
  809. X             */
  810. X            while( len++ < 0 )
  811. X            {
  812. X                i++;
  813. X            }
  814. X        }
  815. X    }
  816. X
  817. X    while( i < T_LEN )
  818. X    {
  819. X        *(buf++) = tbuf[i++];
  820. X    }
  821. X
  822. X    return( (int) (buf - bufstart) );
  823. X
  824. } /* tostring(... */
  825. X
  826. /*
  827. X * $Log:    tostring.c,v $
  828. X * Revision 1.4  90/05/11  00:13:11  cpcahil
  829. X * added copyright statment
  830. X * 
  831. X * Revision 1.3  90/02/24  21:50:33  cpcahil
  832. X * lots of lint fixes
  833. X * 
  834. X * Revision 1.2  90/02/24  17:29:42  cpcahil
  835. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  836. X * id string
  837. X * 
  838. X * Revision 1.1  90/02/22  23:17:44  cpcahil
  839. X * Initial revision
  840. X * 
  841. X */
  842. SHAR_EOF
  843. chmod 0640 dmake/dbug/malloc/tostring.c ||
  844. echo 'restore of dmake/dbug/malloc/tostring.c failed'
  845. Wc_c="`wc -c < 'dmake/dbug/malloc/tostring.c'`"
  846. test 2716 -eq "$Wc_c" ||
  847.     echo 'dmake/dbug/malloc/tostring.c: original size 2716, current size' "$Wc_c"
  848. rm -f _shar_wnt_.tmp
  849. fi
  850. # ============= dmake/dbug/malloc/tostring.h ==============
  851. if test -f 'dmake/dbug/malloc/tostring.h' -a X"$1" != X"-c"; then
  852.     echo 'x - skipping dmake/dbug/malloc/tostring.h (File already exists)'
  853.     rm -f _shar_wnt_.tmp
  854. else
  855. > _shar_wnt_.tmp
  856. sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/tostring.h' &&
  857. /*
  858. X * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  859. X * You may copy, distribute, and use this software as long as this
  860. X * copyright statement is not removed.
  861. X */
  862. /*
  863. X * $Id: tostring.h,v 1.2 90/05/11 00:13:11 cpcahil Exp $
  864. X */
  865. #define B_BIN     2
  866. #define B_DEC    10
  867. #define B_HEX    16
  868. #define B_OCTAL     8
  869. X
  870. /* 
  871. X * $Log:    tostring.h,v $
  872. X * Revision 1.2  90/05/11  00:13:11  cpcahil
  873. X * added copyright statment
  874. X * 
  875. X * Revision 1.1  90/02/23  07:09:05  cpcahil
  876. X * Initial revision
  877. X * 
  878. X */
  879. SHAR_EOF
  880. chmod 0640 dmake/dbug/malloc/tostring.h ||
  881. echo 'restore of dmake/dbug/malloc/tostring.h failed'
  882. Wc_c="`wc -c < 'dmake/dbug/malloc/tostring.h'`"
  883. test 491 -eq "$Wc_c" ||
  884.     echo 'dmake/dbug/malloc/tostring.h: original size 491, current size' "$Wc_c"
  885. rm -f _shar_wnt_.tmp
  886. fi
  887. # ============= dmake/dmake.c ==============
  888. if test -f 'dmake/dmake.c' -a X"$1" != X"-c"; then
  889.     echo 'x - skipping dmake/dmake.c (File already exists)'
  890.     rm -f _shar_wnt_.tmp
  891. else
  892. > _shar_wnt_.tmp
  893. sed 's/^X//' << 'SHAR_EOF' > 'dmake/dmake.c' &&
  894. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/dmake.c,v 1.1 91/05/06 15:23:06 dvadura Exp $
  895. -- SYNOPSIS -- The main program.
  896. -- 
  897. -- DESCRIPTION
  898. -- 
  899. --     dmake [-#dbug_string] [ options ]
  900. --             [ macro definitions ] [ target ... ]
  901. -- 
  902. --     This file contains the main command line parser for the
  903. --     make utility.  The valid flags recognized are as follows:
  904. -- 
  905. --     -f file         - use file as the makefile
  906. --    -C file        - duplicate console output to file (MSDOS only)
  907. --    -K file        - .KEEP_STATE file
  908. --     -#dbug_string   - dump out debugging info, see below
  909. --     -v{dfimt}    - verbose, print what we are doing, as we do it.
  910. -- 
  911. --      options: (can be catenated, ie -irn == -i -r -n)
  912. -- 
  913. --    -A        - enable AUGMAKE special target mapping
  914. --    -c        - use non-standard comment scanning
  915. --     -i              - ignore errors
  916. --     -n              - trace and print, do not execute commands
  917. --     -t              - touch, update dates without executing commands
  918. --     -T              - do not apply transitive closure
  919. --     -r              - don't use internal rules
  920. --     -s              - do your work silently
  921. --    -S        - force Sequential make, overrides -P
  922. --     -q              - check if target is up to date.  Does not
  923. --               do anything.  Returns 0 if up to date, -1
  924. --               otherwise.
  925. --     -p              - print out a version of the makefile
  926. --    -P#        - set value of MAXPROCESS
  927. --     -e              - define environment strings as macros
  928. --     -E              - as -e but done after parsing makefile
  929. --     -u              - force unconditional update of target
  930. --     -k              - make all independent targets even if errors
  931. --     -V              - print out this make version number
  932. --     -M        - Microsoft make compatibility, (* disabled *)
  933. --     -h              - print out usage info
  934. --     -x        - export macro defs to environment
  935. -- 
  936. --     NOTE:  - #ddbug_string is only availabe for versions of dmake that
  937. --         have been compiled with -DDBUG switch on.  Not the case for
  938. --         distributed versions.  Any such versions must be linked
  939. --         together with a version of Fred Fish's debug code.
  940. --              
  941. --     NOTE:  - in order to compile the code the include file stddef.h
  942. --         must be shipped with the bundled code.
  943. -- 
  944. -- AUTHOR
  945. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  946. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  947. --
  948. -- COPYRIGHT
  949. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  950. -- 
  951. --      This program is free software; you can redistribute it and/or
  952. --      modify it under the terms of the GNU General Public License
  953. --      (version 1), as published by the Free Software Foundation, and
  954. --      found in the file 'LICENSE' included with this distribution.
  955. -- 
  956. --      This program is distributed in the hope that it will be useful,
  957. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  958. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  959. --      GNU General Public License for more details.
  960. -- 
  961. --      You should have received a copy of the GNU General Public License
  962. --      along with this program;  if not, write to the Free Software
  963. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  964. --
  965. -- LOG
  966. --     $Log:    dmake.c,v $
  967. X * Revision 1.1  91/05/06  15:23:06  dvadura
  968. X * dmake Release Version 3.7
  969. X * 
  970. */
  971. X
  972. /* Set this flag to one, and the global variables in vextern.h will not
  973. X * be defined as 'extern', instead they will be defined as global vars
  974. X * when this module is compiled. */
  975. #define _DEFINE_GLOBALS_ 1
  976. X
  977. #include "extern.h"
  978. #include "patchlvl.h"
  979. #include "version.h"
  980. X
  981. #ifndef MSDOS
  982. #define USAGE \
  983. "Usage:\n%s [-AeEhiknpqrsStTuVx] [-v{dfimt}] [-P#] [-{f|K} file] [macro[*][+][:]=value ...] [target ...]\n"
  984. #else
  985. #define USAGE \
  986. "Usage:\n%s [-AeEhiknpqrsStTuVx] [-v{dfimt}] [-P#] [-{f|C|K} file] [macro[*][+][:]=value ...] [target ...]\n"
  987. #endif
  988. X
  989. static char *sccid = "Copyright (c) 1990,1991 by Dennis Vadura";
  990. static char _warn  = TRUE;        /* warnings on by default */
  991. X
  992. static    void    _do_VPATH();
  993. static    void    _do_ReadEnvironment();
  994. static  void    _do_f_flag ANSI((char, char *, char **));
  995. X
  996. PUBLIC int
  997. main(argc, argv)
  998. int  argc;
  999. char **argv;
  1000. {
  1001. #ifdef MSDOS
  1002. X   char*   std_fil_name = NIL(char);
  1003. #endif
  1004. X
  1005. X   char*   fil_name = NIL(char);
  1006. X   char*   state_name = NIL(char);
  1007. X   char*   cmdmacs;
  1008. X   char*   targets;
  1009. X   FILE*   mkfil;
  1010. X   int     ex_val;
  1011. X   int     m_export;
  1012. X
  1013. X   DB_ENTER("main");
  1014. X
  1015. X   /* Initialize Global variables to their default values       */
  1016. X   Prolog(argc, argv);
  1017. X   Create_macro_vars();
  1018. X   Catch_signals(Quit);
  1019. X
  1020. X   Def_macro( "MAKECMD", Pname, M_PRECIOUS|M_NOEXPORT );
  1021. X   Pname = basename(Pname);
  1022. X
  1023. X   DB_PROCESS(Pname);
  1024. X   (void) setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* stdout line buffered */
  1025. X
  1026. X   Continue  = FALSE;
  1027. X   Comment   = FALSE;
  1028. X   Get_env   = FALSE;
  1029. X   Force     = FALSE;
  1030. X   Target    = FALSE;
  1031. X   If_expand = FALSE;
  1032. X   Listing   = FALSE;
  1033. X   Readenv   = FALSE;
  1034. X   Rules     = TRUE;
  1035. X   Trace     = FALSE;
  1036. X   Touch     = FALSE;
  1037. X   Check     = FALSE;
  1038. X   Microsoft = FALSE;
  1039. X   Makemkf   = FALSE;
  1040. X   m_export  = FALSE;
  1041. X   cmdmacs   = NIL(char);
  1042. X   targets   = NIL(char);
  1043. X
  1044. X   Verbose     = V_NONE;
  1045. X   Transitive  = TRUE;
  1046. X   Nest_level  = 0;
  1047. X   Line_number = 0;
  1048. X   Suppress_temp_file = FALSE;
  1049. X
  1050. X   while( --argc > 0 ) {
  1051. X      register char *p;
  1052. X      char *q;
  1053. X
  1054. X      if( *(p = *++argv) == '-' ) {
  1055. X         if( p[1] == '\0' ) Fatal("Missing option letter");
  1056. X
  1057. X         /* copy options to Buffer for $(MFLAGS), strip 'f' and 'C'*/
  1058. X         q = strchr(Buffer, '\0');
  1059. X         while (*p != '\0') {
  1060. X        char c = (*q++ = *p++);
  1061. X            if( c == 'f' || c == 'C' ) q--;
  1062. X     }
  1063. X
  1064. X     if( *(q-1) == '-' )
  1065. X        q--;
  1066. X     else
  1067. X            *q++ = ' ';
  1068. X
  1069. X     *q = '\0';
  1070. X
  1071. X         for( p = *argv+1; *p; p++) switch (*p) {
  1072. X        case 'f':
  1073. X           _do_f_flag( 'f', *++argv, &fil_name ); argc--;
  1074. X           break;
  1075. X
  1076. #ifdef MSDOS
  1077. X        case 'C':
  1078. X           _do_f_flag( 'C', *++argv, &std_fil_name ); argc--;
  1079. X           Hook_std_writes( std_fil_name );
  1080. X           break;
  1081. #endif
  1082. X
  1083. X        case 'K':
  1084. X           _do_f_flag( 'K', *++argv, &state_name ); argc--;
  1085. X           Def_macro(".KEEP_STATE", state_name, M_EXPANDED|M_PRECIOUS);
  1086. X           break;
  1087. X
  1088. X        case 'k': Continue   = TRUE;  break;
  1089. X        case 'c': Comment    = TRUE;  break;
  1090. X        case 'p': Listing    = TRUE;  break;
  1091. X        case 'r': Rules      = FALSE; break;
  1092. X        case 'n': Trace      = TRUE;  break;
  1093. X        case 't': Touch      = TRUE;  break;
  1094. X        case 'q': Check      = TRUE;  break;
  1095. X        case 'u': Force      = TRUE;  break;
  1096. X        case 'x': m_export   = TRUE;  break;
  1097. X        case 'T': Transitive = FALSE; break;
  1098. X        case 'e': Get_env    = 'e';   break;
  1099. X        case 'E': Get_env    = 'E';   break;
  1100. X
  1101. X        case 'V': Version();  Quit(NIL(CELL));  break;
  1102. X        case 'A': Def_macro("AUGMAKE", "y", M_EXPANDED); break;
  1103. X        case 'i': Def_macro(".IGNORE", "y", M_EXPANDED); break;
  1104. X        case 's': Def_macro(".SILENT", "y", M_EXPANDED); break;
  1105. X        case 'S': Def_macro(".SEQUENTIAL", "y", M_EXPANDED); break;
  1106. X
  1107. X        case 'v':
  1108. X           if( p[-1] != '-' ) Usage(TRUE);
  1109. X           while( p[1] ) switch( *++p ) {
  1110. X          case 'd': Verbose |= V_PRINT_DIR; break;
  1111. X          case 'f': Verbose |= V_FILE_IO;   break;
  1112. X          case 'i': Verbose |= V_INFER;     break;
  1113. X          case 'm': Verbose |= V_MAKE;      break;
  1114. X          case 't': Verbose |= V_LEAVE_TMP; break;
  1115. X
  1116. X          default: Usage(TRUE); break;
  1117. X           }
  1118. X           if( !Verbose ) Verbose = V_ALL;
  1119. X           break;
  1120. X
  1121. X        case 'P':
  1122. X           if( p[1] ) {
  1123. X          Def_macro( "MAXPROCESS", p+1, M_MULTI|M_EXPANDED );
  1124. X          p += strlen(p)-1;
  1125. X           }
  1126. X           else
  1127. X          Fatal( "Missing number for -P flag" );
  1128. X           break;
  1129. X
  1130. #ifdef DBUG
  1131. X        case '#':
  1132. X           DB_PUSH(p+1);
  1133. X           p += strlen(p)-1;
  1134. X           break;
  1135. #endif
  1136. X
  1137. X        case 'h': Usage(FALSE); break;
  1138. X        default:  Usage(TRUE);  break;
  1139. X     }
  1140. X      }
  1141. X      else if( (q = strchr(p, '=')) != NIL(char) ) {
  1142. X     cmdmacs = _stradd( cmdmacs, _strdup(p), TRUE );
  1143. X     Parse_macro( p, (q[-1]!='+')?M_PRECIOUS:M_DEFAULT );
  1144. X      }
  1145. X      else {
  1146. X     register CELLPTR cp;
  1147. X     targets = _stradd( targets, _strdup(p), TRUE );
  1148. X     Add_prerequisite(Root, cp = Def_cell(p), FALSE, FALSE);
  1149. X     cp->ce_flag |= F_TARGET;
  1150. X     cp->ce_attr |= A_FRINGE;
  1151. X     Target = TRUE;
  1152. X      }
  1153. X   }
  1154. X
  1155. X   Def_macro( "MAKEMACROS",  cmdmacs, M_PRECIOUS|M_NOEXPORT );
  1156. X   Def_macro( "MAKETARGETS", targets, M_PRECIOUS|M_NOEXPORT );
  1157. X   if( cmdmacs != NIL(char) ) FREE(cmdmacs);
  1158. X   if( targets != NIL(char) ) FREE(targets);
  1159. X
  1160. X   Def_macro( "MFLAGS", Buffer, M_PRECIOUS|M_NOEXPORT );
  1161. X   Def_macro( "%", "$@", M_PRECIOUS|M_NOEXPORT );
  1162. X
  1163. X   if( *Buffer ) Def_macro( "MAKEFLAGS", Buffer+1, M_PRECIOUS|M_NOEXPORT );
  1164. X
  1165. X   _warn  = FALSE;      /* disable warnings for builtin rules */
  1166. X   ex_val = Target;     /* make sure we don't mark any        */
  1167. X   Target = TRUE;       /* of the default rules as            */
  1168. X   Make_rules();        /* potential targets                  */
  1169. X   _warn = TRUE;
  1170. X
  1171. X   if( Rules ) {
  1172. X      char *fname;
  1173. X
  1174. X      if( (mkfil=Search_file("MAKESTARTUP", &fname)) != NIL(FILE) ) {
  1175. X         Parse(mkfil);
  1176. X         mkfil = NIL(FILE);
  1177. X      }
  1178. X      else
  1179. X         Fatal( "Configuration file `%s' not found", fname );
  1180. X   }
  1181. X
  1182. X   Target = ex_val;
  1183. X
  1184. X   if( Get_env == 'e' ) _do_ReadEnvironment();
  1185. X
  1186. X   if( fil_name != NIL(char) )
  1187. X      mkfil = Openfile( fil_name, FALSE, TRUE );
  1188. X   else {
  1189. X      /* Search .MAKEFILES dependent list looking for a makefile.
  1190. X       */
  1191. X      register CELLPTR cp;
  1192. X      register LINKPTR lp;
  1193. X
  1194. X      cp = Def_cell( ".MAKEFILES" );
  1195. X
  1196. X      if( (lp = cp->CE_PRQ) != NIL(LINK) ) {
  1197. X         int s_n, s_t, s_q;
  1198. X
  1199. X         s_n = Trace;
  1200. X         s_t = Touch;
  1201. X         s_q = Check;
  1202. X
  1203. X         Trace = Touch = Check = FALSE;
  1204. X         Makemkf = Wait_for_completion = TRUE;
  1205. X         mkfil = NIL(FILE);
  1206. X
  1207. X         for(;  lp != NIL(LINK) && mkfil == NIL(FILE); lp=lp->cl_next) {
  1208. X        if( lp->cl_prq->ce_attr & A_FRINGE ) continue;
  1209. X
  1210. X            mkfil = Openfile( lp->cl_prq->CE_NAME, FALSE, FALSE );
  1211. X
  1212. X            if( mkfil == NIL(FILE) &&
  1213. X        Make(lp->cl_prq, lp, NIL(CELL)) != -1 )
  1214. X               mkfil = Openfile( lp->cl_prq->CE_NAME, FALSE, FALSE );
  1215. X         }
  1216. X
  1217. X         Trace = s_n;
  1218. X         Touch = s_t;
  1219. X         Check = s_q;
  1220. X         Makemkf = Wait_for_completion = FALSE;
  1221. X      }
  1222. X   }
  1223. X
  1224. X   if( mkfil != NIL(FILE) ) {
  1225. X      char *f = Filename();
  1226. X      char *p;
  1227. X
  1228. X      if( strcmp(f, "stdin") == 0 ) f = "-";
  1229. X      p = _stradd( "-f", f, FALSE );
  1230. X      Def_macro( "MAKEFILE", p, M_PRECIOUS|M_NOEXPORT );
  1231. X      Parse( mkfil );
  1232. X   }
  1233. X   else if( !Rules )
  1234. X      Fatal( "No `makefile' present" );
  1235. X
  1236. X   if( Nest_level     ) Fatal( "Missing .END for .IF" );
  1237. X   if( Get_env == 'E' ) _do_ReadEnvironment();
  1238. X
  1239. X   _do_VPATH();                  /* kludge it up with .SOURCE    */
  1240. X
  1241. X   if( Listing ) Dump();        /* print out the structures     */
  1242. X   if( Trace ) Glob_attr &= ~A_SILENT;    /* make sure we see the trace   */
  1243. X
  1244. X   if( !Target )
  1245. X      Fatal( "No target" );
  1246. X   else {
  1247. X      Test_circle( Root, TRUE );
  1248. X      Check_circle_dfa();
  1249. X   }
  1250. X
  1251. X   Push_dir( Start_dir, ".SETDIR", (int)(Glob_attr & A_IGNORE ));
  1252. X
  1253. X   if( m_export ) {
  1254. X      int i;
  1255. X
  1256. X      for( i=0; i<HASH_TABLE_SIZE; ++i ) {
  1257. X     HASHPTR hp = Macs[i];
  1258. X         char *tmpstr = hp->ht_value;
  1259. X
  1260. X         if(    tmpstr != NIL(char)
  1261. X             && !(hp->ht_flag & M_NOEXPORT)
  1262. X         && Write_env_string(hp->ht_name, tmpstr) != 0 )
  1263. X            Warning( "Could not export %s", hp->ht_name );
  1264. X      }
  1265. X   }
  1266. X   if( Buffer != NIL(char) ) {FREE( Buffer ); Buffer = NIL(char);}
  1267. X   if( Trace ) Def_macro(".SEQUENTIAL", "y", M_EXPANDED);
  1268. X   if( Glob_attr & A_SEQ ) Def_macro( "MAXPROCESS", "1", M_EXPANDED|M_FORCE );
  1269. X
  1270. X   ex_val = Make_targets();
  1271. X
  1272. X   Pop_dir( (Glob_attr & A_IGNORE) != 0 );
  1273. X   Clear_signals();
  1274. X   Epilog(ex_val);      /* Does not return -- EVER */
  1275. }
  1276. X
  1277. X
  1278. static void
  1279. _do_f_flag( flag, name, fname )
  1280. char  flag;
  1281. char *name;
  1282. char **fname;
  1283. {
  1284. X   if( *fname == NIL(char) ) {
  1285. X      if( name != NIL(char) ) {
  1286. X     *fname = name;
  1287. X      } else
  1288. X     Fatal("No file name for -%c", flag);
  1289. X   } else
  1290. X      Fatal("Only one `-%c file' allowed", flag);
  1291. }
  1292. X
  1293. X
  1294. static void
  1295. _do_ReadEnvironment()
  1296. {
  1297. X   t_attr saveattr = Glob_attr;
  1298. X
  1299. X   Glob_attr |= A_SILENT;
  1300. X   ReadEnvironment();
  1301. X   Glob_attr = saveattr;
  1302. }
  1303. X
  1304. X
  1305. static void
  1306. _do_VPATH()
  1307. {
  1308. X   HASHPTR hp;
  1309. X   char    *_rl[2];
  1310. X   extern char **Rule_tab;
  1311. X
  1312. X   hp = GET_MACRO("VPATH");
  1313. X   if( hp == NIL(HASH) ) return;
  1314. X
  1315. X   _rl[0] = ".SOURCE :^ $(VPATH:s/:/ /)";
  1316. X   _rl[1] = NIL(char);
  1317. X
  1318. X   Rule_tab = _rl;
  1319. X   Parse( NIL(FILE) );
  1320. }
  1321. X
  1322. X
  1323. /*  The file table and pointer to the next FREE slot for use by both
  1324. X    Openfile and Closefile.  Each open stacks the new file onto the open
  1325. X    file stack, and a corresponding close will close the passed file, and
  1326. X    return the next file on the stack.  The maximum number of nested
  1327. X    include files is limited by the value of MAX_INC_DEPTH */
  1328. X
  1329. static struct {
  1330. X   FILE         *file;      /* file pointer                 */
  1331. X   char         *name;      /* name of file                 */
  1332. X   int          numb;       /* line number                  */
  1333. } ftab[ MAX_INC_DEPTH ];
  1334. X
  1335. static int next_file_slot = 0;
  1336. X
  1337. /* Set the proper macro value to reflect the depth of the .INCLUDE directives.
  1338. X */
  1339. static void
  1340. _set_inc_depth()
  1341. {
  1342. X   char buf[10];
  1343. X   sprintf( buf, "%d", next_file_slot-1 );
  1344. X   Def_macro( "INCDEPTH", buf, M_MULTI|M_NOEXPORT );
  1345. }
  1346. X
  1347. X
  1348. PUBLIC FILE *
  1349. Openfile(name, mode, err)/*
  1350. ===========================
  1351. X   This routine opens a file for input or output depending on mode.
  1352. X   If the file name is `-' then it returns standard input.
  1353. X   The file is pushed onto the open file stack.  */
  1354. char *name;
  1355. int  mode;
  1356. int  err;
  1357. {
  1358. X   FILE *fil;
  1359. X
  1360. X   DB_ENTER("Openfile");
  1361. X
  1362. X   if( name == NIL(char) || !*name )
  1363. X      if( !err )
  1364. X         DB_RETURN(NIL(FILE));
  1365. X      else
  1366. X         Fatal( "Openfile:  NIL filename" );
  1367. SHAR_EOF
  1368. true || echo 'restore of dmake/dmake.c failed'
  1369. fi
  1370. echo 'End of part 7, continue with part 8'
  1371. echo 8 > _shar_seq_.tmp
  1372. exit 0
  1373.  
  1374. exit 0 # Just in case...
  1375. -- 
  1376. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1377. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1378. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1379. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1380.