# Converts the font size and name in a LiveMath File. # # I know there are almost no commetns inside, but I hope things are # somewhat self-explanatory. If you have questions, email me # # ivo@livemath.com # $szFileVersion = '3,5,0,15'; @htm_files = ('.htm', '.html', '.shtml', '.Htm', '.Html', '.Shtml', '.SHtml', '.HTM', '.HTML', '.SHTML'); $searchdir = `pwd`; ($searchdir =~ /\/$/)?():($searchdir =~ s/$/\//) ; $nodirs = 'true'; &parse_data; $searchdir =~ s/\s*$//; if (($ok ne 'HELP') && ($ok ne 'INPUTERROR')) { &find_files; if ($ok ne 'NOSUCHDIR') { &modify_files; } } if ($ok ne 'INPUTERROR') { &return_msg; } sub parse_data { @params = @ARGV; $ok = 'NOPARAMS' ; foreach $param (@params) { ($name, $value) = split(/=/, $param); $value =~ tr/+/ /; if (($ok ne 'DEFAULT') && ($ok ne 'HELP') && ( ! ( $param =~ /^perl/i) ) && ($param ne 'pl2ax.pl')) { $ok = 'PARAMS' ; if ($name =~ /searchdir/i) { $searchdir = $value ; if ( ! ( $value =~ /^\//) ) { $searchdir = `pwd`."\/".$value; $searchdir =~ s/[\n\r]// ; ($searchdir =~ /\/$/)?():($searchdir =~ s/$/\//) ; } } elsif ($name =~ /default/i) { $ok = 'DEFAULT' ; } elsif ($name =~ /help/i) { $ok = 'HELP' ; } elsif ($name =~ /nodirs/i) { $nodirs = $value ; } elsif ($name =~ /ext/i) { push(@htm_files, $value) ; } } if ($ok eq 'DEFAULT') { $searchdir = `pwd`; } } if ($ok =~ /NOPARAMS/i) { $ok = 'DEFAULT' ; } # User input if ($ok ne 'HELP') { print "\n\n"; print "For details on usage, start the script with parameter help:\n" ; print "perl5 pl2ax.pl help\n\n\n" ; $ok = 'OK' ; if ($ok ne 'INPUTERROR') { print "\n\n"; print "Have you backed up all of your files? (Yes/No)\n" ; if ( ! ( =~ /^yes/i ) ) { print "\n\n"; print "Your files are going to be changed by this script!\n" ; print "There is no automatic backup provided with it.\n\n" ; print "We DO require that you fully understand this and you need\n" ; print "to answer Yes to the question above in order to proceed.\n\n" ; print "Thank you\n\n" ; $ok = 'INPUTERROR' ; } } if ($ok ne 'INPUTERROR') { print "\n\n"; print "Current directory: $searchdir\n" ; print "Press Enter to confirm, or type a new directory:\n" ; $ui = ; if ( ! ( $ui =~ /^$/i ) ) { print "\n\n"; $searchdir = $ui ; if ( ! ( $searchdir =~ /^\//) ) { $searchdir = `pwd`."\/".$searchdir; $searchdir =~ s/[\n\r]// ; ($searchdir =~ /\/$/)?():($searchdir =~ s/$/\//) ; } print "New directory is $searchdir\n" ; print "If you want another one, cancel the script while answering\n" ; print "the last question here and start over.\n" ; } } if ($ok ne 'INPUTERROR') { print "\n\n"; print "Do you want to search all subdirectories also?\n" ; print "Current setting is ".(($nodirs =~ /true/i)?("Yes"):("No"))."\n" ; print "Press Enter to confirm, or type a new choice (Yes/No):\n" ; $ui = ; if ( ! ( $ui =~ /^$/i ) ) { if ( $ui =~ /^yes/i ) { $nodirs = 'true' ; } else { $nodirs = 'false' ; } print "\n\n"; print "New choice is ".(($nodirs =~ /true/i)?("Yes"):("No"))."\n" ; print "If you want another one, cancel the script while answering\n" ; print "the last question here and start over.\n" ; } } if ($ok ne 'INPUTERROR') { print "\n\n"; print "Here is what you asked for:\n\n" ; print "Directory: $searchdir \n" ; print "Search subdirectories: ".(($nodirs =~ /true/i)?("Yes"):("No"))."\n\n" ; print "Are you sure this is correct? (Yes/No)\n" ; if ( ! ( =~ /^yes/i ) ) { print "\n\n"; print "Your files are going to be changed by this script!\n" ; print "There is no automatic backup provided with it.\n\n" ; print "We DO require that you fully understand this and you need\n" ; print "to answer Yes to the question above in order to proceed.\n\n" ; print "Thank you\n\n" ; $ok = 'INPUTERROR' ; } } if ($ok ne 'INPUTERROR') { print "\n\n"; print "Are you double-sure you want to do the conversion? (Yes/No)\n" ; if ( ! ( =~ /^yes/i ) ) { print "\n\n"; print "Your files are going to be changed by this script!\n" ; print "There is no automatic backup provided with it.\n\n" ; print "We DO require that you fully understand this and you need\n" ; print "to answer Yes to the question above in order to proceed.\n\n" ; print "Thank you\n\n" ; $ok = 'INPUTERROR' ; } } } } sub find_files { if ( chdir($searchdir) ) { $ls_all = `ls -R`; $ls_all = ':'.$ls_all; @dirs = split ( /\s+\.\// , $ls_all ) ; foreach $file (@htm_files) { foreach $dir ( @dirs ) { ($cdir , $ls) = split ( /\:/ , $dir ) ; @ls = split(/\s*\n\s*/,$ls); foreach $temp_file (@ls) { $tf = $cdir.'/'.$temp_file; $tf =~ s/^\///; if (((-T $tf) && ($tf =~ s/$file/$file/e)) && (($nodirs ne "false") || ($cdir eq ""))) { push(@HTM_FILES,$tf); } } } } } else { $ok = 'NOSUCHDIR' ; } } sub modify_files { foreach $FILE (@HTM_FILES) { print "Now working on $FILE\n"; $ls = `ls -l \"$FILE\"`; @ls = split ( / / , $ls ) ; $_ = $ls[0] ; $mod = 0 ; $mod += (/.r......../ ? 400 : 0 ) ; $mod += (/..w......./ ? 200 : 0 ) ; $mod += (/...x....../ ? 100 : 0 ) ; $mod += (/....r...../ ? 40 : 0 ) ; $mod += (/.....w..../ ? 20 : 0 ) ; $mod += (/......x.../ ? 10 : 0 ) ; $mod += (/.......r../ ? 4 : 0 ) ; $mod += (/........w./ ? 2 : 0 ) ; $mod += (/.........x/ ? 1 : 0 ) ; $cmd = "chmod 0777 \"$FILE\""; `$cmd` ; # Get system type open(FILE,"$FILE"); @LINES = ; close(FILE); $FILETEXT = join ( 'ThiSisGoNNabethescriptnewwww09091723line!' , @LINES ) ; if ($FILETEXT =~ /\r\n/) { $ft = 'Win' ; } elsif ($FILETEXT =~ /\r/) { $ft = 'Mac' ; $FILETEXT =~ s/\r/ThiSisGoNNabethescriptnewwww09091723line\!/gs ; } elsif ($FILETEXT =~ /\n/) { $ft = 'Unix' ; } else { $ft = 'Mac' ; } $FILETEXT =~ s/[\r\n]//gs ; $FILETEXT =~ s/ThiSisGoNNabethescriptnewwww09091723line\!/\n/gs ; $LINES = $FILETEXT ; $_ = $LINES ; # We do the next loop twise -- once for tags with type=plugin/x-theorist # once for tags without it while ( /^(.*?)\<\s*embed(.*?)type\s*\=\s*\"{0,1}plugin\/x\-theorist\"{0,1}(.*?)\>(.*)$/sig ) { # We have to make sure we are not covering longer than a tag print "\n\nYo\n\n"; if ((!($2 =~ /\<\s*?object/sig)) && (!($2 =~ /\<\s*?embed/sig))){ $TAG = "\"; $B_TAG = $1; $A_TAG = $4 ; $_ = $TAG; if (/width\s*\=\s*\"{0,1}(\d*?)\D/sig){ $WIDTH = $1; }else{ $WIDTH = '300'; } $_ = $TAG; if (/height\s*\=\s*\"{0,1}(\d*?)\D/sig){ $HEIGHT = $1; }else{ $HEIGHT = '200'; } $_ = $TAG; if (/bgcolor\s*\=\s*\"{0,1}(\#......)/sig){ $BGCOLOR = $1; }else{ $BGCOLOR = 'None'; } $_ = $TAG; if (/exprcode\s*\=\s*\"(.*?)\"/sig){ $EXPRCODE = $1; }else{ $EXPRCODE = 'None'; } $_ = $TAG; if (/src\s*\=\s*\"(.*?)\"/sig){ $SRC = $1; }else{ $_ = $TAG; if (/src\s*\=\s*?(.*?)\s/sig){ $SRC = $1; }else{ $_ = $TAG; if (/src\s*\=\s*?(.*?)\>/sig){ $SRC = $1; }else{ $SRC = 'None'; } } } $OB_TAG = "\"; $OB_TAG = $OB_TAG."\"; if ($SRC ne 'None') { $OB_TAG = $OB_TAG."\";} if ($BGCOLOR ne 'None') { $OB_TAG = $OB_TAG."\"; } if ($EXPRCODE ne 'None') { $OB_TAG = $OB_TAG."\"; } $OA_TAG = "\No Support for LM Objects\<\/noembed\>\<\/object\>"; $TAG =~ s/\>$/ \>/; $TAG =~ s/pluginspage\s*\=\s*(.*?)\s/thatsthepluginspageofthelivemathfontconvertor02135626/gis; $TAG =~ s/type\s*\=\s*(.*?)\s/type\=\"plugin\/x\-theorist\" /is; $_ = $TAG ; if ( /type\s*\=/ ) { $TAG =~ s/thatsthepluginspageofthelivemathfontconvertor02135626/ pluginspage\=\"http\:\/\/www\.livemath\.com\/3\.0\/\?type\=downplug\&lang\=enl\" /gis; } else { $TAG =~ s/thatsthepluginspageofthelivemathfontconvertor02135626/ pluginspage\=\"http\:\/\/www\.livemath\.com\/3\.0\/\?type\=downplug\&lang\=enl\" type\=\"plugin\/x\-theorist\" /gis; } $TAG =~ s/embed/livemathfontconvertertemptag0113/gis; $_ = $A_TAG; if ( /^(.*?)\<\/object\>/gis ) { if ( $1 =~ /\(.*)$/sig ) { # We have to make sure we are not covering longer than a tag if ((!($2 =~ /\<\s*?object/sig)) && (!($2 =~ /\<\s*?embed/sig)) && (!($3 =~ /\<\s*?object/sig)) && (!($3 =~ /\<\s*?object/sig))){ $TAG = "\"; $B_TAG = $1; $A_TAG = $5 ; $SRC = $3."\.thp"; $_ = $TAG; if (/width\s*\=\s*\"{0,1}(\d*?)\D/sig){ $WIDTH = $1; }else{ $WIDTH = '300'; } $_ = $TAG; if (/height\s*\=\s*\"{0,1}(\d*?)\D/sig){ $HEIGHT = $1; }else{ $HEIGHT = '200'; } $_ = $TAG; if (/bgcolor\s*\=\s*\"{0,1}(\#......)/sig){ $BGCOLOR = $1; }else{ $BGCOLOR = 'None'; } $_ = $TAG; if (/exprcode\s*\=\s*\"(.*?)\"/sig){ $EXPRCODE = $1; }else{ $EXPRCODE = 'None'; } $OB_TAG = "\"; $OB_TAG = $OB_TAG."\"; $OB_TAG = $OB_TAG."\"; if ($BGCOLOR ne 'None') { $OB_TAG = $OB_TAG."\"; } if ($EXPRCODE ne 'None') { $OB_TAG = $OB_TAG."\"; } $OA_TAG = "\No Support for LM Objects\<\/noembed\>\<\/object\>"; $TAG =~ s/\>$/ \>/; $TAG =~ s/pluginspage\s*\=\s*(.*?)\s/thatsthepluginspageofthelivemathfontconvertor02135626/gis; $TAG =~ s/type\s*\=\s*(.*?)\s/type\=\"plugin\/x\-theorist\" /is; $_ = $TAG ; if ( /type\s*\=/ ) { $TAG =~ s/thatsthepluginspageofthelivemathfontconvertor02135626/ pluginspage\=\"http\:\/\/www\.livemath\.com\/3\.0\/\?type\=downplug\&lang\=enl\" /gis; } else { $TAG =~ s/thatsthepluginspageofthelivemathfontconvertor02135626/ pluginspage\=\"http\:\/\/www\.livemath\.com\/3\.0\/\?type\=downplug\&lang\=enl\" type\=\"plugin\/x\-theorist\" /gis; } $TAG =~ s/embed/livemathfontconvertertemptag0113/gis; $_ = $A_TAG; if ( /^(.*?)\<\/object\>/gis ) { if ( $1 =~ /\$FILE"); foreach $LINE (@LINES) { if ($ft =~ /Win/) { $LINE =~ s/$/\r\n/gs; } elsif ($ft =~ /Mac/) { $LINE =~ s/$/\r/gs; } elsif ($ft =~ /Unix/) { $LINE =~ s/$/\n/gs; } else { $LINE =~ s/$/\r\n/gs; } print FILE $LINE ; } close(FILE); $cmd = "chmod $mod \"$FILE\"" ; `$cmd` ; } } sub return_msg { if ($ok eq 'OK') { open(LOGFILE,"\>pl2ax.log"); print LOGFILE "\n"; print LOGFILE "The following parameters were used:\n"; print LOGFILE "-----------------------------------------------------------------\n"; print LOGFILE "searchdir = $searchdir\n"; print LOGFILE "nodirs = $nodirs\n\n\n\n"; print LOGFILE "The following files (in no particular order) were found:\n"; print LOGFILE "-----------------------------------------------------------------\n"; foreach $FILE (@HTM_FILES) { print LOGFILE "$searchdir$FILE\n"; } close(LOGFILE); print "\n"; print "The following parameters were used:\n"; print "-----------------------------------------------------------------\n"; print "searchdir = $searchdir\n"; print "nodirs = $nodirs\n\n\n\n"; print "The following files (in no particular order) were found:\n"; print "-----------------------------------------------------------------\n"; foreach $FILE (@HTM_FILES) { print "$searchdir$FILE\n"; } print "\nYour log file is pl2ax.log\n"; } elsif ($ok eq 'NOSUCHDIR') { print "\nYour search directory was set to:\n"; print "$searchdir\n"; print "-----------------------------------------------------------------\n\n"; print "The change directory command did not secceed!\n"; print "Most probably, there is no such directory. Please, check the spelling again.\n\n"; } else { print "\nUsage:\n"; print "-----------------------------------------------------------------\n\n"; print "The converter will go through a directory of MathView/Theorist Plug-In\n"; print ".html/.htm files, and change the following HTML tags \n"; print "required for running the plugin under MS Internet Explorer 5.5+:\n\n"; print "1. Changing the tags\n"; print " Our great friends at Microsoft Corporation discontinued support\n"; print " for Netscape style plugins and required ActiveX technology to \n"; print " replace these plugins. So we did our part and created a new ActiveX\n"; print " plugin. Now you have to do your part and modify a little bit your web\n"; print " pages to host it.\n\n"; print "To use this script, you must have PERL installed on your webserver. \n"; print "If you are an inexperienced user, you may wish to give this \n"; print "script to your System Administrator, and ask them to run it for you. \n\n"; print "Note, that your pages should contain correct HTML. Otherwise, this script\n"; print "May not be able to recognize your tags and may not work properly!\n"; print "Especially if your existing \ tags are messed up!\n\n"; print "Command Line for Running This Script:\n"; print "% perl5 pl2ax.pl searchdir=/usr/lm/fontchange/ nodirs=true ext=.php ext=.php3\n\n"; print "You can specify as many extensions as you wish. These will be added to \n"; print "the default list of extensions which includes HTM, HTML and SHTML\n\n"; print "If the parameter searchdir is omitted, the current directory will be serached.\n"; print "NODIRS parameter set to true means no subdirectories will be processed. The \n"; print "default value of FALSE means that all subdirectories will be processed.\n\n"; } }