int main(int argc, char *argv[]) { log_t *log; log = open_log(_T("-"), _T("json")); if(log == NULL) { puts("Failed."); } open_section(log, _T("compile")); open_item(log); add_value(log, _T("date"), _T(__DATE__)); add_value(log, _T("time"), _T(__TIME__)); close_item(log); open_item(log); add_value(log, _T("file"), _T(__FILE__)); add_value(log, _T("timestamp"), _T(__TIMESTAMP__)); close_item(log); close_section(log); open_section(log, _T("test")); open_item(log); add_value(log, _T("test"), _T("field")); close_item(log); close_section(log); close_log(log); return 0; }
void argtype_t::parse(Tokenizer *tz) { this->name = tz->get_token(); tz->check_token("{"); string token = tz->get_token(); while (token != "}") { if (token == "value") { short val = tz->get_integer(); string nname = tz->get_token(); add_value(nname, val, false); } if (token == "flag") { short val = tz->get_integer(); string nname = tz->get_token(); add_value(nname, val, true); } token = tz->get_token(); } //log_message("Arg type %s parsed\n", this->name.c_str()); }
// Sends the HMDP request 'List' // @param sockfd the socket descriptor of the server // @param token the token used for verification // @param list the list of files found in the clients hooli directory void request_list(int sockfd, char *token, csv_record *list) { char *request; // The 'List' message char *list_size; // The size of the list of files and checksums int length; // The length of the 'List' message asprintf(&list_size, "%d", get_list_size(list)); add_command(&request, COMMAND_LIST); // |-----------------| add_key(&request, KEY_TOKEN); // |List\n | add_value(&request, token); // |-----------------| add_key(&request, KEY_LENGTH); // |Token:value\n | add_value(&request, list_size); // |-----------------| delimit_header(&request); // |Length:value\n\n | add_body(&request, list); // |-----------------| // |Body: | // |-----------------| length = strlen(request); // Check to see if the message sent successfully if (send_all(sockfd, request, &length) == -1) { syslog(LOG_ERR, "Only sent %d bytes\n", length); } //end if free(list_size); free(request); list_size = NULL; request = NULL; } //end request_list
// Sends the HMDP request 'Auth' // @param sockfd the socket descriptor of the server // @param username the username of the client // @param password the password of the client void request_auth(int sockfd, char *username, char *password) { char *request; // The 'Auth' message int length; // The length of the 'Auth' message add_command(&request, COMMAND_AUTH); // |-------------------| add_key(&request, KEY_USERNAME); // |Auth\n | add_value(&request, username); // |-------------------| add_key(&request, KEY_PASSWORD); // |Username:value\n | add_value(&request, password); // |-------------------| delimit_header(&request); // |Password:value\n\n | // |-------------------| length = strlen(request); // Check to see if the message sent successfully if (send_all(sockfd, request, &length) == -1) { syslog(LOG_ERR, "Only sent %d bytes\n", length); } //end if free(request); request = NULL; } //end request_auth
void make_adjustments(int col, int row1, int row2, int n, int k, int* object, int* cv, int old_k, int* old_object, int* old_cv, int* missing, int* idx_mat) { int h = n*n; remove_value(col, row1, n, k, object, old_k, cv, missing, idx_mat); remove_value(col, row2, n, k, object, old_k, cv, missing, idx_mat); old_remove_value(col, row1, n, k, object, old_k, old_object, old_cv, missing); old_remove_value(col, row2, n, k, object, old_k, old_object, old_cv, missing); add_value(object[col*h+row2], col, row1, n, k, object, old_k, cv, missing, idx_mat); add_value(object[col*h+row1], col, row2, n, k, object, old_k, cv, missing, idx_mat); old_add_value(object[col*h+row2], col, row1, n, k, object, old_k, old_object, old_cv, missing); old_add_value(object[col*h+row1], col, row2, n, k, object, old_k, old_object, old_cv, missing); }
static void read_word(ParseInfo pi) { char c; bool reading = true; ojc_reader_backup(&pi->rd); ojc_reader_protect(&pi->rd); while (reading) { c = ojc_reader_get(&pi->err, &pi->rd); switch (c) { case ',': case ']': case '}': case ' ': case '\t': case '\f': case '\n': case '\r': ojc_reader_backup(&pi->rd); reading = false; break; case '\0': reading = false; break; default: break; } } if (16 <= pi->rd.tail - pi->rd.start) { // TBD sizeof _Str.ca if ('\0' == c) { ojc_set_error_at(pi, OJC_INCOMPLETE_ERR, __FILE__, __LINE__, "invalid token"); } else { ojc_set_error_at(pi, OJC_PARSE_ERR, __FILE__, __LINE__, "invalid token"); } } else if (0 == strncmp("true", pi->rd.start, 4)) { add_value(pi, get_val(pi, OJC_TRUE)); } else if (0 == strncmp("false", pi->rd.start, 5)) { add_value(pi, get_val(pi, OJC_FALSE)); } else if (0 == strncmp("null", pi->rd.start, 4)) { add_value(pi, get_val(pi, OJC_NULL)); } else if (ojc_word_ok) { add_word(pi, pi->rd.start, pi->rd.tail - pi->rd.start); } else { if ('\0' == c) { ojc_set_error_at(pi, OJC_INCOMPLETE_ERR, __FILE__, __LINE__, "invalid token"); } else { ojc_set_error_at(pi, OJC_PARSE_ERR, __FILE__, __LINE__, "invalid token"); } } ojc_reader_release(&pi->rd); }
void random_updater::add_column_to_sets(unsigned j) { if (m_core_solver.m_r_heading[j] < 0) { m_var_set.insert(j); add_value(m_core_solver.m_r_x[j]); } else { unsigned row = m_core_solver.m_r_heading[j]; for (auto row_c : m_core_solver.m_r_A.m_rows[row]) { unsigned cj = row_c.m_j; if (m_core_solver.m_r_heading[cj] < 0) { m_var_set.insert(cj); add_value(m_core_solver.m_r_x[cj]); } } } }
// Sends the HMDP response '200' // @param connectionfd the socket descriptor of the client // @param token the verification token for the client void response_200(int connectionfd, char *token) { char *response; // The '200' message int length; // The length of the message add_status(&response, STATUS_200); // |--------------------------------| add_message(&response, MESSAGE_200); // |200 Authentication Successful\n | add_key(&response, KEY_TOKEN); // |--------------------------------| add_value(&response, token); // |Token:value\n\n | delimit_header(&response); // |--------------------------------| length = strlen(response); // Check to see if the message sent successfully if (send_all(connectionfd, response, &length) == -1) { syslog(LOG_ERR, "Only sent %d bytes\n", length); } //end if free(response); response = NULL; } //end response_200
static void object_start(ParseInfo pi) { ojcVal obj = get_val(pi, OJC_OBJECT); add_value(pi, obj); stack_push(&pi->stack, obj); }
void config_set_value(struct config *c, const char *section, const char *name, const char *value) { add_value(section, name, value, c); }
int main(int argc, const char **argv) { float *inputs; int i, error; memory_t memory; cache_t cache; membase_t *p_mem; float_heap heap; /* Set up the simulated memory. */ p_mem = make_cached_memory(argc, argv, NUM_ELEMS * sizeof(int)); /* Generate random floats to sort. */ printf("Generating %d random floats to sort.\n", NUM_ELEMS); inputs = malloc(NUM_ELEMS * sizeof(float)); srand48(SEED); for (i = 0; i < NUM_ELEMS; i++) inputs[i] = (float) drand48(); /* Use the heap to sort the sequence of floats. */ printf("Sorting numbers using the heap.\n"); init_heap(&heap, p_mem, NUM_ELEMS); for (i = 0; i < NUM_ELEMS; i++) add_value(&heap, inputs[i]); /* Sort the inputs so that we can check the heap's results. */ printf("Checking the results against the sorted inputs.\n"); qsort(inputs, NUM_ELEMS, sizeof(float), compare_float_ptrs); error = 0; for (i = 0; i < NUM_ELEMS; i++) { float val = get_first_value(&heap); if (val != inputs[i]) { printf("ERROR: heap and sorted array don't match at " "index %d! heap = %f, val = %f\n", i, val, inputs[i]); error = 1; } } if (error) { printf("Some values didn't match, aborting.\n"); abort(); } /* Print out the results of the heap sort. */ printf("\nMemory-Access Statistics:\n\n"); p_mem->print_stats(p_mem); printf("\n"); return 0; }
static int str_gsub (lua_State *L) { size_t srcl; const char *src = luaL_checklstring(L, 1, &srcl); const char *p = luaL_checkstring(L, 2); int max_s = luaL_optint(L, 4, srcl+1); int anchor = (*p == '^') ? (p++, 1) : 0; int n = 0; MatchState ms; luaL_Buffer b; luaL_buffinit(L, &b); ms.L = L; ms.src_init = src; ms.src_end = src+srcl; while (n < max_s) { const char *e; ms.level = 0; e = match(&ms, src, p); if (e) { n++; add_value(&ms, &b, src, e); } if (e && e>src) /* non empty match? */ src = e; /* skip it */ else if (src < ms.src_end) luaL_addchar(&b, *src++); else break; if (anchor) break; } luaL_addlstring(&b, src, ms.src_end-src); luaL_pushresult(&b); lua_pushinteger(L, n); /* number of substitutions */ return 2; }
/* in : - examples is same than above - n_ex is explicit - attribute is the attribute which is discretized - index is the index of the attrbiute in the examples values out : - nothing */ void discretize_attribute(struct example_t *examples, int n_ex, struct attribute_t *attribute) { int i; double first_value = -INFINITE, last_value, tmp; string tmp_label, tmp_value = ""; qsort((void *)examples, n_ex, sizeof(*examples), compare_int_strings); strcpy(tmp_label, examples[0].property); get_double_from_string(examples[0].tab_values[index_to_discretize], &last_value); for(i = 1; i < n_ex; ++i) { if(strcmp(examples[i].property, tmp_label) != 0) { if(first_value != -INFINITE) sprintf(tmp_value, "%s %f", HIGHER, first_value); get_double_from_string(examples[i].tab_values[index_to_discretize], &tmp); sprintf(tmp_value, "%s %s %f", tmp_value, LESS_OR_EQUAL, (last_value + tmp)/2.); add_value(attribute, tmp_value); get_double_from_string(examples[i].tab_values[index_to_discretize], &first_value); strcpy(tmp_label, examples[i].property); } else { get_double_from_string(examples[i].tab_values[index_to_discretize], &last_value); } } }
Element:: Element (::XSCRT::XML::Element< wchar_t > const& e) :Base (e), regulator__ () { ::XSCRT::Parser< wchar_t > p (e); while (p.more_elements ()) { ::XSCRT::XML::Element< wchar_t > e (p.next_element ()); ::std::basic_string< wchar_t > n (::XSCRT::XML::uq_name (e.name ())); if (n == L"value") { ::XMLSchema::string< wchar_t >::_ptr t (new ::XMLSchema::string< wchar_t > (e)); add_value (t); } else if (n == L"long") { ::XMLSchema::long_::_ptr t (new ::XMLSchema::long_ (e)); add_long (t); } else if (n == L"el") { ::Recursive::Element::_ptr t (new ::Recursive::Element (e)); add_el (t); } else { } } }
// Sends the HMDP response '302' // @param connectionfd the socket descriptor of the client // @param response_list the list of files for the client to upload void response_302(int connectionfd, csv_record *response_list) { char *response; // The '302' message char *list_size; // The size of the body of the message int length; // The length of the message asprintf(&list_size, "%d", get_list_size(response_list)); add_status(&response, STATUS_302); // |----------------------| add_message(&response, MESSAGE_302); // |302 Files requested\n | add_key(&response, KEY_LENGTH); // |----------------------| add_value(&response, list_size); // |Length:value\n\n | delimit_header(&response); // |----------------------| add_body(&response, response_list); // |Body: | // |----------------------| length = strlen(response); // Check to see if the message sent successfully if (send_all(connectionfd, response, &length) == -1) { syslog(LOG_ERR, "Only sent %d bytes\n", length); } //end if free(list_size); free(response); list_size = NULL; response = NULL; } //end response_302
static void array_start(ParseInfo pi) { ojcVal array = get_val(pi, OJC_ARRAY); add_value(pi, array); stack_push(&pi->stack, array); }
static void read_false(ParseInfo pi) { if ('a' == *pi->cur++ && 'l' == *pi->cur++ && 's' == *pi->cur++ && 'e' == *pi->cur++) { add_value(pi, Qfalse); } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected false"); } }
static void read_true(ParseInfo pi) { if ('r' == *pi->cur++ && 'u' == *pi->cur++ && 'e' == *pi->cur++) { add_value(pi, Qtrue); } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected true"); } }
Argument( int argc, char** argv ) : CommandLine( argc, argv ) { add_help_option(); add_value( "kvs::PolygonObject file path.", true ); if( !this->parse() ) exit( EXIT_FAILURE ); }
static void read_null(ParseInfo pi) { if ('u' == *pi->cur++ && 'l' == *pi->cur++ && 'l' == *pi->cur++) { add_value(pi, Qnil); } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected null"); } }
static void read_false(ParseInfo pi) { if (0 == reader_expect(&pi->rd, "alse")) { add_value(pi, Qfalse); } else { oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected false"); } }
static gchar* do_get_action(IpcamIAjax *iajax, GList *item_list) { JsonBuilder *builder; JsonNode *res_node = NULL; GList *item; JsonGenerator *generator; builder = json_builder_new(); generator = json_generator_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_object(builder); for (item = g_list_first(item_list); item; item = g_list_next(item)) { const gchar *name = item->data; if (g_str_equal(name, "method")) { GVariant *value = NULL; value = ipcam_iajax_get_configuration(iajax, "network:method"); if (value) { add_value(builder, name, value); g_variant_unref(value); } } else if (g_str_equal(name, "address")) { do_get_action_address(iajax, builder); } else if (g_str_equal(name, "pppoe")) { do_get_action_pppoe(iajax, builder); } else if (g_str_equal(name, "port")) { do_get_action_port(iajax, builder); } else { g_warn_if_reached(); } } json_builder_end_object(builder); json_builder_end_object(builder); res_node = json_builder_get_root(builder); json_generator_set_root(generator, res_node); json_generator_set_pretty(generator, TRUE); gchar *result = json_generator_to_data(generator, NULL);; json_node_free(res_node); g_object_unref(G_OBJECT(builder)); g_object_unref(G_OBJECT(generator)); return result; }
Argument( int argc, char** argv ) : CommandLine ( argc, argv ) { add_help_option(); add_option( "f", "input filename", 1, false ); add_option( "b", "block size", 1, false ); add_option( "t", "transfer function", 1, false ); add_option( "rl", "repeat level", 1, false ); add_option( "s", "stochastic renderer", 1, false ); add_value( "hydrogen", false ); }
static bool on_number_value (void * userContext, const string & name, real_t v) { user_context * ctx = static_cast<user_context *>(userContext); if (v > 0) { // If v is unsigned integer if (static_cast<real_t>(static_cast<uintmax_t>(v)) == v) add_value(ctx, name, value(static_cast<uintmax_t>(v))); else add_value(ctx, name, value(v)); } else { // If v is signed integer if (static_cast<real_t>(static_cast<intmax_t>(v)) == v) add_value(ctx, name, value(static_cast<intmax_t>(v))); else add_value(ctx, name, value(v)); } return true; }
GCMarker* GarbageCollector::new_marker() { GCMarker* marker = freed->next; if(marker->colour != freed->colour) marker = new GCMarker(); allocated++; add_value(marker); return marker; }
Pulsar::IntegrationTI::IntegrationTI () { add( &Integration::get_nchan, "nchan", "Number of frequency channels" ); add( &Integration::get_npol, "npol", "Number of polarizations" ); add( &Integration::get_nbin, "nbin", "Number of pulse phase bins" ); add( &Integration::get_epoch, &Integration::set_epoch, "mjd", "Epoch (MJD)" ); add( &Integration::get_duration, &Integration::set_duration, "duration", "Integration length (s)" ); add( &Integration::get_folding_period, &Integration::set_folding_period, "period", "Folding period (s)" ); // note that explicit casts are required for overloaded methods VGenerator<double> dgenerator; add_value(dgenerator( "freq", "Channel centre frequency (MHz)", ( double (Integration::*) (unsigned) const ) &Integration::get_centre_frequency, &Integration::set_centre_frequency, &Integration::get_nchan )); VGenerator<float> fgenerator; add_value(fgenerator( "wt", "Channel weight", &Integration::get_weight, &Integration::set_weight, &Integration::get_nchan )); import( "point", Pulsar::Pointing::Interface(), &Integration::getadd<Pointing> ); import( "aux", Pulsar::AuxColdPlasmaMeasures::Interface(), &Integration::getadd<AuxColdPlasmaMeasures> ); }
JsonValue::JsonValuePtr Effect::get_info() const { auto info = JsonValue::create_object(); info->add_key_value("name", name()); info->add_key_value("start_time", (int32)_start_time); info->add_key_value("end_time", (int32)_end_time); auto params = JsonValue::create_array(); for (auto it = begin(_params); it != end(_params); ++it) { params->add_value((*it)->to_json()); } info->add_key_value("params", params); return info; }
PolizElem* PolizFunAssign::EvaluateFun(PolizItem **stack) const { PolizElem *operand1 = Pop(stack); PolizInt *i1 = dynamic_cast<PolizInt*>(operand1); if (!i1) throw PolizExNotInt(operand1); PolizElem *operand2 = Pop(stack); PolizVarAddr *i2 = dynamic_cast<PolizVarAddr*>(operand2); if (!i2) throw PolizExNotVarAddr(operand2); i2->set_value(i1->Get()); if (is_first_var(i2->Get()->name)) add_var(i2->Get()->name, i1->Get()); else add_value(i2->Get()->name, i1->Get()); return 0; }
char_buffer_st *lua_gsub(const char *src, size_t srcl, const char *p, size_t lp,const char *tr, size_t max_s, const char **error_ptr) { int anchor; size_t n; LuaMatchState ms; char_buffer_st *b; if(max_s == 0) max_s = srcl+1; anchor = (*p == '^'); n = NEW_SIZE(srcl); b = (char_buffer_st*)malloc(sizeof(char_buffer_st) + n); if(!b) return NULL; b->size = n; b->used = 0; n = 0; if (anchor) p++, lp--; // skip anchor character ms.error = 0; ms.src_init = src; ms.src_end = src+srcl; ms.p_end = p + lp; while (n < max_s) { const char *e; ms.level = 0; e = match(&ms, src, p); if(ms.error) goto free_and_null; if (e) { n++; if(!add_value(&ms, &b, src, e, tr)) goto free_and_null; } if (e && e>src) // non empty match? src = e; // skip it else if (src < ms.src_end){ if(!add_char(&ms, &b, *src++)) goto free_and_null; } else break; if (anchor) break; } if(!add_str(&ms, &b, src, ms.src_end-src)) goto free_and_null; b->buf[b->used] = '\0'; return b; free_and_null: if(b) free(b); if(error_ptr) *error_ptr = ms.error; return NULL; }
/*CREATE LIST OF TOKENS*/ void Createlist(char *exp,List infix_l) { char p[MAXNAME]; //store var name int cnt; while((*exp == ' ' || *exp == '\t') && *exp!='\0') //remove spaces exp++; if(*exp=='\'') //override check eval symbol. exp++; if(*exp == '\0') return; while(*exp!='\0') //read till end of line { while((*exp == ' ' || *exp == '\t') && *exp!='\0') exp++; if(match_char(*exp)==0) //if variable { exp = Extract_word(exp,p); cnt = Count(infix_l); InsertAfter(p,infix_l,cnt); } else if(match_num(*exp)==0) //if number { exp = Extract_num(exp,p); cnt = Count(infix_l); InsertAfter(p,infix_l,cnt); add_value(p,0,p); } else if(match_bool(*exp)==0) //if boolean op { exp = Extract_bool(exp,p); cnt = Count(infix_l); InsertAfter(p,infix_l,cnt); } else { p[0] = *exp; //else single letter operator p[1]='\0'; cnt = Count(infix_l); InsertAfter(p,infix_l,cnt); exp++; } } }