Пример #1
0
Файл: init.c Проект: naudhr/tup
int tup_init(void)
{
	if(find_tup_dir() != 0) {
		fprintf(stderr, "tup %s usage: tup [args]\n", tup_version());
		fprintf(stderr, "For information on Tupfiles and other commands, see the tup(1) man page.\n");
		fprintf(stderr, "No .tup directory found. Either create a Tupfile.ini file at the top of your project, or manually run 'tup init' there.\n");
		return -1;
	}
	if(tup_entry_init() < 0) {
		return -1;
	}
	if(server_pre_init() < 0) {
		return -1;
	}
	if(tup_drop_privs() < 0) {
		goto out_err;
	}
	if(open_tup_top() < 0) {
		goto out_err;
	}
	if(tup_lock_init() < 0) {
		goto out_err;
	}
	color_init();
	if(tup_db_open() != 0) {
		goto out_unlock;
	}
	return 0;

out_unlock:
	tup_lock_exit();
out_err:
	server_post_exit();
	return -1;
}
Пример #2
0
static WidgetInfo *
create_color_scale (void)
{
  GtkWidget *vbox;
  GtkWidget *scale;
  GtkWidget *align;
  GimpRGB    rgb;
  GimpHSV    hsv;

  color_init (&rgb);
  gimp_rgb_to_hsv (&rgb, &hsv);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  align = gtk_alignment_new (0.5, 0.5, 0.8, 0.0);
  scale = gimp_color_scale_new (GTK_ORIENTATION_HORIZONTAL,
                                GIMP_COLOR_SELECTOR_HUE);
  gimp_color_scale_set_color (GIMP_COLOR_SCALE (scale), &rgb, &hsv);
  gtk_range_set_value (GTK_RANGE (scale), 40);
  gtk_container_add (GTK_CONTAINER (align), scale);
  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Color Scale"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-color-scale", vbox, SMALL);
}
Пример #3
0
Color *color_create(double red, double green, double blue) {
  Color *color = memory_alloc(sizeof(Color));
  if (color != NULL) {
    color_init(color, red, green, blue);
  }
  return color; 
}
Пример #4
0
/**
 * This function initializes the PWM Channels and the UART
 */
void init()
{
	color_init();
	uart_init();

	//Interrupts enable
	sei();
}
Пример #5
0
static void init_ncurses(void)
{
  initscr();

  timeout(1); // enable the non block getch()
  curs_set(0); // cursor invisible
  noecho();
  keypad(stdscr, TRUE); // enable getch() get KEY_UP/DOWN
  color_init();
}
Пример #6
0
int main(int argc, char *argv[])
{
	int ret;
	if (argc < 2)
		usage(EXIT_FAILURE);
	color_init(false);
	ret = parseargs(argc, argv);
	fclose(stdout);
	return ret;
}
Пример #7
0
void	start_graph(void)
{
	initscr();
	raw();
	color_init();
	curs_set(0);
	cbreak();
	noecho();
	nodelay(stdscr, TRUE);
	scrollok(stdscr, TRUE);
	draw_border();
}
Пример #8
0
static void DoRenderFloodFillRGB(T** data, int width, int height, int start_x, int start_y, float* replace_data, float tolerance)
{
  T *r = data[0], *g = data[1], *b = data[2];
  int offset, x, y;
  T target_color[3];
  T replace_color[3];
  T tol = (T)tolerance;

  replace_color[0] = (T)replace_data[0];
  replace_color[1] = (T)replace_data[1];
  replace_color[2] = (T)replace_data[2];

  offset = start_y * width + start_x;
  if (color_equal(replace_color, r[offset], g[offset], b[offset]))
    return;

  color_init(target_color, r[offset], g[offset], b[offset]);

  /* very simple 4 neighbors stack based flood fill */

  xyStackArray* stack = xyStackArrayCreate();

  /* a color in the xy_stack is always similar to the target color,
  and it was already replaced */
  xyStackArrayPush(stack, start_x, start_y);
  color_copy(replace_color, r[offset], g[offset], b[offset]);

  while (xyStackArrayHasData(stack))
  {
    xyStackArrayPop(stack, x, y);

    /* right */
    if (x < width - 1)
      fill_color(stack, replace_color, target_color, r, g, b, width, x + 1, y, tol);

    /* left */
    if (x > 0)
      fill_color(stack, replace_color, target_color, r, g, b, width, x - 1, y, tol);

    /* top */
    if (y < height - 1)
      fill_color(stack, replace_color, target_color, r, g, b, width, x, y + 1, tol);

    /* bottom */
    if (y > 0)
      fill_color(stack, replace_color, target_color, r, g, b, width, x, y - 1, tol);
  }

  xyStackArrayDestroy(stack);
}
Пример #9
0
void ritual()
{
    myusbInit();

    myBT_Init();
    line_init();
    distance_init();
    sonic_init();
    motor_init();
    motor_left_duty(10);
    motor_right_duty(10);
    color_init();
    myCmdLineInit();

}
Пример #10
0
  virtual void initializer() {
    char buffer[1024];
    snprintf(buffer, sizeof(buffer), "resources/?.lua;giggle/engine_resources/?.lua");

    // initialize globals
    color_init();

    // allow the instantiation process to make renderer calls (to
    // allocate image assets, etc)
    GIGGLE->renderer->await_initialization();
    GIGGLE->renderer->begin_frame();
    game = new Game(buffer);
    GIGGLE->renderer->end_frame();

    last_frame_ms = GIGGLE->renderer->time_millis();
  }
Пример #11
0
int main (int argc, char *argv[]) 
{
    if (!freopen("stdout.txt", "w", stdout)) {
	ERR("Failed to open stdout.txt");
    }

    if (!freopen("stderr.txt", "w", stderr)) {
	ERR("Failed to open stderr.txt");
    }

    color_init();

    if (!config_init()) {
	DIE("Config init");
    }

    if (!sdl_init(video_w, video_h)) {
	DIE("SDL init");
    }

    if (!ttf_init()) {
	DIE("TTF init");
    }

    if (!console_init()) {
	DIE("No console");
    }

    gl_enter_2d_mode();

    console_log("hello\n");
    console_log("there\n");
    console_log("thereabcdefghijklmnopqrstuvwxyz\n");
    console_log("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\n");
    sdl_loop();
    gl_leave_2d_mode();

    quit();

    LOG("Exit(0)");

    return (0);
}
Пример #12
0
/**
 * Basic (i.e. minimal) initialization of libdia. 
 *
 * It does not load any plug-ins but instead brings libdia to a state that plug-in loading can take place.
 * @param flags a set of DIA_INTERACTIVE, DIA_MESSAGE_STDERR
 */
void
libdia_init (guint flags)
{
  static gboolean initialized = FALSE;
  
  if (initialized)
    return;

  if (flags & DIA_MESSAGE_STDERR)
    set_message_func(stderr_message_internal);    
  LIBXML_TEST_VERSION;

#ifdef G_OS_WIN32
  xmlSetGenericErrorFunc(NULL, myXmlErrorReporting);
#endif

  if (flags & DIA_VERBOSE) {
    dia_log_message_enable (TRUE);
    dia_log_message ("initializing libdia");
  }
  stdprops_init();

  if (flags & DIA_INTERACTIVE) {
    char *diagtkrc;

    gtk_widget_set_default_colormap(gdk_rgb_get_cmap());

    diagtkrc = dia_config_filename("diagtkrc");
    dia_log_message ("Config from %s", diagtkrc);
    gtk_rc_parse(diagtkrc);
    g_free(diagtkrc);

    color_init();
  }
  initialized = TRUE;

  object_registry_init();

  /* The group_type is registered in app, but it needs to be exported anyway */
  object_register_type(&stdpath_type);
}
Пример #13
0
static WidgetInfo *
create_color_hex_entry (void)
{
  GtkWidget *vbox;
  GtkWidget *entry;
  GtkWidget *align;
  GimpRGB    color;

  color_init (&color);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  align = gtk_alignment_new (0.5, 0.5, 0.5, 0.0);
  entry = gimp_color_hex_entry_new ();
  gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (entry), &color);
  gtk_container_add (GTK_CONTAINER (align), entry);
  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Color Hex Entry"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-color-hex-entry", vbox, SMALL);
}
Пример #14
0
int video_init(void)
{
    XGCValues gc_values;
    Display *display;

    _video_gc = video_get_gc(&gc_values);
    display = x11ui_get_display_ptr();

    x11video_log = log_open("X11Video");

    color_init();
    
#ifdef USE_MITSHM
    if (!try_mitshm) {
        use_mitshm = 0;
    } else {
        /* This checks if the server has MITSHM extensions available
           If try_mitshm is true and we are on a different machine,
           frame_buffer_alloc will fall back to non shared memory calls. */
        int major_version, minor_version, pixmap_flag;

        /* Check whether the server supports the Shared Memory Extension. */
        if (!XShmQueryVersion(display, &major_version, &minor_version, &pixmap_flag)) {
            log_warning(x11video_log, "The MITSHM extension is not supported on this display.");
            use_mitshm = 0;
        } else {
            DEBUG_MITSHM((_("MITSHM extensions version %d.%d detected."), major_version, minor_version));
	    if (!pixmap_flag) {
		DEBUG_MITSHM(("The MITSHM extension is supported on this display, but shared pixmaps are not available."));
	    }
            use_mitshm = 1;
        }
    }

#else
    use_mitshm = 0;
#endif

    return 0;
}
Пример #15
0
static WidgetInfo *
create_color_button (void)
{
  GtkWidget *vbox;
  GtkWidget *button;
  GtkWidget *align;
  GimpRGB    color;

  color_init (&color);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  align = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
  button =  gimp_color_button_new ("Color Button",
                                   80, 20, &color,
                                   GIMP_COLOR_AREA_SMALL_CHECKS);
  gtk_container_add (GTK_CONTAINER (align), button);
  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Color Button"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-color-button", vbox, SMALL);
}
Пример #16
0
static WidgetInfo *
create_color_area (void)
{
  GtkWidget *vbox;
  GtkWidget *area;
  GtkWidget *align;
  GimpRGB    color;

  color_init (&color);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  align = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
  area = gimp_color_area_new (&color, GIMP_COLOR_AREA_SMALL_CHECKS, 0);
  gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE);
  gtk_widget_set_size_request (area, -1, 25);
  gtk_container_add (GTK_CONTAINER (align), area);
  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Color Area"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-color-area", vbox, SMALL);
}
Пример #17
0
/**
 * Basic (i.e. minimal) initialization of libdia. 
 *
 * It does not load any plug-ins but instead brings libdia to a state that plug-in loading can take place.
 * @param flags a set of DIA_INTERACTIVE, DIA_MESSAGE_STDERR
 */
void
libdia_init (guint flags)
{
  static gboolean initialized = FALSE;
  
  if (initialized)
    return;

  if (flags & DIA_MESSAGE_STDERR)
    set_message_func(stderr_message_internal);    
  LIBXML_TEST_VERSION;

#ifdef G_OS_WIN32
  xmlSetGenericErrorFunc(NULL, myXmlErrorReporting);
#endif

  if (flags & DIA_VERBOSE) {
    dia_log_message_enable (TRUE);
    dia_log_message ("initializing libdia");
  }
  stdprops_init();

  if (flags & DIA_INTERACTIVE) {
    char *diagtkrc;

    dia_image_init();

    diagtkrc = dia_config_filename("diagtkrc");
    dia_log_message ("Config from %s", diagtkrc);
    gtk_rc_parse(diagtkrc);
    g_free(diagtkrc);

    color_init();
  }
  initialized = TRUE;

  object_registry_init();
}
Пример #18
0
static WidgetInfo *
create_color_selection (void)
{
  GtkWidget *vbox;
  GtkWidget *selection;
  GtkWidget *align;
  GimpRGB    color;

  color_init (&color);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
  selection = gimp_color_selection_new ();
  gimp_color_selection_set_show_alpha(GIMP_COLOR_SELECTION (selection), TRUE);
  gimp_color_selection_set_color  (GIMP_COLOR_SELECTION (selection), &color);
  gtk_widget_set_size_request (selection, 400, -1);
  gtk_container_add (GTK_CONTAINER (align), selection);
  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox),
                      gtk_label_new ("Color Selection"), FALSE, FALSE, 0);

  return new_widget_info ("gimp-widget-color-selection", vbox, ASIS);
}
Пример #19
0
Файл: main.c Проект: NatTuck/teg
/* Initialize the server for the first game */
void game_init()
{
	player_init();
	color_init();
	pactos_init();
	scores_init();
	xmlscores_load();
	metaserver_init();

	g_game.connections = 0;
	g_game.players = 0;
	g_game.playing = 0;

	/* default values */
	g_game.fichas = 5;
	g_game.fichas2 = 3;
	g_game.mission = FALSE;
	g_game.cmission = TRUE;
	g_game.reglas = TEG_RULES_TEG;
	g_game.fog_of_war = FALSE;
	g_game.player_fow = NULL;

	game_new();
}
Пример #20
0
int
main( int argc, char **argv )
{
	int opt_id;
	char *root_dir;

	/* Initialize global variables */
	globals.fstree = NULL;
	globals.history = NULL;
	/* Set sane camera state so setup_modelview_matrix( ) in ogl.c
	 * doesn't choke. (It does get called in splash screen mode) */
	camera->fov = 45.0;
	camera->near_clip = 1.0;
	camera->far_clip = 2.0;

#ifdef DEBUG
	debug_init( );
#endif
#ifdef ENABLE_NLS
	/* Initialize internationalization (i8e i18n :-) */
	setlocale( LC_ALL, "" );
	bindtextdomain( PACKAGE, LOCALEDIR );
	textdomain( PACKAGE );
#endif

	/* Parse command-line options */
	for (;;) {
		opt_id = getopt_long( argc, argv, "", cli_opts, NULL );
		if (opt_id < 0)
			break;
		switch (opt_id) {
			case OPT_DISCV:
			/* --discv */
			initial_fsv_mode = FSV_DISCV;
			break;

			case OPT_MAPV:
			/* --mapv */
			initial_fsv_mode = FSV_MAPV;
			break;

			case OPT_TREEV:
			/* --treev */
			initial_fsv_mode = FSV_TREEV;
			break;

			case OPT_CACHEDIR:
			/* --cachedir <dir> */
			printf( "cache directory: %s\n", optarg );
			printf( "(caching not yet implemented)\n" );
			/* TODO: Implement caching */
			break;

			case OPT_NOCACHE:
			/* --nocache */
			/* TODO: Implement caching */
			break;

			case OPT_HELP:
			/* --help */
			default:
			/* unrecognized option */
			printf( _(usage_summary), argv[0] );
			fflush( stdout );
			exit( EXIT_SUCCESS );
			break;
		}
	}

	/* Determine root directory */
	if (optind < argc) {
                /* From command line */
		root_dir = xstrdup( argv[optind++] );
		if (optind < argc) {
			/* Excess arguments! */
			fprintf( stderr, _("Junk in command line:") );
			while (optind < argc)
				fprintf( stderr, " %s", argv[optind++] );
			fprintf( stderr, "\n" );
			fflush( stderr );
		}
	}
	else {
		/* Use current directory */
		root_dir = xstrdup( "." );
	}

	/* Initialize GTK+ */
	gtk_init( &argc, &argv );

	/* Check for OpenGL support */
	if (!gdk_gl_query( ))
		quit( _("fsv requires OpenGL support.") );

	window_init( initial_fsv_mode );
	color_init( );

	fsv_load( root_dir );
	xfree( root_dir );

	gtk_main( );

	return 0;
}
Пример #21
0
int plugin_main(void)
{
    int action;
    int sleep_time=DEFAULT_WAIT_TIME;
    int nb_wanted_polygons=DEFAULT_NB_POLYGONS;
    int i;
    struct polygon_fifo polygons[NB_SCREENS];
    struct polygon_move move[NB_SCREENS]; /* This describes the movement of the leading
                                             polygon, the others just follow */
    struct polygon leading_polygon[NB_SCREENS];
    FOR_NB_SCREENS(i)
    {
#ifdef HAVE_LCD_COLOR
        struct screen *display = rb->screens[i];
        if (display->is_color)
            display->set_background(LCD_BLACK);
#endif
        fifo_init(&polygons[i]);
        polygon_move_init(&move[i]);
        polygon_init(&leading_polygon[i], rb->screens[i]);
    }

#ifdef HAVE_LCD_COLOR
    struct line_color color;
    color_init(&color);
#endif

    while (true)
    {
        FOR_NB_SCREENS(i)
        {
            struct screen * display=rb->screens[i];
            if(polygons[i].nb_items>nb_wanted_polygons)
            {   /* We have too many polygons, we must drop some of them */
                fifo_pop(&polygons[i]);
            }
            if(nb_wanted_polygons==polygons[i].nb_items)
            {   /* We have the good number of polygons, we can safely drop
                the last one to add the new one later */
                fifo_pop(&polygons[i]);
            }
            fifo_push(&polygons[i], &leading_polygon[i]);

            /*
            * Then we update the leading polygon for the next round acording to
            * current move (the move may be altered in case of sreen border
            * collision)
            */
            polygon_update(&leading_polygon[i], display, &move[i]);

            /* Now the drawing part */
#ifdef HAVE_LCD_COLOR
            color_apply(&color, display);
#endif
            display->clear_display();
            polygons_draw(&polygons[i], display);
            display->update();
        }
#ifdef HAVE_LCD_COLOR
        color_change(&color);
#endif
        /* Speed handling*/
        if (sleep_time<0)/* full speed */
            rb->yield();
        else
            rb->sleep(sleep_time);
        action = pluginlib_getaction(TIMEOUT_NOBLOCK,
                                     plugin_contexts, ARRAYLEN(plugin_contexts));
        switch(action)
        {
        case DEMYSTIFY_QUIT:
            cleanup(NULL);
            return PLUGIN_OK;

        case DEMYSTIFY_ADD_POLYGON:
        case DEMYSTIFY_ADD_POLYGON_REPEAT:
            if(nb_wanted_polygons<MAX_POLYGONS)
                ++nb_wanted_polygons;
            break;

        case DEMYSTIFY_REMOVE_POLYGON:
        case DEMYSTIFY_REMOVE_POLYGON_REPEAT:
            if(nb_wanted_polygons>MIN_POLYGONS)
                --nb_wanted_polygons;
            break;

        case DEMYSTIFY_INCREASE_SPEED:
        case DEMYSTIFY_INCREASE_SPEED_REPEAT:
            if(sleep_time>=0)
                --sleep_time;
            break;

        case DEMYSTIFY_DECREASE_SPEED:
        case DEMYSTIFY_DECREASE_SPEED_REPEAT:
            ++sleep_time;
            break;

        default:
            if (rb->default_event_handler_ex(action, cleanup, NULL)
                    == SYS_USB_CONNECTED)
                return PLUGIN_USB_CONNECTED;
            break;
        }
    }
}
Пример #22
0
int export_img(struct play_s *play)
{
	/*
	 Export img uses following pipeline:

	 file -(uncompressed_buffer)->     reads data from stream file
	 unpack -(uncompressed_buffer)->   decompresses lzo/quicklz packets
	 rgb -(rgb)->               does conversion to BGR
	 scale -(scale)->           does rescaling
	 color -(color)->           applies color correction
	 img                        writes separate image files for each frame
	*/

	ps_bufferattr_t attr;
	ps_buffer_t uncompressed_buffer, compressed_buffer,
		    rgb_buffer, color_buffer, scale_buffer;
	img_t img;
	color_t color;
	scale_t scale;
	unpack_t unpack;
	rgb_t rgb;
	int ret = 0;

	if ((ret = ps_bufferattr_init(&attr)))
		goto err;

	/* buffers */
	if ((ret = ps_bufferattr_setsize(&attr, play->compressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&compressed_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_setsize(&attr, play->uncompressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&uncompressed_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&color_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&rgb_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&scale_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_destroy(&attr)))
		goto err;

	/* filters */
	if ((ret = unpack_init(&unpack, &play->glc)))
		goto err;
	if ((ret = rgb_init(&rgb, &play->glc)))
		goto err;
	if ((ret = scale_init(&scale, &play->glc)))
		goto err;
	if (play->scale_width && play->scale_height)
		scale_set_size(scale, play->scale_width, play->scale_height);
	else
		scale_set_scale(scale, play->scale_factor);
	if ((ret = color_init(&color, &play->glc)))
		goto err;
	if (play->override_color_correction)
		color_override(color, play->brightness, play->contrast,
			       play->red_gamma, play->green_gamma, play->blue_gamma);
	if ((ret = img_init(&img, &play->glc)))
		goto err;
	img_set_filename(img, play->export_filename_format);
	img_set_stream_id(img, play->export_video_id);
	img_set_format(img, play->img_format);
	img_set_fps(img, play->fps);

	/* pipeline... */
	if ((ret = unpack_process_start(unpack, &compressed_buffer, &uncompressed_buffer)))
		goto err;
	if ((ret = rgb_process_start(rgb, &uncompressed_buffer, &rgb_buffer)))
		goto err;
	if ((ret = scale_process_start(scale, &rgb_buffer, &scale_buffer)))
		goto err;
	if ((ret = color_process_start(color, &scale_buffer, &color_buffer)))
		goto err;
	if ((ret = img_process_start(img, &color_buffer)))
		goto err;

	/* ok, read the file */
	if ((ret = file_read(play->file, &compressed_buffer)))
		goto err;

	/* wait 'till its done and clean up the mess... */
	if ((ret = img_process_wait(img)))
		goto err;
	if ((ret = color_process_wait(color)))
		goto err;
	if ((ret = scale_process_wait(scale)))
		goto err;
	if ((ret = rgb_process_wait(rgb)))
		goto err;
	if ((ret = unpack_process_wait(unpack)))
		goto err;

	unpack_destroy(unpack);
	rgb_destroy(rgb);
	scale_destroy(scale);
	color_destroy(color);
	img_destroy(img);

	ps_buffer_destroy(&compressed_buffer);
	ps_buffer_destroy(&uncompressed_buffer);
	ps_buffer_destroy(&color_buffer);
	ps_buffer_destroy(&scale_buffer);
	ps_buffer_destroy(&rgb_buffer);

	return 0;
err:
	fprintf(stderr, "exporting images failed: %s (%d)\n", strerror(ret), ret);
	return ret;
}
Пример #23
0
int export_yuv4mpeg(struct play_s *play)
{
	/*
	 Export yuv4mpeg uses following pipeline:

	 file -(uncompressed_buffer)->     reads data from stream file
	 unpack -(uncompressed_buffer)->   decompresses lzo/quicklz packets
	 scale -(scale)->           does rescaling
	 color -(color)->           applies color correction
	 ycbcr -(ycbcr)->           does conversion to Y'CbCr (if necessary)
	 yuv4mpeg                   writes yuv4mpeg stream
	*/

	ps_bufferattr_t attr;
	ps_buffer_t uncompressed_buffer, compressed_buffer,
		    ycbcr_buffer, color_buffer, scale_buffer;
	yuv4mpeg_t yuv4mpeg;
	ycbcr_t ycbcr;
	scale_t scale;
	unpack_t unpack;
	color_t color;
	int ret = 0;

	if ((ret = ps_bufferattr_init(&attr)))
		goto err;

	/* buffers */
	if ((ret = ps_bufferattr_setsize(&attr, play->compressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&compressed_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_setsize(&attr, play->uncompressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&uncompressed_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&color_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&ycbcr_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&scale_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_destroy(&attr)))
		goto err;

	/* initialize filters */
	if ((ret = unpack_init(&unpack, &play->glc)))
		goto err;
	if ((ret = ycbcr_init(&ycbcr, &play->glc)))
		goto err;
	ycbcr_set_levels(ycbcr, play->tv_levels);
	if ((ret = scale_init(&scale, &play->glc)))
		goto err;
	if (play->scale_width && play->scale_height)
		scale_set_size(scale, play->scale_width, play->scale_height);
	else
		scale_set_scale(scale, play->scale_factor);
	if ((ret = color_init(&color, &play->glc)))
		goto err;
	if (play->override_color_correction)
		color_override(color, play->brightness, play->contrast,
			       play->red_gamma, play->green_gamma, play->blue_gamma);
	if ((ret = yuv4mpeg_init(&yuv4mpeg, &play->glc)))
		goto err;
	yuv4mpeg_set_fps(yuv4mpeg, play->fps);
	yuv4mpeg_set_stream_id(yuv4mpeg, play->export_video_id);
	yuv4mpeg_set_interpolation(yuv4mpeg, play->interpolate);
	yuv4mpeg_set_filename(yuv4mpeg, play->export_filename_format);

	/* construct the pipeline */
	if ((ret = unpack_process_start(unpack, &compressed_buffer, &uncompressed_buffer)))
		goto err;
	if ((ret = scale_process_start(scale, &uncompressed_buffer, &scale_buffer)))
		goto err;
	if ((ret = color_process_start(color, &scale_buffer, &color_buffer)))
		goto err;
	if ((ret = ycbcr_process_start(ycbcr, &color_buffer, &ycbcr_buffer)))
		goto err;
	if ((ret = yuv4mpeg_process_start(yuv4mpeg, &ycbcr_buffer)))
		goto err;

	/* feed it with data */
	if ((ret = file_read(play->file, &compressed_buffer)))
		goto err;

	/* threads will do the dirty work... */
	if ((ret = yuv4mpeg_process_wait(yuv4mpeg)))
		goto err;
	if ((ret = color_process_wait(color)))
		goto err;
	if ((ret = scale_process_wait(scale)))
		goto err;
	if ((ret = ycbcr_process_wait(ycbcr)))
		goto err;
	if ((ret = unpack_process_wait(unpack)))
		goto err;

	unpack_destroy(unpack);
	ycbcr_destroy(ycbcr);
	scale_destroy(scale);
	color_destroy(color);
	yuv4mpeg_destroy(yuv4mpeg);

	ps_buffer_destroy(&compressed_buffer);
	ps_buffer_destroy(&uncompressed_buffer);
	ps_buffer_destroy(&color_buffer);
	ps_buffer_destroy(&scale_buffer);
	ps_buffer_destroy(&ycbcr_buffer);

	return 0;
err:
	fprintf(stderr, "exporting yuv4mpeg failed: %s (%d)\n", strerror(ret), ret);
	return ret;
}
Пример #24
0
int play_stream(struct play_s *play)
{
	/*
	 Playback uses following pipeline:

	 file -(uncompressed)->     reads data from stream file
	 unpack -(uncompressed)->   decompresses lzo/quicklz packets
	 rgb -(rgb)->               does conversion to BGR
	 scale -(scale)->           does rescaling
	 color -(color)->           applies color correction
	 demux -(...)-> gl_play, alsa_play

	 Each filter, except demux and file, has glc_threads_hint(glc) worker
	 threads. Packet order in stream is preserved. Demux creates
	 separate buffer and _play handler for each video/audio stream.
	*/

	ps_bufferattr_t attr;
	ps_buffer_t uncompressed_buffer, compressed_buffer,
		    rgb_buffer, color_buffer, scale_buffer;
	demux_t demux;
	color_t color;
	scale_t scale;
	unpack_t unpack;
	rgb_t rgb;
	int ret = 0;

	if ((ret = ps_bufferattr_init(&attr)))
		goto err;

	/*
	 'compressed_buffer' buffer holds raw data from file and
	 has its own size.
	*/
	if ((ret = ps_bufferattr_setsize(&attr, play->compressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&compressed_buffer, &attr)))
		goto err;

	/* rest use 'uncompressed_buffer' size */
	if ((ret = ps_bufferattr_setsize(&attr, play->uncompressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&uncompressed_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&color_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&rgb_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&scale_buffer, &attr)))
		goto err;

	/* no longer necessary */
	if ((ret = ps_bufferattr_destroy(&attr)))
		goto err;

	/* init filters */
	if ((ret = unpack_init(&unpack, &play->glc)))
		goto err;
	if ((ret = rgb_init(&rgb, &play->glc)))
		goto err;
	if ((ret = scale_init(&scale, &play->glc)))
		goto err;
	if (play->scale_width && play->scale_height)
		scale_set_size(scale, play->scale_width, play->scale_height);
	else
		scale_set_scale(scale, play->scale_factor);
	if ((ret = color_init(&color, &play->glc)))
		goto err;
	if (play->override_color_correction)
		color_override(color, play->brightness, play->contrast,
			       play->red_gamma, play->green_gamma, play->blue_gamma);
	if ((ret = demux_init(&demux, &play->glc)))
		goto err;
	demux_set_video_buffer_size(demux, play->uncompressed_size);
	demux_set_audio_buffer_size(demux, play->uncompressed_size / 10);
	demux_set_alsa_playback_device(demux, play->alsa_playback_device);

	/* construct a pipeline for playback */
	if ((ret = unpack_process_start(unpack, &compressed_buffer, &uncompressed_buffer)))
		goto err;
	if ((ret = rgb_process_start(rgb, &uncompressed_buffer, &rgb_buffer)))
		goto err;
	if ((ret = scale_process_start(scale, &rgb_buffer, &scale_buffer)))
		goto err;
	if ((ret = color_process_start(color, &scale_buffer, &color_buffer)))
		goto err;
	if ((ret = demux_process_start(demux, &color_buffer)))
		goto err;

	/* the pipeline is ready - lets give it some data */
	if ((ret = file_read(play->file, &compressed_buffer)))
		goto err;

	/* we've done our part - just wait for the threads */
	if ((ret = demux_process_wait(demux)))
		goto err; /* wait for demux, since when it quits, others should also */
	if ((ret = color_process_wait(color)))
		goto err;
	if ((ret = scale_process_wait(scale)))
		goto err;
	if ((ret = rgb_process_wait(rgb)))
		goto err;
	if ((ret = unpack_process_wait(unpack)))
		goto err;

	/* stream processed - clean up time */
	unpack_destroy(unpack);
	rgb_destroy(rgb);
	scale_destroy(scale);
	color_destroy(color);
	demux_destroy(demux);

	ps_buffer_destroy(&compressed_buffer);
	ps_buffer_destroy(&uncompressed_buffer);
	ps_buffer_destroy(&color_buffer);
	ps_buffer_destroy(&scale_buffer);
	ps_buffer_destroy(&rgb_buffer);

	return 0;
err:
	if (!ret) {
		fprintf(stderr, "playing stream failed: initializing filters failed\n");
		return EAGAIN;
	} else {
		fprintf(stderr, "playing stream failed: %s (%d)\n", strerror(ret), ret);
		return ret;
	}
}
Пример #25
0
Файл: pixbuf.c Проект: GNOME/dia
DIA_PLUGIN_CHECK_INIT

PluginInitResult
dia_plugin_init(PluginInfo *info)
{
  /*
   * If GTK is not initialized yet don't register this plug-in. This is
   * almost the same as app_is_interactive() but avoids to make plug-ins
   * depend on Dia's app core function. Also what we really need is a 
   * display, not an interactive app ;)
   */
  if (gdk_display_get_default ()) {
    if (!dia_plugin_info_init(info, "Pixbuf",
			      _("gdk-pixbuf-based bitmap export/import"),
			      _plugin_can_unload,
                              _plugin_unload))
      return DIA_PLUGIN_INIT_ERROR;
    else {
      GSList* formats = gdk_pixbuf_get_formats ();
      GSList* sl;

      /* if we get this far we still may be running non-interactive. To avoid complains
       * from color_convert() we are initializing ourselves ;)
       */
     color_init ();

     /*
      * Instead of hard-coding capabilities, ask GdkPixbuf what's installed
      */
     for (sl = formats; sl != NULL; sl = g_slist_next (sl)) {
        GdkPixbufFormat* format = (GdkPixbufFormat*)sl->data;

        if (gdk_pixbuf_format_is_writable (format)) {
          DiaExportFilter* efilter = g_new0 (DiaExportFilter, 1);
          gchar* name;

          name = gdk_pixbuf_format_get_name (format);
          /* the pixbuf desriptions are too generic for Dia's usage, make our own */
          efilter->description = g_strdup_printf ("Pixbuf[%s]", name);
          /* NOT: gdk_pixbuf_format_get_description (format); */
          efilter->extensions = (const gchar**)gdk_pixbuf_format_get_extensions (format);
          efilter->export_func = export_data;
          efilter->user_data = g_strdup (name);
          efilter->unique_name = g_strdup_printf ("pixbuf-%s", (gchar*)efilter->user_data);
          g_free (name);
          _export_filters = g_list_append (_export_filters, efilter);
          filter_register_export(efilter);
        }
        /* there is no write only filter */
        {
          DiaImportFilter* ifilter;
          gchar* name;

          name = gdk_pixbuf_format_get_name (format);
          /* filter out the less useful ones to keep the total list reasonable short 
           * (If anyone complains make it configurable via persistence and this default ;-)
           */
          if (   strcmp (name, "ani") == 0
              || strcmp (name, "ico") == 0
              || strcmp (name, "pcx") == 0
              || strcmp (name, "pnm") == 0
              || strcmp (name, "ras") == 0
              || strcmp (name, "tiff") == 0
              || strcmp (name, "wbmp") == 0
              || strcmp (name, "xbm") == 0)
            {
              g_free (name);
              continue;
            }
	  ifilter = g_new0 (DiaImportFilter, 1);
          /* the pixbuf desriptions are too generic for Dia's usage, make our own */
          ifilter->description = g_strdup_printf ("Pixbuf[%s]", name);
          ifilter->extensions = (const gchar**)gdk_pixbuf_format_get_extensions (format);
          ifilter->import_func = import_data;
          ifilter->user_data = gdk_pixbuf_format_get_name (format);
          /* they are in differnt namespaces aren't they? */
          ifilter->unique_name = g_strdup_printf ("pixbuf-%s", name);
	  /* don't use pixbuf loader for vector formats */
	  if (   strcmp (name, "svg") == 0
	      || strcmp (name, "svgz") == 0
	      || strcmp (name, "wmf") == 0
	      || strcmp (name, "emf") == 0)
	    ifilter->hints = FILTER_DONT_GUESS;
          g_free (name);
          _import_filters = g_list_append (_import_filters, ifilter);
          filter_register_import(ifilter);
        }
      }
      g_slist_free (formats);
    }
  }

  return DIA_PLUGIN_INIT_OK;
}
Пример #26
0
void mtr_init(void)
{
    num_std_materials = MATERIAL_MAX;

    color_init();

    std_material =
	(struct material_st *)malloc(sizeof(struct material_st) *
				     num_std_materials);
    if (std_material == NULL) {
	perror("Cannot allocate memory for std_material.\n");
	exit(EXIT_FAILURE);
    }

    int mat = 0;
    GLfloat color[4];

    mat = MATERIAL_NONE;
    mtr_get_std_color(COLOR_NONE, color);
    copy_material(black_mat, &(std_material[mat]));
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("none");

    mat = MATERIAL_WHITE;
    mtr_get_std_color(COLOR_WHITE, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("white");

    mat = MATERIAL_BLACK;
    mtr_get_std_color(COLOR_BLACK, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("black");

    mat = MATERIAL_RED;
    mtr_get_std_color(COLOR_RED, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("red");

    mat = MATERIAL_BLUE;
    mtr_get_std_color(COLOR_BLUE, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("blue");

    mat = MATERIAL_GREEN;
    mtr_get_std_color(COLOR_GREEN, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("green");

    mat = MATERIAL_YELLOW;
    mtr_get_std_color(COLOR_YELLOW, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("yellow");

    mat = MATERIAL_MAGENTA;
    mtr_get_std_color(COLOR_MAGENTA, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("magenta");

    mat = MATERIAL_CYAN;
    mtr_get_std_color(COLOR_CYAN, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("cyan");

    mat = MATERIAL_1000;
    mtr_get_std_color(COLOR_1000, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("mat1000");

    mat = MATERIAL_0100;
    mtr_get_std_color(COLOR_0100, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("mat0100");

    mat = MATERIAL_0010;
    mtr_get_std_color(COLOR_0010, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("mat0010");

    mat = MATERIAL_0001;
    mtr_get_std_color(COLOR_0001, color);
    copy_material(black_mat, &std_material[mat]);
    copy_vec4(color, std_material[mat].matblk.ambient);
    copy_vec4(color, std_material[mat].matblk.diffuse);
    std_material[mat].id = mat;
    std_material[mat].name = strdup("mat0001");

    id = MATERIAL_MAX;

}
Пример #27
0
int main (int argc, char **argv)
{
	int ret=0, i;
	int need=0, given=0, cycle_db=0, db_order=0;
	alpm_list_t *t;

	struct sigaction a;
	init_config (argv[0]);
	a.sa_handler = handler;
	sigemptyset(&a.sa_mask);
	a.sa_flags = 0;
	sigaction(SIGINT, &a, NULL);
	sigaction(SIGTERM, &a, NULL);

	int opt;
	int opt_index=0;
	static struct option opts[] =
	{
		{"query",      no_argument,       0, 'Q'},
		{"sync",       no_argument,       0, 'S'},
		{"dbpath",     required_argument, 0, 'b'},
		{"deps",       no_argument,       0, 'd'},
		{"explicit",   no_argument,       0, 'e'},
		{"groups",     no_argument,       0, 'g'},
		{"help",       no_argument,       0, 'h'},
		{"info",       no_argument,       0, 'i'},
		{"list",       no_argument,       0, 'l'},
		{"foreign",    no_argument,       0, 'm'},
		{"file",       no_argument,       0, 'p'},
		{"quiet",      no_argument,       0, 'q'},
		{"root",       required_argument, 0, 'r'},
		{"search",     no_argument,       0, 's'},
		{"unrequired", no_argument,       0, 't'},
		{"upgrades",   no_argument,       0, 'u'},
		{"config",     required_argument, 0, 'c'},
		{"just-one",   no_argument,       0, '1'},
		{"aur",        no_argument,       0, 'A'},
		{"escape",     no_argument,       0, 'x'},
		{"format",     required_argument, 0, 'f'},
		{"list-repo",  required_argument, 0, 'L'},
		{"query-type", required_argument, 0, 1000},
		{"csep",       required_argument, 0, 1001},
		{"delimiter",  required_argument, 0, 1001},
		{"sort",       required_argument, 0, 1002},
		{"nocolor",    no_argument,       0, 1003},
		{"number",     no_argument,       0, 1004},
		{"get-res",    no_argument,       0, 1005},
		{"show-size",  no_argument,       0, 1006},
		{"aur-url",    required_argument, 0, 1007},
		{"insecure",   no_argument,       0, 1008},
		{"qdepends",   no_argument,       0, 1009},
		{"qconflicts", no_argument,       0, 1010},
		{"qprovides",  no_argument,       0, 1011},
		{"qreplaces",  no_argument,       0, 1012},
		{"qrequires",  no_argument,       0, 1013},
		{"color",      no_argument,       0, 1014},
		{"version",    no_argument,       0, 'v'},

		{0, 0, 0, 0}
	};

	
	while ((opt = getopt_long (argc, argv, "1Ac:b:def:ghiLlmpQqr:Sstuvx", opts, &opt_index)) != -1) 
	{
		switch (opt) 
		{
			case '1':
				config.just_one = 1;
				break;
			case 'A':
				if (config.aur) break;
				config.aur = ++db_order;
				given |= N_DB;
				break;
			case 'c':
				FREE (config.configfile);
				config.configfile = strndup (optarg, PATH_MAX);
				break;
			case 'b':
				FREE (config.dbpath);
				config.dbpath = strndup (optarg, PATH_MAX);
				break;
			case 'd':
				config.filter |= F_DEPS;
				break;
			case 'e':
				config.filter |= F_EXPLICIT;
				break;
			case 'x':
				config.escape = 1;
				break;
			case 'f':
				config.custom_out = 1;
				strncpy (config.format_out, optarg, PATH_MAX);
				format_str (config.format_out);
				break;
			case 'g':
				if (config.op) break;
				config.op = OP_LIST_GROUP;
				config.filter |= F_GROUP;
				cycle_db = 1;
				break;
			case 'i':
				if (config.op)
				{
					if (config.op == OP_INFO) config.op = OP_INFO_P;
					break;
				}
				config.op = OP_INFO;
				need |= N_TARGET | N_DB;
				break;
			case 'L':
				config.list = 1;
				break;
			case 'l':
				if (config.op) break;
				config.op = OP_LIST_REPO;
				need |= N_DB;
				cycle_db = 1;
				break;
			case 'm':
				config.filter |= F_FOREIGN;
				break;
			case 'p':
				config.is_file = 1;
				need |= N_TARGET;
				break;
			case 'Q':
				if (config.db_local) break;
				config.db_local = ++db_order;
				given |= N_DB;
				break;
			case 'q':
				config.quiet = 1;
				break;
			case 'r':
				FREE (config.rootdir);
				config.rootdir = strndup (optarg, PATH_MAX);
				break;
			case 's':
				if (config.op) break;
				config.op = OP_SEARCH;
				need |= N_DB;
				cycle_db = 1;
				break;
			case 'S':
				if (config.db_sync) break;
				config.db_sync = ++db_order;
				given |= N_DB;
				break;
			case 't':
				config.filter |= F_UNREQUIRED;
				break;
			case 1000: /* --query-type */
				if (config.op) break;
				config.op = OP_QUERY;
				if (strcmp (optarg, "depends")==0)
					config.query = OP_Q_DEPENDS;
				else if (strcmp (optarg, "conflicts")==0)
					config.query = OP_Q_CONFLICTS;
				else if (strcmp (optarg, "provides")==0)
					config.query = OP_Q_PROVIDES;
				else if (strcmp (optarg, "replaces")==0)
					config.query = OP_Q_REPLACES;
				need |= N_TARGET | N_DB;
				break;
			case 1009: /* --qdepends */
				SETQUERY (OP_Q_DEPENDS); break;
			case 1010: /* --qconflicts */
				SETQUERY (OP_Q_CONFLICTS); break;
			case 1011: /* --qprovides */
				SETQUERY (OP_Q_PROVIDES); break;
			case 1012: /* --qreplaces */
				SETQUERY (OP_Q_REPLACES); break;
			case 1013: /* --qrequires */
				SETQUERY (OP_Q_REQUIRES); break;
			case 1001: /* --delimiter */
				strncpy (config.delimiter, optarg, SEP_LEN);
				format_str (config.delimiter);
				break;
			case 1002: /* --sort */
				config.sort = optarg[0];
				break;
			case 1003: /* --nocolor */
				config.colors=0;
				break;
			case 1004: /* --number */
				config.numbering = 1;
				break;
			case 1005: /* --get-res */
				if (dup2(FD_RES, FD_RES) == FD_RES)
					config.get_res = 1;
				break;
			case 1006: /* --show-size */
				config.show_size = 1;
				break;
			case 1007: /* --aur-url */
				FREE (config.aur_url);
				config.aur_url = strdup (optarg);
				break;
			case 1008: /* --insecure */
				config.insecure = 1;
				break;
			case 1014: /* --color */
				config.colors=1;
				break;
			case 'u':
				config.filter |= F_UPGRADES;
				break;
			case 'v':
				version(); break;
			case 'h': usage (0); break;
			default: /* '?' */
				usage (1);
		}
	}
	if (config.list)
	{
		/* -L displays respository list and exits. */
		alpm_list_t *dbs = get_db_sync ();
		if (dbs)
		{
			for(t = dbs; t; t = alpm_list_next(t))
				printf ("%s\n", (char *)t->data);
			FREELIST (dbs);
		}
		cleanup (0);
	}
	if (!config.custom_out)
	{
		if (config.colors)
			color_init();
#if defined(HAVE_GETTEXT) && defined(ENABLE_NLS)
		/* TODO: specific package-query locale ? */
		setlocale (LC_ALL, "");
		bindtextdomain ("yaourt", LOCALEDIR);
		textdomain ("yaourt");
#endif
	}
	if ((need & N_DB) && !(given & N_DB))
	{
		fprintf(stderr, "search or information must have database target (-{Q,S,A}).\n");
		exit(1);
	}
	for (i = optind; i < argc; i++)
	{
		if (!config.just_one ||
		    !alpm_list_find_str (targets, argv[i]))
			targets = alpm_list_add(targets, strdup(argv[i]));
	}
	if (i!=optind) 
	{
		given |= N_TARGET;
	}
	if ((need & N_TARGET) && !(given & N_TARGET))
	{
		fprintf(stderr, "no targets specified.\n");
		usage(1);
	}
	if (targets == NULL)
	{
		if (config.op == OP_SEARCH)	config.op = OP_LIST_REPO_S;
	}
	else if (!config.op && (given & N_DB)) /* Show info by default */
		config.op = OP_INFO;
	// init_db_sync initializes alpm after parsing [options]
	if (!init_db_sync ()) cleanup(1);
	if (config.is_file)
	{
		for(t = targets; t; t = alpm_list_next(t))
		{
			alpm_pkg_t *pkg=NULL;
			const char *filename = t->data;
			if (alpm_pkg_load (config.handle, filename, 0, ALPM_SIG_USE_DEFAULT, &pkg)!=0 || pkg==NULL)
			{
				fprintf(stderr, "unable to read %s.\n", filename);
				continue;
			}
			print_package (filename, pkg, alpm_pkg_get_str);
			ret++;
		}
		cleanup(!ret);
	}

	if  (cycle_db || targets)
	{
		for (i=1; i<=db_order && (cycle_db || targets); i++)
		{
			/*printf ("%d, aur %d, local %d, sync %d\n", i, config.aur, config.db_local, config.db_sync);*/
			if (config.db_sync == i)
			{
				for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t))
					ret += deal_db (t->data);
				if (!ret && config.op == OP_INFO_P)
				{
					config.op = OP_QUERY;
					config.query = OP_Q_PROVIDES;
					for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t))
						ret += deal_db (t->data);
					config.op = OP_INFO_P;
				}
			}
			else if (config.db_local == i)
				ret += deal_db (alpm_get_localdb(config.handle));
			else if (config.aur == i)
				switch (config.op)
				{
					case OP_INFO:
					case OP_INFO_P: ret += aur_info (&targets); break;
					case OP_SEARCH: ret += aur_search (targets); break;
					default: break;
				}
		}
	}
	else if (!config.aur && config.db_local)
		ret += alpm_search_local (config.filter, NULL, NULL);
	else if (config.aur && !(given & N_TARGET))
	{
		if (config.filter & F_FOREIGN)
		{
			/* -Am */
			config.aur_foreign = 1;
			config.just_one = 1;
			alpm_search_local (config.filter, "%n", &targets);
			ret += aur_info (&targets);
			if (config.db_local)
				/* -AQm */
				ret += search_pkg_by_name (alpm_get_localdb(config.handle), &targets);
		}
		else if (config.filter & F_UPGRADES)
		{
			/* -Au */
			config.aur_upgrades = 1;
			if (config.db_local)
				/* -AQu */
				ret += alpm_search_local (config.filter, NULL, NULL);
			alpm_search_local (F_FOREIGN | (config.filter & ~F_UPGRADES), "%n>%v", &targets);
			ret += aur_info (&targets);
		}
	}

	show_results();

	/* Some cleanups */
	cleanup(!ret);
	return 0;
}
Пример #28
0
/* parse command line arguments and preform needed actions */
static int parseargs(int argc, char *argv[])
{
	int i;
	const char *from_file = NULL;
	int ret = 0;

	opterr = 0;
	while ((i = getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) {
		switch (i) {

		case 'V':
			printf("pax-utils-%s: %s compiled %s\n%s\n"
			       "%s written for Gentoo by <solar, vapier and grobian @ gentoo.org>\n",
			       VERSION, __FILE__, __DATE__, rcsid, argv0);
			exit(EXIT_SUCCESS);
			break;
		case 'h': usage(EXIT_SUCCESS); break;
		case 'f':
			if (from_file) warn("You prob don't want to specify -f twice");
			from_file = optarg;
			break;
		case 'E':
			strncpy(match_etypes, optarg, sizeof(match_etypes));
			break;
		case 'M':
			match_bits = atoi(optarg);
			break;
		case 'O':
			if (sscanf(optarg, "%o", &match_perms) == -1)
				match_bits = 0;
			break;
		case 'o': {
			if (freopen(optarg, "w", stdout) == NULL)
				err("Could not open output stream '%s': %s", optarg, strerror(errno));
			break;
		}
		case 'N': {
			if (find_lib) warn("You prob don't want to specify -N twice");
			find_lib = optarg;
			break;
		}
		case 'F': {
			if (out_format) warn("You prob don't want to specify -F twice");
			out_format = optarg;
			break;
		}
		case 'Z': show_size = 1; break;
		case 'g': g_match = 1; break;
		case 'y': scan_symlink = 0; break;
		case 'A': scan_archives = 1; break;
		case 'C': color_init(true); break;
		case 'B': show_banner = 0; break;
		case 'p': scan_envpath = 1; break;
		case 'R': dir_recurse = 1; break;
		case 'm': dir_crossmount = 0; break;
		case 'n': show_needed = 1; break;
		case 'i': show_interp = 1; break;
		case 'b': show_bind = 1; break;
		case 'S': show_soname = 1; break;
		case 'q': be_quiet = 1; break;
		case 'v': be_verbose = (be_verbose % 20) + 1; break;
		case 'a': show_perms = show_endian = show_bind = 1; break;
		case 'D': show_endian = 1; break;
		case ':':
			err("Option '%c' is missing parameter", optopt);
		case '?':
			err("Unknown option '%c' or argument missing", optopt);
		default:
			err("Unhandled option '%c'; please report this", i);
		}
	}
	/* let the format option override all other options */
	if (out_format) {
		show_needed = show_interp = show_bind = show_soname = \
		show_perms = show_endian = show_size = 0;
		for (i = 0; out_format[i]; ++i) {
			if (!IS_MODIFIER(out_format[i])) continue;

			switch (out_format[++i]) {
			case '+': break;
			case '%': break;
			case '#': break;
			case 'F': break;
			case 'p': break;
			case 'f': break;
			case 'k': break;
			case 'N': break;
			case 'o': break;
			case 'a': break;
			case 'M': break;
			case 'Z': show_size = 1; break;
			case 'D': show_endian = 1; break;
			case 'O': show_perms = 1; break;
			case 'n': show_needed = 1; break;
			case 'i': show_interp = 1; break;
			case 'b': show_bind = 1; break;
			case 'S': show_soname = 1; break;
			default:
				err("Invalid format specifier '%c' (byte %i)",
				    out_format[i], i+1);
			}
		}

	/* construct our default format */
	} else {
		size_t fmt_len = 30;
		out_format = xmalloc(sizeof(char) * fmt_len);
		*out_format = '\0';
		if (!be_quiet)     xstrcat(&out_format, "%a ", &fmt_len);
		if (!be_quiet)     xstrcat(&out_format, "%o ", &fmt_len);
		if (show_perms)    xstrcat(&out_format, "%O ", &fmt_len);
		if (show_size)     xstrcat(&out_format, "%Z ", &fmt_len);
		if (show_endian)   xstrcat(&out_format, "%D ", &fmt_len);
		if (show_needed)   xstrcat(&out_format, "%n ", &fmt_len);
		if (show_interp)   xstrcat(&out_format, "%i ", &fmt_len);
		if (show_bind)     xstrcat(&out_format, "%b ", &fmt_len);
		if (show_soname)   xstrcat(&out_format, "%S ", &fmt_len);
		if (find_lib)      xstrcat(&out_format, "%N ", &fmt_len);
		if (!be_quiet)     xstrcat(&out_format, "%F ", &fmt_len);
	}
	if (be_verbose > 2) printf("Format: %s\n", out_format);

	/* now lets actually do the scanning */
	if (scan_envpath)
		scanmacho_envpath();
	if (!from_file && optind == argc && ttyname(0) == NULL && !scan_envpath)
		from_file = "-";
	if (from_file) {
		scanmacho_from_file(from_file);
		from_file = *argv;
	}
	if (optind == argc && !scan_envpath && !from_file)
		err("Nothing to scan !?");
	while (optind < argc) {
		search_path = argv[optind++];
		ret = scanmacho_dir(search_path);
	}

	return ret;
}