Monday, June 15, 2009

Collect My Passport

The window opens from 13:30 to 16:00. I arrived 15:55. I hate LA's traffic.

Thursday, June 11, 2009

Ambiguous Extraction

Say you need to extract the id of Company A as originator ({pOriginatorName}) and Company A as underwriter ({pUnderwriterName}), what should you do when you encounter this response?

<html>
<head />
<body>
...
<select name="originator">
<option selected value="0">Company A</value>
<option value="1">Company B</value>
<option value="2">Company C</value>
</select>
...
<select name="underwriter">
<option value="-1">Please select</value>
<option value="9005">Company A</value>
<option value="9006">Company B</value>
</select>
...
</body>
</html>
Then it's time to use the XML functions provided by the good people of Mercury (now HP), first extract the options inside the select element by using web_reg_save_param function:
web_reg_save_param("pOriginatorIDText",
"LB/IC=name=\"originator\"",
"RB/IC=</select>",
"Ord=1",
"Search=body",
LAST);

web_reg_save_param("pUnderwriterIDText",
"LB/IC=name=\"underwriter\"",
"RB/IC=</select>",
"Ord=1",
"Search=body",
LAST);


Follow by the functions to extract the related values:
iNumOfValues = lr_xml_get_values("XML=<select {pOriginatorIDText}</select>",
"ValueParam=pCollectedOriginatorName",
"Query=/select/option",
"SelectAll=yes",
LAST);

iNumOfValues = lr_xml_get_values("XML=<select {pOriginatorIDText}</select>",
"ValueParam=pCollectedOriginatorID",
"Query=/select/option/@value",
"SelectAll=yes",
LAST);

for (i = 0; i < iNumOfValues; i++) {
sprintf(buf, "{pCollectedOriginatorName_%d}", i+1);
sprintf(buf, rtrim(lr_eval_string(buf)) );
sprintf(sParamName, "pCollectedOriginatorName_%d", i+1);
lr_save_string(buf, sParamName);

if (strcmp(buf, lr_eval_string("{pOriginatorName}")) == 0) {
lr_output_message("Originator name found");
sprintf (buf, "{pCollectedOriginatorID_%d}", i+1);
lr_save_string(lr_eval_string(buf), "pOriginatorID");
}

sprintf (buf, "Retrieved value %d : {pCollectedOriginatorName_%d}", i+1, i+1);
lr_output_message(lr_eval_string(buf));
}
//#####################################
iNumOfValues = lr_xml_get_values("XML=<select {pUnderwriterIDText}</select>",
"ValueParam=pCollectedUnderwriterName",
"Query=/select/option",
"SelectAll=yes",
LAST);

iNumOfValues = lr_xml_get_values("XML=<select {pUnderwriterIDText}</select>",
"ValueParam=pCollectedUnderwriterID",
"Query=/select/option/@value",
"SelectAll=yes",
LAST);

for (i = 0; i < iNumOfValues; i++) {
sprintf(buf, "{pCollectedUnderwriterName_%d}", i+1);
sprintf(buf, rtrim(lr_eval_string(buf)) );
sprintf(sParamName, "pCollectedUnderwriterName_%d", i+1);
lr_save_string(buf, sParamName);

if (strcmp(buf, lr_eval_string("{pUnderwriterName}")) == 0) {
lr_output_message("Underwriter name found");
sprintf (buf, "{pCollectedUnderwriterID_%d}", i+1);
lr_save_string(lr_eval_string(buf), "pUnderwriterID");
}

sprintf (buf, "Retrieved value %d : {pCollectedUnderwriterName_%d}", i+1, i+1);
lr_output_message(lr_eval_string(buf));
}

Yes, it looks complicated, but:
pOriginatorID = 0
pUnderwriterID = 9005

Mish Mash Of Different Version Work

This is weird, but LR controller v9.1 can talk & run scripts when paired with generator v7.8FP1, vice versa.

Test it this morning.

Wednesday, June 10, 2009

rtrim

Delete trailing spaces
char *rtrim(char * string)
{
while (strcmp(strrchr(string, ' '), " ") == 0) {
string[strlen(string)-1] = 0;
}
return string;
}
Googled this and can't find good solution.

Wednesday, June 3, 2009

Use PPM-Make To Make My Own PPM Repository

After getting tired of disappearing modules @ theoryx5.uwinnipeg.ca, and having to merge the files between several machines manually, I decided to build my own repository.

Luckily, Randy Kobes (the maintainer of theoryx5.uwinnipeg.ca) also releases PPM-Make to compile the code from scratch, together with the release of MinGW under PPM, these make my life a lot easier to compile and host the ppm myself.

Playing with the PPM-Make module for a while, I realized that I sorely need:
  1. To organize the directory structure
    • The .ppd & .tar.gz files: http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/
    • Archive (zip file for local install): http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/zips/
  2. Another option (I named it vsz) to insert the version of the module to the zip file name for archiving purposes.
After hacking and gluing everything together, I present Acme-Bleach from my repository. To install:
> ppm install http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/Acme-Bleach.ppd

I'll upload more modules as I get them successfully compiled and tested.

Tuesday, June 2, 2009

PPM-Make

Just research the PPM::Make problem on my desktop, it appears that it has v0.94, I need to upgrade it to v0.96, and that's not half of the problem: apparently the ppm repository at theoryx5.uwinnipeg.ca doesn't have v0.96. Surprise!

So I need to add tcool.org PPM repository:
> ppm repo add http://ppm.tcool.org/archives/package.xml

Researching the module again:
>ppm search ppm-make
1: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.940
Repo: theoryx5.uwinnipeg.ca

2: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.96
Repo: ppm.tcool.org

Remedy:
>ppm install 2 --force
Downloading PPM-Make-0.96...done
Downloading libwww-perl-5.826...done
Downloading version-0.76...done
Downloading IO-Compress-2.019...done
Downloading Compress-Raw-Bzip2-2.019...done
Downloading Compress-Raw-Zlib-2.019...done
Unpacking PPM-Make-0.96...done
Unpacking libwww-perl-5.826...done
Unpacking version-0.76...done
Unpacking IO-Compress-2.019...done
Unpacking Compress-Raw-Bzip2-2.019...done
Unpacking Compress-Raw-Zlib-2.019...done
Generating HTML for PPM-Make-0.96...done
Generating HTML for libwww-perl-5.826...done
Generating HTML for version-0.76...done
Generating HTML for IO-Compress-2.019...done
Generating HTML for Compress-Raw-Bzip2-2.019...done
Generating HTML for Compress-Raw-Zlib-2.019...done
Updating files in site area...done
169 files installed
8 files unchanged
22 files updated

Last, for $ENV{PATH} move C:\Perl5.8.8\site\bin to the front of C:\Perl5.8.8\bin