1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
|
/*******************************************************************************
Copyright (c) 1994,1995 William Pemberton (wfp5p@virginia.edu)
The X Consortium, and any party obtaining a copy of these files from
the X Consortium, directly or indirectly, is granted, free of charge, a
full and unrestricted irrevocable, world-wide, paid up, royalty-free,
nonexclusive right and license to deal in this software and
documentation files (the "Software"), including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons who receive
copies from any such party to do so. This license includes without
limitation a license to do the foregoing actions under any patents of
the party supplying this software to the X Consortium.
*******************************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "xbuffy.h"
#define cmpTok(tok,str,tokVal) {if ( strcmp(tok,str) == 0) return(tokVal);}
extern ApplicationData_t data;
static char *tokens[22] = {
"box", "title", "command", "audio", "mailbox", "newsbox", "checkfile", "origmode",
"newmode", "beep", "nobeep", "highlight", "nohighlight", "last", "headertime", "polltime",
"shortname", "longname", "background", "foreground",
#ifdef USE_LED
"led",
#endif
NULL
};
enum TokType
{
UNK_T = 0, BOX_T, TITLE_T, COMMAND_T, AUDIO_T, MAILBOX_T, NEWSBOX_T, CHECKFILE_T,
ORIGMODE_T, NEWMODE_T, BEEP_T, NOBEEP_T, HIGHLIGHT_T, NOHIGHLIGHT_T, LAST_T, HEADER_T, POLL_T,
SHORT_T, LONG_T, BG_T, FG_T
#ifdef USE_LED
, LED_T
#endif
};
typedef enum TokType TokenType;
TokenType token(line, next)
char *line;
char *next;
{
char tok[30];
char *p1;
int x;
p1 = line;
x = 0;
while ((*p1 != '\0') && (isspace(*p1)))
p1++;
while ((*p1 != '\0') && (!isspace(*p1)) && (x < 29))
{
tok[x++] = (isupper(*p1) ? tolower(*p1) : *p1);
p1++;
}
tok[x] = '\0';
while ((*p1 != '\0') && (isspace(*p1)))
p1++;
strcpy(next, p1);
if (NEWstrlen(next))
next[NEWstrlen(next) - 1] = '\0'; /* strip the newline */
for (x = 0; tokens[x] != NULL; x++)
{
if (strcmp(tok, tokens[x]) == 0)
return (x + 1);
}
return (UNK_T);
}
void clearBox(tempBox)
BoxInfo_t *tempBox;
{
if (tempBox->box != NULL)
{
free(tempBox->box);
tempBox->box = NULL;
}
if (tempBox->command != NULL)
{
free(tempBox->command);
tempBox->command = NULL;
}
if (tempBox->audioCmd != NULL)
{
free(tempBox->audioCmd);
tempBox->audioCmd = NULL;
}
if (tempBox->boxTitle != NULL)
{
free(tempBox->boxTitle);
tempBox->boxTitle = NULL;
}
if (tempBox->bgName != NULL)
{
free(tempBox->bgName);
tempBox->bgName = NULL;
}
if (tempBox->fgName != NULL)
{
free(tempBox->fgName);
tempBox->fgName = NULL;
}
tempBox->type = 0;
tempBox->last = 0;
tempBox->headerTime = tempBox->origMode = 0;
tempBox->pollTime = tempBox->headerTime = -1;
#ifdef USE_LED
tempBox->pid = 0;
tempBox->led = -1;
#endif
tempBox->BoxNameType = tempBox->nobeep = tempBox->nohighlight = UNDEF;
}
char *parseTwiddle(str)
char *str;
{
static char retVal[MAX_STRING];
char *ptr, *res;
char *home;
ptr = str;
res = retVal;
while (*ptr != '\0')
{
if (*ptr == '~')
{
home = (char *) getenv("HOME");
strcpy(res, home);
res += NEWstrlen(home);
}
else
*(res++) = *ptr;
++ptr;
}
*res = '\0';
return (retVal);
}
char *parseEnv(str)
char *str;
{
static char retVal[MAX_STRING];
char envStr[MAX_STRING];
char *ptr,*res;
char *envValue,*envPtr;
ptr = str;
envPtr = envStr;
res = retVal;
while (*ptr != '\0')
{
if (*ptr == '{')
{
ptr++;
while ( (*ptr != '\0') && (*ptr != '}') )
{
*envPtr = *ptr;
ptr++;
envPtr++;
}
if (*ptr == '}')
ptr++;
*envPtr = '\0';
envValue = (char *)getenv(envStr);
strcpy(res,envValue);
res+=NEWstrlen(envValue);
}
else
{
*(res++) = *ptr;
++ptr;
}
}
*res = '\0';
return(retVal);
}
#ifdef TESTBOX
char *showNull(w)
char *w;
{
if (w == NULL)
return ("NULL");
else
return (w);
}
void dumpBox(tempBox)
BoxInfo_t tempBox;
{
printf("Dumping Box = *%s*\n", tempBox.box);
printf("type = %i\n", tempBox.type);
printf("command = *%s*\n", showNull(tempBox.command));
printf("audio = *%s*\n", showNull(tempBox.audioCmd));
printf("boxTitle = *%s*\n", showNull(tempBox.boxTitle));
printf("pollTime = %i headerTime = %i\n", tempBox.pollTime, tempBox.headerTime);
printf("nobeep = %i nohighlight = %i origMode = %i \n", tempBox.nobeep, tmpBox.nohighlight, tempBox.origMode);
printf("nametype = %i\n\n", tempBox.BoxNameType);
}
#endif
void readBoxfile(const char *boxFile)
{
BoxInfo_t tempBox;
FILE *boxes;
char line[MAX_STRING];
int inBox;
char next[MAX_STRING];
tempBox.bgName = tempBox.fgName = tempBox.box = tempBox.command = tempBox.audioCmd = tempBox.boxTitle = NULL;
#ifdef USE_LED
tempBox.led = -1;
#endif
clearBox(&tempBox);
if ((boxes = fopen(boxFile, "r")) == 0)
{
if( boxFile == data.boxFile || errno != ENOENT )
fprintf(stderr, "Could not open boxfile %s\n", boxFile);
return;
}
inBox = 0;
while (fgets(line, MAX_STRING - 2, boxes) != 0)
{
line[MAX_STRING - 1] = '\0'; /* just in case */
if (line[0] == '#') /* it's a comment */
continue;
switch (token(line, next))
{
case BOX_T:
if (inBox)
{
#ifndef TESTBOX
initBox(tempBox.box,
tempBox.type, tempBox.pollTime,
tempBox.headerTime, tempBox.BoxNameType,
tempBox.command,
tempBox.audioCmd,
tempBox.boxTitle,
tempBox.origMode,
tempBox.nobeep,
tempBox.nohighlight,
tempBox.bgName,
tempBox.fgName
# ifdef USE_LED
, tempBox.led
# endif
);
#else
dumpBox(tempBox);
#endif
clearBox(&tempBox);
}
tempBox.box = (char *) strdup(parseTwiddle(parseEnv(next)));
inBox = TRUE;
break;
case TITLE_T:
tempBox.boxTitle = (char *) strdup(next);
tempBox.BoxNameType = USR;
break;
case COMMAND_T:
tempBox.command = (char *) strdup(next);
break;
case AUDIO_T:
tempBox.audioCmd = (char *) strdup(next);
break;
case MAILBOX_T:
tempBox.type = MAILBOX;
break;
case NEWSBOX_T:
tempBox.type = NNTPBOX;
break;
case CHECKFILE_T:
tempBox.type = CHECKFILE;
break;
case ORIGMODE_T:
tempBox.origMode = TRUE;
break;
case NEWMODE_T:
tempBox.origMode = FALSE;
break;
case BEEP_T:
tempBox.nobeep = FALSE;
break;
case NOBEEP_T:
tempBox.nobeep = TRUE;
break;
case HIGHLIGHT_T:
tempBox.nohighlight = FALSE;
break;
case NOHIGHLIGHT_T:
tempBox.nohighlight = TRUE;
break;
case LAST_T:
tempBox.last = atoi(next);
break;
case HEADER_T:
tempBox.headerTime = atoi(next);
break;
case POLL_T:
tempBox.pollTime = atoi(next);
break;
case SHORT_T:
tempBox.BoxNameType = SHORT;
break;
case LONG_T:
tempBox.BoxNameType = LONG;
break;
case BG_T:
tempBox.bgName = (char *) strdup(next);
break;
case FG_T:
tempBox.fgName = (char *) strdup(next);
break;
#ifdef USE_LED
case LED_T:
tempBox.led = atoi(next);
break;
#endif
default:
break;
}
} /* while */
if (inBox)
#ifndef TESTBOX
initBox(tempBox.box,
tempBox.type, tempBox.pollTime,
tempBox.headerTime, tempBox.BoxNameType,
tempBox.command,
tempBox.audioCmd,
tempBox.boxTitle,
tempBox.origMode,
tempBox.nobeep,
tempBox.nohighlight,
tempBox.bgName,
tempBox.fgName
# ifdef USE_LED
, tempBox.led
# endif
);
#else
dumpBox(tempBox);
#endif
fclose(boxes);
}
#ifdef TESTBOX
main()
{
readBoxfile("boxfile.sample");
}
#endif
|