/*
 * Read a control file (or a stanza of a status file) and parse it,
 * filling parsed fields into the package structure
 */
static int control_read(FILE *file, package_t *p)
{
	char *line;

	while ((line = get_line_from_file(file)) != NULL) {
		line[strlen(line)] = 0;

		if (strlen(line) == 0) {
			break;
		} else
			if (strstr(line, "Package: ") == line) {
				p->package = strdup(line + 9);
		} else
			if (strstr(line, "Status: ") == line) {
				p->status = status_parse(line + 8);
		} else
			if (strstr(line, "Depends: ") == line) {
				p->depends = strdup(line + 9);
		} else
			if (strstr(line, "Provides: ") == line) {
				p->provides = strdup(line + 10);
		} else
			if (strstr(line, "Description: ") == line) {
				p->description = strdup(line + 13);
		/* This is specific to the Debian Installer. Ifdef? */
		} else
			if (strstr(line, "installer-menu-item: ") == line) {
				p->installer_menu_item = atoi(line + 21);
		}
		/* TODO: localized descriptions */
	}
	free(line);
	return EXIT_SUCCESS;
}
Пример #2
0
static void
config_tag(void)
{
     struct screen *s;
     struct tag *t;
     size_t i, n;
     struct conf_sec *sec, **ks, **mb;
     char *name, *tmp;
     int screenid;

     /* [tags] */
     sec = fetch_section_first(NULL, "tags");
     ks = fetch_section(sec, "tag");
     n = fetch_section_count(ks);

     if (fetch_opt_first(sec, "1", "circular").boolean)
          W->flags |= WMFS_TAGCIRC;

     /* [mouse] */
     if((mb = fetch_section(sec, "mouse")))
     {
          config_mouse_section(&W->tmp_head.tag, mb);
          free(mb);
     }

     /* [tag] */
     for(i = 0; i < n; ++i)
     {
          name = fetch_opt_first(ks[i], "tag", "name").str;
          screenid = fetch_opt_first(ks[i], "-1", "screen").num;

          SLIST_FOREACH(s, &W->h.screen, next)
               if(screenid == s->id || screenid == -1)
               {
                    t = tag_new(s, name);

                    t->statusctx = status_new_ctx(NULL, NULL);
                    ISTRDUP(t->statusctx.status, fetch_opt_first(ks[i], "", "statusline").str);
                    if(t->statusctx.status)
                         status_parse(&t->statusctx);
               }
     }

     /* If no tag at all on a screen, add one anyway */
     SLIST_FOREACH(s, &W->h.screen, next)
          if(TAILQ_EMPTY(&s->tags))
               tag_new(s, "tag");

     free(ks);
}
Пример #3
0
static void
config_theme(void)
{
     struct theme *t, *p = NULL;
     size_t i, n;
     struct conf_sec *sec, **ks;
     char *tmp;

     /* [themes] */
     sec = fetch_section_first(NULL, "themes");
     ks = fetch_section(sec, "theme");

     /* No theme section? Make one with default value anyway. */
     if(!(n = fetch_section_count(ks)))
          ++n;

     SLIST_INIT(&W->h.theme);

     /* [theme]*/
     for(i = 0; i < n; ++i)
     {
          t = (struct theme*)xcalloc(1, sizeof(struct theme));

          t->name = fetch_opt_first(ks[i], "default", "name").str;

          wmfs_init_font(fetch_opt_first(ks[i], "fixed", "font").str, t);

          /* bars */
          t->bars.fg    = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "bars_fg").str);
          t->bars.bg    = color_atoh(fetch_opt_first(ks[i], "#222222", "bars_bg").str);
          t->bars_width = fetch_opt_first(ks[i], "12", "bars_width").num;

          /*
           * Elements
           */
          t->tags_n.fg         = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_normal_fg").str);
          t->tags_n.bg         = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_normal_bg").str);
          t->tags_s.fg         = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_sel_fg").str);
          t->tags_s.bg         = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_sel_bg").str);
          t->tags_o.fg         = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_occupied_fg").str);
          t->tags_o.bg         = color_atoh(fetch_opt_first(ks[i], "#444444", "tags_occupied_bg").str);
          t->tags_u.fg         = color_atoh(fetch_opt_first(ks[i], "#444444", "tags_urgent_fg").str);
          t->tags_u.bg         = color_atoh(fetch_opt_first(ks[i], "#CC4444", "tags_urgent_bg").str);
          t->tags_border_col   = color_atoh(fetch_opt_first(ks[i], "#888888", "tags_border_color").str);
          t->tags_border_width = fetch_opt_first(ks[i], "0", "tags_border_width").num;

          /* status line */
          t->tags_n_sl = status_new_ctx(NULL, t);
          t->tags_s_sl = status_new_ctx(NULL, t);
          t->tags_o_sl = status_new_ctx(NULL, t);
          t->tags_u_sl = status_new_ctx(NULL, t);

          ISTRDUP(t->tags_n_sl.status, fetch_opt_first(ks[i], "", "tags_normal_statusline").str);
          ISTRDUP(t->tags_s_sl.status, fetch_opt_first(ks[i], "", "tags_sel_statusline").str);
          ISTRDUP(t->tags_o_sl.status, fetch_opt_first(ks[i], "", "tags_occupied_statusline").str);
          ISTRDUP(t->tags_u_sl.status, fetch_opt_first(ks[i], "", "tags_urgent_statusline").str);

          if(t->tags_n_sl.status)
               status_parse(&t->tags_n_sl);
          if(t->tags_s_sl.status)
               status_parse(&t->tags_s_sl);
          if(t->tags_o_sl.status)
               status_parse(&t->tags_o_sl);
          if(t->tags_u_sl.status)
               status_parse(&t->tags_u_sl);

          /* Client / frame */
          t->client_n.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "client_normal_fg").str);
          t->client_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "client_normal_bg").str);
          t->client_s.fg = color_atoh(fetch_opt_first(ks[i], "#222222", "client_sel_fg").str);
          t->client_s.bg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "client_sel_bg").str);
          t->frame_bg    = color_atoh(fetch_opt_first(ks[i], "#555555", "frame_bg").str);
          t->client_titlebar_width = fetch_opt_first(ks[i], "12", "client_titlebar_width").num;
          t->client_border_width   = fetch_opt_first(ks[i], "1", "client_border_width").num;

          /* status line */
          t->client_n_sl = status_new_ctx(NULL, t);
          t->client_s_sl = status_new_ctx(NULL, t);

          ISTRDUP(t->client_n_sl.status, fetch_opt_first(ks[i], "", "client_normal_statusline").str);
          ISTRDUP(t->client_s_sl.status, fetch_opt_first(ks[i], "", "client_sel_statusline").str);

          if(t->client_n_sl.status)
               status_parse(&t->client_n_sl);
          if(t->client_s_sl.status)
               status_parse(&t->client_s_sl);

          SLIST_INSERT_TAIL(&W->h.theme, t, next, p);

          p = t;
     }

     free(ks);
}
Пример #4
0
/*
 * Read a control file (or a stanza of a status file) and parse it,
 * filling parsed fields into the package structure
 */
void control_read(FILE *f, struct package_t *p)
{
	char buf[BUFSIZE];
	while (fgets(buf, BUFSIZE, f) && !feof(f))
	{
		buf[strlen(buf)-1] = 0;
		if (*buf == 0)
			return;
		/* these are common to both installed and uninstalled packages */
		else if (strstr(buf, "Package: ") == buf)
		{
			p->package = strdup(buf+9);
		}
		else if (strstr(buf, "Status: ") == buf)
		{
			p->status = status_parse(buf+8);
		}
		else if (strstr(buf, "Depends: ") == buf)
		{
			p->depends = strdup(buf+9);
		}
		else if (strstr(buf, "Provides: ") == buf)
		{
			p->provides = strdup(buf+10);
		}
		else if (strstr(buf, "Description: ") == buf)
		{
			p->description = strdup(buf+13);
			p->long_description = read_block(f);
		}
#ifdef SUPPORTL10N
		else if (strstr(buf, "description-") == buf)
		{
			/* Localized description */
			struct language_description_t *l;
			l = di_malloc(sizeof(struct language_description_t));
			memset(l,'\0',sizeof (struct language_description_t));
			l->next = p->localized_descriptions;
			p->localized_descriptions = l;
			buf[14] = '\0';
			l->language = strdup(buf+12);
			l->description = strdup(buf+16);
			l->long_description = read_block(f);
		}
#endif
		/* This is specific to the Debian Installer. Ifdef? */
		else if (strcasestr(buf, "Installer-Menu-Item: ") == buf)
		{
			p->installer_menu_item = atoi(buf+21);
		}
		else if (strcasestr(buf, "Priority: ") == buf)
		{
			p->priority = strdup(buf + 10);
		}
		else if (strcasestr(buf, "Section: ") == buf)
		{
			p->section = strdup(buf + 9);
		}
		else if (strcasestr(buf, "Installed-Size: ") == buf)
		{
			p->installed_size = strdup(buf + 16);
		}
		else if (strcasestr(buf, "Maintainer: ") == buf)
		{
			p->maintainer = strdup(buf + 12);
		}
		else if (strcasestr(buf, "Version: ") == buf)
		{
			p->version = strdup(buf + 9);
		}
		else if (strcasestr(buf, "Suggests: ") == buf)
		{
			p->suggests = strdup(buf + 10);
		}
		else if (strcasestr(buf, "Recommends: ") == buf)
		{
			p->recommends = strdup(buf + 12);
		}
		else if (strcasestr(buf, "Conffiles: ") == buf)
		{
			p->conffiles = read_block(f);
		}

	}
}