ecupde.c
来自「一个通讯程序源码」· C语言 代码 · 共 683 行 · 第 1/2 页
C
683 行
*/ if((tpde->tty[0] == '=') || (tpde->tty[0] == '/')) /* Devices device type */ { if(!(tdve = hdb_choose_Device(tpde->tty,tpde->baud))) { sprintf(errmsg,"no idle line matches type '%s' at %u baud", *tpde->tty ? tpde->tty : "Any",tpde->baud); rtn = -1; goto RETURN; } sprintf(newtty,"/dev/%s",tdve->line); if((itmp = lock_tty(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s (%s): %s", tpde->tty,tdve->line,linst_err_text(itmp)); rtn = -1; goto RETURN; } if((itmp = reserve_line(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s: %s",newtty,linst_err_text(itmp)); rtn = -1; goto RETURN; } } /* * if desired line is a specific tty */ else if(tpde->tty[0]) { pdetty_to_devtty(tpde->tty,newtty); if((shm->Liofd > 0) && !strcmp(newtty,shm->Lline)) { rtn = 0; /* requesting line we already have */ goto RETURN; } if((itmp = lock_tty(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s: %s",newtty,linst_err_text(itmp)); rtn = -1; goto RETURN; } if((itmp = reserve_line(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s: %s",newtty,linst_err_text(itmp)); rtn = -1; goto RETURN; } } /* * if desired line is "Any" (any Devices type beginning with ACU) */ else /* "Any" */ { tdve = hdb_choose_Any(tpde->baud); if(!tdve) { sprintf(errmsg,"no idle ACU line at %u baud",tpde->baud); rtn = -1; goto RETURN; } sprintf(newtty,"/dev/%s",tdve->line); if((itmp = lock_tty(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s: %s",newtty,linst_err_text(itmp)); rtn = -1; goto RETURN; } if((itmp = reserve_line(newtty)) && (itmp != LINST_WEGOTIT)) { sprintf(errmsg,"%s: %s",newtty,linst_err_text(itmp)); rtn = -1; goto RETURN; } } rtn = !(!strcmp(newtty,shm->Lline) && (shm->Liofd != -1)); if(rtn) { lclose(); strcpy(shm->Lline,newtty); }RETURN:#ifdef CHOOSE_DEBUG sprintf(s256,"choose_tty_for_pde rtn=%d line='%s' errmsg='%s' itmp=%d", rtn,shm->Lline,errmsg,itmp); ecu_log_event((int)xmtr_pid,s256);#endif return(rtn);} /* end of choose_tty_for_pde *//*+------------------------------------------------------------------------- copy_pde_to_Lvariables(tpde,trial)'trial' controls whether this is a dry run (setup) or a live requestif changing line, close old line and open new oneif cannot change line, return -1, else 0--------------------------------------------------------------------------*/intcopy_pde_to_Lvariables(tpde,trial)register PDE *tpde;int trial;{ int reopen = 0; int lerr; DVE *tdve;#ifdef CHOOSE_DEBUG char s80[80]; sprintf(s80,"copy_pde trial=%d Lline='%s' pdetty='%s'", trial,shm->Lline,tpde->tty); ecu_log_event((int)xmtr_pid,s80);#endif enddvent(); /* krock safety */ if(!trial) { if((reopen = choose_tty_for_pde(tpde)) < 0) return(-1); /* errmsg[] updated */ } else if((!tpde->tty[0]) || (!strcmp(tpde->tty,"Any"))) { if(!(tdve = hdb_choose_Any(tpde->baud))) { strcpy(errmsg,"no idle line matches type 'Any'"); return(-1); } strcpy(shm->Lline,"/dev/"); strncat(shm->Lline,tdve->line,sizeof(shm->Lline) - 5); shm->Lline[sizeof(shm->Lline) - 1] = 0; } else if((tpde->tty[0] == '/') || (tpde->tty[0] == '=')) { if(!(tdve = hdb_choose_Device(tpde->tty,tpde->baud))) { sprintf(errmsg,"no idle line matches type '%s' at %u baud", *tpde->tty ? tpde->tty : "Any",tpde->baud); return(-1); } strcpy(shm->Lline,"/dev/"); strncat(shm->Lline,tdve->line,sizeof(shm->Lline) - 5); shm->Lline[sizeof(shm->Lline) - 1] = 0; } else pdetty_to_devtty(tpde->tty,shm->Lline);#ifdef CHOOSE_DEBUG sprintf(s80,"copy_pde 2 Lline='%s' reopen=%d",shm->Lline,reopen); ecu_log_event((int)xmtr_pid,s80);#endif shm->Lbaud = tpde->baud; strcpy(shm->Llogical,tpde->logical); strcpy(shm->Ldescr,tpde->descr); strcpy(shm->Ltelno,tpde->telno); if(!shm->Ldescr[0]) strcpy(shm->Ldescr,shm->Llogical); shm->Lparity = tpde->parity; if(shm->Lbaud != tpde->baud) shm->Lmodem_already_init = 0; Ldial_debug_level = tpde->debug_level; /* tpde->dcdwatch is explicitly unused here; must defer until connect */ if(!trial) { if(reopen) { if(lerr = lopen()) { tcap_curbotleft(); pprintf("%s: %s\n",shm->Lline,linst_err_text(lerr)); termecu(TERMECU_LINE_OPEN_ERROR); } } else { lset_baud_rate(1); lset_parity(1); } } return(0);} /* end of copy_pde_to_Lvariables *//*+----------------------------------------------------------------------- logical_telno_to_pde() - logical dial string to dialing info (PDE) NOT USED BY THE CURSES DIRECTORY MANAGERA logical telephone number is one of:1. null,2. a symbolic identifer, or3. an actual telephone number. A symbolic identifer is a string whose initial character is aletter. An actual telephone number begins with a numeral.This function converts a logical telephone number to a dialingentry (PDE) from the directory or a constructed static one. Itis called by command line processing when 'ecu logical-name' isspecified or in response to a %dial logical-name.The function returns one of the following: directory or static PDE if no error occurs (PDE *)0 if not numeric phone number and logical string not found in directory; global char[] errmsg has been plugged with error message------------------------------------------------------------------------*/PDE *logical_telno_to_pde(logical)char *logical;{ static PDE literal_number_pde; register PDE *tpde = 0; extern int phdir_list_quan;#ifdef CHOOSE_DEBUG char s80[80]; sprintf(s80,"logical_telno_to_pde(logical='%s')",logical); ecu_log_event((int)xmtr_pid,s80);#endif/* * if literal phone number, return homemade, static "PDE" * with most stuff dummied up with the status quo */ if(isdigit(*logical)) { tpde = &literal_number_pde; memset((char *)tpde,0,sizeof(PDE)); tpde->baud = shm->Lbaud; tpde->parity = shm->Lparity; strncpy(tpde->logical,logical,DESTREF_LEN); tpde->logical[DESTREF_LEN] = 0; strncpy(tpde->telno,logical,DESTREF_LEN); tpde->telno[DESTREF_LEN] = 0; strncpy(tpde->tty,shm->Lline + 5,PDE_TTY_LEN); tpde->tty[PDE_TTY_LEN] = 0; if((strlen(logical) + 8) <= PDE_DESCR_LEN) sprintf(tpde->descr,"<telno %s>",logical); else strcpy(tpde->descr,"<telno>"); tpde->dcdwatch = 'n'; goto RETURN; }/* * if empty phone number, return homemade, static "PDE" * with most stuff dummied up with the status quo */ if(!*logical) { tpde = &literal_number_pde; memset((char *)tpde,0,sizeof(PDE)); tpde->baud = shm->Lbaud; tpde->parity = shm->Lparity; strcpy(tpde->tty,shm->Lline + 5); if(!tpde->tty[0]) strcpy(tpde->tty,default_tty + 5); strcpy(tpde->descr,"<direct connect>"); tpde->dcdwatch = 'n'; goto RETURN; } /* * read directory if necessary */ if(!phdir_list_quan) { if(phdir_list_read() && !phdir_list_quan) { /* if still no good, ... */ strcpy(errmsg,"phone directory empty"); tpde = 0; goto RETURN; } } /* * now, look up the entry */ if(tpde = phdir_list_search(logical,0)) goto RETURN; /* * whoops ... not found */ shm->Lrname[0] = 0; shm->Ltelno[0] = 0; shm->Ldescr[0] = 0; strcpy(errmsg,"entry not found in directory"); tpde = 0;RETURN:#ifdef CHOOSE_DEBUG sprintf(s80,"logical_telno_to_pde %s%s", (tpde) ? "chosen tty=" : "no tty chosen", (tpde) ? tpde->tty : ""); ecu_log_event((int)xmtr_pid,s80);#endif return(tpde);} /* end of logical_telno_to_pde *//*+------------------------------------------------------------------------- call_logical_telno(logical) - call a logical or literal telephone number-1 if no such entry or pde_dial() status--------------------------------------------------------------------------*/intcall_logical_telno(logical)char *logical;{ int ret; PDE *tpde; if(tpde = logical_telno_to_pde(logical)) ret = pde_dial(tpde); else { pprintf("%s: %s\n",logical,errmsg); ret = eFATAL_ALREADY; } return(ret);} /* end of call_logical_telno *//* vi: set tabstop=4 shiftwidth=4: *//* end of ecupde.c */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?