示例#1
0
文件: button.c 项目: fvwmorg/fvwm
/**
*** MakeContainer()
*** Allocs and sets the container-specific fields of a button.
**/
void MakeContainer(button_info *b)
{
  b->c=(container_info*)mymalloc(sizeof(container_info));
  memset((void *)b->c, 0, sizeof(container_info));
  b->flags.b_Container = 1;
  if(b->parent != NULL)
  {
    if (b->parent->c->flags.b_IconBack || b->parent->c->flags.b_IconParent)
      b->c->flags.b_IconParent = 1;
    if (b->parent->c->flags.b_Colorset ||
	b->parent->c->flags.b_ColorsetParent)
      b->c->flags.b_ColorsetParent = 1;
  }
  else /* This applies to the UberButton */
  {
    b->c->flags.b_Font = 1;
    b->c->flags.b_Padding = 1;
    b->c->flags.b_Frame = 1;
    b->c->flags.b_Back = 1;
    b->c->flags.b_Fore = 1;
    b->c->font_string=safestrdup("fixed");
    b->c->xpad=2;
    b->c->ypad=4;
    b->c->back=safestrdup("rgb:90/80/90");
    b->c->fore=safestrdup("black");
    b->c->framew=2;
  }

}
示例#2
0
/*
  Example:
  filter allow localhost "/etc/tinyhost/filter"
*/
int add_new_filter(char *aclname, char *expression)
{
  static int filter_count = 1;

  /* First, add space for another pointer to the filter array. */
  config.filters =
      saferealloc(config.filters,
		  sizeof(struct filter_s *) * (filter_count + 1));
  if (!config.filters)
    return (-1);

  /* Allocate space for an actual structure */
  config.filters[filter_count - 1] = safemalloc(sizeof(struct filter_s));
  if (!config.filters[filter_count - 1])
    return (-1);

  log_message(LOG_INFO, "%s: New filter '%s' for %s", __func__, expression,
	      aclname);

  /* Set values for filters structure. */
  config.filters[filter_count - 1]->expression = safestrdup(expression);
  if (!config.filters[filter_count - 1]->expression)
    return (-1);

  config.filters[filter_count - 1]->aclname = safestrdup(aclname);
  if (!config.filters[filter_count - 1]->aclname)
    return (-1);


  /* Set NULL to denote end of array */
  config.filters[filter_count] = NULL;

  filter_count++;
  return (0);
}
示例#3
0
/* split string val into a list of str's, each containing
   an ordinary substring or a variable reference of the form $(bla).
   The list is appended to pre, the last list entry is returned.
*/
static str *
split_string (char *val, str *pre)
{
  char *s = NULL, *t = NULL;
  char *v = val;
  str *curr = pre;

  while (v && *v)
    {
      s = strstr (v, "$(");
      if (s)
	{
	  t = strstr (s, ")");
	}

      if (s && t)
	{
	  /* append the part before $( */
	  curr->next = (str *) safemalloc (sizeof (str));
	  curr = curr->next;
	  *s = '\0';
	  curr->s = safestrdup (v);
	  curr->is_var = 0;
	  *s = '$';

	  /* append the variable reference, silently omit the ) */
	  curr->next = (str *) safemalloc (sizeof (str));
	  curr = curr->next;
	  curr->next = NULL;
	  *t = '\0';
	  curr->s = safestrdup (s + 2);
	  curr->is_var = 1;
	  *t = ')';

	  v = t + 1;
	}
      else
	{
	  /* append the part after the last variable reference */
	  curr->next = (str *) safemalloc (sizeof (str));
	  curr = curr->next;
	  curr->next = NULL;
	  curr->s = safestrdup (v);
	  curr->is_var = 0;
	  v = NULL;
	}
    }
  return curr;
}
示例#4
0
/* gets called if the first ofcd rule is found */
static void filter_read_catlist(void)
{
  FILE *fd;
  char buf[FILTER_BUFFER_LEN];

  catlist_initialized = 1;

  if (!config.ofcdcategories) {
    log_message(LOG_INFO, "No category file specified");
    return;
  }

  if ((fd = fopen(config.ofcdcategories, "r"))) {
    int i = 0;
    while (i < MAX_CATEGORIES && fgets(buf, FILTER_BUFFER_LEN, fd)) {
      buf[strlen(buf) - 1] = '\0';
      if (!(catlist[i++] = safestrdup(buf))) {
	log_message(LOG_ERR, "%s: memory problem", __func__);
	goto COMMON_EXIT;
      }
    }
    catlist_initialized = 2;
    log_message(LOG_INFO, "Got %d categories from %s", i,
		config.ofcdcategories);
  } else
    log_message(LOG_INFO, "%s: Read failed %s: %m", __func__,
		config.ofcdcategories);

COMMON_EXIT:
  fclose(fd);
}
示例#5
0
std::string
iconv_charset_converter_c::convert(iconv_t handle,
                                   const std::string &source) {
  if (reinterpret_cast<iconv_t>(-1) == handle)
    return source;

  int length        = source.length() * 4;
  char *destination = (char *)safemalloc(length + 1);
  memset(destination, 0, length + 1);

  iconv(handle, NULL, 0, NULL, 0); // Reset the iconv state.

  size_t length_source      = length / 4;
  size_t length_destination = length;
  char *source_copy         = safestrdup(source.c_str());
  char *ptr_source          = source_copy;
  char *ptr_destination     = destination;
  iconv(handle, (ICONV_CONST char **)&ptr_source, &length_source, &ptr_destination, &length_destination);
  iconv(handle, NULL, NULL, &ptr_destination, &length_destination);

  safefree(source_copy);
  std::string result = destination;
  safefree(destination);

  return result;
}
示例#6
0
文件: html-error.c 项目: bowb/wabbit
/*
 * Add the error information to the conn structure.
 */
int
indicate_http_error (struct conn_s *connptr, int number,
                     const char *message, ...)
{
        va_list ap;
        char *key, *val;

        va_start (ap, message);

        while ((key = va_arg (ap, char *))) {
                val = va_arg (ap, char *);

                if (add_error_variable (connptr, key, val) == -1) {
                        va_end (ap);
                        return (-1);
                }
        }

        connptr->error_number = number;
        connptr->error_string = safestrdup (message);

        va_end (ap);

        return (add_standard_vars (connptr));
}
示例#7
0
/* Each input field has a history, depending on the passed
   direction, get the desired history item into the input field.
   After "Restart" the yank point is one entry beyond the last
   inserted item.
   Normal yanks, going backward, go down the array decrementing
   yank count before extracting.
   Forward yanks increment before extracting. */
static void process_history(int direction) {
  int count;
  if (!CF.cur_input                     /* no input fields */
      || !CF.cur_input->input.value_history_ptr) { /* or no history */
    return;                             /* bail out */
  }
  /* yankat is always one beyond slot to yank from. */
  count = CF.cur_input->input.value_history_yankat + direction;
  if (count < 0 || count >= VH_SIZE ||
	     CF.cur_input->input.value_history_ptr[count] == 0 ) {
    if (direction <= 0) {               /* going down */
      for (count = VH_SIZE - 1;
	   CF.cur_input->input.value_history_ptr[count] == 0;
	   --count);                    /* find last used slot */
    } else {                            /* going up */
      count = 0;                        /* up is the bottom */
    }
  }
  CF.cur_input->input.value =
    safestrdup(CF.cur_input->input.value_history_ptr[count]);
  CF.cur_input->input.n = strlen(CF.cur_input->input.value);
  CF.cur_input->input.value_history_yankat = count; /* new yank point */
  CF.cur_input->input.buf = CF.cur_input->input.n;
  CF.rel_cursor = 0;
  CF.abs_cursor = 0;
  CF.cur_input->input.left = 0;
  return;
}
示例#8
0
char *
recursive_replace (GtkWidget *d, char *val)
{
  str *head, *r, *tail, *next;
  char *nval;

  head = (str *) safemalloc (sizeof (str));
  head->is_var = 0;
  head->s = safestrdup("");
  head->next = NULL;

  split_string (val, head);
  for (r = head; r->next != NULL; r = r->next)
    {
      next = r->next;
      if (next->is_var)
	{
	  nval = (char *) gtk_object_get_data (GTK_OBJECT (d), next->s);
	  if (nval)
	    {
	      /* this changes r->next, thus freeing next is safe */
	      tail = split_string (nval, r);
	      tail->next = next->next;
	      free (next->s);
	      free (next);
	    }
	  else
	    {
	      next->is_var = 0;
	    }
	}
    }
  return combine_string (head);
}
示例#9
0
/* add a rule to the filter rulelist
 *
 * return the pointer of the newly created rule on success,
 * NULL otherwise
 */
static struct filter_rulelist *filter_addrule(const char *pat,
					      struct filter_rulelist **list,
					      filtertype_t type)
{
  struct filter_rulelist *p = *list;

  log_message(LOG_INFO, "%s:    Adding pattern '%d' '%s'", __func__, type, pat);

  if (!p) {			/* head of list */
    p = *list = safecalloc(1, sizeof(struct filter_rulelist));
  } else {			/* next entry */

    /* 
     * find the end of our list, this leaves room for
     * optimizations
     */
    while (p->next)
      p = p->next;

    p->next = safecalloc(1, sizeof(struct filter_rulelist));
    p = p->next;
  }

  if (p) {
    p->type = type;
    if (!(p->pat = safestrdup(pat))) {
      safefree(p);
      p = NULL;
    }
  }
  return p;
}
示例#10
0
Bool change_goody_colorset(int cset, Bool force)
{
	if (cset < 0)
	{
		return False;
	}
	if (cset == tipscolorset && Tip.win != None)
	{
		char *s;

		if (Tip.text != NULL)
		{
			s = safestrdup(Tip.text);
		}
		else
		{
			s = NULL;
		}
		PopupTipWindow(Tip.px, Tip.py, s);
		if (s != NULL)
		{
			free(s);
		}
	}
	if (!force && cset != colorset)
	{
		return False;
	}
	CreateOrUpdateGoodyGC();

	return True;
}
示例#11
0
void parseopts(int argc, char *argv[])
{
    int c;

    while((c=getopt(argc, argv, "vdf:")) != -1)	{
        switch(c)	{
        case 'd':
            _debug = 1;
            break;
        case 'v':
            _verbose = 1;
            break;
        case 'f':
            cfgfile = safestrdup(optarg, "cfgfile optarg");
            break;
        default:
            exit(2);
        }
    }
    if(cfgfile == NULL)	{
        char *home = getenv("HOME");
        if(home == NULL)
            log_exit(3, "Error: $HOME not set for default config file");
        cfgfile = safemalloc(strlen(home) + strlen(default_cfg) + 3, "malloc cfgfile");
        sprintf(cfgfile, "%s/%s", home, default_cfg);
    }
}
示例#12
0
文件: plugin.c 项目: streambag/fribid
/**
 * Stores the current parameters so they get included with the request.
 */
void regutil_initRequest(Plugin *plugin, const char *type) {
    if (!g_ascii_strcasecmp(type, "pkcs10")) {
        // Limit number of objects
        RegutilPKCS10 *other = plugin->info.regutil.input.pkcs10;
        size_t count = 0;
        for (; other; other = other->next) {
            if (++count > 10) {
                plugin->lastError = BIDERR_InternalError;
                return;
            }
        }
        
        // Add PKCS10
        RegutilPKCS10 *copy = malloc(sizeof(RegutilPKCS10));
        memcpy(copy, &plugin->info.regutil.currentPKCS10, sizeof(RegutilPKCS10));
        copy->subjectDN = safestrdup(plugin->info.regutil.currentPKCS10.subjectDN);
        
        copy->next = plugin->info.regutil.input.pkcs10;
        plugin->info.regutil.input.pkcs10 = copy;
        
        plugin->info.regutil.currentPKCS10.includeFullDN = false;
        plugin->lastError = BIDERR_OK;
    } else if (!g_ascii_strcasecmp(type, "cmc")) {
        // CMC
        RegutilCMC *cmc = &plugin->info.regutil.input.cmc;
        
        free(cmc->oneTimePassword);
        free(cmc->rfc2729cmcoid);
        cmc->oneTimePassword = safestrdup(plugin->info.regutil.currentCMC.oneTimePassword);
        cmc->rfc2729cmcoid = safestrdup(plugin->info.regutil.currentCMC.rfc2729cmcoid);
        
        plugin->lastError = BIDERR_OK;
    } else {
        plugin->lastError = RUERR_InvalidValue;
    }
}
示例#13
0
文件: Ficonv.c 项目: fvwmorg/fvwm
static
int set_default_iconv_charsets(FlocaleCharset *fc)
{
	int i=0,j=0;

	if (!FiconvSupport || FLCIconvUtf8Charset == NULL || fc == NULL)
		return False;

	while(FLC_GET_LOCALE_CHARSET(FLCIconvUtf8Charset,i) != NULL)
	{
		j = 0;
		while(FLC_GET_LOCALE_CHARSET(fc,j) != NULL)
		{
			if (is_iconv_supported(
				  FLC_GET_LOCALE_CHARSET(
					  FLCIconvUtf8Charset,i),
				  FLC_GET_LOCALE_CHARSET(fc,j)))
			{
				FLC_SET_ICONV_INDEX(FLCIconvUtf8Charset,i);
				FLC_SET_ICONV_INDEX(fc,j);

				if (is_translit_supported(
					    FLC_GET_LOCALE_CHARSET(
						    FLCIconvUtf8Charset,i),
					    FLC_GET_LOCALE_CHARSET(fc,j)))
				{
					FLC_SET_ICONV_TRANSLIT_CHARSET(
						fc, safestrdup(translit_csname(
							FLC_GET_LOCALE_CHARSET(
								fc,j))));
				} else {
					FLC_SET_ICONV_TRANSLIT_CHARSET(
						fc, FLC_TRANSLIT_NOT_SUPPORTED);
				}

				return 1;
			}
			j++;
		}
		i++;
	}
	FLC_SET_ICONV_INDEX(FLCIconvUtf8Charset,
			    FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
	FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
	return 0;
}
示例#14
0
文件: Ficonv.c 项目: fvwmorg/fvwm
static
void set_iconv_charset_index(FlocaleCharset *fc)
{
	int i = 0;

	if (!FiconvSupport || fc == NULL)
		return;

	if (FLC_DO_ICONV_CHARSET_INITIALIZED(fc))
		return; /* already set */
	if (FLCIconvUtf8Charset == NULL ||
	    !FLC_DO_ICONV_CHARSET_INITIALIZED(FLCIconvUtf8Charset))
	{
		FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
		return;
	}
	while(FLC_GET_LOCALE_CHARSET(fc,i) != NULL)
	{
		if (is_iconv_supported(
			FLC_GET_ICONV_CHARSET(FLCIconvUtf8Charset),
			FLC_GET_LOCALE_CHARSET(fc,i)))
		{
			FLC_SET_ICONV_INDEX(fc,i);
			if (is_translit_supported(
				    FLC_GET_ICONV_CHARSET(FLCIconvUtf8Charset),
				    FLC_GET_LOCALE_CHARSET(fc,i)))
			{
				FLC_SET_ICONV_TRANSLIT_CHARSET(
					fc, safestrdup(
						translit_csname(
							FLC_GET_LOCALE_CHARSET(
								fc,i))));
			} else {
				FLC_SET_ICONV_TRANSLIT_CHARSET(
					fc, FLC_TRANSLIT_NOT_SUPPORTED);
			}
			return;
		}
		i++;
	}
	FLC_SET_ICONV_INDEX(fc, FLC_INDEX_ICONV_CHARSET_NOT_FOUND);
}
示例#15
0
static const func_t *find_builtin_function(char *func)
{
	static int nfuncs = 0;
	func_t *ret_func;
	char *temp;
	char *s;

	if (!func || func[0] == 0)
	{
		return NULL;
	}

	/* since a lot of lines in a typical rc are probably menu/func
	 * continues: */
	if (func[0]=='+' || (func[0] == ' ' && func[1] == '+'))
	{
		return &(func_table[0]);
	}

	temp = safestrdup(func);
	for (s = temp; *s != 0; s++)
	{
		if (isupper(*s))
		{
			*s = tolower(*s);
		}
	}
	if (nfuncs == 0)
	{
		for ( ; (func_table[nfuncs]).action != NULL; nfuncs++)
		{
			/* nothing to do here */
		}
	}
	ret_func = (func_t *)bsearch(
		temp, func_table, nfuncs, sizeof(func_t), func_comp);
	free(temp);

	return ret_func;
}
示例#16
0
/* Duplicate a menu item into newly allocated memory.  The new item is
 * completely independent of the old one. */
struct MenuItem *menuitem_clone(struct MenuItem *mi)
{
	MenuItem *new_mi;
	int i;

	/* copy everything */
	new_mi = (MenuItem *)safemalloc(sizeof(MenuItem));
	memcpy(new_mi, mi, sizeof(MenuItem));
	/* special treatment for a few parts */
	MI_NEXT_ITEM(new_mi) = NULL;
	MI_PREV_ITEM(new_mi) = NULL;
	MI_WAS_DESELECTED(new_mi) = 0;
	if (MI_ACTION(mi) != NULL)
	{
		MI_ACTION(new_mi) = safestrdup(MI_ACTION(mi));
	}
	for (i = 0; i < MAX_MENU_ITEM_LABELS; i++)
	{
		if (MI_LABEL(mi)[i] != NULL)
		{
			MI_LABEL(new_mi)[i] = strdup(MI_LABEL(mi)[i]);
		}
	}
	if (MI_PICTURE(mi) != NULL)
	{
		MI_PICTURE(new_mi) = PCloneFvwmPicture(MI_PICTURE(mi));
	}
	for (i = 0; i < MAX_MENU_ITEM_MINI_ICONS; i++)
	{
		if (MI_MINI_ICON(mi)[i] != NULL)
		{
			MI_MINI_ICON(new_mi)[i] =
				PCloneFvwmPicture(MI_MINI_ICON(mi)[i]);
		}
	}

	return new_mi;
}
示例#17
0
/**
 * Add a mapping (local port -> remote host + port) to the gateway structure.
 *
 * Creates a listening port for the local side and adds the fd to the fd_map
 * on the gateway that maps listening ports to the map structure.
 *
 * The mappings are stored in an array of pointers gw->pm that is grown
 * appropriately and gw->n_maps stores the size of this array.
 *
 * @gw			gateway structure to add to
 * @local_port	the local port to listen on -- bound to localhost:NNNN
 * @host		the remote host to tunnel to
 * @remote_port	the port on the remote side to connect to
 * @return		Nothing, if anything fails here the program exits
 */
void add_map_to_gw(struct gw_host *gw,
				  uint32_t local_port,
				  char *host,
				  uint32_t remote_port)
{
	struct static_port_map *spm;

	debug("Adding map %d %s:%d to %s", local_port, host, remote_port, gw->name);

	spm = safemalloc(sizeof(struct static_port_map), "static_port_map alloc");
	spm->parent = gw;
	spm->local_port = local_port;
	spm->remote_host = safestrdup(host, "spm strdup hostname");
	spm->remote_port = remote_port;
	spm->ch = safemalloc(sizeof(struct chan_sock *), "spm->ch");

	spm->listen_fd = create_listen_socket(local_port, "localhost");
	add_fdmap(gw->listen_fdmap, spm->listen_fd, spm);
	spm->parent = gw;
	spm->n_channels = 0;

	saferealloc((void **)&gw->pm, (gw->n_maps + 1) * sizeof(spm), "gw->pm realloc");
	gw->pm[gw->n_maps++] = spm;
}
示例#18
0
/*
 * Initializes a linked list of strings containing hosts/urls to be filtered
 */
void filter_init(void)
{
  struct filter_list *p = NULL, *q;
  struct filter_s *f;

  if (!config.filters) {
    filterlist_initialized = 1;
    return;
  }

  if (!fl && !filterlist_initialized) {
    int i = 0;
    while ((f = config.filters[i++])) {

      /* are there already rules for this acl? */
      if (!(q = filter_get(f->aclname))) {

	log_message(LOG_INFO, "%s: New Filter for %s", __func__, f->aclname);

	if (!p) {		/* head of list */
	  p = fl = safecalloc(1, sizeof(struct filter_list));
	} else {		/* next entry */
	  p->next = safecalloc(1, sizeof(struct filter_list));
	  p = p->next;
	}
	p->aclname = safestrdup(f->aclname);
	q = p;
      } else {
	log_message(LOG_INFO, "%s: Found Filter for %s", __func__, f->aclname);
      }

      filter_read(f->expression, &q->rules);
    }
    filterlist_initialized = 1;
  }
}
示例#19
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;
}
示例#20
0
文件: reqs.c 项目: OPSF/uClinux
/*
 * Add an entry to the upstream list
 */
void
upstream_add(const char *host, int port, const char *domain)
{
	char *ptr;
	struct upstream *up = safemalloc(sizeof (struct upstream));

	if (!up) {
		log_message(LOG_ERR, "Unable to allocate memory in upstream_add()");
		return;
	}

	up->host = up->domain = NULL;
	up->ip = up->mask = 0;

	if (domain == NULL) {
		if (!host || host[0] == '\0' || port < 1) {
			log_message(LOG_WARNING, "Nonsense upstream rule: invalid host or port");
			goto upstream_cleanup;
		}

		up->host = safestrdup(host);
		up->port = port;

		log_message(LOG_INFO, "Added upstream %s:%d for [default]", host, port);
	} else if (host == NULL) {
		if (!domain || domain[0] == '\0') {
			log_message(LOG_WARNING, "Nonsense no-upstream rule: empty domain");
			goto upstream_cleanup;
		}

		ptr = strchr(domain, '/');
		if (ptr) {
			struct in_addr addrstruct;

			*ptr = '\0';
			if (inet_aton(domain, &addrstruct) != 0) {
				up->ip = ntohl(addrstruct.s_addr);
				*ptr++ = '/';

				if (strchr(ptr, '.')) {
					if (inet_aton(ptr, &addrstruct) != 0)
						up->mask = ntohl(addrstruct.s_addr);
				} else {
					up->mask = ~((1 << (32 - atoi(ptr))) - 1);
				}
			}
		} else {
			up->domain = safestrdup(domain);
		}

		log_message(LOG_INFO, "Added no-upstream for %s", domain);
	} else {
		if (!host || host[0] == '\0' || port < 1 || !domain || domain == '\0') {
			log_message(LOG_WARNING, "Nonsense upstream rule: invalid parameters");
			goto upstream_cleanup;
		}

		up->host = safestrdup(host);
		up->port = port;
		up->domain = safestrdup(domain);

		log_message(LOG_INFO, "Added upstream %s:%d for %s",
			    host, port, domain);
	}

	if (!up->domain && !up->ip) { /* always add default to end */
		struct upstream *tmp = config.upstream_list;

		while (tmp) {
			if (!tmp->domain && !tmp->ip) {
				log_message(LOG_WARNING,
					    "Duplicate default upstream");
				goto upstream_cleanup;
			}

			if (!tmp->next) {
				up->next = NULL;
				tmp->next = up;
				return;
			}

			tmp = tmp->next;
		}
	}

	up->next = config.upstream_list;
	config.upstream_list = up;

	return;

      upstream_cleanup:
	safefree(up->host);
	safefree(up->domain);
	safefree(up);

	return;
}
示例#21
0
文件: FvwmPager.c 项目: att/uwin
/***********************************************************************
 *
 *  Procedure:
 *	main - start of module
 *
 ***********************************************************************/
int main(int argc, char **argv)
{
  char *display_name = NULL;
  int itemp,i;
  char line[100];
  short opt_num;
  Window JunkRoot, JunkChild;
  int JunkX, JunkY;
  unsigned JunkMask;

#ifdef I18N_MB
  setlocale(LC_CTYPE, "");
#endif
  /* Save our program  name - for error messages */
  MyName = GetFileNameFromPath(argv[0]);

  if(argc  < 6)
    {
      fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
	      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] = atoi(argv[1]);
  fd[1] = atoi(argv[2]);

  fd_width = GetFdWidth();

  opt_num = 6;
  if (argc >= 7 && (StrEquals(argv[opt_num], "-transient") ||
		    StrEquals(argv[opt_num], "transient")))
  {
    opt_num++;
    is_transient = True;
      do_ignore_next_button_release = True;
  }

  /* Check for an alias */
  if (argc >= opt_num + 1)
    {
      char *s;

      if (!StrEquals(argv[opt_num], "*"))
      {
	for (s = argv[opt_num]; *s; s++)
	{
	  if (!isdigit(*s) &&
	      (*s != '-' || s != argv[opt_num] || *(s+1) == 0))
	  {
	    free(MyName);
	    MyName=safestrdup(argv[opt_num]);
	    opt_num++;
	    break;
	  }
	}
      }
    }

  if (argc < opt_num + 1)
    {
      desk1 = Scr.CurrentDesk;
      desk2 = Scr.CurrentDesk;
    }
  else if (StrEquals(argv[opt_num], "*"))
    {
      desk1 = Scr.CurrentDesk;
      desk2 = Scr.CurrentDesk;
      fAlwaysCurrentDesk = 1;
    }
  else
    {
      desk1 = atoi(argv[opt_num]);
      if (argc == opt_num+1)
	desk2 = desk1;
      else
	desk2 = atoi(argv[opt_num+1]);
      if(desk2 < desk1)
	{
	  itemp = desk1;
	  desk1 = desk2;
	  desk2 = itemp;
	}
    }
  ndesks = desk2 - desk1 + 1;

  Desks = (DeskInfo *)safemalloc(ndesks*sizeof(DeskInfo));
  memset(Desks, 0, ndesks * sizeof(DeskInfo));
  for(i=0;i<ndesks;i++)
    {
      sprintf(line,"Desk %d",i+desk1);
      CopyString(&Desks[i].label,line);
      Desks[i].colorset = -1;
      Desks[i].highcolorset = -1;
      Desks[i].ballooncolorset = -1;
    }

  /* Initialize X connection */
  if (!(dpy = XOpenDisplay(display_name)))
    {
      fprintf(stderr,"%s: can't open display %s", MyName,
	      XDisplayName(display_name));
      exit (1);
    }
  x_fd = XConnectionNumber(dpy);
  InitPictureCMap(dpy);
  FScreenInit(dpy);
  AllocColorset(0);
  FShapeInit(dpy);

  Scr.screen = DefaultScreen(dpy);
  Scr.Root = RootWindow(dpy, Scr.screen);
  /* make a temp window for any pixmaps, deleted later */
  initialize_viz_pager();

#ifdef DEBUG
  fprintf(stderr,"[main]: Connection to X server established.\n");
#endif

  SetMessageMask(fd,
                 M_ADD_WINDOW|
                 M_CONFIGURE_WINDOW|
                 M_DESTROY_WINDOW|
                 M_FOCUS_CHANGE|
                 M_NEW_PAGE|
                 M_NEW_DESK|
                 M_RAISE_WINDOW|
                 M_LOWER_WINDOW|
                 M_ICONIFY|
		 M_ICON_LOCATION|
		 M_DEICONIFY|
		 M_RES_NAME|
		 M_RES_CLASS|
		 M_WINDOW_NAME|
		 M_ICON_NAME|
		 M_CONFIG_INFO|
		 M_END_CONFIG_INFO|
		 M_MINI_ICON|
		 M_END_WINDOWLIST|
		 M_RESTACK);
#ifdef DEBUG
  fprintf(stderr,"[main]: calling ParseOptions\n");
#endif
  ParseOptions();
  if (is_transient)
    {
      XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,
		    &window_x, &window_y, &JunkX, &JunkY, &JunkMask);
      usposition = 1;
      xneg = 0;
      yneg = 0;
    }
#ifdef DEBUG
  fprintf(stderr,
	  "[main]: back from calling ParseOptions, calling init pager\n");
#endif

  if (PagerFore == NULL)
    PagerFore = safestrdup("black");

  if (PagerBack == NULL)
    PagerBack = safestrdup("white");

  if (HilightC == NULL)
    HilightC = safestrdup(PagerFore);

  if (WindowLabelFormat == NULL)
    WindowLabelFormat = safestrdup("%i");

  if (font_string == NULL)
    font_string = safestrdup("fixed");

  if ((HilightC == NULL) && (HilightPixmap == NULL))
    HilightDesks = 0;

  if (BalloonFont == NULL)
    BalloonFont = safestrdup("fixed");

  if (BalloonBorderColor == NULL)
    BalloonBorderColor = safestrdup("black");

  if (BalloonTypeString == NULL)
    BalloonTypeString = safestrdup("%i");

  if (BalloonFormatString == NULL)
    BalloonFormatString = safestrdup("%i");

  /* open a pager window */
  initialize_pager();
#ifdef DEBUG
  fprintf(stderr,"[main]: back from init pager, getting window list\n");
#endif

  /* Create a list of all windows */
  /* Request a list of all windows,
   * wait for ConfigureWindow packets */
  SendInfo(fd,"Send_WindowList",0);
#ifdef DEBUG
  fprintf(stderr,"[main]: back from getting window list, looping\n");
#endif

  if (is_transient)
  {
    Bool is_pointer_grabbed = False;
    Bool is_keyboard_grabbed = False;
    XSync(dpy,0);
    for (i = 0; i < 50 && !(is_pointer_grabbed && is_keyboard_grabbed); i++)
    {
      if (!is_pointer_grabbed &&
	  XGrabPointer(
	    dpy, Scr.Root, True,
	    ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|
	    PointerMotionMask|EnterWindowMask|LeaveWindowMask, GrabModeAsync,
	    GrabModeAsync, None, None, CurrentTime) == GrabSuccess)
      {
	is_pointer_grabbed = True;
      }
      if (!is_keyboard_grabbed &&
	  XGrabKeyboard(
	    dpy, Scr.Root, True, GrabModeAsync, GrabModeAsync, CurrentTime) ==
	  GrabSuccess)
      {
	is_keyboard_grabbed = True;
      }
      /* If you go too fast, other windows may not get a change to release
       * any grab that they have. */
      usleep(20000);
    }
    if (!is_pointer_grabbed)
    {
      XBell(dpy, 0);
      fprintf(stderr,
	      "%s: could not grab pointer in transient mode. exiting.\n",
	      MyName);
      exit(1);
    }

    XSync(dpy,0);
  }

  /* tell fvwm we're running */
  SendFinishedStartupNotification(fd);

  Loop(fd);
#ifdef DEBUG
  if (debug_term_signal)
  {
    fprintf(stderr,"[main]: Terminated due to signal %d\n",
                   debug_term_signal);
  }
#endif
  return 0;
}
示例#22
0
/*
 *
 *  Procedure:
 *      main - start of module
 *
 */
int
main(int argc, char **argv)
{
	/* The struct holding the module info */
	static ModuleArgs* module;
	char *enter_fn="Silent Raise";        /* default */
	char *leave_fn=NULL;
	char *buf;
	int len;
	unsigned long m_mask;
	unsigned long mx_mask;
	unsigned long last_win = 0;   /* last window handled */
	unsigned long focus_win = 0;  /* current focus */
	unsigned long raised_win = 0;
	fd_set_size_t fd_width;
	int fd[2];
	int timeout;
	int sec = 0;
	int usec = 0;
	int n;
	struct timeval value;
	struct timeval *delay;
	fd_set in_fdset;
	Bool do_pass_id = False;
	Bool use_enter_mode = False;
	Bool use_leave_mode = False;
#ifdef DEBUG
	int count = 0;
#endif

#ifdef DEBUGTOFILE
	freopen(".FvwmAutoDebug","w",stderr);
#endif

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


	if (module->user_argc < 1 || module->user_argc > 5)
	{
		fprintf(stderr,"FvwmAuto can use one to five arguments.\n");
		exit(1);
	}

	/* Dead pipes mean fvwm died */
#ifdef HAVE_SIGACTION
	{
		struct sigaction  sigact;

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

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

	signal(SIGPIPE, TerminateHandler);
	signal(SIGINT,  TerminateHandler);
	signal(SIGHUP,  TerminateHandler);
	signal(SIGQUIT, TerminateHandler);
	signal(SIGTERM, TerminateHandler);
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(SIGPIPE, 0);
	siginterrupt(SIGINT, 0);
	siginterrupt(SIGHUP, 0);
	siginterrupt(SIGQUIT, 0);
	siginterrupt(SIGTERM, 0);
#endif
#endif

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

	if ((timeout = atoi(module->user_argv[0]) ))
	{
		sec = timeout / 1000;
		usec = (timeout % 1000) * 1000;
	}
	else
	{
		sec = 0;
		usec = 1000;
	}
	delay = &value;

	n = 1;
	if (n < module->user_argc && module->user_argv[n])
	{
		char *token;

		/* -passid option */
		if (n < module->user_argc && *module->user_argv[n] && StrEquals(module->user_argv[n], "-passid"))
		{
			do_pass_id = True;
			n++;
		}
		if (n < module->user_argc && *module->user_argv[n] && StrEquals(module->user_argv[n], "-menterleave"))
		{
			/* enterleave mode */
			use_leave_mode = True;
			use_enter_mode = True;
			n++;
		}
		else if (n < module->user_argc && *module->user_argv[n] && StrEquals(module->user_argv[n], "-menter"))
		{
			/* enter mode */
			use_leave_mode = False;
			use_enter_mode = True;
			n++;
		}
		else if (n < module->user_argc && *module->user_argv[n] && StrEquals(module->user_argv[n], "-mfocus"))
		{
			/* focus mode */
			use_leave_mode = False;
			use_enter_mode = False;
			n++;
		}
		/*** enter command ***/
		if (n < module->user_argc && *module->user_argv[n] && StrEquals(module->user_argv[n], "Nop"))
		{
			/* nop */
			enter_fn = NULL;
			n++;
		}
		else if (n < module->user_argc)
		{
			/* override default */
			enter_fn = module->user_argv[n];
			n++;
		}
		/* This is a hack to prevent user interaction with old configs.
		 */
		if (enter_fn)
		{
			token = PeekToken(enter_fn, NULL);
			if (!StrEquals(token, "Silent"))
			{
				enter_fn = safestrdup(
					CatString2("Silent ", enter_fn));
			}
		}
		/*** leave command ***/
		if (n < module->user_argc && module->user_argv[n] && *module->user_argv[n] &&
		    StrEquals(module->user_argv[n], "Nop"))
		{
			/* nop */
			leave_fn = NULL;
			n++;
		}
		else if (n < module->user_argc)
		{
			/* leave function specified */
			leave_fn=module->user_argv[n];
			n++;
		}
		if (leave_fn)
		{
			token = PeekToken(leave_fn, NULL);
			if (!StrEquals(token, "Silent"))
			{
				leave_fn = safestrdup(
					CatString2("Silent ", leave_fn));
			}
		}
	}

	/* Exit if nothing to do. */
	if (!enter_fn && !leave_fn)
	{
		return -1;
	}

	if (use_enter_mode)
	{
		m_mask = 0;
		mx_mask = MX_ENTER_WINDOW | MX_LEAVE_WINDOW | M_EXTENDED_MSG;
	}
	else
	{
		mx_mask = M_EXTENDED_MSG;
		m_mask = M_FOCUS_CHANGE;
	}
	/* Disable special raise/lower support on general actions. *
	 * This works as expected in most of cases. */
	if (matchWildcards("*Raise*", CatString2(enter_fn, leave_fn)) ||
	    matchWildcards("*Lower*", CatString2(enter_fn, leave_fn)))
	{
		m_mask |= M_RAISE_WINDOW | M_LOWER_WINDOW;
	}

	/* migo (04/May/2000): It is simply incorrect to listen to raise/lower
	 * packets and change the state if the action itself has no raise/lower.
	 * Detecting whether to listen or not by the action name is good enough.
	 m_mask = M_FOCUS_CHANGE | M_RAISE_WINDOW | M_LOWER_WINDOW;
	*/

	SetMessageMask(fd, m_mask);
	SetMessageMask(fd, mx_mask);
	/* tell fvwm we're running */
	SendFinishedStartupNotification(fd);
	/* tell fvwm that we want to be lock on send */
	SetSyncMask(fd, m_mask);
	SetSyncMask(fd, mx_mask);

	fd_width = fd[1] + 1;
	FD_ZERO(&in_fdset);

	/* create the command buffer */
	len = 0;
	if (enter_fn != 0)
	{
		len = strlen(enter_fn);
	}
	if (leave_fn != NULL)
	{
		len = max(len, strlen(leave_fn));
	}
	if (do_pass_id)
	{
		len += 32;
	}
	buf = safemalloc(len);

	while (!isTerminated)
	{
		char raise_window_now;
		static char have_new_window = 0;

		FD_SET(fd[1], &in_fdset);

		myfprintf(
			(stderr, "\nstart %d (hnw = %d, usec = %d)\n", count++,
			 have_new_window, usec));
		/* fill in struct - modified by select() */
		delay->tv_sec = sec;
		delay->tv_usec = usec;
#ifdef DEBUG
		{
			char tmp[32];

			sprintf(tmp, "%d usecs", (delay) ?
				(int)delay->tv_usec : -1);
			myfprintf((stderr, "select: delay = %s\n",
				   (have_new_window) ? tmp : "infinite" ));
		}
#endif
		if (fvwmSelect(fd_width, &in_fdset, NULL, NULL,
			       (have_new_window) ? delay : NULL) == -1)
		{
			myfprintf(
				(stderr, "select: error! (%s)\n",
				 strerror(errno)));
			break;
		}

		raise_window_now = 0;
		if (FD_ISSET(fd[1], &in_fdset))
		{
			FvwmPacket *packet = ReadFvwmPacket(fd[1]);

			if (packet == NULL)
			{
				myfprintf(
					(stderr,
					 "Leaving because of null packet\n"));
				break;
			}

			myfprintf(
				(stderr,
				 "pw = 0x%x, fw=0x%x, rw = 0x%x, lw=0x%x\n",
				 (int)packet->body[0], (int)focus_win,
				 (int)raised_win, (int)last_win));

			switch (packet->type)
			{
			case MX_ENTER_WINDOW:
				focus_win = packet->body[0];
				if (focus_win != raised_win)
				{
					myfprintf((stderr,
						   "entered new window\n"));
					have_new_window = 1;
					raise_window_now = 0;
				}
				else if (focus_win == last_win)
				{
					have_new_window = 0;
				}
				else
				{
					myfprintf((stderr,
						   "entered other window\n"));
				}
				break;

			case MX_LEAVE_WINDOW:
				if (use_leave_mode)
				{
					if (focus_win == raised_win)
					{
						focus_win = 0;
					}
					myfprintf((stderr,
						   "left raised window\n"));
					have_new_window = 1;
					raise_window_now = 0;
				}
				break;

			case M_FOCUS_CHANGE:
				/* it's a focus package */
				focus_win = packet->body[0];
				if (focus_win != raised_win)
				{
					myfprintf((stderr,
						   "focus on new window\n"));
					have_new_window = 1;
					raise_window_now = 0;
				}
				else
				{
					myfprintf((stderr,
						   "focus on old window\n"));
				}
				break;

			case M_RAISE_WINDOW:
				myfprintf(
					(stderr, "raise packet 0x%x\n",
					 (int)packet->body[0]));
				raised_win = packet->body[0];
				if (have_new_window && focus_win == raised_win)
				{
					myfprintf(
						(stderr, "its the old window:"
						 " don't raise\n"));
					have_new_window = 0;
				}
				break;

			case M_LOWER_WINDOW:
				myfprintf(
					(stderr, "lower packet 0x%x\n",
					 (int)packet->body[0]));
				if (have_new_window &&
				    focus_win == packet->body[0])
				{
					myfprintf(
						(stderr,
						 "window was explicitly"
						 " lowered, don't raise it"
						 " again\n"));
					have_new_window = 0;
				}
				break;
			} /* switch */
			SendUnlockNotification(fd);
		}
		else
		{
			if (have_new_window)
			{
				myfprintf((stderr, "must raise now\n"));
				raise_window_now = 1;
			}
		}

		if (raise_window_now)
		{
			myfprintf((stderr, "raising 0x%x\n", (int)focus_win));

			if (leave_fn &&
			    ((last_win && !use_leave_mode) ||
			     (raised_win && use_enter_mode)))
			{
				/* if focus_win isn't the root */
				if (do_pass_id)
				{
					sprintf(buf, "%s 0x%x\n", leave_fn,
						(int)last_win);
				}
				else
				{
					sprintf(buf, "%s\n", leave_fn);
				}
				SendInfo(fd, buf, last_win);
				if (use_enter_mode)
				{
					raised_win = 0;
				}
			}

			if (focus_win && enter_fn)
			{
				/* if focus_win isn't the root */
				if (do_pass_id)
				{
					sprintf(buf, "%s 0x%x\n", enter_fn,
						(int)focus_win);
				}
				else
				{
					sprintf(buf, "%s\n", enter_fn);
				}
				SendInfo(fd, buf, focus_win);
				raised_win = focus_win;
			}
			else if (focus_win && enter_fn == NULL)
			{
				raised_win = focus_win;
			}
			/* force fvwm to synchronise on slow X connections to
			 * avoid a race condition.  Still possible, but much
			 * less likely. */
			SendInfo(fd, "XSync", focus_win);

			/* switch to wait mode again */
			last_win = focus_win;
			have_new_window = 0;
		}
	} /* while */

	return 0;
}
示例#23
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;
}
示例#24
0
/*
 * Inserts a new access control into the list. The function will figure out
 * whether the location is an IP address (with optional netmask) or a
 * domain name.
 *
 * Returns:
 *    -1 on failure
 *     0 otherwise.
 */
int
insert_acl(char *location, acl_access_t access_type)
{
	size_t i;
	struct acl_s **rev_acl_ptr, *acl_ptr, *new_acl_ptr;
	char *nptr;

	assert(location != NULL);

	/*
	 * First check to see if the location is a string or numeric.
	 */
	for (i = 0; location[i] != '\0'; i++) {
		/*
		 * Numeric strings can not contain letters, so test on it.
		 */
		if (isalpha((unsigned char) location[i])) {
			break;
		}
	}

	/*
	 * Add a new ACL to the list.
	 */
	rev_acl_ptr = &access_list;
	acl_ptr = access_list;
	while (acl_ptr) {
		rev_acl_ptr = &acl_ptr->next;
		acl_ptr = acl_ptr->next;
	}
	new_acl_ptr = (struct acl_s*)safemalloc(sizeof(struct acl_s));
	if (!new_acl_ptr) {
		return -1;
	}

	new_acl_ptr->acl_access = access_type;

	if (location[i] == '\0') {
		DEBUG2("ACL \"%s\" is a number.", location);

		/*
		 * We did not break early, so this a numeric location.
		 * Check for a netmask.
		 */
		new_acl_ptr->type = ACL_NUMERIC;
		nptr = strchr(location, '/');
		if (nptr) {
			*nptr++ = '\0';

			new_acl_ptr->netmask = strtol(nptr, NULL, 10);
			if (new_acl_ptr->netmask < 0
			    || new_acl_ptr->netmask > 32) {
				safefree(new_acl_ptr);
				return -1;
			}
		} else {
			new_acl_ptr->netmask = 32;
		}
	} else {
		DEBUG2("ACL \"%s\" is a string.", location);

		new_acl_ptr->type = ACL_STRING;
		new_acl_ptr->netmask = 32;
	}

	new_acl_ptr->location = safestrdup(location);
	if (!new_acl_ptr->location) {
		safefree(new_acl_ptr);
		return -1;
	}

	*rev_acl_ptr = new_acl_ptr;
	new_acl_ptr->next = acl_ptr;

	return 0;
}
示例#25
0
static void execute_complex_function(
	cond_rc_t *cond_rc, const exec_context_t *exc, char *action,
	Bool *desperate, Bool has_ref_window_moved)
{
	cond_rc_t tmp_rc;
	cfunc_action_t type = CF_MOTION;
	char c;
	FunctionItem *fi;
	Bool Persist = False;
	Bool HaveDoubleClick = False;
	Bool HaveHold = False;
	Bool NeedsTarget = False;
	Bool ImmediateNeedsTarget = False;
	int do_allow_unmanaged = FUNC_ALLOW_UNMANAGED;
	int do_allow_unmanaged_immediate = FUNC_ALLOW_UNMANAGED;
	char *arguments[11], *taction;
	char *func_name;
	int x, y ,i;
	XEvent d;
	FvwmFunction *func;
	static int depth = 0;
	const exec_context_t *exc2;
	exec_context_changes_t ecc;
	exec_context_change_mask_t mask;
	int trigger_evtype;
	int button;
	XEvent *te;

	if (cond_rc == NULL)
	{
		condrc_init(&tmp_rc);
		cond_rc = &tmp_rc;
	}
	cond_rc->rc = COND_RC_OK;
	mask = 0;
	d.type = 0;
	ecc.w.fw = exc->w.fw;
	ecc.w.w = exc->w.w;
	ecc.w.wcontext = exc->w.wcontext;
	/* find_complex_function expects a token, not just a quoted string */
	func_name = PeekToken(action, &taction);
	if (!func_name)
	{
		return;
	}
	func = find_complex_function(func_name);
	if (func == NULL)
	{
		if (*desperate == 0)
		{
			fvwm_msg(
				ERR, "ComplexFunction", "No such function %s",
				action);
		}
		return;
	}
	if (!depth)
	{
		Scr.flags.is_executing_complex_function = 1;
	}
	depth++;
	*desperate = 0;
	/* duplicate the whole argument list for use as '$*' */
	if (taction)
	{
		arguments[0] = safestrdup(taction);
		/* strip trailing newline */
		if (arguments[0][0])
		{
			int l= strlen(arguments[0]);

			if (arguments[0][l - 1] == '\n')
			{
				arguments[0][l - 1] = 0;
			}
		}
		/* Get the argument list */
		for (i = 1; i < 11; i++)
		{
			taction = GetNextToken(taction, &arguments[i]);
		}
	}
	else
	{
		for (i = 0; i < 11; i++)
		{
			arguments[i] = NULL;
		}
	}
	/* In case we want to perform an action on a button press, we
	 * need to fool other routines */
	te = exc->x.elast;
	if (te->type == ButtonPress)
	{
		trigger_evtype = ButtonRelease;
	}
	else
	{
		trigger_evtype = te->type;
	}
	func->use_depth++;

	for (fi = func->first_item; fi != NULL; fi = fi->next_item)
	{
		if (fi->flags & FUNC_NEEDS_WINDOW)
		{
			NeedsTarget = True;
			do_allow_unmanaged &= fi->flags;
			if (fi->condition == CF_IMMEDIATE)
			{
				do_allow_unmanaged_immediate &= fi->flags;
				ImmediateNeedsTarget = True;
				break;
			}
		}
	}

	if (ImmediateNeedsTarget)
	{
		if (DeferExecution(
			    &ecc, &mask, CRS_SELECT, trigger_evtype,
			    do_allow_unmanaged_immediate))
		{
			func->use_depth--;
			__cf_cleanup(&depth, arguments, cond_rc);
			return;
		}
		NeedsTarget = False;
	}
	else
	{
		ecc.w.w = (ecc.w.fw) ? FW_W_FRAME(ecc.w.fw) : None;
		mask |= ECC_W;
	}

	/* we have to grab buttons before executing immediate actions because
	 * these actions can move the window away from the pointer so that a
	 * button release would go to the application below. */
	if (!GrabEm(CRS_NONE, GRAB_NORMAL))
	{
		func->use_depth--;
		fvwm_msg(
			ERR,
			"ComplexFunction", "Grab failed in function %s,"
			" unable to execute immediate action", action);
		__cf_cleanup(&depth, arguments, cond_rc);
		return;
	}
	exc2 = exc_clone_context(exc, &ecc, mask);
	__run_complex_function_items(
		cond_rc, CF_IMMEDIATE, func, exc2, arguments,
		has_ref_window_moved);
	exc_destroy_context(exc2);
	for (fi = func->first_item;
	     fi != NULL && cond_rc->break_levels == 0;
	     fi = fi->next_item)
	{
		/* c is already lowercase here */
		c = fi->condition;
		switch (c)
		{
		case CF_IMMEDIATE:
			break;
		case CF_DOUBLE_CLICK:
			HaveDoubleClick = True;
			Persist = True;
			break;
		case CF_HOLD:
			HaveHold = True;
			Persist = True;
			break;
		default:
			Persist = True;
			break;
		}
	}

	if (!Persist || cond_rc->break_levels != 0)
	{
		func->use_depth--;
		__cf_cleanup(&depth, arguments, cond_rc);
		UngrabEm(GRAB_NORMAL);
		return;
	}

	/* Only defer execution if there is a possibility of needing
	 * a window to operate on */
	if (NeedsTarget)
	{
		if (DeferExecution(
			    &ecc, &mask, CRS_SELECT, trigger_evtype,
			    do_allow_unmanaged))
		{
			func->use_depth--;
			__cf_cleanup(&depth, arguments, cond_rc);
			UngrabEm(GRAB_NORMAL);
			return;
		}
	}

	te = (mask & ECC_ETRIGGER) ? ecc.x.etrigger : exc->x.elast;
	switch (te->xany.type)
	{
	case ButtonPress:
	case ButtonRelease:
		x = te->xbutton.x_root;
		y = te->xbutton.y_root;
		button = te->xbutton.button;
		/* Take the click which started this fuction off the
		 * Event queue.  -DDN- Dan D Niles [email protected] */
		FCheckMaskEvent(dpy, ButtonPressMask, &d);
		break;
	default:
		if (FQueryPointer(
			    dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y,
			    &JunkX, &JunkY, &JunkMask) == False)
		{
			/* pointer is on a different screen */
			x = 0;
			y = 0;
		}
		button = 0;
		break;
	}

	/* Wait and see if we have a click, or a move */
	/* wait forever, see if the user releases the button */
	type = CheckActionType(x, y, &d, HaveHold, True, &button);
	if (type == CF_CLICK)
	{
		int button2;

		/* If it was a click, wait to see if its a double click */
		if (HaveDoubleClick)
		{
			type = CheckActionType(
				x, y, &d, True, False, &button2);
			switch (type)
			{
			case CF_HOLD:
			case CF_MOTION:
			case CF_CLICK:
				if (button == button2)
				{
					type = CF_DOUBLE_CLICK;
				}
				else
				{
					type = CF_CLICK;
				}
				break;
			case CF_TIMEOUT:
				type = CF_CLICK;
				break;
			default:
				/* can't happen */
				break;
			}
		}
	}
	else if (type == CF_TIMEOUT)
	{
		type = CF_HOLD;
	}

	/* some functions operate on button release instead of presses. These
	 * gets really weird for complex functions ... */
	if (d.type == ButtonPress)
	{
		d.type = ButtonRelease;
		if (d.xbutton.button > 0 &&
		    d.xbutton.button <= NUMBER_OF_MOUSE_BUTTONS)
		{
			d.xbutton.state &=
				(~(Button1Mask >> (d.xbutton.button - 1)));
		}
示例#26
0
文件: conns.c 项目: OPSF/uClinux
struct conn_s *
initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
{
	struct conn_s *connptr;
	struct buffer_s *cbuffer, *sbuffer;

	assert(client_fd >= 0);

	/*
	 * Allocate the memory for all the internal components
	 */
	cbuffer = new_buffer();
	sbuffer = new_buffer();

	if (!cbuffer || !sbuffer)
		goto error_exit;

	/*
	 * Allocate the space for the conn_s structure itself.
	 */
	connptr = safemalloc(sizeof(struct conn_s));
	if (!connptr)
		goto error_exit;

	connptr->client_fd = client_fd;
	connptr->server_fd = -1;

	connptr->cbuffer = cbuffer;
	connptr->sbuffer = sbuffer;

	connptr->request_line = NULL;

	/* These store any error strings */
	connptr->error_variables = NULL;
	connptr->error_variable_count = 0;
	connptr->error_string = NULL;
	connptr->error_number = -1;

	connptr->connect_method = FALSE;
	connptr->show_stats = FALSE;

	connptr->protocol.major = connptr->protocol.minor = 0;

	/* There is _no_ content length initially */
	connptr->content_length.server = connptr->content_length.client = -1;

	connptr->client_ip_addr = safestrdup(ipaddr);
	connptr->client_string_addr = safestrdup(string_addr);

	connptr->upstream_proxy = NULL;

	update_stats(STAT_OPEN);

	return connptr;

error_exit:
	/*
	 * If we got here, there was a problem allocating memory
	 */
	if (cbuffer)
		delete_buffer(cbuffer);
	if (sbuffer)
		delete_buffer(sbuffer);

	return NULL;
}
示例#27
0
文件: filter.c 项目: eausky/tinyproxy
/*
 * Initializes a linked list of strings containing hosts/urls to be filtered
 */
void
filter_init(void)
{
	FILE *fd;
	struct filter_list *p;
	char buf[FILTER_BUFFER_LEN];
	char *s;
	int cflags;

	if (!fl && !already_init) {
		fd = fopen(config.filter, "r");
		if (fd) {
			p = NULL;

			cflags = REG_NEWLINE | REG_NOSUB;
			if (config.filter_extended)
				cflags |= REG_EXTENDED;
			if (!config.filter_casesensitive)
				cflags |= REG_ICASE;

			while (fgets(buf, FILTER_BUFFER_LEN, fd)) {
				/*
				 * Remove any trailing white space and
				 * comments.
				 */
				s = buf;
				while (*s) {
					if (isspace((unsigned char)*s)) break;
					if (*s == '#') {
						/*
						 * If the '#' char is preceeded by
						 * an escape, it's not a comment
						 * string.
						 */
						if (s == buf || *(s - 1) != '\\')
							break;
					}
					++s;
				}
				*s = '\0';

				/* skip leading whitespace */
				s = buf;
				while (*s && isspace((unsigned char)*s))
					s++;

				/* skip blank lines and comments */
				if (*s == '\0')
					continue;

				if (!p)	/* head of list */
					fl = p =
					    safecalloc(1,
						       sizeof(struct
							      filter_list));
				else {	/* next entry */
					p->next =
					    safecalloc(1,
						       sizeof(struct
							      filter_list));
					p = p->next;
				}

				p->pat = safestrdup(s);
				p->cpat = safemalloc(sizeof(regex_t));
				if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {
					fprintf(stderr, "Bad regex in %s: %s\n",
						config.filter, p->pat);
					exit(EX_DATAERR);
				}
			}
			if (ferror(fd)) {
				perror("fgets");
				exit(EX_DATAERR);
			}
			fclose(fd);

			already_init = 1;
		}
	}
}
示例#28
0
/*
 * Change by PRB ([email protected]), 31/10/93.  Prepend a hot key
 * specifier to each item in the list.  This means allocating the
 * memory for each item (& freeing it) rather than just using the window
 * title directly. */
void CMD_WindowList(F_CMD_ARGS)
{
	struct MenuRoot *mr;
	struct MenuParameters mp;
	char* ret_action = NULL;
	FvwmWindow *t;
	FvwmWindow **windowList;
	FvwmWindow **iconifiedList = NULL;
	int numWindows;
	int ii;
	char tname[128];
	char loc[64];
	char *name=NULL;
	Bool free_name = False;
	int dwidth;
	int dheight;
	char *tlabel;
	int last_desk_done = INT_MIN;
	int last_desk_displayed = INT_MIN;
	int next_desk = 0;
	char *t_hot=NULL;             /* Menu label with hotkey added */
	char scut = '0';              /* Current short cut key */
	char *opts=NULL;
	char *tok=NULL;
	int desk = Scr.CurrentDesk;
	unsigned long flags = SHOW_DEFAULT;
	char *func = NULL;
	char *ffunc = NULL;
	char *tfunc = NULL;
	char *default_action = NULL;
	MenuReturn mret;
	MenuOptions mops;
	int low_layer = 0;  /* show all layers by default */
	int high_layer = INT_MAX;
	int max_label_width = 0;
	int skiplist_mode = 0; /* do not show skiplist by default */
	Bool use_hotkey = True;
	KeyCode old_sor_keycode;
	char sor_default_keyname[8] = { 'M', 'e', 't', 'a', '_', 'L' };
	char *sor_keyname = sor_default_keyname;
	/* Condition vars. */
	Bool use_condition = False;
	Bool current_at_end = False;
	Bool iconified_at_end = False;
	int ic = 0;
	int ij;
	WindowConditionMask mask;
	char *cond_flags;
	Bool first_desk = True;
	Bool empty_menu = True;
	Bool was_get_menu_opts_called = False;
	FvwmWindow * const fw = exc->w.fw;
	const Window w = exc->w.w;
	const exec_context_t *exc2;

	memset(&mops, 0, sizeof(mops));
	memset(&mret, 0, sizeof(MenuReturn));
	/* parse postitioning args - must call this even if no action is given
	 * because it sets the xinerama screen origin */
	if (action && *action)
	{
		/* Look for condition - CreateFlagString returns NULL if no '('
		 * or '[' */
		cond_flags = CreateFlagString(action, &action);
		if (cond_flags)
		{
			/* Create window mask */
			use_condition = True;
			DefaultConditionMask(&mask);

			/* override for Current [] */
			mask.my_flags.use_circulate_hit = 1;
			mask.my_flags.use_circulate_hit_icon = 1;

			CreateConditionMask(cond_flags, &mask);
			free(cond_flags);
		}
		opts = get_menu_options(
			action, w, fw, NULL, NULL, NULL, &mops);
		was_get_menu_opts_called = True;

		/* parse options */
		while (opts && *opts)
		{
			opts = GetNextSimpleOption(opts, &tok);
			if (!tok)
			{
				break;
			}

			if (StrEquals(tok,"NoHotkeys"))
			{
				use_hotkey = False;
			}
			else if (StrEquals(tok,"Function"))
			{
				opts = GetNextSimpleOption(opts, &func);
			}
			else if (StrEquals(tok,"Desk"))
			{
				free(tok);
				opts = GetNextSimpleOption(opts, &tok);
				if (tok)
				{
					desk = atoi(tok);
					flags &= ~SHOW_ALLDESKS;
				}
			}
			else if (StrEquals(tok,"CurrentDesk"))
			{
				desk = Scr.CurrentDesk;
				flags &= ~SHOW_ALLDESKS;
			}
			else if (StrEquals(tok,"NotAlphabetic"))
			{
				flags &= ~SHOW_ALPHABETIC;
			}
			else if (StrEquals(tok,"Alphabetic"))
			{
				flags |= SHOW_ALPHABETIC;
			}
			else if (StrEquals(tok,"SortByClass"))
			{
				flags |= SORT_BYCLASS;
			}
			else if (StrEquals(tok,"SortByResource"))
			{
				flags |= SORT_BYRESOURCE;
			}
			else if (StrEquals(tok,"ReverseOrder"))
			{
				flags |= SORT_REVERSE;
			}
			else if (StrEquals(tok,"CurrentAtEnd"))
			{
				current_at_end = True;
			}
			else if (StrEquals(tok,"IconifiedAtEnd"))
			{
				iconified_at_end = True;
			}
			else if (StrEquals(tok,"NoDeskSort"))
			{
				flags |= NO_DESK_SORT;
			}
			else if (StrEquals(tok,"ShowPage"))
			{
				flags |= SHOW_PAGE_X | SHOW_PAGE_Y;
			}
			else if (StrEquals(tok,"ShowPageX"))
			{
				flags |= SHOW_PAGE_X;
			}
			else if (StrEquals(tok,"ShowPageY"))
			{
				flags |= SHOW_PAGE_Y;
			}
			else if (StrEquals(tok,"ShowScreen"))
			{
				flags |= SHOW_SCREEN;
			}
			else if (StrEquals(tok,"UseIconName"))
			{
				flags |= SHOW_ICONNAME;
			}
			else if (StrEquals(tok,"NoGeometry"))
			{
				flags &= ~SHOW_GEOMETRY;
				flags &= ~SHOW_INFONOTGEO;
			}
			else if (StrEquals(tok,"NoGeometryWithInfo"))
			{
				flags &= ~SHOW_GEOMETRY;
				flags |= SHOW_INFONOTGEO;
			}
			else if (StrEquals(tok,"Geometry"))
			{
				flags |= SHOW_GEOMETRY;
				flags &= ~SHOW_INFONOTGEO;
			}
			else if (StrEquals(tok,"NoIcons"))
			{
				flags &= ~SHOW_ICONIC;
			}
			else if (StrEquals(tok,"Icons"))
			{
				flags |= SHOW_ICONIC;
			}
			else if (StrEquals(tok,"OnlyIcons"))
			{
				flags = SHOW_ICONIC;
			}
			else if (StrEquals(tok,"NoNormal"))
			{
				flags &= ~SHOW_NORMAL;
			}
			else if (StrEquals(tok,"Normal"))
			{
				flags |= SHOW_NORMAL;
			}
			else if (StrEquals(tok,"OnlyNormal"))
			{
				flags = SHOW_NORMAL;
			}
			else if (StrEquals(tok,"NoSticky"))
			{
				flags &= ~(SHOW_STICKY_ACROSS_PAGES);
				flags &= ~(SHOW_STICKY_ACROSS_DESKS);
			}
			else if (StrEquals(tok,"NoStickyPage"))
			{
				flags &= ~(SHOW_STICKY_ACROSS_PAGES);
			}
			else if (StrEquals(tok,"NoStickyDesk"))
			{
				flags &= ~(SHOW_STICKY_ACROSS_DESKS);
			}
			else if (StrEquals(tok,"Sticky"))
			{
				flags |= SHOW_STICKY_ACROSS_PAGES;
				flags |= SHOW_STICKY_ACROSS_DESKS;
			}
			else if (StrEquals(tok,"StickyPage"))
			{
				flags |= SHOW_STICKY_ACROSS_PAGES;
			}
			else if (StrEquals(tok,"StickyDesk"))
			{
				flags |= SHOW_STICKY_ACROSS_DESKS;
			}
			else if (StrEquals(tok,"OnlySticky"))
			{
				flags = SHOW_STICKY_ACROSS_PAGES;
				flags = SHOW_STICKY_ACROSS_DESKS;
			}
			else if (StrEquals(tok,"OnlyStickyPage"))
			{
				flags = SHOW_STICKY_ACROSS_PAGES;
			}
			else if (StrEquals(tok,"OnlyStickyDesk"))
			{
				flags = SHOW_STICKY_ACROSS_DESKS;
			}
			else if (StrEquals(tok,"UseListSkip"))
			{
				/* deprecated as of 02-May-2007 (SS) */
				fprintf(stderr, "UseListSkip is deprecated. Please use \"UseSkipList\".\n");
				skiplist_mode = 1;
			}
			else if (StrEquals(tok,"UseSkipList"))
			{
				skiplist_mode = 1;
			}
			else if (StrEquals(tok,"OnlyListSkip"))
			{
				/* deprecated as of 02-May-2007 (SS) */
				fprintf(stderr, "OnlyListSkip is deprecated. Please use \"OnlySkipList\".\n");
				skiplist_mode = 2;
			}
			else if (StrEquals(tok,"OnlySkipList"))
			{
				skiplist_mode = 2;
			}
			else if (StrEquals(tok,"NoDeskNum"))
			{
				flags |= NO_DESK_NUM;
			}
			else if (StrEquals(tok,"NoLayer"))
			{
				flags |= NO_LAYER;
			}
			else if (StrEquals(tok,"NoCurrentDeskTitle"))
			{
				flags |= NO_CURRENT_DESK_TITLE;
			}
			else if (StrEquals(tok,"TitleForAllDesks"))
			{
				flags |= TITLE_FOR_ALL_DESKS;
			}
			else if (StrEquals(tok,"NoNumInDeskTitle"))
			{
				flags |= NO_NUM_IN_DESK_TITLE;
			}
			/* these are a bit dubious, but we should keep the
			 * OnTop options for compatibility */
			else if (StrEquals(tok, "NoOnTop"))
			{
				if (high_layer >= Scr.TopLayer)
				{
					high_layer = Scr.TopLayer - 1;
				}
			}
			else if (StrEquals(tok, "OnTop"))
			{
				if (high_layer < Scr.TopLayer)
				{
					high_layer = Scr.TopLayer;
				}
			}
			else if (StrEquals(tok, "OnlyOnTop"))
			{
				high_layer = low_layer = Scr.TopLayer;
			}
			else if (StrEquals(tok, "NoOnBottom"))
			{
				if (low_layer <= Scr.BottomLayer)
				{
					low_layer = Scr.BottomLayer - 1;
				}
			}
			else if (StrEquals(tok, "OnBottom"))
			{
				if (low_layer > Scr.BottomLayer)
				{
					low_layer = Scr.BottomLayer;
				}
			}
			else if (StrEquals(tok, "OnlyOnBottom"))
			{
				high_layer = low_layer = Scr.BottomLayer;
			}
			else if (StrEquals(tok, "Layer"))
			{
				free(tok);
				opts = GetNextSimpleOption(opts, &tok);
				if (tok)
				{
					low_layer = high_layer = atoi(tok);
					free(tok);
					opts = GetNextSimpleOption(opts, &tok);
					if (tok)
					{
						high_layer = atoi(tok);
					}
				}
			}
			else if (StrEquals(tok, "SelectOnRelease"))
			{
				if (sor_keyname != sor_default_keyname)
				{
					free(sor_keyname);
				}
				sor_keyname = NULL;
				opts = GetNextSimpleOption(opts, &sor_keyname);
			}
			else if (StrEquals(tok, "MaxLabelWidth"))
			{
				char *wid;

				opts = GetNextSimpleOption(opts, &wid);
				if (wid)
				{
					max_label_width = atoi(wid);
					if (max_label_width < 1)
					{
						max_label_width = 1;
					}
					free(wid);
				}
			}
			else if (!opts || !*opts)
			{
				default_action = safestrdup(tok);
			}
			else
			{
				fvwm_msg(
					ERR, "WindowList","Unknown option '%s'",
					tok);
			}
			if (tok)
			{
				free(tok);
			}
		}
	}
	if (was_get_menu_opts_called == False)
	{
		opts = get_menu_options(
			action, w, fw, NULL, NULL, NULL, &mops);
	}

	tlabel = get_desk_title(desk, flags, True);
	mr = NewMenuRoot(tlabel);
	if (!(flags & NO_CURRENT_DESK_TITLE))
	{
		AddToMenu(mr, tlabel, "TITLE", False, False, False);
		empty_menu = False;
	}
	free(tlabel);

	numWindows = 0;
	for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
	{
		numWindows++;
	}
	windowList = malloc(numWindows*sizeof(t));
	if (windowList == NULL)
	{
		return;
	}
	if (iconified_at_end)
	{
		iconifiedList = malloc(numWindows*sizeof(t));
		if (iconifiedList == NULL)
		{
			free(windowList);
			return;
		}
	}
	/* get the windowlist starting from the current window (if any)*/
	t = get_focus_window();
	if (t == NULL)
	{
		t = Scr.FvwmRoot.next;
	}
	else if (current_at_end)
	{
		if (t->next)
		{
			t = t->next;
		}
		else
		{
			t = Scr.FvwmRoot.next;
		}
	}
	for (ii = 0; ii < numWindows; ii++)
	{
		if (flags & SORT_REVERSE)
		{
			windowList[numWindows - ii - 1] = t;
		}
		else if (iconified_at_end && IS_ICONIFIED(t))
		{
			iconifiedList[ic++] = t;
		}
		else
		{
			windowList[ii - ic] = t;
		}
		if (t->next)
		{
			t = t->next;
		}
		else
		{
			t = Scr.FvwmRoot.next;
		}
	}
	if (iconified_at_end && ic > 0)
	{
		if (current_at_end && ii > ic)
		{
			windowList[numWindows - 1] = windowList[--ii - ic];
		}
		for (ij = 0; ij < ic; ij++)
		{
			windowList[ij + (ii - ic)] = iconifiedList[ij];
		}
	}

	/* Do alphabetic sort */
	if (flags & (SHOW_ALPHABETIC | SORT_BYCLASS | SORT_BYRESOURCE))
	{
		/* This will be compare or compareReverse if a reverse order
		 * is selected. */
		int (*sort)(const FvwmWindow **a, const FvwmWindow **b);

		switch (flags & (SHOW_ALPHABETIC | SHOW_ICONNAME | \
			SORT_BYCLASS | SORT_BYRESOURCE))
		{
		case SHOW_ALPHABETIC:
			compare = visibleCompare;
			break;
		case SHOW_ALPHABETIC | SHOW_ICONNAME:
			compare = iconCompare;
			break;
		/* Sorting based on class name produces an alphabetic
		 * order so the keyword alphabetic is redundant. */
		case SORT_BYCLASS:
		case SORT_BYCLASS | SHOW_ALPHABETIC:
			compare = classCompare;
			break;
		case SORT_BYCLASS | SHOW_ICONNAME:
		case SORT_BYCLASS | SHOW_ICONNAME | SHOW_ALPHABETIC:
			compare = classIconCompare;
			break;
		case SORT_BYRESOURCE:
		case SORT_BYRESOURCE | SORT_BYCLASS:
		case SORT_BYRESOURCE | SORT_BYCLASS | SHOW_ALPHABETIC:
			compare = resourceCompare;
			break;
		case SORT_BYRESOURCE | SHOW_ICONNAME:
		case SORT_BYRESOURCE | SHOW_ICONNAME | SORT_BYCLASS:
		case SORT_BYRESOURCE | SHOW_ICONNAME | SORT_BYCLASS | \
		SHOW_ALPHABETIC:
			compare = resourceIconCompare;
			break;

		/* All current cases are covered, but if something
		 * changes in the future we leave compare valid even if
		 * it isn't what is expected. */
		default:
			compare = visibleCompare;
			break;
		}

		if ( flags & SORT_REVERSE )
		{
			sort = compareReverse;
		}
		else
		{
			sort = compare;
		}
		qsort(windowList, numWindows, sizeof(t),
		      (int(*)(const void*, const void*))sort);
	}

	while(next_desk != INT_MAX)
	{
		/* Sort window list by desktop number */
		if ((flags & SHOW_ALLDESKS) && !(flags & NO_DESK_SORT))
		{
			/* run through the windowlist finding the first desk
			 * not already processed */
			next_desk = INT_MAX;
			for (ii = 0; ii < numWindows; ii++)
			{
				t = windowList[ii];
				if (t->Desk >last_desk_done &&
				    t->Desk < next_desk)
				{
					next_desk = t->Desk;
				}
			}
		}
		if (!(flags & SHOW_ALLDESKS))
		{
			/* if only doing one desk and it hasn't been done */
			if (last_desk_done  == INT_MIN)
				next_desk = desk; /* select the desk */
			else
				next_desk = INT_MAX; /* flag completion */
		}
		if (flags & NO_DESK_SORT)
			next_desk = INT_MAX; /* only go through loop once */

		last_desk_done = next_desk;
		for (ii = 0; ii < numWindows; ii++)
		{
			t = windowList[ii];
			if (t->Desk != next_desk && !(flags & NO_DESK_SORT))
			{
				continue;
			}
			if (skiplist_mode == 0 && DO_SKIP_WINDOW_LIST(t))
			{
				/* don't want skiplist windows - skip */
				continue;
			}
			if (skiplist_mode == 2 && !DO_SKIP_WINDOW_LIST(t))
			{
				/* don't want no skiplist one - skip */
				continue;
			}
			if (use_condition && !MatchesConditionMask(t, &mask))
			{
				/* doesn't match specified condition */
				continue;
			}
			if (!(flags & SHOW_ICONIC) && (IS_ICONIFIED(t)))
			{
				/* don't want icons - skip */
				continue;
			}
			if (!(flags & SHOW_STICKY_ACROSS_PAGES) &&
			    (IS_STICKY_ACROSS_PAGES(t)))
			{
				/* don't want sticky ones - skip */
				continue;
			}
			if (!(flags & SHOW_STICKY_ACROSS_DESKS) &&
			    (IS_STICKY_ACROSS_DESKS(t)))
			{
				/* don't want sticky ones - skip */
				continue;
			}
			if (!(flags & SHOW_NORMAL) &&
			    !(IS_ICONIFIED(t) ||
			      IS_STICKY_ACROSS_PAGES(t) ||
			      IS_STICKY_ACROSS_DESKS(t)))
			{
				/* don't want "normal" ones - skip */
				continue;
			}
			if (get_layer(t) < low_layer ||
			    get_layer(t) > high_layer)
			{
				/* don't want this layer */
				continue;
			}

			empty_menu = False;
			/* add separator between desks when geometry
			 * shown but not at the top*/
			if (t->Desk != last_desk_displayed)
			{
				if (last_desk_displayed != INT_MIN)
				{
					if (((flags & SHOW_GEOMETRY) ||
					     (flags & SHOW_INFONOTGEO)) &&
					    !(flags & TITLE_FOR_ALL_DESKS))
					{
						AddToMenu(
							mr, NULL, NULL, False,
							False, False);
					}
					if (flags & TITLE_FOR_ALL_DESKS)
					{
						tlabel = get_desk_title(
							t->Desk, flags, False);
						AddToMenu(
							mr, tlabel, "TITLE",
							False, False, False);
						free(tlabel);
					}
				}
				last_desk_displayed = t->Desk;
			}
			if (first_desk && flags & TITLE_FOR_ALL_DESKS)
			{
				tlabel = get_desk_title(t->Desk, flags, False);
				AddToMenu(
					mr, tlabel, "TITLE", False, False,
					False);
				free(tlabel);
			}
			first_desk = False;

			if (flags & SHOW_ICONNAME)
			{
				name = t->visible_icon_name;
			}
			else
			{
				name = t->visible_name;
			}

			free_name = False;
			if (!name)
			{
				name = "NULL_NAME";
			}
			else if (max_label_width > 0 &&
				 strlen(name) > max_label_width)
			{
				name = strdup(name);
				name[max_label_width] = '\0';
				free_name = True;
			}

			t_hot = safemalloc(strlen(name) + 80);
			if (use_hotkey)
			{
				/* Generate label */
				sprintf(t_hot, "&%c. ", scut);
			}
			else
			{
				*t_hot = 0;
			}
			if (!(flags & SHOW_INFONOTGEO))
			{
				strcat(t_hot, name);
			}
			if (*t_hot == 0)
			{
				strcpy(t_hot, " ");
			}

			/* Next shortcut key */
			if (scut == '9')
			{
				scut = 'A';
			}
			else if (scut == 'Z')
			{
				scut = '0';
			}
			else
			{
				scut++;
			}

			if (flags & SHOW_INFONOTGEO)
			{
				tname[0]=0;
				if (!IS_ICONIFIED(t) &&
				    !(flags & NO_DESK_NUM))
				{
					sprintf(loc,"%d:", t->Desk);
					strcat(tname,loc);
				}
				if (IS_ICONIFIED(t))
				{
					strcat(tname, "(");
				}
				strcat(t_hot,"\t");
				strcat(t_hot,tname);
				strcat(t_hot, name);
				if (IS_ICONIFIED(t))
				{
					strcat(t_hot, ")");
				}
			}
			else if (flags & SHOW_GEOMETRY)
			{
				size_borders b;

				tname[0]=0;
				if (IS_ICONIFIED(t))
				{
					strcpy(tname, "(");
				}
				if (!(flags & NO_DESK_NUM))
				{
					sprintf(loc, "%d", t->Desk);
					strcat(tname, loc);
				}
				if (flags & SHOW_SCREEN)
				{
					fscreen_scr_arg fscr;
					int scr;

					fscr.xypos.x =
						Scr.Vx + t->g.frame.x +
						t->g.frame.width / 2;
					fscr.xypos.y =
						Scr.Vy + t->g.frame.y +
						t->g.frame.height / 2;
					scr = FScreenGetScrId(
						&fscr, FSCREEN_XYPOS);
					sprintf(loc, "@%d", scr);
					strcat(tname, loc);
				}
				if (flags & SHOW_PAGE_X)
				{
					sprintf(loc, "+%d",
						(Scr.Vx + t->g.frame.x +
						 t->g.frame.width / 2) /
						Scr.MyDisplayWidth);
					strcat(tname, loc);
				}
				if (flags & SHOW_PAGE_Y)
				{
					sprintf(loc, "+%d",
						(Scr.Vy + t->g.frame.y +
						 t->g.frame.height/2) /
						Scr.MyDisplayHeight);
					strcat(tname, loc);
				}
				if (!(flags & NO_LAYER))
				{
					sprintf(loc, "(%d)",
						(get_layer(t)));
					strcat(tname, loc);
				}
				strcat(tname, ":");
				get_window_borders(t, &b);
				dheight = t->g.frame.height -
					b.total_size.height;
				dwidth = t->g.frame.width -
					b.total_size.width;

				dwidth = (dwidth - t->hints.base_width)
					  /t->orig_hints.width_inc;
				dheight = (dheight - t->hints.base_height)
					  /t->orig_hints.height_inc;

				sprintf(loc,"%d",dwidth);
				strcat(tname, loc);
				sprintf(loc,"x%d",dheight);
				strcat(tname, loc);
				if (t->g.frame.x >=0)
				{
					sprintf(loc,"+%d",t->g.frame.x);
				}
				else
				{
					sprintf(loc,"%d",t->g.frame.x);
				}
				strcat(tname, loc);
				if (t->g.frame.y >=0)
				{
					sprintf(loc,"+%d",t->g.frame.y);
				}
				else
				{
					sprintf(loc,"%d",t->g.frame.y);
				}
				strcat(tname, loc);

				if (IS_STICKY_ACROSS_PAGES(t) ||
				    IS_STICKY_ACROSS_DESKS(t))
				{
					strcat(tname, " S");
				}
				if (IS_ICONIFIED(t))
				{
					strcat(tname, ")");
				}
				strcat(t_hot,"\t");
				strcat(t_hot,tname);
			}
			ffunc = func ? func : "WindowListFunc";
			tfunc = safemalloc(strlen(ffunc) + 36);
			/* support two ways for now: window context
			 * (new) and window id param (old) */
			sprintf(tfunc, "WindowId %lu %s %lu",
				FW_W(t), ffunc, FW_W(t));
			AddToMenu(
				mr, t_hot, tfunc, False, False, False);
			free(tfunc);
			/* Add the title pixmap */
			if (FMiniIconsSupported && t->mini_icon)
			{
				MI_MINI_ICON(MR_LAST_ITEM(mr))[0] =
					t->mini_icon;
				/* increase the cache count. Otherwise the
				 * pixmap will be eventually removed from the
				 * cache by DestroyMenu */
				t->mini_icon->count++;
			}
			if (t_hot)
			{
				free(t_hot);
			}
			if (free_name)
			{
				free(name);
			}
		}
	}

	if (empty_menu)
	{
		/* force current desk title */
		tlabel = get_desk_title(desk, flags, True);
		AddToMenu(mr, tlabel, "TITLE", False, False, False);
		free(tlabel);
	}

	if (func)
	{
		free(func);
	}
	free(windowList);
	if (iconified_at_end)
	{
		free(iconifiedList);
	}
	/* Use the WindowList menu style if there is one */
	change_mr_menu_style(mr, "WindowList");

	/* Activate select_on_release style */
	old_sor_keycode = MST_SELECT_ON_RELEASE_KEY(mr);
	if (sor_keyname &&
	    (!MST_SELECT_ON_RELEASE_KEY(mr) ||
	     sor_keyname != sor_default_keyname))
	{
		MST_SELECT_ON_RELEASE_KEY(mr) =
			XKeysymToKeycode(
				dpy, FvwmStringToKeysym(dpy, sor_keyname));
	}

	memset(&mp, 0, sizeof(mp));
	mp.menu = mr;
	exc2 = exc_clone_context(exc, NULL, 0);
	mp.pexc = &exc2;
	mp.flags.has_default_action = (default_action && *default_action != 0);
	mp.flags.is_sticky = 1;
	mp.flags.is_submenu = 0;
	mp.flags.is_already_mapped = 0;
	mp.flags.is_triggered_by_keypress =
		(!default_action && exc->x.etrigger->type == KeyPress);
	mp.pops = &mops;
	mp.ret_paction = &ret_action;
	do_menu(&mp, &mret);
	/* Restore old menu style */
	MST_SELECT_ON_RELEASE_KEY(mr) = old_sor_keycode;
	if (ret_action)
	{
		free(ret_action);
	}
	DestroyMenu(mr, False, False);
	if (mret.rc == MENU_DOUBLE_CLICKED &&
	    default_action && *default_action)
	{
		execute_function(cond_rc, exc2, default_action, 0);
	}
	if (default_action != NULL)
	{
		free(default_action);
	}
	if (use_condition)
	{
		FreeConditionMask(&mask);
	}
	if (sor_keyname && sor_keyname != sor_default_keyname)
	{
		free(sor_keyname);
	}
	exc_destroy_context(exc2);

	return;
}
static void initialize_with_defaults (struct config_s *conf,
                                      struct config_s *defaults)
{
        if (defaults->logf_name) {
                conf->logf_name = safestrdup (defaults->logf_name);
        }

        if (defaults->config_file) {
                conf->config_file = safestrdup (defaults->config_file);
        }

        conf->syslog = defaults->syslog;
        conf->port = defaults->port;

        if (defaults->stathost) {
                conf->stathost = safestrdup (defaults->stathost);
        }

        conf->godaemon = defaults->godaemon;
        conf->quit = defaults->quit;

        if (defaults->user) {
                conf->user = safestrdup (defaults->user);
        }

        if (defaults->group) {
                conf->group = safestrdup (defaults->group);
        }

        if (defaults->ipAddr) {
                conf->ipAddr = safestrdup (defaults->ipAddr);
        }

#ifdef FILTER_ENABLE
        if (defaults->filter) {
                conf->filter = safestrdup (defaults->filter);
        }

        conf->filter_url = defaults->filter_url;
        conf->filter_extended = defaults->filter_extended;
        conf->filter_casesensitive = defaults->filter_casesensitive;
#endif                          /* FILTER_ENABLE */

#ifdef XTINYPROXY_ENABLE
        conf->add_xtinyproxy = defaults->add_xtinyproxy;
#endif

#ifdef REVERSE_SUPPORT
        /* struct reversepath *reversepath_list; */
        conf->reverseonly = defaults->reverseonly;
        conf->reversemagic = defaults->reversemagic;

        if (defaults->reversebaseurl) {
                conf->reversebaseurl = safestrdup (defaults->reversebaseurl);
        }
#endif

#ifdef UPSTREAM_SUPPORT
        /* struct upstream *upstream_list; */
#endif                          /* UPSTREAM_SUPPORT */

        if (defaults->pidpath) {
                conf->pidpath = safestrdup (defaults->pidpath);
        }

    
        conf->idletimeout = defaults->idletimeout;

        if (defaults->bind_address) {
                conf->bind_address = safestrdup (defaults->bind_address);
        }

        conf->bindsame = defaults->bindsame;

        if (defaults->via_proxy_name) {
                conf->via_proxy_name = safestrdup (defaults->via_proxy_name);
        }

        conf->disable_viaheader = defaults->disable_viaheader;

        if (defaults->errorpage_undef) {
                conf->errorpage_undef = safestrdup (defaults->errorpage_undef);
        }

        if (defaults->statpage) {
                conf->statpage = safestrdup (defaults->statpage);
        }

        /* vector_t access_list; */
        /* vector_t connect_ports; */
        /* hashmap_t anonymous_map; */
}
示例#30
0
int main(int argc, char *argv[], char *envp[])
{
	int i;
	struct line_list l, options, request_list;
	char msg[SMALLBUFFER], *s;

	Init_line_list(&l);
	Init_line_list(&options);
	Init_line_list(&request_list);

	/* set signal handlers */
	(void) plp_signal (SIGHUP, cleanup_HUP);
	(void) plp_signal (SIGINT, cleanup_INT);
	(void) plp_signal (SIGQUIT, cleanup_QUIT);
	(void) plp_signal (SIGTERM, cleanup_TERM);
	(void) signal(SIGCHLD, SIG_DFL);
	(void) signal(SIGPIPE, SIG_IGN);

	/*
	 * set up the user state
	 */

	Status_line_count = 1;

#ifndef NODEBUG
	Debug = 0;
#endif

	Displayformat = REQ_DLONG;

	Initialize(argc, argv, envp, 'T' );
	Setup_configuration();
	Get_parms(argc, argv );      /* scan input args */
	if( A_flag && !getenv( "AUTH" ) ){
		FPRINTF(STDERR,"lpstat: requested authenticated transfer (-A) and AUTH environment variable not set");
		usage();
	}

	/* set up configuration */
	Get_printer();
	Fix_Rm_Rp_info(0,0);
	Get_all_printcap_entries();

	/* check on printing scheduler is running */
	if( t_flag ){
		All_printers = 1;
		r_flag = d_flag = p_flag = o_flag = 1;
		s_flag = 0;
	}
	if( s_flag ){
		/* a_flag = 1; */
		r_flag = 1;
		d_flag = 1;
		v_flag = 1;
		All_printers = 1;
	}

	if( All_printers ){
		Merge_line_list( &request_list, &All_line_list,0,0,0);
	}
	Merge_line_list( &request_list, &Printer_list,0,0,0);
	Check_max(&options,2);
	if( options.count ){
		for( i = options.count; i > 0 ; --i ){
			options.list[i] = options.list[i-1];
		}
		options.list[0] = safestrdup(Logname_DYN,__FILE__,__LINE__);
		++options.count;
	}
	options.list[options.count] = 0;

	if( Found_flag == 0 ){
		if( request_list.count == 0 ){
			Split(&request_list,Printer_DYN,", ",1,0,1,1,0,0);
		}
		o_flag = 1;
		flag_count = 1;
	}
#ifdef ORIGINAL_DEBUG//JY@1020
	if(DEBUGL1)Dump_line_list("lpstat - printer request list", &request_list);
	if(DEBUGL1)Dump_line_list("lpstat - options", &options);
#endif

	if( r_flag ){
		Write_fd_str(1,"scheduler is running\n");
	}
	if( d_flag ){
		if( Printer_DYN == 0 ){
			Write_fd_str(1,"no system default destination\n");
		} else {
			SNPRINTF(msg,sizeof(msg))
				"system default destination: %s\n", Printer_DYN);
			Write_fd_str(1,msg);
		}
	}
	if( v_flag ){
		for( i = 0; i < request_list.count; ++i ){
			Set_DYN(&Printer_DYN,request_list.list[i] );
			Fix_Rm_Rp_info(0,0);
			SNPRINTF(msg,sizeof(msg)) "system for %s: %s\n", Printer_DYN, RemoteHost_DYN);
			Write_fd_str(1,msg);
		}
	}

	/* see if additional status required */

	Free_line_list( &Printer_list );

	for( i = 0; i < request_list.count; ++i ){
		s = request_list.list[i];
		Set_DYN(&Printer_DYN,s );
		Show_status(options.list, 0);
	}

	Free_line_list( &Printer_list );
	if( flag_count ){
		for( i = 0; i < request_list.count; ++i ){
			s = request_list.list[i];
			Set_DYN(&Printer_DYN,s );
			Show_status(options.list, 1);
		}
	}

	DEBUG1("lpstat: done");
	Remove_tempfiles();
	DEBUG1("lpstat: tempfiles removed");

	Errorcode = 0;
	DEBUG1("lpstat: cleaning up");
	return(0);
}