Exemple #1
0
Fichier : bb.c Projet : stroucki/bb
int bbinit(int argc, char **argv)
{
    aa_defparams.supported|= AA_NORMAL_MASK | AA_BOLD_MASK | AA_DIM_MASK;
    aa_parseoptions(NULL, NULL, &argc, argv);
    if (argc != 1 && (argc != 2 || ((argv[1][0] <= '0' || argv[1][0] > '8') && strcmp(argv[1], "-loop")))) {
	printf("Usage: bb [aaoptions] [number]\n\n");
	printf("Options:\n"
	       "  -loop          play demo in infinite loop\n\n"
	       "AAlib options:\n%s\n", aa_help);
	exit(1);
    }
    context = aa_autoinit(&aa_defparams);
    if (!context) {
	printf("Failed to initialize aalib\n");
	exit(2);
    }
    if (!aa_autoinitkbd(context, 0)) {
	aa_close(context);
	printf("Failed to initialize keyboard\n");
	exit(3);
    }
    if (argc == 2 && !strcmp(argv[1], "-loop"))
	loopmode = 1;
    else if (argc == 2)
	stage = atol(argv[1]);
    aa_hidecursor(context);
    return 1;
}
Exemple #2
0
/*****************************************************************************
 * Create: allocates aa video thread output method
 *****************************************************************************
 * This function allocates and initializes a aa vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;

    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
        msg_Err( p_vout, "out of memory" );
        return( 1 );
    }

    /* Don't parse any options, but take $AAOPTS into account */
    aa_parseoptions( NULL, NULL, NULL, NULL );

    if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
    {
        msg_Err( p_vout, "cannot initialize aalib" );
        return( 1 );
    }

    p_vout->pf_init = Init;
    p_vout->pf_end = End;
    p_vout->pf_manage = Manage;
    p_vout->pf_render = Render;
    p_vout->pf_display = Display;

    p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
    p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
    aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
    aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
    aa_hidemouse( p_vout->p_sys->aa_context );
    return( 0 );
}
Exemple #3
0
/**
 * This function allocates and initializes a aa vout method.
 */
static int Open(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys;

#ifndef _WIN32
    if (!vlc_xlib_init (object))
        return VLC_EGENERIC;
#endif

    /* Allocate structure */
    vd->sys = sys = calloc(1, sizeof(*sys));
    if (!sys)
        return VLC_ENOMEM;

    /* Don't parse any options, but take $AAOPTS into account */
    aa_parseoptions(NULL, NULL, NULL, NULL);

    /* */
    sys->aa_context = aa_autoinit(&aa_defparams);
    if (!sys->aa_context) {
        msg_Err(vd, "cannot initialize aalib");
        goto error;
    }
    vout_display_DeleteWindow(vd, NULL);

    aa_autoinitkbd(sys->aa_context, 0);
    aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK);

    /* */
    video_format_t fmt = vd->fmt;
    fmt.i_chroma = VLC_CODEC_RGB8;
    fmt.i_width  = aa_imgwidth(sys->aa_context);
    fmt.i_height = aa_imgheight(sys->aa_context);
    fmt.i_visible_width = fmt.i_width;
    fmt.i_visible_height = fmt.i_height;

    /* Setup vout_display now that everything is fine */
    vd->fmt = fmt;
    vd->info.has_pictures_invalid = true;
    vd->info.needs_event_thread = true;

    vd->pool    = Pool;
    vd->prepare = Prepare;
    vd->display = PictureDisplay;
    vd->control = Control;
    vd->manage  = Manage;

    /* Inspect initial configuration and send correction events
     * FIXME how to handle aspect ratio with aa ? */
    vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);

    return VLC_SUCCESS;

error:
    if (sys && sys->aa_context)
        aa_close(sys->aa_context);
    free(sys);
    return VLC_EGENERIC;
}
Exemple #4
0
int AA_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
	int keyboard;
	int i;

	/* Initialize all variables that we clean on shutdown */
	for ( i=0; i<SDL_NUMMODES; ++i ) {
		SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
		SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
	}
	/* Modes sorted largest to smallest */
	SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
	SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
	SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
	SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
	SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
	SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
	SDL_modelist[6] = NULL;

	/* Initialize the library */

	AA_mutex = SDL_CreateMutex();

	aa_parseoptions (NULL, NULL, NULL, NULL);

	AA_context = aa_autoinit(&aa_defparams);
	if ( ! AA_context ) {
		SDL_SetError("Unable to initialize AAlib");
		return(-1);
	}

	/* Enable mouse and keyboard support */

	if ( ! aa_autoinitkbd (AA_context, AA_SENDRELEASE) ) {
		SDL_SetError("Unable to initialize AAlib keyboard");
		return(-1);
	}
	if ( ! aa_autoinitmouse (AA_context, AA_SENDRELEASE) ) {
		fprintf(stderr,"Warning: Unable to initialize AAlib mouse");
	}
	AA_rparams = aa_getrenderparams();

	local_this = this;

	aa_resizehandler(AA_context, AA_ResizeHandler);

	fprintf(stderr,"Using AAlib driver: %s (%s)\n", AA_context->driver->name, AA_context->driver->shortname);

	AA_in_x11 = (SDL_strcmp(AA_context->driver->shortname,"X11") == 0);
	/* Determine the screen depth (use default 8-bit depth) */
	vformat->BitsPerPixel = 8;
	vformat->BytesPerPixel = 1;

	/* We're done! */
	return(0);
}
Exemple #5
0
int 
main (int argc, char **argv)
{
  if (!aa_parseoptions (NULL, NULL, &argc, argv) || argc != 1)
    {
      printf ("%s", aa_help);
      exit (1);
    }
  initialize ();
  game ();
  uninitialize ();
  return 1;
}
Exemple #6
0
static int aarenderer_open(int w, int h, int fs) {
    int   argc = 1;
    char *argv[] = { "foo", NULL };
    int i;
    if (!aa_parseoptions(NULL, NULL, &argc, argv) || argc != 1) {
        printf("%s\n", aa_help);
        return 0;
    }
    context = aa_autoinit(&aa_defparams);
    if (context == NULL) {
        printf("Can not intialize aalib\n");
        return 0;
    }

    bitmap = aa_image (context);
    params = aa_getrenderparams ();
    for (i = 0; i < 256; i++)
        aa_setpalette(palette, i, pal[i * 3] * 4, pal[i * 3 + 1] * 4, pal[i * 3 + 2] * 4);
    aa_hidecursor(context);
    return 1;
}
Exemple #7
0
static void parseenv(struct aa_hardware_params *p, aa_renderparams * r)
{
	char *env;
	int argc = 1;
	int i;
	char *argv[256], *argv1[256];
	inparse = 1;
	env = getenv("AAOPTS");
	if (env == NULL)
		return;
	if (env[0]) {
		for (i = 0; i < (int)strlen(env); i++) {
			int s;
			char stop = ' ';
			while (env[i] == ' ')
				i++;
			if (env[i] == '"')
				i++, stop = '"';
			s = i;
			while (env[i] != stop && env[i])
				i++;
			if (i - s) {
				argv1[argc] = argv[argc] = calloc(i - s + 1, 1);
				strncpy(argv[argc], env + s, i - s);
				argc++;
				if (argc == 255)
					break;
			}
		}
	}
	i = argc;
	if (i != 1) {
		aa_parseoptions(p, r, &i, argv);
		for (i = 1; i < argc; i++)
			free(argv1[i]);
	}
	inparse = 0;
}
Exemple #8
0
int main(int argc, char **argv)
{
	aa_context *c;
	int i, y;
	char s[256];
	aa_renderparams *p;
	strcpy(s, "line editor.");
	if (!aa_parseoptions(NULL, NULL, &argc, argv) || argc != 1) {
		printf("%s\n", aa_help);
		exit(1);
	}
	c = aa_autoinit(&aa_defparams);
	if (c == NULL) {
		printf("Can not intialize aalib\n");
		exit(2);
	}
	if (!aa_autoinitkbd(c, 0)) {
		printf("Can not intialize keyboard\n");
		aa_close(c);
		exit(3);
	}
	for (i = 0; i < aa_imgwidth(c); i++)
		for (y = 0; y < aa_imgheight(c); y++)
			aa_putpixel(c, i, y, i + y < 80 ? i : ((i + y) < 100 ? (i + y == 89 ? 150 : 0) : y * 8));
	aa_hidecursor(c);
	aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c));
	aa_printf(c, 0, 0, AA_SPECIAL, "Fast rendering routine %i",1);
	aa_flush(c);
	aa_getkey(c, 1);
	aa_edit(c, 0, 1, 20, s, 256);
	aa_puts(c, 0, 0, AA_SPECIAL, "Key lookup test        ");
	aa_flush(c);
	int ch;
	while ((ch = aa_getevent(c, 1)) != ' ') {
		char s[80];
		sprintf(s, "Key event test-space to exit. c:%i", ch);
		aa_puts(c, 0, 0, AA_SPECIAL, s);
		aa_flush(c);
	}
	if (aa_autoinitmouse(c, AA_MOUSEALLMASK)) {
		int co = 0;
		sprintf(s, "Mouse test-space to exit");
		aa_puts(c, 0, 0, AA_SPECIAL, s);
		aa_flush(c);
		while (aa_getevent(c, 1) != ' ') {
			int x, y, b;
			char s[80];
			co++;
			aa_getmouse(c, &x, &y, &b);
			sprintf(s, "Mouse test-space to exit. x:%i y:%i b:%i event #%i  ", x, y, b, co);
			aa_puts(c, 0, 0, AA_SPECIAL, s);
			aa_flush(c);
		}
		aa_hidemouse(c);
		while (aa_getevent(c, 1) != ' ') {
			int x, y, b;
			char s[80];
			co++;
			aa_getmouse(c, &x, &y, &b);
			sprintf(s, "Hidden mouse test-space to exit. x:%i y:%i b:%i event #%i  ", x, y, b, co);
			aa_puts(c, 0, 0, AA_SPECIAL, s);
			aa_flush(c);
		}
		aa_uninitmouse(c);
	}
	p = aa_getrenderparams();
	for (i = 0; i < AA_DITHERTYPES; i++) {
		p->dither = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, aa_dithernames[i]);
		aa_flush(c);
		aa_getkey(c, 1);
	}
	for (i = 0; i < 255; i += 32) {
		p->bright = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - bright changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->bright = 0;
	for (i = 0; i < 128; i += 16) {
		p->contrast = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - contrast changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->contrast = 0;
	for (i = 0; i < 255; i += 32) {
		p->gamma = 1 + i / 32.0;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - gamma changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	p->gamma = 1.0;
	for (i = 0; i < 255; i += 32) {
		p->randomval = i;
		aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c));
		aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - randomval changes");
		aa_flush(c);
		aa_getkey(c, 1);
	}
	aa_close(c);
	return 0;
}
Exemple #9
0
int main(int argc, char **argv) {
	int help_flag = 0;
	int aahelp_flag = 0;
	int justoutput_flag = 0;
	int loadavg_flag = 0;
	int ipc_flag = 0;
	int port_num = DEFPORT;
	int max_iterations = 0;
	int delay = 0;
	int normal_load;
	int socket_fd = -1;
	float randomizestyletime = 0;
	float randomizesitetime  = 0;
	char *endptr;

	setlocale(LC_ALL, "");
	bindtextdomain("aajm", LOCALEDIR);
	textdomain("aajm");

	char options[] = "aljhip:n:d:m:t:s:T:S:";
	static struct option long_options[] =
        {
		{"help", no_argument, &help_flag, 1},
		{"aahelp", no_argument, &aahelp_flag, 1},
		{"justoutput", no_argument, &justoutput_flag, 1},
		{"ipc", no_argument, &ipc_flag, 1},
		{"loadavg", no_argument, &loadavg_flag, 1},
		{"maxiterations", required_argument, 0, 'm'},
		{"port", required_argument, 0, 'p'},
		{"normalload", required_argument, 0, 'n'},
		{"delay", required_argument, 0, 'd'},
		{"siteswap", required_argument, 0, 's'},
		{"style", required_argument, 0, 't'},
		{"rstyle", required_argument, 0, 'S'},
		{"rsiteswap", required_argument, 0, 'T'},
		{0,0,0,0}
	};

	normal_load = (int)(DEFLOAD * 100);
	char optch;
	int option_index = 0;

	//jmlib = new JMLib(errorCB);
    jmlib = JMLib::alloc();
	jmlib->setPatternDefault();
	jmlib->setStyleDefault();
	jmlib->startJuggle();

	aa_parseoptions(NULL, NULL, &argc, argv);

	while( (optch = getopt_long(argc,argv,options,
			long_options,&option_index)) != -1)
		switch(optch) {
			case 's':
				jmlib->setPattern("Something",optarg,
					HR_DEF, DR_DEF);
				break;
			case 't':
				jmlib->setStyle(optarg);
				break;
			case 'S':
				randomizesitetime = strtod(optarg, &endptr);
				if (endptr==optarg || *endptr != 0) {
						randomizesitetime = DEFRANDOMSITETIME;
				}
				break;
			case 'T':
				randomizestyletime = strtod(optarg, &endptr);
				if (endptr==optarg || *endptr != 0) {
						randomizestyletime = DEFRANDOMSTYLETIME;
				}
				break;
			case 'h':
				help_flag=1;
				break;
			case 'a':
				aahelp_flag=1;
				break;
			case 'j':
				justoutput_flag=1;
				break;
			case 'm':
				max_iterations = atoi(optarg);
				break;
			case 'd':
				delay = atoi(optarg);
				break;
			case 'l':
				loadavg_flag=1;
				break;
			case 'n':
				normal_load = (int)(100*atof(optarg));
				break;
			case 'i':
				ipc_flag=1;
				break;
			case 'p':
				port_num=atoi(optarg);
				break;
		}

	if(aahelp_flag || help_flag) {
		printf(gettext("AAJM, An ASCII Art Juggling program\n"));
		printf(gettext("Usage: %s [OPTIONS]\n"),argv[0]);
	}
	if(help_flag) {
		printf(gettext("Jugglemaster Options:\n"));
		printf(gettext("  -s, --siteswap=XX          show siteswap XX (3)\n"));
		printf(gettext("  -t, --style=XX             use style XX (\"Normal\")\n"));
		printf(gettext("  -S, --rsiteswap=XX         Randomize siteswap every XX seconds (%f)\n"), DEFRANDOMSITETIME);
		printf(gettext("  -T, --rstyle=XX            Randomize style every XX seconds (%f)\n"), DEFRANDOMSTYLETIME);
		printf(gettext("  -d, --delay=XX             delay XX ms between frames (%i)\n"), (int)DEFSPEED/1000);
		printf(gettext("  -m, --maxiterations=XX     do at most XX iterations\n"));
		printf(gettext("  -j, --justoutput           only output [don't init kb or mouse]\n"));
		printf(gettext("  -i, --ipc                  enable IPC\n"));
		printf(gettext("  -p, --port=XX              use port XX for IPC (%i)\n"),DEFPORT);
		printf(gettext("  -l, --loadavg              change speed based on load average\n"));
		printf(gettext("  -n, --normalload=XX        a normal load average for your machine (%2.2f)\n"),DEFLOAD);
		printf(gettext("  -h, --help                 get help [this screen]\n"));
		printf(gettext("  -a, --aahelp               get help on AA options\n\n"));
	}
	if(aahelp_flag) {
		printf(gettext("AALib Options:\n%s\n\n"),aa_help);
	}
	if(aahelp_flag || help_flag) {
		return 0;
	}


	context = aa_autoinit(&aa_defparams);
	if (context == NULL) {
		printf(gettext("Failed to initialize aalib\n"));
		exit(1);
	}

	if(!justoutput_flag) {
		aa_autoinitkbd(context, 0);
		aa_hidecursor(context);
	}
	params = aa_getrenderparams();
	jmlib->setWindowSize(aa_imgwidth(context),aa_imgheight(context));
	jmlib->startJuggle();

	aa_resizehandler(context, resizehandler);

	if(loadavg_flag) {
		/* If we're doing that thing where we care, then this
			can go down to as-low-as-possible priority */
		nice(19);
	}

	if(ipc_flag) {
		socket_fd = startlistening(port_num);
	}

	main_loop(max_iterations,delay,loadavg_flag,normal_load, socket_fd,
                  randomizestyletime, randomizesitetime);

	if(socket_fd > 0) {
		stoplistening(socket_fd);
	}
	aa_close(context);

	delete jmlib;
	return 1;
}
static int parse_suboptions(const char *arg) {
    char *pseudoargv[4], *osdcolor = NULL, *subcolor = NULL, **strings,
         *helpmsg = NULL;
    int pseudoargc, displayhelp = 0, *booleans;
    const opt_t extra_opts[] = {
            {"osdcolor", OPT_ARG_MSTRZ, &osdcolor,    NULL},
            {"subcolor", OPT_ARG_MSTRZ, &subcolor,    NULL},
            {"help",     OPT_ARG_BOOL,  &displayhelp, NULL} };
    opt_t *subopts = NULL, *p;
    char * const strings_list[] = {"-driver", "-kbddriver", "-mousedriver", "-font",
        "-width", "-height", "-minwidth", "-minheight", "-maxwidth",
        "-maxheight", "-recwidth", "-recheight", "-bright",  "-contrast",
        "-gamma",  "-dimmul", "-boldmul", "-random" };
    char * const booleans_list[] = {"-dim", "-bold", "-reverse", "-normal",
        "-boldfont", "-inverse", "-extended", "-eight", "-dither",
        "-floyd_steinberg", "-error_distribution"};
    char * const nobooleans_list[] = {"-nodim", "-nobold", "-noreverse", "-nonormal",
        "-noboldfont", "-noinverse", "-noextended", "-noeight", "-nodither",
        "-nofloyd_steinberg", "-noerror_distribution"};
    const int nstrings = sizeof(strings_list) / sizeof(char*);
    const int nbooleans = sizeof(booleans_list) / sizeof(char*);
    const int nextra_opts = sizeof(extra_opts) / sizeof(opt_t);
    const int nsubopts = nstrings + nbooleans + nextra_opts;
    int i, retval = 0;

    subopts = calloc(nsubopts + 1, sizeof(opt_t));
    strings = calloc(nstrings, sizeof(char*));
    booleans = calloc(nbooleans, sizeof(int));

    p = subopts;
    for (i=0; i<nstrings; i++, p++) {
        p->name = strings_list[i] + 1; // skip '-'
        p->type = OPT_ARG_MSTRZ;
        p->valp = &strings[i];
    }
    for (i=0; i<nbooleans; i++, p++) {
        p->name = booleans_list[i] + 1;
        p->type = OPT_ARG_BOOL;
        p->valp = &booleans[i];
    }
    memcpy(p, extra_opts, sizeof(extra_opts));

    retval = subopt_parse(arg, subopts);

    if (retval == 0 && displayhelp) {
        helpmsg = strdup(aa_help);
        for (i=0; i<(signed)strlen(helpmsg); i++)
            if (helpmsg[i] == '-') helpmsg[i] = ' ';
        mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_HelpHeader);
        mp_msg(MSGT_VO, MSGL_INFO, "%s\n\n", helpmsg);
        mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_AdditionalOptions);
        retval = -1;
    }
    if (retval == 0) {
        pseudoargv[3] = NULL;
        for (i=0; i<nstrings; i++) {
            pseudoargc = 3;         // inside loop because aalib changes it
            if (strings[i] != NULL) {
                pseudoargv[1] = strings_list[i];
                pseudoargv[2] = strings[i];
                aa_parseoptions(&aa_defparams, &aa_defrenderparams,
                                                &pseudoargc, pseudoargv);
            }
        }
        pseudoargv[2] = NULL;
        for (i=0; i<nbooleans; i++) {
            pseudoargc = 2;
            if (booleans[i]) pseudoargv[1] = booleans_list[i];
            else pseudoargv[1] = nobooleans_list[i];
            aa_parseoptions(&aa_defparams, &aa_defrenderparams,
                                                &pseudoargc, pseudoargv);
        }
        if (osdcolor) aaopt_osdcolor = getcolor(osdcolor);
        if (subcolor) aaopt_subcolor = getcolor(subcolor);
    }

    free(subopts);
    free(booleans);
    if (strings) {
        for (i=0; i<nstrings; i++)
            free(strings[i]);
        free(strings);
    }
    free(osdcolor);
    free(subcolor);
    free(helpmsg);
    return retval;
}