da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1985-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* http://www.opensource.org/licenses/cpl1.0.txt *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#pragma prototyped
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * string interface to confstr(),pathconf(),sysconf(),sysinfo()
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * extended to allow some features to be set per-process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstatic const char id[] = "\n@(#)$Id: getconf (AT&T Research) 2009-07-02 $\0\n";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "univlib.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <ast.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <error.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <fs3d.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <ctype.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <regex.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <proc.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "conftab.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "FEATURE/libpath"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#ifndef DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define DEBUG_astconf 0
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef _pth_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef ASTCONF_system
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define ASTCONF_system 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _sys_systeminfo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# if !_lib_sysinfo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# if _lib_systeminfo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# define _lib_sysinfo 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# define sysinfo(a,b,c) systeminfo(a,b,c)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# if _lib_syscall && _sys_syscall
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# include <sys/syscall.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# if defined(SYS_systeminfo)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# define _lib_sysinfo 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# define sysinfo(a,b,c) syscall(SYS_systeminfo,a,b,c)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# undef _lib_sysinfo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define CONF_ERROR (CONF_USER<<0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define CONF_READONLY (CONF_USER<<1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define CONF_ALLOC (CONF_USER<<2)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define CONF_GLOBAL (CONF_USER<<3)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define DEFAULT(o) ((state.std||!dynamic[o].ast)?dynamic[o].std:dynamic[o].ast)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define INITIALIZE() do{if(!state.data)synthesize(NiL,NiL,NiL);}while(0)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define STANDARD(v) (streq(v,"standard")||streq(v,"strict")||streq(v,"posix")||streq(v,"xopen"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define MAXVAL 256
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if MAXVAL <= UNIV_SIZE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef MAXVAL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define MAXVAL (UNIV_SIZE+1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef _UNIV_DEFAULT
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _UNIV_DEFAULT "att"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char null[1];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char root[2] = "/";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct Feature_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct Feature_s*next;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* value;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz char* std;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz char* ast;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short length;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short standard;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin unsigned int flags;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short op;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin} Feature_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Conf_t* conf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* name;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin unsigned int flags;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short standard;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin short section;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin} Lookup_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Feature_t dynamic[] =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_conformance 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_conformance+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "CONFORMANCE",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "ast",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "standard",
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "ast",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 11,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_conformance
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_fs_3d 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_fs_3d+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "FS_3D",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "0",
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 5,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_fs_3d
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_getconf 2
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_getconf+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "GETCONF",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin _pth_getconf,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 7,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_READONLY,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_hosttype 3
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_hosttype+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "HOSTTYPE",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin HOSTTYPE,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 8,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_READONLY,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_hosttype
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_libpath 4
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_libpath+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "LIBPATH",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef CONF_LIBPATH
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_LIBPATH,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 7,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_libpath
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_libprefix 5
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_libprefix+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "LIBPREFIX",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef CONF_LIBPREFIX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_LIBPREFIX,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "lib",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 9,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_libprefix
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_libsuffix 6
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_libsuffix+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "LIBSUFFIX",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef CONF_LIBSUFFIX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_LIBSUFFIX,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ".so",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 9,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_libsuffix
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_path_attributes 7
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_path_attributes+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "PATH_ATTRIBUTES",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _WINIX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "c",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 15,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_READONLY,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_path_attributes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_path_resolve 8
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz &dynamic[OP_path_resolve+1],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "PATH_RESOLVE",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "physical",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "metaphysical",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 12,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_path_resolve
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#define OP_universe 9
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "UNIVERSE",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &null[0],
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "att",
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 8,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CONF_AST,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin OP_universe
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin },
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* id;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Feature_t* features;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz int std;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* default initialization from here down */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int prefix;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int synthesizing;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* last;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Feature_t* recent;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ast_confdisc_f notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin} State_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstatic State_t state = { "getconf", "_AST_FEATURES", dynamic, -1 };
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic char* feature(const char*, const char*, const char*, unsigned int, Error_f);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return fmtbuf() copy of s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinbuffer(char* s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return strcpy(fmtbuf(strlen(s) + 1), s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * synthesize state for fp
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fp==0 initializes from getenv(state.name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * value==0 just does lookup
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * otherwise state is set to value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinsynthesize(register Feature_t* fp, const char* path, const char* value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* d;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* v;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz register char* p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(-2, "astconf synthesize name=%s path=%s value=%s fp=%p%s", fp->name, path, value, fp, state.synthesizing ? " SYNTHESIZING" : "");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.synthesizing)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!state.data)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* se;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* de;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* ve;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.prefix = strlen(state.name) + 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = state.prefix + 3 * MAXVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s = getenv(state.name))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n += strlen(s) + 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = roundof(n, 32);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(state.data = newof(0, char, n, 0)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.last = state.data + n - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strcpy(state.data, state.name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.data += state.prefix - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *state.data++ = '=';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strcpy(state.data, s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ve = state.data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.synthesizing = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = ve; isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (d = s; *d && !isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (se = d; isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (v = d; *v && !isspace(*v); v++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (de = v; isspace(*v); v++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!*v)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (ve = v; *ve && !isspace(*ve); ve++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*ve)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *ve = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ve = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *de = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *se = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin feature(s, d, v, 0, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *se = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *de = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!ve)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *ve++ = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.synthesizing = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!fp)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return state.data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!state.last)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = strlen(value);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto ok;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = (char*)fp->name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = fp->length;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin d = state.data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (isspace(*d))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin d++;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!*d)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (strneq(d, s, n) && isspace(d[n]))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (d += n + 1; *d && !isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = d; *s && !isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = s - d;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin value = (const char*)d;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto ok;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz for (s = p = d + n + 1; *s && !isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (v = s; *s && !isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = s - v;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if ((!path || *path == *p && strlen(path) == (v - p - 1) && !memcmp(path, p, v - p - 1)) && strneq(v, value, n))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto ok;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; *d = *s++; d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (d != state.data)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin d--;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; *d && !isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; *d && !isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (; *d && !isspace(*d); d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!fp->op)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->flags & CONF_ALLOC)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value[0] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value[0])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin value = "0";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!path || !path[0] || path[0] == '/' && !path[1])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin path = "-";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n += strlen(path) + strlen(value) + 3;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (d + n >= state.last)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int i;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin i = d - state.data;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.data -= state.prefix;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin c = n + state.last - state.data + 3 * MAXVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin c = roundof(c, 32);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(state.data = newof(state.data, char, c, 0)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.last = state.data + c - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.data += state.prefix;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin d = state.data + i;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (d != state.data)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *d++ = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = (char*)fp->name; *d = *s++; d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *d++ = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = (char*)path; *d = *s++; d++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *d++ = ' ';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = (char*)value; *d = *s++; d++);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-3, "astconf synthesize %s", state.data - state.prefix);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin setenviron(state.data - state.prefix);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.notify)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*state.notify)(NiL, NiL, state.data - state.prefix);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = s - (char*)value - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(fp->flags & CONF_ALLOC))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (n == 1 && (*value == '0' || *value == '-'))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(fp->value = newof(fp->value, char, n, 1)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->flags |= CONF_ALLOC;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin memcpy(fp->value, value, n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value[n] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return fp->value;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * initialize the value for fp
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if command!=0 then it is checked for on $PATH
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * synthesize(fp,path,succeed) called on success
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * otherwise synthesize(fp,path,fail) called
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chininitialize(register Feature_t* fp, const char* path, const char* command, const char* succeed, const char* fail)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(-2, "astconf initialize name=%s path=%s command=%s succeed=%s fail=%s fp=%p%s", fp->name, path, command, succeed, fail, fp, state.synthesizing ? " SYNTHESIZING" : "");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (fp->op)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_conformance:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = getenv("POSIXLY_CORRECT") != 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_hosttype:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_path_attributes:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_path_resolve:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = fs3d(FS3D_TEST);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_universe:
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz ok = streq(_UNIV_DEFAULT, DEFAULT(OP_universe));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /*FALLTHROUGH...*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin default:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p = getenv("PATH"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int r = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* d = p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Sfio_t* tmp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(-2, "astconf initialize name=%s ok=%d PATH=%s", fp->name, ok, p);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp = sfstropen())
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (*p++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case 0:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case ':':
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (command && (fp->op != OP_universe || !ok))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (r = p - d - 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfwrite(tmp, d, r);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfputc(tmp, '/');
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfputr(tmp, command, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((d = sfstruse(tmp)) && !eaccess(d, X_OK))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->op != OP_universe)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin d = p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case '/':
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (r)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->op == OP_universe)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (p[0] == 'u' && p[1] == 's' && p[2] == 'r' && p[3] == '/')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for (p += 4; *p == '/'; p++);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (p[0] == 'b' && p[1] == 'i' && p[2] == 'n')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for (p += 3; *p == '/'; p++);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (!*p || *p == ':')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin break;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->op == OP_universe)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (strneq(p, "xpg", 3) || strneq(p, "5bin", 4))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (strneq(p, "bsd", 3) || strneq(p, "ucb", 3))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin default:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(tmp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ok = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-1, "AHA#%d state.std=%d %s [%s] std=%s ast=%s value=%s ok=%d", __LINE__, state.std, fp->name, ok ? succeed : fail, fp->std, fp->ast, fp->value, ok);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin synthesize(fp, path, ok ? succeed : fail);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * format synthesized value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinformat(register Feature_t* fp, const char* path, const char* value, unsigned int flags, Error_f conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Feature_t* sp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(-2, "astconf format name=%s path=%s value=%s flags=%04x fp=%p%s", fp->name, path, value, flags, fp, state.synthesizing ? " SYNTHESIZING" : "");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (value)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin fp->flags &= ~CONF_GLOBAL;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else if (fp->flags & CONF_GLOBAL)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin return fp->value;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (fp->op)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_conformance:
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (value && STANDARD(value))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz value = fp->std;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz n = state.std = streq(fp->value, fp->std);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-1, "AHA#%d state.std=%d %s [%s] std=%s ast=%s value=%s", __LINE__, state.std, fp->name, value, fp->std, fp->ast, fp->value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!synthesize(fp, path, value))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz initialize(fp, path, NiL, fp->std, fp->value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-1, "AHA#%d state.std=%d %s [%s] std=%s ast=%s value=%s", __LINE__, state.std, fp->name, value, fp->std, fp->ast, fp->value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (!n && STANDARD(fp->value))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz state.std = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (sp = state.features; sp; sp = sp->next)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (sp->std && sp->op && sp->op != OP_conformance)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz astconf(sp->name, path, sp->std);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-1, "AHA#%d state.std=%d %s [%s] std=%s ast=%s value=%s", __LINE__, state.std, fp->name, value, fp->std, fp->ast, fp->value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_fs_3d:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->value = fs3d(value ? value[0] ? FS3D_ON : FS3D_OFF : FS3D_TEST) ? "1" : null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_hosttype:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_path_attributes:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _PC_PATH_ATTRIBUTES
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* e;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin intmax_t v;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * _PC_PATH_ATTRIBUTES is a bitmap for 'a' to 'z'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((v = pathconf(path, _PC_PATH_ATTRIBUTES)) == -1L)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = fp->value;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin e = s + sizeof(fp->value) - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (n = 'a'; n <= 'z'; n++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (v & (1 << (n - 'a')))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *s++ = n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s >= e)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *s = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_path_resolve:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!synthesize(fp, path, value))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz initialize(fp, path, NiL, "logical", DEFAULT(OP_path_resolve));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case OP_universe:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _lib_universe
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (getuniverse(fp->value) < 0)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz strcpy(fp->value, DEFAULT(OP_universe));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin setuniverse(value);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef UNIV_MAX
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (n < univ_max && !streq(value, univ_name[n])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n++;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (n >= univ_max)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: %s: universe value too large", fp->name, value);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef ATT_UNIV
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = setuniverse(n + 1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value && n > 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin setuniverse(n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = universe(value ? n + 1 : U_GET);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (n <= 0 || n >= univ_max)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strcpy(fp->value, univ_name[n - 1]);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (value && streq(path, "="))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (state.synthesizing)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (!(fp->flags & CONF_ALLOC))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->value = 0;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz n = strlen(value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (!(fp->value = newof(fp->value, char, n, 1)))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->value = null;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz else
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->flags |= CONF_ALLOC;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz memcpy(fp->value, value, n);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->value[n] = 0;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz else
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz synthesize(fp, path, value);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz initialize(fp, path, "echo", DEFAULT(OP_universe), "ucb");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin default:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin synthesize(fp, path, value);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (streq(path, "="))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin fp->flags |= CONF_GLOBAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return fp->value;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * value==0 get feature name
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * value!=0 set feature name
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 0 returned if error or not defined; otherwise previous value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfeature(const char* name, const char* path, const char* value, unsigned int flags, Error_f conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Feature_t* fp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value && (streq(value, "-") || streq(value, "0")))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin value = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (fp = state.features; fp && !streq(fp->name, name); fp = fp->next);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(-2, "astconf feature name=%s path=%s value=%s flags=%04x fp=%p%s", name, path, value, flags, fp, state.synthesizing ? " SYNTHESIZING" : "");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!fp)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.notify && !(*state.notify)(name, path, value))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = strlen(name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(fp = newof(0, Feature_t, 1, n + 1)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: out of space", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->op = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->name = (const char*)fp + sizeof(Feature_t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strcpy((char*)fp->name, name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->length = n;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz fp->std = &null[0];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fp->next = state.features;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.features = fp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->flags & CONF_READONLY)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: cannot set readonly symbol", fp->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.notify && !streq(fp->value, value) && !(*state.notify)(name, path, value))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.recent = fp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return format(fp, path, value, flags, conferror);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * binary search for name in conf[]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic int
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinlookup(register Lookup_t* look, const char* name, unsigned int flags)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Conf_t* mid = (Conf_t*)conf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Conf_t* lo = mid;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Conf_t* hi = mid + conf_elements;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int v;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* e;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const Prefix_t* p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin static Conf_t num;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->flags = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->call = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->standard = (flags & ASTCONF_AST) ? CONF_AST : -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->section = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*name == '_')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin name++;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin again:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (p = prefix; p < &prefix[prefix_elements]; p++)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (strneq(name, p->name, p->length) && ((c = name[p->length] == '_' || name[p->length] == '(' || name[p->length] == '#') || (v = isdigit(name[p->length]) && name[p->length + 1] == '_')))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->call < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->standard >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->standard = p->standard;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->call >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->call = p->call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (name[p->length] == '(' || name[p->length] == '#')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->conf = &num;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strncpy((char*)num.name, name, sizeof(num.name));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin num.call = p->call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin num.flags = *name == 'C' ? CONF_STRING : 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin num.op = (short)strtol(name + p->length + 1, &e, 10);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (name[p->length] == '(' && *e == ')')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin e++;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (*e)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin name += p->length + c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->section < 0 && !c && v)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->section = name[0] - '0';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin name += 2;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto again;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if HUH_2006_02_10
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->section < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->section = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->name = name;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(-2, "astconf normal name=%s standard=%d section=%d call=%d flags=%04x elements=%d", look->name, look->standard, look->section, look->call, flags, conf_elements);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin c = *((unsigned char*)name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (lo <= hi)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mid = lo + (hi - lo) / 2;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(-3, "astconf lookup name=%s mid=%s", name, mid->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(v = c - *((unsigned char*)mid->name)) && !(v = strcmp(name, mid->name)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hi = mid;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin lo = (Conf_t*)conf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin do
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((look->standard < 0 || look->standard == mid->standard) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (look->section < 0 || look->section == mid->section) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (look->call < 0 || look->call == mid->call))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto found;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } while (mid-- > lo && streq(mid->name, look->name));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin mid = hi;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hi = lo + conf_elements - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (++mid < hi && streq(mid->name, look->name))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((look->standard < 0 || look->standard == mid->standard) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (look->section < 0 || look->section == mid->section) &&
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (look->call < 0 || look->call == mid->call))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto found;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (v > 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin lo = mid + 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hi = mid - 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin found:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->call < 0 && look->standard >= 0 && (look->section <= 1 || (mid->flags & CONF_MINMAX)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->flags |= CONF_MINMAX;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look->conf = mid;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(-2, "astconf lookup name=%s standard=%d:%d section=%d:%d call=%d:%d", look->name, look->standard, mid->standard, look->section, mid->section, look->call, mid->call);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return a tolower'd copy of s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfmtlower(register const char* s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b = t = fmtbuf(strlen(s) + 1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (c = *s++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (isupper(c))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin c = tolower(c);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *t++ = c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *t = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * print value line for p
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if !name then value prefixed by "p->name="
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if (flags & CONF_MINMAX) then default minmax value used
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinprint(Sfio_t* sp, register Lookup_t* look, const char* name, const char* path, int listflags, Error_f conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Conf_t* p = look->conf;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin register unsigned int flags = look->flags;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* f;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int i;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int olderrno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int drop;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int defined;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin intmax_t v;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char buf[PATH_MAX];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char flg[16];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!name && !(p->flags & CONF_STRING) && (p->flags & (CONF_FEATURE|CONF_LIMIT|CONF_MINMAX)) && (p->flags & (CONF_LIMIT|CONF_PREFIXED)) != CONF_LIMIT)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= CONF_PREFIXED;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin olderrno = errno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = 0;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(-1, "astconf name=%s:%s:%s standard=%d section=%d call=%s op=%d flags=|%s%s%s%s%s:|%s%s%s%s%s%s%s%s%s%s"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz , name, look->name, p->name, p->standard, p->section, prefix[p->call + CONF_call].name, p->op
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (flags & CONF_FEATURE) ? "FEATURE|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (flags & CONF_LIMIT) ? "LIMIT|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (flags & CONF_MINMAX) ? "MINMAX|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (flags & CONF_PREFIXED) ? "PREFIXED|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (flags & CONF_STRING) ? "STRING|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_DEFER_CALL) ? "DEFER_CALL|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_DEFER_MM) ? "DEFER_MM|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_FEATURE) ? "FEATURE|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_LIMIT_DEF) ? "LIMIT_DEF|" : (p->flags & CONF_LIMIT) ? "LIMIT|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_MINMAX_DEF) ? "MINMAX_DEF|" : (p->flags & CONF_MINMAX) ? "MINMAX|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_NOUNDERSCORE) ? "NOUNDERSCORE|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_PREFIXED) ? "PREFIXED|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_PREFIX_ONLY) ? "PREFIX_ONLY|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_STANDARD) ? "STANDARD|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_STRING) ? "STRING|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin , (p->flags & CONF_UNDERSCORE) ? "UNDERSCORE|" : ""
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin );
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= CONF_LIMIT_DEF|CONF_MINMAX_DEF;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror && name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & CONF_PREFIX_ONLY) && look->standard < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(flags & CONF_MINMAX) || !(p->flags & CONF_MINMAX))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (p->call)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case CONF_pathconf:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (path == root)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: path expected", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin default:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (path != root)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: path not expected", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_DEFER_CALL)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (path != root)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: path not expected", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & CONF_DEFER_MM) || !(p->flags & CONF_MINMAX_DEF))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->standard >= 0 && (name[0] != '_' && ((p->flags & CONF_UNDERSCORE) || look->section <= 1) || name[0] == '_' && (p->flags & CONF_NOUNDERSCORE)) || look->standard < 0 && name[0] == '_')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (i = (p->op < 0 || (flags & CONF_MINMAX) && (p->flags & CONF_MINMAX_DEF)) ? 0 : p->call)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case CONF_confstr:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "confstr";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _lib_confstr
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(v = confstr(p->op, buf, sizeof(buf))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (v > 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[sizeof(buf) - 1] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = (const char*)buf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto predef;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case CONF_pathconf:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "pathconf";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _lib_pathconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((v = pathconf(path, p->op)) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto predef;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case CONF_sysconf:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "sysconf";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _lib_sysconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((v = sysconf(p->op)) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto predef;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case CONF_sysinfo:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "sysinfo";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _lib_sysinfo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((v = sysinfo(p->op, buf, sizeof(buf))) >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin buf[sizeof(buf) - 1] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = (const char*)buf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto predef;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin default:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "synthesis";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin case 0:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = 0;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (p->standard == CONF_AST)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (streq(p->name, "RELEASE") && (i = open("/proc/version", O_RDONLY)) >= 0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin n = read(i, buf, sizeof(buf) - 1);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin close(i);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (n > 0 && buf[n - 1] == '\n')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin n--;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (n > 0 && buf[n - 1] == '\r')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin n--;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin buf[n] = 0;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (buf[0])
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin v = 0;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin s = buf;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin break;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_MINMAX_DEF)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!((p->flags & CONF_LIMIT_DEF)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= CONF_MINMAX;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin listflags &= ~ASTCONF_system;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin predef:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look->standard == CONF_AST)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (streq(p->name, "VERSION"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner v = ast.version;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & CONF_MINMAX)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & CONF_MINMAX_DEF) && (!(listflags & ASTCONF_system) || !(p->flags & CONF_DEFER_MM)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = p->minmax.number;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = p->minmax.string;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if ((p->flags & CONF_LIMIT_DEF) && (!(listflags & ASTCONF_system) || !(p->flags & CONF_DEFER_CALL)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = p->limit.number;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = p->limit.string;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags &= ~(CONF_LIMIT_DEF|CONF_MINMAX_DEF);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin v = -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin defined = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!defined)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!errno)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & CONF_FEATURE) || !(p->flags & (CONF_LIMIT|CONF_MINMAX)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags &= ~(CONF_LIMIT_DEF|CONF_MINMAX_DEF);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & CONF_PREFIXED)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags &= ~(CONF_LIMIT_DEF|CONF_MINMAX_DEF);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (errno != EINVAL || !i)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!sp)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (call)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, ERROR_SYSTEM|2, "%s: %s error", p->name, call);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (!(listflags & ASTCONF_system))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: unknown name", p->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags &= ~(CONF_LIMIT_DEF|CONF_MINMAX_DEF);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= CONF_ERROR;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = olderrno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((listflags & ASTCONF_defined) && !(flags & (CONF_LIMIT_DEF|CONF_MINMAX_DEF)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((drop = !sp) && !(sp = sfstropen()))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto bad;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (listflags & ASTCONF_table)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin f = flg;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_DEFER_CALL)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'C';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_DEFER_MM)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'D';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_FEATURE)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'F';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_LIMIT)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'L';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_MINMAX)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'M';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_NOSECTION)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'N';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_PREFIXED)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'P';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_STANDARD)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'S';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_UNDERSCORE)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'U';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_NOUNDERSCORE)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'V';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_PREFIX_ONLY)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'W';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (f == flg)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'X';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%*s %*s %d %2s %4d %6s ", sizeof(p->name), p->name, sizeof(prefix[p->standard].name), prefix[p->standard].name, p->section, prefix[p->call + CONF_call].name, p->op, flg);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_LIMIT_DEF)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->limit.string)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "L[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->limit.string, "\"", "\"", strlen(p->limit.string), FMT_SHELL) : p->limit.string);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "L[%I*d] ", sizeof(p->limit.number), p->limit.number);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_MINMAX_DEF)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->minmax.string)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "M[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->minmax.string, "\"", "\"", strlen(p->minmax.string), FMT_SHELL) : p->minmax.string);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "M[%I*d] ", sizeof(p->minmax.number), p->minmax.number);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & CONF_ERROR)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "error");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (defined)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (v != -1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*d", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*u", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "\n");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(flags & CONF_PREFIXED) || (listflags & ASTCONF_base))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & (CONF_PREFIXED|CONF_STRING)) == (CONF_PREFIXED|CONF_STRING) && (!(listflags & ASTCONF_base) || p->standard != CONF_POSIX))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((p->flags & CONF_UNDERSCORE) && !(listflags & ASTCONF_base))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "_");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s", (listflags & ASTCONF_lower) ? fmtlower(prefix[p->standard].name) : prefix[p->standard].name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->section > 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%d", p->section);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "_");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s=", (listflags & ASTCONF_lower) ? fmtlower(p->name) : p->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & CONF_ERROR)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "error");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (defined)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (v != -1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*d", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*u", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "undefined");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "\n");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!name && !(listflags & ASTCONF_base) && !(p->flags & CONF_STRING) && (p->flags & (CONF_FEATURE|CONF_MINMAX)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->flags & CONF_UNDERSCORE)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "_");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s", (listflags & ASTCONF_lower) ? fmtlower(prefix[p->standard].name) : prefix[p->standard].name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p->section > 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%d", p->section);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "_%s=", (listflags & ASTCONF_lower) ? fmtlower(p->name) : p->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (v != -1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*d", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (defined)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%I*u", sizeof(v), v);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "undefined");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "\n");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (drop)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (call = sfstruse(sp))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = buffer(call);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "[ out of space ]";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(sp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bad:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (listflags & ASTCONF_error) ? (char*)0 : null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * return read stream to native getconf utility
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Sfio_t*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinnativeconf(Proc_t** pp, const char* operand)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Sfio_t* sp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* cmd[3];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin long ops[2];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if DEBUG_astconf
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(-2, "astconf defer %s %s", _pth_getconf, operand);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmd[0] = (char*)state.id;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmd[1] = (char*)operand;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmd[2] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ops[0] = PROC_FD_DUP(open("/dev/null",O_WRONLY,0), 2, PROC_FD_CHILD);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ops[1] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*pp = procopen(_pth_getconf, cmd, environ, ops, PROC_READ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (sp = sfnew(NiL, NiL, SF_UNBOUND, (*pp)->rfd, SF_READ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfdisc(sp, SF_POPDISC);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return sp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin procclose(*pp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * value==0 gets value for name
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * value!=0 sets value for name and returns previous value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * path==0 implies path=="/"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * settable return values are in permanent store
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * non-settable return values copied to a tmp fmtbuf() buffer
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if (streq(astgetconf("PATH_RESOLVE", NiL, NiL, 0, 0), "logical"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * our_way();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * universe = astgetconf("UNIVERSE", NiL, "att", 0, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * astgetconf("UNIVERSE", NiL, universe, 0, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if (flags&ASTCONF_error)!=0 then error return value is 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * otherwise 0 not returned
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define ALT 16
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinchar*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinastgetconf(const char* name, const char* path, const char* value, int flags, Error_f conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Lookup_t look;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Sfio_t* tmp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if __OBSOLETE__ < 20080101
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pointerof(flags) == (void*)errorf)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin conferror = errorf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags = ASTCONF_error;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (conferror && conferror != errorf)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin conferror = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!name)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (path)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(name = value))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.data)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ast_confdisc_f notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _HUH20000515 /* doesn't work for shell builtins */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin free(state.data - state.prefix);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.data = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin notify = state.notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.notify = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin INITIALIZE();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.notify = notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin value = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin INITIALIZE();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!path)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin path = root;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state.recent && streq(name, state.recent->name) && (s = format(state.recent, path, value, flags, conferror)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (lookup(&look, name, flags))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ro:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: cannot set value", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (flags & ASTCONF_error) ? (char*)0 : null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return print(NiL, &look, name, path, flags, conferror);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((n = strlen(name)) > 3 && n < (ALT + 3))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (streq(name + n - 3, "DEV"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp = sfstropen())
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(tmp, "/dev/");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = (char*)name; s < (char*)name + n - 3; s++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfputc(tmp, isupper(*s) ? tolower(*s) : *s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((s = sfstruse(tmp)) && !access(s, F_OK))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto ro;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = buffer(s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(tmp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(tmp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (streq(name + n - 3, "DIR"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Lookup_t altlook;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char altname[ALT];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin static const char* dirs[] = { "/usr/lib", "/usr", null };
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin strcpy(altname, name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin altname[n - 3] = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (lookup(&altlook, altname, flags))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: cannot set value", altname);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (flags & ASTCONF_error) ? (char*)0 : null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return print(NiL, &altlook, altname, path, flags, conferror);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = altname; *s; s++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (isupper(*s))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *s = tolower(*s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp = sfstropen())
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (n = 0; n < elementsof(dirs); n++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(tmp, "%s/%s/.", dirs[n], altname);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((s = sfstruse(tmp)) && !access(s, F_OK))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin goto ro;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = buffer(s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(tmp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(tmp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((look.standard < 0 || look.standard == CONF_AST) && look.call <= 0 && look.section <= 1 && (s = feature(look.name, path, value, flags, conferror)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = EINVAL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (conferror && !(flags & ASTCONF_system))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*conferror)(&state, &state, 2, "%s: unknown name", name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (flags & ASTCONF_error) ? (char*)0 : null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * astconf() never returns 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinchar*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinastconf(const char* name, const char* path, const char* value)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return astgetconf(name, path, value, 0, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * set discipline function to be called when features change
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * old discipline function returned
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinAst_confdisc_f
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinastconfdisc(Ast_confdisc_f new_notify)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Ast_confdisc_f old_notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin INITIALIZE();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin old_notify = state.notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin state.notify = new_notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return old_notify;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * list all name=value entries on sp
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * path==0 implies path=="/"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinvoid
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinastconflist(Sfio_t* sp, const char* path, int flags, const char* pattern)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* f;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* call;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Feature_t* fp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Lookup_t look;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin regex_t re;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin regdisc_t redisc;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int olderrno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char flg[8];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf_a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Proc_t* proc;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Sfio_t* pp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin INITIALIZE();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!path)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin path = root;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (access(path, F_OK))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errorf(&state, &state, 2, "%s: not found", path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin olderrno = errno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look.flags = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(flags & (ASTCONF_read|ASTCONF_write|ASTCONF_parse)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= ASTCONF_read|ASTCONF_write;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_parse)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin flags |= ASTCONF_write;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(flags & (ASTCONF_matchcall|ASTCONF_matchname|ASTCONF_matchstandard)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin pattern = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pattern)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin memset(&redisc, 0, sizeof(redisc));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin redisc.re_version = REG_VERSION;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin redisc.re_errorf = (regerror_t)errorf;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin re.re_disc = &redisc;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regcomp(&re, pattern, REG_DISCIPLINE|REG_EXTENDED|REG_LENIENT|REG_NULL))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_read)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (look.conf = (Conf_t*)conf; look.conf < (Conf_t*)&conf[conf_elements]; look.conf++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pattern)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_matchcall)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, prefix[look.conf->call + CONF_call].name, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_matchname)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, look.conf->name, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_matchstandard)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, prefix[look.conf->standard].name, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin print(sp, &look, NiL, path, flags, errorf);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _pth_getconf_a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pp = nativeconf(&proc, _pth_getconf_a))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "GC";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (f = sfgetr(pp, '\n', 1))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (s = f; *s && *s != '=' && *s != ':' && !isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (*s++ = 0; isspace(*s); s++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!lookup(&look, f, flags))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_table)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look.standard < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look.standard = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (look.section < 1)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin look.section = 1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%*s %*s %d %2s %4d %5s %s\n", sizeof(conf[0].name), f, sizeof(prefix[look.standard].name), prefix[look.standard].name, look.section, call, 0, "N", s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_parse)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s %s - %s\n", state.id, f, s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s=%s\n", f, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfclose(pp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin procclose(proc);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_write)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin call = "AC";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (fp = state.features; fp; fp = fp->next)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pattern)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_matchcall)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, call, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_matchname)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, fp->name, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_matchstandard)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (regexec(&re, prefix[fp->standard].name, 0, NiL, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(s = feature(fp->name, path, NiL, 0, 0)) || !*s)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = "0";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags & ASTCONF_table)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin f = flg;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->flags & CONF_ALLOC)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'A';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fp->flags & CONF_READONLY)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'R';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (f == flg)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f++ = 'X';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *f = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%*s %*s %d %2s %4d %5s %s\n", sizeof(conf[0].name), fp->name, sizeof(prefix[fp->standard].name), prefix[fp->standard].name, 1, call, 0, flg, s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (flags & ASTCONF_parse)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s %s - %s\n", state.id, (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sp, "%s=%s\n", (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (pattern)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin regfree(&re);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno = olderrno;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}