コード例 #1
0
ファイル: wsort.c プロジェクト: anygo/uniprojectsdn
void readInput()
{
	struct stat info;
	unsigned char *input;
	unsigned char cur;
	unsigned char next;
	int ccount = 0;

	fstat(STDIN_FILENO, &info);
	filesize = info.st_size;

	if (filesize < 1) 
		exit(EXIT_SUCCESS);

	input = (unsigned char*)malloc(sizeof(unsigned char)*filesize);
	output = (unsigned char*)malloc(sizeof(unsigned char)*filesize);
	input = mmap(0, filesize, PROT_WRITE, MAP_PRIVATE, STDIN_FILENO, 0);
	
	
	while (ccount < filesize, input[ccount] <= 32)
	{
		/* ignoriere leere Strings und
		 * sonstigen Bloedsinn am Anfang
		 */
		ccount++;
	}

	addToBucket(&input[ccount++]);

	while (ccount <= filesize)
	//while (ccount < filesize)
	{
	cur = input[ccount];
		if (cur == '\n')
		{
			input[ccount] = '\0';  /*ENTFERNE MICHHHH*/
			if ((next = input[++ccount]) >= 32)
			{
				addToBucket(&input[ccount]);
			}
			else
			{
			//	input[ccount] = '\0';
				/* nix tun, falls leere Zeile gelesen */
			}
		}
		else
		{
			ccount++;
		}
	}
}
コード例 #2
0
ファイル: trailermatic.c プロジェクト: 1100101/trailermatic
PRIVATE void processRSSList(auto_handle *session, const simple_list items, uint16_t feedID) {
   simple_list current_item = items;
   simple_list current_url = NULL;
   am_filter filter = NULL;
   const char * url;
   char path[4096];
   HTTPResponse *response = NULL;

   while(current_item && current_item->data) {
      feed_item item = (feed_item)current_item->data;
      current_url = item->urls;
      while(current_url && current_url->data)
      {
         url = (const char*)current_url->data;
         if(isMatch(session->filters, url, &filter)) {
            if(!session->match_only) {
               get_filename(path, NULL, url, session->download_folder);
               if (!has_been_downloaded(session->downloads, url) && !file_exists(path)) {
                  dbg_printft(P_MSG, "[%d] Found new download: %s (%s)", feedID, item->name, url);
                  response = downloadFile(url, path, filter->agent);
                  if(response) {
                     if(response->responseCode == 200) {
                        if(session->prowl_key_valid) {
                           prowl_sendNotification(PROWL_NEW_TRAILER, session->prowl_key, item->name);
                        }

                        if(session->download_done_script && *(session->download_done_script))
                        {
                          callDownloadDoneScript(session->download_done_script, path);
                        }

                        dbg_printf(P_MSG, "  Download complete (%dMB) (%.2fkB/s)", response->size / 1024 / 1024, response->downloadSpeed / 1024);
                        /* add url to bucket list */
                        if (addToBucket(url, &session->downloads, session->max_bucket_items) == 0) {
                           session->bucket_changed = 1;
                           save_state(session->statefile, session->downloads);
                        }
                     } else {
                        dbg_printf(P_ERROR, "  Error: Download failed (Error Code %d)", response->responseCode);
                        if(session->prowl_key_valid) {
                           prowl_sendNotification(PROWL_DOWNLOAD_FAILED, session->prowl_key, item->name);
                        }
                     }

                     HTTPResponse_free(response);
                  }
               } else {
                 dbg_printf(P_MSG, "File downloaded previously: %s", basename(path));
               }
            } else {
               dbg_printft(P_MSG, "[%s] Match: %s (%s)", feedID, item->name, url);
            }
         }
         current_url = current_url->next;
      }
      current_item = current_item->next;
   }
}
コード例 #3
0
ファイル: OpenMPUtil.c プロジェクト: weeitb/HPCWordCloud
/**
 * Adds the two hashmaps together at the given bucket index.
 * 'Add' means that entries with matching keys have their
 * values added together, and unique keys from src are
 * added to the destination map.
 * The result is stored in the dest hashmap.
 * @param dest first operand and result map to add
 * @param src second operand map to add
 * @param bucketIdx bucket index to add to maps at
 */
unsigned int mergeBuckets(HashMap* dest, HashMap* src, unsigned int bucketIdx) {
  MapNode* currentBucket = src->buckets[bucketIdx];
  unsigned int valuesAdded = 0;
  while(currentBucket != NULL) {
    valuesAdded += addToBucket(dest, currentBucket->k, currentBucket->v, bucketIdx);
    currentBucket = currentBucket->nextNode;
  }
  return valuesAdded;
}
コード例 #4
0
ファイル: mpiUtil.c プロジェクト: weeitb/HPCWordCloud
/**
 * unpacks a block of serialized data and adds it to input
 * hashmap
 * @param map map to add serialized key value pairs to
 * @param data serialized key value pairs to parse
 */
void addSerializedToMap(HashMap* map, unsigned char* data, int nBytes) {
  uint32_t nElements;
  //unsigned char* startPtr = data;
  nElements = *data++;
  nElements |= *data++ << 8;
  nElements |= *data++ << 16;
  nElements |= *data++ << 24;
  //printf("nElements is %d", nElements);
  //printf("number of elements %d\n", nElements);
  uint32_t elementIdx = 0;
  Key k;
  Value v;
  unsigned int hash;
  for (elementIdx = 0; elementIdx < nElements; elementIdx++) {
     data = unserializeBucket(&v, &k, data);
     hash = (*map->hasher)(k) % map->nBuckets;
     //A little inefficient, we could copy location information in message.
     map->nElements += addToBucket(map, k, v, hash);
  }
}
コード例 #5
0
ファイル: automatic.c プロジェクト: 1100101/Automatic
PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simple_list items, const rss_feed * feed) {
  simple_list current_item = items;
  HTTPResponse *torrent = NULL;
  char fname[MAXPATHLEN];
  char *download_folder = NULL;
  char *feedID = NULL;
  char *download_url = NULL;

  if(!curl_session && !session) {
    printf("curl_session == NULL && session == NULL\n");
    abort();
  }

  if(feed != NULL) {
    feedID = feed->id;
  }

  while(current_item && current_item->data) {
    feed_item item = (feed_item)current_item->data;

    if(isMatch(session->filters, item->name, feedID, &download_folder)) {
      if(!session->match_only) {
         if(has_been_downloaded(session->downloads, item)) {
            dbg_printf(P_INFO, "Duplicate torrent: %s", item->name);
         } else {
            int8_t result = -1;
            dbg_printft(P_MSG, "[%s] Found new download: %s (%s)", feedID, item->name, item->url);
            if(isMagnetURI(item->url)) {
               result = addMagnetToTM(session, item->url, download_folder);
            } else {
               // It's a torrent file
               // Rewrite torrent URL, if necessary
               if((feed != NULL) && (feed->url_pattern != NULL) && (feed->url_replace != NULL)) {
                  download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace);
               }

               torrent = downloadTorrent(curl_session, download_url != NULL ? download_url : item->url);
               if(torrent) {
                  get_filename(fname, torrent->content_filename, item->url, session->torrent_folder);

                  /* add torrent to Transmission */
                  result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder);
                  HTTPResponse_free(torrent);
               }

               am_free(download_url);
            }

            // process result
            if( result >= 0) {  //result == 0 -> duplicate torrent
               if(result > 0) { //torrent was added
                  if(session->prowl_key_valid) {
                     prowl_sendNotification(PROWL_NEW_DOWNLOAD, session->prowl_key, item->name);
                  }

                  if(session->toasty_key) {
                     toasty_sendNotification(PROWL_NEW_DOWNLOAD, session->toasty_key, item->name);
                  }

                  if(session->pushalot_key) {
                     pushalot_sendNotification(PUSHALOT_NEW_DOWNLOAD, session->pushalot_key, item->name);
                  }
                  
                  if(session->pushover_key) {
                     pushover_sendNotification(PUSHOVER_NEW_DOWNLOAD, session->pushover_key, item->name);
                  }
               }

               /* add url to bucket list */
               result = addToBucket(item->guid != NULL ? item->guid : item->url, &session->downloads, session->max_bucket_items);
               if (result == 0) {
                  session->bucket_changed = 1;
                  save_state(session->statefile, session->downloads);
               }
            } else {  //an error occurred
               if(session->prowl_key_valid) {
                  prowl_sendNotification(PROWL_DOWNLOAD_FAILED, session->prowl_key, item->name);
               }

               if(session->toasty_key) {
                  toasty_sendNotification(PROWL_DOWNLOAD_FAILED, session->toasty_key, item->name);
               }

               if(session->pushalot_key) {
                  pushalot_sendNotification(PUSHALOT_DOWNLOAD_FAILED, session->pushalot_key, item->name);
               }
               
               if(session->pushover_key) {
                  pushover_sendNotification(PUSHOVER_DOWNLOAD_FAILED, session->pushover_key, item->name);
               }
            }
         }
      } else {
         dbg_printft(P_MSG, "[%s] Match: %s (%s)", feedID, item->name, item->url);
      }
    }

    current_item = current_item->next;
  }
}