Beispiel #1
0
static PyObject * mvw(PyObject *self, PyObject *args)
{
    int y, x, width, rep_len, end_len, ret;
    char *message, *rep, *end;
    const char *m_enc, *r_enc, *e_enc;
    PyObject *window;
    WINDOW *win;

    /* We use the 'et' format because we don't want Python
       to touch the encoding and generate Unicode Exceptions */

    if(!PyArg_ParseTuple(args, "Oiiietetet", 
                &window, &y, &x, &width, &m_enc, &message,
                &r_enc, &rep, &e_enc, &end))
            return NULL;

    if (window != Py_None)
        win = ((PyCursesWindowObject *)window)->win;
    else
        win = NULL;
    
    rep_len = strlen(rep);
    end_len = theme_strlen(end, 0);

    /* Make width relative to current x */
    width += x;

    int i = 0;
    for (i = 0; ((x < width - end_len) || (message[i] == '%')); i++) {
        ret = do_char(win, width - end_len, &i, &y, &x, message);
        if (ret)
            break;
    }

    int j = 0;
    for(j = 0; x < (width - end_len); j = (j + 1) % rep_len)
        do_char(win, width - end_len, &j, &y, &x, rep);

    for(j = 0; end[j]; j++)
        do_char(win, width, &j, &y, &x, end);

    PyMem_Free(rep);
    PyMem_Free(end);

    if (ret == -1) {
        PyMem_Free(message);
        return Py_BuildValue("s", NULL);
    }
    else {
        PyObject *r = Py_BuildValue("s", lstrip(&message[i]));
        PyMem_Free(message);
        return r;
    }
}
Beispiel #2
0
int dispatch_cmd(otts_synth_plugin_t *synth, char *cmd_line)
{
	char *cmd = NULL;
	size_t cmd_len;
	char *msg = NULL;

	cmd_len = strcspn(cmd_line, " \t\n\r\f");
	cmd = g_strndup(cmd_line, cmd_len);
	pthread_mutex_lock(&module_stdout_mutex);

	if (!strcasecmp("audio", cmd)) {
		msg = do_audio(synth);
	} else if (!strcasecmp("set", cmd)) {
		msg = do_set(synth);
	} else if (!strcasecmp("speak", cmd)) {
		msg = do_speak(synth);
	} else if (!strcasecmp("key", cmd)) {
		msg = do_key(synth);
	} else if (!strcasecmp("sound_icon", cmd)) {
		msg = do_sound_icon(synth);
	} else if (!strcasecmp("char", cmd)) {
		msg = do_char(synth);
	} else if (!strcasecmp("pause", cmd)) {
		do_pause(synth);
	} else if (!strcasecmp("stop", cmd)) {
		do_stop(synth);
	} else if (!strcasecmp("list_voices", cmd)) {
		msg = do_list_voices(synth);
	} else if (!strcasecmp("loglevel", cmd)) {
		msg = do_loglevel(synth);
	} else if (!strcasecmp("debug", cmd)) {
		msg = do_debug(synth, cmd_line);
	} else if (!strcasecmp("quit", cmd)) {
		do_quit(synth);
	} else {
/*should we log?*/
		printf("300 ERR UNKNOWN COMMAND\n");
		fflush(stdout);
	}

	if (msg != NULL) {
		if (0 > printf("%s\n", msg)) {
			log_msg(OTTS_LOG_CRIT, "Broken pipe, exiting...\n");
			synth->close(2);
		}
		fflush(stdout);
		g_free(msg);
	}

	pthread_mutex_unlock(&module_stdout_mutex);
	g_free(cmd);

	return (0);
}
Beispiel #3
0
void
do_line(struct vfont *vfp, char *line)
{
    int currx;
    int char_id;
    size_t char_count;
    size_t len = strlen(line);

    if (vfp == VFONT_NULL) return;

    currx = xpos;

    for (char_count = 0; char_count < len; char_count++) {
        struct vfont_dispatch *vdp;

        char_id = (int) line[char_count] & 0377;

        /* Obtain the dimensions for the character */
        vdp = &vfp->vf_dispatch[char_id];
        width = vdp->vd_left + vdp->vd_right;
        height = vdp->vd_up + vdp->vd_down;
        if (debug) fprintf(stderr, "%c w=%2d h=%2d, currx=%d\n", char_id, width, height, currx);

        /*
         * pace characters are frequently not represented in the font
         * set, so leave white space here.
         */
        if (width <= 1) {
            char_id = 'n';	/* 1-en space */
            vdp = &vfp->vf_dispatch[char_id];
            width = vdp->vd_left + vdp->vd_right;
            if (width <= 1) {
                char_id = 'N';	/* 1-en space */
                vdp = &vfp->vf_dispatch[char_id];
                width = vdp->vd_left + vdp->vd_right;
                if (width <= 1)
                    width = 16;	/* punt */
            }
            currx += width;
            continue;
        }

        if (currx + width > fb_getwidth(fbp) - 1) {
            fprintf(stderr, "fblabel:  Ran off screen\n");
            break;
        }

        do_char(vfp, vdp, currx, ypos);
        currx += vdp->vd_width + 2;
    }
}
Beispiel #4
0
void
do_line(int xpos, int ypos, register char *line)
{
    register int    currx;
    register int    char_count, char_id;
    register int	len = strlen( line );
    if ( font.ffdes == NULL )
    {
	bu_log( "ERROR: do_line() called before get_font().\n" );
	return;
    }
    currx = xpos;

    for ( char_count = 0; char_count < len; char_count++ )
    {
	char_id = (int) line[char_count] & 0377;

	/* Since there is no valid space in font, skip to the right
	   using the width of the digit zero.
	*/
	if ( char_id == ' ' )
	{
	    currx += (SWABV(font.dir['0'].width) + 2) / ir_aperture;
	    continue;
	}

	/* locate the bitmap for the character in the file */
	if ( fseek( font.ffdes, (long)(SWABV(font.dir[char_id].addr)+font.offset), 0 )
	     == EOF
	    )
	{
	    bu_log( "fseek() to %ld failed.\n",
		    (long)(SWABV(font.dir[char_id].addr) + font.offset)
		);
	    return;
	}

	/* Read in the dimensions for the character */
	font.width = font.dir[char_id].right + font.dir[char_id].left;
	font.height = font.dir[char_id].up + font.dir[char_id].down;

	if ( currx + font.width > fb_getwidth( fbiop ) - 1 )
	    break;		/* won't fit on screen */

	do_char( char_id, currx, ypos );
	currx += (SWABV(font.dir[char_id].width) + 2) / ir_aperture;
    }
    return;
}
Beispiel #5
0
int
main(int argc, char *argv[]) 
{
    extern char		*optarg;
    extern int		optind;
    struct lcd_driver	*driver = &lcd_drivertab[0];
    char		*drivertype, *cp;
    char		*devname = DEFAULT_DEVICE;
    char		*drvopts = NULL;
    int			ch, i;

    if ((progname = strrchr(argv[0], '/'))) {
	progname++;
    } else {
	progname = argv[0];
    }

    drivertype = getenv("LCD_TYPE");
    
    while ((ch = getopt(argc, argv, "Dd:f:o:v")) != -1) {
	switch(ch) {
	case 'D':
	    debuglevel++;
	    break;
	case 'd':
	    drivertype = optarg;
	    break;
	case 'f':
	    devname = optarg;
	    break;
	case 'o':
	    drvopts = optarg;
	    break;
	case 'v':
	    vflag = 1;
	    break;
	default:
	    usage();
	}
    }
    argc -= optind;
    argv += optind;
    
    /* If an LCD type was specified, look it up */
    if (drivertype != NULL) {
	driver = NULL;
	for (i = 0; lcd_drivertab[i].l_code != NULL; i++) {
	    if (!strcmp(drivertype, lcd_drivertab[i].l_code)) {
		driver = &lcd_drivertab[i];
		break;
	    }
	}
	if (driver == NULL) {
	    warnx("LCD driver '%s' not known", drivertype);
	    usage();
	}
    }
    debug(1, "Driver selected for %s", driver->l_name);
    driver->l_prepare(devname, drvopts);
    atexit(driver->l_finish);

    if (argc > 0) {
	debug(2, "reading input from %d argument%s", argc, (argc > 1) ? "s" : "");
	for (i = 0; i < argc; i++)
	    for (cp = argv[i]; *cp; cp++)
		do_char(driver, *cp);
    } else {
	debug(2, "reading input from stdin");
	setvbuf(stdin, NULL, _IONBF, 0);
	while ((ch = fgetc(stdin)) != EOF)
	    do_char(driver, (char)ch);
    }
    exit(EX_OK);
}