summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e9f21b1)
raw | patch | inline | side by side (parent: e9f21b1)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 13 Jul 2004 21:10:06 +0000 (21:10 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 13 Jul 2004 21:10:06 +0000 (21:10 +0000) |
12 files changed:
src/command.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/screen_file.c | patch | blob | history | |
src/screen_help.c | patch | blob | history | |
src/screen_keydef.c | patch | blob | history | |
src/screen_play.c | patch | blob | history | |
src/screen_utils.c | patch | blob | history | |
src/strfsong.c | patch | blob | history | |
src/support.c | patch | blob | history | |
src/utils.c | patch | blob | history | |
src/wreadln.c | patch | blob | history | |
src/wreadln.h | patch | blob | history |
diff --git a/src/command.c b/src/command.c
index c256d0c5ce73cab035d1737b31aa93a4707dfa05..d38402b2cdac5bb84056cc09a79902ec152aeef2 100644 (file)
--- a/src/command.c
+++ b/src/command.c
for(i=0; i<=63; i++)
if( key==KEY_F(i) )
{
- snprintf(buf, 32, "F%d", i );
+ g_snprintf(buf, 32, "F%d", i );
return buf;
}
if( !(key & ~037) )
- snprintf(buf, 32, "Ctrl-%c", 'A'+(key & 037)-1 );
+ g_snprintf(buf, 32, "Ctrl-%c", 'A'+(key & 037)-1 );
else if( (key & ~037) == 224 )
- snprintf(buf, 32, "Alt-%c", 'A'+(key & 037)-1 );
+ g_snprintf(buf, 32, "Alt-%c", 'A'+(key & 037)-1 );
else if( key>32 && key<256 )
- snprintf(buf, 32, "%c", key);
+ g_snprintf(buf, 32, "%c", key);
else
- snprintf(buf, 32, "0x%03X", key);
+ g_snprintf(buf, 32, "0x%03X", key);
}
return buf;
}
int j;
static char keystr[80];
- strncpy(keystr, key2str(cmds[i].keys[0]), 80);
+ g_strlcpy(keystr, key2str(cmds[i].keys[0]), sizeof(keystr));
if( !all )
return keystr;
j=1;
while( j<MAX_COMMAND_KEYS && cmds[i].keys[j]>0 )
{
- strcat(keystr, " ");
- strcat(keystr, key2str(cmds[i].keys[j]));
+ g_strlcat(keystr, " ", sizeof(keystr));
+ g_strlcat(keystr, key2str(cmds[i].keys[j]), sizeof(keystr));
j++;
}
return keystr;
{
if( buf )
#ifdef ENABLE_KEYDEF_SCREEN
- snprintf(buf, bufsize,
- _("Key %s assigned to %s and %s (press %s for the key editor)"),
- key2str(cp[i].keys[j]),
- get_key_command_name(cp[i].command),
- get_key_command_name(cmd),
- get_key_names(CMD_SCREEN_KEYDEF,0));
+ g_snprintf(buf, bufsize,
+ _("Key %s assigned to %s and %s (press %s for the key editor)"),
+ key2str(cp[i].keys[j]),
+ get_key_command_name(cp[i].command),
+ get_key_command_name(cmd),
+ get_key_names(CMD_SCREEN_KEYDEF,0));
#else
- snprintf(buf, bufsize,
+ g_snprintf(buf, bufsize,
_("Error: Key %s assigned to %s and %s !!!\n"),
key2str(cp[i].keys[j]),
get_key_command_name(cp[i].command),
diff --git a/src/main.c b/src/main.c
index 1cba667bf2eec3b33e09813208acdfc7e6b4ec5c..ece1ad593064d1dcfa7326224ef766c4511a0f56 100644 (file)
--- a/src/main.c
+++ b/src/main.c
strfsong(tmp, BUFSIZE, options.xterm_title_format, song);
}
else
- strncpy(tmp, PACKAGE " version " VERSION, BUFSIZE);
+ g_strlcpy(tmp, PACKAGE " version " VERSION, BUFSIZE);
- if( strcmp(title,tmp) )
+ if( strncmp(title,tmp,BUFSIZE) )
{
- strncpy(title, tmp, BUFSIZE);
+ g_strlcpy(title, tmp, BUFSIZE);
set_xterm_title(title);
}
}
diff --git a/src/screen_file.c b/src/screen_file.c
index 02dc4c4b3feefb390af21a49c3b4d96da72b468b..d25229d1e1a41070179b1296ab584ca8dc374914 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
list_callback(int index, int *highlight, void *data)
{
static char buf[BUFSIZE];
- //mpdclient_t *c = (mpdclient_t *) data;
+ /*mpdclient_t *c = (mpdclient_t *) data;*/
filelist_entry_t *entry;
mpd_InfoEntity *entity;
mpd_Directory *dir = entity->info.directory;
char *dirname = utf8_to_locale(basename(dir->path));
- snprintf(buf, BUFSIZE, "[%s]", dirname);
+ g_snprintf(buf, BUFSIZE, "[%s]", dirname);
g_free(dirname);
return buf;
}
char *filename = utf8_to_locale(basename(plf->path));
#ifdef USE_OLD_LAYOUT
- snprintf(buf, BUFSIZE, "*%s*", filename);
+ g_snprintf(buf, BUFSIZE, "*%s*", filename);
#else
- snprintf(buf, BUFSIZE, "<Playlist> %s", filename);
+ g_snprintf(buf, BUFSIZE, "<Playlist> %s", filename);
#endif
g_free(filename);
return buf;
filelist_entry_t *entry;
mpd_InfoEntity *entity;
mpd_PlaylistFile *plf;
- char *str, buf[BUFSIZE];
+ char *str, *buf;
int key;
entry=( filelist_entry_t *) g_list_nth_data(filelist->list,lw->selected);
plf = entity->info.playlistFile;
str = utf8_to_locale(basename(plf->path));
- snprintf(buf, BUFSIZE, _("Delete playlist %s [%s/%s] ? "), str, YES, NO);
+ buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO);
g_free(str);
key = tolower(screen_getch(screen->status_window.w, buf));
+ g_free(buf);
if( key==KEY_RESIZE )
screen_resize();
if( key != YES[0] )
static char *
browse_title(char *str, size_t size)
{
- snprintf(str, size, _("Browse: %s"), basename(filelist->path));
+ g_snprintf(str, size, _("Browse: %s"), basename(filelist->path));
return str;
}
diff --git a/src/screen_help.c b/src/screen_help.c
index 68021c6515c558563c8ba3259ffd64a55ed83678..94fe9ab5b35dde881d27f40a08bb2102005a12f9 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
static char *
list_callback(int index, int *highlight, void *data)
{
- static char buf[256];
+ static char buf[512];
if( help_text_rows<0 )
{
if( help_text[index].command == CMD_NONE )
{
if( help_text[index].text )
- snprintf(buf, 256, "%28s", _(help_text[index].text));
+ g_snprintf(buf, sizeof(buf), "%28s", _(help_text[index].text));
else
if( help_text[index].highlight == 2 )
{
int i;
- for(i=3; i<COLS-3 && i<256; i++)
+ for(i=3; i<COLS-3 && i<sizeof(buf); i++)
buf[i]='-';
buf[i] = '\0';
}
else
- strcpy(buf, " ");
+ g_strlcpy(buf, " ", sizeof(buf));
return buf;
}
if( help_text[index].text )
- snprintf(buf, 256,
- "%20s : %s ",
- get_key_names(help_text[index].command, TRUE),
- _(help_text[index].text));
+ g_snprintf(buf, sizeof(buf),
+ "%20s : %s ",
+ get_key_names(help_text[index].command, TRUE),
+ _(help_text[index].text));
else
- snprintf(buf, 256,
- "%20s : %s ",
- get_key_names(help_text[index].command, TRUE),
- get_key_description(help_text[index].command));
+ g_snprintf(buf, sizeof(buf),
+ "%20s : %s ",
+ get_key_names(help_text[index].command, TRUE),
+ get_key_description(help_text[index].command));
return buf;
}
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 4ed30dfccbaad50d3a43ae07a989fa67aeef4694..3451dd2ed9ac019c56281525d77e86ce17319568 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
assign_new_key(WINDOW *w, int cmd_index, int key_index)
{
int key;
- char buf[BUFSIZE];
+ char *buf;
command_t cmd;
- snprintf(buf, BUFSIZE, _("Enter new key for %s: "), cmds[cmd_index].name);
+ buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name);
key = screen_getch(w, buf);
+ g_free(buf);
if( key==KEY_RESIZE )
screen_resize();
if( key==ERR )
index--;
if( index<MAX_COMMAND_KEYS && cmds[subcmd].keys[index]>0 )
{
- snprintf(buf,
- BUFSIZE, "%d. %-20s (%d) ",
- index+1,
- key2str(cmds[subcmd].keys[index]),
- cmds[subcmd].keys[index]);
+ g_snprintf(buf,
+ BUFSIZE, "%d. %-20s (%d) ",
+ index+1,
+ key2str(cmds[subcmd].keys[index]),
+ cmds[subcmd].keys[index]);
return buf;
}
else if ( index==subcmd_addpos )
{
- snprintf(buf, BUFSIZE, _("%d. Add new key "), index+1 );
+ g_snprintf(buf, BUFSIZE, _("%d. Add new key "), index+1 );
return buf;
}
}
if( subcmd<0 )
return _("Edit key bindings");
- snprintf(str, size, _("Edit keys for %s"), cmds[subcmd].name);
+ g_snprintf(str, size, _("Edit keys for %s"), cmds[subcmd].name);
return str;
}
diff --git a/src/screen_play.c b/src/screen_play.c
index e9cb465e2811804b1b30ae27bfe1802ed90ec884..307471f2cbdd03840e6feb598503584061690647 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
if( code == MPD_ACK_ERROR_EXIST )
{
- char buf[256];
+ char *buf;
int key;
- snprintf(buf, 256, _("Replace %s [%s/%s] ? "), filename, YES, NO);
+ buf=g_strdup_printf(_("Replace %s [%s/%s] ? "), filename, YES, NO);
key = tolower(screen_getch(screen->status_window.w, buf));
+ g_free(buf);
if( key == YES[0] )
{
if( mpdclient_cmd_delete_playlist(c, filename) )
if( strcmp(options.host, "localhost") == 0 )
return _("Playlist");
- snprintf(str, size, _("Playlist on %s"), options.host);
+ g_snprintf(str, size, _("Playlist on %s"), options.host);
return str;
}
diff --git a/src/screen_utils.c b/src/screen_utils.c
index 9870fc33a3a1bb02260e5b8052adb2957073ec92..baa371be1aec79ae12c1ece3bd4691b1cb995869 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
{
if( g_getenv("WINDOWID") )
{
- char buffer[512];
+ char *msg;
va_list ap;
va_start(ap,format);
- vsnprintf(buffer,sizeof(buffer),format,ap);
+ msg = g_strdup_vprintf(format,ap);
va_end(ap);
- printf("%c]0;%s%c", '\033', buffer, '\007');
+ printf("%c]0;%s%c", '\033', msg, '\007');
+ g_free(msg);
}
else
options.enable_xterm_title = FALSE;
diff --git a/src/strfsong.c b/src/strfsong.c
index a06ae95a119811c85c706364b45c4fdfca7834a1..bac6d472f734fe8df06e8119382bbddb258074c3 100644 (file)
--- a/src/strfsong.c
+++ b/src/strfsong.c
temp = g_malloc0(max);
if( _strfsong(temp, max, p+1, song, &p) >0 )
{
- strncat(s, temp, max-length);
+ g_strlcat(s, temp, max);
length = strlen(s);
found = TRUE;
}
/* pass-through non-escaped portions of the format string */
if (p[0] != '#' && p[0] != '%' && length<max)
{
- strncat(s, p, 1);
- length++;
- ++p;
+ s[length++] = *p;
+ p++;
continue;
}
/* let the escape character escape itself */
if (p[0] == '#' && p[1] != '\0' && length<max)
{
- strncat(s, p+1, 1);
- length++;
+ s[length++] = *(p+1);
p+=2;
continue;
}
}
else if (strncmp("%time%", p, n) == 0)
{
- if (song->time != MPD_SONG_NO_TIME) {
- gchar s[10];
- snprintf(s, 9, "%d:%d", song->time / 60,
- song->time % 60 + 1);
- /* nasty hack to use static buffer */
- temp = g_strdup(s);
- }
+ if (song->time != MPD_SONG_NO_TIME)
+ temp = g_strdup_printf("%d:%d",
+ song->time / 60,
+ song->time % 60 + 1);
}
if( temp == NULL)
but put the real character back in (pseudo-const) */
if( length+templen > max )
templen = max-length;
- strncat(s, p, templen);
+ g_strlcat(s, p,max);
length+=templen;
}
else {
found = TRUE;
if( length+templen > max )
templen = max-length;
- strncat(s, temp, templen);
+ g_strlcat(s, temp, max);
length+=templen;
g_free(temp);
}
diff --git a/src/support.c b/src/support.c
index 3717e6c0f4a0c8137978cf82fe584a9d453e8f4c..254c15eb139e6e7cfcdb3c0dac2b5bb4e2b58141 100644 (file)
--- a/src/support.c
+++ b/src/support.c
char *
lowerstr(char *str)
{
- size_t i;
- size_t len = strlen(str);
+ gsize i;
+ gsize len = strlen(str);
if( str==NULL )
return NULL;
char *
strscroll(char *str, char *separator, int width, scroll_state_t *st)
{
- char *tmp, *buf;
- size_t len;
+ gchar *tmp, *buf;
+ gsize len, size;
if( st->offset==0 )
{
}
/* create a buffer containing the string and the separator */
- tmp = g_malloc(strlen(str)+strlen(separator)+1);
- strcpy(tmp, str);
- strcat(tmp, separator);
+ size = strlen(str)+strlen(separator)+1;
+ tmp = g_malloc(size);
+ g_strlcpy(tmp, str, size);
+ g_strlcat(tmp, separator, size);
len = strlen(tmp);
if( st->offset >= len )
st->offset = 0;
/* create the new scrolled string */
- buf = g_malloc(width+1);
- strncpy(buf, tmp+st->offset, width);
+ size = width+1;
+ buf = g_malloc(size);
+ g_strlcpy(buf, tmp+st->offset, size);
if( strlen(buf) < width )
- strncat(buf, tmp, width-strlen(buf));
+ g_strlcat(buf, tmp, size);
if( time(NULL)-st->t >= 1 )
{
diff --git a/src/utils.c b/src/utils.c
index 58340c42ece27d90c977dc9f9a8172e722e46d2b..0f63ff1da3dcb8fc3c906c22bdd7a7c1eef80870 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
{
mpd_Directory *dir = entity->info.directory;
gchar *tmp = utf8_to_locale(dir->path);
+ gsize size = strlen(tmp)+2;
- name = g_malloc(strlen(tmp)+2);
- strcpy(name, tmp);
- strcat(name, "/");
+ name = g_malloc(size);
+ g_strlcpy(name, tmp, size);
+ g_strlcat(name, "/", size);
g_free(tmp);
}
else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG &&
diff --git a/src/wreadln.c b/src/wreadln.c
index 700769bd158175ebb1bd7644526fe3abccd1b776..930cb5429f85ad51462f0f295c1ceeab2b80e4d5 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
#define WRLN_MAX_LINE_SIZE 1024
#define WRLN_MAX_HISTORY_LENGTH 32
-unsigned int wrln_max_line_size = WRLN_MAX_LINE_SIZE;
-unsigned int wrln_max_history_length = WRLN_MAX_HISTORY_LENGTH;
+guint wrln_max_line_size = WRLN_MAX_LINE_SIZE;
+guint wrln_max_history_length = WRLN_MAX_HISTORY_LENGTH;
wrln_wgetch_fn_t wrln_wgetch = NULL;
wrln_gcmp_pre_cb_t wrln_pre_completion_callback = NULL;
wrln_gcmp_post_cb_t wrln_post_completion_callback = NULL;
extern void screen_bell(void);
-char *
+gchar *
wreadln(WINDOW *w,
- char *prompt,
- char *initial_value,
- int x1,
+ gchar *prompt,
+ gchar *initial_value,
+ gint x1,
GList **history,
GCompletion *gcmp)
{
GList *hlist = NULL, *hcurrent = NULL;
- char *line;
- int x0, y, width;
- int cursor = 0, start = 0;
- int key = 0, i;
+ gchar *line;
+ gint x0, y, width;
+ gint cursor = 0, start = 0;
+ gint key = 0, i;
/* move the cursor one step to the right */
void cursor_move_right(void) {
if( hlist==hcurrent )
{
/* save the current line */
- strncpy(hlist->data, line, wrln_max_line_size);
+ g_strlcpy(hlist->data, line, wrln_max_line_size);
}
/* get previous line */
hlist = hlist->prev;
- strncpy(line, hlist->data, wrln_max_line_size);
+ g_strlcpy(line, hlist->data, wrln_max_line_size);
}
cursor_move_to_eol();
drawline();
else if( initial_value )
{
/* copy the initial value to the line buffer */
- strncpy(line, initial_value, wrln_max_line_size);
+ g_strlcpy(line, initial_value, wrln_max_line_size);
cursor_move_to_eol();
drawline();
}
switch (key)
{
+#ifdef HAVE_GETMOUSE
case KEY_MOUSE: /* ignore mouse events */
+#endif
case ERR: /* ingnore errors */
break;
list = g_completion_complete(gcmp, line, &prefix);
if( prefix )
{
- int len = strlen(prefix);
- strncpy(line, prefix, len);
+ g_strlcpy(line, prefix, wrln_max_line_size);
cursor_move_to_eol();
g_free(prefix);
}
if( hlist==hcurrent )
{
/* save the current line */
- strncpy(hlist->data, line, wrln_max_line_size);
+ g_strlcpy(hlist->data, line, wrln_max_line_size);
}
/* get previous line */
hlist = hlist->prev;
- strncpy(line, hlist->data, wrln_max_line_size);
+ g_strlcpy(line, hlist->data, wrln_max_line_size);
}
- // if (cursor > strlen(line))
cursor_move_to_eol();
break;
case KEY_DOWN:
{
/* get next line */
hlist = hlist->next;
- strncpy(line, hlist->data, wrln_max_line_size);
+ g_strlcpy(line, hlist->data, wrln_max_line_size);
}
cursor_move_to_eol();
break;
{
if (strlen (line + cursor)) /* if the cursor is */
{ /* not at the last pos */
- char *tmp = 0;
- tmp = g_malloc0(strlen (line + cursor) + 1);
- strcpy (tmp, line + cursor);
+ gchar *tmp = 0;
+ gsize size = strlen(line + cursor) + 1;
+
+ tmp = g_malloc0(size);
+ g_strlcpy (tmp, line + cursor, size);
line[cursor] = key;
line[cursor + 1] = 0;
- strcat (&line[cursor + 1], tmp);
+ g_strlcat (&line[cursor + 1], tmp, size);
g_free(tmp);
cursor_move_right();
}
/* update the current history entry */
size_t size = strlen(line)+1;
hcurrent->data = g_realloc(hcurrent->data, size);
- strncpy(hcurrent->data, line, size);
+ g_strlcpy(hcurrent->data, line, size);
}
else
{
diff --git a/src/wreadln.h b/src/wreadln.h
index 55c24b91f48563e5c077bfd09bc0f8d185ef333d..667740c2261d664c9a5d5e3e2676c60dc552fde7 100644 (file)
--- a/src/wreadln.h
+++ b/src/wreadln.h
#define WREADLN_H
/* max size allocated for a line */
-extern unsigned int wrln_max_line_size;
+extern guint wrln_max_line_size;
/* max items stored in the history list */
-extern unsigned int wrln_max_history_length;
+extern guint wrln_max_history_length;
/* custom wgetch function */
typedef int (*wrln_wgetch_fn_t) (WINDOW *w);
/* Note, wreadln calls curs_set() and noecho(), to enable cursor and
* disable echo. wreadln will not restore these settings when exiting! */
-char *wreadln(WINDOW *w, /* the curses window to use */
- char *prompt, /* the prompt string or NULL */
- char *initial_value, /* initial value or NULL for a empty line
- * (char *) -1 => get value from history */
- int x1, /* the maximum x position or 0 */
- GList **history, /* a pointer to a history list or NULL */
- GCompletion *gcmp /* a GCompletion structure or NULL */
- );
+gchar *wreadln(WINDOW *w, /* the curses window to use */
+ gchar *prompt, /* the prompt string or NULL */
+ gchar *initial_value, /* initial value or NULL for a empty line
+ * (char *) -1 = get value from history */
+ gint x1, /* the maximum x position or 0 */
+ GList **history, /* a pointer to a history list or NULL */
+ GCompletion *gcmp /* a GCompletion structure or NULL */
+ );
#endif