Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461/**************************************************************************23util2.c4Colin Ramsay ([email protected])56 Dec 0067ADVANCED COSET ENUMERATOR, Version 3.00189Copyright 200010Centre for Discrete Mathematics and Computing,11Department of Mathematics and12Department of Computer Science & Electrical Engineering,13The University of Queensland, QLD 4072.14(http://staff.itee.uq.edu.au/havas)1516These are the utilities for Level 2 of ACE.1718**************************************************************************/1920#include "al2.h"2122#include <string.h>23#include <ctype.h>24#include <sys/types.h>25#include <time.h>2627/******************************************************************28void al2_init(void)2930One-off initialisation of the Level 2 stuff, and all lower levels.31Note that there is no need to initialise, for example, intarr[].32******************************************************************/3334void al2_init(void)35{36al1_init();3738okstart = okcont = okredo = FALSE;39tabinfo = tabindex = FALSE;40lresult = -8192; /* invalid mode ! */4142echo = FALSE;43skipnl = TRUE;4445currip = currkey[0] = currname[0] = '\0';4647currword = NULL;48currsiz = currexp = 0;4950intcnt = 0;5152srand((unsigned int)time(NULL)); /* Seed rand() with time */53}5455/******************************************************************56char *al2_strdup(char *s)5758strdup() is not ANSI C, so this is our version. Should we regard59an error as fatal, and abort?60******************************************************************/6162char *al2_strdup(char *s)63{64char *t;6566if ((t = malloc(strlen(s)+1)) == NULL)67{ al2_continue("out of memory in al2_strdup()"); }6869return(strcpy(t,s));70}7172/******************************************************************73int al2_outlen(int i)7475Returns the print-length of an integer i (i.e., ~ $\log_{10}i$).76The int i is assumed to satisfy i >= 0.77******************************************************************/7879int al2_outlen(int i)80{81int len = 1;8283while ((i /= 10) != 0)84{ len++; }8586return(len);87}8889/**************************************************************************90All Level 2 errors are filtered by one of the following three handlers.91These take the appropriate action, and then jump back to the top-level92main() routine; ie, the outermost level of Level 2. We swallow the93remainder of any input line (possibly losing some commands); so multi-line94commands in error may not be properly tidied-up. The question of what95exactly to do if fip/fop are not stdin/stdout is put in the `too hard'96basket; we simply switch them both back to their defaults. Note that,97although the code for _continue() & _restart() is the same, they return to98different points (& do different things) in main().99100Warning: The error-handling is fairly basic, since it's not our intent to101develop a fully-fledged interactive interface. We simply tidy-up the best102we can and carry on.103**************************************************************************/104105/******************************************************************106void al2_continue(char *msg)107108An error has occurred, but it doesn't affected the ok... flags, or109the table's validity.110******************************************************************/111112void al2_continue(char *msg)113{114if (fop != stdout)115{116if (fop != NULL)117{ fclose(fop); }118fop = stdout;119}120if (fip != stdin)121{122if (fip != NULL)123{ fclose(fip); }124fip = stdin;125currip = '\0';126}127128fflush(fop);129fprintf(fop, "** ERROR (continuing with next line)\n");130fprintf(fop, " %s\n", msg);131132while ( !(currip == '\n' || currip == '\r' || currip == EOF) )133{ al2_nextip(); }134135longjmp(env,1);136}137138/******************************************************************139void al2_restart(char *msg)140141Something nasty has happened & we'll be disallowing continue/redo.142******************************************************************/143144void al2_restart(char *msg)145{146if (fop != stdout)147{148if (fop != NULL)149{ fclose(fop); }150fop = stdout;151}152if (fip != stdin)153{154if (fip != NULL)155{ fclose(fip); }156fip = stdin;157currip = '\0';158}159160fflush(fop);161fprintf(fop, "** ERROR (restarting with next line)\n");162fprintf(fop, " %s\n", msg);163164while ( !(currip == '\n' || currip == '\r' || currip == EOF) )165{ al2_nextip(); }166167longjmp(env,2);168}169170/******************************************************************171void al2_abort(char *msg)172173No point in being clever here, we're going to stop.174******************************************************************/175176void al2_abort(char *msg)177{178if (fop != stdout)179{180if (fop != NULL)181{ fclose(fop); }182fop = stdout;183}184if (fip != stdin)185{186if (fip != NULL)187{ fclose(fip); }188fip = stdin;189currip = '\0';190}191192fflush(fop);193fprintf(fop, "** ERROR (aborting)\n");194fprintf(fop, " %s\n", msg);195196longjmp(env,3);197}198199/******************************************************************200void al2_aip(char *name)201202Switch to a new input file. We abort via _restart() if this is not203possible, and that call will reset fip/fop properly.204******************************************************************/205206void al2_aip(char *name)207{208/* Close the current input file (unless it is 'stdin'). */209210if (fip != stdin && fip != NULL)211{ fclose(fip); }212fip = NULL;213214/* Try to open the new input file (unless it is 'stdin'). */215216if (strcmp(name, "stdin") != 0)217{218if ((fip = fopen(name, "r")) == NULL)219{ al2_restart("can't open new input, using 'stdin'"); }220}221else222{ fip = stdin; }223224currip = '\0'; /* Initialise current i/p char. */225}226227/******************************************************************228void al2_aop(char *name)229230Switch to a new output file. We abort via _restart() if this is231not possible, and that call will reset fip/fop properly. Note232that there is no need to run setvbuf() on stdout, since this was233done in the call to al0_init().234******************************************************************/235236void al2_aop(char *name)237{238/* Close the current output file (unless it is 'stdout'). */239240if (fop != stdout && fop != NULL)241{ fclose(fop); }242fop = NULL;243244/* Try to open the new output file (unless it is 'stdout'). */245246if (strcmp(name, "stdout") != 0)247{248if ((fop = fopen(name, "w")) == NULL)249{ fprintf(fop, "can't open new output, using 'stdout'"); }250else251{ setvbuf(fop, NULL, _IOLBF, 0); } /* line buffered o/p */252}253else254{ fop = stdout; }255}256257/******************************************************************258void al2_dump(Logic allofit)259260Dump out the internals of Level 2 of ACE, working through al2.h261more or less in order.262******************************************************************/263264void al2_dump(Logic allofit)265{266int i;267268fprintf(fop, " #---- %s: Level 2 Dump ----\n", ACE_VER);269270/* env; - nothing (meaningful) we can do here! */271272/* okstart, okcont, okredo; */273fprintf(fop, "okstart=%d okcont=%d okredo=%d\n",274okstart, okcont, okredo);275276/* tabinfo, tabindex, lresult */277fprintf(fop, "tabinfo=%d tabindex=%d lresult=%d\n",278tabinfo, tabindex, lresult);279280/* echo, skipnl, currip, currkey, currname; */281fprintf(fop, "echo=%d skipnl=%d currip=%d", echo, skipnl, currip);282if (isprint(currip))283{ fprintf(fop, "(%c)\n", currip); }284else285{ fprintf(fop, "\n"); }286fprintf(fop, "currkey=%s\n", currkey);287fprintf(fop, "currname=%s\n", currname);288289/* *currword, currsiz, currexp; */290fprintf(fop, "currsize=%d currexp=%d currword=", currsiz, currexp);291if (currword == NULL)292{ fprintf(fop, "NULL"); }293else294{295if (allofit)296{297for (i = 0; i < currsiz; i++)298{ fprintf(fop, "%d ", currword[i]); }299}300else301{ fprintf(fop, "non-NULL"); }302}303fprintf(fop, "\n");304305/* intcnt, intarr[32]; */306if (intcnt == 0)307{ fprintf(fop, "intcnt=0 (empty)\n"); }308else309{310fprintf(fop, "intcnt=%d intarr[]=", intcnt);311for (i = 0; i < intcnt; i++)312{ fprintf(fop, "%d ", intarr[i]); }313fprintf(fop, "\n");314}315316fprintf(fop, " #---------------------------------\n");317}318319/******************************************************************320void al2_opt(void)321322Pretty-print the date of compilation and all the various options323included in this build.324******************************************************************/325326void al2_opt(void)327{328#ifdef DATE329fprintf(fop, "%s executable built:\n %s\n", ACE_VER, DATE);330#else331fprintf(fop, "%s executable built: ??\n", ACE_VER);332#endif333334fprintf(fop, "Level 0 options:\n");335#ifdef AL0_STAT336fprintf(fop, " statistics package = on\n");337#else338fprintf(fop, " statistics package = off\n");339#endif340#ifdef AL0_CC341fprintf(fop, " coinc processing messages = on\n");342#else343fprintf(fop, " coinc processing messages = off\n");344#endif345#ifdef AL0_DD346fprintf(fop, " dedn processing messages = on\n");347#else348fprintf(fop, " dedn processing messages = off\n");349#endif350351fprintf(fop, "Level 1 options:\n");352#ifdef AL1_BINARY353fprintf(fop, " workspace multipliers = binary\n");354#else355fprintf(fop, " workspace multipliers = decimal\n");356#endif357358fprintf(fop, "Level 2 options:\n");359#ifdef AL2_HINFO360fprintf(fop, " host info = on\n");361#else362fprintf(fop, " host info = off\n");363#endif364}365366/******************************************************************367void al2_help(void)368******************************************************************/369370void al2_help(void)371{372fprintf(fop, " #---- %s: Level 2 Help ----\n", ACE_VER);373fprintf(fop, "add gen[erators] / sg : <word list> ;\n");374fprintf(fop, "add rel[ators] / rl : <relation list> ;\n");375fprintf(fop, "aep : 1..7 ;\n");376fprintf(fop, "ai / alter i[nput] : [<filename>] ;\n");377fprintf(fop, "ao / alter o[utput] : [<filename>] ;\n");378fprintf(fop, "as[is] : [0/1] ;\n");379fprintf(fop, "beg[in] / end / start ;\n");380fprintf(fop, "bye / exit / q[uit] ;\n");381fprintf(fop, "cc / coset coinc[idence] : int ;\n");382fprintf(fop, "c[factor] / ct[ factor] : [int] ;\n");383fprintf(fop, "check / redo ;\n");384fprintf(fop, "com[paction] : [0..100] ;\n");385fprintf(fop, "cont[inue] ;\n");386fprintf(fop, "cy[cles] ;\n");387fprintf(fop, "ded mo[de] / dmod[e] : [0..4] ;\n");388fprintf(fop, "ded si[ze] / dsiz[e] : [0/1..] ;\n");389fprintf(fop, "def[ault] ;\n");390fprintf(fop, "del gen[erators] / ds : <int list> ;\n");391fprintf(fop, "del rel[ators] / dr : <int list> ;\n");392fprintf(fop, "d[ump] : [0/1/2[,0/1]] ;\n");393fprintf(fop, "easy ;\n");394fprintf(fop, "echo : [0/1] ;\n");395fprintf(fop, "enum[eration] / group name : <string> ;\n");396fprintf(fop, "fel[sch] : [0/1] ;\n");397fprintf(fop, "f[factor] / fi[ll factor] : [0/1..] ;\n");398fprintf(fop, "gen[erators] / subgroup gen[erators] : <word list> ;\n");399fprintf(fop, "gr[oup generators]: [<letter list> / int] ;\n");400fprintf(fop, "group relators / rel[ators] : <relation list> ;\n");401fprintf(fop, "hard ;\n");402fprintf(fop, "h[elp] ;\n");403fprintf(fop, "hlt ;\n");404fprintf(fop, "ho[le limit] : [-1/0..100] ;\n");405fprintf(fop, "look[ahead] : [0/1..4] ;\n");406fprintf(fop, "loop[ limit] : [0/1..] ;\n");407fprintf(fop, "max[ cosets] : [0/2..] ;\n");408fprintf(fop, "mend[elsohn] : [0/1] ;\n");409fprintf(fop, "mess[ages] / mon[itor] : [int] ;\n");410fprintf(fop, "mo[de] ;\n");411fprintf(fop, "nc / normal[ closure] : [0/1] ;\n");412fprintf(fop, "no[ relators in subgroup] : [-1/0/1..] ;\n");413fprintf(fop, "oo / order[ option] : int ;\n");414fprintf(fop, "opt[ions] ;\n");415fprintf(fop, "par[ameters] ; - old option (ignored)\n");416fprintf(fop, "path[ compression] : [0/1] ;\n");417fprintf(fop, "pd mo[de] / pmod[e] : [0/1..3] ;\n");418fprintf(fop, "pd si[ze] / psiz[e] : [0/2/4/8/...] ;\n");419fprintf(fop, "print det[ails] / sr : [int] ;\n");420fprintf(fop, "pr[int table] : [[-]int[,int[,int]]] ;\n");421fprintf(fop, "pure c[t] ;\n");422fprintf(fop, "pure r[t] ;\n");423fprintf(fop, "rc / random coinc[idences]: int[,int] ;\n");424fprintf(fop, "rec[over] / contig[uous] ;\n");425fprintf(fop, "rep : 1..7[,int] ;\n");426fprintf(fop, "restart ; - old option (ignored)\n");427fprintf(fop, "r[factor] / rt[ factor] : [int] ;\n");428fprintf(fop, "row[ filling] : [0/1] ;\n");429fprintf(fop, "sc / stabil[ising cosets] : int ;\n");430fprintf(fop, "sims : 1/3/5/7/9 ;\n");431fprintf(fop, "st[andard table] ;\n");432#ifdef AL0_STAT433fprintf(fop, "stat[istics] / stats ;\n");434#endif435fprintf(fop, "style ;\n");436fprintf(fop, "subg[roup name] : <string> ;\n");437fprintf(fop, "sys[tem] : <string> ;\n");438fprintf(fop, "text : <string> ;\n");439fprintf(fop, "ti[me limit] : [-1/0/1..] ;\n");440fprintf(fop, "tw / trace[ word] : int,<word> ;\n");441fprintf(fop, "wo[rkspace] : [int[k/m/g]] ;\n");442fprintf(fop, "# ... <newline> - a comment (ignored)\n");443fprintf(fop, " #---------------------------------\n");444}445446/******************************************************************447void al2_nextip(void)448449Primes currip with the next character from fip, if we're not at the450end-of-file. Echoes the character if echo is on.451******************************************************************/452453void al2_nextip(void)454{455if (currip != EOF)456{457currip = fgetc(fip);458459if (echo && currip != EOF)460{ fputc(currip, fop); }461}462}463464/******************************************************************465void al2_skipws(void)466467Skip all whitespace characters.468******************************************************************/469470void al2_skipws(void)471{472Logic comment = (currip == '#');473474while ( currip == ' ' || currip == '\t' || comment ||475(skipnl && (currip == '\n' || currip == '\r')) )476{477al2_nextip();478comment = (currip == '#' ||479(comment && currip != '\n' && currip != '\r' && currip != EOF));480}481}482483/******************************************************************484void al2_nextnw(void)485486Skip to the next non-whitespace character.487******************************************************************/488489void al2_nextnw(void)490{491al2_nextip();492al2_skipws();493}494495496497498