home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD1.img
/
d1xx
/
d168
/
src
/
com
/
remcr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-22
|
1KB
|
90 lines
/*
* REMCR.C
*
* REMCR [-l] file1 file2 ... filen
*
* -l : convert file name to lower case
*
*/
#include <stdio.h>
extern char *malloc();
main(ac,av)
char *av[];
{
register short i;
FILE *fi;
long len;
char *buf;
char clower = 0;
for (i = 1; i < ac; ++i) {
if (strcmp(av[i], "-l") == 0) {
clower = 1;
continue;
}
printf("%-20s ", av[i]);
fflush(stdout);
if ((fi = fopen(av[i], "r")) == NULL) {
perror(av[i]);
continue;
}
fseek(fi, 0, 2);
len = ftell(fi);
printf("%6ld ", len);
fflush(stdout);
if (len < 0 || (buf = malloc(len*2)) == NULL) {
puts("len < 0 or malloc failed");
fclose(fi);
continue;
}
fseek(fi, 0, 0);
if (fread(buf, len, 1, fi) != 1) {
puts("read failed");
goto done;
}
fclose(fi);
len = remcr(buf, len);
if (clower) {
register char *ptr;
for (ptr = av[i]; *ptr; ++ptr) {
if (*ptr >= 'A' && *ptr <= 'Z')
*ptr |= 0x20;
}
}
if ((fi = fopen(av[i], "w")) == NULL) {
puts("Unable to open for write");
goto done;
}
printf("write ");
fflush(stdout);
if (fwrite(buf, len, 1, fi) != 1) {
puts("write failed");
goto done;
}
puts("ok");
done:
fclose(fi);
free(buf);
}
}
remcr(buf, len)
register char *buf;
register long len;
{
register char *ptr = buf + len;
register long i, j;
for (i = j = 0; i < len; ++i) {
if (buf[i] == 13)
continue;
ptr[j++] = buf[i];
}
bmov(buf + len, buf, j);
return(j);
}