コード例 #1
0
ファイル: more.c プロジェクト: jyin0813/OpenBSD-src
int
do_shell(char *filename)
{
	char cmdbuf[200];

	kill_line();
	putchar('!');
	fflush(stdout);
	promptlen = 1;
	if (lastp)
		fputs(shell_line, stdout);
	else {
		if (ttyin(cmdbuf, sizeof(cmdbuf) - 2, '!') < 0)
			return (-1);
		if (expand(shell_line, sizeof(shell_line), cmdbuf)) {
			kill_line();
			promptlen = printf("!%s", shell_line);
		}
	}
	fflush(stdout);
	write(STDERR_FILENO, "\n", 1);
	promptlen = 0;
	shellp = 1;
	execute(filename, shell, shell, "-c", shell_line);
}
コード例 #2
0
ファイル: more.c プロジェクト: jyin0813/OpenBSD-src
/*
 * Execute a colon-prefixed command.
 * Returns <0 if not a command that should cause
 * more of the file to be printed.
 */
int
colon(char *filename, int cmd, int nlines)
{
	int ch;

	if (cmd == 0)
		ch = readch();
	else
		ch = cmd;
	lastcolon = ch;
	switch (ch) {
	case 'f':
		kill_line();
		if (!no_intty)
			promptlen =
			    printf("\"%s\" line %lld", fnames[fnum],
				(long long)Currline);
		else
			promptlen = printf("[Not a file] line %lld",
			    (long long)Currline);
		fflush(stdout);
		return (-1);
	case 'n':
		if (nlines == 0) {
			if (fnum >= nfiles - 1)
				end_it();
			nlines++;
		}
		putchar('\r');
		erasep(0);
		skipf(nlines);
		return (0);
	case 'p':
		if (no_intty) {
			write(STDERR_FILENO, &bell, 1);
			return (-1);
		}
		putchar('\r');
		erasep(0);
		if (nlines == 0)
			nlines++;
		skipf (-nlines);
		return (0);
	case '!':
		if (do_shell(filename) < 0) {
			kill_line();
			prompt(filename);
		}
		return (-1);
	case 'q':
	case 'Q':
		end_it();
		/*FALLTHROUGH*/
	default:
		write(STDERR_FILENO, &bell, 1);
		return (-1);
	}
}
コード例 #3
0
ファイル: more.c プロジェクト: aalm/obsd-src
void
prompt(char *filename)
{
	if (clreol)
		cleareol();
	else if (promptlen > 0)
		kill_line();
	if (!hard) {
		promptlen = 8;
		if (Senter && Sexit) {
			tputs(Senter, 1, putch);
			promptlen += (2 * soglitch);
		}
		if (clreol)
			cleareol();
		fputs("--More--", stdout);
		if (filename != NULL)
			promptlen += printf("(Next file: %s)", filename);
		else if (!no_intty)
			promptlen += printf("(%d%%)",
			    (int)((file_pos * 100) / file_size));
		if (dum_opt) {
			fputs(DUM_PROMPT, stdout);
			promptlen += sizeof(DUM_PROMPT) - 1;
		}
		if (Senter && Sexit)
			tputs(Sexit, 1, putch);
		if (clreol)
			clreos();
		fflush(stdout);
	} else
		write(STDERR_FILENO, &bell, 1);
	inwait++;
}
コード例 #4
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
void
do_asm_func(int type)
{	/* syntax is
	   name of the data : identifier
	 */
	char  n[NAMESIZE];
	char *ptr;

	/* get identifier */ 
	if (!symname(n)) {
		error("invalid identifier");
		kill_line();
		return;
	}

	/* close function */
	needbrack(")");

	/* duplicate identifier */
	ptr = new_string(1, n);

	/* gen code */
	if (ptr)
		out_ins(I_LDWI, type, (INTPTR_T)ptr);
	else
		error("out of memory");
}
コード例 #5
0
ファイル: more.c プロジェクト: pali/util-linux
static void prompt(char *filename)
{
	if (clreol)
		cleareol();
	else if (promptlen > 0)
		kill_line();
	if (!hard) {
		promptlen = 0;
		if (Senter && Sexit) {
			putstring(Senter);
			promptlen += (2 * soglitch);
		}
		if (clreol)
			cleareol();
		promptlen += printf(_("--More--"));
		if (filename != NULL) {
			promptlen += printf(_("(Next file: %s)"), filename);
		} else if (!no_intty) {
			promptlen +=
			    printf("(%d%%)",
				   (int)((file_pos * 100) / file_size));
		}
		if (dum_opt) {
			promptlen +=
			    printf(_("[Press space to continue, 'q' to quit.]"));
		}
		if (Senter && Sexit)
			putstring(Sexit);
		if (clreol)
			clreos();
		fflush(stdout);
	} else
		ringbell();
	inwait++;
}
コード例 #6
0
ファイル: console.c プロジェクト: salexa92/os161ass1
void setHistory(char *buffer) {
	kill_line();
	char nextChar;
	int j;
	for (j = 0; buffer[j] != '\0'; ++j) {
		nextChar = buffer[j];
		input.buf[input.e++ % INPUT_BUF] = nextChar;
		input.f++;
		consputc(nextChar);
	}
}
コード例 #7
0
ファイル: io.c プロジェクト: BouKiCHi/husic_git
void unget_line (void)
{
	int i;

	i = (int)strlen(line);
	if (i > 0) {
		fseek(input, 0-i-CR_LEN, SEEK_CUR);
		line_number--;
	}

	kill_line();
}
コード例 #8
0
ファイル: io.c プロジェクト: BouKiCHi/husic_git
/*
 *	open output file
 * Input : nothing but uses global fname
 * Output : nothing but fname contain the name of the out file now
 * 
 * Guess the name of the outfile thanks to the input one and try to open it
 * In case of succes returns YES and output is the handle of the opened file
 * else returns NO
 * 
 */
int openout (void)
{
   outfname (fname);
   if ((output = fopen (fname, "w")) == NULL) {
      pl ("Open failure : ");
      pl (fname);
      pl ("\n");
      return (NO);
      }
   kill_line ();
   return (YES);
}
コード例 #9
0
ファイル: more.c プロジェクト: aalm/obsd-src
/*
 * Clean up terminal state and exit. Also come here if interrupt signal received
 */
void __dead
end_it(void)
{
	reset_tty();
	if (clreol) {
		putchar('\r');
		clreos();
		fflush(stdout);
	} else if (promptlen > 0) {
		kill_line();
		fflush(stdout);
	} else
		write(STDERR_FILENO, "\n", 1);
	_exit(0);
}
コード例 #10
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
int outcomma(void)
{

   if (!match(","))
    {
      error("missing ,");
      kill_line();
      return 1;
    }

  outbyte(',');

  return 0;

 }
コード例 #11
0
ファイル: io.c プロジェクト: BouKiCHi/husic_git
/*
 *	open input file
 * Input : char* p
 * Output : int error code
 * 
 * Try to open the file whose filename is p, return YES if opened, else NO
 * Updates fname with the actual opened name
 * input is the handle of the opened file
 * 
 */
int openin (char *p)
{
	strcpy(fname, p);
    strcpy(fname_copy, fname);
    
	fixname (fname);
	if (!checkname (fname))
		return (NO);
	if ((input = fopen (fname, "r")) == NULL) {
		pl ("Open failure\n");
		return (NO);
	}
	kill_line ();
	return (YES);
}
コード例 #12
0
ファイル: more.c プロジェクト: aalm/obsd-src
void
error(char *mess)
{
	if (clreol)
		cleareol();
	else
		kill_line();
	promptlen += strlen (mess);
	if (Senter && Sexit) {
		tputs(Senter, 1, putch);
		fputs(mess, stdout);
		tputs(Sexit, 1, putch);
	} else
		fputs(mess, stdout);
	fflush(stdout);
	errors++;
}
コード例 #13
0
ファイル: more.c プロジェクト: pali/util-linux
static void more_error(char *mess)
{
	if (clreol)
		cleareol();
	else
		kill_line();
	promptlen += strlen(mess);
	if (Senter && Sexit) {
		putstring(Senter);
		putsout(mess);
		putstring(Sexit);
	} else
		putsout(mess);
	fflush(stdout);
	errors++;
	siglongjmp(restore, 1);
}
コード例 #14
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
int outnameunderline(void)
{
  char	n[NAMESIZE];

  if (!symname(n))
    {
      error("invalid identifier");
      kill_line();
      return 1;
     }

  prefix();
  outstr(n);

  return 0;

 }
コード例 #15
0
ファイル: io.c プロジェクト: BouKiCHi/husic_git
void readline (void)
{
	int	k;
	FILE	*unit;

	FOREVER {
		if (feof (input))
			return;
		if ((unit = input2) == NULL)
			unit = input;
		kill_line ();
		while ((k = fgetc (unit)) != EOF) {
			if ((k == '\r') | (k == EOL) | (lptr >= LINEMAX))
				break;
			line[lptr++] = k;
		}
		line_number++;
		line[lptr] = 0;
		if (k <= 0)
			if (input2 != NULL) {
				if (globals_h_in_process) {
					/* Add special treatment to ensure globals.h stuff appears at the beginning */
					dumpglbs();
					ol(".code");
					globals_h_in_process = 0;
				}
				input2 = inclstk[--inclsp];
				line_number = inclstk_line[inclsp];
				fclose (unit);
			}
		if (lptr) {
			if ((ctext) & (cmode)) {
				flush_ins();
				comment ();
				outstr (line);
				newl ();
			}
			lptr = 0;
			return;
		}
	}
}
コード例 #16
0
ファイル: more.c プロジェクト: aalm/obsd-src
char *
resize_line(char *pos)
{
	char *np;

	linsize *= 2;
	if (Line != Lineb)
		np = realloc(Line, linsize);
	else if ((np = malloc(linsize)) != NULL)
		memcpy(np, Lineb, sizeof(Lineb));
	if (np == NULL) {
		kill_line();
		fputs("out of memory!\n", stdout);
		reset_tty();
		exit(1);
	}
	pos = np + (pos - Line);
	Line = np;

	return (pos);
}
コード例 #17
0
ファイル: editline.c プロジェクト: jakubpawlo/editline
static el_status_t tty_special(int c)
{
#ifdef CONFIG_SIGINT
    if (c == rl_intr) {
        el_intr_pending = SIGINT;
        return CSsignal;
    }
#endif
    if (c == rl_quit) {
        el_intr_pending = SIGQUIT;
        return CSeof;
    }
#ifdef CONFIG_SIGSTOP
    if (c == rl_susp) {
        el_intr_pending = SIGTSTP;
        return CSsignal;
    }
#endif

   if (rl_meta_chars && ISMETA(c))
        return CSdispatch;

    if (c == rl_erase || c == DEL)
        return bk_del_char();
    if (c == rl_kill) {
        if (rl_point != 0) {
            rl_point = 0;
            reposition();
        }
        Repeat = NO_ARG;
        return kill_line();
    }

#ifdef CONFIG_EOF
    if (c == rl_eof && rl_point == 0 && rl_end == 0)
        return CSeof;
#endif

    return CSdispatch;
}
コード例 #18
0
ファイル: more.c プロジェクト: aalm/obsd-src
/*
 * Read a command and do it. A command consists of an optional integer
 * argument followed by the command character.  Return the number of lines
 * to display in the next screenful.  If there is nothing more to display
 * in the current file, zero is returned.
 */
int
command(char *filename, FILE *f)
{
	int nlines;
	int retval;
	int ch;
	char colonch;
	int done;
	char comchar, cmdbuf[80];

#define ret(val) retval=val;done++;break

	retval = done = 0;
	if (!errors)
		prompt(filename);
	else
		errors = 0;
	for (;;) {
		nlines = number(&comchar);
		lastp = colonch = 0;
		if (comchar == '.') {	/* Repeat last command */
			lastp++;
			comchar = lastcmd;
			nlines = lastarg;
			if (lastcmd == ':')
				colonch = lastcolon;
		}
		lastcmd = comchar;
		lastarg = nlines;
		if (comchar == otty.c_cc[VERASE]) {
			kill_line();
			prompt(filename);
			continue;
		}
		switch (comchar) {
		case ':':
			retval = colon(filename, colonch, nlines);
			if (retval >= 0)
				done++;
			break;
		case 'b':
		case ctrl('B'):
		    {
			int initline;

			if (no_intty) {
				write(STDERR_FILENO, &bell, 1);
				return (-1);
			}

			if (nlines == 0)
				nlines++;

			putchar('\r');
			erasep(0);
			putchar('\n');
			if (clreol)
				cleareol();
			printf("...back %d page", nlines);
			if (nlines > 1)
				fputs("s\n", stdout);
			else
				putchar('\n');

			if (clreol)
				cleareol();
			putchar('\n');

			initline = Currline - (off_t)dlines * (nlines + 1);
			if (!noscroll)
				--initline;
			if (initline < 0)
				initline = 0;
			Fseek(f, (off_t)0);
			Currline = 0; /* skiplns() will make Currline correct */
			skiplns(initline, f);
			ret(dlines);
		    }
		case ' ':
		case 'z':
			if (nlines == 0)
				nlines = dlines;
			else if (comchar == 'z')
				dlines = nlines;
			ret(nlines);
		case 'd':
		case ctrl('D'):
			if (nlines != 0)
				nscroll = nlines;
			ret(nscroll);
		case 'q':
		case 'Q':
			end_it();
		case 's':
		case 'f':
			if (nlines == 0)
				nlines++;
			if (comchar == 'f')
				nlines *= dlines;
			putchar('\r');
			erasep(0);
			putchar('\n');
			if (clreol)
				cleareol();
			printf("...skipping %d line", nlines);
			if (nlines > 1)
				fputs("s\n", stdout);
			else
				putchar('\n');

			if (clreol)
				cleareol();
			putchar('\n');

			while (nlines > 0) {
				while ((ch = Getc(f)) != '\n') {
					if (ch == EOF) {
						retval = 0;
						done++;
						goto endsw;
					}
				}
				Currline++;
				nlines--;
			}
			ret(dlines);
		case '\n':
			if (nlines != 0)
				dlines = nlines;
			else
				nlines = 1;
			ret(nlines);
		case '\f':
			if (!no_intty) {
				doclear();
				Fseek(f, screen_start.chrctr);
				Currline = screen_start.line;
				ret(dlines);
			} else {
				write(STDERR_FILENO, &bell, 1);
				break;
			}
		case '\'':
			if (!no_intty) {
				kill_line();
				fputs("\n***Back***\n\n", stdout);
				Fseek(f, context.chrctr);
				Currline = context.line;
				ret(dlines);
			} else {
				write(STDERR_FILENO, &bell, 1);
				break;
			}
		case '=':
			kill_line();
			promptlen = printf("%lld", (long long)Currline);
			fflush(stdout);
			break;
		case 'n':
			lastp++;
		case '/':
			if (nlines == 0)
				nlines++;
			kill_line();
			putchar('/');
			promptlen = 1;
			fflush(stdout);
			if (lastp) {
				/* Use previous r.e. */
				write(STDERR_FILENO, "\r", 1);
				if (search(NULL, f, nlines) < 0)
					break;
			} else {
				if (ttyin(cmdbuf, sizeof(cmdbuf) - 2, '/') < 0) {
					kill_line();
					prompt(filename);
					continue;
				}
				write(STDERR_FILENO, "\r", 1);
				if (search(cmdbuf, f, nlines) < 0)
					break;
			}
			ret(dlines-1);
		case '?':
		case 'h':
			if (noscroll)
				doclear();
			fputs(more_help, stdout);
			prompt(filename);
			break;
		default:
			if (dum_opt) {
				kill_line();
				if (Senter && Sexit) {
					tputs(Senter, 1, putch);
					fputs(DUM_ERROR, stdout);
					promptlen = sizeof(DUM_ERROR) - 1 +
					    (2 * soglitch);
					tputs(Sexit, 1, putch);
				} else {
					fputs(DUM_ERROR, stdout);
					promptlen = sizeof(DUM_ERROR) - 1;
				}
				fflush(stdout);
			} else
				write(STDERR_FILENO, &bell, 1);
			break;
		}
		if (done)
			break;
	}
	putchar('\r');
endsw:
	inwait = 0;
	notell++;
	return (retval);
}
コード例 #19
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
void dopsdinc(void)
{
 INTPTR_T dummy; /* Used in the qstr function, I don't know its utility yet */
 int numericarg = 0; /* Number of numeric arg to test validity */

 if (amatch("pal",3))
   {
    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $0");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".incpal \"");

    if (readqstr() == 0)  /* read the filename */
    {
       error("bad filename in incpal");
       kill_line();
       return;
    }

    outstr(litq2);
    outstr("\"");

    if (match(","))
      outstr(",");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);
       outdec(dummy);
       if (match(","))
         outstr(",");

       }

    newl();
    ol(".code");

    if (numericarg>2)
      error("Maximum 2 numeric arg for incpal(name,\"filename\" [,start_pal] [,nb_pal])");

    kill_line();

    }
 else
 if (amatch("bin",3))
   {
    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $0");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CCHAR);

    if (!match(",")) {
        error("missing ,");
        kill_line();
        return;
    }

    ot(".incbin \"");
    if (readqstr() == 0)   /* read the filename */
    {
       error("bad filename in incbin");
       kill_line();
       return;
    }
    outstr(litq2);
    outstr("\"\n");

    if (!match(")"))
      error("missing )");

    newl();
    ol(".code");
    kill_line();
   }
 else
 if (amatch("bat",3))
   {

    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $0");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".incbat \"");

    if (readqstr() == 0)
    {
       error("bad filename in incbat");
       kill_line();
       return;
    }

    outstr(litq2);
    outstr("\"");

    if (match(","))
      outstr(",");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);
       outdec(dummy);
       if (match(","))
         outstr(",");

       }

    newl();
    ol(".code");

    if ((numericarg!=1) &&
        (numericarg!=3) &&
        (numericarg!=5))
      error("Either 1,3 or 5 numeric arguments are needed for incbat statement");

    kill_line();

    }
 else
 if (amatch("spr",3))
   {

    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $0");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".incspr \"");

    if (readqstr() == 0)
    {
       error("bad filename in incspr");
       kill_line();
       return;
    }

    outstr(litq2);
    outstr("\"");

    if (match(","))
      outstr(",");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);
       outdec(dummy);
       if (match(","))
         outstr(",");

       }

    newl();
    ol(".code");

    if ((numericarg!=0) &&
        (numericarg!=2) &&
        (numericarg!=4))
      error("Either 0,2 or 4 numeric arguments are needed for incspr statement");

    kill_line();

    }
 else
 if (amatch("chr",3))
   {

    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $0800");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".incchr \"");

    if (readqstr() == 0)
    {
       error("bad filename in incchr");
       kill_line();
       return;
    }

    outstr(litq2);
    outstr("\"");

    if (match(","))
      outstr(",");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);
       outdec(dummy);
       if (match(","))
         outstr(",");

       }

    newl();
    ol(".code");

    if ((numericarg!=0) &&
        (numericarg!=2) &&
        (numericarg!=4))
      error("Either 0,2 or 4 numeric arguments are needed for incchr statement");

    kill_line();

   }
 else
 if (amatch("chr_ex",6))
   {
	do_inc_ex(8);
   }
 else
 if (amatch("tile",4))
   {

    if (!match("("))
      error("missing (");

    ol(".data");
    ol(".dw $1000");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":\n");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".inctile \"");

    if (readqstr() == 0)
    {
       error("bad filename in inctile");
       kill_line();
       return;
    }

    outstr(litq2);
    outstr("\"");

    if (match(","))
      outstr(",");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);
       outdec(dummy);
       if (match(","))
         outstr(",");

       }

    newl();
    ol(".code");

    if ((numericarg!=0) &&
        (numericarg!=2) &&
        (numericarg!=4))
      error("Either 0,2 or 4 numeric arguments are needed for inctile statement");

    kill_line();

    }
 else
 if (amatch("tile_ex",7))
   {
	do_inc_ex(16);
   }
 else
   {
    error("Unknown include directive");
    kill_line();
    }
 return;
}
コード例 #20
0
ファイル: more.c プロジェクト: aalm/obsd-src
/*
 * Search for nth occurrence of regular expression contained in buf in the file
 */
int
search(char *buf, FILE *file, int n)
{
	off_t startline = Ftell(file);
	off_t line1 = startline;
	off_t line2 = startline;
	off_t line3 = startline;
	off_t saveln;
	int lncount, rv;
	char ebuf[BUFSIZ];
	static regex_t reg;
	static int initialized;

	context.line = saveln = Currline;
	context.chrctr = startline;
	lncount = 0;
	if (buf != NULL && *buf != '\0') {
		if ((rv = regcomp(&reg, buf, REG_NOSUB)) != 0) {
			initialized = 0;
			regerror(rv, &reg, ebuf, sizeof(ebuf));
			regfree(&reg);
			error(ebuf);
			return (-1);
		}
		initialized = 1;
	} else if (!initialized) {
		error("No previous regular expression");
		return (-1);
	}
	while (!feof(file)) {
		line3 = line2;
		line2 = line1;
		line1 = Ftell(file);
		rdline(file);
		lncount++;
		if ((rv = regexec(&reg, Line, 0, NULL, 0)) == 0) {
			if (--n == 0) {
				if (lncount > 3 || (lncount > 1 && no_intty)) {
					putchar('\n');
					if (clreol)
						cleareol();
					fputs("...skipping\n", stdout);
				}
				if (!no_intty) {
					Currline -= (lncount >= 3 ? 3 : lncount);
					Fseek(file, line3);
					if (noscroll) {
						if (clreol) {
							home();
							cleareol();
						} else
							doclear();
					}
				} else {
					kill_line();
					if (noscroll) {
					    if (clreol) {
						    home();
						    cleareol();
					    } else
						    doclear();
					}
					fputs(Line, stdout);
					putchar('\n');
				}
				break;
			}
		} else if (rv != REG_NOMATCH) {
			regerror(rv, &reg, ebuf, sizeof(ebuf));
			error(ebuf);
			return (-1);
		}
	}
	if (feof(file)) {
		if (!no_intty) {
			Currline = saveln;
			Fseek(file, startline);
		} else {
			fputs("\nPattern not found\n", stdout);
			end_it();
		}
		error("Pattern not found");
		return (-1);
	}
	return (0);
}
コード例 #21
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
void dopsddef(void)
{
  int numericarg = 0;
  INTPTR_T dummy;
  INTPTR_T dummy_array[16];
  int i;

  if (amatch("pal",3))
   {

    if (!match("("))
      error("missing (");

    readstr(); /* read the label name */
    addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ',' in #defpal");
        kill_line();
        return;
      }

    numericarg = 0;

    while (!match(")"))
    {
       number(&dummy_array[numericarg]);
       numericarg++;

       if (numericarg>16)
         error("No more than 16 colors can be defined at once");

       match(",");
    }

    ol(".data");
    prefix();
    outstr(litq2);
    outstr(":");
    ot(".defpal ");

    for (i = 0; i < numericarg; i++)
    {
       outhexfix(dummy_array[i],3);

       if (i < numericarg - 1)
       {
          outstr(",");
          if (i == 7)
          {
             outstr(" \\\n");
             ot("\t");
          }
       }
    }

    newl();
    ol(".code");

    kill_line();

    }
  else
 if (amatch("chr",3))
   {

    if (!match("("))
      error("missing (");

    ol(".data");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".defchr ");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);

       switch (numericarg)
         {
          case 1:
               outhexfix(dummy,4);
               outstr(",");
               break;
          case 2:
               outdec(dummy);
               outstr(",\\");
               newl();
               break;
          case 10:
               outhexfix(dummy,8);
               break;
          default:
       	       outhexfix(dummy,8);
               outstr(",\\");
               newl();

          }

         match(",");

       }

    newl();
    ol(".code");

    if (numericarg!=10)
      error("You must enter the VRAM address, the default palette and 8 values for pattern");

    kill_line();

    }
  else
 if (amatch("spr",3))
   {

    if (!match("("))
      error("missing (");

    ol(".data");

    readstr(); /* read the label name */
    prefix();
    outstr(litq2);
    outstr(":");
	addglb_far(litq2, CINT);

    if (!match(","))
      {
        error("missing ,");
        kill_line();
        return;
      }

    ot(".defspr ");

    numericarg = 0;

    while (!match(")"))
      {
       numericarg++;

       number(&dummy);

       switch (numericarg)
         {
          case 1:
               outhexfix(dummy,4);
               outstr(",");
               break;
          case 2:
               outdec(dummy);
               outstr(",\\");
               newl();
               break;
          case 34:
               outhexfix(dummy,8);
               break;
          default:
       	       outhexfix(dummy,8);
               outstr(",");

               if (!(numericarg & 1))
                 {
                  outstr("\\");
                  newl();
                 }

          }

       match(",");

       }

    newl();
    ol(".code");

    if (numericarg!=34)
      error("You must enter the VRAM address, the default palette and 32 values for pattern");

    kill_line();

    }
  else
    {
      error("Unknown define directive");
      kill_line();
    }
 return;
 }
コード例 #22
0
ファイル: console.c プロジェクト: salexa92/os161ass1
void consoleintr(int (*getc)(void)) {
	int c, doprocdump = 0;
	// int historyInd = 1; //when arr not full we should put here the last  command written, most cases, when full davka should be 15
	acquire(&cons.lock);
	int tmp;
	while ((c = getc()) >= 0) {
		switch (c) {
		case C('P'):  // Process listing.
					doprocdump = 1; // procdump() locks cons.lock indirectly; invoke later
		break;
		case C('U'):  // Kill line.
					kill_line();
		break;
		case C('H'):
		case '\x7f':  // Backspace
			if (input.e != input.w) { //regular caret
				input.e--;
				input.f--;
				if (input.e < input.f) {  // middle caret
					midflag = input.f - input.e;
					int i = input.e;
					while (i < input.f) {
						input.buf[i % INPUT_BUF] =
								input.buf[(i + 1) % INPUT_BUF];
						i++;
					}
				}
				consputc(BACKSPACE);
				midflag = 0;
			}
			break;
		case KEY_LEFT: // Left arrow
			if (input.e != input.w) {
				input.e--;
				consputc(KEY_LEFT);
			}
			break;
		case KEY_RIGHT: // Right arrow
			if (input.f > input.e) {
				input.e++;
				consputc(KEY_RIGHT);
			}
			break;
		case KEY_UP: // Key Up
			if (historyInd != 0)
				kill_line();
			if (historyList.size > 0) {
				char buffer[INPUT_BUF];
				tmp = (historyInd - 1) % historyList.size;
				if (tmp > -1) {
					historyInd = tmp;
					if (history(buffer, historyInd) == 0) {
						setHistory(buffer);
					} else
						panic("history");
				}
			}
			break;
		case KEY_DOWN: // Key Down
			kill_line();
			if (historyInd < historyList.size - 1) {
				char buffer[INPUT_BUF];
				historyInd = (historyInd + 1) % MAX_HISTORY;
				if (historyInd < historyList.size) {
					if (history(buffer, historyInd) == 0) {
						setHistory(buffer);
					} else
						panic("history");
				} else
					kill_line();
			} else if (historyInd == historyList.size - 1)
				kill_line();
			break;
		default:
			if (c != 0 && input.f - input.r < INPUT_BUF) {
				c = (c == '\r') ? '\n' : c;
				if (c == '\n') {
					// if any command is currently written, first record it in the history books
					if (input.f >= input.w) {
						updateHistory();
					}
				}
				//*** regular caret ***
				if (input.e >= input.f) {
					input.buf[input.e++ % INPUT_BUF] = c;
					consputc(c);
				}
				//*** middle caret ***
				else {
					if (c == '\n') {
						input.buf[input.f % INPUT_BUF] = c;
						input.e = input.f + 1;
						consputc(c);
					} else {
						int index = input.f;
						while (index > input.e) { // first shift by one each char in buffer from caret to the end
							input.buf[index % INPUT_BUF] = input.buf[(index - 1)
																	 % INPUT_BUF];
							index--;
						}
						input.buf[input.e % INPUT_BUF] = c; // Write new char in buffer
						int i = input.e;
						index = input.f + 1;
						while (i < index) // Print those chars from buffer to console
							consputc(input.buf[i++ % INPUT_BUF]);
						i = input.e;
						index = input.f;
						while (i < index) { // move caret back to it's place after the new character
							consputc(KEY_LEFT);
							i++;
						}
						input.e++;
					}
				}
				input.f++;
				if (c == '\n' || c == C('D') || input.f == input.r + INPUT_BUF) {
					input.w = input.f;
					input.e = input.f;
					wakeup(&input.r);
				}
			}
			break;
		}
	}
	release(&cons.lock);
	if (doprocdump) {
		procdump();  // now call procdump() wo. cons.lock held
	}
}
コード例 #23
0
ファイル: pseudo.c プロジェクト: BouKiCHi/husic_git
void
do_inc_ex(int type)
{
	int end;
	int i;
	INTPTR_T j;
	int num;
	int nb_tile;
	char label[NAMESIZE];
	char label2[NAMESIZE];
	char str[NAMESIZE+32];
	struct {
		char fname[FILENAMESIZE];
		INTPTR_T  arg[5];
	} tiles[16];

	if(!match("(")) {
		error("missing '('");
		kill_line();
		return;
	}

	readstr(); /* read the label name */
	strcpy(label, litq2);
	strcpy(label2, litq2);
	strcpy(str, "__data__");
	for(i = (int)strlen(label2), j = 0; i < NAMEMAX; i++)
		label2[i] = str[j++];
	label2[i] = '\0';
	addglb(label2, ARRAY, CINT, 0, EXTERN);
	addglb(label, ARRAY, CINT, 0, EXTERN);

	if(!match(",")) {
		error("comma missing");
		kill_line();
		return;
	}

	end = 0;
	num = 0;
	nb_tile = 0;
	while (!end) {
		// if (match("\\"));
	    if(!readqstr()) {
			error("not a file name");
			kill_line();
			return;
		}
		if(!match(",")) {
			error("comma missing");
			kill_line();
			return;
		}
		strcpy(tiles[num].fname, litq2);

		for (i = 0; i < 5; i++) {
			// if (match("\\"));
			if(!number(&tiles[num].arg[i])) {
				error("not a number");
				kill_line();
				return;
			}
			if (match(")")) {
				if (i == 4) {
					kill_line();
					end = 1;
					break;
				}
				else {
					error("arg missing");
					kill_line();
					return;
				}
			}
			if(!match(",")) {
				error("comma missing");
				kill_line();
				return;
			}
			while((ch() == ' ') || (ch() == '\t'))
				gch();
			if (ch() == '\0') {
				error("arg missing");
				kill_line();
				return;
			}
		}
		nb_tile += tiles[num].arg[2] * tiles[num].arg[3];
		num++;
		if (num == 16) {
			if(!end) {
				error("too many args (max 16 files)");
				kill_line();
				return;
			}
		}
	}

	/* create const array to hold extra infos */
	new_const();
	const_val[const_val_idx++] = const_data_idx;	/* number of tile */
	sprintf(str, "%i", nb_tile);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile size */
	sprintf(str, "%i", type);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile bank */
	sprintf(str, "BANK(_%s)", label2);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile addr */
	sprintf(str, "     _%s", label2);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = -(litptr + 1024);	/* pal idx table addr */
	add_const(CINT);

	/* create pal idx table */
	for(i = 0; i < num; i++) {
		j = tiles[i].arg[2] * tiles[i].arg[3];
		while (j) {
			j--;
			if (litptr < LITMAX)
				litq[litptr++] = (tiles[i].arg[4] << 4);
		}
	}

	/* dump incchr/tile cmds */
	ol(".data");
	if (type == 8)
		ol(".dw $0800");
	else
		ol(".dw $1000");
	prefix();
	outstr(label2);
	outstr(":\n");
	for(i = 0; i < num; i++) {
		if (type == 8)
			ot(".incchr \"");
		else
			ot(".inctile \"");
		outstr(tiles[i].fname);
		outstr("\"");
		for (j = 0; j < 4; j++) {
			outstr(",");
			outdec(tiles[i].arg[j]);
		}
		newl();
	}
	ol(".code");
	kill_line();
}