home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1993-07-11 | 29.1 KB | 1,222 lines
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "menu.h" #include "resspr.h" #include "colourtran.h" #include "bbc.h" #include "event.h" #include "win.h" #include "dbox.h" #include "werr.h" #include "wimp.h" #include "res.h" #include "visdelay.h" #include "template.h" #include "wimpt.h" #include "os.h" #include "swis.h" #include "kernel.h" #include "msgs.h" #define CMOS_preferences "<CheckCMOS$Dir>.CMOS_Pref" #define Program_Settings "<CheckCMOS$Dir>.Settings" char Task_Name[10]; typedef int mask; mask prog_settings = 0x00; #define READATTR 5 #define FILEFOUND 1 #define UNUSED(X) (X=X) #define max(X,Y) (((X)>(Y))?(X):(Y)) #define min(X,Y) (((X)<(Y))?(X):(Y)) static wimp_w control_handle; /* window handle */ static wimp_w cmos_items_handle; /* window handle */ typedef char cmos_ram[240]; typedef struct { mask ignore; char name[100]; int start_byte; int start_bit; int end_byte; int end_bit; int old_value; int new_value; char *cmos_error; BOOL needs_reset; } cmos_item; BOOL file_exists ( char *filename ) { _kernel_osfile_block finfo; return (_kernel_osfile(READATTR, filename, &finfo) == FILEFOUND); } void read_line (FILE *index, char *item, int buffsize) { int i; char c; c = fgetc(index); for (i=0;(i<(buffsize-1)) && (c!=10) && !feof(index);i++) { item[i]=c; c = fgetc(index); } item[i]=0; } struct { char ignore_name[100]; } ignore_item[32]; void initialize_Ignore_masks (void) { int i; for (i=0;i<=31;i++) ignore_item[i].ignore_name[0]=0; } mask find_or_create_mask ( char *ignore_str ) { int i; if (strlen(ignore_str)==0) return 0; for (i=0;i<=31;i++) { if (strcmp(ignore_item[i].ignore_name,ignore_str)==0) return (1<<i); if (strlen(ignore_item[i].ignore_name)==0) { strcpy (ignore_item[i].ignore_name,ignore_str); return (1<<i); } } werr (TRUE ,msgs_lookup("ER6:Too many Ignore groups (max 32 unique groups)")); exit (0); return 0; } mask find_mask ( char *ignore_str ) { int i; if (strlen(ignore_str)==0) return 0; for (i=0;i<=31;i++) { if (strcmp(ignore_item[i].ignore_name,ignore_str)==0) return (1<<i); } return 0; } char *get_ignore_name ( int ignore_number ) { return (ignore_item[ignore_number].ignore_name); } #define max_cmos_items 200 cmos_item cmos_item_array[max_cmos_items]; cmos_ram current_cmos; cmos_ram preferred_cmos; void read_cmos (cmos_ram *current_cmos) { int i; int temp; for (i=0;i<=239;i++) { wimpt_noerr(os_byte(161,&i,&temp)); (*current_cmos)[i] = temp; } } void modify_cmos (cmos_ram old_cmos, cmos_ram new_cmos) { int i; int temp; visdelay_begin (); for (i=0;i<=239;i++) { if (new_cmos[i] != old_cmos[i]) { temp = new_cmos[i]; wimpt_noerr(os_byte(162,&i,&temp)); } visdelay_percent (100*i/240); } visdelay_end (); } void read_cmos_preferences (cmos_ram *preferred_cmos) { os_filestr f; f.action = 16; /* load file */ f.name = CMOS_preferences; f.loadaddr = (int)preferred_cmos; f.execaddr = 0; wimpt_noerr(os_file(&f)); } void save_cmos_preferences (cmos_ram preferred_cmos) { os_filestr f; f.action = 10; /* save file */ f.name = CMOS_preferences; f.loadaddr = 0xFF2; f.start = (int)preferred_cmos; f.end = (int)preferred_cmos+240; wimpt_noerr(os_file(&f)); } void read_prog_settings (mask *prog_settings) { if (file_exists (Program_Settings)) { FILE *fh; fh = fopen (Program_Settings,"r"); while (!feof(fh)) { char name[100]; read_line (fh,name,sizeof(name)); *prog_settings |= find_mask (name); } fclose (fh); } } void save_prog_settings (mask prog_settings) { FILE *fh; int i; fh=fopen(Program_Settings,"w"); for (i=0;i<=31;i++) if (prog_settings & (1<<i)) fprintf (fh,"%s\n",get_ignore_name(i)); fclose (fh); } cmos_ram cmos_bits; void initialize_cmos_bits ( void ) { int byte; for (byte=0;byte<=239;byte++) cmos_bits[byte] = 0x00; } void allocate_cmos_bit ( int byte, int bit ) { if (cmos_bits[byte] & (1<<bit)) { werr (TRUE ,msgs_lookup("ER2:CMOS Byte %d, Bit %d allocated twice"),byte,bit); exit (0); } cmos_bits[byte] |= (1<<bit); } void allocate_cmos_byte ( int byte ) { if (cmos_bits[byte]) { int bit; for (bit=0;bit<=7;bit++) if (cmos_bits[byte] & (1<<bit)) { werr (TRUE ,msgs_lookup("ER3:CMOS Byte %d allocated twice"),byte); exit (0); } } cmos_bits[byte] = 0xFF; } void allocate_cmos_bits ( int start_byte, int start_bit, int end_byte, int end_bit ) { int byte, bit; if (start_byte==end_byte) { if ((start_bit!=0) || (end_bit!=7)) { for (bit=start_bit;bit<=end_bit;bit++) allocate_cmos_bit (start_byte,bit); } else allocate_cmos_byte (start_byte); } else { if (start_bit!=0) for (bit=start_bit;bit<=7;bit++) allocate_cmos_bit (start_byte,bit); else allocate_cmos_byte (start_byte); for (byte=start_byte+1;byte<=end_byte-1;byte++) allocate_cmos_byte (byte); if (end_bit!=7) for (bit=0;bit<=end_bit;bit++) allocate_cmos_bit (end_byte,bit); else allocate_cmos_byte (end_byte); } } void check_cmos_allocations ( void ) { int byte, bit; for (byte=0;byte<=239;byte++) if (cmos_bits[byte]!=0xFF) for (bit=0;bit<=7;bit++) if ((cmos_bits[byte] & (1<<bit))==0) { werr (TRUE ,msgs_lookup("ER4:CMOS Byte %d, Bit %d not allocated"),byte,bit); exit (0); } } int cmos_item_insert_point = 0; void initialize_cmos_item ( char *ignore_str, char *item_name, int start_byte, int start_bit, int end_byte, int end_bit, BOOL needs_reset ) { mask ignore; allocate_cmos_bits (start_byte, start_bit, end_byte, end_bit); ignore = find_or_create_mask (ignore_str); if (cmos_item_insert_point==max_cmos_items) { werr (TRUE ,msgs_lookup("ER10:Program limitation - too many CMOS items described")); exit (0); } cmos_item_array[cmos_item_insert_point].ignore = ignore; strcpy (cmos_item_array[cmos_item_insert_point].name,item_name); cmos_item_array[cmos_item_insert_point].start_byte = start_byte; cmos_item_array[cmos_item_insert_point].start_bit = start_bit; cmos_item_array[cmos_item_insert_point].end_byte = end_byte; cmos_item_array[cmos_item_insert_point].end_bit = end_bit; cmos_item_array[cmos_item_insert_point].cmos_error = NULL; cmos_item_array[cmos_item_insert_point].needs_reset = needs_reset; cmos_item_insert_point++; strcpy(cmos_item_array[cmos_item_insert_point].name,""); } void get_token ( char **token, char **temp) { while (**temp==' ') *temp=*temp+1; *token = *temp; while ((**temp!=' ')&&(**temp!=0)) *temp=*temp+1; if (**temp==' ') { **temp=0; *temp=*temp+1; } while (**temp==' ') *temp=*temp+1; } BOOL convert_num ( char *s, int *num, int maxnum ) { int i; for (i=0;i<strlen(s);i++) if ((s[i]<'0')||(s[i]>'9')) return FALSE; *num = 0; for (i=0;i<strlen(s);i++) { *num = (*num)*10 + (s[i]-'0'); if (*num>maxnum) return FALSE; } return TRUE; } void uppercase ( char *s ) { int i; for (i=0;i<strlen(s);i++) if ((s[i]>='a')&&(s[i]<='z')) s[i] = s[i] - 'a' + 'A'; } void uppercase_word ( char *s ) { int i; for (i=0;(i<strlen(s)) && (s[i]!=':');i++) if ((s[i]>='a')&&(s[i]<='z')) s[i] = s[i] - 'a' + 'A'; } char *token_lookup (char *s) { static char temp[256]; char *msgptr; msgptr = msgs_lookup(s); strcpy(temp,msgptr); uppercase(temp); return temp; } void parse_location_line (char *line, int *start_byte, int *start_bit, int *end_byte, int *end_bit, BOOL *error) { char *temp = line; char *token; BOOL first_bit_specified = FALSE; uppercase(line); /* BYTE <num> [BIT <num>] [TO [BYTE <num>] [BIT <num>]] */ /* TO must be followed by a BYTE or BIT */ /* Anomily: BYTE 5 BIT 3 ... means only bit 3 */ *error=FALSE; get_token (&token,&temp); if (strcmp(token,token_lookup("LANG1:BYTE"))==0) { get_token (&token,&temp); if (!convert_num (token,start_byte,240)) { *error = TRUE; return; } get_token (&token,&temp); if (strcmp(token,token_lookup("LANG2:BIT"))==0) { get_token (&token,&temp); if (!convert_num (token,start_bit,7)) { *error = TRUE; return; } get_token (&token,&temp); first_bit_specified = TRUE; } else *start_bit = 0; if (strcmp(token,token_lookup("LANG3:TO"))==0) { get_token (&token,&temp); if (strcmp(token,token_lookup("LANG1:BYTE"))==0) { get_token (&token,&temp); if (!convert_num (token,end_byte,240)) { *error = TRUE; return; } get_token (&token,&temp); if (strcmp(token,token_lookup("LANG2:BIT"))==0) { get_token (&token,&temp); if (!convert_num (token,end_bit,7)) { *error = TRUE; return; } get_token (&token,&temp); } else *end_bit = 7; } else if (strcmp(token,token_lookup("LANG2:BIT"))==0) { *end_byte = *start_byte; get_token (&token,&temp); if (!convert_num (token,end_bit,7)) { *error = TRUE; return; } get_token (&token,&temp); } else { *error = TRUE; return; } } else { *end_byte = *start_byte; if (first_bit_specified) *end_bit = *start_bit; else *end_bit = 7; } if (strlen(token)!=0) *error = TRUE; } else *error = TRUE; } void trim_ends (char *line) { char *start = line; char *end; while (*start==' ') start++; memmove (line,start,strlen(start)+1); end = line+strlen(line)-1; while (*end==' ') *end-- = 0; } int os_version (void) { _kernel_swi_regs reg; reg.r[0] = 129; /* Read keyboard for information */ reg.r[1] = 0; /* Read the OS version identifier */ reg.r[2] = 0xFF; _kernel_swi (OS_Byte,®,®); return reg.r[1]; } void os_not_supported (void) { werr (TRUE ,msgs_lookup("ER9:Risc OS 2.00 to Risc OS 3.11 only supported")); exit (0); } void init_cmos_array (void) { FILE *fh; int LineNo = 0; char CMOS_Table[50]; switch (os_version()) { case 0xA0 : os_not_supported(); case 0xA1 : case 0xA2 : sprintf (CMOS_Table,"<CheckCMOS$Dir>.RISCOS2"); break; case 0xA3 : case 0xA4 : sprintf (CMOS_Table,"<CheckCMOS$Dir>.RISCOS3"); break; default : os_not_supported(); } initialize_cmos_bits(); initialize_Ignore_masks(); if (!file_exists (CMOS_Table)) { werr (TRUE ,msgs_lookup("ER7:CMOS Table could not be found (to create one see docs)")); exit (0); } fh = fopen (CMOS_Table,"r"); while (!feof(fh)) { typedef struct { char group[100]; char name[100]; int start_byte; int start_bit; int end_byte; int end_bit; BOOL needs_reset; } cmos_desc; char line[100]=""; cmos_desc new_item; BOOL error; *new_item.group=0; new_item.needs_reset=TRUE; while ((strlen(line)==0) && !feof(fh)) { read_line (fh,line,sizeof(line)); LineNo++; } if (!feof(fh)) { parse_location_line (line,&new_item.start_byte,&new_item.start_bit,&new_item.end_byte,&new_item.end_bit,&error); if (error) { werr (TRUE ,msgs_lookup("ER8:Parse Error in CMOS_Table, line %d"),LineNo); exit (0); } read_line (fh,new_item.name,sizeof(new_item.name)); LineNo++; read_line (fh,line,sizeof(line)); LineNo++; trim_ends (line); uppercase_word (line); while (strcmp(line,token_lookup("LANG7:End"))!=0) { if ((strlen(line)==0)&&feof(fh)) { werr (TRUE ,msgs_lookup("ER8:Parse Error in CMOS_Table, line %d"),LineNo); exit (0); } { if (strncmp(line,token_lookup("LANG4:Group"),strlen(token_lookup("LANG4:Group")))==0) { strcpy (new_item.group,line+strlen(token_lookup("LANG4:Group"))+1); trim_ends (new_item.group); } else if (strcmp(line,token_lookup("LANG6:Needs reset to take effect"))==0) new_item.needs_reset = TRUE; else if (strcmp(line,token_lookup("LANG5:Has instant effect"))==0) new_item.needs_reset = FALSE; else { werr (TRUE ,msgs_lookup("ER8:Parse Error in CMOS_Table, line %d"),LineNo); exit (0); } } read_line (fh,line,sizeof(line)); trim_ends (line); uppercase_word (line); LineNo++; } initialize_cmos_item (new_item.group,new_item.name,new_item.start_byte,new_item.start_bit,new_item.end_byte,new_item.end_bit,new_item.needs_reset); } } fclose (fh); check_cmos_allocations(); } void perform_cmos_check ( BOOL *cmos_changed ) { int i; *cmos_changed = FALSE; for (i=0;i<240;i++) if (current_cmos[i] != preferred_cmos[i]) *cmos_changed = TRUE; } void set_error_message ( int target_item, char *message ) { int item; if ( prog_settings & cmos_item_array[target_item].ignore ) return; for (item=0;strlen(cmos_item_array[item].name)!=0;item++) if (strcmp(cmos_item_array[item].cmos_error,message)==0) return; cmos_item_array[target_item].cmos_error = message; } void collate_changes_to_cmos (cmos_ram current_cmos, cmos_ram preferred_cmos, int *changes) { int item; for (item=0;strlen(cmos_item_array[item].name)!=0;item++) { int byte, bit; BOOL ok = TRUE; char mask; if (cmos_item_array[item].start_byte == cmos_item_array[item].end_byte) { mask = 0; for (bit=cmos_item_array[item].start_bit;bit<=cmos_item_array[item].end_bit;bit++) mask |= (1<<bit); if ((preferred_cmos[cmos_item_array[item].start_byte] & mask) != (current_cmos[cmos_item_array[item].start_byte] & mask)) ok = FALSE; } else { mask = 0; for (bit=cmos_item_array[item].start_bit;bit<=7;bit++) mask |= (1<<bit); if ((preferred_cmos[cmos_item_array[item].start_byte] & mask) != (current_cmos[cmos_item_array[item].start_byte] & mask)) ok = FALSE; for (byte=cmos_item_array[item].start_byte+1;byte<=cmos_item_array[item].end_byte-1;byte++) if (preferred_cmos[byte] != current_cmos[byte]) ok = FALSE; mask = 0; for (bit=0;bit<=cmos_item_array[item].end_bit;bit++) mask |= (1<<bit); if ((preferred_cmos[cmos_item_array[item].end_byte] & mask) != (current_cmos[cmos_item_array[item].end_byte] & mask)) ok = FALSE; } cmos_item_array[item].cmos_error = NULL; if (!ok) set_error_message (item,cmos_item_array[item].name); } /* count the changes */ *changes = 0; for (item=0;strlen(cmos_item_array[item].name)!=0;item++) if (cmos_item_array[item].cmos_error) *changes = *changes + 1; } void get_screen_size (int *x, int *y) { _kernel_swi_regs reg; int X, Y, XE, YE; reg.r[0] = -1; reg.r[1] = 11; _kernel_swi (OS_ReadModeVariable,®,®); X = reg.r[2] + 1; reg.r[0] = -1; reg.r[1] = 12; _kernel_swi (OS_ReadModeVariable,®,®); Y = reg.r[2] + 1; reg.r[0] = -1; reg.r[1] = 4; _kernel_swi (OS_ReadModeVariable,®,®); XE = 1<<reg.r[2]; reg.r[0] = -1; reg.r[1] = 5; _kernel_swi (OS_ReadModeVariable,®,®); YE = 1<<reg.r[2]; *x = X*XE; *y = Y*YE; } void redo_viewer(wimp_redrawstr r) { int item; int x, y; x = r.box.x0-r.scx+10; y = r.box.y1-r.scy-10; for (item=0;strlen(cmos_item_array[item].name)!=0;item++) if (cmos_item_array[item].cmos_error) { bbc_move (x, y); printf ("%s",cmos_item_array[item].cmos_error); y = y - 36; } } void redraw_viewer (wimp_openstr o) { wimp_redrawstr r; BOOL more; r.w = o.w; wimpt_noerr(wimp_redraw_wind(&r, &more)); while (more) { if (r.w==cmos_items_handle) redo_viewer(r); wimpt_noerr(wimp_get_rectangle(&r, &more)); } } void get_input_focus(void) { wimp_caretstr caret; caret.w = control_handle; caret.i = -1; caret.x = 0; caret.y = 0; caret.height = 1<<25; caret.index = -1; wimpt_complain(wimp_set_caret_pos(&caret)); } void recollate_changes_to_cmos ( void ) { wimp_wind *w; wimp_redrawstr r; int cmos_changes; collate_changes_to_cmos (current_cmos,preferred_cmos,&cmos_changes); w = template_syshandle("CMOS_Items"); r.w = cmos_items_handle; r.box.x0 = w->ex.x0; r.box.x1 = w->ex.x1; r.box.y0 = min(w->box.y0-w->box.y1+2,-(10+(cmos_changes*36))); r.box.y1 = 0; wimpt_complain (wimp_set_extent(&r)); { wimp_wstate s; wimpt_noerr(wimp_get_wind_state(cmos_items_handle, &s)); wimpt_noerr(wimp_open_wind(&s.o)); } wimpt_noerr(wimp_force_redraw(&r)); /* r.w = control_handle; dbox_setfield ((dbox)(r.w),3,"REBOOT"); wimpt_noerr(wimp_force_redraw(&r)); */ } /****************************** MENU **************************************/ menu CMOS_CHK_Menu; typedef enum { menu_INFO=1, menu_IGNORE, menu_SAVE } main_menu_choices; menu Ignore_Menu; void set_menu_flags () { int i; for (i=0;i<=31;i++) { if (strlen(get_ignore_name(i))!=0) menu_setflags (Ignore_Menu, i+1, (prog_settings & (1<<i)), FALSE); } } void MenuEventHandler (void *handle, char *hit) { UNUSED (handle); switch(hit[0]) { case menu_INFO: { dbox InfoDbox; if ((InfoDbox = dbox_new("ProgInfo")) != NULL) { dbox_setfield(InfoDbox,0,Task_Name); dbox_setfield(InfoDbox,1,msgs_lookup("DESC:CMOS Ram controller")); dbox_setfield(InfoDbox,2,"Paul Denize"); dbox_setfield(InfoDbox,3,msgs_lookup("VERS:Version Unknown")); dbox_show(InfoDbox); dbox_fillin(InfoDbox); dbox_dispose(&InfoDbox); } } break; case menu_IGNORE: { prog_settings ^= (1<<(hit[1]-1)); set_menu_flags (); recollate_changes_to_cmos (); } break; case menu_SAVE: save_prog_settings (prog_settings); break; } } typedef enum { Continue_Icon = 1, Save_Icon, Reset_Icon } cmos_control_window_icons; void main_buttonpress(wimp_mousestr *m) { switch (m->bbits & (wimp_BLEFT|wimp_BMID|wimp_BRIGHT)) { case wimp_BLEFT: switch (m->i) { case Continue_Icon: exit(0); break; case Save_Icon: save_cmos_preferences (current_cmos); exit(0); break; case Reset_Icon: { BOOL reset_required = FALSE; int item; os_error err; wimp_errflags errflags = (wimp_EOK + 16); char mess[100]; for (item=0;(strlen(cmos_item_array[item].name)!=0) && (!reset_required);item++) reset_required = ((cmos_item_array[item].cmos_error) && (cmos_item_array[item].needs_reset)); modify_cmos (current_cmos,preferred_cmos); err.errnum = 0; sprintf (mess,"%s %s",msgs_lookup("MESS:Message from"),Task_Name); if (reset_required) strcpy(err.errmess,msgs_lookup("MSG1:CMOS has been altered, Some settings may require a reset before they will take effect")); else strcpy(err.errmess,msgs_lookup("MSG2:CMOS has been altered, No reset required")); wimpt_noerr(wimp_reporterror (&err,errflags,mess)); exit(0); } break; } get_input_focus(); break; } } #define Escape_Key 0x1B #define Return_Key 0x0D void main_keypress ( int chcode ) { switch (chcode) { case Escape_Key: exit(0); break; case Return_Key: exit(0); break; } wimp_processkey (chcode); } void send_help_reply (wimp_msgstr* msg) { msg->hdr.your_ref = msg->hdr.my_ref; msg->hdr.action = wimp_MHELPREPLY; msg->hdr.size = 256; switch (msg->data.helprequest.m.i) { case 1: /* Continue icon */ sprintf(msg->data.helpreply.text, msgs_lookup("HE1:This is the CONTINUE button.|M\\Scontinue with system as it is.")); break; case 2: /* Save icon */ sprintf(msg->data.helpreply.text, msgs_lookup("HE2:This is the SAVE button.|M\\Ssave current settings as your preferred settings.")); break; case 3: /* Reset icon */ sprintf(msg->data.helpreply.text, msgs_lookup("HE3:This is the RESET button.|M\\Sreset the CMOS to the stored preferred settings.")); break; default: sprintf(msg->data.helpreply.text, msgs_lookup("HE4:This is the Check_CMOS alert window.|MCMOS items that are not set to the values you selected as preferred are indicated here.")); break; } wimpt_noerr(wimp_sendmessage(wimp_ESEND, msg, msg->hdr.task)); } void recentre_windows ( void ) { wimp_wstate s; wimpt_noerr(wimp_get_wind_state(control_handle, &s)); { int screenx, screeny; get_screen_size (&screenx, &screeny); { int middle1; int middle2; int dx; int dy; middle1 = screenx/2; middle2 = s.o.box.x0 + ((s.o.box.x1-s.o.box.x0)/2); dx = middle1 - middle2; middle1 = screeny/2; middle2 = s.o.box.y0 + ((s.o.box.y1-s.o.box.y0)/2); dy = middle1 - middle2; s.o.box.x0 += dx; s.o.box.x1 += dx; s.o.box.y0 += dy; s.o.box.y1 += dy; } } wimpt_noerr(wimp_open_wind(&s.o)); { wimp_wstate s2; wimpt_noerr(wimp_get_wind_state(cmos_items_handle, &s2)); { int middle1 = s.o.box.x0 + ((s.o.box.x1-s.o.box.x0)/2); int middle2 = s2.o.box.x0 + ((s2.o.box.x1-s2.o.box.x0)/2); int dx = middle1 - middle2 - 20; int dy = 116 - (s2.o.box.y0 - s.o.box.y0); s2.o.box.x0 += dx; s2.o.box.x1 += dx; s2.o.box.y0 += dy; s2.o.box.y1 += dy; } wimpt_noerr(wimp_open_wind(&s2.o)); } } void control_event_handler(wimp_eventstr *e, void *handle) /* event handler */ { handle = handle; switch (e->e) { case wimp_ENULL: event_setmask(event_getmask()|wimp_EMNULL); recentre_windows(); break; case wimp_EREDRAW: redraw_viewer(e->data.o); break; case wimp_EOPEN: { wimp_wstate s; if (e->data.o.w == control_handle) { wimpt_noerr(wimp_get_wind_state(cmos_items_handle, &s)); s.o.behind = e->data.o.behind; { int middle1 = e->data.o.box.x0 + ((e->data.o.box.x1-e->data.o.box.x0)/2); int middle2 = s.o.box.x0 + ((s.o.box.x1-s.o.box.x0)/2); int dx = middle1 - middle2 - 20; int dy = 116 - (s.o.box.y0 - e->data.o.box.y0); s.o.box.x0 += dx; s.o.box.x1 += dx; s.o.box.y0 += dy; s.o.box.y1 += dy; } wimpt_noerr(wimp_open_wind(&s.o)); e->data.o.behind = cmos_items_handle; } else { wimpt_noerr(wimp_get_wind_state(cmos_items_handle, &s)); e->data.o.box = s.o.box; /* not Movable */ e->data.o.behind = s.o.behind; /* non Orderable */ } } wimpt_noerr(wimp_open_wind(&e->data.o)); break; case wimp_ECLOSE: win_register_event_handler(control_handle, 0, 0); wimpt_noerr(wimp_delete_wind(control_handle)); win_activedec(); break; case wimp_EBUT: main_buttonpress(&e->data.but.m); break; case wimp_EKEY: main_keypress(e->data.key.chcode); break; case wimp_ESEND: case wimp_ESENDWANTACK: switch(e->data.msg.hdr.action) { case wimp_MMODECHANGE: event_setmask(event_getmask()&~wimp_EMNULL); break; case wimp_MHELPREQUEST: send_help_reply(&e->data.msg); break; } } } void get_task_name (char *name) { char obey_dir[256]; char *leaf; os_read_var_val("Obey$Dir",obey_dir,sizeof(obey_dir)); leaf = obey_dir; while (strchr(leaf,'.')!=0) { leaf = strchr(leaf,'.')+2; } strcpy(name,leaf); } void alert_user_of_changes (void) { int cmos_changes; init_cmos_array (); read_prog_settings (&prog_settings); collate_changes_to_cmos (current_cmos,preferred_cmos,&cmos_changes); if (cmos_changes) { wimp_wind *w; wimp_wstate s; get_task_name (Task_Name); wimpt_init(Task_Name); resspr_init(); template_init(); if ((w = template_syshandle("CMOS_Items")) == 0) werr (FALSE, msgs_lookup ("ER1:Template \"CMOS_Items\" not found")); w->ex.y0 = min(w->box.y0-w->box.y1+2,-(10+(cmos_changes*36))); w->ex.y1 = 0; wimpt_noerr(wimp_create_wind(w, &cmos_items_handle)); wimpt_noerr(wimp_get_wind_state(cmos_items_handle, &s)); s.o.behind = -1; wimpt_noerr(wimp_open_wind(&s.o)); if ((w = template_syshandle("Control")) == 0) werr (FALSE, msgs_lookup ("ER0:Template \"Control\" not found")); wimpt_noerr(wimp_create_wind(w, &control_handle)); wimpt_noerr(wimp_get_wind_state(control_handle, &s)); s.o.behind = cmos_items_handle; wimpt_noerr(wimp_open_wind(&s.o)); recentre_windows(); win_claim_unknown_events(cmos_items_handle); win_claim_unknown_events(control_handle); win_activeinc(); win_register_event_handler(control_handle, control_event_handler, 0); win_register_event_handler(cmos_items_handle, control_event_handler, 0); { char menustr[200]; sprintf (menustr,">%s,%s,%s", msgs_lookup("MENU0:Info"), msgs_lookup("MENU1:Ignore"), msgs_lookup("MENU2:Save Options")); CMOS_CHK_Menu = menu_new(Task_Name,menustr); } { char menustr[200] = ""; int i; for(i=0;i<=31;i++) { char *ignore_name; ignore_name = get_ignore_name(i); if (strlen(ignore_name)!=0) { strcat (menustr,","); strcat(menustr,ignore_name); } } Ignore_Menu = menu_new(msgs_lookup("MENU1:Ignore"),menustr); } menu_submenu (CMOS_CHK_Menu,menu_IGNORE,Ignore_Menu); set_menu_flags (); event_attachmenu(cmos_items_handle, CMOS_CHK_Menu, MenuEventHandler, NULL); event_attachmenu(control_handle, CMOS_CHK_Menu, MenuEventHandler, NULL); get_input_focus(); event_setmask(event_getmask()|wimp_EMPTRLEAVE |wimp_EMPTRENTER); while (TRUE) event_process(); } } int main () { BOOL cmos_changed; res_init("CheckCMOS"); msgs_init(); read_cmos (¤t_cmos); if (!file_exists(CMOS_preferences)) save_cmos_preferences (current_cmos); else { read_cmos_preferences (&preferred_cmos); perform_cmos_check(&cmos_changed); if (cmos_changed) alert_user_of_changes (); } return 0; }