diff options
-rw-r--r-- | conf.c | 6 | ||||
-rw-r--r-- | list_window.c | 4 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | mpc.c | 23 | ||||
-rw-r--r-- | options.c | 5 | ||||
-rw-r--r-- | screen.c | 10 | ||||
-rw-r--r-- | screen_file.c | 32 | ||||
-rw-r--r-- | screen_play.c | 6 | ||||
-rw-r--r-- | screen_utils.c | 4 |
9 files changed, 45 insertions, 46 deletions
@@ -6,6 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> + +#include <glib.h> #include <ncurses.h> #include "config.h" @@ -104,7 +106,7 @@ read_rc_file(char *filename, options_t *options) { D(perror(filename)); if( free_filename ) - free(filename); + g_free(filename); return -1; } @@ -248,7 +250,7 @@ read_rc_file(char *filename, options_t *options) D(printf( "--\n\n" )); if( free_filename ) - free(filename); + g_free(filename); return 0; } diff --git a/list_window.c b/list_window.c index d976ce05c..b04b817da 100644 --- a/list_window.c +++ b/list_window.c @@ -14,7 +14,7 @@ list_window_init(WINDOW *w, int width, int height) { list_window_t *lw; - lw = malloc(sizeof(list_window_t)); + lw = g_malloc(sizeof(list_window_t)); memset(lw, 0, sizeof(list_window_t)); lw->w = w; lw->cols = width; @@ -29,7 +29,7 @@ list_window_free(list_window_t *lw) if( lw ) { memset(lw, 0, sizeof(list_window_t)); - free(lw); + g_free(lw); } return NULL; } @@ -28,6 +28,7 @@ exit_and_cleanup(void) fprintf(stderr,"Error: %s\n", mpc_error_str(mpc)); mpc_close(mpc); } + g_free(options.host); } void @@ -1,8 +1,3 @@ -/* - * $Id: mpc.c,v 1.5 2004/03/17 23:19:21 kalle Exp $ - * - */ - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -62,7 +57,7 @@ mpc_close(mpd_client_t *c) if( c->connection ) mpd_closeConnection(c->connection); if( c->cwd ) - free( c->cwd ); + g_free( c->cwd ); return 0; } @@ -80,10 +75,10 @@ mpc_connect(char *host, int port) exit(EXIT_FAILURE); } - c = malloc(sizeof(mpd_client_t)); + c = g_malloc(sizeof(mpd_client_t)); memset(c, 0, sizeof(mpd_client_t)); c->connection = connection; - c->cwd = strdup(""); + c->cwd = g_strdup(""); return c; } @@ -228,20 +223,20 @@ mpc_get_song_name(mpd_Song *song) snprintf(buf, MAX_SONG_LENGTH, "%s - %s", song->artist, song->title); name = utf8_to_locale(buf); strncpy(buf, name, MAX_SONG_LENGTH); - free(name); + g_free(name); return buf; } else { name = utf8_to_locale(song->title); strncpy(buf, name, MAX_SONG_LENGTH); - free(name); + g_free(name); return buf; } } name = utf8_to_locale(basename(song->file)); strncpy(buf, name, MAX_SONG_LENGTH); - free(name); + g_free(name); return buf; } @@ -294,7 +289,7 @@ mpc_free_filelist(mpd_client_t *c) if( entry->entity ) mpd_freeInfoEntity(entry->entity); - free(entry); + g_free(entry); list=list->next; } g_list_free(c->filelist); @@ -325,7 +320,7 @@ mpc_update_filelist(mpd_client_t *c) if( c->cwd && c->cwd[0] ) { /* add a dummy entry for ./.. */ - filelist_entry_t *entry = malloc(sizeof(filelist_entry_t)); + filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t)); memset(entry, 0, sizeof(filelist_entry_t)); entry->entity = NULL; c->filelist = g_list_append(c->filelist, (gpointer) entry); @@ -334,7 +329,7 @@ mpc_update_filelist(mpd_client_t *c) while( (entity=mpd_getNextInfoEntity(c->connection)) ) { - filelist_entry_t *entry = malloc(sizeof(filelist_entry_t)); + filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t)); memset(entry, 0, sizeof(filelist_entry_t)); entry->entity = entity; @@ -3,6 +3,7 @@ #include <unistd.h> #include <string.h> #include <ncurses.h> +#include <glib.h> #include <popt.h> #include "config.h" @@ -98,9 +99,9 @@ options_init( void ) memset(&options, 0, sizeof(options_t)); if( (value=getenv(MPD_HOST_ENV)) ) - options.host = strdup(value); + options.host = g_strdup(value); else - options.host = strdup(DEFAULT_HOST); + options.host = g_strdup(DEFAULT_HOST); if( (value=getenv(MPD_PORT_ENV)) ) options.port = atoi(value); else @@ -220,9 +220,9 @@ screen_exit(void) screen->playlist = list_window_free(screen->playlist); screen->filelist = list_window_free(screen->filelist); screen->helplist = list_window_free(screen->helplist); - free(screen->buf); - free(screen->findbuf); - free(screen); + g_free(screen->buf); + g_free(screen->findbuf); + g_free(screen); screen = NULL; } return 0; @@ -311,12 +311,12 @@ screen_init(void) exit(EXIT_FAILURE); } - screen = malloc(sizeof(screen_t)); + screen = g_malloc(sizeof(screen_t)); memset(screen, 0, sizeof(screen_t)); screen->mode = SCREEN_PLAY_WINDOW; screen->cols = COLS; screen->rows = LINES; - screen->buf = malloc(screen->cols); + screen->buf = g_malloc(screen->cols); screen->buf_size = screen->cols; screen->findbuf = NULL; screen->painted = 0; diff --git a/screen_file.c b/screen_file.c index c866566de..42d945617 100644 --- a/screen_file.c +++ b/screen_file.c @@ -15,7 +15,7 @@ #define BUFSIZE 1024 -#undef USE_OLD_LAYOUT +#define USE_OLD_LAYOUT static char * list_callback(int index, int *highlight, void *data) @@ -37,7 +37,7 @@ list_callback(int index, int *highlight, void *data) #ifdef USE_OLD_LAYOUT return "[..]"; #else - return "<d> .."; + return "d .."; #endif } if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY ) @@ -48,9 +48,9 @@ list_callback(int index, int *highlight, void *data) #ifdef USE_OLD_LAYOUT snprintf(buf, BUFSIZE, "[%s]", dirname); #else - snprintf(buf, BUFSIZE, "<d> %s", dirname); + snprintf(buf, BUFSIZE, "d %s", dirname); #endif - free(dirname); + g_free(dirname); return buf; } else if( entity->type==MPD_INFO_ENTITY_TYPE_SONG ) @@ -58,9 +58,9 @@ list_callback(int index, int *highlight, void *data) mpd_Song *song = entity->info.song; #ifdef USE_OLD_LAYOUT - return mpc_get_song_name(song)); + return mpc_get_song_name(song); #else - snprintf(buf, BUFSIZE, "<m> %s", mpc_get_song_name(song)); + snprintf(buf, BUFSIZE, "m %s", mpc_get_song_name(song)); return buf; #endif @@ -73,9 +73,9 @@ list_callback(int index, int *highlight, void *data) #ifdef USE_OLD_LAYOUT snprintf(buf, BUFSIZE, "*%s*", filename); #else - snprintf(buf, BUFSIZE, "<p> %s", filename); + snprintf(buf, BUFSIZE, "p %s", filename); #endif - free(filename); + g_free(filename); return buf; } return "Error: Unknow entry!"; @@ -96,7 +96,7 @@ change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) parent[0] = '\0'; } if( c->cwd ) - free(c->cwd); + g_free(c->cwd); c->cwd = parent; } else @@ -104,8 +104,8 @@ change_directory(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) { mpd_Directory *dir = entity->info.directory; if( c->cwd ) - free(c->cwd); - c->cwd = strdup(dir->path); + g_free(c->cwd); + c->cwd = g_strdup(dir->path); } else return -1; @@ -126,7 +126,7 @@ load_playlist(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) mpd_finishCommand(c->connection); screen_status_printf("Loading playlist %s...", filename); - free(filename); + g_free(filename); return 0; } @@ -156,7 +156,7 @@ handle_delete(screen_t *screen, mpd_client_t *c) plf = entity->info.playlistFile; str = utf8_to_locale(basename(plf->path)); snprintf(buf, BUFSIZE, "Delete playlist %s [y/n] ? ", str); - free(str); + g_free(str); key = tolower(screen_getch(screen->status_window.w, buf)); if( key!='y' ) { @@ -170,7 +170,7 @@ handle_delete(screen_t *screen, mpd_client_t *c) { str = utf8_to_locale(mpc_error_str(c)); screen_status_printf("Error: %s", str); - free(str); + g_free(str); beep(); return -1; } @@ -210,7 +210,7 @@ add_directory(mpd_client_t *c, char *dir) dirname = utf8_to_locale(dir); screen_status_printf("Adding directory %s...\n", dirname); - free(dirname); + g_free(dirname); dirname = NULL; mpd_sendLsInfoCommand(c->connection, dir); @@ -356,7 +356,7 @@ file_get_header(mpd_client_t *c) TOP_HEADER_FILE ": %s ", tmp ); - free(tmp); + g_free(tmp); return buf; } diff --git a/screen_play.c b/screen_play.c index 5f93ad093..72c223ed3 100644 --- a/screen_play.c +++ b/screen_play.c @@ -50,7 +50,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c) /* send save command to mpd */ mpd_sendSaveCommand(c->connection, filename_utf8); mpd_finishCommand(c->connection); - free(filename_utf8); + g_free(filename_utf8); /* handle errors */ if( mpc_error(c)) { @@ -58,7 +58,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c) { char *str = utf8_to_locale(mpc_error_str(c)); screen_status_message(str); - free(str); + g_free(str); } else screen_status_printf("Error: Unable to save playlist as %s", filename); @@ -68,7 +68,7 @@ handle_save_playlist(screen_t *screen, mpd_client_t *c) } /* success */ screen_status_printf("Saved %s", filename); - free(filename); + g_free(filename); /* update the file list if it has been initalized */ if( c->filelist ) { diff --git a/screen_utils.c b/screen_utils.c index 61c212edc..b93069c22 100644 --- a/screen_utils.c +++ b/screen_utils.c @@ -56,7 +56,7 @@ screen_getstr(WINDOW *w, char *prompt) curs_set(1); if( wgetnstr(w, buf, 256) == OK ) - line = strdup(buf); + line = g_strdup(buf); noecho(); curs_set(0); @@ -90,7 +90,7 @@ screen_find(screen_t *screen, case CMD_LIST_RFIND: if( screen->findbuf ) { - free(screen->findbuf); + g_free(screen->findbuf); screen->findbuf=NULL; } /* continue... */ |