Permalink
Browse files

- Separated log stuff in different files

- Added function to detect the disk space
- Fixed bug in parser to find the installation size
  • Loading branch information...
megastep committed Sep 2, 1999
1 parent 9d98c54 commit 735654e51999f85a506f7ca56ca89f097757fff6
Showing with 140 additions and 67 deletions.
  1. +1 −1 Makefile
  2. +1 −1 console_ui.c
  3. +58 −2 detect.c
  4. +1 −53 file.c
  5. +0 −6 file.h
  6. +1 −1 install.c
  7. +3 −2 install.h
  8. +59 −0 install_log.c
  9. +14 −0 install_log.h
  10. +1 −0 log.c
  11. +1 −1 log.h
View
@@ -1,6 +1,6 @@
CFLAGS = -g
OBJS = main.o console_ui.o install.o detect.o copy.o file.o log.o
OBJS = main.o console_ui.o install.o detect.o copy.o file.o log.o install_log.o
LIBS = -lxml -lz
all: testxml setup
View
@@ -104,7 +104,7 @@ static void parse_option(install_info *info, xmlNodePtr node)
mark_option(info, node, "true", 0);
/* Add this option size to the total */
sizestr = xmlGetProp(node, "install");
sizestr = xmlGetProp(node, "size");
if ( sizestr ) {
info->install_size += atoi(sizestr);
}
View
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include "detect.h"
@@ -65,8 +66,63 @@ const char *detect_libc(void)
/* Function to detect the MB of diskspace on a path */
/* Ripped straight from the Myth II GUI installer */
/* The upper directory in the path must be valid ! */
int detect_diskspace(const char *path)
{
#warning FIXME Stephane! :)
return(0);
int fd[ 2 ];
int pid;
int len;
char *arg[ 4 ];
char buf[ 1024 ], path_up[PATH_MAX];
char *cp;
char *end;
strcpy(path_up, path);
cp = (char*)rindex(path_up, '/');
if(cp)
*cp = '\0';
pipe( fd );
pid = fork();
if( pid == -1 )
return -1;
if( pid == 0 ) {
arg[ 0 ] = "df";
arg[ 1 ] = "-m";
arg[ 2 ] = (char*) path_up;
arg[ 3 ] = 0;
close( 1 ); /* close normal stdout */
dup( fd[1] ); /* make stdout same as pfds[1] */
close( fd[0] ); /* we don't need this */
execvp( "df", arg );
perror( "exec df" );
exit(-1);
} else {
close( fd[1] ); /* we don't need this */
len = read( fd[0], buf, sizeof(buf) );
close( fd[0] );
}
if( len > 0 ) {
// Checking if df is reporting an error of some sort.
if( strcmp( buf, "df:" ) == 0 ) {
fprintf( stderr, buf );
return -1;
}
// Skip report header line.
cp = buf;
end = cp + len;
while( (cp < end) && (*cp != '\n') ) {
cp++;
}
sscanf( cp, "%*s %*d %*d %d %*s %*s", &len );
}
return len;
}
View
54 file.c
@@ -14,58 +14,6 @@
#include "file.h"
void log_debug(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_DEBUG, "%s\n", buf);
}
void log_quiet(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_QUIET, "%s\n", buf);
}
void log_normal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_NORMAL, "%s\n", buf);
}
void log_warning(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_WARNING, "%s\n", buf);
}
void log_fatal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_FATAL, "%s\n", buf);
abort();
}
stream *file_open(install_info *info, const char *path, const char *mode)
{
stream *streamp;
@@ -257,7 +205,7 @@ int file_mkdir(install_info *info, const char *path, int mode)
/* Only create the directory if we need to */
retval = 0;
if ( (stat(path, &sb) != 0) || S_ISDIR(sb.st_mode) ) {
if ( (stat(path, &sb) != 0) || !S_ISDIR(sb.st_mode) ) {
/* Log the action */
log_quiet(info, "Creating directory: %s\n", path);
View
6 file.h
@@ -16,12 +16,6 @@ typedef struct {
gzFile zfp;
} stream;
extern void log_debug(install_info *info, const char *fmt, ...);
extern void log_quiet(install_info *info, const char *fmt, ...);
extern void log_normal(install_info *info, const char *fmt, ...);
extern void log_warning(install_info *info, const char *fmt, ...);
extern void log_fatal(install_info *info, const char *fmt, ...);
extern stream *file_open(install_info *info,const char *path,const char *mode);
extern int file_read(install_info *info, void *buf, int len, stream *streamp);
extern int file_write(install_info *info, void *buf, int len, stream *streamp);
View
@@ -6,7 +6,7 @@
#include "install.h"
#include "detect.h"
#include "log.h"
/* Functions to retrieve attribution information from the XML tree */
static const char *GetProductName(install_info *info)
View
@@ -5,8 +5,6 @@
#include <limits.h>
#include <gnome-xml/parser.h>
#include "log.h"
/* The default location of the product */
#define DEFAULT_PATH "/usr/local/games"
@@ -24,6 +22,9 @@ typedef enum {
/* Forward declaration (used by UI) */
struct UI_data;
/* Forward declaration */
typedef struct _install_log install_log;
/* The main installation information structure */
typedef struct {
View
@@ -0,0 +1,59 @@
/* Functions to log messages */
#include <stdarg.h>
#include <stdio.h>
#include "install_log.h"
#include "log.h"
void log_debug(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_DEBUG, "%s\n", buf);
}
void log_quiet(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_QUIET, "%s\n", buf);
}
void log_normal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_NORMAL, "%s\n", buf);
}
void log_warning(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_WARNING, "%s\n", buf);
}
void log_fatal(install_info *info, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
print_log(info->log, LOG_FATAL, "%s\n", buf);
abort();
}
View
@@ -0,0 +1,14 @@
#ifndef _log_install_h
#define _log_install_h
/* Functions to log messages */
#include "install.h"
extern void log_debug(install_info *info, const char *fmt, ...);
extern void log_quiet(install_info *info, const char *fmt, ...);
extern void log_normal(install_info *info, const char *fmt, ...);
extern void log_warning(install_info *info, const char *fmt, ...);
extern void log_fatal(install_info *info, const char *fmt, ...);
#endif
View
1 log.c
@@ -4,6 +4,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "install_log.h"
#include "log.h"
struct _install_log {
View
2 log.h
@@ -4,7 +4,7 @@
/* Functions to perform install logging */
typedef struct _install_log install_log;
#include "install.h"
typedef enum {
LOG_DEBUG,

0 comments on commit 735654e

Please sign in to comment.