void builtin_fc_list(t_argparser_result *result) { int first_index; int second_index; t_line *save; if (!history_get_first(edit_singleton()->history)) save = NULL; else { save = line_copy(history_get_from_last(edit_singleton()->history, 0)); history_pop_last(edit_singleton()->history); } builtin_fc_list_get_indexes(result, &first_index, &second_index); if (first_index == -1 || second_index == -1) { shenv_singl_error(1, "fc: history specification out of range"); return ; } if (argparser_result_opt_is_set(result, "r")) list_reverse(result, first_index, second_index); else list_normal(result, first_index, second_index); if (save) history_push(edit_singleton()->history, save); }
void line_list_copy(line_list_t *copyer, line_list_t *copee) { dlink_t *a, *b; assert(copyer); assert(copee); assert(line_list_get_count(copyer) == line_list_get_count(copee)); a = copyer->tail->next; for (b = copee->tail->next; b != copee->head; b = b->next) { line_copy((line_t *)a->object, (line_t *)b->object); a = a->next; } }
/* * Allocate an Element and store a duplicate of the data pointed to by * obj in the Element. Modules do not get duplicated. The function needs * to handle each type of object separately in a case statement. */ Element *element_init(ObjectType type, void *obj){ Element *e = malloc(sizeof(Element)); if(!e){ printf("malloc failed in element_init\n"); return NULL; } e->type = type; e->next = NULL; switch (e->type) { case ObjNone: printf("ObjNone not implemented in element_init\n"); break; case ObjLine: line_copy(&(e->obj.line), (Line*)obj); break; case ObjPoint: point_copy(&(e->obj.point), (Point*)obj); break; case ObjPolyline: polyline_init(&(e->obj.polyline)); polyline_copy(&(e->obj.polyline), (Polyline*)obj); break; case ObjPolygon: polygon_init(&(e->obj.polygon)); polygon_copy(&(e->obj.polygon), (Polygon*)obj); break; case ObjIdentity: break; case ObjMatrix: matrix_copy(&(e->obj.matrix), (Matrix*)obj); break; case ObjColor: case ObjBodyColor: case ObjSurfaceColor: color_copy(&(e->obj.color), (Color*)obj); break; case ObjSurfaceCoeff: e->obj.coeff = *(float*)obj; break; case ObjLight: printf("ObjLight not implemented in element_init\n"); break; case ObjModule: e->obj.module = obj; break; default: printf("ObjectType %d is not handled in element_init\n",type); } return e; }
static bool engine_step() { char string[StringSize]; int event; engine_get(Engine,string,StringSize); event = uci_parse(Uci,string); if ((event & EVENT_MOVE) != 0) { return false; } if ((event & EVENT_PV) != 0) { LastMove = Uci->best_pv[0]; LastDepth = Uci->best_depth; LastSelDepth = Uci->best_sel_depth; LastScore = Uci->best_score; LastTime = Uci->time; LastNodeNb = Uci->node_nb; line_copy(LastPV,Uci->best_pv); if (LastMove != FirstMove) { FirstMove = LastMove; FirstDepth = LastDepth; FirstSelDepth = LastSelDepth; FirstScore = LastScore; FirstTime = LastTime; FirstNodeNb = LastNodeNb; line_copy(FirstPV,LastPV); } } return true; }
/** * Parse a "$FLYSEN" sentence. * * @see http://www.flytec.ch/public/Special%20NMEA%20sentence.pdf */ bool FlytecDevice::ParseFLYSEN(NMEAInputLine &line, NMEAInfo &info) { // Detect firmware/sentence version // // V or A in field 9 -> 3.31- // V or A in field 10 -> 3.32+ NMEAInputLine line_copy(line); line_copy.Skip(8); bool has_date_field = false; char validity = line_copy.ReadFirstChar(); if (validity != 'A' && validity != 'V') { validity = line_copy.ReadFirstChar(); if (validity != 'A' && validity != 'V') return false; has_date_field = true; } // Date(ddmmyy), 6 Digits (only in firmware version 3.32+) if (has_date_field) NMEAParser::ReadDate(line, info.date_time_utc); // Time(hhmmss), 6 Digits fixed time; if (NMEAParser::ReadTime(line, info.date_time_utc, time) && !NMEAParser::TimeHasAdvanced(time, last_time, info)) return true; if (validity == 'V') { // In case of V (void=not valid) GPS data should not be used. // GPS altitude, position and speed should be ignored. line.Skip(7); } else { // Latitude(ddmm.mmm), 8 Digits incl. decimal // N (or S), 1 Digit // Longitude(dddmm.mmm), 9 Digits inc. decimal // E (or W), 1 Digit GeoPoint location; if (NMEAParser::ReadGeoPoint(line, location)) { info.location = location; info.location_available.Update(info.clock); } // Track (xxx Deg), 3 Digits fixed track; if (line.ReadChecked(track)) { info.track = Angle::Degrees(track); info.track_available.Update(info.clock); } // Speed over Ground (xxxxx dm/s), 5 Digits fixed ground_speed; if (line.ReadChecked(ground_speed)) { info.ground_speed = ground_speed / 10; info.ground_speed_available.Update(info.clock); } // GPS altitude (xxxxx meter), 5 Digits fixed gps_altitude; if (line.ReadChecked(gps_altitude)) { info.gps_altitude = gps_altitude; info.gps_altitude_available.Update(info.clock); } } // Validity of 3 D fix A or V, 1 Digit line.Skip(); // Satellites in Use (0 to 12), 2 Digits unsigned satellites_used; if (line.ReadChecked(satellites_used)) { info.gps.satellites_used = satellites_used; info.gps.satellites_used_available.Update(info.clock); } // Raw pressure (xxxxxx Pa), 6 Digits fixed pressure; if (line.ReadChecked(pressure)) info.ProvideStaticPressure(AtmosphericPressure::Pascal(pressure)); // Baro Altitude (xxxxx meter), 5 Digits (-xxxx to xxxxx) (Based on 1013.25hPa) fixed baro_altitude; if (line.ReadChecked(baro_altitude)) info.ProvidePressureAltitude(baro_altitude); // Variometer (xxxx cm/s), 4 or 5 Digits (-9999 to 9999) fixed vario; if (line.ReadChecked(vario)) info.ProvideTotalEnergyVario(vario / 100); // True airspeed (xxxxx dm/s), 5 Digits fixed tas; if (line.ReadChecked(tas)) info.ProvideTrueAirspeed(tas / 10); // Airspeed source P or V, 1 Digit P= pitot, V = Vane wheel line.Skip(); // Temp. PCB (xxx °C), 3 Digits fixed pcb_temperature; bool pcb_temperature_available = line.ReadChecked(pcb_temperature); // Temp. Balloon Envelope (xxx °C), 3 Digits fixed balloon_temperature; bool balloon_temperature_available = line.ReadChecked(balloon_temperature); if (balloon_temperature_available) { info.temperature = CelsiusToKelvin(balloon_temperature); info.temperature_available = true; } else if (pcb_temperature_available) { info.temperature = CelsiusToKelvin(pcb_temperature); info.temperature_available = true; } // Battery Capacity Bank 1 (0 to 100%) 3 Digits fixed battery_level_1; bool battery_level_1_available = line.ReadChecked(battery_level_1); // Battery Capacity Bank 2 (0 to 100%) 3 Digits fixed battery_level_2; bool battery_level_2_available = line.ReadChecked(battery_level_2); if (battery_level_1_available) { if (battery_level_2_available) info.battery_level = (battery_level_1 + battery_level_2) / 2; else info.battery_level = battery_level_1; info.battery_level_available.Update(info.clock); } else if (battery_level_2_available) { info.battery_level = battery_level_2; info.battery_level_available.Update(info.clock); } // Dist. to WP (xxxxxx m), 6 Digits (Max 200000m) // Bearing (xxx Deg), 3 Digits // Speed to fly1 (MC0 xxxxx cm/s), 5 Digits // Speed to fly2 (McC. xxxxx cm/s) 5 Digits // Keypress Code (Experimental empty to 99) 2 Digits return true; }
static int parse_info(uci_t * uci, const char string[]) { int event; parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; int n; int multipvline=0; sint64 ln; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init event = EVENT_NONE; strcpy(command,"info"); parse_open(parse,string); parse_add_keyword(parse,"cpuload"); parse_add_keyword(parse,"currline"); parse_add_keyword(parse,"currmove"); parse_add_keyword(parse,"currmovenumber"); parse_add_keyword(parse,"depth"); parse_add_keyword(parse,"hashfull"); parse_add_keyword(parse,"multipv"); parse_add_keyword(parse,"nodes"); parse_add_keyword(parse,"nps"); parse_add_keyword(parse,"pv"); parse_add_keyword(parse,"refutation"); parse_add_keyword(parse,"score"); parse_add_keyword(parse,"seldepth"); parse_add_keyword(parse,"string"); parse_add_keyword(parse,"tbhits"); parse_add_keyword(parse,"time"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"cpuload")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->cpu = double(n) / 1000.0; } else if (my_string_equal(option,"currline")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->current_line,uci->board,argument,LineSize); } else if (my_string_equal(option,"currmove")) { ASSERT(!my_string_empty(argument)); uci->root_move = move_from_can(argument,uci->board); ASSERT(uci->root_move!=MoveNone); } else if (my_string_equal(option,"currmovenumber")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1&&n<=uci->root_move_nb); if (n >= 1 && n <= uci->root_move_nb) { uci->root_move_pos = n - 1; ASSERT(uci->root_move_pos>=0&&uci->root_move_pos<uci->root_move_nb); } } else if (my_string_equal(option,"depth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1); if (n >= 0) { if (n > uci->depth) event |= EVENT_DEPTH; uci->depth = n; } } else if (my_string_equal(option,"hashfull")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->hash = double(n) / 1000.0; } else if (my_string_equal(option,"multipv")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); if(Uci->multipv_mode) multipvline=n; ASSERT(n>=1); } else if (my_string_equal(option,"nodes")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); if (ln >= 0) uci->node_nb = ln; } else if (my_string_equal(option,"nps")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->speed = double(n); } else if (my_string_equal(option,"pv")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); event |= EVENT_PV; } else if (my_string_equal(option,"refutation")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); } else if (my_string_equal(option,"score")) { ASSERT(!my_string_empty(argument)); parse_score(uci,argument); } else if (my_string_equal(option,"seldepth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->sel_depth = n; } else if (my_string_equal(option,"string")) { if(!strncmp(argument,"DrawOffer",9)) event |= EVENT_DRAW; if(!strncmp(argument,"Resign",6)) event |= EVENT_RESIGN; // TODO: argument to EOS ASSERT(!my_string_empty(argument)); } else if (my_string_equal(option,"tbhits")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); } else if (my_string_equal(option,"time")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->time = double(n) / 1000.0; } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); // update display //lousy uci,filter out lower depth multipv lines that have been repeated from the engine if(multipvline>1 && uci->depth<uci->best_depth) event &= ~EVENT_PV; if ((event & EVENT_PV) != 0) { uci->best_score = uci->score; uci->best_depth = uci->depth; if(multipvline==1)uci->depth=-1; //HACK ,clears the engine outpout window,see send_pv in adapter.cpp uci->best_sel_depth = uci->sel_depth; line_copy(uci->best_pv,uci->pv); } return event; }
/* * Draw the module into the image using the given view transformation matrix [VTM], * Lighting and DrawState by traversing the list of Elements. * (For now, Lighting can be an empty structure.) */ void module_draw(Module *md, Matrix *VTM, Matrix *GTM, DrawState *ds, Lighting *lighting, Image *src){ /* for antialiasing Module *thickLineMod = module_create(); Element *thickLineE; float dx, dy, dz, lineLength; Vector u, v, w;*/ // all locally needed variables Matrix LTM, tempGTM; Line tempLine; DrawState *tempds = drawstate_create(); Point tempPointLTM, tempPointGTM, tempPointVTM; Polyline *tempPolyline = polyline_create(); Polygon *tempPolygon = polygon_create(); Element *e = md->head; matrix_identity(<M); // loop until the end of the linked list is reached while(e){ //printf("Handling type %d\n", e->type); // draw based on type switch(e->type){ case ObjNone: break; case ObjPoint: //printf("drawing point "); // copy, xform, normalize, draw matrix_xformPoint(<M, &(e->obj.point), &tempPointLTM); matrix_xformPoint(GTM, &tempPointLTM, &tempPointGTM); matrix_xformPoint(VTM, &tempPointGTM, &tempPointVTM); point_normalize(&(tempPointVTM)); //point_print(&tempPointVTM, stdout); point_draw(&tempPointVTM, src, ds->color); break; case ObjLine: line_copy(&tempLine, &(e->obj.line)); //printf("drawing line "); // copy, xform, normalize, draw matrix_xformLine(<M, &tempLine); matrix_xformLine(GTM, &tempLine); matrix_xformLine(VTM, &tempLine); line_normalize(&tempLine); line_draw(&tempLine, src, ds->color); //line_print(&tempLine, stdout); /*if(antialias){ dx = tempLine.b.val[0]-tempLine.a.val[0]; dy = tempLine.b.val[1]-tempLine.a.val[1]; dz = tempLine.b.val[2]-tempLine.a.val[2]; lineLength = sqrt(dx*dx+dy*dy+dz*dz); module_scale( thickLineMod, 1, lineLength, 1 ); vector_set(&v, dx, dy, dz); vector_normalize(&v); vector_set(&u, -dz, dx, dy); vector_cross(&u, &v, &w); vector_cross(&v, &w, &u); vector_normalize(&u); vector_normalize(&w); module_rotateXYZ( thickLineMod, &u, &v, &w ); module_translate( thickLineMod, tempLine.a.val[0], tempLine.a.val[1], tempLine.a.val[2] ); module_cylinder( thickLineMod, 4, 1, 1, 0, 0, 0 ); thickLineE = element_init(ObjModule, thickLineMod); thickLineE->next = e->next; e->next = thickLineE; }*/ break; case ObjPolyline: //printf("drawing polyline "); // copy, xform, normalize, draw polyline_copy(tempPolyline, &(e->obj.polyline)); matrix_xformPolyline(<M, tempPolyline); matrix_xformPolyline(GTM, tempPolyline); matrix_xformPolyline(VTM, tempPolyline); polyline_normalize(tempPolyline); //polyline_print(tempPolyline, stdout); polyline_draw(tempPolyline, src, ds->color); break; case ObjPolygon: //printf("drawing polygon "); // copy, xform, normalize, draw polygon_copy(tempPolygon, &(e->obj.polygon)); matrix_xformPolygon(<M, tempPolygon); matrix_xformPolygon(GTM, tempPolygon); matrix_xformPolygon(VTM, tempPolygon); polygon_normalize(tempPolygon); //polygon_print(tempPolygon, stdout); polygon_draw(tempPolygon, src, ds); break; case ObjColor: drawstate_setColor(ds, e->obj.color); break; case ObjBodyColor: break; case ObjSurfaceColor: break; case ObjSurfaceCoeff: break; case ObjLight: break; case ObjIdentity: matrix_identity(<M); break; case ObjMatrix: matrix_multiply(&(e->obj.matrix), <M, <M); break; case ObjModule: matrix_multiply(GTM, <M, &tempGTM); drawstate_copy(tempds, ds); module_draw(e->obj.module, VTM, &tempGTM, tempds, lighting, src); break; default: printf("ObjectType %d is not handled in module_draw\n",e->type); } // advance traversal e = e->next; } // clean up polygon_free(tempPolygon); polyline_free(tempPolyline); free(tempds); }