File: wnmap.c

package info (click to toggle)
libwn6 6.0-12
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,004 kB
  • ctags: 3,903
  • sloc: ansic: 45,078; makefile: 958; csh: 274; sh: 26
file content (125 lines) | stat: -rw-r--r-- 1,861 bytes parent folder | download | duplicates (4)
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
/*************************************************************************

  wn_load_map_array(map_array,from,to)

  wn_strmap(s,map_array)
  wn_memmap(mem,len,map_array)

  wn_strcharmap(s,from_c,to_c)

*************************************************************************/
/****************************************************************************

COPYRIGHT NOTICE:

  The source code in this file is provided free of charge
  to the author's consulting clients.  It is in the
  public domain and therefore may be used by anybody for
  any purpose.

AUTHOR:

  Will Naylor

****************************************************************************/
#include "wnlib.h"
#include "wnasrt.h"

#include "wnmap.h"



#define MASK  (255)    /* make char positive */



void wn_strcharmap(register char *s,register char from_c,register char to_c)
{
  register int c;

  for(;;)
  {
    c = *s;

    if(c == '\0')
    {
      break;
    }
    else if(c == from_c)
    {
      *s = to_c;
    }

    ++s;
  }
}


void wn_strmap(register char *s,register char map_array[256])
{
  register char c;

  for(;;)
  {
    c = *s;

    if(c == '\0')
    {
      break;
    }

    *s = map_array[c&MASK]; 

    ++s;
  }
}


void wn_memmap(register char *string,int len,register char map_array[256])
{
  register char *fin;

  fin = string+len;

  for(;string != fin;++string)
  {
    *string = map_array[(*string)&MASK];
  }
}


local void identity_map_array(register char map_array[256])
{
  register int c;

  for(c=0;c<256;++c)
  {
    map_array[c] = (char)c;
  }
}


void wn_load_map_array(register char map_array[256],
		       register char *from,register char *to)
{
  identity_map_array(map_array);

  for(;;)
  {
    if(*from == '\0')
    {
      wn_assert(*to == '\0');

      break;
    }

    map_array[(*from)&MASK] = *to;

    ++from;  ++to;
  }
}