void parse_config(char *file) { char line[80]; FILE *f = fopen(file, "r"); if (!f) error("[!] Error opening configuration file"); while (fgets(line, 80, f) != NULL) { if (line[0] == '#') continue; if(strstr(line, "socks_port") != NULL) SOCKS_PORT = strtol(get_value(line), NULL, 10); else if(strstr(line, "socks_addr") != NULL) SOCKS_ADDR = string_value(get_value(line)); else if(strstr(line, "listen_addr") != NULL) LISTEN_ADDR = string_value(get_value(line)); else if(strstr(line, "listen_port") != NULL) LISTEN_PORT = strtol(get_value(line), NULL, 10); else if(strstr(line, "resolv_conf") != NULL) RESOLVCONF = string_value(get_value(line)); else if(strstr(line, "log_file") != NULL) LOGFILE = string_value(get_value(line)); else if(strstr(line, "daemon") != NULL) DAEMON = string_value(get_value(line)); } if (fclose(f) != 0) error("[!] Error closing configuration file"); }
struct ast* rlength(struct ast* a) { switch (a->node_type) { case N_STRING_1: { return new_integer_node(strlen(string_value(a))); break; }; case N_STRING_2: { return new_integer_node(strlen(string_value(a))); break; }; case N_IDENTIFIER: { return rlength(eval_ast(a)); break; }; case N_ARRAY: { return new_integer_node(array_tree_size(a->left)); break; }; case N_ARRAY_CONTENT: { return rlength(eval_ast(a->left)); break; }; default: { no_method_error("length", a); break; }; }; return new_nil_node(); };
/* \fn owi_display(owi, index, current, flags) * Display one value in html (depending on type, flags) * \param[in] owi handler * \param[in] index data index * \param[in] current current data value * \param[in] flags flags for display behavior */ void owi_display(struct owi_t *owi, unsigned int index, struct string_t *current, unsigned int flags) { /* Loop */ int i = 0; /* Valid values for html select/checkbox elements */ struct array_t *valid = NULL; /* Current data */ struct data_t *data = &(owi->data[index]); /* Error variable */ struct string_t *error = NULL; /* Class name for variables */ struct string_t *class = NULL; /* Flags set so its not just display values? */ if (data->flags & flags) { /* Create error variable */ error = string_insert_value(string_copy_value(data->html), 0, OWI_ERROR_PREFIX); class = string_copy_value("text"); /* Checkbox? */ if (data->type == DATA_TYPE_CHECKBOX) { /* Parse valid values from string */ valid = string_split_value(string_copy_value(data->valid), "|"); /* Print checkbox */ printf("<input type=\"checkbox\" class=\"checkbox\" " "name=\"%s\" value=\"%s\" %s /> ", data->html, string_value(array_value(valid, 0)), current && !string_compare(current, array_value(valid, 0)) ? "checked" : ""); /* Free valid values */ array_free(&valid); /* Selectbox? */ } else if (data->type == DATA_TYPE_SELECT) { /* Parse valid values from string */ valid = string_split_value(string_copy_value(data->valid), "|"); /* Print selectbox */ printf("<select name=\"%s\" class=\"%s\">\n", data->html, string_value(class)); /* Loop through values */ for (i = 0; i < array_length(valid); i++) { /* Flag for current value */ int current_value = 0; /* Current value? */ if (current && string_compare(current, array_value(valid, i))) { current_value = 1; } /* Print on stdout */ printf("<option value=\"%s\" %s>%s</option>\n", string_value(array_value(valid, i)), current_value == 0 ? " selected" : "", string_value(array_value(valid, i))); } printf("</select><br />\n"); /* Free valid values */ array_free(&valid); } else if (data->type == DATA_TYPE_TEXT) {
char * extended_scope_string (RESULT_NODE *scope) { RESULT_NODE *member; static char line [LINE_MAX + 1]; int length = 0; line [0] = '\0'; if (scope) { member = scope; while ((member-> script_node-> type == GG_MEMBER || member-> script_node-> type == GG_ATTRIBUTE) && member-> scope) member = member-> scope; if (member-> script_node-> type != GG_MEMBER && member-> script_node-> type != GG_ATTRIBUTE) { strncat (line, string_value (& member-> value), LINE_MAX - length); length += strlen (member-> value. s); member = member-> parent; } while (member != scope-> parent && length < LINE_MAX) { if (member-> script_node-> type == GG_MEMBER) { strncat (line, "->", LINE_MAX - length); length += 2; } else { strncat (line, ".", LINE_MAX - length); length += 1; } if (member-> name) { strncat (line, string_value (& member-> name-> value), LINE_MAX - length); length += strlen (member-> name-> value. s); } if (member-> script_node-> before) { strncat (line, "(...)", LINE_MAX - length); length += 5; } member = member-> parent; } } return line; }
static int sock_connect (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread) { RESULT_NODE *host = argc > 0 ? argv [0] : NULL; RESULT_NODE *service = argc > 1 ? argv [1] : NULL; RESULT_NODE *timeout = argc > 2 ? argv [2] : NULL; RESULT_NODE *error = argc > 3 ? argv [3] : NULL; if (! service) { strcpy (object_error, "Missing argument: service"); return -1; } if (service-> value. type == TYPE_UNDEFINED) { result-> culprit = service-> culprit; service-> culprit = NULL; lsend_ggcode_call_ok (& gsl_thread-> queue-> qid, NULL, NULL, NULL, NULL, 0); return 0; } { THREAD *thread; if (start_socket_agent ()) return -1; thread = thread_create (AGENT_NAME, ""); tcb = thread-> tcb; tcb-> gsl_thread = gsl_thread; tcb-> result = result; tcb-> buffer = NULL; tcb-> error = error; tcb-> sock_handle = NULL; tcb-> context = item; tcb-> handle = 0; lsend_smtsock_connect (& sockq-> qid, & thread-> queue-> qid, NULL, NULL, NULL, 0, (word) (timeout ? number_value (& timeout-> value) : 0), "tcp", host ? string_value (& host-> value) : "", string_value (& service-> value), 0, 0, 0); return 0; } return 0; /* Just in case */ }
/* Register params in environment */ void register_params(environment *env, value *param_list) { value *current_param; if (!param_list) return; current_param = param_list; while (current_param!=NULL) { value *param = NULL; value *param_name; param_name = string_value(current_param->identifier); switch(current_param->value_type) { case VT_INTEGR: param = assign(env, param_name, int_value(0), 1); break; case VT_VOID: param = assign(env, param_name, void_value(), 1); break; case VT_FUNCTN: param = assign(env, param_name, null_fn, 1); break; default: fatal("Could not determine parameter type!"); } append_code(make_quad_value("", param, NULL, NULL, TT_POP_PARAM, 0)); current_param = current_param->next; } }
object symbol(char *str, unsigned long len) { unsigned long bucket; object el, o; char *symstr; unsigned long symlen; bucket = symbol_string_hash(str, len) % symbol_table.nbuckets; el = symbol_table.buckets[bucket]; while (!is_null(el)) { o = symbol_string(car(el)); symstr = string_value(o); symlen = string_length(o); if ((len == symlen) && (memcmp(symstr, str, len) == 0)) return car(el); el = cdr(el); } /* not there, intern now */ o = make_string_buffer(str, len); el = make_symbol_with_string(o); symbol_table.buckets[bucket] = cons(el, symbol_table.buckets[bucket]); return el; }
void lisp_display(object exp, FILE *out) { switch (type_of(exp)) { case T_STRING: fprintf(out, "%.*s", (int) string_length(exp), string_value(exp)); break; case T_CHARACTER: fputc(character_value(exp), out); break; case T_PAIR: if (is_finite_list(exp, NULL)) { fprintf(out, "("); display_pair(exp, out); fprintf(out, ")"); } else { fprintf(out, "#<unprintable-structure>"); } break; default: lisp_print(exp, out); break; } }
static const wchar_t *block_name(C_procedure_t *block, obj_t *env) { if (block == b_eval) return L"b_eval"; if (block == b_accum_operator) return L"b_accum_operator"; if (block == b_accum_arg) return L"b_accum_arg"; if (block == b_eval_sequence) return L"b_eval_sequence"; if (block == NULL) return L"NULL"; /* XXX Move this code into env.c. */ if (!env) env = library_env(r6rs_library()); if (is_pair(env)) { obj_t *frame = pair_car(env); while (frame) { obj_t *binding = pair_car(frame); obj_t *value = binding_value(binding); if (is_procedure(value) && procedure_is_C(value)) { C_procedure_t *body; body = (C_procedure_t *)procedure_body(value); if (body == block) { obj_t *name = symbol_name(binding_name(binding)); return string_value(name); } } frame = pair_cdr(frame); } } return L"<some-proc>"; }
static int conv_ord (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread) { RESULT_NODE *arg = argc > 0 ? argv [0] : NULL; if (! arg) { strcpy (object_error, "Missing argument: arg"); return -1; } if (arg-> value. type == TYPE_UNDEFINED) { result-> culprit = arg-> culprit; arg-> culprit = NULL; return 0; } { string_value (&arg-> value); if (arg-> value. type == TYPE_STRING) { result-> value. type = TYPE_NUMBER; result-> value. n = arg-> value. s [0]; } else { result-> culprit = arg-> culprit; arg-> culprit = NULL; } return 0; } return 0; /* Just in case */ }
pointer scm_load_ext(scheme *sc, pointer args) { pointer first_arg; pointer retval; char filename[MAXPATHLEN], init_fn[MAXPATHLEN+6]; char *name; HMODULE dll_handle; void (*module_init)(scheme *sc); if ((args != sc->NIL) && is_string((first_arg = pair_car(args)))) { name = string_value(first_arg); make_filename(name, filename); make_init_fn(name, init_fn); dll_handle = dl_attach(filename); if (dll_handle == 0) { retval = sc -> F; } else { module_init = (void(*)(scheme *))dl_proc(dll_handle, init_fn); if (module_init != 0) { (*module_init)(sc); retval = sc -> T; } else { retval = sc->F; } } } else { retval = sc -> F; } return(retval); }
static int conv_string (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread) { RESULT_NODE *arg = argc > 0 ? argv [0] : NULL; if (! arg) { strcpy (object_error, "Missing argument: arg"); return -1; } if (arg-> value. type == TYPE_UNDEFINED) { result-> culprit = arg-> culprit; arg-> culprit = NULL; return 0; } { if (arg-> value. type != TYPE_UNDEFINED) { string_value (&arg-> value); copy_value (&result-> value, &arg-> value); } return 0; } return 0; /* Just in case */ }
std::string Cell::toString() const { if (isSymbol()) return symname(m_value); return string_value(m_value); }
struct ast* eval_instance_native_method(struct ast* m) { if (m != NULL){ char* method_name; if (m->node_type == N_METHOD_CALL_1) { method_name = strdup(((struct method_call_node*)m)->method_name); }; if (!strcmp(method_name, LENGTH)) { struct method_call_node* mc = (struct method_call_node*)m; return rlength(eval_ast(mc->left_ast)); } else if (!strcmp(method_name, EACH_ITERATOR)) { struct method_call_node* mc = (struct method_call_node*)m; return reach(eval_ast(mc->left_ast), mc->opt_block); } else if (!strcmp(method_name, RESPOND_TO)) { struct method_call_node* mc = (struct method_call_node*)m; struct list_node* arg_node = mc->args; if (list_length(arg_node) != 1){ wrong_arguments_error(list_length(arg_node), 1); } return rrespond_to(eval_ast(mc->left_ast), strdup(string_value(eval_ast(arg_node->arg)))); } else if (!strcmp(method_name, NIL_METHOD)) { return rnil((struct method_call_node*)m); } else if (!strcmp(method_name, OBJECT_ID)) { return robject_id((struct method_call_node*)m); }; }; return new_nil_node(); };
const wchar_t *charbuf_C_str(const charbuf_t *cbp) { // Ensure string is NUL-terminated. charbuf_append_char((charbuf_t *)cbp, L'\0'); ((charbuf_t *)cbp)->cb_pos--; return string_value(cbp->cb_buf); }
static char * make_col_name(const struct key_t *k) { const struct col_t *pc; char **names, **s, *output; assert(k); assert(k->nkeys); assert(k->keys); s = names = calloc(k->nkeys, sizeof(char*)); for(pc=k->keys; pc < k->keys + k->nkeys; pc++) { *s++ = strdup(string_value(pc)); } output = join(k->nkeys, names, "/"); for(s=names; s < names + k->nkeys; s++) { free(*s); } free(names); return output; }
obj_t *env_lookup(env_t *env, obj_t *var) { /* * for frame in env: * for binding in frame: * if binding.name == var: * return binding * assert False, 'unbound variable' */ assert(is_symbol(var)); #if ENV_TRACE printf_unchecked("lookup(%ls, %O)\n", string_value(symbol_name(var)), env); #endif while (!is_null(env)) { obj_t *frame = pair_car(env); #if ENV_TRACE if (pair_cdr(env)) { printf(" FRAME"); obj_t *p = frame; while (!is_null(p)) { printf_unchecked(" %O: %O", binding_name(pair_car(p)), binding_value(pair_car(p))); p = pair_cdr(p); } printf("\n"); } else { printf(" FRAME [builtins]\n"); } #endif while (!is_null(frame)) { obj_t *binding = pair_car(frame); assert(is_binding(binding)); if (binding_name(binding) == var) { #if ENV_TRACE printf(" found\n\n"); #endif return binding; } frame = pair_cdr(frame); } env = pair_cdr(env); } fprintf(stderr, "unbound variable \"%ls\"\n", string_value(symbol_name(var))); assert(false && "unbound variable"); }
void charbuf_append_char(charbuf_t *cbp, wchar_t wc) { if (cbp->cb_len == cbp->cb_pos) { cbp->cb_len *= 2; obj_t tmp = make_string_fill(cbp->cb_len, L'\0'); string_set_substring(tmp, 0, cbp->cb_pos, string_value(cbp->cb_buf)); cbp->cb_buf = tmp; } string_set_char_nc(cbp->cb_buf, cbp->cb_pos++, wc); }
static int sock_handle_write (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, THREAD *gsl_thread) { RESULT_NODE *buffer = argc > 0 ? argv [0] : NULL; RESULT_NODE *timeout = argc > 1 ? argv [1] : NULL; RESULT_NODE *error = argc > 2 ? argv [2] : NULL; if (! buffer) { strcpy (object_error, "Missing argument: buffer"); return -1; } if (buffer-> value. type == TYPE_UNDEFINED) { result-> culprit = buffer-> culprit; buffer-> culprit = NULL; lsend_ggcode_call_ok (& gsl_thread-> queue-> qid, NULL, NULL, NULL, NULL, 0); return 0; } { SOCK_HANDLE_ITEM *socket = item; THREAD *thread; if (start_socket_agent ()) return -1; thread = thread_create (AGENT_NAME, ""); tcb = thread-> tcb; tcb-> gsl_thread = gsl_thread; tcb-> result = result; tcb-> buffer = NULL; tcb-> error = error; tcb-> sock_handle = socket; tcb-> context = NULL; tcb-> handle = 0; lsend_smtsock_writeh (& sockq-> qid, & thread-> queue-> qid, NULL, NULL, NULL, 0, (word) (timeout ? number_value (& timeout-> value) : 0), socket-> handle, (qbyte) strlen (string_value (& buffer-> value)), (byte *) buffer-> value. s, TRUE, 0); return 0; } return 0; /* Just in case */ }
static cv_t default_handler(obj_t cont, obj_t values) { /* * For all non-message-irritants-who conditions, * print the condition's class. * For all message conditions, print the condition's message. * If who or irritants given, print (cons who irritants). */ assert(is_cont(cont)); EVAL_LOG("cont=%O values=%O", cont, values); obj_t ex = CAR(values); obj_t parts = record_get_field(ex, 0); const char *psn = program_short_name(); size_t psnl = strlen(psn); size_t i, size = vector_len(parts); for (i = 0; i < size; i++) { obj_t rtd = record_rtd(vector_ref(parts, i)); if (rtd != message && rtd != irritants && rtd != who) { ofprintf(stderr, "%*s: %O\n", (int)psnl, psn, rtd_name(rtd)); psn = ""; } } obj_t who_p = FALSE_OBJ; obj_t irr_p = make_uninitialized(); for (i = 0; i < size; i++) { obj_t p = vector_ref(parts, i); obj_t rtd = record_rtd(p); if (rtd == message) { obj_t msg = record_get_field(p, 0); const wchar_t *chars = string_value(msg); fprintf(stderr, "%*s %ls\n", (int)psnl, psn, chars); psn = ""; } else if (rtd == who) who_p = record_get_field(p, 0); else if (rtd == irritants) irr_p = record_get_field(p, 0); } if (who_p != FALSE_OBJ && !is_uninitialized(irr_p)) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, CONS(who_p, irr_p)); psn = ""; } else if (who_p != FALSE_OBJ) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, who_p); psn = ""; } else if (!is_uninitialized(irr_p)) { ofprintf(stderr, "%*s %O\n", (int)psnl, psn, irr_p); psn = ""; } if (*psn) fprintf(stderr, "%s: unknown exception\n", psn); ofprintf(stderr, "\n"); return cv(EMPTY_LIST, CONS(make_uninitialized(), EMPTY_LIST)); }
double name_value_pairs::numeric_value(std::string const& key) const { double z = 0.0; std::string s(string_value(key)); std::string::size_type last_nonblank = s.find_last_not_of(' '); s.resize(++last_nonblank); if(!s.empty()) { z = numeric_io_cast<double>(s); } return z; }
Json SqliteStore::get(const string& key) { auto& stmt = m_select; stmt->reset(); stmt->bind(1, key); auto query = stmt->exec_query(); if (query.is_valid()) { string value = query.string_value(0); string error; return Json::parse(value, error); } else { return nullptr; } }
struct ast* eval_class_native_method(struct method_call_node* m){ if (m != NULL) { // new if (!strcmp(m->method_name, NEW)) { //creo objeto struct class* class_ptr = find_class(string_value(m->left_ast)); struct sym* sym_list = copy_instance_variables_for_class(class_ptr); struct ast* new_object = new_object_node(class_ptr, sym_list); struct sym* s = find_method_for_class(string_value(m->left_ast), "initialize"); // initialize está definido if (s != NULL) { // llamo a initialize sobre el objeto eval_and_push_args_and_object_info(s->args, m->args, new_object); struct ast* eval = eval_ast(s->ast); //eval initialize update_instance(new_object); //Antes de hacer pop, salvo en la instancia los cambios en sus variables de instancia pop_scope(); // pop del scope pusheado }; return new_object; }; }; };
struct ast* reach(struct ast* a, struct ast* block) { if (a->node_type == N_ARRAY) { if (block != NULL) { struct ast* arr = (struct ast*) a->left; struct opt_block_node* b = (struct opt_block_node*) block; // obtengo arreglo a partir de Array int arr_size = array_tree_size(arr); struct ast* result[arr_size]; struct ast* ptr = arr; int i; for (i = (arr_size - 1); i > -1; i--) { result[i] = ptr->left; ptr = ptr->right; }; // itero sobre array for (i = 0; i < arr_size; i++) { push_scope(); // put first arg to scope if (b->opt_ids != NULL) { put_sym(SYM_VAR, string_value(b->opt_ids->arg), result[i], NULL); }; // eval block stmts eval_ast(b->stmts); pop_scope(); }; return a; } else { block_is_required_error(EACH_ITERATOR); }; } else { no_method_error(EACH_ITERATOR, a); }; };
void display(LISP_OBJ_PTR objp) { switch (objp->form) { case INT_FORM: fprintf(out_stream, "%d", int_value(objp)); break; case FLOAT_FORM: fprintf(out_stream, "%g", float_value(objp)); break; case CHAR_FORM: fprintf(out_stream, "%c", char_value(objp)); break; case STRING_FORM: fprintf(out_stream, "%s", string_value(objp)); break; case SYMBOL_FORM: fprintf(out_stream, "%s", symbol_value(objp)); break; case PROCEDURE_FORM: fprintf(out_stream, "<PROCEDURE>"); break; case BOOLEAN_FORM: fprintf(out_stream, "#%c", bool_value(objp) ? 't' : 'f'); break; case CONS_FORM: fprintf(out_stream, "("); while (TRUE) { print_lispobj(car(objp)); objp = cdr(objp); if (objp == nil_ptr) break; if (!(is_pair(objp))) { printf(" . "); print_lispobj(objp); break; } fprintf(out_stream, " "); } fprintf(out_stream, ")"); break; case NO_FORM: fprintf(out_stream, "no form, boss"); break; default: fprintf(out_stream, "dunno that form %d", form(objp)); } }
bool createTXTRecord(scopedTXTRecord& txtRecord, Local<Object>& object) { HandleScope scope; Local<Array> names = object->GetPropertyNames(); uint32_t length = names->Length(); for (uint32_t index = 0; index<length; ++index) { Local<Value> key = names->Get(index); if (key->IsString()) { // Local<Value> buffer = object->Get(key); Handle<Value> buffer = object->Get(key); String::Utf8Value string_value( buffer->ToString()); // A DNS-SD key is 7-bit ascii String::AsciiValue keyString(key); std::string buf(*keyString, keyString.length()); /* Local<Object> obj; uint8_t valLen = 0; const void *value = NULL; if (Buffer::HasInstance(buffer)) { obj = buffer->ToObject(); valLen = Buffer::Length(obj); value = Buffer::Data(obj); } if (txtRecord.setValue(buf.c_str(), valLen, value) != kDNSServiceErr_NoError) { return false; } */ if (txtRecord.setValue(buf.c_str(), buffer->ToString()->Utf8Length(), *string_value) != kDNSServiceErr_NoError) { return false; } } else { return false; } } return true; }
object io_file_as_port(object filename, unsigned long port_type) { char *name; unsigned long namelen; FILE *f; namelen = string_length(filename); name = xmalloc(namelen + 1); memcpy(name, string_value(filename), namelen); name[namelen] = 0; if ((f = fopen(name, (port_type == PORT_TYPE_INPUT) ? "r" : "w+")) == NULL) { xfree(name); error("Cannot open file -- io-file-as-port", filename); } xfree(name); return make_port(f, port_type); }
static pointer plugin_function(scheme *sc, pointer args) { printf("this is a plugin!\n"); /* first argument is an integer */ long i = ivalue(car(args)); printf("the first argument is %d\n", i); /* pop first argument using cdr */ args = cdr(args); /* second argument is a string */ char *str = string_value(car(args)); printf("the second argument is %s\n", str); /* pop the argument */ args = cdr(args); /* second argument is a float*/ SPFLOAT flt = rvalue(car(args)); printf("the third argument is %g\n", flt); /* return a float */ return mk_real(sc, 0.2468); }
TEST(EventToStringTest, ScalarType) { IntValue int_value(-42); std::string int_str; EXPECT_TRUE(ToString(&int_value, &int_str)); EXPECT_STREQ("-42", int_str.c_str()); UIntValue uint_value(42); std::string uint_str; EXPECT_TRUE(ToString(&uint_value, &uint_str)); EXPECT_STREQ("42", uint_str.c_str()); LongValue long_value(-42); std::string long_str; EXPECT_TRUE(ToString(&long_value, &long_str)); EXPECT_STREQ("-42", long_str.c_str()); ULongValue ulong_value(42); std::string ulong_str; EXPECT_TRUE(ToString(&ulong_value, &ulong_str)); EXPECT_STREQ("42", ulong_str.c_str()); FloatValue float_value(.5); std::string float_str; EXPECT_TRUE(ToString(&float_value, &float_str)); EXPECT_STREQ("0.5", float_str.c_str()); DoubleValue double_value(.25); std::string double_str; EXPECT_TRUE(ToString(&double_value, &double_str)); EXPECT_STREQ("0.25", double_str.c_str()); StringValue string_value("dummy"); std::string string_str; EXPECT_TRUE(ToString(&string_value, &string_str)); EXPECT_STREQ("\"dummy\"", string_str.c_str()); }
char * name_the_symbol (RESULT_NODE *node) { char *scope_string = "", *point_string = ""; if (node-> scope) scope_string = extended_scope_string (node-> scope); /* Print point if scope & name or neither scope nor name is defined. */ if ((node-> scope != NULL) == (node-> name != NULL)) point_string = "."; snprintf (error_buffer, LINE_MAX, "%s%s%s", scope_string, point_string, node-> name ? string_value (& node-> name-> value) : ""); return error_buffer; }