2 * help.c -- Help command
4 * Copyright (C) 2006-2009 Mikael Berthe <mikael@lilotux.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #define DEFAULT_LANG "en"
36 // Return the language code string (a 2-letters string).
37 static const char *get_lang(void) {
38 static const char *lang_str
= DEFAULT_LANG
;
42 opt_l
= settings_opt_get("lang");
43 if (opt_l
&& strlen(opt_l
) == 2 && isalpha(opt_l
[0]) && isalpha(opt_l
[1])) {
44 strncpy(lang
, opt_l
, sizeof(lang
));
52 // help_process(string)
53 // Display help about the "string" command.
54 // If string is null, display general help.
55 // Return 0 in case of success.
56 int help_process(char *string
)
59 scr_LogPrint(LPRINT_NORMAL
, "Help isn't available.");
64 char *helpfiles_dir
, *filename
;
66 const int datasize
= 4096;
71 for (p
= string
; p
&& *p
; p
++) {
72 if (!isalnum(*p
) && *p
!= '_' && *p
!= '-') {
73 scr_LogPrint(LPRINT_NORMAL
, "Cannot find help (invalid keyword).");
80 helpfiles_dir
= g_strdup_printf("%s/mcabber/help", DATA_DIR
);
83 if (string
&& *string
) {
86 filename
= g_strdup_printf("%s/%s/hlp_%s.txt", helpfiles_dir
, lang
, p
);
88 filename
= g_strdup_printf("%s/%s/hlp.txt", helpfiles_dir
, lang
);
90 fp
= fopen(filename
, "r");
92 if (!(fp
) && (g_strcmp0(lang
, DEFAULT_LANG
)) ) {
95 filename
= g_strdup_printf("%s/%s/hlp_%s.txt", helpfiles_dir
, DEFAULT_LANG
, p
);
97 filename
= g_strdup_printf("%s/%s/hlp.txt", helpfiles_dir
, DEFAULT_LANG
);
99 fp
= fopen(filename
, "r");
103 g_free(helpfiles_dir
);
106 scr_LogPrint(LPRINT_NORMAL
, "No help found.");
110 data
= g_new(char, datasize
);
112 if (fgets(data
, datasize
, fp
) == NULL
) break;
113 // Strip trailing newline
114 for (p
= data
; *p
; p
++) ;
117 if (*p
== '\n' || *p
== '\r')
119 // Displaty the help line
120 scr_LogPrint(LPRINT_NORMAL
, "%s", data
);
127 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID
, TRUE
);
128 update_roster
= TRUE
;
132 #endif /* DATA_DIR */
135 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */