home *** CD-ROM | disk | FTP | other *** search
- #include "global.h"
- #include "cat.h"
- #include "edit.h"
- #include "control.h"
- #include "util.h"
- #include "lu.h"
-
- #define VERSION 104
- #define usage() (void) fprintf ( stderr, "Usage: %s [-p|-l|-e|-t|-s|-r|-v|-x|-z]\n", file ); exit ( 4 );
- #define check_flag() if ( argv[1][2] ) { usage() }
-
- extern char *sprintf();
- char text_file[MAX_FILE_LENGTH], file[MAX_FILE_LENGTH];
- char history_file[MAX_FILE_LENGTH], last_file[MAX_FILE_LENGTH];
- #ifdef LOCKF_BROKEN
- char lock_file[MAX_FILE_LENGTH];
- #endif LOCKF_BROKEN
-
- /* void init_file_names ( invocation )
- *
- * This function works out the names of the files used by gosip, from the
- * name by which it is invoked, and places them in various global variables.
- *
- * invocation : points to the name by which gosip was invoked (argv[0]).
- */
- void init_file_names ( invocation )
- char *invocation;
- {
- char *ptr = invocation, *temp = invocation;
-
- while ( *ptr != '\0' )
- if ( *ptr++ == '/' )
- temp = ptr;
- (void) strcpy ( file, temp);
- (void) sprintf ( history_file, "%s/HISTOrY.%s", DATA_FILE_DIRECTORY, file );
- (void) sprintf ( text_file, "%s%s/text.%s", DATA_FILE_DIRECTORY, SECRET_DIR, file );
- (void) sprintf ( last_file, "%s/LAsT.%s", DATA_FILE_DIRECTORY, file );
- #ifdef LOCKF_BROKEN
- (void) sprintf ( lock_file, "%s/lLo$Ck.%s", DATA_FILE_DIRECTORY, file );
- #endif LOCKF_BROKEN
- }
-
- /* void reserve()
- *
- * This function prints a message as soon as the gosip file is no longer
- * being edited. It firsts checks if gosip is being edit. If so, it
- * fork()s, and the child checks for the lock every 5 seconds.
- */
- static void reserve()
- {
- int pid;
-
- if ( ! lock ( CHECK ) )
- {
- (void) printf ( "The %s file is not being edited.\n", file );
- exit ( 1 );
- }
- error ( pid = fork(), "fork failed" );
- if ( pid == 0 )
- {
- while ( lock ( CHECK ) )
- sleep ( 5 );
- (void) printf ( "\007\r\nThe %s file is no longer being edited.\r\n", file );
- }
- else
- (void) printf ( "You'll be informed when %s becomes available.\n", file );
- exit ( 0 );
- }
-
- main ( argc, argv )
- int argc;
- char *argv[];
- {
- init_file_names ( argv[0] );
- check_if_up();
-
- if ( ! strcmp ( file, "lu" ) )
- lu ( argc, argv );
- if ( ! strcmp ( file, "allgoss" ) )
- {
- char *files[FILE_NUM], **fptr = files;
- byte num = allgoss ( files );
-
- while ( num-- )
- puts ( *fptr++ );
- exit ( 0 );
- }
-
- if ( argc == 1 )
- {
- char *opt = getenv ( "GOSIP" );
-
- if ( opt )
- {
- argc = 2;
- argv[1] = opt;
- }
- }
- switch ( argc )
- {
- default:
- usage();
- case 1:
- do_edit ( normal, "dummy" );
- case 2:
- if ( argv[1][0] == '-' )
- switch ( argv[1][1] )
- {
- case '#':
- if ( strcmp ( usercode(), SUPER_USER ) )
- catfile ( normal ); /* pretend the option doesn't exist */
- if ( argv[1][2] == '\0' )
- {
- puts ( "Use the option correctly, fishhead.\n" );
- exit ( 3 );
- }
- if ( ! access ( DOWN_FILE, F_OK ) )
- {
- puts ( "The system is already down, fool.\n" );
- exit ( 2 );
- }
- (void) printf ( "Bringing down the %s files.\n", file );
- { /* set up a 'lock' file */
- FILE *fp = fopen ( DOWN_FILE, "w" );
-
- if ( ! fp )
- {
- perror ( "Couldn't create lock file" );
- exit ( 2 );
- }
- (void) fprintf ( fp, "%s\n", &argv[1][2] );
- error ( fclose ( fp ), "Couldn't close lock file" );
- if ( chmod ( DOWN_FILE, 0666 ) == -1 )
- perror ( "Couldn't alter permissions" );
- }
- (void) printf ( "The %s files are down.\n", file );
- exit ( 0 );
- case '@':
- check_flag();
- if ( strcmp ( usercode(), SUPER_USER ) )
- catfile ( normal ); /* pretend the option doesn't exist */
- if ( access ( DOWN_FILE, F_OK ) )
- {
- puts ( "The system isn't down, fool.\n" );
- exit ( 2 );
- }
- inform_users();
- if ( unlink ( DOWN_FILE ) )
- perror ( "Couldn't remove the down file" );
- else
- (void) printf ( "Brought %s up again.\n", file );
- exit ( 0 );
- case 'c':
- do_edit ( cflag, &argv[1][2] );
- case 'e':
- check_flag();
- do_edit ( abort, "dummy" );
- case 'l':
- check_flag();
- catfile ( normal );
- case 'p':
- (void) printf ( "Sending %s to the printer.\n", file );
- (void) fflush ( stdout );
- if ( argv[1][2] )
- {
- argv[1][1] = 'P';
- execlp ( "lpr", "lpr", argv[1], text_file, (char *) 0 );
- }
- else
- execlp ( "lpr", "lpr", text_file, (char *) 0 );
- perror ( "Couldn't run lpr" );
- exit ( 2 );
- case 'r':
- check_flag();
- reserve();
- case 's':
- check_flag();
- exit ( lock ( CHECK ) != 0);
- case 't':
- check_flag();
- if ( lock ( CHECK ) )
- {
- lastedit ( EDIT );
- exit ( 1 );
- }
- else
- {
- (void) printf ( "The %s file is not being edited.\n", file );
- exit ( 0 );
- }
- case 'v':
- check_flag();
- (void) printf ( "APS %s version %d.\n", file, VERSION );
- exit ( 0 );
- case 'x':
- check_flag();
- do_edit ( normal, "dummy" );
- case 'z':
- check_flag();
- catfile ( raw );
- default:
- usage();
- }
- else
- if ( argv[1][1] == '\0' )
- catfile ( normal );
- else
- usage();
- }
- }
-