home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
languages
/
northc_384
/
script
/
script.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-09
|
2KB
|
109 lines
/* (c) 1990 S.Hawtin.
Permission is granted to copy this file provided
1) It is not used for commercial gain
2) This notice is included in all copies
3) Altered copies are marked as such
No liability is accepted for the contents of the file.
*/
#include <stdio.h>
#define BUF_LEN 256
int
copy(src,dest)
char *src;
char *dest;
{/* Copy a file from one place to another */
FILE *in;
FILE *out;
char buffer[BUF_LEN];
int count,total;
in = fopen(src,"r");
out = fopen(dest,"w");
if(in==NULL || out==NULL)
{if(in!=NULL)
fclose(in);
else
printf("Failed to open \"%s\" for reading\n",src);
if(out!=NULL)
fclose(out);
else
printf("Failed to open \"%s\" for writing\n",dest);
return(-1);
}
count = 1;
total = 0;
while(count>0)
{
count = fread(buffer,sizeof(char),BUF_LEN,in);
if(count>0)
{total += count;
fwrite(buffer,sizeof(char),count,out);
}
}
fclose(in);
fclose(out);
return(total);
}
int
ask(str)
char *str;
{/* Ask a question and return the result */
int answer = -1;
char result[20];
while(answer==-1)
{puts(str);
fflush(stdout);
gets(result);
switch (result[0])
{case 'y': case 'Y':
answer = 1;
break;
case 'n': case 'N':
answer = 0;
}
}
return(answer ? ~0 : 0);
}
int
type(name)
char *name;
{/* Type out the contents of a file */
FILE *in;
char buffer[BUF_LEN];
int count;
in = fopen(name,"r");
if(in==NULL)
{
printf("Failed to open \"%s\" for reading\n",name);
return(-1);
}
count = 1;
while(count>0)
{
count = fread(buffer,sizeof(char),BUF_LEN,in);
if(count>0)
{
fwrite(buffer,sizeof(char),count,stdout);
}
}
fclose(in);
return(0);
}
void
echo(str)
char *str;
{/* Put a string on the terminal */
puts(str);
putchar('\n');
}