HAND CODED C++ / PERL - SAMPLES

PERL ROUTINE - All Code is for Demo Use Only

  *** 1995 - PERL PAGER INSTANT MESSENGER ROUTINE + USER INTERFACE
1  
Here's where you can find out about all the latest happenings at Continental Cablevision of Jacksonville! When can you get your pager, internet and cable television services on the same bill? Look here and find out! Content is updated regularly, so be sure to check back often!
 
Page Me!  

HSD Internet Paging Application

Please select the person you wish to page:

Please enter your name:

Enter a brief alphanumeric message, then press enter or click Page Me! Your message can be no longer than 80 characters.

 

#!/usr/sbin/perl5

# cgi-snpppage
# accept request for page from HTML form
#
# Dante Dionne v1.0 5/18/96
#
# Input parameters (via a POST or GET method):
#
# msg alphanumeric message to be sent with page (required)
# name originator of message (optional)
# pagerid numeric pager identification (required)
# host paging server hostname (required)
#
# An alphanumeric message of the form:
#
# message [name]
#
# is sent to the specified 'pagerid' at the paging server 'host'.

require "ccse-lib.pl";

# Parse input into associative array 'in'.

if (!(&ReadParse(*in))) {
&CgiError("No input supplied");
exit;
}

($pin,$junk) = split (/ /, $in{"pagerid"}, 2);

# Make sure that all the required parameters were supplied.

if ($in{"msg"} eq "") {
&CgiError("No message was specified");
exit;
}

if ($pin eq "") {
&CgiError("No pager ID was specified");
exit;
}

if ($in{"host"} eq "") {
&CgiError("No host was specified");
exit;
}

# construct message string.

$pagetext = $in{"msg"} . " [" . $in{"name"} . "]";

require "snpplib.pl";

# subroutine to catch any SNPP failure.

sub fail {
$save = &snpp'error;
&snpp'close;
&CgiError($save);
exit;
}

# send message to paging server.

&snpp'open($in{"host"}) || &fail;
&snpp'pagerid($pin) || &fail;
&snpp'message($pagetext) || &fail;
&snpp'send || &fail;
&snpp'close;

# return HTML form to caller.

print &PrintHeader;
print &HtmlTop("Message sent");
print "<B>$pagetext</B>\n<p><B>Sent to: $junk</B>\n";
print &HtmlBot;
 

 

PERL SCRIPT - All Code is for Demo Use Only

  ** 1996 - PERL LOGIN SCRIPT - INTEGRATING JAVASCRIPT, HTML & TEXT FILE FOR USER LOGIN ACCESS
2 #!/usr/bin/perl

print "Content-type: text/html\n\n";

# Get input for the first time.
&get_input_first;

# Get back button include.

# Will die if password is no good.
&verify_password;

# Read test file
&read_testfile;

# Write test header
&write_header;

# Print hidden data & test footer.
&print_footer;


###############
# subroutines #


########################
sub get_input_first {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
if ($FORM{$name} eq "") {

print "<body bgcolor=\"ffffff\">";
print "<h2>You must enter the required information.\n";
print "<p>Please try again.\n";
die;
}
}
}


##################
sub get_back {

open (BACK,"../back.jav") || print "Can't open back button.";
open (BACK,"../back.jav") || die "Can't open back button.";
push(@backlink, $_) while(<BACK>);
close (BACK);
}


########################
sub verify_password {

open (LIST,"./passwd.txt") || print "Can't open password file.";
open (LIST,"./passwd.txt") || die "Can't open password file.";
push(@passwd, $_) while(<LIST>);
close (LIST);
foreach (@passwd) {

$_ =~ tr/A-Z/a-z/;
}

$pass = $FORM{'password'};
$pass =~ tr/A-Z/a-z/;
$pchek = $FORM{'p2'};
$pchek =~ tr/A-Z/a-z/;

$correct_pass = 0;
$authorization = 0;

open (PASS,">./passwd.txt") || print "<p>Someone else is accessing the password file; please try re-submitting.<p><a href=\"JavaScript:history.go(-1);\">(back)</a>";
open (PASS,">./passwd.txt") || die;

for ($i = 0; $i <= $#passwd; $i++) {

split(':', $passwd[$i]);

if (@_[7] =~ /\n/) {

chop (@_[7]);
}

# if (@_[6] eq $pass && @_[6] eq $pchek) {

if (@_[6] eq $pass) {

$correct_pass = 1;
if (@_[7] >= 1 && $authorization == 0) {

$authorization = 1;
@_[7]--;

push (@pinfo, @_);

}
}

if (@_[7] == 0) {

open (T,">>./expired");
close (T);
print "<body bgcolor=\"ffffff\"><center><p><h2>Your password has expired.<br>Thank you for using CyberTest.<p><a href=\"JavaScript:history.go(-1);\">(back)</a>";
die;
} else {
$_ = join(':', @_);
print(PASS"$_\n");
}

}


flock(PASS, 8);
close (PASS);


$message = "<body bgcolor=\"ffffff\"><center><p><h2>You have entered an invalid password.</h2><p><h3>Please go <a href=\"JavaScript:history.go(-1);\">back</a> and re-enter your password.";
if ($correct_pass != 1) {

print $message;
die;
}

if ($authorization != 1) {

print "<p><h2>You are not authorized to take a test.<p><a href=\"JavaScript:history.go(-1);\">(back)</a>";
die;
}
}


##################
sub read_testfile {

open (TEST,"../tests/@pinfo[0].txt") || print "Can't open test file.";
open (TEST,"../tests/@pinfo[0].txt") || die "Can't open test file.";
push(@testdata, $_) while(<TEST>);
close (TEST);
}


#####################
sub write_header {

print "<HEAD><META HTTP-EQUIV=\"Content-language\" CONTENT=\"en\"><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
print "<TITLE>proveit on cyberTest</TITLE><LINK REV=made href=\"mailto:support\@proveit.com\"><META NAME=\"keywords\" CONTENT=\"\">\n";
print "<META NAME=\"description\" CONTENT=\"Virtual Learning Technologies\"><META NAME=\"rating\" CONTENT=\"General\">\n";
print "<META NAME=\"revisit-after\" CONTENT=\"365 days\"><META NAME=\"ROBOTS\" CONTENT=\"NONE\"><META NAME=\"DC.title\" CONTENT=\"TechTest\">\n";
print "<META NAME=\"DC.creator\" CONTENT=\"Know It All\"><META NAME=\"DC.subject\" CONTENT=\"Internet Based Testing and Skill Assessment\">\n";
print "<META NAME=\"DC.description\" CONTENT=\"Virtual Learning Technologies\"><META NAME=\"DC.publisher\" CONTENT=\"Virtual Learning Technologies\">\n";
print "<META NAME=\"DC.language\" CONTENT=\"ENG\"></HEAD>\n";
&timerscript;
&valscript;
&tstamp;
print "<p align=\"left\">&nbsp;</p><h1 align=\"center\"><font color=\"#000080\">Welcome to Prove It!</font></h1>\n";
print "<blockquote><p align=\"center\">Please answer all questions. When you have completed the test, enter your name and the password you were given to take the test in the boxes provided.</p><hr>\n";
&post;

}


#######
sub timerscript {

open (TIME,"../timerSript.jav") || print "Can't open timer file.";
open (TIME,"../timerSript.jav") || die "Can't open timer file.";
push(@timejav, $_) while(<TIME>);
close (TIME);
print "@timejav";
}


#######
sub valscript {

open (VALID,"../valScript.jav") || print "Can't open validate file.";
open (VALID,"../valScript.jav") || die "Can't open validate file.";
push(@validjav, $_) while(<VALID>);
close (VALID);
print "@validjav";
}


#######
sub tstamp {

open (TSTAMP,"../tStamp.jav") || print "Can't open time stamp file.";
open (TSTAMP,"../tStamp.jav") || die "Can't open time stamp file.";
push(@tstampjav, $_) while(<TSTAMP>);
close (TSTAMP);
print "@tstampjav";
}


#######
sub post {

open (POST,"../post.jav") || print "Can't open post file.";
open (POST,"../post.jav") || die "Can't open post file.";
push(@postjav, $_) while(<POST>);
close (POST);
print "@postjav";
}


#####################
sub print_footer {

print "@testdata";
print "<input type=\"hidden\" name=\"testname\" value=@pinfo[0]>\n";
print "<input type=\"hidden\" name=\"First_Name\" value=@pinfo[1]>\n";
print "<input type=\"hidden\" name=\"Company_Name\" value=@pinfo[2]>\n";
print "<input type=\"hidden\" name=\"SS_NUM\" value=@pinfo[3]>\n";
print "<input type=\"hidden\" name=\"CUST_ID\" value=@pinfo[4]>\n";
print "<input type=\"hidden\" name=\"admine\" value=@pinfo[5]>\n";
print "<input type=\"hidden\" name=\"password\" value=@pinfo[6]>\n";
print "<input type=\"hidden\" name=\"credits\" value=@pinfo[7]>\n";

open (FORM,"../form.jav") || print "Can't open form file.";
open (FORM,"../form.jav") || die "Can't open form file.";
push(@formjav, $_) while(<FORM>);
close (FORM);
print "@formjav";

}

Text File: 496935:dante:vlt:111223333:9500:dante@ccse.net:dante:48

C++ APPLICATION - All Code is for Demo Use Only

  *** 1995 - PHONEBOOK APP
3 // A simple file maintenance program which
// can add or update entries
//
#include <fstream.h>
#include <ctype.h>

struct PhoneList
  {
    char name[31];
    char phone[21];
  };

// Function prototypes
void Add(fstream& phone);
void Update(fstream& phone);
void List(fstream& phone);

void main()
  {
    char answer = ' '; 
    // Declare the stream
    fstream phone("phone.lst",ios::in | ios::out);
   
    if (!phone) // If phone file has not been opened
      {
        cout << "*** Error opening file phone.lst ***";
        return;
      }
   
    while (1) // Do forever
      {
        cout << endl << "(A)dd, (U)pdate, (L)ist, (Q)uit? ";
        cin >> answer;
        cin.ignore(80,'\n');
        cout << endl;
       
        switch (toupper(answer)) // Allow single test
          {
            case 'A':
              Add(phone);
              break;
            case 'U':
              Update(phone);
              break;
            case 'L':
              List(phone);
              break;
            case 'Q':
              return;
          }
      }
    }
//-------------------------------------------------------------
// Add a phone entry
//   
void Add(fstream& phone)
  {
    PhoneList entry = {0};
   
    cout << "What is the name? ";
    cin.getline(entry.name,31);
    cout << "What is the number? ";
    cin.getline(entry.phone,21);
   
    phone.seekg(0,ios::end); // Move to end of file
    phone.write((char*)&entry,sizeof(PhoneList));
  }
//-------------------------------------------------------------
// Add a phone entry
//   

void Update(fstream& phone)              
  {
    PhoneList entry = {0};
    const int size = sizeof(PhoneList);
    int count = 0;

    cout << "Enter entry number :" ;
    cin >> count;
    cin.ignore(80,'\n');
    if (count < 1)
      {
        cout << "Error - not a valid entry" << endl;
        return;
      }
   
    // Find record
    phone.seekg(size*(count - 1),ios::beg); // Find it
    phone.read((char*)&entry,size);         // Read it
    if (phone.bad() || phone.eof())         // Check for error
      {
        cout << "Error - not a valid entry" << endl;
        phone.clear();               // Clear error flags
        return;
      }

    cout <<  count  << ": "         // Confirm entry
            << entry.name << '\t'
            << entry.phone << endl;
    cout << "New name (blank for cancel)? ";
    cin.getline(entry.name,31); 
    if (entry.name[0] == '\0') // Quick zero length test
      return;
    cout << "New number? ";
    cin.getline(entry.phone,21);

    phone.seekg(size*(count - 1),ios::beg); // Find it again
    phone.write((char*)&entry,size);        // Write it
  }

void List(fstream& phone)
  {     
    PhoneList entry;
    int count = 0;

    cout << "Name\tNumber" << endl;
    phone.seekg(0,ios::beg); // Set position to beginning
    while (!phone.eof())     // While more entries
     {
       phone.read((char*)&entry,sizeof(PhoneList));
       if (phone.eof())      // Eof not set till after end
         break;
       cout << ++count << ": "
            << entry.name << '\t'
            << entry.phone << endl;
     }
    phone.clear();           // Reset eof flag
  }
 

 

C++ APPLICATION - All Code is for Demo Use Only

  *** 1995 - C++ - INFORMATION LOOKUP APP
4 // A simple in-memory property database program. Through a menu,
// the user decides if he or she wants to see a property
// database on the screen or search for a specific property.
#include <iostream.h>
#include <string.h>   // For strcmp()                    

void DisplayMenu();
int  GetAnswer();
void DisplayProps(char * code[], float price[],
                  char * addr[], float commPer[]);
void SearchProps(char * code[], float price[],
                 char * addr[], float commPer[]);

// Eight properties maximum due to next constant
int const NUM = 8;

void main()
{
  int ans;
  // Define the program's data in parallel arrays
  // A code that uniquely identifies each property
  char * code[NUM] = { "231DV", "821WQ", "199OI", "294JU",
                       "901RE", "829BN", "483LQ", "778AS" };
  // The price of each property
  float price[NUM] = { 89432.34, 123029.34, 321293.95,
                       214293.20, 68402.92, 421034.53,
                       232456.54, 432123.40};
   // The address of each property
   char * addr[NUM] = { "919 N. Elm", "2202 West Sycamore",
                        "7560 E. 26th Pl.", "213 W. 104th Ave",
                        "123 Willow Rd.", "5629 S. 188th",
                        "45 North Harvard", "17093 Lansford" };
   // The broker's commission on each property
   float commPer[NUM] = {.072, .07, .065, .091,
                         .078, .0564, .102, .0834 };
  do
  {
    DisplayMenu();
    ans = GetAnswer();

    switch (ans)
    { case (1) : { DisplayProps(code, price, addr, commPer);
                   break; }
      case (2) : { SearchProps(code, price, addr, commPer);
                   break; }
      case (3) : { return;
                   break; }   // "unreachable code"
    }   // If user entered bad value, while loop will repeat
  } while (ans != 3);   // Keep looping until return takes over
  return;
}
//*********************************************************
void DisplayMenu()
{   // Display a menu for the user
  cout << endl << endl;
  cout << "\t\t** Property Database Menu **" << endl << endl;
  cout << "Here are your choices:" << endl << endl;
  cout << "\t1. Look at the property listing" << endl;
  cout << "\t2. Search for a property by its code" << endl;
  cout << "\t3. Quit the program" << endl;
  cout << endl << "What is your choice? ";
  return;
}
//*********************************************************
int GetAnswer()
{   // Get the user's menu choice
  int ans;   // Local variable also named ans
  cin >> ans;   // Answer to menu
  cin.ignore(80,'\n');
  return (ans);
}
//*********************************************************
void DisplayProps(char * code[], float price[],
                  char * addr[], float commPer[])
{   // Display a list of properties
  int ctr;   // for-loop control variable
  cout.precision(2);
  cout.setf(ios::showpoint);
  cout.setf(ios::fixed);
  for (ctr = 0; ctr < NUM; ctr++)
    {
      cout << endl << "Code: " << code[ctr]
           << "\t Price: $" << price[ctr] << endl;
      cout << "Address: " << addr[ctr] << endl;
      cout << "Commission percentage: "
           << commPer[ctr] * 100.0 << "%" << endl << endl;
      if (ctr == 3)   // Don't scroll off too fast
        {
          cout << "Press enter to continue...";
          cin.ignore(80,'\n');
        }
    }
  cout << "Press enter to continue...";
  cin.ignore(80,'\n');

  return;
}
//*********************************************************
void SearchProps(char * code[], float price[],
                 char * addr[], float commPer[])
 {   // Ask the user for a property code and display match
   int ctr;         // for-loop control variable
   int found = 0;   // Initially not found
   char buf[6];      // Code plus null zero size
   // Get the search key
   cout << "I'll now search for a specific property." << endl;
   cout << "What is the property's code? ";
   cin.getline(buf, 6);
   for (ctr = 0; ctr < NUM; ctr++)
     {
       if (!strcmp(code[ctr], buf))
         {
           cout << endl << "Code: " << code[ctr]
                << "\t Price: $" << price[ctr] << endl;
           cout << "Address: " << addr[ctr] << endl;
           cout << "Commission percentage: "
                << commPer[ctr]*100.0
                << "%" << endl << endl;   // Show as a percent
           found = 1;
           break;
         }
      }
   if (!found)
     {
       cout << endl << "* I'm sorry, but I don't find code "
            << buf;
     }
  return;
 }

 

ANSII C / C++ COMING SOON - All Code is for Demo Use Only

  *** 1995
5