ARPDAS_QNX6 1.0
|
00001 /* cictrans.c Defines cic_transmit() */ 00002 #include <stdlib.h> 00003 #include "nortlib.h" 00004 #include "cmdalgo.h" 00005 #include "tm.h" 00006 00007 typedef struct cmd_lev { 00008 struct cmd_lev *prev; 00009 short int pos; /* offset in buffer */ 00010 cmd_state state; 00011 } cmd_level; 00012 00013 static cmd_level *cur = NULL; 00014 static short int curpos = 0; 00015 static char cmdbuf[CMD_INTERP_MAX]; 00016 00017 /* cic_transmit receives commands from the interactive command 00018 parser and transmits them as required to the command server 00019 using the nortlib routine ci_sendcmd(). Commands are only 00020 actually transmitted if the transmit argument is non-zero. 00021 Since the client and server share source code, it is easy 00022 for cmdgen to determine whether a particular command will 00023 result in an action at the far end. 00024 00025 cic_transmit also keeps track of the command parser states, 00026 recording the commands required to get to a particular 00027 state. For example, in the HOX command configuration, 00028 entering "OH\r" will cause the parser to change to a new 00029 state (submemu) which expects OH commands. This does 00030 not require transmission, but it does need to be recorded 00031 because of the new state. Subsequent commands will be 00032 transmitted prefixed by the "OH\r" until a "\r" is 00033 entered, returning the parser to the base state. 00034 00035 The command in buf is not ASCIIZ. Spaces may be represented 00036 by NULs and the terminating newline should be universally 00037 represented by a NUL. These must be translated back to 00038 their original representation before actual transmission. 00039 */ 00040 void cic_transmit(char *buf, int n_chars, int transmit) { 00041 int c; 00042 cmd_level *cl, *cl_save; 00043 00044 for (; n_chars > 0; n_chars--) { 00045 c = *buf++; 00046 if (c == 0) { 00047 if (n_chars == 1) c = '\n'; 00048 else c = ' '; 00049 } 00050 cmdbuf[curpos++] = c; 00051 if (curpos > CMD_INTERP_MAX) 00052 nl_error(3, "Maximum transmissable command length exceeded"); 00053 } 00054 if (transmit) { 00055 cmdbuf[curpos] = '\0'; 00056 ci_sendcmd(cmdbuf, 0); 00057 } 00058 for (cl = cur; cl != NULL && cmd_check(&cl->state); cl = cl->prev); 00059 if (cl == NULL) { 00060 cl = malloc(sizeof(cmd_level)); 00061 if (cl == NULL) nl_error(4, "No memory in cic_transmit"); 00062 cl->prev = cur; 00063 cl->pos = curpos; 00064 cmd_report(&cl->state); 00065 cur = cl; 00066 } else while (cur != cl) { 00067 cl_save = cur; 00068 cur = cur->prev; 00069 free(cl_save); 00070 } 00071 curpos = cur->pos; 00072 } 00073 00074 /* 00075 =Name cic_transmit(): Internal keyboard client send command 00076 =Subject Command Server and Client 00077 =Synopsis 00078 00079 #include "nortlib.h" 00080 void cic_transmit(char *buf, int n_chars, int transmit); 00081 00082 =Description 00083 cic_transmit() is called by keyboard command clients to 00084 transmit them as required to the command server 00085 using the nortlib routine =ci_sendcmd=(). Commands are only 00086 actually transmitted if the transmit argument is non-zero. 00087 Since the client and server share source code, it is easy 00088 for cmdgen to determine whether a particular command will 00089 result in an action at the far end.<P> 00090 00091 cic_transmit also keeps track of the command parser states, 00092 recording the commands required to get to a particular 00093 state. For example, in the HOX command configuration, 00094 entering "OH\r" will cause the parser to change to a new 00095 state (submemu) which expects OH commands. This does 00096 not require transmission, but it does need to be recorded 00097 because of the new state. Subsequent commands will be 00098 transmitted prefixed by the "OH\r" until a "\r" is 00099 entered, returning the parser to the base state.<P> 00100 00101 The command in buf is not ASCIIZ. Spaces may be represented 00102 by NULs and the terminating newline should be universally 00103 represented by a NUL. These must be translated back to 00104 their original representation before actual transmission.<P> 00105 00106 This is an internal function and should not be called 00107 casually. =ci_sendcmd=() is a better choice for sending 00108 commands.<P> 00109 00110 =Returns 00111 Nothing 00112 00113 =SeeAlso 00114 =ci_sendcmd=(), =Command Server and Client= Functions. 00115 00116 =End 00117 */