1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A#include <ast.h>
1N/A#include <ctype.h>
1N/A
1N/Astatic char** ids;
1N/A
1N/Astatic const char* dflt[] = { "ast", "standard", 0 };
1N/A
1N/A/*
1N/A * initialize the conformance() id list
1N/A */
1N/A
1N/Astatic char**
1N/Ainitconformance(void)
1N/A{
1N/A char* m;
1N/A char** p;
1N/A char* t;
1N/A int h;
1N/A int i;
1N/A int j;
1N/A int c;
1N/A Sfio_t* sp;
1N/A
1N/A static const char* conf[] = { "CONFORMANCE", "HOSTTYPE", "UNIVERSE" };
1N/A
1N/A p = 0;
1N/A if (sp = sfstropen())
1N/A {
1N/A for (i = h = 0, j = 1; i < elementsof(conf); i++)
1N/A if (*(m = astconf(conf[i], NiL, NiL)) && (h |= (1<<i)) || !i && (m = "ast"))
1N/A {
1N/A t = m;
1N/A while ((c = *m++) && c != '.')
1N/A {
1N/A if (isupper(c))
1N/A c = tolower(c);
1N/A sfputc(sp, c);
1N/A }
1N/A sfputc(sp, 0);
1N/A j++;
1N/A if ((c = (m - t)) == 6 && strneq(t, "linux", 5))
1N/A {
1N/A sfputr(sp, "gnu", 0);
1N/A j++;
1N/A }
1N/A else if (c > 3 && strneq(t, "bsd", 3) || c == 7 && strneq(t, "debian", 7))
1N/A {
1N/A sfputr(sp, "bsd", 0);
1N/A j++;
1N/A }
1N/A if (h & 1)
1N/A break;
1N/A }
1N/A i = sfstrtell(sp);
1N/A sfstrseek(sp, 0, SEEK_SET);
1N/A if (p = newof(0, char*, j, i))
1N/A {
1N/A m = (char*)(p + j--);
1N/A memcpy(m, sfstrbase(sp), i);
1N/A i = 0;
1N/A p[i++] = m;
1N/A while (i < j)
1N/A {
1N/A while (*m++);
1N/A p[i++] = m;
1N/A }
1N/A p[i] = 0;
1N/A }
1N/A sfstrclose(sp);
1N/A }
1N/A if (!p)
1N/A p = (char**)dflt;
1N/A return ids = p;
1N/A}
1N/A
1N/A/*
1N/A * return conformance id if s size n is in conformance
1N/A * prefix match of s on the conformance id table
1N/A * s==0 => "standard"
1N/A */
1N/A
1N/Achar*
1N/Aconformance(const char* s, size_t n)
1N/A{
1N/A char** p;
1N/A char** q;
1N/A char* m;
1N/A const char* e;
1N/A const char* t;
1N/A
1N/A static uint32_t serial = ~(uint32_t)0;
1N/A
1N/A if (!(p = ids) || serial != ast.env_serial)
1N/A {
1N/A serial = ast.env_serial;
1N/A if (ids)
1N/A {
1N/A if (ids != (char**)dflt)
1N/A free(ids);
1N/A ids = 0;
1N/A }
1N/A p = initconformance();
1N/A }
1N/A if (!s)
1N/A s = dflt[1];
1N/A if (!n)
1N/A n = strlen(s);
1N/A e = s + n;
1N/A if (*s == '(')
1N/A s++;
1N/A do
1N/A {
1N/A while (s < e && (isspace(*s) || *s == ',' || *s == '|'))
1N/A s++;
1N/A if (*s == ')')
1N/A break;
1N/A for (t = s; s < e && !isspace(*s) && *s != ',' && *s != '|' && *s != ')'; s++);
1N/A if (s == t)
1N/A break;
1N/A q = p;
1N/A while (m = *q++)
1N/A if (strneq(t, m, s - t))
1N/A return m;
1N/A if (s < e)
1N/A s++;
1N/A } while (s < e);
1N/A return 0;
1N/A}