From: <ny...@us...> - 2006-07-30 04:07:28
|
Revision: 160 Author: nyaochi Date: 2006-07-29 21:07:19 -0700 (Sat, 29 Jul 2006) ViewCVS: http://svn.sourceforge.net/pmplib/?rev=160&view=rev Log Message: ----------- - Activate GMIF_STRIP_ARTIST flag when stripping words are specified. The previous implementation could not work with -z (--source) option. - Stripping heading words now works on Win32 GUI version. Modified Paths: -------------- trunk/pmplib/frontend/easypmp/cui/main.c trunk/pmplib/frontend/easypmp/cui/option.c trunk/pmplib/frontend/easypmp/win32gui/preference.h trunk/pmplib/frontend/easypmp/win32gui/processingdlg.h Modified: trunk/pmplib/frontend/easypmp/cui/main.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/main.c 2006-07-30 02:06:40 UTC (rev 159) +++ trunk/pmplib/frontend/easypmp/cui/main.c 2006-07-30 04:07:19 UTC (rev 160) @@ -239,6 +239,7 @@ ucs2char_t* ucs2str = mbsdupucs2(opt.mbs_strip_words); easypmp_set_strip_words(&opt, ucs2str); ucs2free(ucs2str); + opt.media_info_source |= GMIF_STRIP_ARTIST; } /* Obtain the path to root directory (path_to_root) from the command line if any. */ Modified: trunk/pmplib/frontend/easypmp/cui/option.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/option.c 2006-07-30 02:06:40 UTC (rev 159) +++ trunk/pmplib/frontend/easypmp/cui/option.c 2006-07-30 04:07:19 UTC (rev 160) @@ -118,7 +118,7 @@ memset(opt, 0, sizeof(*opt)); // Set default values here. - opt->media_info_source |= (GMIF_TAG | GMIF_STRIP_ARTIST); + opt->media_info_source = GMIF_TAG; opt->system_encoding = get_default_encoding(); opt->music_encoding = get_default_encoding(); } Modified: trunk/pmplib/frontend/easypmp/win32gui/preference.h =================================================================== --- trunk/pmplib/frontend/easypmp/win32gui/preference.h 2006-07-30 02:06:40 UTC (rev 159) +++ trunk/pmplib/frontend/easypmp/win32gui/preference.h 2006-07-30 04:07:19 UTC (rev 160) @@ -47,7 +47,7 @@ { iDBProces = 2; iMediaInfoSource = 0; - strStripWords = _T("the "); + strStripWords = _T("the"); iPlaylistProcess = 2; bConvertInPlaylist = TRUE; bConvertInMusic = TRUE; Modified: trunk/pmplib/frontend/easypmp/win32gui/processingdlg.h =================================================================== --- trunk/pmplib/frontend/easypmp/win32gui/processingdlg.h 2006-07-30 02:06:40 UTC (rev 159) +++ trunk/pmplib/frontend/easypmp/win32gui/processingdlg.h 2006-07-30 04:07:19 UTC (rev 160) @@ -266,8 +266,11 @@ // Set source of media information. opt.media_info_source = media_info_sources[m_preference.iMediaInfoSource]; - // Set a list of strip words. - easypmp_set_strip_words(&opt, CT2CW(m_preference.strStripWords)); + // Set words to be stripped from artist names. + if (!m_preference.strStripWords.IsEmpty()) { + easypmp_set_strip_words(&opt, CT2CW(m_preference.strStripWords)); + opt.media_info_source |= GMIF_STRIP_ARTIST; + } // Set Playlist conversion options. switch (m_preference.iPlaylistProcess) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-01-03 10:49:34
|
Revision: 231 http://svn.sourceforge.net/pmplib/?rev=231&view=rev Author: nyaochi Date: 2007-01-03 02:49:31 -0800 (Wed, 03 Jan 2007) Log Message: ----------- - Moved Martin's TTY management code to console_posix.c (untested). - Implemented the similar console routine for Win32 (console_win32.c). Modified Paths: -------------- trunk/pmplib/frontend/easypmp/cui/easypmp_cui.vcproj trunk/pmplib/frontend/easypmp/cui/util.c Added Paths: ----------- trunk/pmplib/frontend/easypmp/cui/console.h trunk/pmplib/frontend/easypmp/cui/console_posix.c trunk/pmplib/frontend/easypmp/cui/console_win32.c Added: trunk/pmplib/frontend/easypmp/cui/console.h =================================================================== --- trunk/pmplib/frontend/easypmp/cui/console.h (rev 0) +++ trunk/pmplib/frontend/easypmp/cui/console.h 2007-01-03 10:49:31 UTC (rev 231) @@ -0,0 +1,39 @@ +/* + * Console manupulator. + * + * Copyright (c) 2006 Nyaochi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit + * http://www.gnu.org/copyleft/gpl.html . + * + */ + +/* $Id$ */ + +#ifndef __CONSOLE_H__ +#define __CONSOLE_H__ + +/** + * \addtogroup cui + * @{ + */ + +int console_init(); +int console_clearln(FILE *fp); +int console_println(FILE *fp, const ucs2char_t* line, int min_width); + +/** @} */ + +#endif/*__CONSOLE_H__*/ Property changes on: trunk/pmplib/frontend/easypmp/cui/console.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/frontend/easypmp/cui/console_posix.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/console_posix.c (rev 0) +++ trunk/pmplib/frontend/easypmp/cui/console_posix.c 2007-01-03 10:49:31 UTC (rev 231) @@ -0,0 +1,201 @@ +/* + * Miscellaneous utilities. + * + * Copyright (c) 2005-2006 Nyaochi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit + * http://www.gnu.org/copyleft/gpl.html . + * + */ + +/* $Id$ */ + +/** + * @file + * Utility functions for the easypmp command line program (mostly + * display related). + * + * @addtogroup cui + * @{ + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ +#ifdef HAVE_STRING_H +#include <string.h> +#endif/*HAVE_STRING_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <ucs2char.h> + +#include "console.h" + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +#if CAN_GET_WIN_SIZE +#include <sys/ioctl.h> +#include <signal.h> +#endif/*CAN_GET_WIN_SIZE*/ + +#include "util.h" + +#if CAN_GET_WIN_SIZE +/** + * The number of characters that can be printed on a single line, + * without causing a line wrap. Since the right-most column is + * required for the cursor, this is one less than the actual terminal + * width. + * + * Defaults to 79 on systems where we can't tell the width of the + * terminal. + */ +static volatile unsigned short int window_width; +#else +static const unsigned short int window_width = 79; +#endif + +/** + * The minimum width of the terminal we're willing to entertain. If + * the terminal gets narrower than this width, we treat it as this + * width. Note that it must be at least 2 to allow for one character + * and the cursor. +*/ +static const int min_term_width = 6; + + +#define POSSIBLE_TTYS 2 +/** + * Flags to indicate whether stdin, stdout, and stderr are attached to + * a terminal. These are used to determine whether we should check + * the width of some progress lines before printing them. Initialised + * in display_init. + */ +static int fd_is_tty[POSSIBLE_TTYS+1]; + +#if CAN_GET_WIN_SIZE + +/** + * Handler for the "terminal window changed size" signal. + * + * @param unused + */ +void window_size_changed(int unused) +{ + static struct winsize wsize; + if (ioctl(1, TIOCGWINSZ, &wsize) != -1) { + if (wsize.ws_col > min_term_width) { + window_width = wsize.ws_col - 1; + } else { + window_width = min_term_width; + } + } +} + +#endif/*CAN_GET_WIN_SIZE*/ + +/** + * Determines whether stdin, stdout and stderr are associated with a + * TTY, and update fd_is_tty accordingly. Also sets up + * window_size_changed as a signal handler. + */ +void display_init() +{ +#ifdef HAVE_TTY + int i; + for(i = 0; i <= POSSIBLE_TTYS; ++i) + fd_is_tty[i] = isatty(i); + +#if CAN_GET_WIN_SIZE + signal(SIGWINCH,window_size_changed); + window_size_changed(0); +#endif/*CAN_GET_WIN_SIZE*/ +#endif/*HAVE_TTY*/ +} + +/** + * Deletes all text on the current line by overwriting it with spaces. + * + * A 'blank line' is written to a given file pointer, @p fp. That is, + * a number of spaces equal to the current window width is written. + * This is followed by a carriage return character, to return the + * cursor to the start of the line. +*/ +void clear_line(FILE *fp) +{ + /* fmt needs 4 chars (%, -, s, \r) + + room for window_width as string (max. 65535) + + null terminator */ + char fmt[10]; + sprintf(fmt, "%%-%us\r", window_width); + fprintf(fp, fmt, ""); +} + +/** + * Displays a UCS-2 string truncated for the terminal width. + * + * Displays as much of a UCS-2 encoded string as will fit on a single + * line in the terminal, and returning the cursor to the start of the + * line. If the terminal is less that the given minimum width, that + * minimum number of characters is displayed anyway, even if it means + * the text will wrap onto the next line. + * + * If @p fp isn't associated with a terminal, just print the whole line. + * + * @param fp FILE* to print on + * @param line the UCS-2 encoded string to display + * @param min_width minimum number of characters to print + */ +void display_line(FILE *fp, const ucs2char_t* const line, + unsigned int min_width) +{ + unsigned int length = ucs2len(line); + const ucs2char_t* line_to_print; + + int writing_to_tty; + /* Check if writing to a terminal. If so, clear the current line. */ + int fd = fileno(fp); + if (0 < fd && fd <= POSSIBLE_TTYS && fd_is_tty[fd]) { + clear_line(fp); + writing_to_tty = 1; + } else { + writing_to_tty = 0; + } + + if(!writing_to_tty) { + /* Write the whole line to the file, add \n. */ + fprints(fp, "%s\r\n", line); + } else if (length <= window_width) { + /* There's enough room to show the whole line. */ + fprints(fp, "%s\r", line); + } + else { + /* Length of the longest string we might display: */ + const int max_trunc_length = MAX(window_width,min_width); + + /* Length of string we actually will display: */ + const size_t trunc_length = MIN(max_trunc_length, length); + + ucs2char_t *truncated_line = ucs2calloc(sizeof(ucs2char_t) * (trunc_length+1)); + ucs2ncpy(truncated_line, line, trunc_length); + fprints(fp, "%s\r", truncated_line); + } +} + + +/** @} */ Property changes on: trunk/pmplib/frontend/easypmp/cui/console_posix.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/frontend/easypmp/cui/console_win32.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/console_win32.c (rev 0) +++ trunk/pmplib/frontend/easypmp/cui/console_win32.c 2007-01-03 10:49:31 UTC (rev 231) @@ -0,0 +1,109 @@ +/* + * Console manupulator for Win32 API. + * + * Copyright (c) 2006 Nyaochi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit + * http://www.gnu.org/copyleft/gpl.html . + * + */ + +/* $Id:$ */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <io.h> +#include <stdio.h> +#include <stdlib.h> +#include <ucs2char.h> + +#include <windows.h> + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +static HANDLE get_handle(FILE *fp) +{ + return (HANDLE)_get_osfhandle(_fileno(fp)); +} + +int console_init() +{ + return 0; +} + +int console_clearln(FILE *fp) +{ + HANDLE hOutput = (HANDLE)_get_osfhandle(_fileno(fp)); + CONSOLE_SCREEN_BUFFER_INFO csbi; + + memset(&csbi, 0, sizeof(csbi)); + if (GetConsoleScreenBufferInfo(hOutput, &csbi)) { + /* The output is a console buffer. */ + DWORD num_written = 0; + csbi.dwCursorPosition.X = csbi.srWindow.Left; + FillConsoleOutputCharacterA( + hOutput, + ' ', + csbi.srWindow.Right - csbi.srWindow.Left + 1, + csbi.dwCursorPosition, + &num_written + ); + SetConsoleCursorPosition(hOutput, csbi.dwCursorPosition); + return 0; + } else { + /* Does nothing for non-console buffer (e.g., redirected file) */ + return 1; + } +} + +int console_println(FILE *fp, const ucs2char_t* line, int min_width) +{ + const int margin = 5; + HANDLE hOutput = (HANDLE)_get_osfhandle(_fileno(fp)); + CONSOLE_SCREEN_BUFFER_INFO csbi; + + memset(&csbi, 0, sizeof(csbi)); + if (GetConsoleScreenBufferInfo(hOutput, &csbi)) { + int x = 0, width = 0; + const ucs2char_t* p = line; + + while (*p) { + memset(&csbi, 0, sizeof(csbi)); + GetConsoleScreenBufferInfo(hOutput, &csbi); + + x = (int)csbi.dwCursorPosition.X; + width = (int)(csbi.srWindow.Right - csbi.srWindow.Left) + 1; + if (width <= x + margin) { + int ndotts = MIN(3, width - x); + while (ndotts-- > 0) fputc('.', fp); + break; + } else { + fputwc((wchar_t)*p, fp); + } + p++; + } + fputc('\r', fp); + return (int)(p - line); + } else { + fprintf(fp, "%S\n", line); + return ucs2len(line); + } +} + + +/** @} */ Property changes on: trunk/pmplib/frontend/easypmp/cui/console_win32.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/pmplib/frontend/easypmp/cui/easypmp_cui.vcproj =================================================================== --- trunk/pmplib/frontend/easypmp/cui/easypmp_cui.vcproj 2006-12-31 07:38:06 UTC (rev 230) +++ trunk/pmplib/frontend/easypmp/cui/easypmp_cui.vcproj 2007-01-03 10:49:31 UTC (rev 231) @@ -180,6 +180,10 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File + RelativePath=".\console_win32.c" + > + </File> + <File RelativePath=".\device.c" > </File> @@ -210,6 +214,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File + RelativePath=".\console.h" + > + </File> + <File RelativePath=".\getopt.h" > </File> Modified: trunk/pmplib/frontend/easypmp/cui/util.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/util.c 2006-12-31 07:38:06 UTC (rev 230) +++ trunk/pmplib/frontend/easypmp/cui/util.c 2007-01-03 10:49:31 UTC (rev 231) @@ -43,159 +43,9 @@ #include <stdlib.h> #include <ucs2char.h> -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#include "console.h" -#if CAN_GET_WIN_SIZE -#include <sys/ioctl.h> -#include <signal.h> -#endif/*CAN_GET_WIN_SIZE*/ - -#include "util.h" - -#if CAN_GET_WIN_SIZE /** - * The number of characters that can be printed on a single line, - * without causing a line wrap. Since the right-most column is - * required for the cursor, this is one less than the actual terminal - * width. - * - * Defaults to 79 on systems where we can't tell the width of the - * terminal. - */ -static volatile unsigned short int window_width; -#else -static const unsigned short int window_width = 79; -#endif - -/** - * The minimum width of the terminal we're willing to entertain. If - * the terminal gets narrower than this width, we treat it as this - * width. Note that it must be at least 2 to allow for one character - * and the cursor. -*/ -static const int min_term_width = 6; - - -#define POSSIBLE_TTYS 2 -/** - * Flags to indicate whether stdin, stdout, and stderr are attached to - * a terminal. These are used to determine whether we should check - * the width of some progress lines before printing them. Initialised - * in display_init. - */ -static int fd_is_tty[POSSIBLE_TTYS+1]; - -#if CAN_GET_WIN_SIZE - -/** - * Handler for the "terminal window changed size" signal. - * - * @param unused - */ -void window_size_changed(int unused) -{ - static struct winsize wsize; - if (ioctl(1, TIOCGWINSZ, &wsize) != -1) { - if (wsize.ws_col > min_term_width) { - window_width = wsize.ws_col - 1; - } else { - window_width = min_term_width; - } - } -} - -#endif/*CAN_GET_WIN_SIZE*/ - -/** - * Determines whether stdin, stdout and stderr are associated with a - * TTY, and update fd_is_tty accordingly. Also sets up - * window_size_changed as a signal handler. - */ -void display_init() -{ -#ifdef HAVE_TTY - int i; - for(i = 0; i <= POSSIBLE_TTYS; ++i) - fd_is_tty[i] = isatty(i); - -#if CAN_GET_WIN_SIZE - signal(SIGWINCH,window_size_changed); - window_size_changed(0); -#endif/*CAN_GET_WIN_SIZE*/ -#endif/*HAVE_TTY*/ -} - -/** - * Deletes all text on the current line by overwriting it with spaces. - * - * A 'blank line' is written to a given file pointer, @p fp. That is, - * a number of spaces equal to the current window width is written. - * This is followed by a carriage return character, to return the - * cursor to the start of the line. -*/ -void clear_line(FILE *fp) -{ - /* fmt needs 4 chars (%, -, s, \r) + - room for window_width as string (max. 65535) + - null terminator */ - char fmt[10]; - sprintf(fmt, "%%-%us\r", window_width); - fprintf(fp, fmt, ""); -} - -/** - * Displays a UCS-2 string truncated for the terminal width. - * - * Displays as much of a UCS-2 encoded string as will fit on a single - * line in the terminal, and returning the cursor to the start of the - * line. If the terminal is less that the given minimum width, that - * minimum number of characters is displayed anyway, even if it means - * the text will wrap onto the next line. - * - * If @p fp isn't associated with a terminal, just print the whole line. - * - * @param fp FILE* to print on - * @param line the UCS-2 encoded string to display - * @param min_width minimum number of characters to print - */ -void display_line(FILE *fp, const ucs2char_t* const line, - unsigned int min_width) -{ - unsigned int length = ucs2len(line); - const ucs2char_t* line_to_print; - - int writing_to_tty; - /* Check if writing to a terminal. If so, clear the current line. */ - int fd = fileno(fp); - if (0 < fd && fd <= POSSIBLE_TTYS && fd_is_tty[fd]) { - clear_line(fp); - writing_to_tty = 1; - } else { - writing_to_tty = 0; - } - - if(!writing_to_tty) { - /* Write the whole line to the file, add \n. */ - fprints(fp, "%s\r\n", line); - } else if (length <= window_width) { - /* There's enough room to show the whole line. */ - fprints(fp, "%s\r", line); - } - else { - /* Length of the longest string we might display: */ - const int max_trunc_length = MAX(window_width,min_width); - - /* Length of string we actually will display: */ - const size_t trunc_length = MIN(max_trunc_length, length); - - ucs2char_t *truncated_line = ucs2calloc(sizeof(ucs2char_t) * (trunc_length+1)); - ucs2ncpy(truncated_line, line, trunc_length); - fprints(fp, "%s\r", truncated_line); - } -} - -/** * Generic display method for progress messages consisting of a * number and a string. * @@ -215,24 +65,9 @@ display_line is used to truncate the line in this way. */ - - // Numeric part, plus associated punctuation - const int prefix_length = 16; - char *fmt = alloca(sizeof(char) * prefix_length + 1); - - ucs2char_t *line = alloca(sizeof(ucs2char_t) * (ucs2len(msg) + prefix_length + 1)); - ucs2char_t *fmt_ucs2; - - // Build the numeric part... - sprintf(fmt, " %u: ", n); - fmt_ucs2 = mbsdupucs2(fmt); - if (fmt_ucs2) { - ucs2cpy(line, fmt_ucs2); - // ... and append the message. - ucs2cat(line, msg); - display_line(fp, line, strlen(fmt)); - ucs2free(fmt_ucs2); - } + console_clearln(fp); + fprintf(fp, " %u: ", n); + console_println(fp, msg, 0); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-01-03 13:38:48
|
Revision: 232 http://svn.sourceforge.net/pmplib/?rev=232&view=rev Author: nyaochi Date: 2007-01-03 05:38:48 -0800 (Wed, 03 Jan 2007) Log Message: ----------- Make console_posix.c work. More test needed. Modified Paths: -------------- trunk/pmplib/frontend/easypmp/cui/Makefile.am trunk/pmplib/frontend/easypmp/cui/console_posix.c trunk/pmplib/frontend/easypmp/cui/main.c Modified: trunk/pmplib/frontend/easypmp/cui/Makefile.am =================================================================== --- trunk/pmplib/frontend/easypmp/cui/Makefile.am 2007-01-03 10:49:31 UTC (rev 231) +++ trunk/pmplib/frontend/easypmp/cui/Makefile.am 2007-01-03 13:38:48 UTC (rev 232) @@ -20,6 +20,8 @@ $(getopt) \ util.c \ util.h \ + console_posix.c \ + console.h \ main.c easypmp_CPPFLAGS = -I$(srcdir)/../common Modified: trunk/pmplib/frontend/easypmp/cui/console_posix.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/console_posix.c 2007-01-03 10:49:31 UTC (rev 231) +++ trunk/pmplib/frontend/easypmp/cui/console_posix.c 2007-01-03 13:38:48 UTC (rev 232) @@ -1,7 +1,7 @@ /* * Miscellaneous utilities. * - * Copyright (c) 2005-2006 Nyaochi + * Copyright (c) 2005-2006 Martin Ellis * * 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 @@ -45,6 +45,8 @@ #include "console.h" +#define HAVE_TTY + #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -95,7 +97,7 @@ * * @param unused */ -void window_size_changed(int unused) +static void window_size_changed(int unused) { static struct winsize wsize; if (ioctl(1, TIOCGWINSZ, &wsize) != -1) { @@ -109,12 +111,22 @@ #endif/*CAN_GET_WIN_SIZE*/ +static int is_tty(FILE *fp) +{ + int fd = fileno(fp); + if (0 < fd && fd <= POSSIBLE_TTYS && fd_is_tty[fd]) { + return 1; + } else { + return 0; + } +} + /** * Determines whether stdin, stdout and stderr are associated with a * TTY, and update fd_is_tty accordingly. Also sets up * window_size_changed as a signal handler. */ -void display_init() +int console_init() { #ifdef HAVE_TTY int i; @@ -126,6 +138,7 @@ window_size_changed(0); #endif/*CAN_GET_WIN_SIZE*/ #endif/*HAVE_TTY*/ + return 0; } /** @@ -136,14 +149,19 @@ * This is followed by a carriage return character, to return the * cursor to the start of the line. */ -void clear_line(FILE *fp) +int console_clearln(FILE *fp) { - /* fmt needs 4 chars (%, -, s, \r) + - room for window_width as string (max. 65535) + - null terminator */ - char fmt[10]; - sprintf(fmt, "%%-%us\r", window_width); - fprintf(fp, fmt, ""); + if (is_tty(fp)) { + /* fmt needs 4 chars (%, -, s, \r) + + room for window_width as string (max. 65535) + + null terminator */ + char fmt[10]; + sprintf(fmt, "%%-%us\r", window_width); + fprintf(fp, fmt, ""); + return 0; + } else { + return 1; + } } /** @@ -161,28 +179,22 @@ * @param line the UCS-2 encoded string to display * @param min_width minimum number of characters to print */ -void display_line(FILE *fp, const ucs2char_t* const line, - unsigned int min_width) +int console_println(FILE *fp, const ucs2char_t* line, int min_width) { - unsigned int length = ucs2len(line); + int length = ucs2len(line); const ucs2char_t* line_to_print; - int writing_to_tty; - /* Check if writing to a terminal. If so, clear the current line. */ - int fd = fileno(fp); - if (0 < fd && fd <= POSSIBLE_TTYS && fd_is_tty[fd]) { - clear_line(fp); - writing_to_tty = 1; - } else { - writing_to_tty = 0; - } + /* Check if writing to a terminal. */ + int writing_to_tty = is_tty(fp); if(!writing_to_tty) { /* Write the whole line to the file, add \n. */ - fprints(fp, "%s\r\n", line); + fprints(fp, "%s\n", line); + return length; } else if (length <= window_width) { /* There's enough room to show the whole line. */ fprints(fp, "%s\r", line); + return length; } else { /* Length of the longest string we might display: */ @@ -194,6 +206,7 @@ ucs2char_t *truncated_line = ucs2calloc(sizeof(ucs2char_t) * (trunc_length+1)); ucs2ncpy(truncated_line, line, trunc_length); fprints(fp, "%s\r", truncated_line); + return trunc_length; } } Modified: trunk/pmplib/frontend/easypmp/cui/main.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-03 10:49:31 UTC (rev 231) +++ trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-03 13:38:48 UTC (rev 232) @@ -113,7 +113,7 @@ easypmp_progress_num_str(fpo, param_int+1, filepath_skippath(param_str)); break; case EASYPMPDBP_GMI|EASYPMPSP_END: - clear_line(fpo); + console_clearln(fpo); fprintf(fpo, " %d files were imported\n", param_int); fprintf(fpo, "\n"); break; @@ -329,11 +329,11 @@ fprintf(fpo, "\n"); memset(&musics, 0, sizeof(musics)); - display_init(); + console_init(); if ((opt.verb & MODE_DATABASE) || ((opt.verb & MODE_PLAYLIST) && (opt.verb & MODE_PLAYLIST_FIND))) { fprintf(fpo, "Enumerating music files\n"); easypmp_enumerate_music(&musics, pmp, &opt, easypmp_enumerate_progress, NULL); - clear_line(fpo); + console_clearln(fpo); fprintf(fpo, " %d music files were found\n", musics.num_elements); fprintf(fpo, "\n"); } @@ -342,7 +342,7 @@ if (opt.verb & MODE_PLAYLIST) { fprintf(fpe, "Enumerating playlist files\n"); easypmp_enumerate_playlist(&playlists, pmp, &opt, easypmp_enumerate_progress, NULL); - clear_line(fpo); + console_clearln(fpo); fprintf(fpo, " %d music files were found\n", playlists.num_elements); fprintf(fpo, "\n"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-01-04 01:39:09
|
Revision: 235 http://svn.sourceforge.net/pmplib/?rev=235&view=rev Author: nyaochi Date: 2007-01-03 17:39:08 -0800 (Wed, 03 Jan 2007) Log Message: ----------- Changed the specification of console_println() for Win32: this function must be called when the console cursor is at the beginning of lines. This change is due to the difficulty of obtaining the cursor position in POSIX environment. Modified Paths: -------------- trunk/pmplib/frontend/easypmp/cui/main.c trunk/pmplib/frontend/easypmp/cui/util.c Modified: trunk/pmplib/frontend/easypmp/cui/main.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-03 14:49:09 UTC (rev 234) +++ trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-04 01:39:08 UTC (rev 235) @@ -45,6 +45,7 @@ #include <easypmp.h> #include "option.h" +#include "console.h" #include "util.h" #ifdef _WIN32 Modified: trunk/pmplib/frontend/easypmp/cui/util.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/util.c 2007-01-03 14:49:09 UTC (rev 234) +++ trunk/pmplib/frontend/easypmp/cui/util.c 2007-01-04 01:39:08 UTC (rev 235) @@ -43,6 +43,7 @@ #include <stdlib.h> #include <ucs2char.h> +#include "util.h" #include "console.h" /** @@ -65,9 +66,20 @@ display_line is used to truncate the line in this way. */ + ucs2char_t *str = alloca(sizeof(ucs2char_t) * (ucs2len(msg) + 32)); + ucs2char_t *p = str; + + /* sprintf(str, " %u: %S", n, msg); */ + *p++ = ' '; + *p++ = ' '; + itoucs2((int)n, p, 10); + p = str + ucs2len(str); + *p++ = ':'; + *p++ = ' '; + ucs2cpy(p, msg); + console_clearln(fp); - fprintf(fp, " %u: ", n); - console_println(fp, msg, 0); + console_println(fp, str, 0); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ny...@us...> - 2007-01-26 15:59:23
|
Revision: 288 http://svn.sourceforge.net/pmplib/?rev=288&view=rev Author: nyaochi Date: 2007-01-26 07:59:23 -0800 (Fri, 26 Jan 2007) Log Message: ----------- Show supported audio codecs and extensions. Modified Paths: -------------- trunk/pmplib/frontend/easypmp/cui/device.c trunk/pmplib/frontend/easypmp/cui/main.c Modified: trunk/pmplib/frontend/easypmp/cui/device.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/device.c 2007-01-26 15:39:06 UTC (rev 287) +++ trunk/pmplib/frontend/easypmp/cui/device.c 2007-01-26 15:59:23 UTC (rev 288) @@ -59,6 +59,8 @@ void device_show_information(pmp_t* pmp, FILE *fp) { + int i; + fprintf(fp, "Device identifier: %s\n", pmp->info.decl.id); fprintf(fp, " Manufacturer: %s\n", pmp->info.decl.manufacturer); fprintf(fp, " Product name: %s\n", pmp->info.decl.name); @@ -67,6 +69,25 @@ fprintf(fp, " Firmware range: %s to %s\n", pmp->info.decl.min_version, pmp->info.decl.max_version); fprintf(fp, " Default language: %s\n", pmp->info.decl.language); + fprintf(fp, " Audio codec(s): "); + for (i = 0;i < pmp->info.num_audio_codecs;++i) { + switch (pmp->info.audio_codecs[i]) { + case PMPCODEC_MPEGLAYER3: fputs("MP3", fp); break; + case PMPCODEC_WMA: fputs("WMA", fp); break; + case PMPCODEC_VORBIS: fputs("Ogg Vorbis", fp); break; + case PMPCODEC_WAV: fputs("WAV", fp); break; + } + if (i != pmp->info.num_audio_codecs-1) fputs(", ", fp); + } + fputc('\n', fp); + + fprintf(fp, " Audio extension(s): "); + for (i = 0;i < pmp->info.num_audio_extensions;++i) { + fprints(fp, "%s", pmp->info.audio_extensions[i]); + if (i != pmp->info.num_audio_extensions-1) fputs(";", fp); + } + fputc('\n', fp); + fprints(fp, " Root directory: %s\n", pmp->info.path_to_root); device_show_path(fp, " Music directory: %s\n", pmp->info.path_to_music); device_show_path(fp, " Playlist directory: %s\n", pmp->info.path_to_playlist); Modified: trunk/pmplib/frontend/easypmp/cui/main.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-26 15:39:06 UTC (rev 287) +++ trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-26 15:59:23 UTC (rev 288) @@ -94,7 +94,7 @@ case EASYPMPP_START: break; case EASYPMPP_OPEN|EASYPMPSP_START: - fprintf(fpo, "Opening the device\n"); + fprintf(fpo, "Opening the portable media device\n"); break; case EASYPMPP_OPEN|EASYPMPSP_END: fprintf(fpo, "\n"); @@ -117,7 +117,6 @@ case EASYPMPP_MUSIC_GMI|EASYPMPSP_END: console_clearln(fpo); fprintf(fpo, " %d files were imported\n", param_int); - fprintf(fpo, "\n"); break; case EASYPMPP_MUSIC_UPDATE|EASYPMPSP_START: fprintf(fpo, "Updating database entries\n"); @@ -361,7 +360,7 @@ fprintf(fpe, "Enumerating playlist files\n"); easypmp_enumerate_playlist(&playlists, pmp, &opt, easypmp_enumerate_progress, NULL); console_clearln(fpo); - fprintf(fpo, " %d music files were found\n", playlists.num_elements); + fprintf(fpo, " %d playlist files were found\n", playlists.num_elements); fprintf(fpo, "\n"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |