本文整理汇总了C++中REPLACE函数的典型用法代码示例。如果您正苦于以下问题:C++ REPLACE函数的具体用法?C++ REPLACE怎么用?C++ REPLACE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了REPLACE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vsmw_delseg
static void
vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx)
{
char *t = NULL;
ssize_t s;
int fd;
CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC);
CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC);
VTAILQ_REMOVE(&vsmw->segs, seg, list);
REPLACE(seg->class, NULL);
REPLACE(seg->id, NULL);
FREE_OBJ(seg);
if (fixidx) {
vsmw_mkent(vsmw, vsmw->idx);
REPLACE(t, VSB_data(vsmw->vsb));
AN(t);
fd = openat(vsmw->vdirfd,
t, O_WRONLY|O_CREAT|O_EXCL, vsmw->mode);
assert(fd >= 0);
vsmw_idx_head(vsmw, fd);
VSB_clear(vsmw->vsb);
VTAILQ_FOREACH(seg, &vsmw->segs, list)
vsmw_fmt_index(vsmw, seg);
AZ(VSB_finish(vsmw->vsb));
s = write(fd, VSB_data(vsmw->vsb), VSB_len(vsmw->vsb));
assert(s == VSB_len(vsmw->vsb));
AZ(close(fd));
AZ(renameat(vsmw->vdirfd, t, vsmw->vdirfd, vsmw->idx));
REPLACE(t, NULL);
}
}
示例2: tweak_group_cc
int
tweak_group_cc(struct vsb *vsb, const struct parspec *par, const char *arg)
{
struct group *gr;
(void)par;
if (arg != NULL) {
if (*arg != '\0') {
gr = getgrnam(arg);
if (gr == NULL) {
VSB_printf(vsb, "Unknown group");
return(-1);
}
REPLACE(mgt_param.group_cc, gr->gr_name);
mgt_param.gid_cc = gr->gr_gid;
} else {
REPLACE(mgt_param.group_cc, "");
mgt_param.gid_cc = 0;
}
} else if (strlen(mgt_param.group_cc) > 0) {
VSB_printf(vsb, "%s (%d)",
mgt_param.group_cc, (int)mgt_param.gid_cc);
} else {
VSB_printf(vsb, "<not set>");
}
return (0);
}
示例3: tweak_user
void
tweak_user(struct cli *cli, const struct parspec *par, const char *arg)
{
struct passwd *pw;
(void)par;
if (arg != NULL) {
if (*arg != '\0') {
pw = getpwnam(arg);
if (pw == NULL) {
VCLI_Out(cli, "Unknown user");
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
REPLACE(mgt_param.user, pw->pw_name);
mgt_param.uid = pw->pw_uid;
} else {
mgt_param.uid = getuid();
}
} else if (mgt_param.user) {
VCLI_Out(cli, "%s (%d)", mgt_param.user, (int)mgt_param.uid);
} else {
VCLI_Out(cli, "UID %d", (int)mgt_param.uid);
}
}
示例4: xyzzy_dyn__init
VCL_VOID
xyzzy_dyn__init(VRT_CTX, struct xyzzy_debug_dyn **dynp,
const char *vcl_name, VCL_STRING addr, VCL_STRING port, VCL_PROBE probe)
{
struct xyzzy_debug_dyn *dyn;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(dynp);
AZ(*dynp);
AN(vcl_name);
if (*addr == '\0' || *port == '\0') {
AN(ctx->handling);
AZ(*ctx->handling);
VRT_fail(ctx, "Missing dynamic backend address or port");
return;
}
ALLOC_OBJ(dyn, VMOD_DEBUG_DYN_MAGIC);
AN(dyn);
REPLACE(dyn->vcl_name, vcl_name);
AZ(pthread_mutex_init(&dyn->mtx, NULL));
dyn_dir_init(ctx, dyn, addr, port, probe);
XXXAN(dyn->dir);
*dynp = dyn;
}
示例5: tweak_group
static void
tweak_group(struct cli *cli, const struct parspec *par, const char *arg)
{
struct group *gr;
(void)par;
if (arg != NULL) {
if (!strcmp(arg, MAGIC_INIT_STRING)) {
gr = getgrnam("nogroup");
if (gr == NULL) {
/* Only replace if tweak_user didn't */
if (master.gid == 0)
master.gid = getgid();
return;
}
} else
gr = getgrnam(arg);
if (gr == NULL) {
VCLI_Out(cli, "Unknown group");
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
REPLACE(master.group, gr->gr_name);
master.gid = gr->gr_gid;
} else if (master.group) {
VCLI_Out(cli, "%s (%d)", master.group, (int)master.gid);
} else {
VCLI_Out(cli, "%d", (int)master.gid);
}
}
示例6: tweak_group
int
tweak_group(struct vsb *vsb, const struct parspec *par, const char *arg)
{
struct group *gr;
(void)par;
if (arg != NULL) {
if (*arg != '\0') {
gr = getgrnam(arg);
if (gr == NULL) {
VSB_printf(vsb, "Unknown group");
return(-1);
}
REPLACE(mgt_param.group, gr->gr_name);
mgt_param.gid = gr->gr_gid;
} else {
mgt_param.gid = getgid();
}
} else if (mgt_param.group) {
VSB_printf(vsb, "%s (%d)", mgt_param.group, (int)mgt_param.gid);
} else {
VSB_printf(vsb, "GID %d", (int)mgt_param.gid);
}
return (0);
}
示例7: sanitise
// Sanitise the given type (sub)AST, which has already been copied
static void sanitise(ast_t** astp)
{
assert(astp != NULL);
ast_t* type = *astp;
assert(type != NULL);
ast_clearflag(*astp, AST_FLAG_PASS_MASK);
if(ast_id(type) == TK_TYPEPARAMREF)
{
// We have a type param reference, convert to a nominal
ast_t* def = (ast_t*)ast_data(type);
assert(def != NULL);
const char* name = ast_name(ast_child(def));
assert(name != NULL);
REPLACE(astp,
NODE(TK_NOMINAL,
NONE // Package name
ID(name)
NONE // Type args
NONE // Capability
NONE)); // Ephemeral
return;
}
// Process all our children
for(ast_t* p = ast_child(type); p != NULL; p = ast_sibling(p))
sanitise(&p);
}
示例8: mgt_cli_setup
void
mgt_cli_setup(int fdi, int fdo, int auth, const char *ident,
mgt_cli_close_f *closefunc, void *priv)
{
struct cli *cli;
struct vev *ev;
cli = VCLS_AddFd(mgt_cls, fdi, fdo, closefunc, priv);
REPLACE(cli->ident, ident);
if (!auth && secret_file != NULL) {
cli->auth = MCF_NOAUTH;
mgt_cli_challenge(cli);
} else {
cli->auth = MCF_AUTH;
mcf_banner(cli, NULL, NULL);
}
AZ(VSB_finish(cli->sb));
(void)VCLI_WriteResult(fdo, cli->result, VSB_data(cli->sb));
ev = VEV_Alloc();
AN(ev);
ev->name = cli->ident;
ev->fd = fdi;
ev->fd_flags = VEV__RD;
ev->callback = mgt_cli_callback2;
ev->priv = cli;
AZ(VEV_Start(mgt_evb, ev));
}
示例9: VRT_init_dir
void
VRT_init_dir(struct cli *cli, struct director **bp, int idx, const void *priv)
{
const struct vrt_backend *t;
struct vdi_simple *vs;
ASSERT_CLI();
(void)cli;
t = priv;
ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC);
XXXAN(vs);
vs->dir.magic = DIRECTOR_MAGIC;
vs->dir.priv = vs;
vs->dir.name = "simple";
REPLACE(vs->dir.vcl_name, t->vcl_name);
vs->dir.getfd = vdi_simple_getfd;
vs->dir.healthy = vdi_simple_healthy;
vs->vrt = t;
vs->backend = VBE_AddBackend(cli, t);
if (vs->vrt->probe != NULL)
VBP_Insert(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
bp[idx] = &vs->dir;
}
示例10: sugar_binop
static ast_result_t sugar_binop(ast_t** astp, const char* fn_name)
{
AST_GET_CHILDREN(*astp, left, right);
ast_t* positional = ast_from(right, TK_POSITIONALARGS);
if(ast_id(right) == TK_TUPLE)
{
ast_t* value = ast_child(right);
while(value != NULL)
{
BUILD(arg, right, NODE(TK_SEQ, TREE(value)));
ast_append(positional, arg);
value = ast_sibling(value);
}
} else {
BUILD(arg, right, NODE(TK_SEQ, TREE(right)));
ast_add(positional, arg);
}
REPLACE(astp,
NODE(TK_CALL,
TREE(positional)
NONE
NODE(TK_DOT, TREE(left) ID(fn_name))
));
return AST_OK;
}
示例11: sugar_update
static ast_result_t sugar_update(ast_t** astp)
{
ast_t* ast = *astp;
assert(ast_id(ast) == TK_ASSIGN);
AST_GET_CHILDREN(ast, value, call);
if(ast_id(call) != TK_CALL)
return AST_OK;
// We are of the form: x(y) = z
// Replace us with: x.update(y where value = z)
AST_EXTRACT_CHILDREN(call, positional, named, expr);
// If there are no named arguments yet, named will be a TK_NONE.
ast_setid(named, TK_NAMEDARGS);
// Build a new namedarg.
BUILD_NO_DEBUG(namedarg, ast,
NODE(TK_UPDATEARG,
ID("value")
NODE(TK_SEQ, TREE(value))));
// Append the named arg to our existing list.
ast_append(named, namedarg);
// Replace with the update call.
REPLACE(astp,
NODE(TK_CALL,
TREE(positional)
TREE(named)
NODE(TK_DOT, TREE(expr) ID("update"))));
return AST_OK;
}
示例12: extmacro_def
void
extmacro_def(const char *name, const char *fmt, ...)
{
char buf[256];
struct extmacro *m;
va_list ap;
VTAILQ_FOREACH(m, &extmacro_list, list)
if (!strcmp(name, m->name))
break;
if (m == NULL && fmt != NULL) {
m = calloc(sizeof *m, 1);
AN(m);
REPLACE(m->name, name);
VTAILQ_INSERT_TAIL(&extmacro_list, m, list);
}
if (fmt != NULL) {
AN(m);
va_start(ap, fmt);
free(m->val);
vbprintf(buf, fmt, ap);
va_end(ap);
m->val = strdup(buf);
AN(m->val);
} else if (m != NULL) {
VTAILQ_REMOVE(&extmacro_list, m, list);
free(m->name);
free(m->val);
free(m);
}
}
示例13: tweak_group
void
tweak_group(struct cli *cli, const struct parspec *par, const char *arg)
{
struct group *gr;
(void)par;
if (arg != NULL) {
if (*arg != '\0') {
gr = getgrnam(arg);
if (gr == NULL) {
VCLI_Out(cli, "Unknown group");
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
REPLACE(mgt_param.group, gr->gr_name);
mgt_param.gid = gr->gr_gid;
} else {
mgt_param.gid = getgid();
}
} else if (mgt_param.group) {
VCLI_Out(cli, "%s (%d)", mgt_param.group, (int)mgt_param.gid);
} else {
VCLI_Out(cli, "GID %d", (int)mgt_param.gid);
}
}
示例14: tweak_user
int
tweak_user(struct vsb *vsb, const struct parspec *par, const char *arg)
{
struct passwd *pw;
(void)par;
if (arg != NULL) {
if (*arg != '\0') {
pw = getpwnam(arg);
if (pw == NULL) {
VSB_printf(vsb, "Unknown user");
return(-1);
}
REPLACE(mgt_param.user, pw->pw_name);
mgt_param.uid = pw->pw_uid;
} else {
mgt_param.uid = getuid();
}
} else if (mgt_param.user) {
VSB_printf(vsb, "%s (%d)", mgt_param.user, (int)mgt_param.uid);
} else {
VSB_printf(vsb, "UID %d", (int)mgt_param.uid);
}
return (0);
}
示例15: vdir_new
void
vdir_new(struct vdir **vdp, const char *name, const char *vcl_name,
vdi_healthy_f *healthy, vdi_resolve_f *resolve, void *priv)
{
struct vdir *vd;
AN(name);
AN(vcl_name);
AN(vdp);
AZ(*vdp);
ALLOC_OBJ(vd, VDIR_MAGIC);
AN(vd);
*vdp = vd;
AZ(pthread_mutex_init(&vd->mtx, NULL));
ALLOC_OBJ(vd->dir, DIRECTOR_MAGIC);
AN(vd->dir);
vd->dir->name = name;
REPLACE(vd->dir->vcl_name, vcl_name);
vd->dir->priv = priv;
vd->dir->healthy = healthy;
vd->dir->resolve = resolve;
vd->vbm = vbit_init(8);
AN(vd->vbm);
}