#
#  writetm.pl
#
#  This package allows the user to easily create a TaskMaster model of a 
#  project and have it write to a properly formatted TaskMaster file.
#
#  Copyright (C) 1993 Lighthouse Design Ltd.
#
#  You may freely copy, distribute, and reuse the code in
#  this example provided this copyright legend and disclaimer
#  are preserved in all copies and derivative work.
#
#  Lighthouse Design disclaims any warranty of any kind,
#  expressed or implied, as to this code's fitness
#  for any particular use.
#

package writetm;

$numTasks = 1;			# root task
$numResources = 3;		# root res, unassigned, expenses
$numCalendars = 1;              # root resource calendar hard wired
$numAssignments = 0;		# none to start with
$numDependencies = 0;		# none to start with
$projectStartDate = "";

sub main'setProjectName{ # project name
    $projectName = $_[0];
}

sub main'setProjectManager{ # project manager
    $projectManager = $_[0];
}

sub main'setProjectStartDate{ # project start date
    $projectStartDate = $_[0];
}

sub main'setProjectEndDate{ # project end date for end on
    $projectEndDate = $_[0];
}

sub main'setDefaultCalendar{ # default calendar name
    $defaultCalendar = $_[0];
}

sub main'addTask{ #ID Name Type Outline StartDate Duration ConstraintType ConstraintDate Expenses LevelPrio Subtitle Notes

    ++$numTasks;
    ($taskID{$numTasks},$taskName{$numTasks},$taskType{$numTasks},$taskOutline{$numTasks}, $taskStartDate{$numTasks}, $taskDuration{$numTasks}, $taskConstraintType{$numTasks}, $taskConstraintDate{$numTasks}, $taskExpenses{$numTasks}, $taskLevelPrio{$numTasks}, $taskSubtitle{$numTasks}, $taskNotes{$numTasks}) = @_;
    if(!$taskOutline{$numTasks}){
	$ignoreOutlines = 1;
    }elsif($taskOutline{$numTasks} !~ /(.*\.)?\d+\.$/){
	print "Adding . -> $taskOutline{$numTasks}\n";
	$taskOutline{$numTasks} .= ".";
	if($taskOutline{$numTasks} !~ /(.*\.)?\d+\.$/){
	    print "Really bad outline number -> $taskOutline{$numTasks}\n";
	    $ignoreOutlines = 1;
	}
    }
    if($taskOutline{$numTasks} =~ /(.*\.)\d+\./){
	if($taskChildren{$1}){
	    $taskChildren{$1} ++;
	}else{
	    $taskChildren{$1} = 1;
	}
    }
	
    if(!$taskConstraintType{$numTasks}){
	$taskConstraintType{$numTasks} = "Earliest";
	$taskConstraintDate{$numTasks} = "7/1/93 0:00:00";
    }elsif(!$taskConstraintDate{$numTasks}){
	$taskConstraintDate{$numTasks} = "today";
    }
    if(!$taskType{$numTasks}){
	$taskType{$numTasks} = "Task";
    }
    $taskIndexOutline{$taskOutline{$numTasks}} = $numTasks;
    $taskIndexID{$taskID{$numTasks}} = $numTasks;
    $taskIDName{$taskName{$numTasks}} = $taskID{$numTasks};
    if(!$earliestTaskStartDate || ($taskStartDate{$numTasks} && &earlier($taskStartDate{$numTasks}, $earliestTaskStartDate))){
	$earliestTaskStartDate = $taskStartDate{$numTasks};
    }
    return $numTasks;
}

sub main'taskIDFromName{ # Name
    return $taskIDName{$_[0]};
}

sub main'taskIDFromOutline { #outline
    return $taskID{&taskIndexFromOutline($_[0])};
}

sub main'taskIndexFromOutline { #outline
    return $taskIndexOutline{$_[0]};
}

sub main'taskIndexFromID { # outline
    return $taskIndexID{$_[0]};
}

sub main'resetWriteTM {
    undef(%resourceID);
    undef(%resourceName);
    undef(%resourceQuantity);
    undef(%resourceIDName);
    undef(%resourceIndexID);
    undef(%resourceCalendarName);
    undef(%pricePerUse);
    undef(%pricePerDay);
    undef(%calendarName);
    undef(%calendarIndexFromName);
    undef(%holidayDates);
    undef(%hoursS);
    undef(%hoursM);
    undef(%hoursT);
    undef(%hoursW);
    undef(%hoursTh);
    undef(%hoursF);
    undef(%hoursSa);
    undef(%assignmentWorkTime);
    undef(%assignmentQuantity);
    undef(%assignmentEffort);
    undef(%taskID);
    undef(%taskName);
    undef(%taskType);
    undef(%taskOutline);
    undef(%taskStartDate);
    undef(%taskDuration);
    undef(%taskConstraintType);
    undef(%taskConstraintDate);
    undef(%taskExpenses);
    undef(%taskLevelPrio);
    undef(%taskSubtitle);
    undef(%taskNotes);
    undef(%taskChildren);
    undef(%taskHasAssignments);
    undef(%taskIndexOutline);
    undef(@holidays);
    undef(%dependFrom);
    undef(%dependTo);
    undef($ignoreOutlines);
    $numTasks = 1;			# root task
    $numResources = 3;		# root res, unassigned, expenses
    $numCalendars = 1;              # root resource calendar hard wired
    $numAssignments = 0;		# none to start with
    $numDependencies = 0;		# none to start with
    $projectStartDate = "";
}
    
sub main'addResource{ #ID Name Quant $PerDay $PerUse $calendarName

    ++$numResources;
    ($resourceID{$numResources}, $resourceName{$numResources}, $resourceQuantity{$numResources}, $pricePerDay{$numResources}, $pricePerUse{$numResources}, $resourceCalendarName{$numResources}) = @_;
    $resourceQuantity{$numResources} = int($resourceQuantity{$numResources}+0.5);
    $resourceIDName{$resourceName{$numResources}} = $resourceID{$numResources};
    $resourceIndexID{$resourceID{$numResources}} = $numResources;
}

sub main'resourceIDFromName{ # Name
    return $resourceIDName{$_[0]};
}

sub main'resourceIndexFromID{ #ID
    return $resourceIndexID{$_[0]};
}

sub main'addCalendar{ # Name HoursS HoursM HoursT HoursW HoursTh HoursF HoursS HolidayDate HolidayDate ...
    $numCalendars ++;
    ($calendarName{$numCalendars}, $hoursS{$numCalendars}, $hoursM{$numCalendars}, $hoursT{$numCalendars}, $hoursW{$numCalendars}, $hoursTh{$numCalendars}, $hoursF{$numCalendars}, $hoursSa{$numCalendars}, @holidays) = @_;
    foreach $holidayDate (@holidays){
	if($holidayDates{$numCalendars}){
	    $holidayDates{$numCalendars} .= "-".$holidayDate;
	}else{
	    $holidayDates{$numCalendars} = $holidayDate;
	}
    }		
    $calendarIndexFromName{$calendarName{$numCalendars}} = $numCalendars;
}

sub main'addCalendarCopyOf {  # newCalendarName, oldCalendarName
    local($newCalendarName, $oldCalendarName) = @_;
    (local($index) = $calendarIndexFromName{$oldCalendarName}) || return 0;

    $numCalendars++;
    $calendarName{$numCalendars} = $newCalendarName;
    $hoursS{$numCalendars} = $hoursS{$index};
    $hoursM{$numCalendars} = $hoursM{$index};
    $hoursT{$numCalendars} = $hoursT{$index};
    $hoursW{$numCalendars} = $hoursW{$index};
    $hoursTh{$numCalendars} = $hoursTh{$index};
    $hoursF{$numCalendars} = $hoursF{$index};
    $hoursSa{$numCalendars} = $hoursSa{$index};
    $holidayDates{$numCalendars} = $holidayDates{$index};
    $calendarIndexFromName{$newCalendarName} = $numCalendars;
}

sub main'setCalendarHoursForDay{ # calendarName, dayNumber(1=Sun), hours
    local($calendarName, $dayNumber, $hours) = @_;
    (local($index) = $calendarIndexFromName{$calendarName}) || return 0;
    if($dayNumber == 1){
	$hoursS{$index} = $hours;
    }elsif($dayNumber == 2){
	$hoursM{$index} = $hours;
    }elsif($dayNumber == 3){
	$hoursT{$index} = $hours;
    }elsif($dayNumber == 4){
	$hoursW{$index} = $hours;
    }elsif($dayNumber == 5){
	$hoursTh{$index} = $hours;
    }elsif($dayNumber == 6){
	$hoursF{$index} = $hours;
    }elsif($dayNumber == 7){
	$hoursSa{$index} = $hours;
    }
}
    
sub main'addCalendarHolidays{ # calendarName, holidayDate
    local($calendarName, @holidayDateList) = @_;
    (local($index) = $calendarIndexFromName{$calendarName}) || return 0;
    foreach $holidayDate (@holidayDateList){
	if($holidayDates{$index}){
	    $holidayDates{$index} .= "-".$holidayDate;
	}else{
	    $holidayDates{$index} = $holidayDate;
	}
    }
}

sub main'calendarFromName{ #calendarName
    return $calendarIndexFromName{$_[0]};
}

sub main'addAssignment{ # TaskID ResourceID WorkTime Quantity %effort
    $numAssignments++;
    ($assignmentTaskID, $assignmentResourceID, $assignmentWorkTime{$numAssignments}, $assignmentQuantity{$numAssignments}, $assignmentEffort{$numAssignments}) = @_;
    $assignmentTask{$numAssignments} = $taskIndexID{$assignmentTaskID};
    $assignmentResource{$numAssignments} = $resourceIndexID{$assignmentResourceID};
    $taskHasAssignments{$assignmentTask{$numAssignments}} = 1;
    $assignmentQuantity{$numAssignments} = int($assignmentQuantity{$numAssignments}+0.5);
}

sub main'addDependency{ # FromTaskID ToTaskID
    $numDependencies++;
    ($dependFromID, $dependToID) = @_;
    $dependFrom{$numDependencies} = $dependFromID;
    $dependTo{$numDependencies} = $dependToID;
}

sub main'outputToFile{ # filename, existingInterfaceFile
    local($filename, $interfaceFile) = @_;
    local($coretextFilename) = $filename . "/CoreText.tmdata";

    if(!&resolve()){
	# messages will be printed out by resolve
	exit 0;
    }

    if((-f "$coretextFilename")){
	print "$filename exists, overwriting\n";
    }elsif((!mkdir($filename, 0775))){
	die "Couldn't create $filename - exiting.";
    }
    if(!open(TMFILE, ">$coretextFilename")){
	die "Couln't open $coretextFilename";
    }
    select((select(TMFILE), $| = 1)[0]);

    if($interfaceFile){
	`cp $interfaceFile $filename`;
    }

    &checkStructure();
    &output();
}

#
#  Local Subroutines
#
sub resolve{
    local($ct);

    #resolve assignments resources and tasks
    for($ct = 1; $ct <= $numAssignments; $ct++){
	if(!$assignmentTask{$ct} || !$assignmentResource{$ct}){
	    print STDERR "Error: couldn't resolve Assignment\n";
	    return 0;
	}
	if($taskType{$assignmentTask{$ct}} eq "Group"){
	    print STDERR "Error: assignment made to group\n";
	}
    }

    # check for unassigned and expenses resource assignments needed
    for($ct = 2; $ct <= $numTasks; $ct++){
	if($taskType{$ct} eq "Task"){
	    if($taskExpenses{$ct}>0){
		$numAssignments++;
		$assignmentTask{$numAssignments} = $ct;
		$assignmentResource{$numAssignments} = 3;
		$assignmentWorkTime{$numAssignments} = "0d";
		$assignmentQuantity{$numAssignments} = int($taskExpenses{$ct}+0.5);
	    }
	    if($taskDuration{$ct} && !$taskHasAssignments{$ct}){
		$numAssignments++;
		$assignmentTask{$numAssignments} = $ct;
		$assignmentResource{$numAssignments} = 2;
		$assignmentWorkTime{$numAssignments} = $taskDuration{$ct};
		$assignmentQuantity{$numAssignments} = 1;
	    }
	}
    }

    # resolve resource calendars
    if($numResources <= 3){
	$numResources++;
	$resourceID{$numResources} = "Default guy";
	$resourceName{$numResources} = "";
	$resourceQuantity{$numResources} = 1;
	$pricePerDay{$numResources} = 0;
	$pricePerUse{$numResources} = 0;
	if($defaultCalendar){
	    $resourceCalendarName{$numResources} = $defaultCalendar;
	}
    }
    for($ct = 4; $ct <= $numResources; $ct++){
	if($resourceCalendarName{$ct} && !$calendarIndexFromName{$resourceCalendarName{$ct}}){
	    print STDERR "Error: couldn't resolve calendar for: $resourceName{$ct}\n";
	    return 0;
	}
    }

    #resolve depends to,from
    for($ct = 1; $ct <=$numDependencies; $ct++){
	$dependFrom{$ct} = $taskIndexID{$dependFrom{$ct}};
	$dependTo{$ct} = $taskIndexID{$dependTo{$ct}};
	if(!$dependFrom{$ct} || !$dependTo{$ct}){
	    print STDERR "Error: couldn't resolve Dependency\n";
	    return 0;
	}
    }

    return 1;
}

sub checkStructure{
    print "Checking Structure...\n";
    if($ignoreOutlines){
	return 1;
    }

    if($numTasks == 1){
	&main'addTask(1,"","Task",1);
    }
    for($count=2; $count <= $numTasks; $count++){ 
	if($taskOutline{$count} =~ /(.*\.)\d+\./){
	    if(!$taskIndexOutline{$1}){
		$numTasks++;	
		$taskName{$numTasks} = "**Unexported Group Task**";
		$taskNotes{$numTasks} = "NOTE:Group task $1 wasn't exported.";
		$taskIndexOutline{$1} = $numTasks;
		$taskOutline{$numTasks} = $1;
		$taskLevelPrio{$numTasks} = 0;
		$taskSubtitle{$numTasks} = "";
		$taskType{$numTasks} = "Group";
		$taskConstraintType{$numTasks} = "Earliest";
		$taskConstraintDate{$numTasks} = "1/1/1970";
	    }
	}
	if($taskChildren{$taskOutline{$count}} && $taskType{$count} !~ /^Group/){
	    $outlineNum = $taskOutline{$count};
	    $numTasks++;	
	    $taskName{$numTasks} = "**Group Task**";
	    $taskIndexOutline{$outlineNum} = $numTasks;
	    $taskOutline{$numTasks} = $outlineNum;
	    $taskLevelPrio{$numTasks} = 0;
	    $taskSubtitle{$numTasks} = "";
	    $taskType{$numTasks} = "Group";
	    $taskChildren{$numTasks} = $taskChildren{$count};
	    $newNum = $taskChildren{$taskOutline{$count}}+1;
	    $taskChildren{$outlineNum} = 0;
	    $taskConstraintType{$numTasks} = "Earliest";
	    $taskConstraintDate{$numTasks} = "1/1/1970";

	    $taskOutline{$count}.= "$newNum.";
	    $taskIndexOutline{$taskOutline{$count}} = $count;
	    $taskNotes{$numTasks} = "NOTE:Task $taskName{$count} was moved to $taskOutline{$count}, it wasn't a group task";
	}
    }
    return 1;
}

sub output{
#
#  Print out the file...
#
    print "Writing...\n\n";
#
# Header
#
    print TMFILE "#!GP_CORE_TEXT-Version-9\n";
    print TMFILE "#TaskMaster Output Perl script v1.0\n";
    print TMFILE "\n";

#
# Date/Duration stuff
#

    print TMFILE "DurationParser\n";
    print TMFILE "\tday 28800\n";
    print TMFILE "\tweek 144000\n";
    print TMFILE "\tmonth 604800\n";
    print TMFILE "\tyear 7200000\n";
    print TMFILE "\tdisplayRT 27\n";
    print TMFILE "\tdisplayWT 27\n";
    print TMFILE "end\n";
    print TMFILE "\n";
    print TMFILE "DateParser\n";
    print TMFILE "\tEuropean 0\n";
    print TMFILE "\tDateFormat 35\n";
    print TMFILE "end\n";
    print TMFILE "\n";

#
# Resources
#

    print TMFILE "# Resource Pool\n";
    print TMFILE "OutlineNumResource \"\"\n";
    print TMFILE "Resource 1\n";
    print TMFILE "\tName \"RootResource\"\n";
    print TMFILE "\tParent -1\n";
    print TMFILE "\tUseCost 0 0.00000\n";
    print TMFILE "\tTimeCost 3 0.00000\n";
    print TMFILE "\tQuantity 1\n";
    print TMFILE "end\n";

    print TMFILE "Resource 2\n";
    print TMFILE "\tName \"Unassigned Tasks\"\n";
    print TMFILE "\tParent 1\n";
    print TMFILE "\tUseCost 0 0.00000\n";
    print TMFILE "\tTimeCost 3 0.00000\n";
    print TMFILE "\tQuantity 1\n";
    if($defaultCalendar){
	&outputCalendar($defaultCalendar);
    }
    print TMFILE "end\n";

    print TMFILE "Resource 3\n";
    print TMFILE "\tName \"Expenses\"\n";
    print TMFILE "\tParent 1\n";
    print TMFILE "\tUseCost 0 1.00000\n";
    print TMFILE "\tTimeCost 3 0.00000\n";
    print TMFILE "\tQuantity -1\n";
    print TMFILE "end\n";
    $count = 4;
    while ($count <= $numResources){
	print TMFILE "Resource $count\n";
	print TMFILE "\tName \"$resourceName{$count}\"\n";
	print TMFILE "\tParent 1\n";
	if($pricePerUse{$count}){
	    printf(TMFILE "\tUseCost 0 %f\n", $pricePerUse{$count});
	}else{
	    print TMFILE "\tUseCost 0 0.00000\n";
	}
	if($pricePerDay{$count}){
	    printf(TMFILE "\tTimeCost 3 %f\n",$pricePerDay{$count});
	}else{
	    print TMFILE "\tTimeCost 3 0.00000\n"; 
	}
	print TMFILE "\tQuantity $resourceQuantity{$count}\n";
	if($resourceCalendarName{$count}){
	    &outputCalendar($resourceCalendarName{$count});
	}
	print TMFILE "end\n";
	$count++;
    }
    print TMFILE "\n";     

#
# Project Stuff
#
    if($projectName){
	print TMFILE "Project \"$projectName\"\n";
    }else{
	print TMFILE "Project \"Imported Project\"\n";
    }
    if($projectManager){
	print TMFILE "Manager \"$projectManager\"\n"; 
    }else{
	$manager = `/usr/ucb/whoami`;
	chop($manager);
	print TMFILE "Manager \"$manager\"\n"; 
    }
    print TMFILE "OutlineNumTask \"\"\n";
    print TMFILE "Alternative 1\n";
    print TMFILE "\tName \"Baseline\"\n";
    print TMFILE "end\n";
    print TMFILE "Alternative 2\n";
    print TMFILE "\tName \"Actual\"\n";
    print TMFILE "end\n";
    print TMFILE "\n";

#
# Tasks
#
    print TMFILE "Task 1\n";
    print TMFILE "\tParent -1\n";
    print TMFILE "\tTaskAlternative 1\n"; 
    if($projectStartDate ne ""){
	print TMFILE "\t\tStartOn ^$projectStartDate^\n";
    }elsif($projectEndDate ne ""){
	print TMFILE "\t\tEndOn ^$projectEndDate^\n";
    }elsif($earliestTaskStartDate && $earliestTaskStartDate ne "1/1/93"){
	print TMFILE "\t\tStartOn ^$earliestTaskStartDate^\n";
    }else{
	print TMFILE "\t\tStartOn ^1/1/93^\n";
    }
    print TMFILE "\tend\n";
    print TMFILE "end\n";
    &printTasksFrom("");
#
# Scenarios
#

    print TMFILE "Scenario\n";
    print TMFILE "\tName \"Baseline-Plan\"\n";
    print TMFILE "\tAlternativeIDs 1 2\n" ;
    print TMFILE "end\n";
    print TMFILE "Scenario\n";
    print TMFILE "\tName \"Baseline-Actual\"\n";
    print TMFILE "\tAlternativeIDs 2 1\n";
    print TMFILE "end\n";

#
# Dependencies
#

    for($count=1; $count <= $numDependencies; $count++){
	print TMFILE "Dependency $dependTo{$count} DependsOn $dependFrom{$count}\n";
	print TMFILE "\tDependencyAlternative 1\n";
	print TMFILE "\t\tRelationType 1\n";
	print TMFILE "\tend\n";
	print TMFILE "end\n";
    }

#
# Assignments
#

    for($count=1; $count <= $numAssignments; $count++){
	print TMFILE "ScheduledEvent $assignmentResource{$count} $assignmentTask{$count} 1\n";
	print TMFILE "\tPersonTime \"$assignmentWorkTime{$count}\"\n";
	if($assignmentEffort{$count}){
	    print TMFILE "\tEffort $assignmentEffort{$count}\n";
	}else{
	    print TMFILE "\tEffort 1.0000\n";
	}
	print TMFILE "\tPercentComplete 0.00000\n";
	print TMFILE "\tAssignment $assignmentResource{$count} $assignmentQuantity{$count}\n";
	print TMFILE "end\n";
    }
    print "Done Writing...\n\n";
    sleep (0.5);
}

sub outputCalendar { # calendar name
    $calendarIndex = $calendarIndexFromName{$_[0]};
    print TMFILE "\tCalendar\n";
    &outputWorkDay($hoursS{$calendarIndex});
    &outputWorkDay($hoursM{$calendarIndex});
    &outputWorkDay($hoursT{$calendarIndex});
    &outputWorkDay($hoursW{$calendarIndex});
    &outputWorkDay($hoursTh{$calendarIndex});
    &outputWorkDay($hoursF{$calendarIndex});
    &outputWorkDay($hoursSa{$calendarIndex});
    if($holidayDates{$calendarIndex}){
	@holidayDates = split(/-/,$holidayDates{$calendarIndex});
	print TMFILE "#\t\tHolidays\n";
	for($i=0; $i <= $#holidayDates; $i++){
	    print TMFILE "\t\tEvent \"1d\" ^$holidayDates[$i] 0:00:00^\n";
	}
    }
    print TMFILE "\tend\n";
}

sub outputWorkDay{ # hoursOfWork
    local($hours) = $_[0];
    local($off, $out);

    print TMFILE "\t\tWorkDay\n";
    if($hours){
	$off = (24 - $hours)/2;
	print TMFILE "\t\t\tOff \"${off}h\"\n";
	print TMFILE "\t\t\tOn  \"${hours}h\"\n";
	print TMFILE "\t\t\tOff \"${off}h\"\n";
    }else{
	print TMFILE "\t\t\tOff \"1d\"\n";
    }
    print TMFILE "\t\tend\n";
}

sub earlier {
    local($aDate, $bDate) = @_;
    
    if(!$aDate || !$bDate){
	return 0;
    }
    @aArray = split(/\//, $aDate);
    @bArray = split(/\//, $bDate);

    return ($aArray[2] < $bArray[2] || $aArray[0] < $bArray[0] || $aArray[1] < $bArray[1]);
}

sub printTasksFrom {
    local($currentOutline) = @_;
    local($count);
    if(!$ignoreOutlines){
	$currentOutline .= "1.";
	while ($count = $taskIndexOutline{$currentOutline}){
	    &outputTask($count);
	    &printTasksFrom($currentOutline);
	    $currentOutline = &increment($currentOutline);
	}	
    }else{
	for($count=2; $count<=$numTasks ;$count++){
	    &outputTask($count);
	}			
    }
}

sub outputTask{ # index
    local($count) = $_[0];

    print TMFILE "Task $count\n";
    print TMFILE "\tTitle \"$taskName{$count}\"\n";
    if($taskSubtitle{$count}){
	print TMFILE "\tSubtitle \"$taskSubtitle{$count}\"\n";
    }
    if($taskNotes{$count}){
	print TMFILE "\tUserField \"$taskNotes{$count}\"\n";
    }
    if($ignoreOutlines){
	print TMFILE "\tParent 1\n";
    }else{
	if($taskOutline{$count} =~ /(.*\.)\d+\./){
	    print TMFILE "\tParent $taskIndexOutline{$1}\n";
	}else{
	    print TMFILE "\tParent 1\n";
	}
    }
    if($taskLevelPrio{$count} > 0){
	print TMFILE "\tPriority $taskLevelPrio{$count}\n";
    }
    print TMFILE "\tTaskAlternative 1\n"; 
    print TMFILE "\t\t$taskConstraintType{$count} ^$taskConstraintDate{$count}^\n";
    print TMFILE "\tend\n";
    print TMFILE "end\n";
}		

sub increment {
    local($outlineNumber) = @_;
    local(@temp);
    if($outlineNumber){
	@temp = split(/\./, $outlineNumber);
	$temp[$#temp]++;
	$ret = join('.',@temp);
	$ret .= '.';
    }else{
	return ("1.");
    }
}

1;

# Place Emacs into Perl-mode
# Local Variables:
# mode: perl
# End:
