static bool find_module_file(const char* module_name, caValue* filenameOut) { Value module; set_string(&module, module_name); int count = list_length(&g_moduleSearchPaths); for (int i=0; i < count; i++) { // For each search path we'll check two places. // Look under searchPath/moduleName.ca Value searchPath; copy(g_moduleSearchPaths[i], &searchPath); circa_join_path(&searchPath, &module); string_append(&searchPath, ".ca"); if (circa_file_exists(as_cstring(&searchPath))) { swap(&searchPath, filenameOut); return true; } // Look under searchPath/moduleName/moduleName.ca copy(g_moduleSearchPaths[i], &searchPath); circa_join_path(&searchPath, &module); circa_join_path(&searchPath, &module); string_append(&searchPath, ".ca"); if (circa_file_exists(as_cstring(&searchPath))) { swap(&searchPath, filenameOut); return true; } } return false; }
void cmd_write (uint64_t cluster, uint8_t adcport, uint64_t maxsize, uint8_t speed) { uart_puts_P("Writing...\r\n"); uint16_t maxblocks = maxsize / 512; uint16_t block = 0; char c = 0x00; while(c != 'q') { char values[512] = {0x00}; for (uint16_t i = 0; i<=80; ++i) { adc_request(adcport); uint16_t adcvalue = adc_read(); string_append(values, num2str(adcvalue, 10)); string_append(values, "\r\n"); for (uint8_t d = 0; d<=speed; ++d) _delay_ms(3); uart_puts(num2str(i, 10)); uart_puts(": "); uart_puts(num2str(adcvalue, 10)); uart_puts("\r\n"); c = uart_getc(); if (c == 'q') break; } fat_write_file(cluster, (unsigned char*)values, block); ++block; if (block >= maxblocks) break; } uart_puts_P("...done\r\n"); }
void inicializar_panel(t_tipo_proceso tipo_proceso, char* path){ char* tipo_proceso_str; if (tipo_proceso == KERNEL) tipo_proceso_str = "kernel"; else if (tipo_proceso == CPU) tipo_proceso_str = "cpu"; else tipo_proceso_str = "?"; proceso_tipo = tipo_proceso; char* logFile = string_duplicate(path); string_append(&logFile, tipo_proceso_str); string_append(&logFile, ".log"); remove(logFile); logger = log_create(logFile, tipo_proceso_str, true, LOG_LEVEL_INFO); log_info(logger, "Inicializando panel para %s, en \"%s\"", tipo_proceso_str, logFile); free(logFile); kernel_cpus_conectadas = list_create(); kernel_consolas_conectadas = list_create(); }
static void build_signature(struct signctx *senv, const char *method, const char *consumerSecret, const char *tokenSecret) { struct signature_param *sp; const size_t nParams = vector_size(&senv->signatureParams); uint32_t i; uint8_t digest[20]; qsort(vector_values(&senv->signatureParams), vector_size(&senv->signatureParams), senv->signatureParams.item_size, bySignatureParamName); string_append(&senv->signatureSeed, "&", 1); if (nParams) { i = 0; do { sp = (struct signature_param *)vector_value(&senv->signatureParams, i); string_appendfmt(&senv->signatureSeed, "%s%%3D", sp->name); string_append_urlencoded_rfc3986(&senv->signatureSeed, sp->value, sp->len); string_append(&senv->signatureSeed, "%26", 3); } while (++i != nParams); string_adjustlen(&senv->signatureSeed, 3); } char _k[256]; const size_t keyLen = sprintf(_k, "%s&%s", consumerSecret, tokenSecret); string_reset(&senv->signatureParamsBuf); hmac((uint8_t *)_k, keyLen, (uint8_t *)string_data(&senv->signatureSeed), string_len(&senv->signatureSeed), digest); base64_encode(digest, 20, &senv->signatureParamsBuf, 0); }
void logearOrdenReduce(char* nombre){ t_log_level nivel; t_log* archivoDeLog; nivel = LOG_LEVEL_INFO; archivoDeLog = log_create("LogNodo", "Nodo", 0, nivel); char *unaPalabra = string_new(); string_append(&unaPalabra, "Solicitud de Reduce con el script "); string_append(&unaPalabra, nombre); log_info(archivoDeLog,unaPalabra); free(unaPalabra); log_destroy(archivoDeLog); }
//Devuelve un num positivo o Devuelve 0 si hay error int getCantidadDeCopiasDe1Bloque_ArchivoDB(const bson_t * documento_X, int numBloque) { bson_iter_t punteroDeBusqueda; bson_iter_t valorEncontrado; int CantidadDeCopias = 0; char *claveGenerada = string_new(); string_append(&claveGenerada, "Bloques"); string_append(&claveGenerada, "."); string_append(&claveGenerada, string_itoa(numBloque)); string_append(&claveGenerada, "."); string_append(&claveGenerada, "cantidadDeCopias"); if (documento_X != NULL && bson_iter_init (&punteroDeBusqueda, documento_X) && bson_iter_find_descendant (&punteroDeBusqueda, claveGenerada, &valorEncontrado) && BSON_ITER_HOLDS_INT32 (&valorEncontrado)) { CantidadDeCopias = bson_iter_int32 (&valorEncontrado); } free(claveGenerada); return CantidadDeCopias; }
static void import_base_rule( void * r_, void * d_ ) { RULE * r = (RULE *)r_; RULE * ir1; RULE * ir2; struct import_base_data * d = (struct import_base_data *)d_; string qualified_name[ 1 ]; OBJECT * qname; string_new ( qualified_name ); string_append ( qualified_name, object_str( d->base_name ) ); string_push_back( qualified_name, '.' ); string_append ( qualified_name, object_str( r->name ) ); qname = object_new( qualified_name->value ); ir1 = import_rule( r, d->class_module, r->name ); ir2 = import_rule( r, d->class_module, qname ); object_free( qname ); /* Copy 'exported' flag. */ ir1->exported = ir2->exported = r->exported; /* If we are importing a class method, localize it. */ if ( ( r->module == d->base_module ) || ( r->module->class_module && ( r->module->class_module == d->base_module ) ) ) { rule_localize( ir1, d->class_module ); rule_localize( ir2, d->class_module ); } string_free( qualified_name ); }
caValue* selector_advance(caValue* value, caValue* selectorElement, caValue* error) { if (is_int(selectorElement)) { int selectorIndex = as_int(selectorElement); if (!is_list(value)) { set_error_string(error, "Value is not indexable: "); string_append_quoted(error, value); return NULL; } if (selectorIndex >= list_length(value)) { set_error_string(error, "Index "); string_append(error, selectorIndex); string_append(error, " is out of range"); return NULL; } return get_index(value, selectorIndex); } else if (is_string(selectorElement)) { caValue* field = get_field(value, as_cstring(selectorElement)); if (field == NULL) { set_error_string(error, "Field not found: "); string_append(error, selectorElement); return NULL; } return field; } else { set_error_string(error, "Unrecognized selector element: "); string_append_quoted(error, selectorElement); return NULL; } }
void join_path(Value* left, Value* right) { const char* leftStr = as_cstring(left); const char* rightStr = as_cstring(right); int left_len = (int) strlen(leftStr); int right_len = (int) strlen(leftStr); if (string_equals(left, "") || string_equals(left, ".")) { copy(right, left); return; } if (string_equals(right, "")) return; int seperatorCount = 0; if (left_len > 0 && is_path_seperator(leftStr[left_len-1])) seperatorCount++; if (right_len > 0 && is_path_seperator(rightStr[0])) seperatorCount++; if (seperatorCount == 2) string_resize(left, left_len - 1); else if (seperatorCount == 0) string_append(left, "/"); string_append(left, right); }
void get_path_relative_to_source(caBlock* relativeTo, Value* relPath, Value* result) { if (relativeTo == NULL) { copy(relPath, result); return; } // Don't modify absolute paths if (is_absolute_path(relPath)) { copy(relPath, result); return; } Value scriptLocation; get_source_file_location(relativeTo, &scriptLocation); if (string_equals(&scriptLocation, "") || string_equals(&scriptLocation, ".")) { set_value(result, relPath); return; } set_value(result, &scriptLocation); if (!string_equals(relPath,"")) { string_append(result, "/"); string_append(result, relPath); } }
void imprimirLista(char* nivel, t_list* rdy, t_list* blk, int cont) { char* tmp = malloc(20); char* retorno = malloc(500); int i; personaje_t* levantador; if (list_size(rdy) == 0 || cont < 0) { //Si no hay nadie listo, no se quien esta ejecutando sprintf(retorno, "Lista de: %s\n\tEjecutando:\n\tListos: \t", nivel); } else { levantador = list_get(rdy, cont); sprintf(retorno, "Lista de: %s\n\tEjecutando: %c\n\tListos: \t", nivel, levantador->name); } for (i = 0; i < list_size(rdy); i++) { levantador = list_get(rdy, i); sprintf(tmp, "%c -> ", levantador->name); string_append(&retorno, tmp); } sprintf(tmp, "\n\tBloqueados: \t"); string_append(&retorno, tmp); for (i = 0; i < list_size(blk); i++) { levantador = list_get(blk, i); sprintf(tmp, "%c -> ", levantador->name); string_append(&retorno, tmp); } log_info(logger, retorno); free(tmp); free(retorno); }
/* * Join tokens in a given list. If sep is true, a space is put * between tokens. If false, no separator. */ static String *join_tokens(List *arg, bool sep) { String *s = make_string(); for (int i = 0; i < LIST_LEN(arg); i++) { Token *tok = LIST_REF(arg, i); if (sep && STRING_LEN(s) && tok->space) o1(s, ' '); switch (tok->toktype) { case TOKTYPE_IDENT: case TOKTYPE_CPPNUM: string_append(s, STRING_BODY(tok->val.str)); break; case TOKTYPE_PUNCT: string_append(s, token_to_string(tok)); break; case TOKTYPE_CHAR: { // TODO: retain original spelling o1(s, '\''); stringize_char(s, tok->val.i, '\''); string_append(s, "\'"); break; } case TOKTYPE_STRING: { o1(s, '"'); for (char *p = STRING_BODY(tok->val.str); *p; p++) stringize_char(s, *p, '\"'); string_append(s, "\""); break; } default: panic("invalid token type: %d", tok->toktype); } } return s; }
static String* create_json(String* content, Project* project, Message* message, List* elements, List* element_types) { Iterator* it; String* base_url_a = string_new(); base_url_a = get_base_url(base_url_a); string_appendf(content, "{project:{name: \"%s\"}, ticket:{id: %d, url: \"%s/%s/ticket/%d\",fields:[", string_rawstr(project->name), message->id, string_rawstr(base_url_a), g_project_code_4_url, message->id); string_free(base_url_a); foreach (it, element_types) { ElementType* et = it->element; String* field_a = string_new(); String* name_a = string_new(); String* value_a = string_new(); string_append(name_a, string_rawstr(et->name)); escape_quot(name_a); string_append(value_a, get_element_value(elements, et)); escape_quot(value_a); string_appendf(field_a, "{name:\"%s\", value:\"%s\"}", string_rawstr(name_a), string_rawstr(value_a)); string_free(name_a); string_free(value_a); string_append(content, string_rawstr(field_a)); string_free(field_a); if (iterator_next(it)) string_append(content, ","); }
char * posicionToString(t_posicion * posicion){ char * pos = string_new(); string_append(&pos, string_from_format("%d",posicion->posX)); string_append(&pos, ","); string_append(&pos, string_from_format("%d",posicion->posY)); return pos; }
void nerr_error_traceback (NEOERR *err, NEOSTRING *str) { NEOERR *more; char buf[1024]; char buf2[1024]; char *err_name; if (err == STATUS_OK) return; if (err == INTERNAL_ERR) { string_append (str, "Internal error"); return; } more = err; string_append (str, "Traceback (innermost last):\n"); while (more && more != INTERNAL_ERR) { err = more; more = err->next; if (err->error != NERR_PASS) { NEOERR *r; if (err->error == 0) { err_name = buf; snprintf (buf, sizeof (buf), "Unknown Error"); } else { r = uListGet (Errors, err->error - 1, (void *)&err_name); if (r != STATUS_OK) { err_name = buf; snprintf (buf, sizeof (buf), "Error %d", err->error); } } snprintf (buf2, sizeof(buf2), " File \"%s\", line %d, in %s()\n%s: %s\n", err->file, err->lineno, err->func, err_name, err->desc); string_append(str, buf2); } else { snprintf (buf2, sizeof(buf2), " File \"%s\", line %d, in %s()\n", err->file, err->lineno, err->func); string_append(str, buf2); if (err->desc[0]) { snprintf (buf2, sizeof(buf2), " %s\n", err->desc); string_append(str, buf2); } } } }
app_action_t application_function_flash_receive(string_t *src, string_t *dst) { unsigned int chunk_offset, chunk_length; if(string_size(&flash_sector_buffer) < SPI_FLASH_SEC_SIZE) { string_format(dst, "ERROR flash-receive: flash sector buffer too small: %d\n", string_size(&flash_sector_buffer)); return(app_action_error); } if(parse_uint(1, src, &chunk_offset, 0, ' ') != parse_ok) { string_append(dst, "ERROR flash-receive: chunk offset required\n"); return(app_action_error); } if(parse_uint(2, src, &chunk_length, 0, ' ') != parse_ok) { string_append(dst, "ERROR flash-receive: chunk chunk_length required\n"); return(app_action_error); } if((chunk_length == 0) || ((chunk_offset % chunk_length) != 0)) { string_append(dst, "ERROR: flash-receive: chunk offset should be divisible by chunk size"); return(app_action_error); } if((chunk_length == 0) || ((SPI_FLASH_SEC_SIZE % chunk_length) != 0)) { string_append(dst, "ERROR: flash-receive: chunk length should be divisible by flash sector size"); return(app_action_error); } if((chunk_offset + chunk_length) > SPI_FLASH_SEC_SIZE) { string_format(dst, "ERROR flash-receive: chunk_length(%u) + chunk_offset(%u) > sector size(%d)\n", chunk_length, chunk_offset, SPI_FLASH_SEC_SIZE); return(app_action_error); } if((flash_sector_buffer_use != fsb_free) && (flash_sector_buffer_use != fsb_config_cache) && (flash_sector_buffer_use != fsb_ota)) { string_format(dst, "ERROR: flash_send: sector buffer in use: %u\n", flash_sector_buffer_use); return(app_action_error); } flash_sector_buffer_use = fsb_ota; string_format(dst, "OK flash-receive: sending bytes: %u, from offset: %u, data: @", chunk_length, chunk_offset); string_splice(dst, -1, &flash_sector_buffer, chunk_offset, chunk_length); string_append(dst, "\n"); if((chunk_offset + chunk_length) >= SPI_FLASH_SEC_SIZE) flash_sector_buffer_use = fsb_free; return(app_action_normal); }
void agregarHeader(char** mensaje){ char* head=string_new(); char* numero=header(string_length(*mensaje)); string_append(&head,numero); string_append(&head,*mensaje); *mensaje=string_duplicate(head); free(numero); free (head); }
char* path_append( char* base, const char* tail ) { if( !base ) return path_clean( string_clone( tail ), path_is_absolute( tail ) ); base = string_append( base, "/" ); base = string_append( base, tail ); base = path_clean( base, path_is_absolute( base ) ); return base; }
LIST *property_set_create( PARSE *parse, FRAME *frame ) { LIST* properties = lol_get( frame->args, 0 ); LIST* sorted = 0; LIST* order_sensitive = 0; LIST* unique; LIST* tmp; LIST* val; string var[1]; #if 0 /* Sort all properties which are not order sensitive */ for(tmp = properties; tmp; tmp = tmp->next) { LIST* g = get_grist(tmp->string); LIST* att = call_rule("feature.attributes", frame, g, 0); if (list_in(att, "order-sensitive")) { order_sensitive = list_new( order_sensitive, tmp->string); } else { sorted = list_new( sorted, tmp->string); } list_free(att); } sorted = list_sort(sorted); sorted = list_append(sorted, order_sensitive); unique = list_unique(sorted); #endif sorted = list_sort(properties); unique = list_unique(sorted); string_new(var); string_append(var, ".ps."); for(tmp = unique; tmp; tmp = tmp->next) { string_append(var, tmp->string); string_push_back(var, '-'); } val = var_get(var->value); if (val == 0) { val = call_rule("new", frame, list_append(list_new(0, "property-set"), unique), 0); var_set(newstr(var->value), list_copy(0, val), VAR_SET); } else { val = list_copy(0, val); } string_free(var); /* The 'unique' variable is freed in 'call_rule'. */ list_free(sorted); return val; }
static void test_string_append() { char *string = string_new(); string_append(&string, "Hello"); string_append(&string, " "); string_append(&string, "world"); CU_ASSERT_STRING_EQUAL(string, "Hello world"); free(string); }
void term_toString(Value* val, Value* out) { Term* t = as_term_ref(val); if (t == NULL) string_append(out, "Term#null"); else { string_append(out, "Term#"); string_append(out, t->id); } }
void block_to_string(Value* value, Value* asStr) { Block* block = as_block(value); if (block == NULL) { string_append(asStr, "Block#null"); } else { string_append(asStr, "Block#"); string_append(asStr, block->id); } }
void CuSuiteSummary(CuSuite* testSuite, char **summary) { int i; for (i = 0 ; i < testSuite->count ; ++i) { CuTest* testCase = testSuite->list[i]; string_append(summary, testCase->failed ? "F" : "."); } string_append(summary, "\n\n"); }
bool block_check_invariants_print_result(Block* block, Value* out) { circa::Value result; block_check_invariants(&result, block); if (list_length(&result) == 0) return true; string_append(out, list_length(&result)); string_append(out, " errors found in block "); string_append_ptr(out, block); string_append(out, "\n"); for (int i=0; i < list_length(&result); i++) { Value* error = list_get(&result,i); string_append(out, "["); string_append(out, as_int(list_get(error, 1))); string_append(out, "]"); string_append(out, as_cstring(list_get(error, 2))); string_append(out, "\n"); } string_append(out, "contents:\n"); print_block(block, out); return false; }
/** * Turns the backtrace into a string that can be displayed * * @param bt * @return */ char *arch_debug_bt2string(struct bt *bt) { #if defined(__SASC) && defined(DEBUG_RESTRACK) string str; char buf[120]; int i; int last_line = -1; char *last_file = NULL; if (!bt) return NULL; if (!(string_initialize(&str,200))) return NULL; /* Load debug infos if not done yet */ arch_debug_load(); string_append(&str,"Backtrace\n"); for (i=0;i<bt->addr_used;i++) { ULONG offset = (ULONG)bt->addr[i] - (ULONG)__code_base; sm_snprintf(buf,sizeof(buf),"\t\t%p (offset %p",bt->addr[i],offset); string_append(&str,buf); if (debug_info_count > 0) { struct debug_info *di; int offset = (ULONG)bt->addr[i] - (ULONG)__code_base; BIN_SEARCH(debug_info_array, 0, debug_info_count-1, (debug_info_array[m].offset <= offset) ? (offset < debug_info_array[m+1].offset?0:(1)):(-1), di); if (di && (di->filename != last_file || di->line != last_line)) { string_append(&str,", "); sm_snprintf(buf,sizeof(buf),"%s/%d",di->filename,di->line); string_append(&str,buf); last_file = di->filename; last_line = di->line; } } string_append(&str,")\n"); } return str.str; #else return NULL; #endif }
int64_t query_index(query_t *query, int64_t id) { string_t *sql = string_new(); char *where = build_filters(query); sqlite3_stmt *stmt; int64_t result; int64_t index = 1; string_append(sql, query->format->index); string_append(sql, query->format->from); string_append(sql, query->format->join); string_append(sql, where); free(where); if (string_size(query->order) > 0) { string_appendf(sql, " ORDER BY %s", string_string(query->order)); } musicd_log(LOG_DEBUG, "query", "%s", string_string(sql)); if (sqlite3_prepare_v2(db_handle(), string_string(sql), -1, &stmt, NULL) != SQLITE_OK) { musicd_log(LOG_ERROR, "query", "can't prepare '%s': %s", string_string(sql), db_error()); string_free(sql); return -1; } string_free(sql); bind_filters(query, stmt); while (1) { result = sqlite3_step(stmt); if (result == SQLITE_DONE) { result = 0; goto finish; } if (result != SQLITE_ROW) { musicd_log(LOG_ERROR, "query", "query_count: sqlite3_step failed"); result = -1; goto finish; } if (sqlite3_column_int64(stmt, 0) == id) { result = index; goto finish; } ++index; } finish: sqlite3_finalize(stmt); return result; }
char* string_join(t_list* chunks, char * separator) { int i; char* ret = string_duplicate(""); for(i = 0; i < list_size(chunks); i++) { if(i) { string_append(&ret, separator); } string_append(&ret, (char*) list_get(chunks, i)); } return ret; }
void string_append(caValue* left, caValue* right) { ca_assert(is_string(left)); if (is_string(right)) string_append(left, as_cstring(right)); else { std::string s = to_string(right); string_append(left, s.c_str()); } }
void string_append_qualified_name(caValue* left, caValue* right) { if (string_eq(left, "")) { copy(right, left); return; } if (string_eq(right, "")) return; string_append(left, ":"); string_append(left, right); }
void format_global_id(Term* term, Value* out) { if (!is_string(out)) set_string(out, ""); if (term == NULL) string_append(out, "null"); else { string_append(out, "#"); string_append(out, term->id); } }