本文整理汇总了C++中savestr函数的典型用法代码示例。如果您正苦于以下问题:C++ savestr函数的具体用法?C++ savestr怎么用?C++ savestr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了savestr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: change_env
/*
* Sets/unsets an environment variable from a pointer that may actually be a
* pointer into environ where the string should not be manipulated.
*/
static void
change_env(char *s, int set)
{
char *eqp;
char *ss;
ss = savestr(s);
if ((eqp = strchr(ss, '=')) != NULL)
*eqp = '\0';
if (set && eqp != NULL)
(void) setenv(ss, eqp + 1, 1);
else
(void) unsetenv(ss);
ckfree(ss);
return;
}
示例2: tryexec
static void
tryexec(char *cmd, char **argv, char **envp)
{
int e;
execve(cmd, argv, envp);
e = errno;
if (e == ENOEXEC) {
initshellproc();
setinputfile(cmd, 0);
commandname = arg0 = savestr(argv[0]);
setparam(argv + 1);
exraise(EXSHELLPROC);
/*NOTREACHED*/
}
errno = e;
}
示例3: sprintf
Screen_Obj *dup_so(QSP_ARG_DECL Screen_Obj *sop)
{
Screen_Obj *dup;
char name[BUF_LEN];
sprintf(name,"%s.dup",SOB_NAME(sop));
dup = simple_object(name);
if( sop == NULL ) return(sop);
SET_SOB_PARENT(dup, SOB_PARENT(sop) );
SET_SOB_PANEL(dup, SOB_PANEL(sop) );
#ifdef HAVE_MOTIF
SET_SOB_FRAME(dup, SOB_FRAME(sop) );
#endif /* HAVE_MOTIF */
SET_SOB_ACTION(dup,savestr(SOB_ACTION(sop)));
SET_SOB_SELECTOR(dup,NULL);
return(dup);
}
示例4: InstallFontSizes
DviFontSizeList *
InstallFontSizes (DviWidget dw, const char *x_name, Boolean *scalablep)
{
char fontNameString[2048];
char **fonts;
int i, count;
int size;
DviFontSizeList *sizes, *new_size;
XFontName fontName;
unsigned int fontNameAttributes;
*scalablep = FALSE;
if (!XParseFontName ((XFontNameString)x_name, &fontName,
&fontNameAttributes))
return 0;
fontNameAttributes &= ~(FontNamePixelSize|FontNamePointSize
|FontNameAverageWidth);
fontNameAttributes |= FontNameResolutionX;
fontNameAttributes |= FontNameResolutionY;
fontName.ResolutionX = dw->dvi.display_resolution;
fontName.ResolutionY = dw->dvi.display_resolution;
XFormatFontName (&fontName, fontNameAttributes, fontNameString);
fonts = XListFonts (XtDisplay (dw), fontNameString, 10000000, &count);
sizes = 0;
for (i = 0; i < count; i++) {
size = ConvertFontNameToSize (fonts[i]);
if (size == 0) {
DisposeFontSizes (dw, sizes);
sizes = 0;
*scalablep = TRUE;
break;
}
if (size != -1) {
new_size = (DviFontSizeList *) XtMalloc (sizeof *new_size);
new_size->next = sizes;
new_size->size = size;
new_size->x_name = savestr (fonts[i]);
new_size->doesnt_exist = 0;
new_size->font = 0;
sizes = new_size;
}
}
XFreeFontNames (fonts);
return sizes;
}
示例5: storedatt
VOID storedatt(PNE pne)
{
int i;
NEAL(pne) = (struct ad *)rmalloc((1+ADN(al))*ADSZ);
memcpy((UNIV)NEAL(pne), (UNIV)al, (1+ADN(al))*ADSZ);
for (i = 1; i <= (int)ADN(al); i++) {
if (GET(ADFLAGS(al, i), ASPEC))
ds.attdef += ADLEN(al, i);
if (NEAL(pne)[i].addef != 0)
NEAL(pne)[i].addef = savestr(NEAL(pne)[i].addef);
}
ds.attcnt += AN(al); /* Number of attributes defined. */
#if 0
/* I can't see any reason to increase AVGRPCNT here. */
ds.attgcnt += ADN(al) - AN(al); /* Number of att grp members. */
#endif
}
示例6: arpafix
/*
* Deal with arpa net addresses. The way this is done is strange.
* name contains an "@" or "%". Look up the machine after it in
* the hash table. If it isn't found, return name unmolested.
* If ???, return name unmolested.
* Otherwise, delete the "@" or "%" and the machine after it from
* name, and return the new string.
*/
static char *
arpafix(char name[], char from[])
{
register char *cp;
register int arpamach;
char newname[BUFSIZ];
if (debug) {
fprintf(stderr, "arpafix(%s, %s)\n", name, from);
}
cp = strrchr(name, '@');
if (cp == NOSTR)
cp = strrchr(name, '%');
if (cp == NOSTR) {
fprintf(stderr,
gettext("Something's amiss -- no @ or %% in arpafix\n"));
return(name);
}
cp++;
arpamach = netlook(cp, '@');
if (debug)
fprintf(stderr,
"cp '%s', arpamach %o, nettypes arpamach %o LOCAL %o\n",
cp, arpamach, nettype(arpamach), nettype(LOCAL));
if (arpamach == 0) {
if (debug)
fprintf(stderr, "machine %s unknown, uses: %s\n",
cp, name);
return(name);
}
if (((nettype(arpamach) & nettype(LOCAL)) & ~AN) == 0) {
if (debug)
fprintf(stderr, "machine %s known but remote, uses: %s\n",
cp, name);
return(name);
}
nstrcpy(newname, sizeof (newname), name);
cp = strrchr(newname, '@');
if (cp == NOSTR)
cp = strrchr(newname, '%');
*cp = 0;
if (debug) fprintf(stderr, "local address, return '%s'\n", newname);
return(savestr(newname));
}
示例7: use_selected
int
use_selected()
{
register SUBJECT *sp;
register ARTICLE *ap;
bool want_read;
char *cmdstr;
int len, ret = 1;
int subj_mask = (sel_mode == SM_THREAD? (SF_THREAD|SF_VISIT) : SF_VISIT);
if (!finish_command(TRUE)) /* get rest of command */
return 0;
if (!buf[1])
return -1;
cmdstr = savestr(buf+1);
want_read = (sel_rereading || *cmdstr =='m');
perform_cnt = 0;
page_line = 1;
len = strlen(cmdstr);
/* A few commands can just loop through the subjects. */
if ((len == 1 && (*cmdstr == 't' || *cmdstr == 'J'))
|| (len == 2
&& (((*cmdstr == '+' || *cmdstr == '-') && cmdstr[0] == cmdstr[1])
|| *cmdstr == 'T'))) {
for (sp = first_subject; sp; sp = sp->next) {
if ((sp->flags & subj_mask) == subj_mask) {
artp = first_art(sp);
if (artp) {
art = article_num(artp);
if (perform(cmdstr, FALSE)) {
fputs("\nInterrupted\n", stdout) FLUSH;
goto break_out;
}
}
#ifdef VERBOSE
IF(verbose)
if (mode != 't' && *cmdstr != 't' && *cmdstr != 'T')
putchar('\n') FLUSH;
#endif
}
}
} else if (strEQ(cmdstr, "E")) {
示例8: LookupFontSizeBySize
static DviFontSizeList *
LookupFontSizeBySize (DviWidget dw, DviFontList *f, int size)
{
DviFontSizeList *fs, *best = 0, *smallest = 0;
int bestsize = 0;
XFontName fontName;
unsigned int fontNameAttributes;
char fontNameString[2048];
int decipointsize;
if (f->scalable) {
decipointsize = (10*size)/dw->dvi.sizescale;
for (best = f->sizes; best; best = best->next)
if (best->size == decipointsize)
return best;
best = (DviFontSizeList *) XtMalloc(sizeof *best);
best->next = f->sizes;
best->size = decipointsize;
f->sizes = best;
XParseFontName (f->x_name, &fontName, &fontNameAttributes);
fontNameAttributes &= ~(FontNamePixelSize|FontNameAverageWidth);
fontNameAttributes |= FontNameResolutionX;
fontNameAttributes |= FontNameResolutionY;
fontNameAttributes |= FontNamePointSize;
fontName.ResolutionX = dw->dvi.display_resolution;
fontName.ResolutionY = dw->dvi.display_resolution;
fontName.PointSize = decipointsize;
XFormatFontName (&fontName, fontNameAttributes, fontNameString);
best->x_name = savestr (fontNameString);
best->doesnt_exist = 0;
best->font = 0;
return best;
}
for (fs = f->sizes; fs; fs=fs->next) {
if (dw->dvi.sizescale*fs->size <= 10*size
&& fs->size >= bestsize) {
best = fs;
bestsize = fs->size;
}
if (smallest == 0 || fs->size < smallest->size)
smallest = fs;
}
return best ? best : smallest;
}
示例9: get_arch_name_from_types
/*
* get_arch_name_from_types() returns the name of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns a pointer
* to the an allocated string "cputype X cpusubtype Y" where X and Y are decimal
* values.
*/
__private_extern__
const char *
get_arch_name_from_types(
cpu_type_t cputype,
cpu_subtype_t cpusubtype)
{
unsigned long i;
char *p;
for(i = 0; arch_flags[i].name != NULL; i++){
if(arch_flags[i].cputype == cputype &&
arch_flags[i].cpusubtype == cpusubtype)
return(arch_flags[i].name);
}
p = savestr("cputype 1234567890 cpusubtype 1234567890");
if(p != NULL)
sprintf(p, "cputype %u cpusubtype %u", cputype, cpusubtype);
return(p);
}
示例10: setparam
void
setparam(char **argv)
{
char **newparam;
char **ap;
int nparam;
for (nparam = 0 ; argv[nparam] ; nparam++);
ap = newparam = ckmalloc((nparam + 1) * sizeof *ap);
while (*argv) {
*ap++ = savestr(*argv++);
}
*ap = NULL;
freeparam(&shellparam);
shellparam.malloc = 1;
shellparam.nparam = nparam;
shellparam.p = newparam;
shellparam.optnext = NULL;
}
示例11: setparam
static void
setparam(int argc, char **argv)
{
char **newparam;
char **ap;
ap = newparam = ckmalloc((argc + 1) * sizeof *ap);
while (*argv) {
*ap++ = savestr(*argv++);
}
*ap = NULL;
freeparam(&shellparam);
shellparam.malloc = 1;
shellparam.nparam = argc;
shellparam.p = newparam;
shellparam.optp = NULL;
shellparam.reset = 1;
shellparam.optnext = NULL;
}
示例12: Dfix1
/*
* $ substitute one word, for i/o redirection
*/
tchar *
Dfix1(tchar *cp)
{
tchar *Dv[2];
#ifdef TRACE
tprintf("TRACE- Dfix1()\n");
#endif
if (noexec)
return (0);
Dv[0] = cp; Dv[1] = NOSTR;
Dfix2(Dv);
if (gargc != 1) {
setname(cp);
bferr("Ambiguous");
}
cp = savestr(gargv[0]);
blkfree(gargv), gargv = 0;
return (cp);
}
示例13: readlast
void
readlast()
{
if ((tmpfp = fopen(lastfile,"r")) != NULL) {
if (fgets(buf,sizeof buf,tmpfp) != NULL) {
long old_last = lasttime;
buf[strlen(buf)-1] = '\0';
if (*buf) {
safefree0(lastngname);
lastngname = savestr(buf);
}
fscanf(tmpfp,"%ld %ld %ld %ld",&lasttime,&lastactsiz,
&lastnewtime,&lastextranum);
if (!lastnewtime)
lastnewtime = starttime;
if (old_last > lasttime)
lasttime = old_last;
}
fclose(tmpfp);
}
}
示例14: ec_add
/* Add a ethernet code to the database */
int
ec_add(register u_int32_t o, register char *text)
{
if (ec_last >= ec_len) {
if (list == NULL) {
ec_len = 512;
list = malloc(ec_len * sizeof(*list));
} else {
ec_len *= 2;
list = realloc(list, ec_len * sizeof(*list));
}
if (list == NULL) {
syslog(LOG_ERR, "ec_add(): malloc: %m");
exit(1);
}
}
list[ec_last].o = o;
list[ec_last].text = savestr(text);
++ec_last;
return (1);
}
示例15: varset
void
varset( /* set a variable's value */
char *vname,
int assign,
double val
)
{
char *qname;
EPNODE *ep1, *ep2;
/* get qualified name */
qname = qualname(vname, 0);
/* check for quick set */
if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM &&
(ep1->type == ':') <= (assign == ':')) {
ep2 = ep1->v.kid->sibling;
if (ep2->type == NUM) {
ep2->v.num = val;
ep1->type = assign;
return;
}
}
/* hand build definition */
ep1 = newnode();
ep1->type = assign;
ep2 = newnode();
ep2->type = SYM;
ep2->v.name = savestr(vname);
addekid(ep1, ep2);
ep2 = newnode();
ep2->type = NUM;
ep2->v.num = val;
addekid(ep1, ep2);
if (assign == ':')
dremove(qname);
else
dclear(qname);
dpush(qname, ep1);
}