util2.c Colin Ramsay (cram@itee.uq.edu.au) 6 Dec 00
ADVANCED COSET ENUMERATOR, Version 3.001
Copyright 2000 Centre for Discrete Mathematics and Computing, Department of Mathematics and Department of Computer Science & Electrical Engineering, The University of Queensland, QLD 4072. (http://staff.itee.uq.edu.au/havas)
One-off initialisation of the Level 2 stuff, and all lower levels. Note that there is no need to initialise, for example, intarr[].
******************************************************************/
strdup() is not ANSI C, so this is our version. Should we regard an error as fatal, and abort?
******************************************************************/
char *al2_strdup(char *s)
{ char *t;
if ((t = malloc(strlen(s)+1)) == NULL)
{ al2_continue("out of memory in al2_strdup()"); }
return(strcpy(t,s));
}
/****************************************************************** int al2_outlen(int i)
Returns the print-length of an integer i (i.e., ~ $\log_{10}i$). The int i is assumed to satisfy i >= 0.
******************************************************************/
int al2_outlen(int i)
{ int len = 1;
while ((i /= 10) != 0)
{ len++; }
return(len);
}
/************************************************************************** All Level 2 errors are filtered by one of the following three handlers. These take the appropriate action, and then jump back to the top-level main() routine; ie, the outermost level of Level 2. We swallow the remainder of any input line (possibly losing some commands); so multi-line commands in error may not be properly tidied-up. The question of what exactly to do if fip/fop are not stdin/stdout is put in the `too hard' basket; we simply switch them both back to their defaults. Note that, although the code for _continue() & _restart() is the same, they return to different points (& do different things) in main().
Warning: The error-handling is fairly basic, since it's not our intent to develop a fully-fledged interactive interface. We simply tidy-up the best we can and carry on.
**************************************************************************/
An error has occurred, but it doesn't affected the ok... flags, or the table's validity.
******************************************************************/
void al2_continue(char *msg)
{ if (fop != stdout)
{ if (fop != NULL)
{ fclose(fop); }
fop = stdout;
} if (fip != stdin)
{ if (fip != NULL)
{ fclose(fip); }
fip = stdin;
currip = '\0';
}
fflush(fop);
fprintf(fop, "** ERROR (continuing with next line)\n");
fprintf(fop, " %s\n", msg);
Switch to a new input file. We abort via _restart() if this is not possible, and that call will reset fip/fop properly.
******************************************************************/
void al2_aip(char *name)
{ /* Close the current input file (unless it is 'stdin'). */
Switch to a new output file. We abort via _restart() if this is not possible, and that call will reset fip/fop properly. Note that there is no need to run setvbuf() on stdout, since this was done in the call to al0_init().
******************************************************************/
void al2_aop(char *name)
{ /* Close the current output file (unless it is 'stdout'). */
Dump out the internals of Level 2 of ACE, working through al2.h more or less in order.
******************************************************************/
Pretty-print the date of compilation and all the various options included in this build.
******************************************************************/
Primes currip with the next character from fip, if we're not at the end-of-file. Echoes the character if echo is on.
******************************************************************/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.