Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/tool/jhton.c view on Meta::CPAN
size_t size = 0; // total bytes needed.
char * result; // string to return.
// DETERMINE SPACE NEEDED:
va_start(Parg, String);
for (stringN = String;
stringN != PCNULL;
stringN = va_arg(Parg, char *))
{
size += strlen(stringN);
}
va_end(Parg);
// ALLOCATE SPACE, CONCATENATE STRINGS:
*(result = (char *) Malloc((size_t) (size + 1))) = CHNULL;
va_start(Parg, String);
for (stringN = String;
stringN != PCNULL;
stringN = va_arg(Parg, char *))
{
if (stringN1 != PCNULL) free((void *) stringN1);
stringN1 = stringN; // all but last string.
(void) strcat(result, stringN);
}
va_end(Parg);
return(result);
} // StrSaveN()
// ****************************************************************************
// M A L L O C
//
// Do a malloc() with error checking.
FUNCTION void * Malloc(
size_t Size) // bytes to get.
{
void * Pm; // pointer to memory.
if ((Pm = malloc(Size)) == (void *) NULL)
Error(ERREXIT, errno, "Cannot malloc %d bytes", Size);
return(Pm);
} // Malloc()
// ****************************************************************************
// U S A G E
//
// Print usage messages (char *gc_usage[]) to stderr and exit with ERREXIT.
// Follow each message line by a newline.
FUNCTION void Usage(void)
{
int which = 0; // current line.
while (gc_usage[which] != PCNULL)
{
(void) fprintf(stderr, gc_usage[which++], gc_myname);
(void) putc('\n', stderr);
}
exit(ERREXIT);
} // Usage()
// ****************************************************************************
// E R R O R
//
// Given an exit value (NOEXIT, ERREXIT, or USAGE), an errno value (NOERRNO if
// none), a message (printf) string, and zero or more argument strings, print
// an error message to stderr and, if exitvalue is NOEXIT, return; if USAGE,
// print a pointer to the program's usage message; otherwise exit with the
// value.
//
// Message is preceded by "<myname>: " using global gc_myname, and by
// "Warning: " for NOEXIT, and followed by a period and newline. If myerrno
// (system error number) is not NOERRNO, a relevant message is appended before
// the period.
FUNCTION void Error(
int Exitvalue, // or NOEXIT for warning.
int MyErrno, // system errno if relevant.
char * Message, ...)
{
va_list Parg; // place in arg list.
(void) fprintf(stderr, "%s: ", gc_myname);
if (Exitvalue == NOEXIT) (void) fputs("Warning: ", stderr);
va_start(Parg, Message);
(void) vfprintf(stderr, Message, Parg);
va_end(Parg);
if (MyErrno != NOERRNO)
{
(void) fprintf(stderr, ": %s (errno = %d)", strerror(MyErrno),
MyErrno);
}
(void) putc('.', stderr);
(void) putc('\n', stderr);
if (Exitvalue == USAGE)
{
(void) fprintf(stderr, "For a usage summary, run %s -?\n",
gc_myname);
}
DBGCODE(DumpTree(g_Pdnhead, /* Depth = */ 0, /* Separator = */ FALSE);)
if (Exitvalue != NOEXIT)
exit(Exitvalue);
} // Error()
#ifdef DEBUG
// ****************************************************************************
// D U M P T R E E
//
// Dump to stdout a representation of the docnode tree under g_Pdnhead.
// Recursively traverse the tree in-order (parent then child then sibling).
FUNCTION void DumpTree(
Pdn_t Pdn, // first node of current sibling list.
int Depth, // current depth.
bool_t Separator) // print a separator line after a long dump.
{
int indent; // for counting to Depth.
// Check if enabled:
if (getenv("DUMP") == PCNULL)
{
PUTS(".\\\" $DUMP not set; DumpTree() disabled.\n");
return;
}
// Check for empty tree:
if ((Depth == 0) && (Pdn == PDNNULL))
{
PUTS("Head pointer is null.\n");
return;
}
// Print siblings and each of their children, indented to Depth after the node
// address:
while (Pdn != PDNNULL)
{
(void) printf("%lx ", (unsigned long) Pdn);
for (indent = 0; indent <= Depth; ++indent) PUTC('.');
(void) printf(" %-5s %3d %c %lx %lx \"%s\"\n",
((Pdn -> dn_type) == DN_TYPE_TEXT) ?
"text" : TAG(Pdn -> dn_type),
Pdn -> dn_linenum,
(Pdn->dn_closed) ? 'c' : 'o',
Pdn -> dn_Pparent,
Pdn -> dn_Pprev,
Pdn -> dn_text);
( run in 0.946 second using v1.01-cache-2.11-cpan-39bf76dae61 )