/* showg.c version 2.1; B D McKay, August 2017. Formerlycalledreadg.c. Thisisastand-aloneeditionoflistg.cthatdoesnot neednautyoranyotherfiles.Uselistginpreference
if you have installed it. */
#define HELPTEXT \ " Write graphs in human-readable format.\n\
\n\
infile is the input file in graph6, sparse6 or digraph6 format\n\ This program does not support incremental sparse6 files; use listg.\n\
outfile is the output file\n\
Defaults are standard input and standard output.\n\
\n\
-p#, -p#:#, -p#-# : only display one graph or a sequence of\n\
graphs. The first graph is number 1. A second number\n\
which is empty or zero means infinity.\n\
\n\
-a : write the adjacency matrix\n\
-A : same as -a with a space between entries\n\
-d : write output to satisfy dreadnaut\n\
-c : write compact dreadnaut form with minimal line-breaks\n\
-e : write a list of edges, preceded by the order and the\n\
number of edges\n\
\n\
-o# : specify number of first vertex (default is 0)\n\
-t : write upper triangle only (affects -a, -A, -d anddefault)\n\
-F : write a form-feed after each graph except the last\n\
-l# : specify screen width limit (default78, 0 means no limit)\n\ This is not currently implemented with -a or -A.\n\
-q : suppress auxiliary output\n\
\n\
-a, -A, -c, -d and -e are incompatible.\n"
/* Remove errno: too hard to get portable without configuration *#ifdefined(__unix)||defined(__unix__)||defined(unix)||\ defined(__ppc__) #include<errno.h> #else interrno=0; #endif #defineABORT(msg){if(errno!=0)perror(msg);exit(1);}
*/
/* extern long ftell(FILE*); Should be in stdio.h */
static FILE*
opengraphfile(char *filename, int *codetype, int assumefixed, long position)
{
FILE *f; int c,firstc; long i,l,pos,pos1,pos2;
boolean bad_header;
if (filename == NULL)
f = stdin; else
{
f = fopen(filename,"r"); if (f == NULL)
{
fprintf(stderr,">E opengraphfile: can't open %s\n",filename); return NULL;
}
}
firstc = c = getc(f); if (c == EOF)
{
*codetype = GRAPH6; return f;
}
if (c != '>')
{
*codetype = firstc == ':' ? SPARSE6 : firstc == '&' ? DIGRAPH6 : GRAPH6;
ungetc(c,f);
} else
{
bad_header = FALSE; if ((c = getc(f)) == EOF || c != '>')
bad_header = TRUE; if (!bad_header &&
((c = getc(f)) == EOF || (c != 'g' && c != 's')))
bad_header = TRUE; if (!bad_header && c == 'g')
{ if ((c = getc(f)) == EOF || c != 'r' ||
(c = getc(f)) == EOF || c != 'a' ||
(c = getc(f)) == EOF || c != 'p' ||
(c = getc(f)) == EOF || c != 'h' ||
(c = getc(f)) == EOF || c != '6' ||
(c = getc(f)) == EOF || c != '<' ||
(c = getc(f)) == EOF || c != '<')
bad_header = TRUE; else
*codetype = GRAPH6 | HAS_HEADER;
} elseif (!bad_header && c == 'd')
{ if ((c = getc(f)) == EOF || c != 'i' ||
(c = getc(f)) == EOF || c != 'g' ||
(c = getc(f)) == EOF || c != 'r' ||
(c = getc(f)) == EOF || c != 'a' ||
(c = getc(f)) == EOF || c != 'p' ||
(c = getc(f)) == EOF || c != 'h' ||
(c = getc(f)) == EOF || c != '6' ||
(c = getc(f)) == EOF || c != '<' ||
(c = getc(f)) == EOF || c != '<')
bad_header = TRUE; else
*codetype = DIGRAPH6 | HAS_HEADER;
} elseif (!bad_header && c == 's')
{ if ((c = getc(f)) == EOF || c != 'p' ||
(c = getc(f)) == EOF || c != 'a' ||
(c = getc(f)) == EOF || c != 'r' ||
(c = getc(f)) == EOF || c != 's' ||
(c = getc(f)) == EOF || c != 'e' ||
(c = getc(f)) == EOF || c != '6' ||
(c = getc(f)) == EOF || c != '<' ||
(c = getc(f)) == EOF || c != '<')
bad_header = TRUE; else
*codetype = SPARSE6 | HAS_HEADER;
} if (bad_header)
{
fprintf(stderr,">E opengraphfile: illegal header in %s\n",
filename == NULL ? "stdin" : filename);
*codetype = UNKNOWN_TYPE | HAS_HEADER; return NULL;
}
}
if (position <= 1) return f;
if (filename == NULL || !assumefixed || (*codetype&SPARSE6)
|| firstc == ':')
{
l = 1; while ((c = getc(f)) != EOF)
{ if (c == '\n')
{
++l; if (l == position) break;
}
} if (l == position) return f;
fprintf(stderr, ">E opengraphfile: can't find line %ld in %s\n",position,
filename == NULL ? "stdin" : filename); return NULL;
} else
{
pos1 = ftell(f); if (pos1 < 0)
{
fprintf(stderr,">E opengraphfile: error on first ftell\n"); return NULL;
}
for (i = 1; (c = getc(f)) != EOF && c != '\n'; ++i) {}
ogf_linelen = i;
if (c == EOF)
{
fprintf(stderr, ">E opengraphfile: required record no present\n"); return NULL;
}
pos2 = ftell(f); if (pos2 < 0)
{
fprintf(stderr,">E opengraphfile: error on second ftell\n"); return NULL;
}
staticchar*
showg_getline(FILE *f) /* read a line with error checking */ /* includes \n (if present) and \0.
Immediate EOF causes NULL return. */
{
DYNALLSTAT(char,s,s_sz); int c; long i;
DYNALLOC1(char,s,s_sz,500,"showg_getline");
i = 0; while ((c = getc(f)) != EOF && c != '\n')
{ if (i == s_sz-2) DYNREALLOC(char,s,s_sz,s_sz+1000,"showg_getline");
s[i++] = c;
}
staticvoid
stringtograph(char *s, graph *g, int m) /* Convert string (graph6, digraph6 or sparse6 format) to graph. */ /* Assumes g is big enough to hold it. */
{ char *p; int n,i,j,k,v,x,nb,need;
size_t ii;
set *gi,*gj;
boolean done;
n = graphsize(s); if (n == 0) return;
p = s + (s[0] == ':' || s[0] == '&') + SIZELEN(n);
if (TIMESWORDSIZE(m) < n)
gt_abort(">E stringtograph: impossible m value\n");
if (s[0] != ':' && s[0] != '&') /* graph6 format */
{
k = 1; for (j = 1; j < n; ++j)
{
gj = GRAPHROW(g,j,m);
for (i = 0; i < j; ++i)
{ if (--k == 0)
{
k = 6;
x = *(p++) - BIAS6;
}
if ((x & TOPBIT6))
{
gi = GRAPHROW(g,i,m);
ADDELEMENT(gi,j);
ADDELEMENT(gj,i);
}
x <<= 1;
}
}
} elseif (s[0] == '&')
{
k = 1; for (i = 0; i < n; ++i)
{
gi = GRAPHROW(g,i,m);
for (j = 0; j < n; ++j)
{ if (--k == 0)
{
k = 6;
x = *(p++) - BIAS6;
}
if ((x & TOPBIT6))
{
ADDELEMENT(gi,j);
}
x <<= 1;
}
}
} else/* sparse6 format */
{ for (i = n-1, nb = 0; i != 0 ; i >>= 1, ++nb) {}
k = 0;
v = 0;
done = FALSE; while (!done)
{ if (k == 0)
{
x = *(p++); if (x == '\n' || x == '\0')
{
done = TRUE; continue;
} else
{
x -= BIAS6; k = 6;
}
} if ((x & B(k))) ++v;
--k;
need = nb;
j = 0; while (need > 0 && !done)
{ if (k == 0)
{
x = *(p++); if (x == '\n' || x == '\0')
{
done = TRUE; continue;
} else
{
x -= BIAS6; k = 6;
}
} if (need >= k)
{
j = (j << k) | (x & M(k));
need -= k; k = 0;
} else
{
k -= need;
j = (j << need) | ((x >> k) & M(need));
need = 0;
}
} if (done) continue;
if (j > v)
v = j; elseif (v < n)
{
ADDELEMENT(GRAPHROW(g,v,m),j);
ADDELEMENT(GRAPHROW(g,j,m),v);
}
}
}
}
graph* /* read graph into nauty format */
readgg(FILE *f, graph *g, int reqm, int *pm, int *pn, boolean *digraph) /* graph6, digraph6 and sparse6 formats are supported f=anopenfile g=placetoputtheanswer(NULLfordynamicallocation) reqm=therequestedvalueofm(0=>computefromn) *pm=theactualvalueofm *pn=thevalueofn *digraph=whethertheinputisadigraph
*/
{ char *s,*p; int m,n; int readg_code;
if ((s = showg_getline(f)) == NULL) return NULL;
if (s[0] == ':')
{
*digraph = FALSE;
p = s + 1;
} elseif (s[0] == '&')
{
readg_code = DIGRAPH6;
*digraph = TRUE;
p = s + 1;
} else
{
readg_code = GRAPH6;
*digraph = FALSE;
p = s;
}
n = graphsize(s); if (readg_code == GRAPH6 && p - s != G6LEN(n))
gt_abort(">E readgg: truncated graph6 line\n"); if (readg_code == DIGRAPH6 && p - s != D6LEN(n))
gt_abort(">E readgg: truncated digraph6 line\n");
if (reqm > 0 && TIMESWORDSIZE(reqm) < n)
gt_abort(">E readgg: reqm too small\n"); elseif (reqm > 0)
m = reqm; else
m = (n + WORDSIZE - 1) / WORDSIZE;
if (g == NULL)
{ if ((g = (graph*)ALLOCS(n,m*sizeof(graph))) == NULL)
gt_abort(">E readgg: malloc failed\n");
}
staticvoid
putedges(FILE *f, graph *g, int linelength,
boolean digraph, int m, int n) /* Write list of edges, preceded by the numbers of vertices and
edges. Use labelorg */
{ int i,j,curlen,ne; char s[20];
set *pg;
ne = 0; for (i = 0, pg = g; i < n; ++i, pg += m)
{ for (j = (digraph?-1:i-1); (j = nextelement(pg,m,j)) >= 0;)
++ne;
}
staticvoid
putcgraph(FILE *f, graph *g, int linelength, boolean digraph, int m, int n) /* write compressed form, using labelorg */
{ int i,curlen,j0; int semicolons; char s[20];
set *pg;
staticvoid
putam(FILE *f, graph *g, int linelength, boolean space, boolean triang, int m, int n) /* write adjacency matrix */
{
set *gi; int i,j;
boolean first;
for (i = 0, gi = (set*)g; i < n - (triang!=0); ++i, gi += m)
{
first = TRUE; for (j = triang ? i+1 : 0; j < n; ++j)
{ if (!first && space) putc(' ',f); else first = FALSE; if (ISELEMENT(gi,j)) putc('1',f); else putc('0',f);
}
putc('\n',f);
}
}
if (sizeof(setword) < 4)
{
fprintf(stderr,">E showg: setword too small\n");
fprintf(stderr," Please report this to brendan.mckay@anu.edu.au\n"); exit(1);
}
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 und die Messung sind noch experimentell.