本文整理汇总了C++中AGALOC函数的典型用法代码示例。如果您正苦于以下问题:C++ AGALOC函数的具体用法?C++ AGALOC怎么用?C++ AGALOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AGALOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_number
/**
* Associate a name with strtol() value, defaulting to zero.
*
* @param[in,out] pp argument list to add to
* @param[in] name the name of the "suboption"
* @param[in] nm_len the length of the name
* @param[in] val the numeric value for the suboption
* @param[in] d_len the length of the value
*
* @returns the new value structure
*/
static tOptionValue *
add_number(void ** pp, char const * name, size_t nm_len,
char const * val, size_t d_len)
{
size_t sz = nm_len + sizeof(tOptionValue) + 1;
tOptionValue * new_val = AGALOC(sz, "int val");
/*
* Scan over whitespace is constrained by "d_len"
*/
while (IS_WHITESPACE_CHAR(*val) && (d_len > 0)) {
d_len--; val++;
}
if (d_len == 0)
new_val->v.longVal = 0;
else
new_val->v.longVal = strtol(val, 0, 0);
new_val->valType = OPARG_TYPE_NUMERIC;
new_val->pzName = (char *)(new_val + 1);
memcpy(new_val->pzName, name, nm_len);
new_val->pzName[ nm_len ] = NUL;
addArgListEntry(pp, new_val);
return new_val;
}
示例2: manageAllocatedData
void
manageAllocatedData(void* pd)
{
static int allocPtrCt = 0;
static int usedPtrCt = 0;
static void** papAllocData = NULL;
if (pd == NULL) {
void** pp = papAllocData;
if (pp == NULL)
return;
while (--usedPtrCt >= 0)
AGFREE(*(pp++));
AGFREE(papAllocData);
papAllocData = NULL;
} else {
if (++usedPtrCt > allocPtrCt) {
allocPtrCt += 16;
papAllocData = (usedPtrCt > 1)
? AGREALOC(papAllocData, allocPtrCt * sizeof(void*), "atbl")
: AGALOC(allocPtrCt * sizeof(void*), "atbl");
}
papAllocData[usedPtrCt-1] = pd;
}
}
示例3: trim_xml_text
/**
* Find the end marker for the named section of XML.
* Trim that text there, trimming trailing white space for all modes
* except for OPTION_LOAD_UNCOOKED.
*/
static char *
trim_xml_text(char * intxt, char const * pznm, tOptionLoadMode mode)
{
static char const fmt[] = "</%s>";
size_t len = strlen(pznm) + sizeof(fmt) - 2 /* for %s */;
char * etext;
{
char z[64], *pz = z;
if (len >= sizeof(z))
pz = AGALOC(len, "scan name");
len = (size_t)sprintf(pz, fmt, pznm);
*intxt = ' ';
etext = strstr(intxt, pz);
if (pz != z) AGFREE(pz);
}
if (etext == NULL)
return etext;
{
char * result = etext + len;
if (mode != OPTION_LOAD_UNCOOKED)
etext = SPN_WHITESPACE_BACK(intxt, etext);
*etext = NUL;
return result;
}
}
示例4: optionTimeDate
/*=export_func optionTimeDate
* private:
*
* what: process an option with a time and date.
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
*
* doc:
* Decipher a time and date value.
=*/
void
optionTimeDate(tOptions * pOpts, tOptDesc * pOD)
{
#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV)
if ((! HAS_pzPkgDataDir(pOpts)) || (pOpts->pzPkgDataDir == NULL))
goto default_action;
/*
* Export the DATEMSK environment variable. getdate_r() uses it to
* find the file with the strptime formats. If we cannot find the file
* we need ($PKGDATADIR/datemsk), then fall back to just a time duration.
*/
{
static char * envptr = NULL;
if (envptr == NULL) {
static char const fmt[] = "DATEMSK=%s/datemsk";
envptr = AGALOC(sizeof(fmt) + strlen(pOpts->pzPkgDataDir), fmt);
sprintf(envptr, fmt, pOpts->pzPkgDataDir);
putenv(envptr);
}
if (access(envptr+8, R_OK) != 0)
goto default_action;
}
/*
* Convert the date to a time since the epoch and stash it in a long int.
*/
{
struct tm stm;
time_t tm;
if (getdate_r(pOD->optArg.argString, &stm) != 0) {
fprintf(stderr, zNotDate, pOpts->pzProgName,
pOD->optArg.argString);
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
return;
}
tm = mktime(&stm);
if (pOD->fOptState & OPTST_ALLOC_ARG) {
AGFREE(pOD->optArg.argString);
pOD->fOptState &= ~OPTST_ALLOC_ARG;
}
pOD->optArg.argInt = tm;
}
return;
default_action:
#endif
optionTimeVal(pOpts, pOD);
if (pOD->optArg.argInt != BAD_TIME)
pOD->optArg.argInt += (unsigned long)time(NULL);
}
示例5: Select_Match_Full
/*=gfunc string_eqv_match_p
*
* what: caseless regex match
* general_use:
*
* exparg: text, text to test for pattern
* exparg: match, pattern/substring to search for
*
* string: "~"
*
* doc: Test to see if a string fully matches a pattern.
* Case is not significant, but any character equivalences
* must be expressed in your regular expression.
=*/
static tSuccess
Select_Match_Full(char const * sample, char const * pattern)
{
regmatch_t m[2];
/*
* On the first call for this macro, compile the expression
*/
if (pCurMacro->funcPrivate == NULL) {
void * mat = (void *)pattern;
regex_t* pRe = AGALOC(sizeof(*pRe), "select match full re");
if (OPT_VALUE_TRACE > TRACE_EXPRESSIONS) {
fprintf(pfTrace, "Compiling ``%s'' with bits 0x%lX\n",
pattern, pCurMacro->res);
}
compile_re(pRe, mat, (int)pCurMacro->res);
pCurMacro->funcPrivate = pRe;
}
if (regexec((regex_t*)pCurMacro->funcPrivate, sample, (size_t)2, m, 0)
!= 0)
return FAILURE;
if ( (m[0].rm_eo != strlen( sample ))
|| (m[0].rm_so != 0))
return FAILURE;
return SUCCESS;
}
示例6: make_quote_str
/**
* make a name resilient to machinations made by 'make'.
* Basically, dollar sign characters are doubled.
*
* @param str the input string
* @returns a newly allocated string with the '$' characters doubled
*/
static char const *
make_quote_str(char const * str)
{
size_t sz = strlen(str) + 1;
char const * scan = str;
char * res;
for (;;) {
char * p = strchr(scan, '$');
if (p == NULL)
break;
sz++;
scan = scan + 1;
}
res = AGALOC(sz, "q name");
scan = res;
for (;;) {
char * p = strchr(str, '$');
if (p == NULL)
break;
sz = (size_t)(p - str) + 1;
memcpy(res, str, sz);
res += sz;
str += sz;
*(res++) = '$';
}
strcpy(res, str);
return scan;
}
示例7: open_tmp_usage
static FILE *
open_tmp_usage(char ** buf)
{
char * bf;
size_t bfsz;
{
unsigned int my_pid = (unsigned int)getpid();
char const * tmpdir = getenv(TMPDIR);
if (tmpdir == NULL)
tmpdir = tmp_dir;
bfsz = TMP_FILE_FMT_LEN + strlen(tmpdir) + 10;
bf = AGALOC(bfsz, "tmp fil");
snprintf(bf, bfsz, TMP_FILE_FMT, tmpdir, my_pid);
}
{
static mode_t const cmask = S_IRWXO | S_IRWXG;
mode_t svmsk = umask(cmask);
int fd = mkstemp(bf);
(void)umask(svmsk);
if (fd < 0) {
AGFREE(bf);
return NULL;
}
*buf = bf;
return fdopen(fd, "w");
}
}
示例8: mk_pager_cmd
static char *
mk_pager_cmd(char const * fname)
{
/*
* Page the file and remove it when done. For shell script processing,
* we must redirect the output to the current stderr, otherwise stdout.
*/
fclose(option_usage_fp);
option_usage_fp = NULL;
{
char const * pager = (char const *)getenv(PAGER_NAME);
size_t bfsz;
char * res;
/*
* Use the "more(1)" program if "PAGER" has not been defined
*/
if (pager == NULL)
pager = MORE_STR;
bfsz = strlen(fname) + strlen(pager) + PAGE_USAGE_FMT_LEN;
res = AGALOC(bfsz, "more cmd");
snprintf(res, bfsz, PAGE_USAGE_FMT, pager, fname);
AGFREE((void*)(intptr_t)fname);
return res;
}
}
示例9: add_bool
/**
* Associate a name with a boolean value
*
* @param[in,out] pp argument list to add to
* @param[in] name the name of the "suboption"
* @param[in] nm_len the length of the name
* @param[in] val the boolean value for the suboption
* @param[in] d_len the length of the value
*
* @returns the new value structure
*/
static tOptionValue *
add_bool(void ** pp, char const * name, size_t nm_len,
char const * val, size_t d_len)
{
size_t sz = nm_len + sizeof(tOptionValue) + 1;
tOptionValue * new_val = AGALOC(sz, "bool val");
/*
* Scan over whitespace is constrained by "d_len"
*/
while (IS_WHITESPACE_CHAR(*val) && (d_len > 0)) {
d_len--; val++;
}
if (d_len == 0)
new_val->v.boolVal = 0;
else if (IS_DEC_DIGIT_CHAR(*val))
new_val->v.boolVal = (unsigned)atoi(val);
else new_val->v.boolVal = ! IS_FALSE_TYPE_CHAR(*val);
new_val->valType = OPARG_TYPE_BOOLEAN;
new_val->pzName = (char *)(new_val + 1);
memcpy(new_val->pzName, name, nm_len);
new_val->pzName[ nm_len ] = NUL;
addArgListEntry(pp, new_val);
return new_val;
}
示例10: shell_stringify
static SCM
shell_stringify(SCM obj, uint_t qt)
{
char * pzNew;
size_t dtaSize = 3;
char * pzDta = ag_scm2zchars(obj, "AG Object");
char * pz = pzDta;
for (;;) {
char c = *(pz++);
switch (c) {
case NUL:
goto loopDone1;
case '"': case '`': case '\\':
dtaSize += 2;
break;
default:
dtaSize++;
}
} loopDone1:;
pzNew = AGALOC(dtaSize, "shell string");
dtaSize = stringify_for_sh(pzNew, qt, pzDta);
{
SCM res = AG_SCM_STR2SCM(pzNew, dtaSize);
AGFREE(pzNew);
return res;
}
}
示例11: prt_set_arg
/**
* Print the bits set in a bit mask option.
* We call the option handling function with a magic value for
* the options pointer and it allocates and fills in the string.
* We print that with a call to prt_entry().
*
* @param[in] fp the file pointer to write to
* @param[in] od the option descriptor with a bit mask value type
*/
static void
prt_set_arg(FILE * fp, tOptDesc * od)
{
char * list = optionMemberList(od);
size_t len = strlen(list);
char * buf = (char *)AGALOC(len + 3, "dir name");
*buf= '=';
memcpy(buf+1, list, len + 1);
prt_entry(fp, od, buf);
AGFREE(buf);
AGFREE(list);
}
示例12: check_existence
/**
* Make sure the directory containing the subject file exists and that
* the file exists or does not exist, per the option requirements.
*
* @param ftype file existence type flags
* @param pOpts program option descriptor
* @param pOD the option descriptor
*/
static void
check_existence(teOptFileType ftype, tOptions * pOpts, tOptDesc * pOD)
{
char const * fname = pOD->optArg.argString;
struct stat sb;
errno = 0;
switch (ftype & FTYPE_MODE_EXIST_MASK) {
case FTYPE_MODE_MUST_NOT_EXIST:
if ((stat(fname, &sb) == 0) || (errno != ENOENT)) {
if (errno == 0)
errno = EINVAL;
fserr_exit(pOpts->pzProgName, "stat", fname);
/* NOTREACHED */
}
/* FALLTHROUGH */
default:
case FTYPE_MODE_MAY_EXIST:
{
char * p = strrchr(fname, DIRCH);
size_t l;
if (p == NULL)
/*
* The file may or may not exist and its directory is ".".
* Assume that "." exists.
*/
break;
l = (size_t)(p - fname);
p = AGALOC(l + 1, "fname");
memcpy(p, fname, l);
p[l] = NUL;
if ((stat(p, &sb) != 0) || (errno = EINVAL, ! S_ISDIR(sb.st_mode)))
fserr_exit(pOpts->pzProgName, "stat", p);
/* NOTREACHED */
AGFREE(p);
break;
}
case FTYPE_MODE_MUST_EXIST:
if ( (stat(fname, &sb) != 0)
|| (errno = EINVAL, ! S_ISREG(sb.st_mode)) )
fserr_exit(pOpts->pzProgName, "stat", fname);
/* NOTREACHED */
break;
}
}
示例13: strdup
static char *
strdup( char const *s )
{
char *cp;
if (s == NULL)
return NULL;
cp = (char *) AGALOC((unsigned) (strlen(s)+1), "strdup");
if (cp != NULL)
(void) strcpy(cp, s);
return cp;
}
示例14: load_old_output
/**
* Load the previous shell script output file. We need to preserve any
* hand-edited additions outside of the START_MARK and END_MARKs.
*
* @param[in] fname the output file name
*/
static char *
load_old_output(char const * fname)
{
/*
* IF we cannot stat the file,
* THEN assume we are creating a new file.
* Skip the loading of the old data.
*/
FILE * fp = fopen(fname, "r" FOPEN_BINARY_FLAG);
struct stat stbf;
char * text;
char * scan;
if (fp == NULL)
return NULL;
/*
* If we opened it, we should be able to stat it and it needs
* to be a regular file
*/
if ((fstat(fileno(fp), &stbf) != 0) || (! S_ISREG(stbf.st_mode))) {
fprintf(stderr, zNotFile, fname);
exit(EXIT_FAILURE);
}
scan = text = AGALOC(stbf.st_size + 1, "f data");
/*
* Read in all the data as fast as our OS will let us.
*/
for (;;) {
int inct = fread((void*)scan, (size_t)1, stbf.st_size, fp);
if (inct == 0)
break;
stbf.st_size -= inct;
if (stbf.st_size == 0)
break;
scan += inct;
}
*scan = NUL;
fclose(fp);
return text;
}
示例15: set_memb_names
static void
set_memb_names(tOptions * opts, tOptDesc * od, char const * const * nm_list,
unsigned int nm_ct)
{
char * pz;
uintptr_t mask = (1UL << (uintptr_t)nm_ct) - 1UL;
uintptr_t bits = (uintptr_t)od->optCookie & mask;
unsigned int ix = 0;
size_t len = 1;
/*
* Replace the enumeration value with the name string.
* First, determine the needed length, then allocate and fill in.
*/
while (bits != 0) {
if (bits & 1)
len += strlen(nm_list[ix]) + PLUS_STR_LEN + 1;
if (++ix >= nm_ct) break;
bits >>= 1;
}
od->optArg.argString = pz = AGALOC(len, "enum");
bits = (uintptr_t)od->optCookie & mask;
if (bits == 0) {
*pz = NUL;
return;
}
for (ix = 0; ; ix++) {
size_t nln;
int doit = bits & 1;
bits >>= 1;
if (doit == 0)
continue;
nln = strlen(nm_list[ix]);
memcpy(pz, nm_list[ix], nln);
pz += nln;
if (bits == 0)
break;
memcpy(pz, PLUS_STR, PLUS_STR_LEN);
pz += PLUS_STR_LEN;
}
*pz = NUL;
(void)opts;
}