Exemplo n.º 1
0
static inline list forward1(list t, int n)
{
   static bucket b[CHARS];   /* buckets */
   group g, g2;              /* groups */
   int pos = 0;              /* pos in string */

   if (n<2) return t;

   initmem(groupmem, sizeof(struct grouprec), n/15);
   initmem(bucketmem, sizeof(struct bucketrec), n/5);

   /* We use a dummy group g as the header of the group data
      structure. It does not contain any elements, but only a
      pointer to the first unfinished group. */
   g = (group) allocmem(groupmem, sizeof(struct grouprec));
   g2 = (group) allocmem(groupmem, sizeof(struct grouprec));
   g->next = g->nextunf = g2;
   g2->head = t;
   g2->next = g2->nextunf = NULL; 
   g2->finis = FALSE;

   intobuckets(g, b, pos);
   while (g->nextunf) {
      pos++;
      intogroups(b, pos);
      intobuckets(g, b, pos);
   }
   t = collect(g);

   freemem(bucketmem);
   freemem(groupmem);

   return t;
}
Exemplo n.º 2
0
int rom_load()
{
	FILE *f;
	byte c, header[16384];

	if (strcmp(romfile, "-")) f = fopen(romfile, "rb");
	else f = stdin;
	if (!f) die("cannot open rom file: %s\n", romfile);

	memset(header, 0xff, 16384);
	fread(header, 16384, 1, f);

	strncpy(rom.name, header+0x0134, 16);
	if (rom.name[14] & 0x80) rom.name[14] = 0;
	if (rom.name[15] & 0x80) rom.name[15] = 0;
	rom.name[16] = 0;

	c = header[0x0147];
	mbc.type = mbc_table[c];
	mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
	rtc.batt = rtc_table[c];
	mbc.romsize = romsize_table[header[0x0148]];
	mbc.ramsize = ramsize_table[header[0x0149]];

	if (!mbc.romsize) die("unknown ROM size %02X\n", header[0x0148]);
	if (!mbc.ramsize) die("unknown SRAM size %02X\n", header[0x0149]);

	rom.bank = malloc(16384 * mbc.romsize);
	memset(rom.bank, 0xff, 16384 * mbc.romsize);
	memcpy(rom.bank, header, 16384);
	fread(rom.bank+1, 16384, mbc.romsize-1, f);
	
	ram.sbank = malloc(8192 * mbc.ramsize);

	if (!ram.loaded)  /* just in case... */
		initmem(ram.sbank, 8192 * mbc.ramsize);
	initmem(ram.ibank, 4096 * 8);
	/* initmem(ram.hi, 256); */

	mbc.rombank = 1;
	mbc.rambank = 0;

	c = header[0x0143];
	hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;

	if (strcmp(romfile, "-")) fclose(f);

	return 0;
}
Exemplo n.º 3
0
int rom_load()
{
	FILE *f;
	byte c, *data, *header;
	int len = 0, rlen;

	if (strcmp(romfile, "-")) f = fopen(romfile, "rb");
	else f = stdin;
	if (!f) die("cannot open rom file: %s\n", romfile);

	data = loadfile(f, &len);
	header = data = decompress(data, &len);
	
	memcpy(rom.name, header+0x0134, 16);
	if (rom.name[14] & 0x80) rom.name[14] = 0;
	if (rom.name[15] & 0x80) rom.name[15] = 0;
	rom.name[16] = 0;

	c = header[0x0147];
	mbc.type = mbc_table[c];
	mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
	rtc.batt = rtc_table[c];
	mbc.romsize = romsize_table[header[0x0148]];
	mbc.ramsize = ramsize_table[header[0x0149]];

	if (!mbc.romsize) die("unknown ROM size %02X\n", header[0x0148]);
	if (!mbc.ramsize) die("unknown SRAM size %02X\n", header[0x0149]);

	rlen = 16384 * mbc.romsize;
	rom.bank = realloc(data, rlen);
	if (rlen > len) memset(rom.bank[0]+len, 0xff, rlen - len);
	
	ram.sbank = malloc(8192 * mbc.ramsize);

	initmem(ram.sbank, 8192 * mbc.ramsize);
	initmem(ram.ibank, 4096 * 8);

	mbc.rombank = 1;
	mbc.rambank = 0;

	c = header[0x0143];
	hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
	hw.gba = (hw.cgb && gbamode);

	if (strcmp(romfile, "-")) fclose(f);

	return 0;
}
Exemplo n.º 4
0
int rom_load(const char *romfile)
{
	byte c, *data, *header;
	int len = 0, rlen;

    header = data = loadfile(romfile, &len);	
	if (data == NULL)
		return 0;

    memcpy(rom.name, header+0x0134, 16);
	if (rom.name[14] & 0x80) rom.name[14] = 0;
	if (rom.name[15] & 0x80) rom.name[15] = 0;
	rom.name[16] = 0;

	c = header[0x0147];
	mbc.type = mbc_table[c];
	mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
	rtc.batt = rtc_table[c];
	mbc.romsize = romsize_table[header[0x0148]];
	mbc.ramsize = ramsize_table[header[0x0149]];

	if (!mbc.romsize) {
		die("unknown ROM size %02X\n", header[0x0148]);
		free(data);
		return 0;
	}
	if (!mbc.ramsize) {
		die("unknown SRAM size %02X\n", header[0x0149]);
		free(data);
		return 0;
	}

	rlen = 16384 * mbc.romsize;
    rom.bank = (void *)data;
	ram.sbank = malloc(8192 * mbc.ramsize);

    initmem(ram.sbank, 8192 * mbc.ramsize);
    initmem(ram.ibank, 4096 * 8);

	mbc.rombank = 1;
	mbc.rambank = 0;

	c = header[0x0143];
	hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
	hw.gba = (hw.cgb && gbamode);

	return 1;
}
Exemplo n.º 5
0
/* Use this function to see what happens when your malloc and free
 * implementations are called.  Run "mem -try <args>" to call this function.
 * We have given you a simple example to start.
 */
void try_mymem(int argc, char **argv) {
        strategies strat;
	void *a, *b, *c, *d, *e;
	if(argc > 1)
	  strat = strategyFromString(argv[1]);
	else
	  strat = First;
	
	
	/* A simple example.  
	   Each algorithm should produce a different layout. */
	
	initmem(strat,500);
	
	a = mymalloc(100);
	b = mymalloc(100);
	c = mymalloc(100);
	myfree(b);
	d = mymalloc(50);
	myfree(a);
	e = mymalloc(25);
	
	print_memory();
	print_memory_status();
	
}
Exemplo n.º 6
0
static inline list MSD(list a, int n)
{
   list res = NULL;
   stack *s;

   if (n < 2) return a;
   initmem(stackmem, sizeof(struct stackrec), n/50);
   push(a, NULL, n, 0);

   while (!stackempty()) {
      s = pop();
      if (!s->size) { /* finished */
         s->tail->next = res;
         res = s->head;
         continue;
      }
       if (s->size <= BYTE_BREAK)
         onebyte(s->head, s->pos);
       else
         twobytes(s->head, s->pos);
   }

   freemem(stackmem);
   return res;
}
Exemplo n.º 7
0
bfl_t
sys$bfl_new(vms$pointer size)
{
    bfl_t                   bfl;

    vms$pointer             array_size;
    vms$pointer             i;

    array_size = (size / BITS_PER_BFL_WORD) + 1;

    // Allocate enough space for the header and the bit array needed
    if ((bfl = (bfl_t) sys$alloc(sizeof(struct bfl) + (array_size) *
            sizeof(bfl_word))) == NULL)
    {
        return(NULL);
    }

    bfl->curpos = 0;
    bfl->len = array_size;

    // Set all as allocated
    sys$initmem((vms$pointer) bfl->bitarray, array_size * sizeof(bfl_word));

    // Now free the ones we have
    // FIXME: This is a terribly ineffecient way to do this
    for(i = 0; i < size; i++)
    {
        sys$bfl_free(bfl, i);
    }

    return(bfl);
}
Exemplo n.º 8
0
int rom_load()
{
	FILE *f=NULL;
	byte c, *header;
	int len = 0, rlen;

	f = fopen(romfile, "rb");
	if (!f) die("cannot open rom file: %s\n", romfile);

	rom.bank = header = loadfile(f, &len);

	fclose(f);

	memcpy(rom.name, header+0x0134, 16);
	if (rom.name[14] & 0x80) rom.name[14] = 0;
	if (rom.name[15] & 0x80) rom.name[15] = 0;
	rom.name[16] = 0;

	c = header[0x0147];
	mbc.type = mbc_table[c];
	mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
	rtc.batt = rtc_table[c];
	mbc.romsize = romsize_table[header[0x0148]];
	mbc.ramsize = ramsize_table[header[0x0149]];

	if (!mbc.romsize) die("unknown ROM size %02X\n", header[0x0148]);
	if (!mbc.ramsize) die("unknown SRAM size %02X\n", header[0x0149]);
	
	ram.sbank = malloc(8192 * mbc.ramsize);
	ram.ibank = malloc(4096 * 8);
	initmem(ram.sbank, 8192 * mbc.ramsize);
	initmem(ram.ibank, 4096 * 8);

	mbc.rombank = 1;
	mbc.rambank = 0;

	c = header[0x0143];
	hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
	hw.gba = (hw.cgb && gbamode);

	return 0;
}
Exemplo n.º 9
0
sys$new_quota(void)
{
    struct quota        *q;

    if ((q = (struct quota *) sys$alloc(sizeof(struct quota))) == NULL)
    {
        return(NULL);
    }

    sys$initmem((vms$pointer) q, sizeof(struct quota));
    return(q);
}
Exemplo n.º 10
0
/* basic sequential allocation of single byte blocks */
int test_alloc_1(int argc, char **argv) {
	strategies strategy;
	int lbound = 1;
	int ubound = 4;

	if (strategyFromString(*(argv+1))>0)
		lbound=ubound=strategyFromString(*(argv+1));

	for (strategy = lbound; strategy <= ubound; strategy++)
	{
		int correct_holes = 0;
		int correct_alloc = 100;
		int correct_largest_free = 0;
		int i;

		void* lastPointer = NULL;
		initmem(strategy,100);
		for (i = 0; i < 100; i++)
		{
			void* pointer = mymalloc(1);
			if ( i > 0 && pointer != (lastPointer+1) )
			{
				printf("Allocation with %s was not sequential at %i; expected %p, actual %p\n", strategy_name(strategy), i,lastPointer+1,pointer);
				return 1;
			}
			lastPointer = pointer;
		}

		if (mem_holes() != correct_holes)
		{
			printf("Holes not counted as %d with %s\n", correct_holes, strategy_name(strategy));
			return	1;
		}

		if (mem_allocated() != correct_alloc)
		{
			printf("Allocated memory not reported as %d with %s\n", correct_alloc, strategy_name(strategy));
			return	1;
		}

		if (mem_largest_free() != correct_largest_free)
		{
			printf("Largest memory block free not reported as %d with %s\n", correct_largest_free, strategy_name(strategy));
			return	1;
		}

	}

	return 0;
}
Exemplo n.º 11
0
Arquivo: sieve.c Projeto: manish05/TCR
void init() {
	cl_uint n;
	cl_platform_id *ids,id=NULL;
	int i,status;
	char s[MAXCHAR];
	/*  choose AMD platform if possible, otherwise just pick one */
	if(CL_SUCCESS!=clGetPlatformIDs(0,NULL,&n))
		error("error getting platforms 1");
	if(NULL==(ids=malloc(sizeof(cl_platform_id)*n))) error("out of memory");
	if(CL_SUCCESS!=clGetPlatformIDs(n,ids,NULL))
		error("error getting platforms 2");
	for(i=0;i<n;i++) {
		if(CL_SUCCESS!=clGetPlatformInfo(ids[i],CL_PLATFORM_VENDOR,MAXCHAR,s,NULL))
			error("error getting platform 3");
		if(!strcmp(s,"Advanced Micro Devices, Inc.")) {
			id=ids[i];
			break;
		}
	}
	if(i==n) id=ids[0];
	free(ids);
	/* get context stuff */
	cl_context_properties cps[3]={CL_CONTEXT_PLATFORM,(cl_context_properties)id,0};
	context=clCreateContextFromType(cps,CL_DEVICE_TYPE_CPU,NULL,NULL,&status);
	if(CL_SUCCESS!=status) error("couldn't create context");
	if(CL_SUCCESS!=clGetContextInfo(context,CL_CONTEXT_DEVICES,0,NULL,(size_t *)&n))
		error("error getting context info 1");
	if(!n) error("no devices!");
	if(NULL==(devices=malloc(n))) error("out of memory");
	if(CL_SUCCESS!=clGetContextInfo(context,CL_CONTEXT_DEVICES,n,devices,NULL))
		error("error getting context info 2");
	/* create opencl command queue */
	cmdq=clCreateCommandQueue(context,devices[0],0,&status);
	if(CL_SUCCESS!=status) error("error creating command queue");
	/* create memory buffers */
	initmem();
	/* copy contents of in to inbuffer */
	inbuffer=clCreateBuffer(context,CL_MEM_READ_WRITE|CL_MEM_USE_HOST_PTR,
		MAXP,in,&status);
	if(CL_SUCCESS!=status) {
		printf("max alloc %d\n",(int)CL_DEVICE_MAX_MEM_ALLOC_SIZE);
		printf("status %d\n",status);
		error("error creating input buffer");
	}
	loadkernel("sieve.cl");
}
Exemplo n.º 12
0
void newmem(long newval)
{ unsigned long maxptrs0=maxptrs;
  void** ptr0=ptr; boolean* marked0=marked; /* handles for old values */
  /* <lie-py> */
  unsigned int* pyobj0=pyobj;
  /* </lie-py> */
  if ((maxptrs=newval)<=GCCRIT)
  
  { maxptrs=maxptrs0;
    error("You can't lower maxobjects from %ld to %ld.\n"
         ,(long)maxptrs,(long)newval);
  }
  initmem();
  { long k;
    for (k=0; k<maxptrs0; k++)
      if (ptr0[k]!=NULL) /* copy all non-null pointers */
      { long h;  
                 { long i; h=hash(ptr0[k]);
                   for (i=0; i<maxptrs; i++) /* find an empty slot; try |maxptrs| times */
                     if (ptr[h]==NULL) break; /* found */
                     else if (++h>=maxptrs) h=0; /* try next slot, wrapping around */
                   if (i==maxptrs)
                   { free(ptr); ptr=ptr0; free(marked); marked=marked0;
                     maxptrs=maxptrs0; /* reset to old values */
                     error("You currently cannot decrease 'maxobjects' below %ld.\n"
                          ,chunks);
                   }
                 }
        ptr[h]=ptr0[k]; /* copy pointer to empty slot */
        marked[h]=false; /* make new pointer unmarked */
        /* <lie-py> */
        if (pyobj0[k]) {
          pyobj[h]=pyobj0[k];
        }
        /* </lie-py> */
      }
  }
  if (!redirected_input)
    Printf("New object table of size %ld.\n",(long)maxptrs);
  free(ptr0); free(marked0); /* release the old tables */
  /* <lie-py> */
  free(pyobj0);
  /* </lie-py> */
}
Exemplo n.º 13
0
static void
rmfram(void)
{
	Type *t;
	Frame *f;
	uchar *nsp;

	t = (Type*)R.s;
	if(t == H)
		error(exModule);
	nsp = R.SP + t->size;
	if(nsp >= R.TS) {
		R.s = t;
		extend();
		T(d) = R.s;
		return;
	}
	f = (Frame*)R.SP;
	R.SP = nsp;
	f->t = t;
	f->mr = nil;
	initmem(t, f);
	T(d) = f;
}
Exemplo n.º 14
0
/* performs a randomized test:
	totalSize == the total size of the memory pool, as passed to initmem2
		totalSize must be less than 10,000 * minBlockSize
	fillRatio == when the allocated memory is >= fillRatio * totalSize, a block is freed;
		otherwise, a new block is allocated.
		If a block cannot be allocated, this is tallied and a random block is freed immediately thereafter in the next iteration
	minBlockSize, maxBlockSize == size for allocated blocks is picked uniformly at random between these two numbers, inclusive
	*/
void do_randomized_test(int strategyToUse, int totalSize, float fillRatio, int minBlockSize, int maxBlockSize, int iterations)
{
	void * pointers[10000];
	int storedPointers = 0;
	int strategy;
	int lbound = 1;
	int ubound = 4;
	int smallBlockSize = maxBlockSize/10;

	if (strategyToUse>0)
		lbound=ubound=strategyToUse;

	FILE *log;
	log = fopen("tests.log","a");
	if(log == NULL) {
	  perror("Can't append to log file.\n");
	  return;
	}

	fprintf(log,"Running randomized tests: pool size == %d, fill ratio == %f, block size is from %d to %d, %d iterations\n",totalSize,fillRatio,minBlockSize,maxBlockSize,iterations);

	fclose(log);

	for (strategy = lbound; strategy <= ubound; strategy++)
	{
		double sum_largest_free = 0;
		double sum_hole_size = 0;
		double sum_allocated = 0;
		int failed_allocations = 0;
		double sum_small = 0;
		struct timespec execstart, execend;
		int force_free = 0;
		int i;
		storedPointers = 0;

		initmem(strategy,totalSize);

#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
		clock_serv_t cclock;
		mach_timespec_t mts;
		host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
		clock_get_time(cclock, &mts);
		mach_port_deallocate(mach_task_self(), cclock);
		execstart.tv_sec = mts.tv_sec;
		execstart.tv_nsec = mts.tv_nsec;
		
#else
		clock_gettime(CLOCK_REALTIME, &execstart);
#endif

		for (i = 0; i < iterations; i++)
		{
			if ( (i % 10000)==0 )
				srand ( time(NULL) );
			if (!force_free && (mem_free() > (totalSize * (1-fillRatio))))
			{
				int newBlockSize = (rand()%(maxBlockSize-minBlockSize+1))+minBlockSize;
				/* allocate */
				void * pointer = mymalloc(newBlockSize);
				if (pointer != NULL)
					pointers[storedPointers++] = pointer;
				else
				{ 
					failed_allocations++;
					force_free = 1;
				}
			}
			else
			{
				int chosen;
				void * pointer;

				/* free */
				force_free = 0;

				if (storedPointers == 0)
					continue;

				chosen = rand() % storedPointers;
				pointer = pointers[chosen];
				pointers[chosen] = pointers[storedPointers-1];

				storedPointers--;

				myfree(pointer);
			}

			sum_largest_free += mem_largest_free();
			sum_hole_size += (mem_free() / mem_holes());
			sum_allocated += mem_allocated();
			sum_small += mem_small_free(smallBlockSize);
		}

#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
		//clock_serv_t cclock;
		//mach_timespec_t mts;
		host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
		clock_get_time(cclock, &mts);
		mach_port_deallocate(mach_task_self(), cclock);
		execend.tv_sec = mts.tv_sec;
		execend.tv_nsec = mts.tv_nsec;
		
#else
		clock_gettime(CLOCK_REALTIME, &execend);
#endif

		log = fopen("tests.log","a");
		if(log == NULL) {
		  perror("Can't append to log file.\n");
		  return;
		}
		
		fprintf(log,"\t=== %s ===\n",strategy_name(strategy));
		fprintf(log,"\tTest took %.2fms.\n", (execend.tv_sec - execstart.tv_sec) * 1000 + (execend.tv_nsec - execstart.tv_nsec) / 1000000.0);
		fprintf(log,"\tAverage hole size: %f\n",sum_hole_size/iterations);
		fprintf(log,"\tAverage largest free block: %f\n",sum_largest_free/iterations);
		fprintf(log,"\tAverage allocated bytes: %f\n",sum_allocated/iterations);
		fprintf(log,"\tAverage number of small blocks: %f\n",sum_small/iterations);
		fprintf(log,"\tFailed allocations: %d\n",failed_allocations);
		fclose(log);


	}
}
Exemplo n.º 15
0
/* basic sequential allocation followed by 50 frees */
int test_alloc_3(int argc, char **argv) {
	strategies strategy;
	int lbound = 1;
	int ubound = 4;

	if (strategyFromString(*(argv+1))>0)
		lbound=ubound=strategyFromString(*(argv+1));

	for (strategy = lbound; strategy <= ubound; strategy++)
	{
		int correct_holes = 50;
		int correct_alloc = 50;
		int correct_largest_free = 1;
		int i;

		void* lastPointer = NULL;
		initmem(strategy,100);
		for (i = 0; i < 100; i++)
		{
			void* pointer = mymalloc(1);
			if ( i > 0 && pointer != (lastPointer+1) )
			{
				printf("Allocation with %s was not sequential at %i; expected %p, actual %p\n", strategy_name(strategy), i,lastPointer+1,pointer);
				return 1;
			}
			lastPointer = pointer;
		}

		for (i = 1; i < 100; i+= 2)
		{
			myfree(mem_pool() + i);
		}

		if (mem_holes() != correct_holes)
		{
			printf("Holes not counted as %d with %s\n", correct_holes, strategy_name(strategy));
			return	1;
		}

		if (mem_allocated() != correct_alloc)
		{
			printf("Memory not reported as %d with %s\n", correct_alloc, strategy_name(strategy));
			return	1;
		}

		if (mem_largest_free() != correct_largest_free)
		{
			printf("Largest memory block free not reported as %d with %s\n", correct_largest_free, strategy_name(strategy));
			return	1;
		}

		for(i=0;i<100;i++) {
		  if(mem_is_alloc(mem_pool()+i) == i%2) {
		    printf("Byte %d in memory claims to ",i);
		    if(i%2)
		      printf("not ");
		    printf("be allocated.  It should ");
		    if(!i%2)
		      printf("not ");
		    printf("be allocated.\n");
		    return 1;
		  }
		}
	}

	return 0;
}
Exemplo n.º 16
0
int rom_load()
{
	int f;
	byte c, *data, *header;
	int len = 0, rlen;


	f = open(romfile, O_RDONLY);
	if (f<0) {
       //  debug("Retry!");
       //  f = open(romfile, O_RDONLY);
       //  if (f<0) DIE("cannot open rom file: %s\n", romfile);
         DIE("cannot open rom file: %s\n", romfile);
      }
      else printf("File opened!\n");

	data = loadfile(f, &len);

      printf("Data loaded!\n");

	header = data = decompress(data, &len);
      printf("Data decompressed!\n");

	memcpy(rom.name, header+0x0134, 16);


	if (rom.name[14] & 0x80) rom.name[14] = 0;
	if (rom.name[15] & 0x80) rom.name[15] = 0;
	rom.name[16] = 0;

	c = header[0x0147];
	mbc.type = mbc_table[c];
	mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
	rtc.batt = rtc_table[c];
	mbc.romsize = romsize_table[header[0x0148]];
	mbc.ramsize = ramsize_table[header[0x0149]];

	if (!mbc.romsize) DIE("unknown ROM size %02X\n", header[0x0148]);
	if (!mbc.ramsize) DIE("unknown SRAM size %02X\n", header[0x0149]);

	rlen = 16384 * mbc.romsize;
	rom.bank = realloc(data, rlen);
	if (rlen > len) memset(rom.bank[0]+len, 0xff, rlen - len);

	ram.sbank = malloc(8192 * mbc.ramsize);

	initmem(ram.sbank, 8192 * mbc.ramsize);
	initmem(ram.ibank, 4096 * 8);

	mbc.rombank = 1;
	mbc.rambank = 0;

	c = header[0x0143];
	hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
	hw.gba = (hw.cgb && gbamode);

	if (strcmp(romfile, "-")) close(f);
      printf("Rom_load ok!\n");

	return 0;
}
Exemplo n.º 17
0
/* alloc, alloc, free, alloc */
int test_alloc_2(int argc, char **argv) {
	strategies strategy;
	int lbound = 1;
	int ubound = 4;

	if (strategyFromString(*(argv+1))>0)
		lbound=ubound=strategyFromString(*(argv+1));

	for (strategy = lbound; strategy <= ubound; strategy++)
	{
		int correct_holes;
		int correct_alloc;
		int correct_largest_free;
		int correct_small;
		void* first;
		void* second;
		void* third;
		int correctThird;

		initmem(strategy,100);

		first = mymalloc(10);
		second = mymalloc(1);
		myfree(first);
		third = mymalloc(1);

		if (second != (first+10))
		{
			printf("Second allocation failed; allocated at incorrect offset with strategy %s", strategy_name(strategy));
			return 1;
		}

		correct_alloc = 2;
		correct_small = (strategy == First || strategy == Best);

		switch (strategy)
		{
			case Best:
				correctThird = (third == first);
				correct_holes = 2;
				correct_largest_free = 89;
				break;
			case Worst:
				correctThird = (third == second+1);
				correct_holes = 2;
				correct_largest_free = 88;
				break;
			case First:
				correctThird = (third == first);
				correct_holes = 2;
				correct_largest_free = 89;
				break;
			case Next:
				correctThird = (third == second+1);
				correct_holes = 2;
				correct_largest_free = 88;
				break;
		        case NotSet:
			        break;
		}

		if (!correctThird)
		{
			printf("Third allocation failed; allocated at incorrect offset with %s", strategy_name(strategy));
			return 1;
		}

		if (mem_holes() != correct_holes)
		{
			printf("Holes counted as %d, should be %d with %s\n", mem_holes(), correct_holes, strategy_name(strategy));
			return	1;
		}

		if (mem_small_free(9) != correct_small)
		{
			printf("Small holes counted as %d, should be %d with %s\n", mem_small_free(9), correct_small, strategy_name(strategy));
			return	1;
		}

		if (mem_allocated() != correct_alloc)
		{
			printf("Memory reported as %d, should be %d with %s\n", mem_allocated(0), correct_alloc, strategy_name(strategy));
			return	1;
		}

		if (mem_largest_free() != correct_largest_free)
		{
			printf("Largest memory block free reported as %d, should be %d with %s\n", mem_largest_free(), correct_largest_free, strategy_name(strategy));
			return	1;
		}

	}

	return 0;
}
Exemplo n.º 18
0
Arquivo: main.c Projeto: ysei/pdp6
int
main()
{
	SDL_Event ev;
	SDL_MouseButtonEvent *mbev;
	SDL_MouseMotionEvent *mmev;
	SDL_Surface *op_surf, *ind_surf, *extra_surf;
	SDL_Rect op_panel = { 0, 274, 1280, 210 };
	SDL_Rect ind_panel = { 0, 64, 1280, 210 };
	SDL_Rect extra_panel = { 0, 0, 1280, 210 };
	int i;
	Light *l;
	Switch *sw;

//	void testinst(Apr*);
//	testinst(&apr);

	if(SDL_Init(SDL_INIT_VIDEO) < 0){
error:
		fprintf(stderr, "error: %s\n", SDL_GetError());
		return 1;
	}
	screen = SDL_SetVideoMode(1280, 484, 32, SDL_DOUBLEBUF);
	if(screen == NULL)
		goto error;

	if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
		fprintf(stderr, "error: init SDL_Image: %s\n", IMG_GetError());
		return 1;
	}

	op_surf = IMG_Load("op_panel.png");
	if(op_surf == NULL){
		fprintf(stderr, "Couldn't load op_panel.png\n");
		return 1;
	}
	ind_surf = IMG_Load("ind_panel.png");
	if(ind_surf == NULL){
		fprintf(stderr, "Couldn't load ind_panel.png\n");
		return 1;
	}
	extra_surf = IMG_Load("extra_panel.png");
	if(extra_surf == NULL){
		fprintf(stderr, "Couldn't load extra_panel.png\n");
		return 1;
	}

	keysurf[0] = IMG_Load("key_n.png");
	if(keysurf[0] == NULL){
		fprintf(stderr, "Couldn't load key_n.png\n");
		return 1;
	}
	keysurf[1] = IMG_Load("key_d.png");
	if(keysurf[1] == NULL){
		fprintf(stderr, "Couldn't load key_d.png\n");
		return 1;
	}
	keysurf[2] = IMG_Load("key_u.png");
	if(keysurf[2] == NULL){
		fprintf(stderr, "Couldn't load key_u.png\n");
		return 1;
	}

	lampsurf[0] = IMG_Load("lamp_off.png");
	if(lampsurf[0] == NULL){
		fprintf(stderr, "Couldn't load lamp_off.png\n");
		return 1;
	}
	lampsurf[1] = IMG_Load("lamp_on.png");
	if(lampsurf[1] == NULL){
		fprintf(stderr, "Couldn't load lamp_on.png\n");
		return 1;
	}

	switchsurf[0] = IMG_Load("switch_d.png");
	if(switchsurf[0] == NULL){
		fprintf(stderr, "Couldn't load switch_d.png\n");
		return 1;
	}
	switchsurf[1] = IMG_Load("switch_u.png");
	if(switchsurf[1] == NULL){
		fprintf(stderr, "Couldn't load switch_u.png\n");
		return 1;
	}

	l = op_lights;
	ir_lght   = l; l += 18;
	mi_lght   = l; l += 36;
	pc_lght   = l; l += 18;
	ma_lght   = l; l += 18;
	pih_lght  = l; l += 7;
	pir_lght  = l; l += 7;
	pio_lght  = l; l += 7;
	rest_lght = l;
	sw = switches;
	data_sw      = sw; sw += 36;
	ma_sw        = sw; sw += 18;
	rest_sw      = sw; sw += 4;
	rim_maint_sw = sw;
	l = ind_lights;
	mb_lght   = l; l += 36;
	ar_lght   = l; l += 36;
	mq_lght   = l; l += 36;
	fe_lght   = l; l += 9;
	sc_lght   = l; l += 9;
	ff_lght   = l;
	l = extra_lights;
	membus_lght = l; l += 36;
	pr_lght     = l; l += 8;
	rlr_lght    = l; l += 8;
	rla_lght    = l;
	for(i = 0; i < nelem(keys); i++){
		keys[i].r.x += op_panel.x;
		keys[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(op_lights); i++){
		op_lights[i].r.x += op_panel.x;
		op_lights[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(ind_lights); i++){
		ind_lights[i].r.x += ind_panel.x;
		ind_lights[i].r.y += ind_panel.y;
	}
	for(i = 0; i < nelem(extra_lights); i++){
		extra_lights[i].r.x += extra_panel.x;
		extra_lights[i].r.y += extra_panel.y;
	}
	for(i = 0; i < nelem(switches)-1; i++){
		switches[i].r.x += op_panel.x;
		switches[i].r.y += op_panel.y;
	}
	rim_maint_sw->r.x += extra_panel.x;
	rim_maint_sw->r.y += extra_panel.y;

	initmem();
	inittty();
	memset(&apr, 0xff, sizeof apr);
	apr.extpulse = 0;

/*	int frm = 0;
	time_t tm, tm2;
	tm = time(nil);*/
	for(;;){
/*
		frm++;
		tm2 = time(nil);
		if((tm2 - tm) > 5){
			print("fps: %f\n", (float)frm/(tm2-tm));
			tm = tm2;
			frm = 0;
		}
*/
//		usleep(1000);

		while(SDL_PollEvent(&ev))
			switch(ev.type){
			case SDL_MOUSEMOTION:
				mmev = (SDL_MouseMotionEvent*)&ev;
				mouse(0, mmev->state,
				      mmev->x, mmev->y);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mbev = (SDL_MouseButtonEvent*)&ev;
				mouse(mbev->button, mbev->state,
				      mbev->x, mbev->y);
				break;
			case SDL_QUIT:
				dumpmem();
				SDL_Quit();
				return 0;
			case SDL_USEREVENT:
				print("user\n");
				break;
			}
		setlights(apr.ir, ir_lght, 18);
		setlights(apr.mi, mi_lght, 36);
		setlights(apr.pc, pc_lght, 18);
		setlights(apr.ma, ma_lght, 18);
		setlights(apr.pih, pih_lght, 7);
		setlights(apr.pio, pio_lght, 7);
		setlights(apr.pir, pir_lght, 7);
		rest_lght[4].state = apr.run;
		rest_lght[5].state = apr.mc_stop;
		rest_lght[6].state = apr.pi_active;
		rest_lght[0].state = apr.sw_addr_stop   = rest_sw[0].state;
		rest_lght[1].state = apr.sw_repeat      = rest_sw[1].state;
		rest_lght[2].state = apr.sw_mem_disable = rest_sw[2].state;
		rest_lght[3].state = apr.sw_power       = rest_sw[3].state;
		apr.sw_rim_maint = rim_maint_sw->state;
		apr.data = getswitches(data_sw, 36);
		apr.mas = getswitches(ma_sw, 18);
		apr.key_start     = keys[0].state == 1;
		apr.key_readin    = keys[0].state == 2;
		apr.key_inst_cont = keys[1].state == 1;
		apr.key_mem_cont  = keys[1].state == 2;
		apr.key_inst_stop = keys[2].state == 1;
		apr.key_mem_stop  = keys[2].state == 2;
		apr.key_io_reset  = keys[3].state == 1;
		apr.key_exec      = keys[3].state == 2;
		apr.key_dep       = keys[4].state == 1;
		apr.key_dep_nxt   = keys[4].state == 2;
		apr.key_ex        = keys[5].state == 1;
		apr.key_ex_nxt    = keys[5].state == 2;
		apr.key_rd_off    = keys[6].state == 1;
		apr.key_rd_on     = keys[6].state == 2;
		apr.key_pt_rd     = keys[7].state == 1;
		apr.key_pt_wr     = keys[7].state == 2;

		setlights(apr.mb, mb_lght, 36);
		setlights(apr.ar, ar_lght, 36);
		setlights(apr.mq, mq_lght, 36);
		setlights(apr.fe, fe_lght, 9);
		setlights(apr.sc, sc_lght, 9);
		ff_lght[0].state = apr.key_ex_st;
		ff_lght[1].state = apr.key_ex_sync;
		ff_lght[2].state = apr.key_dep_st;
		ff_lght[3].state = apr.key_dep_sync;
		ff_lght[4].state = apr.key_rd_wr;
		ff_lght[5].state = apr.mc_rd;
		ff_lght[6].state = apr.mc_wr;
		ff_lght[7].state = apr.mc_rq;

		ff_lght[8].state = apr.if1a;
		ff_lght[9].state = apr.af0;
		ff_lght[10].state = apr.af3;
		ff_lght[11].state = apr.af3a;
		ff_lght[12].state = apr.et4_ar_pse;
		ff_lght[13].state = apr.f1a;
		ff_lght[14].state = apr.f4a;
		ff_lght[15].state = apr.f6a;

		ff_lght[16].state = apr.sf3;
		ff_lght[17].state = apr.sf5a;
		ff_lght[18].state = apr.sf7;
		ff_lght[19].state = apr.ar_com_cont;
		ff_lght[20].state = apr.blt_f0a;
		ff_lght[21].state = apr.blt_f3a;
		ff_lght[22].state = apr.blt_f5a;
		ff_lght[23].state = apr.iot_f0a;

		ff_lght[24].state = apr.fpf1;
		ff_lght[25].state = apr.fpf2;
		ff_lght[26].state = apr.faf1;
		ff_lght[27].state = apr.faf2;
		ff_lght[28].state = apr.faf3;
		ff_lght[29].state = apr.faf4;
		ff_lght[30].state = apr.fmf1;
		ff_lght[31].state = apr.fmf2;

		ff_lght[32].state = apr.fdf1;
		ff_lght[33].state = apr.fdf2;
		ff_lght[34].state = apr.ir & H6 && apr.mq & F1 && !apr.nrf3;
		ff_lght[35].state = apr.nrf1;
		ff_lght[36].state = apr.nrf2;
		ff_lght[37].state = apr.nrf3;
		ff_lght[38].state = apr.fsf1;
		ff_lght[39].state = apr.chf7;

		ff_lght[40].state = apr.dsf1;
		ff_lght[41].state = apr.dsf2;
		ff_lght[42].state = apr.dsf3;
		ff_lght[43].state = apr.dsf4;
		ff_lght[44].state = apr.dsf5;
		ff_lght[45].state = apr.dsf6;
		ff_lght[46].state = apr.dsf7;
		ff_lght[47].state = apr.dsf8;

		ff_lght[48].state = apr.dsf9;
		ff_lght[49].state = apr.msf1;
		ff_lght[50].state = apr.mpf1;
		ff_lght[51].state = apr.mpf2;
		ff_lght[52].state = apr.mc_split_cyc_sync;
		ff_lght[53].state = apr.mc_stop_sync;
		ff_lght[54].state = apr.shf1;
		ff_lght[55].state = apr.sc == 0777;

		ff_lght[56].state = apr.chf1;
		ff_lght[57].state = apr.chf2;
		ff_lght[58].state = apr.chf3;
		ff_lght[59].state = apr.chf4;
		ff_lght[60].state = apr.chf5;
		ff_lght[61].state = apr.chf6;
		ff_lght[62].state = apr.lcf1;
		ff_lght[63].state = apr.dcf1;

		ff_lght[64].state = apr.pi_ov;
		ff_lght[65].state = apr.pi_cyc;
		ff_lght[66].state = !!apr.pi_req;
		ff_lght[67].state = apr.iot_go;
		ff_lght[68].state = apr.a_long;
		ff_lght[69].state = apr.ma == apr.mas;
		ff_lght[70].state = apr.uuo_f1;
		ff_lght[71].state = apr.cpa_pdl_ov;

		ff_lght[72].state = !apr.ex_user;
		ff_lght[73].state = apr.cpa_illeg_op;
		ff_lght[74].state = apr.ex_ill_op;
		ff_lght[75].state = apr.ex_uuo_sync;
		ff_lght[76].state = apr.ex_pi_sync;
		ff_lght[77].state = apr.mq36;

		ff_lght[78].state = apr.key_rim_sbr;
		ff_lght[79].state = apr.ar_cry0_xor_cry1;
		ff_lght[80].state = apr.ar_cry0;
		ff_lght[81].state = apr.ar_cry1;
		ff_lght[82].state = apr.ar_ov_flag;
		ff_lght[83].state = apr.ar_cry0_flag;
		ff_lght[84].state = apr.ar_cry1_flag;
		ff_lght[85].state = apr.ar_pc_chg_flag;

		ff_lght[86].state = apr.cpa_non_exist_mem;
		ff_lght[87].state = apr.cpa_clock_enable;
		ff_lght[88].state = apr.cpa_clock_flag;
		ff_lght[89].state = apr.cpa_pc_chg_enable;
		ff_lght[90].state = apr.cpa_arov_enable;
		ff_lght[91].state = !!(apr.cpa_pia&4);
		ff_lght[92].state = !!(apr.cpa_pia&2);
		ff_lght[93].state = !!(apr.cpa_pia&1);

		setlights(membus0, membus_lght, 36);
		setlights(apr.pr, pr_lght, 8);
		setlights(apr.rlr, rlr_lght, 8);
		setlights(apr.rla, rla_lght, 8);

		SDL_BlitSurface(op_surf, NULL, screen, &op_panel);
		SDL_BlitSurface(ind_surf, NULL, screen, &ind_panel);
		SDL_BlitSurface(extra_surf, NULL, screen, &extra_panel);
		for(i = 0; i < nelem(keys); i++)
			SDL_BlitSurface(keys[i].surfs[keys[i].state],
			                NULL, screen, &keys[i].r);
		for(i = 0; i < nelem(op_lights); i++)
			SDL_BlitSurface(op_lights[i].surfs[op_lights[i].state && apr.sw_power],
			                NULL, screen, &op_lights[i].r);
		for(i = 0; i < nelem(ind_lights); i++)
			SDL_BlitSurface(ind_lights[i].surfs[ind_lights[i].state && apr.sw_power],
			                NULL, screen, &ind_lights[i].r);
		for(i = 0; i < nelem(extra_lights); i++)
			SDL_BlitSurface(extra_lights[i].surfs[extra_lights[i].state && apr.sw_power],
			                NULL, screen, &extra_lights[i].r);
		for(i = 0; i < nelem(switches); i++)
			SDL_BlitSurface(switches[i].surfs[switches[i].state],
			                NULL, screen, &switches[i].r);
		SDL_Flip(screen);
	}
}
Exemplo n.º 19
0
int main(int argn, char **argv) {
  int sound = 1;
  int jump = 0;

  if (argn >= 2) {
   switch (argv[1][0]) {
    case 'n' : sound = 0;
               break;
    case '1' : jump = 1;
               break;
    case '2' : jump = 2;
               break;
    case '3' : jump = 3;
               break;
    case '4' : jump = 4;
               break;
   }
  }

  memset(vesa,0,modes*sizeof(tvesa));
  //vesa[3].flags = 1; //erz-effekt kann 8 bit
  readconfig();
  if ((dflags & dfNosound)) sound = 0;

  initvesa(vesa,modes);

  tarjstream s("fulcrum.dat");
//  tstream s;

  if ( SDL_Init (SDL_INIT_VIDEO) != 0 ) exit("Error: Couldn't initialize SDL");
  atexit(SDL_Quit);


  i8_init();
  if (sound) initxm();

  int memsize = vesa[1].xres*vesa[1].yres*28 + 16000000;
  if (sound == 0) memsize -= 1000000;
  initmem(memsize);

  if (jump == 1) goto main;
  if (jump == 2) goto pic;
  if (jump == 3) goto extro;
  if (jump == 4) goto erz;

  //intro part
  setmode(0);

  initcredits(s,vesa[0]);
  initmese(s,vesa[0],1     ,0     ,0      ,0);
                   //camera,tracks,ambient,debug);
  if (sound) loadxm(s,"fx.rxm",0);
  startmese(0/*frame*/);

  if (keypressed()) {
    if (sound) rxmstop(xmStop);
    goto weg;
  }
  if (sound) rxmstop(xmFade);

//goto weg;
//if (keypressed()) getch();


  emptymem();


main:
  //main part
  setmode(1);
  initmoove(s,vesa[1]);

  if (sound) loadxm(s,"looping.rxm",0);
  startmoove();

  if (keypressed()) {
    if (sound) rxmstop(xmStop);
    goto weg;
  }
  if (sound) rxmstop(xmStop);


  emptymem();
pic:
  //adler pic
  setmode(2);
  ShowPic(s, vesa[2]);
  if (delay(8000)) goto weg;
  emptymem();
extro:
  //extro
  setmode(0);
//  initcredits(s,vesa[0]);
  initmese(s,vesa[0],0     ,1     ,1      ,0);
                   //camera,tracks,ambient,debug);

  if (sound) loadxm(s,"fx.rxm",0x20);
  startmese(/*60000*/0/*frame*/);

  if (keypressed()) {
    if (sound) rxmstop(xmStop);
    goto weg;
  }
  if (sound) rxmstop(xmFade);

  emptymem();

erz:
  //erzeffekt
  setmode(3);

  initerz(s,vesa[3]);

  if (sound) loadxm(s,"bunga.rxm",0);
  starterz();

  if (keypressed()) {
    if (sound) rxmstop(xmStop);
    goto weg;
  }
  if (sound) rxmstop(xmFade);
weg:
  if (sound) donexm();

  i8_done();
  textmode();
//checkit();

  return 0;
};
Exemplo n.º 20
0
int main (int argc, char **argv)
{
	LISP expr, val;
	char *progname, *prog = 0;

	progname = *argv++;
	for (--argc; argc>0 && **argv=='-'; --argc, ++argv) {
		char *p;

		for (p=1+*argv; *p; ++p) switch (*p) {
		case 'h':
			fprintf (stderr, "Usage: %s [-h] [-v] [-t] [-m#] prog [arg...]\n",
				progname);
			return (0);
		case 't':
			++trace;
			break;
		case 'v':
			++verbose;
			break;
		case 'm':
			if (! *++p) {
				if (argc <= 1)
					break;
				p = *++argv;
				--argc;
			}
			memsz = atoi (p);
			p += strlen (p) - 1;
			break;
		}
	}
	if (argc > 0) {
		prog = *argv++;
		--argc;
	}

	if (memsz < 1000)
		memsz = (sizeof (unsigned) < 4 ? 64000 : 256000) / sizeof (cell);
	if (verbose) {
		fprintf (stderr, "Micro Scheme Interpreter, Release 1.0\n");
		fprintf (stderr, "Memory size = %d bytes\n", memsz * sizeof (cell));
	}
	mem = (cell *) malloc (sizeof (cell) * memsz);
	gclabel = malloc (memsz);
	if (!mem || !gclabel) {
		fprintf (stderr, "Out of memory\n");
		return (-1);
	}

	if (prog && freopen (prog, "r", stdin) != stdin) {
		fprintf (stderr, "Cannot open %s\n", prog);
		return (-1);
	}

	initmem ();
	T = alloc (TBOOL);              /* логическая истина #t */
	ZERO = number (0);              /* целый ноль */
	ENV = cons (cons (symbol ("version"), number (10)), NIL);
	initcontext (stdfunc);
	for (;;) {
		gc ();
		if (isatty (0))
			printf ("> ");
		expr = getexpr ();
		if (feof (stdin))
			break;
		val = eval (expr, 0);
		if (verbose) {
			putexpr (expr, stdout);
			printf (" --> ");
			putexpr (val, stdout);
			putchar ('\n');
		}
	}
	return (0);
}
Exemplo n.º 21
0
int
main(int argc, char *argv[])
{
	int	c;
	char	*ptr;

	ERR_ZERO(&msgset);
	while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
		switch (c) {
		case 'a':	aflag++;	break;
		case 'b':	bflag = 1;	break;
		case 'c':	cflag = 1;	break;
		case 'd':	dflag = 1;	break;
		case 'e':	eflag = 1;	break;
		case 'F':	Fflag = 1;	break;
		case 'g':	gflag = 1;	break;
		case 'h':	hflag = 1;	break;
		case 'p':	pflag = 1;	break;
		case 'r':	rflag = 1;	break;
		case 's':	sflag = 1;	break;
		case 't':	tflag = 1;	break;
		case 'u':	uflag = 0;	break;
		case 'w':	wflag = 1;	break;
		case 'v':	vflag = 0;	break;
		case 'y':	yflag = 1;	break;
		case 'z':	zflag = 0;	break;

		case 'm':
			msglist();
			return(0);

		case 'X':
			for (ptr = strtok(optarg, ","); ptr;
			    ptr = strtok(NULL, ",")) {
				char *eptr;
				long msg = strtol(ptr, &eptr, 0);
				if ((msg == LONG_MIN || msg == LONG_MAX) &&
				    errno == ERANGE)
				    err(1, "invalid error message id '%s'",
					ptr);
				if (*eptr || ptr == eptr || msg < 0 ||
				    msg >= ERR_SETSIZE)
					errx(1, "invalid error message id '%s'",
					    ptr);
				ERR_SET(msg, &msgset);
			}
			break;
		case '?':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage();

	/* open the input file */
	if ((yyin = fopen(argv[0], "r")) == NULL)
		err(1, "cannot open '%s'", argv[0]);

	/* initialize output */
	outopen(argv[1]);

	if (yflag)
		yydebug = 1;

	initmem();
	initdecl();
	initscan();
	initmtab();

	yyparse();

	/* Following warnings cannot be suppressed by LINTED */
	nowarn = 0;

	chkglsyms();

	outclose();

	return (nerr != 0);
}
Exemplo n.º 22
0
int
main(int argc, char *argv[])
{
	int	c, i;
	size_t	len;
	char	*lname;

	libs = xcalloc(1, sizeof (char *));

	opterr = 0;
	while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) {
		switch (c) {
		case 's':
			sflag = 1;
			break;
		case 't':
			tflag = 1;
			break;
		case 'u':
			uflag = 0;
			break;
		case 'x':
			xflag = 1;
			break;
		case 'p':
			pflag = 1;
			break;
		case 'C':
			len = strlen(optarg);
			lname = xmalloc(len + 10);
			(void)sprintf(lname, "llib-l%s.ln", optarg);
			libname = lname;
			Cflag = 1;
			uflag = 0;
			break;
		case 'H':
			Hflag = 1;
			break;
		case 'h':
			hflag++;
			break;
		case 'F':
			Fflag = 1;
			break;
		case 'l':
			for (i = 0; libs[i] != NULL; i++)
				continue;
			libs = xrealloc(libs, (i + 2) * sizeof (char *));
			libs[i] = xstrdup(optarg);
			libs[i + 1] = NULL;
			break;
		case '?':
			usage();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc == 0)
		usage();

	initmem();

	/* initialize hash table */
	inithash();

	inittyp();

	for (i = 0; i < argc; i++)
		readfile(argv[i]);

	/* write the lint library */
	if (Cflag) {
		forall(mkstatic);
		outlib(libname);
	}

	/* read additional libraries */
	for (i = 0; libs[i] != NULL; i++)
		readfile(libs[i]);

	forall(mkstatic);

	mainused();

	/* perform all tests */
	forall(chkname);

	exit(0);
	/* NOTREACHED */
}