home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / MAK358AS.ZIP / AR.C next >
Encoding:
C/C++ Source or Header  |  1992-02-22  |  4.6 KB  |  172 lines

  1. /* Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  2. This file is part of GNU Make.
  3.  
  4. GNU Make is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8.  
  9. GNU Make is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with GNU Make; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  * MS-DOS port (c) 1990 by Thorsten Ohl <ohl@gnu.ai.mit.edu>
  20.  *
  21.  * To this port, the same copying conditions apply as to the
  22.  * original release.
  23.  *
  24.  * IMPORTANT:
  25.  * This file is not identical to the original GNU release!
  26.  * You should have received this code as patch to the official
  27.  * GNU release.
  28.  *
  29.  * MORE IMPORTANT:
  30.  * This port comes with ABSOLUTELY NO WARRANTY.
  31.  *
  32.  * $Header: e:/gnu/make/RCS/ar.c'v 3.58.0.2 90/07/18 10:17:58 tho Exp $
  33.  */
  34.  
  35. #include "make.h"
  36. #include "file.h"
  37.  
  38.  
  39.  
  40. #ifdef MSDOS
  41. /* Defined in zipscan.c.  */
  42. extern long ar_scan (char *archive, long (*f) (int, char *, long, long, long,
  43.              long, int, int, int, long), long arg);
  44. extern long ar_name_equal (char *name, char *mem);
  45. extern long ar_member_touch (char *arname, char *memname);
  46. #else /* not MSDOS */
  47. /* Defined in arscan.c.  */
  48. extern long int ar_scan ();
  49. extern int ar_member_touch ();
  50. #endif /* not MSDOS */
  51.  
  52.  
  53. /* Return nonzero if NAME is an archive-member reference, zero if not.
  54.    An archive-member reference is a name like `lib(member)'.
  55.    If a name like `lib((entry))' is used, a fatal error is signaled at
  56.    the attempt to use this unsupported feature.  */
  57.  
  58. int
  59. ar_name (name)
  60.      char *name;
  61. {
  62.   char *p = index (name, '('), *end = name + strlen (name) - 1;
  63.   
  64.   if (p == 0 || p == name || *end != ')')
  65.     return 0;
  66.  
  67.   if (p[1] == '(' && end[-1] == ')')
  68.     fatal ("attempt to use unsupported feature: `%s'", name);
  69.  
  70.   return 1;
  71. }
  72.  
  73. static long int ar_member_date_1 ();
  74.  
  75. /* Return the modtime of NAME.  */
  76.  
  77. time_t
  78. ar_member_date (name)
  79.      char *name;
  80. {
  81.   char *arname;
  82.   char *memname;
  83.   char *p;
  84.   long int val;
  85.  
  86.   /* This "file" is an archive member.  */
  87.   p = index (name, '(');
  88.   arname = savestring (name, p - name);
  89.   val = strlen (p) - 2;
  90.   if (val > 15)
  91.     val = 15;
  92.   memname = savestring (p + 1, val);
  93.   p = rindex (memname, ')');
  94.   if (p != 0)
  95.     *p = '\0';
  96.  
  97.   /* Make sure we know the modtime of the archive itself because
  98.      we are likely to be called just before commands to remake a
  99.      member are run, and they will change the archive itself.  */
  100.   (void) f_mtime (enter_file (arname), 0);
  101.  
  102.   val = ar_scan (arname, ar_member_date_1, (long int) memname);
  103.  
  104.   free (arname);
  105.   free (memname);
  106.   return (val <= 0 ? (time_t) -1 : (time_t) val);
  107. }
  108.  
  109. /* This function is called by `ar_scan' to find which member to look at.  */
  110.  
  111. /* ARGSUSED */
  112. static long int
  113. ar_member_date_1 (desc, name, hdrpos, datapos, size, date, uid, gid, mode, mem)
  114.      int desc;
  115.      char *name;
  116.      long int hdrpos, datapos, size, date;
  117.      int uid, gid, mode;
  118.      char *mem;
  119. {
  120.   return ar_name_equal (name, mem) ? date : 0;
  121. }
  122.  
  123. /* Set the archive-member NAME's modtime to now.  */
  124.  
  125. int
  126. ar_touch (name)
  127.      char *name;
  128. {
  129.   register char *p, *arname, *memname;
  130.   register int val;
  131.  
  132.   p = index (name, '(');
  133.   arname = savestring (name, p - name);
  134.   val = strlen (p) - 2;
  135.   if (val > 15)
  136.     val = 15;
  137.   memname = savestring (p + 1, val);
  138.   p = rindex (memname, ')');
  139.   if (p != 0)
  140.     *p = '\0';
  141.  
  142.   /* Make sure we know the modtime of the archive itself before we
  143.      touch the member, since this will change the archive itself.  */
  144.   (void) f_mtime (enter_file (arname), 0);
  145.  
  146.   val = 1;
  147.   switch (ar_member_touch (arname, memname))
  148.     {
  149.     case -1:
  150.       error ("touch: Archive `%s' does not exist", arname);
  151.       break;
  152.     case -2:
  153.       error ("touch: `%s' is not a valid archive", arname);
  154.     case -3:
  155.       perror_with_name ("touch: ", arname);
  156.       break;
  157.     case 1:
  158.       error ("touch: Member `%s' does not exist in `%s'", memname, arname);
  159.       break;
  160.     case 0:
  161.       val = 0;
  162.       break;
  163.     default:
  164.       error ("touch: Bad return code from ar_member_touch on `%s'", name);
  165.     }
  166.  
  167.   free (arname);
  168.   free (memname);
  169.  
  170.   return val;
  171. }
  172.