|
From: Pascal B. <pb...@us...> - 2001-12-03 13:32:13
|
Update of /cvsroot/mpkg/mpkg/src
In directory usw-pr-cvs1:/tmp/cvs-serv7884/src
Modified Files:
dist.c file.c mpkg.h
Log Message:
* src/dist.c (fnmatch.h): Include it, and check fnmatch presence.
Delete patmatch.
(add_depend): Tempory variable is no longer in register.
New global variable dist.
(add_command, add_depend, add_file, free_dist, sort_dist_files):
Don't put dist in arguments.
(read_dist): Change functions calls.
(struct fileinfo): New.
Index: dist.c
===================================================================
RCS file: /cvsroot/mpkg/mpkg/src/dist.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** dist.c 2001/11/28 14:20:46 1.8
--- dist.c 2001/12/03 13:32:09 1.9
***************
*** 1,19 ****
! /*
! * Distribution functions for Meta pkg (mpkg).
! *
! * Copyright 2001 by CubicSoft.
! * Copyright 1999-2001 by Easy Software Products.
! *
! * This program is free software; you can redistribute it and/or modify
! * it under the terms of the GNU General Public License as published by
! * the Free Software Foundation; either version 2, or (at your option)
! * any later version.
! *
! * This program is distributed in the hope that it will be useful,
! * but WITHOUT ANY WARRANTY; without even the implied warranty of
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! * GNU General Public License for more details.
! */
#if defined HAVE_CONFIG_H
# include <config.h>
--- 1,17 ----
! /* Distribution functions for Meta pkg (mpkg).
+ Copyright 2001 by CubicSoft.
+ Copyright 1999-2001 by Easy Software Products.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details. */
+
#if defined HAVE_CONFIG_H
# include <config.h>
***************
*** 67,70 ****
--- 65,74 ----
#endif
+ #if HAVE_FNMATCH_H
+ # include <fnmatch.h>
+ #else /* not HAVE_FNMATCH_H */
+ # include <libmisc/fnmatch.h>
+ #endif
+
#if HAVE_UNISTD_H
# include <unistd.h>
***************
*** 80,83 ****
--- 84,89 ----
#include <stdio.h>
+ static dist_t *dist = NULL; /* Distribution information. */
+
/* That's could be better to delete this in the future. I prefere
create a header. */
***************
*** 94,98 ****
int *skip));
static int get_vernumber PARAMS ((const char *version));
- static int patmatch PARAMS ((const char *, const char *));
#define SKIP_SYSTEM 1 /* Not the right system */
--- 100,103 ----
***************
*** 111,116 ****
/* Add a command to the distribution. */
void
! add_command (dist_t * dist, /* I - Distribution */
! FILE * fp, /* I - Distribution file */
char type, /* I - Command type */
const char *command) /* I - Command string */
--- 116,120 ----
/* Add a command to the distribution. */
void
! add_command (FILE * fp, /* I - Distribution file */
char type, /* I - Command type */
const char *command) /* I - Command string */
***************
*** 166,171 ****
/* Add a dependency to the distribution. */
void
! add_depend (dist_t *dist, /* I - Distribution */
! char type, /* I - Type of dependency */
const char *line) /* I - Line from file */
{
--- 170,174 ----
/* Add a dependency to the distribution. */
void
! add_depend (char type, /* I - Type of dependency */
const char *line) /* I - Line from file */
{
***************
*** 204,208 ****
line++;
! LOGVERBOSE (printf (stderr, "Add dependency <%s>(%u).\n",
(char *)temp->product, (int)dist->num_depends));
--- 207,211 ----
line++;
! LOGVERBOSE (fprintf (stderr, "Add dependency <%s>(%u).\n",
(char *)temp->product, (int)dist->num_depends));
***************
*** 265,281 ****
/* Add a file to the distribution. */
file_t * /* O - New file */
! add_file (dist_t *dist) /* I - Distribution */
{
file_t *file; /* New file */
! if (dist->num_files == 0)
! dist->files = (file_t *) malloc (sizeof (file_t));
else
! dist->files = (file_t *) realloc (dist->files, sizeof (file_t) *
! (dist->num_files + 1));
! file = dist->files + dist->num_files;
! dist->num_files++;
return (file);
}
--- 268,290 ----
/* Add a file to the distribution. */
file_t * /* O - New file */
! add_file (dist_t *ldist) /* I - Distribution */
{
file_t *file; /* New file */
+ dist_t *mdist;
! if (ldist)
! mdist = ldist;
else
! mdist = dist;
! if (mdist->num_files == 0)
! mdist->files = (file_t *) malloc (sizeof (file_t));
! else
! mdist->files = (file_t *) realloc (mdist->files, sizeof (file_t) *
! (mdist->num_files + 1));
+ file = mdist->files + mdist->num_files;
+ mdist->num_files++;
+
return (file);
}
***************
*** 284,307 ****
/* Free memory used by a distribution. */
void
! free_dist (dist_t * dist) /* I - Distribution to free */
{
int i; /* Looping var */
! if (dist->num_files > 0)
! free (dist->files);
! free_strings (dist->num_descriptions, dist->descriptions);
! for (i = 0; i < dist->num_commands; i++)
! free (dist->commands[i].command);
! if (dist->num_commands)
! free (dist->commands);
! if (dist->num_depends)
! free (dist->depends);
! free (dist);
}
--- 293,316 ----
/* Free memory used by a distribution. */
void
! free_dist (dist_t *ldist) /* I - Distribution to free */
{
int i; /* Looping var */
! if (ldist->num_files > 0)
! free (ldist->files);
! free_strings (ldist->num_descriptions, ldist->descriptions);
! for (i = 0; i < ldist->num_commands; i++)
! free (ldist->commands[i].command);
! if (ldist->num_commands)
! free (ldist->commands);
! if (ldist->num_depends)
! free (ldist->depends);
! free (ldist);
}
***************
*** 404,408 ****
--- 413,481 ----
}
+ /* Produce pattern matching for general informations like `toto/*'. */
+ struct fileinfo
+ {
+ char type;
+ int mode;
+ const char *group;
+ const char *user;
+ };
+
+ int
+ explore_dir (const struct fileinfo *finfo, char *temp, const char *src,
+ const char *pattern, const char *dst)
+ {
+ DIR *dir;
+ DIRENT *dent;
+ struct stat fileinfo;
+ file_t *file;
+ if (temp == src)
+ dir = opendir (".");
+ else
+ dir = opendir (src);
+
+ if (dir == NULL)
+ {
+ fprintf (stderr,
+ "mpkg: Unable to open directory \"%s\" - %s\n",
+ src, strerror (errno));
+ return 1;
+ }
+ else
+ {
+ /* Make sure we have a directory separator. */
+ if (temp > src)
+ temp[-1] = '/';
+
+ while ((dent = readdir (dir)) != NULL)
+ {
+ strcpy (temp, dent->d_name);
+ if (stat (src, &fileinfo))
+ continue; /* Skip files we can't read. */
+
+ if (S_ISDIR (fileinfo.st_mode))
+ continue; /* Skip directories. */
+
+ if (!fnmatch (dent->d_name, pattern, 0))
+ continue;
+
+ file = add_file (NULL);
+
+ file->type = finfo->type;
+ file->mode = finfo->mode;
+ strcpy (file->src, src);
+ strcpy (file->dst, dst);
+ strncat (file->dst, dent->d_name,
+ sizeof (file->dst) - 1);
+ strcpy (file->user, finfo->user);
+ strcpy (file->group, finfo->group);
+ }
+
+ closedir (dir);
+ }
+ return 0;
+ }
+
/* Read a software distribution. */
***************
*** 429,437 ****
int mode; /* File permissions */
int skip; /* 1 = skip files, 0 = archive files */
- dist_t *dist; /* Distribution data */
file_t *file; /* Distribution file */
- struct stat fileinfo; /* File information */
- DIR *dir; /* Directory */
- DIRENT *dent; /* Directory entry */
struct passwd *pwd; /* Password entry */
--- 502,506 ----
***************
*** 439,442 ****
--- 508,513 ----
/* Create a new, blank distribution. */
LOGVERBOSE (fprintf (stderr, "Alloc new distribution.\n"));
+ /* This is not very secure to alloc dist here, but this a better
+ performance issue. */
dist = (dist_t *) calloc (sizeof (dist_t), 1);
***************
*** 493,516 ****
listfiles[listlevel], temp);
else if (strcmp (line, "%preinstall") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_PRE_INSTALL,
! temp);
else if (strcmp (line, "%install") == 0
|| strcmp (line, "%postinstall") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_POST_INSTALL,
! temp);
else if (strcmp (line, "%remove") == 0
|| strcmp (line, "%preremove") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_PRE_REMOVE,
! temp);
else if (strcmp (line, "%postremove") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_POST_REMOVE,
! temp);
else if (strcmp (line, "%prepatch") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_PRE_PATCH,
! temp);
else if (strcmp (line, "%patch") == 0
|| strcmp (line, "%postpatch") == 0)
! add_command (dist, listfiles[listlevel], COMMAND_POST_PATCH,
! temp);
else if (strcmp (line, "%product") == 0)
{
--- 564,581 ----
listfiles[listlevel], temp);
else if (strcmp (line, "%preinstall") == 0)
! add_command (listfiles[listlevel], COMMAND_PRE_INSTALL, temp);
else if (strcmp (line, "%install") == 0
|| strcmp (line, "%postinstall") == 0)
! add_command (listfiles[listlevel], COMMAND_POST_INSTALL, temp);
else if (strcmp (line, "%remove") == 0
|| strcmp (line, "%preremove") == 0)
! add_command (listfiles[listlevel], COMMAND_PRE_REMOVE, temp);
else if (strcmp (line, "%postremove") == 0)
! add_command (listfiles[listlevel], COMMAND_POST_REMOVE, temp);
else if (strcmp (line, "%prepatch") == 0)
! add_command (listfiles[listlevel], COMMAND_PRE_PATCH, temp);
else if (strcmp (line, "%patch") == 0
|| strcmp (line, "%postpatch") == 0)
! add_command (listfiles[listlevel], COMMAND_POST_PATCH, temp);
else if (strcmp (line, "%product") == 0)
{
***************
*** 603,613 ****
}
else if (strcmp (line, "%incompat") == 0)
! add_depend (dist, DEPEND_INCOMPAT, temp);
else if (strcmp (line, "%provides") == 0)
! add_depend (dist, DEPEND_PROVIDES, temp);
else if (strcmp (line, "%replaces") == 0)
! add_depend (dist, DEPEND_REPLACES, temp);
else if (strcmp (line, "%requires") == 0)
! add_depend (dist, DEPEND_REQUIRES, temp);
else
{
--- 668,678 ----
}
else if (strcmp (line, "%incompat") == 0)
! add_depend (DEPEND_INCOMPAT, temp);
else if (strcmp (line, "%provides") == 0)
! add_depend (DEPEND_PROVIDES, temp);
else if (strcmp (line, "%replaces") == 0)
! add_depend (DEPEND_REPLACES, temp);
else if (strcmp (line, "%requires") == 0)
! add_depend (DEPEND_REQUIRES, temp);
else
{
***************
*** 683,686 ****
--- 748,753 ----
if (*temp)
{
+ struct fileinfo finfo;
+
/* Add using wildcards. */
if ((temp = strrchr (src, '/')) == NULL)
***************
*** 694,744 ****
if (dst[strlen (dst) - 1] != '/')
strncat (dst, "/", sizeof (dst) - 1);
-
- if (temp == src)
- dir = opendir (".");
- else
- dir = opendir (src);
! if (dir == NULL)
! fprintf (stderr,
! "mpkg: Unable to open directory \"%s\" - %s\n",
! src, strerror (errno));
! else
! {
! /* Make sure we have a directory separator. */
! if (temp > src)
! temp[-1] = '/';
!
! while ((dent = readdir (dir)) != NULL)
! {
! strcpy (temp, dent->d_name);
! if (stat (src, &fileinfo))
! continue; /* Skip files we can't read. */
!
! if (S_ISDIR (fileinfo.st_mode))
! continue; /* Skip directories. */
!
! if (!patmatch (dent->d_name, pattern))
! continue;
!
! file = add_file (dist);
!
! file->type = type;
! file->mode = mode;
! strcpy (file->src, src);
! strcpy (file->dst, dst);
! strncat (file->dst, dent->d_name,
! sizeof (file->dst) - 1);
! strcpy (file->user, user);
! strcpy (file->group, group);
! }
!
! closedir (dir);
! }
}
else
{
/* Add single file. */
! file = add_file (dist);
file->type = type;
--- 761,776 ----
if (dst[strlen (dst) - 1] != '/')
strncat (dst, "/", sizeof (dst) - 1);
! finfo.type = type;
! finfo.mode = mode;
! finfo.group = group;
! finfo.user = user;
! if (explore_dir (&finfo, temp, src, pattern, dst))
! return NULL;
}
else
{
/* Add single file. */
! file = add_file (NULL);
file->type = type;
***************
*** 770,774 ****
}
! sort_dist_files (dist);
return (dist);
--- 802,806 ----
}
! sort_dist_files (NULL);
return (dist);
***************
*** 778,798 ****
/* Sort the files in the distribution. */
void
! sort_dist_files (dist_t * dist) /* I - Distribution to sort */
{
int i; /* Looping var */
file_t *file; /* File in distribution */
/* Sort the files. */
! if (dist->num_files > 1)
! qsort (dist->files, dist->num_files, sizeof (file_t),
(int (*)(const void *, const void *)) compare_files);
/* Remove duplicates. */
! for (i = dist->num_files - 1, file = dist->files; i > 0; i--, file++)
if (strcmp (file[0].dst, file[1].dst) == 0)
{
memcpy (file, file + 1, i * sizeof (file_t));
! dist->num_files--;
file--;
}
--- 810,832 ----
/* Sort the files in the distribution. */
void
! sort_dist_files (dist_t *ldist) /* I - Distribution to sort */
{
int i; /* Looping var */
file_t *file; /* File in distribution */
+ dist_t *mdist;
+ mdist = (ldist ? ldist : dist);
/* Sort the files. */
! if (mdist->num_files > 1)
! qsort (mdist->files, mdist->num_files, sizeof (file_t),
(int (*)(const void *, const void *)) compare_files);
/* Remove duplicates. */
! for (i = mdist->num_files - 1, file = mdist->files; i > 0; i--, file++)
if (strcmp (file[0].dst, file[1].dst) == 0)
{
memcpy (file, file + 1, i * sizeof (file_t));
! mdist->num_files--;
file--;
}
***************
*** 1032,1036 ****
_get_line (FILE *fp, char *buffer, int size)
{
! register char c = 0;
register int fd = fileno(fp);
char *tmp = buffer;
--- 1066,1070 ----
_get_line (FILE *fp, char *buffer, int size)
{
! char c = 0;
register int fd = fileno(fp);
char *tmp = buffer;
***************
*** 1461,1550 ****
}
-
- /* Pattern matching. */
-
- /* FIXME : Substitute this function to `fnmatch', which is standard on
- GNU system, and it is presente in `deb' library. -- Pascal. */
-
- static int /* O - 1 if match, 0 if no match */
- patmatch (const char *s, /* I - String to match against */
- const char *pat) /* I - Pattern to match against */
- {
- /* Range check the input. */
- if (s == NULL || pat == NULL)
- return (0);
-
- /*
- * Loop through the pattern and match strings, and stop if we come to a
- * point where the strings don't match or we find a complete match.
- */
-
- while (*s != '\0' && *pat != '\0')
- {
- if (*pat == '*')
- {
- /* Wildcard - 0 or more characters. */
- pat++;
- if (*pat == '\0')
- return (1); /* Last pattern char is *, so everything matches now. */
-
- /* Test all remaining combinations until we get to the end of the
- string. */
-
- while (*s != '\0')
- {
- if (patmatch (s, pat))
- return (1);
-
- s++;
- }
- }
- else if (*pat == '?')
- {
- /* Wildcard - 1 character. */
- pat++;
- s++;
- continue;
- }
- else if (*pat == '[')
- {
- /* Match a character from the input set [chars]. */
- pat++;
- while (*pat != ']' && *pat != '\0')
- if (*s == *pat)
- break;
- else if (pat[1] == '-' && *s >= pat[0] && *s <= pat[2])
- break;
- else
- pat++;
-
- if (*pat == ']' || *pat == '\0')
- return (0);
-
- while (*pat != ']' && *pat != '\0')
- pat++;
-
- if (*pat == ']')
- pat++;
-
- s++;
-
- continue;
- }
- else if (*pat == '\\')
- {
- /* Handle quoted characters. */
- pat++;
- }
-
- /* Stop if the pattern and string don't match. */
- if (*pat++ != *s++)
- return (0);
- }
-
- /*
- * Done parsing the pattern and string; return 1 if the last character matches
- * and 0 otherwise...
- */
- return (*s == *pat);
- }
--- 1495,1496 ----
Index: file.c
===================================================================
RCS file: /cvsroot/mpkg/mpkg/src/file.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** file.c 2001/10/25 16:18:40 1.3
--- file.c 2001/12/03 13:32:09 1.4
***************
*** 1,30 ****
! /*
! * File functions for Mete pkg (mpkg).
! *
! * Copyright 2001 by CubicSoft.
! * Copyright 1999-2001 by Easy Software Products.
! *
! * This program is free software; you can redistribute it and/or modify
! * it under the terms of the GNU General Public License as published by
! * the Free Software Foundation; either version 2, or (at your option)
! * any later version.
! *
! * This program is distributed in the hope that it will be useful,
! * but WITHOUT ANY WARRANTY; without even the implied warranty of
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! * GNU General Public License for more details.
! *
! * Contents:
! *
! * copy_file() - Copy a file...
! * make_directory() - Make a directory.
! * make_link() - Make a symbolic link.
! * strip_execs() - Strip symbols from executable files in the
! * distribution.
! */
! /*
! * Include necessary headers...
! */
#include "mpkg.h"
--- 1,16 ----
! /* File functions for Mete pkg (mpkg).
! Copyright 2001 by CubicSoft.
! Copyright 1999-2001 by Easy Software Products.
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2, or (at your option)
! any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details. */
#include "mpkg.h"
***************
*** 41,49 ****
#endif
-
- /*
- * 'copy_file()' - Copy a file...
- */
-
int /* O - 0 on success, -1 on failure */
copy_file (const char *dst, /* I - Destination file */
--- 27,30 ----
***************
*** 60,67 ****
! /*
! * Check that the destination directory exists...
! */
!
strcpy (buffer, dst);
if ((slash = strrchr (buffer, '/')) != NULL)
--- 41,45 ----
! /* Check that the destination directory exists. */
strcpy (buffer, dst);
if ((slash = strrchr (buffer, '/')) != NULL)
***************
*** 71,78 ****
make_directory (buffer, 0755, owner, group);
! /*
! * Open files...
! */
!
unlink (dst);
--- 49,53 ----
make_directory (buffer, 0755, owner, group);
! /* Open files. */
unlink (dst);
***************
*** 94,101 ****
}
! /*
! * Copy from src to dst...
! */
!
while ((bytes = fread (buffer, 1, sizeof (buffer), srcfile)) > 0)
if (fwrite (buffer, 1, bytes, dstfile) < bytes)
--- 69,73 ----
}
! /* Copy from src to dst. */
while ((bytes = fread (buffer, 1, sizeof (buffer), srcfile)) > 0)
if (fwrite (buffer, 1, bytes, dstfile) < bytes)
***************
*** 111,118 ****
}
! /*
! * Close files, change permissions, and return...
! */
!
fclose (srcfile);
fclose (dstfile);
--- 83,87 ----
}
! /* Close files, change permissions, and return. */
fclose (srcfile);
fclose (dstfile);
***************
*** 124,132 ****
}
-
- /*
- * 'make_directory()' - Make a directory.
- */
-
int /* O - 0 = success, -1 = error */
make_directory (const char *directory, /* I - Directory */
--- 93,96 ----
***************
*** 169,176 ****
! /*
! * 'make_link()' - Make a symbolic link.
! */
!
int /* O - 0 = success, -1 = error */
make_link (const char *dst, /* I - Destination file */
--- 133,137 ----
! /* 'make_link()' - Make a symbolic link. */
int /* O - 0 = success, -1 = error */
make_link (const char *dst, /* I - Destination file */
***************
*** 200,207 ****
! /*
! * 'strip_execs()' - Strip symbols from executable files in the distribution.
! */
!
void
strip_execs (dist_t * dist) /* I - Distribution to strip... */
--- 161,165 ----
! /* 'strip_execs()' - Strip symbols from executable files in the distribution. */
void
strip_execs (dist_t * dist) /* I - Distribution to strip... */
Index: mpkg.h
===================================================================
RCS file: /cvsroot/mpkg/mpkg/src/mpkg.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** mpkg.h 2001/11/28 14:20:46 1.3
--- mpkg.h 2001/12/03 13:32:09 1.4
***************
*** 235,242 ****
*/
! void add_command PARAMS ((dist_t *dist, FILE *fp, char type,
const char *command));
! void add_depend PARAMS ((dist_t *dist, char type, const char *line));
! file_t *add_file PARAMS ((dist_t *dist));
int copy_file PARAMS ((const char *dst, const char *src,
int mode, int owner, int group));
--- 235,242 ----
*/
! void add_command PARAMS ((FILE *fp, char type,
const char *command));
! void add_depend PARAMS ((char type, const char *line));
! file_t *add_file PARAMS ((dist_t*));
int copy_file PARAMS ((const char *dst, const char *src,
int mode, int owner, int group));
***************
*** 287,291 ****
const char *format));
int run_command PARAMS ((const char *directory, const char *command, ...));
! void sort_dist_files PARAMS ((dist_t *dist));
void strip_execs PARAMS ((dist_t *dist));
--- 287,291 ----
const char *format));
int run_command PARAMS ((const char *directory, const char *command, ...));
! void sort_dist_files PARAMS ((dist_t*));
void strip_execs PARAMS ((dist_t *dist));
|