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

  1. /*
  2.  * chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
  3.  *
  4.  * ptabl.c    Print the Periodic Table with sorted elements in place
  5.  */
  6.  
  7. #include <curses.h>
  8. #include "windows.h"
  9. #include <stdio.h>
  10. #include "variables.h"
  11. #include "tune.h"
  12. #include "element.h"
  13. #include <signal.h>
  14.  
  15. extern int    stop();
  16.  
  17. /* helps to print out where the elements go */
  18. int    horz[10] = { 0, 2, 4, 6, 8, 10, 12, 14, 18, 20 };
  19.  
  20. /*
  21.  * ptabl() - no input
  22.  *
  23.  * purpose:    To print the periodic table then fill in spaces with
  24.  *        appropriate ''selected'' elements.
  25.  */
  26. ptabl()
  27. {
  28.     struct    elem    *tmp;
  29.     FILE    *fd;        /* Periodic table is in a file */
  30.     char    foo[80];    /* And we need to read it into something */
  31.     int    z, i, n, ics;    /* element number reference */
  32.  
  33.     if (gtot == -1) {
  34.         mvwaddstr(mn, 15, 0, "Please choose some selection characteristics before you do this.");
  35.         wrefresh(mn);
  36.         sleep(2);
  37.         wmove(mn, 15, 0); wclrtoeol(mn);
  38.         return(0);
  39.     }
  40.  
  41.     strcpy(foo, TABLE);
  42.  
  43.     wclear(mn); wrefresh(mn);
  44.     clear(); refresh();
  45. l16:    mvwaddstr(btm, 0, 0, "VT100 alternate graphic set (if yes, no transcript of this table) ");
  46.     wrefresh(btm);
  47.     cur = btm; xp = 65; yp = 0;
  48.     noecho(); crmode();
  49.     switch(getchar()) {
  50.         case '?': help(16); goto l16;
  51.         case 'y':
  52.         case 'Y':
  53. #ifdef    USERSHELL
  54.             signal(SIGTSTP, SIG_IGN);
  55. #endif    USERSHELL
  56.             strcat(foo, "_graphic"); ics = 1; break;
  57.         default: ics = 0; break;
  58.     }
  59.     if ((fd = fopen(foo, "r")) == NULL) {
  60.         bot("Cannot open periodic table.. sorry..");
  61.         sleep(3);
  62.         return(0);
  63.     }
  64.     if (ics) printf("\033(0");    /* on graphics */
  65.     for (i = 0; i < 22; i++) {    /* read in the table */
  66.         fgets(foo, 80, fd);
  67.         mvwaddstr(graph, i, 0, foo);
  68.         wrefresh(graph);
  69.     }                /* and output to WINDOW *graph */
  70.     fclose(fd);
  71.     if (ics) printf("\033(B");
  72.     tablsort();            /* Put characteristics on screen */
  73.     if (ics) printf("\033(0"); fflush(stdout);
  74.     for (i = 1; i < gtot+1; i++) {    /* format and print element sym. */
  75.         n = sub1[i];
  76.         for (tmp = e; n != tmp->anum; tmp = tmp->next) ;
  77.         if (tmp->anum > 56 && tmp->anum < 72)
  78.             wmove(graph, horz[8], (13 + ((tmp->fam - 1) * 3)));
  79.         else if (tmp->anum > 88 && tmp->anum < 104)
  80.             wmove(graph, horz[9], (13 + ((tmp->fam - 1) * 3)));
  81.         else if (tmp->anum > 103 && tmp->anum < 111)
  82.             wmove(graph, horz[tmp->row], (1 + ((tmp->fam - 1) * 3) - (104 - tmp->anum)));
  83.         else
  84.             wmove(graph, horz[tmp->row], (1 + ((tmp->fam - 1) * 3)));
  85.  
  86.         wrefresh(graph);
  87.         wstandout(graph);
  88.         if (ics) {        /* I realize the slowness... */
  89.             printf("\033(B"); fflush(stdout);
  90.             wprintw(graph, "%2s", tmp->sym);
  91.             wrefresh(graph);
  92.             printf("\033(0"); fflush(stdout);
  93.         } else
  94.             wprintw(graph, "%2s", tmp->sym);
  95.         wrefresh(graph);
  96.         wstandend(graph);
  97.     }
  98.     if (ics) printf("\033(B");
  99.     wrefresh(graph);
  100.     if (!ics) capture(graph, 0, 0);
  101.     spc();
  102.     wclear(graph); wrefresh(graph);
  103.     clear();
  104.     refresh();
  105. #ifdef    USERSHELL
  106.     signal(SIGTSTP, stop);
  107. #endif    USERSHELL
  108.     return(0);
  109. }
  110.