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

  1. /*
  2.  * Chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
  3.  *
  4.  * schar.c    Interface with user for sorting
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "element.h"
  10. #include "variables.h"
  11. #include "windows.h"
  12. #include "tune.h"
  13.  
  14. extern float closev[];
  15.  
  16. /*
  17.  * whichone() - no input
  18.  *
  19.  * purpose:    to find out how many characteristics we are sorting already
  20.  */
  21. whichone()
  22. {
  23.     if (dosort[2].wch != 0)
  24.         return(3);
  25.     if (dosort[1].wch != 0)
  26.         return(2);
  27.     if (dosort[0].wch != 0)
  28.         return(1);
  29.     return(0);
  30. }
  31.  
  32. /*
  33.  * tablsort() - no input
  34.  *
  35.  * purpose:    Put characteristics on table window
  36.  */
  37. tablsort()
  38. {
  39.     int    i;
  40.     
  41.     for (i = 0; i < 3; i++) {
  42.         if (dosort[i].wch != 0) {
  43.             wmove(graph, i*4, 57);
  44.             wstandout(graph);
  45.             wprintw(graph, "%s", sopts[dosort[i].wch].chst);
  46.             wstandend(graph);
  47.             switch(dosort[i].sgn) {
  48.                 case EQUAL: mvwaddstr(graph, i*4+1, 58, "is Equal to"); break;
  49.                 case GREATER: wmove(graph, i*4+1, 58); wprintw(graph, "is %s", sopts[dosort[i].wch].upline); break;
  50.                 case CLOSE: mvwaddstr(graph, i*4+1, 58, "is Close to"); break;
  51.                 default: wmove(graph, i*4+1, 58); wprintw(graph, "is %s", sopts[dosort[i].wch].dnline); break;
  52.             }
  53.             wmove(graph, i*4+2, 59);
  54.             wprintw(graph, "%4.*f", sopts[dosort[i].wch].dnum, dosort[i].amt);
  55.         }
  56.     }
  57.     wrefresh(graph);
  58. }
  59.  
  60. /*
  61.  * upsort() - no input
  62.  *
  63.  * purpose:    Update the sort window
  64.  */
  65. upsort()
  66. {
  67.     int    i;
  68.  
  69.     wclear(srt);
  70.     mvwaddstr(srt, 0, 0, "Current selecting characteristics: (max of 3)");
  71.     for (i = 0; i < 3; i++) {
  72.         if (dosort[i].wch != 0) {
  73.             wmove(srt, i+2, 0);
  74.             wstandout(srt);
  75.             wprintw(srt, "%s", sopts[dosort[i].wch].chst);
  76.             wstandend(srt);
  77.             switch(dosort[i].sgn) {
  78.                 case EQUAL: wprintw(srt, " is Equal to "); break;
  79.                 case GREATER: wprintw(srt, " is %s ", sopts[dosort[i].wch].upline); break;
  80.                 case LESS: wprintw(srt, " is %s ", sopts[dosort[i].wch].dnline); break;
  81.                 case CLOSE: wprintw(srt, " is Close to "); break;
  82.             }
  83.             wprintw(srt, "%4.*f", sopts[dosort[i].wch].dnum, dosort[i].amt);
  84.         }
  85.     }
  86.     wrefresh(srt);
  87. }
  88.  
  89. /*
  90.  * schar() - no input
  91.  *
  92.  * purpose:    Interface with user to select sorting characteristics
  93.  *        to sort elements from
  94.  */
  95. schar()
  96. {
  97.     char    str[50];
  98.     int    n, curn, i;
  99.  
  100.     noecho();
  101.     crmode();
  102. lop1:    clear(); refresh();
  103.     for (;;) {
  104. lop2:        upsort();                /* Update sorts */
  105.         wclear(mn); wrefresh(mn);
  106.         menu("Select Elemental Characteristics");
  107.         for (i = 1; i < 8; i++) {
  108.             wmove(mn, i+1, 0);
  109.             wprintw(mn, "%d] %s", i, sopts[i].chst);
  110.             wmove(mn, i+1, 40);
  111.             wprintw(mn, "%d] %s", i+7, sopts[i+7].chst);
  112.         }
  113.         wmove(mn, 9, 40);
  114.         wprintw(mn, "15] %s", sopts[15].chst);
  115. l17:        mvwaddstr(mn, 11, 0, "Your Choice [14]? ");
  116.         wclrtoeol(mn);
  117.         cur = mn; xp = 18; yp = 11;
  118.         mvwaddstr(mn, 11, 16, " ");
  119.         wrefresh(mn);
  120.         echo();
  121.         nocrmode();
  122.         gets(str);
  123.         if (str[0] == '?') { help(17); goto l17; }
  124.         if (!strlen(str)) n = 14; else n = atoi(str);
  125.         fixup(mn);
  126.         switch(n) {
  127.             case 14:        /* Main Menu */
  128.                 esort();
  129.                 wclear(mn);
  130.                 return(0);
  131.             case 15:        /* Clear all chars */
  132.                 mvwaddstr(mn, 12, 0, "Are you sure? ");
  133.                 wrefresh(mn);
  134.                 cur = mn; xp = 15; yp = 12;
  135.                 noecho();
  136.                 crmode();
  137.                 if (wgetch(mn) == 'y') {
  138.                     for (i = 0; i < 3; i++)
  139.                         dosort[i].wch = 0;
  140.                 }
  141.                 gtot = -1;
  142.                 wmove(mn, 12, 0); wclrtoeol(mn);
  143.                 wrefresh(mn);
  144.                 goto lop1;
  145.             default:
  146.                 if (n < 1 || n > 15)
  147.                     goto lop2;
  148.                 else
  149.                     break;
  150.         }
  151.         curn = whichone();
  152.         if (dosort[0].wch == n || dosort[1].wch == n || dosort[2].wch == n) {
  153.             bot("This characteristic is already being sorted.");
  154.             sleep(3);
  155.             bot(" ");
  156.             mvwaddstr(btm, 0, 0, "Do you wish to change this characteristic? ");
  157.             wrefresh(btm);
  158.             cur = btm; xp = 44; yp = 0;
  159.             noecho(); crmode();
  160.             if (getchar() == 'y') {
  161.                 bot(" ");
  162.                 for (i = 0; i < 2; i++) {
  163.                     if (dosort[i].wch == n)
  164.                         curn = i;
  165.                 }
  166.                 goto lop3;
  167.             } else if (curn != 3) {
  168.                 mvwaddstr(btm, 0, 0, "Do you wish to make another characteristic of the same type? ");
  169.                 wrefresh(btm);
  170.                 cur = btm; xp = 62; yp = 0;
  171.                 noecho(); crmode();
  172.                 if (getchar() != 'y') {
  173.                     wclear(btm); wrefresh(btm);
  174.                     goto lop2;
  175.                 }
  176.                 wclear(btm); wrefresh(btm);
  177.             }
  178.         }
  179.         if (curn > 2) {
  180.             bot("Maximum of three sorting characteristics");
  181.             sleep(3);
  182.             bot(" ");
  183.             goto lop2;
  184.         }
  185. lop3:        dosort[curn].wch = n;
  186.         wclear(mn); wrefresh(mn);
  187.         wmove(mn, 1, 0);
  188.         wprintw(mn, "You would like to select some elements with their '%s' being", sopts[n].chst);
  189.         mvwaddstr(mn, 3, 0, "1] Equal To");
  190.         wmove(mn, 4, 0); wprintw(mn, "2] %s", sopts[n].upline);
  191.         wmove(mn, 5, 0); wprintw(mn, "3] %s", sopts[n].dnline);
  192.         wmove(mn, 6, 0);
  193.         wprintw(mn, "4] Close To (+/- %1.*f)", sopts[n].dnum, closev[n]);
  194.         wmove(mn, 7, 0); wprintw(mn, "5] Exit (will erase characteristic)");
  195. lop4:        mvwaddstr(mn, 11, 0, "Your Choice? ");
  196.         wrefresh(mn);
  197.         cur = mn; xp = 14; yp = 11;
  198.         noecho();
  199.         crmode();
  200.         switch(wgetch(mn)) {
  201.             case '?': help(20); goto lop4;
  202.             case '1': wprintw(mn, "Equal To"); dosort[curn].sgn = EQUAL;    break;
  203.             case '2': wprintw(mn, "Greater Than"); dosort[curn].sgn = GREATER;    break;
  204.             case '3': wprintw(mn, "Less Than"); dosort[curn].sgn = LESS;    break;
  205.             case '4': wprintw(mn, "Close To"); dosort[curn].sgn = CLOSE;    break;
  206.             case '5': dosort[curn].wch = 0;
  207.                   if (curn == 1) {
  208.                     if (dosort[2].wch != 0) {
  209.                         dosort[1].wch = dosort[2].wch;
  210.                         dosort[1].sgn = dosort[2].sgn;
  211.                         dosort[1].amt = dosort[2].amt;
  212.                         dosort[2].wch = 0;
  213.                     }
  214.                   } else if (curn == 0) {
  215.                     if (dosort[1].wch != 0) {
  216.                         dosort[0].wch = dosort[1].wch;
  217.                         dosort[0].sgn = dosort[1].sgn;
  218.                         dosort[0].amt = dosort[1].amt;
  219.                         dosort[1].wch = 0;
  220.                     }
  221.                     if (dosort[2].wch != 0) {
  222.                         dosort[1].wch = dosort[2].wch;
  223.                         dosort[1].sgn = dosort[2].sgn;
  224.                         dosort[1].amt = dosort[2].amt;
  225.                         dosort[2].wch = 0;
  226.                     }
  227.                   }
  228.                 goto lop1;
  229.             default:
  230.                 goto lop4;
  231.         }
  232. lop5:        mvwaddstr(mn, 12, 0, "What Value? ");
  233.         wclrtoeol(mn);
  234.         wrefresh(mn);
  235.         cur = mn; xp = 13; yp = 12;
  236.         echo();
  237.         nocrmode();
  238.         scanf("%f", &dosort[curn].amt);
  239.         if (dosort[curn].amt > 9999) {
  240.             bot("Maximum amount is 9999.");
  241.             sleep(2);
  242.             bot(" ");
  243.             goto lop5;
  244.         }
  245.         getchar();        /* Eat the \n that scanf doesn't */
  246.     }
  247. }
  248.