aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-09-08 21:48:22 +0000
committerJason Woodward2003-09-08 21:48:22 +0000
commitc3bee61b1b986fc38f9c89698f117b884acccc81 (patch)
treec77e6b9773b90a34f5408b78b38d6af7ea31dece
parent6a5a324b237b5b3d3013a1039fdfcad8d9cb76b4 (diff)
downloadslapt-get-c3bee61b1b986fc38f9c89698f117b884acccc81.tar.gz
code updates
-rw-r--r--ChangeLog4
-rw-r--r--Makefile4
-rw-r--r--doc/slapt-get.84
-rw-r--r--src/configuration.c36
-rw-r--r--src/configuration.h3
-rw-r--r--src/curl.c8
-rw-r--r--src/main.c6
-rw-r--r--src/package.c92
-rw-r--r--src/package.h2
9 files changed, 90 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index ef64579..c7d0681 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
+0.9 Sep 08, 2003
+ * --re-install is now --reinstall
+ * code updates
+
0.8 Sep 07, 2003
* --remove target now accepts multiple arguments
( --remove pkg1 pkg2 pkg3 pkg4 )
diff --git a/Makefile b/Makefile
index 1d21dee..301885b 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VERSION=0.8
CC=gcc
CURLFLAGS=`curl-config --libs`
CFLAGS=-W -Werror -Wall -O2 -ansi -pedantic -Iinclude
-DEBUGFLAGS=-g
+DEBUGFLAGS=-W -Werror -Wall -ansi -pedantic -Iinclude -g
OBJS=src/configuration.o src/package.o src/curl.o src/action.o src/main.o
RCDEST=/etc/jaospkgrc
RCSOURCE=example.jaospkgrc
@@ -19,7 +19,7 @@ $(PROGNAME): $(OBJS)
$(CC) $(CFLAGS) $(CURLFLAGS) -o $(PROGNAME) $(OBJS)
$(PROGNAME)-debug: $(OBJS)
- $(CC) $(CFLAGS) $(CURLFLAGS) $(DEBUGFLAGS) -o $(PROGNAME) $(OBJS)
+ $(CC) $(DEBUGFLAGS) $(CURLFLAGS) -o $(PROGNAME) $(OBJS)
install: $(PROGNAME)
install $(PROGNAME) $(SBINDIR)
diff --git a/doc/slapt-get.8 b/doc/slapt-get.8
index 6399f91..ea02a9d 100644
--- a/doc/slapt-get.8
+++ b/doc/slapt-get.8
@@ -33,7 +33,7 @@ jaospkg \- frontend to pkgtools
.B --no-prompt
]
[
-.B --re-install
+.B --reinstall
]
[
.B --ignore-excludes
@@ -96,7 +96,7 @@ Will not install or download packages.
.B --no-prompt
Do not prompt for package upgrade confirmation.
.TP
-.B --re-install
+.B --reinstall
Install the package even if it is already installed.
.TP
.B --ignore-excludes
diff --git a/src/configuration.c b/src/configuration.c
index d2a23d4..fab035d 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -219,7 +219,7 @@ struct exclude_list *parse_exclude(char *line){
list->count = 0;
/* skip ahead past the = */
- line = index(line,'=') + 1;
+ line = strchr(line,'=') + 1;
while( position < (int) strlen(line) ){
if( strstr(line + position,",") == NULL ){
@@ -237,8 +237,8 @@ struct exclude_list *parse_exclude(char *line){
continue;
}else{
- pointer = index(line + position,',');
- buffer = calloc( strlen(line + position) - strlen(pointer) + 1, sizeof(char) );
+ pointer = strchr(line + position,',');
+ buffer = calloc( strlen(line + position) - strlen(pointer) + 1, sizeof *buffer );
memcpy(buffer,line + position,strlen(line + position) - strlen(pointer) );
buffer[ strlen(line + position) - strlen(pointer) ] = '\0';
memcpy(list->excludes[ list->count ], buffer, strlen(buffer) );
@@ -254,30 +254,6 @@ struct exclude_list *parse_exclude(char *line){
return list;
}
-int is_excluded(const rc_config *global_config,const char *pkg_name){
- int i;
-
- if( global_config->ignore_excludes == 1 )
- return 0;
-
- /* maybe EXCLUDE= isn't defined in our rc? */
- if( global_config->exclude_list == NULL )
- return 0;
-
- for(i = 0; i < global_config->exclude_list->count;i++){
- /*
- * this is kludgy... global_config->exclude_list->excludes[i] is 1 char longer
- * than pkg_name
- */
- if( (strncmp(global_config->exclude_list->excludes[i],pkg_name,strlen(pkg_name)) == 0)
- && (strlen(global_config->exclude_list->excludes[i]) - strlen(pkg_name) < 2) ){
- return 1;
- }
- }
-
- return 0;
-}
-
/* recursively create dirs */
void create_dir_structure(const char *dir_name){
char *pointer = NULL;
@@ -296,7 +272,7 @@ void create_dir_structure(const char *dir_name){
if( strstr(dir_name + position,"/" ) == NULL ){
/* pointer = dir_name + position; */
- dir_name_buffer = calloc( strlen(dir_name + position) + 1 , sizeof(char) );
+ dir_name_buffer = calloc( strlen(dir_name + position) + 1 , sizeof *dir_name_buffer );
memcpy(dir_name_buffer,dir_name + position,strlen(dir_name + position));
dir_name_buffer[ strlen(dir_name + position) ] = '\0';
@@ -322,9 +298,9 @@ void create_dir_structure(const char *dir_name){
}else{
/* figure our dir name and mk it */
- pointer = index(dir_name + position,'/');
+ pointer = strchr(dir_name + position,'/');
dir_name_buffer = calloc(
- strlen(dir_name + position) - strlen(pointer) + 1 , sizeof(char)
+ strlen(dir_name + position) - strlen(pointer) + 1 , sizeof *dir_name_buffer
);
memcpy(dir_name_buffer,dir_name + position, strlen(dir_name + position) - strlen(pointer));
dir_name_buffer[ (strlen(dir_name + position) - strlen(pointer)) ] = '\0';
diff --git a/src/configuration.h b/src/configuration.h
index 44d71eb..7f8355f 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -21,7 +21,7 @@
#define EXCLUDE_TOKEN "EXCLUDE="
struct exclude_list {
- char excludes[500][50];
+ char excludes[100][50];
int count;
};
@@ -44,5 +44,4 @@ FILE *open_file(const char *,const char *);
char spinner(void);
void clean_pkg_dir(const char *);
struct exclude_list *parse_exclude(char *);
-int is_excluded(const rc_config *,const char *);
void create_dir_structure(const char *);
diff --git a/src/curl.c b/src/curl.c
index 627f29a..effebb8 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -60,7 +60,7 @@ FILE *download_pkg_list(const rc_config *global_config){
#endif
url = calloc(
- strlen(global_config->mirror_url) + strlen(PKG_LIST) + 1, sizeof(char)
+ strlen(global_config->mirror_url) + strlen(PKG_LIST) + 1, sizeof *url
);
if( url == NULL ){
fprintf(stderr,"Failed to calloc url\n");
@@ -96,7 +96,7 @@ FILE *download_patches_list(const rc_config *global_config){
#endif
url = calloc(
- strlen(global_config->mirror_url) + strlen(PATCHDIR) + strlen(PATCHES_LIST) + 1 , sizeof(char)
+ strlen(global_config->mirror_url) + strlen(PATCHDIR) + strlen(PATCHES_LIST) + 1 , sizeof *url
);
if( url == NULL ){
fprintf(stderr,"Failed to calloc url\n");
@@ -123,7 +123,7 @@ char *download_pkg(const rc_config *global_config,pkg_info *pkg){
/* build the file name */
file_name = calloc(
- strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 , sizeof(char)
+ strlen(pkg->name)+strlen("-")+strlen(pkg->version)+strlen(".tgz") + 1 , sizeof *file_name
);
if( file_name == NULL ){
fprintf(stderr,"Failed to calloc file_name\n");
@@ -145,7 +145,7 @@ char *download_pkg(const rc_config *global_config,pkg_info *pkg){
/* build the url */
url = calloc(
- strlen(global_config->mirror_url) + strlen(pkg->location) + strlen(file_name) + strlen("/") + 1 , sizeof(char)
+ strlen(global_config->mirror_url) + strlen(pkg->location) + strlen(file_name) + strlen("/") + 1 , sizeof *url
);
if( url == NULL ){
fprintf(stderr,"Failed to calloc url\n");
diff --git a/src/main.c b/src/main.c
index baefa67..6b28809 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,7 +39,7 @@ int main( int argc, char *argv[] ){
{"simulate", 0, 0, 'm'},
{"version", 0, 0, 'v'},
{"no-prompt", 0, 0, 'b'},
- {"re-install", 0, 0, 'n'},
+ {"reinstall", 0, 0, 'n'},
{"ignore-excludes", 0, 0, 'x'},
};
int option_index = 0;
@@ -122,7 +122,7 @@ int main( int argc, char *argv[] ){
case 'b': /* auto */
global_config->no_prompt = 1;
break;
- case 'n': /* re-install */
+ case 'n': /* reinstall */
global_config->re_install = 1;
break;
case 'x': /* ignore-excludes */
@@ -162,7 +162,7 @@ void usage(){
printf(" --dist-upgrade - assumes MIRROR is set to newer release\n");
printf(" --simulate - show pkgs to be upgraded\n");
printf(" --no-prompt - do not prompt during upgrade\n");
- printf(" --re-install - re-install the pkg even if installed\n");
+ printf(" --reinstall - re-install the pkg even if installed\n");
printf(" --ignore-excludes - install excludes anyway\n");
}
diff --git a/src/package.c b/src/package.c
index 92840ca..ac360d6 100644
--- a/src/package.c
+++ b/src/package.c
@@ -29,7 +29,10 @@ struct pkg_list *parse_pkg_list(void){
char *getline_buffer = NULL;
char *size_c = NULL;
char *size_u = NULL;
- struct pkg_list *list = calloc( 1 , sizeof(struct pkg_list) );
+ pkg_info **realloc_tmp;
+ struct pkg_list *list;
+
+ list = calloc( 1 , sizeof *list );
/* open pkg list */
@@ -41,7 +44,7 @@ struct pkg_list *parse_pkg_list(void){
regcomp(&size_c_regex,PKG_SIZEC_PATTERN, REG_EXTENDED|REG_NEWLINE);
regcomp(&size_u_regex,PKG_SIZEU_PATTERN, REG_EXTENDED|REG_NEWLINE);
- list->pkgs = calloc(1 , sizeof(pkg_info *) );
+ list->pkgs = calloc(1 , sizeof *list->pkgs );
if( list->pkgs == NULL ){
fprintf(stderr,"Failed to calloc pkgs\n");
exit(1);
@@ -56,7 +59,7 @@ struct pkg_list *parse_pkg_list(void){
regexec_return = regexec( &name_regex, getline_buffer, nmatch, pmatch, 0);
if( regexec_return == 0 ){
- list->pkgs[list->pkg_count] = calloc( 1 , sizeof(pkg_info) );
+ list->pkgs[list->pkg_count] = calloc( 1 , sizeof *list->pkgs[list->pkg_count] );
if( list->pkgs[list->pkg_count] == NULL ){
fprintf(stderr,"Failed to calloc list->pkgs[list->pkg_count]\n");
exit(1);
@@ -100,7 +103,7 @@ struct pkg_list *parse_pkg_list(void){
/* size_c */
if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)){
if( (regexec_return = regexec( &size_c_regex, getline_buffer, nmatch, pmatch, 0)) == 0 ){
- size_c = calloc( (pmatch[1].rm_eo - pmatch[1].rm_so) + 1 , sizeof(char) );
+ size_c = calloc( (pmatch[1].rm_eo - pmatch[1].rm_so) + 1 , sizeof *size_c );
if( size_c == NULL ){
fprintf(stderr,"Failed to calloc size_c\n");
exit(1);
@@ -120,7 +123,7 @@ struct pkg_list *parse_pkg_list(void){
/* size_u */
if( (getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)){
if( regexec( &size_u_regex, getline_buffer, nmatch, pmatch, 0) == 0 ){
- size_u = calloc( (pmatch[1].rm_eo - pmatch[1].rm_so) + 1 , sizeof(char) );
+ size_u = calloc( (pmatch[1].rm_eo - pmatch[1].rm_so) + 1 , sizeof *size_u );
if( size_u == NULL ){
fprintf(stderr,"Failed to calloc size_u\n");
exit(1);
@@ -166,10 +169,12 @@ struct pkg_list *parse_pkg_list(void){
list->pkg_count += 1;
/* grow our struct array */
- list->pkgs = realloc(list->pkgs , sizeof(pkg_info *) * (list->pkg_count + 1) );
- if( list->pkgs == NULL ){
+ realloc_tmp = realloc(list->pkgs , sizeof *list->pkgs * (list->pkg_count + 1) );
+ if( realloc_tmp == NULL ){
fprintf(stderr,"Failed to realloc pkgs\n");
exit(1);
+ }else{
+ list->pkgs = realloc_tmp;
}
/* printf("%c\b",spinner()); this interferes with --list scripting */
@@ -185,8 +190,8 @@ char *gen_short_pkg_description(pkg_info *pkg){
char *short_description = NULL;
short_description = calloc(
strlen(pkg->description) - strlen(pkg->name) + 2
- - strlen( index(pkg->description,'\n') ) + 1,
- sizeof(char)
+ - strlen( strchr(pkg->description,'\n') ) + 1,
+ sizeof *short_description
);
if( short_description == NULL ){
fprintf(stderr,"Failed to calloc short_description\n");
@@ -196,7 +201,7 @@ char *gen_short_pkg_description(pkg_info *pkg){
short_description,
pkg->description + (strlen(pkg->name) + 2),
strlen(pkg->description) - (strlen(pkg->name) + 2)
- - strlen( index(pkg->description,'\n') )
+ - strlen( strchr(pkg->description,'\n') )
);
short_description[ strlen(short_description) ] = '\0';
@@ -211,7 +216,10 @@ struct pkg_list *get_installed_pkgs(void){
size_t nmatch = MAX_NMATCH;
regmatch_t pmatch[MAX_PMATCH];
int regexec_return;
- struct pkg_list *list = calloc( 1 , sizeof(struct pkg_list) );
+ pkg_info **realloc_tmp;
+ struct pkg_list *list;
+
+ list = calloc( 1 , sizeof *list );
list->pkg_count = 0;
/* open our pkg_log_dir */
@@ -235,7 +243,7 @@ struct pkg_list *get_installed_pkgs(void){
exit(1);
}
- list->pkgs = calloc( 1 , sizeof(pkg_info *) );
+ list->pkgs = calloc( 1 , sizeof *list->pkgs );
if( list->pkgs == NULL ){
fprintf(stderr,"Failed to calloc pkgs\n");
exit(1);
@@ -244,7 +252,8 @@ struct pkg_list *get_installed_pkgs(void){
while( (file = readdir(pkg_log_dir)) != NULL ){
if( ( regexec(&regex,file->d_name,nmatch,pmatch,0) ) == 0 ){
pkg_info *existing_pkg = NULL;
- pkg_info *tmp_pkg = calloc( 1 , sizeof(pkg_info) );
+ pkg_info *tmp_pkg;
+ tmp_pkg = calloc( 1 , sizeof *tmp_pkg );
if( tmp_pkg == NULL ){
fprintf(stderr,"Failed to calloc tmp_pkg\n");
exit(1);
@@ -268,23 +277,25 @@ struct pkg_list *get_installed_pkgs(void){
if( ((existing_pkg = get_newest_pkg(list->pkgs,tmp_pkg->name,list->pkg_count)) == NULL)
|| (strcmp(existing_pkg->version,tmp_pkg->version) < 0 )){
- list->pkgs[list->pkg_count] = calloc(1 , sizeof(pkg_info));
+ list->pkgs[list->pkg_count] = calloc(1 , sizeof *list->pkgs[list->pkg_count] );
if( list->pkgs[list->pkg_count] == NULL ){
fprintf(stderr,"Failed to calloc list->pkgs[list->pkg_count]\n");
exit(1);
}
- memcpy(list->pkgs[list->pkg_count],tmp_pkg,sizeof(pkg_info));
+ memcpy(list->pkgs[list->pkg_count],tmp_pkg,sizeof *tmp_pkg);
if( existing_pkg ) free(existing_pkg);
list->pkg_count++;
/* grow our pkgs array */
- list->pkgs = realloc(list->pkgs , sizeof(pkg_info *) * (list->pkg_count + 1 ) );
- if( list->pkgs == NULL ){
+ realloc_tmp = realloc(list->pkgs , sizeof *list->pkgs * (list->pkg_count + 1 ) );
+ if( realloc_tmp == NULL ){
fprintf(stderr,"Failed to realloc pkgs\n");
if( errno ){
perror("realloc");
}
exit(1);
+ }else{
+ list->pkgs = realloc_tmp;
}
}
@@ -307,14 +318,14 @@ pkg_info *get_newest_pkg(pkg_info **pkgs,const char *pkg_name,int pkg_count){
if( (strcmp(pkgs[iterator]->name,pkg_name)) == 0 ){
if( pkg == NULL ){
- if( (pkg = calloc(1 , sizeof(pkg_info))) == NULL ){
+ if( (pkg = calloc(1 , sizeof *pkg)) == NULL ){
fprintf(stderr,"Failed to calloc pkg\n");
exit(0);
}
}
if( strcmp(pkg->version,pkgs[iterator]->version) < 0 ){
- pkg = memcpy(pkg,pkgs[iterator] , sizeof(pkg_info) );
+ pkg = memcpy(pkg,pkgs[iterator] , sizeof *pkgs[iterator] );
}
}
@@ -355,6 +366,7 @@ struct pkg_list *parse_update_pkg_list(void){
size_t nmatch = MAX_NMATCH;
regmatch_t pmatch[MAX_PMATCH];
char *getline_buffer = NULL;
+ pkg_info **realloc_tmp;
struct pkg_list *list;
list = malloc( sizeof *list );
@@ -377,7 +389,7 @@ struct pkg_list *parse_update_pkg_list(void){
if( (regexec( &regex, getline_buffer, nmatch, pmatch, 0)) == 0 ){
/* find out why malloc isn't working here... mem leak somewhere */
- list->pkgs[list->pkg_count] = calloc( 1 , sizeof(pkg_info) );
+ list->pkgs[list->pkg_count] = calloc( 1 , sizeof *list->pkgs[list->pkg_count] );
if( list->pkgs[list->pkg_count] == NULL ){
fprintf(stderr,"Failed to calloc list->pkgs[list->pkg_count]\n");
exit(1);
@@ -419,11 +431,15 @@ struct pkg_list *parse_update_pkg_list(void){
list->pkgs[list->pkg_count]->size_c = 0;
list->pkgs[list->pkg_count]->size_u = 0;
list->pkg_count++;
- list->pkgs = realloc(list->pkgs , sizeof(pkg_info *) * (list->pkg_count + 1));
- if( list->pkgs == NULL ){
+
+ realloc_tmp = realloc(list->pkgs , sizeof *list->pkgs * (list->pkg_count + 1));
+ if( realloc_tmp == NULL ){
fprintf(stderr,"Failed to realloc pkgs\n");
exit(1);
+ }else{
+ list->pkgs = realloc_tmp;
}
+
} /* end if regexec */
} /* end if strstr */
@@ -456,7 +472,7 @@ pkg_info *lookup_pkg(const char *pkg_name){
exit(0);
}
}
- memcpy(pkg,pkgs->pkgs[iterator] , sizeof(pkg_info) );
+ memcpy(pkg,pkgs->pkgs[iterator] , sizeof *pkgs->pkgs[iterator] );
}
}
@@ -482,7 +498,7 @@ int install_pkg(const rc_config *global_config,pkg_info *pkg){
pkg_file_name = download_pkg(global_config,pkg);
/* build and execute our command */
- command = calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof(char) );
+ command = calloc( strlen(INSTALL_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
command[0] = '\0';
command = strcat(command,INSTALL_CMD);
command = strcat(command,pkg_file_name);
@@ -525,7 +541,7 @@ int upgrade_pkg(const rc_config *global_config,pkg_info *pkg){
pkg_file_name = download_pkg(global_config,pkg);
/* build and execute our command */
- command = calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof(char) );
+ command = calloc( strlen(UPGRADE_CMD) + strlen(pkg_file_name) + 1 , sizeof *command );
command[0] = '\0';
command = strcat(command,UPGRADE_CMD);
command = strcat(command,pkg_file_name);
@@ -554,7 +570,7 @@ int remove_pkg(pkg_info *pkg){
int cmd_return;
/* build and execute our command */
- command = calloc( strlen(REMOVE_CMD) + strlen(pkg->name) + 1 , sizeof(char) );
+ command = calloc( strlen(REMOVE_CMD) + strlen(pkg->name) + 1 , sizeof *command );
command[0] = '\0';
command = strcat(command,REMOVE_CMD);
command = strcat(command,pkg->name);
@@ -573,3 +589,27 @@ void free_pkg_list(struct pkg_list *list){
free(list);
}
+int is_excluded(const rc_config *global_config,const char *pkg_name){
+ int i;
+
+ if( global_config->ignore_excludes == 1 )
+ return 0;
+
+ /* maybe EXCLUDE= isn't defined in our rc? */
+ if( global_config->exclude_list == NULL )
+ return 0;
+
+ for(i = 0; i < global_config->exclude_list->count;i++){
+ /*
+ * this is kludgy... global_config->exclude_list->excludes[i] is 1 char longer
+ * than pkg_name
+ */
+ if( (strncmp(global_config->exclude_list->excludes[i],pkg_name,strlen(pkg_name)) == 0)
+ && (strlen(global_config->exclude_list->excludes[i]) - strlen(pkg_name) < 2) ){
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/src/package.h b/src/package.h
index 81f7184..2badfc5 100644
--- a/src/package.h
+++ b/src/package.h
@@ -71,4 +71,6 @@ int upgrade_pkg(const rc_config *,pkg_info *);
int remove_pkg(pkg_info *);
/* free memory allocated for pkg_list struct */
void free_pkg_list(struct pkg_list *);
+/* exclude pkg based on pkg name */
+int is_excluded(const rc_config *,const char *);