8
/* Remove the '\r' characters specifics to DOS */
9
int convert(char *filename)
16
/* Open the input file and process it into a temp file */
17
printf("Processing file <%s>... ", filename);
18
in=fopen(filename, "rt");
21
printf("Unable to open this file: <%s>.\n", filename);
24
tmp=fopen("dos2unix.tmp", "wt");
27
printf("Unable to open temporary file.\n");
42
/* Copy the temp file into the input file */
43
tmp=fopen("dos2unix.tmp", "rt");
46
printf("Unable to open this file: <%s>.\n", filename);
49
out=fopen(filename, "wt");
52
printf("Unable to open temporary file.\n");
66
unlink("dos2unix.tmp");
71
/* Return the filename or its extension if it has one */
72
char *file_extension(char *filename)
77
for(i=strlen(filename); i > 0; i--)
79
if(filename[i] == '.') break;
86
/* Used by scandir to select files to sort */
87
int select_file(const struct dirent *d)
89
const char *files[]={ "Makefile", "Makefile.in", ".c", ".h", ".txt" , NULL};
92
while(files[i] != NULL)
94
if(!strcmp(file_extension((char *)d->d_name), files[i])) break;
97
//printf("<%i: %s>\n", i, files[i]);
106
int main(int argc, char *argv[], char **arge)
109
struct dirent **namelist;
115
strcpy(filename, argv[1]);
116
if(convert(filename))
118
printf("Error !!!\n");
123
n = scandir(".", &namelist, select_file, alphasort);
129
//printf("<%s>\n", namelist[n]->d_name);
130
convert(namelist[n]->d_name);
131
chmod(namelist[n]->d_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);