Production in Euphoria

a white paper

4/15/2005 Michael James Raley (Thinkways-at-yahoo.com)


Sample code : the error class accumulator

This snippet of code shows part of a program designed to read
a list of errors from a report file.
If that type of error message is found within the sequence
"error_class" it will increment the count for that type of
error, otherwise it will append the new type of error into
the sequence and start counting it.
 
 constant err_type = 1 err_count = 2 
 
 error_line = "" 

 sequence error_class
 error_class = {{" ."},{0}}
    
 atom class_find class_find = 0
 ...........(snipped out for brevity)....
  
  class_find = find(line,error_class[err_type])
   if class_find then 
    error_class[err_count][class_find] += 1
   else 
    error_class[err_type] = append(error_class[err_type], line) 
    error_class[err_count] = append(error_class[err_count], 1)
   end if 

Sample code : calling FTP

Here we create a master include file to hold standard date information then create a short FTP program control program to get a file and rename it locally using the Day of the week
{filename : SYSTEM_DATE.E}
global object
 TheDate,
 Name_of_Month, SumMonths,
 Name_of_Day,   GD_Month,  
 GD_Day,        GD_Year,   
 GD_Julian,     TheYear,  
 TheMonth,      TheDay,
 TheJulian,
 numday,        weekdays

-------Current Date sequence-------------------------
    TheDate   = date() --{YYY}{MM}{DD}{HH}{MM}{SS}{DOW}{DOY}
    TheYear   = TheDate[1]-100  --(Euphoria counts from 1900!) 
    TheMonth  = TheDate[2] 
    TheDay    = TheDate[3] 
    TheJulian = TheDate[8]
    numday    = TheDate[7] 

  weekdays= {"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"}
  Name_of_Day = weekdays[numday]
(eof)
(filename : MyFTP.exw) 

 include SYSTEM_DATE.E
 include MISC.E
 include PASSWORDS.E
 include FILE.E

 atom handle ,  df
 constant screen = 1 

 df = open("ftpmacro.get","w") --write a short macro file
 puts(df,"user\n") --first line of file is the FTP user command
 puts(df, FTP_USER)--write using a user name defined in PASSWORDS.E 
 puts(df, FTP_PWD) --write using a password defined in PASSWORDS.E
 puts(df,"get TESTFILE TESTFILE" & Name_of_Day &".txt\n")
 puts(df,"bye\n") -- write command to tell FTP your done 
 close(df) -- close your FTP Macro file

--tell the FTP program to connect to hostaname using our macro file
 handle = system_exec("ftp -i -n -v -s:ftpmacro.get hostname.org")
--test the file directory to see if it exists locally 
 
  if sequence(dir("TESTFILE" & Name_of_Day &".txt"))
    then
      puts(screen ,"a File was found on" & Name_of_Day)
    else 
      puts(screen ,"a File was not found on" & Name_of_Day)
   end if 

By using the Modular design that we only have to modify a little bit of information if we want to create a differnt FTP control program. We can create a series of programs by simply cloning MyFTP.exw and changing only the literal information such as hostname that require it.

Hosted by www.Geocities.ws

1