Example #1
0
int main()
{
    FILE* file=fopen("matrix.dat","r");
    matrix_t matrix=readFromFile(file);
    fclose(file);
    printTable(&matrix);
    freeTable(&matrix);

    return 0;
}
Example #2
0
bool test_duplicate_insert_overrides() {
    Table * t = makeTable();
    hset(t, "Key", "A");
    hset(t, "Key", "B");
    char* returned = hget(t, "Key");
    ASSERT(returned != 0, "Table returned null on duplicate insert");
    ASSERT(returned[0] != 'A', "Table returned old value on duplicate insert");
    ASSERT(returned[0] == 'B', "Table returned wrong value on duplicate insert");
    freeTable(t); 
    return true;
}
Example #3
0
Error
DXNotifyRegisteredNoExecute(char *name)
{
    struct _entry *entry;
    struct _string *str;
    struct _table *table = getTable();
    if (! table)
	return ERROR;

    entry = getEntry(table, name);
    if (! entry)
	goto error;
    
    for (str = entry->modids; str; str = str->link)
	DXReadyToRunNoExecute((Pointer)str->string);
    
    freeTable(table);
    return OK;

error:
    freeTable(table);
    return ERROR;
}
Example #4
0
Error
DXRegisterForNotificationNoExecute(char *name, Pointer modid)
{
    struct _entry *entry;
    struct _table *table = getTable();
    if (! table)
	return ERROR;

    entry = getEntry(table, name);
    if (! entry)
	goto error;

    if (! isModidRegistered(entry, modid))
	if (! registerModid(table, entry, modid, NOTIFY_READYTORUN_NOEXECUTE))
	    goto error;
    
    freeTable(table);
    return OK;

error:
    freeTable(table);
    return ERROR;
}
// QC:?
void ScriptVariable::setval(ScriptTable* c) {
	if(isPointer()) {
		getPointee()->setval(c);
		return;
	}

	setType(VAR_TBL);

	if(data) {
		freeTable(data, params);
	}

	data = (char*)c;
	params = (char*) AOEMALLOC(sizeof(int));
	*(int*) params = 1;
}
Example #6
0
bool test_segfault_during_delete() {
    Table * t = makeTable();
    char * key1 = "0";
    char * key2 = "8";

    ASSERT( (hash(key1) % t->size) == (hash(key2) % t->size), "Keys will not collide. Update keys for this test.")

    hset(t, key1, "asdf");
    hset(t, key2, "asdf");

    hdel(t, key2);
    hdel(t, key1); // This segfaults

    freeTable(t);

    return true;
}
Example #7
0
void prune(hashTable** oldT, hashTable** newT, triple*** oldA, triple*** newA, long u){

	//build new hashtable skipping values if need to be pruned
	//keep one char 
	//keep strs at leased used times
	//non empty prefix?
	int newPref[(*oldT)->num_triples];

	for(int j = 0; j < (*oldT)->num_triples; j++) {
		if((*oldA)[j]->pref == SPECIAL || (*oldA)[j]->pref == EMPTY) {
				newPref[j] = (*newT)->num_triples;
				addTriple((*newA), (*newT), (*oldA)[j]->c, (*oldA)[j]->pref);
		} else if ((*oldA)[j]->used  >= u) {
			//lookup value at location of old pref
				//add the new code as the value at the old code


// oldA  [[code: 0, c:c, pref:0], [code: 1, c:a, pref:0],[code: 2, c:b, pref:0],[code: 3, c:a, pref:1],[code: 4, c:b, pref:1]]

// newPref [[oldcode 0, newcode:-2], [old]]

			//at old code put new location
				newPref[j] = (*newT)->num_triples;
				addTriple((*newA), (*newT), (*oldA)[j]->c, newPref[(*oldA)[j]->pref]);

			//send the code locaiton in old array and the new location

		} 
	}


	freeTable((*oldT));
	freeArray(*oldA);


	(*oldA) = (*newA);
	(*oldT) = (*newT);

}
Example #8
0
Table tablePrune( Table table, int window, int pos, int *numbits )
{
	int curbits;
	int maxcode;
	int code;
	int swp;
	Table newTable;
	int i;
	newTable = tableMake(table->maxbits);
	curbits = STARTING_BITS;
	maxcode = 1 << curbits;
	for (i = 0; i < table->size; i++)
	{
		if (table->entries[i] && 
			(pos - table->entries[i]->accessed < window || i <= NUM_SPECIALS + UCHAR_MAX))
		{
			code = i;
			while (code >= 0 && table->entries[code])
			{
				tableInsert(table->entries[code], newTable);
				if (maxcode <= getSize(newTable))
				{
					curbits++;
					maxcode *= 2;
				}

				swp = table->entries[code]->prefix;
				table->entries[code] = 0;
				code = swp;
			}
		}
	}
	*numbits = curbits;
	freeTable(table);
	// printf("Table Size: %d\n", newTable->size);
	// tableDump(newTable);
	return newTable;
}
Example #9
0
File: wf.c Project: kgross99/count
int main(int argc, char *argv[]) {
	int chars_read=1;
	if (argc < 2) {
		printf("Usage wf int  size of hashtable\n");
		return 1;
	}
	tablesize = atoi(argv[1]);

	printf("calling create table\n");
	htable = createTable(tablesize, (void *) hashcode, (void *) toString,
			(void *) freeWordObj, (void *) compareTo);
	printf("table created with table size %d\n", tablesize);

	char * line = NULL;
	while (chars_read>-1){
	chars_read = getline(&line, &maxlinelength, stdin);

	token = strtok(line, delimiters);


	while (token != NULL) {
	CountWord(htable, token);

		token = strtok(NULL, delimiters);
	//	if (token!=NULL){
		//CountWord(htable, token);
	//	printf("tokenized\n");
	//	}
	}
	}
printf("finished sample\n");
	printTable(htable);
	printf("ran printTable\n");
	freeTable(htable);
	printf("ran freetable\n");

	return 0;
}
// setType change le type d'une variable.
// Si la variable contient du contenu, il sera libere de la memoire.
// QC:P
void ScriptVariable::setType(varType t) {
	// Liberation des anciennes zones memoire
	switch(type){
	case VAR_STR:
		if(t != VAR_STR) {
			if(data) {
				AOEFREE(data);
				data = NULL;
			}
		}
		break;

	case VAR_PACK:
		if(data) {
			AOEFREE(data);
			data = NULL;
		}
		if(params) {
			AOEFREE(params);
			params = NULL;
		}
		value = 0;
		break;

	case VAR_OBJ:
		assert(data != NULL);
		untrackPointer(data);
		type = VAR_NULL;
		break;

	case VAR_HTBL:
		if(data != NULL) {
			type = VAR_NULL;
		}
		break;

	case VAR_RECT:
		if(data != NULL) {
			delete (Rect*) data;
		}
		break;

	case VAR_TBL:
		if(t != VAR_TBL) {
			freeTable(data, params); // Free with reference count.
		}

	case VAR_XML:
	case VAR_FCT:
	case VAR_RAW:
	case VAR_PTR:
	case VAR_TXTFCT:
	case VAR_INT:
	case VAR_PAIR:
	case VAR_NULL:
		break;
	}

	// Creation des nouvelles zones memoire
	switch(t){
	case VAR_STR:
		if(type != VAR_STR) {
			data = NULL;
		}
		break;

	case VAR_PACK:
		value = 0;

	case VAR_TBL:
		params = NULL;

	case VAR_HTBL:
	case VAR_RECT:
		data = NULL;

		break;

	case VAR_XML:
	case VAR_OBJ:
	case VAR_FCT:
	case VAR_RAW:
	case VAR_PTR:
	case VAR_TXTFCT:
	case VAR_INT:
	case VAR_PAIR:
	case VAR_NULL:
		break;
	}

	type = t;
}
Example #11
0
int main(int argc, char **argv){
  FILE *f = NULL, *fout = NULL;

  char line[1024];
  char *tmp, *fName;
  char foutname[100];
  int i;
  char first;
  int pending = 0, files;

  fprintf(stderr, "\nHelpPC Reference Library to HTML converter. Ver 1.02\n"
	  "Copyleft (l) Stanislav Sokolov\n\n");

  if(argc == 1){
    fprintf(stderr, "Usage:\n  %s [file.txt [file2.txt [...]]]\n"
	    "or\n  %s *.txt\n\n", argv[0], argv[0]);
    return 10;
  }
  
  mkdir(BASE_PATH, 0777);

  /* Build conversion table */
  fprintf(stderr, "Building conversion table and index files...\n");
  i = buildConv(argc, argv);
  fprintf(stderr, "Found %d keywords corresponding to %d unique entries.\n",
	  i >> 16, i & 0xFFFF);

  /* Parse the files */
  for(files = 1; files < argc; files++){  //For all files given to function
    if((f = fopen(argv[files], "r")) == NULL){
      fprintf(stderr, "Error opening %s\n", argv[files]);
      exit(100);
    }

    fprintf(stderr, "\nParsing %s...\n", argv[files]);

    while(fgets(line, 200, f) != NULL){
      cleanLine(line);
      line[strlen(line) - 1] = '\0';
      first = line[0];

      if(first == '@'){
	/* do nothing */
      } else if(first == ':'){ /*Make new html file*/
	if(pending){
	  fprintf(fout, "</PRE>\n\n</BODY>\n</HTML>");
	  fclose(fout);
	}

	pending = 1;
	rmFirst(line);
	tmp = strtok(line, ":");
	fName = makeFName(tmp);
      
	sprintf(foutname, "%s/%s", BASE_PATH, fName);
	if((fout = fopen(foutname, "w+")) == NULL){
	  convError("Cannot open for writing!");
	  convError(foutname);
	  return 3;
	}
	free(fName);
      
	fprintf(fout,
		"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>\n\n<BODY><PRE>", 
		tmp);

      } else if(first == '^'){ /* Make H2 */
	rmFirst(line);
	fprintf(fout, "</PRE>\n\n<H2 ALIGN=Center>%s</H2>\n\n<PRE>\n", line);
	continue;
      } else if(first == '%'){ /* Make Bold */
	rmFirst(line);
	fprintf(fout, "<B>%s</B>\n", line);
      } else {
	if(line[0] != '\0'){
	  parseLine(line);
	}
	fprintf(fout, "%s\n", line);
      }
    
    }/* while */
    fclose(f);
  }/* for */

  fprintf(stderr, "\nAll done.\n");
  
  
  if(pending){
    fprintf(fout, "</PRE>\n\n</BODY>\n</HTML>");
    fclose(fout);
  }
  
  fclose(f);
  freeTable(c_head);

  return 0;
}
Example #12
0
XImage *
read_ppm_file(Display *disp, Colormap cmap, int depth, IOSTREAM *fd)
{ XImage *img;
  long here = Stell(fd);
  int c;
  int fmt, encoding;
  int width, height, bytes_per_line, scale=0;
  char *data;
  int allocdepth;
  int pad = XBitmapPad(disp);
  Visual *v = DefaultVisual(disp, DefaultScreen(disp));

  ncolours = nmapped = nfailed = 0;	/* statistics */
  assert(pad%8 == 0);

  if ( (c=Sgetc(fd)) != 'P' )
  { Sungetc(c, fd);
    return NULL;
  }

  if ( !cmap )
    cmap = DefaultColormap(disp, DefaultScreen(disp));

  c = Sgetc(fd);
  if ( c < '1' || c > '9' )
    goto errout;
  c -= '0';
  fmt      = ((c - 1) % 3) + 1;
  encoding = c - fmt;

  width = getNum(fd);
  height = getNum(fd);

  if ( fmt == PNM_PBM )
  { depth = 1;
  } else
  { scale = getNum(fd);
    if ( !depth )
      depth = DefaultDepth(disp, DefaultScreen(disp));
  }

  if ( width < 0 || height < 0 || scale < 0 )
    goto errout;

  allocdepth = (depth >= 24 ? 32 : depth);
  bytes_per_line = roundup((width*allocdepth+7)/8, pad/8);
  data = (char *)pceMalloc(height * bytes_per_line);

  img = XCreateImage(disp,
		     v,
		     depth,
		     fmt == PNM_PBM ? XYBitmap : ZPixmap,
		     0,
		     data,
		     width, height,
		     pad, bytes_per_line);
  if ( !img )
  { perror("XCreateImage");
    pceFree(data);
    goto errout;
  }
  img->bits_per_pixel = depth;

  switch(encoding)
  { int x, y;

    case PNM_ASCII:
    { switch(fmt)
      { case PNM_PBM:
	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int value = getNum(fd);

	      if ( value < 0 || value > 1 )
		goto errout;

	      XPutPixel(img, x, y, value);
	    }
	  }
	  break;
	case PNM_PGM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int g = getNum(fd);
	      unsigned long pixel;

	      if ( g < 0 || g > scale )
		goto errout;
	      if ( scale != 255 )
		g = rescale(g, scale, 255);

	      pixel = colourPixel(disp, depth, cmap, t, g, g, g);
	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int r = getNum(fd);
	      int g = getNum(fd);
	      int b = getNum(fd);
	      unsigned long pixel;

	      if ( r < 0 || r > scale ||
		   g < 0 || g > scale ||
		   b < 0 || b > scale )
		goto errout;

	      if ( scale != 255 )
	      { r = rescale(r, scale, 255);
		g = rescale(g, scale, 255);
		b = rescale(b, scale, 255);
	      }

	      pixel = colourPixel(disp, depth, cmap, t, r, g, b);

	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	break;
      }
      break;
    }
    case PNM_RAWBITS:
    { switch(fmt)
      { case PNM_PBM:
	{ int byte = 0;
	  int bit = 0;

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( !bit )
	      { byte = Sgetc(fd);
		bit = 8;
	      }

	      bit--;
	      XPutPixel(img, x, y, (byte & (1<<bit)) ? 1 : 0);
	    }
	    bit = 0;			/* scanlines are byte-aligned */
	  }
	  break;
	}
	case PNM_PGM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int g;
	      unsigned long pixel;

	      if ( Sfeof(fd) || (g=Sgetc(fd)) > scale )
		goto errout;
	      if ( scale != 255 )
		g = rescale(g, scale, 255);

	      pixel = colourPixel(disp, depth, cmap, t, g, g, g);
	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int r, g, b;
	      unsigned long pixel;

	      if ( Sfeof(fd) ||
		   (r=Sgetc(fd)) > scale ||
		   (g=Sgetc(fd)) > scale ||
		   (b=Sgetc(fd)) > scale )
		goto errout;

	      if ( scale != 255 )
	      { r = rescale(r, scale, 255);
		g = rescale(g, scale, 255);
		b = rescale(b, scale, 255);
	      }

	      pixel = colourPixel(disp, depth, cmap, t, r, g, b);

	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	break;
      }
      break;
    }
    case PNM_RUNLEN:
    { int rlen = 0;
      unsigned long cpixel = NOPIXEL;

      switch(fmt)
      { case PNM_PGM:
	{ Table t = newTable(64);

	  DEBUG(NAME_pnm, Cprintf("Reading runlength encoded graymap\n"));

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( rlen-- > 0 )
	      { XPutPixel(img, x, y, cpixel);
	      } else
	      { int g;

		if ( (g=Sgetc(fd)) > scale ||
		     (rlen = Sgetc(fd)) == EOF )
		  goto errout;
		rlen &= 0xff;
		if ( scale != 255 )
		  g = rescale(g, scale, 255);

		cpixel = colourPixel(disp, depth, cmap, t, g, g, g);
		XPutPixel(img, x, y, cpixel);
		rlen--;
	      }
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( rlen-- > 0 )
	      { XPutPixel(img, x, y, cpixel);
	      } else
	      { int r, g, b;

		if ( (r=Sgetc(fd)) > scale ||
		     (g=Sgetc(fd)) > scale ||
		     (b=Sgetc(fd)) > scale ||
		     (rlen = Sgetc(fd)) == EOF )
		  goto errout;

		rlen &= 0xff;
		if ( scale != 255 )
		{ r = rescale(r, scale, 255);
		  g = rescale(g, scale, 255);
		  b = rescale(b, scale, 255);
		}

		cpixel = colourPixel(disp, depth, cmap, t, r, g, b);

		XPutPixel(img, x, y, cpixel);
		rlen--;
	      }
	    }
	  }
	  freeTable(t);

	  break;
	}
      }
    }
  }

  DEBUG(NAME_ppm,
	Cprintf("PNM: Converted %dx%dx%d image, %d colours (%d mapped, %d failed)\n",
		width, height, depth, ncolours, nmapped, nfailed));

  return img;

errout:
  DEBUG(NAME_ppm,
	Cprintf("PNM: Format error, index = %d\n", Stell(fd)));
  Sseek(fd, here, SEEK_SET);
  return NULL;
}
Example #13
0
void freeTable(struct tableentry *entry)
{
    if (entry == NULL) return;
    freeTable(entry->next);
    free(entry);
}
Example #14
0
ElementFile::~ElementFile()
{
    freeTable();
    delete jacobians;
    delete jacobians_reducedQ;
}