/* weaving.h
   headers for weavereduce.c from Tim's Rudimentary Treadle Reducer,
   Copyright (C) 2002, Tim McLarnan

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Do, please, let me hear from you if you use this package, or if you
have questions.

Tim McLarnan, Dept. of Mathematics, Earlham College, Richmond, IN 47374 USA
timm AT cs.earlham.edu

*/


/*--------------------------------------------------------------
  Data types:
  SetLists are lists of sets.
  In our code, the SetLists all have length 2.
  PairLists are lists of SetLists.
  TargetAndOptions hold a list of structures, each containing a set
    and a list of pairs of sets.  The union of each pair is the target.
  IntPairLists are lists of pairs of ints.
----------------------------------------------------------------*/

typedef struct setlist {
  BigSet set;
  struct setlist *next;
} SetListDesc, *SetList;

typedef struct pairlist {
  SetList head;
  struct pairlist *next;
} PairListDesc, *PairList;

typedef struct targetandoptions {
  BigSet target;
  PairList options;
} TargetAndOptionsDesc, *TargetAndOptions;

typedef struct intpairlist {
  int member[2];
  struct intpairlist *next;
} IntPairList;


void SafeBigSetMake(BigSet *b, long max_size);

void SafeBigSetCopy(BigSet source, BigSet *target);

void *SafeMalloc(size_t size);

long SetListLength(SetList sl);

void LoadPattern(char *InputString);

void GridOut(char *grid, int Rows, int Cols, char *color);

void PrintPattern();

int DeChaff();

void PrintBricks();

void InitializeBrickList();

int IsNew(BigSet s, SetList sl);

void MakeBricks();

void MakeTargetOptionsSkeleton();

void MakeTargetOptions();

long PairListLength(PairList pl);

int PLLCompare(const void *x, const void *y);

void PrintTargetOptions(int terseness);

void SortTargetOptions();

int Used(BigSet b);

void RemoveUnusedBricks();

long BrickIndex(BigSet s);

void OptionsToSets();

void PrintWorkSets();

void PrintSolution(const unsigned char solutionSet[]);

int DFS(unsigned char solutionSet[], long size, long level);

void FreeSetList(SetList sl);

void FreePairList(PairList pl);

void FreeIntPairList(IntPairList *ipl);

void CleanUp();

int getNumericalValue(char *instring, char *name);

void bailOut();

void regrets();

/* Error codes */

#define NOSOLN 1
#define TIMEOUT 2
#define MALLOC 10
#define SSCANF 11
#define INPUTAREFS 12
#define GNV 13
#define SHAFTCOUNT 14
#define TARGETCOUNT 15
#define TREADLECOUNT 16
#define BSMALLOC 17
