* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/
/* this file contains various functionality useful to standalone systems */
***************************************************************************/
/* this file contains various functionality useful to standalone systems */
/* loads a file and returns a pointer to it in memory. The file contains
* a 0 byte(sentinel) after len bytes - the length of the file. */
int loadFile(const char *fileName, void **data, size_t *len)
{
/* loads a file and returns a pointer to it in memory. The file contains
* a 0 byte(sentinel) after len bytes - the length of the file. */
int loadFile(const char *fileName, void **data, size_t *len)
{
- FILE * pFile;
- pFile = fopen(fileName,"rb");
- if (pFile == NULL)
- {
- LOG_ERROR("Can't open %s\n", fileName);
+ FILE *pFile;
+ pFile = fopen(fileName, "rb");
+ if (pFile == NULL) {
+ LOG_ERROR("Can't open %s", fileName);
- if (fseek(pFile, 0, SEEK_END) != 0)
- {
- LOG_ERROR("Can't open %s\n", fileName);
+ if (fseek(pFile, 0, SEEK_END) != 0) {
+ LOG_ERROR("Can't open %s", fileName);
- if (fseek(pFile, 0, SEEK_SET) != 0)
- {
- LOG_ERROR("Can't open %s\n", fileName);
+ if (fseek(pFile, 0, SEEK_SET) != 0) {
+ LOG_ERROR("Can't open %s", fileName);
- if (fread(*data, 1, *len, pFile)!=*len)
- {
+ if (fread(*data, 1, *len, pFile) != *len) {
- }
- else
- {
- command_print(CMD_CTX, "%s not found %d", CMD_ARGV[0], retval);
- }
+ } else
+ command_print(CMD_CTX, "%s not found", CMD_ARGV[0]);
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "w");
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "w");
int retval = ERROR_FAIL;
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "a");
int retval = ERROR_FAIL;
FILE *config_file = NULL;
config_file = fopen(CMD_ARGV[0], "a");
if (fwrite(CMD_ARGV[i], 1, strlen(CMD_ARGV[i]),
config_file) != strlen(CMD_ARGV[i]))
break;
if (fwrite(CMD_ARGV[i], 1, strlen(CMD_ARGV[i]),
config_file) != strlen(CMD_ARGV[i]))
break;
if (fwrite(" ", 1, 1, config_file) != 1)
break;
}
if (fwrite(" ", 1, 1, config_file) != 1)
break;
}
if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk))
if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk))
command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]);
command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]);
strcpy(fullname2, destdir);
strcat(fullname2, "/");
strcat(fullname2, entry->d_name);
strcpy(fullname2, destdir);
strcat(fullname2, "/");
strcat(fullname2, entry->d_name);
Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?");
return JIM_ERR;
}
- Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name)));
+ Jim_ListAppendElement(interp, objPtr,
+ Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name)));
Jim_WrongNumArgs(interp, 1, argv, "peek ?address?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "peek ?address?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "poke ?address? ?value?");
return JIM_ERR;
}
Jim_WrongNumArgs(interp, 1, argv, "poke ?address? ?value?");
return JIM_ERR;
}
/* not so pretty code to fish out ip number*/
static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc,
/* not so pretty code to fish out ip number*/
static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc,
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs(&ifp) < 0)
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs(&ifp) < 0)
if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
NI_NUMERICHOST) < 0)
if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
NI_NUMERICHOST) < 0)
Jim_AppendString(interp, tclOutput, ip, strlen(ip));
break;
Jim_AppendString(interp, tclOutput, ip, strlen(ip));
break;
/* not so pretty code to fish out eth0 mac address */
static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc,
/* not so pretty code to fish out eth0 mac address */
static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc,
{
if (strcmp("eth0", ifr->ifr_name) != 0)
continue;
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
{
if (strcmp("eth0", ifr->ifr_name) != 0)
continue;
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
char buffer[256];
sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x",
Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
char buffer[256];
sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x",
- ifreq.ifr_hwaddr.sa_data[0]&0xff,
- ifreq.ifr_hwaddr.sa_data[1]&0xff,
- ifreq.ifr_hwaddr.sa_data[2]&0xff,
- ifreq.ifr_hwaddr.sa_data[3]&0xff,
- ifreq.ifr_hwaddr.sa_data[4]&0xff,
- ifreq.ifr_hwaddr.sa_data[5]&0xff);
+ ifreq.ifr_hwaddr.sa_data[0]&0xff,
+ ifreq.ifr_hwaddr.sa_data[1]&0xff,
+ ifreq.ifr_hwaddr.sa_data[2]&0xff,
+ ifreq.ifr_hwaddr.sa_data[3]&0xff,
+ ifreq.ifr_hwaddr.sa_data[4]&0xff,
+ ifreq.ifr_hwaddr.sa_data[5]&0xff);
Jim_AppendString(interp, tclOutput, buffer, strlen(buffer));
Jim_AppendString(interp, tclOutput, buffer, strlen(buffer));
.handler = handle_cat_command,
.mode = COMMAND_ANY,
.help = "display text file content",
.handler = handle_cat_command,
.mode = COMMAND_ANY,
.help = "display text file content",
},
{
.name = "trunc",
.handler = handle_trunc_command,
.mode = COMMAND_ANY,
.help = "truncate a file to zero length",
},
{
.name = "trunc",
.handler = handle_trunc_command,
.mode = COMMAND_ANY,
.help = "truncate a file to zero length",
.handler = handle_append_command,
.mode = COMMAND_ANY,
.help = "append a variable number of strings to a file",
.handler = handle_append_command,
.mode = COMMAND_ANY,
.help = "append a variable number of strings to a file",
{
.name = "meminfo",
.handler = handle_meminfo_command,
.mode = COMMAND_ANY,
.help = "display free heap space",
},
{
.name = "meminfo",
.handler = handle_meminfo_command,
.mode = COMMAND_ANY,
.help = "display free heap space",
},
{
.name = "mac",
.mode = COMMAND_ANY,
.jim_handler = ioutil_Jim_Command_mac,
.help = "show MAC address",
},
{
.name = "mac",
.mode = COMMAND_ANY,
.jim_handler = ioutil_Jim_Command_mac,
.help = "show MAC address",
},