Esempio n. 1
0
static int
bootenv_random_fill(int count)
{
	int        rc;
	boot_env_t *bep;
	int        i;
	char       name[8];
	uint64_t   objnum;
	uint64_t   timestamp;

	bep = NULL;
	rc  = bootenv_new("mytank/ROOT/workspace", 300, 9101, 0, &bep);
	if (rc < 0) {
		return (-rc);
	}
	rc = bootenv_add(&be_conf, bep);
	if (rc < 0) {
		return (-rc);
	}

	rc  = bootenv_new("abctank/ROOT/vanila", 200, 9101, 1, &bep);
	if (rc < 0) {
		return (-rc);
	}
	rc = bootenv_add(&be_conf, bep);
	if (rc < 0) {
		return (-rc);
	}

	for (i = 0; i < count; i++) {
		genname(name, sizeof(name));
		objnum    = random();
		timestamp = random();

		bep = NULL;
		rc  = bootenv_new(name, objnum, timestamp, 0, &bep);
		if (rc < 0) {
			return (-rc);
		}
		rc = bootenv_add(&be_conf, bep);
		if (rc < 0) {
			return (-rc);
		}
	}

	return (0);
}
Esempio n. 2
0
void definefilter(int *aborted)
{
	struct filterfileent ffile;
	char fntemp[14];
	struct filterlist fl;

	int pfd;
	int bw;

	get_filter_description(ffile.desc, aborted, "");

	if (*aborted)
		return;

	genname(time(NULL), fntemp);

	pfd =
	    open(get_path(T_WORKDIR, fntemp), O_CREAT | O_WRONLY | O_TRUNC,
		 S_IRUSR | S_IWUSR);
	if (pfd < 0) {
		tui_error(ANYKEY_MSG, "Cannot create filter data file");
		*aborted = 1;
		return;
	}

	close(pfd);

	pfd =
	    open(OTHIPFLNAME, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);

	if (pfd < 0) {
		listfileerr(1);
		return;
	}
	strcpy(ffile.filename, fntemp);
	bw = write(pfd, &ffile, sizeof(struct filterfileent));
	if (bw < 0)
		listfileerr(2);

	close(pfd);

	init_filter_table(&fl);
	modify_host_parameters(&fl);
	savefilter(get_path(T_WORKDIR, fntemp), &fl);
	destroyfilter(&fl);
}
Esempio n. 3
0
/** Compute graph.
 * @param graph the resulting nodes and edges will be added to this graph.
 * The graph will *not* be cleared automatically. The graph will be locked
 * while adding nodes.
 */
void
NavGraphGeneratorVoronoi::compute(fawkes::LockPtr<fawkes::NavGraph> graph)
{
	VD vd;
	for (auto o : obstacles_) {
		vd.insert(Site_2(o.first, o.second));
	}

	polygons_.clear();

	Iso_rectangle rect(Point_2(bbox_p1_x_, bbox_p1_y_), Point_2(bbox_p2_x_, bbox_p2_y_));

	std::map<std::string, Point_2> points;
	std::map<std::string, std::string> props_gen;
	props_gen["generated"] = "true";

	unsigned int num_nodes = 0;
	if (vd.is_valid()) {
		VD::Edge_iterator e;
		graph.lock();
		for (e = vd.edges_begin(); e != vd.edges_end(); ++e) {
			if (e->is_segment()) {
				if (bbox_enabled_) {
					CGAL::Bounded_side source_side, target_side;
					source_side = rect.bounded_side(e->source()->point());
					target_side = rect.bounded_side(e->target()->point());

					if (source_side == CGAL::ON_UNBOUNDED_SIDE || target_side == CGAL::ON_UNBOUNDED_SIDE)
						continue;
				}

				// check if we have a point in the vicinity
				std::string source_name, target_name;
				bool have_source = contains(points, e->source()->point(),
				                            source_name, near_threshold_);
				bool have_target = contains(points, e->target()->point(),
				                            target_name, near_threshold_);

				if (! have_source) {
					source_name = genname(num_nodes);
					//printf("Adding source %s\n", source_name.c_str());
					graph->add_node(NavGraphNode(source_name,
					                             e->source()->point().x(), e->source()->point().y(),
					                             props_gen));
					points[source_name] = e->source()->point();
				}
				if (! have_target) {
					target_name = genname(num_nodes);
					//printf("Adding target %s\n", target_name.c_str());
					graph->add_node(NavGraphNode(target_name,
					                             e->target()->point().x(), e->target()->point().y(),
					                             props_gen));
					points[target_name] = e->target()->point();
				}

				graph->add_edge(NavGraphEdge(source_name, target_name, props_gen));
			} else {
				//printf("Unbounded edge\n");
			}
		}

		// Store Polygons
		VD::Bounded_faces_iterator f;
		for (f = vd.bounded_faces_begin(); f != vd.bounded_faces_end(); ++f) {
			unsigned int num_v = 0;
			Ccb_halfedge_circulator ec_start = f->outer_ccb();
			Ccb_halfedge_circulator ec = ec_start;

			do { ++num_v; } while ( ++ec != ec_start );

			Polygon2D poly(num_v);
			size_t poly_i = 0;
			bool f_ok = true;
			do {
				const Point_2 &p = ec->source()->point();
				if (bbox_enabled_) {
					if (rect.has_on_unbounded_side(p)) {
						f_ok = false;
						break;
					}
				}
				poly[poly_i][0] = p.x();
				poly[poly_i][1] = p.y();
				++poly_i;
			} while ( ++ec != ec_start );
			if (f_ok)  polygons_.push_back(poly);
		}

		std::list<Eigen::Vector2f> node_coords;
		std::vector<NavGraphNode>::const_iterator n;
		for (n = graph->nodes().begin(); n != graph->nodes().end(); ++n) {
			node_coords.push_back(Eigen::Vector2f(n->x(), n->y()));
		}

		polygons_.remove_if([&node_coords](const Polygon2D &poly) {
				                  for (const auto nc : node_coords) {
					                  if (polygon_contains(poly, nc))  return true;
				                  }
				                  return false;
			                  }
		);

		polygons_.sort([](const Polygon2D &p1, const Polygon2D &p2)
		               {
			               return polygon_area(p2) < polygon_area(p1);
		               }
		);

		graph->calc_reachability();
		graph.unlock();
	}
}
Esempio n. 4
0
int main(int argc, char* argv[])
{
  const char *comment = "Created with Bin2Var v1.10";
  FILE *fp;
  char *buf, str[256], *c;
  int i, n, ext, n2;
  unsigned short chk;

  printf("Bin2Var v1.20 by David Phillips <*****@*****.**>\n\n");
  if (argc != 3)
    die(0);

  buf = strrchr(argv[2], '.');
  if (!buf)
    die("Output file must have an extension!\n");
  if (!stricmp(buf, ".82p"))
    ext = E_82P;
  else if (!stricmp(buf, ".83p"))
    ext = E_83P;
  else if (!stricmp(buf, ".8xp"))
    ext = E_8XP;
  else if (!stricmp(buf, ".85s"))
    ext = E_85S;
  else if (!stricmp(buf, ".86p"))
    ext = E_86P;
  else if (!stricmp(buf, ".86s"))
    ext = E_86S;
  else
    die("Extension \'%s\' is not supported!\n", buf);
  genname(argv[2], str);

  fp = fopen(argv[1], "rb");
  if (!fp)
    die("Failed to open input file: %s\n", argv[1]);
  n = fsize(fp);
  buf = (char *)malloc(n);
  fread(buf, n, 1, fp);
  if (ferror(fp))
    die("Error reading input file: %s\n", argv[1]);
  fclose(fp);
  fp = fopen(argv[2], "wb");
  if (!fp)
    die("Failed to open output file: %s\n", argv[2]);
  chk = 0;

  if (ext == E_82P)
    fwrite("**TI82**\x1a\x0a\x00", 11, 1, fp);
  else if (ext == E_83P)
    fwrite("**TI83**\x1a\x0a\x00", 11, 1, fp);
  else if (ext == E_8XP)
    fwrite("**TI83F*\x1a\x0a\x00", 11, 1, fp);
  else if (ext == E_85S)
    fwrite("**TI85**\x1a\x0c\x00", 11, 1, fp);
  else if ((ext == E_86P) || (ext == E_86S))
    fwrite("**TI86**\x1a\x0a\x00", 11, 1, fp);
  writecomment(fp, comment);
  if ((ext == E_82P) )
    i = n + 17;
  else if (ext == E_83P)
	  i = (n * 2) + 26;
  else if (ext == E_8XP)
	  i = (n * 2) + 20;
  else if (ext == E_85S)
    i = n + 10 + strlen(str);
  else
    i = n + 18;
  fwrite(&i, 2, 1, fp);
  if ((ext == E_82P) || (ext == E_83P) || (ext == E_8XP))
    cfwrite("\x0b\0x00", 2, fp, &chk);
  else if (ext == E_85S)
  {
    i = 4 + strlen(str);
    cfwrite(&i, 1, fp, &chk);
    cfwrite("\0x00", 1, fp, &chk);
  }
  else
    cfwrite("\x0c\0x00", 2, fp, &chk);
  if(ext == E_8XP)
	  i = (n * 2) + 5;
  else if(ext == E_83P)
	  i = (n * 2) + 11;
  else
	  i = n + 2;

  cfwrite(&i, 2, fp, &chk);
  if ((ext == E_82P) || (ext == E_83P) || (ext == E_8XP))
    cfwrite("\x06", 1, fp, &chk);
  else if (ext == E_86P)
    cfwrite("\x12", 1, fp, &chk);
  else if ((ext == E_85S) || (ext == E_86S))
    cfwrite("\x0c", 1, fp, &chk);
  i = strlen(str);
  if ((ext == E_85S) || (ext == E_86P) || (ext == E_86S))
    cfwrite(&i, 1, fp, &chk);
  cfwrite(str, i, fp, &chk);
  memset(str, 0, 8);
  if (ext != E_85S)
    cfwrite(str, 8 - i, fp, &chk);
  if (ext == E_8XP)
  {
	i = (n * 2) + 5;
	n2 = (n * 2) + 3;
  }
  else if (ext == E_83P)
  {
	  i = (n * 2) + 11;
	  n2 = (n * 2) + 9;
  }
  else
  {
	i = n + 2;
    n2 = n;
  }
  cfwrite(&i, 2, fp, &chk);
  cfwrite(&n2, 2, fp, &chk);
  if(ext == E_8XP)
  {
	  cfwrite("\xBB", 1, fp, &chk);
	  cfwrite("\x6C", 1, fp, &chk);
	  cfwrite("\x3F", 1, fp, &chk);
  }
  if((ext == E_83P) || (ext == E_8XP))
	  datawrite(buf, n, fp, &chk);
  else
	  cfwrite(buf, n, fp, &chk);
  if(ext == E_83P)
  {
	  cfwrite("\x3F", 1, fp, &chk);
	  cfwrite("\xD4", 1, fp, &chk);
	  cfwrite("\x3F", 1, fp, &chk);
	  cfwrite("0000", 4, fp, &chk);
	  cfwrite("\x3F", 1, fp, &chk);
	  cfwrite("\xD4", 1, fp, &chk);
  }

  fwrite(&chk, 2, 1, fp);

  if (ferror(fp))
    die("Failed writing output file: %s\n", argv[2]);
  fclose(fp);
  free(buf);
  printf("'%s' successfully converted to '%s'\n", argv[1], argv[2]);

  return 0;
}