]> jfr.im git - irc/evilnet/x3.git/blob - src/helpfile.h
Couple of srvx updates.
[irc/evilnet/x3.git] / src / helpfile.h
1 /* helpfile.h - Help file loading and display
2 * Copyright 2000-2004 srvx Development Team
3 *
4 * This file is part of x3.
5 *
6 * x3 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 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
21 #if !defined(HELPFILE_H)
22 #define HELPFILE_H
23
24 #include "common.h"
25
26 struct userNode;
27 struct handle_info;
28 struct string_list;
29
30 extern struct userNode *message_dest; /* message destination; useful in expansion callbacks */
31
32 #define MIN_LINE_SIZE 40
33 #define MAX_LINE_SIZE 450
34
35 #define TABLE_REPEAT_HEADERS 0x0001 /* repeat the headers for each columnset? */
36 #define TABLE_PAD_LEFT 0x0002 /* pad cells on the left? */
37 #define TABLE_REPEAT_ROWS 0x0004 /* put more than one row on a line? */
38 #define TABLE_NO_FREE 0x0008 /* don't free the contents? */
39 #define TABLE_NO_HEADERS 0x0010 /* is there actually no header? */
40 #define TABLE_NO_FOOTER 0x0020 /* Dont send a -----End---- footer */
41
42 struct helpfile_table {
43 unsigned int length : 16;
44 unsigned int width : 8;
45 unsigned int flags : 8;
46 const char ***contents;
47 };
48
49 struct helpfile_expansion {
50 enum { HF_STRING, HF_TABLE } type;
51 union {
52 char *str;
53 struct helpfile_table table;
54 } value;
55 };
56
57 typedef struct helpfile_expansion (*expand_func_t)(const char *variable);
58 typedef void (*irc_send_func)(struct userNode *from, const char *to, const char *msg);
59
60 struct helpfile {
61 const char *name;
62 struct dict *db;
63 expand_func_t expand;
64 };
65
66 struct language
67 {
68 char *name;
69 struct language *parent;
70 struct dict *messages; /* const char* -> const char* */
71 struct dict *helpfiles; /* phelpfile->name -> phelpfile */
72 };
73 extern struct language *lang_C;
74 extern struct dict *languages;
75
76 #define MSG_TYPE_NOTICE 0
77 #define MSG_TYPE_PRIVMSG 1
78 #define MSG_TYPE_WALLCHOPS 2
79 #define MSG_TYPE_NOXLATE 4
80 #define MSG_TYPE_MULTILINE 8
81
82 int send_message(struct userNode *dest, struct userNode *src, const char *message, ...);
83 int send_message_type(int msg_type, struct userNode *dest, struct userNode *src, const char *message, ...);
84 int send_target_message(int msg_type, const char *dest, struct userNode *src, const char *format, ...);
85 int send_help(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic);
86 int send_help_brief(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic);
87 /* size is maximum line width (up to MAX_LINE_SIZE); 0 means figure it out.
88 * irc_send is either irc_privmsg or irc_notice; NULL means figure it out. */
89 void table_send(struct userNode *from, const char *to, unsigned int size, irc_send_func irc_send, struct helpfile_table table);
90
91 #if defined(GCC_VARMACROS)
92 # define send_channel_message(CHANNEL, ARGS...) send_target_message(5, (CHANNEL)->name, ARGS)
93 # define send_channel_notice(CHANNEL, ARGS...) send_target_message(4, (CHANNEL)->name, ARGS)
94 # define send_channel_wallchops(CHANNEL, ARGS...) send_target_message(6, (CHANNEL)->name, ARGS)
95 #elif defined(C99_VARMACROS)
96 # define send_channel_message(CHANNEL, ...) send_target_message(5, (CHANNEL)->name, __VA_ARGS__)
97 # define send_channel_notice(CHANNEL, ...) send_target_message(4, (CHANNEL)->name, __VA_ARGS__)
98 # define send_channel_wallchops(CHANNEL, ...) send_target_message(6, (CHANNEL)->name, __VA_ARGS__)
99 #endif
100
101 struct message_entry
102 {
103 const char *msgid;
104 const char *format;
105 };
106 void message_register_table(const struct message_entry *table);
107 struct language *language_find(const char *name);
108 const char *language_find_message(struct language *lang, const char *msgid);
109 #define handle_find_message(HANDLE, MSGID) language_find_message((HANDLE) ? (HANDLE)->language : lang_C, (MSGID))
110 #define user_find_message(USER, MSGID) language_find_message((USER)->handle_info ? (USER)->handle_info->language : lang_C, (MSGID))
111 void helpfile_init(void);
112 void helpfile_finalize(void);
113
114 struct helpfile *open_helpfile(const char *fname, expand_func_t expand);
115 void close_helpfile(struct helpfile *hf);
116
117 #ifdef HAVE_HELPSERV
118 const char *get_helpserv_id(const char *nick, struct userNode *user);
119 #endif
120
121 #endif