home *** CD-ROM | disk | FTP | other *** search
- /*
- * Display the welcome screen and find the Pcomm support files. Returns a
- * pointer to the STATUS structure. All errors are fatal.
- */
-
- #include <stdio.h>
- #include <curses.h>
- #include "config.h"
- #ifdef SHAREDMEM
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #endif /* SHAREDMEM */
- #include "misc.h"
- #include "status.h"
-
- struct STATUS *
- init(short_cut)
- char *short_cut;
- {
- char *mktemp(), *strcpy();
- struct STATUS *s_ptr;
- void info();
- #ifdef SHAREDMEM
- int i, j, mode;
- extern int shm_id;
- char *shmat();
- void exit();
-
- /*
- * Since the "pcomm_input" program does not run set-user/group-id
- * the mode must be set so the effective ID can read/write to the
- * shared memory segment. Kinda strange... real ID's aren't used.
- */
- #ifdef SETUGID
- mode = 0666;
- #else /* SETUGID */
- mode = 0600;
- #endif /* SETUGID */
- /* create a shared memory segment */
- shm_id = shmget(IPC_PRIVATE, sizeof (struct STATUS), mode|IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
- if (shm_id < 0) {
- endwin();
- perror("shmget");
- exit(1);
- }
- s_ptr = (struct STATUS *) shmat(shm_id, (char *) 0, 0);
- if ((int) s_ptr == -1) {
- endwin();
- perror("shmat");
- exit(1);
- }
- #else /* SHAREDMEM */
- static struct STATUS s;
- s_ptr = &s;
- #endif /* SHAREDMEM */
- /* some defaults */
- s_ptr->fd = -1;
- s_ptr->add_lf = 0;
- s_ptr->log = 0;
- s_ptr->print = 0;
- strcpy(s_ptr->log_path, "NOT_DEFINED");
- #ifdef SHAREDMEM
- s_ptr->clr = 0;
- s_ptr->row = 0;
- s_ptr->col = 0;
- for (i=0; i<LINES; i++) {
- for (j=0; j<COLS; j++)
- s_ptr->vs[i][j] = ' ';
- s_ptr->vs[i][COLS] = NULL;
- }
- #else /* SHAREDMEM */
- strcpy(s_ptr->vs_path, mktemp("/tmp/pcommXXXXXX"));
- #endif /* SHAREDMEM */
- /* display herald if no short-cut */
- if (short_cut == NULL)
- info(1);
-
- erase();
- refresh();
- return(s_ptr);
- }
-
- /*
- * Search the extra directory (supplied on the command line), then the
- * directory in the PCOMM environmental variable, then the current working
- * directory, and lastly, the default directory.
- */
-
- char *
- findfile(extra, name)
- char *extra, *name;
- {
- int i;
- char *pcomm, *getenv(), *path, pbuf[200], *getcwd(), *strdup();
- char temp[200];
-
- /* see if PCOMM variable is set */
- pcomm = getenv("PCOMM");
- if (pcomm == NULL || *pcomm == NULL)
- pcomm = NULL;
- else {
- /* zap the trailing separator */
- if (pcomm[strlen(pcomm)-1] == '/')
- pcomm[strlen(pcomm)-1] = NULL;
- }
-
- for (i=0; i<4; i++) {
- /* directory search order */
- switch (i) {
- case 0: /* extra directory from command line */
- path = extra;
- break;
- case 1: /* PCOMM environmental variable */
- path = pcomm;
- break;
- case 2: /* current working directory */
- path = getcwd(pbuf, 200);
- break;
- case 3: /* Pcomm's default directory */
- path = DEFAULT_DIR;
- break;
- }
- if (path == NULL)
- continue;
-
- sprintf(temp, "%s/%s", path, name);
- /* read permission checked */
- if (!access(temp, 4))
- return(strdup(temp));
- }
- return(NULL);
- }
-