Initial import (again)
[srvx.git] / src / helpfile.h
1 /* helpfile.h - Help file loading and display
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #if !defined(HELPFILE_H)
20 #define HELPFILE_H
21
22 #include "common.h"
23
24 struct userNode;
25 struct handle_info;
26 struct string_list;
27
28 extern struct userNode *message_dest; /* message destination; useful in expansion callbacks */
29
30 #define MIN_LINE_SIZE           40
31 #define MAX_LINE_SIZE           450
32
33 #define TABLE_REPEAT_HEADERS 0x0001 /* repeat the headers for each columnset? */
34 #define TABLE_PAD_LEFT       0x0002 /* pad cells on the left? */
35 #define TABLE_REPEAT_ROWS    0x0004 /* put more than one row on a line? */
36 #define TABLE_NO_FREE        0x0008 /* don't free the contents? */
37 #define TABLE_NO_HEADERS     0x0010 /* is there actually no header? */
38
39 struct helpfile_table {
40     unsigned int length : 16;
41     unsigned int width : 8;
42     unsigned int flags : 8;
43     const char ***contents;
44 };
45
46 struct helpfile_expansion {
47     enum { HF_STRING, HF_TABLE } type;
48     union {
49         char *str;
50         struct helpfile_table table;
51     } value;
52 };
53
54 typedef struct helpfile_expansion (*expand_func_t)(const char *variable);
55 typedef void (*irc_send_func)(struct userNode *from, const char *to, const char *msg);
56
57 struct helpfile {
58     const char *name;
59     struct dict *db;
60     expand_func_t expand;
61 };
62
63 struct language
64 {
65     char *name;
66     struct language *parent;
67     struct dict *messages; /* const char* -> const char* */
68     struct dict *helpfiles; /* phelpfile->name -> phelpfile */
69 };
70 extern struct language *lang_C;
71 extern struct dict *languages;
72
73 int send_message(struct userNode *dest, struct userNode *src, const char *message, ...);
74 int send_message_type(int msg_type, struct userNode *dest, struct userNode *src, const char *message, ...);
75 int send_target_message(int msg_type, const char *dest, struct userNode *src, const char *format, ...);
76 int send_help(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic);
77 /* size is maximum line width (up to MAX_LINE_SIZE); 0 means figure it out.
78  * irc_send is either irc_privmsg or irc_notice; NULL means figure it out. */
79 void table_send(struct userNode *from, const char *to, unsigned int size, irc_send_func irc_send, struct helpfile_table table);
80
81 #define send_channel_message(CHANNEL, ARGS...) send_target_message(5, (CHANNEL)->name, ARGS)
82 #define send_channel_notice(CHANNEL, ARGS...) send_target_message(4, (CHANNEL)->name, ARGS)
83 #define send_channel_wallchops(CHANNEL, ARGS...) send_target_message(6, (CHANNEL)->name, ARGS)
84
85 struct message_entry
86 {
87     const char *msgid;
88     const char *format;
89 };
90 void message_register_table(const struct message_entry *table);
91 struct language *language_find(const char *name);
92 const char *language_find_message(struct language *lang, const char *msgid);
93 #define handle_find_message(HANDLE, MSGID) language_find_message((HANDLE) ? (HANDLE)->language : lang_C, (MSGID))
94 #define user_find_message(USER, MSGID) language_find_message((USER)->handle_info ? (USER)->handle_info->language : lang_C, (MSGID))
95 void helpfile_finalize(void);
96
97 struct helpfile *open_helpfile(const char *fname, expand_func_t expand);
98 void close_helpfile(struct helpfile *hf);
99
100 #endif