File: grades.c

package info (click to toggle)
kdrill 6.5deb2-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,340 kB
  • sloc: ansic: 7,636; makefile: 47
file content (158 lines) | stat: -rw-r--r-- 3,741 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* "grades.c"
 *	has code for selecting grade levels,
 *	PLUS init for the showinorder stuffs
 */

#include <stdio.h>

#include <ctype.h>
#include <Intrinsic.h>
#include <StringDefs.h>
#include <Xaw/Command.h>
#include <Xaw/Label.h>
#include <Xaw/Form.h>
#include <stdint.h>
#include "defs.h"
#include "externs.h"
#include "game.h"
#include "grades.h"
#include "options.h"
#include "utils.h"

/* [0] is "all" button */
Widget gradeButtons[8];
int gradelevelflags;




/* printgrades:
 *	update grade widgets, cause the stupid things don't seem to want
 *	to start as they SHOULD start. Grrr...
 *	CANNOT CALL THIS from a grade button callback, due to
 *	BUG in Xaw.so.6
 */

void printgrades(){
	int buttonloop;
	for(buttonloop=1;buttonloop<8;buttonloop++){
		if(gradelevelflags & (1<<buttonloop)){
			SetWhiteOnBlack(gradeButtons[buttonloop]);
		} else {
			SetBlackOnWhite(gradeButtons[buttonloop]);
		}
	}
}

/* parsegrades:
 *  initialize gradelevelflags, according to ascii string
 *	(containing single word)
 *	If string has no acceptable grade levels, we will
 *	set to ALL grades.
 */
void parsegrades(char *gradestring){
	char *parse = gradestring;
	gradelevelflags = 0;

	while(*parse && (!isspace(*parse )) ){
	    switch(*parse){
		case '1': case '2':
		case '3': case '4':
		case '5': case '6':
			gradelevelflags |= (1 << (*parse -  '0') );
			break;
		case '+':
			gradelevelflags |= ABOVESIXGRADE;
			break;
	    }
	    parse++;
	}

	if(gradelevelflags == 0)
		gradelevelflags = ALLGRADES;
}


/* routine for GradeCallback.
 * This gets called whenever we CHANGE our grade selections.
 * We then update our preference database
 */
void calcgradestring() {
	char gradestring[10];
	gradestring[0]='\0';

	/* Yes, this is messed up. oh well, it works */
	if(gradelevelflags&0x02) strcat(gradestring,"1");
	if(gradelevelflags&0x04) strcat(gradestring,"2");
	if(gradelevelflags&0x08) strcat(gradestring,"3");
	if(gradelevelflags&0x10) strcat(gradestring,"4");
	if(gradelevelflags&0x20) strcat(gradestring,"5");
	if(gradelevelflags&0x40) strcat(gradestring,"6");
	if(gradelevelflags&0x80) strcat(gradestring,"+");

	SetXtrmString("gradelevel",gradestring);
}
/* GradeCalback:
 *	calback for different grade buttons
 */
void GradeCallback(Widget w,XtPointer data,XtPointer calldata){
	char statusbuff[100];
	char statusprefix[100];
	int grademask;
	int intdata = (int)(intptr_t) data;
	grademask = 1 << intdata;
	
	switch(intdata){
		case 1:	case 2:
		case 3:	case 4:
		case 5: case 6:
		case 7: /* + */
			/* already on? */
			if(gradelevelflags & grademask){
				gradelevelflags -= grademask;
				if(! gradelevelflags) {
					setstatus("Must have at least one grade level!");
					Beep();
					gradelevelflags |= grademask;
					return;
				} else {
					CountKanji();
					if(numberofkanji < HAVE_AT_LEAST ) {
						setstatus("Too few kanji");
						gradelevelflags |= grademask;
						Beep();
						CountKanji();
						return;
						
					}
					ReverseButton(w);
					if(intdata <=6)
						sprintf(statusprefix,"Grade %d unset: ",intdata);
					else
						sprintf(statusprefix,"Grade + unset: ");
				}
				/* CountKanji already called above */
                   	} else {
			/* nope.. turn on grade level */
				ReverseButton(w);
				gradelevelflags |= grademask;
					if(intdata <=6)
						sprintf(statusprefix,"Grade %d set: ",intdata);
					else
						sprintf(statusprefix,"Grade + set: ");
			}
			CountKanji();
			break;

		case 0:/* "All" button */
			gradelevelflags = ALLGRADES;
			printgrades();
			sprintf(statusprefix,"All grades selected: ");
			CountKanji();
			break;
	}
	sprintf(statusbuff,"%s%d kanji active",statusprefix,numberofkanji);
	calcgradestring();/* update preferences */
	setstatus(statusbuff);
}