Changeset 903 in kBuild for trunk/src/gmakenew/ar.c
- Timestamp:
- May 23, 2007 5:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/ar.c
r503 r903 25 25 #include <fnmatch.h> 26 26 27 /* Defined in arscan.c. */28 extern long int ar_scan PARAMS ((char *archive, long int (*function) (), long int arg));29 extern int ar_name_equal PARAMS ((char *name, char *mem, int truncated));30 #ifndef VMS31 extern int ar_member_touch PARAMS ((char *arname, char *memname));32 #endif33 34 27 /* Return nonzero if NAME is an archive-member reference, zero if not. 35 28 An archive-member reference is a name like `lib(member)'. … … 38 31 39 32 int 40 ar_name (c har *name)41 { 42 c har *p = strchr (name, '(');43 c har *end;33 ar_name (const char *name) 34 { 35 const char *p = strchr (name, '('); 36 const char *end; 44 37 45 38 if (p == 0 || p == name) … … 58 51 59 52 /* Parse the archive-member reference NAME into the archive and member names. 60 Put the malloc'd archive name in *ARNAME_P if ARNAME_P is non-nil;61 put the malloc'd member name in *MEMNAME_P if MEMNAME_P is non-nil. */53 Creates one allocated string containing both names, pointed to by ARNAME_P. 54 MEMNAME_P points to the member. */ 62 55 63 56 void 64 ar_parse_name (char *name, char **arname_p, char **memname_p) 65 { 66 char *p = strchr (name, '('), *end = name + strlen (name) - 1; 67 68 if (arname_p != 0) 69 *arname_p = savestring (name, p - name); 70 71 if (memname_p != 0) 72 *memname_p = savestring (p + 1, end - (p + 1)); 73 } 74 75 76 static long int ar_member_date_1 PARAMS ((int desc, char *mem, int truncated, long int hdrpos, 77 long int datapos, long int size, long int date, int uid, int gid, int mode, char *name)); 57 ar_parse_name (const char *name, char **arname_p, char **memname_p) 58 { 59 char *p; 60 61 *arname_p = xstrdup (name); 62 p = strchr (*arname_p, '('); 63 *(p++) = '\0'; 64 p[strlen(p) - 1] = '\0'; 65 *memname_p = p; 66 } 67 68 69 70 /* This function is called by `ar_scan' to find which member to look at. */ 71 72 /* ARGSUSED */ 73 static long int 74 ar_member_date_1 (int desc UNUSED, const char *mem, int truncated, 75 long int hdrpos UNUSED, long int datapos UNUSED, 76 long int size UNUSED, long int date, 77 int uid UNUSED, int gid UNUSED, int mode UNUSED, 78 const void *name) 79 { 80 return ar_name_equal (name, mem, truncated) ? date : 0; 81 } 78 82 79 83 /* Return the modtime of NAME. */ 80 84 81 85 time_t 82 ar_member_date (c har *name)86 ar_member_date (const char *name) 83 87 { 84 88 char *arname; 85 int arname_used = 0;86 89 char *memname; 87 90 long int val; … … 100 103 arfile = lookup_file (arname); 101 104 if (arfile == 0 && file_exists_p (arname)) 102 { 103 arfile = enter_file (arname); 104 arname_used = 1; 105 } 105 arfile = enter_file (strcache_add (arname)); 106 106 107 107 if (arfile != 0) … … 109 109 } 110 110 111 val = ar_scan (arname, ar_member_date_1, (long int) memname); 112 113 if (!arname_used) 114 free (arname); 115 free (memname); 111 val = ar_scan (arname, ar_member_date_1, memname); 112 113 free (arname); 116 114 117 115 return (val <= 0 ? (time_t) -1 : (time_t) val); 118 }119 120 /* This function is called by `ar_scan' to find which member to look at. */121 122 /* ARGSUSED */123 static long int124 ar_member_date_1 (int desc UNUSED, char *mem, int truncated,125 long int hdrpos UNUSED, long int datapos UNUSED,126 long int size UNUSED, long int date,127 int uid UNUSED, int gid UNUSED, int mode UNUSED, char *name)128 {129 return ar_name_equal (name, mem, truncated) ? date : 0;130 116 } 131 117 … … 135 121 #ifdef VMS 136 122 int 137 ar_touch (c har *name)123 ar_touch (const char *name) 138 124 { 139 125 error (NILF, _("touch archive member is not available on VMS")); … … 142 128 #else 143 129 int 144 ar_touch (c har *name)130 ar_touch (const char *name) 145 131 { 146 132 char *arname, *memname; 147 int arname_used = 0; 148 register int val; 133 int val; 149 134 150 135 ar_parse_name (name, &arname, &memname); 151 136 152 137 /* Make sure we know the modtime of the archive itself before we 153 touch the member, since this will change the archive itself. */138 touch the member, since this will change the archive modtime. */ 154 139 { 155 140 struct file *arfile; 156 arfile = lookup_file (arname); 157 if (arfile == 0) 158 { 159 arfile = enter_file (arname); 160 arname_used = 1; 161 } 162 163 (void) f_mtime (arfile, 0); 141 arfile = enter_file (strcache_add (arname)); 142 f_mtime (arfile, 0); 164 143 } 165 144 … … 188 167 } 189 168 190 if (!arname_used) 191 free (arname); 192 free (memname); 169 free (arname); 193 170 194 171 return val; … … 201 178 struct ar_glob_state 202 179 { 203 c har *arname;204 c har *pattern;180 const char *arname; 181 const char *pattern; 205 182 unsigned int size; 206 183 struct nameseq *chain; … … 212 189 213 190 static long int 214 ar_glob_match (int desc UNUSED, c har *mem, int truncated UNUSED,191 ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED, 215 192 long int hdrpos UNUSED, long int datapos UNUSED, 216 193 long int size UNUSED, long int date UNUSED, int uid UNUSED, 217 int gid UNUSED, int mode UNUSED, struct ar_glob_state *state) 218 { 194 int gid UNUSED, int mode UNUSED, const void *arg) 195 { 196 struct ar_glob_state *state = (struct ar_glob_state *)arg; 197 219 198 if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0) 220 199 { 221 200 /* We have a match. Add it to the chain. */ 222 struct nameseq *new = (struct nameseq *)xmalloc (state->size);223 new->name = concat (state->arname, mem, ")");201 struct nameseq *new = xmalloc (state->size); 202 new->name = strcache_add (concat (state->arname, mem, ")")); 224 203 new->next = state->chain; 225 204 state->chain = new; … … 267 246 268 247 struct nameseq * 269 ar_glob (c har *arname,char *member_pattern, unsigned int size)248 ar_glob (const char *arname, const char *member_pattern, unsigned int size) 270 249 { 271 250 struct ar_glob_state state; 272 char **names;273 251 struct nameseq *n; 252 const char **names; 253 char *name; 274 254 unsigned int i; 275 255 … … 280 260 ar_glob_match will accumulate them in STATE.chain. */ 281 261 i = strlen (arname); 282 state.arname = (char *) alloca (i + 2); 283 bcopy (arname, state.arname, i); 284 state.arname[i] = '('; 285 state.arname[i + 1] = '\0'; 262 name = alloca (i + 2); 263 memcpy (name, arname, i); 264 name[i] = '('; 265 name[i + 1] = '\0'; 266 state.arname = name; 286 267 state.pattern = member_pattern; 287 268 state.size = size; 288 269 state.chain = 0; 289 270 state.n = 0; 290 (void) ar_scan (arname, ar_glob_match, (long int)&state);271 ar_scan (arname, ar_glob_match, &state); 291 272 292 273 if (state.chain == 0) … … 294 275 295 276 /* Now put the names into a vector for sorting. */ 296 names = (char **) alloca (state.n * sizeof (char *));277 names = alloca (state.n * sizeof (const char *)); 297 278 i = 0; 298 279 for (n = state.chain; n != 0; n = n->next) … … 300 281 301 282 /* Sort them alphabetically. */ 302 qsort ( (char *)names, i, sizeof (*names), alpha_compare);283 qsort (names, i, sizeof (*names), alpha_compare); 303 284 304 285 /* Put them back into the chain in the sorted order. */
Note:
See TracChangeset
for help on using the changeset viewer.