Sample Progress 4GL Logic to create mos_content Ok this is a scaled-down version of my Progress program.
It first builds a temp-table to hold all of the filenames (Progress program files) that are in a previously specified group of directories (I did not include the code that performs the functionality of reading and storing the directory names).
Then it uses the directory temp-table to processes each filename (program). It reads each individual line of the program into another temp-table so it can embed html (for color and hyperlinks) and exports the newly-formatted lines to a text file along with the sql commands that will be used to upload the data into the mambo database.
============================================
Procedure Read-Files-from-Directory:
============================================
/* Input from the selected directory. */
input from os-dir (cCurrentRootDirectory).
/* Loop and read all of the files from the directory. */
repeat:
/* Import the current file name. */
import cFileName cFileFullName.
/* Store the file name as a record in the temp-table. */
create gttFile.
assign gttFile.iFileNumber = (iFileNumber + 1)
gttFile.cFileName = cFileName
gttFile.FullName = cFileFullName
end.
=================================================
/* Setup the output stream. */
OUTPUT STREAM TextFile TO VALUE(cOutputFile).
/* For each file name in the temp-table: */
for each gttFile no-lock by gttFile.FullName:
/* Set the line counter and function counter. */
assign iLineNumber = 1.
/* Set the input source to be the current filename. */
input from value (gttFile.FullName).
/* Read and process each line of this program: */
repeat:
/* Read a line from the input file */
import unformatted cMosContentLine.
/* Place input line into temp-table replacing commas
with backslashes for Mambo. */
create gttContent.
assign gttContent.LineNumber = iLineNumber
gttContent.cFileName = gttFile.cFileName
gttContent.ContentLine = REPLACE (cMosContentLine, "'", '\').
/* Increment the line number. */
iLineNumber = (iLineNumber + 1).
end.
/* Process and format the program lines. */
run Process-Content.
/* Build & write the SQL stmt prefix that includes the file name. */
run WritePrefix (input gttFile.cFileName).
/* Write the program content to the output file. */
run WriteContent.
/* Build the end of the SQL command statement. */
run WriteEndStmt (input gttFile.cFileName).
end. /* for each gttFile */
/* Close the output stream. */
output close.
================================================== ===
Procedure Process-Content:
================================================== ===
/* For each content line in the temp-table: */
for each gttContent:
/* Save the line content to a local variable. */
cMosContentLine = gttContent.ContentLine.
/* Add some html formatting in the line here.... */
if index (cMosContentLine, '&ANALYZE-SUSPEND') > 0 and
index (cMosContentLine, '_PROCEDURE') > 0 and
index (cMosContentLine, '_PROCEDURE-SETTINGS') = 0 then
assign cMosContentLine =
process-procedure-header (input cMosContentLine).
/* Assign the newly formatted line back to the temp-table. */
assign gttContent.ContentLine = cMosContentLine.
end.
================================================== ====
Procedure WritePrefix:
================================================== ====
/* Build the record prefix. */
cRecordPrefix =
"INSERT INTO mos_content (title,title_alias,introtext,state,sectionid,catid ,created,created_by)
VALUES('" + pcFileName + "','" + pcFileName + "','".
/* Output the record prefix. */
run writeOutput (input cRecordPrefix).
================================================== =====
Procedure WriteContent:
================================================== =====
/* For each content line for this program: */
for each gttContent:
/* Write the content line to the output file. */
run writeOutput (input gttContent.ContentLine).
end.
================================================== ====
Procedure WriteEndStmt:
================================================== ====
/* Build the end statement. */
cMosEndStmt = cMosHTMLEnd + cMosState + cMosSectionId +
cMosCatId + cMosCreated + cMosCreatedBy +
chr(10) + chr(10).
/* Output the end of the statement. */
run writeOutput (input cMosEndStmt).
================================================== ===
Procedure writeOutput:
================================================== ===
define input parameter cInputLine as character no-undo format 'x(256)'.
/* Output the line to the text file. */
put stream Textfile unformatted cInputLine.
================================================== ====
This is a sample of the output text file that contains the mysql commands that will add the programs line by line into the mos_content database:
================================================== ======
INSERT INTO mos_content (title,title_alias,introtext,state,sectionid,catid ,created,created_by)
VALUES('ProgramName1.p','ProgramName1.p',
'<font color="#FFFFFF"><br><strong>Progress Program File 1 Content with embedded html tags...</strong><br>',
'1','10','83','0000-00-00 00:00:00','62');
INSERT INTO mos_content (title,title_alias,introtext,state,sectionid,catid ,created,created_by)
VALUES('ProgramName2.p','ProgramName2.p',
'<font color="#FFFFFF"><br><strong>Progress Program File 2 Content with embedded html tags...</strong><br>',
'1','10','83','0000-00-00 00:00:00','62');
================================================== =====
I am importing the data above by copy/pasting the file contents into a query window and running it.
Hope that helps,
Stacey |