1/***************************************************************************** 2* This is the main header file for gtools. nauty version 2.7. * 3* Subject to the copyright notice in nauty.h. * 4* @configure_input@ 5*****************************************************************************/ 6 7/* The parts between the ==== lines are modified by configure when 8creating gtools.h out of gtools-h.in. If configure is not being 9used, it is necessary to check they are correct. 10====================================================================*/ 11 12#ifndef _GTOOLS_H_ /* only process this file once */ 13#define _GTOOLS_H_ 14 15#define HAVE_ERRNO_H @header_errno_h@ /* <errno.h> exists */ 16#define HAVE_PERROR @have_perror@ /* perror() exists */ 17#define HAVE_PIPE @have_pipe@ /* pipe() exists */ 18#define HAVE_WAIT @have_wait@ /* wait() exists */ 19#define HAVE_WAIT_H @header_sys_wait_h@ /* <sys/wait.h> exists */ 20#define HAVE_POPEN @have_popen@ /* popen() and pclose() exist */ 21#define POPEN_DEC @popen_dec@ /* popen() is declared */ 22#define FTELL_DEC @ftell_dec@ /* ftell() is declared */ 23#define FDOPEN_DEC @fdopen_dec@ /* fdopen() is declared */ 24#define SORTPROG "@sort_prog@" /* name of sort program */ 25#define SORT_NEWKEY @sort_newparams_ok@ /* if -k is supported */ 26#define HAVE_PID_T @have_pid_t@ /* pid_t is defined */ 27#define PUTENV_DEC @putenv_dec@ /* putenv() is declared */ 28#define SETENV_DEC @setenv_dec@ /* setenv() is declared */ 29#define HAVE_PUTENV @have_putenv@ /* putenv() exists */ 30#define HAVE_SETENV @have_setenv@ /* setenv() exists */ 31#define HAVE_FORK @have_fork@ /* fork() exists */ 32#define HAVE_SIGNAL_H @header_signal_h@ /* <signal.h> exists */ 33#define HAVE_FSEEKO @have_fseeko@ /* fseeko() and ftello() exist */ 34#define HAVE_SIGACTION @have_sigaction@ /* sigaction() exists */ 35#define HAVE_SIGPROCMASK @have_sigprocmask@ /* sigprocmask() exists */ 36#define ALLOW_INTERRUPT @allow_interrupt@ /* no --disable-interrupt */ 37 38/* @edit_msg@ */ 39 40/*==================================================================*/ 41 42#ifndef MAXN 43#define MAXN 0 44#endif 45 46#define SIZELEN(n) ((n)<=SMALLN?1:((n)<=SMALLISHN?4:8)) 47 /* length of size code in bytes */ 48#define G6BODYLEN(n) \ 49 (((size_t)(n)/12)*((size_t)(n)-1) + (((size_t)(n)%12)*((size_t)(n)-1)+11)/12) 50#define G6LEN(n) (SIZELEN(n) + G6BODYLEN(n)) 51 /* exact graph6 string length excluding \n\0 52 This twisted expression works up to n=227023 in 32-bit arithmetic 53 and for larger n if size_t has 64 bits. */ 54#define D6BODYLEN(n) \ 55 ((n)*(size_t)((n)/6) + (((n)*(size_t)((n)%6)+5)/6)) 56#define D6LEN(n) (1 + SIZELEN(n) + D6BODYLEN(n)) 57 /* exact digraph6 string length excluding \n\0 58 This twisted expression works up to n=160529 in 32-bit arithmetic 59 and for larger n if size_t has 64 bits. */ 60 61#include "naututil.h" /* which includes stdio.h */ 62#include "nausparse.h" 63 64#if HAVE_ERRNO_H 65#include <errno.h> 66#else 67extern int errno; 68#endif 69 70#if HAVE_WAIT_H && !defined(AVOID_SYS_WAIT_H) 71#include <sys/wait.h> 72#endif 73 74#if HAVE_SIGNAL_H 75#include <signal.h> 76#endif 77 78#if HAVE_PERROR 79#define ABORT(msg) do {if (errno != 0) perror(msg); exit(1);} while(0) 80#else 81#define ABORT(msg) do {exit(1);} while(0) 82#endif 83 84/* Here we set environment variables that determine the sorting order 85 for the shortg program. Older docs for sort say that it uses 86 LC_COLLATE, but the POSIX description of locales says that the 87 LC_ALL variable takes precedence over LC_COLLATE. To be safe, 88 we will define both. Also, define this to be nothing if the 89 variable KEEP_SORT_LOCALE is defined. */ 90#ifdef KEEP_SORT_LOCALE 91#define SET_C_COLLATION 92#else 93#if PUTENV_DEC && HAVE_PUTENV 94#define SET_C_COLLATION putenv("LC_ALL=C"); putenv("LC_COLLATE=C") 95#elif SETENV_DEC && HAVE_SETENV 96#define SET_C_COLLATION setenv("LC_ALL","C",1); setenv("LC_COLLATE","C",1) 97#elif HAVE_PUTENV 98int putenv(char*); 99#define SET_C_COLLATION putenv("LC_ALL=C"); putenv("LC_COLLATE=C") 100#elif HAVE_SETENV 101int setenv(const char*,const char*,int); 102#define SET_C_COLLATION setenv("LC_ALL","C",1); setenv("LC_COLLATE","C",1) 103#else 104#define SET_C_COLLATION 105#endif 106#endif 107 108#if HAS_STDIO_UNLOCK && !defined(NAUTY_IN_MAGMA) && !defined(IS_JAVA) 109#define FLOCKFILE(f) flockfile(f) 110#define FUNLOCKFILE(f) funlockfile(f) 111#define GETC(f) getc_unlocked(f) 112#undef PUTC 113#define PUTC(c,f) putc_unlocked(c,f) 114#else 115#define FLOCKFILE(f) 116#define FUNLOCKFILE(f) 117#define GETC(f) getc(f) 118#undef PUTC 119#define PUTC(c,f) putc(c,f) 120#endif 121 122#define BIAS6 63 123#define MAXBYTE 126 124#define SMALLN 62 125#define SMALLISHN 258047 126#define TOPBIT6 32 127#define C6MASK 63 128 129#define GRAPH6_HEADER ">>graph6<<" 130#define SPARSE6_HEADER ">>sparse6<<" 131#define DIGRAPH6_HEADER ">>digraph6<<" 132#define PLANARCODE_HEADER ">>planar_code<<" 133#define PLANARCODELE_HEADER ">>planar_code le<<" 134#define PLANARCODEBE_HEADER ">>planar_code be<<" 135#define EDGECODE_HEADER ">>edge_code<<" 136 137#define GRAPH6 1 138#define SPARSE6 2 139#define PLANARCODE 4 140#define PLANARCODELE 8 141#define PLANARCODEBE 16 142#define EDGECODE 32 143#define INCSPARSE6 64 144#define PLANARCODEANY (PLANARCODE|PLANARCODELE|PLANARCODEBE) 145#define DIGRAPH6 128 146#define UNKNOWN_TYPE 256 147#define HAS_HEADER 512 148 149#define NODIGRAPHSYET(code) if (((code)&DIGRAPH6)) \ 150 gt_abort(">E Sorry, this program doesn't support digraphs yet.\n") 151 152#define ARG_OK 0 153#define ARG_MISSING 1 154#define ARG_TOOBIG 2 155#define ARG_ILLEGAL 3 156 157#define MAXARG 2000000000L 158#define NOLIMIT (MAXARG+31L) 159 160#define SWBOOLEAN(c,boool) if (sw==c) boool=TRUE; 161#define SWCOUNT(c,count) if (sw==c) ++count; 162#define SWINT(c,boool,val,id) if (sw==c) \ 163 {boool=TRUE;arg_int(&arg,&val,id);} 164#define SWLONG(c,boool,val,id) if (sw==c) \ 165 {boool=TRUE;arg_long(&arg,&val,id);} 166#define SWRANGE(c,sep,boool,val1,val2,id) if (sw==c) \ 167 {boool=TRUE;arg_range(&arg,sep,&val1,&val2,id);} 168#define SWREAL(c,boool,val,id) if (sw==c) \ 169 {boool=TRUE;arg_double(&arg,&val,id);} 170#define SWREALRANGE(c,sep,boool,val1,val2,id) if (sw==c) \ 171 {boool=TRUE;arg_doublerange(&arg,sep,&val1,&val2,id);} 172#define SWSEQUENCE(c,sep,boool,val,maxvals,numvals,id) if (sw==c) \ 173 {boool=TRUE;arg_sequence(&arg,sep,val,maxvals,&numvals,id);} 174#define SWSEQUENCEMIN(c,sep,boool,val,minvals,maxvals,numvals,id) if (sw==c) \ 175 {boool=TRUE;arg_sequence_min(&arg,sep,val,minvals,maxvals,&numvals,id);} 176 177#ifdef HELPUSECMD 178#ifdef HELPTEXT2 179#define PUTHELPTEXT printf("\nUsage: %s %s\n\n%s",argv[0],USAGE,HELPTEXT1);\ 180 printf("%s",HELPTEXT2); 181#else 182#define PUTHELPTEXT printf("\nUsage: %s %s\n\n%s",argv[0],USAGE,HELPTEXT) 183#endif 184#else 185#ifdef HELPTEXT2 186#define PUTHELPTEXT printf("\nUsage: %s\n\n%s",USAGE,HELPTEXT1);\ 187 printf("%s",HELPTEXT2); 188#else 189#define PUTHELPTEXT printf("\nUsage: %s\n\n%s",USAGE,HELPTEXT) 190#endif 191#endif 192 193#define HELP if (argc > 1 && (strcmp(argv[1],"-help")==0 \ 194 || strcmp(argv[1],"/?")==0 \ 195 || strcmp(argv[1],"--help")==0)) \ 196 { PUTHELPTEXT; return 0; } 197 198#define PUTVERSION if (argc > 1 && (strcmp(argv[1],"-version")==0 \ 199 || strcmp(argv[1],"--version")==0)) \ 200 { printf("Nauty&Traces version %.4f (%d bits)\n",\ 201 NAUTYVERSIONID/10000.0,WORDSIZE); return 0; } 202 203#define GETHELP \ 204fprintf(stderr," Use %s -help to see more detailed instructions.\n",argv[0]) 205 206#define alloc_error gt_abort 207 208#define CATMSG0(fmt) sprintf(msg+strlen(msg),fmt) 209#define CATMSG1(fmt,x1) sprintf(msg+strlen(msg),fmt,x1) 210#define CATMSG2(fmt,x1,x2) sprintf(msg+strlen(msg),fmt,x1,x2) 211#define CATMSG3(fmt,x1,x2,x3) sprintf(msg+strlen(msg),fmt,x1,x2,x3) 212#define CATMSG4(fmt,x1,x2,x3,x4) sprintf(msg+strlen(msg),fmt,x1,x2,x3,x4) 213#define CATMSG5(fmt,x1,x2,x3,x4,x5) sprintf(msg+strlen(msg),fmt,x1,x2,x3,x4,x5) 214#define CATMSG6(fmt,x1,x2,x3,x4,x5,x6) \ 215 sprintf(msg+strlen(msg),fmt,x1,x2,x3,x4,x5,x6) 216 217/************************************************************************/ 218 219/* @edit_msg@ */ 220 221#ifdef __cplusplus 222extern "C" { 223#endif 224 225extern void gtools_check(int,int,int,int); 226extern FILE *opengraphfile(char*,int*,boolean,long); 227extern void writeline(FILE*,char*); 228extern char *gtools_getline(FILE*); /* formerly getline() */ 229extern int graphsize(char*); 230extern void encodegraphsize(int,char**); 231extern void stringcounts(char*,int*,size_t*); 232extern void stringtograph(char*,graph*,int); 233extern void stringtograph_inc(char*,graph*,int,graph*,int); 234extern size_t edgecount(char*); 235extern int checkgline(char*); 236extern graph *readgg(FILE*,graph*,int,int*,int*,boolean*); 237extern graph *readg(FILE*,graph*,int,int*,int*); 238extern graph *readgg_inc(FILE*,graph*,int,int*,int*,graph*,int,int,boolean*); 239extern graph *readg_inc(FILE*,graph*,int,int*,int*,graph*,int,int); 240extern char *ntog6(graph*,int,int); 241extern char *ntos6(graph*,int,int); 242extern char *ntod6(graph*,int,int); 243extern char *sgtos6(sparsegraph*); 244extern char *sgtog6(sparsegraph*); 245extern char *sgtod6(sparsegraph*); 246extern void writeg6(FILE*,graph*,int,int); 247extern void writed6(FILE*,graph*,int,int); 248extern void writes6(FILE*,graph*,int,int); 249extern void writeg6_sg(FILE*,sparsegraph*); 250extern void writes6_sg(FILE*,sparsegraph*); 251extern void writed6_sg(FILE*,sparsegraph*); 252extern char *ntois6(graph*,graph*,int,int); 253extern void writeis6(FILE*,graph*,graph*,int,int); 254extern void writepc_sg(FILE*,sparsegraph*); 255extern void stringtosparsegraph(char*,sparsegraph*,int*); 256extern sparsegraph *read_sg(FILE*,sparsegraph*); 257extern sparsegraph *read_sg_loops(FILE*,sparsegraph*,int*); 258extern sparsegraph *read_sgg_loops(FILE*,sparsegraph*,int*,boolean*); 259extern sparsegraph *readpc_sg(FILE*,sparsegraph*); 260extern sparsegraph *readpcle_sg(FILE*,sparsegraph*); 261extern char *getecline(FILE*); 262extern void writelast(FILE*); 263extern int longval(char**,long*); 264extern void arg_int(char**,int*,char*); 265extern void arg_long(char**,long*,char*); 266extern void arg_range(char**,char*,long*,long*,char*); 267extern int doublevalue(char**,double*); 268extern void arg_double(char**,double*,char*); 269extern void arg_doublerange(char**,char*,double*,double*,char*); 270extern void arg_sequence(char**,char*,long*,int,int*,char*); 271extern void arg_sequence_min(char**,char*,long*,int,int,int*,char*); 272 273extern void writerange(FILE*,int,long,long); 274extern void gt_abort(const char*); 275extern char *stringcopy(char*); 276extern boolean strhaschar(char*,int); 277 278extern void fcanonise(graph*,int,int,graph*,char*,boolean); 279extern void fcanonise_inv 280 (graph*,int,int,graph*,char*,void(*)(graph*,int*,int*,int, 281 int,int,int*,int,boolean,int,int),int,int,int,boolean); 282extern void fcanonise_inv_sg 283 (sparsegraph*,int,int,sparsegraph*,char*,void(*)(graph*,int*,int*, 284 int,int,int,int*,int,boolean,int,int),int,int,int,boolean); 285extern void setlabptn(int*,int*,int*,int); 286extern void fgroup(graph*,int,int,char*,int*,int*); 287extern void fgroup_inv 288 (graph*,int,int,char*,int*,int*,void(*)(graph*,int*,int*,int, 289 int,int,int*,int,boolean,int,int),int,int,int); 290extern int istransitive(graph*,int,int,graph*); 291extern void tg_canonise(graph*,graph*,int,int); 292 293extern TLS_ATTR int readg_code; 294extern TLS_ATTR char *readg_line; 295extern TLS_ATTR size_t ogf_linelen; 296extern TLS_ATTR boolean is_pipe; 297 298#ifdef __cplusplus 299} 300#endif 301 302#ifdef CPUDEFS 303CPUDEFS 304#endif 305 306/* @edit_msg@ */ 307 308#endif /* _GTOOLS_H_ */ 309