home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / chemtab / part02 / scrmisc.c < prev    next >
C/C++ Source or Header  |  1991-03-12  |  5KB  |  234 lines

  1. /*
  2.  * chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
  3.  *
  4.  * scrmisc.c    Collection of curses screen misc stuff
  5.  */
  6.  
  7. #include <curses.h>
  8. #include "variables.h"
  9. #include "windows.h"
  10.  
  11. /* The SPACING define is for spacing the transcripts.  This spacing technique
  12.  * will USUALLY work for most print queues WITHOUT end-of-page form-feeding,
  13.  * meaning the print command doesn't care about upper and lower margins.  If
  14.  * so, a lower value may be needed. */
  15. #define    SPACING        4
  16.  
  17. menu(str)
  18. char    *str;
  19. {
  20.     wstandout(mn);
  21.     mvwaddstr(mn, 0, (40 - (strlen(str) / 2)), str);
  22.     wstandend(mn);
  23.     wrefresh(mn);
  24. }
  25.  
  26. /*
  27.  * bot(str)
  28.  *    input:    str - char - string to print on bottom
  29.  *    output: curses only
  30.  *
  31.  * purpose:    Take ''str'' and put it on ''btm'' (window)
  32.  */
  33. bot(strn)
  34. char    *strn;
  35. {
  36.     wclear(btm); mvwaddstr(btm, 0, 0, strn); wrefresh(btm);
  37. }
  38.  
  39. /*
  40.  * spc() - no input
  41.  *
  42.  * purpose:    To prompt the user that there is more..
  43.  */
  44. spc()
  45. {
  46.     wclear(btm); mvwaddstr(btm, 0, 0, "<< Press SPACE BAR to continue >>");
  47.     wrefresh(btm);
  48.     cur = btm; xp = 33; yp = 1;
  49.     noecho(); crmode();
  50.     getchar();
  51.     wclear(btm);
  52.     wrefresh(btm);
  53. }
  54.  
  55. int    needsit(win)
  56. WINDOW    *win;
  57. {
  58.     int    y, x;
  59.  
  60.     for (y = 0; y < win->_maxy; y++) {
  61.         for (x = 0; x < win->_maxx; x++)
  62.             if (mvwinch(win, y, x) != ' ')
  63.                 return(1);
  64.     }
  65.     return(0);
  66. }
  67.  
  68. void    help(num)
  69. int    num;
  70. {
  71.     FILE    *fp;
  72.     char    str[60];
  73.     int    line, i;
  74.  
  75.     hlp = newwin(16, 62, 4, 8);
  76.     wrefresh(hlp);
  77.  
  78.     if ((fp = fopen(HELPFILE, "r")) == NULL) {
  79.         mvwaddstr(hlp, 7, 1, "The HELPFILE is not available.");
  80.         mvwaddstr(hlp, 8, 1, "Contact a chemtab administrator.");
  81.         sleep(5);
  82.         delwin(hlp);
  83.         goto clean;
  84.     }
  85.  
  86.     line = 0;
  87.     for (;;) {
  88.         fgets(str, 60, fp);
  89.         if (str[0] == '_')
  90.             if (++line == num)
  91.                 break;
  92.     }
  93.  
  94.     for (i = 1; i < 15; i++) {
  95.         if (fgets(str, 60, fp) == NULL) break;
  96.         if (str[0] == '_') break;
  97.         mvwaddstr(hlp, i, 2, str);
  98.     }
  99.  
  100.     box(hlp, '|', '-');
  101. clean:    wstandout(hlp); mvwaddstr(hlp, 15, 15, "Press <<RETURN>> to continue...");
  102.     wrefresh(hlp);
  103.     wstandend(hlp);
  104.     cur = hlp; xp = 46; yp = 15;
  105.     noecho();
  106.     gets(str);
  107.     wclear(hlp); wrefresh(hlp);
  108.     delwin(hlp);
  109.     hlp = NULL;
  110.     if (needsit(stdscr)) { touchwin(stdscr); wrefresh(stdscr); }
  111.     if (needsit(graph)) { touchwin(graph); wrefresh(graph); }
  112.     if (needsit(mn)) { touchwin(mn); wrefresh(mn); }
  113.     if (needsit(srt)) { touchwin(srt); wrefresh(srt); }
  114.     if (needsit(btm)) { touchwin(btm); wrefresh(btm); }
  115. }
  116.  
  117. capture(win, f, z)
  118. WINDOW    *win;
  119. int    f, z;
  120. {
  121.     char    c;
  122.     int    i, j, icn = 0;            /* Internal count */
  123.     if (!trans)
  124.         return(1);
  125.  
  126.     for (;;) {
  127. l22:        wclear(btm); mvwaddstr(btm, 0, 0, "Would you like this on your transcript? ");
  128.         wrefresh(btm);
  129.         cur = btm; xp = 41; yp = 0;
  130.         noecho(); crmode();
  131.         c = wgetch(btm);
  132.         if (c == 'y') break;
  133.         if (c == '?') { help(22); goto l22; }
  134.         else if (c == 'n') return(1);
  135.     }
  136.             
  137.     if (!z) {
  138.         for (i = 0; i < SPACING; i++) {
  139.             fputc('\n', fp);
  140.             icn++;
  141.         }
  142.     } else {
  143.         for (i = 0; i < SPACING-2; i++) {
  144.             fputc('\n', fp);
  145.             icn++;
  146.         }
  147.         fprintf(fp, "Your selection characteristics are listed on the next line.\n");
  148.         icn++;
  149.         for (i = 0; i < 3; i++) {
  150.             if (dosort[i].wch != 0) {
  151.                 icn++;
  152.                 fprintf(fp, "%s ", sopts[dosort[i].wch].chst);
  153.                 switch(dosort[i].sgn) {
  154.                     case EQUAL: fprintf(fp, "= "); break;
  155.                     case GREATER: fprintf(fp, "> "); break;
  156.                     case CLOSE: fprintf(fp, "~ "); break;
  157.                     default: fprintf(fp, "< ");
  158.                 }
  159.                 fprintf(fp, "%4.*f  ", sopts[dosort[i].wch].dnum, dosort[i].amt);
  160.             }
  161.         }
  162.     }
  163.     fputc('\n', fp);
  164.     for (i = 0; i < 23; i++) {
  165.         if (!f)
  166.             fprintf(fp, "      ");
  167.         for (j = 0; j < 80; j++) {
  168.             wmove(graph, i, j);
  169.             fputc(winch(graph), fp);
  170.         }
  171.         fputc('\n', fp);
  172.     }
  173.     for (i = 0; i < SPACING-2; i++)
  174.         fputc('\n', fp);
  175.  
  176.     fflush(fp);
  177.     return(1);
  178. }
  179.  
  180. version()
  181. {
  182.     clear(); refresh();
  183.  
  184.     standout();
  185.     mvaddstr(0, 34, "Chemtab V2.01");
  186.     standend();
  187.     mvaddstr(2, 0, "Element data (text): ");
  188.     printw("%s", PERTABLE);
  189.     mvaddstr(3, 0, "Element table (binary): ");
  190.     printw("%s", BINTABLE);
  191.     mvaddstr(4, 0, "Periodic table (text): ");
  192.     printw("%s", TABLE);
  193.     mvaddstr(5, 0, "Periodic table (graphic): ");
  194.     printw("%s_graphic", TABLE);
  195.     mvaddstr(6, 0, "Online help file (text): ");
  196.     printw("%s", HELPFILE);
  197.     mvaddstr(7, 0, "Close value file (text): ");
  198.     printw("%s", CLOSEFILE);
  199.     standout();
  200.     mvaddstr(9, 0, "The above files must be properly defined for the program to run");
  201.     mvaddstr(10, 0, "The files below are optional definitions");
  202.     standend();
  203. #ifdef    USERSHELL
  204.     mvaddstr(12, 0, "Job stopping is enabled.");
  205. #else
  206.     mvaddstr(12, 0, "Job stopping is disabled.");
  207. #endif    USERSHELL
  208.  
  209. #ifdef    PRINTER
  210.     mvaddstr(13, 0, "Printing is enabled through the ");
  211.     printw("%s ", PRINTER);
  212.     printw("command.");
  213. #else
  214.     mvaddstr(13, 0, "Printing is disabled.");
  215. #endif    PRINTER
  216.  
  217. #ifdef    TRANSCRIPT
  218.     mvaddstr(14, 0, "User logs are kept in ");
  219.     printw("%s.", TRANSCRIPT);
  220. #else
  221.     mvaddstr(14, 0, "User logs are disabled.");
  222. #endif    TRANSCRIPT
  223.  
  224. #ifdef    ReGIS
  225.     mvaddstr(15, 0, "ReGIS graphics module is installed.");
  226. #else
  227.     mvaddstr(15, 0, "ReGIS graphics module is not installed.");
  228. #endif    ReGIS
  229.  
  230.     refresh();
  231.     spc();
  232.     clear(); refresh();
  233. }
  234.