X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Ffe-common%2Fcore%2Ffe-help.c;fp=apps%2Firssi%2Fsrc%2Ffe-common%2Fcore%2Ffe-help.c;h=b51b894937675a66868eb9f1a361b5965561f294;hb=18d69a0a1fec438e241bb4f431506ed59a34066b;hp=c093b84b296547e249e4258f30d0c04a21231c9e;hpb=f7be6adec0248118cddde9b04522c13cd90568cd;p=silc.git diff --git a/apps/irssi/src/fe-common/core/fe-help.c b/apps/irssi/src/fe-common/core/fe-help.c index c093b84b..b51b8949 100644 --- a/apps/irssi/src/fe-common/core/fe-help.c +++ b/apps/irssi/src/fe-common/core/fe-help.c @@ -13,9 +13,9 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "module.h" @@ -23,7 +23,6 @@ #include "commands.h" #include "levels.h" #include "misc.h" -#include "line-split.h" #include "settings.h" #include "printtext.h" @@ -117,46 +116,43 @@ static void help_category(GSList *cmdlist, int items) static int show_help_file(const char *file) { const char *helppath; - char tmpbuf[1024], *str, *path, **paths, **tmp; - LINEBUF_REC *buffer = NULL; - int f, ret, recvlen; + char *path, **paths, **tmp; + GIOChannel *handle; + GString *buf; + gsize tpos; helppath = settings_get_str("help_path"); paths = g_strsplit(helppath, ":", -1); - f = -1; + handle = NULL; for (tmp = paths; *tmp != NULL; tmp++) { /* helpdir/command or helpdir/category/command */ path = g_strdup_printf("%s/%s", *tmp, file); - f = open(path, O_RDONLY); + handle = g_io_channel_new_file(path, "r", NULL); g_free(path); - if (f != -1) + if (handle != NULL) break; } g_strfreev(paths); - if (f == -1) + if (handle == NULL) return FALSE; + g_io_channel_set_encoding(handle, NULL, NULL); + buf = g_string_sized_new(512); /* just print to screen whatever is in the file */ - do { - recvlen = read(f, tmpbuf, sizeof(tmpbuf)); - - ret = line_split(tmpbuf, recvlen, &str, &buffer); - if (ret > 0) { - str = g_strconcat("%|", str, NULL); - printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, str); - g_free(str); - } + while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) { + buf->str[tpos] = '\0'; + g_string_prepend(buf, "%|"); + printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, buf->str); } - while (ret > 0); - line_split_free(buffer); + g_string_free(buf, TRUE); - close(f); + g_io_channel_unref(handle); return TRUE; } @@ -252,13 +248,10 @@ static void show_help(const char *data) /* SYNTAX: HELP [] */ static void cmd_help(const char *data) { - char *cmd, *ptr; - - cmd = g_strdup(data); - ptr = cmd+strlen(cmd); - while (ptr[-1] == ' ') ptr--; *ptr = '\0'; + char *cmd; - g_strdown(cmd); + cmd = g_ascii_strdown(data, -1); + g_strchomp(cmd); show_help(cmd); g_free(cmd); }