/* ** COMMAND: branch ** ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? ** ** Run various subcommands to manage branches of the open repository or ** of the repository identified by the -R or --repository option. ** ** %fossil branch new BRANCH-NAME BASIS ?--bgcolor COLOR? ?--private? ** ** Create a new branch BRANCH-NAME off of check-in BASIS. ** You can optionally give the branch a default color. The ** --private option makes the branch private. ** ** %fossil branch list ?-all | --closed? ** %fossil branch ls ?-all | --closed? ** ** List all branches. Use --all or --closed to list all branches ** or closed branches. The default is to show only open branches. ** ** Options: ** -R|--repository FILE Run commands on repository FILE */ void branch_cmd(void){ int n; const char *zCmd = "list"; db_find_and_open_repository(0, 0); if( g.argc<2 ){ usage("new|list|ls ..."); } if( g.argc>=3 ) zCmd = g.argv[2]; n = strlen(zCmd); if( strncmp(zCmd,"new",n)==0 ){ branch_new(); }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ Stmt q; int vid; char *zCurrent = 0; int showAll = find_option("all",0,0)!=0; int showClosed = find_option("closed",0,0)!=0; if( g.localOpen ){ vid = db_lget_int("checkout", 0); zCurrent = db_text(0, "SELECT value FROM tagxref" " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); } branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); while( db_step(&q)==SQLITE_ROW ){ const char *zBr = db_column_text(&q, 0); int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); } db_finalize(&q); }else{ fossil_panic("branch subcommand should be one of: " "new list ls"); } }
/* ** COMMAND: test-urlparser ** ** Usage: %fossil test-urlparser URL ?options? ** ** --remember Store results in last-sync-url ** --prompt-pw Prompt for password if missing */ void cmd_test_urlparser(void){ int i; unsigned fg = 0; url_proxy_options(); if( find_option("remember",0,0) ){ db_must_be_within_tree(); fg |= URL_REMEMBER; } if( find_option("prompt-pw",0,0) ) fg |= URL_PROMPT_PW; if( g.argc!=3 && g.argc!=4 ){ usage("URL"); } url_parse(g.argv[2], fg); for(i=0; i<2; i++){ fossil_print("g.url.isFile = %d\n", g.url.isFile); fossil_print("g.url.isHttps = %d\n", g.url.isHttps); fossil_print("g.url.isSsh = %d\n", g.url.isSsh); fossil_print("g.url.protocol = %s\n", g.url.protocol); fossil_print("g.url.name = %s\n", g.url.name); fossil_print("g.url.port = %d\n", g.url.port); fossil_print("g.url.dfltPort = %d\n", g.url.dfltPort); fossil_print("g.url.hostname = %s\n", g.url.hostname); fossil_print("g.url.path = %s\n", g.url.path); fossil_print("g.url.user = %s\n", g.url.user); fossil_print("g.url.passwd = %s\n", g.url.passwd); fossil_print("g.url.canonical = %s\n", g.url.canonical); fossil_print("g.url.fossil = %s\n", g.url.fossil); fossil_print("g.url.flags = 0x%02x\n", g.url.flags); if( g.url.isFile || g.url.isSsh ) break; if( i==0 ){ fossil_print("********\n"); url_enable_proxy("Using proxy: "); } } }
void parse_options(int argc, char **argv, const OptionDef *options, void (* parse_arg_function)(const char*)) { const char *opt, *arg; int optindex, handleoptions=1; const OptionDef *po; /* parse options */ optindex = 1; while (optindex < argc) { opt = argv[optindex++]; if (handleoptions && opt[0] == '-' && opt[1] != '\0') { if (opt[1] == '-' && opt[2] == '\0') { handleoptions = 0; continue; } po= find_option(options, opt + 1); if (!po->name) po= find_option(options, "default"); if (!po->name) { unknown_opt: fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt); exit(1); } arg = NULL; if (po->flags & HAS_ARG) { arg = argv[optindex++]; if (!arg) { fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt); exit(1); } } if (po->flags & OPT_STRING) { char *str; str = av_strdup(arg); *po->u.str_arg = str; } else if (po->flags & OPT_BOOL) { *po->u.int_arg = 1; } else if (po->flags & OPT_INT) { *po->u.int_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT_MIN, INT_MAX); } else if (po->flags & OPT_INT64) { *po->u.int64_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT64_MIN, INT64_MAX); } else if (po->flags & OPT_FLOAT) { *po->u.float_arg = parse_number_or_die(opt+1, arg, OPT_FLOAT, -1.0/0.0, 1.0/0.0); } else if (po->flags & OPT_FUNC2) { if(po->u.func2_arg(opt+1, arg)<0) goto unknown_opt; } else { po->u.func_arg(arg); } if(po->flags & OPT_EXIT) exit(0); } else { if (parse_arg_function) parse_arg_function(opt); } } }
/* fossil bundle import BUNDLE ?OPTIONS? ** ** Attempt to import the changes contained in BUNDLE. Make the change ** private so that they do not sync. ** ** OPTIONS: ** --force Import even if the project-code does not match ** --publish Imported changes are not private */ static void bundle_import_cmd(void){ int forceFlag = find_option("force","f",0)!=0; int isPriv = find_option("publish",0,0)==0; char *zMissingDeltas; verify_all_options(); if ( g.argc!=4 ) usage("import BUNDLE ?OPTIONS?"); bundle_attach_file(g.argv[3], "b1", 1); /* Only import a bundle that was generated from a repo with the same ** project code, unless the --force flag is true */ if( !forceFlag ){ if( !db_exists("SELECT 1 FROM config, bconfig" " WHERE config.name='project-code'" " AND bconfig.bcname='project-code'" " AND config.value=bconfig.bcvalue;") ){ fossil_fatal("project-code in the bundle does not match the " "repository project code. (override with --force)."); } } /* If the bundle contains deltas with a basis that is external to the ** bundle and those external basis files are missing from the local ** repo, then the delta encodings cannot be decoded and the bundle cannot ** be extracted. */ zMissingDeltas = db_text(0, "SELECT group_concat(substr(delta,1,10),' ')" " FROM bblob" " WHERE typeof(delta)='text' AND length(delta)=40" " AND NOT EXISTS(SELECT 1 FROM blob WHERE uuid=bblob.delta)"); if( zMissingDeltas && zMissingDeltas[0] ){ fossil_fatal("delta basis artifacts not found in repository: %s", zMissingDeltas); } db_begin_transaction(); db_multi_exec( "CREATE TEMP TABLE bix(" " blobid INTEGER PRIMARY KEY," " delta INTEGER" ");" "CREATE INDEX bixdelta ON bix(delta);" "INSERT INTO bix(blobid,delta)" " SELECT blobid," " CASE WHEN typeof(delta)=='integer'" " THEN delta ELSE 0 END" " FROM bblob" " WHERE NOT EXISTS(SELECT 1 FROM blob WHERE uuid=bblob.uuid AND size>=0);" "CREATE TEMP TABLE got(rid INTEGER PRIMARY KEY ON CONFLICT IGNORE);" ); manifest_crosslink_begin(); bundle_import_elements(0, 0, isPriv); manifest_crosslink_end(0); describe_artifacts_to_stdout("IN got", "Imported content:"); db_end_transaction(0); }
/* ** Identify a subsection of the check-in tree using command-line switches. ** There must be one of the following switch available: ** ** --branch BRANCHNAME All check-ins on the most recent ** instance of BRANCHNAME ** --from TAG1 [--to TAG2] Check-in TAG1 and all primary descendants ** up to and including TAG2 ** --checkin TAG Check-in TAG only ** ** Store the RIDs for all applicable check-ins in the zTab table that ** should already exist. Invoke fossil_fatal() if any kind of error is ** seen. */ void subtree_from_arguments(const char *zTab){ const char *zBr; const char *zFrom; const char *zTo; const char *zCkin; int rid = 0, endRid; zBr = find_option("branch",0,1); zFrom = find_option("from",0,1); zTo = find_option("to",0,1); zCkin = find_option("checkin",0,1); if( zCkin ){ if( zFrom ) fossil_fatal("cannot use both --checkin and --from"); if( zBr ) fossil_fatal("cannot use both --checkin and --branch"); rid = symbolic_name_to_rid(zCkin, "ci"); endRid = rid; }else{ endRid = zTo ? name_to_typed_rid(zTo, "ci") : 0; } if( zFrom ){ rid = name_to_typed_rid(zFrom, "ci"); }else if( zBr ){ rid = name_to_typed_rid(zBr, "br"); }else if( zCkin==0 ){ fossil_fatal("need one of: --branch, --from, --checkin"); } db_multi_exec("INSERT OR IGNORE INTO \"%w\" VALUES(%d)", zTab, rid); if( rid!=endRid ){ Blob sql; blob_zero(&sql); blob_appendf(&sql, "WITH RECURSIVE child(rid) AS (VALUES(%d) UNION ALL " " SELECT cid FROM plink, child" " WHERE plink.pid=child.rid" " AND plink.isPrim", rid); if( endRid>0 ){ double endTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", endRid); blob_appendf(&sql, " AND child.rid!=%d" " AND (SELECT mtime FROM event WHERE objid=plink.cid)<=%.17g", endRid, endTime ); } if( zBr ){ blob_appendf(&sql, " AND EXISTS(SELECT 1 FROM tagxref" " WHERE tagid=%d AND tagtype>0" " AND value=%Q and rid=plink.cid)", TAG_BRANCH, zBr); } blob_appendf(&sql, ") INSERT OR IGNORE INTO \"%w\" SELECT rid FROM child;", zTab); db_multi_exec("%s", blob_str(&sql)/*safe-for-%s*/); } }
/* ** COMMAND: test-missing ** ** Usage: %fossil test-missing ** ** Look at every artifact in the repository and verify that ** all references are satisfied. Report any referenced artifacts ** that are missing or shunned. ** ** Options: ** ** --notshunned Do not report shunned artifacts ** --quiet Only show output if there are errors */ void test_missing(void){ Stmt q; Blob content; int nErr = 0; int nArtifact = 0; int i; Manifest *p; unsigned flags = 0; int quietFlag; if( find_option("notshunned", 0, 0)!=0 ) flags |= MISSING_SHUNNED; quietFlag = find_option("quiet","q",0)!=0; db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); db_prepare(&q, "SELECT mid FROM mlink UNION " "SELECT srcid FROM tagxref WHERE srcid>0 UNION " "SELECT rid FROM tagxref UNION " "SELECT rid FROM attachment JOIN blob ON src=uuid UNION " "SELECT objid FROM event"); while( db_step(&q)==SQLITE_ROW ){ int rid = db_column_int(&q, 0); content_get(rid, &content); p = manifest_parse(&content, rid, 0); if( p ){ nArtifact++; nErr += check_exists(p->zBaseline, flags, p, "baseline of", 0); nErr += check_exists(p->zAttachSrc, flags, p, "file of", 0); for(i=0; i<p->nFile; i++){ nErr += check_exists(p->aFile[i].zUuid, flags, p, "file of", p->aFile[i].zName); } for(i=0; i<p->nParent; i++){ nErr += check_exists(p->azParent[i], flags, p, "parent of", 0); } for(i=0; i<p->nCherrypick; i++){ nErr += check_exists(p->aCherrypick[i].zCPTarget+1, flags, p, "cherry-pick target of", 0); nErr += check_exists(p->aCherrypick[i].zCPBase, flags, p, "cherry-pick baseline of", 0); } for(i=0; i<p->nCChild; i++){ nErr += check_exists(p->azCChild[i], flags, p, "in", 0); } for(i=0; i<p->nTag; i++){ nErr += check_exists(p->aTag[i].zUuid, flags, p, "target of", 0); } manifest_destroy(p); } } db_finalize(&q); if( nErr>0 || quietFlag==0 ){ fossil_print("%d missing or shunned references in %d control artifacts\n", nErr, nArtifact); } }
/* * returns a block that has been memalloc()'ed */ char *read_option(struct module *am, char *name) { int ao=0, bo=0, co=0; char *as=NULL, *bs=NULL, *cs=NULL; struct module *bm=NULL; char *result=NULL; int size; /* do_error("read_option(%p, %s)", am, name);*/ if (am!=NULL) ao = find_option(am, name); if ((bm = find_module("global"))!=NULL) bo = find_option(bm, name); /* else do_error("erk! lost global!");*/ if (cli!=NULL) co = find_option(cli, name); /* do_error("read_option(): ao = %i, bo = %i, co = %i", ao, bo, co);*/ /* if any are 'set', then they override; otherwise, they build up */ if (ao>0) { bo=0; co=0; } /* if (bo>0) co=0;*/ if (co>0) bo=0; /* cli overrides global block. This makes /much/ more sense ... */ if (ao==0 && bo==0 && co==0) return NULL; /* couldn't find it */ as = get_option(am, ao); bs = get_option(bm, bo); cs = get_option(cli, co); size = ((as==NULL)?(0):(strlen(as))) + ((bs==NULL)?(0):(strlen(bs))) + ((cs==NULL)?(0):(strlen(cs))) + 1; result = memalloc(size); result[0]=0; /* cli + global + per-module. Different to absolute overrides, above, where * cli is more important than global. */ if (cs!=NULL) strcat(result, cs); if (bs!=NULL) strcat(result, bs); if (as!=NULL) strcat(result, as); return result; }
/* ** COMMAND: test-subtree ** ** Usage: %fossil test-subtree ?OPTIONS? ** ** Show the subset of check-ins that match the supplied options. This ** command is used to test the subtree_from_options() subroutine in the ** implementation and does not really have any other practical use that ** we know of. ** ** Options: ** --branch BRANCH Include only check-ins on BRANCH ** --from TAG Start the subtree at TAG ** --to TAG End the subtree at TAG ** --checkin TAG The subtree is the single check-in TAG ** --all Include FILE and TAG artifacts ** --exclusive Include FILES exclusively on check-ins */ void test_subtree_cmd(void){ int bAll = find_option("all",0,0)!=0; int bExcl = find_option("exclusive",0,0)!=0; db_find_and_open_repository(0,0); db_begin_transaction(); db_multi_exec("CREATE TEMP TABLE tobundle(rid INTEGER PRIMARY KEY);"); subtree_from_arguments("tobundle"); verify_all_options(); if( bAll ) find_checkin_associates("tobundle",bExcl); describe_artifacts_to_stdout("IN tobundle", 0); db_end_transaction(1); }
/* ** COMMAND: leaves* ** ** Usage: %fossil leaves ?OPTIONS? ** ** Find leaves of all branches. By default show only open leaves. ** The -a|--all flag causes all leaves (closed and open) to be shown. ** The -c|--closed flag shows only closed leaves. ** ** The --recompute flag causes the content of the "leaf" table in the ** repository database to be recomputed. ** ** Options: ** -a|--all show ALL leaves ** -c|--closed show only closed leaves ** --bybranch order output by branch name ** --recompute recompute the "leaf" table in the repository DB ** ** See also: descendants, finfo, info, branch */ void leaves_cmd(void){ Stmt q; Blob sql; int showAll = find_option("all", "a", 0)!=0; int showClosed = find_option("closed", "c", 0)!=0; int recomputeFlag = find_option("recompute",0,0)!=0; int byBranch = find_option("bybranch",0,0)!=0; char *zLastBr = 0; int n; char zLineNo[10]; db_find_and_open_repository(0,0); if( recomputeFlag ) leaf_rebuild(); blob_zero(&sql); blob_append(&sql, timeline_query_for_tty(), -1); blob_appendf(&sql, " AND blob.rid IN leaf"); if( showClosed ){ blob_appendf(&sql," AND %z", leaf_is_closed_sql("blob.rid")); }else if( !showAll ){ blob_appendf(&sql," AND NOT %z", leaf_is_closed_sql("blob.rid")); } if( byBranch ){ db_prepare(&q, "%s ORDER BY nullif(branch,'trunk') COLLATE nocase," " event.mtime DESC", blob_str(&sql)); }else{ db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_str(&sql)); } blob_reset(&sql); n = 0; while( db_step(&q)==SQLITE_ROW ){ const char *zId = db_column_text(&q, 1); const char *zDate = db_column_text(&q, 2); const char *zCom = db_column_text(&q, 3); const char *zBr = db_column_text(&q, 7); char *z; if( byBranch && fossil_strcmp(zBr, zLastBr)!=0 ){ fossil_print("*** %s ***\n", zBr); fossil_free(zLastBr); zLastBr = fossil_strdup(zBr); } n++; sqlite3_snprintf(sizeof(zLineNo), zLineNo, "(%d)", n); fossil_print("%6s ", zLineNo); z = mprintf("%s [%.10s] %s", zDate, zId, zCom); comment_print(z, 7, 79); fossil_free(z); } fossil_free(zLastBr); db_finalize(&q); }
/* ** COMMAND: scrub* ** %fossil scrub ?OPTIONS? ?REPOSITORY? ** ** The command removes sensitive information (such as passwords) from a ** repository so that the repository can be sent to an untrusted reader. ** ** By default, only passwords are removed. However, if the --verily option ** is added, then private branches, concealed email addresses, IP ** addresses of correspondents, and similar privacy-sensitive fields ** are also purged. If the --private option is used, then only private ** branches are removed and all other information is left intact. ** ** This command permanently deletes the scrubbed information. THE EFFECTS ** OF THIS COMMAND ARE IRREVERSIBLE. USE WITH CAUTION! ** ** The user is prompted to confirm the scrub unless the --force option ** is used. ** ** Options: ** --force do not prompt for confirmation ** --private only private branches are removed from the repository ** --verily scrub real thoroughly (see above) */ void scrub_cmd(void){ int bVerily = find_option("verily",0,0)!=0; int bForce = find_option("force", "f", 0)!=0; int privateOnly = find_option("private",0,0)!=0; int bNeedRebuild = 0; db_find_and_open_repository(OPEN_ANY_SCHEMA, 2); db_close(1); db_open_repository(g.zRepositoryName); if( !bForce ){ Blob ans; char cReply; blob_zero(&ans); prompt_user( "Scrubbing the repository will permanently delete information.\n" "Changes cannot be undone. Continue (y/N)? ", &ans); cReply = blob_str(&ans)[0]; if( cReply!='y' && cReply!='Y' ){ fossil_exit(1); } } db_begin_transaction(); if( privateOnly || bVerily ){ bNeedRebuild = db_exists("SELECT 1 FROM private"); delete_private_content(); } if( !privateOnly ){ db_multi_exec( "UPDATE user SET pw='';" "DELETE FROM config WHERE name GLOB 'last-sync-*';" "DELETE FROM config WHERE name GLOB 'peer-*';" "DELETE FROM config WHERE name GLOB 'login-group-*';" "DELETE FROM config WHERE name GLOB 'skin:*';" "DELETE FROM config WHERE name GLOB 'subrepo:*';" ); if( bVerily ){ db_multi_exec( "DELETE FROM concealed;" "UPDATE rcvfrom SET ipaddr='unknown';" "DROP TABLE IF EXISTS accesslog;" "UPDATE user SET photo=NULL, info='';" ); } } if( !bNeedRebuild ){ db_end_transaction(0); db_multi_exec("VACUUM;"); }else{ rebuild_db(0, 1, 0); db_end_transaction(0); } }
void parse_options(int argc, char **argv, const OptionDef *options) { const char *opt, *arg; int optindex; const OptionDef *po; /* parse options */ optindex = 1; while (optindex < argc) { opt = argv[optindex++]; if (opt[0] == '-' && opt[1] != '\0') { po= find_option(options, opt + 1); if (!po->name) po= find_option(options, "default"); if (!po->name) { unknown_opt: fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt); exit(1); } arg = NULL; if (po->flags & HAS_ARG) { arg = argv[optindex++]; if (!arg) { fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt); exit(1); } } if (po->flags & OPT_STRING) { char *str; str = av_strdup(arg); *po->u.str_arg = str; } else if (po->flags & OPT_BOOL) { *po->u.int_arg = 1; } else if (po->flags & OPT_INT) { *po->u.int_arg = atoi(arg); } else if (po->flags & OPT_FLOAT) { *po->u.float_arg = atof(arg); } else if (po->flags & OPT_FUNC2) { if(po->u.func2_arg(opt+1, arg)<0) goto unknown_opt; } else { po->u.func_arg(arg); } } else { parse_arg_file(opt); } } }
/* ---------------------------------------------------------------------- */ static int get_option_string (const char **opt_list, int count_opt_list, char **next_char) /* ---------------------------------------------------------------------- */ { /* * Read a line and check for options */ int j; int opt_l, opt; char *opt_ptr; char option[MAX_LENGTH]; opt_ptr = *next_char; if (opt_ptr[0] == '-') { opt_ptr++; copy_token (option, &opt_ptr, &opt_l); if (find_option (&(option[1]), &opt, opt_list, count_opt_list, FALSE) == OK) { j = opt; *next_char = opt_ptr; } else { error_msg ("Unknown option.", CONTINUE); error_msg (*next_char, CONTINUE); input_error++; j = OPTION_ERROR; } } else { copy_token (option, &opt_ptr, &opt_l); if (find_option (&(option[0]), &opt, opt_list, count_opt_list, TRUE) == OK) { j = opt; *next_char = opt_ptr; } else { j = OPTION_DEFAULT; } } return (j); }
void st_close (st_parameter_close *clp) { close_status status; gfc_unit *u; #if !HAVE_UNLINK_OPEN_FILE char * path; path = NULL; #endif library_start (&clp->common); status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED : find_option (&clp->common, clp->status, clp->status_len, status_opt, "Bad STATUS parameter in CLOSE statement"); if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK) { library_end (); return; } u = find_unit (clp->common.unit); if (u != NULL) { if (u->flags.status == STATUS_SCRATCH) { if (status == CLOSE_KEEP) generate_error (&clp->common, LIBERROR_BAD_OPTION, "Can't KEEP a scratch file on CLOSE"); #if !HAVE_UNLINK_OPEN_FILE path = (char *) gfc_alloca (u->file_len + 1); unpack_filename (path, u->file, u->file_len); #endif } else { if (status == CLOSE_DELETE) { #if HAVE_UNLINK_OPEN_FILE delete_file (u); #else path = (char *) gfc_alloca (u->file_len + 1); unpack_filename (path, u->file, u->file_len); #endif } } close_unit (u); #if !HAVE_UNLINK_OPEN_FILE if (path != NULL) unlink (path); #endif } /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ library_end (); }
int svn_config_enumerate(svn_config_t *cfg, const char *section, svn_config_enumerator_t callback, void *baton) { cfg_section_t *sec; apr_hash_index_t *opt_ndx; int count; apr_pool_t *subpool; find_option(cfg, section, NULL, &sec); if (sec == NULL) return 0; subpool = svn_pool_create(cfg->pool); count = 0; for (opt_ndx = apr_hash_first(subpool, sec->options); opt_ndx != NULL; opt_ndx = apr_hash_next(opt_ndx)) { void *opt_ptr; cfg_option_t *opt; const char *temp_value; apr_hash_this(opt_ndx, NULL, NULL, &opt_ptr); opt = opt_ptr; ++count; make_string_from_option(&temp_value, cfg, sec, opt, NULL); if (!callback(opt->name, temp_value, baton)) break; } svn_pool_destroy(subpool); return count; }
void svn_config_get(svn_config_t *cfg, const char **valuep, const char *section, const char *option, const char *default_value) { *valuep = default_value; if (cfg) { cfg_section_t *sec; cfg_option_t *opt = find_option(cfg, section, option, &sec); if (opt != NULL) { make_string_from_option(valuep, cfg, sec, opt, NULL); } else /* before attempting to expand an option, check for the placeholder. * If there is none, there is no point in calling expand_option_value. */ if (default_value && strchr(default_value, '%')) { apr_pool_t *tmp_pool = svn_pool_create(cfg->pool); const char *x_default; expand_option_value(cfg, sec, default_value, &x_default, tmp_pool); if (x_default) { svn_stringbuf_set(cfg->tmp_value, x_default); *valuep = cfg->tmp_value->data; } svn_pool_destroy(tmp_pool); } } }
svn_boolean_t svn_config__is_expanded(svn_config_t *cfg, const char *section, const char *option) { cfg_option_t *opt; if (cfg == NULL) return FALSE; /* does the option even exist? */ opt = find_option(cfg, section, option, NULL); if (opt == NULL) return FALSE; /* already expanded? */ if (opt->expanded) return TRUE; /* needs expansion? */ if (opt->value && strchr(opt->value, '%')) return FALSE; /* no expansion necessary */ return TRUE; }
void p11_tool_usage (const p11_tool_desc *usages, const struct option *longopts) { const struct option *longopt; const int indent = 22; const char *long_name; const char *description; const char *next; char short_name; int spaces; int len; int i; for (i = 0; usages[i].text != NULL; i++) { /* If no option, then this is a heading */ if (!usages[i].option) { printf ("%s\n\n", usages[i].text); continue; } longopt = find_option (longopts, usages[i].option); long_name = longopt ? longopt->name : NULL; short_name = short_option (usages[i].option); description = usages[i].text; if (short_name && long_name) len = printf (" -%c, --%s", (int)short_name, long_name); else if (long_name) len = printf (" --%s", long_name); else len = printf (" -%c", (int)short_name); if (longopt && longopt->has_arg) len += printf ("%s<%s>", long_name ? "=" : " ", usages[i].arg ? usages[i].arg : "..."); if (len < indent) { spaces = indent - len; } else { printf ("\n"); spaces = indent; } while (description) { while (spaces-- > 0) fputc (' ', stdout); next = strchr (description, '\n'); if (next) { next += 1; printf ("%.*s", (int)(next - description), description); description = next; spaces = indent; } else { printf ("%s\n", description); break; } } } }
void parse_option_file(char *prog, FILE *option_file) { int j; float f; char name[50], val[50]; while (fscanf(option_file, "%s %s", name, val) == 2) { if (name[0] != '-') { fprintf(stderr, "Need '-' before option '%s'\n", name); usage(prog); } j = find_option(prog, name+1); switch(options[j].type) { case INT_OPTION: if (sscanf(val, "%d", options[j].valp.i) != 1) { fprintf(stderr, "Can't parse argument '%s' as integer\n", val); usage(prog); } break; case DOUBLE_OPTION: if (sscanf(val, "%f", &f) != 1) { fprintf(stderr, "Can't parse argument '%s' as double\n", val); usage(prog); } *options[j].valp.d = f; break; case STRING_OPTION: *(options[j].valp.s) = strsave(val); break; default: fprintf(stderr, "Internal error. Don't know option type %d\n", options[j].type); exit(1); } } }
char *read_string( int argc, char **argv, const char *option, char *default_value ) { int iplace = find_option( argc, argv, option ); if( iplace >= 0 && iplace < argc-1 ) return argv[iplace+1]; return default_value; }
liAction *li_plugin_config_action(liServer *srv, liWorker *wrk, const gchar *name, liValue *val) { liAction *a = NULL; liServerAction *sa; liServerOption *sopt; liServerOptionPtr *soptptr; if (NULL != (sa = (liServerAction*) g_hash_table_lookup(srv->actions, name))) { if (NULL == (a = sa->create_action(srv, wrk, sa->p, val, sa->userdata))) { ERROR(srv, "Action '%s' creation failed", name); } } else if (NULL != (sopt = find_option(srv, name))) { liOptionSet setting; if (!li_parse_option(srv, wrk, sopt, name, option_value(val), &setting)) goto exit; a = li_action_new_setting(setting); } else if (NULL != (soptptr = find_optionptr(srv, name))) { liOptionPtrSet setting; if (!li_parse_optionptr(srv, wrk, soptptr, name, option_value(val), &setting)) goto exit; a = li_action_new_settingptr(setting); } else if (NULL != g_hash_table_lookup(srv->setups, name)) { ERROR(srv, "'%s' can only be called in a setup block", name); } else { ERROR(srv, "unknown action %s", name); } exit: li_value_free(val); return a; }
/** * Sets a string-valued option. * * An error string (function-internal constant, do NOT free) * is returned if the type of the option does not correspond to * the function which is called. Upon success, NULL is returned. * * set_string_option_value does NOT strdup the value! * * @param opt_name The name of the option to set. * @param value Its new value. * @return NULL if all OK; otherwise a string describing the problem. */ char * set_string_option_value(char *opt_name, char *value) { int opt; opt = find_option(opt_name); if (opt < 0) return "No such option"; else if (cqpoptions[opt].type == OptContext) return set_context_option_value(opt_name, value, 1); else if (cqpoptions[opt].type != OptString) return "Wrong option type (tried to set integer-valued variable to string value)"; else if (validate_string_option_value(opt, value)) { /* free the old value */ if (*((char **)cqpoptions[opt].address)) free(*((char **)cqpoptions[opt].address)); if (strcmp(cqpoptions[opt].opt_name, "Registry") == 0 || strcmp(cqpoptions[opt].opt_name, "LocalCorpusDirectory") == 0) { *((char **)cqpoptions[opt].address) = expand_filename(value); free(value); } else *((char **)cqpoptions[opt].address) = value; execute_side_effects(opt); return NULL; } else return "Illegal value for this option"; }
static void add_rule(struct context *ctx, int type, const char *data) { char **tokens; int ntokens; void **opts; int i; tokens = G_tokenize(data, ","); ntokens = G_number_of_tokens(tokens); opts = G_malloc(ntokens * sizeof(void *)); for (i = 0; i < ntokens; i++) { char buf[256]; char *name; strcpy(buf, tokens[i]); name = G_chop(buf); opts[i] = (name[0] == '-') ? find_flag(ctx, name[1]) : find_option(ctx, name); } G_free_tokens(tokens); G__option_rule(type, ntokens, opts); }
void ciao_zmq_device(char *type_atom, char *frontend, char *backend) { ciao_zmq_socket_assoc *front_assoc= find_socket(frontend); if(front_assoc == NULL) { report_error(EINVAL, "socket_not_found", frontend); return; } ciao_zmq_socket_assoc *back_assoc= find_socket(backend); if(back_assoc==NULL) { report_error(EINVAL, "socket_not_found", backend); return; } ciao_zmq_atom_option *opt= find_option(device_options, type_atom); if(opt == NULL) { report_error(EINVAL, "invalid_device", type_atom); return; } zmq_device(opt->value, front_assoc->zmq_socket, back_assoc->zmq_socket); }
void ciao_zmq_socket(char *socket_atom, char *type_atom) { // .. Check if the socket exists ................................. if(find_socket(socket_atom)!=NULL) { report_error(EINVAL, "socket_already_exists", socket_atom); return; } // .. Fetch the socket type ...................................... ciao_zmq_atom_option *type_option= find_option(socket_options, type_atom); if(type_option==NULL) { report_error(EINVAL, "invalid_socket_type", socket_atom); return; } // .. Create the new socket ...................................... ciao_zmq_state *state= get_state(); void *newsocket= zmq_socket(state->zmq_context, type_option->value); if(newsocket==NULL) { report_error(errno, "error_creating_socket", socket_atom); return; } // .. Add the new socket record .................................. ciao_zmq_socket_assoc *assoc= malloc(sizeof(ciao_zmq_socket_assoc)); assoc->next= state->socket_list; assoc->zmq_socket= newsocket; strncpy(assoc->socket_atom_chars, socket_atom, CIAO_ZMQ_MAX_ATOM_LEN); state->socket_list= assoc; }
int read_int( int argc, char **argv, const char *option, int default_value ) { int iplace = find_option( argc, argv, option ); if( iplace >= 0 && iplace < argc-1 ) return atoi( argv[iplace+1] ); return default_value; }
gboolean li_plugin_config_setup(liServer *srv, const char *name, liValue *val) { gboolean result = FALSE; liServerSetup *ss; liServerOption *sopt; liServerOptionPtr *soptptr; if (NULL != (ss = (liServerSetup*) g_hash_table_lookup(srv->setups, name))) { if (!ss->setup(srv, ss->p, val, ss->userdata)) { ERROR(srv, "Setup '%s' failed", name); goto exit; } result = TRUE; } else if (NULL != (sopt = find_option(srv, name))) { liOptionSet setting; if (!li_parse_option(srv, srv->main_worker, sopt, name, option_value(val), &setting)) goto exit; g_array_index(srv->option_def_values, liOptionValue, sopt->index) = setting.value; result = TRUE; } else if (NULL != (soptptr = find_optionptr(srv, name))) { liOptionPtrSet setting; if (!li_parse_optionptr(srv, srv->main_worker, soptptr, name, option_value(val), &setting)) goto exit; li_release_optionptr(srv, g_array_index(srv->optionptr_def_values, liOptionPtrValue*, soptptr->index)); g_array_index(srv->optionptr_def_values, liOptionPtrValue*, soptptr->index) = setting.value; result = TRUE; } else if (NULL != g_hash_table_lookup(srv->setups, name)) {
bool Profile::cfg_read(const char *file, const char *section, const char *option, char *value) { off_t option_offset; off_t section_offset; FILE *fd; fd = fopen(file,"r"); if(!fd) { error("cfg_read : can't open %s",file); error("%s",strerror(errno)); return(false); } /* return if section not found */ if ((section_offset = find_section(fd, section)) < 0) { func("cfg_read(): can't find section '%s'", section); return false; } option_offset = find_option(fd, option, value, section_offset); /* return if option not found */ if(option_offset<1) { func("cfg_read(): can't find option[%s] section[%s]", option, section); return false; } fclose(fd); return(true); }
void SettingsMgr::set_as_number(string const& k, double d) { string sp = get_as_string(k); if (sp == S(d)) { F_->msg("Option '" + k + "' already has value: " + sp); return; } const Option& opt = find_option(k); assert(opt.vtype == kInt || opt.vtype == kDouble || opt.vtype == kBool); if (opt.vtype == kInt) { m_.*opt.val.i.ptr = iround(d); if (k == "pseudo_random_seed") do_srand(); } else if (opt.vtype == kDouble) { if (k == "epsilon") { if (d <= 0.) throw ExecuteError("Value of epsilon must be positive."); epsilon = d; } m_.*opt.val.d.ptr = d; } else // if (opt.vtype == kBool) m_.*opt.val.b.ptr = (fabs(d) >= 0.5); }
/* Return a pointer to an option in CFG, or NULL if it doesn't exist. if SECTIONP is non-null, return a pointer to the option's section. OPTION may be NULL. */ static cfg_option_t * find_option(svn_config_t *cfg, const char *section, const char *option, cfg_section_t **sectionp) { void *sec_ptr = get_hash_value(cfg->sections, cfg->tmp_key, section, cfg->section_names_case_sensitive); if (sectionp != NULL) *sectionp = sec_ptr; if (sec_ptr != NULL && option != NULL) { cfg_section_t *sec = sec_ptr; cfg_option_t *opt = get_hash_value(sec->options, cfg->tmp_key, option, cfg->option_names_case_sensitive); /* NOTE: ConfigParser's sections are case sensitive. */ if (opt == NULL && apr_strnatcasecmp(section, SVN_CONFIG__DEFAULT_SECTION) != 0) /* Options which aren't found in the requested section are also sought after in the default section. */ opt = find_option(cfg, SVN_CONFIG__DEFAULT_SECTION, option, &sec); return opt; } return NULL; }
/* ** COMMAND: tarball* ** ** Usage: %fossil tarball VERSION OUTPUTFILE [--name DIRECTORYNAME] [-R|--repository REPO] ** ** Generate a compressed tarball for a specified version. If the --name ** option is used, its argument becomes the name of the top-level directory ** in the resulting tarball. If --name is omitted, the top-level directory ** named is derived from the project name, the check-in date and time, and ** the artifact ID of the check-in. */ void tarball_cmd(void){ int rid; Blob tarball; const char *zName; zName = find_option("name", 0, 1); db_find_and_open_repository(0, 0); if( g.argc!=4 ){ usage("VERSION OUTPUTFILE"); } rid = name_to_typed_rid(g.argv[2], "ci"); if( rid==0 ){ fossil_fatal("Checkin not found: %s", g.argv[2]); return; } if( zName==0 ){ zName = db_text("default-name", "SELECT replace(%Q,' ','_') " " || strftime('_%%Y-%%m-%%d_%%H%%M%%S_', event.mtime) " " || substr(blob.uuid, 1, 10)" " FROM event, blob" " WHERE event.objid=%d" " AND blob.rid=%d", db_get("project-name", "unnamed"), rid, rid ); } tarball_of_checkin(rid, &tarball, zName); blob_write_to_file(&tarball, g.argv[3]); blob_reset(&tarball); }