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
|
/*************************************************************************
wn_load_map_array(map_array,from,to)
wn_strmap(s,map_array)
wn_blkmap(blk,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 <ctype.h>
#include "wnlib.h"
#define MASK (255) /* make char positive */
wn_strcharmap(s,from_c,to_c)
register char *s;
register char from_c,to_c;
{
register int c;
while(TRUE)
{
c = *s;
if(c == '\0')
{
break;
}
else if(c == from_c)
{
*s = to_c;
}
++s;
}
}
wn_strmap(s,map_array)
register char *s;
register char map_array[256];
{
register char c;
while(TRUE)
{
c = *s;
if(c == '\0')
{
break;
}
*s = map_array[c&MASK];
++s;
}
}
wn_blkmap(string,len,map_array)
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];
}
}
wn_load_map_array(map_array,from,to)
register char map_array[256],*from,*to;
{
identity_map_array(map_array);
while(TRUE)
{
if(*from == '\0')
{
wn_assert(*to == '\0');
break;
}
map_array[(*from)&MASK] = *to;
++from; ++to;
}
}
local identity_map_array(map_array)
register char map_array[256];
{
register int c;
for(c=0;c<256;++c)
{
map_array[c] = c;
}
}
|