[LON-CAPA-cvs] cvs: doc /help/course_manual buildTexxml.pl

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 04 Dec 2006 18:12:23 -0000


albertel		Mon Dec  4 13:12:23 2006 EDT

  Modified files:              
    /doc/help/course_manual	buildTexxml.pl 
  Log:
  - style
  - check that selection is valid
  
  
Index: doc/help/course_manual/buildTexxml.pl
diff -u doc/help/course_manual/buildTexxml.pl:1.1 doc/help/course_manual/buildTexxml.pl:1.2
--- doc/help/course_manual/buildTexxml.pl:1.1	Fri Dec  1 18:41:33 2006
+++ doc/help/course_manual/buildTexxml.pl	Mon Dec  4 13:12:22 2006
@@ -1,35 +1,44 @@
 #!/usr/bin/perl
+use strict;
 
 if ($#ARGV != 0) {
-  print "Correct command usage: \n";
-  print "   perl buildTexxml.pl all\n";
-  print "Or \n";
-  print "   perl buildTexxml.pl section\n";
+    print("Correct command usage: \n");
+    print("   perl buildTexxml.pl all\n");
+    print("Or \n");
+    print("   perl buildTexxml.pl section\n");
 }
 
-$option = $ARGV[0]; 
+my $option = $ARGV[0]; 
 
-@section = `cat section_order.txt`;
-chomp @section;
+my @section = `cat section_order.txt`;
+chomp(@section);
 
-if($option eq 'all') {
-  foreach $section (@section) {
-    $section='sections/'.$section;
-    $section_list=$section_list.$section.' ';
-  }
-  `cat sections/start.texxml $section_list sections/end.texxml > course.manual.texxml`;
+if ($option eq 'all') {
+    my $section_list;
+    foreach my $section (@section) {
+	$section_list .= 'sections/'.$section.' ';
+    }
+    system("cat sections/start.texxml $section_list sections/end.texxml > course.manual.texxml");
 }
 
-if($option eq 'section') {
-  print "Choose from the following manual sections:\n";
-  $num=0;
-  foreach $section (@section) {
-    print "$num - $section\n";
-    $num++;
-  }
-  print "Enter a number 0 - $num for the section you want to print: ";
-  $selection=<STDIN>;
-  print "builing section...\n";
-  `cat sections/start.texxml sections/$section[$selection] sections/end.texxml > section.manual.texxml`; 
+if ($option eq 'section') {
+    print("Choose from the following manual sections:\n");
+    my $num=0;
+    foreach my $section (@section) {
+	print("$num - $section\n");
+	$num++;
+    }
+    $num--;
+
+    print("Enter a number 0 - $num for the section you want to print: ");
+    my $selection=<STDIN>;
+    chomp($selection);
+
+    if ($selection < 0 || $selection > $#section) {
+	print("Invalid selection ($selection)\n");
+	exit(1);
+    }
+    print("builing section $section[$selection]\n");
+    system("cat sections/start.texxml sections/$section[$selection] sections/end.texxml > section.manual.texxml"); 
 }