Exemple #1
0
/* return malloc'ed buffer.  caller must free it */
char *
print_wires(void)
{
  addrlist *al;
  char s[256];
  int i;
  char *buf;
  int bufcount = 0;
  int buf_size = 1024;

  buf = SALLOC(buf_size);	/* initial allocation (may grow!) */
  if (!buf)
    return NULL;

  if (!localnets) {
    xstrlcpy(buf, "No networks\n", buf_size);
    return buf;
  }
  /* check if there's more than one network */
  if (!localnets->ip_next) {
    /* use buf_size for sizeof(buf) because of the realloc() below */
    xsnprintf(buf, buf_size,
	      "Network: wire=\"%s\" (netnumber=%s).\n",
	      localnets->ip_net_name, localnets->ip_net_num);
    return buf;
  }
  buf[0] = '\0';		/* null out buffer before appending */
  for (i = 1, al = localnets; al; al = al->ip_next, i++) {
    xsnprintf(s, sizeof(s), "Network %d: wire=\"%s\" (netnumber=%s).\n",
	      i, al->ip_net_name, al->ip_net_num);
    bufcount += strlen(s);
    if (bufcount > buf_size) {
      buf_size *= 2;
      buf = xrealloc(buf, buf_size);
    }
    xstrlcat(buf, s, buf_size);
  }
  return buf;
}
Exemple #2
0
/* return malloc'ed buffer.  caller must free it */
char *
print_wires(void)
{
  addrlist *al;
  char s[256];
  int i;
  char *buf;
  int bufcount = 0;
  int buf_size = 1024;

  buf = SALLOC(1024);
  if (!buf)
    return NULL;

  if (!localnets) {
    sprintf(buf, "No networks.\n");
    return buf;
  }
  /* check if there's more than one network */
  if (!localnets->ip_next) {
    sprintf(buf,
	    "Network: wire=\"%s\" (netnumber=%s).\n",
	    localnets->ip_net_name, localnets->ip_net_num);
    return buf;
  }
  buf[0] = '\0';		/* null out buffer before appending */
  for (i = 1, al = localnets; al; al = al->ip_next, i++) {
    sprintf(s, "Network %d: wire=\"%s\" (netnumber=%s).\n",
	    i, al->ip_net_name, al->ip_net_num);
    bufcount += strlen(s);
    if (bufcount > buf_size) {
      buf_size *= 2;
      buf = xrealloc(buf, buf_size);
    }
    strcat(buf, s);
  }
  return buf;
}
Exemple #3
0
/* force_unique_signames() tries to ensure that each signal has a unique name.
   By default, the name of signal i is s[i].desc.  The names of any signals
   that are not unique are modified by appending a unique suffix to each
   such signal.  For example, if there are five signals with default names
        A, A, B, C, B
   they are renamed as
        A:1*, A:2*, B:3*, C, B:4*

   For efficiency, this function makes two assumptions that may cause it
   to fail to achieve its intended purpose in rare cases.  First, the unique
   suffix is limited to five characters, so that at most 999 signals can be
   renamed.  Second, if any default name ends with a string that matches a
   unique suffix, it will not be recognized as non-unique.  For example, if
   the default names are
       A, A, A:0*
   they are renamed as
       A:0*, A:1*, A:0*
   The format of the suffix has been chosen to make this unlikely.
 */
void force_unique_signames(void) {
    int i, j;

    SALLOC(sname, sizeof(char *), nsig);

    for (i = 0; i < nsig; i++) {
	for (j = i+1; j < nsig; j++) {
	    if (strcmp(s[i].desc, s[j].desc) == 0) {
		sname[i] = sname[j] = "change";
	    }
	}
    }

    for (i = j =  0; i < nsig; i++) {
	if (sname[i] == NULL && j < 1000) {
	    SSTRCPY(sname[i], s[i].desc);
	}
	else {
	    SUALLOC(sname[i], sizeof(char), strlen(s[i].desc) + 6);
	    sprintf(sname[i], "%s:%d*", s[i].desc, j++);
	}
    }	
}
Exemple #4
0
void *Service_svc_BUTLER_newState(Server *srv)
{
  ButlerState *bs = NULL;
  int x = 0;
  ualloc_t *ua = Server_ua(srv);
  hash_t *ch = NULL;
  void *vp = NULL;

  bs = SALLOC(ua, ButlerState);
  if (!bs)
    Debug_PANIC("could not allocate ButlerState");
  bs->srv = srv;
  x = HASH_CREATE_SIMPLE(ua, HASH_F_COPYKEY | HASH_F_NCASEKEY, &bs->nick_reg);
  if (x)
    Debug_PANIC("could not create nick_reg hash: error#%d", x);
  bs->cmdh = cmdHash_create(ua);
  if (!bs->cmdh)
    Debug_PANIC("could not create cmd_hash");
  ch = bs->cmdh;
  vp = (void *)bs;
  x = cmdHash_add(ua,ch,"reg*ister", butler_register,vp);    if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"rec*onnect",butler_reconnect,vp);   if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"rep*lay",butler_replay,vp);         if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"ma*il",butler_mail, vp);            if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"se*t",butler_set, vp);              if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"sh*ow",butler_show, vp);            if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"di*sconnect",butler_disconnect,vp); if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"un*register",butler_unregister,vp); if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"he*lp",butler_help,vp);             if (x) goto LOSE;
  x = cmdHash_add(ua,ch,"rem*ember",butler_remember,vp);     if (x) goto LOSE;
  /*
  ** There are a couple global events that we are interested in
  */
  Server_registerEventHandler(
    srv,
    SERVER_EV_SHUTDOWN,
    "BUTLER:shutdown",
    (EventFn)Service_svc_BUTLER_event,
    vp
  );
  Server_registerEventHandler(
    srv,
    SERVER_EV_REHASH,
    "BUTLER:rehash",
    (EventFn)Service_svc_BUTLER_event,
    vp
  );
  Server_registerEventHandler(
    srv,
    SERVER_EV_CLI_NICK,
    "BUTLER:cli_nick",
    (EventFn)Service_svc_BUTLER_event,
    vp
  );
  Server_registerEventHandler(
    srv,
    SERVER_EV_CLI_REGISTER,
    "BUTLER:cli_register",
    (EventFn)Service_svc_BUTLER_event,
    vp
  );
  butler_restoreState(bs);
  return vp;
 LOSE:
  /* XXX */
  return NULL;
}