home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part03 / init.c < prev   
Encoding:
C/C++ Source or Header  |  1988-05-17  |  3.5 KB  |  146 lines

  1. /*
  2.  * Display the welcome screen and find the pcomm files.  Returns a
  3.  * pointer to the STATUS structure.  All errors are fatal.
  4.  */
  5.  
  6. #define DEFAULT "/usr/local/lib/pcomm"
  7. #define VERSION "1.0"
  8.  
  9. #include <stdio.h>
  10. #include <curses.h>
  11. #include "misc.h"
  12. #include "status.h"
  13.  
  14. struct STATUS *
  15. init(extra, file)
  16. char *extra, *file;
  17. {
  18.     char *ans, *findfile(), *strdup(), *mktemp();
  19.     static struct STATUS s;
  20.     void s_error_win(), free_ptr();
  21.     extern char *null_ptr;
  22.                     /* find the support files */
  23.     if ((ans = findfile(extra, "pcomm.param")) == NULL)
  24.         s_error_win("Can't find pcomm.param file");
  25.     s.p_path = strdup(ans);
  26.  
  27.     if ((ans = findfile(extra, "pcomm.dial_dir")) == NULL)
  28.         s_error_win("Can't find pcomm.dial_dir file");
  29.     s.d_path = strdup(ans);
  30.  
  31.     if ((ans = findfile(extra, "pcomm.modem")) == NULL)
  32.         s_error_win("Can't find pcomm.modem file");
  33.     s.m_path = strdup(ans);
  34.                     /* some defaults */
  35.     s.lock_path = null_ptr;
  36.     s.vs_path = mktemp("/tmp/pcommXXXXXX");
  37.     s.log_path = strdup("NOT_DEFINED");
  38.     s.fd = -1;
  39.     s.log = 0;
  40.     s.print = 0;
  41.     s.msg = 0;
  42.     s.pid = -1;
  43.                     /* display herald if no short-cut */
  44.     if (file == NULL) {
  45.  
  46.         mvaddstr(2, 18, "PPPPPP    CCCC    OOOO    MM   MM   MM   MM");
  47.         mvaddstr(3, 18, "P    P   C       O    O   M M M M   M M M M");
  48.         mvaddstr(4, 18, "PPPPPP   C       O    O   M  M  M   M  M  M");
  49.         mvaddstr(5, 18, "P        C       O    O   M     M   M     M");
  50.         mvaddstr(6, 18, "P         CCCC    OOOO    M     M   M     M");
  51.  
  52.         mvprintw(10, 26, ">>> Pcomm Version %s <<<", VERSION);
  53.         mvaddstr(13, 14, "A public domain telecommunication program for Unix");
  54.         mvaddstr(14, 8, "designed to operate similar to the popular MSDOS program, ProComm.");
  55.         mvaddstr(15, 11, "ProComm (TM) is copyrighted by Datastorm Technologies, Inc.");
  56.         mvaddstr(19, 45, "Emmet P. Gray");
  57.         mvaddstr(20, 45, "...!ihnp4!uiucuxc!fthood!egray");
  58.         move(LINES-1, COLS-1);
  59.         refresh();
  60.                     /* Delay so you can read the herald */
  61.         wait_key(stdscr, 5);
  62.     }
  63.     erase();
  64.     refresh();
  65.     free_ptr(extra);
  66.     return(&s);
  67. }
  68.  
  69. /*
  70.  * Search the extra directory (supplied on the command line), then the
  71.  * directory in the PCOMM environmental variable, then the current directory,
  72.  * and lastly, the default directory.
  73.  */
  74.  
  75. char *
  76. findfile(extra, name)
  77. char *extra, *name;
  78. {
  79.     int i;
  80.     static char temp[200];
  81.     char *pcomm, *getenv(), *path, pbuf[200], *getcwd();
  82.     
  83.                     /* see if PCOMM variable is set */    
  84.     pcomm = getenv("PCOMM");
  85.     if (pcomm == NULL || *pcomm == NULL)
  86.         pcomm = NULL;
  87.     else {
  88.                     /* zap the trailing separator */
  89.         if (pcomm[strlen(pcomm)-1] == '/')
  90.             pcomm[strlen(pcomm)-1] = NULL;
  91.     }
  92.  
  93.     for (i=0; i<4; i++) {
  94.                     /* directory search order */
  95.         switch(i) {
  96.             case 0:
  97.                 path = extra;
  98.                 break;
  99.             case 1:
  100.                 path = pcomm;
  101.                 break;
  102.             case 2:
  103.                 path = getcwd(pbuf, 200);
  104.                 break;
  105.             case 3:
  106.                 path = DEFAULT;
  107.                 break;
  108.         }
  109.         sprintf(temp, "%s/%s", path, name);
  110.                     /* read permission checked */
  111.         if (!access(temp, 4))
  112.             return(temp);
  113.     }
  114.     return(NULL);
  115. }
  116.  
  117. /*
  118.  * Handle fatal errors, similar to error_win() but we can't rely on
  119.  * the status structure (since it hasn't been created yet!).
  120.  */
  121.  
  122. void
  123. s_error_win(str)
  124. char *str;
  125. {
  126.     WINDOW *se_win, *newwin();
  127.     void exit();
  128.  
  129.     se_win = newwin(7, 70, 9, 5);
  130.                     /* display the nasty note */
  131.     mvwaddstr(se_win, 2, 4, str);
  132.     mvwattrstr(se_win, 5, 24, A_BLINK, "Press any key to exit");
  133.     box(se_win, '|', '-');
  134.     beep();
  135.     wrefresh(se_win);
  136.  
  137.     wgetch(se_win);
  138.     delwin(se_win);
  139.                     /* erase the window we made */
  140.     touchwin(stdscr);
  141.     erase();
  142.     refresh();
  143.     endwin();
  144.     exit(1);
  145. }
  146.