4 typedef char pstring[1024];
9 /****************************************************************************
10 line strncpy but always null terminates. Make sure there is room!
11 ****************************************************************************/
12 char *StrnCpy(char *dest,char *src,int n)
15 while (n-- && (*d++ = *src++)) ;
20 /*******************************************************************
21 convert a string to upper case
22 ********************************************************************/
23 void strupper(char *s)
28 if (is_shift_jis (*s)) {
30 } else if (is_kana (*s)) {
46 static char *map_filename(char *s, /* This is null terminated */
47 char *pattern, /* This isn't. */
48 int len) /* This is the length of pattern. */
50 static pstring matching_bit; /* The bit of the string which matches */
51 /* a * in pattern if indeed there is a * */
52 char *sp; /* Pointer into s. */
53 char *pp; /* Pointer into p. */
54 char *match_start; /* Where the matching bit starts. */
57 StrnCpy(pat, pattern, len); /* Get pattern into a proper string! */
58 strcpy(matching_bit,""); /* Match but no star gets this. */
59 pp = pat; /* Initialise the pointers. */
61 if ((len == 1) && (*pattern == '*')) {
62 return NULL; /* Impossible, too ambiguous for */
66 while ((*sp) /* Not the end of the string. */
67 && (*pp) /* Not the end of the pattern. */
68 && (*sp == *pp) /* The two match. */
69 && (*pp != '*')) { /* No wildcard. */
70 sp++; /* Keep looking. */
73 if (!*sp && !*pp) /* End of pattern. */
74 return matching_bit; /* Simple match. Return empty string. */
76 pp++; /* Always interrested in the chacter */
78 if (!*pp) { /* It is at the end of the pattern. */
79 StrnCpy(matching_bit, s, sp-s);
82 /* The next character in pattern must match a character further */
83 /* along s than sp so look for that character. */
85 while ((*sp) /* Not the end of s. */
86 && (*sp != *pp)) /* Not the same */
87 sp++; /* Keep looking. */
88 if (!*sp) { /* Got to the end without a match. */
90 } else { /* Still hope for a match. */
91 /* Now sp should point to a matching character. */
92 StrnCpy(matching_bit, match_start, sp-match_start);
93 /* Back to needing a stright match again. */
94 while ((*sp) /* Not the end of the string. */
95 && (*pp) /* Not the end of the pattern. */
96 && (*sp == *pp)) { /* The two match. */
97 sp++; /* Keep looking. */
100 if (!*sp && !*pp) /* Both at end so it matched */
107 return NULL; /* No match. */
111 static void do_fwd_mangled_map(char *s, char *MangledMap)
113 /* MangledMap is a series of name pairs in () separated by spaces.
114 * If s matches the first of the pair then the name given is the
115 * second of the pair. A * means any number of any character and if
116 * present in the second of the pair as well as the first the
117 * matching part of the first string takes the place of the * in the
120 * I wanted this so that we could have RCS files which can be used
121 * by UNIX and DOS programs. My mapping string is (RCS rcs) which
122 * converts the UNIX RCS file subdirectory to lowercase thus
123 * preventing mangling.
125 char *start=MangledMap; /* Use this to search for mappings. */
126 char *end; /* Used to find the end of strings. */
128 pstring new_string; /* Make up the result here. */
129 char *np; /* Points into new_string. */
131 DEBUG(5,("Mangled Mapping '%s' map '%s'\n", s, MangledMap));
133 while ((*start) && (*start != '('))
135 start++; /* Skip the ( */
137 continue; /* Always check for the end. */
138 end = start; /* Search for the ' ' or a ')' */
139 DEBUG(5,("Start of first in pair '%s'\n", start));
140 while ((*end) && !((*end == ' ') || (*end == ')')))
144 continue; /* Always check for the end. */
146 DEBUG(5,("End of first in pair '%s'\n", end));
147 if ((match_string = map_filename(s, start, end-start))) {
148 DEBUG(5,("Found a match\n"));
150 start = end+1; /* Point to start of what it is to become. */
151 DEBUG(5,("Start of second in pair '%s'\n", start));
154 while ((*end) /* Not the end of string. */
155 && (*end != ')') /* Not the end of the pattern. */
156 && (*end != '*')) /* Not a wildcard. */
160 continue; /* Always check for the end. */
163 strcpy(np, match_string);
164 np += strlen(match_string);
165 end++; /* Skip the '*' */
166 while ((*end) /* Not the end of string. */
167 && (*end != ')') /* Not the end of the pattern. */
168 && (*end != '*')) /* Not a wildcard. */
173 continue; /* Always check for the end. */
175 *np++ = '\0'; /* NULL terminate it. */
176 DEBUG(5,("End of second in pair '%s'\n", end));
177 strcpy(s, new_string); /* Substitute with the new name. */
178 DEBUG(5,("s is now '%s'\n", s));
180 start = end; /* Skip a bit which cannot be wanted */
187 main(int argc,char *argv[])
191 strcpy(name,argv[2]);
193 do_fwd_mangled_map(name,argv[1]);
194 printf("name=%s\n",name);