Exemplo n.º 1
0
static char*
getrec(register Sfio_t* sp, register int delimiter, register int flags)
{
	register int	c;
	register char*	glob;

	sfstrseek(sp, 0, SEEK_SET);
	glob = ed.global;
	while ((c = getchr()) != delimiter) {
		if (c == '\n') {
			ed.peekc = c;
			break;
		}
		if (c == EOF) {
			if (glob)
				ed.peekc = (flags & REC_LINE) ? 0 : c;
			else if (delimiter != '\n' || (flags & (REC_LINE|REC_SPLICE)))
				error(2, "unexpected EOF");
			else if (flags & REC_TEXT)
				return 0;
			break;
		}
		if (c == '\\' && ((c = getchr()) != delimiter || (flags & REC_SPLICE) && c != '\n') && c && !(flags & REC_IGNORE))
			sfputc(sp, '\\');
		if (!c)
			error(1, "null character ignored");
		else if (!(flags & REC_IGNORE))
			sfputc(sp, c);
	}
	if (flags & REC_TERMINATE)
		sfputc(sp, c);
	if (!(glob = sfstruse(sp)))
		error(ERROR_SYSTEM|3, "out of space");
	return glob;
}
Exemplo n.º 2
0
/*FUNCTION*/
int c_equal(tpLspObject pLSP,
            LVAL p,
            LVAL q
  ){
/*noverbatim
CUT*/
  if( p == q ) return 1;
  if( gettype(p) != gettype(q) )return 0;
  switch( gettype(p) ){
    case NTYPE_CON:
      return equal(car(p),car(q)) && equal(cdr(p),cdr(q));
    case NTYPE_FLO:
      return getfloat(p)==getfloat(q);
    case NTYPE_INT:
      return getint(p)==getint(q);
    case NTYPE_STR:
      return  getstring(p) == getstring(q) ||
                       !strcmp(getstring(p),getstring(q));
    case NTYPE_SYM:
      return getsymbol(p) == getsymbol(q) ||
                 !strcmp(getsymbol(p),getsymbol(q));
    case NTYPE_CHR:
      return getchr(p) == getchr(q);
    default:
      return 0;
      break;
    }
  }
Exemplo n.º 3
0
Arquivo: melody.c Projeto: rdebath/sgt
static int gc (void) {
    char c;

    while (c = nd_getchr(), isspace(c))
	getchr();
    return getchr();
}
Exemplo n.º 4
0
/*
 * Get command character.
 * The character normally comes from the keyboard,
 * but may come from ungotten characters
 * (characters previously given to ungetcc or ungetsc).
 */
int
getcc(void)
{
	if (unget_end) {
		/*
		 * We have just run out of ungotten chars.
		 */
		unget_end = 0;
		if (len_cmdbuf() == 0 || !empty_screen())
			return (getchr());
		/*
		 * Command is incomplete, so try to complete it.
		 */
		switch (mca) {
		case A_DIGIT:
			/*
			 * We have a number but no command.  Treat as #g.
			 */
			return ('g');

		case A_F_SEARCH:
		case A_B_SEARCH:
			/*
			 * We have "/string" but no newline.  Add the \n.
			 */
			return ('\n');

		default:
			/*
			 * Some other incomplete command.  Let user complete it.
			 */
			return (getchr());
		}
	}

	if (ungot == NULL) {
		/*
		 * Normal case: no ungotten chars, so get one from the user.
		 */
		return (getchr());
	}

	/*
	 * Return the next ungotten char.
	 */
	{
		struct ungot *ug = ungot;
		int c = ug->ug_char;
		ungot = ug->ug_next;
		free(ug);
		unget_end = (ungot == NULL);
		return (c);
	}
}
Exemplo n.º 5
0
Arquivo: ed.c Projeto: 00001/plan9port
void
global(int k)
{
	Rune *gp, globuf[GBSIZE];
	int c, *a1;

	if(globp)
		error(Q);
	setwide();
	squeeze(dol > zero);
	c = getchr();
	if(c == '\n')
		error(Q);
	compile(c);
	gp = globuf;
	while((c=getchr()) != '\n') {
		if(c == EOF)
			error(Q);
		if(c == '\\') {
			c = getchr();
			if(c != '\n')
				*gp++ = '\\';
		}
		*gp++ = c;
		if(gp >= &globuf[GBSIZE-2])
			error(Q);
	}
	if(gp == globuf)
		*gp++ = 'p';
	*gp++ = '\n';
	*gp = 0;
	for(a1=zero; a1<=dol; a1++) {
		*a1 &= ~01;
		if(a1 >= addr1 && a1 <= addr2 && match(a1) == k)
			*a1 |= 01;
	}

	/*
	 * Special case: g/.../d (avoid n^2 algorithm)
	 */
	if(globuf[0] == 'd' && globuf[1] == '\n' && globuf[2] == 0) {
		gdelete();
		return;
	}
	for(a1=zero; a1<=dol; a1++) {
		if(*a1 & 01) {
			*a1 &= ~01;
			dot = a1;
			globp = globuf;
			commands();
			a1 = zero;
		}
	}
}
Exemplo n.º 6
0
/*FUNCTION*/
LVAL c_char_upcase(tpLspObject pLSP,
                   LVAL p
  ){
/*noverbatim
CUT*/
  LVAL q;

  if( null(p) || !characterp(p) )return NIL;
  q = newchar();
  setchar(q, (isalpha(getchr(p)) && islower(getchr(p))) ?
          toupper((int) getchr(p)) : getchr(p));
  return q;
  }
Exemplo n.º 7
0
char *gets(char *s)
{
	char *p;

	p = s;

	while(1)
	{
		*p = getchr();
		if (*p == '\b')
		{
			if (p > s)
			{
				putchr('\b');
				putchr(' ');
				putchr('\b');
				p--;
			}
			continue;
		}
		else if (*p != '\r')
		{
			putchr(*p);
		}
		if (*p == '\r')
			break;
		p++;
	}
	*p = '\0';

	return s;
}
Exemplo n.º 8
0
Arquivo: ed.c Projeto: redox-os/libc
void error(char *s)
{
    int c;

    wrapp = 0;
    listf = 0;
    listn = 0;
    putchr('?');
    puts(s);
    count = 0;
    lseek(0, (long)0, 2);
    pflag = 0;
    if (globp)
        lastc = '\n';
    globp = 0;
    peekc = lastc;
    if(lastc)
        while ((c = getchr()) != '\n' && c != EOF)
            ;
    if (io > 0) {
        close(io);
        io = -1;
    }
    longjmp(savej, 1);
}
Exemplo n.º 9
0
Arquivo: ed.c Projeto: 00001/plan9port
void
error1(char *s)
{
	int c;

	wrapp = 0;
	listf = 0;
	listn = 0;
	count = 0;
	seek(0, 0, 2);
	pflag = 0;
	if(globp)
		lastc = '\n';
	globp = 0;
	peekc = lastc;
	if(lastc)
		for(;;) {
			c = getchr();
			if(c == '\n' || c == EOF)
				break;
		}
	if(io > 0) {
		close(io);
		io = -1;
	}
	putchr('?');
	putst(s);
}
Exemplo n.º 10
0
Arquivo: ed.c Projeto: 00001/plan9port
int
gety(void)
{
	int c;
	Rune *gf, *p;

	p = linebuf;
	gf = globp;
	for(;;) {
		c = getchr();
		if(c == '\n') {
			*p = 0;
			return 0;
		}
		if(c == EOF) {
			if(gf)
				peekc = c;
			return c;
		}
		if(c == 0)
			continue;
		*p++ = c;
		if(p >= &linebuf[LBSIZE-2])
			error(Q);
	}
}
Exemplo n.º 11
0
/* get command character. */
int
getcc(void)
{
	int ch;

	/* left over from error() routine. */
	if (cmdstack) {
		ch = cmdstack;
		cmdstack = NULL;
		return(ch);
	}
	if (cp > cmdbuf && position(TOP) == NULL_POSITION) {
		/*
		 * Command is incomplete, so try to complete it.
		 * There are only two cases:
		 * 1. We have "/string" but no newline.  Add the \n.
		 * 2. We have a number but no command.  Treat as #g.
		 * (This is all pretty hokey.)
		 */
		if (mca != A_DIGIT)
			/* Not a number; must be search string */
			return('\n');
		else
			/* A number; append a 'g' */
			return('g');
	}
	return(getchr());
}
Exemplo n.º 12
0
/*FUNCTION*/
int c_flatc(tpLspObject pLSP,
            LVAL p
  ){
/*noverbatim
CUT*/
  int j;
  LVAL fp;

  if( null(p) )return 3;
  switch( gettype(p) ){
    case NTYPE_CON:
      for( fp = p , j = 1/*(*/ ; fp ; fp = cdr(fp) )
      j+= flatc(car(fp))+1/*space*/;
      return p ? j : 1+j; /*) was calculated as a space. (Not always.) */
    case NTYPE_FLO:
      sprintf(BUFFER,"%lf",getfloat(p));
      break;
    case NTYPE_INT:
      sprintf(BUFFER,"%ld",getint(p));
      break;
    case NTYPE_STR:
      sprintf(BUFFER,"\"%s\"",getstring(p));
      break;
    case NTYPE_SYM:
      sprintf(BUFFER,"%s",getsymbol(p));
      break;
    case NTYPE_CHR:
      sprintf(BUFFER,"#\\%c",getchr(p));
      break;
    default:
      return 0;
      }
  return strlen(BUFFER);
  }
Exemplo n.º 13
0
Arquivo: ed.c Projeto: 00001/plan9port
void
callunix(void)
{
	int c, pid;
	Rune rune;
	char buf[512];
	char *p;

	setnoaddr();
	p = buf;
	while((c=getchr()) != EOF && c != '\n')
		if(p < &buf[sizeof(buf) - 6]) {
			rune = c;
			p += runetochar(p, &rune);
		}
	*p = 0;
	pid = fork();
	if(pid == 0) {
		execlp("rc", "rc", "-c", buf, (char*)0);
		sysfatal("exec failed: %r");
		exits("execl failed");
	}
	waiting = 1;
	while(waitpid() != pid)
		;
	waiting = 0;
	if(vflag)
		putst("!");
}
Exemplo n.º 14
0
main ( )
{
	int c ;

	while ( ( c = getchr ( ) ) !=  EOF )
		putchar ( c ) ;
}
Exemplo n.º 15
0
static void
newline(void)
{
	register int	warned = 0;

	for (;;)
		switch (getchr()) {

		case EOF:
		case '\n':
			return;

		case 'l':
			ed.print = REG_SUB_LIST;
			continue;

		case 'n':
			ed.print = REG_SUB_NUMBER;
			continue;

		case 'p':
			ed.print = REG_SUB_PRINT;
			continue;

		default:
			if (!warned) {
				warned = 1;
				error(2, "extra characters at end of command");
			}
			continue;
		}
}
Exemplo n.º 16
0
uint8_t DeviceCommands::next_command(void)
{
    static char c;
    c = getchr();
    if (c>0)
        put(c);
        if (parse()) {
            if (strcmp(command.name, "echo") == 0)
                echo(command.parameters[0]);
            else if (strcmp(command.name, "set_pwm") == 0)
                set_pwm((uint8_t)command.parameters[0], command.parameters[1]);
            else if (strcmp(command.name, "set_motors") == 0)
                set_motors(command.parameters[0], command.parameters[1], command.parameters[2], command.parameters[3]);
            else if (strcmp(command.name, "set_led") == 0)
                set_led((uint8_t)command.parameters[0], (uint8_t)command.parameters[1]);
            else if (strcmp(command.name, "read_adc") == 0)
                read_adc();
            else if (strcmp(command.name, "stop") == 0)
                stop();

            
            
  //          comm << cp.command.name<<"\t"<<cp.command.nparameters<<"\n";
        }
    return 0;
}
Exemplo n.º 17
0
Arquivo: ed.c Projeto: redox-os/libc
void newline(void)
{
    int c;

    if ((c = getchr()) == '\n' || c == EOF)
        return;
    if (c=='p' || c=='l' || c=='n') {
        pflag++;
        if (c=='l')
            listf++;
        else if (c=='n')
            listn++;
        if ((c=getchr())=='\n')
            return;
    }
    error(Q);
}
Exemplo n.º 18
0
static void
global(int sense, int query)
{
	register char*		s;
	register int		c;
	register Line_t*	a1;

	if (ed.global)
		error(2, "recursive global not allowed");
	setwide();
	squeeze(ed.dol > ed.zero);
	compile();
	if (query)
		newline();
	else {
		s = getrec(ed.buffer.global, '\n', REC_SPLICE|REC_TERMINATE);
		if (s[0] == '\n' && !s[1])
			sfputr(ed.buffer.global, "p\n", 0);
	}
	for (a1 = ed.zero; a1 <= ed.dol; a1++) {
		a1->offset &= ~LINE_GLOBAL;
		if (a1 >= ed.addr1 && a1 <= ed.addr2 && execute(a1, 0) == sense)
			a1->offset |= LINE_GLOBAL;
	}

	/* special case: g/.../d (avoid n^2 algorithm) */

	if (!query && s[0] == 'd' && s[1] == '\n' && !s[2])
		gdelete();
	else {
		for (a1 = ed.zero; a1 <= ed.dol; a1++) {
			if (a1->offset & LINE_GLOBAL) {
				a1->offset &= ~LINE_GLOBAL;
				ed.dot = a1;
				if (query) {
					putrec(lineget(a1->offset));
					if ((c = getchr()) == EOF)
						break;
					else if (c == '\n')
						continue;
					else if (c == '&') {
						newline();
						if (!*(ed.global = sfstrbase(ed.buffer.query)))
							error(2, "no saved command");
					}
					else {
						ed.peekc = c;
						ed.global = getrec(ed.buffer.query, '\n', REC_TERMINATE);
					}
				}
				else
					ed.global = s;
				commands();
				a1 = ed.zero;
			}
		}
	}
}
Exemplo n.º 19
0
Arquivo: ed.c Projeto: 00001/plan9port
void
compile(int eof)
{
	Rune c;
	char *ep;
	char expbuf[ESIZE];

	if((c = getchr()) == '\n') {
		peekc = c;
		c = eof;
	}
	if(c == eof) {
		if(!pattern)
			error(Q);
		return;
	}
	if(pattern) {
		free(pattern);
		pattern = 0;
	}
	ep = expbuf;
	do {
		if(c == '\\') {
			if(ep >= expbuf+sizeof(expbuf)) {
				error(Q);
				return;
			}
			ep += runetochar(ep, &c);
			if((c = getchr()) == '\n') {
				error(Q);
				return;
			}
		}
		if(ep >= expbuf+sizeof(expbuf)) {
			error(Q);
			return;
		}
		ep += runetochar(ep, &c);
	} while((c = getchr()) != eof && c != '\n');
	if(c == '\n')
		peekc = c;
	*ep = 0;
	pattern = regcomp(expbuf);
}
Exemplo n.º 20
0
Arquivo: ed.c Projeto: redox-os/libc
int getnum(void)
{
    int r, c;

    r = 0;
    while ((c=getchr())>='0' && c<='9')
        r = r*10 + c - '0';
    peekc = c;
    return (r);
}
Exemplo n.º 21
0
/*
 *	function to say press return to continue and reset scroll when done
 */
static void
retcont(void)
{
	cursor(1, 24);
	lprcat("Press ");
	standout("return");
	lprcat(" to continue: ");
	while (getchr() != '\n')
		; /* nothing */
	setscroll();
}
Exemplo n.º 22
0
static int
getnum(void)
{
	register int c;
	register int r;

	r = 0;
	while ((c = getchr()) >= '0' && c <= '9')
		r = r * 10 + c - '0';
	ed.peekc = c;
	return r;
}
Exemplo n.º 23
0
/*FUNCTION*/
LVAL c_char_code(tpLspObject pLSP,
                 LVAL p
  ){
/*noverbatim
CUT*/
  LVAL q;

  if( null(p) || !characterp(p) )return NIL;
  q = newint();
  setint(q,(int)getchr(p));
  return q;
  }
Exemplo n.º 24
0
Arquivo: ed.c Projeto: 00001/plan9port
int
compsub(void)
{
	int seof, c;
	Rune *p;

	seof = getchr();
	if(seof == '\n' || seof == ' ')
		error(Q);
	compile(seof);
	p = rhsbuf;
	for(;;) {
		c = getchr();
		if(c == '\\') {
			c = getchr();
			*p++ = ESCFLG;
			if(p >= &rhsbuf[LBSIZE/sizeof(Rune)])
				error(Q);
		} else
		if(c == '\n' && (!globp || !globp[0])) {
			peekc = c;
			pflag++;
			break;
		} else
		if(c == seof)
			break;
		*p++ = c;
		if(p >= &rhsbuf[LBSIZE/sizeof(Rune)])
			error(Q);
	}
	*p = 0;
	peekc = getchr();
	if(peekc == 'g') {
		peekc = 0;
		newline();
		return 1;
	}
	newline();
	return 0;
}
Exemplo n.º 25
0
Arquivo: ed.c Projeto: 00001/plan9port
void
filename(int comm)
{
	char *p1, *p2;
	Rune rune;
	int c;

	count = 0;
	c = getchr();
	if(c == '\n' || c == EOF) {
		p1 = savedfile;
		if(*p1 == 0 && comm != 'f')
			error(Q);
		p2 = file;
		while(*p2++ = *p1++)
			;
		return;
	}
	if(c != ' ')
		error(Q);
	while((c=getchr()) == ' ')
		;
	if(c == '\n')
		error(Q);
	p1 = file;
	do {
		if(p1 >= &file[sizeof(file)-6] || c == ' ' || c == EOF)
			error(Q);
		rune = c;
		p1 += runetochar(p1, &rune);
	} while((c=getchr()) != '\n');
	*p1 = 0;
	if(savedfile[0] == 0 || comm == 'e' || comm == 'f') {
		p1 = savedfile;
		p2 = file;
		while(*p1++ = *p2++)
			;
	}
}
Exemplo n.º 26
0
Arquivo: ed.c Projeto: 00001/plan9port
void
browse(void)
{
	int forward, n;
	static int bformat, bnum; /* 0 */

	forward = 1;
	peekc = getchr();
	if(peekc != '\n'){
		if(peekc == '-' || peekc == '+') {
			if(peekc == '-')
				forward = 0;
			getchr();
		}
		n = getnum();
		if(n > 0)
			bpagesize = n;
	}
	newline();
	if(pflag) {
		bformat = listf;
		bnum = listn;
	} else {
		listf = bformat;
		listn = bnum;
	}
	if(forward) {
		addr1 = addr2;
		addr2 += bpagesize;
		if(addr2 > dol)
			addr2 = dol;
	} else {
		addr1 = addr2-bpagesize;
		if(addr1 <= zero)
			addr1 = zero+1;
	}
	printcom();
}
Exemplo n.º 27
0
/*
 * Output a message in the lower left corner of the screen
 * and wait for carriage return.
 */
void
error(const char *s)
{
	int ch;

	++errmsgs;
	if (!any_display) {
		/*
		 * Nothing has been displayed yet.  Output this message on
		 * error output (file descriptor 2) and don't wait for a
		 * keystroke to continue.
		 *
		 * This has the desirable effect of producing all error
		 * messages on error output if standard output is directed
		 * to a file.  It also does the same if we never produce
		 * any real output; for example, if the input file(s) cannot
		 * be opened.  If we do eventually produce output, code in
		 * edit() makes sure these messages can be seen before they
		 * are overwritten or scrolled away.
		 */
		if (s != NULL)
			fprintf(stderr, "%s\n", s);
		return;
	}

	lower_left();
	clear_eol();
	so_enter();
	if (s != NULL)
		printf("%s  ", s);
	fputs(return_to_continue, stdout);
	so_exit();

	if ((ch = getchr()) != '\n') {
		if (ch == 'q')
			quit();
		cmdstack = ch;
	}
	lower_left();

	if ((s != NULL ? strlen(s) : 0) + sizeof(return_to_continue) + 
	    so_width + se_width + 1 > (size_t)sc_width)
		/*
		 * Printing the message has probably scrolled the screen.
		 * {{ Unless the terminal doesn't have auto margins,
		 *    in which case we just hammered on the right margin. }}
		 */
		repaint();
	fflush(stdout);
}
Exemplo n.º 28
0
Arquivo: ed.c Projeto: redox-os/libc
int compsub(void)
{
    int seof, c;
    char *p;

    if ((seof = getchr()) == '\n' || seof == ' ')
        error(Q);
    compile(seof);
    p = rhsbuf;
    for (;;) {
        c = getchr();
        if (c=='\\')
            c = getchr() | 0200;
        if (c=='\n') {
            if (globp && globp[0])	/* last '\n' does not count */
                c |= 0200;
            else {
                peekc = c;
                pflag++;
                break;
            }
        }
        if (c==seof)
            break;
        *p++ = c;
        if (p >= &rhsbuf[LBSIZE/2])
            error(Q);
    }
    *p++ = 0;
    if ((peekc = getchr()) == 'g') {
        peekc = 0;
        newline();
        return(1);
    }
    newline();
    return(0);
}
Exemplo n.º 29
0
int getfile(char *buff)
{
	int i, count = 0;
	char num, cmpnum, data, check, sum = 0;

	putchr(NAK);
	while((data = getchr()) != EOT)
	{
		if (data != SOH)
			continue;
		num = getchr();
		cmpnum = getchr();
		for (i = 0; i < 128; i++)
		{
			*buff++ = getchr();
			sum += buff[-1];
		}
		check = getchr();
		putchr(ACK);
		count++;
#if 0
		if ((sum & 0xff) == check)
		{
			putchr(ACK);
			count++;
		}
		else
		{
			putchr(NAK);
			buff -= 128;
		}
#endif
	}
	putchr(ACK);

	return count;
}
Exemplo n.º 30
0
static void
page(void)
{
	register int	direction;
	register int	n;

	switch (direction = getchr()) {

	case '-':
	case '.':
	case '+':
		break;

	default:
		ed.peekc = direction;
		direction = '+';
		break;

	}
	if ((n = getnum()) > 0)
		ed.page.size = n;
	newline();
	if (ed.print)
		ed.page.print = ed.print;
	else
		ed.print = ed.page.print;
	switch (direction) {

	case '-':
		ed.addr1 = ed.addr2 - ed.page.size + 1;
		break;

	case '.':
		ed.addr2 += ed.page.size / 2;
		ed.addr1 = ed.addr2 - ed.page.size + 1;
		break;

	case '+':
		ed.addr1 = ed.addr2;
		ed.addr2 += ed.page.size - 1;
		break;

	}
	if (ed.addr1 <= ed.zero)
		ed.addr1 = ed.zero + 1;
	if (ed.addr2 > ed.dol)
		ed.addr2 = ed.dol;
	print();
}