コード例 #1
0
ファイル: ixpc.c プロジェクト: aztrock/wmii.libixp
static int
xread(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf;
	int count;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_open(client, file, P9_OREAD);
	if(fid == nil)
		fatal("Can't open file '%s': %s\n", file, ixp_errbuf());

	buf = emalloc(fid->iounit);
	while((count = ixp_read(fid, buf, fid->iounit)) > 0)
		write(1, buf, count);

	if(count == -1)
		fatal("cannot read file/directory '%s': %s\n", file, ixp_errbuf());

	return 0;
}
コード例 #2
0
ファイル: pyxp.c プロジェクト: milkypostman/wmiirc-lua
static PyObject *
Wmii_ls(Wmii *self, PyObject *args)
{
    const char *file;
    char *buf;
    PyArg_ParseTuple(args, "s", &file);
    int count;
    PyObject *list;

    IxpCFid *fid;
    IxpStat stat;
    IxpMsg msg;

    fid = ixp_open(self->client, file, P9_OREAD);
    buf = malloc(fid->iounit);

    list = PyList_New(0);

    while( (count = ixp_read(fid, buf, fid->iounit)) > 0 )
    {

        msg = ixp_message(buf, count, MsgUnpack);
        while(msg.pos < msg.end)
        {
            ixp_pstat(&msg, &stat);
            PyList_Append(list, PyString_FromString(stat.name));
        }
    }

    ixp_close(fid);
    free(buf);
    return list;
}
コード例 #3
0
ファイル: wmiir.c プロジェクト: bartman/wmii
static int
xread(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf;
	int count;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	if(argc == 0)
		usage();
	file = EARGF(usage());
	do {
		fid = ixp_open(client, file, P9_OREAD);
		if(fid == nil)
			fatal("Can't open file '%s': %r\n", file);

		buf = emalloc(fid->iounit);
		while((count = ixp_read(fid, buf, fid->iounit)) > 0)
			write(1, buf, count);
		ixp_close(fid);

		if(count == -1)
			fprint(2, "%s: cannot read file '%s': %r\n", argv0, file);
	} while((file = ARGF()));

	return 0;
}
コード例 #4
0
ファイル: clientutil.c プロジェクト: bartman/wmii
char*
readctl(char *key) {
	char *s, *p;
	int nkey, n;

	if(ctlfid == nil) {
		ctlfid = ixp_open(client, "ctl", OREAD);
		n = ixp_read(ctlfid, ctl, 1023);
		ectl = ctl + n;
		ixp_close(ctlfid);
	}

	nkey = strlen(key);
	p = ctl - 1;
	do {
		p++;
		if(!strncmp(p, key, nkey)) {
			p += nkey;
			s = strchr(p, '\n');
			n = (s ? s : ectl) - p;
			s = freelater(emalloc(n + 1));
			s[n] = '\0';
			return strncpy(s, p, n);
		}
	} while((p = strchr(p, '\n')));
	return "";
}
コード例 #5
0
ファイル: pyxp.c プロジェクト: milkypostman/wmiirc-lua
static PyObject *
Wmii_read(Wmii *self, PyObject *args)
{
    const char *file;

    char *readbuf;
    unsigned int count = 1;

    char *buf;
    unsigned int len;
    unsigned int size;

    PyObject *outstr;

    IxpCFid *fid;

    PyArg_ParseTuple(args, "s", &file);

    fid = ixp_open(self->client, file, P9_OREAD);

    readbuf = malloc(fid->iounit);

    len = 1;
    size = fid->iounit;
    buf = malloc(size);
    buf[0] = '\0';

    while( (count = ixp_read(fid, readbuf, fid->iounit)) > 0 )
    {
        while( (len+count) > size )
        {
            size <<= 1;
            buf = realloc(buf, size);
        }
        strcpy(&buf[len-1], readbuf);
        len += count;
    }

    ixp_close(fid);
    outstr = PyString_FromString(buf);

    free(buf);
    free(readbuf);

    return outstr;

}
コード例 #6
0
ファイル: ixpc.c プロジェクト: aztrock/wmii.libixp
static int
xls(int argc, char *argv[]) {
	IxpMsg m;
	Stat *stat;
	IxpCFid *fid;
	char *file, *buf;
	int lflag, dflag, count, nstat, mstat, i;

	lflag = dflag = 0;

	ARGBEGIN{
	case 'l':
		lflag++;
		break;
	case 'd':
		dflag++;
		break;
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());

	stat = ixp_stat(client, file);
	if(stat == nil)
		fatal("cannot stat file '%s': %s\n", file, ixp_errbuf());

	if(dflag || (stat->mode&P9_DMDIR) == 0) {
		print_stat(stat, lflag);
		ixp_freestat(stat);
		return 0;
	}
	ixp_freestat(stat);

	fid = ixp_open(client, file, P9_OREAD);
	if(fid == nil)
		fatal("Can't open file '%s': %s\n", file, ixp_errbuf());

	nstat = 0;
	mstat = 16;
	stat = emalloc(sizeof(*stat) * mstat);
	buf = emalloc(fid->iounit);
	while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
		m = ixp_message(buf, count, MsgUnpack);
		while(m.pos < m.end) {
			if(nstat == mstat) {
				mstat <<= 1;
				stat = ixp_erealloc(stat, sizeof(*stat) * mstat);
			}
			ixp_pstat(&m, &stat[nstat++]);
		}
	}

	qsort(stat, nstat, sizeof(*stat), comp_stat);
	for(i = 0; i < nstat; i++) {
		print_stat(&stat[i], lflag);
		ixp_freestat(&stat[i]);
	}
	free(stat);

	if(count == -1)
		fatal("cannot read directory '%s': %s\n", file, ixp_errbuf());
	return 0;
}
コード例 #7
0
ファイル: wmiir.c プロジェクト: bartman/wmii
static int
xls(int argc, char *argv[]) {
	IxpMsg m;
	Stat *stat;
	IxpCFid *fid;
	char *file;
	char *buf;
	int lflag, dflag, pflag;
	int count, nstat, mstat, i;

	lflag = dflag = pflag = 0;

	ARGBEGIN{
	case 'l':
		lflag++;
		break;
	case 'd':
		dflag++;
		break;
	case 'p':
		pflag++;
		break;
	default:
		usage();
	}ARGEND;

	count = 0;
	file = EARGF(usage());
	do {
		stat = ixp_stat(client, file);
		if(stat == nil)
			fatal("cannot stat file '%s': %r\n", file);

		i = strlen(file);
		if(file[i-1] == '/') {
			file[i-1] = '\0';
			if(!(stat->mode&P9_DMDIR))
				fatal("%s: not a directory", file);
		}
		if(dflag || (stat->mode&P9_DMDIR) == 0) {
			print_stat(stat, lflag, file, pflag);
			ixp_freestat(stat);
			continue;
		}
		ixp_freestat(stat);

		fid = ixp_open(client, file, P9_OREAD);
		if(fid == nil)
			fatal("Can't open file '%s': %r\n", file);

		nstat = 0;
		mstat = 16;
		stat = emalloc(mstat * sizeof *stat);
		buf = emalloc(fid->iounit);
		while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
			m = ixp_message(buf, count, MsgUnpack);
			while(m.pos < m.end) {
				if(nstat == mstat) {
					mstat <<= 1;
					stat = erealloc(stat, mstat * sizeof *stat);
				}
				ixp_pstat(&m, &stat[nstat++]);
			}
		}
		ixp_close(fid);

		qsort(stat, nstat, sizeof *stat, comp_stat);
		for(i = 0; i < nstat; i++) {
			print_stat(&stat[i], lflag, file, pflag);
			ixp_freestat(&stat[i]);
		}
		free(stat);
	} while((file = ARGF()));

	if(count == -1)
		fatal("cannot read directory '%s': %r\n", file);
	return 0;
}