]>
Commit | Line | Data |
---|---|---|
1 | /* helpfile.h - Help file loading and display | |
2 | * Copyright 2000-2004 srvx Development Team | |
3 | * | |
4 | * This file is part of srvx. | |
5 | * | |
6 | * srvx 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 | |
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 | ||
41 | struct helpfile_table { | |
42 | unsigned int length : 16; | |
43 | unsigned int width : 8; | |
44 | unsigned int flags : 8; | |
45 | const char ***contents; | |
46 | }; | |
47 | ||
48 | struct helpfile_expansion { | |
49 | enum { HF_STRING, HF_TABLE } type; | |
50 | union { | |
51 | char *str; | |
52 | struct helpfile_table table; | |
53 | } value; | |
54 | }; | |
55 | ||
56 | typedef struct helpfile_expansion (*expand_func_t)(const char *variable); | |
57 | typedef void (*irc_send_func)(struct userNode *from, const char *to, const char *msg); | |
58 | ||
59 | struct helpfile { | |
60 | const char *name; | |
61 | struct dict *db; | |
62 | expand_func_t expand; | |
63 | }; | |
64 | ||
65 | struct language | |
66 | { | |
67 | char *name; | |
68 | struct language *parent; | |
69 | struct dict *messages; /* const char* -> const char* */ | |
70 | struct dict *helpfiles; /* phelpfile->name -> phelpfile */ | |
71 | }; | |
72 | extern struct language *lang_C; | |
73 | extern struct dict *languages; | |
74 | ||
75 | #define MSG_TYPE_NOTICE 0 | |
76 | #define MSG_TYPE_PRIVMSG 1 | |
77 | #define MSG_TYPE_WALLCHOPS 2 | |
78 | #define MSG_TYPE_NOXLATE 4 | |
79 | #define MSG_TYPE_MULTILINE 8 | |
80 | ||
81 | int send_message(struct userNode *dest, struct userNode *src, const char *message, ...); | |
82 | int send_message_type(int msg_type, struct userNode *dest, struct userNode *src, const char *message, ...); | |
83 | int send_target_message(int msg_type, const char *dest, struct userNode *src, const char *format, ...); | |
84 | int send_help(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic); | |
85 | /* size is maximum line width (up to MAX_LINE_SIZE); 0 means figure it out. | |
86 | * irc_send is either irc_privmsg or irc_notice; NULL means figure it out. */ | |
87 | void table_send(struct userNode *from, const char *to, unsigned int size, irc_send_func irc_send, struct helpfile_table table); | |
88 | ||
89 | #define send_channel_message(CHANNEL, ARGS...) send_target_message(5, (CHANNEL)->name, ARGS) | |
90 | #define send_channel_notice(CHANNEL, ARGS...) send_target_message(4, (CHANNEL)->name, ARGS) | |
91 | #define send_channel_wallchops(CHANNEL, ARGS...) send_target_message(6, (CHANNEL)->name, ARGS) | |
92 | ||
93 | struct message_entry | |
94 | { | |
95 | const char *msgid; | |
96 | const char *format; | |
97 | }; | |
98 | void message_register_table(const struct message_entry *table); | |
99 | struct language *language_find(const char *name); | |
100 | const char *language_find_message(struct language *lang, const char *msgid); | |
101 | #define handle_find_message(HANDLE, MSGID) language_find_message((HANDLE) ? (HANDLE)->language : lang_C, (MSGID)) | |
102 | #define user_find_message(USER, MSGID) language_find_message((USER)->handle_info ? (USER)->handle_info->language : lang_C, (MSGID)) | |
103 | void helpfile_init(void); | |
104 | void helpfile_finalize(void); | |
105 | ||
106 | struct helpfile *open_helpfile(const char *fname, expand_func_t expand); | |
107 | void close_helpfile(struct helpfile *hf); | |
108 | ||
109 | #endif |