config.c
wsh/src/tcp-s/config.c · 4.0 KB
From the archive wsh-147.tar.gz
Download the archive « Back to the archive contents
#include <sys/types.h>
#include <stdio.h>
#include <sys/stat.h>
#include <signal.h>
/*#define DEBUG /* Provides extra debugging info */
int exists(file)
char *file;
{
struct stat statbuf;
if ( stat(file, &statbuf) == 0 )
return(1);
else
return(0);
}
main()
{
int irix=0;
char cflags[BUFSIZ], ldflags[BUFSIZ];
char line[BUFSIZ];
FILE *makefile;
if ( exists("Makefile") )
{
fprintf(stderr, "Makefile already exists. Continue? [y/n] ");
fgets(line, BUFSIZ-1, stdin);
if ( line[0] == 'y' )
printf("Continuing...\n");
else
{
printf("Configuration aborted. Exiting.\n");
exit(0);
}
}
if ( (makefile=fopen("Makefile", "w")) == NULL )
{
perror("Can't create Makefile");
printf("Configuration aborted. Exiting.\n");
exit(2);
}
#ifdef DEBUG
sprintf(cflags, " -g -DDEBUG");
#else
sprintf(cflags, " -O");
#endif
if ( grep("/usr/include/unistd.h", "_getpty") )
{
strcat(cflags, " -DIRIX");
irix=1;
}
if ( grep("/usr/include/utmp.h", "ut_host") )
strcat(cflags, " -DHAVE_UTHOST");
if ( exists("/usr/include/arpa/telnet.h") )
strcat(cflags, " -DHAVE_ARPA_TELNET");
if ( exists("/usr/include/termio.h") )
strcat(cflags, " -DHAVE_TERMIO_H");
if ( exists("/usr/include/sys/bsdtty.h") )
strcat(cflags, " -DHAVE_BSDTTY_H");
/* Check for ioctl compatibility. (FreeBSD) */
if ( exists("/usr/include/sys/ioctl_compat.h") )
strcat(cflags, " -DNEED_COMPAT_H");
if ( exists("/usr/include/sys/inet.h") )
strcat(cflags, " -DNEED_INET_H");
if ( exists("/usr/include/sys/select.h") )
strcat(cflags, " -DNEED_SELECT_H");
else
{
#ifdef SIGTSTP
if ( ! irix )
strcat(cflags, " -DSHORT_IAC");
#else
/* AIX uses 255 instead of -1 for IAC */ ;
#endif
}
if ( exists("/usr/lib/libnet.a") )
strcat(ldflags, " -lnet");
if ( exists("/usr/lib/libnsl_s.a") )
strcat(ldflags, " -lnsl_s");
/* Solaris 2.1 */
if ( exists("/usr/lib/libsocket.a") )
{
strcat(ldflags, " -lsocket");
strcat(cflags, " -DSHORT_IAC -DSOLARIS");
}
if ( exists("/usr/lib/libnsl.a") )
strcat(ldflags, " -lnsl");
if ( exists("/usr/lib/libsun.a") )
strcat(ldflags, " -lsun"); /* IRIX needs this for getpw*() */
if ( exists("/usr/lib/libshadow.a") ) {
printf("You may need to define NEEDSHADOW in login.h\n");
strcat(ldflags, " -lshadow");
}
fprintf(makefile,"# This Makefile has been generated from the Configure script.\n# Shareware copyright 1993, by Sam Lantinga\n\n");
fprintf(makefile, "\nCFLAGS = %s\nLIBS = %s\n\n", cflags, ldflags);
fprintf(makefile,"#\n# Internet stream version (TCP protocol).\n#\n\n");
#ifdef SIGTSTP
fprintf(makefile, "STUFF = tcpserv\n\n");
#else
fprintf(makefile, "STUFF = tcpserv\n\n");
#endif
fprintf(makefile, "tcp:\t$(STUFF)\n\n");
fprintf(makefile, "bgtcli.o tcpserv.o telnet.o: tcp.h\n\n");
fprintf(makefile, "bgtcli: bgtcli.o tty.o telnet.o\n\t$(CC) -o $@ bgtcli.o tty.o telnet.o $(LIBS)\n\n");
#ifdef SIGTSTP
fprintf(makefile,
"connect: connect.o tty.o\n\t$(CC) -o $@ connect.o tty.o\n\n");
#endif
fprintf(makefile, "tcpserv: tcpserv.o sync-rw.o tty.o telnet.o login.o\n\t$(CC) -o $@ tcpserv.o sync-rw.o tty.o telnet.o login.o $(LIBS)\n\n");
fprintf(makefile,
"daemonize: daemonize.o tty.o\n\t$(CC) -o $@ daemonize.o tty.o\n\n");
fprintf(makefile, "#\n# Misc. stuff\n#\n\n");
fprintf(makefile,
"hostinfo:\thostinfo.o\n\t$(CC) -o $@ hostinfo.o $(LIBS)\n");
fprintf(makefile, "\nclean:\n\t-rm -f tmp* *.o \n\t-rm -f core $(STUFF) hostinfo Makefile\n\n");
fprintf(makefile, "backup: tcpserv bgtcli connect\n\tmv $(STUFF) ${HOME}/shprogs/; make clean; cd ..; tar -cf tcp-s.tar tcp-s\n");
fclose(makefile);
exit(0);
}
/* Yeesh. I have to write a word grep function.... */
int grep(file, word)
char *file;
char *word;
{
FILE *fp;
char *wptr, *ptr, buffer[BUFSIZ];
if ( (fp=fopen(file, "r")) == NULL )
return(0);
ptr=word;
while ( fgets(buffer, BUFSIZ-1, fp) != NULL )
{
for ( wptr=buffer; *wptr; ++wptr)
{
if ( *wptr == *ptr )
{
++ptr;
if ( *ptr == '\0' )
{
(void) fclose(fp);
return(1);
}
}
else
ptr=word;
}
}
(void) fclose(fp);
return(0);
}