📄 ecuphdir.c
字号:
/*+------------------------------------------------------------------------- check_curr_pde() -- return 1 if there is a current pde, else 0--------------------------------------------------------------------------*/check_curr_pde(){ if(!curr_pde) { dirw_bot_msg("no directory entry selected"); return(0); } return(1);} /* end of check_curr_pde *//*+------------------------------------------------------------------------- phdir_add_or_edit_read(prompt,edit,y,buf,bufmax,delim)There are numerous theoretcally possible string overflow possibilitiesin here, but no practical string will be long enough--------------------------------------------------------------------------*/voidphdir_add_or_edit_read(prompt,edit,y,buf,bufmax,delim)char *prompt;int edit;int y;char *buf;int bufmax;uchar *delim;{ int wgpos = -1; char s80[80]; int done = 0; if(!check_curr_pde()) return; wmove(addw,PDE_ITEM_COUNT + 3,2); waddstr(addw,prompt); wstandout(addw); if(edit) strcpy(s80,buf); do { (void)wingets(addw,y,20,s80,bufmax,delim,edit,&wgpos); wstandend(addw); clear_area(addw,y,20,bufmax); edit = 1; /* if we come back again, edit string */ switch(*((uchar *)delim)) { case ESC: waddstr(addw,buf); done = 1; break; case TAB: case NL: case XFcurdn: *delim = NL; case XFend: strcpy(buf,s80); waddstr(addw,buf); done = 1; break; case CTL_U: s80[0] = 0; break; case CTL_B: case XFcurup: strcpy(buf,s80); waddstr(addw,buf); *delim = CTL_B; done = 1; break; default: ring_bell(); break; } } while(!done); clear_area(addw,PDE_ITEM_COUNT + 3,2,strlen(prompt));} /* end of phdir_add_or_edit_read *//*+------------------------------------------------------------------------- phdir_add_or_edit(tpde,edit)--------------------------------------------------------------------------*/intphdir_add_or_edit(tpde,edit)register PDE *tpde;int edit;{ int input_state = 0; int changed = 0; int done = 0; int aborted = 0; int itmp; int wgedit = 0; int wgpos = -1; char s64[64]; uchar delim = 0; int y,x; PDE *old_curr_pde = (PDE *)0; uint baud; char cmpbuf[128]; char *emsg = (char *)0; if(!edit) { dirw_bot_msg("ESC: abort ^U: erase input"); dirw_cmd_line_setup( "Only the 1st 10 characters appear in the table", "Enter new directory entry name: "); getyx(dirw,y,x); wstandout(dirw); while((delim != ESC) && (delim != NL)) { (void)wingets(dirw,y,x,tpde->logical,DESTREF_LEN+1,&delim, wgedit,&wgpos); wgedit = 1; } wstandend(dirw); dirw_bot_msg(""); if((!strlen(tpde->logical)) || (delim == ESC)) { dirw_bot_msg("add aborted"); return(0); } if(!isalpha(tpde->logical[0])) { dirw_bot_msg("first character must be alphabetic"); return(0); } if(phdir_list_search(tpde->logical,1)) { sprintf(s64,"'%s' is already in the directory",tpde->logical); ring_bell(); dirw_bot_msg(s64); return(0); } tpde->descr[0] = 0; tpde->telno[0] = 0; tpde->tty[0] = 0; tpde->parity = 0; tpde->baud = DEFAULT_BAUD_RATE; tpde->debug_level = 0; tpde->dcdwatch = 'n'; /* do not modify shm->Ldcdwatch */ phdir_list_add(tpde); old_curr_pde = curr_pde; curr_pde = tpde; scrw_fill_at(SCRW_LINES / 2,tpde,&scrw_curr_pde_line); tpde = curr_pde; } /* end of add code */ dirw_cmd_line_setup("",""); /* * get a new window */ sprintf(s64,"entry: %s",tpde->logical); addw = window_create(s64,3,ADDW_TLY,ADDW_TLX,ADDW_LINES,ADDW_COLS); wmove(addw,2,2); waddstr(addw,"telephone number"); wmove(addw,3,2); waddstr(addw,"device"); wmove(addw,4,2); waddstr(addw,"baud rate"); wmove(addw,5,2); waddstr(addw,"parity"); wmove(addw,6,2); waddstr(addw,"description"); wmove(addw,7,2); waddstr(addw,"debug level"); wmove(addw,7,23); waddstr(addw,"(dialer -x value 0-9)"); wmove(addw,8,2); waddstr(addw,"DCD watch"); wmove(addw,2,20); waddstr(addw,tpde->telno); wmove(addw,3,20); waddstr(addw,(tpde->tty[0]) ? tpde->tty : "Any"); sprintf(s64,"%-5u",tpde->baud); wmove(addw,4,20); waddstr(addw,s64); s64[0] = (tpde->parity) ? to_upper((char)tpde->parity) : 'N'; s64[1] = 0; wmove(addw,5,20); waddstr(addw,s64); wmove(addw,6,20); waddstr(addw,tpde->descr); sprintf(s64,"%u",tpde->debug_level); wmove(addw,7,20); waddstr(addw,s64); wmove(addw,8,20); waddch(addw,tpde->dcdwatch); wmove(addw,PDE_ITEM_COUNT + 4,2); if(edit) waddstr(addw,"ESC: exit END: accept ^U: erase ^B: back TAB: fwd"); else waddstr(addw,"ESC: cancel END: accept ^U: erase field ^B: back up"); wrefresh(addw);/* add/edit common */ while(!done) { changed = 0; switch(input_state) { case 0: if(edit) strcpy(s64,tpde->telno); phdir_add_or_edit_read("Enter telephone number", edit,input_state + 2,tpde->telno,DESTREF_LEN+1,&delim); if(edit && strcmp(tpde->telno,s64)) changed = 1; break; case 1: if(!tpde->tty[0]) strcpy(tpde->tty,"Any"); if(edit) strcpy(s64,tpde->tty);CASE_1_AGAIN: phdir_add_or_edit_read( (emsg) ? emsg : "Enter tty (e.g. 1a), Any or [=/]Devices-type", edit,input_state + 2,s64,PDE_TTY_LEN+1,&delim); if((delim != ESC) && (s64[0] == '/') && regexp_compile(s64 + 1,cmpbuf,sizeof(cmpbuf),&emsg)) { ring_bell(); goto CASE_1_AGAIN; } emsg = (char *)0; if(!strlen(s64) || !strcmpi(s64,"any")) { strcpy(s64,"Any"); clear_area(addw,input_state + 2,20,PDE_TTY_LEN+1); waddstr(addw,s64); } if(edit) changed = !!strcmp(tpde->tty,s64); if(!strcmpi(s64,"any")) tpde->tty[0] = 0; else strcpy(tpde->tty,s64); break; case 2: sprintf(s64,"%u",tpde->baud); phdir_add_or_edit_read( "Enter rate (110,300,600,1200,2400,4800,9600,19200,38400)", 1,input_state + 2,s64,5+1,&delim); if(valid_baud_rate(baud = atoi(s64)) < 0) { ring_bell(); continue; } if(edit && (tpde->baud != baud )) changed = 1; tpde->baud = baud; break; case 3: sprintf(s64,"%c",(tpde->parity) ? tpde->parity : 'N'); phdir_add_or_edit_read("Enter parity (n,o,e)", 1,input_state + 2,s64,1+1,&delim); switch(s64[0] = to_lower(s64[0])) { case 'n': s64[0] = 0; case 'o': case 'e': if(edit && (tpde->parity != s64[0])) changed = 1; tpde->parity = s64[0]; break; default: ring_bell(); continue; } break; case 4: if(edit) strcpy(s64,tpde->descr); phdir_add_or_edit_read("Enter description", edit,input_state + 2,tpde->descr,PDE_DESCR_LEN+1,&delim); if(edit && strcmp(tpde->descr,s64)) changed = 1; break; case 5: sprintf(s64,"%u",tpde->debug_level); phdir_add_or_edit_read("Enter dialer debug level (0-9)", 1,input_state + 2,s64,1+1,&delim); if(!isdigit(s64[0])) { ring_bell(); continue; } itmp = atoi(s64); if(edit && (itmp != tpde->debug_level)) changed = 1; tpde->debug_level = itmp; break; case 6: sprintf(s64,"%c",tpde->dcdwatch); phdir_add_or_edit_read( "0=off,1=on,t=terminate ecu on carrier loss,n=no change", 1,input_state + 2,s64,1+1,&delim); switch(s64[0] = to_lower(s64[0])) { case '0': case '1': case 't': case 'n': break; default: ring_bell(); continue; } if(edit && ((uchar)s64[0] != tpde->dcdwatch)) changed = 1; tpde->dcdwatch = s64[0]; break; } switch(delim) /* process delimiter */ { case CTL_L: case CTL_R: touchwin(stdscr); wrefresh(stdscr); touchwin(dirw); wrefresh(dirw); touchwin(scrw); wrefresh(scrw); break; case CTL_B: if(input_state) input_state--; else input_state = 6; break; case ESC: if(edit) { dirw_bot_msg("edit exit"); done = 1; } else { phdir_list_remove(tpde); if(old_curr_pde) curr_pde = old_curr_pde; else { pputs("\nphdir_add_or_edit logic error\n"); termecu(TERMECU_XMTR_FATAL_ERROR); } dirw_bot_msg("add aborted"); aborted = 1; done = 1; } break; case XFend: done = 1; case NL: if(edit && changed) phdir_list_set_dirty(1); input_state++; input_state %= PDE_ITEM_COUNT; break; default: ring_bell(); break; } } delwin(addw); addw = (WINDOW *)0; touchwin(scrw); if(aborted) { scrw_fill_at(scrw_curr_pde_line + 1,curr_pde, &scrw_curr_pde_line); } else phdir_display(scrw_curr_pde_line,tpde,1); return(!aborted);} /* end of phdir_add_or_edit *//*+------------------------------------------------------------------------- phdir_cmd_add(tpde)if tpde != 0, it is an already valid pde that is to be addedelse if == 0, interactive add--------------------------------------------------------------------------*/voidphdir_cmd_add(tpde)register PDE *tpde;{ if(tpde) { phdir_list_add(tpde); } else { if(!(tpde = (PDE *)calloc(1,sizeof(PDE )))) { dirw_bot_msg("Out of memory -- cannot add new entry"); return; } if(!phdir_add_or_edit(tpde,0)) /* routine will add to list ... */ { /* ... if good return */ free((char *)tpde); return; } } phdir_list_set_dirty(1); curr_pde = tpde; scrw_fill_at(SCRW_LINES / 2,curr_pde,&scrw_curr_pde_line);} /* end of phdir_cmd_add *//*+------------------------------------------------------------------------- phdir_cmd_mark(tpde) - mark for redial--------------------------------------------------------------------------*/voidphdir_cmd_mark(tpde)register PDE *tpde;{ if(!tpde) return; if(!tpde->redial) { tpde->redial = 1; if(tpde == curr_pde) phdir_display_logical(scrw_curr_pde_line,curr_pde,1); pde_marked_for_redial_count++; dirw_display_config(); }} /* end of phdir_cmd_mark *//*+------------------------------------------------------------------------- phdir_cmd_unmark(tpde) - unmark for redial--------------------------------------------------------------------------*/voidphdir_cmd_unmark(tpde)register PDE *tpde;{ if(!tpde) return; if(tpde->redial) { tpde->redial = 0; if(tpde == curr_pde) phdir_display_logical(scrw_curr_pde_line,curr_pde,1); pde_marked_for_redial_count--; dirw_display_config(); }} /* end of phdir_cmd_unmark *//*+------------------------------------------------------------------------- phdir_cmd_unmark_all() - unmark for redial all PDEs--------------------------------------------------------------------------*/voidphdir_cmd_unmark_all(){ register PDE *tpde; register y; tpde = phdir_list_head; while(tpde) { tpde->redial = 0; tpde = tpde->next; } for(y = 0; y < SCRW_LINES; y++) { wmove(scrw,y,1); waddch(scrw,' '); } pde_marked_for_redial_count = 0; dirw_display_config();} /* end of phdir_cmd_unmark_all *//*+------------------------------------------------------------------------- phdir_cmd_remove_oops()--------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -