# Check existing project file for valid contents and grab sections
#
if {![regexp {[ ]*(program|library)[ ]*([^;]*);.((.*)uses.([^;]*);.)?(.*)begin.(.*)} [$oldProject contents] total prjType prjName dummy1 grab1 usesBody grab2 remain]} {
m4_error $E_PRJCONTENTS
return $newProject
}
if {![regexp {(.*)[ ]*end\..*(// Do not delete this block -- regeneration marker -- start)(.*)(// Do not delete this block -- regeneration marker -- end)} $remain total grabCode dummy1 genuses dummy2]} {
m4_error $E_PRJCONTENTS
return $newProject
}
#
# Grab generated uses in existing project file
#
set tempList [split $genuses "\n"]
foreach line $tempList {
if {[regexp {^[ ]*//[ ]*([^ ]+)$} $line total name]} {
set genUsesList [linsert $genUsesList 0 $name]
}
}
#
# Create project type and name
#
if {$prjName == "<default>"} {
set prjName $projectName
}
$newProject append "${prjType} ${prjName};"
$newProject append $grab1
#
# Create uses list
#
set usesList [split $usesBody "\n"]
if {$uses != ""} {
$newProject append "\nuses\n"
$newProject indent +
set first 1
set oldremain ""
foreach line $usesList {
if {[regexp {^[ ]*(([^ ,;]+)([ ]+in[ ]+[^ ,;]+)?)([,;])?([ ]*.*)$} $line total name unitname filename dummy remain]} {