static void print_summary(long size, char *filename)
{
	if (du_depth == 1) {
		printf("summary\n");
		print_normal(size, filename);
	}
}
int main() {
	print_seed();
	print_weibull();
	print_exponential();
	print_normal();
	print_cauchy();
	print_pareto();

	return 0;
}
int du_main(int argc, char **argv)
{
	int status = EXIT_SUCCESS;
	int i;
	int c;

	/* default behaviour */
	print = print_normal;

	/* parse argv[] */
	while ((c = getopt(argc, argv, "sl"
#ifdef BB_FEATURE_HUMAN_READABLE
"hm"
#endif
"k")) != EOF) {
			switch (c) {
			case 's':
					print = print_summary;
					break;
			case 'l':
					count_hardlinks = 1;
					break;
#ifdef BB_FEATURE_HUMAN_READABLE
			case 'h': disp_hr = 0;        break;
			case 'm': disp_hr = MEGABYTE; break;
#endif
			case 'k': break;
			default:
					show_usage();
			}
	}

	/* go through remaining args (if any) */
	if (optind >= argc) {
		if (du(".") == 0)
			status = EXIT_FAILURE;
	} else {
		long sum;

		for (i=optind; i < argc; i++) {
			if ((sum = du(argv[i])) == 0)
				status = EXIT_FAILURE;
			if(is_directory(argv[i], FALSE, NULL)==FALSE) {
				print_normal(sum, argv[i]);
			}
			reset_ino_dev_hashtable();
		}
	}

	return status;
}
Exemplo n.º 4
0
static void
print_dollarhex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
		 void * dis_info,
		 long value,
		 unsigned int attrs ATTRIBUTE_UNUSED,
		 bfd_vma pc ATTRIBUTE_UNUSED,
		 int length ATTRIBUTE_UNUSED)
{
  disassemble_info *info = (disassemble_info *) dis_info;

  info->fprintf_func (info->stream, "$%lx", value & 0xffffffff);

  if (0)
    print_normal (cd, dis_info, value, attrs, pc, length);
}
Exemplo n.º 5
0
int main(int ac, char **arv)
{
	int error;

#ifdef DEBUG
	/* logfile=/var/log/log.txt */
	create_log();
	fprintf(log_path, "ac = %d\n", ac);
	fflush(log_path);
#endif

	/* setup signal handlers */
	init_signals();

	/* printer DEVICE ID and command line option check */
	if((error = get_printer_devid()) < 0 || check_arg(ac,arv) < 0){

		/*
		   Not Canon printer
			or
		   "--gui" option not found
		*/
#ifdef DEBUG
		write_log("Now normal printing ......\n");
#endif
		print_normal();
		exit(0);
	}

	/* create semapho and other setup */
	if((error = lm_init(PRNT_PATH))){
		exit(0);
	}

	/* monitor_process/print_process/status_process start */
	lm_main_fork();

	/* delete semapho */
	remove_sem(sem_id);
	/* free memory (status monitor argv string) */
	free_arg();

#ifdef DEBUG
	write_log("LM end \n");
#endif
	exit(0);
}
Exemplo n.º 6
0
int
main(int argc, char **argv)
{
	kstat_ctl_t	*kc;
	kstat_t		*ksp;
	kstat_named_t	*knp;
	struct vcpu	*vc;
	struct core	*core;
	struct pchip	*chip;
	struct link	**ins;
	char		*s;
	int		nspec;
	int		optc;
	int		opt_s = 0;
	int		opt_p = 0;
	int		opt_v = 0;
	int		ex = 0;

	cmdname = basename(argv[0]);


	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	/* collect the kstats */
	if ((kc = kstat_open()) == NULL)
		die(_("kstat_open() failed"));

	if ((ksp = kstat_lookup(kc, "cpu_info", -1, NULL)) == NULL)
		die(_("kstat_lookup() failed"));

	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {

		if (strcmp(ksp->ks_module, "cpu_info") != 0)
			continue;
		if (kstat_read(kc, ksp, NULL) == NULL)
			die(_("kstat_read() failed"));

		vc = find_link(&vcpus, ksp->ks_instance, &ins);
		if (vc == NULL) {
			vc = zalloc(sizeof (struct vcpu));
			vc->v_link.l_id = ksp->ks_instance;
			vc->v_link_core.l_id = ksp->ks_instance;
			vc->v_link_pchip.l_id = ksp->ks_instance;
			vc->v_link.l_ptr = vc;
			vc->v_link_core.l_ptr = vc;
			vc->v_link_pchip.l_ptr = vc;
			ins_link(ins, &vc->v_link);
		}

		if ((knp = kstat_data_lookup(ksp, "state")) != NULL) {
			vc->v_state = mystrdup(knp->value.c);
		} else {
			vc->v_state = "unknown";
		}

		if ((knp = kstat_data_lookup(ksp, "cpu_type")) != NULL) {
			vc->v_cpu_type = mystrdup(knp->value.c);
		}
		if ((knp = kstat_data_lookup(ksp, "fpu_type")) != NULL) {
			vc->v_fpu_type = mystrdup(knp->value.c);
		}

		if ((knp = kstat_data_lookup(ksp, "state_begin")) != NULL) {
			vc->v_state_begin = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "clock_MHz")) != NULL) {
			vc->v_clock_mhz = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "brand")) == NULL) {
			vc->v_brand = _("(unknown)");
		} else {
			vc->v_brand = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "socket_type")) == NULL) {
			vc->v_socket = "Unknown";
		} else {
			vc->v_socket = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "implementation")) == NULL) {
			vc->v_impl = _("(unknown)");
		} else {
			vc->v_impl = mystrdup(knp->value.str.addr.ptr);
		}
		/*
		 * Legacy code removed the chipid and cpuid fields... we
		 * do the same for compatibility.  Note that the original
		 * pattern is a bit strange, and we have to emulate this because
		 * on SPARC we *do* emit these.  The original pattern we are
		 * emulating is: $impl =~ s/(cpuid|chipid)\s*\w+\s+//;
		 */
		if ((s = strstr(vc->v_impl, "chipid")) != NULL) {
			char *x = s + strlen("chipid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nochipid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nochipid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nochipid:
		if ((s = strstr(vc->v_impl, "cpuid")) != NULL) {
			char *x = s + strlen("cpuid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nocpuid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nocpuid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nocpuid:

		if ((knp = kstat_data_lookup(ksp, "chip_id")) != NULL)
			vc->v_pchip_id = knp->value.l;
		chip = find_link(&pchips, vc->v_pchip_id, &ins);
		if (chip == NULL) {
			chip = zalloc(sizeof (struct pchip));
			chip->p_link.l_id = vc->v_pchip_id;
			chip->p_link.l_ptr = chip;
			ins_link(ins, &chip->p_link);
		}
		vc->v_pchip = chip;

		if ((knp = kstat_data_lookup(ksp, "core_id")) != NULL)
			vc->v_core_id = knp->value.l;
		core = find_link(&cores, vc->v_core_id, &ins);
		if (core == NULL) {
			core = zalloc(sizeof (struct core));
			core->c_link.l_id = vc->v_core_id;
			core->c_link.l_ptr = core;
			core->c_link_pchip.l_id = vc->v_core_id;
			core->c_link_pchip.l_ptr = core;
			core->c_pchip = chip;
			ins_link(ins, &core->c_link);
			chip->p_ncore++;
			(void) find_link(&chip->p_cores, core->c_link.l_id,
			    &ins);
			ins_link(ins, &core->c_link_pchip);
		}
		vc->v_core = core;



		/* now put other linkages in place */
		(void) find_link(&chip->p_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_pchip);
		chip->p_nvcpu++;

		(void) find_link(&core->c_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_core);
		core->c_nvcpu++;
	}

	(void) kstat_close(kc);

	nspec = 0;

	while ((optc = getopt(argc, argv, "pvs")) != EOF) {
		switch (optc) {
		case 's':
			opt_s = 1;
			break;
		case 'p':
			opt_p = 1;
			break;
		case 'v':
			opt_v = 1;
			break;
		default:
			usage(NULL);
		}
	}

	while (optind < argc) {
		long id;
		char *eptr;
		struct link *l;
		id = strtol(argv[optind], &eptr, 10);
		l = find_link(&vcpus, id, NULL);
		if ((*eptr != '\0') || (l == NULL)) {
			(void) fprintf(stderr,
			    _("%s: processor %s: Invalid argument\n"),
			    cmdname, argv[optind]);
			ex = 2;
		} else {
			((struct vcpu *)l->l_ptr)->v_doit = 1;
			((struct vcpu *)l->l_ptr)->v_pchip->p_doit = 1;
			((struct vcpu *)l->l_ptr)->v_core->c_doit = 1;
		}
		nspec++;
		optind++;
	}

	if (opt_s && opt_v) {
		usage(_("options -s and -v are mutually exclusive"));
	}
	if (opt_s && nspec != 1) {
		usage(_("must specify exactly one processor if -s used"));
	}
	if (opt_v && opt_p) {
		print_vp(nspec);
	} else if (opt_s && opt_p) {
		print_ps();
	} else if (opt_p) {
		print_p(nspec);
	} else if (opt_v) {
		print_v(nspec);
	} else if (opt_s) {
		print_s();
	} else {
		print_normal(nspec);
	}

	return (ex);
}
Exemplo n.º 7
0
int
main(
	int argc,
	char ** argv
)
{
	double inset_distance = 5;
	double hole_radius = 1.15;
	const char * input_file = NULL;
	const char * output_file = NULL;
	int show_model = 0;
	int option_index = 0;

	while (1)
	{
		const int c = getopt_long(
			argc,
			argv,
			"vmI:r:i:O:",
			long_options,
			&option_index
		);
		if (c == -1)
			break;
		switch(c)
		{
		case 'm': show_model = 1; break;
		case 'v': verbose++; break;
		case 'i': inset_distance = atof(optarg); break;
		case 'r': hole_radius = atof(optarg); break;
		case 'I': input_file = optarg; break;
		case 'O': output_file = optarg; break;
		case 'h': case '?':
			usage(stdout);
			return 0;
		default:
			usage(stderr);
			return -1;
		}
	}

	int input_fd;
	if (!input_file)
	{
		fprintf(stderr, "Input STL must be specified\n");
		return -1;
	} else {
		input_fd = open(input_file, O_RDONLY);
		if (input_fd < 0)
		{
			perror(input_file);
			return -1;
		}
	}

	if (!output_file)
	{
		output_file = "stdout";
		output = stdout;
	} else {
		output = fopen(output_file, "w");
		if (!output)
		{
			perror(output_file);
			return -1;
		}
	}

	stl_3d_t * const stl = stl_3d_parse(input_fd);
	if (!stl)
	{
		fprintf(stderr, "%s: Unable to parse STL\n", input_file);
		return EXIT_FAILURE;
	}
	close(input_fd);


	if (verbose)
		fprintf(stderr,
			"%s: %d faces, %d vertex\n",
			input_file,
			stl->num_face,
			stl->num_vertex
		);

	fprintf(output, "module model() {\n"
		"render() difference() {\n"
	 	"import(\"%s\");\n",
		input_file
	);
	//printf("%%model();\n");

	int * const face_used
		= calloc(sizeof(*face_used), stl->num_face);
	const stl_vertex_t ** const vertex_list
		= calloc(sizeof(*vertex_list), stl->num_vertex);

	// for face, generate the set of coplanar points that go with it
	// and "drill" holes in the model for those corners.
	for (int i = 0 ; i < stl->num_face ; i++)
	{
		if (face_used[i])
			continue;

		const stl_face_t * const f = &stl->face[i];
		const int vertex_count = stl_trace_face(
			stl,
			f,
			vertex_list,
			face_used,
			0
		);

		refframe_t ref;
		refframe_init(
			&ref,
			f->vertex[0]->p,
			f->vertex[1]->p,
			f->vertex[2]->p
		);

		// replace the origin with the actual origin
		//ref.origin.p[0] = 0;
		//ref.origin.p[1] = 0;
		//ref.origin.p[2] = 0;

		fprintf(output, "translate([%f,%f,%f])",
			f->vertex[0]->p.p[0],
			f->vertex[0]->p.p[1],
			f->vertex[0]->p.p[2]
		);
			
		print_multmatrix(&ref, 0);
		fprintf(output, "{\n");

		// generate a bolt hole for each non-copolanar corner
		for (int j = 0 ; j < vertex_count ; j++)
		{
			double x, y;
			refframe_inset(
				&ref,
				inset_distance,
				&x,
				&y,
				vertex_list[(j+0) % vertex_count]->p,
				vertex_list[(j+1) % vertex_count]->p,
				vertex_list[(j+2) % vertex_count]->p
			);

			fprintf(output, "translate([%f,%f,0]) cylinder(r=%f, h=%f, center=true);\n",
				x,
				y,
				hole_radius,
				10.0
			);
		}

		fprintf(output, "}\n");
	}

	fprintf(output, "}\n}\n");

	if (show_model)
		fprintf(output, "model();\n");


	// For each vertex, extract a small region around the corner
	const int div = sqrt(stl->num_vertex);
	const double spacing = 32;

	for(int i = 0 ; i < stl->num_vertex ; i++)
	{
		const stl_vertex_t * const v = &stl->vertex[i];
		const v3_t origin = v->p;

		v3_t avg = {{ 0, 0, 0}};
		find_normal(stl, v, inset_distance, &avg);

		if (!show_model)
		{
			fprintf(output, "translate([%f,%f,20])", (i/div)*spacing, (i%div)*spacing);
			fprintf(output, "render() intersection()");
		}

		fprintf(output, "{\n");

		//printf("%%\n");
		if (!show_model)
		{
			print_normal(&avg, show_model);
			fprintf(output, "translate([%f,%f,%f])", 
				-origin.p[0], -origin.p[1], -origin.p[2]);
			fprintf(output, "model();\n");
			fprintf(output, "translate([0,0,-20]) cylinder(r=15,h=20);\n");
		} else {
			fprintf(output, "translate([%f,%f,%f])", 
				origin.p[0], origin.p[1], origin.p[2]);
			print_normal(&avg, show_model);
			fprintf(output, "%%translate([0,0,-20]) cylinder(r=15,h=20);\n");
		}

		//avg = v3_norm(avg);

		fprintf(output, "}\n");
	}

	return 0;
}