1*4c620fe5SSimon J. Gerraty /* $NetBSD: metachar.h,v 1.4 2015/06/21 20:26:02 christos Exp $ */ 2*4c620fe5SSimon J. Gerraty 3*4c620fe5SSimon J. Gerraty /*- 4*4c620fe5SSimon J. Gerraty * Copyright (c) 2015 The NetBSD Foundation, Inc. 5*4c620fe5SSimon J. Gerraty * All rights reserved. 6*4c620fe5SSimon J. Gerraty * 7*4c620fe5SSimon J. Gerraty * This code is derived from software contributed to The NetBSD Foundation 8*4c620fe5SSimon J. Gerraty * by Christos Zoulas. 9*4c620fe5SSimon J. Gerraty * 10*4c620fe5SSimon J. Gerraty * Redistribution and use in source and binary forms, with or without 11*4c620fe5SSimon J. Gerraty * modification, are permitted provided that the following conditions 12*4c620fe5SSimon J. Gerraty * are met: 13*4c620fe5SSimon J. Gerraty * 1. Redistributions of source code must retain the above copyright 14*4c620fe5SSimon J. Gerraty * notice, this list of conditions and the following disclaimer. 15*4c620fe5SSimon J. Gerraty * 2. Redistributions in binary form must reproduce the above copyright 16*4c620fe5SSimon J. Gerraty * notice, this list of conditions and the following disclaimer in the 17*4c620fe5SSimon J. Gerraty * documentation and/or other materials provided with the distribution. 18*4c620fe5SSimon J. Gerraty * 19*4c620fe5SSimon J. Gerraty * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*4c620fe5SSimon J. Gerraty * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*4c620fe5SSimon J. Gerraty * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*4c620fe5SSimon J. Gerraty * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*4c620fe5SSimon J. Gerraty * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*4c620fe5SSimon J. Gerraty * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*4c620fe5SSimon J. Gerraty * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*4c620fe5SSimon J. Gerraty * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*4c620fe5SSimon J. Gerraty * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*4c620fe5SSimon J. Gerraty * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*4c620fe5SSimon J. Gerraty * POSSIBILITY OF SUCH DAMAGE. 30*4c620fe5SSimon J. Gerraty */ 31*4c620fe5SSimon J. Gerraty #ifndef _METACHAR_H 32*4c620fe5SSimon J. Gerraty #define _METACHAR_H 33*4c620fe5SSimon J. Gerraty 34*4c620fe5SSimon J. Gerraty #include <ctype.h> 35*4c620fe5SSimon J. Gerraty 36*4c620fe5SSimon J. Gerraty extern unsigned char _metachar[]; 37*4c620fe5SSimon J. Gerraty 38*4c620fe5SSimon J. Gerraty #define ismeta(c) _metachar[(c) & 0x7f] 39*4c620fe5SSimon J. Gerraty 40*4c620fe5SSimon J. Gerraty static inline int 41*4c620fe5SSimon J. Gerraty hasmeta(const char *cmd) 42*4c620fe5SSimon J. Gerraty { 43*4c620fe5SSimon J. Gerraty while (!ismeta(*cmd)) 44*4c620fe5SSimon J. Gerraty cmd++; 45*4c620fe5SSimon J. Gerraty 46*4c620fe5SSimon J. Gerraty return *cmd != '\0'; 47*4c620fe5SSimon J. Gerraty } 48*4c620fe5SSimon J. Gerraty 49*4c620fe5SSimon J. Gerraty static inline int 50*4c620fe5SSimon J. Gerraty needshell(const char *cmd, int white) 51*4c620fe5SSimon J. Gerraty { 52*4c620fe5SSimon J. Gerraty while (!ismeta(*cmd) && *cmd != ':' && *cmd != '=') { 53*4c620fe5SSimon J. Gerraty if (white && isspace((unsigned char)*cmd)) 54*4c620fe5SSimon J. Gerraty break; 55*4c620fe5SSimon J. Gerraty cmd++; 56*4c620fe5SSimon J. Gerraty } 57*4c620fe5SSimon J. Gerraty 58*4c620fe5SSimon J. Gerraty return *cmd != '\0'; 59*4c620fe5SSimon J. Gerraty } 60*4c620fe5SSimon J. Gerraty 61*4c620fe5SSimon J. Gerraty #endif /* _METACHAR_H */ 62