Exemplo n.º 1
0
int main(int argc, char **argv)
{
	int n;
	unsigned int seed;
	FILE *fout;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <n> [<seed>]\n", argv[0]);
		exit(1);
	}

	n = atoi(argv[1]);
	if (argc == 3) {
		seed = atoi(argv[1]);
	} 


	fout = fopen("data.bin", "w");
	if (!fout) {
		perror("");
	}

	generate_file(n ,seed, fout);

	fclose(fout);
	exit(0);
}
Exemplo n.º 2
0
void generate_group(const char *group) {
  char *dir_name = get_group_directory(group);
  DIR *dirp;
  struct dirent *dp;
  char file_name[MAX_FILE_NAME];
  struct stat stat_buf;

  if ((dirp = opendir(dir_name)) == NULL)
    return;
    
  while ((dp = readdir(dirp)) != NULL) {
    snprintf(file_name, MAX_FILE_NAME, "%s/%s", dir_name,
	     dp->d_name);

    if (stat(file_name, &stat_buf) == -1) {
      fprintf(stderr, "Couldn't stat file %s", file_name);
      break;
    }
    
    if (! S_ISDIR(stat_buf.st_mode) &&
	is_number(dp->d_name)) {
      generate_file(file_name, atoi(dp->d_name));
    }
  }
  closedir(dirp);
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
	int file_count, opt;
	char *opath = NULL;
	int targetfd;
	struct file_stripe_info *finfo;

	while ((opt = getopt(argc, argv, "o:")) != -1) {
		switch (opt) {
		case 'o':
			opath = optarg;
			break;
		default:
			usage(argv[0]);
			return -1;
		}
	}

	file_count = argc - optind;

	if (!opath || !file_count) {
		usage(argv[0]);
		return -1;
	}

	finfo = validate_and_open_files(&argv[optind], file_count);
	if (!finfo)
		goto err;

	targetfd = open(opath, O_RDWR|O_CREAT, finfo->mode);
	if (targetfd < 0)
		goto err;

	if (generate_file(targetfd, finfo) < 0)
		goto err;

	if (fsync(targetfd) < 0)
		fprintf(stderr, "ERROR: %s\n", strerror(errno));
	if (close(targetfd) < 0)
		fprintf(stderr, "ERROR: %s\n", strerror(errno));

	close_files(finfo);
	free(finfo);

	return 0;

err:
	if (finfo) {
		close_files(finfo);
		free(finfo);
	}

	return -1;
}
Exemplo n.º 4
0
int main(int argc, char ** argv)
{
    pid_t pid1, pid2, pid3;
    int status;

    pid1 = fork();

    if (pid1 == 0) {
        //child process
        generate_file();
        printf("File created.\n");
        exit(EXIT_SUCCESS);
    }  else {
        //parent process
        waitpid( pid1, &status, 0);
        pid1 = fork();
        if (pid1 == 0) {
            //child process
            execlp("wc", "wc", "-m", "random.txt", (char * ) 0);
        } else {
            pid2 = fork();
            if (pid2 == 0) {
                //child process
                execlp("wc", "wc", "-w", "random.txt", (char *) 0);
            } else {
                //parent process
                pid3 = fork();
                if (pid3 == 0) {
                    //child process
                    execl("./average", "average", "random.txt", (char *) 0);
                }   else {
//                    parent process
                    waitpid(pid1, &status, 0);
                    printf("Child %d terminated with status %d\n", pid1, status);
                    waitpid(pid2, &status, 0);
                    printf("Child %d terminated with status %d\n", pid2, status);
                    waitpid(pid3, &status, 0);
                    printf("Child %d terminated with status %d\n", pid3, status);
                }

            }

        }


    }



    return 0;
}
Exemplo n.º 5
0
/**
 * Main entry point.
 */
int main(int argc, char** argv) {
    char* output = argv[1];
    char use_define = 1;
    
    if (argc < 2) {
        print_usage(argv[0]);
        return 1;
    
    } else if (argc == 3) {
        output = argv[2];
    }
    
    generate_file(argv[1], output, use_define);
    
    return 0;
}
Exemplo n.º 6
0
Arquivo: Ex12.c Projeto: marrusian/C
int main(void)
{
   char picture[ROWS][COLS+1] = {{0}};

   srand((unsigned int) time(0));
   if(generate_file(FLNM, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);
 
   if(generate_image(FLNM, (char*)picture, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);

   display_image((char*)picture, ROWS, COLS);

   if(store_image(IMGNM, (char*)picture, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);

   return 0;
}
Exemplo n.º 7
0
int
main (int argc, char * argv [])
{
	PARAMS params = { 1.0, -1, -1, 0, 0, 0, NULL } ;
	const char * filename ;
	int k ;

	if (argc < 4)
		usage_exit (argv [0]) ;

	for (k = 1 ; k < argc - 3 ; k++)
	{	if (strcmp (argv [k], "-from") == 0)
		{	k++ ;
			params.start_freq = parse_double_or_die (argv [k], "from frequency") ;
			continue ;
			} ;
		if (strcmp (argv [k], "-to") == 0)
		{	k++ ;
			params.end_freq = parse_double_or_die (argv [k], "to frequency") ;
			continue ;
			} ;
		if (strcmp (argv [k], "-amp") == 0)
		{	k++ ;
			params.amplitude = strtod (argv [k], NULL) ;
			continue ;
			} ;

		if (argv [k][0] == '-')
		{	params.sweep_func = parse_sweep_type (argv [k]) ;
			continue ;
			} ;

		printf ("\nUnknow option '%s'.\n\n", argv [k]) ;
		exit (1) ;
		} ;

	params.samplerate = parse_int_or_die (argv [argc - 3], "sample rate") ;
	params.seconds = parse_double_or_die (argv [argc - 2], "seconds") ;
	filename = argv [argc - 1] ;

	check_int_range ("sample rate", params.samplerate, 1000, 200 * 1000) ;
	check_double_range ("seconds", params.seconds, 0.1, 100.0) ;

	if (params.sweep_func == NULL)
		params.sweep_func = parse_sweep_type ("-log") ;
	if (params.start_freq <= 0.0)
		params.start_freq = 100.0 ;
	if (params.end_freq <= 0.0)
		params.end_freq = params.samplerate / 2.0 - 100.0 ;

	if (params.end_freq <= params.start_freq)
	{	printf ("\nError : end frequency %g < start frequency %g.\n\n", params.end_freq, params.start_freq) ;
		exit (1) ;
		} ;

	params.format = guess_major_format (filename) | SF_FORMAT_FLOAT ;

	generate_file (filename, &params) ;

	return 0 ;
} /* main */