示例#1
0
int main(int ac, char** av)
{
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  uint32_t x[2];

  prussdrv_init();

  if (prussdrv_open(PRU_EVTOUT_0))
  {
    printf("prussdrv_open open failed\n");
    return -1;
  }

  prussdrv_pruintc_init(&pruss_intc_initdata);

  /* execute code on pru0 */
#define PRU_NUM 0
  prussdrv_exec_program(PRU_NUM, "./iep.bin");

  signal(SIGINT, on_sigint);
  while (is_sigint == 0)
  {
    usleep(500000);
    read_words(x);
    printf("0x%08x, 0x%08x\n", x[0], x[1]);
  }

  /* disable pru and close memory mapping */
  prussdrv_pru_disable(PRU_NUM);
  prussdrv_exit();

  return 0;
}
示例#2
0
static void
add_users (const char *filename, unsigned n)
{
    krb5_error_code ret;
    int i;
    void *kadm_handle;
    krb5_context context;
    unsigned nwords;
    char **words;

    ret = krb5_init_context(&context);
    if (ret)
	errx (1, "krb5_init_context failed: %d", ret);
    ret = kadm5_s_init_with_password_ctx(context,
					 KADM5_ADMIN_SERVICE,
					 NULL,
					 KADM5_ADMIN_SERVICE,
					 NULL, 0, 0,
					 &kadm_handle);
    if(ret)
	krb5_err(context, 1, ret, "kadm5_init_with_password");

    nwords = read_words (filename, &words);

    for (i = 0; i < n; ++i)
	add_user (context, kadm_handle, nwords, words);
    kadm5_destroy(kadm_handle);
    krb5_free_context(context);
}
示例#3
0
/*
 * Lê todos os arquivos e passa as palavras de cada um para a função de read_words()
 */
void read_files(int argc, char** argv) {
    int i;
    FILE *arquivo;

    for (i = 1; i < argc; i++) {
        arquivo = fopen(argv[i], "r");
        if (arquivo != NULL) {
            // vamos obter o tamanho do arquivo em bytes
            fseek(arquivo, 0, SEEK_END);
            long tam_arquivo = ftell(arquivo);
            rewind(arquivo);

            // vamos alocar memória para todo o conteúdo do arquivo
            char *buffer = (char*) malloc(sizeof (char) * tam_arquivo);
            // a memória foi alocada com sucesso?
            if (buffer != NULL) {
                // copiar o conteúdo do arquivo para o buffer
                size_t resultado = fread(buffer, 1, tam_arquivo, arquivo);

                // verificar se a operação foi feita com sucesso
                if (resultado == tam_arquivo) {
                    printf("O conteudo do arquivo foi lido com sucesso\n\n");
                    //fprintf(stderr, "arquivo: %s\n", buffer);
                }
            }
            // passa o arquivo inteiro lido para a função de 
            read_words(buffer, argv[i]);
            fclose(arquivo); // fecha o arquivo
            free(buffer); // libera a memória do buffer
        }
    }

}
示例#4
0
int main()
{
    std::vector<std::string> words;

    std::cout << "Write some words" << std::endl;
    read_words(std::cin, words);

    std::cout << "There are " << words.size() << " words" << std::endl;

    return 0;
}
示例#5
0
int
main (int ac, char** av)
{
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  uint32_t x[MEM_SIZE];
  const size_t n = sizeof (x) / sizeof (x[0]);
  size_t i;
  size_t count = 0;

  printf ("n: %u \n", n);

  prussdrv_init ();

  if (prussdrv_open (PRU_EVTOUT_0))
    {
      printf ("prussdrv_open open failed\n");
      return -1;
    }

  prussdrv_pruintc_init (&pruss_intc_initdata);

  /* zero_words(n); */

  /* write data from data.bin */
  prussdrv_load_datafile (PRU_NUM, "./data.bin");

  /* execute code on pru0 */
  prussdrv_exec_program_at (PRU_NUM, "./text.bin", START_ADDR);
  // prussdrv_exec_program(PRU_NUM, "./text.bin");

  signal (SIGINT, on_sigint);
  while (is_sigint == 0)
    {
      printf ("reading count: %d\n", count++);
      usleep (1000000);
      read_words (x, n);
      for (i = 0; i != n; ++i)
        {
          //printf("mem 0x%08x: (%f)\n", x[i], *((float*)(x + i)));
          printf ("mem %d %08x: (%08x)\n", i, (x + i), (unsigned int) (*(x + i)));
        }
      printf ("\n");
    }

  /* disable pru and close memory mapping */
  prussdrv_pru_disable (PRU_NUM);
  prussdrv_exit ();

  return 0;
}
示例#6
0
WordSearch::WordSearch(const string& topdir, const string& ignore_file) {
    load_ignored_words(ignore_file);
    /* filter the directory only for files ending with "txt" */
    gvsu::FileSystem dir (topdir);
    unsigned long wordCount = 0;
    map<int, set<string>> lengthMap;
    map<string, unsigned int> wordFrequency;
    map<unsigned int, set<string>> leastFrequent;
    map<string, map<string, int>> predictWord;
    map<string, set<string>> wordFileMap;


    for (auto entry : dir) {
        cout << "Reading words from " << entry.second << endl;
        read_words (entry.first + "/" + entry.second);
    }
}
示例#7
0
文件: arccc.c 项目: thouis/arcccc
int main(int argc, char *argv[])
{
  GSList *words, *letters, *constraints, *ll;
  GPtrArray *dictionary;
  gchar *grid;
  struct wordvar *w;

  if (argc != 3) {
    printf("usage: %s grid dictionary\n", argv[0]);
    exit (-1);
  }
  
  words = letters = constraints = NULL;

  grid = read_grid(argv[1], &words, &letters, &constraints);
  dictionary = read_words(argv[2]);
  init_vars(words, letters, dictionary);

  printf("%s\n", grid);

  w = words->data;
  printf("Initial %d\n", w->possible_values->len);

  for (ll = constraints; ll != NULL; ll = ll->next) {
    struct constraint *c = ll->data;
    put_constraint_on_queue(c);
  }

  run_constraints();

  printf("First %d\n", w->possible_values->len);

  for (ll = constraints; ll != NULL; ll = ll->next) {
    struct constraint *c = ll->data;
    put_constraint_on_queue(c);
  }


  total = 0;
  find_solution(words, letters, grid, 0);
  printf("total %d\n", total);


  return (0);
}
示例#8
0
//Charactor *
int main(int argc, char *argv[])
{
	Charactor *head;
	head = (Charactor *)malloc(sizeof(Charactor));
	head->next = NULL;

	int i;

//	char data[1000] = {"我不认识你,你是谁啊,你好"};

//	for (i = 0; i < strlen(data); i++)
//	{
///		printf("%c\t", data[i]);
//	}


//	head = find(data, head);
//	Count(head);

	read_words(head);
	Count(head);
	return EXIT_SUCCESS;
}
示例#9
0
User *User_Line_Parse(char *line) {
  char     **words;
  char      *name;
  User      *user;

  int    i;

  words   = read_words(0,line);
  name    = words[0];
  user    = User_Create(name,-1);
  
  int    gcount = 0;

  i = 2;

  while (words[i] != NULL) {
    char     *groupname = words[i];
    Labgroup *group     = Labgroup_Create(groupname,-1);

    user->groups[gcount] = group;

    gcount++;
    i++;
      
  }

  user->groups[gcount] = NULL;

  i = 0;
  
  while (words[i] != NULL) {
    free(words[i]);
    i++;
  }
  
  return user;
}
示例#10
0
static void
generate_requests (const char *filename, unsigned nreq)
{
    krb5_context context;
    krb5_error_code ret;
    int i;
    char **words;
    unsigned nwords;

    ret = krb5_init_context (&context);
    if (ret)
	errx (1, "krb5_init_context failed: %d", ret);

    nwords = read_words (filename, &words);

    for (i = 0; i < nreq; ++i) {
	char *name = words[rand() % nwords];
	krb5_get_init_creds_opt *opt;
	krb5_creds cred;
	krb5_principal principal;
	int result_code;
	krb5_data result_code_string, result_string;
	char *old_pwd, *new_pwd;
	int aret;

	krb5_get_init_creds_opt_alloc (context, &opt);
	krb5_get_init_creds_opt_set_tkt_life (opt, 300);
	krb5_get_init_creds_opt_set_forwardable (opt, FALSE);
	krb5_get_init_creds_opt_set_proxiable (opt, FALSE);

	ret = krb5_parse_name (context, name, &principal);
	if (ret)
	    krb5_err (context, 1, ret, "krb5_parse_name %s", name);

	aret = asprintf (&old_pwd, "%s", name);
	if (aret == -1)
	    krb5_errx(context, 1, "out of memory");
	aret = asprintf (&new_pwd, "%s2", name);
	if (aret == -1)
	    krb5_errx(context, 1, "out of memory");

	ret = krb5_get_init_creds_password (context,
					    &cred,
					    principal,
					    old_pwd,
					    nop_prompter,
					    NULL,
					    0,
					    "kadmin/changepw",
					    opt);
	if( ret == KRB5KRB_AP_ERR_BAD_INTEGRITY
	    || ret == KRB5KRB_AP_ERR_MODIFIED) {
	    char *tmp;

	    tmp = new_pwd;
	    new_pwd = old_pwd;
	    old_pwd = tmp;

	    ret = krb5_get_init_creds_password (context,
						&cred,
						principal,
						old_pwd,
						nop_prompter,
						NULL,
						0,
						"kadmin/changepw",
						opt);
	}
	if (ret)
	    krb5_err (context, 1, ret, "krb5_get_init_creds_password");

	krb5_free_principal (context, principal);


	ret = krb5_set_password (context,
				 &cred,
				 new_pwd,
				 NULL,
				 &result_code,
				 &result_code_string,
				 &result_string);
	if (ret)
	    krb5_err (context, 1, ret, "krb5_change_password");

	free (old_pwd);
	free (new_pwd);
	krb5_free_cred_contents (context, &cred);
	krb5_get_init_creds_opt_free(context, opt);
    }
}
示例#11
0
文件: mapreduce.c 项目: anmousyon/uni
int main(int argc, char **argv){
	printf("starting\n");
	int num_maps = atoi(argv[1]);
	int BUFSZ = 250;
	int buffer[BUFSZ];
	int child[num_maps];
	int pid = 1;
	int cid = 0;
	int ptc[num_maps][2];
	int ctp[num_maps][2];
	int total = 0;

	printf("opening file\n");
	//open the file
	FILE *fp;
	fp = fopen(argv[3], "r");

	//find number of words each child needs to read
	int num_words = count_words(fp);
	int to_read = num_words/num_maps;

	printf("opening pipes\n");
	//open pipes
	int i;
	for(i=0; i<num_maps; i++){
		pipe(ptc[i]);
		pipe(ctp[i]);
	}

	printf("forking children\n");
	//fork all new children
	for(i=0; i<num_maps; i++){
		if(pid != 0){
			pid = fork();
			child[i] = pid;
			cid = i;
		}
	}

	//parent process
	if(pid>0){
		printf("parent process\n");
		for(int i=0;i<num_maps;i++){
			//close unnecessary pipes
			write(ptc[i][0], buffer, sizeof(buffer));
			close(ctp[i][1]);

			//wait for teach child to finish before reading
			int returnstatus;
			waitpid(child[i], &returnstatus, 0);

			//get data from child then close the child
			read(ctp[i][0], &buffer[i], sizeof(int));
			close(ctp[i][0]);
		}
		//add up the total
		for(int i=0; i<num_maps; i++){
			total += buffer[i];
		}
		//print the total
		printf("total: %d\n", total);
	}

	//child process
	if(pid == 0){
		printf("child process\n");
		//close unnecessary pipes
    	close(ptc[cid][1]);
    	close(ctp[cid][0]);
		//find section to read
		int start = cid * to_read;
		int end = (cid+1) * to_read;
		//correct for integer division
		if (end >= (num_words-to_read)){
			end = num_words;
		}
		//calc frequency
		fp = fopen(argv[3], "r");
		int frequency = read_words(fp, start, end, argv[2]);
		//print out findings
		printf("child %d started at %d and ended at %d\n", cid, start, end);
		printf("child %d found: %d\n", cid, frequency);
		//send the frequency to parent then close pipe
    	write(ctp[cid][1], &frequency, sizeof(frequency));
    	close(ctp[cid][1]);
	}
}
示例#12
0
unsigned char *read_den(char *filename,int *xptr,int *yptr,int *zptr)
{
    FILE *fd;			/* file descriptor */
    unsigned char *data;	/* data array */
    int swapbytes;		/* true if header must be byte-swapped */
    short map_version;		/* Version of this .den file                 */
    short orig_min[3];		/* Dimensions of original data file          */
    short orig_max[3];
    short orig_len[3];
    short extr_min[3];		/* Extracted portion of original file        */
    short extr_max[3];		/*   (mins and maxes will be subset of       */
    short extr_len[3];		/*    orig and lengths will be <= orig)      */
    short map_min[3];		/* Dimensions of this map                    */
    short map_max[3];		/*   (mins will be 0 in this program and     */
    short map_len[3];		/*    lens may be != extr if warps > 0)      */
    short map_warps;		/* Number of warps since extraction          */
				/*   (0 = none)                              */
    int map_length;		/* Total number of densities in map          */
				/*   (= product of lens)                     */
	
    /* open the file */
    if ((fd = fopen(filename, "rb")) == NULL) {
		fprintf(stderr, "cannot open file %s\n", filename);
		return(NULL);
    }
	
    /* read the magic number */
    if (!read_shorts(fd, &map_version, 1, 0)) {
		fprintf(stderr, "read failed on file %s (empty file?)\n", filename);
		return(NULL);
    }
    if (map_version == MAP_CUR_VERSION) {
		swapbytes = 0;
    } else if (map_version == MAP_CUR_VERSION_SWAB) {
		swapbytes = 1;
    } else {
		fprintf(stderr, "file %s is not a density file\n", filename);
		return(NULL);
    }
	
    /* read the volume size information */
    if (!read_shorts(fd, orig_min, 3, swapbytes) ||
		!read_shorts(fd, orig_max, 3, swapbytes) ||
		!read_shorts(fd, orig_len, 3, swapbytes) ||
		!read_shorts(fd, extr_min, 3, swapbytes) ||
		!read_shorts(fd, extr_max, 3, swapbytes) ||
		!read_shorts(fd, extr_len, 3, swapbytes) ||
		!read_shorts(fd, map_min, 3, swapbytes) ||
		!read_shorts(fd, map_max, 3, swapbytes) ||
		!read_shorts(fd, map_len, 3, swapbytes) ||
		!read_shorts(fd, &map_warps, 1, swapbytes) ||
		!read_words(fd, &map_length, 1, swapbytes)) {
		fprintf(stderr, "read failed on file %s (truncated file?)\n",filename);
		return(NULL);
    }
    if (map_length != map_len[0]*map_len[1]*map_len[2]) {
		fprintf(stderr, "density file %s has an inconsistent header\n",
			filename);
		return(NULL);
    }
	
    /* allocate array for data */
    data = (unsigned char *)malloc(map_length);
    if (data == NULL) {
		fprintf(stderr, "out of memory\n");
		return(NULL);
    }
	
    /* copy the data from the file */
    if (!read_bytes(fd, (char *)data, map_length)) {
		fprintf(stderr, "read failed on file %s\n", filename);
		fclose(fd);
		free(data);
		return(NULL);
    }
	
    /* finish up */
    fclose(fd);
    *xptr = map_len[0];
    *yptr = map_len[1];
    *zptr = map_len[2];
    return(data);
}
示例#13
0
void
play_game_anagram()
{
    
       
    srand(time(NULL));
    system("clear");   
    
    printf("\n\n\n************************************ ANAGRAM GAME ********************\n\n");
    printf("***************** You need to guess the correct word by looking at the given anagram... ******************** \n\n");
    
    char proceed = 'y';
    
    int count = read_words(); //read the file and get the word count for the game
    //printf("count is %d\n", count);
    //exit(0);

    int anagram_no = 1; //these many words are displayed without asking and then ask for user confirmation

    while(proceed == 'y' || proceed == 'Y')
    {
        
        system("clear");
        printf("\n\n\n************************************ ANAGRAM GAME ********************\n\n");
        printf("***************** You need to guess the correct word by looking at the given anagram... ******************** \n\n");
        int no_tries = 0, no_hints = 0;
        int max_tries = 0, max_hints = 0;
        int right = 0;
        
        

        int disp_word_num = rand() % count;
        int disp_word_len = strlen(words[disp_word_num]);
        char display_word[MAX_LENGTH];
        char hint_buf[MAX_LENGTH];
        char answer[MAX_LENGTH];

        //strcopy(hint_buf, words[disp_word_num]);
        //fill_word(hint_buf, '.', disp_word_len);
        memset(hint_buf, '.', disp_word_len);

        if(disp_word_len <=5)
            max_tries = 3;
        else
            max_tries = 5;
            
        if(disp_word_len <=5)
            max_hints = 2;
        else
            max_hints = 4;

        strcpy(display_word, words[disp_word_num]);
        shuffle_word(display_word, disp_word_len);
        while(++no_tries <= max_tries)
        {    
            printf("            Anagram #%d: %s, Type in correct word, Attempt #%d :  ", anagram_no, display_word, no_tries);
            fgets(answer, MAX_LENGTH, stdin);
        
        
            //check if it is right answer
            if(strncmp(answer, words[disp_word_num], disp_word_len) == 0)
            {
                printf("\n\nNice...Right Answer...You have succeeded in %d Attemtpts\n\n\n", no_tries);
                right = 1;
                break;
            }
            else
            {
                if(++no_hints <= max_hints)
                    give_hint(words[disp_word_num], hint_buf, no_hints, disp_word_len);   
            }   
        
        }
        
        if(!right)
        {
            printf("\n\nNice try...Answer is : %s\n", words[disp_word_num]);
            //getchar();
        }
        fflush(NULL);
        
        if(anagram_no++ < ASK_USER_AFTER)
        {
            sleep(3);
            continue;
        }

        printf("\nWant to Proceed with another word now...?(y/n): ");
        //proceed = getchar();
        proceed = fgetc(stdin);
        getchar(); //to eat the new_line character left by fgetc
        
                  
    }
    
    printf("\n\nThank you for Playing...Try again when you have some time....\n\n");
    return 0;
}