示例#1
0
/*
 * Put group selection information in internal format.
 */
void
selectgrp(const char *str)
{
	struct grp *gp;
	size_t sz;
	const char *endstr;

	gp = selgrp = (struct grp *)salloc(sizeof *gp);
	for (;;) {
		gp->g_gid = -1;
		if ((endstr = strchr(str, ',')) == NULL)
			endstr = str + strlen(str);
		sz = endstr - str;
		gp->g_name = salloc(sz + 1);
		memcpy(gp->g_name, str, sz);
		gp->g_name[sz] = '\0';
		if (getgrnam(gp->g_name) == NULL) {
			fprintf(stderr, "%s was not found\n", gp->g_name);
			exit(1);
		}
		if (*endstr == '\0' || *(str = endstr + 1) == '\0')
			break;
		str = endstr + 1;
		gp->g_next = (struct grp *)salloc(sizeof *gp);
		gp = gp->g_next;
	}
	gp->g_next = NULL;
}
示例#2
0
void
load(void){
	register int c;
	register struct blk *p,*q;
	struct blk *t,*s;
	c = readc() & 0377;
	sptr = stable[c];
	if(sptr != 0){
		p = sptr->val;
		if(c >= ARRAYST){
			q = salloc(length(p));
			rewind(p);
			while(sfeof(p) == 0){
				s = dcgetwd(p);
				if(s == 0){putwd(q, (struct blk *)NULL);}
				else{
					t = copy(s,length(s));
					putwd(q,t);
				}
			}
			pushp(q);
		}
		else{
			q = copy(p,length(p));
			pushp(q);
		}
	}
	else{
		q = salloc(1);
		sputc(q,0);
		pushp(q);
	}
	return;
}
示例#3
0
struct blk *
removr(struct blk *p,int n)
{
	int nn;
	register struct blk *q,*s,*r;

	rewind(p);
	nn = (n+1)/2;
	q = salloc(nn);
	while(n>1){
		sputc(q,sgetc(p));
		n -= 2;
	}
	r = salloc(2);
	while(sfeof(p) == 0)sputc(r,sgetc(p));
	release(p);
	if(n == 1){
		s = dcdiv(r,tenptr);
		release(r);
		rewind(rem);
		if(sfeof(rem) == 0)sputc(q,sgetc(rem));
		release(rem);
		irem = q;
		return(s);
	}
	irem = q;
	return(r);
}
示例#4
0
文件: main.c 项目: elbing/apex
void inlineeq(void)
{
	int ds, n, sz1 = 0;

	n = curfile->lineno;
	if (szstack[0] != 0)
		printf(".nr %d \\n(.s\n", sz1 = salloc());
	ds = salloc();
	printf(".rm %d \n", ds);
	display = 0;
	do {
		if (*in)
			printf(".as %d \"%s\n", ds, in);
		init();
		yyparse();
		if (eqnreg > 0) {
			printf(".as %d \\*(%d\n", ds, eqnreg);
			sfree(eqnreg);
			printf(".lf %d\n", curfile->lineno+1);
		}
	} while (getline(in) == lefteq);
	if (*in)
		printf(".as %d \"%s", ds, in);
	if (sz1)
		printf("\\s\\n(%d", sz1);
	printf("\\*(%d\n", ds);
	printf(".lf %d\n", curfile->lineno+1);
	if (curfile->lineno > n+3)
		fprintf(stderr, "eqn warning: multi-line %c...%c, file %s:%d,%d\n",
			lefteq, righteq, curfile->fname, n, curfile->lineno);
	sfree(ds);
	if (sz1) sfree(sz1);
}
示例#5
0
/*
 * Put user selection information in internal format.
 */
void
selectuser(const char *str)
{
	struct user *up;
	size_t sz;
	const char *endstr;

	up = seluser = (struct user *)salloc(sizeof *up);
	for (;;) {
		up->u_uid = -1;
		if ((endstr = strchr(str, ',')) == NULL)
			endstr = str + strlen(str);
		sz = endstr - str;
		up->u_name = salloc(sz + 1);
		memcpy(up->u_name, str, sz);
		up->u_name[sz] = '\0';
		if (getpwnam(up->u_name) == NULL) {
			fprintf(stderr, "%s was not found\n", up->u_name);
			exit(1);
		}
		if (*endstr == '\0' || *(str = endstr + 1) == '\0')
			break;
		up->u_next = (struct user *)salloc(sizeof *up);
		up = up->u_next;
	}
	up->u_next = NULL;
}
示例#6
0
Blk*
getdec(Blk *p, int sc)
{
	int cc;
	Blk *q, *t, *s;

	rewind(p);
	if(length(p)*2 < sc) {
		q = copy(p,length(p));
		return(q);
	}
	q = salloc(length(p));
	while(sc >= 1) {
		sputc(q,sgetc(p));
		sc -= 2;
	}
	if(sc != 0) {
		t = mult(q,tenptr);
		s = salloc(cc = length(q));
		release(q);
		rewind(t);
		while(cc-- > 0)
			sputc(s,sgetc(t));
		sputc(s,0);
		release(t);
		t = div(s,tenptr);
		release(s);
		release(rem);
		return(t);
	}
	return(q);
}
/**
 * @function Gui_DemoFileBrowser
 * @brief File browser demo
 * @param signal_t sig: unused
 * @return none
 */
void Gui_DemoFileBrowser(signal_t sig) {

  rect_st rec;
  coord_t hEntry, y, pitch;

  Gui_DemoNewPage("built-in file browser");

  /*allocate memory for storing file paths*/
  if(path_file == NULL) path_file = salloc(PATH_BUFF_SIZE);
  if(path_folder == NULL) path_folder = salloc(PATH_BUFF_SIZE);
  if(path_file != NULL && path_folder != NULL) {

    SetFont(G_FONT_DEFAULT);
    hEntry = P2D_GetTextHeight() + 4;
    pitch = hEntry - 3;
    y = 20;

    /**
     * widgets for file selection
     */
    path_file[0] = 0;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "Select a file"); y += pitch;

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, path_file, PATH_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_OPEN);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_SELECT_FILE);

    /**
     * widgets for folder selection
     */
    path_folder[0] = 0;
    y += pitch*2;
    rec = GUI_Rect(15, y, 295, hEntry);
    GUI_W_TextAdd(&rec, "Select a folder"); y += pitch;

    rec = GUI_Rect(15, y, 265, hEntry);
    GUI_W_UsrEntryAdd(&rec, path_folder, PATH_BUFF_SIZE, false);

    rec = GUI_Rect(285, y, hEntry, hEntry);
    GUI_W_ButtonAdd(&rec, NULL, G_IMG_OPEN);
    GUI_SetSignal(E_PUSHED_TO_RELEASED, SIG_SELECT_FOLDER);

    /* => page creation is now completed. Jump to the page's handler*/
    GUI_SetUserTask(Gui_DemoFileBrowserHandler);
  }
  else {

    /*critical: salloc error*/
    CleanExit();
  }
}
示例#8
0
/*
====================================================================
Create an all empty levelset.
====================================================================
*/
LevelSet *levelset_create_empty( int count, char *author, char *name )
{
	int i;
	LevelSet *set = salloc( 1, sizeof( LevelSet ) );
	
	strcpy( set->name, name );
	set->count = count;
	set->levels = salloc( count, sizeof( Level* ) );
	for ( i = 0; i < count; i++ )
		set->levels[i] = level_create_empty( author, name );
	set->version = 1; set->update = 0;
	return set;
}
示例#9
0
/**
 * @function GUI_W_GraphAdd
 * @brief add graph container
 * @param const rect_st *_rec: graph dimension
 * @param uint16_t refreshTime: refresh period, in ms
 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error.
 */
g_obj_st /*@null@*/ *GUI_W_GraphAdd(const rect_st *_rec, e_grid_type grid, uint16_t refreshTime) {

  g_obj_st *g_obj = NULL, *res = NULL;
  graph_st *graph = NULL;
  uint16_t cnt;
  int32_t i32;

  /*check parameters*/
  if(_rec != NULL && _rec->w > 2) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate & init the graph*/
      graph = salloc(sizeof(graph_st));
      if(graph != NULL) {

        graph->curve = NULL;
        graph->refreshTime = refreshTime;
        graph->timer = 0;
        graph->colBack = 0; //GetColor(G_COL_E_BACKGROUND);
        graph->colGrid = P2D_Color(9, 190, 247); //GetColor(G_COL_TEXT);

        if(grid >= _GRAPH_GRID_CNT) grid = GRAPH_GRID_DISABLED;
        graph->fGrid = arGrid[grid];

        /*allocate the display LUT; => 256 entries (8bits)*/
        graph->lut = salloc(sizeof(coord_t) * 256);
        if(graph->lut != NULL) {

          /*performs <value to coord> translation only one time, use LUT when displaying*/
          for(cnt = 0; cnt < 256; cnt++) {
            i32 = _rec->y + _rec->h - 1;
            i32 = i32 - (((int32_t)cnt * _rec->h) / 256);
            graph->lut[cnt] = (coord_t) i32;
          }

          /*linkage between generic obj & graph*/
          g_obj->rec = *_rec;
          g_obj->draw = GraphDraw;
          g_obj->task = GraphRefresh;
          g_obj->obj = graph;

          res = g_obj;
        }
      }
    }
  }
  return res;
}
示例#10
0
文件: pconf.c 项目: 4auka/cmusphinx
/* env_scan: substitutes environment values into a string */
static char *
env_scan(char const *str)
{
    extern char *getenv();
    char buf[1024];		/* buffer for temp use */
    register char *p = buf;	/* holds place in the buffer */
    char var[50];		/* holds the name of the env variable */
    char *val;

    while (*str)
	if (*str == '$') {
	    if (*++str == '$') {
		*p++ = *str++;
		continue;
	    }
	    val = var;
	    while (isalnum((unsigned char) *str) || *str == '_')
		*val++ = *str++;
	    *p = '\0';
	    val = (val == var) ? "$" : getenv(var);
	    if (val) {
		strcat(p, val);
		p += strlen(val);
	    }
	} else
	    *p++ = *str++;
    *p = '\0';
    return salloc(buf);
}
示例#11
0
string::string(const char *p, int n) : len(n)
{
  assert(n >= 0);
  ptr = salloc(n, &sz);
  if (n != 0)
    memcpy(ptr, p, n);
}
示例#12
0
/*
 * Turn a list of names into a string of the same names.
 */
char*
detract(struct header* hp, unsigned long flags)
{
	Walk_str_t	ws;

	if (flags & GNAME) {
		if (hp->h_names) {
			if (flags & GCOMMA)
				note(DEBUG, "detract asked to insert commas");
			ws.sep = (flags & GCOMMA) ? 2 : 1;
			ws.flags = flags &= ~GCOMMA;
			ws.count = 0;
			ws.base = ws.next = 0;
			dictwalk(&hp->h_names, stringize, &ws);
			if (ws.count) {
				ws.base = ws.next = salloc(ws.count + 2);
				ws.sep--;
				dictwalk(&hp->h_names, stringize, &ws);
				return ws.base;
			}
		}
	}
	else if (flags & GSUB)
		return hp->h_subject;
	return 0;
}
示例#13
0
文件: reader.c 项目: knusbaum/Wily
static void
updateBody(rdWin *w, ulong p0, ulong p1, char *str)
{
	char *newbuf;
	ulong newlen;

	assert(w);
	if (w->body == 0)
		return;
	if (str)
		newlen = w->bodylen + p1;
	else
		newlen = w->bodylen - (p1 - p0);
	newbuf = salloc(newlen);
	strncpy(newbuf, w->body, p0);
	if (str) {
		strncpy(newbuf + p0, str, p1);
		strcpy(newbuf + p0 + p1, w->body + p0);
	} else {
		strcpy(newbuf + p0, w->body + p1);
	}
	free(w->body);
	w->body = newbuf;
	w->bodylen = newlen;
}
示例#14
0
/**
 * @function GUI_AddKey
 * @brief ... add a key. Not safe outside the keyboard macro; that's why the file is not in the <widget> folder
 * @param const rect_st *rec: key dimension
 * @param const uint8_t *glyph: glyph array (size KBD_MAP_COUNT). One glyph per map
 * @return g_obj_st: NULL if error, pointer to the generic object otherwise
 */
g_obj_st /*@null@*/ *GUI_AddKey(const rect_st *rec, const uint8_t *glyph) {

  g_obj_st *g_obj = NULL, *res = NULL;
  key_st *key = NULL;

  /*check parameters*/
  if(rec != NULL && glyph != NULL && pMapId != NULL) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate a key*/
      key = salloc(sizeof(key_st));
      if(key != NULL) {

        /*key settings*/
        gmemcpy(key->glyph, glyph, KBD_MAP_COUNT * sizeof(key->glyph[0]));

        /*linkage between generic obj & key*/
        g_obj->rec = *rec;
        g_obj->draw = KeyDraw;
        g_obj->task = NULL;
        g_obj->obj = key;
        res = g_obj;
      }
    }
  }

  return res;
}
示例#15
0
/*
 * Extract a list of names from a line,
 * and make a list of names from it.
 */
void
extract(struct header* hp, unsigned long flags, register char* s)
{
	register struct name*	np;
	register int		n;
	register struct list*	x;
	char			buf[LINESIZE];

	if (s) {
		note(DEBUG, "extract type=0x%08x data=\"%s\"%s", flags, s, (hp->h_clear & flags) ? " [clear]" : "");
		if (flags & GNAME) {
			if (hp->h_clear & flags) {
				hp->h_clear &= ~flags;
				dictwalk(&hp->h_names, clear, &flags);
			}
			while (s = yankword(s, buf))
				if (np = dictsearch(&hp->h_names, buf, INSERT|IGNORECASE|STACK)) {
					np->flags = flags;
					hp->h_flags |= flags;
					if (!hp->h_first && (flags & GTO) || (flags & GFIRST)) {
						flags &= ~GFIRST;
						hp->h_first = np->name;
					}
				}
		}
		else if (flags & GSUB) {
			hp->h_clear &= ~flags;
			if (!*s) {
				hp->h_flags &= ~flags;
				hp->h_subject = 0;
			}
			else if (!hp->h_subject || !streq(hp->h_subject, s)) {
				hp->h_flags |= flags;
				hp->h_subject = savestr(s);
			}
		}
		else if (flags & GMISC) {
			if (hp->h_clear & flags) {
				hp->h_clear &= ~flags;
				hp->h_misc.head = hp->h_misc.tail = 0;
			}
			if (*s) {
				if ((n = strlen(s)) > 0 && s[n - 1] == '\n')
					s[--n] = 0;
				for (x = hp->h_misc.head; x; x = x->next)
					if (streq(x->name, s))
						return;
				hp->h_flags |= flags;
				x = (struct list*)salloc(sizeof(struct list) + n + 1);
				strcpy(x->name, s);
				x->next = 0;
				if (hp->h_misc.tail)
					hp->h_misc.tail->next = x;
				else
					hp->h_misc.head = x;
				hp->h_misc.tail = x;
			}
		}
	}
}
示例#16
0
void dlist_push_back(dlist_t *l, void *n)
{
    // Allocate a dlist node
    dlist_node_t *s = (dlist_node_t *)salloc(dlist_node_salloc_id);
    //assert(s);
    s->node = n;
    
    kthread_mutex_lock(&l->lock);
    
    // Push back
    s->next = NULL;
    s->prev = l->tail;
    
    if (l->tail) {
        l->tail->next = s;
    }
    l->tail = s;
    
    if (!l->head) {
        l->head = s;
    }
    
    l->count++;
    
    kthread_mutex_unlock(&l->lock);
}
示例#17
0
文件: exec.c 项目: knusbaum/Wily
/*
 * Run 'cmd' with arg 'arg' in View 'v'.
 *
 * 'arg' may be null, 'cmd' must be nonnull.
 */
void
run(View *v, char *cmd, char *arg) {
	char	*buf, *buf2;
	char	*a2;

	cmd += strspn(cmd, whitespace);
	if(!*cmd)
		return;

	/*
	 * For builtins, we want to separate cmd and arg,
	 * and if we're passed a pointer to 'arg', we must pass
	 * one on to builtin, even if the arg is just whitespace.
	 */
	if(arg) {
		buf = salloc( strlen(cmd) + strlen(arg) + 2);
		sprintf(buf, "%s %s", cmd, arg);
	} else {
		buf = strdup(cmd);
	}
	buf2 = strdup(buf);	/* before we scribble over buf */

	cmd = strtok(buf, whitespace);
	assert(*cmd && !isspace(*cmd));

	a2 = strtok(0, "");
	if(!a2)
		a2 = arg;

	if(!builtin(v, cmd, a2))
		ex_run(v, buf2);

	free (buf);
	free (buf2);
}
示例#18
0
soundfile_t *
soundfile_open_read(const char *path) {
	dp(30, "path=%s \n", path);
	soundfile_t *s = salloc(sizeof *s);
	s->m = sft_read;
	if 	(g_regex_match_simple ("\\.wv$", path, 0, 0)) {
		char error[80] = {0};
	    int flags = 0;
	    int norm_offset = 0;
		s->t = sft_wavpack;
	    s->p = WavpackOpenFileInput(path, error, flags, norm_offset);
		if (!s->p)
			die("can not open input file '%s'", path);
		s->bits_per_sample = WavpackGetBitsPerSample(s->p);
		s->channels = WavpackGetNumChannels(s->p);
		s->samplerate = WavpackGetSampleRate(s->p);
		s->frames = WavpackGetNumSamples(s->p);
	} else {
		SF_INFO	 	infile_info = {0};
		if (strcmp(path, "-"))
			s->p = sf_open(path, SFM_READ, &infile_info);
		else
			s->p = sf_open_fd(0, SFM_READ, &infile_info, 0);
		if (!s->p)
			die("can not open input file '%s'", path);
		s->t = sft_libsndfile;
		s->channels = infile_info.channels;
		s->samplerate = infile_info.samplerate;
		s->frames = infile_info.frames;
	}
	return s;
}
示例#19
0
文件: reader.c 项目: knusbaum/Wily
/*
 * add a new item to the end of the list
 */
int
rdAddItem(rdWin *w, char *text)
{
	rdItem **pi;
	rdItem *i;
	int len;
	char *sep = "\n";

	assert(w);
	assert(text);
	len = (int)strlen(text);
	if (w->wintype != rdList || !text || !*text) {
		DPRINT("addItem() call for non-list window");
		return 1;
	}
	i = salloc(sizeof(*i));
	for (pi = &w->items; *pi; pi = &((*pi)->next));
	*pi = i;
	i->p0 = w->bodylen;
	i->p1 = i->p0 + len;
	i->next = 0;
	if (rpc_insert(wilyq, w->id, i->p0, text) || rpc_insert(wilyq, w->id, i->p1++, sep)) {
		DPRINT("Could not insert item into window");
		return 1;
	}
	len += strlen(sep);
	w->bodylen += len;
	return 0;
}
示例#20
0
文件: reader.c 项目: knusbaum/Wily
void
rdBodyToFile(rdWin *w, char *filename)
{
	FILE *fp;
	char *buf;

	assert(w);
	assert(filename);
	buf = salloc(w->bodylen+1);
	if (rpc_settag(wilyq, w->id, "Sending... ")) {
		DPRINT("Could not change tag");
		return;
	}
	if (rpc_read(wilyq, w->id, 0, w->bodylen, buf)) {
		DPRINT("Could not retrieve body text");
		return;
	}
	if ((fp = fopen(filename, "w"))) {
		(void)fprintf(fp,"%s",buf);
		fclose(fp);
	} else {
		DPRINT("Could not write body text to a file");
	}
	free(buf);
	return;
}
示例#21
0
/**
 * @function GUI_AddGenericObject
 * @brief Allocate & initialize a new generic object
 * @param none
 * @return g_obj_st*: pointer to the object if success, NULL otherwise
 */
g_obj_st /*@null@*/ *GUI_AddGenericObject(void) {

  g_obj_st *obj = NULL;

  /*try to allocate memory for the new object*/
  obj = salloc(sizeof(g_obj_st));
  if(obj != NULL) {

    /*set default content for the new object*/
    gmemset(obj, 0, sizeof(g_obj_st));
    GUI_ObjSetNeedRefresh(obj, true);
    obj->group = group;

    /*insert object in the linked list (base or top layer)*/
    if(bTopLayerActive == false) {
      if(headBase == NULL) headBase = obj;
      else if(lastAddedObj != NULL) lastAddedObj->next = obj;
      else { /*cannot happen*/ }
    }
    else {
      if(headTop == NULL) headTop = obj;
      else if(lastAddedObj != NULL) lastAddedObj->next = obj;
      else { /*cannot happen*/ }
    }

    lastAddedObj = obj;
  }

  return obj;
}
示例#22
0
/*
 * Read /etc/shadow.
 */
void
readshadow(void)
{
#ifdef	SHADOW_PWD
	struct login *lp;
	struct spwd *sp;
	size_t sz;

	setspent();
	while (sp = getspent()) {
		if ((lp = findlogin(sp->sp_namp)) == NULL)
			continue;
		sz = strlen(sp->sp_pwdp);
		lp->l_pwdp = salloc(sz + 1);
		strcpy(lp->l_pwdp, sp->sp_pwdp);
		lp->l_lstchg = sp->sp_lstchg;
		lp->l_min = sp->sp_min;
		lp->l_max = sp->sp_max;
		lp->l_warn = sp->sp_warn;
		lp->l_inact = sp->sp_inact;
		lp->l_expire = sp->sp_expire;
		lp->l_flag = sp->sp_flag;
	}
	endspent();
#endif	/* SHADOW_PWD */
}
示例#23
0
/**
 * @function GUI_W_SliderAdd
 * @brief add a slider
 * @param const rect_st *rec: object dimension
 * @param uint8_t *pValue: pointer to the value of the slider (range[0-255])
 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error.
 */
g_obj_st /*@null@*/ *GUI_W_SliderAdd(const rect_st *rec, uint8_t *pValue) {

  g_obj_st *g_obj = NULL, *res = NULL;
  slider_st *slider = NULL;

  /*check parameters*/
  if(rec != NULL && pValue != NULL) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate & init the slider*/
      slider = salloc(sizeof(slider_st));
      if(slider != NULL) {
        slider->pValue = pValue;
        slider->value = *pValue;

        /*linkage between generic obj & slider*/
        g_obj->rec = *rec;
        g_obj->draw = SliderDraw;
        g_obj->task = SliderRefresh;
        g_obj->obj = slider;
        GUI_ObjSetFocusable(g_obj, true); /*slider is a focusable object*/
        res = g_obj;
      }
    }
  }
  return res;
}
示例#24
0
static r_type_ptr createBoolean(type_info* ti) {
    int* t = scalloc(1, sizeof(int));
	*t = 0;
    int** ret = salloc(sizeof(int*));
    *ret = t;
    return (r_type_ptr)ret;
}
示例#25
0
/**
 * @function GUI_W_TabParentAdd
 * @brief add a tab container
 * @param const rect_st *rec: object dimension
 * @param length_t tabHeight: height of the tabs
 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error.
 */
g_obj_st /*@null@*/ *GUI_W_TabParentAdd(const rect_st *rec, length_t tabHeight) {

  g_obj_st *g_obj = NULL, *res = NULL;
  parent_tab_st *parentTab = NULL;

  /*check parameters*/
  if(rec != NULL && rec->h > tabHeight) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate & init the graph*/
      parentTab = salloc(sizeof(parent_tab_st));
      if(parentTab != NULL) {

        parentTab->tab = NULL;
        parentTab->tabHeight = tabHeight;
        parentTab->tabPosX = rec->x;      /*first tab will start at this coord*/

        /*linkage between generic obj & graph*/
        g_obj->rec = *rec;
        g_obj->draw = ParentTabDraw;
        g_obj->task = NULL;
        g_obj->obj = parentTab;
        GUI_ObjSetStatic(g_obj, true); /*parent tab is static: no need to refresh when pressed*/

        res = g_obj;
      }
    }
  }
  return res;
}
示例#26
0
static r_type_ptr createFromBoolean(int I, type_info* ti) {
	int *space = scalloc(1, sizeof(int));
	*space = I;
	int** ret = salloc(sizeof(int*));
	*ret = space;
	return (r_type_ptr)ret;
}
示例#27
0
int 
mail(char **people)
{
	register char *cp2, *cp3;
	register int s;
	char *buf, **ap;
	struct header head;

	for (s = 0, ap = people; *ap; ap++)
		s += strlen(*ap) + 2;
	buf = (char *)salloc((unsigned)(s+1));
	cp2 = buf;
	for (ap = people; *ap; ap++) {
		for (cp3 = *ap; *cp3; ) {
			if (*cp3 == ' ' || *cp3 == '\t') {
				*cp3++ = ',';
				while (*cp3 == ' ' || *cp3 == '\t')
					cp3++;
			} else
				cp3++;
		}
		cp2 = copy(*ap, cp2);
		*cp2++ = ',';
		*cp2++ = ' ';
	}
	*cp2 = '\0';
	head.h_to = buf;
	head.h_subject = head.h_cc = head.h_bcc = head.h_defopt = NOSTR;
	head.h_others = NOSTRPTR;
	head.h_seq = 0;
	mail1(&head, Fflag, NOSTR);
	return(0);
}
示例#28
0
文件: over.c 项目: 99years/plan9
void boverb(int p1, int p2)
{
	int treg;
	double h, b, d, d1, d2;
	extern double Overgap, Overwid, Overline;

	treg = salloc();
	yyval = p1;
	d = EM(Overgap, ps);
	h = eht[p1] + eht[p2] + d;
	b = eht[p2] - d;
	dprintf(".\tS%d <- %d over %d; b=%g, h=%g\n", 
		yyval, p1, p2, b, h);
	nrwid(p1, ps, p1);
	nrwid(p2, ps, p2);
	printf(".nr %d \\n(%d\n", treg, p1);
	printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
	printf(".nr %d \\n(%d+%gm\n", treg, treg, Overwid);
	d2 = eht[p2]-ebase[p2]-d;	/* denom */
	printf(".ds %d \\v'%gm'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\v'%gm'\\\n", 
		yyval, REL(d2,ps), treg, p2, p2, REL(-d2,ps));
	d1 = 2 * d + ebase[p1];		/* num */
	printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gm'\\*(%d\\v'%gm'\\\n", 
		p2, p1, REL(-d1,ps), p1, REL(d1,ps));
	printf("\\h'-\\n(%du-\\n(%du/2u+%gm'\\v'%gm'\\l'\\n(%du-%gm'\\h'%gm'\\v'%gm'\n", 
		treg, p1, Overline, REL(-d,ps),
		treg, 2*Overline, Overline, REL(d,ps));
	ebase[yyval] = b;
	eht[yyval] = h;
	lfont[yyval] = rfont[yyval] = 0;
	sfree(p2);
	sfree(treg);
}
示例#29
0
/**
 * @function GUI_W_RadioAdd
 * @brief add a radio
 * @param const rect_st *rec: object dimension
 * @param const void *str: text of the checkbox (will be copied into it)
 * @param const uint8_t *pCurrentId: pointer to current id of the selected radio
 * @param uint8_t id: id of the radio
 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error.
 */
g_obj_st /*@null@*/ *GUI_W_RadioAdd(const rect_st *rec, const void /*@null@*/ *str, const uint8_t *pCurrentId, uint8_t id) {

  g_obj_st *g_obj = NULL, *res = NULL;
  radio_st *radio = NULL;

  /*check parameters*/
  if(rec != NULL && pCurrentId != NULL) {

    /*allocate a generic object*/
    g_obj = GUI_AddGenericObject();
    if(g_obj != NULL) {

      /*allocate & init the radio*/
      radio = salloc(sizeof(radio_st));
      if(radio != NULL) {

        radio->colorText = GetColor(G_COL_TEXT);
        radio->font = GetCurrentFont();
        radio->str = AllocateAndCopyStr(str);
        radio->pCurrentId = pCurrentId;
        radio->id = id;
        radio->state = *pCurrentId == id? 1: 0;

        /*linkage between generic obj & radio*/
        g_obj->rec = *rec;
        g_obj->draw = RadioDraw;
        g_obj->task = RadioRefresh;
        g_obj->obj = radio;
        GUI_ObjSetFocusable(g_obj, true); /*radio is a focusable object*/
        res = g_obj;
      }
    }
  }
  return res;
}
示例#30
0
文件: reader.c 项目: knusbaum/Wily
void
rdInclude(rdWin *w, char *str, size_t len)
{
	size_t nlines;
	char *buf;
	char *prefix = "> ";
	size_t nlen, plen = strlen(prefix);
	ulong p0, p1;

	assert(w);
	assert(str);
	nlines = countlines(str, len);
	if (rpc_addr(wilyq, w->id, ".", &p0, &p1)) {
		DPRINT("Could not get address of dot");
		return;
	}
	nlen = len + nlines*plen + 1;
	buf = salloc(nlen);
	prefixlines(str, len, prefix, plen, buf);
	if (rpc_insert(wilyq, w->id, p1, buf)) {
		DPRINT("Could not insert included text");
	}
	w->bodylen += nlen;
	free(buf);
}