int main(void) { struct ds in; ds_init(&in); while (!ds_get_line(&in, stdin)) { struct ofpbuf odp_key; struct flow flow; struct ds out; int error; char *s; /* Delete comments, skip blank lines. */ s = ds_cstr(&in); if (*s == '#') { puts(s); continue; } if (strchr(s, '#')) { *strchr(s, '#') = '\0'; } if (s[strspn(s, " ")] == '\0') { putchar('\n'); continue; } /* Convert string to OVS DP key. */ ofpbuf_init(&odp_key, 0); error = odp_flow_key_from_string(ds_cstr(&in), &odp_key); if (error) { printf("odp_flow_key_from_string: error\n"); goto next; } /* Convert odp_key to flow. */ error = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow); if (error) { printf("odp_flow_key_to_flow: error\n"); goto next; } /* Convert cls_rule back to odp_key. */ ofpbuf_uninit(&odp_key); ofpbuf_init(&odp_key, 0); odp_flow_key_from_flow(&odp_key, &flow); /* Convert odp_key to string. */ ds_init(&out); odp_flow_key_format(odp_key.data, odp_key.size, &out); puts(ds_cstr(&out)); ds_destroy(&out); next: ofpbuf_uninit(&odp_key); } ds_destroy(&in); return 0; }
static int parse_actions(void) { struct ds in; ds_init(&in); vlog_set_levels_from_string_assert("odp_util:console:dbg"); while (!ds_get_test_line(&in, stdin)) { struct ofpbuf odp_actions; struct ds out; int error; /* Convert string to OVS DP actions. */ ofpbuf_init(&odp_actions, 0); error = odp_actions_from_string(ds_cstr(&in), NULL, &odp_actions); if (error) { printf("odp_actions_from_string: error\n"); goto next; } /* Convert odp_actions back to string. */ ds_init(&out); format_odp_actions(&out, odp_actions.data, odp_actions.size); puts(ds_cstr(&out)); ds_destroy(&out); next: ofpbuf_uninit(&odp_actions); } ds_destroy(&in); return 0; }
static char * cell_to_text(struct cell *cell, const struct table_style *style) { if (!cell->text) { if (cell->json) { if (style->cell_format == CF_JSON || !cell->type) { cell->text = json_to_string(cell->json, JSSF_SORT); } else { struct ovsdb_datum datum; struct ovsdb_error *error; struct ds s; error = ovsdb_datum_from_json(&datum, cell->type, cell->json, NULL); if (!error) { ds_init(&s); if (style->cell_format == CF_STRING) { ovsdb_datum_to_string(&datum, cell->type, &s); } else { ovsdb_datum_to_bare(&datum, cell->type, &s); } ovsdb_datum_destroy(&datum, cell->type); cell->text = ds_steal_cstr(&s); } else { cell->text = json_to_string(cell->json, JSSF_SORT); ovsdb_error_destroy(error); } } } else { cell->text = xstrdup(""); } } return cell->text; }
static int parse_actions(const char *in) { struct ofpbuf odp_actions; struct ds out; int error; /* Convert string to OVS DP actions. */ ofpbuf_init(&odp_actions, 0); error = odp_actions_from_string(in, NULL, &odp_actions); if (error) { printf("odp_actions_from_string: error\n"); goto next; } /* Convert odp_actions back to string. */ ds_init(&out); format_odp_actions(&out, odp_actions.data, odp_actions.size, NULL); puts(ds_cstr(&out)); ds_destroy(&out); next: ofpbuf_uninit(&odp_actions); return 0; }
unsigned char work() { scanf("%d", &n); if (n == 0) return 0; m = 0; int i, j, k; for (i = 0; i < n - 1; ++i) { assert(next_notblank() == 'A' + i); scanf("%d", &k); while (k--) { from[m] = i; to[m] = next_notblank() - 'A'; scanf("%d", &weight[m++]); } } // Kruskal's algorithm int mst_w = 0; for (i = 0; i < m - 1; ++i) for (j = i + 1; j < m; ++j) if (weight[i] > weight[j]) { SWAP(k, from[i], from[j]); SWAP(k, to[i], to[j]); SWAP(k, weight[i], weight[j]); } ds_init(n); for (i = 0; i < m; ++i) if (ds_root(from[i]) != ds_root(to[i])) { mst_w += weight[i]; ds_union(from[i], to[i]); } printf("%d\n", mst_w); return 1; }
static void test_lex(const char *input) { struct ds output; ds_init(&output); struct lexer lexer; lexer_init(&lexer, input); ds_clear(&output); while (lexer_get(&lexer) != LEX_T_END) { size_t len = output.length; lex_token_format(&lexer.token, &output); /* Check that the formatted version can really be parsed back * losslessly. */ if (lexer.token.type != LEX_T_ERROR) { const char *s = ds_cstr(&output) + len; struct lexer l2; lexer_init(&l2, s); lexer_get(&l2); compare_token(&lexer.token, &l2.token); lexer_destroy(&l2); } ds_put_char(&output, ' '); } lexer_destroy(&lexer); ds_chomp(&output, ' '); puts(ds_cstr(&output)); ds_destroy(&output); }
action_syntax_error(struct action_context *ctx, const char *message, ...) { if (action_error_handle_common(ctx)) { return; } struct ds s; ds_init(&s); ds_put_cstr(&s, "Syntax error"); if (ctx->lexer->token.type == LEX_T_END) { ds_put_cstr(&s, " at end of input"); } else if (ctx->lexer->start) { ds_put_format(&s, " at `%.*s'", (int) (ctx->lexer->input - ctx->lexer->start), ctx->lexer->start); } if (message) { ds_put_char(&s, ' '); va_list args; va_start(args, message); ds_put_format_valist(&s, message, args); va_end(args); } ds_put_char(&s, '.'); ctx->error = ds_steal_cstr(&s); }
void parse_ofp_flow_mod_file(const char *file_name, uint16_t command, struct ofputil_flow_mod **fms, size_t *n_fms) { size_t allocated_fms; FILE *stream; struct ds s; stream = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r"); if (stream == NULL) { ovs_fatal(errno, "%s: open", file_name); } allocated_fms = *n_fms; ds_init(&s); while (!ds_get_preprocessed_line(&s, stream)) { if (*n_fms >= allocated_fms) { *fms = x2nrealloc(*fms, &allocated_fms, sizeof **fms); } parse_ofp_flow_mod_str(&(*fms)[*n_fms], ds_cstr(&s), command, false); *n_fms += 1; } ds_destroy(&s); if (stream != stdin) { fclose(stream); } }
// --------------------------------------------------------------------------------------- // Initialize the game sound system // // Initialize the game sound system. Depending on what sound library is being used, // call the appropriate low-level initiailizations // // returns: 1 => init success // 0 => init failed // int snd_init(int use_a3d, int use_eax) { int rval; if ( Cmdline_freespace_no_sound ) return 0; if (ds_initialized) { nprintf(( "Sound", "SOUND => Direct Sound is already initialized!\n" )); return 1; } snd_clear(); // Init DirectSound // Connect to DirectSound int num_tries=0; int gave_warning = 0; while(1) { rval = ds_init(use_a3d, use_eax); if( rval != 0 ) { nprintf(( "Sound", "SOUND ==> Error initializing DirectSound, trying again in 1 second.\n")); Sleep(1000); } else { break; } if ( num_tries++ > 5 ) { if ( !gave_warning ) { MessageBox(NULL, XSTR("DirectSound could not be initialized. If you are running any applications playing sound in the background, you should stop them before continuing.",971), NULL, MB_OK); gave_warning = 1; } else { goto Failure; } } } // Init the Audio Compression Manager if ( ACM_init() == -1 ) { HWND hwnd = (HWND)os_get_window(); MessageBox(hwnd, XSTR("Could not properly initialize the Microsoft ADPCM codec.\n\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec.",972), NULL, MB_OK); // Warning(LOCATION, "Could not properly initialize the Microsoft ADPCM codec.\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec."); } // Init the audio streaming stuff audiostream_init(); ds_initialized = 1; return 1; Failure: // Warning(LOCATION, "Sound system was unable to be initialized. If you continue, sound will be disabled.\n"); nprintf(( "Sound", "SOUND => Direct Sound init unsuccessful, continuing without sound.\n" )); return 0; }
static int stream_open(struct stream *s) { ds_init(&s->log); if (pipe(s->fds)) { VLOG_WARN("failed to create pipe: %s", strerror(errno)); return errno; } set_nonblocking(s->fds[0]); return 0; }
ex_t histogram(bfpath *bfp) { ex_t rc; uint count; void *dsh, *dbe; dsv_t val; rhistogram_t hist; dbe = ds_init(bfp); if (dbe == NULL) return EX_ERROR; dsh = ds_open(dbe, bfp, DS_READ); if (dsh == NULL) return EX_ERROR; if (DST_OK != ds_txn_begin(dsh)) { ds_close(dsh); ds_cleanup(dbe); fprintf(stderr, "cannot begin transaction!\n"); return EX_ERROR; } ds_get_msgcounts(dsh, &val); mgood = val.goodcount; mbad = val.spamcount; memset(&hist, 0, sizeof(hist)); rc = ds_foreach(dsh, ds_histogram_hook, &hist); if (DST_OK != ds_txn_commit(dsh)) { ds_close(dsh); ds_cleanup(dbe); fprintf(stderr, "cannot commit transaction!\n"); return EX_ERROR; } ds_close(dsh); ds_cleanup(dbe); count = print_histogram(&hist); if (verbose > 0) { printf("hapaxes: ham %7u, spam %7u\n", ham_hapax, spam_hapax); printf(" pure: ham %7u, spam %7u\n", ham_only, spam_only); } else { printf("hapaxes: ham %7u (%5.2f%%), spam %7u (%5.2f%%)\n", ham_hapax, PCT(ham_hapax), spam_hapax, PCT(spam_hapax)); printf(" pure: ham %7u (%5.2f%%), spam %7u (%5.2f%%)\n", ham_only, PCT(ham_only), spam_only, PCT(spam_only)); } return rc; }
/* Returns a string that describes some of 'b''s metadata plus a hex dump of up * to 'maxbytes' from the start of the buffer. */ char * dp_packet_to_string(const struct dp_packet *b, size_t maxbytes) { struct ds s; ds_init(&s); ds_put_format(&s, "size=%"PRIu32", allocated=%"PRIu32", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n", dp_packet_size(b), b->allocated, dp_packet_headroom(b), dp_packet_tailroom(b)); ds_put_hex_dump(&s, dp_packet_data(b), MIN(dp_packet_size(b), maxbytes), 0, false); return ds_cstr(&s); }
/* Returns a string that describes some of 'b''s metadata plus a hex dump of up * to 'maxbytes' from the start of the buffer. */ char * ofpbuf_to_string(const struct ofpbuf *b, size_t maxbytes) { struct ds s; ds_init(&s); ds_put_format(&s, "size=%"PRIu32", allocated=%"PRIu32", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n", b->size, b->allocated, ofpbuf_headroom(b), ofpbuf_tailroom(b)); ds_put_hex_dump(&s, b->data, MIN(b->size, maxbytes), 0, false); return ds_cstr(&s); }
static void sys_statusbar(void* args) { dis_map* disp = ds_init(SCREEN_X_PIXEL, 272, TFT_16); if (NULL == disp) { LOG((LOG_ERROR, "创建状态栏显示对象失败")); return; } jpg_display(disp, 0, 0, "../res/jpg/bak.jpg") ; jpg_stormem(disp, disp->bak_ptr, 0, 0, "../res/jpg/bak.jpg"); show_statusbar_draw(disp, args); ds_destory(disp); pthread_exit(0); }
int main() { int rc = 0; struct tspec { pthread_t t; void *(*start) (void *); } thr[3] = {{0, &t1_start}, {0, &t2_start}, {0, &t3_start}}; const size_t N_THREADS = sizeof(thr)/sizeof(thr[0]); size_t i = 0; void *ret = NULL; do { rc = ds_init(); if (rc) break; rc = ds_set("MAIN_DONE", false, __func__); for (i = 0; i < N_THREADS; ++i) { (void) fprintf(stderr, "%s: starting t%ld\n", __func__, (long)i+1); rc = pthread_create(&thr[i].t, NULL, thr[i].start, NULL); if (rc) break; } const unsigned int nap = 10; (void) fprintf(stderr, "%s: taking a nap for %d seconds\n", __func__, nap); (void) sleep(nap); (void) fprintf(stderr, "%s: woke up\n", __func__); rc = ds_signal("MAIN_DONE", __func__); if (rc) break; } while(0); for(i = 0; i < N_THREADS; ++i) { if (thr[i].t) { (void) fprintf(stderr, "%s: joining t%ld .. ", __func__, (long)i+1); rc = pthread_join(thr[i].t, &ret); (void) fprintf(stderr, "%s\n", rc ? "FAILED" : "done"); } } ds_destroy(); (void) fprintf(stderr, "%s exiting [%d]\n", __func__, rc); return rc; }
char * svec_join(const struct svec *svec, const char *delimiter) { struct ds ds; size_t i; ds_init(&ds); for (i = 0; i < svec->n; i++) { if (i) { ds_put_cstr(&ds, delimiter); } ds_put_cstr(&ds, svec->names[i]); } return ds_cstr(&ds); }
//============================================================================================================================ void ICACHE_FLASH_ATTR ds18b20_init() { int r; ds_init(); OWFind(); // r = ds_search(ow_addr); // if(r) // { // ets_uart_printf("Found Device @ %02x %02x\r\n", ow_addr[0], ow_addr[1], ow_addr[2], ow_addr[3], ow_addr[4], ow_addr[5], ow_addr[6], ow_addr[7]); // if(crc8(ow_addr, 7) != ow_addr[7]) // ets_uart_printf( "CRC mismatch, crc=%xd, addr[7]=%xd\r\n", crc8(ow_addr, 7), ow_addr[7]); // } // else ets_uart_printf("No DS18B20 detected, sorry.\r\n"); }
static int ds_pci_resume(device_t dev) { struct sc_info *sc; sc = pcm_getdevinfo(dev); if (ds_init(sc) == -1) { device_printf(dev, "unable to reinitialize the card\n"); return ENXIO; } if (mixer_reinit(dev) == -1) { device_printf(dev, "unable to reinitialize the mixer\n"); return ENXIO; } return 0; }
int main(int argc, char ** argv) { ds d = ds_init(); for (int i = 0; i < 100; i++) insert_d(d, f(i)); delete_d(d, 1337); for (int i = 0; i < 10000; i++) insert_d(d, f(i)); delete_max_d(d); return 0; }
static bool switch_status_remote_packet_cb(struct relay *r, void *ss_) { struct switch_status *ss = ss_; struct rconn *rc = r->halves[HALF_REMOTE].rconn; struct ofpbuf *msg = r->halves[HALF_REMOTE].rxbuf; struct switch_status_category *c; struct nicira_header *request; struct nicira_header *reply; struct status_reply sr; struct ofpbuf *b; int retval; if (msg->size < sizeof(struct nicira_header)) { return false; } request = msg->data; if (request->header.type != OFPT_EXPERIMENTER || request->vendor != htonl(NX_VENDOR_ID) || request->subtype != htonl(NXT_STATUS_REQUEST)) { return false; } sr.request.string = (void *) (request + 1); sr.request.length = msg->size - sizeof *request; ds_init(&sr.output); for (c = ss->categories; c < &ss->categories[ss->n_categories]; c++) { if (!memcmp(c->name, sr.request.string, MIN(strlen(c->name), sr.request.length))) { sr.category = c; c->cb(&sr, c->aux); } } reply = make_openflow_xid(sizeof *reply + sr.output.length, OFPT_EXPERIMENTER, request->header.xid, &b); reply->vendor = htonl(NX_VENDOR_ID); reply->subtype = htonl(NXT_STATUS_REPLY); memcpy(reply + 1, sr.output.string, sr.output.length); retval = rconn_send(rc, b, NULL); if (retval && retval != EAGAIN) { VLOG_WARN(LOG_MODULE, "send failed (%s)", strerror(retval)); } ds_destroy(&sr.output); return true; }
/* Similar to parse_ofp_flow_mod_str(), except that the string is read from * 'stream' and the command is always OFPFC_ADD. Returns false if end-of-file * is reached before reading a flow, otherwise true. */ bool parse_ofp_flow_mod_file(struct list *packets, enum nx_flow_format *cur, bool *flow_mod_table_id, FILE *stream, uint16_t command) { struct ds s; bool ok; ds_init(&s); ok = ds_get_preprocessed_line(&s, stream) == 0; if (ok) { parse_ofp_flow_mod_str(packets, cur, flow_mod_table_id, ds_cstr(&s), command, true); } ds_destroy(&s); return ok; }
//}}} // {{{ test_printer static void test_printer() { PRINTER = ds_init(FS_DOT_NUM, 640 , BIT_L); if (NULL == PRINTER) return; /* dis_mod_set(PRINTER ,HZ_32DZ ,ASC_32DZ); printf_str(PRINTER, 120, 1, "一卡通充值机", 1); char tip[64]; sprintf(tip,"终端号: %s",p16pos.devphyid); printf_str(PRINTER, 30, 50, tip, 1); char date[24] = {0}; SAFE_GET_DATETIME("%Y/%m/%d",date); sprintf(tip,"日期: %s",date); printf_str(PRINTER, 30, 90, tip, 1); memset(date,0,sizeof date); SAFE_GET_DATETIME("%H:%M:%S",date); sprintf(tip,"时间: %s",date); printf_str(PRINTER, 30, 130, tip, 1); fs_print_dat(PRINTER->ptr,PRINTER->buf_size) ; int ret; uint8 step; while(1) { ret = fs_print_status(&step); if(0 == ret) { disp_msg("打印测试完成",10); return; } else if(-1==ret) { disp_msg("打印失败",10); } else { continue; } } */ }
void device_service_create() { master_device_port = ipc_port_alloc_kernel(); if (master_device_port == IP_NULL) panic("can't allocate master device port"); ds_init(); dev_lookup_init(); net_io_init(); device_pager_init(); chario_init(); #ifdef FIPC fipc_init(); #endif (void) kernel_thread(kernel_task, io_done_thread, 0); (void) kernel_thread(kernel_task, net_thread, 0); }
int main(){ /*********** data service module ************/ init_syslog(); //char ss[18]={51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68}; //Print_hex(ss,18); XGSetLogOutCallback(xg_printf); Info("***********************FOTILE IKCC START***************************"); Info("***********************FOTILE IKCC START***************************"); Info("***********************FOTILE IKCC START***************************"); #if 0 ds_init(); /*********** hardware service module ************/ hw_init(); /*********** message transfer ************/ msg_transfer_init(); /*********** net socket ************/ ikcc_init_net_server(8888); /*********** native socket ************/ ikcc_init_native_socket("/tmp/native_socket"); /*********** lua script ************/ #endif #ifdef LUA_SCRIPT ikcc_init_ssid_tcp_server(23576); //lua_init_lua(); //此功能会加载lua cjson库 需要安装到板子上 //cjson_test(); #endif /* LUA_SCRIPT */ ft_xlink_gateway_init(); /***********console command************/ //init_console(); //此接口会阻塞 while(1) { sleep(10); } Info("core over!"); }
static ex_t dump_wordlist(bfpath *bfp) { ex_t rc; void *dbe; token_count = 0; dbe = ds_init(bfp); rc = ds_oper(dbe, bfp, DS_READ, ds_dump_hook, NULL); ds_cleanup(dbe); if (rc != EX_OK) fprintf(stderr, "error dumping tokens!\n"); else if (verbose) fprintf(dbgout, "%d tokens dumped\n", token_count); return rc; }
/* Returns a string that represents 'protocols'. The return value might be a * comma-separated list if 'protocols' doesn't have a simple name. The return * value is "none" if 'protocols' is 0. * * The caller must free the returned string (with free()). */ char * ofputil_protocols_to_string(enum ofputil_protocol protocols) { struct ds s; ovs_assert(!(protocols & ~OFPUTIL_P_ANY)); if (protocols == 0) { return xstrdup("none"); } ds_init(&s); while (protocols) { const struct proto_abbrev *p; int i; if (s.length) { ds_put_char(&s, ','); } for (p = proto_abbrevs; p < &proto_abbrevs[N_PROTO_ABBREVS]; p++) { if ((protocols & p->protocol) == p->protocol) { ds_put_cstr(&s, p->name); protocols &= ~p->protocol; goto match; } } for (i = 0; i < CHAR_BIT * sizeof(enum ofputil_protocol); i++) { enum ofputil_protocol bit = 1u << i; if (protocols & bit) { ds_put_cstr(&s, ofputil_protocol_to_string(bit)); protocols &= ~bit; goto match; } } OVS_NOT_REACHED(); match: ; } return ds_steal_cstr(&s); }
/** * @brief 加载配置文件 * @return - 返回0 表示成功,其它表示失败 */ static int do_load_config() { int ret = sam_read_termno(p16pos.termno); if (!ret) { p16pos.load_sam = 1; } else { p16pos.load_sam = 0; } MAIN_DISP = ds_init(480, 272, TFT_16); if (NULL == MAIN_DISP) { error_exit(2, "初始化屏幕显示失败"); } return 0; }
// --------------------------------------------------------------------------------------- // Initialize the game sound system // // Initialize the game sound system. Depending on what sound library is being used, // call the appropriate low-level initiailizations // // returns: 1 => init success // 0 => init failed // int snd_init() { int rval; if ( Cmdline_freespace_no_sound ) return 0; if (ds_initialized) { nprintf(( "Sound", "SOUND => Audio is already initialized!\n" )); return 1; } snd_clear(); rval = ds_init(); if ( rval != 0 ) { nprintf(( "Sound", "SOUND ==> Fatal error initializing audio device, turn sound off.\n" )); Cmdline_freespace_no_sound = Cmdline_freespace_no_music = 1; goto Failure; } if ( OGG_init() == -1 ) { mprintf(("Could not initialize the OGG vorbis converter.\n")); } snd_aav_init(); // Init the audio streaming stuff audiostream_init(); ds_initialized = 1; Sound_enabled = TRUE; return 1; Failure: // Warning(LOCATION, "Sound system was unable to be initialized. If you continue, sound will be disabled.\n"); nprintf(( "Sound", "SOUND => Audio init unsuccessful, continuing without sound.\n" )); return 0; }
log_wakeup(const struct backtrace *backtrace, const char *format, ...) { struct ds ds; va_list args; ds_init(&ds); va_start(args, format); ds_put_format_valist(&ds, format, args); va_end(args); if (backtrace) { int i; ds_put_char(&ds, ':'); for (i = 0; i < backtrace->n_frames; i++) { ds_put_format(&ds, " 0x%x", backtrace->frames[i]); } } VLOG_DBG("%s", ds_cstr(&ds)); ds_destroy(&ds); }
void device_service_create(void) { master_device_port = ipc_port_alloc_kernel(); if (master_device_port == IP_NULL) panic("can't allocate master device port"); ipc_kobject_set(master_device_port, 1, IKOT_MASTER_DEVICE); ds_init(); net_io_init(); device_pager_init(); datadev_init(); (void) kernel_thread(kernel_task, io_done_thread, (char *)0); (void) kernel_thread(kernel_task, net_thread, (char *)0); #if XKMACHKERNEL && !DIPC_XKERN /* * Initialize the x-kernel */ (void) kernel_thread(kernel_task, xkInit, (char *)0); #endif /* XKMACHKERNEL && !DIPC_XKERN */ }