Beispiel #1
0
static t_shiftdata *read_shifts(const char *fn)
{
    FILE        *fp;
    double       xx;
    int          i, j, nx, ny;
    t_shiftdata *sd;

    snew(sd, 1);
    fp = libopen(fn);
    if (2 != fscanf(fp, "%d%d", &nx, &ny))
    {
        gmx_fatal(FARGS, "Error reading from file %s", fn);
    }

    sd->nx = nx;
    sd->ny = ny;
    sd->dx = nx/(2*M_PI);
    sd->dy = ny/(2*M_PI);
    snew(sd->data, nx+1);
    for (i = 0; (i <= nx); i++)
    {
        snew(sd->data[i], ny+1);
        for (j = 0; (j < ny); j++)
        {
            if (i == nx)
            {
                sd->data[i][j] = sd->data[0][j];
            }
            else
            {
                if (1 != fscanf(fp, "%lf", &xx))
                {
                    gmx_fatal(FARGS, "Error reading from file %s", fn);
                }
                sd->data[i][j] = xx;
            }
        }
        sd->data[i][j] = sd->data[i][0];
    }
    ffclose(fp);

    if (bDebugMode())
    {
        dump_sd(fn, sd);
    }

    return sd;
}
Beispiel #2
0
static int net_printing_dump(struct net_context *c, int argc,
			     const char **argv)
{
	int ret = -1;
	TALLOC_CTX *ctx = talloc_stackframe();
	TDB_CONTEXT *tdb;
	TDB_DATA kbuf, newkey, dbuf;

	if (argc < 1 || c->display_usage) {
		d_fprintf(stderr, "%s\nnet printing dump <file.tdb>\n",
			  _("Usage:"));
		goto done;
	}

	tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0600);
	if (!tdb) {
		d_fprintf(stderr, _("failed to open tdb file: %s\n"), argv[0]);
		goto done;
	}

	for (kbuf = tdb_firstkey(tdb);
	     kbuf.dptr;
	     newkey = tdb_nextkey(tdb, kbuf), free(kbuf.dptr), kbuf=newkey)
	{
		dbuf = tdb_fetch(tdb, kbuf);
		if (!dbuf.dptr) {
			continue;
		}

		if (strncmp((const char *)kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
			dump_form(ctx, (const char *)kbuf.dptr+strlen(FORMS_PREFIX), dbuf.dptr, dbuf.dsize);
			SAFE_FREE(dbuf.dptr);
			continue;
		}

		if (strncmp((const char *)kbuf.dptr, DRIVERS_PREFIX, strlen(DRIVERS_PREFIX)) == 0) {
			dump_driver(ctx, (const char *)kbuf.dptr+strlen(DRIVERS_PREFIX), dbuf.dptr, dbuf.dsize);
			SAFE_FREE(dbuf.dptr);
			continue;
		}

		if (strncmp((const char *)kbuf.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX)) == 0) {
			dump_printer(ctx, (const char *)kbuf.dptr+strlen(PRINTERS_PREFIX), dbuf.dptr, dbuf.dsize);
			SAFE_FREE(dbuf.dptr);
			continue;
		}

		if (strncmp((const char *)kbuf.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX)) == 0) {
			dump_sd(ctx, (const char *)kbuf.dptr+strlen(SECDESC_PREFIX), dbuf.dptr, dbuf.dsize);
			SAFE_FREE(dbuf.dptr);
			continue;
		}

	}

	ret = 0;

 done:
	talloc_free(ctx);
	return ret;
}