Пример #1
0
Файл: parse.c Проект: 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;
}
Пример #2
0
/*
 *
 * SendUnlockNotification - informs mvwm that the module has
 * finished it's procedures and mvwm may proceed.
 *
 */
void SendUnlockNotification(int *fd)
{
	SendText(fd, ModuleUnlockResponse, 0);
}
Пример #3
0
void SendQuitNotification(int *fd)
{
	ModuleContinue = 0;
	SendText(fd, ModuleUnlockResponse, 0); /* unlock just in case */
}
Пример #4
0
/*
 *
 * SendFinishedStartupNotification - informs mvwm that the module has
 * finished its startup procedures and is fully operational now.
 *
 */
void SendFinishedStartupNotification(int *fd)
{
	SendText(fd, ModuleFinishedStartupResponse, 0);
}
Пример #5
0
    void UpdateAI(const uint32 diff)
    {
        if (Must_Die)
            if (Must_Die_Timer <= diff)
            {
                m_creature->ForcedDespawn();
                return;
            } else Must_Die_Timer -= diff;

        if (!Escape)
        {
            if (!PlayerGUID)
                return;

            if (spellEscape_Timer <= diff)
            {
                DoCast(m_creature, SPELL_RIZZLE_ESCAPE, false);
                spellEscape_Timer = 10000;
            } else spellEscape_Timer -= diff;

            if (Teleport_Timer <= diff)
            {
                //temp solution - unit can't be teleported by core using spelleffect 5, only players
                Map* pMap = m_creature->GetMap();
                if (pMap)
                {
                    pMap->CreatureRelocation(m_creature, 3706.39, -3969.15, 35.9118, 0);
                    m_creature->AI_SendMoveToPacket(3706.39, -3969.15, 35.9118, 0, 0, 0);
                }
                //begin swimming and summon depth charges
                Player* pPlayer = Unit::GetPlayer(PlayerGUID);
                SendText(MSG_ESCAPE_NOTICE, pPlayer);
                DoCast(m_creature, SPELL_PERIODIC_DEPTH_CHARGE);
                m_creature->SetUnitMovementFlags(MOVEMENTFLAG_HOVER | MOVEMENTFLAG_SWIMMING);
                m_creature->SetSpeed(MOVE_RUN, 0.85f, true);
                m_creature->GetMotionMaster()->MovementExpired();
                m_creature->GetMotionMaster()->MovePoint(CurrWP, WPs[CurrWP][0], WPs[CurrWP][1], WPs[CurrWP][2]);
                Escape = true;
            } else Teleport_Timer -= diff;

            return;
        }

        if (ContinueWP)
        {
            m_creature->GetMotionMaster()->MovePoint(CurrWP, WPs[CurrWP][0], WPs[CurrWP][1], WPs[CurrWP][2]);
            ContinueWP = false;
        }

        if (Grenade_Timer <= diff)
        {
            Player* pPlayer = Unit::GetPlayer(PlayerGUID);
            if (pPlayer)
            {
                DoScriptText(SAY_RIZZLE_GRENADE, m_creature, pPlayer);
                DoCast(pPlayer, SPELL_RIZZLE_FROST_GRENADE, true);
            }
            Grenade_Timer = 30000;
        } else Grenade_Timer -= diff;

        if (Check_Timer <= diff)
        {
            Player* pPlayer = Unit::GetPlayer(PlayerGUID);
            if (!pPlayer)
            {
                m_creature->ForcedDespawn();
                return;
            }

            if (m_creature->IsWithinDist(pPlayer, 10) && m_creature->GetPositionX() > pPlayer->GetPositionX() && !Reached)
            {
                DoScriptText(SAY_RIZZLE_FINAL, m_creature);
                m_creature->SetUInt32Value(UNIT_NPC_FLAGS, 1);
                m_creature->setFaction(35);
                m_creature->GetMotionMaster()->MoveIdle();
                m_creature->RemoveAurasDueToSpell(SPELL_PERIODIC_DEPTH_CHARGE);
                Reached = true;
            }

            Check_Timer = 1000;
        } else Check_Timer -= diff;

    }
Пример #6
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;
}
Пример #7
0
/*
 *
 *  Procedure:
 *      main - start of module
 *
 */
int main(int argc, char **argv)
{
	char *display_name = NULL;
	char *tline;

	FlocaleInit(LC_CTYPE, "", "", "FvwmIdent");

	module = ParseModuleArgs(argc,argv,0); /* no alias */
	if (module == NULL)
	{
		fprintf(
			stderr, "FvwmIdent Version %s should only be executed"
			" by fvwm!\n", VERSION);
		exit(1);
	}

#ifdef HAVE_SIGACTION
	{
		struct sigaction  sigact;

		sigemptyset(&sigact.sa_mask);
		sigaddset(&sigact.sa_mask, SIGPIPE);
		sigaddset(&sigact.sa_mask, SIGTERM);
		sigaddset(&sigact.sa_mask, SIGQUIT);
		sigaddset(&sigact.sa_mask, SIGINT);
		sigaddset(&sigact.sa_mask, SIGHUP);
# ifdef SA_INTERRUPT
		sigact.sa_flags = SA_INTERRUPT;
# else
		sigact.sa_flags = 0;
# endif
		sigact.sa_handler = TerminateHandler;

		sigaction(SIGPIPE, &sigact, NULL);
		sigaction(SIGTERM, &sigact, NULL);
		sigaction(SIGQUIT, &sigact, NULL);
		sigaction(SIGINT,  &sigact, NULL);
		sigaction(SIGHUP,  &sigact, NULL);
	}
#else
	/* We don't have sigaction(), so fall back to less robust methods.  */
#ifdef USE_BSD_SIGNALS
	fvwmSetSignalMask( sigmask(SIGPIPE) |
			   sigmask(SIGTERM) |
			   sigmask(SIGQUIT) |
			   sigmask(SIGINT) |
			   sigmask(SIGHUP) );
#endif
	signal(SIGPIPE, TerminateHandler);
	signal(SIGTERM, TerminateHandler);
	signal(SIGQUIT, TerminateHandler);
	signal(SIGINT,  TerminateHandler);
	signal(SIGHUP,  TerminateHandler);
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(SIGPIPE, 1);
	siginterrupt(SIGTERM, 1);
	siginterrupt(SIGQUIT, 1);
	siginterrupt(SIGINT, 1);
	siginterrupt(SIGHUP, 1);
#endif
#endif

	fd[0] = module->to_fvwm;
	fd[1] = module->from_fvwm;

	/* Open the Display */
	if (!(dpy = XOpenDisplay(display_name)))
	{
		fprintf(stderr,"%s: can't open display %s", module->name,
			XDisplayName(display_name));
		exit (1);
	}
	x_fd = XConnectionNumber(dpy);
	screen= DefaultScreen(dpy);
	Root = RootWindow(dpy, screen);
	XSetErrorHandler(ErrorHandler);

	flib_init_graphics(dpy);
	FlocaleAllocateWinString(&FwinString);

	SetMessageMask(fd, M_CONFIGURE_WINDOW | M_WINDOW_NAME | M_ICON_NAME
		       | M_RES_CLASS | M_RES_NAME | M_END_WINDOWLIST |
		       M_CONFIG_INFO | M_END_CONFIG_INFO | M_SENDCONFIG);
	SetMessageMask(fd, MX_PROPERTY_CHANGE);
	/* scan config file for set-up parameters */
	/* Colors and fonts */

	InitGetConfigLine(fd,CatString3("*",module->name,0));
	GetConfigLine(fd,&tline);

	while (tline != (char *)0)
	{
		if (strlen(tline) <= 1)
		{
			continue;
		}
		if (strncasecmp(tline,
				CatString3("*",module->name,0),
				module->namelen+1) == 0)
		{
			tline += (module->namelen +1);
			if (strncasecmp(tline, "Font", 4) == 0)
			{
				CopyStringWithQuotes(&font_string, &tline[4]);
			}
			else if (strncasecmp(tline, "Fore", 4) == 0)
			{
				CopyString(&ForeColor, &tline[4]);
				colorset = -1;
			}
			else if (strncasecmp(tline, "Back", 4) == 0)
			{
				CopyString(&BackColor, &tline[4]);
				colorset = -1;
			}
			else if (strncasecmp(tline, "Colorset", 8) == 0)
			{
				sscanf(&tline[8], "%d", &colorset);
				AllocColorset(colorset);
			}
			else if (strncasecmp(tline, "MinimalLayer", 12) == 0)
			{
				char *layer_str = PeekToken(&tline[12], NULL);
				if (layer_str == NULL)
				{
					minimal_layer = default_layer;
				}
				else if (sscanf(
					layer_str, "%d", &minimal_layer) != 1)
				{
					if (strncasecmp(
						layer_str, "none", 4) == 0)
					{
						minimal_layer = -1;
					}
					else
					{
						minimal_layer = default_layer;
					}
				}
			}
		}
		else if (strncasecmp(tline, "Colorset", 8) == 0)
		{
			LoadColorset(&tline[8]);
		}
		else if (strncasecmp(
			tline, XINERAMA_CONFIG_STRING,
			sizeof(XINERAMA_CONFIG_STRING) - 1) == 0)
		{
			FScreenConfigureModule(
				tline + sizeof(XINERAMA_CONFIG_STRING) - 1);
		}
		GetConfigLine(fd, &tline);
	}

	if(module->window == 0)
	{
		fvwmlib_get_target_window(
			dpy, screen, module->name, &(module->window), True);
	}

	fd_width = GetFdWidth();

	/* Create a list of all windows */
	/* Request a list of all windows,
	 * wait for ConfigureWindow packets */
	SendText(fd, "Send_WindowList", 0);

	/* tell fvwm we're running */
	SendFinishedStartupNotification(fd);
	if (module->window == Root)
	{
		exit(0);
	}

	Loop(fd);
	return 0;
}
Пример #8
0
/*********************************************************************
// Name:  TSendMail
// Input:   1) host:    Name of the mail host where the SMTP server resides
//                      max accepted length of name = 256
//          2) appname: Name of the application to use in the X-mailer
//                      field of the message. if NULL is given the application
//                      name is used as given by the GetCommandLine() function
//                      max accespted length of name = 100
// Output:  1) error:   Returns the error code if something went wrong or
//                      SUCCESS otherwise.
//
//  See SendText() for additional args!
//********************************************************************/
PHPAPI int TSendMail(char *host, int *error, char **error_message,
			  char *headers, char *Subject, char *mailTo, char *data,
			  char *mailCc, char *mailBcc, char *mailRPath)
{
	int ret;
	char *RPath = NULL;
	zend_string *headers_lc = NULL, *headers_trim = NULL; /* headers_lc is only created if we've a header at all */
	char *pos1 = NULL, *pos2 = NULL;

	if (host == NULL) {
		*error = BAD_MAIL_HOST;
		return FAILURE;
	} else if (strlen(host) >= HOST_NAME_LEN) {
		*error = BAD_MAIL_HOST;
		return FAILURE;
	} else {
		strcpy(PW32G(mail_host), host);
	}

	if (headers) {
		char *pos = NULL;

		/* Use PCRE to trim the header into the right format */
		if (NULL == (headers_trim = php_win32_mail_trim_header(headers))) {
			*error = W32_SM_PCRE_ERROR;
			return FAILURE;
		}

		/* Create a lowercased header for all the searches so we're finally case
		 * insensitive when searching for a pattern. */
		headers_lc = zend_string_tolower(headers_trim);
		if (headers_lc == headers_trim) {
			zend_string_release_ex(headers_lc, 0);
		}
	}

	/* Fall back to sendmail_from php.ini setting */
	if (mailRPath && *mailRPath) {
		RPath = estrdup(mailRPath);
	} else if (INI_STR("sendmail_from")) {
		RPath = estrdup(INI_STR("sendmail_from"));
	} else if (headers_lc) {
		int found = 0;
		char *lookup = ZSTR_VAL(headers_lc);

		while (lookup) {
			pos1 = strstr(lookup, "from:");

			if (!pos1) {
				break;
			} else if (pos1 != ZSTR_VAL(headers_lc) && *(pos1-1) != '\n') {
				if (strlen(pos1) >= sizeof("from:")) {
					lookup = pos1 + sizeof("from:");
					continue;
				} else {
					break;
				}
			}

			found = 1;

			/* Real offset is memaddress from the original headers + difference of
			 * string found in the lowercase headrs + 5 characters to jump over
			 * the from: */
			pos1 = headers + (pos1 - lookup) + 5;
			if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
				RPath = estrndup(pos1, strlen(pos1));
			} else {
				RPath = estrndup(pos1, pos2 - pos1);
			}

			break;
		}

		if (!found) {
			if (headers_lc) {
				zend_string_free(headers_lc);
			}
			*error = W32_SM_SENDMAIL_FROM_NOT_SET;
			return FAILURE;
		}
	}

	/* attempt to connect with mail host */
	*error = MailConnect();
	if (*error != 0) {
		if (RPath) {
			efree(RPath);
		}
		if (headers) {
			zend_string_free(headers_trim);
			zend_string_free(headers_lc);
		}
		/* 128 is safe here, the specifier in snprintf isn't longer than that */
		*error_message = ecalloc(1, HOST_NAME_LEN + 128);
		snprintf(*error_message, HOST_NAME_LEN + 128,
			"Failed to connect to mailserver at \"%s\" port %d, verify your \"SMTP\" "
			"and \"smtp_port\" setting in php.ini or use ini_set()",
			PW32G(mail_host), !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port"));
		return FAILURE;
	} else {
		ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers ? ZSTR_VAL(headers_trim) : NULL, headers ? ZSTR_VAL(headers_lc) : NULL, error_message);
		TSMClose();
		if (RPath) {
			efree(RPath);
		}
		if (headers) {
			zend_string_free(headers_trim);
			zend_string_free(headers_lc);
		}
		if (ret != SUCCESS) {
			*error = ret;
			return FAILURE;
		}
		return SUCCESS;
	}
}