Exemple #1
0
static int  plugin_ctrl (UgetPluginAria2* plugin, int code, void* data)
{
	switch (code) {
	case UGET_PLUGIN_CTRL_START:
		if (plugin->node == NULL)
			return plugin_start (plugin, data);
		break;

	case UGET_PLUGIN_CTRL_STOP:
		plugin->stopped = TRUE;
		return TRUE;

	case UGET_PLUGIN_CTRL_SPEED:
		// speed control
		return plugin_ctrl_speed (plugin, data);

	case UGET_PLUGIN_CTRL_NODE_UPDATED:
		break;
	}

	return FALSE;
}
Exemple #2
0
static void
panel_parse_plugin(xconf *xc)
{
    plugin_instance *plug = NULL;
    gchar *type = NULL;

    ENTER;
    xconf_get_str(xconf_find(xc, "type", 0), &type);
    if (!type || !(plug = plugin_load(type))) {
        ERR( "fbpanel: can't load %s plugin\n", type);
        return;
    }
    plug->panel = p;
    XCG(xc, "expand", &plug->expand, enum, bool_enum);
    XCG(xc, "padding", &plug->padding, int);
    XCG(xc, "border", &plug->border, int);
    plug->xc = xconf_find(xc, "config", 0);

    if (!plugin_start(plug)) {
        ERR( "fbpanel: can't start plugin %s\n", type);
        exit(1);
    }
    p->plugins = g_list_append(p->plugins, plug);
}
Exemple #3
0
static int
panel_parse_plugin(panel *p, FILE *fp)
{
    line s;
    plugin *plug = NULL;
    gchar *type = NULL;
    FILE *tmpfp;
    int expand , padding, border;
    
    ENTER;
    s.len = 256;
    if (!(tmpfp = tmpfile())) {
        ERR( "can't open temporary file with tmpfile()\n");
        RET(0);
    }
    border = expand = padding = 0;
    while (get_line(fp, &s) != LINE_BLOCK_END) {
        if (s.type == LINE_NONE) {
            ERR( "fbpanel: bad line %s\n", s.str);
            goto error;
        }
        if (s.type == LINE_VAR) {
            if (!g_ascii_strcasecmp(s.t[0], "type")) {
                type = g_strdup(s.t[1]);
                DBG("plug %s\n", type);
            } else if (!g_ascii_strcasecmp(s.t[0], "expand"))
                expand = str2num(bool_pair,  s.t[1], 0);
            else if (!g_ascii_strcasecmp(s.t[0], "padding"))
                padding = atoi(s.t[1]);
            else if (!g_ascii_strcasecmp(s.t[0], "border"))
                border = atoi(s.t[1]);
            else {
                ERR( "fbpanel: unknown var %s\n", s.t[0]);
                goto error;
            }
        } else if (s.type == LINE_BLOCK_START) {
            if (!g_ascii_strcasecmp(s.t[0], "Config")) {
                int pno = 1;
                while (pno) {
                    get_line_as_is(fp, &s);
                    if (s.type == LINE_NONE) {
                        ERR( "fbpanel: unexpected eof\n");
                        goto error;
                    } else if (s.type == LINE_BLOCK_START) {
                        pno++;
                    } else if (s.type == LINE_BLOCK_END) {
                        pno--;
                    } 
                    fprintf(tmpfp, "%s\n", s.str);
                }              
            } else {
                ERR( "fbpanel: unknown block %s\n", s.t[0]);
                goto error;
            }
        } else {
            ERR( "fbpanel: illegal in this context %s\n", s.str);
            goto error;
        }
    }
    
    if (!type || !(plug = plugin_load(type))) {
        ERR( "fbpanel: can't load %s plugin\n", type);
        goto error;
    }
    plug->panel = p;
    plug->fp = tmpfp;
    plug->expand = expand;
    plug->padding = padding;
    plug->border = border;
    fprintf(tmpfp, "}\n");
    fseek(tmpfp, 0, SEEK_SET);
    DBG("starting\n");
    if (!plugin_start(plug)) {
        ERR( "fbpanel: can't start plugin %s\n", type);
        goto error;
    }
    DBG("plug %s\n", type);
    p->plugins = g_list_append(p->plugins, plug);
    g_free(type);
    RET(1);
    
 error:
    fclose(tmpfp);
    g_free(type);
    if (plug)
          plugin_put(plug);
    RET(0);
    
}
Exemple #4
0
static int load_flat(char *fn, buffer *buf)
{
	int i, j, intp;
	char *texti;
	FILE *fp;
	int *fmts = NULL;
	int nfmt = -1;
	char instring[256], *p, *coords, *contents, *comma;
	int sw = 80, sh = 20, sf = 0, f;
	int s = 0;
	int *styles = NULL;
	int nsty = 0;
	int n;
	MwFmt fmt;
	int lastph = -1;
	cval value;
	char *endp;
	int type;
	value.number = 0;

	if ((fp = fopen(fn, "r")) == NULL)
		return 1;

	for (s = 0; s < buf->nsht; s++) {
		for (i = line_last_used(buf, s); i > 0; i--) {
			for (j = col_last_changed(buf, s, i, sf); j > 0; j--) {
				ins_data(buf, siod_interpreter, NULL,
					value, EMPTY, s, i, j);
				ins_format(buf, s, i, j, sf);
			}
		}
	}

	buf->a1_refs = a1_refs;

	s = 0;	/* old files have no .sheet tags, so start at first sheet */
	while (fgets(instring, 250, fp) != NULL) {
		char b[1024];
		b[0] = '\0';	/* make sure we don't keep stuff between loops */

		/* strip off \r\n */
/*
   if ((p = strpbrk(instring, "\r\n")) != NULL) *p = '\0';
 */

		switch (instring[0]) {
		case '\0':
		case '#':
			break;
		case '.':
                        if (!strncmp(instring, ".margins ", 9)) {
                                sscanf(instring, ".margins %d %d %d %d %d %d",
                                       &(buf->top_margin),
                                       &(buf->bottom_margin),
                                       &(buf->left_margin),
                                       &(buf->right_margin),
                                       &(buf->header_margin),
                                       &(buf->footer_margin));
			} else if (!strncmp(instring, ".a1_refs ", 9)) {
				sscanf(instring, ".a1_refs %d",
					&(buf->a1_refs));
                        } else if (!strncmp(instring, ".paper ", 7)) {
                                sscanf(instring, ".paper %s %d %d %d",
                                       b,
                                       &(buf->paper_width),
                                       &(buf->paper_height),
                                       &(buf->orientation));
                                buf->paper_name = MwStrdup(b);
                        } else if (!strncmp(instring, ".header ", 8)) {
                                sscanf(instring, ".header %[^\n]", b);
                                buf->header = MwStrdup(b);
                        } else if (!strncmp(instring, ".footer ", 8)) {
                                sscanf(instring, ".footer %[^\n]", b);
                                buf->footer = MwStrdup(b);
                        } else if (!strncmp(instring, ".header_on_first ", 17)) {
                                sscanf(instring, ".header_on_first %d",
                                       &(buf->header_on_first));
                        } else if (!strncmp(instring, ".first_page ", 12)) {
                                sscanf(instring, ".first_page %d",
                                       &(buf->first_page_number));
                        } else if (!strncmp(instring, ".sw ", 4)) {
				sscanf(instring, ".sw %d", &sw);
				buf->sw = sw;
			} else if (!strncmp(instring, ".sh ", 4)) {
				sscanf(instring, ".sh %d", &sh);
				buf->sh = sh;
/* The old "standard format" used the .sf tag, which was bitmapped and
must no longer be used. Thus .nsf (new standard format)
*/
			} else if (!strncmp(instring, ".nsf ", 5)) {
				sscanf(instring, ".nsf %d", &sf);
				std_fmt_set(buf, sf);
			} else if (!strncmp(instring, ".cw ", 4)) {
				int w;
				sscanf(instring, ".cw %d %d", &i, &w);
				set_width(buf, s, i, w);
			} else if (!strncmp(instring, ".rh ", 4)) {
				int h;
				sscanf(instring, ".rh %d %d", &i, &h);
				set_height(buf, s, i, h);
			} else if (!strncmp(instring, ".ft", 3)) {
				sscanf(instring, ".ft%d", &n);
				if (n > nfmt) {
					nfmt = n;
					fmts = MwRealloc(fmts,
							(nfmt+1)*sizeof *fmts);
				}
				fmts[n] = MwLoadFormats(fp);
				/* now replace style with the real one */
				MwDecodeFormat(fmts[n], ~0, &fmt);
				/* Careful now. Some versions of Siag
				   produced bogus styles
				*/
				if (fmt.style < nsty
					&& styles[fmt.style] < nstyle) {
					fmt.style = styles[fmt.style];
					fmts[n] = MwEncodeFormat(~0, &fmt);
				} else {
					fmt.style = 0;
				}
			} else if (!strncmp(instring, ".style ", 7)) {
				int n;
				sscanf(instring, ".style %d", &n);
				if (n >= nsty) {
					nsty = n;
					styles = MwRealloc(styles,
							(nsty+1)*sizeof *styles);
				}
				styles[n] = load_styles(fp);
			} else if (!strncmp(instring, ".sheet ", 7)) {
				char name[1000];
				sscanf(instring, ".sheet %d %[^\n]", &s, name);
				if (s >= buf->nsht)
					buffer_add_sheet(buf, s);
				buffer_rename_sheet(buf, s, name);
			} else if (!strncmp(instring, ".fmt", 4)) {
				int h;
				char b[256];
				sscanf(instring, ".fmt%d %[^\n]", &h, b);
				h >>= MW_FMT_SHIFT;	/* 0 <= h <= 15 */
				lookup_style(style2name(h), b,
						style_table[h].type);
			} else if (!strncmp(instring, ".plugin-geometry ", 17)) {
				int n, width, height;
				n = sscanf(instring, ".plugin-geometry %d %d",
						&width, &height);
				if (lastph >= 0 && n >= 2) {
					plugin_size_set(lastph,
						width, height);
				}
			} else if (!strncmp(instring, ".plugin ", 8)) {
				int n;
				int row, col;
				char name[1024];
				plugin_t plugin;
				sscanf(instring, ".plugin %d %d %s",
					&row, &col, name);
				plugin.row = row;
				plugin.col = col;
				plugin.name = MwStrdup(name);
				p = file_name(buf, name);
				lastph = plugin.ph = plugin_start(p);
				MwFree(p);
				plugin.displayed = 0;
				if (plugin.ph != -1) {
					n = buf->sht[s].nplugin++;
					buf->sht[s].plugin = MwRealloc(buf->sht[s].plugin,
						buf->sht[s].nplugin*sizeof(plugin_t));
					buf->sht[s].plugin[n] = plugin;
				}
			} else if (!strncmp(instring, ".p", 2)) {
				int n;
				char key[256], *value;
				sscanf(instring, ".p%d %s", &n, key);
				value = MwMalloc(n+1);
				fread(value, n, 1, fp);
				value[n] = '\0';
				put_property(buf, key, value);
				MwFree(value);
			}
			break;
		default:	/* cell definition */
			if ((coords = strtok(instring, "\t")) == NULL)
				break;
			if ((contents = strtok((char *) 0, "\t\n\r")) == NULL)
				break;
			if ((p = strtok(coords, " ")) == NULL)
				break;
			i = atoi(p);
			if ((p = strtok(NULL, " ")) == NULL)
				break;
			j = atoi(p);
			if ((p = strtok(NULL, " ")) == NULL)
				break;
			f = atoi(p);
			if (nfmt == -1 || f > nfmt) {	/* old */
				f = MwFmtOldToNew(f);
			} else {
				f = fmts[f];
			}
			switch (contents[0]) {
			case '$':	/* string expression */
				if ((texti = (contents+1)) == 0)
					return 1;
				ins_data(buf, siod_interpreter, texti,
					value, STRING, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '=':	/* old style expression */
	/* Special case SIOD and C for backward compatibility. */
				if (contents[1] == '=') {	/* C */
					intp = C_interpreter;
					texti = (contents+2);
				} else {	/* SIOD */
					intp = siod_interpreter;
					texti = (contents+1);
				}
				value.number = strtod(texti, &endp);
				if (texti != endp && only_space(endp)) {
					type = CONSTANT;
				} else {
					type = EXPRESSION;
				}
				if (texti == 0) return 1;
				ins_data(buf, intp, texti,
					value, type, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '+':	/* new style expression */
				if ((comma = strchr(contents, ',')) == NULL)
					return 1;
				*comma = '\0';
				intp = name2interpreter(contents+1);
				if (intp < 0) return 1;
				if (intp == siod_interpreter &&
						comma[1] == '=') {
			/* C expression masquerading as SIOD */
					intp = C_interpreter;
					texti = (comma+2);
				} else {
					texti = (comma+1);
				}
				if (texti == 0) return 1;
				ins_data(buf, intp,
					texti, value, EXPRESSION, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case '\"':	/* label */
				if ((texti = (contents + 1)) == 0)
					return 1;
				ins_data(buf, siod_interpreter, texti,
					value, LABEL, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			case 'm':	/* embedded */
				if ((texti = (contents + 1)) == 0)
					return 1;
				embed_load(contents+1);
				ins_data(buf, siod_interpreter, texti,
					value, EMBED, s, i, j);
				ins_format(buf, s, i, j, f);
				break;
			default:	/* anything else means empty */
				ins_format(buf, s, i, j, f);
				break;
			}
			break;
		}