示例#1
0
int main(int agrc, char *argv[]){

	std::cout << "test for echo" << std::endl;

	char *mymsg = func();
	//printf("%s\n", mymsg);
	free(mymsg);

	myclass mc1;
	myclass mc2;

	mc1.valor = 9;
	mc2.valor = 15;

	mc2 = mc1;

	printf("mc1: %d\n", mc1.valor);
	printf("mc2: %d\n\n", mc2.valor);

	myclass mc3 = cfunc();

	printf("mc3: %d\n", mc3.valor);

	return 0;

}
示例#2
0
str *__ctype_str(int (*cfunc)(int)) {
    str *s = new str();
    for(__ss_int i=0; i<256; i++)
        if(cfunc(i))
            s->unit += (char)i;
    return s;
}
示例#3
0
int
cpCollideShapes(cpShape *a, cpShape *b, cpContact **arr)
{
	// Their shape types must be in order.
	assert(a->klass->type <= b->klass->type);
	
	collisionFunc cfunc = colfuncs[a->klass->type + b->klass->type*CP_NUM_SHAPES];
	return (cfunc) ? cfunc(a, b, arr) : 0;
}
示例#4
0
int
cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr)
{
	// Their shape types must be in order.
	cpAssertSoft(a->klass->type <= b->klass->type, "Collision shapes passed to cpCollideShapes() are not sorted.");
	
	collisionFunc cfunc = colfuncs[a->klass->type + b->klass->type*CP_NUM_SHAPES];
	return (cfunc) ? cfunc(a, b, arr) : 0;
}
示例#5
0
文件: str.cpp 项目: GINK03/shedskin
__ss_bool str::__ctype_function(int (*cfunc)(int))
{
  int i, l = unit.size();
  if(!l)
      return False;

  for(i = 0; i < l; i++)
      if(!cfunc((int)unit[i])) return False;

  return True;
}
示例#6
0
文件: mpi_10.c 项目: wbkifun/my_stuff
int main( int argc, char **argv ) {
	int rank, size, Nnode;
	MPI_Init( &argc, &argv );
	MPI_Comm_rank( MPI_COMM_WORLD, &rank );
	MPI_Comm_size( MPI_COMM_WORLD, &size );
	Nnode = size - 1;

	int i;
	float *data;

	if ( rank == MASTER ) {
		printf("MASTER: number of worker tasks will be= %d\n", Nnode);

		int index, dest;
		int Nx = CHUNKSIZE*Nnode;
		float *result;
		data = (float *)calloc( Nx, sizeof(float) ); 
		result = (float *)calloc( Nx, sizeof(float) ); 

		index = 0;
		for ( dest=1; dest<= Nnode; dest++ ) {
			printf("Sending to worker task= %d\n", dest);
			MPI_Send( &data[index], CHUNKSIZE, MPI_FLOAT, dest, 0, MPI_COMM_WORLD );
			index += CHUNKSIZE;
		}

		index = 0;
		for ( dest=1; dest<= Nnode; dest++ ) {
			printf("Receive from worker task= %d\n", dest);
			MPI_Recv( &result[index], CHUNKSIZE, MPI_FLOAT, dest, 1, MPI_COMM_WORLD, &status );
			index += CHUNKSIZE;
		}

		printf("Result:\n");
		for ( i=0; i<Nx; i++ ) printf("%g ", result[i] ); 
		printf("\n");
		printf("MASTER: All Done!\n");
	}

	else {
		data = (float *)calloc( CHUNKSIZE, sizeof(float) ); 
		//printf("Receive from master task= %d\n", rank);
		MPI_Recv( data, CHUNKSIZE, MPI_FLOAT, MASTER, 0, MPI_COMM_WORLD, &status );
		cfunc( rank, data );

		//printf("Send to master task= %d\n", rank);
		MPI_Send( data, CHUNKSIZE, MPI_FLOAT, MASTER, 1, MPI_COMM_WORLD );
	}

	MPI_Finalize();
	return 0;
}
示例#7
0
/*
 * Process a single external definition
 */
extdef()
{
	register o, elsize;
	int type, sclass;
	register struct hshtab *ds;

	if(((o=symbol())==EOF) || o==SEMI)
		return;
	peeksym = o;
	type = INT;
	sclass = EXTERN;
	xdflg = FNDEL;
	if ((elsize = getkeywords(&sclass, &type)) == -1 && peeksym!=NAME)
		goto syntax;
	if (type==STRUCT)
		blkhed();
	do {
		defsym = 0;
		decl1(EXTERN, type, 0, elsize);
		if ((ds=defsym)==0)
			return;
		funcsym = ds;
		ds->hflag =| FNDEL;
		outcode("BS", SYMDEF, ds->name);
		xdflg = 0;
		if ((ds->type&XTYPE)==FUNC) {
			if ((peeksym=symbol())==LBRACE || peeksym==KEYW) {
				funcblk.type = decref(ds->type);
				cfunc(ds->name);
				return;
			}
		} else 
			cinit(ds);
	} while ((o=symbol())==COMMA);
	if (o==SEMI)
		return;
syntax:
	if (o==RBRACE) {
		error("Too many }'s");
		peeksym = 0;
		return;
	}
	error("External definition syntax");
	errflush(o);
	statement(0);
}
示例#8
0
/*ARGSUSED1*/
void key (unsigned char key, int x, int y) {
    switch (key) {
    case 'b': bfunc(); break;
    case 'c': cfunc(); break;
    case 'l': lfunc(); break;
    case 't': tfunc(); break;
    case 'f': ffunc(); break;
    case 'n': nfunc(); break;
    case 'u': ufunc(); break;
    case 'U': Ufunc(); break;
    case 'p': pfunc(); break;
    case 'P': Pfunc(); break;
    case 'w': wfunc(); break;
    case 'x': xfunc(); break;
    case 'X': Xfunc(); break;
    case 'y': yfunc(); break;
    case '\033': exit(EXIT_SUCCESS); break;
    default: break;
    }
}
示例#9
0
int scamper_writebuf_consume(scamper_writebuf_t *wb, void *cparam,
			     int cfunc(void *param))
{
  wb->cparam = cparam;
  wb->cfunc  = cfunc;

  /* don't need to consume if there is already stuff queued to send */
  if(slist_count(wb->iovs) > 0)
    return 0;

  /* consume.  if there is no effect then drop the consume pointer */
  cfunc(cparam);
  if(slist_count(wb->iovs) == 0)
    {
      wb->cparam = NULL;
      wb->cfunc  = NULL;
    }

  return 0;
}
示例#10
0
void correlate(int corr_func, dataset *d, field *c, FILE *out) {
	ULONG *dd; 
	ULONG *dr;
	ULONG *rr;
	ULONG i, j;
	int k;
	p3 sep;
	LDOUBLE l;
	correlation_function cfunc;

	/* Get the right function. */
	switch (corr_func) {
		case PEEBLES_HAUSER:
			cfunc = &ph_corr;
			break;
		case DAVIS_PEEBLES:
			cfunc = &dp_corr;
			break;
		case HAMILTON:
			cfunc = &ham_corr;
			break;
		case LANDY_SZALAY:
		default:
			cfunc = &ls_corr;
			break;
	}

	/* Allocate. */
	dd = (ULONG*)malloc(d->num_bins * sizeof(ULONG));
	check_malloc(dd, __LINE__);
	dr = (ULONG*)malloc(d->num_bins * sizeof(ULONG));
	check_malloc(dr, __LINE__);
	rr = (ULONG*)malloc(d->num_bins * sizeof(ULONG));
	check_malloc(rr, __LINE__);

	/* Zero the storages. */
	memset(dd, 0, d->num_bins * sizeof(ULONG));
	memset(dr, 0, d->num_bins * sizeof(ULONG));
	memset(rr, 0, d->num_bins * sizeof(ULONG));


	/* Calculate DD and DR pairs, and add for each bin. */
	/* XXX: We require that one pair can only end up in one bin, so we can
	 * stop going through the bins as soon as we find a match. This means
	 * that overlapping bins to achieve some effect will not result in
	 * expected behaviour. */
	printf("DD and DR pairs\n");
	for (i=0; i < d->data.num_pts; i++) {
		/* Print some progress info. */
		printf("%lu ", i);
		if (i != 0 && (i % 10 == 0))
			printf("\n");

		for (j=i+1; j < d->data.num_pts; j++) {
			sep.x = d->data.pts[i].x - d->data.pts[j].x;
			sep.y = d->data.pts[i].y - d->data.pts[j].y;
			sep.z = d->data.pts[i].z - d->data.pts[j].z;
			l = NORM(sep);
			for (k=0; k < d->num_bins; k++) {
				if (d->bins[k][0] <= l
					&& l <= d->bins[k][1]) {
					dd[k]+=2;
					break;
				}
			}
		}

		for (j=0; j < c->num_pts; j++) {
			sep.x = d->data.pts[i].x - c->pts[j].x;
			sep.y = d->data.pts[i].y - c->pts[j].y;
			sep.z = d->data.pts[i].z - c->pts[j].z;
			l = NORM(sep);
			for (k=0; k < d->num_bins; k++) {
				if (d->bins[k][0] <= l
					&& l <= d->bins[k][1]) {
					dr[k]++;
					break;
				}
			}
		}
	}
	printf("\n");

	/* Calculate RR pairs. */
	printf("RR pairs\n");
	for (i=0; i < c->num_pts; i++) {
		/* Print some progress info. */
		printf("%lu ", i);
		if (i != 0 && (i % 10 == 0))
			printf("\n");

		for (j=i+1; j < c->num_pts; j++) {
			sep.x = c->pts[i].x - c->pts[j].x;
			sep.y = c->pts[i].y - c->pts[j].y;
			sep.z = c->pts[i].z - c->pts[j].z;
			l = NORM(sep);
			for (k=0; k < d->num_bins; k++) {
				if (d->bins[k][0] <= l
					&& l <= d->bins[k][1]) {
					rr[k]+=2;
					break;
				}
			}
		}
	}
	printf("\n");

	/* Calculate the correlation and Poisson error
	 * for each bin. Then print bin low bound, high bound, ksi and error
	 * on each row. */
	{
		LDOUBLE ksi, error;
		LDOUBLE rat = c->num_pts/(LDOUBLE)d->data.num_pts;
		for (k=0; k < d->num_bins; k++) {
			printf("Bin %d [%lg, %lg] ", 
				k, d->bins[k][0], d->bins[k][1]);
			printf("dd %lu ", dd[k]);
			printf("dr %lu ", dr[k]);
			printf("rr %lu\n", rr[k]);
			if (rr[k] == 0) {
				/* XXX: Something like this is what _should_
				 * be done, however, it would require
				 * enabling GNU extensions or somesuch. */
				/*
				ksi = error = NAN;
				*/
				fprintf(out, "%lg %lg %s %s\n",
					d->bins[k][0], d->bins[k][1],
					"NaN", "NaN");
			}
			else {
				/* Use the given estimator. */
				ksi = cfunc(rat, dd[k], dr[k], rr[k]);

				/* For the Poisson errors, we have:
				 * (1+ksi)/sqrt(x), where x can be DD,
				 * (N/N_r)*DR or (N/N_r)^2*RR. Of these,
				 * Martinez & Saar suggest using one of the
				 * latter two. Of these, again the latter
				 * is more convenient, as the RR counts should
				 * be consistently large. */
				/*
				error = (1 + ksi)/sqrt(dd[k]);
				error = (1 + ksi)/sqrt(dr[k]/rat);
				*/
				error = (1 + ksi)/sqrt(rr[k]/(rat*rat));

				fprintf(out, "%lg %lg %lg %lg\n",
					d->bins[k][0], d->bins[k][1],
					ksi, error);
			}
		}
	}

	/* Cleanup. */
	free(dd);
	free(dr);
	free(rr);
}
示例#11
0
文件: show.c 项目: fstltna/empserver
int
show(void)
{
    char *p;
    void (*cfunc)(int);
    void (*sfunc)(int);
    void (*bfunc)(int);
    struct natstr *natp;
    int tlev;
    char buf[1024];
    int rlev;

again:
    p = getstarg(player->argp[1], "Show what ('?' to list options)? ", buf);
    if (!p || !*p)
	return RET_SYN;
    if (*p == '?') {
	pr("bridge, item, land, news, nuke, plane, sect, ship, product, tower, updates\n");
	goto again;
    }

    natp = getnatp(player->cnum);
    rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]);

    if (!player->argp[3]) {
	tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]);
	if (player->god)
	    tlev = 1000;
    } else {
	tlev = (int)atoi(player->argp[3]);
	if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god)
	    tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]);
    }
    if (player->god)
	rlev = 1000;
    switch (*p) {
    case 'b':
	show_bridge(99999);
	return RET_OK;
    case 't':
	show_tower(99999);
	return RET_OK;
    case 'i':
	show_item(99999);
	return RET_OK;
    case 'n':
	if (*(p + 1) == 'e') {
	    show_news(99999);
	    return RET_OK;
	}
	if (drnuke_const > MIN_DRNUKE_CONST)
	    tlev = ((rlev / drnuke_const) > tlev ? tlev :
		    (rlev / drnuke_const));
	bfunc = show_nuke_build;
	cfunc = show_nuke_capab;
	sfunc = show_nuke_stats;
	break;
    case 'l':
	bfunc = show_land_build;
	sfunc = show_land_stats;
	cfunc = show_land_capab;
	break;
    case 'p':
	if (p[1] == 'r') {
	    show_product(99999);
	    return RET_OK;
	}
	bfunc = show_plane_build;
	sfunc = show_plane_stats;
	cfunc = show_plane_capab;
	break;
    case 's':
	if (*(p + 1) == 'e') {
	    bfunc = show_sect_build;
	    sfunc = show_sect_stats;
	    cfunc = show_sect_capab;
	} else {
	    bfunc = show_ship_build;
	    sfunc = show_ship_stats;
	    cfunc = show_ship_capab;
	}
	break;
    case 'u':
	show_updates(player->argp[2] ? atoi(player->argp[2]) : 8);
	return RET_OK;
    default:
	return RET_SYN;
    }

    p = getstarg(player->argp[2],
		 "Build, stats, or capability data (b,s,c)? ", buf);
    if (!p || !*p)
	return RET_SYN;
    pr("Printing for tech level '%d'\n", tlev);
    if (*p == 'B' || *p == 'b')
	bfunc(tlev);
    else if (*p == 'C' || *p == 'c')
	cfunc(tlev);
    else if (*p == 'S' || *p == 's')
	sfunc(tlev);
    else
	return RET_SYN;
    return RET_OK;
}
示例#12
0
文件: c02.c 项目: sergev/2.11BSD
/*
 * Process a single external definition
 */
extdef()
{
	register o;
	int sclass, scflag;
	struct nmlist typer;
	register struct nmlist *ds;

	if(((o=symbol())==EOFC) || o==SEMI)
		return;
	peeksym = o;
	sclass = 0;
	blklev = 0;
	if (getkeywords(&sclass, &typer)==0) {
		sclass = EXTERN;
		if (peeksym!=NAME)
			goto syntax;
	}
	scflag = 0;
	if (sclass==DEFXTRN) {
		scflag++;
		sclass = EXTERN;
	}
	if (sclass!=EXTERN && sclass!=STATIC && sclass!=TYPEDEF)
		error("Illegal storage class");
	do {
		defsym = 0;
		paraml = NULL;
		parame = NULL;
		if (sclass==TYPEDEF) {
			decl1(TYPEDEF, &typer, 0, (struct nmlist *)NULL);
			continue;
		}
		decl1(EXTERN, &typer, 0, (struct nmlist *)NULL);
		if ((ds=defsym)==0)
			return;
		funcsym = ds;
		if ((ds->htype&XTYPE)==FUNC) {
			if ((peeksym=symbol())==LBRACE || peeksym==KEYW
			 || (peeksym==NAME && csym->hclass==TYPEDEF)) {
				funcblk.type = decref(ds->htype);
				funcblk.strp = ds->hstrp;
				setinit(ds);
				outcode("BS", SYMDEF, sclass==EXTERN?ds->name:"");
				cfunc();
				return;
			}
			if (paraml)
				error("Inappropriate parameters");
		} else if ((o=symbol())==COMMA || o==SEMI) {
			peeksym = o;
			o = (length((union tree *)ds)+ALIGN) & ~ALIGN;
			if (sclass==STATIC) {
				setinit(ds);
				outcode("BSBBSBN", SYMDEF, "", BSS, NLABEL, ds->name, SSPACE, o);
			} else if (scflag)
				outcode("BSN", CSPACE, ds->name, o);
		} else {
			if (o!=ASSIGN) {
				error("Declaration syntax");
				peeksym = o;
			}
			setinit(ds);
			if (sclass==EXTERN)
				outcode("BS", SYMDEF, ds->name);
			outcode("BBS", DATA, NLABEL, ds->name);
			if (cinit(ds, 1, sclass) & ALIGN)
				outcode("B", EVEN);
		}
	} while ((o=symbol())==COMMA);
	if (o==SEMI)
		return;
syntax:
	if (o==RBRACE) {
		error("Too many }'s");
		peeksym = 0;
		return;
	}
	error("External definition syntax");
	errflush(o);
	statement();
}
示例#13
0
int gdt_compare(const struct gdt_generic_datatype * d1,
                const struct gdt_generic_datatype * d2)
{
    if ( d1->type != d2->type ) {
        gds_assert_quit("types are not compatible (%s, line %d)",
                   __FILE__, __LINE__);
    }

    gds_cfunc cfunc = d1->compfunc;

    if ( d1->type == DATATYPE_CHAR ) {
        return cfunc(&d1->data.c, &d2->data.c);
    }
    else if ( d1->type == DATATYPE_UNSIGNED_CHAR ) {
        return cfunc(&d1->data.uc, &d2->data.uc);
    }
    else if ( d1->type == DATATYPE_SIGNED_CHAR ) {
        return cfunc(&d1->data.sc, &d2->data.sc);
    }
    else if ( d1->type == DATATYPE_INT ) {
        return cfunc(&d1->data.i, &d2->data.i);
    }
    else if ( d1->type == DATATYPE_UNSIGNED_INT ) {
        return cfunc(&d1->data.ui, &d2->data.ui);
    }
    else if ( d1->type == DATATYPE_LONG ) {
        return cfunc(&d1->data.l, &d2->data.l);
    }
    else if ( d1->type == DATATYPE_UNSIGNED_LONG ) {
        return cfunc(&d1->data.ul, &d2->data.ul);
    }
    else if ( d1->type == DATATYPE_LONG_LONG ) {
        return cfunc(&d1->data.ll, &d2->data.ll);
    }
    else if ( d1->type == DATATYPE_UNSIGNED_LONG_LONG ) {
        return cfunc(&d1->data.ull, &d2->data.ull);
    }
    else if ( d1->type == DATATYPE_SIZE_T ) {
        return cfunc(&d1->data.st, &d2->data.st);
    }
    else if ( d1->type == DATATYPE_DOUBLE ) {
        return cfunc(&d1->data.d, &d2->data.d);
    }
    else if ( d1->type == DATATYPE_STRING ) {
        return cfunc(&d1->data.pc, &d2->data.pc);
    }
    else if ( d1->type == DATATYPE_POINTER ) {
        return cfunc(&d1->data.p, &d2->data.p);
    }
    else {
        gds_assert_quit("unrecognized type (%s, line %d)", __FILE__, __LINE__);
    }

    return 0;
}
示例#14
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	WT_DECL_RET;
	WT_SESSION *session;
	size_t len;
	int (*cfunc)(WT_SESSION *, WT_CONNECTION *, int, char *[]);
	int ch, major_v, minor_v, tret, (*func)(WT_SESSION *, int, char *[]);
	const char *cmd_config, *config, *p1, *p2, *p3, *rec_config;
	char *p, *secretkey;
	bool logoff, needconn, recover, salvage;

	conn = NULL;
	p = NULL;

	/* Get the program name. */
	if ((progname = strrchr(argv[0], '/')) == NULL)
		progname = argv[0];
	else
		++progname;
	command = "";

	needconn = false;

	/* Check the version against the library build. */
	(void)wiredtiger_version(&major_v, & minor_v, NULL);
	if (major_v != WIREDTIGER_VERSION_MAJOR ||
	    minor_v != WIREDTIGER_VERSION_MINOR) {
		fprintf(stderr,
		    "%s: program build version %d.%d does not match "
		    "library build version %d.%d\n",
		    progname,
		    WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR,
		    major_v,  minor_v);
		return (EXIT_FAILURE);
	}

	cmd_config = config = secretkey = NULL;
	/*
	 * We default to returning an error if recovery needs to be run.
	 * Generally we expect this to be run after a clean shutdown.
	 * The printlog command disables logging entirely.  If recovery is
	 * needed, the user can specify -R to run recovery.
	 */
	rec_config = REC_ERROR;
	logoff = recover = salvage = false;
	/* Check for standard options. */
	while ((ch = __wt_getopt(progname, argc, argv, "C:E:h:LRSVv")) != EOF)
		switch (ch) {
		case 'C':			/* wiredtiger_open config */
			cmd_config = __wt_optarg;
			break;
		case 'E':			/* secret key */
			free(secretkey);	/* lint: set more than once */
			if ((secretkey = strdup(__wt_optarg)) == NULL) {
				(void)util_err(NULL, errno, NULL);
				goto err;
			}
			memset(__wt_optarg, 0, strlen(__wt_optarg));
			break;
		case 'h':			/* home directory */
			home = __wt_optarg;
			break;
		case 'L':			/* no logging */
			rec_config = REC_LOGOFF;
			logoff = true;
			break;
		case 'R':			/* recovery */
			rec_config = REC_RECOVER;
			recover = true;
			break;
		case 'S':			/* salvage */
			rec_config = REC_SALVAGE;
			salvage = true;
			break;
		case 'V':			/* version */
			printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
			goto done;
		case 'v':			/* verbose */
			verbose = true;
			break;
		case '?':
		default:
			usage();
			goto err;
		}
	if ((logoff && recover) || (logoff && salvage) ||
	    (recover && salvage)) {
		fprintf(stderr, "Only one of -L, -R, and -S is allowed.\n");
		goto err;
	}
	argc -= __wt_optind;
	argv += __wt_optind;

	/* The next argument is the command name. */
	if (argc < 1) {
		usage();
		goto err;
	}
	command = argv[0];

	/* Reset getopt. */
	__wt_optreset = __wt_optind = 1;

	func = NULL;
	cfunc = NULL;
	switch (command[0]) {
	case 'a':
		if (strcmp(command, "alter") == 0)
			func = util_alter;
		break;
	case 'b':
		if (strcmp(command, "backup") == 0)
			func = util_backup;
		break;
	case 'c':
		if (strcmp(command, "compact") == 0)
			func = util_compact;
		else if (strcmp(command, "copyright") == 0) {
			util_copyright();
			goto done;
		} else if (strcmp(command, "create") == 0) {
			func = util_create;
			config = "create";
		}
		break;
	case 'd':
		if (strcmp(command, "downgrade") == 0) {
			cfunc = util_downgrade;
			needconn = true;
		} else if (strcmp(command, "drop") == 0)
			func = util_drop;
		else if (strcmp(command, "dump") == 0)
			func = util_dump;
		break;
	case 'l':
		if (strcmp(command, "list") == 0)
			func = util_list;
		else if (strcmp(command, "load") == 0) {
			func = util_load;
			config = "create";
		} else if (strcmp(command, "loadtext") == 0) {
			func = util_loadtext;
			config = "create";
		}
		break;
	case 'p':
		if (strcmp(command, "printlog") == 0) {
			func = util_printlog;
			rec_config = REC_LOGOFF;
		}
		break;
	case 'r':
		if (strcmp(command, "read") == 0)
			func = util_read;
		else if (strcmp(command, "rebalance") == 0)
			func = util_rebalance;
		else if (strcmp(command, "rename") == 0)
			func = util_rename;
		break;
	case 's':
		if (strcmp(command, "salvage") == 0)
			func = util_salvage;
		else if (strcmp(command, "stat") == 0) {
			func = util_stat;
			config = "statistics=(all)";
		}
		break;
	case 't' :
		if (strcmp(command, "truncate") == 0)
			func = util_truncate;
		break;
	case 'u':
		if (strcmp(command, "upgrade") == 0)
			func = util_upgrade;
		break;
	case 'v':
		if (strcmp(command, "verify") == 0)
			func = util_verify;
		break;
	case 'w':
		if (strcmp(command, "write") == 0)
			func = util_write;
		break;
	default:
		break;
	}
	if (func == NULL && cfunc == NULL) {
		usage();
		goto err;
	}

	/* Build the configuration string. */
	len = 10;					/* some slop */
	p1 = p2 = p3 = "";
	if (config != NULL)
		len += strlen(config);
	if (cmd_config != NULL)
		len += strlen(cmd_config);
	if (secretkey != NULL) {
		len += strlen(secretkey) + 30;
		p1 = ",encryption=(secretkey=";
		p2 = secretkey;
		p3 = ")";
	}
	len += strlen(rec_config);
	if ((p = malloc(len)) == NULL) {
		(void)util_err(NULL, errno, NULL);
		goto err;
	}
	if ((ret = __wt_snprintf(p, len, "%s,%s,%s%s%s%s",
	    config == NULL ? "" : config,
	    cmd_config == NULL ? "" : cmd_config,
	    rec_config, p1, p2, p3)) != 0) {
		(void)util_err(NULL, ret, NULL);
		goto err;
	}
	config = p;

	/* Open the database and a session. */
	if ((ret = wiredtiger_open(home,
	    verbose ? verbose_handler : NULL, config, &conn)) != 0) {
		(void)util_err(NULL, ret, NULL);
		goto err;
	}
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		(void)util_err(NULL, ret, NULL);
		goto err;
	}

	/* Call the function. */
	if (needconn)
		ret = cfunc(session, conn, argc, argv);
	else
		ret = func(session, argc, argv);

	if (0) {
err:		ret = 1;
	}
done:

	/* Close the database. */
	if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
		ret = tret;

	free(p);
	free(secretkey);

	return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
示例#15
0
文件: interface.c 项目: rforge/ucminf
void F77_SUB(cfunc)(int *n, double x[], double value[]) { 
  cfunc(n, x, value) ;    
}