static void syntax_error ( char *near_str ) { put_msg (ERROR, "Syntax error near\n"); put_msg (ERROR, " ... >>>%s<<<", near_str); if (fgets(rest_of_line, 200, in_s)) append_msg (ERROR, rest_of_line); }
static void tangent_or_normal(int x, int y, int flag) { float dx, dy, length, sx, sy, tanlen; dx = (float)(smart_point2.x - smart_point1.x); dy = (float)(smart_point2.y - smart_point1.y); if (dx == 0.0 && dy == 0.0) length = 0.0; else length = sqrt(dx * dx + dy * dy); if (length < ZERO_TOLERANCE) { put_msg("%s", "singularity, can't draw tangent/normal"); beep(); return; } tanlen = cur_tangnormlen * (appres.INCHES? PIX_PER_INCH: PIX_PER_CM) / 2.0; sx = dx * tanlen / length; sy = dy * tanlen / length; if (flag) { tangent_normal_line(x, y, -sy, sx); put_msg("%s", "added normal"); } else { tangent_normal_line(x, y, sx, sy); put_msg("%s", "added tangent"); } }
int append_record ( record r, schema_p s ) { tbl_p tbl = s->tbl; page_p pg = get_page_for_append ( s->name ); if (pg == NULL) { put_msg (FATAL, "Failed to get page for appending to \"%s\".\n", s->name); exit (EXIT_FAILURE); } if ( put_page_record (pg, r, s) == -1 ) { /* not enough space in the current page */ unpin (pg); pg = get_next_page ( pg ); if (pg == NULL) { put_msg (FATAL, "Failed to get page for \"%s\" block %d.\n", s->name, page_block_nr(pg) + 1); exit (EXIT_FAILURE); } if ( put_page_record (pg, r, s) == -1 ) { put_msg (FATAL, "Failed to put record to page for \"%s\" block %d.\n", s->name, page_block_nr(pg) + 1); exit (EXIT_FAILURE); } } tbl->current_pg = pg; tbl->num_records++; return 0; }
void undo(void) { /* turn off Compose key LED */ setCompLED(0); switch (last_action) { case F_ADD: undo_add(); break; case F_DELETE: undo_delete(); break; case F_MOVE: undo_move(); break; case F_EDIT: undo_change(); break; case F_GLUE: undo_glue(); break; case F_BREAK: undo_break(); break; case F_LOAD: undo_load(); break; case F_SCALE: undo_scale(); break; case F_ADD_POINT: undo_addpoint(); break; case F_DELETE_POINT: undo_deletepoint(); break; case F_ADD_ARROW_HEAD: undo_add_arrowhead(); break; case F_DELETE_ARROW_HEAD: undo_delete_arrowhead(); break; case F_CONVERT: undo_convert(); break; case F_OPEN_CLOSE: undo_open_close(); break; case F_JOIN: case F_SPLIT: undo_join_split(); break; default: put_msg("Nothing to UNDO"); return; } put_msg("Undo complete"); }
void test_page_read_with_offset ( const char *fname ) { put_msg (INFO, "test_page_read_with_offset() ...\n"); pager_init (); /* put_pager_info (DEBUG, "After pager_init"); */ page_p pg; int int_out; char str_out[14]; int bnr; for (bnr = 0; bnr < NUM_BLOCKS_IN_FILE; bnr++) { pg = get_page ( fname, bnr ); if ( pg == NULL) { put_msg (FATAL, "get_page %d fails\n", bnr); put_pager_info (FATAL, "After get_page"); exit (EXIT_FAILURE); } /* put_pager_info (DEBUG, "After get_page"); */ int i = 0; while (!eob(pg)) { int offset = PAGE_HEADER_SIZE + i*(INT_SIZE + str_len); int_out = page_get_int_at(pg, offset); if ( int_out != ints_in[i] + bnr ) { put_msg (FATAL, "test_page_read fails: (read: %d, should be %d)\n", int_out, ints_in[i] + bnr); put_pager_info (FATAL, "After page_get_int_at"); exit (EXIT_FAILURE); } offset += INT_SIZE; page_get_str_at (pg, offset, str_out, str_len); if ( strcmp (str_out, strs_in[i]) != 0 ) { put_msg (FATAL, "test_page_read fails: (read: \"%s\", should be \"%s\")\n", str_out, strs_in[i] + bnr); put_pager_info (FATAL, "After page_get_str_at"); exit (EXIT_FAILURE); } i++; } unpin (pg); } put_pager_profiler_info (INFO); pager_terminate (); /* put_pager_info (DEBUG, "After pager_terminate"); */ put_msg (INFO, "test_page_read_with_offset() succeeds.\n"); }
void put_db_info ( pmsg_level level ) { char *db_dir = system_dir (); if (db_dir == NULL) return; put_msg (level, "======Database at %s:\n", db_dir); tbl_p tbl; for (tbl = db_tables; tbl != NULL; tbl = tbl->next) put_tbl_info (level, tbl); put_msg (level, "======\n"); }
/******************************************************************************* * Function Name : timer1_isr * Description : timer1 interrupt per 1ms * Input : None * Output : * Return : None *******************************************************************************/ void timer0_isr(void) { REG32(TMR0_CPND) |= BIT(1); u32Delay_1msCnt++; u32Timer0_1msCnt++; //u32Test_1msCnt++; #if LED_REUSE_ADKEY if(u32Timer0_1msCnt%8 == 7) { if(adc_chk_flag==1) { adc_chk_flag = 2; ADKeyInit(); } } #endif if(u32Timer0_1msCnt%8 == 0) //keep the same timeout as the WDT wakeupt time { #if (USER_CONFIG==CONFIG_AX3251_AIRBORNE) //here not into power save mode #else powerSaveCheck(); #endif ScanKey(0); led_SetStatus(); sd_Detect(); usb20_detect(); { static SYSTEM_STATE prev_state=0xff; if(prev_state != g_SystemState) { prev_state = g_SystemState; //deg_Printf("SYS_State=%d\n",g_SystemState); } } } if((u32Timer0_1msCnt%500)==0) { put_msg(SYSTEM_500MS); OSD_changeFlag = 1; } if((u32Timer0_1msCnt%1000)==0) { #if SOFT_POWER_ON_OFF poweroff_1s_check(); //add for tmp test #endif task_record_1s_check(); //add for md wait some times f_check_rec_video_file_size(); put_msg(SYSTEM_1S); } }
static void init_align_canvas(int x, int y, unsigned int shift) /* Shift Key Status from XEvent */ { int ux; cur_c = &objects; toggle_all_compoundmarkers(); draw_compoundelements(cur_c, ERASE); old_c = copy_compound(&objects); xcmin=ycmin=0; /* get the current page size */ xcmax = paper_sizes[appres.papersize].width; ycmax = paper_sizes[appres.papersize].height; if (!appres.INCHES) { xcmax = (int)(xcmax*2.54*PIX_PER_CM/PIX_PER_INCH); ycmax = (int)(ycmax*2.54*PIX_PER_CM/PIX_PER_INCH); } /* swap height and width if landscape */ if (appres.landscape) { ux = xcmax; xcmax = ycmax; ycmax = ux; } align_ellipse(); align_arc(); align_line(); align_spline(); align_compound(); align_text(); /* * Display messages indicating that distribution or alignment can't be * performed with respect to the canvas. */ if ((cur_halign == ALIGN_DISTRIB_C) || (cur_halign == ALIGN_DISTRIB_E)) put_msg("Can't DISTRIBUTE horizontally with respect to the canvas"); else if (cur_halign == ALIGN_ABUT) put_msg("Can't ABUT horizontally with respect to the canvas"); if ((cur_valign == ALIGN_DISTRIB_C) || (cur_valign == ALIGN_DISTRIB_E)) put_msg("Can't DISTRIBUTE vertically with respect to the canvas"); else if (cur_valign == ALIGN_ABUT) put_msg("Can't ABUT vertically with respect to the canvas"); draw_compoundelements(cur_c, PAINT); toggle_all_compoundmarkers(); clean_up(); set_latestobjects(old_c); set_action_object(F_EDIT, O_ALL_OBJECT); set_modifiedflag(); }
void put_tbl_info ( pmsg_level level, tbl_p t ) { if ( t == NULL ) { put_msg (level, "--empty tbl desc\n"); return; } put_schema_info (level, t->sch); put_file_info (level, t->sch->name); put_msg (level, " %d records\n", t->num_records); put_msg (level, "----\n"); }
void my_send(int server_pid, char *msg) { int i; i = 0; while (msg[i]) { put_msg(server_pid, msg[i]); i++; } put_msg(server_pid, '\n'); }
static void display_record ( record r, schema_p s ) { field_desc_p f = s->first; int i = 0; for ( ; f != NULL; f = f->next, i++ ) { if ( is_int_field (f) ) put_msg (FORCE, "%20d", *(int *)r[i] ); else put_msg (FORCE, "%20s", (char *)r[i] ); } put_msg (FORCE, "\n"); }
void put_schema_info ( pmsg_level level, schema_p s ) { if ( s == NULL ) { put_msg (level, "--empty schema\n"); return; } field_desc_p f; put_msg (level, "--schema %s: %d field(s), totally %d bytes\n", s->name, s->num_fields, s->len); for ( f = s->first; f != NULL; f = f->next) put_field_info (level, f); put_msg (level, "--\n"); }
static void create_tbl () { char tbl_name[30], field_name[30], field_type[4], separator[5]; int len; if ( fscanf (in_s, " table %s (", tbl_name) != 1) { put_msg (ERROR, "Do not know what to create\n"); return; } put_msg (DEBUG, "table name: \"%s\".\n", tbl_name); schema_p sch = get_schema (tbl_name); if ( sch != NULL ) { put_msg (ERROR, "Table \"%s\" already exists.\n", tbl_name); skip_line (); return; } sch = new_schema (tbl_name); while (!feof(in_s)) { fscanf (in_s, "%s %3s", field_name, field_type); if ( strcmp (field_type, t_int) == 0 ) { add_field ( sch, new_int_field ( field_name )); } else if ( strcmp (field_type, t_str) == 0 ) { fscanf (in_s, "(%d)", &len); add_field ( sch, new_str_field ( field_name, len )); } else { strcat (field_name, " "); strcat (field_name, field_type); syntax_error (field_name); remove_schema (sch); return; } fscanf (in_s, "%s", separator); put_msg(DEBUG, "seperator: \"%s\".\n", separator); if (separator[0] == ')') { skip_line (); break; } } }
static void put_seg_desc(void) { if(segtype != SEG_VIRTUAL) { if(segtype > SEG_END) { if(!ingroup) { long len; int i, ml; char *me; len = get_seglen(); me = msgbuf; rb->snprintf(me,MAXDESCLEN, "%4d: ", currseg); me = me+rb->strlen(me); if(segtype >= SEG_DATA && len) { rb->snprintf(me,MAXDESCLEN, "%5ld bytes, ", len); me = me+rb->strlen(me); } ml = 0; for(i = 0; seg_desc[i]; i++) { if(seg_desc[i] == '\n') { *me = '\0'; put_msg(msgbuf); me = msgbuf; rb->snprintf(me,MAXDESCLEN, " "); me = me+rb->strlen(me); ml = 0; } else { if(ml < MAXDESCLEN) *me++ = seg_desc[i]; ml++; } } *me = '\0'; put_msg(msgbuf); } else { rb->snprintf(msgbuf,MAXDESCLEN, "%4d:", currseg); put_tmp_msg(msgbuf); } } else put_msg(seg_desc); } #ifdef DEBUG_TAPE else fprintf(stderr, "virtual segment\n"); #endif }
static void show_database () { char db_token[20]; if ( fscanf (in_s, "%s", db_token) != 1) { put_msg (ERROR, "Show what?\n"); return; } if ( strcmp (db_token, t_database) != 0 ) { put_msg (ERROR, "Cannot show \"%s\".\n", db_token ); return; } put_db_info (FORCE); }
int main(void) { t_game game; if (!(WIN_VALUE % 2) && initscr()) { glob = &game; init(&game); setwins(&game); score_init(&game); while ((game.size = menu(&game) + 3) > 5) put_score(&game); if (game.size > 3 && game.size < 6) { set_plateau(&game); if (start(&game)) put_msg(game.msgbar, " GAME BEGIN", 2); play(&game); refresh(); } ft_exit("ya", &game); } else ft_putendl("Game_2048: Initialisation failed."); return (0); }
int equal_record ( record r1, record r2, schema_p s ) { if ( r1 == NULL || r2 == NULL || s == NULL ) { put_msg (ERROR, "equal_record: NULL record or schema!\n" ); return 0; } field_desc_p fd; int i = 0;; for ( fd = s->first; fd != NULL; fd = fd->next, i++) { if ( is_int_field (fd) ) { if (*(int *)r1[i] != *(int *)r2[i]) return 0; } else { if ( strcmp ((char *)r1[i], (char *)r2[i]) != 0 ) return 0; } } return 1; }
static void _zf_log_write_imp( const zf_log_spec *log, const src_location *const src, const mem_block *const mem, const int lvl, const char *const tag, const char *const fmt, va_list va) { zf_log_message msg; char buf[ZF_LOG_BUF_SZ]; const unsigned mask = log->output->mask; msg.lvl = lvl; msg.tag = tag; g_buffer_cb(&msg, buf); if (ZF_LOG_PUT_CTX & mask) { put_ctx(&msg); } if (ZF_LOG_PUT_TAG & mask) { put_tag(&msg, tag); } if (0 != src && ZF_LOG_PUT_SRC & mask) { put_src(&msg, src); } if (ZF_LOG_PUT_MSG & mask) { put_msg(&msg, fmt, va); } log->output->callback(&msg, log->output->arg); if (0 != mem && ZF_LOG_PUT_MSG & mask) { output_mem(log, &msg, mem); } }
int add_field ( schema_p s, field_desc_p f ) { if ( s == NULL ) return -1; if ( s->len + f->len > BLOCK_SIZE - PAGE_HEADER_SIZE ) { put_msg (ERROR, "schema already has %d bytes, adding %d will exceed limited %d bytes.\n", s->len, f->len, BLOCK_SIZE - PAGE_HEADER_SIZE); return -1; } if ( s->num_fields == 0) { s->first = f; f->offset = 0; } else { s->last->next = f; f->offset = s->len; } s->last = f; s->num_fields++; s->len += f->len; return s->num_fields; }
int write_objects(FILE *fp) { F_arc *a; F_compound *c; F_ellipse *e; F_line *l; F_spline *s; F_text *t; /* * A 2 for the orientation means that the origin (0,0) is at the upper * left corner of the screen (2nd quadrant). */ if (!update_figs) put_msg("Writing . . ."); #ifdef I18N /* set the numeric locale to C so we get decimal points for numbers */ setlocale(LC_NUMERIC, "C"); #endif /* I18N */ write_fig_header(fp); for (a = objects.arcs; a != NULL; a = a->next) { num_object++; write_arc(fp, a); } for (c = objects.compounds; c != NULL; c = c->next) { num_object++; write_compound(fp, c); } for (e = objects.ellipses; e != NULL; e = e->next) { num_object++; write_ellipse(fp, e); } for (l = objects.lines; l != NULL; l = l->next) { num_object++; write_line(fp, l); } for (s = objects.splines; s != NULL; s = s->next) { num_object++; write_spline(fp, s); } for (t = objects.texts; t != NULL; t = t->next) { num_object++; write_text(fp, t); } #ifdef I18N /* reset to original locale */ setlocale(LC_NUMERIC, ""); #endif /* I18N */ if (ferror(fp)) { fclose(fp); return (-1); } if (fclose(fp) == EOF) return (-1); return (0); }
int write_file(char *file_name, Boolean update_recent) { FILE *fp; if (!ok_to_write(file_name, "SAVE")) return (-1); if ((fp = fopen(file_name, "wb")) == NULL) { file_msg("Couldn't open file %s, %s", file_name, strerror(errno)); beep(); return (-1); } num_object = 0; if (write_objects(fp)) { file_msg("Error writing file %s, %s", file_name, strerror(errno)); beep(); exit (2); return (-1); } if (!update_figs) put_msg("%d object(s) saved in \"%s\"", num_object, file_name); /* update the recent list if caller desires */ if (update_recent) update_recent_list(file_name); return (0); }
static void * msgqueueping(void *arg) { queuepair_t *qpair; size_t size; int *ret; int i; int tmp; int *counter; ret = Malloc(sizeof(int)); *ret = 0; qpair = (queuepair_t *)arg; for (i=0; i < LOOPSIZE; i++) { size = get_msg_timed(qpair->inq, &counter, sizeof(int *), TIMELIMIT); if (size == 0) { printf(" timeout\n"); goto OUT; } else { /* avoid ++ to lure out concurrency problems */ tmp = *counter + 1; usleep(1000); *counter = tmp; put_msg(qpair->outq, &counter, sizeof(int *)); } } OUT: pthread_exit(ret); }
void interpret ( int argc, char* argv[] ) { init_with_options (argc, argv); //test_rec_write("test"); char token[30]; while (!feof(in_s)) { fscanf (in_s, "%s", token); put_msg (DEBUG, "current token is \"%s\".\n", token); if (strcmp(token, t_quit) == 0) { quit(); break;} if (token[0] == '#') { skip_line (); continue; } if (strcmp(token, t_help) == 0) { show_help_info (); continue; } if (strcmp(token, t_database) == 0) { set_database(); continue; } if (strcmp(token, t_show) == 0) { show_database(); continue; } if (strcmp(token, t_print) == 0) { print_str(); continue; } if (strcmp(token, t_create) == 0) { create_tbl(); continue; } if (strcmp(token, t_drop) == 0) { drop_tbl(); continue; } if (strcmp(token, t_insert) == 0) { insert_row(); continue; } if (strcmp(token, t_select) == 0) { select_rows(); continue; } syntax_error (token); } }
static void _bt_log_write_imp( const bt_log_spec *log, const src_location *const src, const mem_block *const mem, const int lvl, const char *const tag, const char *const fmt, va_list va) { bt_log_message msg; char buf[BT_LOG_BUF_SZ]; const unsigned mask = log->output->mask; msg.lvl = lvl; msg.tag = tag; g_buffer_cb(&msg, buf); const char *rst_color_p = bt_common_color_reset(); const char *rst_color_e = rst_color_p + strlen(rst_color_p); const char *color_p = ""; const char *color_e = color_p; switch (lvl) { case BT_LOG_INFO: color_p = bt_common_color_fg_blue(); color_e = color_p + strlen(color_p); break; case BT_LOG_WARN: color_p = bt_common_color_fg_yellow(); color_e = color_p + strlen(color_p); break; case BT_LOG_ERROR: case BT_LOG_FATAL: color_p = bt_common_color_fg_red(); color_e = color_p + strlen(color_p); break; default: break; } msg.p = put_stringn(color_p, color_e, msg.p, msg.e); if (BT_LOG_PUT_CTX & mask) { put_ctx(&msg); } if (BT_LOG_PUT_TAG & mask) { put_tag(&msg, tag); } if (0 != src && BT_LOG_PUT_SRC & mask) { put_src(&msg, src); } if (BT_LOG_PUT_MSG & mask) { put_msg(&msg, fmt, va); } msg.p = put_stringn(rst_color_p, rst_color_e, msg.p, msg.e); log->output->callback(&msg, log->output->arg); if (0 != mem && BT_LOG_PUT_MSG & mask) { output_mem(log, &msg, mem); } }
void put_selected(void) { int i, x,y; char *com; set_mousefun("place object","new object","cancel library", "place and edit","change draw mode", "place at orig posn"); set_action_on(); cur_c = lib_compounds[cur_library_object]->compound; new_c = copy_compound(cur_c); /* add it to the depths so it is displayed */ add_compound_depth(new_c); /* find lower-right corner for draw_box() */ off_library_x = new_c->secorner.x; off_library_y = new_c->secorner.y; /* and upper-left in case the user wants to place it at its original position */ /* this is saved here because the compound was shifted to 0,0 when reading in */ orig_put_x = lib_compounds[cur_library_object]->corner.x; orig_put_y = lib_compounds[cur_library_object]->corner.y; canvas_locmove_proc = init_move_object; canvas_ref_proc = null_proc; canvas_leftbut_proc = place_lib_object; canvas_middlebut_proc = sel_place_lib_obj_proc; canvas_rightbut_proc = cancel_place_lib_obj; set_cursor(null_cursor); /* get the pointer position */ get_pointer_win_xy(&x, &y); /* draw the first image */ init_move_object(BACKX(x), BACKY(y)); /* message that we're placing object so and so */ com = strdup(lib_compounds[cur_library_object]->compound->comments); if (strlen(com)) { /* change newlines to blanks */ for (i=strlen(com); i>=0; i--) if (com[i] == '\n') com[i] = ' '; put_msg("Placing library object \"%s\" (%s.fig)", com, library_objects_texts[cur_library_object]); } else { put_msg("Placing library object %s.fig", library_objects_texts[cur_library_object]); } }
static void init_delete_point(F_line *obj, int type, int x, int y, F_point *p, F_point *q) { int n; switch (type) { case O_POLYLINE: cur_l = (F_line *) obj; /* the search routine will ensure we don't have a box */ n = num_points(cur_l->points); if (cur_l->type == T_POLYGON) { if (n <= 4) { /* count first pt twice for closed object */ put_msg("A polygon cannot have less than 3 points"); beep(); return; } } else if (n <= 1) { /* alternative would be to remove the dot altogether */ put_msg("A dot must have at least 1 point"); beep(); return; } linepoint_deleting(cur_l, p, q); break; case O_SPLINE: cur_s = (F_spline *) obj; n = num_points(cur_s->points); if (closed_spline(cur_s)) { if (n <= CLOSED_SPLINE_MIN_NUM_POINTS) { put_msg("A closed spline cannot have less than %d points", CLOSED_SPLINE_MIN_NUM_POINTS); beep(); return; } } else if (n <= OPEN_SPLINE_MIN_NUM_POINTS) { put_msg("A spline cannot have less than %d points", OPEN_SPLINE_MIN_NUM_POINTS); beep(); return; } splinepoint_deleting(cur_s, p, q); break; default: return; } }
int schema_num_flds ( schema_p sch ) { if ( sch == NULL ) { put_msg (ERROR, "schema_num_flds: NULL schema.\n"); return -1; } return sch->num_fields; }
field_desc_p schema_last_fld_desc ( schema_p sch ) { if ( sch == NULL ) { put_msg (ERROR, "schema_last_fld_desc: NULL schema.\n"); return NULL; } return sch->last; }
int schema_len ( schema_p sch ) { if ( sch == NULL ) { put_msg (ERROR, "schema_len: NULL schema.\n"); return -1; } return sch->len; }
void put_field_info ( pmsg_level level, field_desc_p f ) { if ( f == NULL ) { put_msg (level, " empty field\n"); return; } put_msg (level, " \"%s\", ", f->name); if ( is_int_field (f) ) append_msg (level, "int "); else append_msg (level, "str "); append_msg (level, "field, len: %d, offset: %d, ", f->len, f->offset); if (f->next != NULL) append_msg (level, ", next field: %s\n", f->next->name); else append_msg (level, "\n"); }