int main (int argc, char **argv) { int i; for (i = 1; i < argc; i++) { FILE *f = fopen (argv[i], "r"); int iftxt; if (!f) { fprintf (stderr, "%s: %s: %s\n", argv[0], argv[i], strerror (errno)); continue; } if (istxt (f)) { char *ofn; FILE *of; int c; ofn = malloc (strlen (argv[i]) + 4 + 1); if (!ofn) abort(); sprintf (ofn, "%s.txt", argv[i]); printf ("%s\n", ofn); of = fopen (ofn, "w"); if (!of) { fprintf (stderr, "%s: %s: %s\n", argv[0], ofn, strerror (errno)); fclose (f); free (ofn); continue; } rewind (f); while ((c = getc (f)) != EOF) { if (c == '\r') putc ('\n', of); else putc (c, of); } fclose (of); free (ofn); } fclose (f); } }
int main(int argc, char **argv) { if(argc!=6) { perror("parameter:./normalization source_file dest_directory norm_choice ignore downsample"); return -1; } if(isreg(argv[1])&&istxt(argv[1])) { switch (atoi(argv[3])) { case 1: normalization_max(argv[1],argv[2]); break; case 2: normalization_mean(argv[1],argv[2],atoi(argv[4]),atoi(argv[5])); break; case 3: normalization_std_mean(argv[1],argv[2],atoi(argv[4])); break; case 4: normalization_log_mean(argv[1],argv[2]); break; } } else { DIR *dp; struct dirent *entry; struct stat statbuf; if((dp=opendir(argv[1]))==NULL) { fprintf(stderr,"cannot open directory: %s\n",argv[1]); } chdir(argv[1]); while((entry=readdir(dp))!=NULL) { lstat(entry->d_name,&statbuf); if(S_ISREG(statbuf.st_mode)&&istxt(entry->d_name)) { printf("normalize %s file\n",entry->d_name); switch (atoi(argv[3])) { case 1: normalization_max(entry->d_name,argv[2]); break; case 2: normalization_mean(entry->d_name,argv[2],atoi(argv[4]),atoi(argv[5])); break; case 3: normalization_std_mean(entry->d_name,argv[2],atoi(argv[4])); break; case 4: normalization_log_mean(entry->d_name,argv[2]); break; } printf("\n"); } } closedir(dp); } }