本文整理汇总了C++中salloc函数的典型用法代码示例。如果您正苦于以下问题:C++ salloc函数的具体用法?C++ salloc怎么用?C++ salloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了salloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectgrp
/*
* 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: load
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: removr
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: inlineeq
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: selectuser
/*
* 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: getdec
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);
}
示例7: Gui_DemoFileBrowser
/**
* @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: salloc
/*
====================================================================
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: GUI_AddGenericObject
/**
* @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 /*@[email protected]*/ *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: env_scan
/* 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: len
string::string(const char *p, int n) : len(n)
{
assert(n >= 0);
ptr = salloc(n, &sz);
if (n != 0)
memcpy(ptr, p, n);
}
示例12: detract
/*
* 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: updateBody
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: GUI_AddGenericObject
/**
* @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 /*@[email protected]*/ *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: extract
/*
* 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;
}
}
}
}