1289720Ssjg/* $NetBSD: metachar.h,v 1.4 2015/06/21 20:26:02 christos Exp $ */ 2289720Ssjg 3289720Ssjg/*- 4289720Ssjg * Copyright (c) 2015 The NetBSD Foundation, Inc. 5289720Ssjg * All rights reserved. 6289720Ssjg * 7289720Ssjg * This code is derived from software contributed to The NetBSD Foundation 8289720Ssjg * by Christos Zoulas. 9289720Ssjg * 10289720Ssjg * Redistribution and use in source and binary forms, with or without 11289720Ssjg * modification, are permitted provided that the following conditions 12289720Ssjg * are met: 13289720Ssjg * 1. Redistributions of source code must retain the above copyright 14289720Ssjg * notice, this list of conditions and the following disclaimer. 15289720Ssjg * 2. Redistributions in binary form must reproduce the above copyright 16289720Ssjg * notice, this list of conditions and the following disclaimer in the 17289720Ssjg * documentation and/or other materials provided with the distribution. 18289720Ssjg * 19289720Ssjg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20289720Ssjg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21289720Ssjg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22289720Ssjg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23289720Ssjg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24289720Ssjg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25289720Ssjg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26289720Ssjg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27289720Ssjg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28289720Ssjg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29289720Ssjg * POSSIBILITY OF SUCH DAMAGE. 30289720Ssjg */ 31289720Ssjg#ifndef _METACHAR_H 32289720Ssjg#define _METACHAR_H 33289720Ssjg 34289720Ssjg#include <ctype.h> 35289720Ssjg 36289720Ssjgextern unsigned char _metachar[]; 37289720Ssjg 38289720Ssjg#define ismeta(c) _metachar[(c) & 0x7f] 39289720Ssjg 40289720Ssjgstatic inline int 41289720Ssjghasmeta(const char *cmd) 42289720Ssjg{ 43289720Ssjg while (!ismeta(*cmd)) 44289720Ssjg cmd++; 45289720Ssjg 46289720Ssjg return *cmd != '\0'; 47289720Ssjg} 48289720Ssjg 49289720Ssjgstatic inline int 50289720Ssjgneedshell(const char *cmd, int white) 51289720Ssjg{ 52289720Ssjg while (!ismeta(*cmd) && *cmd != ':' && *cmd != '=') { 53289720Ssjg if (white && isspace((unsigned char)*cmd)) 54289720Ssjg break; 55289720Ssjg cmd++; 56289720Ssjg } 57289720Ssjg 58289720Ssjg return *cmd != '\0'; 59289720Ssjg} 60289720Ssjg 61289720Ssjg#endif /* _METACHAR_H */ 62