Пример #1
0
/*
 *  check lower case version of address agains patterns
 */
static Pattern*
checkaddr(char *arg)
{
	Pattern *p;
	Reprog *rp;
	String *s;

	s = s_copy(arg);
	mklower(s_to_c(s));

	for(p = patterns; p != nil; p = p->next)
		switch(p->type){
		case Texact:
			if(strcmp(p->arg, s_to_c(s)) == 0){
				free(s);
				return p;
			}
			break;
		case Tregexp:
			rp = regcomp(p->arg);
			if(rp == nil)
				continue;
			if(regexec(rp, s_to_c(s), nil, 0)){
				free(rp);
				free(s);
				return p;
			}
			free(rp);
			break;
		}
	s_free(s);
	return 0;
}
Пример #2
0
// NOTE,we assume this has directory info (including scripts/ or pkg/xx)
//      as well as ".ecl" on the end.
ref_ptr<EScriptProgram> find_script2( const ScriptDef& script, 
                                     bool complain_if_not_found,
                                     bool cache_script)
{
    ScriptStorage::iterator itr = scrstore.find( script.c_str() );
    if (itr != scrstore.end())
        return (*itr).second;

    ref_ptr<EScriptProgram> program( new EScriptProgram );
    program->pkg = script.pkg();
    
    if (program->read( script.c_str() ) != 0)
    {
        if (complain_if_not_found)
        {
            cerr << "Unable to read script '" << script.name() << "'" << endl;
            Log( "Unable to read script '%s'\n", script.c_str() );
        }
        return ref_ptr<EScriptProgram>(0);
    }

    if (cache_script)
    {
        string tmpname = script.name();
        mklower( tmpname );
        scrstore.insert( ScriptStorage::value_type( tmpname.c_str(), program ) );
    }

    return program;
}
Пример #3
0
/*
 * Search for expanded name from a list of previously compressed names.
 * Return the offset from msg if found or -1.
 * dnptrs is the pointer to the first name on the list,
 * not the pointer to the start of the message.
 */
static int dn_find (u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr)
{
    u_char **cpp;

    for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
        u_char *dn = exp_dn;
        u_char *sp = *cpp;
        u_char *cp = *cpp;
        int     n;

        while ((n = *cp++) != 0) {
            /*
             * check for indirection
             */
            switch (n & INDIR_MASK) {
            case 0:    /* normal case, n == len */
                while (--n >= 0) {
                    if (*dn == '.')
                        goto next;
                    if (*dn == '\\')
                        dn++;
                    if (mklower(*dn++) != mklower(*cp++))
                        goto next;
                }
                if ((n = *dn++) == '\0' && *cp == '\0')
                    return (sp - msg);
                if (n == '.')
                    continue;
                goto next;

            case INDIR_MASK:  /* indirection */
                cp = msg + (((n & 0x3f) << 8) | *cp);
                break;

            default:          /* illegal type */
                return (-1);
            }
        }
        if (*dn == '\0')
            return (sp - msg);
next:
        ;
    }
    return (-1);
}
Пример #4
0
/*
 * getfile()
 *
 * char fname[];	file name to find
 * int lockfl;		check the file for locks?
 */
int getfile(char *fname, int lockfl)
{
	struct buffer *bp;
	struct line *lp;
	int i;
	int s;
	char bname[NBUFN];	/* buffer name to put file */

#if	MSDOS
	mklower(fname);		/* msdos isn't case sensitive */
#endif
	for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
		if ((bp->b_flag & BFINVS) == 0
		    && strcmp(bp->b_fname, fname) == 0) {
			swbuffer(bp);
			lp = curwp->w_dotp;
			i = curwp->w_ntrows / 2;
			while (i-- && lback(lp) != curbp->b_linep)
				lp = lback(lp);
			curwp->w_linep = lp;
			curwp->w_flag |= WFMODE | WFHARD;
			cknewwindow();
			mlwrite("(Old buffer)");
			return TRUE;
		}
	}
	makename(bname, fname);	/* New buffer name.     */
	while ((bp = bfind(bname, FALSE, 0)) != NULL) {
		/* old buffer name conflict code */
		s = mlreply("Buffer name: ", bname, NBUFN);
		if (s == ABORT)	/* ^G to just quit      */
			return s;
		if (s == FALSE) {	/* CR to clobber it     */
			makename(bname, fname);
			break;
		}
	}
	if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
		mlwrite("Cannot create buffer");
		return FALSE;
	}
	if (--curbp->b_nwnd == 0) {	/* Undisplay.           */
		curbp->b_dotp = curwp->w_dotp;
		curbp->b_doto = curwp->w_doto;
		curbp->b_markp = curwp->w_markp;
		curbp->b_marko = curwp->w_marko;
	}
	curbp = bp;		/* Switch to it.        */
	curwp->w_bufp = bp;
	curbp->b_nwnd++;
	s = readin(fname, lockfl);	/* Read it in.          */
	cknewwindow();
	return s;
}
Пример #5
0
/*
 *  simplify an address, reduce to a domain
 */
static String*
simplify(char *addr)
{
	int dots, dotlim;
	char *p, *at;
	String *s;

	mklower(addr);
	at = strchr(addr, '@');
	if(at == nil){
		/* local address, make it an exact match */
		s = s_copy("=");
		s_append(s, addr);
		return s;
	}

	/* copy up to, and including, the '@' sign */
	at++;
	s = s_copy("~");
	for(p = addr; p < at; p++){
		if(strchr(".*+?(|)\\[]^$", *p))
			s_putc(s, '\\');
		s_putc(s, *p);
	}

	/*
	 * just any address matching the two most significant domain elements,
	 * except for .uk, which needs three.
	 */
	s_append(s, "(.*\\.)?");
	p = addr+strlen(addr);			/* point at NUL */
	if (p[-1] == '.')
		*--p = '\0';
	if (p - addr > 3 && strcmp(".uk", p - 3) == 0)
		dotlim = 3;
	else
		dotlim = 2;
	dots = 0;
	while(--p > at)
		if(*p == '.' && ++dots >= dotlim){
			p++;
			break;
		}
	for(; *p; p++){
		if(strchr(".*+?(|)\\[]^$", *p) != nil)
			s_putc(s, '\\');
		s_putc(s, *p);
	}
	s_terminate(s);

	return s;
}
Пример #6
0
void
afs_string_to_key(char *str, char *cell, DES_cblock *key)
{
    char realm[REALM_SZ+1];
    strncpy(realm, cell, REALM_SZ);
    realm[REALM_SZ] = 0;
    mklower(realm);

    if (strlen(str) > 8)
        afs_transarc_StringToKey (str, realm, key);
    else
        afs_cmu_StringToKey (str, realm, key);
}
Пример #7
0
/*
 *  simplify an address, reduce to a domain
 */
static String*
simplify(char *addr)
{
	int dots;
	char *p, *at;
	String *s;

	mklower(addr);
	at = strchr(addr, '@');
	if(at == nil){
		/* local address, make it an exact match */
		s = s_copy("=");
		s_append(s, addr);
		return s;
	}

	/* copy up to the '@' sign */
	at++;
	s = s_copy("~");
	for(p = addr; p < at; p++){
		if(strchr(".*+?(|)\\[]^$", *p))
			s_putc(s, '\\');
		s_putc(s, *p);
	}

	/* just any address matching the two most significant domain elements */
	s_append(s, "(.*\\.)?");
	p = addr+strlen(addr);
	dots = 0;
	for(; p > at; p--){
		if(*p != '.')
			continue;
		if(dots++ > 0){
			p++;
			break;
		}
	}
	for(; *p; p++){
		if(strchr(".*+?(|)\\[]^$", *p) != 0)
			s_putc(s, '\\');
		s_putc(s, *p);
	}
	s_terminate(s);

	return s;
}
Пример #8
0
ref_ptr<EScriptProgram> find_script( const std::string& name, 
                                     bool complain_if_not_found,
                                     bool cache_script)
{
    ScriptStorage::iterator itr = scrstore.find( name.c_str() );
    if (itr != scrstore.end())
    {
        if (cache_script)
        {
            return (*itr).second;
        }
        else
        {
            ref_ptr<EScriptProgram> res( (*itr).second );
            scrstore.erase( itr );
            return res;
        }
    }

    ref_ptr<EScriptProgram> program( new EScriptProgram );
    string pathname = "scripts/";
    pathname += name.c_str();
    if (name.find(".ecl") == string::npos)
        pathname += ".ecl";
    
    if (program->read( pathname.c_str() ) != 0)
    {
        if (complain_if_not_found)
        {
            cerr << "Unable to read script '" << pathname.c_str() << "'" << endl;
            Log( "Unable to read script '%s'\n", pathname.c_str() );
        }
        return ref_ptr<EScriptProgram>(0);
    }

    if (cache_script)
    {
        string tmpname = name;
        mklower( tmpname );
        scrstore.insert( ScriptStorage::value_type( tmpname.c_str(), program ) );
    }

    return program;
}
Пример #9
0
/*
 *  patterns are either
 *	~ regular expression
 *	= exact match string
 *
 *  all comparisons are case insensitive
 */
static int
readpatterns(char *path)
{
	Biobuf *b;
	char *p;
	char *token[2];
	int n;
	int bang;

	b = Bopen(path, OREAD);
	if(b == nil)
		return -1;
	while((p = Brdline(b, '\n')) != nil){
		p[Blinelen(b)-1] = 0;
		n = tokenize(p, token, 2);
		if(n == 0)
			continue;

		mklower(token[0]);
		p = token[0];
		if(*p == '!'){
			p++;
			bang = 1;
		} else
			bang = 0;

		if(*p == '='){
			if(newpattern(Texact, p+1, bang) < 0)
				return -1;
		} else if(*p == '~'){
			if(newpattern(Tregexp, p+1, bang) < 0)
				return -1;
		} else if(strcmp(token[0], "#include") == 0 && n == 2)
			readpatterns(token[1]);
	}
	Bterm(b);
	return 0;
}
Пример #10
0
/*
 *  link patterns in order
 */
static int
newpattern(int type, char *arg, int bang)
{
	Pattern *p;
	static Pattern *last;

	mklower(arg);

	p = mallocz(sizeof *p, 1);
	if(p == nil)
		return -1;
	if(type == Tregexp){
		p->arg = malloc(strlen(arg)+3);
		if(p->arg == nil){
			free(p);
			return -1;
		}
		p->arg[0] = 0;
		strcat(p->arg, "^");
		strcat(p->arg, arg);
		strcat(p->arg, "$");
	} else {
		p->arg = strdup(arg);
		if(p->arg == nil){
			free(p);
			return -1;
		}
	}
	p->type = type;
	p->bang = bang;
	if(last == nil)
		patterns = p;
	else
		last->next = p;
	last = p;

	return 0;
}
Пример #11
0
char *
vms2unix_path(char *dst, const char *src)
{
    char current[NFILEN];
    int need_dev = FALSE;
    int have_dev = FALSE;
    char tmp[NFILEN];
    char *output = dst;
    char *base = tmp;
    char *s = strcpy(tmp, src);	/* ... to permit src == dst */
    char *d;

    strip_version(s);

    /* look for node specification */
    if ((s = strchr(base, COLON)) != 0
	&& (s[1] == COLON)) {
	while (base < s) {
	    *dst++ = *base++;
	}
	*dst++ = '!';
	base += 2;
	need_dev = TRUE;
    }

    /*
     * Look for device specification.  If not found, see if the path must
     * begin at the top of the device.  In this case, it would be ambiguous
     * if no device is supplied.
     */
    if ((s = strchr(base, COLON)) != NULL) {
	*dst++ = SLASHC;
	while (base < s) {
	    *dst++ = *base++;
	}
	base++;			/* skip over ":" */
	have_dev = TRUE;
    } else if (need_dev
	       || ((base[0] == L_BLOCK)
		   && (base[1] != '-')
		   && (base[1] != PERIOD)
		   && (base[1] != R_BLOCK))) {	/* must supply a device */
	char *a = getcwd(current, NFILEN);
	char *b = strchr(a ? a : "?", COLON);
	if ((b != 0)
	    && (b[1] == COLON)) {	/* skip over node specification */
	    a = b + 2;
	    b = strchr(a, COLON);
	}
	if (b != 0) {
	    *dst++ = SLASHC;	/* begin the device */
	    while (a < b) {
		*dst++ = *a++;
	    }
	    have_dev = TRUE;
	}			/* else, no device in getcwd! */
    }

    /* translate directory-syntax */
    if ((s = strchr(base, L_BLOCK)) != NULL) {
	int bracketed = TRUE;
	if (s[1] == R_BLOCK) {
	    if (dst != output && *dst != SLASHC)
		*dst++ = SLASHC;
	    *dst++ = PERIOD;
	    if (s[2] != EOS)
		*dst++ = SLASHC;
	    s += 2;
	    d = s;
	    bracketed = FALSE;
	} else if (s[1] == PERIOD) {
	    if (have_dev && dst[-1] != SLASHC)
		*dst++ = SLASHC;
	    s += 2;
	    d = s;
	} else if (s[1] == '-' && strchr("-.]", s[2])) {
	    s++;
	    while (*s == '-') {
		s++;
		*dst++ = PERIOD;
		*dst++ = PERIOD;
		if (*s == PERIOD
		    && (s[1] == '-' || s[1] == R_BLOCK))
		    /* allow "-.-" */
		    s++;
		if (*s == '-')
		    *dst++ = SLASHC;
	    }
	    d = s;
	} else if (!strncmp(s + 1, RootDir, sizeof(RootDir) - 1)
		   && strchr(".]", s[sizeof(RootDir)])) {
	    s += sizeof(RootDir);
	    d = s;
	} else {
	    d = s;
	    *s++ = SLASHC;
	}
	/* expect s points to the last token before right-bracket */
	if (bracketed) {
	    while (*s && *s != R_BLOCK) {
		if (*s == PERIOD)
		    *s = SLASHC;
		s++;
	    }
	    if (*s)
		*s = s[1] ? SLASHC : EOS;
	}
    } else {
	if (have_dev && dst[-1] != SLASHC)
	    *dst++ = SLASHC;
	d = base;
    }

    /*
     * Copy the remainder of the string, trimming trailing "."
     */
    for (s = dst; *d; s++, d++) {
	*s = *d;
	if (*s == PERIOD && d[1] == EOS)
	    *s = EOS;
    }
    *s = EOS;

    s = vms_pathleaf(dst);

    /* SCCS hack */
    if (*s == '$') {
	*s++ = PERIOD;
    } else if (s[0] == 's' && s[1] == '$') {
	s[1] = PERIOD;
	s += 2;
    }

    return mklower(output);
}
Пример #12
0
/* loop through the names to be translated */
void
main(int argc, char *argv[])
{
	String *s;
	String *alias;		/* the alias for the name */
	char **names;		/* names of this system */
	String *files;		/* list of files to search */
	int i, rv;
	char *p;

	ARGBEGIN {
	case 'd':
		debug = 1;
		break;
	case 'f':
		from = 1;
		break;
	case 'n':
		namefiles = ARGF();
		break;
	} ARGEND
	if (chdir(UPASLIB) < 0) {
		perror("translate(chdir):");
		exit(1);
	}

	/* get environmental info */
	names = sysnames_read();
	files = getdbfiles();
	alias = s_new();

	/* loop through the names to be translated (from standard input) */
	for(i=0; i<argc; i++) {
		s = unescapespecial(s_copy(mklower(argv[i])));
		if(strchr(s_to_c(s), '!') == 0)
			rv = translate(s_to_c(s), names, files, alias);
		else
			rv = -1;
		if(from){
			if (rv >= 0 && *s_to_c(alias) != '\0'){
				p = strchr(s_to_c(alias), '\n');
				if(p)
					*p = 0;
				p = strchr(s_to_c(alias), '!');
				if(p) {
					*p = 0;
					print("%s", s_to_c(alias));
				} else {
					p = strchr(s_to_c(alias), '@');
					if(p)
						print("%s", p+1);
					else
						print("%s", s_to_c(alias));
				}
			}
		} else {
			if (rv < 0 || *s_to_c(alias) == '\0')
				print("local!%s\n", s_to_c(s));
			else {
				/* this must be a write, not a print */
				write(1, s_to_c(alias), strlen(s_to_c(alias)));
			}
		}
		s_free(s);
	}
	exits(0);
}
Пример #13
0
/*
 * Evaluate a function.
 *
 * @fname: name of function to evaluate.
 */
char *gtfun(char *fname)
{
	int fnum;	/* index to function to eval */
	int status;	/* return status */
	char *tsp;	/* temporary string pointer */
	char arg1[NSTRING];	/* value of first argument */
	char arg2[NSTRING];	/* value of second argument */
	char arg3[NSTRING];	/* value of third argument */
	static char result[2 * NSTRING];	/* string result */

	/* look the function up in the function table */
	fname[3] = 0;		/* only first 3 chars significant */
	mklower(fname);		/* and let it be upper or lower case */
	for (fnum = 0; fnum < ARRAY_SIZE(funcs); fnum++)
		if (strcmp(fname, funcs[fnum].f_name) == 0)
			break;

	/* return errorm on a bad reference */
	if (fnum == ARRAY_SIZE(funcs))
		return errorm;

	/* if needed, retrieve the first argument */
	if (funcs[fnum].f_type >= MONAMIC) {
		if ((status = macarg(arg1)) != TRUE)
			return errorm;

		/* if needed, retrieve the second argument */
		if (funcs[fnum].f_type >= DYNAMIC) {
			if ((status = macarg(arg2)) != TRUE)
				return errorm;

			/* if needed, retrieve the third argument */
			if (funcs[fnum].f_type >= TRINAMIC)
				if ((status = macarg(arg3)) != TRUE)
					return errorm;
		}
	}


	/* and now evaluate it! */
	switch (fnum) {
	case UFADD:
		return itoa(atoi(arg1) + atoi(arg2));
	case UFSUB:
		return itoa(atoi(arg1) - atoi(arg2));
	case UFTIMES:
		return itoa(atoi(arg1) * atoi(arg2));
	case UFDIV:
		return itoa(atoi(arg1) / atoi(arg2));
	case UFMOD:
		return itoa(atoi(arg1) % atoi(arg2));
	case UFNEG:
		return itoa(-atoi(arg1));
	case UFCAT:
		strcpy(result, arg1);
		return strcat(result, arg2);
	case UFLEFT:
		return strncpy(result, arg1, atoi(arg2));
	case UFRIGHT:
		return (strcpy(result,
			       &arg1[(strlen(arg1) - atoi(arg2))]));
	case UFMID:
		return (strncpy(result, &arg1[atoi(arg2) - 1],
				atoi(arg3)));
	case UFNOT:
		return ltos(stol(arg1) == FALSE);
	case UFEQUAL:
		return ltos(atoi(arg1) == atoi(arg2));
	case UFLESS:
		return ltos(atoi(arg1) < atoi(arg2));
	case UFGREATER:
		return ltos(atoi(arg1) > atoi(arg2));
	case UFSEQUAL:
		return ltos(strcmp(arg1, arg2) == 0);
	case UFSLESS:
		return ltos(strcmp(arg1, arg2) < 0);
	case UFSGREAT:
		return ltos(strcmp(arg1, arg2) > 0);
	case UFIND:
		return strcpy(result, getval(arg1));
	case UFAND:
		return ltos(stol(arg1) && stol(arg2));
	case UFOR:
		return ltos(stol(arg1) || stol(arg2));
	case UFLENGTH:
		return itoa(strlen(arg1));
	case UFUPPER:
		return mkupper(arg1);
	case UFLOWER:
		return mklower(arg1);
	case UFTRUTH:
		return ltos(atoi(arg1) == 42);
	case UFASCII:
		return itoa((int) arg1[0]);
	case UFCHR:
		result[0] = atoi(arg1);
		result[1] = 0;
		return result;
	case UFGTKEY:
		result[0] = tgetc();
		result[1] = 0;
		return result;
	case UFRND:
		return itoa((ernd() % abs(atoi(arg1))) + 1);
	case UFABS:
		return itoa(abs(atoi(arg1)));
	case UFSINDEX:
		return itoa(sindex(arg1, arg2));
	case UFENV:
#if	ENVFUNC
		tsp = getenv(arg1);
		return tsp == NULL ? "" : tsp;
#else
		return "";
#endif
	case UFBIND:
		return transbind(arg1);
	case UFEXIST:
		return ltos(fexist(arg1));
	case UFFIND:
		tsp = flook(arg1, TRUE);
		return tsp == NULL ? "" : tsp;
	case UFBAND:
		return itoa(atoi(arg1) & atoi(arg2));
	case UFBOR:
		return itoa(atoi(arg1) | atoi(arg2));
	case UFBXOR:
		return itoa(atoi(arg1) ^ atoi(arg2));
	case UFBNOT:
		return itoa(~atoi(arg1));
	case UFXLATE:
		return xlat(arg1, arg2, arg3);
	}

	exit(-11);		/* never should get here */
}