Пример #1
0
        ////////////////////////////////////////////////////////////
        // PrepareConnect
        //
        void PrepareConnect()
        {
            log_trace("PrepareConnect");

            _server->registerMethod("boolean", *this, &BinRpcTest::boolean);

            // test connect using cxxtools::net::AddrInfo
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                client.prepareConnect(cxxtools::net::AddrInfo(_listen, _port));
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test connect using host and port
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                client.prepareConnect(_listen, _port);
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test connect using uri
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                std::ostringstream uri;
                uri << "bin://localhost:" << _port << '/';
                client.prepareConnect(cxxtools::net::Uri(uri.str()));
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test failing connect in connect
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                CXXTOOLS_UNIT_ASSERT_NOTHROW(client.prepareConnect(_listen, _port + 1));
                CXXTOOLS_UNIT_ASSERT_THROW(client.connect(), cxxtools::IOError);
            }

            // test failing connect when calling function
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");
                CXXTOOLS_UNIT_ASSERT_NOTHROW(client.prepareConnect(_listen, _port + 1));

                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_THROW(boolean.end(2000), cxxtools::IOError);
            }

        }
Пример #2
0
/*
 * ****TIPOUT   TIPOUT****
 */
void
tipout(void)
{
	char buf[BUFSIZ];
	char *cp;
	int cnt;
	int omask;

	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGEMT, intEMT);		/* attention from TIPIN */
	signal(SIGTERM, intTERM);	/* time to go signal */
	signal(SIGIOT, intIOT);		/* scripting going on signal */
	signal(SIGHUP, intTERM);	/* for dial-ups */
	signal(SIGSYS, intSYS);		/* beautify toggle */
	(void) setjmp(sigbuf);
	for (omask = 0;; sigsetmask(omask)) {
		cnt = read(FD, buf, BUFSIZ);
		if (cnt <= 0) {
			/* lost carrier */
			if (cnt < 0 && errno == EIO) {
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			} else if (cnt == 0 && errno == ENOENT) {
				if (getppid() != 1)
					kill(getppid(),SIGUSR1);
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			} else if (cnt < 0) {
				if (getppid() != 1)
					kill(getppid(),SIGUSR1);
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			}
			continue;
		}
#define	ALLSIGS	sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
		omask = sigblock(ALLSIGS);
		for (cp = buf; cp < buf + cnt; cp++)
			*cp &= 0177;
		if (write(1, buf, cnt) < 0)
			exit(1);
		if (boolean(value(SCRIPT)) && fscript != NULL) {
			if (!boolean(value(BEAUTIFY))) {
				fwrite(buf, 1, cnt, fscript);
				continue;
			}
			for (cp = buf; cp < buf + cnt; cp++)
				if ((*cp >= ' ' && *cp <= '~') ||
				    any(*cp, value(EXCEPTIONS)))
					putc(*cp, fscript);
		}
	}
}
Пример #3
0
inline boolean empty_output_buffer (j_compress_ptr cinfo)
{
    dest_mgr * dest = reinterpret_cast<dest_mgr*>(cinfo->dest);
    dest->out->write((char*)dest->buffer, BUFFER_SIZE);
    if (!*(dest->out)) return boolean(0);
    dest->pub.next_output_byte = dest->buffer;
    dest->pub.free_in_buffer = BUFFER_SIZE;
    return boolean(1);
}
Пример #4
0
Eval prim_p_atom(Expr e) {
	while(e.type == PAIR) {
		if(e.pair[0].type == PAIR || e.pair[0].type == ENVIRONMENT || e.pair[0].type == ARRAY)
			return final_eval(boolean(false));
		e = e.pair[1];
	}
	if(e.type != NIL)
		error(L"Malformed list");
	return final_eval(boolean(true));
}
Пример #5
0
cons_t* proc_finitep(cons_t* p, environment_t*)
{
  assert_length(p, 1);
  assert_number(car(p));

  if ( type_of(car(p)) == INTEGER )
    return boolean(true);

  return boolean(std::isfinite(car(p)->number.real));
}
Пример #6
0
cons_t* proc_infinitep(cons_t* p, environment_t*)
{
  assert_length(p, 1);
  assert_number(car(p));

  if ( type_of(car(p)) == INTEGER )
    return boolean(false);

  return boolean(std::fpclassify(car(p)->number.real) == FP_INFINITE);
}
Пример #7
0
cons_t* proc_nanp(cons_t* p, environment_t*)
{
  assert_length(p, 1);
  assert_number(car(p));

  if ( realp(car(p)) )
    return boolean(std::isnan(car(p)->number.real));

  return boolean(false);
}
Пример #8
0
Eval prim_lesser_eq(Expr args) {
	Expr before = take_typed(&args, NUMBER), k;
	while(maybe_take_typed(&args, &k, NUMBER)) {
		if(!(mpq_cmp(before.num, k.num) <= 0))
			return final_eval(boolean(false));
		before = k;
	}
	
	return final_eval(boolean(true));
}
Пример #9
0
void stmt(){
	int l = label;
	int t;
	int br;
	switch(look->tag){
		case ';':
			move();
			break;
		case IF:     // if(x) s1  or  if(x) s1 else s2
			match(IF);
			match('(');
			t = boolean();
			match(')');
			gen("if false t%d goto L%d\n",t,l);
			stmt();
			gen("L%d:\n",label++);
			if(look->tag != ELSE)
				break;
			match(ELSE);
			stmt();
			break;
		case WHILE:
			match(WHILE);
			match('(');
			t = boolean();
			match(')');
			gen("L%d:\n",label++);
			stmt();
			gen("if true t%d goto L%d\n",t,l);
			gen("L%d:\n",label++);
			br = label;
			break;
		case DO:
			match(DO);
			gen("L%d:\n",label++);
			stmt();
			match(WHILE);
			match('(');
			t = boolean();
			match(')');
			match(';');
			gen("if true t%d goto L%d\n",t,l);
			break;
		case BREAK:
			match(BREAK);
			gen("goto L%d\n",br);
			match(';');
		case '{':
			block();
			break;
		default:
			assign();
			break;
	}
}
Пример #10
0
/*ARGSUSED*/
void
variable(int c)
{
	char	buf[256];

	if (prompt("[set] ", buf, sizeof(buf)))
		return;
	vlex(buf);
	if (vtable[BEAUTIFY].v_access&CHANGED) {
		vtable[BEAUTIFY].v_access &= ~CHANGED;
		kill(tipout_pid, SIGSYS);
	}
	if (vtable[SCRIPT].v_access&CHANGED) {
		vtable[SCRIPT].v_access &= ~CHANGED;
		setscript();
		/*
		 * So that "set record=blah script" doesn't
		 *  cause two transactions to occur.
		 */
		if (vtable[RECORD].v_access&CHANGED)
			vtable[RECORD].v_access &= ~CHANGED;
	}
	if (vtable[RECORD].v_access&CHANGED) {
		vtable[RECORD].v_access &= ~CHANGED;
		if (boolean(value(SCRIPT)))
			setscript();
	}
	if (vtable[TAND].v_access&CHANGED) {
		vtable[TAND].v_access &= ~CHANGED;
		if (boolean(value(TAND)))
			tandem("on");
		else
			tandem("off");
	}
	if (vtable[LECHO].v_access&CHANGED) {
		vtable[LECHO].v_access &= ~CHANGED;
		HD = boolean(value(LECHO));
	}
	if (vtable[PARITY].v_access&CHANGED) {
		vtable[PARITY].v_access &= ~CHANGED;
		setparity(NOSTR);
	}
	if (vtable[HARDWAREFLOW].v_access&CHANGED) {
		vtable[HARDWAREFLOW].v_access &= ~CHANGED;
		if (boolean(value(HARDWAREFLOW)))
			hardwareflow("on");
		else
			hardwareflow("off");
	}
	if (vtable[LINEDISC].v_access&CHANGED) {
		vtable[LINEDISC].v_access &= ~CHANGED;
		linedisc(NOSTR);
	}
}
Пример #11
0
/* ARGSUSED */
void
variable(int cc)
{
	char	buf[256];

	if (prompt("[set] ", buf, sizeof (buf)))
		return;
	vlex(buf);
	if (vtable[BEAUTIFY].v_access&CHANGED) {
		vtable[BEAUTIFY].v_access &= ~CHANGED;
		(void) kill(pid, SIGSYS);
	}
	if (vtable[SCRIPT].v_access&CHANGED) {
		vtable[SCRIPT].v_access &= ~CHANGED;
		setscript();
		/*
		 * So that "set record=blah script" doesn't
		 *  cause two transactions to occur.
		 */
		if (vtable[RECORD].v_access&CHANGED)
			vtable[RECORD].v_access &= ~CHANGED;
	}
	if (vtable[RECORD].v_access&CHANGED) {
		vtable[RECORD].v_access &= ~CHANGED;
		if (boolean(value(SCRIPT)))
			setscript();
	}
	if (vtable[TAND].v_access&CHANGED) {
		vtable[TAND].v_access &= ~CHANGED;
		if (boolean(value(TAND)))
			tandem("on");
		else
			tandem("off");
	}
	if (vtable[LECHO].v_access&CHANGED) {
		vtable[LECHO].v_access &= ~CHANGED;
		boolean(value(HALFDUPLEX)) = boolean(value(LECHO));
	}
	if (vtable[PARITY].v_access&CHANGED) {
		vtable[PARITY].v_access &= ~CHANGED;
		setparity(NULL);
	}
	if (vtable[BAUDRATE].v_access&CHANGED) {
		vtable[BAUDRATE].v_access &= ~CHANGED;
		ttysetup(speed(number(value(BAUDRATE))));
	}
	if (vtable[HARDWAREFLOW].v_access & CHANGED) {
		vtable[HARDWAREFLOW].v_access &= ~CHANGED;
		if (boolean(value(HARDWAREFLOW)))
			hardwareflow("on");
		else
			hardwareflow("off");
	}
}
Пример #12
0
ATrans *boolean(Node *p) /* computes the transitions to boolean nodes -> next & init */
{
  ATrans *t1, *t2, *lft, *rgt, *result = (ATrans *)0;
  int id;
  switch(p->ntyp) {
  case TRUE:
    result = emalloc_atrans();
    clear_set(result->to,  0);
    clear_set(result->pos, 1);
    clear_set(result->neg, 1);
  case FALSE:
    break;
  case AND:
    lft = boolean(p->lft);
    rgt = boolean(p->rgt);
    for(t1 = lft; t1; t1 = t1->nxt) {
      for(t2 = rgt; t2; t2 = t2->nxt) {
	ATrans *tmp = merge_trans(t1, t2);
	if(tmp) {
	  tmp->nxt = result;
	  result = tmp;
	}
      }
    }
    free_atrans(lft, 1);
    free_atrans(rgt, 1);
    break;
  case OR:
    lft = boolean(p->lft);
    for(t1 = lft; t1; t1 = t1->nxt) {
      ATrans *tmp = dup_trans(t1);
      tmp->nxt = result;
      result = tmp;
    }
    free_atrans(lft, 1);
    rgt = boolean(p->rgt);
    for(t1 = rgt; t1; t1 = t1->nxt) {
      ATrans *tmp = dup_trans(t1);
      tmp->nxt = result;
      result = tmp;
    }
    free_atrans(rgt, 1);
    break;
  default:
    build_alternating(p);
    result = emalloc_atrans();
    clear_set(result->to,  0);
    clear_set(result->pos, 1);
    clear_set(result->neg, 1);
    add_set(result->to, already_done(p));
  }
  return result;
}
Пример #13
0
long
hunt(char *name)
{
	char *cp;
	sig_t f;

	f = signal(SIGALRM, dead);
	while ((cp = getremote(name))) {
		deadfl = 0;
		uucplock = strrchr(cp, '/');
		if (uucplock == NULL)
			uucplock = cp;
		else
			uucplock++;

		if (uu_lock(uucplock) < 0)
			continue;
		/*
		 * Straight through call units, such as the BIZCOMP,
		 * VADIC and the DF, must indicate they're hardwired in
		 *  order to get an open file descriptor placed in FD.
		 * Otherwise, as for a DN-11, the open will have to
		 *  be done in the "open" routine.
		 */
		if (!HW)
			break;
		if (setjmp(deadline) == 0) {
			alarm(10);
			FD = open(cp, (O_RDWR |
			    (boolean(value(DC)) ? O_NONBLOCK : 0)));
		}
		alarm(0);
		if (FD < 0) {
			perror(cp);
			deadfl = 1;
		}
		if (!deadfl) {
			struct termios cntrl;

			tcgetattr(FD, &cntrl);
			if (!boolean(value(DC)))
				cntrl.c_cflag |= HUPCL;
			tcsetattr(FD, TCSAFLUSH, &cntrl);
			ioctl(FD, TIOCEXCL, 0);
			signal(SIGALRM, SIG_DFL);
			return ((long)cp);
		}
		(void)uu_unlock(uucplock);
	}
	signal(SIGALRM, f);
	return (deadfl ? -1 : (long)cp);
}
Пример #14
0
void do_delwin(state *st) {
  long slot;
  ei_decode_long(st->args, &(st->index), &slot);
  if (slot == 0) {
    boolean(st, FALSE);
  } else if (st->win[slot] == NULL) {
    boolean(st, FALSE);
  } else if (st->win[slot] != NULL) {
    delwin(st->win[slot]);
    st->win[slot] = NULL;
    boolean(st, TRUE);
  }
}
Пример #15
0
/*
 * Dial up on a BIZCOMP Model 1022 with either
 * 	tone dialing (mod = "V")
 *	pulse dialing (mod = "W")
 */
static int
biz_dialer(char *num, char *mod)
{
	int connected = 0;
	char cbuf[40];

	if (boolean(value(VERBOSE)))
		printf("\nstarting call...");
	/*
	 * Disable auto-answer and configure for tone/pulse
	 *  dialing
	 */
	if (cmd("\02K\r")) {
		printf("can't initialize bizcomp...");
		return (0);
	}
	strcpy(cbuf, "\02.\r");
	cbuf[1] = *mod;
	if (cmd(cbuf)) {
		printf("can't set dialing mode...");
		return (0);
	}
	strcpy(cbuf, "\02D");
	strcat(cbuf, num);
	strcat(cbuf, "\r");
	write(FD, cbuf, strlen(cbuf));
	if (!detect("7\r")) {
		printf("can't get dial tone...");
		return (0);
	}
	if (boolean(value(VERBOSE)))
		printf("ringing...");
	/*
	 * The reply from the BIZCOMP should be:
	 *	2 \r or 7 \r	failure
	 *	1 \r		success
	 */
	connected = detect("1\r");
#if ACULOG
	if (timeout) {
		char line[80];

		sprintf(line, "%d second dial timeout",
			number(value(DIALTIMEOUT)));
		logent(value(HOST), num, "biz1022", line);
	}
#endif
	if (timeout)
		biz22_disconnect();	/* insurance */
	return (connected);
}
Пример #16
0
void builtin_nilp(struct Value *argument, struct Value *env,
  struct Value **out)
{
  struct Value *exp;
  (void) env;
  exp = ((struct Pair*)argument->value)->car;
  evaluate(exp, env, &exp);
  if (exp->type == NIL)
  {
    *out = boolean(1);
    return;
  }
  *out = boolean(0);
}
Пример #17
0
RCP<const Boolean> Interval::contains(const RCP<const Basic> &a) const
{
    if (not is_a_Number(*a))
        return make_rcp<Contains>(a, rcp_from_this_cast<const Set>());
    if ((eq(*start_, *a) and left_open_) or (eq(*end_, *a) and right_open_))
        return boolean(false);
    if (eq(*start_, *a) or eq(*end_, *a))
        return boolean(true);
    if (eq(*min({end_, a}), *end_))
        return boolean(false);
    if (eq(*max({start_, a}), *start_))
        return boolean(false);
    return boolean(true);
}
Пример #18
0
/*
 * ****TIPIN   TIPIN****
 */
static void
tipin(void)
{
	int bol = 1;
	int gch;
	char ch;

	/*
	 * Kinda klugey here...
	 *   check for scripting being turned on from the .tiprc file,
	 *   but be careful about just using setscript(), as we may
	 *   send a SIGEMT before tipout has a chance to set up catching
	 *   it; so wait a second, then setscript()
	 */
	if (boolean(value(SCRIPT))) {
		sleep(1);
		setscript();
	}

	while (1) {
		gch = getchar()&STRIP_PAR;
		/* XXX does not check for EOF */
		if ((gch == character(value(ESCAPE))) && bol) {
			if (!noesc) {
				if (!(gch = escape()))
					continue;
			}
		} else if (!cumode && gch == character(value(RAISECHAR))) {
			setboolean(value(RAISE), !boolean(value(RAISE)));
			continue;
		} else if (gch == '\r') {
			bol = 1;
			ch = gch;
			parwrite(FD, &ch, 1);
			if (boolean(value(HALFDUPLEX)))
				printf("\r\n");
			continue;
		} else if (!cumode && gch == character(value(FORCE)))
			gch = getchar()&STRIP_PAR;
		bol = any(gch, value(EOL));
		if (boolean(value(RAISE)) && islower(gch))
			gch = toupper(gch);
		ch = gch;
		parwrite(FD, &ch, 1);
		if (boolean(value(HALFDUPLEX)))
			printf("%c", ch);
	}
}
Пример #19
0
/*
 * Dial up on a BIZCOMP Model 1031 with either
 * 	tone dialing (mod = "f")
 *	pulse dialing (mod = "w")
 */
static int
biz_dialer(char *num, char *mod)
{
	int connected = 0;

	if (!bizsync(FD)) {
		logent(value(HOST), "", "biz", "out of sync");
		(void) printf("bizcomp out of sync\n");
		delock(uucplock);
		exit(0);
	}
	if (boolean(value(VERBOSE)))
		(void) printf("\nstarting call...");
	echo("#\rk$\r$\n");			/* disable auto-answer */
	echo("$>$.$ #\r");			/* tone/pulse dialing */
	echo(mod);
	echo("$\r$\n");
	echo("$>$.$ #\re$ ");			/* disconnection sequence */
	echo(DISCONNECT_CMD);
	echo("\r$\n$\r$\n");
	echo("$>$.$ #\rr$ ");			/* repeat dial */
	echo(num);
	echo("\r$\n");
	if (boolean(value(VERBOSE)))
		(void) printf("ringing...");
	/*
	 * The reply from the BIZCOMP should be:
	 *	`^G NO CONNECTION\r\n^G\r\n'	failure
	 *	` CONNECTION\r\n^G'		success
	 */
	connected = detect(" ");
#ifdef ACULOG
	if (timeout) {
		char line[80];

		(void) sprintf(line, "%d second dial timeout",
		    number(value(DIALTIMEOUT)));
		logent(value(HOST), num, "biz", line);
	}
#endif
	if (!connected)
		flush(" NO CONNECTION\r\n\07\r\n");
	else
		flush("CONNECTION\r\n\07");
	if (timeout)
		biz31_disconnect();	/* insurance */
	return (connected);
}
Пример #20
0
static int
gobble(char match, char response[])
{
	char *cp = response;
	sig_t f;
	char c;

	f = signal(SIGALRM, sigALRM);
	dialtimeout = 0;
	do {
		if (setjmp(timeoutbuf)) {
			signal(SIGALRM, f);
			*cp = '\0';
			return (0);
		}
		alarm(number(value(DIALTIMEOUT)));
		read(FD, cp, 1);
		alarm(0);
		c = (*cp++ &= 0177);
#ifdef notdef
		if (boolean(value(VERBOSE)))
			putchar(c);
#endif
	} while (c != '\n' && c != match);
	signal(SIGALRM, SIG_DFL);
	*cp = '\0';
	return (c == match);
}
Пример #21
0
/*
 * Hash a term.
 */
extern hash_t hash_term(term_t t)
{
    switch (type(t))
    {
        case VAR:
            return hash_var(var(t));
        case NIL:
            return hash_nil();
        case BOOL:
            return hash_bool(boolean(t));
        case NUM:
            return hash_num(num(t));
        case ATOM:
            return hash_atom(atom(t));
        case STR:
            return hash_string(string(t));
        case FOREIGN:
            return hash_foreign(foreign(t));
        case FUNC:
            return hash_func(func(t));
        default:
        {
            hash_t dummy = HASH(0, 0);
            return dummy;
        }
    }
}
/**
 *  Turn into a Php::Value
 *  @return Php::Value
 */
Php::Value Array::phpValue() const
{
    // create an output value
    Php::Value output;

    // loop over the entire array
    for (int i = 0; i < size(); ++i)
    {
        // switch through all the types and add them to the php value
        switch (type(i))
        {
        case JSON::Type::Null:    output.set(i, nullptr);              break;
        case JSON::Type::Boolean: output.set(i, boolean(i));           break;
        case JSON::Type::Decimal: output.set(i, decimal(i));           break;
        case JSON::Type::Integer: output.set(i, integer(i));           break;
        case JSON::Type::String:  output.set(i, c_str(i));             break;
        case JSON::Type::Array:   output.set(i, array(i).phpValue());  break;
        case JSON::Type::Object:  output.set(i, object(i).phpValue()); break;
        default:                                                       break;
        }
    }

    // return our output
    return output;
}
Пример #23
0
void Boolean::execute(QScriptContextPrivate *context)
{
#ifndef Q_SCRIPT_NO_EVENT_NOTIFY
    engine()->notifyFunctionEntry(context);
#endif
    bool value;
    if (context->argumentCount() > 0)
        value = context->argument(0).toBoolean();
    else
        value = false;

    QScriptValueImpl boolean(engine(), value);
    if (!context->isCalledAsConstructor()) {
        context->setReturnValue(boolean);
    } else {
        QScriptValueImpl &obj = context->m_thisObject;
        obj.setClassInfo(classInfo());
        obj.setInternalValue(boolean);
        obj.setPrototype(publicPrototype);
        context->setReturnValue(obj);
    }
#ifndef Q_SCRIPT_NO_EVENT_NOTIFY
    engine()->notifyFunctionExit(context);
#endif
}
Пример #24
0
/*
 * FTP - send single character
 *  wait for echo & handle timeout
 */
static void
send(char c)
{
	char cc;
	int retry = 0;

	cc = c;
	xpwrite(FD, &cc, 1);
	if (number(value(CDELAY)) > 0 && c != '\r')
		nap(number(value(CDELAY)));
	if (!boolean(value(ECHOCHECK))) {
		if (number(value(LDELAY)) > 0 && c == '\r')
			nap(number(value(LDELAY)));
		return;
	}
tryagain:
	timedout = 0;
	alarm(number(value(ETIMEOUT)));
	read(FD, &cc, 1);
	alarm(0);
	if (timedout) {
		printf("\r\ntimeout error (%s)\r\n", ctrl(c));
		if (retry++ > 3)
			return;
		xpwrite(FD, &null, 1); /* poke it */
		goto tryagain;
	}
}
Пример #25
0
/*
 * Cu-like put command
 */
void
cu_put(char cc)
{
	FILE *fd;
	char line[BUFSIZ];
	int argc;
	char *expand();
	char *copynamex;

	if (prompt("[put] ", copyname, sizeof(copyname)))
		return;
	if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) {
		printf("usage: <put> from [to]\r\n");
		return;
	}
	if (argc == 1)
		argv[1] = argv[0];
	copynamex = expand(argv[0]);
	if ((fd = fopen(copynamex, "r")) == NULL) {
		printf("%s: cannot open\r\n", copynamex);
		return;
	}
	if (boolean(value(ECHOCHECK)))
		snprintf(line, sizeof(line), "cat>%s\r", argv[1]);
	else
		snprintf(line, sizeof(line), "stty -echo;cat>%s;stty echo\r", argv[1]);
	transmit(fd, "\04", line);
}
Пример #26
0
/*
 * FTP - local ==> remote
 *  send local file to remote host
 *  terminate transmission with pseudo EOF sequence
 */
void
sendfile(char cc)
{
	FILE *fd;
	char *fnamex;
	char *expand();

	putchar(cc);
	/*
	 * get file name
	 */
	if (prompt("Local file name? ", fname, sizeof(fname)))
		return;

	/*
	 * look up file
	 */
	fnamex = expand(fname);
	if ((fd = fopen(fnamex, "r")) == NULL) {
		printf("%s: cannot open\r\n", fname);
		return;
	}
	transmit(fd, value(EOFWRITE), NULL);
	if (!boolean(value(ECHOCHECK))) {
		flush_remote ();
	}
}
Пример #27
0
/*
 * Query sizes of basic C data types.
 *
 */
extern "C" cons_t* proc_sizeof(cons_t* p, environment_t*)
{
  static struct {
    const char* name;
    size_t size;
  } sizes[] = {
    {"char", sizeof(char)},
    {"int", sizeof(int)},
    {"long", sizeof(long)},
    {"longlong", sizeof(long long)},
    {"pointer", sizeof(void*)}, // shorthand
    {"short", sizeof(short)},
    {"void*", sizeof(void*)},
    {NULL, 0}
  };

  assert_length(p, 1);
  assert_type(SYMBOL, car(p));

  std::string s = symbol_name(car(p));

  for ( size_t n=0; sizes[n].name != NULL; ++n )
    if ( s == sizes[n].name )
      return integer(sizes[n].size);

  // not found
  return boolean(false);
}
Пример #28
0
/*ARGSUSED*/
static void
intEMT(int signo)
{
	char c, line[256];
	char *pline = line;
	char reply;

	read(fildes[0], &c, 1);
	while (c != '\n' && (size_t)(pline - line) < sizeof(line)) {
		*pline++ = c;
		read(fildes[0], &c, 1);
	}
	*pline = '\0';
	if (boolean(value(SCRIPT)) && fscript != NULL)
		fclose(fscript);
	if (pline == line) {
		setboolean(value(SCRIPT), FALSE);
		reply = 'y';
	} else {
		if ((fscript = fopen(line, "a")) == NULL)
			reply = 'n';
		else {
			reply = 'y';
			setboolean(value(SCRIPT), TRUE);
		}
	}
	write(repdes[1], &reply, 1);
	longjmp(sigbuf, 1);
}
Пример #29
0
static void
unidialer_disconnect(void)
{
	int okay, retries;

	acu_flush (); /* flush any clutter */

	unidialer_tty_clocal (TRUE);

 	/* first hang up the modem*/
	ioctl (FD, TIOCCDTR, 0);
	acu_nap (250);
	ioctl (FD, TIOCSDTR, 0);

	/*
	 * If AT&D2, then dropping DTR *should* just hangup the modem. But
	 * some modems reset anyway; also, the modem may be programmed to reset
	 * anyway with AT&D3. Play it safe and wait for the full reset time before
	 * proceeding.
	 */
	acu_nap (reset_delay);

	if (!unidialer_waitfor_modem_ready (reset_delay))
	{
#ifdef DEBUG
			printf ("unidialer_disconnect: warning CTS low.\r\n");
#endif
	}

	/*
	 * If not strapped for DTR control, try to get command mode.
	 */
	for (retries = okay = 0; retries < MAXRETRY && !okay; retries++)
	{
		int timeout_value;
		/* flush any clutter */
		if (!acu_flush ())
		{
#ifdef DEBUG
			printf ("unidialer_disconnect: warning flush failed.\r\n");
#endif
		}
		timeout_value = escape_guard_time;
		timeout_value += (timeout_value * retries / MAXRETRY);
		acu_nap (timeout_value);
		acu_flush (); /* flush any clutter */
		unidialer_modem_cmd (FD, escape_sequence);
		acu_nap (timeout_value);
		unidialer_modem_cmd (FD, hangup_command);
		okay = unidialer_get_okay (reset_delay);
	}
	if (!okay)
	{
		logent(value(HOST), "", modem_name, "can't hang up modem");
		if (boolean(value(VERBOSE)))
			printf("hang up failed\n");
	}
	(void) acu_flush ();
	close (FD);
}
Пример #30
0
/*
 * FTP - local ==> remote
 *  send local file to remote host
 *  terminate transmission with pseudo EOF sequence
 */
void
sendfile(int c)
{
	FILE *fp;
	char *fnamex;

	putchar(c);
	/*
	 * get file name
	 */
	if (prompt("Local file name? ", fname, sizeof(fname)))
		return;

	/*
	 * look up file
	 */
	fnamex = expand(fname);
	if ((fp = fopen(fnamex, "r")) == NULL) {
		printf("%s: cannot open\r\n", fname);
		return;
	}
	transmit(fp, value(EOFWRITE), NULL);
	if (!boolean(value(ECHOCHECK)))
		tcdrain(FD);
}