예제 #1
0
파일: subs.c 프로젝트: radixo/openbsd-src
void
roll(void)
{
	char    c;
	int     row;
	int     col;

	if (iroll) {
		getyx(stdscr, row, col);
		mvprintw(17, 0, "ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			D0 = c - '0';
			printw(" %c", c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			D1 = c - '0';
			printw(" %c", c);
			move(17, 0);
			clrtoeol();
			move(row, col);
			return;
		}
		move(17, 0);
		clrtoeol();
		move(row, col);
	}
	D0 = rnum(6) + 1;
	D1 = rnum(6) + 1;
	d0 = 0;
}
예제 #2
0
/*
 * read line, removing any leading or trailing spaces
 */
int readln(int handle, int isnet, char *buf, int max)
{
    int c, p ;

    p=0 ;

    // Skip Leading White Characters
    do {
        c=readc(handle, isnet) ;
    } while (c==' ' || c=='\t') ;

    // Copy the line
    if (c>0 && c!='\n') do {
            buf[p]=c ;
            p++ ;
            c=readc(handle, isnet) ;
        } while (c!='\n' && p<max-1) ;

    // Remove trailing white characters
    while (p>0 && buf[p-1]==' ' || buf[p-1]=='\t') p-- ;

    // terminate and return
    buf[p]='\0' ;
    if (c<0) return -1 ;
    else return p ;
}
예제 #3
0
파일: dc.c 프로젝트: carriercomm/plan9-gpl
int
command(void)
{
	char line[100], *sl;
	int pid, p, c;

	switch(c = readc()) {
	case '<':
		return(cond(NL));
	case '>':
		return(cond(NG));
	case '=':
		return(cond(NE));
	default:
		sl = line;
		*sl++ = c;
		while((c = readc()) != '\n')
			*sl++ = c;
		*sl = 0;
		if((pid = fork()) == 0) {
			execl("/bin/rc","rc","-c",line,nil);
			exits("shell");
		}
		for(;;) {
			if((p = waitpid()) < 0)
				break;
			if(p== pid)
				break;
		}
		Bprint(&bout,"!\n");
		return(0);
	}
}
예제 #4
0
파일: main.c 프로젝트: fdotli/libu
static int test_full_advance (int opts)
{
    int i;
    char c, prev, star = '*';
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));

    /* fill the rb */
    for (i = 0; i < SZ; i++)
        con_err_if (writec(rb, star));

    for (c = 32; c < 126; c++)
    {
        if (c < (SZ + 32))
            con_err_if (readc(rb, &star));
        else
        {
            prev = c - SZ; 
            con_err_if (readc(rb, &prev));
        }

        con_err_if (writec(rb, c));
    }

    return 0;
err:
    return 1;
}
예제 #5
0
파일: compsq.c 프로젝트: damieng/johnelliot
static dsk_err_t reads(SQ_COMPRESS_DATA *self, signed short *s)
{
	unsigned char c1, c2;
	dsk_err_t err;
	
	err = readc(self, &c1); if (err) return err;
	err = readc(self, &c2); if (err) return err;

	*s = ((c2 << 8) | c1);
	return DSK_ERR_OK;
}
예제 #6
0
파일: sh.c 프로젝트: Ju2ender/c-e
/*
 * 读取一个字符,并做一些预处理
 * 1.从预读缓存中读取
 * 2.从流中直接读取
 */
char getc() 
{ 
        char c; 

        if(peekc) { 
                c = peekc;  /* 如果有预读缓存,读取缓存并返回 */
                peekc = 0;  /* 清除预读缓存 */
                return(c); 
        } 
        if(argp > eargp) {  /* Token列表溢出 */
                argp -= 10; 
                while((c=getc()) != '\n'); /* 取完换行符前所有字符 */
                argp += 10; 
                err("Too many args"); 
                gflg++; 
                return(c); 
        } 
        if(linep > elinep) { /* 命令参数缓存溢出 */
                linep -= 10; 
                while((c=getc()) != '\n'); /* 取完换行符之前所有字符 */
                linep += 10; 
                err("Too many characters"); 
                gflg++; 
                return(c); 
        } 
getd: 
        if(dolp) {  /* 存在带'$'前缀的命令参数字符 */
                c = *dolp++; 
                if(c != '\0') 
                        return(c); 
                dolp = 0;   /* 带'$'前缀的参数扫描完毕,dolp清零 */
        } 
        c = readc(); /* 从流中读取一个字符 */    
        if(c == '\\') { 
                c = readc();    /* 遇到转义符,继续读取下一个字符 */
                if(c == '\n') 
                        return(' ');    /* 斜杠在行末,返回空格接续下一行 */
                return(c|QUOTE);    /* 引用该字符 */
        } 
        if(c == '$') { 
                c = readc();    /* 遇到'$',继续读取一个字符 */
                if(c>='0' && c<='9') {  /* 位置变量 */
                        if(c-'0' < dolc)    /* 位置参数在合法范围内 */
                                dolp = dolv[c-'0'];     /* dolp指向替代的命令参数字符 */
                        goto getd;  /* 跳转getd处理 */
                } 
                if(c == '$') {  /* 当前进程pid */
                        dolp = pidp;    /* dolp指向之前记录的pid字符串 */
                        goto getd;  /* 跳转getd处理 */
                } 
        } 
        return(c&0177);     /* 普通字符直接返回,限定在ascii */
} 
예제 #7
0
파일: dpp.c 프로젝트: ageneau/ecl-mirror
char *
read_token(void)
{
        int c;
        int left_paren = 0;
        char *p;

        p = poolp;
        c = readc();
        while (isspace(c))
                c = readc();
        do {
                if (c == '(') {
                        left_paren++;
                        pushc(c);
                } else if (c == ')') {
                        if (left_paren == 0) {
                                break;
                        } else {
                                left_paren--;
                                pushc(c);
                        }
                } else if (isspace(c) && left_paren == 0) {
                        do
                                c = readc();
                        while (isspace(c));
                        break;
                } else if (c == '@') {
                        c = readc();
                        if (c == '\'') {
                                (void)read_symbol(0);
                                poolp--;
                        } else if (c == '[') {
                                (void)read_symbol(1);
                                poolp--;
                        } else if (c == '@') {
                                pushc(c);
                        } else {
                                char *name;
                                unreadc(c);
                                poolp = name = read_function();
                                (void)translate_function(poolp);
                        }
                } else {
                        pushc(c);
                }
                c = readc();
        } while (1);
        unreadc(c);
        pushc('\0');
        return(p);
}
예제 #8
0
파일: dpp.c 프로젝트: ageneau/ecl-mirror
int
jump_to_at(void)
{
        int c;
 GO_ON:
        while ((c = readc()) != '@')
                putc(c, out);
        if ((c = readc()) == '@') {
                putc(c, out);
                goto GO_ON;
        }
        return c;
}
예제 #9
0
파일: dc.c 프로젝트: carriercomm/plan9-gpl
Blk*
readin(void)
{
	Blk *p, *q;
	int dp, dpct, c;

	dp = dpct=0;
	p = salloc(0);
	for(;;){
		c = readc();
		switch(c) {
		case '.':
			if(dp != 0)
				goto gotnum;
			dp++;
			continue;
		case '\\':
			readc();
			continue;
		default:
			if(c >= 'A' && c <= 'F')
				c = c - 'A' + 10;
			else
			if(c >= '0' && c <= '9')
				c -= '0';
			else
				goto gotnum;
			if(dp != 0) {
				if(dpct >= 99)
					continue;
				dpct++;
			}
			create(chptr);
			if(c != 0)
				sputc(chptr,c);
			q = mult(p,inbas);
			release(p);
			p = add(chptr,q);
			release(q);
		}
	}
gotnum:
	unreadc(c);
	if(dp == 0) {
		sputc(p,0);
		return(p);
	} else {
		q = scale(p,dpct);
		return(q);
	}
}
예제 #10
0
파일: word.c 프로젝트: davidgiven/FUZIX
int nextc(char quote)
{
	register char c, d;
	if ((d = readc()) == ESCAPE) {
		if ((c = readc()) == NL) {
			chkpr(NL);
			d = nextc(quote);
		} else if (quote && c != quote && !escchar(c))
			peekc = c | MARK;
		else
			d = c | QUOTE;
	}
	return d;
}
예제 #11
0
파일: subs.c 프로젝트: ajinkya93/netbsd-src
void
roll(struct move *mm)
{
	char    c;
	int     row;
	int     col;

	row = col = 0;
	if (iroll) {
		if (tflag) {
			row = curr;
			col = curc;
			curmove(17, 0);
		} else
			writec('\n');
		writel("ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			mm->D0 = c - '0';
			writec(' ');
			writec(c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			mm->D1 = c - '0';
			writec(' ');
			writec(c);
			if (tflag) {
				curmove(17, 0);
				cline();
				curmove(row, col);
			} else
				writec('\n');
			return;
		}
		if (tflag) {
			curmove(17, 0);
			cline();
			curmove(row, col);
		} else
			writec('\n');
	}
	mm->D0 = rnum(6) + 1;
	mm->D1 = rnum(6) + 1;
	mm->d0 = 0;
}
예제 #12
0
파일: subs.c 프로젝트: radixo/openbsd-src
int
yorn(char special)
{
	char    c;
	int     i;

	i = 1;
	while ((c = readc()) != 'Y' && c != 'N') {
		if (special && c == special)
			return(2);
		if (i) {
			if (special)
				printw("  (Y, N, or %c)", special);
			else
				printw("  (Y or N)");
			i = 0;
		} else
			beep();
	}
	if (c == 'Y')
		addstr("  Yes.\n");
	else
		addstr("  No.\n");
	refresh();
	return(c == 'Y');
}
예제 #13
0
void
load(void){
	register int c;
	register struct blk *p,*q;
	struct blk *t,*s;
	c = readc() & 0377;
	sptr = stable[c];
	if(sptr != 0){
		p = sptr->val;
		if(c >= ARRAYST){
			q = salloc(length(p));
			rewind(p);
			while(sfeof(p) == 0){
				s = dcgetwd(p);
				if(s == 0){putwd(q, (struct blk *)NULL);}
				else{
					t = copy(s,length(s));
					putwd(q,t);
				}
			}
			pushp(q);
		}
		else{
			q = copy(p,length(p));
			pushp(q);
		}
	}
	else{
		q = salloc(1);
		sputc(q,0);
		pushp(q);
	}
	return;
}
예제 #14
0
파일: advio.cpp 프로젝트: tommasward/Mytget
int BufferStream::read_line(char *line, int maxsize, long timeout) {
    int i, rc;
    char c;
    char *pptr;

    pptr = line;

    for (i = 1; i < maxsize; i++) {
        if ((rc=readc(&c, timeout)) < 0) {
            return rc;  // error
        } else if (rc == 0) {  // EOF
            if (i == 1) {  // read nothing but EOF
                return 0;
            } else {
                break;
            }
        }
        *pptr = c;
        pptr++;
        if (c == '\n')
            break;
    }

    *pptr = '\0';

    if (i == maxsize)
        return i-1;
    else
        return i;
};
예제 #15
0
파일: UNLZW.C 프로젝트: Inzaghi2012/EZP
static unsigned short getcode()
{
  register unsigned short d1,len;

  len=code_len;
  d1=0;
  while (len>0)
  {
   if (inbuf==0)
   {
    if (UEOF==(inchar=readc())) return MEOF;
    inbuf=8;
   }

   if (len>=inbuf) { len=len-inbuf; d1=((d1<<inbuf)|inchar); inbuf=0; }
   else { inbuf=inbuf-len; d1=((d1<<len)|(inchar>>inbuf)); len=0;
	  /* inchar=(inchar<<(16-inbuf)); inchar=(inchar>>(16-inbuf)); */
	  inchar &=BitSet[inbuf];
	  }
  }
  if (d1==257)
  {
  return UEOF;
  }
  return d1;
}
예제 #16
0
파일: subs.c 프로젝트: ajinkya93/netbsd-src
int
yorn(int special)
{
	char    c;
	int     i;

	i = 1;
	while ((c = readc()) != 'Y' && c != 'N') {
		if (special && c == special)
			return (2);
		if (i) {
			if (special) {
				writel("  (Y, N, or ");
				writec(special);
				writec(')');
			} else
				writel("  (Y or N)");
			i = 0;
		} else
			writec('\007');
	}
	if (c == 'Y')
		writel("  Yes.\n");
	else
		writel("  No.\n");
	if (tflag)
		buflush();
	return (c == 'Y');
}
예제 #17
0
파일: util.c 프로젝트: snimmagadda/http
ssize_t
readline(int fd, void *buf, size_t len)
{
	ssize_t	n, nread;
	char	c = 0, *p;

	p = buf;
	for (n = 1; n < len; n++) {
		nread = readc(fd, &c);
		switch (nread) {
		case 1:
			*p++ = c;
			if (c == '\n')
				goto done;
			break;
		case 0:
			return 0;
		default:
			return -1;
		}
	}

done:
	if (c != '\n')
		errx(1, "readline: Line too long");

	*p = 0;
	if (http_debug)
		fprintf(stderr, ">>> %s", (char *)buf);

	return n;
}
예제 #18
0
파일: ssh.c 프로젝트: anastasop/oneshot
void redirect(int fd){
	int c, rfd;
	int mark;
	char *op;
	do
		c=readc();
	while(c==' ' || c=='\t');
	mark=argp-args;
	word(c);
	if(!skip){
		if(redir[fd]!=fd) err("duplicate redirection\n");
		else if(argp!=args+mark+1) err("ambiguous redirection\n");
		else{
			if(fd==1){
				op="create";
				rfd=creat(argp[-1], 0666);
			}
			else{
				op="open";
				rfd=open(argp[-1], O_RDONLY);
			}
			if(rfd==-1) err("can't %s %s\n", op, argp[-1]);
			else
				redir[fd]=rfd;
		}
	}
	argp=args+mark;
	chargp=*argp;
}
예제 #19
0
파일: ssh.c 프로젝트: anastasop/oneshot
int nextis(int match){
	int c;
	c=readc();
	if(c==match) return 1;
	peekc=c;
	return 0;
}
예제 #20
0
파일: macro.c 프로젝트: 8l/FUZIX
static void comsubst(void)
{
	/* command substn */
	FILEBLK cb;
	register char d;
	register STKPTR savptr = fixstak();

	usestak();
	while ((d = readc()) != SQUOTE && d)
		pushstak(d);

	{
		register char *argc;
		trim(argc = fixstak());
		push(&cb);
		estabf(argc);
	}
	{
		register TREPTR t =
		    makefork(FPOU, cmd(EOFSYM, MTFLG | NLFLG));
		int pv[2];

		/* this is done like this so that the pipe
		 * is open only when needed
		 */
		chkpipe(pv);
		initf(pv[INPIPE]);
		execute(t, 0, 0, pv);
		close(pv[OTPIPE]);
	}
	tdystak(savptr);
	staktop = movstr(savptr, stakbot);

	while (d = readc())
		pushstak(d | quote);

	await(0);

	while (stakbot != staktop) {
		if ((*--staktop & STRIP) != NL) {
			++staktop;
			break;
		}
	}
	pop();
}
예제 #21
0
파일: sh6.c 프로젝트: alwayrun/v6shell
/*
 * Ignore any `#!shell' sequence as the first line of a regular file.
 * The length of this line is limited to (LINEMAX - 1) characters.
 */
static void
sh_magic(void)
{
	struct stat sb;
	size_t len;

	if (fstat(FD0, &sb) == -1 || !S_ISREG(sb.st_mode))
		return;
	if (lseek(FD0, (off_t)0, SEEK_CUR) == 0) {
		if (readc() == HASH && readc() == BANG) {
			for (len = 2; len < LINEMAX; len++)
				if (readc() == EOL)
					return;
			err(SH_ERR, FMT1S, ERR_TMCHARS);
		}
		(void)lseek(FD0, (off_t)0, SEEK_SET);
	}
}
예제 #22
0
파일: dc.c 프로젝트: carriercomm/plan9-gpl
int
getstk(void)
{
	int n;
	uchar c;

	c = readc();
	if(c != '<')
		return c;
	n = 0;
	while(1) {
		c = readc();
		if(c == '>')
			break;
		n = n*10+c-'0';
	}
	return n;
}
예제 #23
0
파일: dpp.c 프로젝트: ageneau/ecl-mirror
int
nextc(void)
{
        int c;

        while (isspace(c = readc()))
                ;
        return(c);
}
예제 #24
0
파일: ssh.c 프로젝트: anastasop/oneshot
void word(int c){
	int doglob;
	arg(chargp);
	doglob=0;
	for(;;){
		switch(c){
		case ' ':
		case '\t':
		case '&':
		case ';':
		case '\n':
		case '|':
		case '<':
		case '>':
			peekc=c;
			goto Done;
		case '\\':
			c=readc();
			if(c=='\n' || c==EOF){
				peekc=' ';
				goto Done;
			}
			argchr(c);
			break;
		case '\'':
			while((c=readc())!='\'' && c!=EOF) argchr(c);
			break;
		case '*':
		case '?':
		case GLOB:
			argchr(GLOB);
			doglob=1;
			argchr(c);
			break;
		default:
			argchr(c);
			break;
		}
		c=readc();
	}
Done:
	argchr('\0');
	if(!skip && doglob) glob();
}
예제 #25
0
파일: sh.c 프로젝트: Ju2ender/c-e
/* 
 * 对命令参数扫描并分割 token
 * readc 直接从流中读取一个字符,getc 对前者的字符进行预处理 
*/
void word()
{
  char c, c1; 

  *argp++ = linep;  /* 将当前命令参数作为一个token放入列表,以'\0'结束,argp指向下一个token位置 */

  loop: 
    switch(c = getc()) { 

      case ' ': 
      case '\t': 
        goto loop;  /* 过滤空格和tab字符 */

      case '\'': 
      case '"': 
        c1 = c; 
        while((c=readc()) != c1) {  /* 多读一个字符,判断是否成对(如引号) */
          if(c == '\n') { 
            error++;    /* 引用未结束遇上换行符,错误计数 */
            peekc = c;  /* 推回预读字符 */
            return; 
          } 
          *linep++ = c|QUOTE; /* 加上引用标识 */
        } 
        goto pack; /* 引用结束,跳转至pack */

      case '&': 
      case ';': 
      case '<': 
      case '>': 
      case '(': 
      case ')': 
      case '|': 
      case '^': 
      case '\n': 
                *linep++ = c; 
                *linep++ = '\0';    /* 元字符等特殊字符单独作为一个token返回 */
                return; 
        } 

        peekc = c;  /* 若为普通字符,推回预读 */

pack: 
        for(;;) { 
                c = getc(); 
                if(any(c, " '\"\t;&<>()|^\n")) {    /* 遇上元字符、分隔符等特殊字符 */
                        peekc = c;  /* 推回预读字符 */
                        if(any(c, "\"'")) 
                                goto loop;  /* 遇上引用字符,跳转到loop继续扫描 */
                        *linep++ = '\0';    /* 分割一个token出来 */
                        return; 
                } 
                *linep++ = c; 
        } 
} 
예제 #26
0
int
command(void){
	int c;
	static char *line;
	static int linesize;
	char *sl;
	register void (*savint)(int);
	register int pid,rpid;
	int retcode;

	switch(c = readc()){
	case '<':
		return(cond(NL));
	case '>':
		return(cond(NG));
	case '=':
		return(cond(NE));
	default:
		if (line == 0)
			line = srealloc(0, linesize = 10);
		sl = line;
		*sl++ = c;
		while((c = readc()) != '\n') {
			if (sl >= &line[linesize-2]) {
				int	diff = sl - line;
				line = srealloc(line, linesize += 10);
				sl = &line[diff];
			}
			*sl++ = c;
		}
		*sl = 0;
		if((pid = fork()) == 0){
			execl(SHELL,"sh","-c",line,NULL);
			exit(0100);
		}
		savint = sigset(SIGINT, SIG_IGN);
		while((rpid = wait(&retcode)) != pid && rpid != -1);
		sigset(SIGINT,savint);
		printf("!\n");
		return(0);
	}
}
예제 #27
0
int
cond(char c)
{
	register struct blk *p;
	register int cc;

	if(subt() != 0)return(1);
	p = pop();
	sunputc(p);
	if(length(p) == 0){
		release(p);
		if(c == '<' || c == '>' || c == NE){
			readc();
			return(0);
		}
		load();
		return(1);
	}
	else {
		if(c == '='){
			release(p);
			readc();
			return(0);
		}
	}
	if(c == NE){
		release(p);
		load();
		return(1);
	}
	fsfile(p);
	cc = sbackc(p);
	release(p);
	if((cc<0 && (c == '<' || c == NG)) ||
		(cc >0) && (c == '>' || c == NL)){
		readc();
		return(0);
	}
	load();
	return(1);
}
예제 #28
0
파일: main.c 프로젝트: fdotli/libu
static int test_empty (int opts)
{
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));
    con_err_if (readc(rb, NULL) == 0);   /* underflow, readc() must fail */

    return 0;
err:
    return 1;
}
예제 #29
0
파일: dpp.c 프로젝트: ageneau/ecl-mirror
char *
read_symbol(int code)
{
        char c, *name = poolp;
        char end = code? ']' : '\'';

        c = readc();
        while (c != end) {
                if (c == '_') c = '-';
                pushc(c); 
                c = readc();
        }
        pushc(0);

        name = search_symbol(poolp = name, 0, code);
        if (name == NULL) {
                name = poolp;
                printf("\nUnknown symbol: %s\n", name);
                pushstr("unknown");
        }
        return name;
}
예제 #30
0
파일: macro.c 프로젝트: 8l/FUZIX
static int skipto(char endch)
{
	/* skip chars up to } */
	register char c;
	while ((c = readc()) && c != endch) {
		switch (c) {

		case SQUOTE:
			skipto(SQUOTE);
			break;

		case DQUOTE:
			skipto(DQUOTE);
			break;

		case DOLLAR:
			if (readc() == BRACE)
				skipto('}');
		}
	}
	if (c != endch) {
		error(badsub);
	}
}