Exemplo n.º 1
0
Arquivo: parse.c Projeto: att/uwin
/**
*** ParseBack()
*** Parses the options possible to Back
**/
static int ParseBack(char **ss)
{
  char *opts[] =
  {
    "icon",
    NULL
  };
  char *t,*s=*ss;
  int r=0;

  while(*s && *s!=')')
  {
    s = trimleft(s);
    if(*s==',')
      s++;
    else switch(GetTokenIndex(s,opts,-1,&s))
    {
    case 0: /* Icon */
      r=1;
      fprintf(stderr,"%s: Back(Icon) not supported yet\n",MyName);
      break;
    default:
      t=seekright(&s);
      fprintf(stderr,"%s: Illegal back option \"%s\"\n",MyName,(t)?t:"");
      if (t)
	free(t);
    }
  }
  if(*s)
    s++;
  *ss=s;

  return r;
}
Exemplo n.º 2
0
void RTF_DoStyleControl (FILE* f, char* control, char* arg)
{
	if(GetTokenIndex(control)==t_s)
	{
		strcpy(style_number,arg);
	}
}
Exemplo n.º 3
0
Arquivo: Start.c Projeto: att/uwin
Bool StartButtonParseConfig(char *tline)
{
  char *rest;
  char *option;
  int i;

  option = tline + Clength;
  i = GetTokenIndex(option, startopts, -1, &rest);
  while (*rest && *rest != '\n' && isspace(*rest))
    rest++;
  switch(i)
  {
  case 0: /* StartName */
    CopyString(&StartName, rest);
    break;
  case 1: /* StartMenu */
    CopyString(&StartPopup, rest);
    break;
  case 2: /* StartIcon */
    CopyString(&StartIconName, rest);
    break;
  default:
    /* unknown option */
    return False;
  } /* switch */

  return True;
}
Exemplo n.º 4
0
/**
*** ParseOptions()
**/
void ParseConfiguration(button_info *ub)
{
	char *s;
	char *items[] =
	{
		NULL, /* filled out below */
		"imagepath",
		"colorset",
		XINERAMA_CONFIG_STRING,
		NULL
	};

	items[0] = mymalloc(strlen(MyName) + 2);
	sprintf(items[0], "*%s", MyName);

	/* send config lines with MyName */
	InitGetConfigLine(fd, items[0]);
	GetConfigLine(fd, &s);
	while (s && s[0])
	{
		char *rest;
		switch (GetTokenIndex(s,items,-1,&rest))
		{
		case -1:
			break;
		case 0:
			if (rest && rest[0] && !config_file)
			{
				ParseConfigLine(&ub, rest);
			}
			break;
		case 1:
			if (imagePath)
			{
				free(imagePath);
			}
			CopyString(&imagePath, rest);
			break;
		case 2:
			/* store colorset sent by fvwm */
			LoadColorset(rest);
			break;
		case 3:
			/* Xinerama state */
			FScreenConfigureModule(rest);
			break;
		}
		GetConfigLine(fd,&s);
	}

	if (config_file)
	{
		ParseConfigFile(ub);
	}

	free(items[0]);
	return;
}
Exemplo n.º 5
0
/* Parse and set options for this taskbar button (start or launcher). This
 * will check for a string of the form (<opt1>,<opt2>...), similar to options
 * for an FvwmButtons button. The return value is a pointer to the rest of the
 * config line.
 *
 * Currently this sets just one option, mouseButton. If no "Mouse <n>" option
 * is found, mouseButton will be set to 0.
 */
char *ParseButtonOptions(char *pos, int *mouseButton)
{
  char *token = NULL;
  char *rest;
  int i;
  static char *buttonOptions[] = {"Mouse", NULL};

  *mouseButton = 0;
  while (*pos && isspace(*pos))
    pos++;
  if (*pos != '(')
    return pos;
  pos++;
  while (*pos && isspace(*pos))
    pos++;

  while (*pos && *pos != ')')
  {
    pos = GetNextToken(pos, &token);
    if (!token)
        break;
    i = GetTokenIndex(token, buttonOptions, 0, NULL);
    switch (i)
    {
    case 0:   /* Mouse */
      *mouseButton = strtol(pos, &rest, 10);
      pos = rest;
      if (*mouseButton < 1 || *mouseButton > NUMBER_OF_EXTENDED_MOUSE_BUTTONS)
      {
        fprintf(stderr,"%s: Invalid mouse button %d", module->name,
                *mouseButton);
        *mouseButton = 0;
      }
      break;

    default:
      fprintf(stderr,"%s: Invalid taskbar button option '%s'", module->name,
              token);
    }
    while (*pos && *pos != ',' && *pos != ')')
      pos++;
    if (*pos == ',') {
      pos++;
      while (*pos && *pos != ',' && *pos != ')')
        pos++;
    }
    free(token);
  }

  if (*pos)
    pos++;
  while (*pos && isspace(*pos))
    pos++;
  return pos;
}
Exemplo n.º 6
0
Arquivo: parse.c Projeto: att/uwin
/**
*** ParseTitle()
*** Parses the options possible to Title
**/
static void ParseTitle(char **ss, byte *flags, byte *mask)
{
  char *titleopts[] =
  {
    "left",
    "right",
    "center",
    "side",
    NULL
  };
  char *t,*s=*ss;

  while(*s && *s!=')')
  {
    s = trimleft(s);
    if(*s==',')
      s++;
    else switch(GetTokenIndex(s,titleopts,-1,&s))
    {
    case 0: /* Left */
      *flags&=~b_TitleHoriz;
      *mask|=b_TitleHoriz;
      break;
    case 1: /* Right */
      *flags&=~b_TitleHoriz;
      *flags|=2;
      *mask|=b_TitleHoriz;
      break;
    case 2: /* Center */
      *flags&=~b_TitleHoriz;
      *flags|=1;
      *mask|=b_TitleHoriz;
      break;
    case 3: /* Side */
      *flags|=b_Horizontal;
      *mask|=b_Horizontal;
      break;
    default:
      t=seekright(&s);
      fprintf(stderr,"%s: Illegal title option \"%s\"\n",MyName,(t)?t:"");
      if (t)
	free(t);
    }
  }
  if(*s) s++;
  *ss=s;
}
Exemplo n.º 7
0
/**
*** ParseSwallow()
*** Parses the options possible to Swallow
**/
static void ParseSwallow(
	char **ss, unsigned int *flags, unsigned int *mask, button_info *b)
{
	char *swallowopts[] =
	{
		"nohints", "hints",
		"nokill", "kill",
		"noclose", "close",
		"respawn", "norespawn",
		"useold", "noold",
		"usetitle", "notitle",
		"fvwmmodule", "nofvwmmodule",
		"swallownew",
		NULL
	};
	char *t, *s = *ss;

	while (*s && *s != ')')
	{
		s = trimleft(s);
		if (*s == ',')
		{
			s++;
			continue;
		}

		switch (GetTokenIndex(s, swallowopts, -1, &s))
		{
		case 0: /* NoHints */
			*flags |= b_NoHints;
			*mask |= b_NoHints;
			break;
		case 1: /* Hints */
			*flags &= ~b_NoHints;
			*mask |= b_NoHints;
			break;
		case 2: /* NoKill */
			*flags &= ~b_Kill;
			*mask |= b_Kill;
			break;
		case 3: /* Kill */
			*flags |= b_Kill;
			*mask |= b_Kill;
			break;
		case 4: /* NoClose */
			*flags |= b_NoClose;
			*mask |= b_NoClose;
			break;
		case 5: /* Close */
			*flags &= ~b_NoClose;
			*mask |= b_NoClose;
			break;
		case 6: /* Respawn */
			*flags |= b_Respawn;
			*mask |= b_Respawn;
			b->newflags.do_swallow_new = 0;
			break;
		case 7: /* NoRespawn */
			*flags &= ~b_Respawn;
			*mask |= b_Respawn;
			b->newflags.do_swallow_new = 0;
			break;
		case 8: /* UseOld */
			*flags |= b_UseOld;
			*mask |= b_UseOld;
			break;
		case 9: /* NoOld */
			*flags &= ~b_UseOld;
			*mask |= b_UseOld;
			break;
		case 10: /* UseTitle */
			*flags |= b_UseTitle;
			*mask |= b_UseTitle;
			break;
		case 11: /* NoTitle */
			*flags &= ~b_UseTitle;
			*mask |= b_UseTitle;
			break;
		case 12: /* FvwmModule */
			*flags |= b_FvwmModule;
			*mask |= b_FvwmModule;
			break;
		case 13: /* NoFvwmModule */
			*flags &= ~b_FvwmModule;
			*mask |= b_FvwmModule;
			break;
		case 14: /* SwallowNew */
			*flags &= ~b_Respawn;
			*mask |= b_Respawn;
			b->newflags.do_swallow_new = 1;
			break;
		default:
			t = seekright(&s);
			fprintf(stderr,
				"%s: Illegal Swallow option \"%s\"\n", MyName,
				(t) ? t : "");
			if (t)
			{
				free(t);
			}
		}
	}
	if (*s)
	{
		s++;
	}
	*ss = s;
}
Exemplo n.º 8
0
/**
*** ParseConfigLine
**/
static void ParseConfigLine(button_info **ubb, char *s)
{
	button_info *ub = *ubb;
	char *opts[] =
	{
		"geometry",
		"buttongeometry",
		"font",
		"padding",
		"columns",
		"rows",
		"back",
		"fore",
		"frame",
		"file",
		"pixmap",
		"boxsize",
		"colorset",
		"activecolorset",
		"presscolorset",
		NULL
	};
	int i, j, k;

	switch (GetTokenIndex(s, opts, -1, &s))
	{
	case 0:/* Geometry */
	{
		char geom[64];

		i = sscanf(s, "%63s", geom);
		if (i == 1)
		{
			parse_window_geometry(geom, 0);
		}
		break;
	}
	case 1:/* ButtonGeometry */
	{
		char geom[64];

		i = sscanf(s, "%63s", geom);
		if (i == 1)
		{
			parse_window_geometry(geom, 1);
		}
		break;
	}
	case 2:/* Font */
		if (ub->c->font_string)
		{
			free(ub->c->font_string);
		}
		CopyStringWithQuotes(&ub->c->font_string, s);
		break;
	case 3:/* Padding */
		i = sscanf(s, "%d %d", &j, &k);
		if (i > 0)
		{
			ub->c->xpad = ub->c->ypad = j;
		}
		if (i > 1)
		{
			ub->c->ypad = k;
		}
		break;
	case 4:/* Columns */
		i = sscanf(s, "%d", &j);
		if (i > 0)
		{
			ub->c->num_columns = j;
		}
		break;
	case 5:/* Rows */
		i = sscanf(s, "%d", &j);
		if (i > 0)
		{
			ub->c->num_rows = j;
		}
		break;
	case 6:/* Back */
		if (ub->c->back)
		{
			free(ub->c->back);
		}
		CopyString(&(ub->c->back), s);
		break;
	case 7:/* Fore */
		if (ub->c->fore)
		{
			free(ub->c->fore);
		}
		CopyString(&(ub->c->fore), s);
		break;
	case 8:/* Frame */
		i = sscanf(s,"%d",&j);
		if (i > 0)
		{
			ub->c->framew = j;
		}
		break;
	case 9:/* File */
		s = trimleft(s);
		if (config_file)
		{
			free(config_file);
		}
		config_file = seekright(&s);
		break;
	case 10:/* Pixmap */
		s = trimleft(s);
		if (strncasecmp(s, "none", 4) == 0)
		{
			ub->c->flags.b_TransBack = 1;
		}
		else
		{
			if (ub->c->back_file)
			{
				free(ub->c->back_file);
			}
			CopyString(&(ub->c->back_file),s);
		}
		ub->c->flags.b_IconBack = 1;
		break;
	case 11: /* BoxSize */
		ParseBoxSize(&s, &ub->c->flags);
		break;
	case 12: /* Colorset */
		i = sscanf(s, "%d", &j);
		if (i > 0)
		{
			ub->c->colorset = j;
			ub->c->flags.b_Colorset = 1;
			AllocColorset(j);
		}
		else
		{
			ub->c->flags.b_Colorset = 0;
		}
		break;
	case 13: /* ActiveColorset */
		i = sscanf(s, "%d", &j);
		if (i > 0)
		{
			ub->c->activeColorset = j;
			ub->c->flags.b_ActiveColorset = 1;
			AllocColorset(j);
		}
		else
		{
			ub->c->flags.b_ActiveColorset = 0;
		}
		break;
	case 14: /* PressColorset */
		i = sscanf(s, "%d", &j);
		if (i > 0)
		{
			ub->c->pressColorset = j;
			ub->c->flags.b_PressColorset = 1;
			AllocColorset(j);
		}
		else
		{
			ub->c->flags.b_PressColorset = 0;
		}
		break;

	default:
		s = trimleft(s);
		ParseButton(ubb, s);
		break;
	}
}
Exemplo n.º 9
0
static signed int expand_vars_extended(
	char *var_name, char *output, cond_rc_t *cond_rc,
	const exec_context_t *exc)
{
	char *rest;
	char dummy[64] = "\0";
	char *target = (output) ? output : dummy;
	int cs = -1;
	int n;
	int i;
	int l;
	int x;
	int y;
	Pixel pixel = 0;
	int val = -12345678;
	const char *string = NULL;
	char *allocated_string = NULL;
	char *quoted_string = NULL;
	Bool should_quote = False;
	Bool is_numeric = False;
	Bool is_target = False;
	Bool is_x;
	Window context_w = Scr.Root;
	FvwmWindow *fw = exc->w.fw;
	signed int len = -1;

	/* allow partial matches for *.cs, gt, ... etc. variables */
	switch ((i = GetTokenIndex(var_name, partial_function_vars, -1, &rest)))
	{
	case VAR_FG_CS:
	case VAR_BG_CS:
	case VAR_HILIGHT_CS:
	case VAR_SHADOW_CS:
	case VAR_FGSH_CS:
		if (!isdigit(*rest) || (*rest == '0' && *(rest + 1) != 0))
		{
			/* not a non-negative integer without leading zeros */
			return -1;
		}
		if (sscanf(rest, "%d%n", &cs, &n) < 1)
		{
			return -1;
		}
		if (*(rest + n) != 0)
		{
			/* trailing characters */
			return -1;
		}
		if (cs < 0)
		{
			return -1;
		}
		alloc_colorset(cs);
		switch (i)
		{
		case VAR_FG_CS:
			pixel = Colorset[cs].fg;
			break;
		case VAR_BG_CS:
			pixel = Colorset[cs].bg;
			break;
		case VAR_HILIGHT_CS:
			pixel = Colorset[cs].hilite;
			break;
		case VAR_SHADOW_CS:
			pixel = Colorset[cs].shadow;
			break;
		case VAR_FGSH_CS:
			pixel = Colorset[cs].fgsh;
			break;
		}
		is_target = True;
		len = pixel_to_color_string(dpy, Pcmap, pixel, target, False);
		goto GOT_STRING;
	case VAR_GT_:
		if (rest == NULL)
		{
			return -1;
		}
		string = _(rest);
		goto GOT_STRING;
	case VAR_INFOSTORE_:
		if (rest == NULL)
			return -1;

		if ((string = get_metainfo_value(rest)) == NULL)
			return -1;

		goto GOT_STRING;
	case VAR_DESK_NAME:
		if (sscanf(rest, "%d%n", &cs, &n) < 1)
		{
			return -1;
		}
		if (*(rest + n) != 0)
		{
			/* trailing characters */
			return -1;
		}
		string = GetDesktopName(cs);
		if (string == NULL)
		{
			const char *ddn = _("Desk");
			allocated_string = (char *)safemalloc(19 + strlen(ddn));
			sprintf(allocated_string, "%s %i", ddn, cs);
			string = allocated_string;
		}
		goto GOT_STRING;
	default:
		break;
	}

	/* only exact matches for all other variables */
	switch ((i = GetTokenIndex(var_name, function_vars, 0, &rest)))
	{
	case VAR_DESK_N:
		is_numeric = True;
		val = Scr.CurrentDesk;
		break;
	case VAR_DESK_WIDTH:
		is_numeric = True;
		val = Scr.VxMax + Scr.MyDisplayWidth;
		break;
	case VAR_DESK_HEIGHT:
		is_numeric = True;
		val = Scr.VyMax + Scr.MyDisplayHeight;
		break;
	case VAR_DESK_PAGESX:
		is_numeric = True;
		val = (int)(Scr.VxMax / Scr.MyDisplayWidth) + 1;
		break;
	case VAR_DESK_PAGESY:
		is_numeric = True;
		val = (int)(Scr.VyMax / Scr.MyDisplayHeight) + 1;
		break;
	case VAR_VP_X:
		is_numeric = True;
		val = Scr.Vx;
		break;
	case VAR_VP_Y:
		is_numeric = True;
		val = Scr.Vy;
		break;
	case VAR_VP_WIDTH:
		is_numeric = True;
		val = Scr.MyDisplayWidth;
		break;
	case VAR_VP_HEIGHT:
		is_numeric = True;
		val = Scr.MyDisplayHeight;
		break;
	case VAR_WA_HEIGHT:
		is_numeric = True;
		val = Scr.Desktops->ewmh_working_area.height;
		break;
	case VAR_WA_WIDTH:
		is_numeric = True;
		val = Scr.Desktops->ewmh_working_area.width;
		break;
	case VAR_WA_X:
		is_numeric = True;
		val = Scr.Desktops->ewmh_working_area.x;
		break;
	case VAR_WA_Y:
		is_numeric = True;
		val = Scr.Desktops->ewmh_working_area.y;
		break;
	case VAR_DWA_HEIGHT:
		is_numeric = True;
		val = Scr.Desktops->ewmh_dyn_working_area.height;
		break;
	case VAR_DWA_WIDTH:
		is_numeric = True;
		val = Scr.Desktops->ewmh_dyn_working_area.width;
		break;
	case VAR_DWA_X:
		is_numeric = True;
		val = Scr.Desktops->ewmh_dyn_working_area.x;
		break;
	case VAR_DWA_Y:
		is_numeric = True;
		val = Scr.Desktops->ewmh_dyn_working_area.y;
		break;
	case VAR_PAGE_NX:
		is_numeric = True;
		val = (int)(Scr.Vx / Scr.MyDisplayWidth);
		break;
	case VAR_PAGE_NY:
		is_numeric = True;
		val = (int)(Scr.Vy / Scr.MyDisplayHeight);
		break;
	case VAR_W_ID:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			is_target = True;
			sprintf(target, "0x%x", (int)FW_W(fw));
		}
		break;
	case VAR_W_NAME:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			string = fw->name.name;
			should_quote = True;
		}
		break;
	case VAR_W_ICONNAME:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			string = fw->icon_name.name;
			should_quote = True;
		}
		break;
	case VAR_W_ICONFILE:
	case VAR_W_MINIICONFILE:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			char *t;

			t = (i == VAR_W_ICONFILE) ?
				fw->icon_bitmap_file : fw->mini_pixmap_file;
			/* expand the path if possible */
			allocated_string = PictureFindImageFile(t, NULL, R_OK);
			if (allocated_string == NULL)
			{
				string = t;
			}
			else if (USE_SVG && *allocated_string == ':' &&
				 (string = strchr(allocated_string + 1, ':')))
			{
				string++;
			}
			else
			{
				string = allocated_string;
			}
		}
		break;
	case VAR_W_ICONFILE_SVGOPTS:
	case VAR_W_MINIICONFILE_SVGOPTS:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			char *t;

			if (!USE_SVG)
			{
				return -1;
			}
			t = (i == VAR_W_ICONFILE_SVGOPTS) ?
				fw->icon_bitmap_file : fw->mini_pixmap_file;
			/* expand the path if possible */
			allocated_string = PictureFindImageFile(t, NULL, R_OK);
			string = allocated_string;
			if (string && *string == ':' &&
			    (t = strchr(string + 1, ':')))
			{
				*t = 0;
			}
			else
			{
				string = "";
			}
		}
		break;
	case VAR_W_CLASS:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			string = fw->class.res_class;
			should_quote = True;
		}
		break;
	case VAR_W_RESOURCE:
		if (fw && !IS_EWMH_DESKTOP(FW_W(fw)))
		{
			string = fw->class.res_name;
			should_quote = True;
		}
Exemplo n.º 10
0
/*#define DEBUG_PARSER*/
static void ParseButton(button_info **uberb, char *s)
{
	button_info *b, *ub = *uberb;
	int i, j;
	char *t, *o;

	b = alloc_button(ub, (ub->c->num_buttons)++);
	s = trimleft(s);

	if (*s == '(' && s++)
	{
		char *opts[] =
		{
			"back",
			"fore",
			"font",
			"title",
			"icon",
			"frame",
			"padding",
			"swallow",
			"panel",
			"actionignoresclientwindow",
			"actiononpress",
			"container",
			"end",
			"nosize",
			"size",
			"left",
			"right",
			"center",
			"colorset",
			"action",
			"id",
			"activeicon",
			"activetitle",
			"pressicon",
			"presstitle",
			"activecolorset",
			"presscolorset",
			"top",
			NULL
		};
		s = trimleft(s);
		while (*s && *s != ')')
		{
			Bool is_swallow = False;

			if (*s == ',')
			{
				s++;
				s = trimleft(s);
				continue;
			}
			if (isdigit(*s) || *s == '+' || *s == '-')
			{
				char *geom;
				int x, y, flags;
				unsigned int w, h;
				geom = seekright(&s);
				if (geom)
				{
					flags = XParseGeometry(geom, &x, &y, &w, &h);
					if (flags&WidthValue)
					{
						b->BWidth = w;
					}
					if (flags&HeightValue)
					{
						b->BHeight = h;
					}
					if (flags & XValue)
					{
						b->BPosX = x;
						b->flags.b_PosFixed = 1;
					}
					if (flags & YValue)
					{
						b->BPosY = y;
						b->flags.b_PosFixed = 1;
					}
					if (flags & XNegative)
					{
						b->BPosX = -1 - x;
					}
					if (flags & YNegative)
					{
						b->BPosY = -1 - y;
					}
					free(geom);
				}
				s = trimleft(s);
				continue;
			}
			switch (GetTokenIndex(s, opts, -1, &s))
			{
			case 0: /* Back */
				s = trimleft(s);
				if (*s == '(' && s++ && ParseBack(&s))
				{
					b->flags.b_IconBack = 1;
				}
				if (b->flags.b_Back && b->back)
				{
					free(b->back);
				}
				b->back = seekright(&s);
				if (b->back)
				{
					b->flags.b_Back = 1;
				}
				else
				{
					b->flags.b_IconBack = 0;
					b->flags.b_Back = 0;
				}
				break;

			case 1: /* Fore */
				if (b->flags.b_Fore && b->fore)
				{
					free(b->fore);
				}
				b->fore = seekright(&s);
				b->flags.b_Fore = (b->fore ? 1 : 0);
				break;

			case 2: /* Font */
				if (b->flags.b_Font && b->font_string)
				{
					free(b->font_string);
				}
				b->font_string = my_get_font(&s);
				b->flags.b_Font = (b->font_string ? 1 : 0);
				break;

			/* ----------------- title --------------- */

			case 3: /* Title */
				s = trimleft(s);
				if (*s == '(' && s++)
				{
					b->justify = 0;
					b->justify_mask = 0;
					ParseTitle(
						&s, &b->justify,
						&b->justify_mask);
					if (b->justify_mask)
					{
						b->flags.b_Justify = 1;
					}
				}
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->title)
					{
						free(b->title);
					}
					b->title = t;
#ifdef DEBUG_PARSER
					fprintf(stderr,
						"PARSE: Title \"%s\"\n",
						b->title);
#endif
					b->flags.b_Title = 1;
				}
				else
				{
					fprintf(stderr,
						"%s: Missing title argument\n",
						MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* ------------------ icon --------------- */

			case 4: /* Icon */
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->flags.b_Swallow)
					{
						fprintf(stderr,
							"%s: a button can not "
							"have an icon and a "
							"swallowed window at "
							"the same time. "
							"Ignoring icon\n",
							MyName);
					}
					else
					{
						if (b->icon_file)
						{
							free(b->icon_file);
						}
						b->icon_file = t;
						b->flags.b_Icon = 1;
					}
				}
				else
				{
					fprintf(stderr,
						"%s: Missing Icon argument\n",
						MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* ----------------- frame --------------- */

			case 5: /* Frame */
				i = strtol(s, &t, 10);
				if (t > s)
				{
					b->flags.b_Frame = 1;
					b->framew = i;
					s = t;
				}
				else
				{
					fprintf(stderr,
						"%s: Illegal frame argument\n",
						MyName);
				}
				break;

			/* ---------------- padding -------------- */

			case 6: /* Padding */
				i = strtol(s,&t,10);
				if (t>s)
				{
					b->xpad = b->ypad = i;
					b->flags.b_Padding = 1;
					s = t;
					i = strtol(s, &t, 10);
					if (t > s)
					{
						b->ypad = i;
						s = t;
					}
				}
				else
				{
					fprintf(stderr,
						"%s: Illegal padding "
						"argument\n", MyName);
				}
				break;

			/* ---------------- swallow -------------- */

			case 7: /* Swallow */
				is_swallow = True;
				/* fall through */

			case 8: /* Panel */
				s = trimleft(s);
				if (is_swallow)
				{
					b->swallow = 0;
					b->swallow_mask = 0;
				}
				else
				{
					/* set defaults */
					b->swallow = b_Respawn;
					b->swallow_mask = b_Respawn;
					b->slide_direction = SLIDE_UP;
					b->slide_position = SLIDE_POSITION_CENTER;
					b->slide_context = SLIDE_CONTEXT_PB;
					b->relative_x = 0;
					b->relative_y = 0;
					b->slide_steps = 12;
					b->slide_delay_ms = 5;
				}
				if (*s == '(' && s++)
				{
					if (is_swallow)
					{
						ParseSwallow(
							&s, &b->swallow,
							&b->swallow_mask, b);
					}
					else
					{
						ParsePanel(
							&s, &b->swallow,
							&b->swallow_mask,
							&b->slide_direction,
							&b->slide_steps,
							&b->slide_delay_ms,
							&b->panel_flags,
							&b->indicator_size,
							&b->relative_x,
							&b->relative_y,
							&b->slide_position,
							&b->slide_context);
					}
				}
				t = seekright(&s);
				o = seekright(&s);
				if (t)
				{
					if (b->hangon)
					{
						free(b->hangon);
					}
					b->hangon = t;
					if (is_swallow)
					{
						if (b->flags.b_Icon)
						{
							fprintf(stderr,
							"%s: a button can not "
							"have an icon and a "
							"swallowed window at "
							"the same time. "
							"Ignoring icon\n",
							MyName);
							b->flags.b_Icon = 0;
						}

						b->flags.b_Swallow = 1;
						b->flags.b_Hangon = 1;
					}
					else
					{
						b->flags.b_Panel = 1;
						b->flags.b_Hangon = 1;
						b->newflags.is_panel = 1;
						b->newflags.panel_mapped = 0;
					}
					b->swallow |= 1;
					if (!(b->swallow & b_NoHints))
					{
						b->hints = (XSizeHints*)
						mymalloc(sizeof(XSizeHints));
					}
					if (o)
					{
						char *p;

						p = module_expand_action(
							Dpy, screen, o, NULL,
							UberButton->c->fore,
							UberButton->c->back);
						if (p)
						{
							if (!(buttonSwallow(b)&b_UseOld))
							{
								exec_swallow(p,b);
							}
							if (b->spawn)
							{
								free(b->spawn);
							}

							/* Might be needed if
							 * respawning sometime
							 */
							b->spawn = o;
							free(p);
						}
					}
				}
				else
				{
					fprintf(stderr,
						"%s: Missing swallow "
						"argument\n", MyName);
					if (t)
					{
						free(t);
					}
					if (o)
					{
						free(o);
					}
				}
				/* check if it is a module by command line inspection if
				 * this hints has not been given in the swallow option */
				if (is_swallow && !(b->swallow_mask & b_FvwmModule))
				{
					if (b->spawn != NULL &&
					    (strncasecmp(b->spawn, "module", 6) == 0 ||
					     strncasecmp(b->spawn, "fvwm", 4) == 0))
					{
						b->swallow |= b_FvwmModule;
					}
				}
				break;

			case 9: /* ActionIgnoresClientWindow */
				b->flags.b_ActionIgnoresClientWindow = 1;
				break;

			case 10: /* ActionOnPress */
				b->flags.b_ActionOnPress = 1;
				break;

			/* ---------------- container ------------ */

			case 11: /* Container */
				/*
				 * SS: This looks very buggy! The FvwmButtons
				 * man page suggests it's here to restrict the
				 * options used with "Container", but it only
				 * restricts those options appearing _before_
				 * the "Container" keyword for a button.
				 * b->flags&=b_Frame|b_Back|b_Fore|b_Padding|b_Action;
				 */

				MakeContainer(b);
				*uberb = b;
				s = trimleft(s);
				if (*s == '(' && s++)
				{
					ParseContainer(&s,b);
				}
				break;

			case 12: /* End */
				*uberb = ub->parent;
				ub->c->buttons[--(ub->c->num_buttons)] = NULL;
				free(b);
				if (!ub->parent)
				{
					fprintf(stderr,"%s: Unmatched END in config file\n",MyName);
					exit(1);
				}
				if (ub->parent->c->flags.b_Colorset ||
				    ub->parent->c->flags.b_ColorsetParent)
				{
					ub->c->flags.b_ColorsetParent = 1;
				}
				if (ub->parent->c->flags.b_IconBack || ub->parent->c->flags.b_IconParent)
				{
					ub->c->flags.b_IconParent = 1;
				}
				return;

			case 13: /* NoSize */
				b->flags.b_Size = 1;
				b->minx = b->miny = 0;
				break;

			case 14: /* Size */
				i = strtol(s, &t, 10);
				j = strtol(t, &o, 10);
				if (t > s && o > t)
				{
					b->minx = i;
					b->miny = j;
					b->flags.b_Size = 1;
					s = o;
				}
				else
				{
					fprintf(stderr,
						"%s: Illegal size arguments\n",
						MyName);
				}
				break;

			case 15: /* Left */
				b->flags.b_Left = 1;
				b->flags.b_Right = 0;
				break;

			case 16: /* Right */
				b->flags.b_Right = 1;
				b->flags.b_Left = 0;
				break;

			case 17: /* Center */
				b->flags.b_Right = 0;
				b->flags.b_Left = 0;
				break;

			case 18: /* Colorset */
				i = strtol(s, &t, 10);
				if (t > s)
				{
					b->colorset = i;
					b->flags.b_Colorset = 1;
					s = t;
					AllocColorset(i);
				}
				else
				{
					b->flags.b_Colorset = 0;
				}
				break;

			/* ----------------- action -------------- */

			case 19: /* Action */
				s = trimleft(s);
				i = 0;
				if (*s == '(')
				{
					s++;
					if (strncasecmp(s, "mouse", 5) != 0)
					{
						fprintf(stderr,
							"%s: Couldn't parse "
							"action\n", MyName);
					}
					s += 5;
					i = strtol(s, &t, 10);
					s = t;
					while (*s && *s != ')')
					{
						s++;
					}
					if (*s == ')')
					{
						s++;
					}
				}
				{
					char *r;
					char *u = s;

					s = GetQuotedString(s, &t, ",)", NULL, "(", ")");
					r = s;
					if (t && r > u + 1)
					{
						/* remove unquoted trailing spaces */
						r -= 2;
						while (r >= u && isspace(*r))
						{
							r--;
						}
						r++;
						if (isspace(*r))
						{
							t[strlen(t) - (s - r - 1)] = 0;
						}
					}
				}
				if (t)
				{
					AddButtonAction(b,i,t);
					free(t);
				}
				else
				{
					fprintf(stderr,
						"%s: Missing action argument\n",
						MyName);
				}
				break;

			case 20: /* Id */
				s = trimleft(s);
				s = DoGetNextToken(s, &t, NULL, ",)", &terminator);

				/* it should include the delimiter */
				if (s && terminator == ')')
				{
					s--;
				}

				if (t)
				{
					if (isalpha(t[0]))
					{
						/* should check for duplicate ids first... */
						b->flags.b_Id = 1;
						if (b->id)
						{
							free(b->id);
						}
						CopyString(&b->id, t);
					}
			        	else
					{
						fprintf(stderr,
							"%s: Incorrect id '%s' "
							"ignored\n", MyName, t);
					}
					free(t);
				}
				else
				{
					fprintf(stderr,
						"%s: Missing id argument\n",
						MyName);
				}
				break;

			/* ------------------ ActiveIcon --------------- */
			case 21: /* ActiveIcon */
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->flags.b_Swallow)
					{
						fprintf(stderr,
							"%s: a button can not "
							"have a ActiveIcon and "
							"a swallowed window at "
							"the same time. "
							"Ignoring ActiveIcon.\n",
							MyName);
					}
					else
					{
						if (b->active_icon_file)
						{
							free(b->active_icon_file);
						}
						b->active_icon_file = t;
						b->flags.b_ActiveIcon = 1;
					}
				}
				else
				{
					fprintf(stderr,
						"%s: Missing ActiveIcon "
						"argument\n", MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* --------------- ActiveTitle --------------- */
			case 22: /* ActiveTitle */
				s = trimleft(s);
				if (*s == '(')
				{
					fprintf(stderr,
						"%s: justification not allowed "
						"for ActiveTitle.\n", MyName);
				}
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->activeTitle)
					{
						free(b->activeTitle);
					}
					b->activeTitle = t;
#ifdef DEBUG_PARSER
					fprintf(stderr,
						"PARSE: ActiveTitle \"%s\"\n",
						b->activeTitle);
#endif
					b->flags.b_ActiveTitle = 1;
				}
				else
				{
					fprintf(stderr,
						"%s: Missing ActiveTitle "
						"argument\n", MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* --------------- PressIcon --------------- */
			case 23: /* PressIcon */
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->flags.b_Swallow)
					{
						fprintf(stderr,
							"%s: a button can not "
							"have a PressIcon and "
							"a swallowed window at "
							"the same time. "
							"Ignoring PressIcon.\n",
							MyName);
					}
					else
					{
						if (b->press_icon_file)
						{
							free(b->press_icon_file);
						}
						b->press_icon_file = t;
						b->flags.b_PressIcon = 1;
					}
				}
				else
				{
					fprintf(stderr,
						"%s: Missing PressIcon "
						"argument\n", MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* --------------- PressTitle --------------- */
			case 24: /* PressTitle */
				s = trimleft(s);
				if (*s == '(')
				{
					fprintf(stderr,
						"%s: justification not allowed "
						"for PressTitle.\n", MyName);
				}
				t = seekright(&s);
				if (t && *t && (t[0] != '-' || t[1] != 0))
				{
					if (b->pressTitle)
					{
						free(b->pressTitle);
					}
					b->pressTitle = t;
#ifdef DEBUG_PARSER
					fprintf(stderr,
						"PARSE: PressTitle \"%s\"\n",
						b->pressTitle);
#endif
					b->flags.b_PressTitle = 1;
				}
				else
				{
					fprintf(stderr,
						"%s: Missing PressTitle "
						"argument\n", MyName);
					if (t)
					{
						free(t);
					}
				}
				break;

			/* --------------- --------------- */
			case 25: /* ActiveColorset */
				i = strtol(s, &t, 10);
				if (t > s)
				{
					b->activeColorset = i;
					b->flags.b_ActiveColorset = 1;
					s = t;
					AllocColorset(i);
				}
				else
				{
					b->flags.b_ActiveColorset = 0;
				}
				break;

			/* --------------- --------------- */
			case 26: /* PressColorset */
				i = strtol(s, &t, 10);
				if (t > s)
				{
					b->pressColorset = i;
					b->flags.b_PressColorset = 1;
					s = t;
					AllocColorset(i);
				}
				else
				{
					b->flags.b_PressColorset = 0;
				}
				break;

			case 27: /* top */
				b->flags.b_Top = 1;
				break;
			/* --------------- --------------- */
			default:
				t = seekright(&s);
				fprintf(stderr,
					"%s: Illegal button option \"%s\"\n",
					MyName, (t) ? t : "");
				if (t)
				{
					free(t);
				}
				break;
			} /* end switch */
			s = trimleft(s);
		}
		if (s && *s)
		{
			s++;
			s = trimleft(s);
		}
	}

	/* get title and iconname */
	if (!b->flags.b_Title)
	{
		b->title = seekright(&s);
		if (b->title && *b->title &&
			((b->title)[0] != '-' || (b->title)[1] != 0))
		{
			b->flags.b_Title = 1;
		}
		else if (b->title)
		{
			free(b->title);
		}
	}
	else
	{
		char *temp;
		temp = seekright(&s);
		if (temp)
		{
			free(temp);
		}
	}

	if (!b->flags.b_Icon)
	{
		b->icon_file = seekright(&s);
		if (b->icon_file && b->icon_file &&
			 ((b->icon_file)[0] != '-'||(b->icon_file)[1] != 0))
		{
			b->flags.b_Icon = 1;
		}
		else if (b->icon_file)
		{
			free(b->icon_file);
		}
	}
	else
	{
		char *temp;
		temp = seekright(&s);
		if (temp)
		{
			free(temp);
		}
	}

	s = trimleft(s);

	/* Swallow hangon command */
	if (strncasecmp(s, "swallow", 7) == 0 || strncasecmp(s, "panel", 7) == 0)
	{
		if (b->flags.b_Swallow || b->flags.b_Panel)
		{
			fprintf(stderr,
				"%s: Illegal with both old and new swallow!\n",
				MyName);
			exit(1);
		}
		s += 7;
		/*
		 * Swallow old 'swallowmodule' command
		 */
		if (strncasecmp(s, "module", 6) == 0)
		{
			s += 6;
		}
		if (b->hangon)
		{
			free(b->hangon);
		}
		b->hangon = seekright(&s);
		if (!b->hangon)
		{
			b->hangon = safestrdup("");
		}
		if (tolower(*s) == 's')
		{
			b->flags.b_Swallow = 1;
			b->flags.b_Hangon = 1;
		}
		else
		{
			b->flags.b_Panel = 1;
			b->flags.b_Hangon = 1;
		}
		b->swallow |= 1;
		s = trimleft(s);
		if (!(b->swallow & b_NoHints))
		{
			b->hints = (XSizeHints*)mymalloc(sizeof(XSizeHints));
		}
		if (*s)
		{
			if (!(buttonSwallow(b) & b_UseOld))
			{
				SendText(fd, s, 0);
			}
			b->spawn = safestrdup(s);
		}
	}
	else if (*s)
	{
		AddButtonAction(b, 0, s);
	}
	return;
}
Exemplo n.º 11
0
Pixel GetColor(char *name)
{
	int i;
	int n;
	int cs;
	char *rest;
	XColor color;

	switch ((i = GetTokenIndex(name, colorset_names, -1, &rest)))
	{
	case 0:
	case 1:
	case 2:
	case 3:
		if (!isdigit(*rest) || (*rest == '0' && *(rest + 1) != 0))
		{
			/* not a non-negative integer without leading zeros */
			fprintf(stderr,
				"Invalid colorset number in color '%s'\n",
				name);
			return 0;
		}
		sscanf(rest, "%d%n", &cs, &n);
		if (*(rest + n) != ']')
		{
			fprintf(stderr,
				"No closing brace after '%d' in color '%s'\n",
				cs, name);
			return 0;
		}
		if (*(rest + n + 1) != 0)
		{
			fprintf(stderr, "Trailing characters after brace in"
				" color '%s'\n", name);
			return 0;
		}
		AllocColorset(cs);
		switch (i)
		{
		case 0:
			color.pixel = Colorset[cs].fg;
			break;
		case 1:
			color.pixel = Colorset[cs].bg;
			break;
		case 2:
			color.pixel = Colorset[cs].hilite;
			break;
		case 3:
			color.pixel = Colorset[cs].shadow;
			break;
		}
		if (!PictureAllocColor(Pdpy, Pcmap, &color, True))
		{
			fprintf(stderr, "Cannot allocate color %d from"
				" colorset %d\n", i, cs);
			return 0;
		}
		return color.pixel;

	default:
		break;
	}

	return GetSimpleColor(name);
}
Exemplo n.º 12
0
Arquivo: parse.c Projeto: att/uwin
/*#define DEBUG_PARSER*/
static void ParseButton(button_info **uberb,char *s)
{
  button_info *b,*ub=*uberb;
  int i,j;
  char *t,*o;

  b = alloc_button(ub, (ub->c->num_buttons)++);
  s = trimleft(s);

  if(*s=='(' && s++)
  {
    char *opts[] =
    {
      "back",
      "fore",
      "font",
      "title",
      "icon",
      "frame",
      "padding",
      "swallow",
      "panel",
      "action",
      "container",
      "end",
      "nosize",
      "size",
      "left",
      "right",
      "center",
      "colorset",
      NULL
    };
    s = trimleft(s);
    while(*s && *s!=')')
    {
      Bool is_swallow = False;

      if (*s == ',')
      {
	      s++;
	      s = trimleft(s);
	      continue;
      }
      if((*s>='0' && *s<='9') || *s=='+' || *s=='-')
      {
	char *geom;
	int x,y,flags;
	unsigned int w,h;

	geom=seekright(&s);
	if (geom)
	{
	  flags=XParseGeometry(geom, &x, &y, &w, &h);
	  if(flags&WidthValue)
	    b->BWidth=w;
	  if(flags&HeightValue)
	    b->BHeight=h;
	  if(flags&XValue)
	  {
	    b->BPosX=x;
	    b->flags|=b_PosFixed;
	  }
	  if(flags&YValue)
	  {
	    b->BPosY=y;
	    b->flags|=b_PosFixed;
	  }
	  if(flags&XNegative)
	    b->BPosX=-1-x;
	  if(flags&YNegative)
	    b->BPosY=-1-y;
	  free(geom);
	}
	s = trimleft(s);
	continue;
      }
      switch(GetTokenIndex(s,opts,-1,&s))
      {
      case 0: /* Back */
	s = trimleft(s);
	if(*s=='(' && s++)
	  if(ParseBack(&s))
	    b->flags|=b_IconBack;
	if(b->flags&b_Back && b->back)
	  free(b->back);
	b->back=seekright(&s);
	if(b->back)
	{
	  b->flags|=b_Back;
	}
	else
	  b->flags&=~(b_IconBack|b_Back);
	break;

      case 1: /* Fore */
	if(b->flags&b_Fore && b->fore)
	  free(b->fore);
	b->fore=seekright(&s);
	if(b->fore)
	{
	  b->flags|=b_Fore;
	}
	else
	  b->flags&=~b_Fore;
	break;

      case 2: /* Font */
	if(b->flags&b_Font && b->font_string)
	  free(b->font_string);
        b->font_string = my_get_font(&s);
	if(b->font_string)
	{
	  b->flags|=b_Font;
	}
	else
	  b->flags&=~b_Font;
	break;

	/* --------------------------- Title ------------------------- */

      case 3: /* Title */
	s = trimleft(s);
	if(*s=='(' && s++)
	{
	  b->justify=0;
	  b->justify_mask=0;
	  ParseTitle(&s,&b->justify,&b->justify_mask);
	  if(b->justify_mask)
	    b->flags|=b_Justify;
	}
	t=seekright(&s);
	if(t && *t && (t[0]!='-' || t[1]!=0))
	{
	  if (b->title)
	    free(b->title);
	  b->title=t;
#ifdef DEBUG_PARSER
	  fprintf(stderr,"PARSE: Title \"%s\"\n",b->title);
#endif
	  b->flags|=b_Title;
	}
	else
	{
	  fprintf(stderr,"%s: Missing title argument\n",MyName);
	  if(t)free(t);
	}
	break;

	/* ---------------------------- icon ------------------------- */

      case 4: /* Icon */
	t=seekright(&s);
	if(t && *t && (t[0] != '-' || t[1] != 0))
	{
	  if (b->flags & b_Swallow)
	  {
	    fprintf(
	      stderr,"%s: a button can not have an icon and a swallowed window"
	      " at the same time. Ignoring icon", MyName);
	  }
	  else
	  {
	    if (b->icon_file)
	      free(b->icon_file);
	    b->icon_file=t;
	    b->IconWin=None;
	    b->flags|=b_Icon;
	  }
	}
	else
	{
	  fprintf(stderr,"%s: Missing icon argument\n",MyName);
	  if(t)free(t);
	}
	break;

	/* --------------------------- frame ------------------------- */

      case 5: /* Frame */
	i=strtol(s,&t,10);
	if(t>s)
	{
	  b->flags|=b_Frame;
	  b->framew=i;
	  s=t;
	}
	else
	  fprintf(stderr,"%s: Illegal frame argument\n",MyName);
	break;

	/* -------------------------- padding ------------------------ */

      case 6: /* Padding */
	i=strtol(s,&t,10);
	if(t>s)
	{
	  b->xpad=b->ypad=i;
	  b->flags |= b_Padding;
	  s=t;
	  i=strtol(s,&t,10);
	  if(t>s)
	  {
	    b->ypad=i;
	    s=t;
	  }
	}
	else
	  fprintf(stderr,"%s: Illegal padding argument\n",MyName);
	break;

	/* -------------------------- swallow ------------------------ */

      case 7: /* Swallow */
	is_swallow = True;
	/* fall through */
      case 8: /* Panel */
	s = trimleft(s);
	if (is_swallow)
	{
	  b->swallow=0;
	  b->swallow_mask=0;
	}
	else
	{
	  /* set defaults */
	  b->swallow = b_Respawn;
	  b->swallow_mask = b_Respawn;
	  b->slide_direction = SLIDE_UP;
	  b->slide_position = SLIDE_POSITION_CENTER;
	  b->slide_context = SLIDE_CONTEXT_PB;
	  b->relative_x = 0;
	  b->relative_y = 0;
	  b->slide_steps = 12;
	  b->slide_delay_ms = 5;
	}
	if(*s=='(' && s++)
	{
	  if (is_swallow)
	    ParseSwallow(&s, &b->swallow,&b->swallow_mask);
	  else
	    ParsePanel(&s, &b->swallow, &b->swallow_mask, &b->slide_direction,
		       &b->slide_steps, &b->slide_delay_ms, &b->panel_flags,
		       &b->indicator_size, &b->relative_x, &b->relative_y,
		       &b->slide_position, &b->slide_context);
	}
	t=seekright(&s);
	o=seekright(&s);
	if(t)
	{
	  if (b->hangon)
	    free(b->hangon);
	  b->hangon=t;
	  if (is_swallow)
	  {
	    if (b->flags & b_Icon)
	    {
	      fprintf(
		stderr,"%s: a button can not have an icon and a swallowed "
		" window at the same time. Ignoring icon", MyName);
	      b->flags &= ~ b_Icon;
	    }

	    b->flags |= (b_Swallow | b_Hangon);
	  }
	  else
	  {
	    b->flags |= (b_Panel | b_Hangon);
	    b->newflags.is_panel = 1;
	    b->newflags.panel_mapped = 0;
	  }
	  b->swallow|=1;
	  if(!(b->swallow&b_NoHints))
	    b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints));
	  if(o)
	  {
	    char *p;

	    p = expand_action(o, NULL);
	    if (p)
	    {
	      if(!(buttonSwallow(b)&b_UseOld))
		SendText(fd,p,0);
	      if (b->spawn)
		free(b->spawn);
	      b->spawn=o;  /* Might be needed if respawning sometime */
	      free(p);
	    }
	  }
	}
	else
	{
	  fprintf(stderr,"%s: Missing swallow argument\n",MyName);
	  if(t)
	    free(t);
	  if(o)
	    free(o);
	}
	break;

	/* --------------------------- action ------------------------ */

      case 9: /* Action */
	s = trimleft(s);
	i=0;
	if(*s=='(')
	{
	  s++;
	  if(strncasecmp(s,"mouse",5)!=0)
	  {
	    fprintf(stderr,"%s: Couldn't parse action\n",MyName);
	  }
	  s+=5;
	  i=strtol(s,&t,10);
	  s=t;
	  while(*s && *s!=')')
	    s++;
	  if(*s==')')
            s++;
	}
        {
          char *r;
          char *u = s;

          s = GetQuotedString(s, &t, ",)", NULL, "(", ")");
          r = s;
          if (t && r > u + 1)
          {
            /* remove unquoted trailing spaces */
            r -= 2;
            while (r >= u && isspace(*r))
              r--;
            r++;
            if (isspace(*r))
            {
              t[strlen(t) - (s - r - 1)] = 0;
            }
          }
        }
	if(t)
	{
	  AddButtonAction(b,i,t);
	  free(t);
	}
	else
	  fprintf(stderr,"%s: Missing action argument\n",MyName);
	break;

	/* -------------------------- container ---------------------- */

      case 10: /* Container */
	b->flags&=b_Frame|b_Back|b_Fore|b_Padding|b_Action;
	MakeContainer(b);
	*uberb=b;
	s = trimleft(s);
	if(*s=='(' && s++)
	  ParseContainer(&s,b);
	break;

      case 11: /* End */
	*uberb=ub->parent;
	ub->c->buttons[--(ub->c->num_buttons)]=NULL;
	free(b);
	if(!ub->parent)
	{
	  fprintf(stderr,"%s: Unmatched END in config file\n",MyName);
	  exit(1);
	}
	return;

      case 12: /* NoSize */
	b->flags|=b_Size;
	b->minx=b->miny=0;
	break;

      case 13: /* Size */
	i=strtol(s,&t,10);
	j=strtol(t,&o,10);
	if(t>s && o>t)
	{
	  b->minx=i;
	  b->miny=j;
	  b->flags|=b_Size;
	  s=o;
	}
	else
	  fprintf(stderr,"%s: Illegal size arguments\n",MyName);
	break;

      case 14: /* Left */
	b->flags |= b_Left;
	b->flags &= ~b_Right;
	break;

      case 15: /* Right */
	b->flags |= b_Right;
	b->flags &= ~b_Left;
	break;

      case 16: /* Center */
	b->flags &= ~(b_Right|b_Left);
	break;

      case 17: /* Colorset */
	i = strtol(s, &t, 10);
	if(t > s)
	{
	  b->colorset = i;
	  b->flags |= b_Colorset;
	  s=t;
	  AllocColorset(i);
	}
	else
	{
	  b->flags &= ~b_Colorset;
	}
	break;

      default:
	t=seekright(&s);
	fprintf(stderr,"%s: Illegal button option \"%s\"\n",MyName,
		(t)?t:"");
	if (t)
	  free(t);
	break;
      }
      s = trimleft(s);
    }
    if (s && *s)
    {
      s++;
      s = trimleft(s);
    }
  }

  /* get title and iconname */
  if(!(b->flags&b_Title))
  {
    b->title=seekright(&s);
    if(b->title && *b->title && ((b->title)[0]!='-'||(b->title)[1]!=0))
      b->flags |= b_Title;
    else
      if(b->title)free(b->title);
  }
  else
  {
    char *temp;
    temp = seekright(&s);
    if (temp)
      free(temp);
  }

  if(!(b->flags&b_Icon))
  {
    b->icon_file=seekright(&s);
    if(b->icon_file && b->icon_file &&
       ((b->icon_file)[0]!='-'||(b->icon_file)[1]!=0))
    {
      b->flags|=b_Icon;
      b->IconWin=None;
    }
    else
      if(b->icon_file)free(b->icon_file);
  }
  else
  {
    char *temp;
    temp = seekright(&s);
    if (temp)
      free(temp);
  }

  s = trimleft(s);

  /* Swallow hangon command */
  if (strncasecmp(s,"swallow",7)==0 || strncasecmp(s,"panel",7)==0)
  {
    if(b->flags & (b_Swallow | b_Panel))
    {
      fprintf(stderr,"%s: Illegal with both old and new swallow!\n",
	      MyName);
      exit(1);
    }
    s+=7;
    /*
     * Swallow old 'swallowmodule' command
     */
    if (strncasecmp(s,"module",6)==0)
    {
      s+=6;
    }
    if (b->hangon)
      free(b->hangon);
    b->hangon=seekright(&s);
    if (!b->hangon)
      b->hangon = safestrdup("");
    if (tolower(*s) == 's')
      b->flags |= b_Swallow | b_Hangon;
    else
      b->flags |= b_Panel | b_Hangon;
    b->swallow|=1;
    s = trimleft(s);
    if(!(b->swallow&b_NoHints))
      b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints));
    if(*s)
    {
      if(!(buttonSwallow(b)&b_UseOld))
	SendText(fd,s,0);
      b->spawn=safestrdup(s);
    }
  }
  else if(*s)
    AddButtonAction(b,0,s);
  return;
}
Exemplo n.º 13
0
Arquivo: parse.c Projeto: att/uwin
/**
*** ParseSwallow()
*** Parses the options possible to Swallow
**/
static void ParseSwallow(char **ss,byte *flags,byte *mask)
{
  char *swallowopts[] =
  {
    "nohints", "hints",
    "nokill","kill",
    "noclose", "close",
    "respawn","norespawn",
    "useold", "noold",
    "usetitle", "notitle",
    NULL
  };
  char *t,*s=*ss;

  while(*s && *s!=')')
  {
    s = trimleft(s);
    if(*s==',')
      s++;
    else switch(GetTokenIndex(s,swallowopts,-1,&s))
    {
    case 0: /* NoHints */
      *flags|=b_NoHints;
      *mask|=b_NoHints;
      break;
    case 1: /* Hints */
      *flags&=~b_NoHints;
      *mask|=b_NoHints;
      break;
    case 2: /* NoKill */
      *flags&=~b_Kill;
      *mask|=b_Kill;
      break;
    case 3: /* Kill */
      *flags|=b_Kill;
      *mask|=b_Kill;
      break;
    case 4: /* NoClose */
      *flags|=b_NoClose;
      *mask|=b_NoClose;
      break;
    case 5: /* Close */
      *flags&=~b_NoClose;
      *mask|=b_NoClose;
      break;
    case 6: /* Respawn */
      *flags|=b_Respawn;
      *mask|=b_Respawn;
      break;
    case 7: /* NoRespawn */
      *flags&=~b_Respawn;
      *mask|=b_Respawn;
      break;
    case 8: /* UseOld */
      *flags|=b_UseOld;
      *mask|=b_UseOld;
      break;
    case 9: /* NoOld */
      *flags&=~b_UseOld;
      *mask|=b_UseOld;
      break;
    case 10: /* UseTitle */
      *flags|=b_UseTitle;
      *mask|=b_UseTitle;
      break;
    case 11: /* NoTitle */
      *flags&=~b_UseTitle;
      *mask|=b_UseTitle;
      break;
    default:
      t=seekright(&s);
      fprintf(stderr,"%s: Illegal Swallow option \"%s\"\n",MyName,
	      (t)?t:"");
      if (t)
	free(t);
    }
  }
  if(*s) s++;
  *ss=s;
}
Exemplo n.º 14
0
Arquivo: parse.c Projeto: att/uwin
char *expand_action(char *in_action, button_info *b)
{
  char *variables[] =
  {
    "$",
    "fg",
    "bg",
    "left",
    "-left",
    "right",
    "-right",
    "top",
    "-top",
    "bottom",
    "-bottom",
    "width",
    "height",
    NULL
  };
  char *action = NULL;
  char *src;
  char *dest;
  char *string = NULL;
  char *rest;
  int px;
  int py;
  int val = 0;
  int offset;
  int x;
  int y;
  int f;
  int i;
  unsigned int w = 0;
  unsigned int h = 0;
  Window win;
  extern int dpw;
  extern int dph;

  /* create a temporary storage for expanding */
  action = (char *)malloc(MAX_MODULE_INPUT_TEXT_LEN);
  if (!action)
  {
    /* could not alloc memory */
    return NULL;
  }

  /* calculate geometry */
  if (b)
  {
    w = buttonWidth(b);
    h = buttonHeight(b);
    buttonInfo(b, &x, &y, &px, &py, &f);
    XTranslateCoordinates(Dpy, MyWindow, Root, x, y, &x, &y, &win);
  }

  for (src = in_action, dest = action; *src != 0; src++)
  {
    if (*src != '$')
    {
      *(dest++) = *src;
    }
    else
    {
      char *dest_org = dest;
      Bool is_string = False;
      Bool is_value = False;

      *(dest++) = *(src++);
      i = GetTokenIndex(src, variables, -1, &rest);
      if (i == -1)
      {
	src--;
	continue;
      }
      switch (i)
      {
      case 0: /* $ */
	continue;
      case 1: /* fg */
	string = UberButton->c->fore;
	is_string = True;
	break;
      case 2: /* bg */
	string = UberButton->c->back;
	is_string = True;
	break;
      case 3: /* left */
	val = x;
	is_value = True;
	break;
      case 4: /* -left */
	val = dpw - x - 1;
	is_value = True;
	break;
      case 5: /* right */
	val = x + w;
	is_value = True;
	break;
      case 6: /* -right */
	val = dpw - x - w - 1;
	is_value = True;
	break;
      case 7: /* top */
	val = y;
	is_value = True;
	break;
      case 8: /* -top */
	val = dph - y - 1;
	is_value = True;
	break;
      case 9: /* bottom */
	val = y + h;
	is_value = True;
	break;
      case 10: /* -bottom */
	val = dph - y - h - 1;
	is_value = True;
	break;
      case 11: /* width */
	val = w;
	is_value = True;
	break;
      case 12: /* height */
	val = h;
	is_value = True;
	break;
      default: /* unknown */
	src--;
	continue;
      } /* switch */
      dest = dest_org;
      src = --rest;
      if (is_value)
      {
	if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <= 16)
	{
	  /* out of space */
	  free(action);
	  return NULL;
	}
	/* print the number into the string */
	sprintf(dest, "%d%n", val, &offset);
	dest += offset;
      }
      else if (is_string)
      {
	if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <= strlen(string))
	{
	  /* out of space */
	  free(action);
	  return NULL;
	}
	/* print the colour name into the string */
	if (string)
	{
	  sprintf(dest, "%s%n", string, &offset);
	  dest += offset;
	}
      }
    } /* if */
  } /* for */
  *dest = 0;
  return action;
}
Exemplo n.º 15
0
/**
*** ParsePanel()
*** Parses the options possible to Panel
**/
static void ParsePanel(
	char **ss, unsigned int *flags, unsigned int *mask, char *direction,
	int *steps, int *delay, panel_flags_type *panel_flags,
	int *indicator_size, int *rela_x, int *rela_y, char *position,
	char *context)
{
	char *swallowopts[] =
	{
		"nohints", "hints",
		"nokill", "kill",
		"noclose", "close",
		"respawn", "norespawn",
		"useold", "noold",
		"usetitle", "notitle",
		"up", "down", "left", "right",
		"steps",
		"delay",
		"smooth",
		"noborder",
		"indicator",
		"position",
		NULL
	};

	char *positionopts[] =
	{
		"button", "module", "root", "center", "left", "top", "right",
		"bottom", "noplr", "noptb", "mlr", "mtb", NULL
	};

	char *t, *s = *ss;
	int n;

	while (*s && *s != ')')
	{
		s = trimleft(s);
		if (*s == ',')
		{
			s++;
			continue;
		}

		switch (GetTokenIndex(s, swallowopts, -1, &s))
		{
		case 0: /* NoHints */
			*flags |= b_NoHints;
			*mask |= b_NoHints;
			break;
		case 1: /* Hints */
			*flags &= ~b_NoHints;
			*mask |= b_NoHints;
			break;
		case 2: /* NoKill */
			*flags &= ~b_Kill;
			*mask |= b_Kill;
			break;
		case 3: /* Kill */
			*flags |= b_Kill;
			*mask |= b_Kill;
			break;
		case 4: /* NoClose */
			*flags |= b_NoClose;
			*mask |= b_NoClose;
			break;
		case 5: /* Close */
			*flags &= ~b_NoClose;
			*mask |= b_NoClose;
			break;
		case 6: /* Respawn */
			*flags |= b_Respawn;
			*mask |= b_Respawn;
			break;
		case 7: /* NoRespawn */
			*flags &= ~b_Respawn;
			*mask |= b_Respawn;
			break;
		case 8: /* UseOld */
			*flags |= b_UseOld;
			*mask |= b_UseOld;
			break;
		case 9: /* NoOld */
			*flags &= ~b_UseOld;
			*mask |= b_UseOld;
			break;
		case 10: /* UseTitle */
			*flags |= b_UseTitle;
			*mask |= b_UseTitle;
			break;
		case 11: /* NoTitle */
			*flags &= ~b_UseTitle;
			*mask |= b_UseTitle;
			break;
		case 12: /* up */
			*direction = SLIDE_UP;
			break;
		case 13: /* down */
			*direction = SLIDE_DOWN;
			break;
		case 14: /* left */
			*direction = SLIDE_LEFT;
			break;
		case 15: /* right */
			*direction = SLIDE_RIGHT;
			break;
		case 16: /* steps */
			sscanf(s, "%d%n", steps, &n);
			s += n;
			break;
		case 17: /* delay */
			sscanf(s, "%d%n", delay, &n);
			s += n;
			break;
		case 18: /* smooth */
			(*panel_flags).smooth = 1;
			break;
		case 19: /* noborder */
			(*panel_flags).ignore_lrborder = 1;
			(*panel_flags).ignore_tbborder = 1;
			break;
		case 20: /* indicator */
			n = 0;
			(*panel_flags).panel_indicator = 1;
			*indicator_size = 0;
			sscanf(s, "%d%n", indicator_size, &n);
			if (*indicator_size < 0 || *indicator_size > 100)
			{
				*indicator_size = 0;
			}
			s += n;
			break;
		case 21: /* position */
			n = 0;
			*rela_x = *rela_y = 0;
			while (*s != ',' && *s != ')' && *s)
			{
				s = trimleft(s);
				/* get x and y offset */
				if (isdigit(*s) || *s == '+' || *s == '-')
				{
					sscanf(s, "%i%n", rela_x, &n);
					s += n;
					if (*s == 'p' || *s == 'P')
					{
						(*panel_flags).relative_x_pixel = 1;
						s++;
					}
					n = 0;
					s = trimleft(s);
					sscanf(s, "%i%n", rela_y, &n);
					s += n;
					if (*s == 'p' || *s == 'P')
					{
						(*panel_flags).relative_y_pixel = 1;
						s++;
					}
					s = trimleft(s);
				}
				switch (GetTokenIndex(s, positionopts, -1, &s))
				{
				case 0: /* button */
					*context = SLIDE_CONTEXT_PB;
					break;
				case 1: /* module */
					*context = SLIDE_CONTEXT_MODULE;
					break;
				case 2: /* root */
					*context = SLIDE_CONTEXT_ROOT;
					break;
				case 3: /* center */
					*position = SLIDE_POSITION_CENTER;
					break;
				case 4: /* left */
					*position = SLIDE_POSITION_LEFT_TOP;
					break;
				case 5: /* top  */
					*position = SLIDE_POSITION_LEFT_TOP;
					break;
				case 6: /* right */
					*position = SLIDE_POSITION_RIGHT_BOTTOM;
					break;
				case 7: /* bottom */
					*position = SLIDE_POSITION_RIGHT_BOTTOM;
					break;
				case 8: /* noplr */
					(*panel_flags).ignore_lrborder = 1;
					break;
				case 9: /* noptb */
					(*panel_flags).ignore_tbborder = 1;
					break;
				case 10: /* mlr */
					(*panel_flags).buttons_lrborder = 1;
					break;
				case 11: /* mtb */
					(*panel_flags).buttons_tbborder = 1;
					break;
				default:
					t = seekright(&s);
					s--;
					if (t)
					{
						fprintf(stderr,
							"%s: Illegal Panel "
							"position option %s\n",
							MyName,	(t) ? t : "");
						free(t);
					}
				}
			}
			break;
		default:
			t = seekright(&s);
			fprintf(stderr,
				"%s: Illegal Panel option \"%s\"\n", MyName,
				(t) ? t : "");
			if (t)
			{
				free(t);
			}
		}
	}
	if (*s)
	{
		s++;
	}
	*ss = s;
}
Exemplo n.º 16
0
/**
*** ParseContainer()
*** Parses the options possible to Container
**/
static void ParseContainer(char **ss,button_info *b)
{
	char *conts[] =
	{
		"columns",
		"rows",
		"font",
		"frame",
		"back",
		"fore",
		"padding",
		"title",
		"swallow",
		"nosize",
		"size",
		"boxsize",
		"colorset",
		NULL
	};
	char *t, *o, *s = *ss;
	int i, j;

	while (*s && *s != ')')
	{
		s = trimleft(s);
		if (*s == ',')
		{
			s++;
			continue;
		}

		switch (GetTokenIndex(s, conts, -1, &s))
		{
		case 0: /* Columns */
			b->c->num_columns = max(1, strtol(s, &t, 10));
			s = t;
			break;
		case 1: /* Rows */
			b->c->num_rows = max(1, strtol(s, &t, 10));
			s = t;
			break;
		case 2: /* Font */
			if (b->c->font_string)
			{
				free(b->c->font_string);
			}
			b->c->font_string = my_get_font(&s);
			b->c->flags.b_Font = (b->c->font_string ? 1 : 0);
			break;
		case 3: /* Frame */
			b->c->framew = strtol(s, &t, 10);
			b->c->flags.b_Frame = 1;
			s = t;
			break;
		case 4: /* Back */
			s = trimleft(s);
			if (*s == '(' && s++ && ParseBack(&s))
			{
				b->c->flags.b_IconBack = 1;
			}
			if (b->c->back)
			{
				free(b->c->back);
			}
			b->c->back = seekright(&s);
			if (b->c->back)
			{
				b->c->flags.b_Back = 1;
			}
			else
			{
				b->c->flags.b_IconBack = 0;
				b->c->flags.b_Back = 0;
			}
			break;
    case 5: /* Fore */
      if (b->c->fore) free(b->c->fore);
      b->c->fore = seekright(&s);
      b->c->flags.b_Fore = (b->c->fore ? 1 : 0);
      break;
    case 6: /* Padding */
      i = strtol(s, &t, 10);
      if (t > s)
      {
	b->c->xpad = b->c->ypad = i;
	s = t;
	i = strtol(s, &t, 10);
	if (t > s)
	{
	  b->c->ypad = i;
	  s = t;
	}
	b->c->flags.b_Padding = 1;
      }
      else
	fprintf(stderr,"%s: Illegal padding argument\n",MyName);
      break;
    case 7: /* Title - flags */
      s = trimleft(s);
      if (*s == '(' && s++)
      {
	b->c->justify = 0;
	b->c->justify_mask = 0;
	ParseTitle(&s, &b->c->justify, &b->c->justify_mask);
	if (b->c->justify_mask)
	{
	  b->c->flags.b_Justify = 1;
	}
      }
      else
      {
	char *temp;
	fprintf(stderr,
		"%s: Illegal title in container options\n",
		MyName);
	temp = seekright(&s);
	if (temp)
	{
	  free(temp);
	}
      }
      break;
    case 8: /* Swallow - flags */
      {
	Bool failed = False;

	s = trimleft(s);
	if (b->c->flags.b_Swallow || b->c->flags.b_Panel)
	{
	  fprintf(stderr, "%s: Multiple Swallow or Panel options are not"
		" allowed in a single button", MyName);
	  failed = True;
	}
	else if (*s == '(' && s++)
	{
	  b->c->swallow = 0;
	  b->c->swallow_mask = 0;
	  ParseSwallow(&s, &b->c->swallow, &b->c->swallow_mask, b);
	  if (b->c->swallow_mask)
	  {
	    b->c->flags.b_Swallow = 1;
	  }
	}
	else
	{
	  fprintf(stderr,
		  "%s: Illegal swallow or panel in container options\n",
		  MyName);
	  failed = True;
	}
	if (failed)
	{
	  char *temp;

	  temp = seekright(&s);
	  if (temp)
	    free(temp);
	}
      }
      break;
    case 9: /* NoSize */
      b->c->flags.b_Size = 1;
      b->c->minx = b->c->miny = 0;
      break;

    case 10: /* Size */
      i = strtol(s, &t, 10);
      j = strtol(t, &o, 10);
      if (t > s && o > t)
      {
	b->c->minx = i;
	b->c->miny = j;
	b->c->flags.b_Size = 1;
	s = o;
      }
      else
	fprintf(stderr,"%s: Illegal size arguments\n",MyName);
      break;

    case 11: /* BoxSize */
      ParseBoxSize(&s, &b->c->flags);
      break;

    case 12: /* Colorset */
      i = strtol(s, &t, 10);
      if (t > s)
      {
	b->c->colorset = i;
	b->c->flags.b_Colorset = 1;
	AllocColorset(i);
	s = t;
      }
      else
      {
	b->c->flags.b_Colorset = 0;
      }
      break;

    default:
      t = seekright(&s);
      fprintf(stderr,"%s: Illegal container option \"%s\"\n",MyName, (t)?t:"");
      if (t)
	free(t);
    }
  }
  if (*s)
  {
    s++;
  }
  *ss = s;
}
Exemplo n.º 17
0
void RTF_DoBodyControl (FILE * f, char* control,char* arg)
{
	short style;

	if (gobble) return;

	switch (GetTokenIndex(control)) 
	{
		case t_stylesheet:
			gobble = TRUE;	/*perform no output, ignore commands 'til level-1*/
			skip_to_level = level-1;
			RTF_ParseStyle( f );
			break;
		case t_fonttbl:	/*skip all of these and their contents!*/
		case t_colortbl:
		case t_info:
			gobble = TRUE;	/*perform no output, ignore commands 'til level-1*/
			skip_to_level = level-1;
			break;
		case t_pict:
			gobble = TRUE;	/*perform no output, ignore commands 'til level-1*/
			if(skip_to_level>=level || skip_to_level==-1) 
				skip_to_level = level-1;
			break;
			
			
		case t_s: /*Style*/
			if (!curr_heading) 
			{
				style = RTF_MapStyle (arg);
				if(style)
				{
					curr_heading = s_h0 + style;
					RTF_PutStr(styles[curr_heading][0]);
					ignore_styles = TRUE;
				}
			}
			break;
			
		case t_b: /*Bold*/
				RTF_SetStyle(&curr_style,s_bold);
			break;
			
		case t_ulw:
		case t_uld:
		case t_uldb:
		case t_ul: /*Underline, maps to "emphasis" HTML style*/
				RTF_SetStyle(&curr_style,s_underline);
			break;
			
		case t_i: /*Italic*/
				RTF_SetStyle(&curr_style,s_italic);
			break;
			
		case t_v: /* Hidden*/
				RTF_SetStyle(&curr_style,s_hidden);
			break;
			
		case t_par: /*Paragraph*/
			if (curr_heading!=s_plain) {
				RTF_PutStr(styles[curr_heading][1]);
				curr_heading = s_plain;
			} else {
				RTF_PutStr(styles[s_para][0]);
			}
			ignore_styles = FALSE;
			break;
			
		case t_plain: /*reset inline styles*/
			RTF_PlainStyle(&curr_style);
			break;
		case t_cell:
		case t_tab:
			RTF_PutChar(' ');
			break;
		case t_endash:
		case t_emdash:
			RTF_PutChar('-');
			break;
		case t_line:
		case t_row:
			RTF_PutStr(styles[s_br][0]);
			break;
		case t_bullet:
			RTF_PutChar('\xb7');
			break;
		case t_start:
		case t_end:
			break;
		case t_rquote:
			//RTF_PutStr("&rsquo;");
			RTF_PutStr("'");
			break;
	}
			
}
Exemplo n.º 18
0
/* Parse 'goodies' specific resources */
Bool GoodiesParseConfig(char *tline)
{
  char *rest;
  char *option;
  int i;

  option = tline + module->namelen+1;
  i = GetTokenIndex(option, goodyopts, -1, &rest);
  while (*rest && *rest != '\n' && isspace(*rest))
    rest++;
  switch(i)
  {
  case 0: /* BellVolume */
    BellVolume = atoi(rest);
    break;
  case 1: /* Mailbox */
    if (strcasecmp(rest, "None") == 0)
    {
      has_mailpath = False;
    }
    else
    {
      int len;

      UpdateString(&mailpath, rest);
      len = strlen(mailpath);
      if (len > 0 && mailpath[len-1] == '\n')
	mailpath[len-1] = 0;
      has_mailpath = True;
    }
    do_check_mail = (has_mailpath && (mailcheck_interval > 0));
    break;
  case 2: /* Mailcheck */
    mailcheck_interval = MAILCHECK_DEFAULT;
    sscanf(rest, "%d", &mailcheck_interval);
    do_check_mail = (has_mailpath && (mailcheck_interval > 0));
    break;
  case 3: /* ClockFormat */
    UpdateString(&clockfmt, rest);
    do_display_clock = True;
    if (clockfmt && clockfmt[0] == '\0' && datefmt && datefmt[0] == '\0')
    {
	    do_display_clock = False;
    }
    break;
  case 4: /* StatusFont */
    CopyStringWithQuotes(&statusfont_string, rest);
    break;
  case 5: /* TipsFore */
    CopyString(&TipsFore, rest);
    tipscolorset = -1;
    break;
  case 6: /* TipsBack */
    CopyString(&TipsBack, rest);
    tipscolorset = -1;
    break;
  case 7: /* TipsColorset */
    tipscolorset = -1;
    tipscolorset = atoi(rest);
    AllocColorset(tipscolorset);
    break;
  case 8: /* MailCommand */
    CopyString(&MailCmd, rest);
    break;
  case 9: /* IgnoreOldMail */
    IgnoreOldMail = True;
    break;
  case 10: /* ShowTips */
    ShowTips = True;
    break;
  case 11: /* DateFormat */
    UpdateString(&datefmt, rest);
    do_display_clock = True;
    if (clockfmt && clockfmt[0] == '\0' && datefmt && datefmt[0] == '\0')
    {
	    do_display_clock = False;
    }
    break;
  case 12: /* MailDir */
    using_MailDir = True;
    break;
  default:
    /* unknown option */
    return False;
  } /* switch */

  return True;
}
Exemplo n.º 19
0
void parse_message_line(char *line)
{
	char *rest;
	int action = -1;
	button_info *b;
	char *act;
	char *buttonn;
	int mousebutton;

	silent = False;
	do
	{
		action = GetTokenIndex(line, actions, -1, &rest);
		if (action == -1)
		{
			show_error("Message not understood: %s", line);
			return;
		}
		if (action == 0)
		{
			silent = True;
			break;
		}
	} while (action == 0);

	/* If silent was given (to surpress erros from parsing commands, then
	 * retokenise the rest of the line, so that token matching for the
	 * actual command is possible.
	 */
	if (silent == True) {
		line = PeekToken(line, &rest);
		action = GetTokenIndex(rest, actions, -1, &rest);
	}

	/* find out which button */
	b = parse_button_id(&rest);
	if (!b || !rest)
	{
		return;
	}

	switch (action)
	{
	case 1:
		/* ChangeButton */
		/* The dimensions of individual buttons (& the overall size of
		 * the FvwmButtons window) is based on the initial
		 * configuration for the module. In some configurations,
		 * dynamically adding/changing a title/icon may mean it no
		 * longer fits on a button. Currently, there are no checks for
		 * this occurance. */
		while (rest && rest[0] != '\0')
		{
			char *option_pair;
			int option, i;
			char *value0, *value;
			FvwmPicture *icon;

			/* parse option and value and give diagnostics */
			rest = GetQuotedString(
				rest, &option_pair, ",", NULL, NULL, NULL);
			while (isspace(*rest))
			{
				rest++;
			}
			if (!option_pair)
				continue;

			option = GetTokenIndex(
				option_pair, button_options, -1, &value0);
			if (option < 0)
			{
				show_error(
					"Unsupported button option line '%s'\n",
					option_pair);
				free(option_pair);
				continue;
			}

			GetNextToken(value0, &value);
			free(option_pair);

			if (value == NULL)
			{
				show_error(
					"No title/icon to change specified.\n");
				continue;
			}
			switch (option)
			{
			case 0:
				/* Title */
				if (b->flags.b_Title)
					free(b->title);
				b->flags.b_Title = 1;
				b->title = value;
				value = NULL;
				break;
			case 2:
				/* ActiveTitle */
				if (b->flags.b_ActiveTitle)
					free(b->activeTitle);
				b->flags.b_ActiveTitle = 1;
				b->title = value;
				value = NULL;
				break;
			case 4:
				/* PressTitle */
				if (b->flags.b_PressTitle)
					free(b->pressTitle);
				b->flags.b_PressTitle = 1;
				b->title = value;
				value = NULL;
				break;
			case 6:
				/* Colorset */
				i = atoi(value);
				b->colorset = i;
				b->flags.b_Colorset = 1;
				AllocColorset(i);
				break;
			default:
				if (
					LoadIconFile(
						value, &icon, b->colorset) == 0)
				{
					show_error(
						"Cannot load icon \"%s\"\n",
						value);
				}
				else
				{
				    switch (option)
				    {
					case 1: /* Icon */
						if (b->flags.b_Icon)
						{
							free(b->icon_file);
							PDestroyFvwmPicture(
								Dpy, b->icon);
						}
						b->flags.b_Icon = 1;
						b->icon_file = value;
						value = NULL;
						b->icon = icon;
						break;
					case 3: /* ActiveIcon */
						if (b->flags.b_ActiveIcon)
						{
							free(b->active_icon_file);
							PDestroyFvwmPicture(
								Dpy,
								b->activeicon);
						}
						b->flags.b_ActiveIcon = 1;
						b->active_icon_file = value;
						value = NULL;
						b->activeicon = icon;
						break;
					case 5: /* PressIcon */
						if (b->flags.b_PressIcon)
						{
							free(b->press_icon_file);
							PDestroyFvwmPicture(
								Dpy,
								b->pressicon);
						}
						b->flags.b_PressIcon = 1;
						b->press_icon_file = value;
						value = NULL;
						b->pressicon = icon;
						break;
					}
				}
				break;
			}

			if (value)
		    {
			    free(value);
		    }
		}

		RedrawButton(b, DRAW_FORCE, NULL);
		if (UberButton->c->flags.b_TransBack)
		{
			SetTransparentBackground(UberButton, Width, Height);
		}
		break;

	case 2:
		/* ExpandButtonVars */
		line = expand_button_vars(b, rest);
		if (line)
		{
			SendText(fd, line, 0);
			free(line);
		}
		break;
	case 3:
		/* PressButton */
		rest = GetQuotedString(rest, &buttonn, "", NULL, NULL, NULL);
		if (buttonn)
		{
			mousebutton = atoi(buttonn);
			free(buttonn);
			if (
				mousebutton <= 0 ||
				mousebutton > NUMBER_OF_EXTENDED_MOUSE_BUTTONS)
			{
				mousebutton = 1;
			}
		}
		else
		{
			mousebutton = 1;
		}
		CurrentButton = b;
		act = GetButtonAction(b, mousebutton);
		ButtonPressProcess(b, &act);
		if (act)
		{
			free(act);
		}
		CurrentButton = NULL;

		break;
	}

	return;
}
Exemplo n.º 20
0
/* translate a colorset spec into a colorset structure */
void parse_colorset(int n, char *line)
{
	int i;
	int w;
	int h;
	int tmp;
	int percent;
	colorset_t *cs;
	char *optstring;
	char *args;
	char *option;
	char *tmp_str;
	char *fg = NULL;
	char *bg = NULL;
	char *hi = NULL;
	char *sh = NULL;
	char *fgsh = NULL;
	char *tint = NULL;
	char *fg_tint = NULL;
	char *bg_tint = NULL;
	char *icon_tint = NULL;
	Bool have_pixels_changed = False;
	Bool has_icon_pixels_changed = False;
	Bool has_fg_changed = False;
	Bool has_bg_changed = False;
	Bool has_sh_changed = False;
	Bool has_hi_changed = False;
	Bool has_fgsh_changed = False;
	Bool has_fg_alpha_changed = False;
	Bool has_tint_changed = False;
	Bool has_fg_tint_changed = False;
	Bool has_bg_tint_changed = False;
	Bool has_icon_tint_changed = False;
	Bool has_pixmap_changed = False;
	Bool has_shape_changed = False;
	Bool has_image_alpha_changed = False;
	Bool pixmap_is_a_bitmap = False;
	Bool do_reload_pixmap = False;
	Bool is_server_grabbed = False;
	XColor color;
	XGCValues xgcv;
	static char *name = "parse_colorset";
	Window win = Scr.NoFocusWin;
	static GC gc = None;

	/* initialize statics */
	if (gc == None)
	{
		gc = fvwmlib_XCreateGC(dpy, win, 0, &xgcv);
	}

	/* make sure it exists and has sensible contents */
	alloc_colorset(n);
	cs = &Colorset[n];

	/*** Parse the options ***/
	while (line && *line)
	{
		/* Read next option specification delimited by a comma or \0.
		 */
		line = GetQuotedString(
			line, &optstring, ",", NULL, NULL, NULL);
		if (!optstring)
			break;
		args = GetNextToken(optstring, &option);
		if (!option)
		{
			free(optstring);
			break;
		}

		switch((i = GetTokenIndex(option, csetopts, 0, NULL)))
		{
		case 0: /* Foreground */
		case 1: /* Fore */
		case 2: /* fg */
			get_simple_color(
				args, &fg, cs, FG_SUPPLIED, FG_CONTRAST,
				"contrast");
			has_fg_changed = True;
			break;
		case 3: /* Background */
		case 4: /* Back */
		case 5: /* bg */
			get_simple_color(
				args, &bg, cs, BG_SUPPLIED, BG_AVERAGE,
				"average");
			has_bg_changed = True;
			break;
		case 6: /* Hilight */
		case 7: /* Hilite */
		case 8: /* hi */
			get_simple_color(args, &hi, cs, HI_SUPPLIED, 0, NULL);
			has_hi_changed = True;
			break;
		case 9: /* Shadow */
		case 10: /* Shade */
		case 11: /* sh */
			get_simple_color(args, &sh, cs, SH_SUPPLIED, 0, NULL);
			has_sh_changed = True;
			break;
		case 12: /* fgsh */
			get_simple_color(
				args, &fgsh, cs, FGSH_SUPPLIED, 0,NULL);
			has_fgsh_changed = True;
			break;
		case 13: /* fg_alpha */
		case 14: /* fgAlpha */
			if (GetIntegerArguments(args, NULL, &tmp, 1))
			{
				if (tmp > 100)
					tmp = 100;
				else if (tmp < 0)
					tmp = 0;
			}
			else
			{
				tmp = 100;
			}
			if (tmp != cs->fg_alpha_percent)
			{
				cs->fg_alpha_percent = tmp;
				has_fg_alpha_changed = True;
			}
			break;
		case 15: /* TiledPixmap */
		case 16: /* Pixmap */
		case 17: /* AspectPixmap */
			has_pixmap_changed = True;
			free_colorset_background(cs, True);
			tmp_str = PeekToken(args, &args);
			if (tmp_str)
			{
				CopyString(&cs->pixmap_args, tmp_str);
				do_reload_pixmap = True;
				cs->gradient_type = 0;
				/* set the flags */
				if (csetopts[i][0] == 'T')
				{
					cs->pixmap_type = PIXMAP_TILED;
				}
				else if (csetopts[i][0] == 'A')
				{
					cs->pixmap_type = PIXMAP_STRETCH_ASPECT;
				}
				else
				{
					cs->pixmap_type = PIXMAP_STRETCH;
				}
			}
			/* the pixmap is build later */
			break;
		case 18: /* Shape */
		case 19: /* TiledShape */
		case 20: /* AspectShape */
			parse_shape(win, cs, i, args, &has_shape_changed);
			break;
		case 21: /* Plain */
			has_pixmap_changed = True;
			free_colorset_background(cs, True);
			break;
		case 22: /* NoShape */
			has_shape_changed = True;
			if (cs->shape_mask)
			{
				add_to_junk(cs->shape_mask);
				cs->shape_mask = None;
			}
			break;
		case 23: /* Transparent */

			/* This is only allowable when the root depth == fvwm
			 * visual depth otherwise bad match errors happen,
			 * it may be even more restrictive but my tests (on
			 * exceed 6.2) show that only == depth is necessary */

			if (Pdepth != DefaultDepth(dpy, (DefaultScreen(dpy))))
			{
				fvwm_msg(
					ERR, name, "can't do Transparent "
					"when root_depth!=fvwm_depth");
				break;
			}
			has_pixmap_changed = True;
			free_colorset_background(cs, True);
			cs->pixmap = ParentRelative;
			cs->pixmap_type = PIXMAP_STRETCH;
			break;
		case 24: /* RootTransparent */
			if (Pdepth != DefaultDepth(dpy, (DefaultScreen(dpy))))
			{
				fvwm_msg(
					ERR, name, "can't do RootTransparent "
					"when root_depth!=fvwm_depth");
				break;
			}
			free_colorset_background(cs, True);
			has_pixmap_changed = True;
			cs->pixmap_type = PIXMAP_ROOT_PIXMAP_PURE;
			do_reload_pixmap = True;
			tmp_str = PeekToken(args, &args);
			if (StrEquals(tmp_str, "buffer"))
			{
				cs->allows_buffered_transparency = True;
			}
			else
			{
				cs->allows_buffered_transparency = False;
			}
			cs->is_maybe_root_transparent = True;
			break;
		case 25: /* Tint */
		case 26: /* PixmapTint */
		case 27: /* ImageTint */
		case 28: /* TintMask */
			parse_simple_tint(
				cs, args, &tint, TINT_SUPPLIED,
				&has_tint_changed, &percent, "tint");
			if (has_tint_changed)
			{
				cs->tint_percent = percent;
			}
			break;
		case 29: /* NoTint */
			has_tint_changed = True;
			cs->tint_percent = 0;
			cs->color_flags &= ~TINT_SUPPLIED;
			break;
		case 30: /* fgTint */
			parse_simple_tint(
				cs, args, &fg_tint, FG_TINT_SUPPLIED,
				&has_fg_tint_changed, &percent, "fgTint");
			if (has_fg_tint_changed)
			{
				cs->fg_tint_percent = percent;
			}
			break;
		case 31: /* bgTint */
			parse_simple_tint(
				cs, args, &bg_tint, BG_TINT_SUPPLIED,
				&has_bg_tint_changed, &percent, "bgTint");
			if (has_bg_tint_changed)
			{
				cs->bg_tint_percent = percent;
			}
			break;
		case 32: /* dither */
			if (cs->pixmap_args || cs->gradient_args)
			{
				has_pixmap_changed = True;
				do_reload_pixmap = True;
			}
			cs->dither = True;
			break;
		case 33: /* nodither */
			if (cs->pixmap_args || cs->gradient_args)
			{
				has_pixmap_changed = True;
				do_reload_pixmap = True;
			}
			cs->dither = False;
			break;
		case 34: /* Alpha */
		case 35: /* PixmapAlpha */
		case 36: /* ImageAlpha */
			if (GetIntegerArguments(args, NULL, &tmp, 1))
			{
				if (tmp > 100)
					tmp = 100;
				else if (tmp < 0)
					tmp = 0;
			}
			else
			{
				tmp = 100;
			}
			if (tmp != cs->image_alpha_percent)
			{
				has_image_alpha_changed = True;
				cs->image_alpha_percent = tmp;
			}
			break;
                /* dither icon is not dynamic (yet) maybe a bad opt: default
		 * to False ? */
		case 37: /* ditherIcon */
			cs->do_dither_icon = True;
			break;
		case 38: /* DoNotDitherIcon */
			cs->do_dither_icon = False;
			break;
		case 39: /* IconTint */
			parse_simple_tint(
				cs, args, &icon_tint, ICON_TINT_SUPPLIED,
				&has_icon_tint_changed, &percent, "IconTint");
			if (has_icon_tint_changed)
			{
				cs->icon_tint_percent = percent;
				has_icon_pixels_changed = True;
			}
			break;
		case 40: /* NoIconTint */
			has_icon_tint_changed = True;
			if (cs->icon_tint_percent != 0)
			{
				has_icon_pixels_changed = True;
			}
			cs->icon_tint_percent = 0;
			break;
		case 41: /* IconAlpha */
			if (GetIntegerArguments(args, NULL, &tmp, 1))
			{
				if (tmp > 100)
					tmp = 100;
				else if (tmp < 0)
					tmp = 0;
			}
			else
			{
				tmp = 100;
			}
			if (tmp != cs->icon_alpha_percent)
			{
				has_icon_pixels_changed = True;
				cs->icon_alpha_percent = tmp;
			}
			break;
		default:
			/* test for ?Gradient */
			if (option[0] && StrEquals(&option[1], "Gradient"))
			{
				cs->gradient_type = toupper(option[0]);
				if (!IsGradientTypeSupported(cs->gradient_type))
					break;
				has_pixmap_changed = True;
				free_colorset_background(cs, True);
				CopyString(&cs->gradient_args, args);
				do_reload_pixmap = True;
				if (cs->gradient_type == V_GRADIENT)
				{
					cs->pixmap_type = PIXMAP_STRETCH_Y;
				}
				else if (cs->gradient_type == H_GRADIENT)
					cs->pixmap_type = PIXMAP_STRETCH_X;
				else
					cs->pixmap_type = PIXMAP_STRETCH;
			}
			else
			{
				fvwm_msg(
					WARN, name, "bad colorset pixmap "
					"specifier %s %s", option, line);
			}
			break;
		} /* switch */

		if (option)
		{
			free(option);
			option = NULL;
		}
		free(optstring);
		optstring = NULL;
	} /* while (line && *line) */

	/*
	 * ---------- change the "pixmap" tint colour ----------
	 */
	if (has_tint_changed)
	{
		/* user specified colour */
		if (tint != NULL)
		{
			Pixel old_tint = cs->tint;
			PictureFreeColors(dpy, Pcmap, &cs->tint, 1, 0, True);
			cs->tint = GetColor(tint);
			if (old_tint != cs->tint)
			{
				have_pixels_changed = True;
			}
		}
		else if (tint == NULL)
		{
			/* default */
			Pixel old_tint = cs->tint;
			PictureFreeColors(dpy, Pcmap, &cs->tint, 1, 0, True);
			cs->tint = GetColor(black);
			if (old_tint != cs->tint)
			{
				have_pixels_changed = True;
			}
		}
	}

	/*
	 * reload the gradient if the tint or the alpha have changed.
	 * Do this too if we need to recompute the bg average and the
	 * gradient is tinted (perforemence issue).
	 */
	if ((has_tint_changed || has_image_alpha_changed ||
	     (has_bg_changed && (cs->color_flags & BG_AVERAGE) &&
	      cs->tint_percent > 0)) && cs->gradient_args)
	{
		do_reload_pixmap = True;
	}

	/*
	 * reset the pixmap if the tint or the alpha has changed
	 */
	if (!do_reload_pixmap &&
	    (has_tint_changed || has_image_alpha_changed  ||
	     (has_bg_changed && cs->alpha_pixmap != None)))
	{
		if (cs->pixmap_type == PIXMAP_ROOT_PIXMAP_PURE ||
		    cs->pixmap_type == PIXMAP_ROOT_PIXMAP_TRAN)
		{
			do_reload_pixmap = True;
		}
		else if (cs->picture != NULL && cs->pixmap)
		{
			XSetClipMask(dpy, gc, cs->picture->mask);
			reset_cs_pixmap(cs, gc);
			XSetClipMask(dpy, gc, None);
			has_pixmap_changed = True;
		}
	}

	/*
	 * (re)build the pixmap or the gradient
	 */
	if (do_reload_pixmap)
	{
		free_colorset_background(cs, False);
		has_pixmap_changed = True;
		if (cs->pixmap_type == PIXMAP_ROOT_PIXMAP_PURE ||
		    cs->pixmap_type == PIXMAP_ROOT_PIXMAP_TRAN)
		{
			cs->pixmap_type = 0;
			if (root_pic.pixmap)
			{
				cs->pixmap = root_pic.pixmap;
				cs->width = root_pic.width;
				cs->height = root_pic.height;
				cs->pixmap_type = PIXMAP_ROOT_PIXMAP_PURE;
#if 0
				fprintf(stderr,"Cset %i LoadRoot 0x%lx\n",
					n, cs->pixmap);
#endif
			}
		}
		else if (cs->pixmap_args)
		{
			parse_pixmap(win, gc, cs, &pixmap_is_a_bitmap);
		}
		else if (cs->gradient_args)
		{
			cs->pixmap = CreateGradientPixmapFromString(
				dpy, win, gc, cs->gradient_type,
				cs->gradient_args, &w, &h, &cs->pixels,
				&cs->nalloc_pixels, cs->dither);
			cs->width = w;
			cs->height = h;
		}
		has_pixmap_changed = True;
	}

	if (cs->picture != NULL && cs->picture->depth != Pdepth)
	{
		pixmap_is_a_bitmap = True;
	}

	/*
	 * ---------- change the background colour ----------
	 */
	if (has_bg_changed ||
	    (has_pixmap_changed && (cs->color_flags & BG_AVERAGE) &&
	     cs->pixmap != None &&
	     cs->pixmap != ParentRelative &&
	     !pixmap_is_a_bitmap))
	{
		Bool do_set_default_background = False;
		Pixmap average_pix = None;

		if (cs->color_flags & BG_AVERAGE)
		{
			if (cs->picture != NULL && cs->picture->picture != None)
			{
				average_pix = cs->picture->picture;
			}
			else if (cs->pixmap != ParentRelative)
			{
				average_pix = cs->pixmap;
			}

			if (average_pix == root_pic.pixmap)
			{
				int w;
				int h;
				XID dummy;

				MyXGrabServer(dpy);
				is_server_grabbed = True;
				if (!XGetGeometry(
				    dpy, average_pix, &dummy,
				    (int *)&dummy, (int *)&dummy,
				    (unsigned int *)&w, (unsigned int *)&h,
				    (unsigned int *)&dummy,
				    (unsigned int *)&dummy))
				{
					average_pix = None;
				}
				else
				{
					if (w != cs->width || h != cs->height)
					{
						average_pix = None;
					}
				}
				if (average_pix == None)
				{
					MyXUngrabServer(dpy);
					is_server_grabbed = False;
				}
			}
		}

		/* note: no average for bitmap */
		if ((cs->color_flags & BG_AVERAGE) && average_pix)
		{
			/* calculate average background color */
			XColor *colors;
			XImage *image;
			XImage *mask_image = None;
			unsigned int i, j, k = 0;
			unsigned long red = 0, blue = 0, green = 0;
			unsigned long tred, tblue, tgreen;
			double dred = 0.0, dblue = 0.0, dgreen = 0.0;

			has_bg_changed = True;
			/* create an array to store all the pixmap colors in */
			/* Note: this may allocate a lot of memory:
			 * cs->width * cs->height * 12 and then the rest of the
			 * procedure can take a lot of times */
			colors = (XColor *)safemalloc(
				cs->width * cs->height * sizeof(XColor));
			/* get the pixmap and mask into an image */
			image = XGetImage(
				dpy, average_pix, 0, 0, cs->width, cs->height,
				AllPlanes, ZPixmap);
			if (cs->mask != None)
			{
				mask_image = XGetImage(
					dpy, cs->mask, 0, 0, cs->width,
					cs->height, AllPlanes, ZPixmap);
			}
			if (is_server_grabbed == True)
			{
				MyXUngrabServer(dpy);
			}
			if (image != None && mask_image != None)
			{
				/* only fetch the pixels that are not masked
				 * out */
				for (i = 0; i < cs->width; i++)
				{
					for (j = 0; j < cs->height; j++)
					{
						if (
							cs->mask == None ||
							XGetPixel(
								mask_image, i,
								j) == 0)
						{
							colors[k++].pixel =
								XGetPixel(
									image,
									i, j);
						}
					}
				}
			}
			if (image != None)
			{
				XDestroyImage(image);
			}
			if (mask_image != None)
			{
				XDestroyImage(mask_image);
			}
			if (k == 0)
			{
				do_set_default_background = True;
			}
			else
			{
				/* look them all up, XQueryColors() can't
				 * handle more than 256 */
				for (i = 0; i < k; i += 256)
				{
					XQueryColors(
						dpy, Pcmap, &colors[i],
						min(k - i, 256));
				}
				/* calculate average, add overflows in a double
				 * .red is short, red is long */
				for (i = 0; i < k; i++)
				{
					tred = red;
					red += colors[i].red;
					if (red < tred)
					{
						dred += (double)tred;
						red = colors[i].red;
					}
					tgreen = green;
					green += colors[i].green;
					if (green < tgreen)
					{
						dgreen += (double)tgreen;
						green = colors[i].green;
					}
					tblue = blue;
					blue += colors[i].blue;
					if (blue < tblue)
					{
						dblue += (double)tblue;
						blue = colors[i].blue;
					}
				}
				dred += red;
				dgreen += green;
				dblue += blue;
				/* get it */
				color.red = dred / k;
				color.green = dgreen / k;
				color.blue = dblue / k;
				{
					Pixel old_bg = cs->bg;

					PictureFreeColors(
						dpy, Pcmap, &cs->bg, 1, 0,
						True);
					PictureAllocColor(
						dpy, Pcmap, &color, True);
					cs->bg = color.pixel;
					if (old_bg != cs->bg)
					{
						have_pixels_changed = True;
					}
				}
			}
			free(colors);
		} /* average */
		else if ((cs->color_flags & BG_SUPPLIED) && bg != NULL)
		{
			/* user specified colour */
			Pixel old_bg = cs->bg;

			PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True);
			cs->bg = GetColor(bg);
			if (old_bg != cs->bg)
			{
				have_pixels_changed = True;
			}
		} /* user specified */
		else if (bg == NULL && has_bg_changed)
		{
			/* default */
			do_set_default_background = True;
		} /* default */
		if (do_set_default_background)
		{
			Pixel old_bg = cs->bg;

			PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True);
			cs->bg = GetColor(white);
			if (old_bg != cs->bg)
			{
				have_pixels_changed = True;
			}
			has_bg_changed = True;
		}

		if (has_bg_changed)
		{
			/* save the bg color for tinting */
			cs->bg_saved = cs->bg;
		}
	} /* has_bg_changed */


	/*
	 * ---------- setup the bg tint colour ----------
	 */
	if (has_bg_tint_changed && cs->bg_tint_percent > 0 && bg_tint != NULL)
	{
		PictureFreeColors(dpy, Pcmap, &cs->bg_tint, 1, 0, True);
		cs->bg_tint = GetColor(bg_tint);
	}

	/*
	 * ---------- tint the bg colour ----------
	 */
	if (has_bg_tint_changed || (has_bg_changed && cs->bg_tint_percent > 0))
	{
		if (cs->bg_tint_percent == 0)
		{
			Pixel old_bg = cs->bg;

			PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True);
			cs->bg = cs->bg_saved;
			if (old_bg != cs->bg)
			{
				have_pixels_changed = True;
				has_bg_changed = True;
			}
		}
		else
		{
			Pixel old_bg = cs->bg;

			PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True);
			cs->bg = GetTintedPixel(
				cs->bg_saved, cs->bg_tint, cs->bg_tint_percent);
			if (old_bg != cs->bg)
			{
				have_pixels_changed = True;
				has_bg_changed = True;
			}
		}
	}

	/*
	 * ---------- setup the fg tint colour ----------
	 */
	if (has_fg_tint_changed && cs->fg_tint_percent > 0 && fg_tint != NULL)
	{
		PictureFreeColors(dpy, Pcmap, &cs->fg_tint, 1, 0, True);
		cs->fg_tint = GetColor(fg_tint);
	}

	/*
	 * ---------- change the foreground colour ----------
	 */
	if (has_fg_changed ||
	    (has_bg_changed && (cs->color_flags & FG_CONTRAST)))
	{
		if (cs->color_flags & FG_CONTRAST)
		{
			Pixel old_fg = cs->fg;

			/* calculate contrasting foreground color */
			color.pixel = cs->bg;
			XQueryColor(dpy, Pcmap, &color);
			color.red = (color.red > 32767) ? 0 : 65535;
			color.green = (color.green > 32767) ? 0 : 65535;
			color.blue = (color.blue > 32767) ? 0 : 65535;

			PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True);
			PictureAllocColor(dpy, Pcmap, &color, True);
			cs->fg = color.pixel;
			if (old_fg != cs->fg)
			{
				have_pixels_changed = True;
				has_fg_changed = 1;
			}
		} /* contrast */
		else if ((cs->color_flags & FG_SUPPLIED) && fg != NULL)
		{
			/* user specified colour */
			Pixel old_fg = cs->fg;

			PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True);
			cs->fg = GetColor(fg);
			if (old_fg != cs->fg)
			{
				have_pixels_changed = True;
				has_fg_changed = 1;
			}
		} /* user specified */
		else if (fg == NULL)
		{
			/* default */
			Pixel old_fg = cs->fg;

			PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True);
			cs->fg = GetColor(black);
			if (old_fg != cs->fg)
			{
				have_pixels_changed = True;
				has_fg_changed = 1;
			}
		}

		/* save the fg color for tinting */
		cs->fg_saved = cs->fg;

	} /* has_fg_changed */

	/*
	 * ---------- tint the foreground colour ----------
	 */
	if (has_fg_tint_changed || (has_fg_changed && cs->fg_tint_percent > 0))
	{
		if (cs->fg_tint_percent == 0)
		{

			Pixel old_fg = cs->fg;

			PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True);
			cs->fg = cs->fg_saved;
			if (old_fg != cs->fg)
			{
				have_pixels_changed = True;
				has_fg_changed = 1;
			}
		}
		else
		{
			Pixel old_fg = cs->fg;

			PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True);
			cs->fg = GetTintedPixel(
				cs->fg_saved, cs->fg_tint,
				cs->fg_tint_percent);
			if (old_fg != cs->fg)
			{
				have_pixels_changed = True;
				has_fg_changed = 1;
			}
		}
	}


	/*
	 * ---------- change the hilight colour ----------
	 */
	if (has_hi_changed ||
	    (has_bg_changed && !(cs->color_flags & HI_SUPPLIED)))
	{
		has_hi_changed = 1;
		if ((cs->color_flags & HI_SUPPLIED) && hi != NULL)
		{
			/* user specified colour */
			Pixel old_hilite = cs->hilite;

			PictureFreeColors(dpy, Pcmap, &cs->hilite, 1, 0, True);
			cs->hilite = GetColor(hi);
			if (old_hilite != cs->hilite)
			{
					have_pixels_changed = True;
			}
		} /* user specified */
		else if (hi == NULL)
		{
			Pixel old_hilite = cs->hilite;

			PictureFreeColors(dpy, Pcmap, &cs->hilite, 1, 0, True);
			cs->hilite = GetHilite(cs->bg);
			if (old_hilite != cs->hilite)
			{
				have_pixels_changed = True;
			}
		}
	} /* has_hi_changed */

	/*
	 * ---------- change the shadow colour ----------
	 */
	if (has_sh_changed ||
	    (has_bg_changed && !(cs->color_flags & SH_SUPPLIED)))
	{
		has_sh_changed = 1;
		if ((cs->color_flags & SH_SUPPLIED) && sh != NULL)
		{
			/* user specified colour */
			Pixel old_shadow = cs->shadow;

			PictureFreeColors(dpy, Pcmap, &cs->shadow, 1, 0, True);
			cs->shadow = GetColor(sh);
			if (old_shadow != cs->shadow)
			{
				have_pixels_changed = True;
			}
		} /* user specified */
		else if (sh == NULL)
		{
			Pixel old_shadow = cs->shadow;

			PictureFreeColors(dpy, Pcmap, &cs->shadow, 1, 0, True);
			cs->shadow = GetShadow(cs->bg);
			if (old_shadow != cs->shadow)
			{
				have_pixels_changed = True;
			}
		}
	} /* has_sh_changed */

	/*
	 * ---------- change the shadow foreground colour ----------
	 */
	if (has_fgsh_changed ||
	    ((has_fg_changed || has_bg_changed) &&
	     !(cs->color_flags & FGSH_SUPPLIED)))
	{
		has_fgsh_changed = 1;
		if ((cs->color_flags & FGSH_SUPPLIED) && fgsh != NULL)
		{
			/* user specified colour */
			Pixel old_fgsh = cs->fgsh;

			PictureFreeColors(dpy, Pcmap, &cs->fgsh, 1, 0, True);
			cs->fgsh = GetColor(fgsh);
			if (old_fgsh != cs->fgsh)
			{
				have_pixels_changed = True;
			}
		} /* user specified */
		else if (fgsh == NULL)
		{
			Pixel old_fgsh = cs->fgsh;

			PictureFreeColors(dpy, Pcmap, &cs->fgsh, 1, 0, True);
			cs->fgsh = GetForeShadow(cs->fg, cs->bg);
			if (old_fgsh != cs->fgsh)
			{
				have_pixels_changed = True;
			}
		}
	} /* has_fgsh_changed */

	/*
	 * ------- the pixmap is a bitmap: create here cs->pixmap -------
	 */
	if (cs->picture != None && pixmap_is_a_bitmap &&
	    (has_pixmap_changed || has_bg_changed))
	{
		cs->pixmap = XCreatePixmap(
			dpy, win, cs->width, cs->height, Pdepth);
		XSetBackground(dpy, gc, cs->bg);
		XSetForeground(dpy, gc, cs->fg);
		reset_cs_pixmap(cs, gc);
	}

	/*
	 * ------- change the masked out parts of the background pixmap -------
	 */
	if (cs->pixmap != None && cs->pixmap != ParentRelative &&
	    (!CSETS_IS_TRANSPARENT_ROOT(cs)||
	     cs->allows_buffered_transparency) &&
	    (cs->mask != None || cs->alpha_pixmap != None ||
	     cs->image_alpha_percent < 100 || cs->tint_percent > 0) &&
	    (has_pixmap_changed || has_bg_changed || has_image_alpha_changed
	     || has_tint_changed))
	{
		/* Now that we know the background colour we can update the
		 * pixmap background. */
		FvwmRenderAttributes fra;
		Pixmap temp, mask, alpha;

		memset(&fra, 0, sizeof(fra));
		temp = XCreatePixmap(dpy, win, cs->width, cs->height, Pdepth);
		if (cs->picture != NULL)
		{
			mask = cs->picture->mask;
			alpha = cs->picture->alpha;
		}
		else
		{
			mask = None;
			alpha = None;
		}
		XSetForeground(dpy, gc, cs->bg);
		XFillRectangle(
			dpy, temp, gc, 0, 0, cs->width, cs->height);

		fra.mask = FRAM_HAVE_ADDED_ALPHA | FRAM_HAVE_TINT;
		fra.added_alpha_percent = cs->image_alpha_percent;
		fra.tint = cs->tint;
		fra.tint_percent = cs->tint_percent;
		PGraphicsRenderPixmaps(
			dpy, win, cs->pixmap, mask, alpha, Pdepth, &fra,
			temp, gc, Scr.MonoGC, Scr.AlphaGC,
			0, 0, cs->width, cs->height,
			0, 0, cs->width, cs->height, False);
		if (cs->pixmap != root_pic.pixmap)
		{
			add_to_junk(cs->pixmap);
		}
		cs->pixmap = temp;
		has_pixmap_changed = True;
		if (CSETS_IS_TRANSPARENT_ROOT(cs))
		{
			cs->pixmap_type = PIXMAP_ROOT_PIXMAP_TRAN;
		}
	} /* has_pixmap_changed */


	/*
	 * ---------- change the icon tint colour ----------
	 */
	if (has_icon_tint_changed)
	{
		/* user specified colour */
		if (icon_tint != NULL)
		{
			Pixel old_tint = cs->icon_tint;
			PictureFreeColors(
				dpy, Pcmap, &cs->icon_tint, 1, 0, True);
			cs->icon_tint = GetColor(icon_tint);
			if (old_tint != cs->icon_tint)
			{
				has_icon_pixels_changed = True;
			}
		}
		else
		{
			/* default */
			Pixel old_tint = cs->icon_tint;
			PictureFreeColors(
				dpy, Pcmap, &cs->icon_tint, 1, 0, True);
			cs->icon_tint = GetColor(black);
			if (old_tint != cs->icon_tint)
			{
				has_icon_pixels_changed = True;
			}
		}
	}

	/*
	 * ---------- send new colorset to fvwm and clean up ----------
	 */
	/* make sure the server has this to avoid races */
	XSync(dpy, False);

	/* inform modules of the change */
	if (have_pixels_changed || has_pixmap_changed || has_shape_changed ||
	    has_fg_alpha_changed || has_icon_pixels_changed)
	{
		BroadcastColorset(n);
	}

	if (fg)
	{
		free(fg);
	}
	if (bg)
	{
		free(bg);
	}
	if (hi)
	{
		free(hi);
	}
	if (sh)
	{
		free(sh);
	}
	if (fgsh)
	{
		free(fgsh);
	}
	if (tint)
	{
		free(tint);
	}
	if (fg_tint)
	{
		free(fg_tint);
	}
	if (bg_tint)
	{
		free(bg_tint);
	}
	if (icon_tint)
	{
		free(icon_tint);
	}
	return;
}
Exemplo n.º 21
0
/*
** seemed kind of silly to have check_allowed_function and
** check_allowed_function2 partially overlapping in their checks, so I
** combined them here and made them wrapper functions instead.
*/
Bool is_function_allowed(
	int function, char *action_string, const FvwmWindow *t,
	request_origin_t request_origin, Bool do_allow_override_mwm_hints)
{
	unsigned int functions;
	char *functionlist[] = {
		MOVE_STRING,
		RESIZE_STRING1,
		RESIZE_STRING2,
		MINIMIZE_STRING,
		MINIMIZE_STRING2,
		MAXIMIZE_STRING,
		CLOSE_STRING1,
		CLOSE_STRING2,
		CLOSE_STRING3,
		CLOSE_STRING4,
		NULL
	};

	if (t == NULL)
	{
		return True;  /* this logic come from animated menu */
	}
	if (do_allow_override_mwm_hints && HAS_MWM_OVERRIDE_HINTS(t))
	{
		/* allow everything */
		functions = ~0;
	}
	else
	{
		/* restrict by mwm hints */
		functions = t->functions;
	}

	/* Hate to do it, but for lack of a better idea, check based on the
	 * menu entry name */
	/* Complex functions are a little tricky, ignore them if no menu item*/
	if (function == F_FUNCTION && action_string != NULL)
	{
		int i;

		/* remap to regular actions */

		i = GetTokenIndex(action_string, functionlist, -1, NULL);
		switch (i)
		{
		case 0:
			function = F_MOVE;
			break;
		case 1:
			function = F_RESIZE;
			break;
		case 2:
			function = F_RESIZE;
			break;
		case 3:
			function = F_ICONIFY;
			break;
		case 4:
			function = F_ICONIFY;
			break;
		case 5:
			function = F_MAXIMIZE;
			break;
		case 6:
			function = F_CLOSE;
			break;
		case 7:
			function = F_DELETE;
			break;
		case 8:
			function = F_DESTROY;
			break;
		case 9:
			function = F_QUIT;
			break;
		default:
			break;
		}
	}
	/* now do the real checks */
	switch(function)
	{
	case F_DELETE:
	        if (IS_UNCLOSABLE(t))
		{
		        return False;
		}
		if (IS_TEAR_OFF_MENU(t))
		{
			/* always allow this on tear off menus */
			break;
		}
		if (!WM_DELETES_WINDOW(t))
		{
			return False;
		}
		/* fall through to close clause */
	case F_CLOSE:
	        if (IS_UNCLOSABLE(t))
		{
		        return False;
		}
		if (IS_TEAR_OFF_MENU(t))
		{
			/* always allow this on tear off menus */
			break;
		}
		if (!(functions & MWM_FUNC_CLOSE))
		{
			return False;
		}
		break;
	case F_DESTROY: /* shouldn't destroy always be allowed??? */
	        if (IS_UNCLOSABLE(t))
		{
		        return False;
		}
		if (IS_TEAR_OFF_MENU(t))
		{
			/* always allow this on tear off menus */
			break;
		}
		if (!(functions & MWM_FUNC_CLOSE))
		{
			return False;
		}
		break;
	case F_RESIZE:
	        if(!__is_resize_allowed(t, functions, request_origin))
		{
		        return False;
		}
		break;
	case F_ICONIFY:
		if ((!IS_ICONIFIED(t) && !(functions & MWM_FUNC_MINIMIZE)) ||
		    IS_UNICONIFIABLE(t))
		{
			return False;
		}
		break;
	case F_MAXIMIZE:
	        if (IS_MAXIMIZE_FIXED_SIZE_DISALLOWED(t) &&
		    !__is_resize_allowed(t, functions, request_origin))
		{
		       return False;
		}
		if ((request_origin && !(functions & MWM_FUNC_MAXIMIZE)) ||
		    IS_UNMAXIMIZABLE(t))
		{
			return False;
		}
		break;
	case F_MOVE:
		/* Move is a funny hint. Keeps it out of the menu, but you're
		 * still allowed to move. */
		if (request_origin && IS_FIXED(t))
		{
			return False;
		}
		else if (!request_origin && IS_FIXED_PPOS(t))
		{
			return False;
		}
		if (request_origin && !(functions & MWM_FUNC_MOVE))
		{
			return False;
		}
		break;
	case F_FUNCTION:
	default:
		break;
	} /* end of switch */

	/* if we fell through, just return True */
	return True;
}
Exemplo n.º 22
0
Bool StartButtonParseConfig(char *tline)
{
	char *rest;
	char *option;
	int i, j, k;
	int titleRecorded = 0, iconRecorded = 0;
	char *tokens[100];  /* This seems really big */
	StartAndLaunchButtonItem *tempPtr;
	int mouseButton;
	char **tmpStrPtr;

	option = tline + module->namelen+1;
	i = GetTokenIndex(option, startopts, -1, &rest);
	while (*rest && *rest != '\n' && isspace(*rest))
	{
		rest++;
	}
	switch(i)
	{
	case 0: /* StartName */
		if (First_Start_Button == NULL)
		{
			First_Start_Button = Last_Start_Button =
				(StartAndLaunchButtonItem*)safemalloc(
					sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(First_Start_Button);
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->isStartButton == False)
		{
			/* shortcut button has been declared before start
			 * button */
			tempPtr = (StartAndLaunchButtonItem*)safemalloc(
				sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(tempPtr);
			tempPtr->tail = First_Start_Button;
			First_Start_Button = tempPtr;
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->buttonCaption != NULL)
		{
			/* declarin caption twice, ignore */
			break;
		}
		CopyString(&(First_Start_Button->buttonCaption), rest);
		break;
	case 1: /* StartMenu */
		rest = ParseButtonOptions(rest, &mouseButton);
		if (First_Start_Button == NULL)
		{
			First_Start_Button = Last_Start_Button =
				(StartAndLaunchButtonItem*)safemalloc(
					sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(First_Start_Button);
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->isStartButton == False)
		{
			/* shortcut button has been declared before start
			 * button */
			tempPtr = (StartAndLaunchButtonItem*) safemalloc(
				sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(tempPtr);
			tempPtr->tail = First_Start_Button;
			First_Start_Button = tempPtr;
			First_Start_Button->isStartButton = True;
		}
		tmpStrPtr = (mouseButton ?
			     &(First_Start_Button->buttonCommands[mouseButton-1])
			     :
			     &(First_Start_Button->buttonCommand));
		if (*tmpStrPtr)
		{
			/* declaring command twice, ignore */
			break;
		}
		CopyString(tmpStrPtr, rest);
		break;
	case 2: /* StartIcon */
		if (First_Start_Button == NULL)
		{
			First_Start_Button = Last_Start_Button =
				(StartAndLaunchButtonItem*)safemalloc(
					sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(First_Start_Button);
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->isStartButton == False)
		{
			/* shortcut button has been declared before start
			 * button */
			tempPtr = (StartAndLaunchButtonItem*) safemalloc(
				sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(tempPtr);
			tempPtr->tail = First_Start_Button;
			First_Start_Button = tempPtr;
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->buttonIconFileName != NULL)
		{
			/* declaring icon twice, ignore */
			break;
		}
		CopyString(&(First_Start_Button->buttonIconFileName), rest);
		break;
	case 3: /* StartCommand */
		rest = ParseButtonOptions(rest, &mouseButton);
		if (First_Start_Button == NULL)
		{
			First_Start_Button = Last_Start_Button =
				(StartAndLaunchButtonItem*)safemalloc(
					sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(First_Start_Button);
			First_Start_Button->isStartButton = True;
		}
		else if (First_Start_Button->isStartButton == False)
		{
			/* shortcut button has been declared before start
			 * button */
			tempPtr = (StartAndLaunchButtonItem*)safemalloc(
				sizeof(StartAndLaunchButtonItem));
			StartAndLaunchButtonItemInit(tempPtr);
			tempPtr->tail = First_Start_Button;
			First_Start_Button = tempPtr;
			First_Start_Button->isStartButton = True;
		}
		tmpStrPtr =
			(mouseButton ?
			 &(First_Start_Button->buttonStartCommands[mouseButton-1]) :
			 &(First_Start_Button->buttonStartCommand));
		if (*tmpStrPtr)
		{
			/* declaring command twice, ignore */
			break;
		}
		CopyString(tmpStrPtr, rest);
		break;
	case 4: /* NoDefaultStartButton */
		NoDefaultStartButton = True;
		break;
	case 5: /* Button */
		if (Last_Start_Button == NULL)
		{
			First_Start_Button = Last_Start_Button =
				(StartAndLaunchButtonItem*)safemalloc(
					sizeof(StartAndLaunchButtonItem));
		}
		else
		{
			Last_Start_Button->tail =
				(StartAndLaunchButtonItem*) safemalloc(
					sizeof(StartAndLaunchButtonItem));
			Last_Start_Button = Last_Start_Button->tail;
		}

		StartAndLaunchButtonItemInit(Last_Start_Button);
		j=0;
		titleRecorded = iconRecorded = 0;
		{
			char *strtok_ptr = 0;

			tokens[j++] = strtok_r(rest, ",", &strtok_ptr);
			while((tokens[j++] = strtok_r(NULL, ",", &strtok_ptr)))
			{
				while(isspace(*(tokens[j-1])))
				{
					tokens[j-1]+=sizeof(char);
				}
			}
		}
		j--;

		for(k=0;k<j;k++)
		{
			if (strncasecmp(tokens[k], "Title", 5)==0)
			{
				tokens[j+1] = tokens[k] + ((sizeof(char))*5);
				while(*(tokens[j+1])==' ')
					tokens[j+1]+=sizeof(char);
				CopyString(
					&(Last_Start_Button->buttonCaption),
					tokens[j+1]);
				titleRecorded=1;
			}
			else if (strncasecmp(tokens[k], "Icon", 4)==0)
			{
				tokens[j+1] = tokens[k] + ((sizeof(char))*4);
				while(*(tokens[j+1])==' ')
					tokens[j+1]+=sizeof(char);
				CopyString(
					&(Last_Start_Button->buttonIconFileName),
					tokens[j+1] );
				iconRecorded = 1;
			}
			else if (strncasecmp(tokens[k], "Action", 6)==0)
			{
				rest = tokens[k] + ((sizeof(char))*6);
				rest = ParseButtonOptions(rest, &mouseButton);
				tokens[j+1] = rest;
				if (mouseButton)
				{
					tmpStrPtr =
						&(Last_Start_Button->
						  buttonStartCommands
						  [mouseButton-1]);
				}
				else
				{
					tmpStrPtr =
						&(Last_Start_Button->
						  buttonStartCommand);
				}
				if (!(*tmpStrPtr))
				{
					/* don't let them set the same action
					 * twice */
					CopyString(tmpStrPtr, tokens[j+1]);
				}
			}
		}
		if (titleRecorded==0)
		{
			CopyString(&(Last_Start_Button->buttonCaption), "\0");
		}
		if (iconRecorded==0)
		{
			CopyString(
				&(Last_Start_Button->buttonIconFileName),
				"\0");
		}
		break;

	case 6: /* WindowButtonsLeftMargin */
		if(atoi(rest)>=0)
		{
			WindowButtonsLeftMargin = atoi(rest);
			has_wb_left_margin = 1;
		}
		break;
	case 7: /* WindowButtonsRightMargin */
		if(atoi(rest)>=0)
		{
			WindowButtonsRightMargin = atoi(rest);
			has_wb_right_margin = 1;
		}
		break;
	case 8: /* StartButtonRightMargin */
		if(atoi(rest)>=0)
		{
			StartButtonRightMargin = atoi(rest);
		}
		break;
	default:
		/* unknown option */
		return False;
	} /* switch */

	return True;
}
Exemplo n.º 23
0
/* expands certain variables in a command to be sent by a module */
char *module_expand_action(
	Display *dpy, int screen , char *in_action, rectangle *r,
	char *forecolor, char *backcolor)
{
	char *variables[] =
	{
		"$",
		"fg",
		"bg",
		"left",
		"-left",
		"right",
		"-right",
		"top",
		"-top",
		"bottom",
		"-bottom",
		"width",
		"height",
		NULL
	};
	char *action = NULL;
	char *src;
	char *dest;
	char *string = NULL;
	char *rest;
	int val = 0;
	int offset;
	int i;
	char *dest_org;
	Bool is_string;
	Bool is_value;
	Bool has_geom;
	Bool has_fg;
	Bool has_bg;
	rectangle tmpr = { 0, 0, 0, 0 };

	has_geom = (r == NULL) ? False : True;
	has_fg = (forecolor == NULL) ? False : True;
	has_bg = (backcolor == NULL) ? False : True;
	if (r == NULL)
	{
		r = &tmpr;
	}
	/* create a temporary storage for expanding */
	action = mvwm_malloc(MAX_MODULE_INPUT_TEXT_LEN);
	for (src = in_action, dest = action; *src != 0; src++)
	{
		if (*src != '$')
		{
			*(dest++) = *src;
			continue;
		}
		/* it's a variable */
		dest_org = dest;
		is_string = False;
		is_value = False;
		*(dest++) = *(src++);
		i = GetTokenIndex(src, variables, -1, &rest);
		if (i == -1)
		{
			src--;
			continue;
		}
		switch (i)
		{
		case 0: /* $ */
			continue;
		case 1: /* fg */
			string = forecolor;
			is_string = has_fg;
			break;
		case 2: /* bg */
			if (backcolor == NULL)
			{
				continue;
			}
			string = backcolor;
			is_string = has_bg;
			break;
		case 3: /* left */
			val = r->x;
			is_value = has_geom;
			break;
		case 4: /* -left */
			val = DisplayWidth(dpy, screen) - r->x - 1;
			is_value = has_geom;
			break;
		case 5: /* right */
			val = r->x + r->width;
			is_value = has_geom;
			break;
		case 6: /* -right */
			val = DisplayWidth(dpy, screen) - r->x - r->width - 1;
			is_value = has_geom;
			break;
		case 7: /* top */
			val = r->y;
			is_value = has_geom;
			break;
		case 8: /* -top */
			val = DisplayHeight(dpy, screen) - r->y - 1;
			is_value = has_geom;
			break;
		case 9: /* bottom */
			val = r->y + r->height;
			is_value = has_geom;
			break;
		case 10: /* -bottom */
			val = DisplayHeight(dpy, screen) - r->y - r->height - 1;
			is_value = has_geom;
			break;
		case 11: /* width */
			val = r->width;
			is_value = has_geom;
			break;
		case 12: /* height */
			val = r->height;
			is_value = has_geom;
			break;
		default: /* unknown */
			src--;
			continue;
		} /* switch */
		if (is_value == False && is_string == False)
		{
			src--;
			continue;
		}
		dest = dest_org;
		src = --rest;
		if (is_value)
		{
			if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <= 16)
			{
				/* out of space */
				free(action);
				return NULL;
			}
			/* print the number into the string */
			sprintf(dest, "%d%n", val, &offset);
			dest += offset;
		}
		else if (is_string)
		{
			if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <=
			    strlen(string))
			{
				/* out of space */
				free(action);
				return NULL;
			}
			/* print the colour name into the string */
			if (string)
			{
				sprintf(dest, "%s%n", string, &offset);
				dest += offset;
			}
		}
	} /* for */
	*dest = 0;

	return action;
}