~ft/gemnine

456b709807fdeb7c725731fd1469f7181b342893 — Sigrid Solveig Haflínudóttir 1 year, 4 months ago 11e93db master
dump raw to stdout if not /dev/cons
1 files changed, 28 insertions(+), 8 deletions(-)

M main.c
M main.c => main.c +28 -8
@@ 5,7 5,7 @@
#include <ctype.h>
#include "gemnine.h"

void
static void
page(Response *r)
{
	if(rfork(RFPROC|RFFDG|RFNOTEG|RFNOWAIT) == 0){


@@ 21,7 21,7 @@ page(Response *r)
	}
}

void
static void
play(Response *r)
{
	if(rfork(RFPROC|RFFDG|RFNOTEG|RFNOWAIT) == 0){


@@ 42,27 42,37 @@ play(Response *r)
	}
}

static void
usage(void)
{
	fprint(2, "usage: %s [-w] [URL]\n", argv0);
	exits("usage");
}

void
main(int argc, char **argv)
{
	Response *r;
	char *s, *t, *u, *tmp;
	Url *url, *x;
	int len, wait, pl, fd;
	int len, raw, wait, pl, fd;
	Plumbmsg *m;
	Biobuf out, body;
	char buf[8192];

	wait = 0;
	ARGBEGIN{
	case 'w':
		wait = 1;
		break;
	default:
		usage();
	}ARGEND;

	if(!wait && argc < 1){
		fprint(2, "usage: gemnine [-w] [URL]\n");
		exits("usage");
	}
	if(!wait && argc < 1)
		usage();

	raw = fd2path(1, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/cons") != 0;

	quotefmtinstall();
	fmtinstall('U', Ufmt);


@@ 94,7 104,7 @@ nexturl:

nextreq:
	if((r = request(url)) != nil){
		if(r->mime != nil && strncmp(r->mime, "text/", 5) != 0){
		if(!raw && r->mime != nil && strncmp(r->mime, "text/", 5) != 0){
			if(strncmp(r->mime, "image/", 6) == 0 || strcmp(r->mime, "application/pdf") == 0)
				page(r);
			else if(strncmp(r->mime, "audio/", 6) == 0)


@@ 136,6 146,15 @@ nextreq:
					fprint(2, "%U: %r\n", url);
				if(!wait)
					exits("failed");
			}else if(raw){
				for(;;){
					if((len = read(r->fd, buf, sizeof(buf))) == 0)
						break;
					if(len < 0)
						goto err;
					if(write(1, buf, len) <= 0)
						break;
				}
			}else{
				Binit(&body, r->fd, OREAD);
				while((s = Brdstr(&body, '\n', 1)) != nil){


@@ 169,6 188,7 @@ nextreq:
		freeresponse(r);
		freeurl(url);
	}else{
err:
		fprint(2, "%U: %r\n", url);
		if(!wait)
			exits("failed");