Example #1
0
static void
exvwarning(int sv_errno, const char *msg, va_list ap)
{
	/* Partially emulate line buffered output so that:
	 *	printf '%d\n' 1 a 2
	 * and
	 *	printf '%d %d %d\n' 1 a 2
	 * both generate sensible text when stdout and stderr are merged.
	 */
	if (output.nextc != output.buf && output.nextc[-1] == '\n')
		flushout(&output);
	if (commandname)
		outfmt(&errout, "%s: ", commandname);
	else
		outfmt(&errout, "%s: ", getprogname());
	if (msg != NULL) {
		doformat(&errout, msg, ap);
		if (sv_errno >= 0)
			outfmt(&errout, ": ");
	}
	if (sv_errno >= 0)
		outfmt(&errout, "%s", strerror(sv_errno));
	out2c('\n');
	flushout(&errout);
}
Example #2
0
void
flushall(void)
{
	flushout(&output);
#ifdef FLUSHERR
	flushout(&errout);
#endif
}
Example #3
0
/*
 * Debugging
 */
void
    peektokens(Tokenrow * trp, char *str)
{
    Token *tp;

    tp = trp->tp;
    flushout();
    if (str)
        fprintf(stderr, "%s ", str);
    if (tp < trp->bp || tp > trp->lp)
        fprintf(stderr, "(tp offset %ld) ", (long int) (tp - trp->bp));
    for (tp = trp->bp; tp < trp->lp && tp < trp->bp + 32; tp++)
    {
        if (tp->type != NL)
        {
            int c = tp->t[tp->len];

            tp->t[tp->len] = 0;
            fprintf(stderr, "%s", tp->t);
            tp->t[tp->len] = (uchar) c;
        }
        fprintf(stderr, tp == trp->tp ? "{%x*} " : "{%x} ", tp->type);
    }
    fprintf(stderr, "\n");
    fflush(stderr);
}
Example #4
0
int
main(int argc, char **argv)
{
	Tokenrow tr;
	time_t t;
	STATIC char ebuf[BUFSIZ];

#if defined(__GNO__) && defined(__STACK_CHECK__)
	atexit(printStack);
#endif
	setbuf(stderr, ebuf);
	t = time(NULL);
	curtime = ctime(&t);
	maketokenrow(3, &tr);
	expandlex();
	setup(argc, argv);
	fixlex();
	iniths();
	genline();
	process(&tr);
	flushout();
	fflush(stderr);
	exit(nerrs > 0);
	return 0;
}
Example #5
0
/*
 * Debugging
 */
void
peektokens(Tokenrow *trp, char *str)
{
	Token *tp;

	tp = trp->tp;
	flushout();
	if (str)
		fprintf(stderr, "%s ", str);
	if (tp<trp->bp || tp>trp->lp)
		fprintf(stderr, "(tp offset %d) ", tp-trp->bp);
	for (tp=trp->bp; tp<trp->lp && tp<trp->bp+32; tp++) {
		if (tp->type!=NL) {
			int c = tp->t[tp->len];
			tp->t[tp->len] = 0;
			fprintf(stderr, "%s", tp->t);
			tp->t[tp->len] = c;
		}
		if (tp->type==NAME) {
			fprintf(stderr, tp==trp->tp?"{*":"{");
			prhideset(tp->hideset);
			fprintf(stderr, "} ");
		} else
			fprintf(stderr, tp==trp->tp?"{%x*} ":"{%x} ", tp->type);
	}
	fprintf(stderr, "\n");
	fflush(stderr);
}
Example #6
0
static void
xtracecommand(struct arglist *varlist, struct arglist *arglist)
{
	struct strlist *sp;
	char sep = 0;
	const char *p, *ps4;

	ps4 = expandstr(ps4val());
	out2str(ps4 != NULL ? ps4 : ps4val());
	for (sp = varlist->list ; sp ; sp = sp->next) {
		if (sep != 0)
			out2c(' ');
		p = strchr(sp->text, '=');
		if (p != NULL) {
			p++;
			outbin(sp->text, p - sp->text, out2);
			out2qstr(p);
		} else
			out2qstr(sp->text);
		sep = ' ';
	}
	for (sp = arglist->list ; sp ; sp = sp->next) {
		if (sep != 0)
			out2c(' ');
		out2qstr(sp->text);
		sep = ' ';
	}
	out2c('\n');
	flushout(&errout);
}
Example #7
0
static void
xtracecommand(struct arglist *varlist, int argc, char **argv)
{
	char sep = 0;
	const char *text, *p, *ps4;
	int i;

	ps4 = expandstr(ps4val());
	out2str(ps4 != NULL ? ps4 : ps4val());
	for (i = 0; i < varlist->count; i++) {
		text = varlist->args[i];
		if (sep != 0)
			out2c(' ');
		p = strchr(text, '=');
		if (p != NULL) {
			p++;
			outbin(text, p - text, out2);
			out2qstr(p);
		} else
			out2qstr(text);
		sep = ' ';
	}
	for (i = 0; i < argc; i++) {
		text = argv[i];
		if (sep != 0)
			out2c(' ');
		out2qstr(text);
		sep = ' ';
	}
	out2c('\n');
	flushout(&errout);
}
Example #8
0
void
emptyoutbuf(struct output *dest)
{
	int offset;

	if (dest->fd == BLOCK_OUT) {
		dest->nextc = out_junk;
		dest->nleft = sizeof out_junk;
		dest->flags |= OUTPUT_ERR;
	} else if (dest->buf == NULL) {
		INTOFF;
		dest->buf = ckmalloc(dest->bufsize);
		dest->nextc = dest->buf;
		dest->nleft = dest->bufsize;
		INTON;
	} else if (dest->fd == MEM_OUT) {
		offset = dest->bufsize;
		INTOFF;
		dest->bufsize <<= 1;
		dest->buf = ckrealloc(dest->buf, dest->bufsize);
		dest->nleft = dest->bufsize - offset;
		dest->nextc = dest->buf + offset;
		INTON;
	} else {
		flushout(dest);
	}
	dest->nleft--;
}
Example #9
0
void
outshstr(const char *p, struct output *file)
{
	static const char norm_chars [] \
		= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	int need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0;
	char c;

	if (need_q)
		outc('\'', file);

	while (c = *p++, c != 0){
		if (c != '\''){
			outc(c, file);
		}else{
			outc('\'', file);
			outc('\\', file);
			outc(c, file);
			outc('\'', file);
		}
	}

	if (need_q)
		outc('\'', file);

	if (file == out2)
		flushout(file);
}
Example #10
0
void
puttokens(Tokenrow *trp)
{
	Token *tp;
	int len;
	uchar *p;

	if (verbose)
		peektokens(trp, "");
	tp = trp->bp;
	for (; tp<trp->lp; tp++) {
		len = tp->len+tp->wslen;
		p = tp->t-tp->wslen;
		while (tp<trp->lp-1 && p+len == (tp+1)->t - (tp+1)->wslen) {
			tp++;
			len += tp->wslen+tp->len;
		}
		memcpy(wbp, p, len);
		wbp += len;
		if (wbp >= &wbuf[OBS]) {
			write(STDOUT_FILENO, wbuf, OBS);
			if (wbp > &wbuf[OBS])
				memcpy(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
			wbp -= OBS;
		}
	}
	trp->tp = tp;
	if (cursource->fd==0)
		flushout();
}
static inline void writeout_short (int value) {
  if (unlikely (wptr > Buff + BUFFSIZE - 2)) {
    flushout();
  }
  *((short *) wptr) = value;
  wptr += 2;
}
static inline void writeout_long (long long value) {
  if (unlikely (wptr > Buff + BUFFSIZE - 8)) {
    flushout();
  }
  *((long long *) wptr) = value;
  wptr += 8;
}
static inline void writeout_int (int value) {
  if (unlikely (wptr > Buff + BUFFSIZE - 4)) {
    flushout();
  }
  *((int *) wptr) = value;
  wptr += 4;
}
Example #14
0
void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;
	enum skipstate skip;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsigs)
			dotrap();
		inter = 0;
		if (iflag == 1 && top) {
			inter = 1;
			showjobs(out2, SHOW_CHANGED);
			chkmail(0);
			flushout(&errout);
			nflag = 0;
		}
		n = parsecmd(inter);
		TRACE(("cmdloop: "); showtree(n));
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (nflag)
				break;
			if (!stoppedjobs()) {
				if (!iflag || !Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, EV_MORE);
		}
		popstackmark(&smark);
		setstackmark(&smark);

		/*
		 * Any SKIP* can occur here!  SKIP(FUNC|BREAK|CONT) occur when
		 * a dotcmd is in a loop or a function body and appropriate
		 * built-ins occurs in file scope in the sourced file.  Values
		 * other than SKIPFILE are reset by the appropriate eval*()
		 * that contained the dotcmd() call.
		 */
		skip = current_skipstate();
		if (skip != SKIPNONE) {
			if (skip == SKIPFILE)
				stop_skipping();
			break;
		}
	}
	popstackmark(&smark);
}
Example #15
0
void
outstr(const char *p, struct output *file)
{
	while (*p)
		outc(*p++, file);
	if (file == out2)
		flushout(file);
}
Example #16
0
int
main(int argc, char * const *argv)
{
	int opt;

	memset(&LOG, 0, sizeof LOG);
	VUT_Init(progname);

	while ((opt = getopt(argc, argv, vopt_optstring)) != -1) {
		switch (opt) {
		case 'a':
			/* Append to file */
			LOG.a_opt = 1;
			break;
		case 'B':
			/* Binary output */
			LOG.B_opt = 1;
			break;
		case 'h':
			/* Usage help */
			usage(0);
			break;
		case 'w':
			/* Write to file */
			REPLACE(LOG.w_arg, optarg);
			break;
		default:
			if (!VUT_Arg(opt, optarg))
				usage(1);
		}
	}

	if (optind != argc)
		usage(1);

	/* Setup output */
	if (LOG.B_opt)
		VUT.dispatch_f = VSL_WriteTransactions;
	else
		VUT.dispatch_f = VSL_PrintTransactions;
	if (LOG.w_arg) {
		openout(LOG.a_opt);
		AN(LOG.fo);
		VUT.sighup_f = rotateout;
	} else
		LOG.fo = stdout;
	VUT.idle_f = flushout;

	VUT_Setup();
	VUT_Main();
	VUT_Fini();

	(void)flushout();

	exit(0);
}
Example #17
0
void
dprintf(const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	doformat(out2, fmt, ap);
	va_end(ap);
	flushout(out2);
}
Example #18
0
void
dprintf(shinstance *psh, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	doformat(psh->out2, fmt, ap);
	va_end(ap);
	flushout(psh->out2);
}
Example #19
0
static void debugPrint(void * /*userdata*/, const char *fmt, ...)
{
    char buffer[4096];
    std::va_list args;
    va_start(args, fmt);
    int rc = std::vsnprintf(buffer, sizeof(buffer), fmt, args);
    va_end(args);
    if(rc > 0)
    {
        std::fprintf(stdout, " - Debug: %s\n", buffer);
        flushout(stdout);
    }
}
Example #20
0
File: main.c Project: cbsd/cbsd
static void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsig)
			dotrap();
		inter = 0;
		if (iflag && top) {
			inter++;
			showjobs(1, SHOWJOBS_DEFAULT);
#ifndef CBSD
			chkmail(0);
#endif
			flushout(&output);
		}
		n = parsecmd(inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs()) {
				if (!Iflag)
					break;
				out2fmt_flush("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, 0);
		}
		popstackmark(&smark);
		setstackmark(&smark);
		if (evalskip != 0) {
			if (evalskip == SKIPRETURN)
				evalskip = 0;
			break;
		}
	}
	popstackmark(&smark);
}
Example #21
0
File: rle.c Project: ombt/ombt
// run-length decoding scheme
void
rldecode(int infd, int outfd)
{
	// sanity checks
	MustBeTrue(infd >= 0 && outfd >= 0);

	// read in file and encode
	unsigned char data1, data2, data3;
	while (getdata(infd, data1) > 0)
	{
		if (data1 != EscapeValue)
		{
			// just write the data out
			MustBeTrue(putdata(outfd, data1) == 1);
		}
		else
		{
			// we have a possible runcount and value
			MustBeTrue(getdata(infd, data2) > 0);
			if (data2 == ZeroValue)
			{
				// write out escape value
				MustBeTrue(putdata(outfd, data1) == 1);
			}
			else
			{
				// get data to write
				MustBeTrue(getdata(infd, data3) > 0);
				for (unsigned char i=0; i<=data2; i++)
				{
					MustBeTrue(putdata(outfd, data3) == 1);
				}
			}
		}
	}

	// flush output buffer
	MustBeTrue(flushout(outfd) == 1);

	// close files
	MustBeTrue(infd == 0 || close(infd) == OK);
	MustBeTrue(outfd == 1 || close(outfd) == OK);

	// all done
	return;
}
Example #22
0
void
cmdloop(struct shinstance *psh, int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE((psh, "cmdloop(%d) called\n", top));
	setstackmark(psh, &smark);
	for (;;) {
		if (psh->pendingsigs)
			dotrap(psh);
		inter = 0;
		if (iflag(psh) && top) {
			inter = 1;
			showjobs(psh, psh->out2, SHOW_CHANGED);
			chkmail(psh, 0);
			flushout(&psh->errout);
		}
		n = parsecmd(psh, inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs(psh)) {
				if (!Iflag(psh))
					break;
				out2str(psh, "\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag(psh) == 0) {
			psh->job_warning = (psh->job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(psh, n, 0);
		}
		popstackmark(psh, &smark);
		setstackmark(psh, &smark);
		if (psh->evalskip == SKIPFILE) {
			psh->evalskip = 0;
			break;
		}
	}
	popstackmark(psh, &smark);
}
Example #23
0
void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsigs)
			dotrap();
		inter = 0;
		if (iflag && top) {
			inter = 1;
			showjobs(out2, SHOW_CHANGED);
			chkmail(0);
			flushout(&errout);
		}
		n = parsecmd(inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs()) {
				if (!Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, 0);
		}
		popstackmark(&smark);
		setstackmark(&smark);
		if (evalskip == SKIPFILE) {
			evalskip = 0;
			break;
		}
	}
	popstackmark(&smark);
}
static inline void writeout (const void *D, size_t len) {
  const char *d = D;
  while (len > 0) {
    int r = Buff + BUFFSIZE - wptr;
    if (r > len) { 
      memcpy (wptr, d, len);
      wptr += len;
      return;
    }
    memcpy (wptr, d, r);
    d += r;
    wptr += r;
    len -= r;
    if (len > 0) {
      flushout();
    }
  }                                
}
Example #25
0
int writeout (const void *D, size_t len) {
  const char *d = D;
  while (len > 0) {
    int r = Buff + BUFFSIZE - wptr;
    if (r > len) {
      r = len;
    }
    memcpy (wptr, d, r);
    d += r;
    wptr += r;
    len -= r;
    if (len > 0) {
      if (flushout () < 0) {
        return -1;
      }
    }
  }
  return 0;
}
Example #26
0
File: cpp.c Project: nikon77/lcc42
int main(int argc, char **argv) {
	Tokenrow tr;			/* token row */
	time_t t;				/* 保存当前时间的整数值 */
	char ebuf[BUFSIZ];		/* stderr buffer(stderr默认是没有buffer的,我们为其建立一个buffer) */

	setbuf(stderr, ebuf);	/* 设定标准错误的输出缓冲区为ebuf */
	t = time(NULL);			/* 获得当前时间的整数值 */
	curtime = ctime(&t);	/* 获得当前时间的字串值(例如: Sat Jul  4 12:27:13 2003)保存到全局变量curtime中 */
	maketokenrow(3, &tr);	/* 建立一个 token row(默认分配3个Token结构) */
	expandlex();			/* 展开状态机 */
	setup(argc, argv);		/* 建立关键字hash表;处理命令行选项参数;将输入源文件压栈 */
	fixlex();				/* 适时的关闭兼容C++单行注释兼容特性 */
	iniths();				/* 初始化hideset,TODO: 啥是hideset? */
	genline();				/* 产生一个行控制(line control)信息 */
	process(&tr);			/* 开始处理源程序 */
	flushout();				/* flush output buffer to stdout */
	fflush(stderr);			/* flush stderr buffer */
	exit(nerrs > 0);		/* 退出进程 */
	return 0;
}
Example #27
0
File: jobs.c Project: dpl0/soc2013
int
fgcmd(int argc __unused, char **argv)
{
	struct job *jp;
	pid_t pgrp;
	int status;

	jp = getjob(argv[1]);
	if (jp->jobctl == 0)
		error("job not created under job control");
	printjobcmd(jp);
	flushout(&output);
	pgrp = jp->ps[0].pid;
	tcsetpgrp(ttyfd, pgrp);
	restartjob(jp);
	jp->foreground = 1;
	INTOFF;
	status = waitforjob(jp, (int *)NULL);
	INTON;
	return status;
}
Example #28
0
int main(int argc, char **argv)
{
    Tokenrow tr;
    time_t t;
    char ebuf[BUFSIZ];

    setbuf(stderr, ebuf);
    t = time(NULL);
    curtime = ctime(&t);
    maketokenrow(3, &tr);
    expandlex();
    setup(argc, argv);
    fixlex();
    iniths();
    genline();
    process(&tr);
    flushout();
    fflush(stderr);
    exit(nerrs > 0);
    return 0;
}
Example #29
0
void
puttokens(Tokenrow *trp)
{
	Token *tp;
	int len;
	uchar *p;

	if (verbose)
		peektokens(trp, "");
	tp = trp->bp;
	for (; tp<trp->lp; tp++) {
		len = tp->len+tp->wslen;
		p = tp->t-tp->wslen;
		while (tp<trp->lp-1 && p+len == (tp+1)->t - (tp+1)->wslen) {
			tp++;
			len += tp->wslen+tp->len;
		}
		if (len>OBS/2) {		/* handle giant token */
			if (wbp > wbuf)
				fwrite(wbuf, 1, wbp-wbuf, stdout);
			fwrite((char *)p, 1, len, stdout);
			wbp = wbuf;
		} else {	
			memcpy(wbp, p, len);
			wbp += len;
		}
		if (wbp >= &wbuf[OBS]) {
			fwrite(wbuf, 1, OBS, stdout);
			if (wbp > &wbuf[OBS])
				memcpy(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
			wbp -= OBS;
		}
	}
	trp->tp = tp;
	if (cursource->fd==stdin)
		flushout();
}
Example #30
0
int write_image (struct lev_storage_file *E, char *data, crc32_logpos_t *P) {
  clearin ();
  assert (E->type == LEV_STORAGE_FILE || (E->type == LEV_STORAGE_HIDE_FILE && !E->size));
  const unsigned zero = 0;
  int l = (E->size + 3) & -4;
  int padded_zero_bytes = l - E->size;
  assert (padded_zero_bytes >= 0 && padded_zero_bytes < 4);
  if (padded_zero_bytes) {
    assert (!memcmp (data + E->size, &zero, padded_zero_bytes));
  }
  P->crc32_complement = crc32_partial (E, sizeof (*E), P->crc32_complement);
  P->log_pos += sizeof (*E);
  P->crc32_complement = crc32_partial (data, l, P->crc32_complement);
  P->log_pos += l;
  struct lev_crc32 C;
  C.type = LEV_CRC32;
  C.pos = P->log_pos;
  C.crc32 = ~P->crc32_complement;
  C.timestamp = last_mtime;
  P->crc32_complement = crc32_partial (&C, sizeof (C), P->crc32_complement);
  P->log_pos += sizeof (C);
  if (writeout (E, sizeof (*E)) < 0 ||
      writeout (data, l) < 0 ||
      writeout (&C, sizeof (C)) < 0 ||
      flushout () < 0) {
    return -1;
  }

  if (test_mode) {
    char base64url_secret[12];
    int r = base64url_encode ((unsigned char *) &E->secret, 8, base64url_secret, 12);
    assert (!r);
    printf ("wget -O %d.jpg http://127.0.0.1:%d/v%lld/%x/%s.jpg\n", E->local_id, http_port, volume_id, E->local_id, base64url_secret);
  }
  return 0;
}