📄 pcmd.c
字号:
/*+------------------------------------------------------------------------- pcmd.c - ecu miscellaneous procedure commands wht@n4hgf.Mt-Park.GA.US Defined functions: get_big_endian_16(ptr) get_big_endian_32(ptr) pcmd_autorz(param) pcmd_baud(param) pcmd_cd(param) pcmd_clrx(param) pcmd_dcdwatch(param) pcmd_dial(param) pcmd_duplex(param) pcmd_echo(param) pcmd_exec(param) pcmd_exit(param) pcmd_flush(param) pcmd_getf(param) pcmd_hangup(param) pcmd_hexdump(param) pcmd_lbreak(param) pcmd_lgets(param) pcmd_logevent(param) pcmd_lookfor(param) pcmd_nap(param) pcmd_nice(param) pcmd_parity(param) pcmd_popd(param) pcmd_prompt(param) pcmd_ptrace(param) pcmd_pushd(param) pcmd_putf(param) pcmd_rname(param) pcmd_rtscts(param) pcmd_send(param) pcmd_set(param) pcmd_setline(param) pcmd_system(param) pcmd_xon(param)--------------------------------------------------------------------------*//*+:EDITS:*//*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 *//*:09-06-1992-13:44-wht@n4hgf-rtscts would not accept a numeric argument *//*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA *//*:01-12-1992-20:54-wht@n4hgf-add autorz command *//*:12-12-1991-05:27-wht@n4hgf-proctrace of intvar shows char value if 0-255 *//*:11-11-1991-14:38-wht@n4hgf-add pcmd_dcdwatch code *//*:10-09-1991-21:54-wht@n4hgf-add -p and -v switch to send *//*:10-09-1991-20:32-wht@n4hgf-proctrace code for send *//*:09-01-1991-19:10-wht@n4hgf2-baud cmd can set rate even if no line open *//*:09-01-1991-18:10-wht@n4hgf2-add setline *//*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh *//*:08-06-1991-21:18-wht@n4hgf-nap -m test wrong sense ... old bug! *//*:08-05-1991-16:22-wht@n4hgf-add nap -1 return and proctrace *//*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 *//*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug *//*:06-05-1991-22:50-wht@n4hgf-fix parity cmd not taking alpha str *//*:05-21-1991-18:52-wht@n4hgf-add pcmd_pushd and pcmd_popd *//*:03-16-1991-15:12-wht@n4hgf-add pcmd_nice *//*:01-09-1991-22:31-wht@n4hgf-ISC port *//*:12-26-1990-02:34-wht@n4hgf-add cmd_rtscts *//*:12-03-1990-04:59-wht@n4hgf-beef up pcmd_exit *//*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "ecu.h"#include "ecuerror.h"#include "termecu.h"#include "ecukey.h"#include "esd.h"#include "var.h"#include "proc.h"#define NAMED_VARIABLE_FLAG 0x1000L#if defined(SVR4)# include <sys/termiox.h>extern int hx_flag;#endifextern int rc_ep_has_run;extern ulong colors_current;extern char errmsg[];extern char curr_dir[CURR_DIRSIZ]; /* current working directory *//*+------------------------------------------------------------------------- pcmd_autorz(param)--------------------------------------------------------------------------*/intpcmd_autorz(param)ESD *param;{char s8[8]; if(get_alpha_zstr(param,s8,sizeof(s8))) return(eSyntaxError); if(!strcmp(s8,"on")) shm->autorz = 1; else if(!strcmp(s8,"off")) shm->autorz = 0; else return(eSyntaxError); shm->autorz_pos = 0; return(0);} /* end of pcmd_autorz *//*+------------------------------------------------------------------------- pcmd_baud(param) - set line or default baud rateThe command sets shm->Lbaud whether or not a line is open.If a line is open, the baud rate is actually set.--------------------------------------------------------------------------*/intpcmd_baud(param)ESD *param;{long new_baud;int erc; if(erc = gint(param,&new_baud)) return(erc); if(!valid_baud_rate((uint)new_baud)) { pprintf("invalid baud rate: %lu\n",new_baud); return(eFATAL_ALREADY); } shm->Lbaud = (uint)new_baud; if(shm->Liofd >= 0) lset_baud_rate(1); if(proctrace) { pprintf("baud rate set to %u\n",shm->Lbaud); } return(0);} /* end of pcmd_baud *//*+------------------------------------------------------------------------- pcmd_cd(param)--------------------------------------------------------------------------*/intpcmd_cd(param)ESD *param;{int erc;ESD *tesd = esdalloc(256); if(!tesd) return(eNoMemory); if(erc = gstr(param,tesd,0)) goto RETURN; if(expand_dirname(tesd->pb,tesd->maxcb)) { pprintf("%s\n",errmsg); param->index = param->old_index; erc = eFATAL_ALREADY; goto RETURN; } if(chdir(tesd->pb) < 0) /* now change to the new directory */ { pperror(tesd->pb); /* print error if we get one */ pputs("\n"); erc = eFATAL_ALREADY; goto RETURN; } get_curr_dir(curr_dir,256);RETURN: esdfree(tesd); return(erc);} /* end of pcmd_cd *//*+------------------------------------------------------------------------- pcmd_pushd(param)--------------------------------------------------------------------------*/intpcmd_pushd(param)ESD *param;{int erc = 0;int arg_present;ESD *tesd = (ESD *)0; if(arg_present = !!end_of_cmd(param)) { if(!(tesd = esdalloc(256))) return(eNoMemory); if(erc = gstr(param,tesd,0)) goto RETURN; } if(!push_directory((arg_present) ? tesd->pb : "",arg_present,1)) { param->index = param->old_index; erc = eFATAL_ALREADY; }RETURN: if(tesd) esdfree(tesd); return(erc);} /* end of pcmd_pushd *//*+------------------------------------------------------------------------- pcmd_popd(param)--------------------------------------------------------------------------*/intpcmd_popd(param)ESD *param;{int erc = 0;int arg_present;char allstr[8]; allstr[0] = 0; if(arg_present = !!end_of_cmd(param)) { if(get_alpha_zstr(param,allstr,sizeof(allstr))) { param->index = param->old_index; return(eSyntaxError); } } if(!pop_directory(allstr,arg_present,1)) { param->index = param->old_index; erc = eFATAL_ALREADY; } return(erc);} /* end of pcmd_popd *//*+------------------------------------------------------------------------- pcmd_clrx(param)--------------------------------------------------------------------------*//*ARGSUSED*/intpcmd_clrx(param)ESD *param;{ if(shm->Liofd < 0) return(eNoLineAttached); lclear_xmtr_xoff(); if(proctrace) pputs("transmitter XOFF cleared\n"); return(0);} /* end of pcmd_clrx *//*+------------------------------------------------------------------------- pcmd_dcdwatch(param)--------------------------------------------------------------------------*/intpcmd_dcdwatch(param)ESD *param;{int erc;char s16[16];char *cptr; if(shm->Liofd < 0) return(eNoLineAttached); if(erc = get_alpha_zstr(param,s16,sizeof(s16))) return(erc); erc = (ldcdwatch_str(s16)) ? eSyntaxError : 0; if(!erc && proctrace) { pputs("DCD watch set to "); cptr = "???"; switch(shm->Ldcdwatch) { case DCDW_OFF: cptr = "off"; break; case DCDW_ON: cptr = "on"; break; case DCDW_TERMINATE: cptr = "TERMINATE"; break; } pprintf("%s\n",cptr); } return(0);} /* end of pcmd_dcdwatch *//*+------------------------------------------------------------------------- pcmd_dial(param) - connect to a remote DTE or to local DCE sets I0 to 0==connect, 1==failed to connect, 2==interrupted, 3==modem error sets S0 to modem result code--------------------------------------------------------------------------*/intpcmd_dial(param)ESD *param;{int erc;ESD *tesd = (ESD *)0; if(shm->Lconnected) { pprintf("Already connected (to %s)\n",shm->Llogical); return(eFATAL_ALREADY); } if(!(tesd = esdalloc(64))) return(eNoMemory); if(erc = gstr(param,tesd,0)) { esdfree(tesd); return(erc); } if((erc = call_logical_telno(tesd->pb)) && (erc == eConnectFailed)) erc = 0; if(!erc && (shm->Liofd < 0)) erc = eNoLineAttached; esdfree(tesd); return(erc);} /* end of pcmd_dial *//*+------------------------------------------------------------------------- pcmd_duplex(param)duplex [f | h]duplex ['f' | 'h']duplex <int> 0 == half, non-0 == full--------------------------------------------------------------------------*/intpcmd_duplex(param)ESD *param;{int erc;int new_duplex;ESD *tesd; if(erc = skip_cmd_break(param)) return(erc); if(!(tesd = esdalloc(64))) return(eNoMemory); erc = gstr(param,tesd,0); new_duplex = to_lower((erc) ? param->pb[param->index] : *tesd->pb); esdfree(tesd); erc = 0; switch(new_duplex) { case 'f': shm->Lfull_duplex = 1; break; case 'h': shm->Lfull_duplex = 0; break; default: erc = eBadParameter; } if(proctrace && !erc) pprintf("duplex set to %s\n",(shm->Lfull_duplex) ? "full" : "half"); return(erc);} /* end of pcmd_duplex *//*+------------------------------------------------------------------------- pcmd_echo(param)echo [-n] <str>--------------------------------------------------------------------------*/intpcmd_echo(param)ESD *param;{int erc;ESD *tesd;char switches[8]; if((tesd = esdalloc(256)) == (ESD *)0) return(eNoMemory); get_switches(param,switches,sizeof(switches)); if(erc = gstr(param,tesd,1)) { esdfree(tesd); return(erc); } pputs(tesd->pb); if(!strchr(switches,'n')) /* if no -n */ pputs("\n"); esdfree(tesd); return(0);} /* end of pcmd_echo *//*+------------------------------------------------------------------------- pcmd_exec(param)--------------------------------------------------------------------------*/intpcmd_exec(param)ESD *param;{ int erc = 0; ESD *tesd = (ESD *)0; if(!(tesd = esdalloc(64))) return(eNoMemory); if(erc = gstr(param,tesd,1)) goto RETURN; /* reset indices */ tesd->index = 0; tesd->old_index = 0; if(proctrace) pprintf("executing: <%s>\n",tesd->pb); if(erc = execute_esd(tesd)) { esdshow(tesd,"error executing dynamic statement:"); proc_error(erc); erc = eFATAL_ALREADY; }RETURN: if(tesd) esdfree(tesd); return(erc);} /* end of pcmd_exec *//*+------------------------------------------------------------------------- pcmd_exit(param)--------------------------------------------------------------------------*/intpcmd_exit(param)ESD *param;{long int1;ulong colors_at_entry = colors_current; if(!gint(param,&int1) && int1) { setcolor(colors_error); pprintf("[procedure terminating ecu: user code %ld]\n",int1); setcolor(colors_at_entry); if((int1 += TERMECU_USER1 - 1) > TERMECU_USERN) { int1 = TERMECU_USERN; pprintf("user exit code too large, using %d\r\n", TERMECU_USERN - TERMECU_USER1); } termecu((int)int1); } setcolor(colors_success); pputs("[procedure terminating ecu: normal exit]\n"); setcolor(colors_at_entry); termecu(0);} /* end of pcmd_exit *//*+------------------------------------------------------------------------- pcmd_lgets(param)lgets [-er] <strvar> <int1> <int2> [<str>]read string into string variable number <stvar>waiting <int1> 1/10th secs for first char,waiting <int2> 1/10th secs for subsequent chars,optionally terminating read upon detection of <str>-e echos to screen-r completely raw, else strip CRs & NLs from either end of string$i0 receives the length of the read<strvar> receives the string--------------------------------------------------------------------------*/intpcmd_lgets(param)ESD *param;{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -