/*---------------------------------------------------------------------------*/
LABELEDLIST NewLabeledList (
    const char	*Label)

/*
 **	Parameters:
 **		Label	label for new list
 **	Globals: none
 **	Operation:
 **		This routine allocates a new, empty labeled list and gives
 **		it the specified label.
 **	Return: New, empty labeled list.
 **	Exceptions: none
 **	History: Fri Aug 18 16:08:46 1989, DSJ, Created.
 */

{
  LABELEDLIST	LabeledList;

  LabeledList = (LABELEDLIST) Emalloc (sizeof (LABELEDLISTNODE));
  LabeledList->Label = (char*)Emalloc (strlen (Label)+1);
  strcpy (LabeledList->Label, Label);
  LabeledList->List = NIL;
  LabeledList->SampleCount = 0;
  return (LabeledList);

}	/* NewLabeledList */
Ejemplo n.º 2
0
struct ListItem *
List_insertInternal(struct List *list, void const *data,
		    struct ListItem **before_pos,
		    struct ListItem *after_pos)
{
  struct ListItem	*item = Emalloc(sizeof(struct ListItem));

  assert((before_pos!=0 || after_pos!=0) &&
	 (before_pos==0 || after_pos==0));
  
  item->data = Emalloc(list->elem_size);
  memcpy(item->data, data, list->elem_size);

  if (before_pos!=0) {
    item->next  = *before_pos;
    *before_pos = item;
  }
  else {
    item->next      = after_pos->next;
    after_pos->next = item;
  }

  ++list->count;

  return item;
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
CLUSTERER *SetUpForClustering(
     LABELEDLIST	CharSample)

/*
**	Parameters:
**		CharSample: LABELEDLIST that holds all the feature information for a
**		given character.
**	Globals:
**		None
**	Operation:
**		This routine reads samples from a LABELEDLIST and enters
**		those samples into a clusterer data structure.  This
**		data structure is then returned to the caller.
**	Return:
**		Pointer to new clusterer data structure.
**	Exceptions:
**		None
**	History:
**		8/16/89, DSJ, Created.
*/

{
	uinT16	N;
	int		i, j;
	FLOAT32	*Sample = NULL;
	CLUSTERER	*Clusterer;
	inT32		CharID;
	LIST FeatureList = NULL;
	FEATURE_SET FeatureSet = NULL;
	FEATURE_DESC FeatureDesc = NULL;
//	PARAM_DESC* ParamDesc;

	FeatureDesc = FeatureDefs.FeatureDesc[ShortNameToFeatureType(PROGRAM_FEATURE_TYPE)];
	N = FeatureDesc->NumParams;
	//ParamDesc = ConvertToPARAMDESC(FeatureDesc->ParamDesc, N);
	Clusterer = MakeClusterer(N,FeatureDesc->ParamDesc);
//	free(ParamDesc);

	FeatureList = CharSample->List;
	CharID = 0;
	iterate(FeatureList)
	{
		FeatureSet = (FEATURE_SET) first_node (FeatureList);
		for (i=0; i < FeatureSet->MaxNumFeatures; i++)
		{
			if (Sample == NULL)
				Sample = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32));
			for (j=0; j < N; j++)
				if (RoundingAccuracy != 0.0)
					Sample[j] = round(FeatureSet->Features[i]->Params[j], RoundingAccuracy);
				else
					Sample[j] = FeatureSet->Features[i]->Params[j];
				MakeSample (Clusterer, Sample, CharID);
		}
		CharID++;
	}
	if ( Sample != NULL ) free( Sample );
	return( Clusterer );

}	/* SetUpForClustering */
/* escape string accordingly 'systemd.unit(5)' which means that '/' gets
 * turned into '-' and special chars into '\xXX'; prepend a prefix and reserve
 * extra space e.g. for a suffix */
static char *systemd_escape(char const *data, size_t len,
			    char const *prefix,
			    size_t extra_space)
{
	static char const	HEX_DIGIT[] = "0123456789abcdef";

	/* assume the worst case which means that every char must be
	 * encoded */
	char			*dst =
		Emalloc(len * 4 + strlen(prefix) + extra_space + 1);
	char const		*src = data;
	char			*out;

	out = stpcpy(dst, prefix);

	while (src < data + len) {
		unsigned char	c = *src++;

		if (c == '/') {
			*out++ = '-';
		} else if (c == '-' || c < 32 || !isascii(c)) {
			*out++ = '\\';
			*out++ = 'x';
			*out++ = HEX_DIGIT[(c >> 4) & 0x0f];
			*out++ = HEX_DIGIT[(c >> 0) & 0x0f];
		} else {
Ejemplo n.º 5
0
/**
 * This routine reads N floats from the specified text file
 * and places them into Buffer.  If Buffer is NULL, a buffer
 * is created and passed back to the caller.  If EOF is
 * encountered before any floats can be read, NULL is
 * returned.
 * @param File open text file to read floats from
 * @param N number of floats to read
 * @param Buffer pointer to buffer to place floats into
 * @return Pointer to buffer holding floats or NULL if EOF
 * @note Globals: None
 * @note Exceptions: ILLEGALFLOAT
 * @note History: 6/6/89, DSJ, Created.
 */
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
  bool needs_free = false;
  int i;
  int NumFloatsRead;

  if (Buffer == NULL) {
    Buffer = reinterpret_cast<FLOAT32*>(Emalloc(N * sizeof(FLOAT32)));
    needs_free = true;
  }

  for (i = 0; i < N; i++) {
    NumFloatsRead = tfscanf(File, "%f", &(Buffer[i]));
    if (NumFloatsRead != 1) {
      if ((NumFloatsRead == EOF) && (i == 0)) {
        if (needs_free) {
            Efree(Buffer);
        }
        return NULL;
      } else {
        DoError(ILLEGALFLOAT, "Illegal float specification");
      }
    }
  }
  return Buffer;
}
Ejemplo n.º 6
0
/**
 * This routine reads textual descriptions of sets of parameters
 * which describe the characteristics of feature dimensions.
 *
 * Exceptions:
 * - ILLEGALCIRCULARSPEC
 * - ILLEGALESSENTIALSPEC
 * - ILLEGALMINMAXSPEC
 * @param File open text file to read N parameter descriptions from
 * @param N number of parameter descriptions to read
 * @return Pointer to an array of parameter descriptors.
 * @note Globals: None
 * @note History: 6/6/89, DSJ, Created.
 */
PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
  int i;
  PARAM_DESC *ParamDesc;
  char Token[TOKENSIZE];

  ParamDesc = (PARAM_DESC *) Emalloc (N * sizeof (PARAM_DESC));
  for (i = 0; i < N; i++) {
    if (tfscanf(File, "%s", Token) != 1)
      DoError (ILLEGALCIRCULARSPEC,
        "Illegal circular/linear specification");
    if (Token[0] == 'c')
      ParamDesc[i].Circular = TRUE;
    else
      ParamDesc[i].Circular = FALSE;

    if (tfscanf(File, "%s", Token) != 1)
      DoError (ILLEGALESSENTIALSPEC,
        "Illegal essential/non-essential spec");
    if (Token[0] == 'e')
      ParamDesc[i].NonEssential = FALSE;
    else
      ParamDesc[i].NonEssential = TRUE;
    if (tfscanf(File, "%f%f", &(ParamDesc[i].Min), &(ParamDesc[i].Max)) != 2)
      DoError (ILLEGALMINMAXSPEC, "Illegal min or max specification");
    ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
    ParamDesc[i].HalfRange = ParamDesc[i].Range / 2;
    ParamDesc[i].MidRange = (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
  }
  return (ParamDesc);
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
ADAPT_TEMPLATES ReadAdaptedTemplates(FILE *File) { 
/*
 **	Parameters:
 **		File	open text file to read adapted templates from
 **	Globals: none
 **	Operation: Read a set of adapted templates from File and return
 **		a ptr to the templates.
 **	Return: Ptr to adapted templates read from File.
 **	Exceptions: none
 **	History: Mon Mar 18 15:18:10 1991, DSJ, Created.
 */
  int i;
  ADAPT_TEMPLATES Templates;

  /* first read the high level adaptive template struct */
  Templates = (ADAPT_TEMPLATES) Emalloc (sizeof (ADAPT_TEMPLATES_STRUCT));
  fread ((char *) Templates, sizeof (ADAPT_TEMPLATES_STRUCT), 1, File);

  /* then read in the basic integer templates */
  Templates->Templates = ReadIntTemplates (File, FALSE);

  /* then read in the adaptive info for each class */
  for (i = 0; i < NumClassesIn (Templates->Templates); i++) {
    Templates->Class[i] = ReadAdaptedClass (File);
  }
  return (Templates);

}                                /* ReadAdaptedTemplates */
Ejemplo n.º 8
0
inline static void
initFDs(/*@out@*/struct FdInfoList 		*fds,
	/*@in@*/struct ConfigInfo const	* const	cfg)
    /*@globals internalState, fileSystem@*/
    /*@modifies internalState, fileSystem, *fds@*/
    /*@requires maxRead(fds)>=0 /\ maxSet(fds)>=0 /\ maxSet(fds->sender_fd)>=0@*/
{
  size_t					i, idx;
  struct InterfaceInfoList const * const	ifs = &cfg->interfaces;

  initSenderFD(&fds->sender_fd);
  initRawFD(&fds->raw_fd);
  
  fds->len = ifs->len;
  fds->dta = static_cast(struct FdInfo*)(Emalloc(fds->len *
						 (sizeof(*fds->dta))));

  assert(fds->dta!=0 || fds->len==0);
  assert(ifs->dta!=0 || ifs->len==0);
  
  for (idx=0, i=0; i<ifs->len; ++i, ++idx) {
    assert(ifs->dta!=0);
    assert(fds->dta!=0);
    
    initClientFD(&fds->dta[idx], &ifs->dta[i]);
  }
}
Ejemplo n.º 9
0
/*---------------------------------------------------------------------------*/
ADAPT_CLASS NewAdaptedClass() { 
/*
 **	Parameters: none
 **	Globals: none
 **	Operation: This operation allocates and initializes a new adapted
 **		class data structure and returns a ptr to it.
 **	Return: Ptr to new class data structure.
 **	Exceptions: none
 **	History: Thu Mar 14 12:58:13 1991, DSJ, Created.
 */
  ADAPT_CLASS Class;
  int i;

  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));
  Class->NumPermConfigs = 0;
  Class->TempProtos = NIL;

  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);
  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);
  zero_all_bits (Class->PermProtos, WordsInVectorOfSize (MAX_NUM_PROTOS));
  zero_all_bits (Class->PermConfigs, WordsInVectorOfSize (MAX_NUM_CONFIGS));

  for (i = 0; i < MAX_NUM_CONFIGS; i++)
    TempConfigFor (Class, i) = NULL;

  return (Class);

}                                /* NewAdaptedClass */
Ejemplo n.º 10
0
/**********************************************************************
 * NewClass
 *
 * Allocate a new class with enough memory to hold the specified number
 * of prototypes and configurations.
 **********************************************************************/
CLASS_TYPE NewClass(int NumProtos, int NumConfigs) {
  CLASS_TYPE Class;

  Class = new CLASS_STRUCT;

  if (NumProtos > 0)
    Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));

  if (NumConfigs > 0)
    Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
      sizeof (BIT_VECTOR));
  Class->MaxNumProtos = NumProtos;
  Class->MaxNumConfigs = NumConfigs;
  Class->NumProtos = 0;
  Class->NumConfigs = 0;
  return (Class);

}
Ejemplo n.º 11
0
/**
 * This routine creates and initializes a new heap data
 * structure containing Size elements.  In actuality, Size + 1
 * elements are allocated.  The first element, element 0, is
 * unused, this makes the index arithmetic easier.
 *
 * Globals:
 * - None
 *
 * @param Size maximum number of entries in the heap
 * @return Pointer to the new heap.
 * @note Exceptions: None
 * @note History: 3/13/89, DSJ, Created.
 */
HEAP *MakeHeap(int Size) {
  HEAP *NewHeap;

  NewHeap = (HEAP *) Emalloc (sizeof (HEAP) + Size * sizeof (HEAPENTRY));

  NewHeap->Size = Size;
  NewHeap->FirstFree = 1;
  return (NewHeap);
}                                /* MakeHeap */
Ejemplo n.º 12
0
/**
 * Allocate and return a new feature set large enough to
 * hold the specified number of features.
 * @param NumFeatures maximum # of features to be put in feature set
 * @return New #FEATURE_SET.
 */
FEATURE_SET NewFeatureSet(int NumFeatures) {
  FEATURE_SET FeatureSet;

  FeatureSet = static_cast<FEATURE_SET>(Emalloc (sizeof (FEATURE_SET_STRUCT) +
    (NumFeatures - 1) * sizeof (FEATURE)));
  FeatureSet->MaxNumFeatures = NumFeatures;
  FeatureSet->NumFeatures = 0;
  return (FeatureSet);

}                                /* NewFeatureSet */
Ejemplo n.º 13
0
static void DefTransitions(struct net_object *netobj, struct net_object *unf_netobj)
{ 
 struct trans_object *trans_el, *trans, *prev_trans;
 struct group_object *pri_group, *unf_new_group, *prev_group;
 list l, curr;
 int i;
  
  /* Immediate transition */
 for( pri_group = netobj->groups; pri_group != NULL; pri_group = pri_group->next)
 {
     
 
//    Create new group
   unf_new_group = (struct group_object *) Emalloc(sizeof(struct group_object));
   unf_new_group->tag = Estrdup(pri_group->tag);
   unf_new_group->pri = pri_group->pri;
   unf_new_group->trans = NULL;
   unf_new_group->center.x = pri_group->center.x;
   unf_new_group->center.y = pri_group->center.y;   
   unf_new_group->movelink = NULL;
   unf_new_group->next = unf_netobj->groups;
         
   i=0;
   for( trans_el = pri_group->trans;  trans_el != NULL; trans_el = trans_el->next)
   {
     l = expandtransition(trans_el, netobj, unf_netobj);     
     curr =NULL;
     while ( (curr = list_iterator(l, curr)) != NULL ){
       trans = (struct trans_object *) DATA(curr);
       trans->next = unf_new_group->trans;
       unf_new_group->trans = trans;             
     }
     
   }
   destroy(&l, NULL);
   unf_netobj->groups = unf_new_group;
   
     
 }

 /* Exponential and Deterministic Transition */
 i = 0;
 for( trans_el = netobj->trans; trans_el != NULL; trans_el = trans_el->next) {
   l = expandtransition(trans_el, netobj, unf_netobj);  
   curr = NULL;   
   while ( (curr = list_iterator(l, curr)) != NULL ){
     trans = (struct trans_object *) DATA(curr);
     trans->next =  unf_netobj->trans;      
     unf_netobj->trans = trans;     
   }
   destroy(&l, NULL);
 }

}
/*---------------------------------------------------------------------------*/
MERGE_CLASS NewLabeledClass (
    char	*Label)
{
  MERGE_CLASS	MergeClass;

  MergeClass = new MERGE_CLASS_NODE;
  MergeClass->Label = (char*)Emalloc (strlen (Label)+1);
  strcpy (MergeClass->Label, Label);
  MergeClass->Class = NewClass (MAX_NUM_PROTOS, MAX_NUM_CONFIGS);
  return (MergeClass);

}	/* NewLabeledClass */
Ejemplo n.º 15
0
/**
 * Allocate a new character description, initialize its
 * feature sets to be empty, and return it.
 *
 * Globals: 
 * - none
 *
 * @return New character description structure.
 * @note Exceptions: none
 * @note History: Wed May 23 15:27:10 1990, DSJ, Created.
 */
CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
  CHAR_DESC CharDesc;
  int i;

  CharDesc = (CHAR_DESC) Emalloc (sizeof (CHAR_DESC_STRUCT));
  CharDesc->NumFeatureSets = FeatureDefs.NumFeatureTypes;

  for (i = 0; i < CharDesc->NumFeatureSets; i++)
    CharDesc->FeatureSets[i] = NULL;

  return (CharDesc);

}                                /* NewCharDescription */
Ejemplo n.º 16
0
/*---------------------------------------------------------------------------*/
MICROFEATURE NewMicroFeature() { 
/*
 **	Parameters: none
 **	Globals: none
 **	Operation:
 **		This routine allocates and returns a new micro-feature
 **		data structure.
 **	Return: New micro-feature.
 **	Exceptions: none
 **	History: 7/27/89, DSJ, Created.
 */
  return ((MICROFEATURE) Emalloc (sizeof (MFBLOCK)));
}                                /* NewMicroFeature */
Ejemplo n.º 17
0
/**
 * Read a permanent configuration description from File
 * and return a ptr to it.
 *
 * @param File  open file to read permanent config from
 * @return Ptr to new permanent configuration description.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 14:25:26 1991, DSJ, Created.
 */
PERM_CONFIG ReadPermConfig(FILE *File) {
  PERM_CONFIG Config = (PERM_CONFIG) alloc_struct(sizeof(PERM_CONFIG_STRUCT),
                                                  "PERM_CONFIG_STRUCT");
  uinT8 NumAmbigs;
  fread ((char *) &NumAmbigs, sizeof(uinT8), 1, File);
  Config->Ambigs = (UNICHAR_ID *)Emalloc(sizeof(UNICHAR_ID) * (NumAmbigs + 1));
  fread(Config->Ambigs, sizeof(UNICHAR_ID), NumAmbigs, File);
  Config->Ambigs[NumAmbigs] = -1;
  fread(&(Config->FontinfoId), sizeof(int), 1, File);

  return (Config);

}                                /* ReadPermConfig */
Ejemplo n.º 18
0
/*---------------------------------------------------------------------------*/
ADAPT_CLASS ReadAdaptedClass(FILE *File) { 
/*
 **	Parameters:
 **		File	open file to read adapted class from
 **	Globals: none
 **	Operation: Read an adapted class description from File and return
 **		a ptr to the adapted class.
 **	Return: Ptr to new adapted class.
 **	Exceptions: none
 **	History: Tue Mar 19 14:11:01 1991, DSJ, Created.
 */
  int NumTempProtos;
  int NumConfigs;
  int i;
  ADAPT_CLASS Class;
  TEMP_PROTO TempProto;

  /* first read high level adapted class structure */
  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));
  fread ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File);

  /* then read in the definitions of the permanent protos and configs */
  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);
  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);
  fread ((char *) Class->PermProtos, sizeof (UINT32),
    WordsInVectorOfSize (MAX_NUM_PROTOS), File);
  fread ((char *) Class->PermConfigs, sizeof (UINT32),
    WordsInVectorOfSize (MAX_NUM_CONFIGS), File);

  /* then read in the list of temporary protos */
  fread ((char *) &NumTempProtos, sizeof (int), 1, File);
  Class->TempProtos = NIL;
  for (i = 0; i < NumTempProtos; i++) {
    TempProto =
      (TEMP_PROTO) c_alloc_struct (sizeof (TEMP_PROTO_STRUCT),
      "TEMP_PROTO_STRUCT");
    fread ((char *) TempProto, sizeof (TEMP_PROTO_STRUCT), 1, File);
    Class->TempProtos = push_last (Class->TempProtos, TempProto);
  }

  /* then read in the adapted configs */
  fread ((char *) &NumConfigs, sizeof (int), 1, File);
  for (i = 0; i < NumConfigs; i++)
    if (test_bit (Class->PermConfigs, i))
      Class->Config[i].Perm = ReadPermConfig (File);
  else
    Class->Config[i].Temp = ReadTempConfig (File);

  return (Class);

}                                /* ReadAdaptedClass */
Ejemplo n.º 19
0
/**
 * This routine allocates memory for a new K-D tree node
 * and places the specified Key and Data into it.  The
 * left and right subtree pointers for the node are
 * initialized to empty subtrees.
 * @param tree  The tree to create the node for
 * @param Key  Access key for new node in KD tree
 * @param Data  ptr to data to be stored in new node
 * @param Index  index of Key to branch on
 * @return pointer to new K-D tree node
 * @note Exceptions: None
 * @note History: 3/11/89, DSJ, Created.
 */
KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index) {
  KDNODE *NewNode;

  NewNode = (KDNODE *) Emalloc (sizeof (KDNODE));

  NewNode->Key = Key;
  NewNode->Data = Data;
  NewNode->BranchPoint = Key[Index];
  NewNode->LeftBranch = tree->KeyDesc[Index].Min;
  NewNode->RightBranch = tree->KeyDesc[Index].Max;
  NewNode->Left = NULL;
  NewNode->Right = NULL;

  return NewNode;
}                                /* MakeKDNode */
Ejemplo n.º 20
0
void
PriorityQueue_init(struct PriorityQueue *q,
		   PriorityQueueCompareFunc cmp_func,
		   size_t count, size_t elem_size)
{
  assert(q!=0);
  assert(cmp_func!=0);
  assert(elem_size>0);

  count = powify(count);
  
  q->data      = Emalloc(count * elem_size);
  q->count     = 0;
  q->elem_size = elem_size;
  q->allocated = count;
  q->cmp_func  = cmp_func;
}
Ejemplo n.º 21
0
/**
 * Read a set of adapted templates from file and return
 * a ptr to the templates.
 *
 * @param fp open text file to read adapted templates from
 * @return Ptr to adapted templates read from file.
 *
 * @note Globals: none
 */
ADAPT_TEMPLATES Classify::ReadAdaptedTemplates(TFile *fp) {
  ADAPT_TEMPLATES Templates;

  /* first read the high level adaptive template struct */
  Templates = (ADAPT_TEMPLATES) Emalloc (sizeof (ADAPT_TEMPLATES_STRUCT));
  fp->FRead(Templates, sizeof(ADAPT_TEMPLATES_STRUCT), 1);

  /* then read in the basic integer templates */
  Templates->Templates = ReadIntTemplates(fp);

  /* then read in the adaptive info for each class */
  for (int i = 0; i < (Templates->Templates)->NumClasses; i++) {
    Templates->Class[i] = ReadAdaptedClass(fp);
  }
  return (Templates);

}                                /* ReadAdaptedTemplates */
Ejemplo n.º 22
0
char *FreeVarName()
{
  char *default_name = "xyzj";
  char *var_name;
  char *suffix = (char *)Emalloc(5);
  static int i=1;
  list l=NULL;

  sprintf(suffix,"%d",i++);
  var_name = NewStringCat(default_name, suffix);
  while(find_key(YACCParsedVarList, (generic_ptr) var_name, CmpVarName, &l) == OK) {
    sprintf(suffix,"%d",i++);
    var_name = NewStringCat(default_name, suffix);
  }
    
  return(var_name);
}
Ejemplo n.º 23
0
suppl_log_list_t *suppl_log_mkf_item(int flag, const char * const s
	, size_t length)
{	suppl_log_list_t *h;

	assert(s);
	assert(length);
	assert(flag == '+' || flag == '-');

	chkHeap
	h = Emalloc(sizeof(suppl_log_list_t) + length);
	h->suppl_l_nxt = 0;
	chkHeap
	memcpy(&h->suppl_l_name[1], s, length);
	h->suppl_l_name[0] = flag;
	h->suppl_l_name[1 + length] = NUL;

	chkHeap
	return h;
}
Ejemplo n.º 24
0
/**
 * Allocates memory for adapted tempates.
 * each char in unicharset to the newly created templates
 *
 * @param InitFromUnicharset if true, add an empty class for
 * @return Ptr to new adapted templates.
 *
 * @note Globals: none
 */
ADAPT_TEMPLATES Classify::NewAdaptedTemplates(bool InitFromUnicharset) {
  ADAPT_TEMPLATES Templates;

  Templates = (ADAPT_TEMPLATES) Emalloc (sizeof (ADAPT_TEMPLATES_STRUCT));

  Templates->Templates = NewIntTemplates ();
  Templates->NumPermClasses = 0;
  Templates->NumNonEmptyClasses = 0;

  /* Insert an empty class for each unichar id in unicharset */
  for (int i = 0; i < MAX_NUM_CLASSES; i++) {
    Templates->Class[i] = nullptr;
    if (InitFromUnicharset && i < unicharset.size()) {
      AddAdaptedClass(Templates, NewAdaptedClass(), i);
    }
  }

  return (Templates);

}                                /* NewAdaptedTemplates */
Ejemplo n.º 25
0
/*---------------------------------------------------------------------------*/
FEATURE_SET NewFeatureSet(int NumFeatures) {
/*
 **	Parameters:
 **		NumFeatures	maximum # of features to be put in feature set
 **	Globals: none
 **	Operation: Allocate and return a new feature set large enough to
 **		hold the specified number of features.
 **	Return: New feature set.
 **	Exceptions: none
 **	History: Mon May 21 14:22:40 1990, DSJ, Created.
 */
  FEATURE_SET FeatureSet;

  FeatureSet = (FEATURE_SET) Emalloc (sizeof (FEATURE_SET_STRUCT) +
    (NumFeatures - 1) * sizeof (FEATURE));
  FeatureSet->MaxNumFeatures = NumFeatures;
  FeatureSet->NumFeatures = 0;
  return (FeatureSet);

}                                /* NewFeatureSet */
Ejemplo n.º 26
0
struct place_object *create_place(struct place_object *place, char *tag)
{
  struct place_object *p;
  
  p = (struct place_object *) Emalloc(PLAOBJ_SIZE);
  p->tag = (char *) Estrdup(tag);
  p->color = NULL;
  p->lisp  = NULL;
  p->mpar  = NULL;
  p->layer  = NewLayerList(WHOLENET,NULL);
  p->cmark  = NULL;
  p->center.x = place->center.x;
  p->center.y = place->center.y;
  p->tagpos.x = place->tagpos.x;
  p->tagpos.y = place->tagpos.y;
  p->colpos.x = place->colpos.x;
  p->colpos.y = place->colpos.y;
  p->next = NULL;  
  return(p);
}
Ejemplo n.º 27
0
/**
 * This operation allocates and initializes a new adapted
 * class data structure and returns a ptr to it.
 *
 * @return Ptr to new class data structure.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Thu Mar 14 12:58:13 1991, DSJ, Created.
 */
ADAPT_CLASS NewAdaptedClass() {
  ADAPT_CLASS Class;
  int i;

  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));
  Class->NumPermConfigs = 0;
  Class->MaxNumTimesSeen = 0;
  Class->TempProtos = NIL_LIST;

  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);
  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);
  zero_all_bits (Class->PermProtos, WordsInVectorOfSize (MAX_NUM_PROTOS));
  zero_all_bits (Class->PermConfigs, WordsInVectorOfSize (MAX_NUM_CONFIGS));

  for (i = 0; i < MAX_NUM_CONFIGS; i++)
    TempConfigFor (Class, i) = NULL;

  return (Class);

}                                /* NewAdaptedClass */
Ejemplo n.º 28
0
int
symbol_add(object_t **obj, char *sym, void *arg, int type)
{
    symbol_t *p, **q;

    _ASSERT(obj != NULL);
    _ASSERT(sym != NULL);

    p = (symbol_t *)Emalloc(sizeof(symbol_t));
    p->next = NULL;
    p->type = type;
    p->sym = Estrdup(sym);
    p->u.ptr = arg;

    for (q = (symbol_t **)obj; *q != NULL; q = &((*q)->next))
        continue;
    *q = p;

    return 0;
}
Ejemplo n.º 29
0
/**
 * Read an adapted class description from File and return
 * a ptr to the adapted class.
 *
 * @param File  open file to read adapted class from
 * @return Ptr to new adapted class.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 14:11:01 1991, DSJ, Created.
 */
ADAPT_CLASS ReadAdaptedClass(FILE *File) {
  int NumTempProtos;
  int NumConfigs;
  int i;
  ADAPT_CLASS Class;
  TEMP_PROTO TempProto;

  /* first read high level adapted class structure */
  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));
  fread ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File);

  /* then read in the definitions of the permanent protos and configs */
  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);
  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);
  fread ((char *) Class->PermProtos, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_PROTOS), File);
  fread ((char *) Class->PermConfigs, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_CONFIGS), File);

  /* then read in the list of temporary protos */
  fread ((char *) &NumTempProtos, sizeof (int), 1, File);
  Class->TempProtos = NIL_LIST;
  for (i = 0; i < NumTempProtos; i++) {
    TempProto =
      (TEMP_PROTO) alloc_struct (sizeof (TEMP_PROTO_STRUCT),
      "TEMP_PROTO_STRUCT");
    fread ((char *) TempProto, sizeof (TEMP_PROTO_STRUCT), 1, File);
    Class->TempProtos = push_last (Class->TempProtos, TempProto);
  }

  /* then read in the adapted configs */
  fread ((char *) &NumConfigs, sizeof (int), 1, File);
  for (i = 0; i < NumConfigs; i++)
    if (test_bit (Class->PermConfigs, i))
      Class->Config[i].Perm = ReadPermConfig (File);
    else
      Class->Config[i].Temp = ReadTempConfig (File);

  return (Class);

}                                /* ReadAdaptedClass */
Ejemplo n.º 30
0
main()
{
    int i;
    int uMemSize;
    char *psz;
    
    uMemSize = 8;
    
    Emalloc_Create();

    for ( i = 0; i < 10; i++ )
    {
        Emalloc_Add(uMemSize, MEMORY_BLOCK_SIZE / uMemSize);
        uMemSize *= 2;
    }

    psz = Emalloc(48);
    free(psz, 48);

    Emalloc_Destroy();
}