home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 April
/
PCWorld_2004-04_cd.bin
/
software
/
temacd
/
remotany
/
RemotelyAnywhere.msi
/
File.sma
< prev
next >
Wrap
Text File
|
2003-08-19
|
6KB
|
255 lines
////////////////////////////////////////////////////////////////////////////////
// //
// RemotelyAnywhere Sample 'SMALL' Scripts //
// //
// RemotelyAnywhere provides a mechanism for scripting via a built-in //
// language. The language is called Small, and more information about //
// it can be found at http://compuphase.com/small.htm. //
// //
// Before you use these sample scripts, you should tailor their //
// behavior to better suit your configuration and your needs. //
// //
// This script demonstrates a simple form that takes user input and then //
// processes it via a callback function. //
// //
// THIS SOFTWARE IS PROVIDED BY 3AM LABS LTD ``AS IS'' AND //
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE //
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE //
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL //
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS //
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) //
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT //
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY //
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF //
// SUCH DAMAGE. //
// //
////////////////////////////////////////////////////////////////////////////////
#include <ra>
//
// Main program. Print out the form that will take input from the user.
//
public main()
{
// Begin output
htmlBeginOutput("File handling");
// Draw a dialog box
htmlBeginDialog("Dump file");
// Start an input form
htmlBeginForm();
// Set up the input form
htmlWrite("<TABLE><TR><TD><!FFONT!>Dump using</TD></TR><TR><TD><!FFONT!>");
htmlRadioButton("type", "1", true);
htmlWrite("Byte<BR></TD></TR><TR><TD><!FFONT!>");
htmlRadioButton("type", "2");
htmlWrite("Word<BR></TD></TR><TR><TD><!FFONT!>");
htmlRadioButton("type", "4");
htmlWrite("Double word<BR></TD></TR></TABLE><BR><TABLE><TR><TD><!FFONT!>Width:</TD><TD>");
htmlEdit("width", "16");
htmlWrite("</TD></TR><TR><TD><!FFONT!>File:</TD><TD><!FFONT!>");
htmlEdit("file");
htmlWrite("</TD></TR></TABLE><BR>");
// Set up the submit button. It will call the function dump() in this script.
htmlButton("Dump", "dump");
// Finish the form
htmlWrite(" ");
htmlButtonBack("Back", false);
htmlEndForm();
htmlEndDialog();
htmlEndOutput();
}
//
// The dump() callback function.
//
public dump()
{
//
// Start output
//
htmlBeginOutput("File handling");
new param[64]="", f, g, w;
//
// Read the 'type' parameter
//
htmlGetParam("type", param);
g=atoi(param);
//
// Read the 'width' parameter
//
htmlGetParam("width", param);
w=atoi(param);
//
// Try to open the file specified in the 'file' parameter
//
if (g!=0 && htmlGetParam("file", param) &&
(f=fopen(param, FILE_READ)))
{
new buf[1024], out[4], format[2];
new rd, p=0;
//
// Set up the page header
//
sprintf(buf, "Dump of \"%s\": <BR><BR></CENTER><PRE>", param);
htmlWrite(buf);
//
// Create the format string according to the output type
// (byte, word, dword)
//
if (g==1) {
sprintf(format, "%%02x ");
} else if (g==2) {
sprintf(format, "%%04x ");
} else {
sprintf(format, "%%08x ");
}
//
// Attempt to read from the file
//
rd=fread(f, buf, 4096);
//
// Main loop
//
do {
new i=0, j, k, t, val;
//
// Loop until we run out of bytes in the buffer
//
while (i<rd) {
//
// Display the offset
//
sprintf(out, "%08x: ", p);
htmlWrite(out);
//
// Display each byte, word or dword in the buffer
//
for (j=0; j<w*g; j+=g) {
//
// Convert the value to word or dword if
// neccessary
//
val=0;
for (k=0; k<g && i+j+k<rd; k++) {
t=gb(buf, i+j+k);
t<<=k*8;
val+=t;
}
//
// If end of buffer
//
if (k==0) {
if (g==1) {
strcpy(out, " ");
} else if (g==2) {
strcpy(out, " ");
} else {
strcpy(out, " ");
}
} else {
//
// Display the hex dump
//
sprintf(out, format, val);
}
htmlWrite(out);
}
htmlWrite(" ");
//
// Display the ASCII representation of the HEX data
//
out{1}=0;
for (j=0; j<w*g && i+j<rd; j++) {
val=gb(buf, i+j);
if (val>=32 && val<128)
out{0}=val;
else
out{0}='.';
// The output needs to be converted
// to html format according to the
// special characters that might
// appear so we pass "true" in the
// "htmlize" parameter overriding
// its default value
htmlWrite(out, true);
}
htmlBR();
i+=j;
p+=j;
}
//
// Loop until we reach the end of the file
//
rd=fread(f, buf, 4096);
} while (rd>0);
fclose(f);
htmlWrite("</PRE><BR><CENTER>");
} else {
htmlWrite("<BR>File not found!<BR>");
}
htmlButtonBack();
htmlEndOutput();
}