~ubuntu-branches/ubuntu/utopic/binkd/utopic-proposed

« back to all changes in this revision

Viewing changes to readflo.c

  • Committer: Bazaar Package Importer
  • Author(s): Marco d'Itri
  • Date: 2002-03-24 22:52:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020324225225-7ru6itlapn03nl35
Tags: upstream-0.9.5a
ImportĀ upstreamĀ versionĀ 0.9.5a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  readflo.c -- Filename translation in ?lo-files
 
3
 *
 
4
 *  readflo.c is a part of binkd project
 
5
 *
 
6
 *  Copyright (C) 1997  Dima Maloff, 5047/13
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version. See COPYING.
 
12
 */
 
13
 
 
14
/*
 
15
 * $Id: readflo.c,v 2.0 2001/01/10 12:12:39 gul Exp $
 
16
 *
 
17
 * $Log: readflo.c,v $
 
18
 * Revision 2.0  2001/01/10 12:12:39  gul
 
19
 * Binkd is under CVS again
 
20
 *
 
21
 * Revision 1.1  1997/03/28  06:20:30  mff
 
22
 * Initial revision
 
23
 *
 
24
 */
 
25
 
 
26
#include <stdio.h>
 
27
#include <string.h>
 
28
#include <stdlib.h>
 
29
#include <ctype.h>
 
30
 
 
31
#include "Config.h"
 
32
#include "readflo.h"
 
33
#include "assert.h"
 
34
 
 
35
RF_RULE *rf_rules = 0;
 
36
 
 
37
/*
 
38
 * Reads a line from a flo to dst[MAXPATHLEN], sets action
 
39
 * 1 -- ok
 
40
 * 0 -- EOF
 
41
 */
 
42
int read_flo_line (char *dst, int *action, FILE *flo)
 
43
{
 
44
  char buf[MAXPATHLEN + 1];
 
45
  int i;
 
46
 
 
47
  while (1)
 
48
  {
 
49
    if (!fgets (buf, MAXPATHLEN, flo))
 
50
      return 0;
 
51
 
 
52
    for (i = strlen (buf) - 1; i > 0 && isspace (buf[i]); --i)
 
53
      buf[i] = 0;
 
54
 
 
55
    switch (*buf)
 
56
      {
 
57
        case 0:
 
58
        case '~':
 
59
          continue;
 
60
        case '^':
 
61
          *action = 'd';
 
62
          strcpy (dst, buf + 1);
 
63
          break;
 
64
        case '#':
 
65
          *action = 't';
 
66
          strcpy (dst, buf + 1);
 
67
          break;
 
68
        default:
 
69
          *action = 0;
 
70
          strcpy (dst, buf);
 
71
          break;
 
72
      }
 
73
    break;
 
74
  }
 
75
  return 1;
 
76
}
 
77
 
 
78
/*
 
79
 * Translates a flo line using rf_rules.
 
80
 * Returns 0 if no rf_rules defined, otherwise returned value
 
81
 * should be free()'d
 
82
 */
 
83
char *trans_flo_line (char *s)
 
84
{
 
85
  RF_RULE *curr;
 
86
  char buf[MAXPATHLEN + 1];
 
87
 
 
88
  if (rf_rules)
 
89
  {
 
90
    char *w;
 
91
 
 
92
    strnzcpy (buf, s, MAXPATHLEN);
 
93
    for (curr = rf_rules; curr; curr = curr->next)
 
94
    {
 
95
      w = ed (buf, curr->from, curr->to, NULL);
 
96
      strnzcpy (buf, w, MAXPATHLEN);
 
97
      free (w);
 
98
    }
 
99
    return xstrdup (buf);
 
100
  }
 
101
  else
 
102
    return 0;
 
103
}
 
104
 
 
105
/*
 
106
 * Add a translation rule for trans_flo_line ()
 
107
 * (From and to are saved as pointers!)
 
108
 */
 
109
void rf_rule_add (char *from, char *to)
 
110
{
 
111
  static RF_RULE *last_rule = 0;
 
112
  RF_RULE *new_rule = xalloc (sizeof (RF_RULE));
 
113
 
 
114
  memset (new_rule, 0, sizeof (RF_RULE));
 
115
  new_rule->from = from;
 
116
  new_rule->to = to;
 
117
  if (last_rule)
 
118
    last_rule->next = new_rule;
 
119
  else
 
120
    rf_rules = new_rule;
 
121
  last_rule = new_rule;
 
122
}