示例#1
0
文件: battle.c 项目: phoboz/yz
static int move_battle_walk(
    BATTLE_ACTOR *ba
)
{
    STEP_POINT *p, *q;

    p = (STEP_POINT *) LIST_HEAD(&ba->walkList);
    if (p == NULL) {

        return 1;

    }

    q = (STEP_POINT *) LIST_NEXT(&p->listNode);
    if (q == NULL) {

        ba->i = p->i;
        ba->j = p->j;

#ifdef DEBUG
        printf("Last element [%d, %d]",
               p->i, p->j);
#endif

        listRemove(&ba->walkList, &p->listNode);
        free(p);

#ifdef DEBUG
        printf(", %d element(s) left\n",
               listCount(&ba->walkList));
#endif

        return 1;

    }

    if (move_player_to(ba->player,
                       q->i * BMARKER_WIDTH,
                       q->j * BMARKER_HEIGHT)) {

#ifdef DEBUG
        printf("[%d, %d] -> [%d, %d]",
               p->i, p->j,
               q->i, q->j);
#endif

        listRemove(&ba->walkList, &p->listNode);
        free(p);

#ifdef DEBUG
        printf(", %d element(s) left\n",
               listCount(&ba->walkList));
#endif

    }

    return 0;
}
示例#2
0
/*5*/void calcPrintData(hashTable arrayHash[]) 
{	
	char*tempWord;
	double avgLinkedList;
	int linkedCount,from,i;
	int totalPrime = 0;
	int linkedListCount = 0;
	int longestLinkIndex = 0;
	int linkedListLengthTotal = 0;
	int longestLengthLinkedList = 0;
	
	for(i=0;i<MAX;i++){
		if(arrayHash[i].elemStatus == 1){ //array is full
			if(arrayHash[i].collision != NULL){
				linkedCount = listCount(arrayHash[i].collision);
				linkedListLengthTotal += linkedCount;
				totalPrime++;
				linkedListCount++;
			}
			else if(arrayHash[i].collision == NULL){
				totalPrime++;
			}
		}
	}
	avgLinkedList = (double)linkedListLengthTotal/linkedListCount; 
	for(i=0;i<MAX;i++){ //finding longest length linked list
		if(arrayHash[i].collision != NULL){
			linkedCount = listCount(arrayHash[i].collision);
			if(linkedCount >= longestLengthLinkedList)
				longestLengthLinkedList = linkedCount;
		}
	}
	for(i=0;i<MAX;i++){ // print index with the linked list length at the index
		if(arrayHash[i].collision != NULL){
			linkedCount = listCount(arrayHash[i].collision);
			printf("index %d list length %d\n",i,linkedCount);
		}
	}
	printf("\nTotal entries: %d\n",(totalPrime + linkedListLengthTotal));
	printf("Entries in primary area: %d\n", totalPrime);
	printf("Number of linked lists: %d\n",linkedListCount);
	printf("Average list length %4.2f\n",avgLinkedList);
	printf("Longest list length: %d\nat index:",longestLengthLinkedList);
	for(i=0;i<MAX;i++){
		if(arrayHash[i].collision != NULL){
			linkedCount = listCount(arrayHash[i].collision);
			if(longestLengthLinkedList == linkedCount){
				printf("\n%d:",i);
				from = 0;
				while((traverse(arrayHash[i].collision,from,(void**)&tempWord)) != 0){ 
					printf(" %s",tempWord);
					from++;
				}
			}
		}
	}
	userInteraction(arrayHash);
}//end calcPrintData
// -----------------------------------------------------------------------------
// CPIMLocalizationData::ConstructFromResourceL
// -----------------------------------------------------------------------------
//
void CPIMLocalizationData::ConstructFromResourceL(
    RResourceFile& aResourceFile,
    TResourceReader& aReader)
{
    TInt listCount(aReader.ReadInt16());

    __ASSERT_DEBUG(listCount > iSubType,
                   User::Panic(KPIMPanicCategory, EPIMPanicGeneral));

    // Find the correct resource structure for the requested sub-type. If
    // the list type is incorrect the reader skips the incorrect resource
    // structure and tries the next one until no lists can be processed.
    for (TInt i(1); i <= listCount; i++)
    {
        TInt listType(aReader.ReadInt8());
        if (listType == iSubType)
        {
            ReadListInfoFromResourceL(aResourceFile, aReader);
            break;
        }
        else if (i < listCount)
        {
            // Advance in resource file since this wasn't the list which
            // was requested. Currently there are three LLINK:s to skip
            aReader.Advance(sizeof(TInt32) * KPIMNumListResourceLinks);
        }
    }
}
示例#4
0
/** \brief Free a list and all memory associated with it
 *
 * \param[in,out] head Pointer to a list
 * \param[in] freeFunc function pointer for freeing the memory of each list item
 *
 * The function removes all items from a list, freeing all associated memory.
 * If freeFunc is NULL, it tries to directly free the data of each node.
 * For complex nodes (e.g. structs) the user needs to provide a node-specific free() function.
 */
void freeList( NODE **head, listFuncPtr freeFunc ) {
	NODE* node = NULL;

	dbg_printf(P_DBG, "[cleanupList] size before: %d", listCount(*head));
	while (*head != NULL) {
		node = *head;
		*head = (*head)->next;
		if(freeFunc != NULL) {
			freeFunc(node->data);
		} else {
			am_free(node->data);
		}
		am_free(node);
	}
	dbg_printf(P_DBG, "[cleanupList] size after: %d", listCount(*head));
}
示例#5
0
文件: main.c 项目: JvetS/Curves
// GLUT callback for rendering.
// Draws all the control points in l, their connecting lines and the curve as specified by the user.
// Ends by printing a description of the current curve to the screen.
void display()
{
	struct list * tmp = l;
	float x, y;
	float t;

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(127, 127, 127);
	glBegin(GL_LINE_STRIP);

	tmp = l;
	while (tmp)
    {
        glVertex2f(tmp->x, tmp->y);
        tmp = tmp->next;
    }

	glEnd();

    glColor3ub(255, 0, 0);

    glBegin(GL_POINTS);
	tmp = l;
    while (tmp)
    {
        glVertex2f(tmp->x, tmp->y);
        tmp = tmp->next;
    }
    glEnd();

    glColor3ub(0, 0, 0);
    glBegin(GL_LINE_STRIP);
	tmp = l;
    if (bezier)
    {
        while (tmp && listCount(tmp) > order)
        {
            for (t = 0.0f; t <= 1.0f; t+=0.01f)
            {
                computeNOrderBezierlf(order, tmp, t, &x, &y);
                glVertex2f(x, y);
            }
            tmp = listGet(tmp, order);
        }
    }
    else
    {
        for (t = knot[order]; t <= knot[count]; t+=0.01f)
        {
            computeNOrderBsplinelf(order + 1, l, t, knot, &x, &y);
            glVertex2f(x, y);
        }
    }
    glEnd();
    
    printHelpglut();
    
    glutSwapBuffers();
}
示例#6
0
/** \brief add new item to bucket list
 *
 * \param[in] guid Unique identifier for a bucket item (e.g. a URL)
 * \param[in,out] head pointer to the bucket list
 * \param[in] maxBucketItems number of maximum items in bucket list
 * \return always returns 0
 *
 * The size of the provided bucket list is kept to maxBucketItems.
 * If it gets larger than the specified value, the oldest element is removed from the list.
 */
int addToBucket(const char* guid, NODE **head, const int maxBucketItems) {
	addToHead(am_strdup(guid), head);
	if(maxBucketItems > 0 && listCount(*head) > (uint32_t)maxBucketItems) {
		dbg_printf(P_INFO2, "[add_to_bucket] bucket gets too large, deleting last item...\n");
		removeLast(*head, NULL);
	}

	return 0;
}
示例#7
0
PRIVATE bool setupSession(auto_handle * session) {
   bool sessionOk = true;

   if(session != NULL) {
      if(listCount(session->feeds) == 0) {
         dbg_printf(P_ERROR, "No feeds specified in automatic.conf!");
         sessionOk = false;
      }

      if(listCount(session->filters) == 0) {
         dbg_printf(P_ERROR, "No filters specified in automatic.conf!");
         sessionOk = false;
      }

      if(sessionOk) {
         // There's been a previous session.
         // Copy over some of its values, and properly free its memory.
         if(mySession != NULL) {
            session->match_only = mySession->match_only;
            if(mySession->bucket_changed) {
               save_state(mySession->statefile, mySession->downloads);
            }

            session_free(mySession);
         }

         mySession = session;

         /* check if Prowl API key is given, and if it is valid */
         if(mySession->prowl_key && verifyProwlAPIKey(mySession->prowl_key) == 1 ) {
            mySession->prowl_key_valid = 1;
         }

         load_state(mySession->statefile, &mySession->downloads);
         printSessionSettings();
      }
   } else {
      sessionOk = false;
   }

   return sessionOk;
}
示例#8
0
PRIVATE void printSessionSettings() {
  dbg_printf(P_INFO, "Transmission version: 1.%d", mySession->transmission_version);
  dbg_printf(P_INFO, "RPC host: %s", mySession->host != NULL ? mySession->host : AM_DEFAULT_HOST);
  dbg_printf(P_INFO, "RPC port: %d", mySession->rpc_port);
  dbg_printf(P_INFO, "RPC auth: %s", mySession->auth != NULL ? mySession->auth : "none");
  dbg_printf(P_INFO, "config file: %s", AutoConfigFile);
  dbg_printf(P_INFO, "Transmission home: %s", mySession->transmission_path);
  dbg_printf(P_INFO, "check interval: %d min", mySession->check_interval);
  dbg_printf(P_INFO, "Upload limit: %d KB/s", mySession->upspeed);
  dbg_printf(P_INFO, "torrent folder: %s", mySession->torrent_folder);
  dbg_printf(P_INFO, "start torrents: %s", mySession->start_torrent == 1 ? "yes" : "no");
  dbg_printf(P_INFO, "state file: %s", mySession->statefile);

  /* determine RPC version */
  if(mySession->use_transmission && mySession->transmission_version == AM_TRANSMISSION_1_3) {
      mySession->rpc_version = getRPCVersion((mySession->host != NULL) ? mySession->host : AM_DEFAULT_HOST,
                                            mySession->rpc_port, mySession->auth);
      if(mySession->rpc_version != 0) {
         dbg_printf(P_INFO, "Transmission RPC Version: %d", mySession->rpc_version);
      }
  }

  if(mySession->prowl_key) {
    dbg_printf(P_INFO, "Prowl API key: %s", mySession->prowl_key);
  }

  if(mySession->toasty_key) {
    dbg_printf(P_INFO, "Toasty DeviceID: %s", mySession->toasty_key);
  }

  if(mySession->pushalot_key) {
    dbg_printf(P_INFO, "Pushalot Token: %s", mySession->pushalot_key);
  }

  if(mySession->pushover_key) {
    dbg_printf(P_INFO, "Pushover Token+User: %s", mySession->pushover_key);
  }

  dbg_printf(P_MSG,  "%d feed URLs", listCount(mySession->feeds));
  dbg_printf(P_MSG,  "Read %d filters from config file", listCount(mySession->filters));
}
示例#9
0
文件: Player.c 项目: tu500/minGame
//Buys an Item, returns true if successful
bool itemBuy(Player *p, Item *i){
    //Check if Item is already owned
    if(listCount(&p->inventory, i) >= 1 ) return false;
    int newmoney = p->money - i->prize;
    int newspace = getFreeInvSpace(p) - i->inventorySizeTaken;
    if( newmoney >= 0 && newspace >= 0){
        p->money = newmoney;
        listInsert(&p->inventory, i);
        updateItems(p);
        return true;
    }
    return false;
}
示例#10
0
int32_t protocalDispatchEvents(ProtocalStatusType *pProtocal)
{
    uint32_t count;
    int32_t ret;
    EventStackType *pEvent;
    uint8_t cmdType;

    (void)listCount(&pProtocal->eventStack, &count);
    if (count == 0)
    {
        return ERROR_NO_RESOURCE;
    }

    /* pop event from stack */
    ret = listGetAt(&pProtocal->eventStack, 0, (uint32_t *)&pEvent);
    if (ret)
        return ret;

    listRemoveData(&pProtocal->eventStack, (uint32_t)pEvent);

    /* Get command type and reset cmdType to release memory */
    cmdType = pEvent->cmdType & 0x7f;
    switch(cmdType)
    {
        case CMD_TYPE_ACK:
            if (pProtocal->pfnAck)
            {
                pProtocal->pfnAck(pEvent->cmd, pEvent->buff[0]);
            }
            break;

        case CMD_TYPE_SET:
        case CMD_TYPE_QUERY:
            if (pProtocal->pfnOnCmd)
            {
                ret = pProtocal->pfnOnCmd(cmdType, pEvent->cmd,
                    pEvent->buff, pEvent->buffSize);
            }
            break;

        default:
            break;
    }

    /* release the memory */
    pEvent->cmdType = 0;

    return ret;
}
示例#11
0
/* #############################################################################
 *
 * Description    create a string from a searchpattern and path information
 * Author         Harry Brueckner
 * Date           2005-04-12
 * Arguments      SEARCHPATTERN pattern   - pattern to create
 *                char** path             - path information to full into the
 *                                          pattern
 *                char* string            - result string which must be freed
 *                                          by the caller
 * Return         1 on error, 0 if ok
 */
int getPatternString(SEARCHPATTERN* pattern, char** path, char** string)
  {
    SEARCHPATTERN*      cpattern = pattern;
    int                 maxlevel = listCount(path);
    char*               concat;

    TRACE(99, "getPatternString()", NULL);

    *string = NULL;
    while (cpattern)
      {
        switch (cpattern -> type)
          {
            case PATTERN_TEMPLATE:
                if (cpattern -> templateid > maxlevel)
                  { return 1; }
                concat = path[cpattern -> templateid - 1];
                break;
            case PATTERN_STRING:
                concat = cpattern -> string;
                break;
            default:
                concat = NULL;
          }

        if (concat)
          {   /* we have a string to concat to the result */
            if (!*string)
              {   /* new string */
                *string = memAlloc(__FILE__, __LINE__, strlen(concat) + 1);
                *string[0] = 0;
              }
            else
              {   /* resize the string */
                *string = memRealloc(__FILE__, __LINE__,
                    *string,
                    strlen(*string) + 1,
                    strlen(*string) + strlen(concat) + 1);
              }

            strStrncat(*string, concat, strlen(concat) + 1);
          }

        cpattern = cpattern -> next;
      }

    return 0;
  }
示例#12
0
文件: battle.c 项目: phoboz/yz
static void free_battle_target(
    BATTLE_ACTOR *ba
)
{
    STEP_POINT *p;

    while ((p = (STEP_POINT *) LIST_HEAD(&ba->targetList)) != NULL) {
        listRemove(&ba->targetList, &p->listNode);
        free(p);
    }

#ifdef DEBUG
    printf("Free battle target, %d element(s) left\n",
           listCount(&ba->targetList));
#endif
}
示例#13
0
PRIVATE int parseFeed(rss_feeds *feeds, const char* feedstr) {
  char *line = NULL, *option = NULL, *param = NULL;
  char *saveptr;
  char *str = NULL;
  rss_feed* feed = NULL;
  int result = SUCCESS; /* be optimistic */

  str = shorten(feedstr);

  line = strtok_r(str, AM_DELIMITER, &saveptr);
  while (line) {
    if(!feed) {
      feed = feed_new();
      assert(feed && "feed_new() failed!");
    }
    if(parseSubOption(line, &option, &param) == 0) {
      if(!strncmp(option, "url", 3)) {
        feed->url = shorten(param);
      } else if(!strncmp(option, "cookies", 6)) {
        feed->cookies = shorten(param);
      } else {
        dbg_printf(P_ERROR, "Unknown suboption '%s'!", option);
      }
      am_free(option);
      am_free(param);
    } else {
      dbg_printf(P_ERROR, "Invalid suboption string: '%s'!", line);
    }
    line = strtok_r(NULL, AM_DELIMITER, &saveptr);
  }


  if(feed && feed->url) {
    /* Maybe the cookies are encoded within the URL */
    if(feed->cookies == NULL) {
      parseCookiesFromURL(feed);
    }
    feed->id = listCount(*feeds);
    feed_add(feed, feeds);
  } else {
    dbg_printf(P_ERROR, "Invalid feed: '%s'", str);
    result = FAILURE;
  }

  am_free(str);
  return result;
}
示例#14
0
文件: test.c 项目: Madsen90/BOSC
int listTest(int threads, int actions, List *list, int expected, void* (*f)(void*)){
	threadStarter(threads, actions, list, f);

	int count = listCount(list);

	if(list->len != expected){
		printf("List has length-property: %d. Expected: %d", list->len, expected);
		return -1;
	}
	
	if(count != expected){
		printf("List has elements: %d. Expected: %d", count, expected);
		return -1;
	}
	
	return 1;
}
示例#15
0
listnode* partition(listnode* A, int B) {
    int d = listCount(A);
    if(d==1){
        return A;
    }
    int i=0;
    listnode *end = A, *temp= A;
    while(end->next != NULL){
        end = end->next;
    }
    listnode *prev = A;
    while(i<d && A!=NULL){
        if(temp->val >= B){
            /*if(temp==end){
                break;
            }*/
           
            if(prev == temp && temp->val >= B){
               
                    listnode *create = listnode_new(temp->val);
                    end->next = create;
                    end = create;
                    prev = temp->next;
                    free(temp);
                    A = temp = prev;    
               
                
            }else{
                listnode *create = listnode_new(temp->val);
                end->next = create;
                end = create;
                prev->next = temp->next;
                free(temp);
                temp = prev->next;
            }
        }else{
            if(temp!=prev){
                prev = prev->next;
            }
            temp = temp->next;
        }
        i++;
    }
    return A;
}
示例#16
0
PRIVATE int getFeeds(NODE **head, const char* strlist) {
  char *p = NULL;
  char *str;
  str = shorten(strlist);
  assert(head != NULL);
  p = strtok(str, AM_DELIMITER);
  while (p) {
    rss_feed* feed = feed_new();
    assert(feed && "feed_new() failed!");
    feed->url = strdup(p);
    feed->id  = listCount(*head);
    /* Maybe the cookies are encoded within the URL */
    parseCookiesFromURL(feed);
    feed_add(feed, head);
    p = strtok(NULL, AM_DELIMITER);
  }
  am_free(str);
  return 0;
}
示例#17
0
/* #############################################################################
 *
 * Description    parse the defined patterns for later use
 * Author         Harry Brueckner
 * Date           2005-04-06
 * Arguments      void
 * Return         0 if everything is ok, otherwise 1
 */
int patternParse(void)
  {
    int                 error = 0,
                        i;

    TRACE(99, "patternParse()", NULL);

    patterncount = listCount(runtime -> searchpatterns);
    patterndata = memAlloc(__FILE__, __LINE__,
        sizeof(SEARCHPATTERN*) * patterncount);
    resultdata = memAlloc(__FILE__, __LINE__,
        sizeof(SEARCHPATTERN*) * patterncount);

    for (i = 0; i < patterncount; i++)
      {
        patterndata[i] = memAlloc(__FILE__, __LINE__,
            sizeof(SEARCHPATTERN));
        patterndata[i] -> type = PATTERN_UNDEF;
        patterndata[i] -> templateid = -1;
        patterndata[i] -> string = NULL;
        patterndata[i] -> next = NULL;

        if (patternCreate(runtime -> searchpatterns[i], patterndata[i]))
          { error = 1; }

        resultdata[i] = memAlloc(__FILE__, __LINE__,
            sizeof(SEARCHPATTERN));
        resultdata[i] -> type = PATTERN_UNDEF;
        resultdata[i] -> templateid = -1;
        resultdata[i] -> string = NULL;
        resultdata[i] -> next = NULL;

        if (patternCreate(runtime -> resultpatterns[i], resultdata[i]))
          { error = 1; }
      }

    return error;
  }
示例#18
0
void conditional_parrern_base(struct node *fptree, struct header_table *htable, int *item_counter,int *item_index, char *generate_string) {	
	struct frequent_patterns *fp = malloc(sizeof(struct frequent_patterns));
	struct frequent_patterns *fp_head = malloc(sizeof(struct frequent_patterns));
	
	struct node *now_node = malloc(sizeof(struct node));
	int ptr_index; 
	fp_head = fp;	
	if(generate_string != "") //printf("%s \n", generate_string);
	while(htable != NULL) {			
		fp = fp_head;
		fp->next = NULL;
		fp->index = 0;
		listStart(htable->cond);		
		while(listNext(htable->cond)) {			
			now_node = listGet(htable->cond);			
			if(fp->index == 0) {
				fp->ptr  = malloc(sizeof(short) * MIN_SUPPORT_INDEX);
			}
			else {
				struct frequent_patterns *new_fp = malloc(sizeof(struct frequent_patterns));
				new_fp->ptr  = malloc(sizeof(short) * MIN_SUPPORT_INDEX);
				fp->next 	 = new_fp;
				fp 			 = new_fp;
			}
			
			fp->counter = now_node->counter;				
			fp->htable_value = htable->no;
			ptr_index   = 0;
			now_node = now_node->parent;
			while(now_node != NULL) {			
				if( now_node->no == -1) break;
				*(fp->ptr + ptr_index) = now_node->no;
				ptr_index++;
				now_node = now_node->parent;
			}						
			fp->index = ptr_index;
		}
		
		struct header_table *sub_htable = malloc(sizeof(struct header_table));		
		struct node         *sub_tree   = malloc(sizeof(struct node));			
		
		sub_tree = create_fptree();						
		sub_tree = build_sub_tree(sub_tree, sub_htable, fp_head, item_counter, item_index);
		
		//dfs(sub_tree);		
		if(sub_tree->child != NULL) {			
			int len = strlen(generate_string) + 4;	
			char *str_ans = malloc(sizeof(char) * len);	
			myString_cat(str_ans, generate_string, htable->no);			
			
			while(sub_htable->next != NULL) sub_htable = sub_htable->next;					
			
			conditional_parrern_base(sub_tree, sub_htable, item_counter, item_index,  str_ans);
			
			dfs(sub_tree);			
			
		}else if(htable->prev == NULL || listCount(htable->cond) > 0){			
			int len = strlen(generate_string) + 4;	
			char *str_ans = malloc(sizeof(char) * len);	
			myString_cat(str_ans, generate_string, htable->no);			
			//printf("%s\n", str_ans);
		}		
		
		htable = htable->prev;
	}		
	while(htable != NULL) {
		header_head = htable;
		htable 	    = htable->next;
		free(header_head);			
	}
	
}
示例#19
0
文件: Menu.c 项目: tu500/minGame
void Menu_Draw(Bitmap* b){

	//Create Background
	DrawFilledRectangle(b, borderX, borderY, SCREEN_X - 2 * borderX, SCREEN_Y - 2 * borderY, RGB(0,0,0));
	//Inner red Border
	DrawRectangle(b, borderX + rectBorder, borderY + rectBorder ,
	 (SCREEN_X - 2 * borderX) - 2 * rectBorder , (SCREEN_Y - 2 * borderY ) - 2 * rectBorder, RGB(193,0,0));

	//Column Header
	char *itemHeader;
	asprintf(&itemHeader, "Itemname    SPD  SPW   INV    PRZ");
	DrawText(b, itemHeader, listEdgeX + 0 * colWidth, listEdgeY - rowHeight -2);
	free(itemHeader);

	//Items
	for(int i = 0 ; i < maxListRows ; i++){
		itemIndex = i + menuSelectedItem - 4;
		if (itemIndex >= 0 && itemIndex <= itemCount){
			//Mark Items you can't afford
			if(itemList[itemIndex]->prize > p1.money){
				DrawFilledCircle(b, listEdgeX +circleRadius , listEdgeY + rowHeight * i + circleRadius + 1, circleRadius ,RGB(255,0,0));
			}	
			//Item Owned
			if(listCount(&p1.inventory, (Item*)itemList[itemIndex]) >= 1){
				DrawFilledCircle(b, listEdgeX +circleRadius , listEdgeY + rowHeight * i + circleRadius + 1, circleRadius ,RGB(0,255,0));
			}
			//Item name
			char *itemName;
			asprintf(&itemName, itemList[itemIndex]->name);
			DrawText(b, itemName, listEdgeX + 0 * colWidth, listEdgeY + rowHeight * i);
			free(itemName);

			//Item Dig-Speed
			char *itemSPD;
			asprintf(&itemSPD, "% 3d", itemList[itemIndex]->speedDigMod);
			DrawText(b, itemSPD, listEdgeX + 6 * colWidth, listEdgeY + rowHeight * i);
			free(itemSPD);

			//Item Walk-Speed
			char *itemSPW;
			asprintf(&itemSPW, "% 2d", itemList[itemIndex]->speedWalkMod);
			DrawText(b, itemSPW, listEdgeX + 9 * colWidth, listEdgeY + rowHeight * i);
			free(itemSPW);	

			//Item Inventory size
			char *itemINV;
			asprintf(&itemINV, "% 4d", itemList[itemIndex]->inventorySizeTaken);
			DrawText(b, itemINV, listEdgeX + 11 * colWidth, listEdgeY + rowHeight * i);
			free(itemINV);		

			//Item Prize
			char *itemPRZ;
			asprintf(&itemPRZ, "% 5d", itemList[itemIndex]->prize);
			DrawText(b, itemPRZ, listEdgeX + 14 * colWidth, listEdgeY + rowHeight * i);
			free(itemPRZ);
			setFont(fontwhite8);
		}else{
			// dunno
		}
	}
	//Draw Border around current selection
	DrawRectangle(b, listEdgeX , listEdgeY + 4 * rowHeight -2, SCREEN_X - (2 * borderX + 2 * 2 * rectBorder + 2), rowHeight + 2 * 1, RGB(128, 0, 0));

	//Separate ItemList from Character Infos
	DrawHorizontalLine(b, listEdgeX , listEdgeY + 10 * rowHeight + 2 , SCREEN_X - (2 * 2 * rectBorder + 2 * borderX + 2), RGB(255,255,255));

	//Draw Player Info (Cash / Free Space)
	setFont(fontwhite16);
	char *playerCash;
	asprintf(&playerCash, "$:%3d Inv:%3d", p1.money, getFreeInvSpace(&p1));
	DrawText(b, playerCash, listEdgeX , listEdgeY + rowHeight * 11);
	free(playerCash);
	setFont(fontwhite8);	


	//Draw Players Minerals
	//Coal
	DrawRLEBitmap(b,sprt_coal,listEdgeX + 1 * colWidth,listEdgeY + rowHeight * 13);
	//Iron
	DrawRLEBitmap(b,sprt_treasure1,listEdgeX + 5 * colWidth,listEdgeY + rowHeight * 13);
	//Gold
	DrawRLEBitmap(b,sprt_gold,listEdgeX + 9 * colWidth,listEdgeY + rowHeight * 13);
	//Diamonds
	DrawRLEBitmap(b,sprt_diam_red,listEdgeX + 13 * colWidth,listEdgeY + rowHeight * 13);

	char *playerMinerals;
	asprintf(&playerMinerals, "     % 3d     % 3d     % 3d     % 3d",
		getMineralAmount(&p1, MIN_COAL),
		getMineralAmount(&p1, MIN_IRON),
		getMineralAmount(&p1, MIN_GOLD),
		getMineralAmount(&p1, MIN_DIAMOND));
	DrawText(b, playerMinerals, listEdgeX - colWidth / 2, listEdgeY + rowHeight * 13.5);
	free(playerMinerals);	


}
示例#20
0
文件: LISTTREE.C 项目: mp-lee/fellow
ULO treeChildCount(tree *t) {
  return listCount(t->child->lnode);
}
示例#21
0
int main(int argc, char **argv) {
  auto_handle *session = NULL;
  char *config_file = NULL;
  char *logfile = NULL;
  char *xmlfile = NULL;
  char erbuf[100];
  NODE *current = NULL;
  uint32_t count = 0;
  uint8_t first_run = 1;
  uint8_t once = 0;
  uint8_t verbose = AM_DEFAULT_VERBOSE;
  uint8_t append_log = 0;
  uint8_t match_only = 0;

  /* this sets the log level to the default before anything else is done.
  ** This way, if any outputting happens in readargs(), it'll be printed
  ** to stderr.
  */
  log_init(NULL, verbose, 0);

  readargs(argc, argv, &config_file, &logfile, &xmlfile, &nofork, &verbose, &once, &append_log, &match_only);

  /* reinitialize the logging with the values from the command line */
  log_init(logfile, verbose, append_log);

  if(!config_file) {
    config_file = am_strdup(AM_DEFAULT_CONFIGFILE);
  }
  strncpy(AutoConfigFile, config_file, strlen(config_file));

  session = session_init();
  session->match_only = match_only;

  if(parse_config_file(session, AutoConfigFile) != 0) {
    if(errno == ENOENT) {
      snprintf(erbuf, sizeof(erbuf), "Cannot find file '%s'", config_file);
    } else {
      snprintf(erbuf, sizeof(erbuf), "Unknown error");
    }
    fprintf(stderr, "Error parsing config file: %s\n", erbuf);
    shutdown_daemon(session);
  }

  setup_signals();

  if(!nofork) {

    /* start daemon */
    if(daemonize() != 0) {
      dbg_printf(P_ERROR, "Error: Daemonize failed. Aborting...");
      shutdown_daemon(session);
    }

    dbg_printft( P_MSG, "Daemon started");
  }

  filter_printList(session->filters);

  dbg_printf(P_MSG, "Trailermatic version: %s", LONG_VERSION_STRING);
  dbg_printf(P_INFO, "verbose level: %d", verbose);
  dbg_printf(P_INFO, "foreground mode: %s", nofork == 1 ? "yes" : "no");
  dbg_printf(P_INFO, "config file: %s", AutoConfigFile);
  dbg_printf(P_INFO, "check interval: %d min", session->check_interval);
  dbg_printf(P_INFO, "download folder: %s", session->download_folder);
  dbg_printf(P_INFO, "state file: %s", session->statefile);
  dbg_printf(P_MSG,  "%d feed URLs", listCount(session->feeds));
  dbg_printf(P_MSG,  "Read %d filters from config file", listCount(session->filters));

  if(session->prowl_key) {
    dbg_printf(P_INFO, "Prowl API key: %s", session->prowl_key);
  }

  if(listCount(session->feeds) == 0) {
    dbg_printf(P_ERROR, "No feed URL specified in trailermatic.conf!\n");
    shutdown_daemon(session);
  }

  if(listCount(session->filters) == 0) {
    dbg_printf(P_ERROR, "No filters specified in trailermatic.conf!\n");
    shutdown_daemon(session);
  }

  /* check if Prowl API key is given, and if it is valid */
  if(session->prowl_key && verifyProwlAPIKey(session->prowl_key) ) {
    session->prowl_key_valid = 1;
  }

  load_state(session->statefile, &session->downloads);
  while(!closing) {
    dbg_printft( P_INFO, "------ Checking for new trailers ------");
     if(xmlfile && *xmlfile) {
       processFile(session, xmlfile);
       once = 1;
    } else {
      current = session->feeds;
      count = 0;
      while(current && current->data) {
        ++count;
        dbg_printf(P_INFO2, "Checking feed %d ...", count);
        processFeed(session, current->data, first_run);
        current = current->next;
      }
      if(first_run) {
        dbg_printf(P_INFO2, "New bucket size: %d", session->max_bucket_items);
      }
      first_run = 0;
    }
    /* leave loop when program is only supposed to run once */
    if(once) {
      break;
    }
    sleep(session->check_interval * 60);
  }
  shutdown_daemon(session);
  return 0;
}