home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume14 / dmake / part03 < prev    next >
Text File  |  1990-07-26  |  40KB  |  1,488 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v14i013: dmake version 3.5 part 3/21
  3. From: dvadura@watdragon.waterloo.edu (Dennis Vadura)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 14, Issue 13
  7. Submitted-by: dvadura@watdragon.waterloo.edu (Dennis Vadura)
  8. Archive-name: dmake/part03
  9.  
  10. #!/bin/sh
  11. # this is part 3 of a multipart archive
  12. # do not concatenate these parts, unpack them in order with /bin/sh
  13. # file unix/arlib.c continued
  14. #
  15. CurArch=3
  16. if test ! -r s2_seq_.tmp
  17. then echo "Please unpack part 1 first!"
  18.      exit 1; fi
  19. ( read Scheck
  20.   if test "$Scheck" != $CurArch
  21.   then echo "Please unpack part $Scheck next!"
  22.        exit 1;
  23.   else exit 0; fi
  24. ) < s2_seq_.tmp || exit 1
  25. echo "x - Continuing file unix/arlib.c"
  26. sed 's/^X//' << 'SHAR_EOF' >> unix/arlib.c
  27. X   check to see if the specified lib is cached.  If so then return that time
  28. X   stamp instead of looking into the library. */
  29. Xchar    *name;
  30. Xchar     *lib;
  31. X{
  32. X   FILE   *f;
  33. X   int    rv;
  34. X   time_t mtime;
  35. X   struct ar_args args;
  36. X
  37. X   /* Check the cache first (if there is a cache) */
  38. X   if( _check_cache(name, lib, &mtime, FALSE) )  return( mtime );
  39. X
  40. X   /* Open the lib file and perform the scan of the members, looking
  41. X    * for our particular member.  If cacheing is enabled it will be
  42. X    * taken care of automatically during the scan. */
  43. X
  44. X   args.lib    = lib;
  45. X   args.member = name;
  46. X   args.time   = (time_t)0L;
  47. X
  48. X   if( (f = fopen(lib, "r")) == NIL(FILE) ) return( (time_t)0L );
  49. X   rv = ar_scan(f, time_function, &args );
  50. X   fclose( f );
  51. X
  52. X   if( rv < 0 ) Fatal("(%s): Invalid library format", lib);
  53. X
  54. X   return( args.time );
  55. X}
  56. X
  57. X
  58. Xint
  59. Xtouch_arch(name, lib)/*
  60. X=======================
  61. X   Look for module 'name' inside 'lib'.  If compiled with cacheing then first
  62. X   check to see if the specified lib is cached.  If so then set that time
  63. X   stamp and write it into the library.  Returns 0 on success, non-zero
  64. X   on failure. */
  65. Xchar   *name;
  66. Xchar   *lib;
  67. X{
  68. X   FILE   *f;
  69. X   int    rv;
  70. X   struct ar_args args;
  71. X
  72. X   /* Open the lib file and perform the scan of the members, looking
  73. X    * for our particular member.  If cacheing is enabled it will be
  74. X    * taken care of automatically during the scan. */
  75. X
  76. X   args.lib    = lib;
  77. X   args.member = name;
  78. X   args.time   = (time_t)0L;
  79. X
  80. X   if( (f = fopen(lib, "r+")) == NIL(FILE) ) return( (time_t)1L );
  81. X   rv = ar_scan(f, touch_function, &args );
  82. X   fclose( f );
  83. X
  84. X   if( rv < 0 ) Fatal("(%s): Invalid library format", lib);
  85. X
  86. X   return( 0 );
  87. X}
  88. X
  89. X
  90. X
  91. Xstatic int
  92. Xtime_function(f, arp, argp)/*
  93. X=============================
  94. X   get library member's time, if it matches than return it in argp, if
  95. X   cacheing is enabled than cache the library members also. */
  96. XFILE           *f;      /* library file          */
  97. Xstruct AR      *arp;    /* library member header */
  98. Xstruct ar_args *argp;
  99. X{
  100. X   int rv = _cache_member( arp->ar_name, argp->lib, arp->ar_time );
  101. X
  102. X   if( strcmp(argp->member, arp->ar_name) == 0 ) {
  103. X      argp->time = arp->ar_time;
  104. X
  105. X      if( arp->ar_time == 0 && !(Glob_attr & A_SILENT) )
  106. X         Warning( "(%s): Can't extract library member timestamp; using EPOCH",
  107. X              argp->member);
  108. X
  109. X      return( rv );  /* 1 => no cacheing, 0 => cacheing */
  110. X   }
  111. X
  112. X   return( FALSE ); /* continue scan */
  113. X}
  114. X
  115. X
  116. X
  117. Xstatic int
  118. Xtouch_function(f, arp, argp)/*
  119. X==============================
  120. X   Update library member's time stamp, and write new time value into cache
  121. X   if required. */
  122. XFILE           *f;      /* library file */
  123. Xstruct AR      *arp;    /* library member header */
  124. Xstruct ar_args *argp;
  125. X{
  126. X   extern time_t time ANSI(( time_t * ));
  127. X   time_t now = time((time_t*) NULL);  /* Current time.          */
  128. X
  129. X   if( strcmp(argp->member, arp->ar_name) == 0 ) {
  130. X      _check_cache( argp->member, argp->lib, &now, TRUE );
  131. X      ar_touch(f, now );
  132. X
  133. X      return( TRUE );
  134. X   }
  135. X
  136. X   return( FALSE ); /* continue scan */
  137. X}
  138. X
  139. X
  140. X
  141. X
  142. Xstatic int
  143. Xar_scan(f, function, arg)/*
  144. X===========================
  145. X   Scan the opened archive, and call the given function for each member found.
  146. X   The function will be called with the file positioned at the beginning of
  147. X   the member and it can read up to arp->ar_size bytes of the archive member.
  148. X   If the function returns 1, we stop and return 1.  We return 0 at the end
  149. X   of the archive, or -1 if the archive has invalid format.  This interface
  150. X   is more general than required by "make", but it can be used by other
  151. X   utilities.  */
  152. Xregister FILE *f;
  153. Xint      (*function) ANSI((FILE *, struct AR *, struct ar_args *));
  154. Xstruct ar_args *arg;
  155. X{
  156. X   extern long atol ANSI((char *));
  157. X   register char *p;
  158. X   struct ar_hdr arhdr;   /* external archive header */
  159. X   off_t         offset;  /* member seek offset      */
  160. X
  161. X#if ASCARCH
  162. X   char magic[SARMAG];
  163. X#else
  164. X   unsigned short word;
  165. X#endif
  166. X
  167. X   fseek( f, 0L, 0 );    /* Start at the beginning of the archive file */
  168. X
  169. X#if ASCARCH
  170. X   fread( magic, sizeof(magic), 1, f );
  171. X   if( strncmp(magic, ARMAG, SARMAG) != 0 ) return( -1 );
  172. X#else
  173. X   fread( (char*)&word, sizeof(word), 1, f );
  174. X   if( word != ARMAG ) return( -1 );
  175. X#endif
  176. X
  177. X   /* scan the library, calling `function' for each member
  178. X    */
  179. X   while( 1 ) {
  180. X      if( fread((char*) &arhdr, sizeof(arhdr), 1, f) != 1 ) break;
  181. X      offset = ftell(f);
  182. X      strncpy(_ar.ar_name, arhdr.ar_name, sizeof(arhdr.ar_name));
  183. X
  184. X      for( p = &_ar.ar_name[sizeof(arhdr.ar_name)];
  185. X           --p >= _ar.ar_name && *p == ' ';);
  186. X
  187. X      p[1] = '\0';
  188. X      if( *p == '/' ) *p = 0;     /* Only SysV has trailing '/' */
  189. X
  190. X#if ASCARCH
  191. X      if( strncmp(arhdr.ar_fmag, ARFMAG, sizeof(arhdr.ar_fmag)) != 0 )
  192. X         return( -1 );
  193. X      _ar.ar_time = atol(arhdr.ar_date);
  194. X      _ar.ar_size = atol(arhdr.ar_size);
  195. X#else
  196. X      _ar.ar_time = arhdr.ar_date;
  197. X      _ar.ar_size = atol(arhdr.ar_size);
  198. X#endif
  199. X
  200. X
  201. X#if DECODE_ALL_AR_FIELDS
  202. X#if ASCARCH
  203. X      _ar.ar_mode = atoi(arhdr.ar_mode);
  204. X      _ar.ar_uid  = atoi(arhdr.ar_uid);
  205. X      _ar.ar_gid  = atoi(arhdr.ar_gid);
  206. X#else
  207. X      _ar.ar_mode = arhdr.ar_mode;
  208. X      _ar.ar_size = arhdr.ar_size;
  209. X      _ar.ar_uid = arhdr.ar_uid;
  210. X      _ar.ar_gid = arhdr.ar_gid;
  211. X#endif
  212. X#endif
  213. X
  214. X      if( (*function)(f, &_ar, arg) ) return( 1 );
  215. X      fseek( f, offset + (_ar.ar_size+1 & ~1L), 0 );
  216. X   }
  217. X
  218. X   if( !feof(f) ) return( -1 );
  219. X   return 0;
  220. X}
  221. X
  222. X
  223. X
  224. Xstatic int
  225. Xar_touch( f, now )/*
  226. X====================
  227. X   touch module header timestamp. */
  228. XFILE   *f;
  229. Xtime_t now;
  230. X{
  231. X   struct ar_hdr arhdr;                /* external archive header */
  232. X
  233. X   fseek(f, - (off_t) (sizeof(arhdr) - sizeof(arhdr.ar_name)), 1);
  234. X
  235. X#if ASCARCH
  236. X   fprintf(f, "%lu", now);
  237. X#else
  238. X   fwrite((char *)now, sizeof(now), 1, f);
  239. X#endif
  240. X
  241. X   return( ferror(f) ? 0 : 1 );
  242. X}
  243. X
  244. X
  245. X#if LC
  246. Xtypedef struct mem {
  247. X   time_t    m_time;        /* modify time of member*/
  248. X   struct mem    *m_next;    /* next member in lib    */
  249. X   char        m_valid;    /* valid cache entry    */
  250. X   char     m_name[1];    /* lib member name    */
  251. X} MEM, *MEMPTR;
  252. X
  253. Xtypedef struct lib {
  254. X   struct lib    *lb_next;    /* next library in list */
  255. X   struct mem    *lb_members;    /* list of lib members    */
  256. X   char        lb_valid;    /* valid cache entry    */
  257. X   char     *lb_name;    /* library name        */
  258. X} LIB, *LIBPTR;
  259. X
  260. Xstatic LIBPTR _cache = NIL(LIB);
  261. Xstatic MEMPTR _find_member ANSI(( LIBPTR, char * ));
  262. X
  263. Xstatic int
  264. X_check_cache( name, lib, pmtime, touch )/*
  265. X==========================================
  266. X   Check to see if we have cached member in lib, if so return time in pmtime
  267. X   and return TRUE, otherwise return FALSE, if touch is TRUE then touch
  268. X   the archive member instead. */
  269. Xchar   *name;
  270. Xchar   *lib;
  271. Xtime_t *pmtime;
  272. Xint    touch;
  273. X{
  274. X   register MEMPTR mp;
  275. X   register LIBPTR lp;
  276. X
  277. X   for( lp=_cache; lp != NIL(LIB) && lp->lb_name != lib; lp=lp->lb_next );
  278. X   if( lp == NIL(LIB) ) return( FALSE );
  279. X
  280. X   mp = _find_member( lp, name );
  281. X   if( mp == NIL(MEM) || !mp->m_valid ) return( FALSE );
  282. X
  283. X   if( touch == TRUE )
  284. X   {
  285. X      mp->m_time = *pmtime;
  286. X      mp->m_valid = 1;
  287. X   }
  288. X   else
  289. X      *pmtime = mp->m_time;
  290. X
  291. X   lp->lb_valid   = 1;
  292. X   lp->lb_members = mp;
  293. X
  294. X   return( TRUE );
  295. X}
  296. X
  297. X
  298. X
  299. Xstatic int
  300. X_cache_member( name, lib, mtime )/*
  301. X===================================
  302. X   Cache name in lib along with it's time */
  303. Xchar   *name;
  304. Xchar   *lib;
  305. Xtime_t mtime;
  306. X{
  307. X   register MEMPTR mp;
  308. X   register LIBPTR lp;
  309. X
  310. X   for( lp=_cache;
  311. X    lp != NIL(LIB) && lp->lb_name != NIL(char) && lp->lb_name != lib;
  312. X    lp=lp->lb_next);
  313. X
  314. X   if( lp == NIL(LIB) )
  315. X   {
  316. X      lp = (LIBPTR) malloc(sizeof(LIB));
  317. X      if( lp == NIL(LIB) ) No_ram();
  318. X
  319. X      lp->lb_name    = lib;
  320. X      lp->lb_members = NIL(MEM);
  321. X      lp->lb_next    = _cache;
  322. X      lp->lb_valid   = 0;
  323. X      _cache = lp;
  324. X   }
  325. X
  326. X   /* On UNIX ar does not allow multiple copies of the same .o file to live
  327. X    * in the same AR file.  If this is not TRUE then use the commented out
  328. X    * version to set the value of mp. */
  329. X
  330. X   /*mp = _find_member(lp, name);*/
  331. X   mp = NIL(MEM);
  332. X
  333. X   if( mp == NIL(MEM) )
  334. X   {
  335. X      mp = (MEMPTR) malloc(sizeof(char)*offsetof(MEM,m_name[strlen(name)+1]));
  336. X      if( mp == NIL(MEM) ) No_ram();
  337. X
  338. X      strcpy( mp->m_name, name );
  339. X      mp->m_time     = mtime;
  340. X
  341. X      if( lp->lb_members == NIL(MEM) ) {
  342. X     mp->m_next     = mp;
  343. X     lp->lb_members = mp;
  344. X      }
  345. X      else {
  346. X     mp->m_next = lp->lb_members->m_next;
  347. X     lp->lb_members->m_next = mp;
  348. X     lp->lb_members = mp;
  349. X      }
  350. X   }
  351. X   else
  352. X      mp->m_time = mtime;
  353. X
  354. X   mp->m_valid = 1;
  355. X
  356. X   return( lp->lb_valid );
  357. X}
  358. X
  359. X
  360. Xstatic MEMPTR
  361. X_find_member( lp, name )
  362. XLIBPTR lp;
  363. Xchar   *name;
  364. X{
  365. X   register MEMPTR mp = lp->lb_members;
  366. X
  367. X   if( mp == NIL(MEM) ) return(mp);
  368. X
  369. X   do {
  370. X      if( !strcmp(mp->m_name, name ) ) return( mp );
  371. X      mp = mp->m_next;
  372. X   }
  373. X   while( mp != lp->lb_members );
  374. X
  375. X   return( NIL(MEM) );
  376. X}
  377. X#endif
  378. X
  379. X
  380. X
  381. Xvoid
  382. Xvoid_lcache( lib, member )/*
  383. X============================
  384. X   Void the library cache for lib.  If member is NIL(char) then nuke all
  385. X   of the members, if member is NOT NIL(char) then invalidate only that
  386. X   member. */
  387. Xchar *lib;
  388. Xchar *member;
  389. X{
  390. X#if LC
  391. X   register LIBPTR lp;
  392. X   register MEMPTR mp;
  393. X   register MEMPTR tmp;
  394. X
  395. X   for( lp=_cache; lp != NIL(LIB) && lp->lb_name != lib; lp=lp->lb_next );
  396. X   if( lp == NIL(LIB) ) return;
  397. X
  398. X   if( member == NIL(char) ) {
  399. X      mp = lp->lb_members;
  400. X      do {
  401. X     tmp = mp->m_next;
  402. X     (void) free( mp );
  403. X     mp = tmp;
  404. X      } while( mp != lp->lb_members );
  405. X
  406. X      lp->lb_valid   = 0;
  407. X      lp->lb_members = NIL(MEM);
  408. X      lp->lb_name    = NIL(char);
  409. X   }
  410. X   else {
  411. X      mp=lp->lb_members;
  412. X      do {
  413. X     if( strcmp( member, mp->m_name) == 0 ) {
  414. X        lp->lb_members = mp->m_next;
  415. X        mp->m_valid = 0;
  416. X     }
  417. X       
  418. X     mp=mp->m_next;
  419. X      } while( mp != lp->lb_members );
  420. X   }
  421. X#endif
  422. X}
  423. SHAR_EOF
  424. echo "File unix/arlib.c is complete"
  425. chmod 0440 unix/arlib.c || echo "restore of unix/arlib.c fails"
  426. echo mkdir - unix/386ix
  427. mkdir unix/386ix
  428. echo "x - extracting unix/386ix/time.h (Text)"
  429. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/time.h &&
  430. X/*
  431. X** Berkeley get this wrong!
  432. X*/
  433. X#ifndef    TIME_h
  434. X#define    TIME_h
  435. X
  436. Xtypedef    long    time_t;    /* this is the thing we use */
  437. X
  438. X#endif    TIME_h
  439. X
  440. SHAR_EOF
  441. chmod 0640 unix/386ix/time.h || echo "restore of unix/386ix/time.h fails"
  442. echo "x - extracting unix/386ix/stdlib.h (Text)"
  443. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/stdlib.h &&
  444. X#ifndef _STDLIB_INCLUDED_
  445. X#define _STDLIB_INCLUDED_
  446. X
  447. Xextern /*GOTO*/ _exit();
  448. Xextern /*GOTO*/ exit();
  449. Xextern /*GOTO*/ abort();
  450. Xextern int system();
  451. Xextern char *getenv();
  452. Xextern char *calloc();
  453. Xextern char *malloc();
  454. Xextern char *realloc();
  455. Xextern free();
  456. Xextern int errno;
  457. X
  458. X#ifndef EIO
  459. X#    include <errno.h>
  460. X#endif
  461. X
  462. X#endif /* _STDLIB_INCLUDED_ */
  463. SHAR_EOF
  464. chmod 0640 unix/386ix/stdlib.h || echo "restore of unix/386ix/stdlib.h fails"
  465. echo "x - extracting unix/386ix/stdarg.h (Text)"
  466. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/stdarg.h &&
  467. X/*
  468. X * stdarg.h
  469. X *
  470. X * defines ANSI style macros for accessing arguments of a function which takes
  471. X * a variable number of arguments
  472. X *
  473. X */
  474. X
  475. X#if !defined(__STDARG)
  476. X#define __STDARG
  477. X
  478. Xtypedef char *va_list;
  479. X
  480. X#define va_dcl int va_alist
  481. X#define va_start(ap,v)  ap = (va_list)&va_alist
  482. X#define va_arg(ap,t)    ((t*)(ap += sizeof(t)))[-1]
  483. X#define va_end(ap)      ap = NULL
  484. X#endif
  485. SHAR_EOF
  486. chmod 0640 unix/386ix/stdarg.h || echo "restore of unix/386ix/stdarg.h fails"
  487. echo "x - extracting unix/386ix/startup.mk (Text)"
  488. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/startup.mk &&
  489. X# Generic UNIX DMAKE startup file.  Customize to suit your needs.
  490. X# Should work for both SYSV, and BSD 4.3
  491. X# See the documentation for a description of internally defined macros.
  492. X#
  493. X# Disable warnings for macros redefined here that were given
  494. X# on the command line.
  495. X__.SILENT := $(.SILENT)
  496. X.SILENT   := yes
  497. X
  498. X# Configuration parameters for DMAKE startup.mk file
  499. X# Set these to NON-NULL if you wish to turn the parameter on.
  500. X_HAVE_RCS    := yes        # yes => RCS  is installed.
  501. X_HAVE_SCCS    := yes        # yes => SCCS is installed.
  502. X
  503. X# Applicable suffix definitions
  504. XA := .a        # Libraries
  505. XE :=        # Executables
  506. XF := .f        # Fortran
  507. XO := .o        # Objects
  508. XP := .p        # Pascal
  509. XS := .s        # Assembler sources
  510. XV := ,v        # RCS suffix
  511. X
  512. X# Recipe execution configurations
  513. XSHELL        := /bin/sh
  514. XSHELLFLAGS    := -ce
  515. XGROUPSHELL    := $(SHELL)
  516. XGROUPFLAGS    := 
  517. XSHELLMETAS    := |();&<>?*][$$:\\#`'"
  518. XGROUPSUFFIX    :=
  519. X
  520. X# Standard C-language command names and flags
  521. X   CPP       := /lib/cpp        # C-preprocessor
  522. X   CC      := cc        # C-compiler and flags
  523. X   CFLAGS   =
  524. X
  525. X   AS      := as        # Assembler and flags
  526. X   ASFLAGS  = 
  527. X
  528. X   LD       = $(CC)        # Loader and flags
  529. X   LDFLAGS  =
  530. X   LDLIBS   =
  531. X
  532. X# Definition of $(MAKE) macro for recursive makes.
  533. X   MAKE = $(MAKECMD) $(MFLAGS)
  534. X
  535. X# Definition of Print command for this system.
  536. X   PRINT = lpr
  537. X
  538. X# Language and Parser generation Tools and their flags
  539. X   YACC      := yacc        # standard yacc
  540. X   YFLAGS  =
  541. X   YTAB      := y.tab        # yacc output files name stem.
  542. X
  543. X   LEX      := lex        # standard lex
  544. X   LFLAGS  =
  545. X   LEXYY  := lex.yy        # lex output file
  546. X
  547. X# Other Compilers, Tools and their flags
  548. X   PC    := pc            # pascal compiler
  549. X   RC    := f77            # ratfor compiler
  550. X   FC    := f77            # fortran compiler
  551. X
  552. X   CO       := co        # check out for RCS
  553. X   COFLAGS := -q
  554. X
  555. X   AR     := ar            # archiver
  556. X   ARFLAGS = ruv
  557. X
  558. X   RM       := /bin/rm        # remove a file command
  559. X   RMFLAGS  =
  560. X
  561. X# Implicit generation rules for making inferences.
  562. X# We don't provide .yr or .ye rules here.  They're obsolete.
  563. X# Rules for making *$O
  564. X   %$O : %.c ; $(CC) $(CFLAGS) -c $<
  565. X   %$O : %$P ; $(PC) $(PFLAGS) -c $<
  566. X   %$O : %$S ; $(AS) $<
  567. X   %$O : %.cl ; class -c $<
  568. X   %$O : %.e %.r %.F %$F
  569. X    $(FC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<
  570. X
  571. X# Executables
  572. X   %$E : %$O ; $(LD) $(LDFLAGS) -o $@ $< $(LDLIBES)
  573. X
  574. X# lex and yacc rules
  575. X   %.c : %.y ; $(YACC)  $(YFLAGS) $<; mv $(YTAB).c $@
  576. X   %.c : %.l ; $(LEX)   $(LFLAGS) $<; mv $(LEXYY).c $@
  577. X
  578. X# This rule tells how to make *.out from it's immediate list of prerequisites
  579. X# UNIX only.
  580. X   %.out :; $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
  581. X
  582. X# RCS support
  583. X.IF $(_HAVE_RCS)
  584. X   % : %$V $$(@:d)RCS/$$(@:f)$V;- $(CO) $(COFLAGS) $@
  585. X   .NOINFER : %$V $$(@:d)RCS/$$(@:f)$V
  586. X.END
  587. X
  588. X# SCCS support
  589. X.IF $(_HAVE_SCCS)
  590. X   % : s.% ; get $@
  591. X   .NOINFER : s.%
  592. X.END
  593. X
  594. X# Recipe to make archive files.
  595. X%$A :
  596. X[
  597. X   $(AR) $(ARFLAGS) $@ $?
  598. X   $(RM) $(RMFLAGS) $?
  599. X   ranlib $@
  600. X]
  601. X
  602. X# DMAKE uses this recipe to remove intermediate targets
  603. X.REMOVE :; $(RM) -f $<
  604. X
  605. X# AUGMAKE extensions for SYSV compatibility
  606. X@B = $(@:b)
  607. X@D = $(@:d)
  608. X@F = $(@:f)
  609. X*B = $(*:b)
  610. X*D = $(*:d)
  611. X*F = $(*:f)
  612. X<B = $(<:b)
  613. X<D = $(<:d)
  614. X<F = $(<:f)
  615. X?B = $(?:b)
  616. X?F = $(?:f)
  617. X?D = $(?:d)
  618. X
  619. X# Turn warnings back to previous setting.
  620. X.SILENT := $(__.SILENT)
  621. X
  622. X# Local startup file if any
  623. X.INCLUDE .IGNORE: "_startup.mk"
  624. SHAR_EOF
  625. chmod 0640 unix/386ix/startup.mk || echo "restore of unix/386ix/startup.mk fails"
  626. echo "x - extracting unix/386ix/make.sh (Text)"
  627. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/make.sh &&
  628. Xmkdir objects
  629. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O infer.c
  630. Xmv infer.o objects
  631. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O make.c
  632. Xmv make.o objects
  633. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O stat.c
  634. Xmv stat.o objects
  635. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O expand.c
  636. Xmv expand.o objects
  637. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O string.c
  638. Xmv string.o objects
  639. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O hash.c
  640. Xmv hash.o objects
  641. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dag.c
  642. Xmv dag.o objects
  643. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dmake.c
  644. Xmv dmake.o objects
  645. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O path.c
  646. Xmv path.o objects
  647. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O imacs.c
  648. Xmv imacs.o objects
  649. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O sysintf.c
  650. Xmv sysintf.o objects
  651. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O parse.c
  652. Xmv parse.o objects
  653. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O getinp.c
  654. Xmv getinp.o objects
  655. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O quit.c
  656. Xmv quit.o objects
  657. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O basename.c
  658. Xmv basename.o objects
  659. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O dump.c
  660. Xmv dump.o objects
  661. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O macparse.c
  662. Xmv macparse.o objects
  663. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O rulparse.c
  664. Xmv rulparse.o objects
  665. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O percent.c
  666. Xmv percent.o objects
  667. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/arlib.c
  668. Xmv arlib.o objects
  669. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/dirbrk.c
  670. Xmv dirbrk.o objects
  671. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/explode.c
  672. Xmv explode.o objects
  673. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/rmprq.c
  674. Xmv rmprq.o objects
  675. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/ruletab.c
  676. Xmv ruletab.o objects
  677. Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/386ix -O unix/runargv.c
  678. Xmv runargv.o objects
  679. Xcc  -o dmake  objects/infer.o objects/make.o objects/stat.o objects/expand.o objects/string.o objects/hash.o objects/dag.o objects/dmake.o objects/path.o objects/imacs.o objects/sysintf.o objects/parse.o objects/getinp.o objects/quit.o objects/basename.o objects/dump.o objects/macparse.o objects/rulparse.o objects/percent.o objects/arlib.o objects/dirbrk.o objects/explode.o objects/rmprq.o objects/ruletab.o objects/runargv.o 
  680. SHAR_EOF
  681. chmod 0640 unix/386ix/make.sh || echo "restore of unix/386ix/make.sh fails"
  682. echo "x - extracting unix/386ix/config.mk (Text)"
  683. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/config.mk &&
  684. X# This is the SysV R3 UNIX configuration file for DMAKE
  685. X#    It simply modifies the values of SRC, and checks to see if
  686. X#    OSENVIRONMENT is defined.  If so it includes the appropriate
  687. X#    config.mk file.
  688. X#
  689. X# It also sets the values of .SOURCE.c and .SOURCE.h to include the local
  690. X# directory.
  691. X#
  692. Xosrdir := $(OS)$(DIRSEPSTR)$(OSRELEASE)
  693. X
  694. X# The following sources are required for SysV R3
  695. XSRC +=  #zero for now. we do have some .h's though
  696. X
  697. X#.SOURCE.c : $(osrdir)
  698. X.SOURCE.h : $(osrdir)
  699. X
  700. X# Local configuration modifications for CFLAGS, there's local SysV includes
  701. X# too.
  702. XCFLAGS += -I$(osrdir)
  703. X
  704. X# See if we modify anything in the lower levels.
  705. X.IF $(OSENVIRONMENT) != $(NULL)
  706. X   .INCLUDE .IGNORE : $(osrdir)$(DIRSEPSTR)$(OSENVIRONMENT)$(DIRSEPSTR)config.mk
  707. X.END
  708. SHAR_EOF
  709. chmod 0640 unix/386ix/config.mk || echo "restore of unix/386ix/config.mk fails"
  710. echo "x - extracting unix/386ix/config.h (Text)"
  711. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/config.h &&
  712. X/* RCS      -- $Header$
  713. X-- SYNOPSIS -- Configurarion include file.
  714. X-- 
  715. X-- DESCRIPTION
  716. X--     There is one of these for each specific machine configuration.
  717. X--    It can be used to further tweek the machine specific sources
  718. X--    so that they compile.
  719. X--
  720. X-- AUTHOR
  721. X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  722. X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  723. X--
  724. X-- COPYRIGHT
  725. X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  726. X-- 
  727. X--      This program is free software; you can redistribute it and/or
  728. X--      modify it under the terms of the GNU General Public License
  729. X--      (version 1), as published by the Free Software Foundation, and
  730. X--      found in the file 'LICENSE' included with this distribution.
  731. X-- 
  732. X--      This program is distributed in the hope that it will be useful,
  733. X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
  734. X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  735. X--      GNU General Public License for more details.
  736. X-- 
  737. X--      You should have received a copy of the GNU General Public License
  738. X--      along with this program;  if not, write to the Free Software
  739. X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  740. X--
  741. X-- LOG
  742. X--     $Log$
  743. X*/
  744. X
  745. X/* define this for configurations that don't have the coreleft function
  746. X * so that the code compiles.  To my knowledge coreleft exists only on
  747. X * Turbo C, but it is needed here since the function is used in many debug
  748. X * macros. */
  749. X#define coreleft() 0L
  750. X
  751. X/* Define the getcwd function that is used in the code, since BSD does
  752. X * not have getcwd, but call it getwd instead. */
  753. Xextern char *getcwd ANSI((char *, int));
  754. X
  755. X/* Define setvbuf, SysV doesn't have one */
  756. X#define setvbuf(fp, bp, type, len) setbuf( fp, NULL );
  757. X
  758. X/* NCR Tower's don't define size_t */
  759. X#ifdef tower
  760. Xtypedef long size_t;
  761. X#endif
  762. SHAR_EOF
  763. chmod 0640 unix/386ix/config.h || echo "restore of unix/386ix/config.h fails"
  764. echo "x - extracting unix/386ix/ar.h (Text)"
  765. sed 's/^X//' << 'SHAR_EOF' > unix/386ix/ar.h &&
  766. X#define PORTAR 1
  767. X#include "/usr/include/ar.h"
  768. SHAR_EOF
  769. chmod 0640 unix/386ix/ar.h || echo "restore of unix/386ix/ar.h fails"
  770. echo "x - extracting sysintf.c (Text)"
  771. sed 's/^X//' << 'SHAR_EOF' > sysintf.c &&
  772. X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/sysintf.c,v 1.1 90/07/21 11:06:34 dvadura Exp $
  773. X-- SYNOPSIS -- system independent interface
  774. X-- 
  775. X-- DESCRIPTION
  776. X--    These are the routines constituting the system interface.
  777. X--    The system is taken to be essentially POSIX conformant.
  778. X--    The original code was extensively revised by T J Thompson at MKS,
  779. X--    and the library cacheing was added by Eric Gisin at MKS.  I then
  780. X--    revised the code yet again, to improve the lib cacheing, and to
  781. X--    make it a little more portable.
  782. X--
  783. X--    The following is a list of routines that are required by this file
  784. X--    in order to work.  These routines are provided as functions by the
  785. X--    standard C lib of the target system or as #defines in system/sysintf.h
  786. X--    or via appropriate C code in the system/ directory for the given
  787. X--    system.
  788. X--
  789. X--    The first group must be provided by a file in the system/ directory
  790. X--    the second group is ideally provided by the C lib.  However, there
  791. X--    are instances where the C lib implementation of the specified routine
  792. X--    does not exist, or is incorrect.  In these instances the routine
  793. X--    must be provided by the the user in the system/ directory of dmake.
  794. X--    (For example, the bsd/ dir contains code for putenv(), and tempnam())
  795. X--
  796. X--    DMAKE SPECIFIC:
  797. X--        seek_arch()
  798. X--        touch_arch()
  799. X--        void_lcache()
  800. X--        runargv()
  801. X--        STAT()
  802. X--
  803. X--    C-LIB SPECIFIC:  (should be present in your C-lib)
  804. X--        utime()
  805. X--        time()
  806. X--        getenv()
  807. X--        putenv()
  808. X--        getcwd()
  809. X--        signal()
  810. X--        chdir()
  811. X--        tempnam()
  812. X-- 
  813. X-- AUTHOR
  814. X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  815. X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  816. X--
  817. X-- COPYRIGHT
  818. X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  819. X-- 
  820. X--      This program is free software; you can redistribute it and/or
  821. X--      modify it under the terms of the GNU General Public License
  822. X--      (version 1), as published by the Free Software Foundation, and
  823. X--      found in the file 'LICENSE' included with this distribution.
  824. X-- 
  825. X--      This program is distributed in the hope that it will be useful,
  826. X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
  827. X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  828. X--      GNU General Public License for more details.
  829. X-- 
  830. X--      You should have received a copy of the GNU General Public License
  831. X--      along with this program;  if not, write to the Free Software
  832. X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  833. X--
  834. X-- LOG
  835. X--     $Log:    sysintf.c,v $
  836. X * Revision 1.1  90/07/21  11:06:34  dvadura
  837. X * Initial Revision Version 3.5
  838. X * 
  839. X*/
  840. X
  841. X#include <stdio.h>
  842. X#include "extern.h"
  843. X#include "sysintf.h"
  844. X#include "alloc.h"
  845. X
  846. X/*
  847. X** Tries to stat the file name.  Returns 0 if the file
  848. X** does not exist.  Note that if lib is not null it tries to stat
  849. X** the name found inside lib.
  850. X**
  851. X** If member is NOT nil then look for the library object which defines the
  852. X** symbol given by name.  If found _strdup the name and return make the
  853. X** pointer pointed at by sym point at it.  Not handled for now!
  854. X*/
  855. Xtime_t
  856. XDo_stat(name, lib, member)
  857. Xchar *name;
  858. Xchar *lib;
  859. Xchar **member;
  860. X{
  861. X   struct stat buf;
  862. X   time_t seek_arch();
  863. X
  864. X   if( member != NIL(char *) )
  865. X      Fatal("Library symbol names not supported");
  866. X
  867. X   if( lib != NIL(char) )
  868. X      return( seek_arch(basename(name), lib) );
  869. X   else
  870. X      return( (STAT(name, &buf) == -1) ? (time_t)0 : buf.st_mtime );
  871. X}
  872. X
  873. X
  874. X
  875. X/* Touch existing file to force modify time to present.
  876. X */
  877. Xint
  878. XDo_touch(name, lib, member)
  879. Xchar *name;
  880. Xchar *lib;
  881. Xchar **member;
  882. X{
  883. X   if( member != NIL(char *) )
  884. X      Fatal("Library symbol names not supported");
  885. X
  886. X   if (lib != NIL(char))
  887. X      return( touch_arch(basename(name), lib) );
  888. X   else
  889. X      return( utime(name, NIL(time_t)) );
  890. X}
  891. X
  892. X
  893. X
  894. Xvoid
  895. XVoid_lib_cache( lib_name, member_name )/*
  896. X=========================================
  897. X   Void the library cache for lib lib_name, and member member_name. */
  898. Xchar *lib_name;
  899. Xchar *member_name;
  900. X{
  901. X   VOID_LCACHE( lib_name, member_name );
  902. X}
  903. X
  904. X
  905. X
  906. X/*
  907. X** return the current time
  908. X*/
  909. Xtime_t
  910. XDo_time()
  911. X{
  912. X   extern time_t time();
  913. X   return (time((time_t*)0));
  914. X}
  915. X
  916. X
  917. X
  918. X/*
  919. X** Execute the string passed in as a command and return
  920. X** the return code. The command line arguments are
  921. X** assumed to be separated by spaces or tabs.  The first
  922. X** such argument is assumed to be the command.
  923. X**
  924. X** If group is true then this is a group of commands to be fed to the
  925. X** the shell as a single unit.  In this case cmd is of the form
  926. X** "file" indicating the file that should be read by the shell
  927. X** in order to execute the command group.
  928. X*/
  929. Xint
  930. XDo_cmnd(cmd, group, do_it, target, how, ignore, last)
  931. Xchar   *cmd;
  932. Xint     group;
  933. Xint    do_it;
  934. XCELLPTR target;
  935. XHOWPTR  how;
  936. Xint     ignore;
  937. Xint    last;
  938. X{
  939. X   int  i;
  940. X
  941. X   if( !do_it ) {
  942. X      if( last && !Doing_bang ) Update_time_stamp( target, how );
  943. X      return(0);
  944. X   }
  945. X
  946. X   if( Max_proc == 1 ) Wait_for_completion = TRUE;
  947. X   if( (i = runargv(target, how, ignore, group, last, cmd)) == -1 )
  948. X      Quit();
  949. X
  950. X   /* NOTE:  runargv must return either 0 or 1, 0 ==> command executed, and
  951. X    * we waited for it to return, 1 ==> command started and is running
  952. X    * concurrently with make process. */
  953. X   return(i);
  954. X}
  955. X
  956. X
  957. X/* Take a command and pack it into an argument vector to be executed. */
  958. Xvoid
  959. XPack_argv( argv, maxargv, group, cmd )
  960. Xchar **argv;
  961. Xint    maxargv;
  962. Xint    group;
  963. Xchar  *cmd;
  964. X{
  965. X   int i;
  966. X
  967. X   if( group || (*_strpbrk(cmd, Shell_metas) != '\0') ) {
  968. X      char* sh = group ? GShell : Shell;
  969. X
  970. X      if( sh != NIL(char) ) {
  971. X         argv[0] = sh;
  972. X         argv[1] = group ? GShell_flags : Shell_flags;
  973. X
  974. X         if( argv[1] == NIL(char) ) {
  975. X            argv[1] = cmd;
  976. X            argv[2] = NIL(char);
  977. X         }
  978. X     else {
  979. X            argv[2] = cmd;
  980. X            argv[3] = NIL(char);
  981. X         }
  982. X      }
  983. X      else if( group )
  984. X            Fatal("GROUPSHELL macro not defined");
  985. X         else
  986. X            Fatal("SHELL macro not defined");
  987. X   }
  988. X   else {
  989. X      i = 0;
  990. X
  991. X      do {
  992. X     if( i == maxargv )
  993. X        Fatal( "Argument limit exceeded, maximum number of arguments %d",
  994. X           maxargv );
  995. X
  996. X         while( iswhite(*cmd) ) ++cmd;
  997. X         if( *cmd ) argv[i++] = cmd;
  998. X
  999. X         while( *cmd != '\0' && !iswhite(*cmd) ) ++cmd;
  1000. X         if( *cmd ) *cmd++ = '\0';
  1001. X      } while( *cmd );
  1002. X
  1003. X      argv[i] = NIL(char);
  1004. X   }
  1005. X}
  1006. X
  1007. X
  1008. X/*
  1009. X** Return the value of ename from the environment
  1010. X** if ename is not defined in the environment then
  1011. X** NIL(char) should be returned
  1012. X*/
  1013. Xchar *
  1014. XRead_env_string(ename)
  1015. Xchar *ename;
  1016. X{
  1017. X   extern char *getenv();
  1018. X   return( getenv(ename) );
  1019. X}
  1020. X
  1021. X
  1022. X
  1023. X/*
  1024. X** Set the value of the environment string ename to value.
  1025. X**  Returns 0 if success, non-zero if failure
  1026. X*/
  1027. Xint
  1028. XWrite_env_string(ename, value)
  1029. Xchar *ename;
  1030. Xchar *value;
  1031. X{
  1032. X   extern int putenv();
  1033. X   char*   p;
  1034. X   char*   envstr = _stradd(ename, value, FALSE);
  1035. X
  1036. X   p = envstr+strlen(ename);    /* Don't change this code, _stradd does not */
  1037. X   *p++ = '=';            /* add the space if *value is 0, it does    */
  1038. X   if( !*value ) *p = '\0';    /* allocate enough memory for one though.   */
  1039. X
  1040. X   return( putenv(envstr) );
  1041. X}
  1042. X
  1043. X
  1044. X
  1045. Xvoid
  1046. XReadEnvironment()
  1047. X{
  1048. X   extern char **Rule_tab;
  1049. X   extern char **environ;
  1050. X   char **rsave;
  1051. X
  1052. X   rsave    = Rule_tab;
  1053. X   Rule_tab = environ;
  1054. X   Readenv  = TRUE;
  1055. X
  1056. X   Parse( NIL(FILE) );
  1057. X
  1058. X   Readenv  = FALSE;
  1059. X   Rule_tab = rsave;
  1060. X}
  1061. X
  1062. X
  1063. X
  1064. X/*
  1065. X** All we have to catch is SIG_INT
  1066. X*/
  1067. Xvoid
  1068. XCatch_signals(fn)
  1069. Xvoid (*fn)();
  1070. X{
  1071. X   if( signal(SIGINT, SIG_IGN) != SIG_IGN )
  1072. X      signal( SIGINT, fn );
  1073. X   if( signal(SIGQUIT, SIG_IGN) != SIG_IGN )
  1074. X      signal( SIGQUIT, fn );
  1075. X}
  1076. X
  1077. X
  1078. X
  1079. X/*
  1080. X** Clear any previously set signals
  1081. X*/
  1082. Xvoid
  1083. XClear_signals()
  1084. X{
  1085. X   if( signal(SIGINT, SIG_IGN) != SIG_IGN )
  1086. X      signal( SIGINT, SIG_DFL );
  1087. X   if( signal(SIGQUIT, SIG_IGN) != SIG_IGN )
  1088. X      signal( SIGQUIT, SIG_DFL );
  1089. X}
  1090. X
  1091. X
  1092. X
  1093. X/*
  1094. X** Set program name
  1095. X*/
  1096. Xvoid
  1097. XProlog(argc, argv)
  1098. Xint   argc;
  1099. Xchar* argv[];
  1100. X{
  1101. X   Pname = (argc == 0) ? DEF_MAKE_PNAME : argv[0];
  1102. X}
  1103. X
  1104. X
  1105. X
  1106. X/*
  1107. X** Do any clean up for exit.
  1108. X*/
  1109. Xvoid
  1110. XEpilog(ret_code)
  1111. Xint ret_code;
  1112. X{
  1113. X   exit( ret_code );
  1114. X}
  1115. X
  1116. X
  1117. X
  1118. X/*
  1119. X** Use the built-in functions of the operating system to get the current
  1120. X** working directory.
  1121. X*/
  1122. Xchar *
  1123. XGet_current_dir()
  1124. X{
  1125. X   static char buf[MAX_PATH_LEN+1];
  1126. X
  1127. X   return( getcwd(buf, sizeof(buf)) );
  1128. X}
  1129. X
  1130. X
  1131. X
  1132. X/*
  1133. X** change working directory
  1134. X*/
  1135. Xint
  1136. XSet_dir(path)
  1137. Xchar*   path;
  1138. X{
  1139. X   return( chdir(path) );
  1140. X}
  1141. X
  1142. X
  1143. X
  1144. X/*
  1145. X** return switch char
  1146. X*/
  1147. Xchar
  1148. XGet_switch_char()
  1149. X{
  1150. X   return( getswitchar() );
  1151. X}
  1152. X
  1153. X
  1154. X
  1155. X/*
  1156. X** Generate a temporary file name and open the file for writing.
  1157. X** If a name cannot be generated or the file cannot be opened
  1158. X** return -1, else return the fileno of the open file.
  1159. X** and update the source file pointer to point at the new file name.
  1160. X** Note that the new name should be freed when the file is removed.
  1161. X*/
  1162. XFILE*
  1163. XOpen_temp(path, suff)
  1164. Xchar **path;
  1165. Xchar *suff;
  1166. X{
  1167. X   extern char *tempnam();
  1168. X
  1169. X   *path = _strjoin( tempnam(NIL(char), "mk"), suff, -1, TRUE );
  1170. X   return( fopen(*path, "w") );
  1171. X}
  1172. X
  1173. X
  1174. X/*
  1175. X** Open a new temporary file and set it up for writing.
  1176. X*/
  1177. XFILE *
  1178. XStart_temp( suffix, cp, how, fname )
  1179. Xchar     *suffix;
  1180. XCELLPTR   cp;
  1181. XHOWPTR    how;
  1182. Xchar    **fname;
  1183. X{
  1184. X   FILE           *fp;
  1185. X   char        *tmpname;
  1186. X   char           *name;
  1187. X   FILELISTPTR new;
  1188. X
  1189. X   name = cp->CE_NAME;
  1190. X   if( (fp = Open_temp( &tmpname, suffix)) == NIL(FILE) )
  1191. X      Fatal("Cannot open temp file `%s' while making `%s'", tmpname, name );
  1192. X
  1193. X   TALLOC( new, 1, FILELIST );
  1194. X
  1195. X   new->fl_next = how->hw_files;
  1196. X   new->fl_name = tmpname;
  1197. X   new->fl_file = fp;        /* indicates temp file is open */
  1198. X
  1199. X   how->hw_files = new;
  1200. X   *fname = tmpname;
  1201. X
  1202. X   return( fp );
  1203. X}
  1204. X
  1205. X
  1206. X/*
  1207. X** Close a previously used temporary file.
  1208. X*/
  1209. Xvoid
  1210. XClose_temp(how, file)
  1211. XHOWPTR  how;
  1212. XFILE    *file;
  1213. X{
  1214. X   FILELISTPTR fl;
  1215. X
  1216. X   for( fl=how->hw_files; fl && fl->fl_file != file; fl=fl->fl_next );
  1217. X   if( fl ) {
  1218. X      fl->fl_file = NIL(FILE);
  1219. X      fclose(file);
  1220. X   }
  1221. X}
  1222. X
  1223. X
  1224. X/*
  1225. X** Clean-up, and close all temporary files associated with a target.
  1226. X*/
  1227. Xvoid
  1228. XUnlink_temp_files( how )/*
  1229. X==========================
  1230. X   Unlink the tempfiles if any exist.  Make sure you close the files first
  1231. X   though.  This ensures that under DOS there is no disk space lost. */
  1232. XHOWPTR how;
  1233. X{
  1234. X   FILELISTPTR next;
  1235. X
  1236. X   while( how->hw_files != NIL(FILELIST) ) {
  1237. X      if( how->hw_files->fl_file ) fclose( how->hw_files->fl_file );
  1238. X
  1239. X      if( Verbose )
  1240. X         printf( "%s:  Left temp file [%s]\n", Pname, how->hw_files->fl_name );
  1241. X      else
  1242. X         (void) unlink( how->hw_files->fl_name );
  1243. X
  1244. X      FREE( how->hw_files->fl_name );
  1245. X      next = how->hw_files->fl_next;
  1246. X      FREE(how->hw_files);
  1247. X      how->hw_files = next;
  1248. X   }
  1249. X}
  1250. X
  1251. X
  1252. Xvoid
  1253. XHandle_result(status, ignore, abort_flg, target)
  1254. Xint    status;
  1255. Xint    ignore;
  1256. Xint    abort_flg;
  1257. XCELLPTR target;
  1258. X{
  1259. X   status = ((status&0xff)==0 ? status>>8
  1260. X        : (status & 0xff)==SIGTERM ? -1
  1261. X        : (status & 0x7f)+128);
  1262. X
  1263. X   if( status )
  1264. X      if( !abort_flg ) {
  1265. X     fprintf( stderr, "%s:  Error code %d, while making '%s'",
  1266. X          Pname, status, target->ce_fname );
  1267. X
  1268. X     if( ignore || Continue ) {
  1269. X        fputs( " (Ignored)\n", stderr );
  1270. X     }
  1271. X     else {
  1272. X        fputc( '\n', stderr );
  1273. X
  1274. X        if( !(target->ce_attr & A_PRECIOUS) )
  1275. X           if( unlink( target->ce_fname ) == 0 )
  1276. X          fprintf(stderr,"%s:  '%s' removed.\n",Pname,target->ce_fname);
  1277. X
  1278. X        Quit();
  1279. X     }
  1280. X      }
  1281. X      else if( !(target->ce_attr & A_PRECIOUS) )
  1282. X     unlink( target->ce_fname );
  1283. X}
  1284. X
  1285. X
  1286. Xvoid
  1287. XUpdate_time_stamp( cp, how )
  1288. XCELLPTR cp;
  1289. XHOWPTR  how;
  1290. X{
  1291. X   HASHPTR hp;
  1292. X   CELLPTR tcp;
  1293. X   int     tmpflg; 
  1294. X
  1295. X   how->hw_flag |= F_MADE;
  1296. X   Unlink_temp_files( how );
  1297. X
  1298. X   /* do the time only at end, of MULTI recipe targets, or immediately
  1299. X    * for non-MULTI recipe targets. */
  1300. X   tmpflg = cp->ce_flag & F_MULTI;
  1301. X
  1302. X   if( (tmpflg && cp->CE_HOW == how) || !tmpflg ) {
  1303. X      tcp = cp;
  1304. X      do {
  1305. X     if( tcp->ce_attr & A_LIBRARY )
  1306. X        Void_lib_cache( tcp->ce_fname, NIL(char) );
  1307. X     else if( !Touch && (tcp->ce_attr & A_LIBRARYM) )
  1308. X        Void_lib_cache( tcp->ce_lib, tcp->ce_fname );
  1309. X
  1310. X     if( Trace ) {
  1311. X        tcp->ce_time  = Do_time();
  1312. X        tcp->ce_flag |= F_STAT;        /* pretend we stated ok */
  1313. X
  1314. X        if( tcp->ce_fname == NIL(char) )
  1315. X           tcp->ce_fname = tcp->CE_NAME;
  1316. X     }
  1317. X     else {
  1318. X        Stat_target( tcp, TRUE );
  1319. X        if( tcp->ce_time == (time_t) 0L )
  1320. X           tcp->ce_time = Do_time();
  1321. X     }
  1322. X
  1323. X     if( Verbose )
  1324. X        printf( "%s:  <<<< Set [%s] time stamp to %ld\n",
  1325. X            Pname, tcp->CE_NAME, tcp->ce_time );
  1326. X
  1327. X     tcp->ce_flag |= F_MADE;
  1328. X     tcp = tcp->ce_all;
  1329. X      }
  1330. X      while( tcp != NIL(CELL) && tcp != cp );
  1331. X   }
  1332. X   else if( tmpflg )
  1333. X      cp->ce_flag |= F_STAT;
  1334. X
  1335. X
  1336. X   /* Scan the list of prerequisites and if we find one that is
  1337. X    * marked as being removable, (ie. an inferred intermediate node
  1338. X    * then remove it.  We remove a prerequisite by running the recipe
  1339. X    * associated with the special target .REMOVE, with $< set to
  1340. X    * the list of prerequisites to remove. */
  1341. X
  1342. X   if( (hp = Get_name( ".REMOVE", Defs, FALSE, NIL(CELL) )) != NIL(HASH) ) {
  1343. X      register LINKPTR dp;
  1344. X      int flag = FALSE;
  1345. X      int rem;
  1346. X      int attr;
  1347. X
  1348. X      tcp = hp->CP_OWNR;
  1349. X      tcp->ce_flag |= F_TARGET;
  1350. X      Clear_prerequisites( tcp->CE_HOW );
  1351. X
  1352. X      for( dp = how->hw_prq; dp != NIL(LINK); dp = dp->cl_next ) {
  1353. X     register CELLPTR prq = dp->cl_prq;
  1354. X
  1355. X     attr = Glob_attr | prq->ce_attr;
  1356. X     rem  = (prq->ce_flag & F_REMOVE) &&
  1357. X        (prq->ce_flag & F_MADE  ) &&
  1358. X        !(attr & A_PRECIOUS) &&
  1359. X        !Force;
  1360. X
  1361. X     if( rem ) {
  1362. X        CELLPTR tmp = prq;
  1363. X        do {
  1364. X           (Add_prerequisite(tcp->CE_HOW, prq, FALSE))->cl_flag |= F_TARGET;
  1365. X           prq->ce_flag &= ~F_REMOVE;
  1366. X           prq = prq->ce_all;
  1367. X        }
  1368. X        while( prq != NIL(CELL) && prq != tmp );
  1369. X        flag = TRUE;
  1370. X     }
  1371. X      }
  1372. X
  1373. X      if( flag ) Remove_prq( tcp );
  1374. X   }
  1375. X}
  1376. SHAR_EOF
  1377. chmod 0440 sysintf.c || echo "restore of sysintf.c fails"
  1378. echo "x - extracting struct.h (Text)"
  1379. sed 's/^X//' << 'SHAR_EOF' > struct.h &&
  1380. X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/struct.h,v 1.1 90/07/19 13:55:36 dvadura Exp $
  1381. X-- SYNOPSIS -- structure definitions
  1382. X-- 
  1383. X-- DESCRIPTION
  1384. X--    dmake main data structure definitions.  See each of the individual
  1385. X--    struct declarations for more detailed information on the defined
  1386. X--    fields and their use.
  1387. X-- 
  1388. X-- AUTHOR
  1389. X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  1390. X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  1391. X--
  1392. X-- COPYRIGHT
  1393. X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  1394. X-- 
  1395. X--      This program is free software; you can redistribute it and/or
  1396. X--      modify it under the terms of the GNU General Public License
  1397. X--      (version 1), as published by the Free Software Foundation, and
  1398. X--      found in the file 'LICENSE' included with this distribution.
  1399. X-- 
  1400. X--      This program is distributed in the hope that it will be useful,
  1401. X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
  1402. X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1403. X--      GNU General Public License for more details.
  1404. X-- 
  1405. X--      You should have received a copy of the GNU General Public License
  1406. X--      along with this program;  if not, write to the Free Software
  1407. X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1408. X--
  1409. X-- LOG
  1410. X--     $Log:    struct.h,v $
  1411. X * Revision 1.1  90/07/19  13:55:36  dvadura
  1412. X * Initial Revision of Version 3.5
  1413. X * 
  1414. X*/
  1415. X
  1416. X#ifndef _STRUCT_INCLUDED_
  1417. X#define _STRUCT_INCLUDED_
  1418. X
  1419. X#include <sys/types.h>
  1420. X#include "itypes.h"
  1421. X
  1422. X/* The following struct is the cell used in the hash table.
  1423. X * NOTE:  It contains the actual hash value.  This allows the hash table
  1424. X *        insertion to compare hash values and to do a string compare only
  1425. X *        for entries that have matching hash_key values.  This elliminates
  1426. X *        99.9999% of all extraneous string compare operations when searching
  1427. X *        a hash table chain for matching entries.  */
  1428. X
  1429. Xtypedef struct hcell {
  1430. X    struct hcell    *ht_next;    /* next entry in the hash table */
  1431. X    char        *ht_name;    /* name of this cell */
  1432. X    char        *ht_value;    /* cell value if and */
  1433. X    uint32        ht_hash;    /* actual hash_value of cell */
  1434. X    int        ht_flag;    /* flags belonging to hash entry */
  1435. X
  1436. X    /* NOTE: some macros have corresponding variables defined
  1437. X     * that control program behaviour.  For these macros a
  1438. X     * bit of ht_flag indicates the variable value will be set, and the
  1439. X     * type of the value that will be set.
  1440. X     *
  1441. X     * The struct below contains a mask for bit variables, and a
  1442. X     * pointer to the global STATIC location for that variable.
  1443. X     * String and char variables point to the same place as ht_value
  1444. X     * and must be updated when ht_value changes, bit variables must
  1445. X     * have their value recomputed. See Def_macro code for more
  1446. X     * details.
  1447. X     *
  1448. X     * NOTE:  Macro variables and Targets are always distinct.  Thus
  1449. X     * the value union contains pointers back at cells that own
  1450. X     * a particular name entry.  A conflict in this can never
  1451. X     * arise, ie pointers at cells will never be used as
  1452. X     * values for a macro variable, since the cell and macro
  1453. X     * name spaces are completely distinct. */
  1454. X
  1455. X    struct {
  1456. X        int    mv_mask;    /* bit mask for bit variable      */
  1457. X        union {
  1458. X             char**    mv_svar;/* ptr to string valued glob var  */
  1459. X            char*    mv_cvar;/* ptr to char   valued glob var */
  1460. X            uint16*    mv_bvar;/* ptr to bit    valued glob var */
  1461. X             int*    mv_ivar;/* ptr to int    valued glob var  */
  1462. X
  1463. X            struct {
  1464. X               struct tcell* ht_owner;/* ptr to CELL owning name */
  1465. X               struct tcell* ht_root; /* rootdir ptr for hash    */
  1466. X            } ht;
  1467. X        } val;
  1468. X    } var;                /* variable's static equivalent */
  1469. X} HASH, *HASHPTR;
  1470. X
  1471. X#define MV_MASK        var.mv_mask
  1472. X#define MV_SVAR     var.val.mv_svar
  1473. X#define MV_CVAR     var.val.mv_cvar
  1474. X#define MV_BVAR     var.val.mv_bvar
  1475. X#define MV_IVAR     var.val.mv_ivar
  1476. X#define CP_OWNR         var.val.ht.ht_owner
  1477. X#define CP_ROOT        var.val.ht.ht_root
  1478. X
  1479. X
  1480. X
  1481. X/* This struct holds the list of temporary files that have been created.
  1482. SHAR_EOF
  1483. echo "End of part 3"
  1484. echo "File struct.h is continued in part 4"
  1485. echo "4" > s2_seq_.tmp
  1486. exit 0
  1487.  
  1488.