Description |
The tnet_ccmp function compares the command part of the
message in the buffer buf with the string cmd.
The tnet_ccmp function is in the RL-TCPnet library. The
prototype is defined in net_config.h.
note
-
The tnet_ccmp function is similar to the standard C
string function strcmp. The difference is that
tnet_ccmp only compares the first string, in buf,
that is either terminated by the NULL character or followed by a
space character. Hence, you must pass the message from the telnet
client using buf and not using cmd.
-
All the characters in the string cmd must be in capital
letters because the string in buf also has only capital
letters. This is due to an internal conversion before calling the
tnet_ccmp function.
|
Example |
U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) {
U16 len,val,ch;
/* Simple Command line parser */
len = strlen (cmd);
if (tnet_ccmp (cmd, "BYE") == __TRUE) {
/* 'BYE' command, send message and disconnect */
len = str_copy (buf, "\r\nDisconnect...\r\n");
/* Hi bit of return value is a disconnect flag */
return (len | 0x8000);
}
if (tnet_ccmp (cmd, "ADIN") == __TRUE) {
/* 'ADIN' command received */
if (len >= 6) {
sscanf (cmd+5,"%d",&ch);
val = AD_in (ch);
len = sprintf (buf,"\r\n ADIN %d = %d",ch,val);
return (len);
}
}
if (tnet_ccmp (cmd, "HELP") == __TRUE || tnet_ccmp (cmd, "?") == __TRUE) {
/* 'HELP' command, display help text */
len = str_copy (buf,tnet_help);
return (len);
}
/* Unknown command, display message */
len = str_copy (buf, "\r\n==> Unknown Command: ");
len += str_copy (buf+len, cmd);
return (len);
}
|