home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
maint
/
part01
/
select.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-13
|
5KB
|
169 lines
/******************************************************************************
*******************************************************************************
Site: Western Michigan University Academic Computer Center
System: Directory/File System Maintenance
Program: maint
Version=01 Level=00 01/24/92 Leonard J. Peirce
Purpose: Allow a user to browse a file using a "pager" of some sort.
If the user has a PAGER environment variable, use it. The
default is DEFAULT_PAGER
Arguments: See individual routine(s)
External variables: See individual routine(s)
Maint external functions:
Defined: file_select
Called: none
Files accessed: filename file to be browsed
Return codes: See individual routine(s)
Compiling instructions: See Makefile
Linking instructions: See Makefile
Other information: (C) Copyright 1992, Leonard J. Peirce
********************************************************************************
*******************************************************************************/
/******************************************************************************/
/* */
/* # I N C L U D E F I L E S */
/* */
/******************************************************************************/
#include "maint.h"
#include <stdio.h>
#ifdef ultrix
#include <cursesX.h>
#include <unistd.h> /* recommended for access(2) */
#else
#include <curses.h>
#include <sys/file.h>
#endif
#include <string.h>
#if !defined(SYSV) || defined(sun)
#include <sys/wait.h>
#endif
#include <sys/stat.h>
/******************************************************************************/
/* */
/* # D E F I N E S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
extern char *getenv();
extern int access(),
wait(),
fork(),
execlp();
int file_select();
/******************************************************************************/
/* */
/* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
/* */
/******************************************************************************/
/*******************************************************************************
********************************************************************************
Function: file_select
Purpose: Process a file that has been selected. If the user has a
PAGER environment variable, use the pager specified. The
default pager is DEFAULT_PAGER.
Global variables:
Name Examine/Modify/Use/Read/Write
---- -----------------------------
none
Return Codes:
Code Reason
---- ------
SUCCESS
FAILURE
********************************************************************************
*******************************************************************************/
int file_select(filename)
/******* FORMAL PARAMETERS *******/
char *filename; /* name of file to be accessed */
{ /*** file_select ***/
/******** LOCAL VARIABLES ********/
char *pager, /* pager for looking at a file */
*tptr; /* pointer to last level of command */
int child, /* pid of child process */
i; /* loop and return value */
#if !defined(SYSV) || defined(sun)
union wait status; /* exit status for child process */
#else
int status;
#endif
/* see if the user has a PAGER */
pager = getenv("PAGER");
if(pager == NULL || *pager == '\0')
pager = DEFAULT_PAGER; /* user doesn't have a PAGER */
tptr = strrchr(pager,'/'); /* get last level to pass to execlp */
if(tptr == NULL)
tptr = pager;
else
tptr++;
if((child = vfork()) == 0)
{
/* we're in the child */
endwin();
execlp(pager,tptr,filename,NULL);
return(FAILURE); /* execlp failed if we get here */
}
else if(child > 0)
{
/* we're in the parent; wait for the child to finish */
while(((i = wait(&status)) != child) && i > 0)
;
}
else
return(FAILURE);
return(SUCCESS);
} /*** file_select ***/