File indexing completed on 2024-12-08 09:47:15
0001 /*************************************************************************** 0002 * Copyright (C) 2004 by Tomas Mecir * 0003 * kmuddy@kmuddy.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU Library General Public License as * 0007 * published by the Free Software Foundation; either version 2 of the * 0008 * License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU Library General Public License for more details. * 0014 ***************************************************************************/ 0015 0016 #include <libmxp/libmxp.h> 0017 0018 #include <stdio.h> 0019 #include <string.h> 0020 0021 void displayResult (mxpResult *res) 0022 { 0023 switch (res->type) 0024 { 0025 case 0: { 0026 printf ("Nothing.\n"); 0027 } 0028 break; 0029 case 1: { 0030 char *s = (char *) res->data; 0031 if (s && (strcmp (s, "\r\n") == 0)) //newlines are always sent separately 0032 printf ("Newline.\n"); 0033 else 0034 printf ("Text: %s\n", s?s:""); 0035 } 0036 break; 0037 case 2: { 0038 int *t = (int *) res->data; 0039 printf ("Line tag: %d\n", *t); 0040 } 0041 break; 0042 case 3: { 0043 flagStruct *fs = (flagStruct *) res->data; 0044 char *s = fs->name; 0045 if (fs->begin) 0046 printf ("Start of flag: %s\n", s?s:""); 0047 else 0048 printf ("End of flag: %s\n", s?s:""); 0049 } 0050 break; 0051 case 4: { 0052 varStruct *vs = (varStruct *) res->data; 0053 char *n = vs->name; 0054 char *v = vs->value; 0055 if (vs->erase) 0056 printf ("Erase variable: %s\n", n?n:""); 0057 else 0058 printf ("Variable: %s, value: %s\n", n?n:"", v?v:""); 0059 } 0060 break; 0061 case 5: { 0062 formatStruct *fs = (formatStruct *) res->data; 0063 unsigned char mask = fs->usemask; 0064 if (mask & USE_BOLD) 0065 printf ("Formatting: %s\n", 0066 (fs->attributes & Bold) ? "bold" : "not bold"); 0067 if (mask & USE_ITALICS) 0068 printf ("Formatting: %s\n", 0069 (fs->attributes & Italic) ? "italics" : "not italics"); 0070 if (mask & USE_UNDERLINE) 0071 printf ("Formatting: %s\n", 0072 (fs->attributes & Underline) ? "underline" : "not underline"); 0073 if (mask & USE_STRIKEOUT) 0074 printf ("Formatting: %s\n", 0075 (fs->attributes & Strikeout) ? "strikeout" : "not strikeout"); 0076 if (mask & USE_FG) 0077 printf ("Formatting: foreground color (%d, %d, %d)\n", fs->fg.r, fs->fg.g, fs->fg.b); 0078 if (mask & USE_BG) 0079 printf ("Formatting: background color (%d, %d, %d)\n", fs->bg.r, fs->bg.g, fs->bg.b); 0080 if (mask & USE_FONT) 0081 printf ("Formatting: font %s\n", fs->font?fs->font:""); 0082 if (mask & USE_SIZE) 0083 printf ("Formatting: size %d\n", fs->size); 0084 } 0085 break; 0086 case 6: { 0087 linkStruct *ls = (linkStruct *) res->data; 0088 printf ("URL link: name %s, URL %s, text %s, hint %s\n", 0089 ls->name?ls->name:"", ls->url?ls->url:"", ls->text?ls->text:"", ls->hint?ls->hint:""); 0090 } 0091 break; 0092 case 7: { 0093 sendStruct *ss = (sendStruct *) res->data; 0094 printf ("Send link: name %s, command %s, text %s, hint %s, to prompt: %s, menu: %s\n", 0095 ss->name?ss->name:"", ss->command?ss->command:"", ss->text?ss->text:"", 0096 ss->hint?ss->hint:"", ss->toprompt?"yes":"no", ss->ismenu?"yes":"no"); 0097 } 0098 break; 0099 case 8: { 0100 char *s = (char *) res->data; 0101 printf ("Expire: %s\n", s?s:""); 0102 } 0103 break; 0104 case 9: { 0105 char *s = (char *) res->data; 0106 printf ("Send this: %s\n", s?s:""); 0107 } 0108 break; 0109 case 10: { 0110 printf ("Horizontal line\n"); 0111 } 0112 break; 0113 case 11: { 0114 soundStruct *ss = (soundStruct *) res->data; 0115 if (ss->isSOUND) 0116 printf ("Sound: file %s, URL %s, volume %d, %d repeats, priority %d, type %s\n", 0117 ss->fname?ss->fname:"", ss->url?ss->url:"", ss->vol, ss->repeats, ss->priority, 0118 ss->type?ss->type:""); 0119 else 0120 printf ("Music: file %s, URL %s, volume %d, %d repeats, continue %s, type %s\n", 0121 ss->fname?ss->fname:"", ss->url?ss->url:"", ss->vol, ss->repeats, 0122 ss->continuemusic?"yes":"no", ss->type?ss->type:""); 0123 } 0124 break; 0125 case 12: { 0126 windowStruct *ws = (windowStruct *) res->data; 0127 printf ("Create window: name %s, title %s, left %d, top %d, width %d, height %d, scrolling %s, floating %s\n", 0128 ws->name?ws->name:"", ws->title?ws->title:"", ws->left, ws->top, ws->width, ws->height, 0129 ws->scrolling?"yes":"no", ws->floating?"yes":"no"); 0130 } 0131 break; 0132 case 13: { 0133 internalWindowStruct *ws = (internalWindowStruct *) res->data; 0134 char *s = 0; 0135 switch (ws->align) { 0136 case Left: s = "left"; break; 0137 case Right: s = "right"; break; 0138 case Bottom: s = "bottom"; break; 0139 case Top: s = "top"; break; 0140 case Middle: s = "middle (invalid!)"; break; 0141 }; 0142 printf ("Create internal window: name %s, title %s, align %s, scrolling %s\n", 0143 ws->name?ws->name:"", ws->title?ws->title:"", s, ws->scrolling?"yes":"no"); 0144 } 0145 break; 0146 case 14: { 0147 char *s = (char *) res->data; 0148 printf ("Close window: %s\n", s?s:""); 0149 } 0150 break; 0151 case 15: { 0152 char *s = (char *) res->data; 0153 printf ("Set active window: %s\n", s?s:""); 0154 } 0155 break; 0156 case 16: { 0157 moveStruct *ms = (moveStruct *) res->data; 0158 printf ("Move cursor: X=%d, Y=%d\n", ms->x, ms->y); 0159 } 0160 break; 0161 case 17: { 0162 printf ("Erase text: %s\n", res->data ? "rest of frame" : "rest of line"); 0163 } 0164 break; 0165 case 18: { 0166 relocateStruct *rs = (relocateStruct *) res->data; 0167 printf ("Relocate: server %s, port %d\n", rs->server, rs->port); 0168 } 0169 break; 0170 case 19: { 0171 printf (res->data ? "Send username\n" : "Send password\n"); 0172 } 0173 break; 0174 case 20: { 0175 imageStruct *is = (imageStruct *) res->data; 0176 char *s = 0; 0177 switch (is->align) { 0178 case Left: s = "left"; break; 0179 case Right: s = "right"; break; 0180 case Bottom: s = "bottom"; break; 0181 case Top: s = "top"; break; 0182 case Middle: s = "middle"; break; 0183 }; 0184 printf ("Image: name %s, URL %s, type %s, height %d, width %d, hspace %d, vspace %d, align %s\n", 0185 is->fname?is->fname:"", is->url?is->url:"", is->type?is->type:"", is->height, 0186 is->width, is->hspace, is->vspace, s); 0187 } 0188 break; 0189 case 21: { 0190 char *s = (char *) res->data; 0191 printf ("Image map: %s\n", s?s:""); 0192 } 0193 break; 0194 case 22: { 0195 gaugeStruct *gs = (gaugeStruct *) res->data; 0196 printf ("Gauge: variable %s, max.variable %s, caption %s, color (%d, %d, %d)\n", 0197 gs->variable?gs->variable:"", gs->maxvariable?gs->maxvariable:"", 0198 gs->caption?gs->caption:"", gs->color.r, gs->color.g, gs->color.b); 0199 } 0200 break; 0201 case 23: { 0202 statStruct *ss = (statStruct *) res->data; 0203 printf ("Status bar: variable %s, max.variable %s, caption %s\n", 0204 ss->variable?ss->variable:"", ss->maxvariable?ss->maxvariable:"", 0205 ss->caption?ss->caption:""); 0206 } 0207 break; 0208 case -1: { 0209 char *s = (char *) res->data; 0210 printf ("Error: %s\n", s?s:""); 0211 } 0212 break; 0213 case -2: { 0214 char *s = (char *) res->data; 0215 printf ("Warning: %s\n", s?s:""); 0216 } 0217 break; 0218 } 0219 } 0220 0221 int main () 0222 { 0223 RGB white = {255, 255, 255}; 0224 RGB black = {0, 0, 0}; 0225 RGB yellow = {255, 255, 0}; 0226 0227 //create MXP handler 0228 MXPHANDLER h = mxpCreateHandler (); 0229 0230 //initialize the MXP handler 0231 mxpSetDefaultText (h, "fixed", 12, false, false, false, false, white, black); 0232 mxpSetHeaderParams (h, 1, "fixed", 28, true, true, true, false, yellow, black); 0233 mxpSetHeaderParams (h, 2, "fixed", 24, true, true, true, false, yellow, black); 0234 mxpSetHeaderParams (h, 3, "fixed", 20, true, true, true, false, yellow, black); 0235 mxpSetHeaderParams (h, 4, "fixed", 16, true, true, false, false, yellow, black); 0236 mxpSetHeaderParams (h, 5, "fixed", 14, true, true, false, false, yellow, black); 0237 mxpSetHeaderParams (h, 6, "fixed", 12, true, true, false, false, yellow, black); 0238 mxpSetDefaultGaugeColor (h, white); 0239 mxpSetNonProportFont (h, "fixed"); 0240 mxpSetClient (h, "KMuddy", "0.7"); 0241 0242 //feed the library with text 0243 mxpProcessText (h, "\e[1z"); 0244 mxpProcessText (h, "<!ELEMENT hp FLAG=\"Set hp\"><Hp>45</hP>"); 0245 mxpProcessText (h, "<!ELEMENT Item '<send href=\"buy &text;\">'><Item>bread</Item><Item>water</item>\r\n"); 0246 mxpProcessText (h, "\e[1z<a></a><a>brb</a>"); 0247 0248 mxpProcessText (h, "<!ELEMENT exit \"<send &exitdir; hint=&exithint; expire=ROOM>\" ATT=\"exitdir=&text; exithint=&text;\">"); 0249 mxpProcessText (h, "<exit exitdir=\"!Turm\" exithint=\": In den Turm|: In den Turm (!Turm)\">Turm</exit>"); 0250 mxpProcessText (h, "<send 'blah' hint='bla bla bla'>some text</send> "); 0251 //display results 0252 while (mxpHasResults (h)) 0253 { 0254 mxpResult *res = mxpNextResult (h); 0255 displayResult (res); 0256 } 0257 0258 //free memory 0259 mxpDestroyHandler (h); 0260 }