~ubuntu-branches/ubuntu/oneiric/irssi/oneiric

« back to all changes in this revision

Viewing changes to src/fe-common/core/fe-help.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-05 15:50:50 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090505155050-aoqlnpes7che9rtd
Tags: 0.8.13-1ubuntu1
* Merge from debian unstable (LP: #372411), remaining changes:
  - debian/patches: 03firsttimer_text
    + Adapt it so it tells you about connecting to irc.ubuntu.com and
      joining #ubuntu instead of irc.debian.org and #debian.
  - debian/patches: 90irc-ubuntu-com
* Fixed debian/patches/90irc-ubuntu-com for new irssi.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "commands.h"
24
24
#include "levels.h"
25
25
#include "misc.h"
26
 
#include "line-split.h"
27
26
#include "settings.h"
28
27
 
29
28
#include "printtext.h"
117
116
static int show_help_file(const char *file)
118
117
{
119
118
        const char *helppath;
120
 
        char tmpbuf[1024], *str, *path, **paths, **tmp;
121
 
        LINEBUF_REC *buffer = NULL;
122
 
        int f, ret, recvlen;
 
119
        char *path, **paths, **tmp;
 
120
        GIOChannel *handle;
 
121
        GString *buf;
 
122
        gsize tpos;
123
123
 
124
124
        helppath = settings_get_str("help_path");
125
125
 
126
126
        paths = g_strsplit(helppath, ":", -1);
127
127
 
128
 
        f = -1;
 
128
        handle = NULL;
129
129
        for (tmp = paths; *tmp != NULL; tmp++) {
130
130
                /* helpdir/command or helpdir/category/command */
131
131
                path = g_strdup_printf("%s/%s", *tmp, file);
132
 
                f = open(path, O_RDONLY);
 
132
                handle = g_io_channel_new_file(path, "r", NULL);
133
133
                g_free(path);
134
134
 
135
 
                if (f != -1)
 
135
                if (handle != NULL)
136
136
                        break;
137
137
 
138
138
        }
139
139
 
140
140
        g_strfreev(paths);
141
141
 
142
 
        if (f == -1)
 
142
        if (handle == NULL)
143
143
                return FALSE;
144
144
 
 
145
        g_io_channel_set_encoding(handle, NULL, NULL);
 
146
        buf = g_string_sized_new(512);
145
147
        /* just print to screen whatever is in the file */
146
 
        do {
147
 
                recvlen = read(f, tmpbuf, sizeof(tmpbuf));
148
 
 
149
 
                ret = line_split(tmpbuf, recvlen, &str, &buffer);
150
 
                if (ret > 0) {
151
 
                        str = g_strconcat("%|", str, NULL);
152
 
                        printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, str);
153
 
                        g_free(str);
154
 
                }
 
148
        while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) {
 
149
                buf->str[tpos] = '\0';
 
150
                g_string_prepend(buf, "%|");
 
151
                printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, buf->str);
155
152
        }
156
 
        while (ret > 0);
157
 
        line_split_free(buffer);
 
153
        g_string_free(buf, TRUE);
158
154
 
159
 
        close(f);
 
155
        g_io_channel_unref(handle);
160
156
        return TRUE;
161
157
}
162
158
 
252
248
/* SYNTAX: HELP [<command>] */
253
249
static void cmd_help(const char *data)
254
250
{
255
 
        char *cmd, *ptr;
256
 
 
257
 
        cmd = g_strdup(data);
258
 
        ptr = cmd+strlen(cmd);
259
 
        while (ptr[-1] == ' ') ptr--; *ptr = '\0';
260
 
 
261
 
        g_strdown(cmd);
 
251
        char *cmd;
 
252
 
 
253
        cmd = g_ascii_strdown(data, -1);
 
254
        g_strchomp(cmd);
262
255
        show_help(cmd);
263
256
        g_free(cmd);
264
257
}