Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / sup / source / skipto.c
blob1b66bfd6a43943c140e9fba311d06dc0e79aa483
1 /* $NetBSD: skipto.c,v 1.5 2002/07/10 20:19:43 wiz Exp $ */
3 /*
4 * Copyright (c) 1991 Carnegie Mellon University
5 * All Rights Reserved.
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie the rights
25 * to redistribute these changes.
27 /************************************************************************
28 * skipover and skipto -- skip over characters in string
30 * Usage: p = skipto (string,charset);
31 * p = skipover (string,charset);
33 * char *p,*charset,*string;
35 * Skipto returns a pointer to the first character in string which
36 * is in the string charset; it "skips until" a character in charset.
37 * Skipover returns a pointer to the first character in string which
38 * is not in the string charset; it "skips over" characters in charset.
39 ************************************************************************
40 * HISTORY
41 * 26-Jun-81 David Smith (drs) at Carnegie-Mellon University
42 * Skipover, skipto rewritten to avoid inner loop at expense of space.
44 * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
45 * Skipover, skipto adapted for VAX from skip() and skipx() on the PDP-11
46 * (from Ken Greer). The names are more mnemonic.
48 * Sindex adapted for VAX from indexs() on the PDP-11 (thanx to Ralph
49 * Guggenheim). The name has changed to be more like the index()
50 * and rindex() functions from Bell Labs; the return value (pointer
51 * rather than integer) has changed partly for the same reason,
52 * and partly due to popular usage of this function.
55 #include "supcdefs.h"
56 #include "supextern.h"
58 static char tab[256] = { 0 };
60 char *
61 skipto(const char *string, const char *charset)
63 const char *setp, *strp;
65 tab[0] = 1; /* Stop on a null, too. */
66 for (setp = charset; *setp; setp++)
67 tab[(unsigned char) *setp] = 1;
68 for (strp = string; tab[(unsigned char) *strp] == 0; strp++)
69 continue;
70 for (setp = charset; *setp; setp++)
71 tab[(unsigned char) *setp] = 0;
72 return __UNCONST(strp);
75 char *
76 skipover(const char *string, const char *charset)
78 const char *setp, *strp;
80 tab[0] = 0; /* Do not skip over nulls. */
81 for (setp = charset; *setp; setp++)
82 tab[(unsigned char) *setp] = 1;
83 for (strp = string; tab[(unsigned char) *strp]; strp++)
84 continue;
85 for (setp = charset; *setp; setp++)
86 tab[(unsigned char) *setp] = 0;
87 return __UNCONST(strp);