示例#1
0
void SaveCheck(int id, char *val) {

    if (IsDlgButtonChecked(ghWndSave, id))
        SaveStr(val);
    else
        SaveStr("");

}
示例#2
0
void SaveRadio(s_radio *radio, int count) {

    while (count--) {
        if (IsDlgButtonChecked(ghWndSave, radio[count].id)) {
            SaveStr(radio[count].val);
            return;
        }
    }
    SaveStr("");

}
示例#3
0
文件: fileio.c 项目: kbingham/screen
static char *findrcfile(char *rcfile)
{
	char buf[256];
	char *p;

	/* Tilde prefix support courtesy <*****@*****.**>,
	 * taken from a Debian patch. */
	if (rcfile && *rcfile == '~') {
		static char rcfilename_tilde_exp[MAXPATHLEN + 1];
		char *slash_position = strchr(rcfile, '/');
		if (slash_position == rcfile + 1) {
			if (!home) {
				Msg(0, "%s: source: tilde expansion failed", rc_name);
				return NULL;
			}
			snprintf(rcfilename_tilde_exp, MAXPATHLEN, "%s/%s", home, rcfile + 2);
		} else if (slash_position) {
			struct passwd *p;
			*slash_position = 0;
			p = getpwnam(rcfile + 1);
			if (!p) {
				Msg(0, "%s: source: tilde expansion failed for user %s", rc_name, rcfile + 1);
				return NULL;
			}
			snprintf(rcfilename_tilde_exp, MAXPATHLEN, "%s/%s", p->pw_dir, slash_position + 1);
		} else {
			Msg(0, "%s: source: illegal tilde expression.", rc_name);
			return NULL;
		}
		rcfile = rcfilename_tilde_exp;
	}

	if (rcfile) {
		char *rcend = strrchr(rc_name, '/');
		if (*rcfile != '/' && rcend && (rcend - rc_name) + strlen(rcfile) + 2 < sizeof(buf)) {
			strncpy(buf, rc_name, rcend - rc_name + 1);
			strncpy(buf + (rcend - rc_name) + 1, rcfile, 256 - (rcend - rc_name));
			if (access(buf, R_OK) == 0)
				return SaveStr(buf);
		}
		return SaveStr(rcfile);
	}
	if ((p = getenv("SCREENRC")) != NULL && *p != '\0') {
		return SaveStr(p);
	} else {
		if (strlen(home) > sizeof(buf) - 12)
			Panic(0, "Rc: home too large");
		sprintf(buf, "%s/.screenrc", home);
		return SaveStr(buf);
	}
}
示例#4
0
static void SaveModemSetting(HWND hWnd)
{
	int n;
	char string[MAX_NUM_LEN];
	char ipaddr[4][4];

	gOptions.ModemEnable = SendMessage(ModemWnd[0], CB_GETCURSEL, 0, 0);

	if (module_type != MODEM_MODULE_EM660) {
		memset(string, 0, sizeof(string));
		GetWindowText(ModemWnd[1], string, sizeof(string));
		SaveStr("APN", string, 1);
	}

	memset(string, 0, sizeof(string));
	GetWindowText(ModemWnd[2], string, sizeof(string));
	SaveStr("ModemDialNumber", string, 1);

	memset(string, 0, sizeof(string));
	GetWindowText(ModemWnd[3], string, sizeof(string));
	SaveStr("ModemUserName", string, 1);

	memset(string, 0, sizeof(string));
	GetWindowText(ModemWnd[4], string, sizeof(string));
	SaveStr("ModemPassword", string, 1);

	GetWindowText(ModemWnd[5], ipaddr[0], sizeof(ipaddr[0]));
	GetWindowText(ModemWnd[6], ipaddr[1], sizeof(ipaddr[1]));
	GetWindowText(ModemWnd[7], ipaddr[2], sizeof(ipaddr[2]));
	GetWindowText(ModemWnd[8], ipaddr[3], sizeof(ipaddr[3]));

	if (CheckIP(ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3], 1) 
		|| ((strcmp(ipaddr[0], "0")==0) && (strcmp(ipaddr[1], "0")==0) &&(strcmp(ipaddr[2], "0")==0) && (strcmp(ipaddr[3], "0")==0))) {
		n = sprintf(string, "%d.%d.%d.%d", atoi(ipaddr[0]), atoi(ipaddr[1]), atoi(ipaddr[2]), atoi(ipaddr[3]));
		string[n] = '\0';
		SaveStr("HeartBeatServer", string, 1);
	}

	SaveOptions(&gOptions);

        reload_modem_configuration();
        modem_reconnect();
        if (gOptions.ModemEnable == 0) {
                modem_thread_exit();
        } else {
                modem_thread_init();
        }
	
	MessageBox1 (hWnd ,LoadStrByID(HID_RESTART) ,LoadStrByID(HIT_RUN),MB_OK | MB_ICONINFORMATION);
}
示例#5
0
Log *logfopen(char *name, FILE * fp)
{
	Log *l;

	if (!fp) {
		if (!(l = lookup_logfile(name)))
			return NULL;
		l->opencount++;
		return l;
	}

	if (!(l = malloc(sizeof(Log))))
		return NULL;
	if (!(l->st = malloc(sizeof(struct stat)))) {
		free((char *)l);
		return NULL;
	}

	if (!(l->name = SaveStr(name))) {
		free((char *)l->st);
		free((char *)l);
		return NULL;
	}
	l->fp = fp;
	l->opencount = 1;
	l->writecount = 0;
	l->flushcount = 0;
	changed_logfile(l);

	l->next = logroot;
	logroot = l;
	return l;
}
示例#6
0
文件: layout.c 项目: skoneka/screen
struct layout *
CreateLayout(char *title, int startat)
{
  struct layout *lay, **pl;
  int i;

  if (startat >= MAXLAY || startat < 0)
    startat = 0;
  for (i = startat; ;)
    {
      if (!laytab[i])
        break;
      if (++i == MAXLAY)
	i = 0;
      if (i == startat)
	{
	  Msg(0, "No more layouts\n");
	  return 0;
	}
    }
  lay = (struct layout *)calloc(1, sizeof(*lay));
  lay->lay_title = SaveStr(title);
  lay->lay_autosave = 1;
  lay->lay_number = i;
  laytab[i] = lay;
  lay->lay_next = 0;

  pl = &layouts;
  while (*pl)
    pl = &(*pl)->lay_next;
  *pl = lay;
  return lay;
}
static int SaveNewWiFiSetting(HWND hWnd)
{
	char tmpstring[128];
	//int idx=0;

	memset(tmpstring, 0, sizeof(tmpstring));
	GetWindowText(WifiWnd[0], tmpstring, sizeof(tmpstring));
	if(tmpstring && strlen(tmpstring)>0){
		SaveStr("SSID", tmpstring, 1);
	} else {
		MessageBox1(hWnd, LoadStrByID(MID_WIFI_ERR1), LoadStrByID(HIT_RUN), MB_OK | MB_ICONSTOP);
		curFocusWnd = 0;
		SetFocusChild(WifiWnd[curFocusWnd]);	
		return 0;
	}

	//wifipasswd
	memset(tmpstring, 0, sizeof(tmpstring));
	GetWindowText(WifiWnd[1], tmpstring, sizeof(tmpstring));
	if (tmpstring[0]) {
		SaveStr("wifipasswd", tmpstring, 1);
		printf("wifi passwd:%s\n", tmpstring);
	}

	//ip assign mode: dhcp or fix
	if (wifidhcpflag != gOptions.wifidhcpfunon) {
		gOptions.wifidhcpfunon = wifidhcpflag;
		SaveInteger("wifidhcp", wifidhcpflag);
	}

	SaveStr("wifiip", (char*)newip[0], 1);
	SaveStr("wifimask", (char*)newip[1], 1);
	SaveStr("wifigateway", (char*)newip[2], 1);

	wireless_load_configuration();
	wireless_request_reconnect();
	return 1;
}
示例#8
0
void
InitBraille()
{
  bd.bd_start_braille=0;
  bd.bd_port = 0;
  bd.bd_braille_table = SaveStr("internal us-braille.tbl"); 
  bd.bd_type = 0;
  bd.bd_baud = 9600;
  bd.bd_bell = 1;
  bd.bd_eightdot = 1;
  bd.bd_info = 0;
  bd.bd_link = 1;
  bd.bd_ncells = 0;
  bd.bd_width = 0;
  bd.bd_ncrc = 1;
  bd.bd_scroll = 1;
  bd.bd_skip = 0;
  bd.bd_using_braille = 0;
  bd.bd_obuflen = 0;
  bd.bd_fd = -1;
  bcopy((char *)btable_local, bd.bd_btable, 256);
}
示例#9
0
文件: layout.c 项目: skoneka/screen
void RenameLayout(struct layout *layout, const char *name)
{
  free(layout->lay_title);
  layout->lay_title = SaveStr(name);
}
示例#10
0
文件: acls.c 项目: skoneka/screen
/*
 * Add a new user. His password may be NULL or "" if none. His name must not 
 * be "none", as this represents the NULL-pointer when dealing with groups.
 * He has default rights, determined by umask.
 */
int
UserAdd(char *name, char *pass, struct acluser **up)
{
  int j;

  if (!up)
    up = FindUserPtr(name);
  if (*up)
    {
      if (pass)
        (*up)->u_password = SaveStr(pass);
      return 1;		/* he is already there */
    }
  if (strcmp("none", name))	/* "none" is a reserved word */
    *up = (struct acluser *)calloc(1, sizeof(struct acluser));
  if (!*up)
    return -1;		/* he still does not exist */
  (*up)->u_plop.buf = NULL;
  (*up)->u_plop.len = 0;
  (*up)->u_plop.enc = 0;
  (*up)->u_Esc = DefaultEsc;
  (*up)->u_MetaEsc = DefaultMetaEsc;
  strncpy((*up)->u_name, name, NAME_MAX);
  (*up)->u_password = NULL;
  if (pass)
    (*up)->u_password = SaveStr(pass);
  if (!(*up)->u_password)
    (*up)->u_password = NullStr;
  (*up)->u_detachwin = -1;
  (*up)->u_detachotherwin = -1;

  (*up)->u_group = NULL;
  /* now find an unused index */
  for ((*up)->u_id = 0; (*up)->u_id < maxusercount; (*up)->u_id++)
    if (!(ACLBIT((*up)->u_id) & ACLBYTE(userbits, (*up)->u_id)))
      break;
  debug2("UserAdd %s id %d\n", name, (*up)->u_id);
  if ((*up)->u_id == maxusercount)
    {
      int j;
      struct win *w;
      struct acluser *u;

      debug2("growing all bitfields %d += %d\n", maxusercount, USER_CHUNK);
      /* the bitfields are full, grow a chunk */
      /* first, the used_uid_indicator: */
      if (GrowBitfield(&userbits, maxusercount, USER_CHUNK, 0))
        {
	  free((char *)*up); *up = NULL; return -1;
	}
      /* second, default command bits  */
      /* (only if we generate commands dynamically) */
/*
      for (j = 0; j < ACL_BITS_PER_CMD; j++)
	if (GrowBitfield(&default_c_userbits[j], maxusercount, USER_CHUNK, 
	    default_c_bit[j]))
	  {
	    free((char *)*up); *up = NULL; return -1;
	  }
*/
      /* third, the bits for each commands */
      for (j = 0; j <= RC_LAST; j++)
        {
	  int i;
	  
	  for (i = 0; i < ACL_BITS_PER_CMD; i++)
	    if (GrowBitfield(&comms[j].userbits[i], maxusercount, USER_CHUNK,
	        default_c_bit[i]))
	      {
	        free((char *)*up); *up = NULL; return -1;
	      }
        }
      /* fourth, default window creation bits per user */
      for (u = users; u != *up; u = u->u_next)
        {
	  for (j = 0; j < ACL_BITS_PER_WIN; j++)
	    {
	      if (GrowBitfield(&u->u_umask_w_bits[j], maxusercount, USER_CHUNK,
		  default_w_bit[j]))
		{
		  free((char *)*up); *up = NULL; return -1;
		}
	    }
	}

      /* fifth, the bits for each window */
      /* keep these in sync with NewWindowAcl() */
      for (w = windows; w; w = w->w_next)
	{
	  /* five a: the access control list */
	  for (j = 0; j < ACL_BITS_PER_WIN; j++)
	    if (GrowBitfield(&w->w_userbits[j], maxusercount, USER_CHUNK,
		default_w_bit[j]))
	      {
		free((char *)*up); *up = NULL; return -1;
	      }
	  /* five b: the activity notify list */
	  /* five c: the silence notify list */
	  if (GrowBitfield(&w->w_mon_notify, maxusercount, USER_CHUNK, 0) ||
	      GrowBitfield(&w->w_lio_notify, maxusercount, USER_CHUNK, 0))
	    {  
	      free((char *)*up); *up = NULL; return -1; 
	    }
	}
      maxusercount += USER_CHUNK;
    }

  /* mark the user-entry as "in-use" */
  ACLBYTE(userbits, (*up)->u_id) |= ACLBIT((*up)->u_id);    

  /* user id 0 is the session creator, he has all rights */
  if ((*up)->u_id == 0)
    AclSetPerm(NULL, *up, "+a", "#?");
  
  /* user nobody has a fixed set of rights: */
  if (!strcmp((*up)->u_name, "nobody"))
    {
      AclSetPerm(NULL, *up, "-rwx", "#?");
      AclSetPerm(NULL, *up, "+x", "su");
      AclSetPerm(NULL, *up, "+x", "detach");
      AclSetPerm(NULL, *up, "+x", "displays");
      AclSetPerm(NULL, *up, "+x", "version");
    }

  /* 
   * Create his umask:
   * Give default_w_bit's for all users, 
   * but allow himself everything on "his" windows.
   */
  for (j = 0; j < ACL_BITS_PER_WIN; j++)
    {
      if (GrowBitfield(&(*up)->u_umask_w_bits[j], 0, maxusercount, 
          default_w_bit[j]))
        {
          free((char *)*up); *up = NULL; return -1;
        }
      ACLBYTE((*up)->u_umask_w_bits[j], (*up)->u_id) |= ACLBIT((*up)->u_id);
    }
  return 0;
}
示例#11
0
文件: input.c 项目: skoneka/screen
static void
InpProcess(char **ppbuf, int *plen)
{
  int len, x;
  char *pbuf;
  char ch;
  struct inpdata *inpdata;
  struct display *inpdisplay;
  int prev, next, search = 0;

  inpdata = (struct inpdata *)flayer->l_data;
  inpdisplay = display;

#define RESET_SEARCH { if (inpdata->search) Free(inpdata->search); }

  LGotoPos(flayer, inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos), INPUTLINE);
  if (ppbuf == 0)
    {
      InpAbort();
      return;
    }
  x = inpdata->inpstringlen + inpdata->inp.pos;
  len = *plen;
  pbuf = *ppbuf;
  while (len)
    {
      char *p = inpdata->inp.buf + inpdata->inp.pos;

      ch = *pbuf++;
      len--;
      if (inpdata->inpmode & INP_EVERY)
	{
	  inpdata->inp.buf[inpdata->inp.len] = ch;
	  if (ch)
	    {
	      display = inpdisplay;
	      (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv);
	      ch = inpdata->inp.buf[inpdata->inp.len];
	    }
	}
      else if (inpdata->inpmode & INP_RAW)
	{
	  display = inpdisplay;
          (*inpdata->inpfinfunc)(&ch, 1, inpdata->priv);	/* raw */
	  if (ch)
	    continue;
	}
      if (((unsigned char)ch & 0177) >= ' ' && ch != 0177 && inpdata->inp.len < inpdata->inpmaxlen)
	{
	  if (inpdata->inp.len > inpdata->inp.pos)
	    memmove(p+1, p, inpdata->inp.len - inpdata->inp.pos);
	  inpdata->inp.buf[inpdata->inp.pos++] = ch;
	  inpdata->inp.len++;

	  if (!(inpdata->inpmode & INP_NOECHO))
	    {
	      struct mchar mc;
	      mc = mchar_so;
	      mc.image = *p++;
	      LPutChar(flayer, &mc, x, INPUTLINE);
	      x++;
	      if (p < inpdata->inp.buf+inpdata->inp.len)
		{
		  while (p < inpdata->inp.buf+inpdata->inp.len)
		    {
		      mc.image = *p++;
		      LPutChar(flayer, &mc, x++, INPUTLINE);
		    }
		  x = inpdata->inpstringlen + inpdata->inp.pos;
		  LGotoPos(flayer, x, INPUTLINE);
		}
	    }
	  RESET_SEARCH;
	}
      else if ((ch == '\b' || ch == 0177) && inpdata->inp.pos > 0)
	{
	  erase_chars(inpdata, p-1, p, x, 1);
	  RESET_SEARCH;
	}
      else if (ch == '\025')			/* CTRL-U */
	{
	  x = inpdata->inpstringlen;
	  if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO))
	    {
	      LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - 1, INPUTLINE, 0, 0);
	      LGotoPos(flayer, x, INPUTLINE);
	    }
	  inpdata->inp.len = inpdata->inp.pos = 0;
	}
      else if (ch == '\013')			/* CTRL-K */
	{
	  x = inpdata->inpstringlen + inpdata->inp.pos;
	  if (inpdata->inp.len > inpdata->inp.pos && !(inpdata->inpmode & INP_NOECHO))
	    {
	      LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - inpdata->inp.pos - 1, INPUTLINE, 0, 0);
	      LGotoPos(flayer, x, INPUTLINE);
	    }
	  inpdata->inp.len = inpdata->inp.pos;
	}
      else if (ch == '\027' && inpdata->inp.pos > 0)		/* CTRL-W */
	{
	  char *oldp = p--;
	  while (p > inpdata->inp.buf && *p == ' ')
	    p--;
	  while (p > inpdata->inp.buf && *(p - 1) != ' ')
	    p--;
	  erase_chars(inpdata, p, oldp, x, 1);
	  RESET_SEARCH;
	}
      else if (ch == '\004' && inpdata->inp.pos < inpdata->inp.len)	/* CTRL-D */
	{
	  erase_chars(inpdata, p, p+1, x, 0);
	  RESET_SEARCH;
	}
      else if (ch == '\001' || (unsigned char)ch == 0201)	/* CTRL-A */
	{
	  LGotoPos(flayer, x -= inpdata->inp.pos, INPUTLINE);
	  inpdata->inp.pos = 0;
	}
      else if ((ch == '\002' || (unsigned char)ch == 0202) && inpdata->inp.pos > 0)	/* CTRL-B */
	{
	  LGotoPos(flayer, --x, INPUTLINE);
	  inpdata->inp.pos--;
	}
      else if (ch == '\005' || (unsigned char)ch == 0205)	/* CTRL-E */
	{
	  LGotoPos(flayer, x += inpdata->inp.len - inpdata->inp.pos, INPUTLINE);
	  inpdata->inp.pos = inpdata->inp.len;
	}
      else if ((ch == '\006' || (unsigned char)ch == 0206) && inpdata->inp.pos < inpdata->inp.len)	/* CTRL-F */
	{
	  LGotoPos(flayer, ++x, INPUTLINE);
	  inpdata->inp.pos++;
	}
      else if ((prev = ((ch == '\020' || (unsigned char)ch == 0220) &&	/* CTRL-P */
	      inpdata->inp.prev)) ||
	  (next = ((ch == '\016' || (unsigned char)ch == 0216) &&  /* CTRL-N */
		   inpdata->inp.next)) ||
	  (search = ((ch == '\022' || (unsigned char)ch == 0222) && inpdata->inp.prev)))
	{
	  struct mchar mc;
	  struct inpline *sel;
	  int pos = -1;

	  mc = mchar_so;

	  if (prev)
	    sel = inpdata->inp.prev;
	  else if (next)
	    sel = inpdata->inp.next;
	  else
	    {
	      /* search */
	      inpdata->inp.buf[inpdata->inp.len] = 0;	/* Remove the ctrl-r from the end */
	      if (!inpdata->search)
		inpdata->search = SaveStr(inpdata->inp.buf);
	      for (sel = inpdata->inp.prev; sel; sel = sel->prev)
		{
		  char *f;
		  if ((f = strstr(sel->buf, inpdata->search)))
		    {
		      pos = f - sel->buf;
		      break;
		    }
		}
	      if (!sel)
		continue;	/* Did not find a match. Process the next input. */
	    }

	  if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO))
	    LClearArea(flayer, inpdata->inpstringlen, INPUTLINE, inpdata->inpstringlen + inpdata->inp.len - 1, INPUTLINE, 0, 0);

	  if ((prev || search) && !inpdata->inp.next)
	    inphist = inpdata->inp;
	  memcpy(&inpdata->inp, sel, sizeof(struct inpline));
	  if (pos != -1)
	    inpdata->inp.pos = pos;
	  if (inpdata->inp.len > inpdata->inpmaxlen)
	    inpdata->inp.len = inpdata->inpmaxlen;
	  if (inpdata->inp.pos > inpdata->inp.len)
	    inpdata->inp.pos = inpdata->inp.len;

	  x = inpdata->inpstringlen;
	  p = inpdata->inp.buf;

	  if (!(inpdata->inpmode & INP_NOECHO))
	    {
	      while (p < inpdata->inp.buf+inpdata->inp.len)
		{
		  mc.image = *p++;
		  LPutChar(flayer, &mc, x++, INPUTLINE);
		}
	    }
	  x = inpdata->inpstringlen + inpdata->inp.pos;
	  LGotoPos(flayer, x, INPUTLINE);
	}

      else if (ch == '\003' || ch == '\007' || ch == '\033' ||
	       ch == '\000' || ch == '\n' || ch == '\r')
	{
          if (ch != '\n' && ch != '\r')
	    inpdata->inp.len = 0;
	  inpdata->inp.buf[inpdata->inp.len] = 0;

	  if (inpdata->inp.len && !(inpdata->inpmode & (INP_NOECHO | INP_RAW)))
	    {
	      struct inpline *store;

	      /* Look for a duplicate first */
	      for (store = inphist.prev; store; store = store->prev)
		{
		  if (strcmp(store->buf, inpdata->inp.buf) == 0)
		    {
		      if (store->next)
			store->next->prev = store->prev;
		      if (store->prev)
			store->prev->next = store->next;
		      store->pos = inpdata->inp.pos;
		      break;
		    }
		}

	      if (!store)
		{
		  store = malloc(sizeof(struct inpline));
		  memcpy(store, &inpdata->inp, sizeof(struct inpline));
		}
	      store->next = &inphist;
	      store->prev = inphist.prev;
	      if (inphist.prev)
		inphist.prev->next = store;
	      inphist.prev = store;
	    }

	  flayer->l_data = 0;	/* so inpdata does not get freed */
          InpAbort();		/* redisplays... */
	  *ppbuf = pbuf;
	  *plen = len;
	  display = inpdisplay;
	  if ((inpdata->inpmode & INP_RAW) == 0)
            (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv);
	  else
            (*inpdata->inpfinfunc)(pbuf - 1, 0, inpdata->priv);
	  if (inpdata->search)
	    free(inpdata->search);
	  free(inpdata);
	  return;
	}
      else
	{
	  /* The user was searching, and then pressed some non-control input. So reset
	   * the search string. */
	  RESET_SEARCH;
	}
    }
  if (!(inpdata->inpmode & INP_RAW))
    {
      flayer->l_x = inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos);
      flayer->l_y = INPUTLINE;
    }
  *ppbuf = pbuf;
  *plen = len;
}