/** * @see cmd_line_base */ virtual bool process_specific_cmd(const string & cmd) { //Set the number of incoming pool threads if (begins_with(cmd, PROGRAM_SET_INT_CMD)) { try { int32_t num_inc_threads = get_int_value(cmd, PROGRAM_SET_INT_CMD); ASSERT_CONDITION_THROW((num_inc_threads <= 0), "The number of worker threads is to be > 0!"); //Set the number of threads m_server.set_num_inc_threads(num_inc_threads); //Remember the new number of threads m_params.m_num_req_threads = num_inc_threads; } catch (std::exception &ex) { LOG_ERROR << ex.what() << "\nEnter '" << PROGRAM_HELP_CMD << "' for help!" << END_LOG; } return false; } else { //Set the number of outgoing pool threads if (begins_with(cmd, PROGRAM_SET_ONT_CMD)) { int32_t num_out_threads = get_int_value(cmd, PROGRAM_SET_ONT_CMD); ASSERT_CONDITION_THROW((num_out_threads <= 0), "The number of worker threads is to be > 0!"); //Set the number of threads m_server.set_num_out_threads(num_out_threads); //Remember the new number of threads m_params.m_num_resp_threads = num_out_threads; return false; } else { return true; } } }
void t_socket_line_reader(void *config) // read messages from socket { CONFIG *c = (CONFIG*) config; long message_id = 0; bool configured = false; while ( running ) { char line_buf[MAX_LINE_SIZE]; memset(line_buf, 0, MAX_LINE_SIZE); // read a message (1 line) from the socket and increment message count if (read_line(c->sk, line_buf, MAX_LINE_SIZE) < 1) { running = false; // server socket closed break; } message_id++; // Telnet server may have latency, so sleep()-and-send() doesn't // work, and switching on message_id is no less brittle than // grepping for magic strings... // debug("message: %d %s", message_id, line_buf); switch (message_id) { case 26: send_message( c->ob_mq, "guest\n" ); break; case 27: send_message( c->ob_mq, "\n\n" ); break; case 28: // we're logged in; it should be OK to send commands to the // server if ( ! configured ) { int w_y, w_x; getmaxyx(c->w2, w_y, w_x); send_message( c->ob_mq, "set height %d\n", w_y ); // server-side paging height send_message( c->ob_mq, "set width %d\n", w_x ); // server-side paging width send_message( c->ob_mq, "iset nowrap 1\n" ); // don't wrap lines (breaks linewise hilighting) send_message( c->ob_mq, "iset gameinfo 1\n" ); // request game information send_message( c->ob_mq, "iset ms 1\n" ); // request timing in milliseconds send_message( c->ob_mq, "-channel 53\n" ); // remove guest chat from channel list send_message( c->ob_mq, "set prompt %\n" ); // a simpler prompt send_message( c->ob_mq, "set style 12\n" ); // computer-readable output format send_message( c->ob_mq, "set seek 0\n" ); // no seek advertisements TODO seek graph (?) send_message( c->ob_mq, "set bell off\n" ); // bell off send_message( c->ob_mq, "set provshow 1\n" ); // annotate provisional and estimated ratings send_message( c->ob_mq, "set interface %s\n", TITLE ); configured = true; } break; default: // user is now logged-in. Handle any messages if ( begins_with(line_buf, "\a" ) ) continue; // skip bells and empty prompts if ( begins_with(line_buf, "% \a" ) ) continue; if ( begins_with(line_buf, "% \n" ) ) continue; if ( equals(line_buf, FICS_PROMPT) ) continue; break; } if ((mq_send(c->ib_mq, line_buf, MAX_LINE_SIZE, PRIORITY)) == -1) perror("mq_send"); } }
int parse_commit(struct commit_node* n, FILE *f) { char lbuf[MAX_LBUF_SIZE]; fgets(lbuf, MAX_LBUF_SIZE, f); if (begins_with(lbuf, COMMIT_TOKEN)) memcpy(n->hash, lbuf + strlen(COMMIT_TOKEN), COMMIT_HASH_SIZE); else return 0; while (strcmp(fgets(lbuf, MAX_LBUF_SIZE, f), "") && strcmp(lbuf, "\n")) { if (begins_with(lbuf, AUTHOR_TOKEN)) n->author = new_str_after_token(lbuf, AUTHOR_TOKEN); if (begins_with(lbuf, DATE_TOKEN)) n->date = new_str_after_token(lbuf, DATE_TOKEN); } parse_comment(n, lbuf, f); return 1; }
void t_curses_term_reader(void *config) // read messages from terminal { CONFIG *c = (CONFIG*) config; while ( running ) { char command_buf[MAX_LINE_SIZE]; memset(command_buf, 0, MAX_LINE_SIZE); use_window(c->w3, (NCURSES_WINDOW_CB) cb_read_command, command_buf); if ( strlen(command_buf) < 1 ) continue; // user command to the server AND echo to the screen send_message(c->ob_mq, command_buf); send_message(c->ib_mq, command_buf); if ( begins_with(command_buf, FICS_QUIT) ) running = false; } }
void parse_jit_arguments(JavaVMInitArgs* vm_arguments) { const char* prefix = "-Xjit:"; for (int arg_num = 0; arg_num < vm_arguments->nOptions; arg_num++) { char *option = vm_arguments->options[arg_num].optionString; if (begins_with(option, prefix)) { // split option on 2 parts char *arg = option + strlen(prefix); JIT **jit; for(jit = jit_compilers; *jit; jit++) (*jit)->next_command_line_argument("-Xjit", arg); } } } //parse_jit_arguments
char *new_str_after_token(char *s, char *tkn) { char *ret, *p; ret = NULL; if (begins_with(s, tkn)) { /* Don't want spaces at the beginning */ for (p = (s + strlen(tkn)); *p == ' '; p++); ret = (char*)malloc(strlen(p) + 1); memset(ret, '\0', strlen(p) + 1); strcpy(ret, p); /* Don't want newlines at the end */ for (p = (ret + strlen(ret) - 1); *p == '\n' && p > ret; p--) *p = '\0'; } return ret; }
search_path parse_leanpkg_path(std::string const & fn) { std::ifstream in(fn); if (!in) throw exception(sstream() << "cannot open " << fn); auto fn_dir = dirname(fn); search_path path; while (!in.eof()) { std::string line; std::getline(in, line); if (auto rest = begins_with(line, "path ")) path.push_back(resolve(*rest, fn_dir)); if (line == "builtin_path") { auto builtin = get_builtin_search_path(); path.insert(path.end(), builtin.begin(), builtin.end()); } } return path; }
int parse_comment(struct commit_node *cn, char *lbuf, FILE *f) { char cbuf[MAX_COMMENT_SIZE]; char *cp, *lp; memset(cbuf, '\0', sizeof(cbuf)); cp = cbuf; while (begins_with(fgets(lbuf, MAX_LBUF_SIZE, f), COMMENT_TOKEN)) { lp = lbuf + strlen(COMMENT_TOKEN); if (cp - cbuf + strlen(lp) < MAX_COMMENT_SIZE) { memcpy(cp, lp, strlen(lp)); cp += strlen(lp); } } cn->comment = new_str_after_token(cbuf, ""); remove_newlines_and_tabs(cn->comment); return 0; }
// only for c++ inline bool overwritearrayspec(std::vector<std::string>& params, bin2hpp::language){ const auto itinend = std::find( params.begin(), params.end(), options::in); const auto ituseaarr = std::find_if(params.begin(), itinend, [](const std::string& s){return begins_with(s, options::stdarr);} ); if(ituseaarr!=itinend){ std::string usearr = ituseaarr->substr(options::stdarr.length()); if(usearr == "true"){ params.erase(ituseaarr); return true; } else if(usearr == "false"){ params.erase(ituseaarr); return false; } throw std::runtime_error("use stdarr without valid option"); } return true; // no option specified, use the default one }
std::optional<ConditionInfo> get_condition (T & begin, const T & end) { bool negated=false; std::string name; if (is_whitespace(begin,end)) return std::optional<ConditionInfo>{}; if (begins_with("Not_",begin,end)) negated=true; for ( ; !( (begin==end) || std::isspace(*begin) ); ++begin ) name.push_back(*begin); return std::optional<ConditionInfo>({negated,std::move(name)}); }
void cb_write_response(WINDOW *w, void *data) { // match strings with these prefixes static char *highlight_prefixes[] = { "{Game ", "Game ", " **ANNOUNCEMENT**", "Removing game ", "Notification: ", "Creating: ", "No ratings adjustment done.", "Your seek matches one", "You are now observing", "(told ", "% " }; // match strings containing these substrings static char *highlight_contains[] = { " tells you: ", " kibitzes: ", "(U)(", "(TD)(", "(C)(", }; char *line = (char *) data; // highlight matches for (int i=0; i < LEN(highlight_prefixes); i++) if ( begins_with(line, highlight_prefixes[i]) ) wattron(w, COLOR_PAIR( GREENISH )); for (int i=0; i < LEN(highlight_contains); i++) if ( contains(line, highlight_contains[i]) ) wattron(w, COLOR_PAIR( GRAY_ON_BLACK )); waddstr(w, line); wstandend(w); wrefresh(w); }
int main(int argc, char *argv[]) { char buffer[MAX_PACKET_SIZE]; static struct sockaddr_in addr; int rc, i, count; struct timeval t1, t2, dt; KICK(argc < 3, "incorrect usage\n" "Usage:\n" "./linphone_proxy <local_ip> <remote_ip>\n"); local_ip = argv[1]; remote_ip = argv[2]; add_poll(&fds[0], STDIN_FILENO); proxy_to_linphone_socket = create_socket(SOCK_DGRAM, SIP_LINPHONE); init_sockaddr(&proxy_to_linphone_addr, "127.0.0.1", SIP_PORT); add_poll(&fds[1], proxy_to_linphone_socket); eprintf("created proxy_to_linphone SIP socket SRC:localhost:%d - DST:localhost:%d\n", SIP_LINPHONE, SIP_PORT); proxy_to_proxy_socket = create_socket(SOCK_DGRAM, SIP_PROXY); init_sockaddr(&proxy_to_proxy_addr, remote_ip, SIP_PROXY); add_poll(&fds[2], proxy_to_proxy_socket); eprintf("created proxy_to_sip SIP socket SRC:localhost:%d - DST:%s:%d\n", SIP_PROXY, remote_ip, SIP_PROXY); proxy_to_linphone_data_socket = create_socket(SOCK_DGRAM, DATA_LINPHONE); init_sockaddr(&proxy_to_linphone_data_addr, "127.0.0.1", DATA_PORT); add_poll(&fds[3], proxy_to_linphone_data_socket); eprintf("created proxy_to_linphone DATA socket SRC:localhost:%d - DST:localhost:%d\n", DATA_LINPHONE, DATA_PORT); proxy_to_proxy_data_socket = create_socket(SOCK_DGRAM, DATA_PROXY); init_sockaddr(&proxy_to_proxy_data_addr, remote_ip, DATA_PROXY); add_poll(&fds[4], proxy_to_proxy_data_socket); eprintf("created proxy_to_proxy DATA socket SRC:localhost:%d - DST:%s:%d\n", DATA_PROXY, remote_ip, DATA_PROXY); manager_socket = create_socket(SOCK_DGRAM, MANAGER_PORT); init_sockaddr(&manager_addr, "0.0.0.0", MANAGER_PORT); add_poll(&fds[5], manager_socket); eprintf("created manager socket SRC:localhost:%d - DST:0.0.0.0:0\n", MANAGER_PORT); while (1) { rc = poll(fds, NUM_FDS, -1); DIE(-1 == rc, "poll"); for (i = 0; i < NUM_FDS; i++) { if (0 == fds[i].revents) { continue; } switch(i) { /* receive line from console */ case 0: break; /* receive SIP packet from linphone */ case 1: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &proxy_to_linphone_addr, buffer); if (begins_with(buffer, "INVITE")) { copy_packet(&out_invite, buffer, count); //printf("captured INVITE packet:\n%s\n", out_invite.buffer); } else if (begins_with(buffer, "ACK")) { copy_packet(&out_ack, buffer, count); //printf("captured ACK packet:\n%s\n", out_ack.buffer); } else if (strstr(buffer, "200 OK") && strstr(buffer, "OPTIONS" )) { copy_packet(&out_op_ok, buffer, count); //printf("captured OPTIONS OK packet:\n%s\n", out_op_ok.buffer); } send_msg(proxy_to_proxy_socket, &proxy_to_proxy_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 1: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive SIP packet from proxy */ case 2: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &addr, buffer); send_msg(proxy_to_linphone_socket, &proxy_to_linphone_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 2: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive data packet from linphone */ case 3: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &proxy_to_linphone_data_addr, buffer); send_msg(proxy_to_proxy_data_socket, &proxy_to_proxy_data_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 3: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive data packet from proxy */ case 4: gettimeofday_safe(&t1); count = recv_msg(fds[i].fd, &addr, buffer); send_msg(proxy_to_linphone_data_socket, &proxy_to_linphone_data_addr, buffer, count); gettimeofday_safe(&t2); time_diff(&t1, &t2, &dt); printf("time case 4: %lu.%06lu\n", dt.tv_sec, dt.tv_usec); break; /* receive command from manager */ case 5: count = recv_msg(fds[i].fd, &manager_addr, buffer); if (begins_with(buffer, "IP: ")) { while (!isdigit(buffer[count - 1])) { buffer[--count] = 0; } strcpy(migrate_ip, buffer + 4); migrate_init(); } else if (begins_with(buffer, "establish")) { migrate_establish(); } else if (begins_with(buffer, "redirect: ")) { while (!isdigit(buffer[count - 1])) { buffer[--count] = 0; } strcpy(redirect_ip, buffer + 10); migrate_redirect(); } break; /* error */ default: break; } } } return EXIT_SUCCESS; }
static int do_mount(const char *mnt, char **typep, mode_t rootmode, int fd, const char *opts, const char *dev, char **sourcep, char **mnt_optsp, off_t rootsize) { int res; int flags = MS_NOSUID | MS_NODEV; char *optbuf; char *mnt_opts = NULL; const char *s; char *d; char *fsname = NULL; char *subtype = NULL; char *source = NULL; char *type = NULL; int check_empty = 1; int blkdev = 0; optbuf = (char *) malloc(strlen(opts) + 128); if (!optbuf) { fprintf(stderr, "%s: failed to allocate memory\n", progname); return -1; } for (s = opts, d = optbuf; *s;) { unsigned len; const char *fsname_str = "fsname="; const char *subtype_str = "subtype="; for (len = 0; s[len]; len++) { if (s[len] == '\\' && s[len + 1]) len++; else if (s[len] == ',') break; } if (begins_with(s, fsname_str)) { if (!get_string_opt(s, len, fsname_str, &fsname)) goto err; } else if (begins_with(s, subtype_str)) { if (!get_string_opt(s, len, subtype_str, &subtype)) goto err; } else if (opt_eq(s, len, "blkdev")) { if (getuid() != 0) { fprintf(stderr, "%s: option blkdev is privileged\n", progname); goto err; } blkdev = 1; } else if (opt_eq(s, len, "nonempty")) { check_empty = 0; } else if (!begins_with(s, "fd=") && !begins_with(s, "rootmode=") && !begins_with(s, "user_id=") && !begins_with(s, "group_id=")) { int on; int flag; int skip_option = 0; if (opt_eq(s, len, "large_read")) { struct utsname utsname; unsigned kmaj, kmin; res = uname(&utsname); if (res == 0 && sscanf(utsname.release, "%u.%u", &kmaj, &kmin) == 2 && (kmaj > 2 || (kmaj == 2 && kmin > 4))) { fprintf(stderr, "%s: note: 'large_read' mount option is deprecated for %i.%i kernels\n", progname, kmaj, kmin); skip_option = 1; } } if (getuid() != 0 && !user_allow_other && (opt_eq(s, len, "allow_other") || opt_eq(s, len, "allow_root"))) { fprintf(stderr, "%s: option %.*s only allowed if 'user_allow_other' is set in /etc/fuse.conf\n", progname, len, s); goto err; } if (!skip_option) { if (find_mount_flag(s, len, &on, &flag)) { if (on) flags |= flag; else flags &= ~flag; } else { memcpy(d, s, len); d += len; *d++ = ','; } } } s += len; if (*s) s++; } *d = '\0'; res = get_mnt_opts(flags, optbuf, &mnt_opts); if (res == -1) goto err; sprintf(d, "fd=%i,rootmode=%o,user_id=%i,group_id=%i", fd, rootmode, getuid(), getgid()); if (check_empty && fuse_mnt_check_empty(progname, mnt, rootmode, rootsize) == -1) goto err; source = malloc((fsname ? strlen(fsname) : 0) + (subtype ? strlen(subtype) : 0) + strlen(dev) + 32); type = malloc((subtype ? strlen(subtype) : 0) + 32); if (!type || !source) { fprintf(stderr, "%s: failed to allocate memory\n", progname); goto err; } if (subtype) sprintf(type, "%s.%s", blkdev ? "fuseblk" : "fuse", subtype); else strcpy(type, blkdev ? "fuseblk" : "fuse"); if (fsname) strcpy(source, fsname); else strcpy(source, subtype ? subtype : dev); res = mount(source, mnt, type, flags, optbuf); if (res == -1 && errno == ENODEV && subtype) { /* Probably missing subtype support */ strcpy(type, blkdev ? "fuseblk" : "fuse"); if (fsname) { if (!blkdev) sprintf(source, "%s#%s", subtype, fsname); } else { strcpy(source, type); } res = mount(source, mnt, type, flags, optbuf); } if (res == -1 && errno == EINVAL) { /* It could be an old version not supporting group_id */ sprintf(d, "fd=%i,rootmode=%o,user_id=%i", fd, rootmode, getuid()); res = mount(source, mnt, type, flags, optbuf); } if (res == -1) { int errno_save = errno; if (blkdev && errno == ENODEV && !fuse_mnt_check_fuseblk()) fprintf(stderr, "%s: 'fuseblk' support missing\n", progname); else fprintf(stderr, "%s: mount failed: %s\n", progname, strerror(errno_save)); goto err; } *sourcep = source; *typep = type; *mnt_optsp = mnt_opts; free(fsname); free(optbuf); return 0; err: free(fsname); free(subtype); free(source); free(type); free(mnt_opts); free(optbuf); return -1; }
static int do_mount(const char *mnt, char **typep, mode_t rootmode, int fd, const char *opts, const char *dev, char **sourcep, char **mnt_optsp) { int res; int flags = MS_NOSUID | MS_NODEV; char *optbuf; char *mnt_opts = NULL; const char *s; char *d; char *fsname = NULL; char *source = NULL; char *type = NULL; int blkdev = 0; optbuf = (char *) malloc(strlen(opts) + 128); if (!optbuf) { fprintf(stderr, "%s: failed to allocate memory\n", progname); return -1; } for (s = opts, d = optbuf; *s;) { unsigned len; const char *fsname_str = "fsname="; for (len = 0; s[len] && s[len] != ','; len++); if (begins_with(s, fsname_str)) { if (!get_string_opt(s, len, fsname_str, &fsname)) goto err; } else if (opt_eq(s, len, "blkdev")) { blkdev = 1; } else if (!begins_with(s, "fd=") && !begins_with(s, "rootmode=") && !begins_with(s, "user_id=") && !begins_with(s, "group_id=")) { int on; int flag; int skip_option = 0; if (opt_eq(s, len, "large_read")) { struct utsname utsname; unsigned kmaj, kmin; res = uname(&utsname); if (res == 0 && sscanf(utsname.release, "%u.%u", &kmaj, &kmin) == 2 && (kmaj > 2 || (kmaj == 2 && kmin > 4))) { fprintf(stderr, "%s: note: 'large_read' mount option is " "deprecated for %i.%i kernels\n", progname, kmaj, kmin); skip_option = 1; } } if (!skip_option) { if (find_mount_flag(s, len, &on, &flag)) { if (on) flags |= flag; else flags &= ~flag; } else { memcpy(d, s, len); d += len; *d++ = ','; } } } s += len; if (*s) s++; } *d = '\0'; res = get_mnt_opts(flags, optbuf, &mnt_opts); if (res == -1) goto err; sprintf(d, "fd=%i,rootmode=%o,user_id=%i,group_id=%i", fd, rootmode, getuid(), getgid()); source = malloc((fsname ? strlen(fsname) : 0) + strlen(dev) + 32); type = malloc(32); if (!type || !source) { fprintf(stderr, "%s: failed to allocate memory\n", progname); goto err; } strcpy(type, blkdev ? "fuseblk" : "fuse"); if (fsname) strcpy(source, fsname); else strcpy(source, dev); if (restore_privs()) goto err; res = mount(source, mnt, type, flags, optbuf); if (res == -1 && errno == EINVAL) { /* It could be an old version not supporting group_id */ sprintf(d, "fd=%i,rootmode=%o,user_id=%i", fd, rootmode, getuid()); res = mount(source, mnt, type, flags, optbuf); } if (drop_privs()) goto err; if (res == -1) { int errno_save = errno; if (blkdev && errno == ENODEV && !fuse_mnt_check_fuseblk()) fprintf(stderr, "%s: 'fuseblk' support missing\n", progname); else { fprintf(stderr, "%s: mount failed: %s\n", progname, strerror(errno_save)); if (errno_save == EPERM) fprintf(stderr, "User doesn't have privilege to mount. " "For more information\nplease see: " "http://tuxera.com/community/ntfs-3g-faq/#unprivileged\n"); } goto err; } else { *sourcep = source; *typep = type; *mnt_optsp = mnt_opts; } out: free(fsname); free(optbuf); return res; err: free(source); free(type); free(mnt_opts); res = -1; goto out; }
void parse_vm_arguments2(Global_Env *p_env) { bool version_printed = false; #ifdef _DEBUG TRACE("p_env->vm_arguments.nOptions = " << p_env->vm_arguments.nOptions); for (int _i = 0; _i < p_env->vm_arguments.nOptions; _i++) TRACE("p_env->vm_arguments.options[ " << _i << "] = " << p_env->vm_arguments.options[_i].optionString); #endif //_DEBUG apr_pool_t *pool; apr_pool_create(&pool, 0); for (int i = 0; i < p_env->vm_arguments.nOptions; i++) { const char* option = p_env->vm_arguments.options[i].optionString; if (begins_with(option, XBOOTCLASSPATH)) { /* * Override for bootclasspath - * set in the environment- the boot classloader will be responsible for * processing and setting up "vm.boot.class.path" and "sun.boot.class.path" * Note that in the case of multiple arguments, the last one will be used */ p_env->VmProperties()->set(XBOOTCLASSPATH, option + strlen(XBOOTCLASSPATH)); } else if (begins_with(option, XBOOTCLASSPATH_A)) { /* * addition to append to boot classpath * set in environment - responsibility of boot classloader to process * Note that we accumulate if multiple, appending each time */ char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_A); const char *value = option + strlen(XBOOTCLASSPATH_A); char *bcp_new = NULL; if (bcp_old) { char *tmp = (char *) STD_MALLOC(strlen(bcp_old) + strlen(PORT_PATH_SEPARATOR_STR) + strlen(value) + 1); strcpy(tmp, bcp_old); strcat(tmp, PORT_PATH_SEPARATOR_STR); strcat(tmp, value); bcp_new = tmp; } p_env->VmProperties()->set(XBOOTCLASSPATH_A, bcp_old ? bcp_new : value); p_env->VmProperties()->destroy(bcp_old); STD_FREE((void*)bcp_new); } else if (begins_with(option, XBOOTCLASSPATH_P)) { /* * addition to prepend to boot classpath * set in environment - responsibility of boot classloader to process * Note that we accumulate if multiple, prepending each time */ char *bcp_old = p_env->VmProperties()->get(XBOOTCLASSPATH_P); const char *value = option + strlen(XBOOTCLASSPATH_P); char *bcp_new = NULL; if (bcp_old) { char *tmp = (char *) STD_MALLOC(strlen(bcp_old) + strlen(PORT_PATH_SEPARATOR_STR) + strlen(value) + 1); strcpy(tmp, value); strcat(tmp, PORT_PATH_SEPARATOR_STR); strcat(tmp, bcp_old); bcp_new = tmp; } p_env->VmProperties()->set(XBOOTCLASSPATH_P, bcp_old ? bcp_new : value); p_env->VmProperties()->destroy(bcp_old); STD_FREE((void*)bcp_new); } else if (begins_with(option, "-Xjit:")) { // Do nothing here, just skip this option for later parsing } else if (strcmp(option, "-Xint") == 0) { p_env->VmProperties()->set("vm.use_interpreter", "true"); #ifdef VM_STATS } else if (begins_with(option, "-Xstats:")) { vm_print_total_stats = true; const char* arg = option + strlen("-Xstats:"); vm_print_total_stats_level = atoi(arg); #endif } else if (strcmp(option, "-version") == 0) { // Print the version number and exit LECHO_VERSION; log_exit(0); } else if (strcmp(option, "-showversion") == 0) { if (!version_printed) { // Print the version number and continue LECHO_VERSION; version_printed = true; } } else if (strcmp(option, "-fullversion") == 0) { // Print the version number and exit LECHO_VM_VERSION; log_exit(0); } else if (begins_with(option, "-Xgc:")) { // make prop_key to be "gc.<something>" char* prop_key = strdup(option + strlen("-X")); prop_key[2] = '.'; TRACE(prop_key << " = 1"); p_env->VmProperties()->set(prop_key, "1"); free(prop_key); } else if (begins_with(option, "-Xem:")) { const char* arg = option + strlen("-Xem:"); p_env->VmProperties()->set("em.properties", arg); } else if (strcmp(option, "-client") == 0 || strcmp(option, "-server") == 0) { p_env->VmProperties()->set("em.properties", option + 1); } else if (begins_with(option, "-Xms") || begins_with(option, "-ms")) { // cut -Xms || -ms const char* arg = option + (begins_with(option, "-ms") ? 3 : 4); TRACE("gc.ms = " << arg); if (atoi(arg) <= 0) { LECHO(34, "Negative or invalid heap size. Default value will be used!"); } p_env->VmProperties()->set("gc.ms", arg); } else if (begins_with(option, "-Xmx") || begins_with(option, "-mx")) { // cut -Xmx const char* arg = option + (begins_with(option, "-mx") ? 3 : 4); TRACE("gc.mx = " << arg); if (atoi(arg) <= 0) { LECHO(34, "Negative or invalid heap size. Default value will be used!"); } p_env->VmProperties()->set("gc.mx", arg); } else if (begins_with(option, "-Xss")) { const char* arg = option + 4; TRACE("thread.stacksize = " << arg); if (atoi(arg) <= 0) { LECHO(34, "Negative or invalid stack size. Default value will be used!"); } p_env->VmProperties()->set("thread.stacksize", arg); } else if (begins_with(option, STRING_POOL_SIZE_OPTION)) { // the pool is already created } else if (begins_with(option, "-agentlib:")) { p_env->TI->addAgent(option); } else if (begins_with(option, "-agentpath:")) { p_env->TI->addAgent(option); } else if (begins_with(option, "-javaagent:")) { char* dest = (char*) STD_MALLOC(strlen("-agentlib:hyinstrument=") + strlen(option + 11) + 1); strcpy(dest, "-agentlib:hyinstrument="); strcat(dest, option + 11); p_env->TI->addAgent(dest); STD_FREE((void*) dest); } else if (begins_with(option, "-Xrun")) { // Compatibility with JNDI p_env->TI->addAgent(option); } else if (strcmp(option, "-Xnoagent") == 0) { // Do nothing, this option is only for compatibility with old JREs } else if (strcmp(option, "-Xdebug") == 0) { // Do nothing, this option is only for compatibility with old JREs } else if (strcmp(option, "-Xfuture") == 0) { // Do nothing, this option is only for compatibility with old JREs } else if (strcmp(option, "-Xinvisible") == 0) { p_env->retain_invisible_annotations = true; } else if (strcmp(option, "-Xverify") == 0) { p_env->verify_all = true; } else if (strcmp(option, "-Xverify:none") == 0 || strcmp(option, "-noverify") == 0) { p_env->VmProperties()->set("vm.use_verifier", "false"); } else if (strcmp(option, "-Xverify:all") == 0) { p_env->verify_all = true; p_env->verify_strict = true; } else if (strcmp(option, "-Xverify:strict") == 0) { p_env->verify_all = true; p_env->verify_strict = true; } else if (strcmp(option, "-verify") == 0) { p_env->verify_all = true; } else if (begins_with(option, "-verbose")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xfileline")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xthread")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xcategory")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xtimestamp")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xverbose")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xwarn")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xfunction")) { // Moved to set_log_levels_from_cmd #ifdef _DEBUG } else if (begins_with(option, "-Xlog")) { // Moved to set_log_levels_from_cmd } else if (begins_with(option, "-Xtrace")) { // Moved to set_log_levels_from_cmd #endif //_DEBUG } else if (strncmp(option, "-D", 2) == 0) { } else if (strncmp(option, "-XD", 3) == 0 || strncmp(option, "-XX:", 4) == 0) { } else if (strcmp(option, "-Xdumpstubs") == 0) { dump_stubs = true; } else if (strcmp(option, "-Xparallel_jit") == 0) { parallel_jit = true; } else if (strcmp(option, "-Xno_parallel_jit") == 0) { parallel_jit = false; } else if (begins_with(option, "-Xdumpfile:")) { const char* arg = option + strlen("-Xdumpfile:"); dump_file_name = arg; } else if (strcmp(option, "_org.apache.harmony.vmi.portlib") == 0) { // Store a pointer to the portlib p_env->portLib = p_env->vm_arguments.options[i].extraInfo; } else if (strcmp(option, "-help") == 0 || strcmp(option, "-h") == 0 || strcmp(option, "-?") == 0) { print_generic_help(); log_exit(0); } else if (strcmp(option,"-X") == 0) { print_help_on_nonstandard_options(); log_exit(0); } else if (begins_with(option, "-enableassertions")) { add_assert_rec(p_env, option, "-enableassertions", true); } else if (begins_with(option, "-ea")) { add_assert_rec(p_env, option, "-ea", true); } else if (begins_with(option, "-disableassertions")) { add_assert_rec(p_env, option, "-disableassertions", false); } else if (begins_with(option, "-da")) { add_assert_rec(p_env, option, "-da", false); } else if (strcmp(option, "-esa") == 0 || strcmp(option, "-enablesystemassertions") == 0) { get_assert_reg(p_env)->enable_system = true; } else if (strcmp(option, "-dsa") == 0 || strcmp(option, "-disablesystemassertions") == 0) { if (p_env->assert_reg) { p_env->assert_reg->enable_system = false; } } else { LECHO(30, "Unknown option {0}" << option); USE_JAVA_HELP; log_exit(1); } } // for apr_pool_destroy(pool); } //parse_vm_arguments2
void parse_vm_arguments1(JavaVMInitArgs *vm_args, size_t *p_string_pool_size, jboolean *p_is_class_data_shared, apr_pool_t* pool) { LogFormat logger_header = LOG_EMPTY; *p_string_pool_size = DEFAULT_STRING_TABLE_SIZE; // initialize logging system as soon as possible log_init(pool); for (int i = 0; i < vm_args->nOptions; i++) { const char* option = vm_args->options[i].optionString; if (begins_with(option, STRING_POOL_SIZE_OPTION)) { const char* arg = option + strlen(STRING_POOL_SIZE_OPTION); *p_string_pool_size = parse_size(arg); if (0 == *p_string_pool_size) { LECHO(34, "Negative or invalid string pool size. A default value is used, " << DEFAULT_STRING_TABLE_SIZE << " bytes."); *p_string_pool_size = DEFAULT_STRING_TABLE_SIZE; } TRACE("string_pool_size = " << *p_string_pool_size); } else if (!strcmp(option, CLASS_DATA_SHARING_OFF_OPTION)) { *p_is_class_data_shared = JNI_FALSE; } else if (!strcmp(option, CLASS_DATA_SHARING_ON_OPTION)) { *p_is_class_data_shared = JNI_TRUE; } else if (!strcmp(option, PORTLIB_OPTION)) { log_set_portlib((HyPortLibrary*) vm_args->options[i].extraInfo); } else if (!strcmp(option, "vfprintf")) { log_set_vfprintf(vm_args->options[i].extraInfo); } else if (!strcmp(option, "exit")) { log_set_exit(vm_args->options[i].extraInfo); } else if (!strcmp(option, "abort")) { log_set_abort(vm_args->options[i].extraInfo); } else if (!strcmp(option, "-Xfileline")) { logger_header |= LOG_FILELINE; } else if (!strcmp(option, "-Xthread")) { logger_header |= LOG_THREAD_ID; } else if (!strcmp(option, "-Xcategory")) { logger_header |= LOG_CATEGORY; } else if (!strcmp(option, "-Xtimestamp")) { logger_header |= LOG_TIMESTAMP; } else if (!strcmp(option, "-Xfunction")) { logger_header |= LOG_FUNCTION; } else if (!strcmp(option, "-Xwarn")) { logger_header |= LOG_WARN; /* * -verbose[:class|:gc|:jni] set specification log filters. */ } else if (!strcmp(option, "-verbose")) { log_enable_info_category(LOG_CLASS_INFO, 0); log_enable_info_category(LOG_GC_INFO, 0); log_enable_info_category(LOG_JNI_INFO, 0); } else if (!strcmp(option, "-verbose:class")) { log_enable_info_category(LOG_CLASS_INFO, 0); } else if (!strcmp(option, "-verbose:gc")) { log_enable_info_category(LOG_GC_INFO, 0); } else if (!strcmp(option, "-verbose:jni")) { log_enable_info_category(LOG_JNI_INFO, 0); } else if (begins_with(option, "-Xverboselog:")) { const char* file_name = option + strlen("-Xverboselog:"); FILE *f = fopen(file_name, "w"); if (NULL != f) { log_set_out(f); } else { WARN(("Cannot open: %s", file_name)); } } else if (begins_with(option, "-Xverbose:")) { log_enable_info_category(option + strlen("-Xverbose:"), 1); } else if (begins_with(option, "-Xnoverbose:")) { log_disable_info_category(option + strlen("-Xnoverbose:"), 1); #ifdef _DEBUG } else if (begins_with(option, "-Xtrace:")) { log_enable_trace_category(option + strlen("-Xtrace:"), 1); } else if (begins_with(option, "-Xnotrace:")) { log_disable_trace_category(option + strlen("-Xnotrace:"), 1); #endif //_DEBUG } } log_set_header_format(logger_header); } // parse_vm_arguments1
void t_curses_term_writer(void *config) // write messages to terminal { CONFIG *c = (CONFIG*) config; UPDATE *u = malloc(sizeof *u); if ( u == NULL ) error("update malloc"); // track changes matrix out as false bool changed[N_ROWS][N_COLS];// = { [0 ... N_ROWS-1][0 ... N_COLS-1] = false }; int s12, g1, _ = 0; while ( running ) { // char recv_buf[MAX_LINE_SIZE]; memset(recv_buf, 0, MAX_LINE_SIZE); int MODE = IDLE; if ( mq_receive(c->ib_mq, recv_buf, MAX_LINE_SIZE, 0) == -1 ) error("mq_receive"); // peek into the message and handle appropriately // if ( begins_with(recv_buf, GAMEINFO_MARKER) ) { parse_gameinfo_string( recv_buf, u ); g1++; } else if ( begins_with(recv_buf, STYLE12_MARKER) ) { // make a copy of the existing ("old") board memset(u->old_board, 0, sizeof u->old_board); memcpy(u->old_board, u->board, sizeof u->board); // parse the new board parse_s12_string( recv_buf, u ); if (s12 > 0) // this is not the first message { // assume new board has not changed memset(changed, false, sizeof changed); // compare new board to old board for (int i=0; i<N_ROWS; i++) for (int j=0; j<N_ROWS; j++) changed[i][j] = (bool) (u->old_board[i][j] != u->board[i][j]); } MODE = u->my_status; if ( ! ( u->white_rating == NULL) ) // have gameinfo use_window(c->w1, (NCURSES_WINDOW_CB) cb_write_board, u); s12++; } else { // normal line, no parsing necessary. write to w2 use_window(c->w2, (NCURSES_WINDOW_CB) cb_write_response, recv_buf); _++; } // handle cursor placement in a mode-dependent way switch ( MODE ) { case PLAYING_MY_MOVE: case PLAYING_OPPONENTS_MOVE: // TODO move cursor to last remaining piece, or king pawn if // first move, etc break; case OBSERVING: case IDLE: // move cursor to the input line // TODO command history (?) wmove(c->w3, LINES, COLS); wrefresh(c->w3); break; default: break; } } // clear dynamic memory free(u->my_nick); free(u->opp_nick); free(u->text); free(u->type); free(u->white_rating); free(u->black_rating); free(u); u = NULL; }
int main(int argc, char *argv[]) { unsigned i, l, m; char buffer[200], *ptr, *ptr1; static unsigned lines[MAX_LINES], ltop = 0, increment = 10, start = 10; static FILE *fp, *fp1; printf("MICRO-BASIC 2.1 line renumbering program\n"); if (argc < 3) { fprintf(stderr, "Use: renumber old new [start [increment]]\n\n"); fprintf(stderr, "Copyright 1993-2000 Dave Dunfield\n"); fprintf(stderr, "All rights reserved.\n"); return 1; } fp = fopen(argv[1], "rvq"); fp1 = fopen(argv[2], "wvq"); if(argc > 3) start = atoi(argv[3]); if(argc > 4) increment = atoi(argv[4]); /* Pass #1: Scan and record all line numbers */ m = 0; while(fgets(buffer, sizeof(buffer)-1, fp)) { if(!(l = atoi(buffer))) { printf("Invalid line number following line %u\n", m); return 0; } if(l <= m) { printf("Improper line sequence following line %u\n", m); return 0; } lines[ltop++] = m = l; } /* Pass #2: Copy lines and replace line numbers */ rewind(fp); m = 0; while(fgets(ptr1 = ptr = buffer, sizeof(buffer), fp)) { /* Replace line number with one from the new sequence */ fixnum: while(isspace(*ptr)) ++ptr; while(ptr1 < ptr) putc(*ptr1++, fp1); if(isdigit(*ptr)) { ++m; l = atoi(ptr); while(isdigit(*ptr)) ++ptr; for(i=0; i < ltop; ++i) if(lines[i] == l) { fprintf(fp1, "%u", i * increment + start); break; } } while(*(ptr1 = ptr)) { if(begins_with(ptr, "THEN")) { ptr += 4; goto fixnum; } if(begins_with(ptr, "ORDER")) { ptr += 5; goto fixnum; } if(begins_with(ptr, "GOTO")) { ptr += 4; goto fixnum; } if(begins_with(ptr, "GOSUB")) { ptr += 5; goto fixnum; } if (*ptr != '\r' && *ptr != '\n') putc(*ptr, fp1); ++ptr; } putc('\n', fp1); } fclose(fp1); fclose(fp); printf("%u lines read, %u fixups\n", ltop, m); return 0; }
static int do_mount(const char *mnt, const char **type, mode_t rootmode, int fd, const char *opts, const char *dev, char **fsnamep, char **mnt_optsp, off_t rootsize) { int res; int flags = MS_NOSUID | MS_NODEV; char *optbuf; char *mnt_opts = NULL; const char *s; char *d; char *fsname = NULL; int check_empty = 1; int blkdev = 0; optbuf = (char *) malloc(strlen(opts) + 128); if (!optbuf) { fprintf(stderr, "%s: failed to allocate memory\n", progname); return -1; } for (s = opts, d = optbuf; *s;) { unsigned len; const char *fsname_str = "fsname="; for (len = 0; s[len] && s[len] != ','; len++); if (begins_with(s, fsname_str)) { unsigned fsname_str_len = strlen(fsname_str); if (fsname) free(fsname); fsname = (char *) malloc(len - fsname_str_len + 1); if (!fsname) { fprintf(stderr, "%s: failed to allocate memory\n", progname); goto err; } memcpy(fsname, s + fsname_str_len, len - fsname_str_len); fsname[len - fsname_str_len] = '\0'; } else if (opt_eq(s, len, "blkdev")) { if (getuid() != 0) { fprintf(stderr, "%s: option blkdev is privileged\n", progname); goto err; } blkdev = 1; } else if (opt_eq(s, len, "nonempty")) { check_empty = 0; } else if (!begins_with(s, "fd=") && !begins_with(s, "rootmode=") && !begins_with(s, "user_id=") && !begins_with(s, "group_id=")) { int on; int flag; int skip_option = 0; if (opt_eq(s, len, "large_read")) { struct utsname utsname; unsigned kmaj, kmin; res = uname(&utsname); if (res == 0 && sscanf(utsname.release, "%u.%u", &kmaj, &kmin) == 2 && (kmaj > 2 || (kmaj == 2 && kmin > 4))) { fprintf(stderr, "%s: note: 'large_read' mount option is deprecated for %i.%i kernels\n", progname, kmaj, kmin); skip_option = 1; } } if (getuid() != 0 && !user_allow_other && (opt_eq(s, len, "allow_other") || opt_eq(s, len, "allow_root"))) { fprintf(stderr, "%s: option %.*s only allowed if 'user_allow_other' is set in /etc/fuse.conf\n", progname, len, s); goto err; } if (!skip_option) { if (find_mount_flag(s, len, &on, &flag)) { if (on) flags |= flag; else flags &= ~flag; } else { memcpy(d, s, len); d += len; *d++ = ','; } } } s += len; if (*s) s++; } *d = '\0'; res = get_mnt_opts(flags, optbuf, &mnt_opts); if (res == -1) goto err; sprintf(d, "fd=%i,rootmode=%o,user_id=%i,group_id=%i", fd, rootmode, getuid(), getgid()); if (fsname == NULL) { fsname = strdup(dev); if (!fsname) { fprintf(stderr, "%s: failed to allocate memory\n", progname); goto err; } } if (check_empty && check_mountpoint_empty(mnt, rootmode, rootsize) == -1) goto err; if (blkdev) *type = "fuseblk"; res = mount(fsname, mnt, *type, flags, optbuf); if (res == -1 && errno == EINVAL) { /* It could be an old version not supporting group_id */ sprintf(d, "fd=%i,rootmode=%o,user_id=%i", fd, rootmode, getuid()); res = mount(fsname, mnt, *type, flags, optbuf); } if (res == -1) { int errno_save = errno; if (blkdev && errno == ENODEV && !has_fuseblk()) fprintf(stderr, "%s: 'fuseblk' support missing; try the kernel module from fuse-2.6.0 or later\n", progname); else fprintf(stderr, "%s: mount failed: %s\n", progname, strerror(errno_save)); goto err; } else { *fsnamep = fsname; *mnt_optsp = mnt_opts; } free(optbuf); return res; err: free(fsname); free(mnt_opts); free(optbuf); return -1; }
void TypeRegistry::define_properties() { for (TypeMap::iterator j=tfmap_.begin(); j!=tfmap_.end(); ++j) { for (TypeList::iterator i=j->second.begin(); i!=j->second.end(); ++i) { typedef std::map<std::string, FunctionList> NameFunctionMap; typedef std::map<std::string, NameFunctionMap> FunctionMap; typedef std::map<std::size_t, FunctionMap> IndexFunctionMap; typedef std::map<std::string, PropertyList> PropertyMap; PropertyMap newprops; NameFunctionMap count_candidates; FunctionMap add_candidates; FunctionMap insert_candidates; IndexFunctionMap remove_candidates; IndexFunctionMap get_candidates; IndexFunctionMap set_candidates; typedef std::map<std::string, StringSet> NameTypeMap; NameTypeMap nameTypeMap; std::size_t max_indices = 0; for (FunctionList::const_iterator k=i->methods.begin(); k!=i->methods.end(); ++k) { if (!k->is_constructor(*i) && !k->is_destructor() && !k->is_static) { if (begins_with(k->name, "getOr") && k->name.size() > 5 && std::isupper(k->name[5], std::locale())) continue; if (begins_with(k->name, "getNum") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (k->params.empty()) { std::string name(k->name.substr(6)); count_candidates[name].push_back(*k); continue; } } if (begins_with(k->name, "get") && ((k->name.size() > 3 && std::isupper(k->name[3], std::locale())) || (k->name.size() == 3))) { std::string name(k->name.substr(3)); std::size_t indices = k->params.size(); get_candidates[indices][k->return_type_specifier][name].push_back(*k); if (indices > max_indices) max_indices = indices; nameTypeMap[name].insert(k->return_type_specifier); continue; } if (begins_with(k->name, "set") && k->name.size() > 3 && std::isupper(k->name[3], std::locale())) { if (!k->params.empty()) { std::string name(k->name.substr(3)); std::size_t indices = k->params.size() - 1; set_candidates[indices][k->params.back().type_specifier][name].push_back(*k); if (indices > max_indices) max_indices = indices; nameTypeMap[name].insert(k->params.back().type_specifier); } continue; } if (begins_with(k->name, "add") && k->name.size() > 3 && std::isupper(k->name[3], std::locale())) { if (k->params.size() == 1) { std::string name(k->name.substr(3)); add_candidates[k->params.front().type_specifier][name].push_back(*k); nameTypeMap[name].insert(k->params.front().type_specifier); } continue; } if (begins_with(k->name, "remove") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (!k->params.empty()) { std::string name(k->name.substr(6)); std::size_t indices = k->params.size(); remove_candidates[indices][k->params.front().type_specifier][name].push_back(*k); } continue; } if (begins_with(k->name, "insert") && k->name.size() > 6 && std::isupper(k->name[6], std::locale())) { if (k->params.size() >= 2) { std::string name(k->name.substr(6)); insert_candidates[k->params.front().type_specifier][name].push_back(*k); } continue; } } } for (NameTypeMap::const_iterator k=nameTypeMap.begin(); k!=nameTypeMap.end(); ++k) { StringSet::const_iterator endIt = k->second.end(); for (StringSet::const_iterator h=k->second.begin(); h!=endIt; ++h) { PropertyDesc pd; pd.name = k->first; pd.type_name = *h; // simple property { const FunctionList &fl_get = get_candidates[0][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[0][*h][k->first].begin(), set_candidates[0][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[0]["const " + *h + " &"][k->first].begin(), set_candidates[0]["const " + *h + " &"][k->first].end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; if (!pd.get_method.empty() || !pd.set_method.empty()) { pd.type = PropertyDesc::SIMPLE; newprops[pd.name].push_back(pd); continue; } } // array property { FunctionList fl_count; fl_count.insert(fl_count.end(), count_candidates[k->first].begin(), count_candidates[k->first].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "s"].begin(), count_candidates[k->first + "s"].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "es"].begin(), count_candidates[k->first + "es"].end()); fl_count.insert(fl_count.end(), count_candidates[k->first + "ren"].begin(), count_candidates[k->first + "ren"].end()); if (fl_count.size()) { std::string& return_type_specifier = fl_count.front().return_type_specifier; const FunctionList &fl_get = get_candidates[1][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[1][*h][k->first].begin(), set_candidates[1][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[1]["const " + *h + " &"][k->first].begin(), set_candidates[1]["const " + *h + " &"][k->first].end()); const FunctionList &fl_add = add_candidates[*h][k->first]; FunctionList fl_remove; fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first].begin(), remove_candidates[1][return_type_specifier][k->first].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "s"].begin(), remove_candidates[1][return_type_specifier][k->first + "s"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "es"].begin(), remove_candidates[1][return_type_specifier][k->first + "es"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[1][return_type_specifier][k->first + "ren"].begin(), remove_candidates[1][return_type_specifier][k->first + "ren"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first].begin(), remove_candidates[2][return_type_specifier][k->first].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "s"].begin(), remove_candidates[2][return_type_specifier][k->first + "s"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "es"].begin(), remove_candidates[2][return_type_specifier][k->first + "es"].end()); fl_remove.insert(fl_remove.end(), remove_candidates[2][return_type_specifier][k->first + "ren"].begin(), remove_candidates[2][return_type_specifier][k->first + "ren"].end()); FunctionList fl_insert = insert_candidates[return_type_specifier][k->first]; fl_insert.erase(std::remove_if(fl_insert.begin(), fl_insert.end(), PropertyFunctionFirstParameterNameFilter<2>(fl_count.front().return_type_specifier)), fl_insert.end()); fl_remove.erase(std::remove_if(fl_remove.begin(), fl_remove.end(), PropertyFunctionFirstParameterNameFilter<1>(fl_count.front().return_type_specifier)), fl_remove.end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; if (!fl_add.empty()) pd.add_method = fl_add.front().name_signature; if (!fl_insert.empty()) pd.insert_method = fl_insert.front().name_signature; if (!fl_remove.empty()) pd.remove_method = fl_remove.front().name_signature; if (!fl_count.empty()) pd.count_method = fl_count.front().name_signature; if (!pd.get_method.empty() || !pd.set_method.empty()) { pd.type = PropertyDesc::ARRAY; newprops[pd.name].push_back(pd); continue; } } } // indexed property for (std::size_t u=1; u<=max_indices; ++u) { const FunctionList &fl_get = get_candidates[u][*h][k->first]; FunctionList fl_set; fl_set.insert(fl_set.end(), set_candidates[u][*h][k->first].begin(), set_candidates[u][*h][k->first].end()); fl_set.insert(fl_set.end(), set_candidates[u]["const " + *h + " &"][k->first].begin(), set_candidates[u]["const " + *h + " &"][k->first].end()); if (!fl_get.empty()) pd.get_method = fl_get.front().name_signature; if (!fl_set.empty()) pd.set_method = fl_set.front().name_signature; for (FunctionList::const_iterator x=fl_get.begin(); x!=fl_get.end(); ++x) { ParameterList get_indices(x->params.begin(), x->params.end()); for (FunctionList::const_iterator y=fl_set.begin(); y!=fl_set.end(); ++y) { ParameterList set_indices(y->params.begin(), y->params.end()); set_indices.pop_back(); if (same_parameters(get_indices, set_indices)) { pd.type = PropertyDesc::INDEXED; pd.get_method = x->name_signature; pd.set_method = y->name_signature; newprops[pd.name].push_back(pd); break; } } } } } } for (PropertyMap::iterator k=newprops.begin(); k!=newprops.end(); ++k) { if (!k->second.empty()) { std::sort(k->second.begin(), k->second.end(), PropertySorter()); PropertyDesc & pd = k->second.front(); const PropertyOptions *opt = cfg_.getPropertyOptions(i->type_name, pd.name); if (opt) { if (!opt->get_method.empty()) pd.get_method = opt->get_method; if (!opt->set_method.empty()) pd.set_method = opt->set_method; if (!opt->remove_method.empty()) pd.remove_method = opt->remove_method; if (!opt->add_method.empty()) pd.add_method = opt->add_method; if (!opt->insert_method.empty()) pd.insert_method = opt->insert_method; if (!opt->count_method.empty()) { Notify::info("define count method of property `" + pd.name + "' in type `" + i->type_name + "' on user request"); pd.type = PropertyDesc::ARRAY; pd.count_method = opt->count_method; } } i->properties.push_back(k->second.front()); } } } } }
/* * Parse the configuration file and set up variables */ int dlg_parse_rc(void) { int i; int l = 1; PARSE_LINE parse; char str[MAX_LEN + 1]; char *var; char *value; char *tempptr; int result = 0; FILE *rc_file = 0; char *params; /* * At startup, dialog determines the settings to use as follows: * * a) if the environment variable $DIALOGRC is set, its value determines * the name of the configuration file. * * b) if the file in (a) can't be found, use the file $HOME/.dialogrc * as the configuration file. * * c) if the file in (b) can't be found, try using the GLOBALRC file. * Usually this will be /etc/dialogrc. * * d) if the file in (c) cannot be found, use the compiled-in defaults. */ /* try step (a) */ if ((tempptr = getenv("DIALOGRC")) != NULL) rc_file = fopen(tempptr, "rt"); if (rc_file == NULL) { /* step (a) failed? */ /* try step (b) */ if ((tempptr = getenv("HOME")) != NULL && strlen(tempptr) < MAX_LEN - (sizeof(DIALOGRC) + 3)) { if (tempptr[0] == '\0' || lastch(tempptr) == '/') sprintf(str, "%s%s", tempptr, DIALOGRC); else sprintf(str, "%s/%s", tempptr, DIALOGRC); rc_file = fopen(tempptr = str, "rt"); } } if (rc_file == NULL) { /* step (b) failed? */ /* try step (c) */ strcpy(str, GLOBALRC); if ((rc_file = fopen(tempptr = str, "rt")) == NULL) return 0; /* step (c) failed, use default values */ } DLG_TRACE(("opened rc file \"%s\"\n", tempptr)); /* Scan each line and set variables */ while ((result == 0) && (fgets(str, MAX_LEN, rc_file) != NULL)) { DLG_TRACE(("rc:%s", str)); if (*str == '\0' || lastch(str) != '\n') { /* ignore rest of file if line too long */ fprintf(stderr, "\nParse error: line %d of configuration" " file too long.\n", l); result = -1; /* parse aborted */ break; } lastch(str) = '\0'; if (begins_with(str, "bindkey", ¶ms)) { if (!dlg_parse_bindkey(params)) { fprintf(stderr, "\nParse error: line %d of configuration\n", l); result = -1; } continue; } parse = parse_line(str, &var, &value); /* parse current line */ switch (parse) { case LINE_EMPTY: /* ignore blank lines and comments */ break; case LINE_EQUALS: /* search table for matching config variable name */ if ((i = find_vars(var)) >= 0) { switch (vars[i].type) { case VAL_INT: *((int *) vars[i].var) = atoi(value); break; case VAL_STR: if (!isquote(value[0]) || !isquote(lastch(value)) || strlen(value) < 2) { fprintf(stderr, "\nParse error: string value " "expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { /* remove the (") quotes */ value++; lastch(value) = '\0'; strcpy((char *) vars[i].var, value); } break; case VAL_BOOL: if (!dlg_strcmp(value, "ON")) *((bool *) vars[i].var) = TRUE; else if (!dlg_strcmp(value, "OFF")) *((bool *) vars[i].var) = FALSE; else { fprintf(stderr, "\nParse error: boolean value " "expected at line %d of configuration " "file (found %s).\n", l, value); result = -1; /* parse aborted */ } break; } #ifdef HAVE_COLOR } else if ((i = find_color(var)) >= 0) { int fg = 0; int bg = 0; int hl = 0; if (str_to_attr(value, &fg, &bg, &hl) == -1) { fprintf(stderr, "\nParse error: attribute " "value expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { dlg_color_table[i].fg = fg; dlg_color_table[i].bg = bg; dlg_color_table[i].hilite = hl; } } else { #endif /* HAVE_COLOR */ fprintf(stderr, "\nParse error: unknown variable " "at line %d of configuration file:\n\t%s\n", l, var); result = -1; /* parse aborted */ } break; case LINE_ERROR: fprintf(stderr, "\nParse error: syntax error at line %d of " "configuration file.\n", l); result = -1; /* parse aborted */ break; } l++; /* next line */ } (void) fclose(rc_file); return result; }
static int do_mount(const char *mnt, char **typep, mode_t rootmode, int fd, const char *opts, const char *dev, char **sourcep, char **mnt_optsp, off_t rootsize) { int res; #ifdef __SOLARIS__ /* * In Solaris, nosuid is equivalent to nosetuid + nodevices. We only * have MS_NOSUID for mount flags (no MS_(NO)SETUID, etc.). But if * we set that as a default, it restricts specifying just nosetuid * or nodevices; there is no way for the user to specify setuid + * nodevices or vice-verse. * On the chance that this is being run from root, we won't try * to add nosetuid or nodevices restrictions; this program must * be exec'd from the library, where we've already sanitized the * options. */ int flags = 0; #else int flags = MS_NOSUID | MS_NODEV; #endif /* __SOLARIS__ */ char *optbuf; char *mnt_opts = NULL; const char *s; char *d; char *fsname = NULL; char *subtype = NULL; char *source = NULL; char *type = NULL; int check_empty = 1; int blkdev = 0; optbuf = (char *) malloc(strlen(opts) + 128); if (!optbuf) { fprintf(stderr, "%s: failed to allocate memory\n", progname); return -1; } for (s = opts, d = optbuf; *s;) { unsigned len; const char *fsname_str = "fsname="; const char *subtype_str = "subtype="; for (len = 0; s[len] && s[len] != ','; len++); if (begins_with(s, fsname_str)) { if (!get_string_opt(s, len, fsname_str, &fsname)) goto err; } else if (begins_with(s, subtype_str)) { if (!get_string_opt(s, len, subtype_str, &subtype)) goto err; } else if (opt_eq(s, len, "blkdev")) { if (getuid() != 0) { fprintf(stderr, "%s: option blkdev is privileged\n", progname); goto err; } blkdev = 1; } else if (opt_eq(s, len, "nonempty")) { check_empty = 0; } else if (!begins_with(s, "fd=") && !begins_with(s, "rootmode=") && !begins_with(s, "user_id=") && !begins_with(s, "group_id=")) { int on; int flag; int skip_option = 0; if (opt_eq(s, len, "large_read")) { struct utsname utsname; unsigned kmaj, kmin; res = uname(&utsname); if (res == 0 && sscanf(utsname.release, "%u.%u", &kmaj, &kmin) == 2 && (kmaj > 2 || (kmaj == 2 && kmin > 4))) { fprintf(stderr, "%s: note: 'large_read' mount option is deprecated for %i.%i kernels\n", progname, kmaj, kmin); skip_option = 1; } } if (getuid() != 0 && !user_allow_other && (opt_eq(s, len, "allow_other") || opt_eq(s, len, "allow_root"))) { fprintf(stderr, "%s: option %.*s only allowed if 'user_allow_other' is set in /etc/fuse.conf\n", progname, len, s); goto err; } if (!skip_option) { if (find_mount_flag(s, len, &on, &flag)) { if (on) flags |= flag; else flags &= ~flag; } else { memcpy(d, s, len); d += len; *d++ = ','; } } } s += len; if (*s) s++; } *d = '\0'; res = get_mnt_opts(flags, optbuf, &mnt_opts); if (res == -1) goto err; sprintf(d, "fd=%i,rootmode=%o,user_id=%i,group_id=%i", fd, rootmode, getuid(), getgid()); if (check_empty && fuse_mnt_check_empty(progname, mnt, rootmode, rootsize) == -1) goto err; source = malloc((fsname ? strlen(fsname) : 0) + (subtype ? strlen(subtype) : 0) + strlen(dev) + 32); type = malloc((subtype ? strlen(subtype) : 0) + 32); if (!type || !source) { fprintf(stderr, "%s: failed to allocate memory\n", progname); goto err; } if (subtype) sprintf(type, "%s.%s", blkdev ? "fuseblk" : "fuse", subtype); else strcpy(type, blkdev ? "fuseblk" : "fuse"); if (fsname) strcpy(source, fsname); else strcpy(source, subtype ? subtype : dev); #ifdef __SOLARIS__ res = mount(source, mnt, MS_OPTIONSTR|flags, type, NULL, 0, optbuf, MAX_MNTOPT_STR); #else res = mount(source, mnt, type, flags, optbuf); #endif /* __SOLARIS__ */ #ifdef __SOLARIS__ if (res == -1 && errno == EINVAL && subtype) { #else if (res == -1 && errno == ENODEV && subtype) { #endif /* Probably missing subtype support */ strcpy(type, blkdev ? "fuseblk" : "fuse"); if (fsname) { if (!blkdev) sprintf(source, "%s#%s", subtype, fsname); } else { strcpy(source, type); } #ifdef __SOLARIS__ res = mount(source, mnt, MS_OPTIONSTR|flags, type, NULL, 0, optbuf, MAX_MNTOPT_STR); #else res = mount(source, mnt, type, flags, optbuf); #endif /* __SOLARIS__ */ } if (res == -1 && errno == EINVAL) { /* It could be an old version not supporting group_id */ sprintf(d, "fd=%i,rootmode=%o,user_id=%i", fd, rootmode, getuid()); #ifdef __SOLARIS__ res = mount(dev, mnt, MS_OPTIONSTR|flags, type, NULL, 0, optbuf, MAX_MNTOPT_STR); #else res = mount(source, mnt, type, flags, optbuf); #endif /* __SOLARIS__ */ } if (res == -1) { int errno_save = errno; if (blkdev && errno == ENODEV && !fuse_mnt_check_fuseblk()) fprintf(stderr, "%s: 'fuseblk' support missing\n", progname); else fprintf(stderr, "%s: mount failed: %s\n", progname, strerror(errno_save)); goto err; } else { *sourcep = source; *typep = type; *mnt_optsp = mnt_opts; } free(optbuf); return res; err: free(fsname); free(subtype); free(source); free(type); free(mnt_opts); free(optbuf); return -1; } static int check_version(const char *dev) { int res; int majorver; int minorver; const char *version_file; FILE *vf; if (strcmp(dev, FUSE_DEV_OLD) != 0) return 0; version_file = FUSE_VERSION_FILE_OLD; vf = fopen(version_file, "r"); if (vf == NULL) { fprintf(stderr, "%s: kernel interface too old\n", progname); return -1; } res = fscanf(vf, "%i.%i", &majorver, &minorver); fclose(vf); if (res != 2) { fprintf(stderr, "%s: error reading %s\n", progname, version_file); return -1; } if (majorver < 3) { fprintf(stderr, "%s: kernel interface too old\n", progname); return -1; } return 0; }
inline bin2hpp::language getlanguage(std::vector<std::string>& params){ const auto itinend = std::find(params.begin(), params.end(), options::in); const auto it = std::find_if(params.begin(), itinend, [](const std::string& s){return begins_with(s, options::standard);}); if( it != itinend ){ assert(it->length() >= options::standard.length()); if(it->length() == options::standard.length()){ throw std::runtime_error("option -lang without name"); // invalidparam_namespace } std::string lang = it->substr(options::standard.length()); // fixme: validate namespace params.erase(it); return tolang(lang); } bin2hpp::language toreturn; return toreturn; }
inline void overwriteconstspec(std::vector<std::string>& params, const bin2hpp::language& constspec, bin2hpp::constid_array& c_arr, bin2hpp::constid_size& c_siz ){ const auto itinend = std::find(params.begin(), params.end(), options::in); { const auto itcons = std::find_if(params.begin(), itinend, [](const std::string &s) { return begins_with(s, options::constspec); } ); if (itcons != itinend) { if(constspec.id == bin2hpp::lang_id::java){ throw std::runtime_error("java does not accept a const id"); } std::string o_c_size = itcons->substr(options::constspec.length()); params.erase(itcons); if (o_c_size == "const") { c_siz = bin2hpp::constid_size::_const; c_arr = bin2hpp::constid_array::_const; } else if (o_c_size == bin2hpp::constid::_constexpr) { if(constspec.id != bin2hpp::lang_id::cpp || !hasconstexpxr(constspec._cpprev)){ throw std::runtime_error("invalid const specifier for the specified language"); } c_siz = bin2hpp::constid_size::_constexpr; c_arr = bin2hpp::constid_array::_constexpr; } else { throw std::runtime_error("invalid const specifier"); } } } { const auto itconstsize = std::find_if(params.begin(), itinend, [](const std::string &s) { return begins_with(s, options::constsize); } ); if (itconstsize != itinend) { if(constspec.id == bin2hpp::lang_id::java){ throw std::runtime_error("java does not accept a const id"); } std::string o_c_size = itconstsize->substr(options::constsize.length()); // fixme: validate namespace params.erase(itconstsize); if (o_c_size == bin2hpp::constid::_const) { c_siz = bin2hpp::constid_size::_const; } else if (o_c_size == bin2hpp::constid::_enum) { c_siz = bin2hpp::constid_size::_enum; } else if (o_c_size == bin2hpp::constid::_constexpr) { if(constspec.id != bin2hpp::lang_id::cpp || !hasconstexpxr(constspec._cpprev)){ throw std::runtime_error("invalid const specifier for the specified language"); } c_siz = bin2hpp::constid_size::_constexpr; } else { throw std::runtime_error("invalid const specifier"); } } } { const auto itconstarray = std::find_if(params.begin(), itinend, [](const std::string &s) { return begins_with(s, options::constarray); } ); if (itconstarray != itinend) { if(constspec.id == bin2hpp::lang_id::java){ throw std::runtime_error("java does not accept a const id"); } std::string o_c_arr = itconstarray->substr(options::constarray.length()); // fixme: validate namespace params.erase(itconstarray); if (o_c_arr == bin2hpp::constid::_const) { c_arr = bin2hpp::constid_array::_const; } else if (o_c_arr == bin2hpp::constid::_constexpr) { if(constspec.id != bin2hpp::lang_id::cpp || !hasconstexpxr(constspec._cpprev)){ throw std::runtime_error("invalid const specifier for the specified language"); } c_arr = bin2hpp::constid_array::_constexpr; } else { throw std::runtime_error("invalid const specifier"); } } } }
inline std::string getnamespace(std::vector<std::string>& params){ const auto itinend = std::find(params.begin(), params.end(), options::in); const auto it = std::find_if(params.begin(), itinend, [](const std::string& s){return begins_with(s, options::ns);}); if( it != itinend ) { assert(it->length() >= options::ns.length()); std::string toreturn = it->substr(options::ns.length()); // fixme: validate namespace params.erase(it); return toreturn; } return bin2hpp::defaultnamespace; }