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
|
/*
* readflo.c -- Filename translation in ?lo-files
*
* readflo.c is a part of binkd project
*
* Copyright (C) 1997 Dima Maloff, 5047/13
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. See COPYING.
*/
/*
* $Id: readflo.c,v 2.1 2002/11/12 17:27:46 gul Exp $
*
* $Log: readflo.c,v $
* Revision 2.1 2002/11/12 17:27:46 gul
* Ignore empty (\r\n) line in lo-files
*
* Revision 2.0 2001/01/10 12:12:39 gul
* Binkd is under CVS again
*
* Revision 1.1 1997/03/28 06:20:30 mff
* Initial revision
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "Config.h"
#include "readflo.h"
#include "assert.h"
RF_RULE *rf_rules = 0;
/*
* Reads a line from a flo to dst[MAXPATHLEN], sets action
* 1 -- ok
* 0 -- EOF
*/
int read_flo_line (char *dst, int *action, FILE *flo)
{
char buf[MAXPATHLEN + 1];
int i;
while (1)
{
if (!fgets (buf, MAXPATHLEN, flo))
return 0;
for (i = strlen (buf) - 1; i >= 0 && isspace (buf[i]); --i)
buf[i] = 0;
switch (*buf)
{
case 0:
case '~':
continue;
case '^':
*action = 'd';
strcpy (dst, buf + 1);
break;
case '#':
*action = 't';
strcpy (dst, buf + 1);
break;
default:
*action = 0;
strcpy (dst, buf);
break;
}
break;
}
return 1;
}
/*
* Translates a flo line using rf_rules.
* Returns 0 if no rf_rules defined, otherwise returned value
* should be free()'d
*/
char *trans_flo_line (char *s)
{
RF_RULE *curr;
char buf[MAXPATHLEN + 1];
if (rf_rules)
{
char *w;
strnzcpy (buf, s, MAXPATHLEN);
for (curr = rf_rules; curr; curr = curr->next)
{
w = ed (buf, curr->from, curr->to, NULL);
strnzcpy (buf, w, MAXPATHLEN);
free (w);
}
return xstrdup (buf);
}
else
return 0;
}
/*
* Add a translation rule for trans_flo_line ()
* (From and to are saved as pointers!)
*/
void rf_rule_add (char *from, char *to)
{
static RF_RULE *last_rule = 0;
RF_RULE *new_rule = xalloc (sizeof (RF_RULE));
memset (new_rule, 0, sizeof (RF_RULE));
new_rule->from = from;
new_rule->to = to;
if (last_rule)
last_rule->next = new_rule;
else
rf_rules = new_rule;
last_rule = new_rule;
}
|