示例#1
0
void productionRule(){
	if(lookahead==OR){
		//printf(" %s", val);
		arraylist_add(stringArray,val);
		arraylist_add(intArray,lookahead);
		//strcpy(list[count],str); 
		match(OR);
		if(lookahead==EOLN){
			//printf(" ep");
			arraylist_add(stringArray,"Epsilon");
			arraylist_add(intArray,7);
			//strcpy(list[count],"epsilon");
		}
		rule();	productionRule();
	}
	else if(lookahead==SEMI){
		arraylist_add(finalString, stringArray);
		arraylist_add(finalInt,intArray);
		counter++;

		stringArray = arraylist_create(objEquals);
		intArray = arraylist_create(objEquals);
		return;}
	else if(lookahead==EOLN) {
		return;}
	else printf("\nPR");
}
示例#2
0
main(int argc, char**argv) {
	lookahead = yylex();
	stringArray = arraylist_create(objEquals);
	intArray = arraylist_create(objEquals);
	finalString = arraylist_create(objEquals);
	finalInt = arraylist_create(objEquals);
	p1Int = arraylist_create(objEquals);
	p1Str = arraylist_create(objEquals);
	p2Int = arraylist_create(objEquals);
	p2Str = arraylist_create(objEquals);


	prodList();
	if(lookahead!=0){
		printf("error");
		return 0;
	}	

	int r,c;//=arraylist_size(arraylist_get(finalString,0));
	int i,j; //counters

	//printf("\nTHIS IS THE SIZE %d\n", s);
	r=arraylist_size(finalString);//r is row
	for (i=0;i<r;i++){
		c=arraylist_size(arraylist_get(finalString,i));
		for(j=0;j<c;j++){
			char *str=arraylist_get(arraylist_get(finalString,i),j);
			int *num=arraylist_get(arraylist_get(finalInt,i),j);
			//printf("%s",str);

			if (arraylist_get(arraylist_get(finalInt,i),(j+1))==GOES)
				printf("\n%s ",str);
			else if (num==GOES)
				printf("%s\t\t",str);
			else if (num==OR)
				printf("\n\t%s\t",str);
			else if (num==7)
				printf("");
			else printf("%s ",str);
		}
	}

	printf("\n");
	passOne();


}
示例#3
0
文件: player.c 项目: janisz/unix
Player* createPlayer(const char *nick, int attribute, int position,
					 int descriptor, arraylist *players, Map* map)
{
	Player *p = (Player*)malloc(sizeof(Player));
	assert(p);
	strncpy(p->nick, nick, NICK_LENGTH);
	p->attribute = attribute;
	p->position = position;
	p->descriptor = descriptor;
	p->players = players;
	p->buffor = arraylist_create();
	p->map = map;
	pthread_mutex_init((p->bufforLock), NULL);
	pthread_cond_init((p->bufforCondition), NULL);
	return p;
}
示例#4
0
int main(int argc, char **argv)
{
    hash_t = hashtable_create();

    array_a = arraylist_create();
    hashtable_set(hash_t, "application name", "Test Application");

    arraylist_add(array_a, "abcd");
    LOG.debug = 1;
    //LOG.error_log_path = "error.log";
    log_init();
    log_debug("Starting server now...\n");
    config_init();
    parse_conf();
    read_logfile("./test.log");
    hashtable_destroy(hash_t);
    arraylist_destroy(array_a);
    return 0;
}
示例#5
0
JNIEXPORT jstring JNICALL
Java_universe_constellation_orion_viewer_djvu_DjvuDocument_getText(JNIEnv *env, jobject thiz, int pageNumber,
		int startX, int startY, int width, int height)
{

    LOGI("==================Start Text Extraction==============");

    miniexp_t pagetext;
    while ((pagetext=ddjvu_document_get_pagetext(doc,pageNumber,0))==miniexp_dummy) {
      //handle_ddjvu_messages(ctx, TRUE);
    }

    if (miniexp_nil == pagetext) {
        return NULL;
    }
//
    ddjvu_status_t status;
    ddjvu_pageinfo_t info;
    while ((status = ddjvu_document_get_pageinfo(doc, pageNumber, &info)) < DDJVU_JOB_OK) {
        //nothing
    }

	LOGI("Extraction rectangle=[%d,%d,%d,%d]", startX, startY, width, height);

	Arraylist values = arraylist_create();

    int w = info.width;
    int h = info.height;
    fz_bbox target = {startX, h - startY - height, startX + width, h - startY};
    LOGI("Extraction irectangle=[%d,%d,%d,%d]", target.x0, target.y0, target.x1, target.y1);

	extractText(pagetext, values, &target);

	arraylist_add(values, 0);

    LOGI("Data: %s", arraylist_getData(values));
    jstring result = (*env)->NewStringUTF(env, arraylist_getData(values));
    arraylist_free(values);

    return result;
}
示例#6
0
文件: map.c 项目: janisz/unix
Map createMap(int width, int height, char *map)
{
	Map m;
	m.width = width;
	m.height = height;
	m.map = (char*)malloc(sizeof(char)*MAP_SIZE(m));
	assert(m.map);
	m.mutexs = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)*MAP_SIZE(m));
	assert(m.mutexs);
	m.rooms = arraylist_create();

	for (int i=0; i<MAP_SIZE(m); i++) {
		pthread_mutex_init(&m.mutexs[i], NULL);
	}

	strncpy(m.map, map, MAP_SIZE(m));

	setRooms(&m);

	return m;
}
示例#7
0
MIRRORENVP 
mirrorenv_open(char *basedir)
{
	MIRRORENVP mdb ;
	char configfile[1024] ;
	int rc ;

	mdb = malloc(sizeof(MIRRORENV)) ;
	if (! mdb) {
		return NULL ;
	}

	mdb->mlist = arraylist_create(5) ;
	if (! mdb->mlist) {
		free(mdb) ;
		return NULL ;
	}

	sprintf(configfile, "%s/mirrors", basedir) ;
	mdb->configfile = strdup(configfile) ;

	rc = arraylist_setcomparefunc(mdb->mlist, mcomparefunc) ;
	rc = arraylist_setitemfreefunc(mdb->mlist, mfreefunc) ;
	rc = arraylist_setitemfindfunc(mdb->mlist, mfindfunc) ;

	rc = read_mconfig_file(mdb->mlist, mdb->configfile) ;

	if (! rc) {
		arraylist_destroy(mdb->mlist) ;
		free(mdb->configfile) ;
		free(mdb) ;
		return NULL ;
	}

	return mdb ;
}
示例#8
0
int main( int argc, char *argv[] )
{
  /* for parsing args */
  extern char *optarg;
  extern int optind;
  int ch;

  /* vars */
  int i,j;
  int listenfd;

  /* select vars */
  fd_set read_set;
  int fdmax;

  /* client arr */
  Arraylist clientList;
  /* channel arr */
  Arraylist channelList;

  /* servername */
  char servername[MAX_SERVERNAME+1];

  while ((ch = getopt(argc, argv, "hD:")) != -1)
  switch (ch) {
  case 'D':
    if (set_debug(optarg)) {
      exit(0);
    }
    break;
  case 'h':
  default: /* FALLTHROUGH */
    usage();
  }
  argc -= optind;
  argv += optind;

  if (argc < 2) {
    usage();
  }
  signal(SIGPIPE, SIG_IGN);
  init_node(argv[0], argv[1]);

  printf( "I am node %lu and I listen on port %d for new users\n", curr_nodeID, curr_node_config_entry->irc_port );

  /* Start your engines here! */
  if (gethostname(servername,MAX_SERVERNAME) < 0){
    perror("gethostname");
    return EXIT_FAILURE;
  }
  servername[MAX_SERVERNAME] = '\0';

  /* delegate all function calling to setupListenSocket.
        It should print out relevant err messages. */
  listenfd = setupListenSocket(curr_node_config_entry->irc_port);
  if (listenfd < 0){
    return EXIT_FAILURE;
  }

  /* initialize client array */
  clientList = arraylist_create();

  /* initialize channel array */
  channelList = arraylist_create();

  /* prepare for select */
  fdmax = listenfd;
  FD_ZERO(&master_set);
  FD_ZERO(&write_set);
  FD_SET(listenfd,&master_set);

  /* FD_ZERO(&write_set);  initially no data to write */

  /* main loop!! */
  for (;;){
    int retval;
    read_set = master_set;

    /* wait until any sockets become available */
    retval = select(fdmax+1,&read_set,&write_set,NULL,NULL);

    if (retval <= 0){
      if (retval < 0)
      DEBUG_PERROR("select");
      continue; /* handle errors gracefully and wait again if timed out (it shouldn't)*/
    }
    /* at least one socket ready*/
    for (i = 0; i <= fdmax; i++){
      if (FD_ISSET(i, &write_set)) {
        int listIndex = findClientIndexBySockFD(clientList,i);
        client_t *thisClient = (client_t *) CLIENT_GET(clientList,listIndex);
        /*client data ready to be written */
        int nbytes;
        /* iterate through item to be sent, until it will block */
        Arraylist outbuf = thisClient->outbuf;

        while (!arraylist_is_empty(outbuf))
        {
          /* write */
          char *dataToSend = (char *) (arraylist_get(outbuf,0)) + thisClient->outbuf_offset;
          size_t sizeToSend = strlen(dataToSend);
          nbytes = send(thisClient->sock, dataToSend, sizeToSend, 0);
          if (nbytes <0){
            /* error */
            if (errno == EPIPE || errno == ECONNRESET){
              /* connection lost or closed by the peer */

              DPRINTF(DEBUG_SOCKETS,"send: client %d hungup\n",i);
              remove_client(clientList,listIndex);
              continue;
            }
          }
          else if (nbytes == sizeToSend){
            /* current line completely sent */
            char *toRemove = (char *) (arraylist_get(outbuf,0));
            arraylist_removeIndex(outbuf,0);
            free(toRemove);
          }
          else{
            /* partial send */
            thisClient->outbuf_offset += nbytes;
            break;
          }
        }
        if (arraylist_is_empty(outbuf))
          FD_CLR(i, &write_set);
      }
      if (FD_ISSET(i, &read_set)) {
        if (i == listenfd){
          /* incoming connection */
          int newindex = handle_incoming_conn(clientList,servername,listenfd);
          if (newindex < 0){
            continue;
          }
          client_t *newClient = CLIENT_GET(clientList,newindex);
          int newfd = newClient->sock;
          FD_SET(newfd,&master_set);
          if (newfd > fdmax){
            fdmax = newfd;
          }
        }
        else{
          /* client data ready */
          char *tempPtr;
          int listIndex = findClientIndexBySockFD(clientList,i);

          /* for split function */
          char** tokenArr;
          int numToken;
          int lastTokenTerminated;

          if (listIndex < 0){
            close(i);
            FD_CLR(i,&master_set);
            continue;
          }

          int nbytes = recv(i, CLIENT_GET(clientList,listIndex)->inbuf + CLIENT_GET(clientList,listIndex)->inbuf_size,
          MAX_MSG_LEN - CLIENT_GET(clientList,listIndex)->inbuf_size, 0);

          /* recv failed. Either client left or error */
          if (nbytes <= 0){
            if (nbytes == 0){
              DPRINTF(DEBUG_SOCKETS,"recv: client %d hungup\n",i);
              remove_client(clientList, listIndex);

            }
            else if (errno == ECONNRESET || errno == EPIPE){
              DPRINTF(DEBUG_SOCKETS,"recv: client %d connection reset \n",i);
              remove_client(clientList, listIndex);

            }
            else{
              perror("recv");
            }
            continue;
          }

          /* NULL terminate to use strpbrk */
          CLIENT_GET(clientList,listIndex)->inbuf_size += nbytes;
          CLIENT_GET(clientList,listIndex)->inbuf[CLIENT_GET(clientList,listIndex)->inbuf_size] = '\0';
          tempPtr = strpbrk(CLIENT_GET(clientList,listIndex)->inbuf,"\r\n");
          if (!tempPtr){
            if (CLIENT_GET(clientList,listIndex)->inbuf_size == MAX_MSG_LEN){
              /* Message too long. Dump the content */
              DPRINTF(DEBUG_INPUT,"recv: message longer than MAX_MESSAGE detected. The message will be discarded\n");
              CLIENT_GET(clientList,listIndex)->inbuf_size = 0;
            }
            continue;
          }

          tokenArr = splitByDelimStr(CLIENT_GET(clientList,listIndex)->inbuf,"\r\n",&numToken,&lastTokenTerminated);
          /* since we have checked if there's delimeter beforehand, there should be at least one terminated token available*/
          if (!tokenArr){
            DPRINTF(DEBUG_INPUT,"splitByDelimStr: failed to split inputToken\n");
            CLIENT_GET(clientList,listIndex)->inbuf_size = 0;
            continue;
          }
          if (!lastTokenTerminated){
            CLIENT_GET(clientList,listIndex)->inbuf_size = strlen(tokenArr[numToken-1]);
            memcpy(CLIENT_GET(clientList,listIndex)->inbuf,tokenArr[numToken-1],CLIENT_GET(clientList,listIndex)->inbuf_size);
            numToken--;
          }

          for (j=0;j<numToken;j++){
            handle_line(clientList,listIndex,channelList,servername,tokenArr[j]);
          }

          for (j = 0; j < arraylist_size(clientList); j++){
            client_t *client = CLIENT_GET(clientList,j);
            if (arraylist_size(client->outbuf)){
                FD_SET(client->sock,&write_set);
            }
          }
          freeTokens(&tokenArr,numToken);
        }
      }
    }
  }

  return 0;
}