-
Notifications
You must be signed in to change notification settings - Fork 0
/
dreadnaut.c
2544 lines (2367 loc) · 80.6 KB
/
dreadnaut.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* *
* This is the main file for dreadnaut() version 2.7, which is a test-bed *
* for nauty() version 2.7 and traces version 2.2. *
* *
* Subject to the copyright notice in the file COPYRIGHT. *
* *
* CHANGE HISTORY *
* 10-Nov-87 : final changes for version 1.2 *
* 5-Dec-87 - replaced all uses of fscanf() by appropriate uses *
* of the new procedures readinteger() and readstring() *
* - changed the '<' command slightly. If a file of the *
* given name cannot be openned, an attempt is made to *
* open a file with the same name extended by DEFEXT. *
* - improved error processing for 'n' command. *
* 28-Sep-88 : changes for version 1.4 : *
* - replaced incorrect %d by %ld in fprintf for ? command *
* 23-Mar-89 : changes for version 1.5 : *
* - added optional startup message *
* - enabled use of refine1 in 'i' command *
* - implemented $$ command *
* - replaced ALLOCS test by DYNALLOC test *
* - modified @ command and added # command *
* - declared local procedures static *
* 25-Mar-89 - implemented k command *
* 27-Mar-89 - implemented * and I commands *
* 29-Mar-89 - implemented K command *
* 2-Apr-89 - added reporting of vertex-invariant statistics *
* 2-Apr-89 - added ## command *
* 4-Apr-89 - added triples(), quadruples(), adjtriang() *
* - updated error reporting for nauty() *
* 5-Apr-89 - removed flushline() from g and e commands *
* - added T command *
* 6-Apr-89 - added cellquads() and distances() *
* 26-Apr-89 - modified ? command, added & and && commands *
* - added indsets(), cliques(), cellquins() *
* 18-Aug-89 - made g, lab, canong dynamically allocated always *
* 2-Mar-90 - added celltrips(), cellcliq(), cellind() *
* 13-Mar-90 - changed canong and savedg in output to h and h' *
* 19-Mar-90 - revised help() a little *
* 19-Apr-90 : changes for version 1.6 *
* - rewrote "*" command to avoid bug in Pyramid C compiler *
* 20-Apr-90 - rewrote above rewrite to avoid bug in SUN3 gcc *
* 23-Apr-90 - undid above rewrite and fixed *my* bug <blush> by *
* making NUMINVARS have type int. Sorry, gcc. *
* 10-Nov-90 - added calls to null routines (see comment on code) *
* 27-Aug-92 : renamed to version 1.7, no changes to this file *
* 5-Jun-93 : renamed to version 1.7+, no changes to this file *
* 18-Aug-93 : renamed to version 1.8, no changes to this file *
* 17-Sep-93 : changes for version 1.9 : *
* - added invariant adjacencies() *
* 7-Jun-96 : changes for version 2.0 : *
* - added invariants cellfano() and cellfano2() *
* - made y=10 the default *
* 11-Jul-96 - added dynamic allocation *
* - rewrote h command and added H command *
* - implemented M and R commands *
* 15-Aug-96 - changed z command to use sethash() *
* 30-Aug-96 - no need to declare seed; already in naututil.h *
* 12-Sep-96 - let i and I commands use userrefproc *
* 9-Dec-96 - made y=infinity the default *
* 6-Sep-97 - allocated arrays before accepting commands *
* 7-Sep-97 - make g,canong,savedg 1-d arrays even statically *
* 22-Sep-97 - undid error introduced on 7-Sep (worksize) *
* 9-Jan-00 - used *_check() instead of *_null() *
* 12-Feb-00 - minor code formatting *
* 17-Aug-00 - now use tc_level from DEFAULTOPTIONS *
* 16-Nov-00 - made changes listed in nauty.h *
* 22-Apr-01 - include nautyinv.h *
* - improve worksize processing for MAXN=0 *
* 5-May-01 - k=0 1 automatic for *, also K=3 or K=0 *
* 2-Jun-01 - added __ command for digraph converse *
* 18-Oct-01 - moved WORKSIZE to here *
* 21-Nov-01 - use NAUTYREQUIRED in *_check() calls *
* 1-Sep-02 - Undid the previous change *
* 17-Nov-03 - Changed INFINITY to NAUTY_INFINITY *
* 15-Nov-04 - Completed all prototypes *
* 23-Nov-06 - no usertcellproc() any more in version 2.4 *
* 10-Nov-09 - removed types shortish and permutation *
* 17-Nov-09 - added sparsegraphs, schreier, A and G commands *
* 19-Nov-09 - added F command, stub for Traces *
* 1-Dec-09 - added traces refinement, M also applies to i *
* 16-Dec-09 - added sr# command for random regular graphs *
* 19-Dec-09 - added s# command for the sparse case *
* - w command is in units of 2*m now *
* 19-May-10 - Incorporate traces canonical labelling *
* 7-Jun-10 - implement %, _ and __ commands for sparse format *
* 8-Jun-10 - add O and P commands, and sparse && command *
* 11-Jun-10 - revise command-line parameters *
* 14-Jun-10 - digraphs and invariants (top level only) in Traces *
* 26-Oct-10 - fix u command for sparse graphs; default G=10 *
* 14-Mar-11 - store partition with savedg *
* 21-Jul-11 - extend M command *
* 24-Oct-11 - add S and OO commands *
* 15-Jan-12 - use putorbitsplus() if USE_ANSICONTROLS *
* 20-Sep-12 - the first argument of ungetc is int, not char *
* 18-Jan-13 - add code for ^C catching in nauty *
* - add usercanonproc sample *
* - ->> means flush output file *
* 14-Nov-14 - fix numcells calculation in 'OO' command *
* 16-Mar-15 - add B command *
* 16-Dec-15 - add r& command *
* 22-Jan-16 - commands with short arguments must be all on one line *
* - most errors cause rest of input line to be skipped *
* 19-Feb-16 - make R command induce a partition if one is defined *
* *
*****************************************************************************/
#include "gtools.h" /* which includes nauty.h, which includes stdio.h */
#include "nautinv.h"
#include "schreier.h"
#include "traces.h"
#define USAGE "dreadnaut [-o options]"
#define HELPTEXT \
" Enter nauty+traces test program.\n\
\n\
-o options - set initial options. The parameter value is a string of\n\
dreadnaut commands from the following set:\n\
a,c,d,m,p,l,G,P,w,y,$,A,V,M\n\
The effect is the same as if these commands are entered\n\
at the beginning of the standard input.\n\
For help within dreadnaut, use the h command.\n"
#define PM(x) ((x) ? '+' : '-')
#define SS(n,sing,plur) (n),((n)==1?(sing):(plur))
#define WORKSIZE 60
#define FLUSHANDPROMPT do { flushline(INFILE); if (prompt) fprintf(PROMPTFILE,"> "); } while (0)
#define SORT_OF_SORT 2
#define SORT_NAME sort2ints
#define SORT_TYPE1 int
#define SORT_TYPE2 int
#include "sorttemplates.c" /* define sort2ints(a,b,n) */
#define INFILE fileptr[curfile]
#define SCHREIER_DEFAULT 10
static long seed;
#if !MAXN
DYNALLSTAT(graph,g,g_sz);
DYNALLSTAT(graph,canong,canong_sz);
DYNALLSTAT(graph,savedg,savedg_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(int,templab,templab_sz);
DYNALLSTAT(int,tempptn,tempptn_sz);
DYNALLSTAT(int,perm,perm_sz);
DYNALLSTAT(int,savedlab,savedlab_sz);
DYNALLSTAT(int,savedptn,savedptn_sz);
DYNALLSTAT(set,tempactive,tempactive_sz);
DYNALLSTAT(set,active,active_sz);
#else
static graph g[MAXM*1L*MAXN];
static graph canong[MAXM*1L*MAXN];
static graph savedg[MAXM*1L*MAXN];
static setword workspace[MAXM*2L*WORKSIZE];
static int lab[MAXN];
static int ptn[MAXN];
static int orbits[MAXN];
static int savedlab[MAXN],savedptn[MAXN];
static int perm[MAXN];
static int templab[MAXN];
static int tempptn[MAXN];
static int tempactive[MAXM];
static set active[MAXM];
#endif
static sparsegraph g_sg;
static sparsegraph canong_sg;
static sparsegraph savedg_sg;
static DEFAULTOPTIONS_GRAPH(options);
static DEFAULTOPTIONS_SPARSEGRAPH(options_sg);
static statsblk stats;
static int curfile;
static FILE *fileptr[MAXIFILES];
static FILE *outfile;
static char def_ext[] = DEFEXT;
static boolean firstpath; /* used in usernode() */
DEFAULTOPTIONS_TRACES(traces_opts);
static TracesStats traces_stats;
#define TMP
#define DENSE_MODE 0
#define SPARSE_MODE 1
#define TRACES_MODE 2
#define SPARSEREP(mode) ((mode)==1||(mode)==2)
#define NOSPARSEYET(c) else if (SPARSEREP(mode)) { fprintf(ERRFILE,\
"command %s is not implemented in the sparse case\n",c); }
#define NODENSEYET else if (!SPARSEREP(mode)) { fprintf(ERRFILE,\
"command %c is not implemented in the dense case\n",c); }
#define NOTRACESYET if (mode==TRACES_MODE) { fprintf(ERRFILE,\
"command %c is not implemented for Traces\n",c); }
static int mode;
#define U_NODE 1 /* masks for u values */
#define U_AUTOM 2
#define U_LEVEL 4
#define U_TCELL 8 /* At version 2.4, usertcellproc() is gone */
#define U_REF 16
#define U_CANON 32
#ifndef NODEPROC
#define NODEPROC usernode
#else
extern void NODEPROC(graph*,int*,int*,int,int,int,int,int,int);
#endif
#ifndef AUTOMPROC
#define AUTOMPROC userautom
#else
extern void AUTOMPROC(int,int*,int*,int,int,int);
#endif
#ifndef LEVELPROC
#define LEVELPROC userlevel
#else
extern void LEVELPROC(int*,int*,int,int*,statsblk*,int,int,int,int,int,int);
#endif
#ifndef REFPROC
#define REFPROC NULL
#else
extern void REFPROC(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
#endif
#ifndef CANONPROC
#define CANONPROC usercanon
#else
extern int CANONPROC(graph*,int*,graph*,unsigned long,int,int,int);
#endif
#ifndef INVARPROC
#define INVARPROC NULL
#define INVARPROCNAME "none"
#else
extern void INVARPROC(graph*,int*,int*,int,int,int,int*,int,boolean,int,int);
#define INVARPROCNAME "user-defined"
#endif
#ifndef INVARPROC_SG
#define INVARPROC_SG NULL
#define INVARPROCNAME_SG "none"
#else
extern void INVARPROC_SG(graph*,int*,int*,int,int,int,int*,int,boolean,int,int);
#define INVARPROCNAME_SG "user-defined"
#endif
static struct invarrec
{
void (*entrypoint)(graph*,int*,int*,int,int,int,int*,int,boolean,int,int);
char *name;
void (*entrypoint_sg)(graph*,int*,int*,int,int,int,int*,int,boolean,int,int);
char *name_sg;
} invarproc[]
= {{INVARPROC, INVARPROCNAME, INVARPROC_SG, INVARPROCNAME_SG},
{NULL, "none", NULL, "none"},
{twopaths, "twopaths", NULL, "unavailable"},
{adjtriang, "adjtriang", NULL, "unavailable"},
{triples, "triples", NULL, "unavailable"},
{quadruples, "quadruples", NULL, "unavailable"},
{celltrips, "celltrips", NULL, "unavailable"},
{cellquads, "cellquads", NULL, "unavailable"},
{cellquins, "cellquins", NULL, "unavailable"},
{distances, "distances", distances_sg, "distances_sg"},
{indsets, "indsets", NULL, "unavailable"},
{cliques, "cliques", NULL, "unavailable"},
{cellcliq, "cellcliq", NULL, "unavailable"},
{cellind, "cellind", NULL, "unavailable"},
{adjacencies, "adjacencies", adjacencies_sg, "adjacencies_sg"},
{cellfano, "cellfano", NULL, "unavailable"},
{cellfano2, "cellfano2", NULL, "unavailable"},
{refinvar, "refinvar", NULL, "unavailable"}
};
#define NUMINVARS ((int)(sizeof(invarproc)/sizeof(struct invarrec)))
static void help(FILE*, int);
static void userautom(int,int*,int*,int,int,int);
static void usernode(graph*,int*,int*,int,int,int,int,int,int);
static void userlevel(int*,int*,int,int*,statsblk*,int,int,int,int,int,int);
static int usercanon(graph*,int*,graph*,unsigned long,int,int,int);
static boolean options_writeautoms,options_writemarkers,
options_digraph,options_getcanon,options_linelength;
static int options_invarproc,options_mininvarlevel,options_maxinvarlevel,
options_invararg,options_tc_level,options_cartesian;
static int options_schreier,options_keepgroup,options_verbosity,
options_strategy;
#if USE_ANSICONTROLS && !DREADTEST
#define PUTORBITS putorbitsplus
#else
#define PUTORBITS putorbits
#endif
#ifdef EXTRADECLS
EXTRADECLS
#endif
#if !HAVE_SIGACTION
#undef ALLOW_INTERRUPT
#define ALLOW_INTERRUPT 0
#endif
#if ALLOW_INTERRUPT
/*****************************************************************************
* *
* Routines for catching SIGINT *
* *
*****************************************************************************/
void
sigintcatcher(int sig)
/* This is the routine called on SIGINT receipt. */
{
struct sigaction ss;
nauty_kill_request = 1;
ss.sa_handler = SIG_DFL;
sigemptyset(&ss.sa_mask);
ss.sa_flags = 0;
sigaction(SIGINT,&ss,0);
}
static void
setsigcatcher(void)
{
struct sigaction ss;
nauty_kill_request = 0;
ss.sa_handler = sigintcatcher;
sigemptyset(&ss.sa_mask);
ss.sa_flags = 0;
sigaction(SIGINT,&ss,0);
}
static void
unsetsigcatcher(void)
{
struct sigaction ss;
nauty_kill_request = 0;
ss.sa_handler = SIG_DFL;
sigemptyset(&ss.sa_mask);
ss.sa_flags = 0;
sigaction(SIGINT,&ss,0);
}
#else
static void
setsigcatcher(void)
{
}
static void
unsetsigcatcher(void)
{
}
#endif
/*****************************************************************************
* *
* This is a program which illustrates the use of nauty. *
* Commands are read from stdin, and may be separated by white space, *
* commas or not separated. Output is written to stdout. *
* For a short description, see the nauty User's Guide. *
* *
*****************************************************************************/
int
main(int argc, char *argv[])
{
int m,n,newm,newn;
boolean gvalid,ovalid,cvalid,pvalid,minus,prompt,doquot;
boolean gvalid_sg,cvalid_sg;
int i,j,k,worksize,numcells,savednc,refcode,umask,qinvar;
int oldorg,oldmode;
int maxsize,cell1,cell2;
boolean ranreg,same;
char *s1,*s2;
int c,d;
unsigned long uli;
size_t sli;
set *gp;
double timebefore,timeafter,mintime;
char filename[515];
int sgn,sgorg,nperm;
int multiplicity,actmult;
long zseed;
permnode *generators;
char *ap,*parameters;
boolean flushing;
HELP; PUTVERSION;
if (argc == 3 && strcmp(argv[1],"-o") == 0)
parameters = argv[2];
else if (argc != 1)
{
fprintf(ERRFILE,USAGE);
exit(1);
}
else
parameters = "";
mode = DENSE_MODE;
curfile = 0;
fileptr[curfile] = stdin;
#ifdef DREADTEST
prompt = FALSE;
#else
prompt = DOPROMPT(INFILE);
#endif
outfile = stdout;
options_writeautoms = options_writemarkers = TRUE;
options_digraph = FALSE;
options_getcanon = options.getcanon;
options_mininvarlevel = options.mininvarlevel;
options_maxinvarlevel = options.maxinvarlevel;
options_invararg = options.invararg;
options_invarproc = 1; /* index into invarproc[] */
options_tc_level = options.tc_level;
options_cartesian = options.cartesian;
options_linelength = options.linelength;
options_schreier = SCHREIER_DEFAULT;
options_keepgroup = FALSE;
generators = NULL;
options_verbosity = 1;
options_strategy = 0;
n = m = 1;
worksize = WORKSIZE;
#if !MAXN
n = WORDSIZE;
DYNALLOC2(graph,g,g_sz,n,m,"dreadnaut");
DYNALLOC1(int,lab,lab_sz,n,"dreadnaut");
DYNALLOC1(int,ptn,ptn_sz,n,"dreadnaut");
DYNALLOC1(int,orbits,orbits_sz,n,"dreadnaut");
DYNALLOC1(int,perm,perm_sz,n,"dreadnaut");
DYNALLOC1(set,active,active_sz,m,"dreadnaut");
n = 1;
#endif
#ifdef DREADTEST
seed = 1;
ran_init(seed);
#else
#ifdef INITSEED
INITSEED;
ran_init(seed);
#endif
#endif
umask = 0;
pvalid = FALSE;
ovalid = FALSE;
gvalid = gvalid_sg = FALSE; /* at most one valid */
cvalid = cvalid_sg = FALSE; /* at most one valid */
sgorg = labelorg = oldorg = 0;
sgn = 0;
multiplicity = 1;
mintime = 0.0;
flushing = FALSE;
#ifdef INITIALIZE
INITIALIZE;
#endif
if (prompt)
{
fprintf(PROMPTFILE,"Dreadnaut version %s.\n",NAUTYVERSION);
fprintf(PROMPTFILE,"> ");
}
nauty_check(WORDSIZE,1,1,NAUTYVERSIONID);
nautinv_check(WORDSIZE,1,1,NAUTYVERSIONID);
nautil_check(WORDSIZE,1,1,NAUTYVERSIONID);
naututil_check(WORDSIZE,1,1,NAUTYVERSIONID);
nausparse_check(WORDSIZE,1,1,NAUTYVERSIONID);
SG_INIT(g_sg);
SG_INIT(canong_sg);
SG_INIT(savedg_sg);
minus = FALSE;
for (ap = parameters; *ap != '\0'; )
{
c = *ap++;
switch (c)
{
case ' ':
case '\t':
break;
case '-':
minus = TRUE;
break;
case '+':
minus = FALSE;
break;
case 'a':
options_writeautoms = !minus;
minus = FALSE;
break;
case 'c':
options_getcanon = !minus;
minus = FALSE;
break;
case 'm':
options_writemarkers = !minus;
minus = FALSE;
break;
case 'p':
options_cartesian = !minus;
minus = FALSE;
break;
case 'B':
flushing = !minus;
minus = FALSE;
break;
case 'd':
options_digraph = !minus;
minus = FALSE;
break;
case 'P':
options_keepgroup = !minus;
minus = FALSE;
break;
case 'w':
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&worksize,"w");
#if MAXN
if (worksize > 2*MAXM*WORKSIZE)
{
fprintf(ERRFILE,
"too big - setting worksize = %d\n",WORKSIZE);
worksize = WORKSIZE;
}
#endif
minus = FALSE;
break;
case 'V':
if (minus)
{
options_verbosity = 0;
minus = FALSE;
}
else
{
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&i,"V");
if (i < 0) fprintf(ERRFILE,"verbosity must be >= 0\n");
else options_verbosity = i;
}
break;
case 'S':
if (minus)
{
options_strategy = 0;
minus = FALSE;
}
else
{
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&i,"S");
/*
if (i < 0) fprintf(ERRFILE,"strategy must be >= 0\n");
else options_strategy = i;
*/
if (i != 0) fprintf(ERRFILE,
"Only strategy 0 is supported in this version\n");
}
break;
case 'G':
if (minus)
{
options_schreier = 0;
minus = FALSE;
}
else
{
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&i,"G");
if (i < 0)
fprintf(ERRFILE,"schreierfails must be >= 0\n");
else
{
options_schreier = i;
if (i > 0) schreier_fails(i);
}
}
break;
case 'y':
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&options_tc_level,"y");
minus = FALSE;
break;
case '$':
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&labelorg,"$");
minus = FALSE;
break;
case 'M':
if (minus)
{
multiplicity = 1;
mintime = 0.0;
minus = FALSE;
}
else
{
actmult = 0;
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&multiplicity,"M");
if (*ap == '/')
{
++ap;
arg_int(&ap,&actmult,"M/");
}
if (multiplicity < 0) multiplicity = 0;
if (actmult < 0) actmult = 0;
if (multiplicity == 0 && actmult == 0) multiplicity = 1;
mintime = (double)actmult;
}
break;
case 'l':
while (*ap == '=' || *ap == ' ') ++ap;
arg_int(&ap,&options_linelength,"l");
minus = FALSE;
break;
case 'A':
d = *ap++;
if (d == 'n' || d == 'N' || d == 'd' || d == 'D')
mode = DENSE_MODE;
else if (d == 's' || d == 'S') mode = SPARSE_MODE;
else if (d == 't' || d == 'T') mode = TRACES_MODE;
else
{
fprintf(ERRFILE,"Mode %c is unknown\n",(d?d:'0'));
break;
}
minus = FALSE;
break;
default:
fprintf(ERRFILE,"Illegal initialization command %c\n",c);
exit(1);
}
}
minus = FALSE;
while (curfile >= 0)
{
if ((c = getc(INFILE)) == EOF || c == '\004')
{
fclose(INFILE);
--curfile;
if (curfile >= 0) prompt = DOPROMPT(INFILE);
}
else switch (c)
{
case '\n': /* possibly issue prompt */
if (prompt) fprintf(PROMPTFILE,"> ");
minus = FALSE;
break;
case ' ': /* do nothing */
case '\t':
#ifndef NLMAP
case '\r':
#endif
case '\f':
break;
case '-': /* remember this for next time */
minus = TRUE;
break;
case '+': /* forget - */
case ',':
case ';':
minus = FALSE;
break;
case '<': /* new input file */
minus = FALSE;
if (curfile == MAXIFILES - 1)
{
fprintf(ERRFILE,"exceeded maximum input nesting of %d\n",
MAXIFILES);
FLUSHANDPROMPT;
break;
}
if (!readstring(INFILE,filename,513))
{
fprintf(ERRFILE,
"missing file name on '<' command : ignored\n");
break;
}
if ((fileptr[curfile+1] = fopen(filename,"r")) == NULL)
{
for (s1 = filename; *s1 != '\0'; ++s1) {}
for (s2 = def_ext; (*s1 = *s2) != '\0'; ++s1, ++s2) {}
fileptr[curfile+1] = fopen(filename,"r");
}
if (fileptr[curfile+1] != NULL)
{
++curfile;
prompt = DOPROMPT(INFILE);
if (prompt)
fprintf(PROMPTFILE,"> ");
}
else
{
fprintf(ERRFILE,"can't open input file\n");
FLUSHANDPROMPT;
}
break;
case '>': /* new output file, or flush output file */
if ((d = getc(INFILE)) != '>') ungetc(d,INFILE);
if (minus)
{
minus = FALSE;
if (d == '>')
fflush(outfile);
else if (outfile != stdout)
{
fclose(outfile);
outfile = stdout;
}
}
else
{
if (!readstring(INFILE,filename,513))
{
fprintf(ERRFILE,
"improper file name, reverting to stdout\n");
outfile = stdout;
FLUSHANDPROMPT;
break;
}
OPENOUT(outfile,filename,d=='>');
if (outfile == NULL)
{
fprintf(ERRFILE,
"can't open output file, reverting to stdout\n");
outfile = stdout;
FLUSHANDPROMPT;
}
}
break;
case 'B':
flushing = !minus;
minus = FALSE;
break;
case '!': /* ignore rest of line */
do
c = getc(INFILE);
while (c != '\n' && c != EOF);
if (c == '\n') ungetc('\n',INFILE);
break;
case 'n': /* read n value */
minus = FALSE;
i = getint_sl(INFILE);
if (i <= 0 || (MAXN && i > MAXN)
|| (!MAXN && i > NAUTY_INFINITY-2))
{
fprintf(ERRFILE,
" n can't be less than 1 or more than %d\n",
MAXN ? MAXN : NAUTY_INFINITY-2);
FLUSHANDPROMPT;
}
else
{
gvalid = FALSE;
cvalid = FALSE;
gvalid_sg = FALSE;
cvalid_sg = FALSE;
pvalid = FALSE;
ovalid = FALSE;
n = i;
m = SETWORDSNEEDED(n);
freeschreier(NULL,&generators);
#if !MAXN
DYNALLOC1(int,lab,lab_sz,n,"dreadnaut");
DYNALLOC1(int,ptn,ptn_sz,n,"dreadnaut");
DYNALLOC1(int,orbits,orbits_sz,n,"dreadnaut");
DYNALLOC1(int,perm,perm_sz,n,"dreadnaut");
DYNALLOC1(set,active,active_sz,m,"dreadnaut");
#endif
}
break;
case 'g': /* read graph */
minus = FALSE;
if (SPARSEREP(mode))
{
readgraph_sg(INFILE,&g_sg,options_digraph,prompt,
options_linelength,n);
gvalid_sg = TRUE;
cvalid_sg = FALSE;
}
else
{
#if !MAXN
DYNALLOC2(graph,g,g_sz,n,m,"dreadnaut");
#endif
readgraph(INFILE,g,options_digraph,prompt,FALSE,
options_linelength,m,n);
gvalid = TRUE;
cvalid = FALSE;
}
ovalid = FALSE;
break;
case 'e': /* edit graph */
minus = FALSE;
if (SPARSEREP(mode))
{
fprintf(ERRFILE,"e command only works in dense mode\n");
FLUSHANDPROMPT;
}
else
{
readgraph(INFILE,g,options_digraph,prompt,gvalid,
options_linelength,m,n);
gvalid = TRUE;
cvalid = FALSE;
ovalid = FALSE;
}
break;
case 'r': /* relabel graph and current partition */
minus = FALSE;
if ((d = getc(INFILE)) != '&') ungetc(d,INFILE);
if (gvalid_sg)
{
if (d == '&')
{
if (pvalid)
relabel_sg(&g_sg,lab,lab,&canong_sg);
}
else
{
readvperm(INFILE,perm,prompt,n,&nperm);
relabel_sg(&g_sg,(pvalid ? lab : NULL),perm,&canong_sg);
}
cvalid_sg = FALSE;
ovalid = FALSE;
}
else if (gvalid)
{
if (d == '&')
{
if (pvalid)
{
#if !MAXN
DYNALLOC2(graph,canong,canong_sz,n,m,"dreadnaut");
#endif
relabel(g,lab,lab,canong,m,n);
}
}
else
{
#if !MAXN
DYNALLOC2(graph,canong,canong_sz,n,m,"dreadnaut");
#endif
readvperm(INFILE,perm,prompt,n,&nperm);
relabel(g,(pvalid ? lab : NULL),perm,canong,m,n);
}
cvalid = FALSE;
ovalid = FALSE;
}
else
{
fprintf(ERRFILE,"g is not defined\n");
FLUSHANDPROMPT;
}
break;
case 'R': /* form subgraph */
if (gvalid)
{
#if !MAXN
DYNALLOC2(graph,canong,canong_sz,n,m,"dreadnaut");
#endif
readvperm(INFILE,perm,prompt,n,&nperm);
if ((minus && nperm == n) || (!minus && nperm == 0))
{
fprintf(ERRFILE,"can't form null graph\n");
FLUSHANDPROMPT;
}
else if (minus)
{
sublabel(g,perm+nperm,n-nperm,canong,m,n);
if (pvalid) numcells = subpartition(lab,ptn,n,perm+nperm,n-nperm);
n = n - nperm;
}
else
{
sublabel(g,perm,nperm,canong,m,n);
if (pvalid) numcells = subpartition(lab,ptn,n,perm,nperm);
n = nperm;
}
cvalid = FALSE;
ovalid = FALSE;
m = SETWORDSNEEDED(n);
}
else if (gvalid_sg)
{
readvperm(INFILE,perm,prompt,n,&nperm);
if ((minus && nperm == n) || (!minus && nperm == 0))
{
fprintf(ERRFILE,"can't form null graph\n");
FLUSHANDPROMPT;
}
else if (minus)
{
sublabel_sg(&g_sg,perm+nperm,n-nperm,&canong_sg);
if (pvalid) numcells = subpartition(lab,ptn,n,perm+nperm,n-nperm);
n = n - nperm;
}
else
{
sublabel_sg(&g_sg,perm,nperm,&canong_sg);
if (pvalid) numcells = subpartition(lab,ptn,n,perm,nperm);
n = nperm;
}
cvalid_sg = FALSE;
ovalid = FALSE;
m = SETWORDSNEEDED(n);
}
else
{
fprintf(ERRFILE,"g is not defined\n");
FLUSHANDPROMPT;
}
minus = FALSE;
break;
case '_': /* complement graph or converse digraph */
minus = FALSE;
if ((d = getc(INFILE)) != '_') ungetc(d,INFILE);
if (!gvalid && !gvalid_sg)
{
fprintf(ERRFILE,"g is not defined\n");
FLUSHANDPROMPT;
}
else if (gvalid)
{
if (d == '_') converse(g,m,n);
else complement(g,m,n);
cvalid = FALSE;
}
else
{
if (d == '_')
{
copy_sg(&g_sg,&canong_sg);
converse_sg(&canong_sg,&g_sg);
cvalid_sg = FALSE;
}
else
{
copy_sg(&g_sg,&canong_sg);
complement_sg(&canong_sg,&g_sg);
cvalid_sg = FALSE;
}