Exemple #1
0
Fichier : parse.c Projet : 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;
}
Exemple #2
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;
	}
}
Exemple #3
0
Fichier : parse.c Projet : att/uwin
/**
*** ParsePanel()
*** Parses the options possible to Panel
**/
static void ParsePanel(char **ss, byte *flags, byte *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++;
    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;
    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((*s>='0' && *s<='9') || *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;
}
Exemple #4
0
Fichier : parse.c Projet : att/uwin
/**
*** 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++;
    else 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->font_string = my_get_font(&s);
      if(b->c->font_string)
      {
	b->c->flags|=b_Font;
      } else
	b->c->flags&=~b_Font;
      break;
    case 3: /* Frame */
      b->c->framew=strtol(s,&t,10);
      b->c->flags|=b_Frame;
      s=t;
      break;
    case 4: /* Back */
      s = trimleft(s);
      if(*s=='(' && s++)
	if(ParseBack(&s))
	  b->c->flags|=b_IconBack;
      if (b->c->back) free(b->c->back);
      b->c->back=seekright(&s);
      if(b->c->back)
      {
	b->c->flags|=b_Back;
      }
      else
	b->c->flags&=~(b_IconBack|b_Back);
      break;
    case 5: /* Fore */
      if (b->c->fore) free(b->c->fore);
      b->c->fore=seekright(&s);
      if(b->c->fore)
      {
	b->c->flags|=b_Fore;
      }
      else
	b->c->flags&=~b_Fore;
      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;
      }
      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;
      }
      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_Panel))
	{
	  fprintf(stderr, "%s: Multiple Swallow or Panel options are not"
		" allowed in a signle 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);
	  if(b->c->swallow_mask)
	  {
	    b->c->flags |= b_Swallow;
	  }
	}
	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;
      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;
	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;
	AllocColorset(i);
	s = t;
      }
      else
      {
	b->c->flags &= ~b_Colorset;
      }
      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;
}
Exemple #5
0
int skinRead( char * dname )
{
 unsigned char   tmp[255];
 unsigned char * ptmp;
 unsigned char   command[32];
 unsigned char   param[256];
 int             c,i;

 setname( skinDirInHome,dname );
 if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
  {
   setname( skinMPlayerDir,dname );
   if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
    {
     setname( skinDirInHome_obsolete,dname );
     if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
      {
       setname( skinMPlayerDir_obsolete,dname );
       if ( ( skinFile = fopen( fn,"rt" ) ) == NULL )
        {
         setname( skinMPlayerDir,dname );
         mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_SKIN_SkinFileNotFound,fn );
         return -1;
        }
      }
    }
  }

 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[skin] file: %s\n",fn );

 appInitStruct( skinAppMPlayer );

 linenumber=0;
 while (fgets(tmp, 255, skinFile))
  {
   linenumber++;

   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
   for ( c=0;c<(int)strlen( tmp );c++ )
    if ( tmp[c] == ';' )
     {
      tmp[c]=0;
      break;
     }
   if ( strlen( tmp ) == 0 ) continue;
   ptmp=trimleft( tmp );
   if ( strlen( ptmp ) == 0 ) continue;
   ptmp=strswap( ptmp,'\t',' ' );
   ptmp=trim( ptmp );

   cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
   strlower( command );
   for( i=0;i<ITEMS;i++ )
    if ( !strcmp( command,skinItem[i].name ) )
     if ( skinItem[i].func( param ) ) return -2;
  }
 if (linenumber == 0) {
   mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SkinFileNotReadable, fn);
   return -1;
 }
 return 0;
}
Exemple #6
0
Fichier : parse.c Projet : 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;
}
Exemple #7
0
/*#define DEBUG_PARSER*/
void match_string(button_info **uberb,char *s)
{
    button_info *b,*ub=*uberb;
    int i,j;
    char *t,*o;
    b=alloc_button(ub,(ub->c->num_buttons)++);
    trimleft(s);

    if(*s=='(' && s++)
    {
        char *opts[]= {"back","fore","font","title","icon","frame","padding",
                       "swallow","action","container","end","nosize","size",
                       NULL
                      };
        trimleft(s);
        while(*s && *s!=')')
        {
            if(*s>='0' && *s<='9')
            {
                sscanf(s,"%dx%d",&i,&j);
                if(i>0) b->BWidth=i;
                if(j>0) b->BHeight=j;
                while(*s!=' ' && *s!='\t' && *s!=')' && *s!=',') s++;
                trimleft(s);
                continue;
            }
            if(*s==',' && s++)
                trimleft(s);
            switch(MatchSeveralLines(s,opts,&s))
            {
            case 0: /* Back */
                trimleft(s);
                if(*s=='(' && s++)
                    if(ParseBack(&s))
                        b->flags|=b_IconBack;
                if(b->flags&b_Back) free(b->back);
                b->back=seekright(&s);
                if(b->back)
                    b->flags|=b_Back;
                else
                    b->flags&=~b_IconBack;
                break;

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

            case 2: /* Font */
                if(b->flags&b_Font) free(b->font_string);
                b->font_string=seekright(&s);
                b->flags|=b_Font;
                break;

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

            case 3: /* Title */
                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[0]!='-' || t[1]!=0))
                {
                    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[0]!='-' && t[1]!=0))
                {
                    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 */
                trimleft(s);
                b->swallow=0;
                b->swallow_mask=0;
                if(*s=='(' && s++)
                    ParseSwallow(&s,&b->swallow,&b->swallow_mask);
                t=seekright(&s);
                o=seekright(&s);
                if(t)
                {
                    b->hangon=t;
                    b->flags|=b_Hangon;
                    b->flags|=b_Swallow;
                    b->swallow|=1;
                    if(!(b->swallow&b_NoHints))
                        b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints));
                    if(o)
                    {
                        if(!(buttonSwallow(b)&b_UseOld))
                            SendText(fd,o,0);
                        b->spawn=o;  /* Might be needed if respawning sometime */
                    }
                }
                else
                {
                    fprintf(stderr,"%s: Missing swallow argument\n",MyName);
                    if(t)free(t);
                    if(o)free(o);
                }
                break;

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

            case 8: /* Action */
                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++;
                }
                t=seekright(&s);
                if(t)
                    AddButtonAction(b,i,strdup(t));
                else
                    fprintf(stderr,"%s: Missing action argument\n",MyName);
                break;

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

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

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

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

            case 12: /* 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;

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

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

    if(!(b->flags&b_Icon))
    {
        b->icon_file=seekright(&s);
        if(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
        free(seekright(&s));

    trimleft(s);

    /* Swallow hangon command */
    if(strncasecmp(s,"swallow",7)==0)
    {
        if(b->flags&b_Swallow)
        {
            fprintf(stderr,"%s: Illegal with both old and new swallow!\n",
                    MyName);
            exit(1);
        }
        s+=7;
        b->hangon=seekright(&s);
        b->flags|=(b_Swallow|b_Hangon);
        b->swallow|=1;
        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=strdup(s);
        }
    }
    else if(*s)
        AddButtonAction(b,0,strdup(s));
    return;
}
Exemple #8
0
/**
*** ParseConfigLine
**/
void ParseConfigLine(button_info **ubb,char *s)
{
    button_info *ub=*ubb;
    char *opts[]= {"geometry","font","padding","columns","rows","back","fore",
                   "frame","file",NULL
                  };
    int i,j,k;

    switch(MatchSeveralLines(s,opts,&s))
    {
    case 0:/* Geometry */
    {
        char geom[64];
        int flags,g_x,g_y,width,height;
        i=sscanf(s,"%63s",geom);
        if(i==1)
        {
            flags=XParseGeometry(geom,&g_x,&g_y,&width,&height);
            if(flags&WidthValue) w=width;
            if(flags&HeightValue) h=height;
            if(flags&XValue) x=g_x;
            if(flags&YValue) y=g_y;
            if(flags&XNegative) xneg=1;
            if(flags&YNegative) yneg=1;
        }
        break;
    }
    case 1:/* Font */
        CopyString(&ub->c->font_string,s);
        break;
    case 2:/* 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 3:/* Columns */
        i=sscanf(s,"%d",&j);
        if(i>0) ub->c->num_columns=j;
        break;
    case 4:/* Rows */
        i=sscanf(s,"%d",&j);
        if(i>0) ub->c->num_rows=j;
        break;
    case 5:/* Back */
        CopyString(&(ub->c->back),s);
        break;
    case 6:/* Fore */
        CopyString(&(ub->c->fore),s);
        break;
    case 7:/* Frame */
        i=sscanf(s,"%d",&j);
        if(i>0) ub->c->framew=j;
        break;
    case 8:/* File */
        trimleft(s);
        config_file=seekright(&s);
        break;
    default:
        trimleft(s);
        match_string(ubb,s);
        break;
    }
}
Exemple #9
0
/**
*** ParseContainer()
*** Parses the options possible to Container
**/
void ParseContainer(char **ss,button_info *b)
{
    char *conts[]= {"columns","rows","font","frame","back","fore",
                    "padding","title","swallow","nosize","size",NULL
                   };
    char *t,*o,*s=*ss;
    int i,j;

    while(*s && *s!=')')
    {
        trimleft(s);
        if(*s==',')
            s++;
        else switch(MatchSeveralLines(s,conts,&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 */
                b->c->font_string=seekright(&s);
                b->c->flags|=b_Font;
                break;
            case 3: /* Frame */
                b->c->framew=strtol(s,&t,10);
                b->c->flags|=b_Frame;
                s=t;
                break;
            case 4: /* Back */
                trimleft(s);
                if(*s=='(' && s++)
                    if(ParseBack(&s))
                        b->c->flags|=b_IconBack;
                b->c->back=seekright(&s);
                if(b->c->back)
                    b->c->flags|=b_Back;
                else
                    b->c->flags&=~b_IconBack;
                break;
            case 5: /* Fore */
                b->c->fore=seekright(&s);
                b->c->flags|=b_Fore;
                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;
                }
                else
                    fprintf(stderr,"%s: Illegal padding argument\n",MyName);
                break;
            case 7: /* Title - flags */
                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;
                }
                else
                {
                    fprintf(stderr,"%s: Illegal title in container options\n",
                            MyName);
                    free(seekright(&s));
                }
                break;
            case 8: /* Swallow - flags */
                trimleft(s);
                if(*s=='(' && s++)
                {
                    b->c->swallow=0;
                    b->c->swallow_mask=0;
                    ParseSwallow(&s,&b->c->swallow,&b->c->swallow_mask);
                    if(b->c->swallow_mask)
                        b->c->flags|=b_Swallow;
                }
                else
                {
                    fprintf(stderr,"%s: Illegal swallow in container options\n",
                            MyName);
                    free(seekright(&s));
                }
                break;
            case 9: /* NoSize */
                b->c->flags|=b_Size;
                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;
                    s=o;
                }
                else
                    fprintf(stderr,"%s: Illegal size arguments\n",MyName);
                break;

            default:
                t=seekright(&s);
                fprintf(stderr,"%s: Illegal container option \"%s\"\n",MyName,t);
                free(t);
            }
    }
    if(*s) s++;
    *ss=s;
}
Exemple #10
0
string& trim(string& s)
{
	trimleft( s );
	trimright( s );
	return s;
}
Exemple #11
0
std::string & trim(std::string & s, const char * charset)
{
    trimleft(s,charset);
    trimright(s,charset);
    return s;
}
Exemple #12
0
xtl::iwstring & trim(xtl::iwstring & s, const wchar_t * charset)
{
    trimleft(s,charset);
    trimright(s,charset);
    return s;
}
Exemple #13
0
xtl::istring & trim(xtl::istring & s, const char * charset)
{
    trimleft(s,charset);
    trimright(s,charset);
    return s;
}