void edit_at(int row, int col, int max_length, int screen_length, char *string_to_edit, char filler, int fixed, int (*check_func)( char ), int convert_upper) { #define BLINK 2 #define NOBLINK 3 char *edit_string; int blink,logical_cursor, cursor, last_char, insert; int first_char_on_screen; int finished; long key; int upper,lower; char asc; int loop,loop2/*,delete_loop*/; char *blank=(char *)malloc(screen_length+1); edit_bottom_title(); for(loop=0;loop<=screen_length;loop++) blank[loop]=' '; blank[loop]='\0'; /* set up the string - create space, copy old, pad out new with filler */ edit_string=(char *)malloc(max_length+1); strcpy(edit_string,string_to_edit); logical_cursor=0; while(edit_string[logical_cursor]!='\0') logical_cursor++; last_char=logical_cursor; /* for(;logical_cursor<max_length;logical_cursor++) edit_string[logical_cursor]=filler; */ edit_string[logical_cursor]='\0'; cursor=0; logical_cursor=0; first_char_on_screen=0; insert=1; if(insert==1) { blink=BLINK; Cursconf(blink,0); } else { blink=NOBLINK; Cursconf(blink,0); } /* print string */ print_at_from(row,col,first_char_on_screen,screen_length,edit_string); SHOW_CURSOR AT(row,col) finished=0; while(!finished) { /* AT(0,0) printf(" %d ",last_char); */ while(!Bconstat(2)) ; key=Bconin(2); upper=(int)(key>>16); lower=(int)(key%256); asc=(char)lower&0x00FF; switch(upper) { case 0x4D: /* right arrow */ if(logical_cursor<last_char/*max_length*/) { logical_cursor++; if(cursor<screen_length) { cursor++; } else { cursor=screen_length; if(first_char_on_screen+screen_length<last_char /*max_length*/ && !fixed) { first_char_on_screen++; print_at_from(row,col,first_char_on_screen,screen_length,edit_string); } } } else { BELL logical_cursor=last_char/*max_length*/; } break; case 0x4B: /* left arrow */ if(logical_cursor>0) { logical_cursor--; } else { BELL logical_cursor=0; } if(cursor>0) { cursor--; } else { cursor=0; if(first_char_on_screen>0 && !fixed) { first_char_on_screen--; print_at_from(row,col,first_char_on_screen,screen_length,edit_string); } } /* logical_cursor--; cursor--; if(logical_cursor<0) { BELL logical_cursor=0; cursor=0; } else if(cursor<0) { cursor=0; if(first_char_on_screen>0 && !fixed) { first_char_on_screen--; print_at_from(row,col,first_char_on_screen,screen_length,edit_string); } }*/ break; case 0x1C: /* return */ finished=1; /* print_at_from(row,col,0,screen_length,blank); */ AT(row,col) printf("%s",blank+1); /* printf("%s",blank);*/ AT(row,col) strcpy(string_to_edit,edit_string); print_at_from(row,col,0,screen_length,string_to_edit); break; case 0x0E: /* backspace */ if(logical_cursor>0) { loop=logical_cursor-1; loop2=logical_cursor; while(loop2<=last_char) { edit_string[loop]=edit_string[loop2]; loop++; loop2++; } edit_string[last_char]='\0'; last_char--; logical_cursor--; if(cursor>0 && last_char<screen_length) { cursor--; } else { if(cursor==0) { first_char_on_screen--; if(first_char_on_screen<0) first_char_on_screen=0; } else { cursor--; } } if(first_char_on_screen+screen_length>last_char) { /* for(delete_loop=0;cursor+delete_loop<screen_length;delete_loop++) { AT(row,delete_loop+col) Bconout(2,' '); }*/ AT(row,col+cursor) printf("%s",blank+cursor+1); } } else BELL break; case 0x53: /* delete */ if(logical_cursor<last_char) { loop=logical_cursor; loop2=logical_cursor+1; while(loop2<=last_char) { edit_string[loop]=edit_string[loop2]; loop++; loop2++; } edit_string[last_char]='\0'; last_char--; if(first_char_on_screen+screen_length>last_char) { /* for(delete_loop=0;cursor+delete_loop<=screen_length;delete_loop++) { AT(row,delete_loop+col) Bconout(2,' '); } */ AT(row,col+cursor) printf("%s",blank+cursor+1); } } else BELL break; case 0x01: /* escape */ finished=1; /* print_at_from(row,col,0,screen_length,blank); *//* AT(row,col) CLEAR_EOL */ AT(row,col) printf("%s",blank+1); /* printf("%s",blank); */ AT(row,col) print_at_from(row,col,0,screen_length,string_to_edit); break; case 0x52: /* insert */ BELL if(insert==1) insert=0; else insert=1; if(insert==1) { blink=BLINK; Cursconf(blink,0); } else { blink=NOBLINK; Cursconf(blink,0); } break; default: if((*check_func)(asc)) { if(insert==1) { if(last_char<max_length) { loop=last_char-1; loop2=last_char; while(loop2>logical_cursor) { edit_string[loop2]=edit_string[loop]; loop--; loop2--; } last_char++; edit_string[last_char]='\0'; if(convert_upper) edit_string[logical_cursor]=toupper(asc); else edit_string[logical_cursor]=asc; logical_cursor++; cursor++; if(cursor>screen_length) { cursor=screen_length; if(first_char_on_screen+screen_length<last_char) first_char_on_screen++; } } else BELL } else { if(logical_cursor<last_char) { if(convert_upper) edit_string[logical_cursor]=toupper(asc); else edit_string[logical_cursor]=asc; logical_cursor++; cursor++; if(cursor>screen_length) { first_char_on_screen++; cursor=screen_length; } } else { if(logical_cursor>=last_char && last_char<max_length) { if(convert_upper) edit_string[last_char]=toupper(asc); else edit_string[last_char]=asc; logical_cursor=last_char; last_char++; logical_cursor++; if(logical_cursor>max_length) logical_cursor=max_length; edit_string[last_char]='\0'; cursor++; if(cursor>screen_length) { cursor=screen_length; if(first_char_on_screen+screen_length<max_length) first_char_on_screen++; } } else BELL } } } break; } if(finished!=1) { /* if(last_char<screen_length) { AT(row,col) CLEAR_EOL }*/ print_at_from(row,col,first_char_on_screen,screen_length,edit_string); AT(row,col+cursor) }
curs_show() { Cursconf(1, 0); }
/* * Set up screen for VT52. * This is called by os_askfile to restore the screen to the normal * state, so it shouldn't allocate data structures. */ vt_setup() { int i; /* * Get rid of the mouse */ graf_mouse(M_OFF, NULL); /* * Get desktop resolution. If monochrome, note the fact so that * we can make sure our color choices get set correctly later on. * If low resolution, change to medium resolution automagically. * * If any other resolution, don't do anything different, and hope * things work out OK. */ drez = Getrez(); if (drez == 0) Setscreen(-1L, -1L, 1); if (drez != 2) { /* * Get desktop palette. */ for (i = 0; i < 16; i++) dpalette[i] = Setcolor(i, -1); /* * Set our palette. */ Setpalette(palette); /* * Tell the rest of the system what good colors * are for various things. */ sdesc_color = colbyte(osWHITE, osBLUE); ldesc_color = colbyte(osBLACK, osWHITE); debug_color = colbyte(osBRIGHTWHITE, osBLACK); text_color = colbyte(osWHITE, osBLACK); text_bold_color = colbyte(osBRIGHTWHITE, osBLACK); text_normal_color = text_color; } else { /* * Monochrome -- note different color name constants */ sdesc_color = colbyte(osmREVERSE, osmREVERSE); ldesc_color = colbyte(osmREVERSE, osmREVERSE); debug_color = colbyte(osmNORMAL, osmNORMAL); text_color = colbyte(osmNORMAL, osmNORMAL); text_bold_color = colbyte(osmREVERSE, osmREVERSE); text_normal_color = text_color; } /* * Set default text color */ vt_color(text_color); /* * Clear the screen, set to no-wrap mode, and enable cursor. * Also, set drawing colors to normal. */ Cconws("\033E\033w\033e"); X = 0; Y = 0; /* * Make the cursor not blink. */ Cursconf(2, 0); }
curs_hide() { Cursconf(0, 0); }