/* Find all labels. */ void scan_labels() { int addr; char *temp; label_init(); /* zero all labels */ temp = prog; /* save pointer to top of program */ /* if the first bas_token in the file is a label */ get_token(); if(bas_token_type==NUMBER) { strcpy(label_table[0].name,bas_token); label_table[0].p=prog; } find_eol(); do { get_token(); if(bas_token_type==NUMBER) { addr = get_next_label(bas_token); if(addr==-1 || addr==-2) { (addr==-1) ?serror(5):serror(6); } strcpy(label_table[addr].name, bas_token); label_table[addr].p = prog; /* current point in program */ } /* if not on a blank line, find next line */ if(bas_tok!=EOL) find_eol(); } while(bas_tok!=FINISHED); prog = temp; /* restore to original */ }
int main() { si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER; si_t app_type = APPLICATION_TYPE_NORMAL; struct window * w; struct scroll_bar* s; struct label* l; char show[25]; /* 初始化用户应用程序 */ application_init(video_access_mode, app_type, "scroll_bar"); /* 申请窗口 */ w = window_init("window with scroll_bar"); /* 申请失败 */ if(w == NULL) { application_exit(); return -1; } window_set_bounds(w, 300, 100, 448, 200); s = scroll_bar_init(1, 400, 20); /* 申请失败 */ if(s == NULL) { application_exit(); return -1; } scroll_bar_set_bounds(s, 428, 0, 20, 200); l = label_init(show); /* 申请失败 */ if(l == NULL) { application_exit(); return -1; } label_set_bounds(l, 10, 40, 400, 20); sprintf(show, "not started"); scroll_bar_register_move_handler(s, WIDGET_POINTER(l), SCROLL_BAR_EVENT_ALL, label_handler); object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(s)); object_attach_child(OBJECT_POINTER(w), OBJECT_POINTER(l)); /* 添加顶层窗口 */ application_add_window(NULL, w); /* 设置主窗口 */ application_set_main_window(w); /* 运行 */ application_exec(); return 0; }
int main(int argc, char *argv[]) { Context context = {}; _cleanup_event_unref_ sd_event *event = NULL; _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); label_init("/etc"); if (argc != 1) { log_error("This program takes no arguments."); r = -EINVAL; goto finish; } if (argc != 1) { log_error("This program takes no arguments."); r = -EINVAL; goto finish; } r = sd_event_default(&event); if (r < 0) { log_error("Failed to allocate event loop: %s", strerror(-r)); goto finish; } sd_event_set_watchdog(event, true); r = connect_bus(&context, event, &bus); if (r < 0) goto finish; r = context_read_data(&context); if (r < 0) { log_error("Failed to read hostname and machine information: %s", strerror(-r)); goto finish; } r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL); if (r < 0) { log_error("Failed to run event loop: %s", strerror(-r)); goto finish; } finish: context_free(&context); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int pixel_init(lua_State *L) { luaL_checkversion(L); luaL_requiref(L, "pixel.framework", pixel_framework, 0); luaL_requiref(L, "pixel.texture", pixel_texture, 0); luaL_requiref(L, "pixel.shader", pixel_shader, 0); luaL_requiref(L, "pixel.renderbuffer", pixel_renderbuffer, 0); luaL_requiref(L, "pixel.matrix", pixel_matrix, 0); luaL_requiref(L, "pixel.color", pixel_color, 0); luaL_requiref(L, "pixel.geometry", pixel_geometry, 0); luaL_requiref(L, "pixel.sprite", pixel_sprite, 0); luaL_requiref(L, "pixel.spritepack", pixel_spritepack, 0); luaL_requiref(L, "pixel.particle", pixel_particle, 0); lua_settop(L, 0); shader_init(); texture_init(); label_init(0); return 0; }
/** * Initialize the templ theme * @param hue [0..360] hue value from HSV color space to define the theme's base color * @param font pointer to a font (NULL to use the default) * @return pointer to the initialized theme */ lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font) { if(font == NULL) font = LV_FONT_DEFAULT; _hue = hue; _font = font; /*For backward compatibility initialize all theme elements with a default style */ uint16_t i; lv_style_t **style_p = (lv_style_t**) &theme; for(i = 0; i < sizeof(lv_theme_t) / sizeof(lv_style_t*); i++) { *style_p = &def; style_p++; } basic_init(); cont_init(); btn_init(); label_init(); img_init(); line_init(); led_init(); bar_init(); slider_init(); sw_init(); lmeter_init(); gauge_init(); chart_init(); cb_init(); btnm_init(); kb_init(); mbox_init(); page_init(); ta_init(); list_init(); ddlist_init(); roller_init(); tabview_init(); win_init(); return &theme; }
int main(int argc, char *argv[]) { struct udev *udev; static const struct option options[] = { { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, {} }; const char *command; unsigned int i; int rc = 1; udev = udev_new(); if (udev == NULL) goto out; log_open(); udev_set_log_fn(udev, udev_main_log); label_init("/dev"); for (;;) { int option; option = getopt_long(argc, argv, "+dhV", options, NULL); if (option == -1) break; switch (option) { case 'd': log_set_max_level(LOG_DEBUG); udev_set_log_priority(udev, LOG_DEBUG); break; case 'h': rc = adm_help(udev, argc, argv); goto out; case 'V': rc = adm_version(udev, argc, argv); goto out; default: goto out; } } command = argv[optind]; if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) { if (strcmp(udevadm_cmds[i]->name, command) == 0) { argc -= optind; argv += optind; /* we need '0' here to reset the internal state */ optind = 0; rc = run_command(udev, udevadm_cmds[i], argc, argv); goto out; } } fprintf(stderr, "missing or unknown command\n\n"); adm_help(udev, argc, argv); rc = 2; out: label_finish(); udev_unref(udev); log_close(); return rc; }
static void show_statusbar_draw(dis_map* disp, void* args) { /* static int8 *sb_icon_tab[] = { XINHAO0_BMP, NULL, DIANCI0_BMP, NULL, LIANJIE_BMP, NULL, DIANYUAN_OK, NULL, NULL, NULL }; */ static char* sb_icon_tab[] = { LIANJIE_BMP, NULL, DIANCI0_BMP, NULL, DIANYUAN_OK, NULL, NULL, NULL }; static proptey time_lbl_props[] = { {LABL_STA_STATION , 120 , 6}, {LABL_STATE , STA_RIGHT , 0}, {LABL_WIDTH , 80 , 10}, {LABL_FONT_TYPE , HZ_16DZ , ASC_16DZ}, // {LABL_BAK_COLOR, WHITE_COLR, 0}, {0xffff , 0 , 0} }; static proptey oper_status_lbl_props[] = { {LABL_STA_STATION , 300 , 6}, {LABL_STATE , STA_LEFT , 0}, {LABL_WIDTH , 120 , 10}, {LABL_FONT_TYPE , HZ_16DZ , ASC_16DZ}, // {LABL_BAK_COLOR, WHITE_COLR, 0}, {0xffff , 0 , 0} }; uint32 seconds = 0; struct pic_lst* statusbar_ptr; statusbar_ptr = piclist_init(); if (NULL == statusbar_ptr) { return; } piclist_props_set(statusbar_ptr, sb_icon_tab, NULL); piclist_property_set(statusbar_ptr, BMP_STAT_SET , 2, 1); piclist_show(disp, statusbar_ptr); label_dst* time_lbl; time_lbl = label_init(); if (NULL == time_lbl) { return; } label_props_set(time_lbl, time_lbl_props); char datetime[64] = {0}; SAFE_GET_DATETIME("%Y/%m/%d %H:%M:%S", datetime); label_property_set(time_lbl, LABL_DIS_CAPTION, datetime); label_dis_bak(disp, time_lbl); // label_dis(disp, time_lbl); label_dst* oper_lbl; char oper_status[31]; oper_lbl = label_init(); if (NULL == oper_lbl) { return; } label_props_set(oper_lbl, oper_status_lbl_props); uint8 login_flag; if (!p16pos.login_flag) { strcpy(oper_status, "未登录"); } else { if (p16pos.work_mode == 0) { snprintf(oper_status, 30, "操作员: %s", p16pos.opername); } else { snprintf(oper_status, 30, "终端已登录"); } } login_flag = p16pos.login_flag; label_property_set(oper_lbl, LABL_DIS_CAPTION, oper_status); label_dis_bak(disp, oper_lbl); CLEAR(disp, 1, 1, SCREEN_X_PIXEL, 26); while (p16pos.app_running) { if (seconds % 10 == 0 || login_flag != p16pos.login_flag) { CLEAR(disp, 1, 1, SCREEN_X_PIXEL, 26); if (net_sta_get() == 1) { piclist_modify(statusbar_ptr, 0, LIANJIE_OK, NULL) ; } else { piclist_modify(statusbar_ptr, 0, LIANJIE_FS, NULL) ; } batt_state_get(statusbar_ptr); power_sig_get(statusbar_ptr); if (!p16pos.login_flag) { strcpy(oper_status, "未登录"); } else { snprintf(oper_status, 30, "操作员: %s", p16pos.opername); } label_property_set(oper_lbl, LABL_DIS_CAPTION, oper_status); label_dis_bak(disp, oper_lbl); piclist_show(disp, statusbar_ptr); login_flag = p16pos.login_flag; } else { CLEAR(disp, 120, 1, 300, 26); } memset(datetime, 0, sizeof datetime); SAFE_GET_DATETIME("%Y/%m/%d %H:%M:%S", datetime); label_property_set(time_lbl, LABL_DIS_CAPTION, datetime); // label_dis(disp, time_lbl); label_dis_bak(disp, time_lbl); lcd_160_upd() ; sleep(1); ++seconds; } LOG((LOG_DEBUG, "show_statusbar_draw end")); label_destory(time_lbl); }
void parser(Commands *commands, Labels *labels, Errors *errors, FILE *input) { int str_count = 0; int hlt = 0; while (!feof(input)) { char *string = (char*) malloc(1000 * sizeof(char)); char *word = (char*) malloc(1000 * sizeof(char)); int i = 0; int j = 0; memset(word, '\0', 1000); memset(string, '\0', 1000); fgets(string, 1000, input); if (feof(input)) { break; } str_count++; while (string[i] == ' ') { i++; } while ((is_letter(string[i])) || (is_number(string[i]))) { word[j++] = toLower(string[i++]); } if (j == 0) { add_error(errors, INCOR_DEF_FUNC, str_count); free(string); free(word); continue; } if (string[i] == ':') { add_label(commands, word, str_count); label_init(labels, word); } else if ((string[i] == ';') || (string[i] == ' ') || (string[i] == '\r') || (string[i] == '\n')) { Opcode cmd = operation(word); int num = 0; int negative = 0; switch (cmd) { case LDC: case LD: case ST: while (string[i] == ' ') i++; if (string[i] == '-') { negative = 1; i++; } if (!is_number(string[i])) { add_error(errors, INCOR_ARG, str_count); free(word); free(string); continue; } while (is_number(string[i])) { num = 10 * num + string[i] - '0'; i++; } if (negative) { num = num * (-1); } add_command_number(commands, cmd, num, str_count); break; case SUB: case MOD: case ADD: case MUL: case DIV: case CMP: add_command_number(commands, cmd, 0, str_count); break; case HLT: add_command_number(commands, cmd, 0, str_count); hlt++; break; case JMP: case BR: while (string[i] == ' ') i++; if (!((is_letter(string[i])) || (is_number(string[i])))) { add_error(errors, INCOR_LBL_ARG, str_count); free(word); free(string); continue; } get_label(commands, string, i, cmd, str_count); break; case ERR: add_error(errors, UNKNOWN_FUNC, str_count); free(string); free(word); continue; case LBL: break; } free(word); } free(string); } if (hlt == 0) { add_error(errors, NO_HLT, 0); } }
static int lfont(lua_State *L) { label_init(lua_tostring(L, 1)); return 0; }
int main(int argc, char *argv[]) { _cleanup_udev_unref_ struct udev *udev = NULL; _cleanup_udev_event_unref_ struct udev_event *event = NULL; _cleanup_udev_device_unref_ struct udev_device *dev = NULL; _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL; char syspath[UTIL_PATH_SIZE]; const char *devpath; const char *action; sigset_t mask, sigmask_orig; int err; err = fake_filesystems(); if (err < 0) return EXIT_FAILURE; udev = udev_new(); if (udev == NULL) return EXIT_FAILURE; log_debug("version %s\n", VERSION); label_init("/dev"); sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); action = argv[1]; if (action == NULL) { log_error("action missing\n"); goto out; } devpath = argv[2]; if (devpath == NULL) { log_error("devpath missing\n"); goto out; } rules = udev_rules_new(udev, 1); strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); goto out; } udev_device_set_action(dev, action); event = udev_event_new(dev); sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, &sigmask_orig); event->fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); if (event->fd_signal < 0) { fprintf(stderr, "error creating signalfd\n"); goto out; } /* do what devtmpfs usually provides us */ if (udev_device_get_devnode(dev) != NULL) { mode_t mode = 0600; if (streq(udev_device_get_subsystem(dev), "block")) mode |= S_IFBLK; else mode |= S_IFCHR; if (!streq(action, "remove")) { mkdir_parents_label(udev_device_get_devnode(dev), 0755); mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); } else { unlink(udev_device_get_devnode(dev)); util_delete_path(udev, udev_device_get_devnode(dev)); } } err = udev_event_execute_rules(event, rules, &sigmask_orig); if (err == 0) udev_event_execute_run(event, NULL); out: if (event != NULL && event->fd_signal >= 0) close(event->fd_signal); label_finish(); return err ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char* argv[]) { struct scroll_bar* s; struct button* b1 = NULL, *b2 = NULL; char msg[LABEL_MAX]; char file_msg[LABEL_MAX]; si_t video_access_mode = VIDEO_ACCESS_MODE_BUFFER; si_t app_type = APPLICATION_TYPE_NORMAL; char* file_name = NULL; si_t fonty = 0; /** * open with file **/ if(argc == 2) { struct stat st; if(stat(argv[1], &st) == -1) { EGUI_PRINT_ERROR("file %s does not exists", argv[1]); return -1; } if(!S_ISREG(st.st_mode) || access(argv[1], R_OK | W_OK) != 0) { EGUI_PRINT_ERROR("file %s cannot access!", argv[1]); return -1; } /** * file too large **/ if(st.st_size > FILE_MAX) { EGUI_PRINT_ERROR("file %s does not exists\n", argv[1]); return -1; } file_name = argv[1]; } else if(argc != 1) { EGUI_PRINT_ERROR("wrong parameter!\nusage: \nediterbasic\nor:\nediterbasic [filename]"); return -1; } /* 初始化用户应用程序 */ application_init(video_access_mode, app_type, "editerbasic"); /** * window **/ main_window = window_init("editer_basic"); /* 申请失败 */ if(main_window == NULL) { application_exit(); return -1; } window_set_bounds(main_window, 300, 100, 550, 300); window_set_color(main_window, NULL, &light_green); /** * label that show process **/ if(file_name) { sprintf(file_msg, "%s", file_name); } else { sprintf(file_msg, "new file"); } file_label = label_init(file_msg); if(file_label == NULL) { application_exit(); return -1; } label_set_bounds(file_label, 10, 10, 365, 20); label_set_color(file_label, &barely_blue, &light_blue); label_set_font(file_label, FONT_MATRIX_12); /** * save button **/ b1 = button_init("save"); if(b1 == NULL) { application_exit(); return -1; } button_set_bounds(b1, 380, 5, 60, 30); button_set_color(b1, &dark_blue, &barely_blue); button_set_font(b1, FONT_MATRIX_12); b1->callback = save_button_callback; b2 = button_init("save as"); if(b2 == NULL) { application_exit(); return -1; } button_set_bounds(b2, 445, 5, 100, 30); button_set_color(b2, &dark_blue, &barely_blue); button_set_font(b2, FONT_MATRIX_12); b2->callback = save_as_button_callback; /** * text_line that shows file context **/ file_context_text_line = text_line_init(FILE_MAX, 0); if(file_context_text_line == NULL) { application_exit(); return -1; } text_line_set_bounds(file_context_text_line, 5, 40, 520, 230); text_line_set_color(file_context_text_line, &dark_blue, NULL, NULL); text_line_set_multilines(file_context_text_line); fonty = get_font_height(file_context_text_line->gd); if(file_name) { if(load_file(file_name, text_line_get_buf(file_context_text_line)) < 0) { EGUI_PRINT_ERROR("failed to load file %s", file_name); application_exit(); return -1; } s = scroll_bar_init(1, fonty * text_line_get_max_line_shown(file_context_text_line), fonty); } else { s = scroll_bar_init(1, file_context_text_line->area.height, fonty); } if(s == NULL) { application_exit(); return -1; } scroll_bar_set_bounds(s, 525, 40, 20, 230); text_line_register_move_handler(file_context_text_line, WIDGET_POINTER(s), TEXT_LINE_EVENT_ALL, scrollbar_subscribe_text_line); scroll_bar_register_move_handler(s, WIDGET_POINTER(file_context_text_line), SCROLL_BAR_EVENT_ALL, text_line_subscribe_scrollbar); log_label = label_init(msg); if(log_label == NULL) { application_exit(); return -1; } label_set_bounds(log_label, 5, 275, 450, 20); label_set_color(log_label, NULL, &light_green); sprintf(msg, "open file successfully!"); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_label)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(file_context_text_line)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(log_label)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b1)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(b2)); object_attach_child(OBJECT_POINTER(main_window), OBJECT_POINTER(s)); /* 添加顶层窗口 */ application_add_window(NULL, main_window); /* 设置主窗口 */ application_set_main_window(main_window); /* 运行 */ application_exec(); return 0; }
void parser_push(const context_t *ctx, const line_t *line) { position_t *pos = line->position; // is the first block already set? if (p->blk == NULL) { p->blk = block_init(NULL, pos); } statement_t *stmt = new_statement(ctx); const operation_t *op = NULL; const char *name = NULL; label_t *label = NULL; // allow the tokenizer to fold comma into ",x" etc addressing mode tokens int allow_index = 0; // tokenize the line pstate_t state = P_INIT; tokenizer_t *tok = tokenizer_init(line->line); while (tokenizer_next(tok, allow_index)) { switch(state) { case P_OP: if (tok->type == T_TOKEN && tok->vals.op == OP_COLON) { // accept after label // continue to next stmt->type = S_LABEQPC; statement_push(stmt); stmt = new_statement(ctx); state = P_INIT; break; } if (tok->type == T_TOKEN && tok->vals.op == OP_ASSIGN) { // after label, that's a label value definition stmt->type = S_LABDEF; // next define the label from param state = P_PARAM; break; } // fall-through! case P_INIT: switch(tok->type) { case T_NAME: name = mem_alloc_strn(tok->line + tok->ptr, tok->len); op = operation_find(name); if (op != NULL) { // check if the operation is compatible with the current CPU if (0 == (ctx->cpu->isa & op->isa)) { // TODO: config for either no message or error warn_operation_not_for_cpu(pos, name, ctx->cpu->name); op = NULL; } } if (op == NULL) { // label // TODO: redefinition? label = label_init(ctx, name, pos); if (state == P_OP) { // we already had a label stmt->type = S_LABEQPC; statement_push(stmt); stmt = new_statement(ctx); } stmt->label = label; // expect operation next (but accept labels too) state = P_OP; } else { // operation stmt->op = op; state = P_PARAM; } break; default: // syntax error error_syntax(pos); goto end; break; } break; case P_PARAM: // parse parameters arith_parse(tok, allow_index, &stmt->param); break; default: error_syntax(pos); goto end; break; }; } statement_push(stmt); end: tokenizer_free(tok); }