예제 #1
0
파일: monitor.c 프로젝트: ayourtch/chimera
void create_trees (JRB hosts)
{
    int i = 0;
    JRB node;
    Host *host;

    nstable = 0;
    nnon_stable = 0;

    stable = make_jrb ();
    non_stable = make_jrb ();

    jrb_traverse (node, hosts)
    {

        host = (Host *) node->val.v;
        if (i++ % NON_STABLE == 0)
        {
            jrb_insert_str (non_stable, host->hnp, new_jval_v (host));
            nnon_stable++;
        }
        else
        {
            jrb_insert_str (stable, host->hnp, new_jval_v (host));
            nstable++;
        }
    }
예제 #2
0
int main()
{
  JRB myJ = make_jrb();
  JRB nod;
  Jval tmp = new_jval_i(5);
  char *key = "luong";
  jrb_insert_str(myJ, key, tmp);
  tmp = new_jval_i(4);
  jrb_insert_str(myJ, key, tmp);
  jrb_traverse(nod, myJ){
    printf("%d ", jval_i(nod->val));
  }
예제 #3
0
void process_files(Dllist dir_list, JRB inode, JRB paths, char *name, JRB links){
	int dup_inode, dup_path;
	char buf[PATH_MAX+1];
	tar *t;

	dup_inode = 1;
	dup_path = 1;
	t = (tar*) malloc(sizeof(tar));

	strcpy(t->name,realpath(name, buf));

	if(lstat(t->name, &t->istat) < 0){
		fprintf(stderr,"ERROR: %s No such file or directory\n",t->name);
				exit(1);
	}

	if(jrb_find_str(paths,realpath(t->name,buf)) != NULL){ //my problem could be here
		dup_path = 0;
		jrb_insert_str(links,strdup(name),
				new_jval_v(jrb_find_str(paths,realpath(t->name,buf))));

//		printf("Ignoring Duplicate %s\n",t->name);
	}

	if(jrb_find_int(inode, t->istat.st_ino) != NULL){
		dup_inode = 0;
//		jrb_insert_str(links,strdup(t->name),
//				new_jval_v(jrb_find_str(paths,realpath(t->name,buf))));
//		printf("Ignoring Duplicate %s\n",t->name);
	}

	if(dup_path && dup_inode) { 
		jrb_insert_str(paths,strdup(realpath(t->name,buf)),new_jval_v(t));
		jrb_insert_int(inode,(int)t->istat.st_ino,new_jval_v(t));
	}

	if(S_ISDIR(t->istat.st_mode)){
		trav_dir(dir_list, inode, paths, name);
	}


}
예제 #4
0
파일: error.c 프로젝트: steve-m/m8cutils
void set_file(char *name)
{
    JRB entry;

    if (!*name)
	name = "<stdin>";
    entry = jrb_find_str(file_names,name);
    if (entry)
	name = jval_v(jrb_val(entry));
    else {
	name = stralloc(name);
	jrb_insert_str(file_names,name,new_jval_v(name));
    }
    current_loc.file = name;
    current_loc.line = 1;
}
예제 #5
0
main()
{
  JRB b;
  JRB bn;
  IS is;

  is = new_inputstruct(NULL);
  b = make_jrb();

  while (get_line(is) >= 0) {
    (void) jrb_insert_str(b, strdup(is->text1), new_jval_v(NULL));
  }

  jrb_traverse(bn, b) {
    printf("%s", jval_s(bn->key));
  }
예제 #6
0
JRB read_hosts (char *fn, int *nhosts)
{

    FILE *fp;
    char s[256];
    char hn[128];
    int port;
    Key key;
    JRB hosts;
    Host *host;
    char keyinput[64];

    fp = fopen (fn, "r");
    if (fp == NULL)
	{
	    perror (fn);
	    exit (1);
	}

    hosts = make_jrb ();
    *nhosts = 0;

    while (fgets (s, 256, fp) != NULL)
	{
	    sscanf (s, "%s %d %s", hn, &port, keyinput);
	    host = (Host *) malloc (sizeof (Host));
	    host->name = strdup (hn);
	    host->port = port;

	    str_to_key (keyinput, &key);
	    key_assign (&(host->key), key);
	    sprintf (s, "%s:%d", hn, port);
	    host->hnp = strdup (s);
	    host->pid = 0;
	    jrb_insert_str (hosts, strdup (s), new_jval_v (host));
	    *nhosts++;
	}

    fclose (fp);

    return (hosts);

}
예제 #7
0
main()
{
  IS is;
  JRB t, tmp;
  int i;
  int j;
  int x;

  j = 0;
  t = make_jrb();
  is = new_inputstruct(NULL);

  while (get_line(is) >= 0) {
    for (i = 0; i < is->NF; i++) {
      jrb_insert_str(t, strdup(is->fields[i]), new_jval_i(j));
      j++;
    }
  }

  jrb_traverse(tmp, t) {
    x = strlen(tmp->key.s);
    printf("%c", tmp->key.s[tmp->val.i%x]);
  }
예제 #8
0
main()
{
  JRB level_1, level_2;
  JRB bn, bn2;
  IS is;

  is = new_inputstruct(NULL);
  level_1 = make_jrb();

  while (get_line(is) >= 0) {
    bn = jrb_find_int(level_1, atoi(is->text1));
    if (bn == NULL) {
      bn = jrb_insert_int(level_1, atoi(is->text1), 
                               new_jval_v((void *)make_jrb()));
    }
    level_2 = (JRB ) jval_v(bn->val);
    jrb_insert_str(level_2, strdup(is->text1), new_jval_v(NULL));
  }

  jrb_traverse(bn, level_1) {
    level_2 = (JRB ) jval_v(bn->val);
    jrb_traverse(bn2, level_2) {
      printf("%s", bn2->key.s);
    }
예제 #9
0
파일: vcd2fst.c 프로젝트: Pidbip/egtkwave
static char *get_scopename(void *xc, FILE *extload)
{
static char sbuff[65537];
char * rc;
#ifdef _WAVE_HAVE_JUDY
PPvoid_t PPValue;
#else
JRB str;
Jval jv;
#endif

for(;;)
        {
        rc = fgets(sbuff, 65536, extload);
        if(rc)
		{
                if(isspace(rc[0]))
                        {
                        char sbuff2[65537];

                        sbuff2[0] = 0;

                        if(strstr(rc+1, "Struct Name:"))
                                {
                                sscanf(rc+14,"%s", sbuff2);
                                if(sbuff2[0])
                                        {
                                        sprintf(rc, "Scope: vcd_struct %s NULL\n", sbuff2);
                                        }
                                }
                        else
                        if(strstr(rc+1, "Struct End"))
                                {
                                sprintf(rc, "Upscope:\n");  
                                }
			}
		}
	else
                {
                return(NULL);
                }

	if(rc[0] == 'V')
		{
                if(!strncmp("Var: ", rc, 5))
                        {
                        char *pnt = rc + 5;
                        char *pntd = strrchr(pnt, ':');

                        if(pntd)
                                {
                                unsigned char vd = FST_VD_IMPLICIT;

                                pntd = strchr(pntd, ' ');
                                if(pntd)
                                        {
                                        pntd++;
                                        if(*pntd == 'o')
                                                {
                                                vd = FST_VD_OUTPUT;
                                                }
                                        else
                                        if(!strncmp(pntd, "in", 2))
                                                {
                                                vd = (pntd[2] == 'p') ? FST_VD_INPUT : FST_VD_INOUT;
                                                }
                                        }

				var_direction[var_direction_idx++] = vd;
                                }
			}
		}
	else
        if(rc[0] == 'S')
                {
                if(!strncmp(rc, "Scope:", 6))
                        {
                        char vht[2048];
                        char cname[2048];
                        char ctype[2048];
			int mtype = FST_ST_VCD_MODULE;

			cname[0] = ctype[1] = 0;

                        sscanf(rc+6, "%s %s %s", vht, cname, ctype+1);
			if(!strncmp("vcd_", vht, 4))
				{
				switch(vht[4])
					{
					case 'g':	mtype = FST_ST_VCD_GENERATE; break; /* other code looks for non-modules to replace type with */
					case 's':	mtype = FST_ST_VCD_STRUCT;   break; /* other code looks for non-modules to replace type with */
					default:	break;
					}
				}
			else
			if(!strncmp("sv_", vht, 3))
				{
				switch(vht[3])
					{
					case 'i':	mtype = FST_ST_VCD_INTERFACE; break; /* other code looks for non-modules to replace type with */
					default:	break;
					}
				}
                        else             
                        if(!strncmp(vht, "vhdl_", 5))
                                {
                                switch(vht[5])   
                                        {                
                                        case 'a':       mtype = FST_ST_VHDL_ARCHITECTURE; break;
                                        case 'r':       mtype = FST_ST_VHDL_RECORD; break;
                                        case 'b':       mtype = FST_ST_VHDL_BLOCK; break;
                                        case 'g':       mtype = FST_ST_VHDL_GENERATE; break;
                                        case 'i':       mtype = FST_ST_VHDL_IF_GENERATE; break;  
                                        case 'f':       mtype = (vht[6] == 'u') ? FST_ST_VHDL_FUNCTION : FST_ST_VHDL_FOR_GENERATE; break;
                                        case 'p':       mtype = (!strncmp(vht+6, "roces", 5)) ? FST_ST_VHDL_PROCESS: FST_ST_VHDL_PROCEDURE; break;
                                        default:        break;
                                        }
                                }

			ctype[0] = mtype + 1; /* bias for zero terminated string */

                        fst_scope_name = fstReaderPushScope(xc, cname, NULL);

			/* process fst_scope_name + cname vs ctype here */
			if((strcmp(ctype+1, "NULL") && strcmp(cname, ctype+1)) || (mtype != FST_ST_VCD_MODULE))
				{
#ifdef _WAVE_HAVE_JUDY
				PPValue = JudySLIns(&PJArray, (uint8_t *)fst_scope_name, PJE0);
				if(!*((char **)PPValue))
					{
					*((char **)PPValue) = strdup(ctype);
					}
#else
				char cstring[65537];
				strcpy(cstring, fst_scope_name);
				str = jrb_find_str(comp_name_jrb, cstring);
				if(!str)
					{
					jv.s = strdup(ctype);
					jrb_insert_str(comp_name_jrb, strdup(cstring), jv);
					}
#endif
				}
                        }
                }
        else
        if(rc[0] == 'U')
                {
                fst_scope_name = fstReaderPopScope(xc);
                }
        }

return(rc);
}
예제 #10
0
main(int argc, char **argv)
{
  IS is;
  JRB people, tmp;
  JRB elevators;
  double t;
  Elevator *e;
  char name[100];
  Person *p;

  elevators = make_jrb();
  people = make_jrb();
  is = new_inputstruct(NULL);

  while (get_line(is) > 0) {
    sscanf(is->fields[0], "%lf", &t);
    if (strcmp(is->fields[1], "Elevator") == 0) {
      e = get_elevator(atoi(is->fields[2]), elevators);
      if (strcmp(is->fields[3], "opening") == 0) {
        if (e->door != 0) {
          printf("Line %d: Elevator %d opening a door that's already open\n", is->line, e->id);
          exit(1);
        }
        if (e->state == 'O') {
          printf("Line %d: Elevator %d opening a door twice\n", is->line, e->id);
          exit(1);
        }
        if (e->state == 'C') {
          printf("Line %d: Elevator %d opening a door that is closing\n", is->line, e->id);
          exit(1);
        }
        e->state = 'O';
        e->time = t;
      } else if (strcmp(is->fields[3], "closing") == 0) {
        if (e->door != 1) {
          printf("Line %d: Elevator %d closing a door that's already closed\n", is->line, e->id);
          exit(1);
        }
        if (e->state == 'C') {
          printf("Line %d: Elevator %d closing a door twice\n", is->line, e->id);
          exit(1);
        }
        if (e->state == 'O') {
          printf("Line %d: Elevator %d closing a door that is opening\n", is->line, e->id);
          exit(1);
        }
        e->state = 'C';
        e->time = t;
      } else if (strcmp(is->fields[5], "closed.") == 0) {
        if (e->state != 'C') {
          printf("Line %d: Elevator %d closed a door that was not closing.\n", is->line, e->id);
          exit(1);
        }
        e->state = 'R';
        e->door = 0;
        e->time = t;
      } else if (strcmp(is->fields[5], "open.") == 0) {
        if (e->state != 'O') {
          printf("Line %d: Elevator %d opened a door that was not opening.\n", is->line, e->id);
          exit(1);
        }
        e->state = 'R';
        e->door = 1;
        e->time = t;
      } else if (strcmp(is->fields[3], "moving") == 0) {
        if (e->state != 'R') {
          printf("Line %d: Elevator %d moving from a non-rest state.\n", is->line, e->id);
          exit(1);
        }
        if (e->door != 0) {
          printf("Line %d: Elevator %d moving when the door is open.\n", is->line, e->id);
          exit(1);
        }
        if (atoi(is->fields[6]) != e->floor) {
          printf("Line %d: Elevator %d moving from a bad floor.\n", is->line, e->id);
          exit(1);
        }
        e->floor = atoi(is->fields[9]);
        e->state = 'M';
        e->time = t;
      } else if (strcmp(is->fields[3], "arrives") == 0) {
        if (e->state != 'M') {
          printf("Line %d: Elevator %d arriving from a non-moving state.\n", is->line, e->id);
          exit(1);
        }
        if (e->door != 0) {
          printf("Line %d: Elevator %d arriving when the door is open.\n", is->line, e->id);
          exit(1);
        }
        if (atoi(is->fields[6]) != e->floor) {
          printf("Line %d: Elevator %d arriving at the wrong floor (%d).\n", is->line, e->id, e->floor);
          exit(1);
        }
        e->state = 'R';
        e->time = t;
      }
    } else if (strcmp(is->fields[1], "Simulation") == 0) {
      exit(0);
    } else {
      sprintf(name, "%s %s", is->fields[1], is->fields[2]);
      if (strcmp(is->fields[3], "arrives") == 0) {
        if (jrb_find_str(people, name) != NULL) {
          printf("%d: Duplicate person %s\n", is->line, name);
          exit(1);
        }
        p = talloc(Person, 1);
        p->name = strdup(name);
        jrb_insert_str(people, p->name, new_jval_v((void *) p));
        p->from = atoi(is->fields[6]);
        p->to = atoi(is->fields[12]);
        p->state = 'A';
      } else {
        tmp = jrb_find_str(people, name);
        if (tmp == NULL) {
          printf("Line %d: Person %s doesn't exist\n", is->line, name);
          exit(1);
        }
        p = (Person *) tmp->val.v;
        if (strcmp(is->fields[4], "on") == 0) {
          if (p->state != 'A') {
            printf("Line %d: Person %s not in arriving state when getting on an elevator\n", is->line, p->name);
            exit(1);
          }
          if (atoi(is->fields[9]) != p->from) {
            printf("Line %d: Person %s not getting on the proper floor\n", is->line, p->name);
            exit(1);
          }
          e = get_elevator(atoi(is->fields[6]), elevators);
          if (e->floor != p->from) {
            printf("Line %d: Person %s getting on an elevator not on the right floor\n", is->line, p->name);
            exit(1);
          }
          if (e->door != 1) {
            printf("Line %d: Person %s getting on an elevator whose door isn't open.\n", is->line, p->name);
            exit(1);
          }
          if (e->state != 'R') {
            printf("Line %d: Person %s getting on an elevator who is not at rest.\n", is->line, p->name);
            exit(1);
          }
          p->state = 'O';
          p->e = e;
        } else if (strcmp(is->fields[4], "off") == 0) {
          if (p->state != 'O') {
            printf("Line %d: Person %s not on the elevator when getting off\n", is->line, p->name);
            exit(1);
          }
          if (atoi(is->fields[9]) != p->to) {
            printf("Line %d: Person %s not getting off on the proper floor\n", is->line, p->name);
            exit(1);
          }
          e = get_elevator(atoi(is->fields[6]), elevators);
          if (e != p->e) {
            printf("Line %d: Person %s getting off the wrong elevator\n", is->line, p->name);
            exit(1);
          }
          if (e->floor != p->to) {
            printf("Line %d: Person %s getting off an elevator not on the right floor\n", is->line, p->name);
            exit(1);
          }
          if (e->door != 1) {
            printf("Line %d: Person %s getting off an elevator whose door isn't open.\n", is->line, p->name);
            exit(1);
          }
          if (e->state != 'R') {
            printf("Line %d: Person %s getting off an elevator who is not at rest.\n", is->line, p->name);
            exit(1);
          }
          p->state = 'F';
        } else if (strcmp(is->fields[4], "done.") == 0) {
          if (p->state != 'F') {
            printf("Line %d: Person %s done before getting off the elevator\n", is->line, p->name);
            exit(1);
          }
          jrb_delete_node(tmp);
          free(p->name);          
          free(p);
        }
      }
    }
  }
  exit(0);
}
예제 #11
0
main(int argc, char **argv)
{

//most of our variables and data structures
int x;
unsigned int j;
int i;
long hSize;
char c;
char experiment[2];
char absName[10000];
char locName[10000];
char otherName[10000];
char input[10000];
JRB check;
Dllist names;
Dllist otherNames;
JRB addresses;
ip *fullAddress;
unsigned int count;
char * buffer;
int hosts;
int killLoc,killAbs,noAbs;
unsigned char ipAddress[4];
unsigned char num[4];
unsigned int actNum[4];
unsigned int numOfNames;

//we initialize addresses, it will hold ALL the names as keys that link to their ip struct
addresses = make_jrb();

//we set hSize based off what the lab assignment said
hSize = 350000;
//allocate buffer
buffer = (char*) malloc(sizeof(char) * hSize);
//open descriptor
hosts = open("converted", O_RDONLY);
//read into buffer then close
read(hosts,buffer,hSize);
close(hosts);

//set x which we use to determine when to terminate 
//data assignment loop
x = 0;

while (x < hSize)
{

/* We initialize names and otherNames every time through loop. There is a reason
   there isn't just one e.g just names that is explained below. */
names = new_dllist();
otherNames = new_dllist();


/*We assign bytes from position determined by x e.g our place in the buffer
  to unsigned chars that comprise the IP address*/

memcpy(&ipAddress[0],buffer+x,sizeof(char));
memcpy(&ipAddress[1],buffer+x+1,sizeof(char));
memcpy(&ipAddress[2],buffer+x+2,sizeof(char));
memcpy(&ipAddress[3],buffer+x+3,sizeof(char));

/*We assign bytes from position determined by x e.g our place in the buffer
  to unsigned chars which we use to determine number of names*/

memcpy(&num[0],buffer+x+4,sizeof(unsigned char));
memcpy(&num[1],buffer+x+5,sizeof(unsigned char));
memcpy(&num[2],buffer+x+6,sizeof(unsigned char));
memcpy(&num[3],buffer+x+7,sizeof(unsigned char));

//we increment x e.g our position in buffer by 8 since we just checked 8 bytes */
x += 8;

/*we assign each of those unsigned chars as unsigned ints */
for (i = 0; i < 4; i++)
	actNum[i] = num[i];	

//we shift the uints into their proper position 
for (i = 3; i >= 0; i--)
	actNum[i] << (3-i)*8;

/*We set numOfNames to 0 and then or it with all of our unsigned ints to get proper
of names*/
numOfNames = 0;
for (i = 0; i < 4; i++)
	numOfNames = numOfNames | actNum[i];

/* We use number of names to determine how many times we need to run our
   names assignment loop */
for (j = 0; j < numOfNames; j++)
{
/*We use these three values to manage our loops e.g killLoc ends local loop
  killAbs ends absLoop. Note the distinction between killAbs and noAbs.
  KillAbs merely implies that we are done checking for absolute names.
  Noabs implies that there was no absolute name on this loop through. */
killLoc = 0;
killAbs = 0;
noAbs = 0;
while (!killLoc)
{
/* We assign byte from x e.g position in the buffer
   to a char and then increment x */
memcpy(&c,buffer+x,sizeof(char));
x++;
/* We use our char c to build a string and
   then concatenate with absName. */
experiment[0] = c;
experiment[1] = '\0';
strcat(absName,experiment);

/*if we see a period we kill local loop and
  move onto absolute loop*/
if (c == '.')
	killLoc = 1;
/*if we see a null terminating character we kill local loop, skip absolute 
  loop and set noabs to true. If we don't see a period or a null
  terminating character, we concatenate our local name.*/
else if(c == '\0')
{
	killLoc = 1;
	killAbs = 1;
	noAbs = 1;
}
else
	strcat(locName,experiment);
}
while (!killAbs)
{
/*Basically the same as the local loop, except now we
  just keep going until there is a null terminating 
  character without worrying about the period. If 
  there is an abs, noabs set to false is implicit
  from the start of the loop e.g we set it to false
  and only the local loop can set it to true.*/
memcpy(&c,buffer+x,sizeof(char));
x++;
experiment[0] = c;
experiment[1] = '\0';
strcat(absName,experiment);

if (c == '\0')
	killAbs = 1;
}

/*We add our local name and (if there is one) absolute name
  to names and otherNames.*/
dll_append(names,new_jval_s(strdup(locName)));
dll_append(otherNames,new_jval_s(strdup(locName)));
if (!noAbs)
{
	dll_append(names,new_jval_s(strdup(absName)));
	dll_append(otherNames,new_jval_s(strdup(absName)));
}
//We empty out our locName and absName for the next pass	
strcpy(locName,"");
strcpy(absName,"");
}

/*I have these variables down here for readability*/
Dllist tmp;
Dllist temp;
char final[10000];
char inner[10000];
dll_traverse(tmp,names)
{
	//assign the ip and copy name into final
	fullAddress = (ip *) tmp->val.v; 
	strcpy(final,jval_s(tmp->val));
	
	//initialize jrb list in ip
	fullAddress->names = make_jrb();
	
	/*Traverse through otherNames to assign the ip's names. The reason
	  we have otherNames and not just names is that running names
	  again within this loop messes up the data. Note that otherNames
	  contains the exact same content as names.*/
	dll_traverse(temp,otherNames)
	{
		strcpy(inner,jval_s(temp->val));
		jrb_insert_str(fullAddress->names,strdup(inner),new_jval_v(NULL));
	
	}
	//assign the ip address
	for (i = 0; i < 4; i++)
		fullAddress->address[i] = ipAddress[i];
	//insert into addresses

	jrb_insert_str(addresses,strdup(final),new_jval_v(fullAddress));
	
	
}