Example #1
0
File: srv.c Project: npe9/harvey
void
srv(Srv *srv)
{
	Req *r;

	fmtinstall('D', dirfmt);
	fmtinstall('F', fcallfmt);

	if(srv->fpool == nil)
		srv->fpool = allocfidpool(srv->destroyfid);
	if(srv->rpool == nil)
		srv->rpool = allocreqpool(srv->destroyreq);
	if(srv->msize == 0)
		srv->msize = 8192+IOHDRSZ;

	changemsize(srv, srv->msize);

	srv->fpool->srv = srv;
	srv->rpool->srv = srv;

	while(r = getreq(srv)){
		if(r->error){
			respond(r, r->error);
			continue;	
		}
		switch(r->ifcall.type){
		default:
			respond(r, "unknown message");
			break;
		case Tversion:	sversion(srv, r);	break;
		case Tauth:	sauth(srv, r);	break;
		case Tattach:	sattach(srv, r);	break;
		case Tflush:	sflush(srv, r);	break;
		case Twalk:	swalk(srv, r);	break;
		case Topen:	sopen(srv, r);	break;
		case Tcreate:	screate(srv, r);	break;
		case Tread:	sread(srv, r);	break;
		case Twrite:	swrite(srv, r);	break;
		case Tclunk:	sclunk(srv, r);	break;
		case Tremove:	sremove(srv, r);	break;
		case Tstat:	sstat(srv, r);	break;
		case Twstat:	swstat(srv, r);	break;
		}
	}

	free(srv->rbuf);
	srv->rbuf = nil;
	free(srv->wbuf);
	srv->wbuf = nil;
	srv->msize = 0;
	freefidpool(srv->fpool);
	srv->fpool = nil;
	freereqpool(srv->rpool);
	srv->rpool = nil;

	if(srv->end)
		srv->end(srv);
}
Example #2
0
static void
error(char *s1, char *s2)
{
	(void) fprintf(stderr, "sdiff: ");
	(void) fprintf(stderr, s1, s2);
	(void) putc('\n', stderr);
	sremove();
	exit(2);
}
Example #3
0
int main() {
  int c, len;
  char s[MAXLINE];
  printf("start...\n");
  len = 0;
  while ((c = getchar()) != '\n' && len < MAXLINE) {
    s[len] = c;
    len++;
  }
  s[len] = '\0';
  if (sremove(s) > -1) {
    printf("{%s}\n", s);
  }
  
  return 0;
}
Example #4
0
static void
cmdin(void)
{
	char	*cp, *ename;
	int	notacc;

	(void) fclose(left);
	(void) fclose(right);
	notacc = 1;
	while (notacc) {
		(void) putc(PROMPT, stdout);
		if ((cp = fgets(inbuf, 10, stdin)) == NULL) {
			(void) putc('\n', stdout);
			break;
		}
		switch (*cp) {

		case 's':
			silent = 1;
			break;

		case 'v':
			silent = 0;
			break;

		case 'q':
			sremove();
			exit(rcode);
			/* NOTREACHED */
			break;

		case 'l':
			cpp(ltemp, left, odes);
			notacc = 0;
			break;

		case 'r':
			cpp(rtemp, right, odes);
			notacc = 0;
			break;

		case 'e':
			while (*++cp == ' ')
				;
			switch (*cp) {
			case 'l':
			case '<':
				notacc = 0;
				ename = ltemp;
				edit(ename);
				break;

			case 'r':
			case '>':
				notacc = 0;
				ename = rtemp;
				edit(ename);
				break;

			case 'b':
			case '|':
				if ((tempdes = fopen(temp, "w")) == NULL)
					error(gettext(
						"Cannot open temp file %s"),
						temp);
				cpp(ltemp, left, tempdes);
				cpp(rtemp, right, tempdes);
				(void) fclose(tempdes);
				notacc = 0;
				ename = temp;
				edit(ename);
				break;

			case '\n':
				if ((tempdes = fopen(temp, "w")) == NULL)
					error(gettext(
						"Cannot open temp file %s"),
						temp);
				(void) fclose(tempdes);
				notacc = 0;
				ename = temp;
				edit(ename);
				break;
			default:
				(void) fprintf(stderr, gettext(
					"Illegal command %s reenter\n"),
					cp);
				break;
			}
			if (notacc == 0)
				cpp(ename, tempdes, odes);
			break;

		default:
			(void) fprintf(stderr, gettext(
				"Illegal command reenter\n"));
			break;
		}
	}
}
Example #5
0
static void
onintr(void)
{
	sremove();
	exit(rcode);
}
Example #6
0
int
main(int argc, char **argv)
{
	int	com;
	int	n1, n2, n;
	char	*bp;
	int	lfd = -1;
	int	rfd = -1;

	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGHUP, (void (*)(int))onintr);
	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGINT, (void (*)(int))onintr);
	if (signal(SIGPIPE, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGPIPE, (void (*)(int))onintr);
	if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
		(void) signal((int)SIGTERM, (void (*)(int))onintr);

	(void) setlocale(LC_ALL, "");
#if	!defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	while (--argc > 1 && **++argv == '-') {
		switch (*++*argv) {

		case 'w':
			/* -w# instead of -w # */
			if (*++*argv)
				llen = atoi(*argv);
			else {
				argc--;
				llen = atoi(*++argv);
			}
			if (llen < WLEN)
				error(gettext("Wrong line length %s"), *argv);
			if (llen > LMAX)
				llen = LMAX;
			break;

		case 'l':
			leftonly++;
			break;

		case 's':
			silent++;
			break;
		case 'o':
			oflag++;
			argc--;
			ofile = *++argv;
			break;
		default:
			error(gettext("Illegal argument: %s"), *argv);
		}
	}
	if (argc != 2) {
		(void) fprintf(stderr, gettext(
		"Usage: sdiff [-l] [-s] [-o output] [-w #] file1 file2\n"));
		return (2);
	}

	file1 = *argv++;
	file2 = *argv;
	file1 = filename(file1, file2);
	file2 = filename(file2, file1);
	hlen = (llen - WGUTTER +1)/2;

	if ((fdes1 = fopen(file1, "r")) == NULL)
		error(gettext("Cannot open: %s"), file1);

	if ((fdes2 = fopen(file2, "r")) == NULL)
		error(gettext("Cannot open: %s"), file2);

	if (oflag) {
		if (tempfd == -1) {
			temp = strdup("/tmp/sdiffXXXXXX");
			tempfd = mkstemp(temp);
			if (tempfd == -1) {
				error(gettext(
					"Cannot open/create temp %s"), temp);
				free(temp);
				temp = 0;
			}
		}
		ltemp = strdup("/tmp/sdifflXXXXXX");
		if ((lfd = mkstemp(ltemp)) == -1 ||
			(left = fdopen(lfd, "w")) == NULL)
				error(gettext(
					"Cannot open/create temp %s"),
					ltemp);
		rtemp = strdup("/tmp/sdiffrXXXXXX");
		if ((rfd = mkstemp(rtemp)) == -1 ||
			(right = fdopen(rfd, "w")) == NULL)
				error(gettext(
					"Cannot open/create temp file %s"),
					rtemp);
		if ((odes = fopen(ofile, "w")) == NULL)
			error(gettext("Cannot open output %s"), ofile);
	}
	/* Call DIFF command */
	(void) strcpy(diffcmd, DIFF);
	(void) strcat(diffcmd, file1);
	(void) strcat(diffcmd, " ");
	(void) strcat(diffcmd, file2);
	diffdes = popen(diffcmd, "r");

	num1 = num2 = 0;

	/*
	 * Read in diff output and decode commands
	 * "change" is used to determine character to put in gutter
	 *  num1 and num2 counts the number of lines in file1 and 2
	 */

	n = 0;
	while ((bp = fgetline(diffdes)) != NULL) {
		change = ' ';
		com = cmd(bp);

	/*
	 * handles all diff output that is not cmd
	 * lines starting with <, >, ., ---
	 */
		if (com == 0)
			continue;

	/* Catch up to from1 and from2 */
		rcode = 1;
		n1 = from1 - num1;
		n2 = from2 - num2;
		n = n1 > n2 ? n2 : n1;
		if (com == 'c' && n > 0)
			n--;
		if (silent)
			(void) fputs(bp, stdout);
		while (n-- > 0) {
			(void) put1();
			(void) put2();
			if (!silent)
				(void) putc('\n', stdout);
			midflg = 0;
		}

	/* Process diff cmd */
		switch (com) {

		case 'a':
			change = '>';
			while (num2 < to2) {
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		case 'd':
			change = '<';
			while (num1 < to1) {
				(void) put1();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		case 'c':
			n1 = to1 - from1;
			n2 = to2 - from2;
			n = n1 > n2 ? n2 : n1;
			change = '|';
			do {
				(void) put1();
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			} while (n--);

			change = '<';
			while (num1 < to1) {
				(void) put1();
				(void) putc('\n', stdout);
				midflg = 0;
			}

			change = '>';
			while (num2 < to2) {
				(void) put2();
				(void) putc('\n', stdout);
				midflg = 0;
			}
			break;

		default:
			(void) fprintf(stderr, gettext(
				"%c: cmd not found\n"), cmd);
			break;
		}

		if (oflag == 1 && com != 0) {
			cmdin();
			if ((left = fopen(ltemp, "w")) == NULL)
				error(gettext(
					"main: Cannot open temp %s"), ltemp);
			if ((right = fopen(rtemp, "w")) == NULL)
				error(gettext(
					"main: Cannot open temp %s"), rtemp);
		}
	}
	/* put out remainder of input files */

	while (put1()) {
		(void) put2();
		if (!silent)
			(void) putc('\n', stdout);
		midflg = 0;
	}
	if (odes)
		(void) fclose(odes);
	sremove();
	return (rcode);
}