Exemplo n.º 1
0
int main(int argc, char **argv)
{
  Node *head = NULL;
  char **filenames = init_filenames();
  char arg;
  char *listfile = "index";
  char *namefile = "filenames";

  while ((arg = getopt(argc,argv,"i:n:")) > 0){
    switch(arg){
      case 'i':
        listfile = optarg;
        break;
      case 'n':
        namefile = optarg;
        break;
      default:
	fprintf(stderr, "Bad arguments for printindex\n");
	exit(1);
    }
  }


    read_list(listfile, namefile, &head, filenames);
    display_list(head, filenames);

  return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    Node *head = NULL;
    char **filenames = init_filenames();
    char ch;
    char *indexfile = "index";
    char *namefile = "filenames";

    while((ch = getopt(argc, argv, "i:n:")) != -1) {
        switch (ch) {
        case 'i':
            indexfile = optarg;
            break;
        case 'n':
            namefile = optarg;
            break;
        default:
            fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
            exit(1);
        }
    }
      
    while(optind < argc) {
		FILE *fname;
		if((fname = fopen(argv[optind], "r")) == NULL) {
			perror("Name file");
			exit(1);
		}

		char line[MAXLINE];
		char splitBy[] = " \t\n";
		char *token;
		char *cleaned_token;

		while ((fgets(line, MAXLINE, fname)) != NULL){
			token = strtok(line, splitBy);
			while (token != NULL) {
				cleaned_token = clean_word(token);
				//only add_word if not empty string
				if (strcmp(cleaned_token, "") != 0)	
				{
					head = add_word(head, filenames, cleaned_token, argv[optind]);
				}
				token = strtok(NULL, splitBy);}
		}

	optind++;
	}
	write_list(namefile, indexfile, head, filenames);
	display_list(head, filenames);
	return 0;
}
Exemplo n.º 3
0
int start_recording(recorder_context_t *rctx)
{
    int retval = 0;
    time_t current_time;

    Log(LOG_INFO, "Starting recorder.\n");


    if ((retval = init_filenames(rctx)) < 0){
        Log(LOG_ERR, "Failed in the initialization of the recording file.\n");
        goto exit;
    }
    Log(LOG_INFO, "Filenames created.\n");

    if ((retval = init_pa(rctx)) < 0){
        Log(LOG_ERR, "Failed in the initializaion of pulse audio.\n");
        goto exit;
    }
    Log(LOG_INFO, "PulseAudio connected.\n");

    Log(LOG_INFO, "Calibrating threshold.\n");
    printf("*****  ATTENTION  *****\n");
    printf("Keep quiet for the next %d seconds please.\n", QUIET_TIME);
    pa_stream_set_read_callback(rctx->recording_stream, detect_threshold_cb, rctx);
    rctx->timestamp = time(NULL);
    current_time = rctx->timestamp;
#ifdef DEBUG
    threshold_file = fopen("/tmp/threshold.pcm", "wb");
#endif
    while (difftime(current_time, rctx->timestamp) < QUIET_TIME){
        pa_mainloop_iterate(rctx->pa_ml, 0, &retval);
        current_time = time(NULL);
        if (retval < 0){
            Log(LOG_ERR,
                "There was a problem calculating the threshold power.\n");
            goto exit;
        }
    }
    Log(LOG_DEBUG, "Threshold: %f\n", rctx->threshold);

    Log(LOG_INFO, "Entering into the mainloop.\n");
    printf("\nNow you can start talking.\n");
    rctx->timestamp = time(NULL);
    pa_stream_set_read_callback(rctx->recording_stream, stream_request_cb, rctx);
    pa_mainloop_run(rctx->pa_ml, &retval);

exit:
    stop_recording(rctx, false);
    return retval;
}
Exemplo n.º 4
0
int main(int argc, char **argv) {

        Node *head = NULL;
        char **filenames = init_filenames();
        char ch;
        char *indexfile = "index";
        char *namefile = "filenames";
        char dirname[PATHLENGTH] = ".";
        char path[PATHLENGTH];

        while((ch = getopt(argc, argv, "i:n:d:")) != -1) {
                switch (ch) {
                        case 'i':
                        indexfile = optarg;
                        break;
                        case 'n':
                        namefile = optarg;
                        break;
                        case 'd':
                        strncpy(dirname, optarg, PATHLENGTH);
                        dirname[PATHLENGTH-1] = '\0'; 
                        break;
                        default:
                        fprintf(stderr, "Usage: indexer [-i FILE] [-n FILE ] [-d DIRECTORY_NAME]\n");
                        exit(1);
                }
        }
        DIR *dir;
        if((dir = opendir(dirname)) == NULL) {
                perror("opendir");
                exit(1);
        }
        struct dirent *dp;
        while((dp = readdir(dir)) != NULL) {
                if(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0 ||
                    strcmp(dp->d_name, ".svn") == 0) {
                        continue;
                }
                path[0] = '\0';
                strncpy(path, dirname, PATHLENGTH);
                strncat(path, "/", PATHLENGTH-strlen(path));
                strncat(path, dp->d_name, PATHLENGTH-strlen(path));
                path[PATHLENGTH-1] = '\0';
                printf("Indexing: %s\n", path);
                head = index_file(head, path, filenames);
        }
        write_list(namefile, indexfile, head, filenames);
        return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv) {
    Node *head = create_node("", 0, 0);
    char **filenames = init_filenames();
    char ch, line[MAXLINE], *token;
    char *indexfile = "index";
    char *namefile = "filenames";
    FILE *fp;

    while((ch = getopt(argc, argv, "i:n:")) != -1) {
        switch (ch) {
        case 'i':
            indexfile = optarg;
            break;
        case 'n':
            namefile = optarg;
            break;
        default:
            fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
            exit(1);
        }
    }

    while (optind < argc) {
	if ( (fp = fopen(argv[optind], "r")) == NULL) {
    		fprintf(stderr, "Cannot open file %s.\n", argv[optind]);
    	}
    	else {	
		while ( fgets(line, MAXLINE, fp) != NULL ) { 
			token = strtok(line, DELIM);
     			for(; token != NULL ;) {
				add_word(head, filenames, convert_to_lower(token), argv[optind]);
				token = strtok(NULL, DELIM);
			}
		}	
    		fclose(fp);
	}
    	optind++;
    }
    
    write_list(namefile, indexfile, head, filenames);
   
    return 0;
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
    Node **head = malloc(sizeof(Node *));
    Node *word_node;
    char **filenames = init_filenames();
    char ch;
    char *indexfile = "index";
    char *namefile = "filenames";
    char *word;

    while((ch = getopt(argc, argv, "i:n:")) != -1) {
    	switch (ch) {
            case 'i':
            	indexfile = optarg;
            	break;
            case 'n':
                namefile = optarg;
                break;
            default:
                fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
                exit(1);
        }
    }
    
    if (argv[optind] == NULL) { // No word arguments were given.
	fprintf(stderr, "Usage: indexfile [-u FILE] [-n FILE] FILE...\n");
	exit(1);
    }

    word = argv[optind];
    read_list(namefile, indexfile, head, filenames);
    word_node = find_word_node(*head, word);
    
    if (word_node != NULL) {
    	print_query(word_node, filenames);      
    }
    else { // The word does not exist in the linked list.
	printf("indexfile %s: word not found\n", argv[optind]);
    }

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char** argv) {
    /*
     * argv[1] = first run's directory 
     * argv[2] = second run's directory
    */
    if (argc != 4) {
        DEBUG(stderr, "argv[1] = first run's directory, argv[2] = second run's directory, argv[3] = input file\n");
    }
    assert(argc == 4);
    DEBUG(stderr, "argv0 = %s, argv1 = %s, argv2 = %s \n", argv[0], argv[1], argv[2]);

    first_dir = (struct directory_files*) malloc(sizeof(struct directory_files));
    second_dir = (struct directory_files*) malloc(sizeof(struct directory_files));
    gettimeofday(&stats.start, NULL);

    DEBUG(stderr, "init_filename\n");
    if (!init_filenames(argv[1], argv[2], argv[3])) {
        fprintf(stderr, "init filenames failed\n");
        exit(1);
    }

    DEBUG(stderr, "build_address_lookup\n");
    if (!build_address_lookup(first_dir->snapshot, second_dir->snapshot)) {
        fprintf(stderr, "build_dictionary failed\n");
        exit(1);
    }

    build_tables(first_dir, second_dir);

//    init_get_input_addrs(second_dir->dataflow_result);
    process_outputs(argv[3]);

    save_outputs();

    gettimeofday(&stats.end, NULL);
    print_stats(stats);
    return 1;
}
int main(int argc, char *argv[]){

  void *this_arte_packet;
  this_arte_packet = malloc(MAX_PACKET_BYTES);

  int sourcename;
  packetType_t sourcetype;
  int ok_packet;
  int packet_count = 0;
  char blank_data[MAX_PACKET_BYTES];
  
  //this_arte_packet = (void *)&(blank_data[0]);

  char input_filename[200], output_filename[200];

  init_filenames(argc, argv, 
		 input_filename, output_filename, 
		 &sourcename, &sourcetype);

  printf("sourcename:%d sourcetype:%c spike_sourcetype:%c\n", 
	 sourcename, sourcetype, NETCOM_UDP_SPIKE);


    if(this_arte_packet == NULL){
    printf("Memory error, sorry :[\n");
    exit(1);
  }

  in_f = fopen(input_filename, "rb");
  out_f = fopen(output_filename, "wb");

  if(in_f == NULL)
    printf("Bad in file: %s\n", input_filename);
  if(out_f == NULL)
    printf("Bad out_file: %s\n", output_filename);
  
  if(in_f == NULL || out_f == NULL)
    exit(1);

  ok_packet = false;
  while(!ok_packet & (feof(in_f) == 0) ){
    ok_packet = get_next_packet(this_arte_packet, sourcename, sourcetype);
  }
  printf("finished looking...\n");  fflush(stdout);

  write_file_header(this_arte_packet, argc, argv, sourcetype);
  
  printf("Finished writing file header.\n"); fflush(stdout);
  
  if( sourcetype == NETCOM_UDP_SPIKE){
    spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
    printf("test before first write_mwl: name:%d n_chans:%d\n", 
	   test_spike->name, test_spike->n_chans);
  }
  
  write_mwl(this_arte_packet, sourcetype);
  
  printf("Finished writing first packet with write_mwl.\n"); fflush(stdout);

  if( sourcetype == NETCOM_UDP_SPIKE){
    spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
    printf("test before loop: name:%d n_chans:%d\n", 
	   test_spike->name, test_spike->n_chans);
  }
  
  if(true){
    
    while( feof(in_f) == 0){
      ok_packet = get_next_packet(this_arte_packet, sourcename, sourcetype);
      if(verbose){
	if (ok_packet){
	  printf("This packet was ok:\n");}
	else {
	  printf("This packet was not ok:\n");}
	
	print_packet(this_arte_packet, sourcetype);
      }
      
      if(ok_packet){
	
	fflush(out_f);
	//printf("in loop...\n");
	if( sourcetype == NETCOM_UDP_SPIKE){
	  spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
	  //printf("test before write_mwl in loop: name:%d n_chans:%d\n", 
	  //	 test_spike->name, test_spike->n_chans);
	}
	
   	write_mwl(this_arte_packet, sourcetype);
	packet_count++;
      }
      interactive_wait("message1\n");
    }
    
  } // end if(true)
    //free(this_arte_packet);

  printf("finished. Wrote %d packet(s)\n", packet_count);
  exit(0);
  
}
Exemplo n.º 9
0
/*
 * The callback will record when mute isn't activated and:
 *    - it'll always record the first SILENCE_BREAKPOINTS events that are 
 *    above the low_point but below the high_point (these are normally the 
 *    trailing of a utterance).
 *    - it'll always record if the event is well below the high_level 
 *    (these are normally the utterances)
 *
 * The counter_activity (which is one of the responsible to record after all, 
 * see the above comment) is reseted mainly by a detected high_point utterance 
 * or when we have detected a long streak of idle.
 *
 * The callback will split an utterance when nothing interesting has been 
 * said in the last HOT_ZONE seconds.
 */
static void stream_request_cb(pa_stream *stream, size_t length, void *userdata)
{
    const void *data;
    size_t size = 0;
    double power, low_point, high_point;
    int retval, retries;
    time_t current_time;
    recorder_context_t *rctx = (recorder_context_t *) userdata;

    if (rctx->dirty_filename){
        fclose(rctx->recording_file);
        fclose(rctx->length_file);

        retries = 0;
        do{
            retval = init_filenames(rctx);
            retries++;
        } while(retval != 0 && retries < 20);
        if (retries == 20){
            Log(LOG_ERR, 
                "There was some nasty problems with the opening of %s file.\n",
                rctx->filename);
            stop_recording(rctx, false);
        }

        rctx->dirty_filename = false;
    }

    if (!rctx->mute){
        pa_stream_peek(stream, &data, &size);
        rctx->is_recording = false;

        power = calculate_rms_power(data, size);
        low_point = rctx->threshold * LOW_BREAKPOINT;
        high_point = rctx->threshold * HIGH_BREAKPOINT;
        rctx->total_activity++;
        if (data){
            if (power >= low_point){
                if (rctx->counter_silence < SILENCE_BREAKPOINT ||
                    power > high_point){

                    rctx->counter_idle = 0;

                    current_time = time(NULL);
                    if (difftime(current_time, rctx->timestamp) >= HOT_ZONE){
                        if (is_interesting(rctx)){
                            dump(rctx);
                            rctx->high_activity = rctx->total_activity = 0;
                        }
                        rctx->timestamp = current_time;
                    }

                    if (power <= high_point){
                        rctx->counter_silence++;
                    }else{
                        rctx->counter_silence = 0;
                        rctx->high_activity++;
                    }

                    rctx->is_recording = true;
                    buffer(rctx, data, size);

                    Log(LOG_DEBUG,
                        "-> power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }else{
                    Log(LOG_DEBUG,
                        "SS power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }
            }else{
                rctx->counter_idle = fmin(++rctx->counter_idle, IDLE_BREAKPOINT);
                if (rctx->counter_idle == IDLE_BREAKPOINT)
                    rctx->counter_silence = 0;
                Log(LOG_DEBUG,
                    "   power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
            }
            pa_stream_drop(stream);
        }
    }
}