evfuncs.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef CACA
#define _DEBUG2 1
#endif
/*
* Possible "if" states
*/
/*
*/
#define ANY_IF_STATE (IN_A_CONDITION | \
IN_A_THEN | \
IN_AN_ELSE | \
int in_an_if = 0; /* keeps track of if depth */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <termio.h>
#include "wish.h"
#include "eval.h"
#include "ctl.h"
#include "moremacros.h"
#include "message.h"
#include "interrupt.h"
#include "retcodes.h" /* abs */
#include "sizes.h"
extern void exit(); /* fmli's own exit routine */
/*
* return value of lastly executed command within an "if" statement
*/
#ifdef TEST
char *argv[];
{
}
mess_temp(s)
char *s;
{
}
mess_perm(s)
char *s;
{
}
#endif
int cmd_if();
int cmd_elif();
int argc;
char *argv[];
{
if (in_an_if <= 0) {
mess_temp("Syntax error - \"fi\" with no pending \"if\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"fi\" with no pending \"then\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
in_an_if--;
if (argc > 1) {
mess_temp("Syntax error - missing semi-colon after \"fi\" statement.");
mess_lock();
in_an_if = 0;
return FAIL;
}
return(Lastret);
}
int argc;
char *argv[];
{
if (in_an_if <= 0) {
mess_temp("Syntax error - \"then\" with no pending \"if\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"then\" within \"then\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"then\" within \"else\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"then\" without a preceeding \"if\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
/*
* If we are in an "elif" but are NOT evaluating its condition
* statement(s) (i.e., a previous "if" condition already evauated
* to true) ... then just return SUCCESS;
*/
return SUCCESS;
return SUCCESS;
}
int argc;
char *argv[];
{
if (in_an_if <= 0) {
mess_temp("Syntax error - \"else\" with no pending \"if\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"else\" within \"else\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"else\" with no pending \"then\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
return SUCCESS;
}
int argc;
char *argv[];
{
register int i;
register int len;
register char *crunch;
char *myargv[4];
char *strnsave();
len = 0;
for (i = 1; i < argc; i++)
for (i = 1; i < argc; i++) {
}
myargv[0] = "sh";
return i;
}
int argc;
char *argv[];
{
register char *p;
int pfd[2];
char *strchr();
unsigned char cc_vintr_sav = '\0';
bool changed_vintr = FALSE;
argv++;
#ifdef _DEBUG2
#endif
return FAIL;
/* if ((errfd = open(p = tmpnam(NULL), O_EXCL | O_CREAT | O_RDWR, 0600)) >= 0)
abs */
unlink(p);
else
return FAIL;
else
case -1:
return FAIL;
case 0: /* child */
close(1);
close(2);
{
close(0);
}
register int c;
exit(1);
close(0);
}
else /* hide the interrupt key */
{
{
}
}
perror("fmli");
This is fmli's exit not the C lib. call */
}
break;
default: /* parent (FMLI) */
{
register int c;
register int retval;
return FAIL;
/* the errno == EINTR is added below to check for
system interrupts like MAILCHECK that were terminating
the read in progress -- added 7/89 by njp */
{
errno = 0;
}
/****
if ((retval = waitspawn(pid)) && errfp != NULL && errstr != NULL)
{
char buf[MESSIZ];
if ((c = fread(buf, sizeof(char), MESSIZ-1, errfp)) > 0)
{
******/
/* for unknown reasons this never worked (returns c = 0) abs
if ((c = read(errfd, buf, sizeof(buf) - 1)) > 0) {
*/
/***** buf[c] = '\0';
if (p = strchr(buf, '\n'))
*p = '\0';
mess_temp(buf);
}
}
******/
/* reset the interrupt key */
if (changed_vintr == TRUE)
{
{
}
}
return retval;
}
break;
}
/*
* lint will complain about it, but there's actually no way to
* reach here because of the exit(), so this is not a return
* without an expression
*/
}
int argc;
char *argv[];
{
int wdwnum;
return SUCCESS;
}
int argc;
char *argv[];
{
int i;
long strtol();
char *bsd_path_to_title();
if (argc < 2)
return FAIL;
i = 1;
if (argc > 2) {
i++;
register char *p;
char *getepenv();
modes = 0775;
else
return FAIL;
} else
}
else
return SUCCESS;
}
int argc;
char *argv[];
{
register int i;
char *bsd_path_to_title();
if (argc < 2)
return FAIL;
mess_temp("WARNING: You are denying some permissions to yourself!");
char buf[20];
return(FAIL);
} else
return SUCCESS;
}
int Long_line = -1;
int argc;
char *argv[];
{
return(FAIL);
if (c == '\n') {
count = -1;
}
}
}
else if (Long_line < 0)
return(FAIL);
return SUCCESS;
}
int argc;
char *argv[];
{
char *p, *f;
char *path_to_full();
if (argc > 1)
else {
free(p);
}
return(FAIL);
free(f);
if (c == '\n') {
count = -1;
}
}
return SUCCESS;
}
int argc;
char *argv[];
{
register char *p;
register int i;
char *strrchr();
for (i = 1; i < argc; i++) {
if (i > 1)
*p = '\0';
return SUCCESS;
}
}
return SUCCESS;
}
#ifndef TEST
extern int cocreate();
extern int cosend();
extern int codestroy();
extern int cocheck();
extern int coreceive();
extern int genfind();
extern int cmd_pathconv();
#endif
extern int cmd_set();
extern int cmd_run();
extern int cmd_regex();
extern int cmd_getlist();
extern int cmd_setcolor();
extern int cmd_reinit();
extern int cmd_message();
extern int cmd_indicator();
extern int cmd_unset();
extern int cmd_getodi();
extern int cmd_setodi();
extern int cmd_cut();
extern int cmd_grep();
extern int cmd_test(); /* ehr3 */
extern int cmd_expr();
static struct {
char *name;
int (*function)();
} func[] = {
{ "extern", execute },
{ "shell", shell },
{ "regex", cmd_regex },
{ "echo", cmd_echo },
{ "fmlcut", cmd_cut },
{ "fmlgrep", cmd_grep },
{ "fmlexpr", cmd_expr },
{ "set", cmd_set },
{ "unset", cmd_unset },
{ "getmod", getmod },
{ "getodi", cmd_getodi },
{ "getfrm", get_wdw },
{ "setmod", setmod },
{ "setodi", cmd_setodi },
{ "readfile", read_file },
{ "longline", long_line },
{ "message", cmd_message },
{ "indicator", cmd_indicator },
{ "run", cmd_run },
{ "getitems", cmd_getlist },
{ "genfind", genfind },
{ "pathconv", cmd_pathconv },
{ "setcolor", cmd_setcolor},
{ "reinit", cmd_reinit},
/*
* not yet ...
*
{ "true", cmd_true},
{ "false", cmd_false},
*/
#ifndef TEST
{ "cocreate", cocreate },
{ "cosend", cosend },
{ "codestroy", codestroy },
{ "cocheck", cocheck },
{ "coreceive", coreceive }
#endif
};
int argc;
char *argv[];
{
register int n, ret;
int n2;
/* test moved to calling routine, SUCCESS is wrong here. abs
* if (argc < 1)
* return SUCCESS;
*/
for (n = 0; n < NUM_FUNCS; n++)
break;
if (n >= NUM_FUNCS)
n = 0;
if (in_an_if) {
switch(argv[0][0]) {
case 'i':
return ret;
}
break;
case 't':
return ret;
}
break;
case 'e':
return ret;
}
return ret;
}
break;
case 'f':
return ret;
}
break;
}
/*
AFTER checking for if-then-else stuff
we need to determine if we are in
executable code or not. We do this by
checking each prior level of nesting.
If any of them fails, then we know
we should not execute this command.
*/
/*
* The condition is TRUE ...
* skip the command if:
*
* we are in an "else"
*
* we are in an "elif" but a previous
* "if" or "elif" evaluated to true
*/
return SUCCESS;
} else {
/*
* The condition is FALSE ...
* skip the command if we are in
* a "then"
*/
return SUCCESS;
}
}
int cmd_rc;
else
return(cmd_rc);
} else {
/*
* Keep track of the return value from the
* lastly executed built-in/executable ...
*/
return(Lastret);
}
}
}
int argc;
char *argv[];
{
int n;
int n2;
in_an_if++;
if (in_an_if == MAX_IF_DEPTH) {
mess_temp("Internal error - \"if\" stack overflow");
mess_lock();
in_an_if = 0;
return FAIL;
}
return SUCCESS;
}
int argc;
char *argv[];
{
int n;
int n2;
if (in_an_if <= 0) {
mess_temp("Syntax error - \"elif\" with no pending \"if\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"elif\" after an \"else\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
mess_temp("Syntax error - \"elif\" with no pending \"then\"");
mess_lock();
in_an_if = 0;
return FAIL;
}
/*
* then don't evaluate the "elif" condition.
*/
}
else
return SUCCESS;
}
/*
* not yet ...
*
cmd_true(argc, argv, in, out, err)
int argc;
char *argv[];
IOSTRUCT *in;
IOSTRUCT *out;
IOSTRUCT *err;
{
return(SUCCESS);
}
cmd_false(argc, argv, in, out, err)
int argc;
char *argv[];
IOSTRUCT *in;
IOSTRUCT *out;
IOSTRUCT *err;
{
return(FAIL);
}
*/