home *** CD-ROM | disk | FTP | other *** search
- /*
- * Chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
- *
- * schar.c Interface with user for sorting
- */
-
- #include <stdio.h>
- #include <curses.h>
- #include "element.h"
- #include "variables.h"
- #include "windows.h"
- #include "tune.h"
-
- extern float closev[];
-
- /*
- * whichone() - no input
- *
- * purpose: to find out how many characteristics we are sorting already
- */
- whichone()
- {
- if (dosort[2].wch != 0)
- return(3);
- if (dosort[1].wch != 0)
- return(2);
- if (dosort[0].wch != 0)
- return(1);
- return(0);
- }
-
- /*
- * tablsort() - no input
- *
- * purpose: Put characteristics on table window
- */
- tablsort()
- {
- int i;
-
- for (i = 0; i < 3; i++) {
- if (dosort[i].wch != 0) {
- wmove(graph, i*4, 57);
- wstandout(graph);
- wprintw(graph, "%s", sopts[dosort[i].wch].chst);
- wstandend(graph);
- switch(dosort[i].sgn) {
- case EQUAL: mvwaddstr(graph, i*4+1, 58, "is Equal to"); break;
- case GREATER: wmove(graph, i*4+1, 58); wprintw(graph, "is %s", sopts[dosort[i].wch].upline); break;
- case CLOSE: mvwaddstr(graph, i*4+1, 58, "is Close to"); break;
- default: wmove(graph, i*4+1, 58); wprintw(graph, "is %s", sopts[dosort[i].wch].dnline); break;
- }
- wmove(graph, i*4+2, 59);
- wprintw(graph, "%4.*f", sopts[dosort[i].wch].dnum, dosort[i].amt);
- }
- }
- wrefresh(graph);
- }
-
- /*
- * upsort() - no input
- *
- * purpose: Update the sort window
- */
- upsort()
- {
- int i;
-
- wclear(srt);
- mvwaddstr(srt, 0, 0, "Current selecting characteristics: (max of 3)");
- for (i = 0; i < 3; i++) {
- if (dosort[i].wch != 0) {
- wmove(srt, i+2, 0);
- wstandout(srt);
- wprintw(srt, "%s", sopts[dosort[i].wch].chst);
- wstandend(srt);
- switch(dosort[i].sgn) {
- case EQUAL: wprintw(srt, " is Equal to "); break;
- case GREATER: wprintw(srt, " is %s ", sopts[dosort[i].wch].upline); break;
- case LESS: wprintw(srt, " is %s ", sopts[dosort[i].wch].dnline); break;
- case CLOSE: wprintw(srt, " is Close to "); break;
- }
- wprintw(srt, "%4.*f", sopts[dosort[i].wch].dnum, dosort[i].amt);
- }
- }
- wrefresh(srt);
- }
-
- /*
- * schar() - no input
- *
- * purpose: Interface with user to select sorting characteristics
- * to sort elements from
- */
- schar()
- {
- char str[50];
- int n, curn, i;
-
- noecho();
- crmode();
- lop1: clear(); refresh();
- for (;;) {
- lop2: upsort(); /* Update sorts */
- wclear(mn); wrefresh(mn);
- menu("Select Elemental Characteristics");
- for (i = 1; i < 8; i++) {
- wmove(mn, i+1, 0);
- wprintw(mn, "%d] %s", i, sopts[i].chst);
- wmove(mn, i+1, 40);
- wprintw(mn, "%d] %s", i+7, sopts[i+7].chst);
- }
- wmove(mn, 9, 40);
- wprintw(mn, "15] %s", sopts[15].chst);
- l17: mvwaddstr(mn, 11, 0, "Your Choice [14]? ");
- wclrtoeol(mn);
- cur = mn; xp = 18; yp = 11;
- mvwaddstr(mn, 11, 16, " ");
- wrefresh(mn);
- echo();
- nocrmode();
- gets(str);
- if (str[0] == '?') { help(17); goto l17; }
- if (!strlen(str)) n = 14; else n = atoi(str);
- fixup(mn);
- switch(n) {
- case 14: /* Main Menu */
- esort();
- wclear(mn);
- return(0);
- case 15: /* Clear all chars */
- mvwaddstr(mn, 12, 0, "Are you sure? ");
- wrefresh(mn);
- cur = mn; xp = 15; yp = 12;
- noecho();
- crmode();
- if (wgetch(mn) == 'y') {
- for (i = 0; i < 3; i++)
- dosort[i].wch = 0;
- }
- gtot = -1;
- wmove(mn, 12, 0); wclrtoeol(mn);
- wrefresh(mn);
- goto lop1;
- default:
- if (n < 1 || n > 15)
- goto lop2;
- else
- break;
- }
- curn = whichone();
- if (dosort[0].wch == n || dosort[1].wch == n || dosort[2].wch == n) {
- bot("This characteristic is already being sorted.");
- sleep(3);
- bot(" ");
- mvwaddstr(btm, 0, 0, "Do you wish to change this characteristic? ");
- wrefresh(btm);
- cur = btm; xp = 44; yp = 0;
- noecho(); crmode();
- if (getchar() == 'y') {
- bot(" ");
- for (i = 0; i < 2; i++) {
- if (dosort[i].wch == n)
- curn = i;
- }
- goto lop3;
- } else if (curn != 3) {
- mvwaddstr(btm, 0, 0, "Do you wish to make another characteristic of the same type? ");
- wrefresh(btm);
- cur = btm; xp = 62; yp = 0;
- noecho(); crmode();
- if (getchar() != 'y') {
- wclear(btm); wrefresh(btm);
- goto lop2;
- }
- wclear(btm); wrefresh(btm);
- }
- }
- if (curn > 2) {
- bot("Maximum of three sorting characteristics");
- sleep(3);
- bot(" ");
- goto lop2;
- }
- lop3: dosort[curn].wch = n;
- wclear(mn); wrefresh(mn);
- wmove(mn, 1, 0);
- wprintw(mn, "You would like to select some elements with their '%s' being", sopts[n].chst);
- mvwaddstr(mn, 3, 0, "1] Equal To");
- wmove(mn, 4, 0); wprintw(mn, "2] %s", sopts[n].upline);
- wmove(mn, 5, 0); wprintw(mn, "3] %s", sopts[n].dnline);
- wmove(mn, 6, 0);
- wprintw(mn, "4] Close To (+/- %1.*f)", sopts[n].dnum, closev[n]);
- wmove(mn, 7, 0); wprintw(mn, "5] Exit (will erase characteristic)");
- lop4: mvwaddstr(mn, 11, 0, "Your Choice? ");
- wrefresh(mn);
- cur = mn; xp = 14; yp = 11;
- noecho();
- crmode();
- switch(wgetch(mn)) {
- case '?': help(20); goto lop4;
- case '1': wprintw(mn, "Equal To"); dosort[curn].sgn = EQUAL; break;
- case '2': wprintw(mn, "Greater Than"); dosort[curn].sgn = GREATER; break;
- case '3': wprintw(mn, "Less Than"); dosort[curn].sgn = LESS; break;
- case '4': wprintw(mn, "Close To"); dosort[curn].sgn = CLOSE; break;
- case '5': dosort[curn].wch = 0;
- if (curn == 1) {
- if (dosort[2].wch != 0) {
- dosort[1].wch = dosort[2].wch;
- dosort[1].sgn = dosort[2].sgn;
- dosort[1].amt = dosort[2].amt;
- dosort[2].wch = 0;
- }
- } else if (curn == 0) {
- if (dosort[1].wch != 0) {
- dosort[0].wch = dosort[1].wch;
- dosort[0].sgn = dosort[1].sgn;
- dosort[0].amt = dosort[1].amt;
- dosort[1].wch = 0;
- }
- if (dosort[2].wch != 0) {
- dosort[1].wch = dosort[2].wch;
- dosort[1].sgn = dosort[2].sgn;
- dosort[1].amt = dosort[2].amt;
- dosort[2].wch = 0;
- }
- }
- goto lop1;
- default:
- goto lop4;
- }
- lop5: mvwaddstr(mn, 12, 0, "What Value? ");
- wclrtoeol(mn);
- wrefresh(mn);
- cur = mn; xp = 13; yp = 12;
- echo();
- nocrmode();
- scanf("%f", &dosort[curn].amt);
- if (dosort[curn].amt > 9999) {
- bot("Maximum amount is 9999.");
- sleep(2);
- bot(" ");
- goto lop5;
- }
- getchar(); /* Eat the \n that scanf doesn't */
- }
- }
-