#!/usr/bin/perl # **** # # getpaper.pl v0.1 # # (c) Anthony D. Joseph, UC Berkeley ... 2003 # (c) MONET Research Group ... 2001 # # Using function "GetField" from bibsearch.pl (c) 1994 Andy Wood. # # This script will respond to a call with the following fields: # # 'action' - either listing or searching paper # 1) Listing papers: # 'area' - area of research papers, e.g. resource management, routing, etc. # 'type' - type of publications, e.g. conference, journal, etc. # 'interleave' - interleave types (default is no) # 'order' - print order: normal or reverse (default is normal) # 'highlight' - case-insensitive name to highlight (default is none) # 'shortAuthor' - shorten and reverse author names (default is no) # 'header' - add file header and footer (default is yes) # 'bold' - use bold instead of italic for format (default is yes) # 'startDate' - start date (YYYYMM) # 'endDate' - end date (YYYYMM) # 'recent' - show n most recent papers (sets interleave yes) # # 2) Searching papers: # 'term' - search term, e.g. qos, multimedia, etc. # 'searchfield' - search field, e.g. author, title, keywords, etc. # 'interleave' - interleave types (always on, can't override) # 'order' - print order: normal or reverse (default is normal) # 'highlight' - case-insensitive name to highlight (default is none) # 'shortAuthor' - shorten and reverse author names (default is no) # 'header' - add file header and footer (default is yes) # 'number' - add paper number (default is no) # 'startDate' - start date (YYYYMM) # 'endDate' - end date (YYYYMM) # 'recent' - show n most recent papers (sets interleave yes) # # When listing papers, it reads the BibTex file corresponding to a certain # research area, and writes out to html nicely. When searching papers, it # reads the BibTex files one by one and perform search on the requested field. # When a matched paper is found, it writes out to html. The key of each bibtex # entry is the file name of that paper. Use a key of "null.ps" for papers with # no paper file. # # MONET Research Group # Computer Science Department # Univ of Illinois at Urbana-Champaign # Urbana, Illinois, USA. # Homepage: http://www-monet.cs.uiuc.edu # Comments: Kai Chen # # **** require "getopts.pl"; # **** # # Configurations # # **** #@CONFIGFILES = ( "/export/sahara/d/prof/adj/public_html/publications/config" ); @CONFIGFILES = ( "./config" ); $BIBFILEDIR = ""; $PAPERFILEDIR = ""; $HEADERFILE = ""; $FOOTERFILE = ""; @bibfiles = (); $bibcount = 0; @fonts = (); $fontcount = 0; $pubcount = 0; # month to number mapping %months = ("January", "01", "February", "02", "March", "03", "April", "04", "May", "05", "June", "06", "July", "07", "August", "08", "September", "09", "October", "10", "November", "11", "December", "12"); # names of publication types %pubnames = ("book", "Book / Book Chapter", "journal", "Journal / Magazine", "conference", "Conference Paper", "report", "Technical Report", "phd", "Ph.D. Thesis", "master", "Master's Thesis"); # define every possible bib field and html output sequence. @elements = ( "author", "editor", "title", "booktitle", "journal", "edition", "chapter", "volume", "number", "pages", "series", "type", "organization", "school", "institution", "publisher", "address", "month", "year", "note"); # **** # # Main part of the script # # It first parses the input parameters, then calls the subroutines # according to the desired action (list or search paper). # # **** # Get user arguments &Getopts("e:"); # e for command line use with expression # Read in the parameters if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); } elsif ($opt_e) { $in = $opt_e; } # parse input pairs to retrieve 'area' and 'type' (default to "all") $user = 0; $action = "list"; $areaid = "all"; $type = "all"; $term = ""; $searchfield = ""; $interleave = "no"; $order = "normal"; $highlight = ""; $shortAuthor = "no"; $header = "yes"; $number = "no"; $startDate = ""; $endDate = ""; $recent = ""; $font = 0; $bold = "yes"; $titleBold = ""; $titleEndBold = ""; @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; # convert plus's to spaces ($key, $val) = split(/=/, $in[$i], 2); if ( $key eq "action" ) { $action = $val; } elsif ( $key eq "area" ) { $areaid = $val; } elsif ( $key eq "type" ) { $type = $val; } elsif ( $key eq "term" ) { $term = $val; } elsif ( $key eq "searchfield" ) { $searchfield = $val; } elsif ( $key eq "user" ) { $user = $val; } elsif ( $key eq "interleave" ) { $interleave = $val; } elsif ( $key eq "order" ) { $order = $val; } elsif ( $key eq "header" ) { $header = $val; } elsif ( $key eq "bold" ) { $bold = $val; } elsif ( $key eq "number" ) { $number = $val; } elsif ( $key eq "startDate" ) { $startDate = $val; } elsif ( $key eq "endDate" ) { $endDate = $val; } elsif ( $key eq "font" ) { $font = $val; } elsif ( $key eq "recent" ) { $recent = $val; $interleave = "yes"; } elsif ( $key eq "highlight" ) { $highlight = $val; $titleBold = ""; $titleEndBold = ""; } elsif ( $key eq "shortAuthor" ) { $shortAuthor = $val; } } if ( $bold ne "yes" ) { $titleBold = ""; $titleEndBold = ""; } if ( ($user > $#CONFIGFILES) || ($user < 0) ) { print "getpaper.pl: illegal user number: $user\n"; } &LoadConfig( $CONFIGFILES[$user] ); $numfiles = $#bibfiles / 4; #print "numfiles is $numfiles\n"; #print "BIBFILEDIR = $BIBFILEDIR\n"; #print "PAPERFILEDIR = $PAPERFILEDIR\n"; #print "HEADERFILE = $HEADERFILE\n"; #print "FOOTERFILE = $FOOTERFILE\n"; #foreach $i (0 .. $#bibfiles) { # print "bibfile $i = $bibfiles[$i]\n"; #} #foreach $i (0 .. $#fonts) { # print "font $i = $fonts[$i]\n"; #} # output header file if ( $header eq "yes" ) { &OutputFile( $HEADERFILE ); } if ( ($font > $#fonts) || ($font < 0) ) { print "getpaper.pl: illegal font number: $font\n"; } # take one of the actions if ( $action eq "list" ) { &ListPaper( $areaid, $type ); } elsif ( $action eq "search" ) { &SearchPaper( $term, $searchfield ); } else { print("getpaper.pl: action $action not supported.\n"); } # output footer file if ( $header eq "yes" ) { print "Found $pubcount publications.
\n"; &OutputFile( $FOOTERFILE ); } exit; sub LoadConfig { local( $filename ) = @_; open ( FILE, $filename) || print "getpaper.pl: Couldn't open config file - $filename\n"; local( $key, $val ); $/ = "\n"; # use new line as record seperator while ( $record = ) { # print "Read |$record| \n"; next if ( $record =~ /^\#.*/ ); # skip comment line next if ( $record =~ /^\s*$/ ); # skip blank lines if ( $record =~ /^\$(.*)\s*=\s*\"(.*)\".*/ ) { # ($key, $val) = split(/=/, $record, 2); $key = $1; $val = $2; # print "Key is $key, Value is $val \n"; # $val =~ s/^.*\"(.*)\".*$/$1/; # retrieve the value if ( $key =~ /$BIBFILEDIR\s*/i ) { $BIBFILEDIR = $val; } elsif ( $key =~ /$PAPERFILEDIR\s*/i ) { $PAPERFILEDIR = $val; } elsif ( $key =~ /$HEADERFILE\s*/i ) { $HEADERFILE = $val; } elsif ( $key =~ /$FOOTERFILE\s*/i ) { $FOOTERFILE = $val; } else { print "getpaper.pl: Unknown config file line - $record\n"; } } elsif ( $record =~ /^\@bibfile\s*=\s*\"(.*)\",\s*\"(.*)\",\s*\"(.*)\",\s*\"(.*)\".*/ ) { $bibfiles[$bibcount++] = $1; $bibfiles[$bibcount++] = $2; $bibfiles[$bibcount++] = $3; $bibfiles[$bibcount++] = $4; } elsif ( $record =~ /^\@font\s*=\s*\"(.*)\".*/ ) { $fonts[$fontcount++] = "\"$1\""; } else { print "getpaper.pl: Got config file line - $record\n"; } } close FILE; } # **** # # SearchPaper # # Search papers with a specific term (first argument) in a # specific field (second argument). All the bibtex files are # read and scanned. For each entry found, it prints out html text. # # **** sub SearchPaper { local( $term, $searchfield) = @_; if ( $header eq "yes" ) { print "

Search results with term \"$term\" in $searchfield field:

\n"; } # bib files to be processed foreach $i (0 .. $numfiles) { $files[$i] = $bibfiles[$i * 4 + 1]; $url[$i] = $bibfiles[$i * 4 + 3]; if ($url[$i] ne "") { $areanames[$i] = "" . $bibfiles[$i * 4 + 2] . ""; } else { $areanames[$i] = $bibfiles[$i * 4 + 2]; } } # Set output count to 0 for 0 entry $typeCount[0] = 0; $typeList[0][0] = ""; # search the papers in the bib files local( $foundSearch ) = 0; foreach $i ( 0 .. $#files ) { # print "Searching file $files[$i] ... \n"; # print "

$areanames[$i]

\n"; if ( $recent eq "" ) { # Set output count to 0 for 0 entry $typeCount[0] = 0; $typeList[0][0] = ""; } $foundSearch |= &SearchBibFile( $files[$i], $areanames[$i], $term, $searchfield ); } if ( $foundSearch == 0 ) { if ( $header eq "yes" ) { print "No publications found.
"; } } elsif ( $recent ne "" ) { if ($typeCount[0] > 0) { # Output papers for each type if ($number eq "yes" ) { print "
    \n"; } else { print "
      \n"; } &OutputPapers(0); if ($number eq "yes" ) { print "
\n"; } else { print "\n"; } } } } # **** # # SearchBibFile # # Search the bib file (first argument) with specific term # (second argument) in the requested field (third argument). # For each bib entry, it prints out the correspondent html # text as output. # # **** sub SearchBibFile { local( $filename, $aname, $term, $searchfield ) = @_; $filename = $BIBFILEDIR.$filename; open ( FILE, $filename) || print "

Couldn't open file - $filename


\n"; local( $found ) = 0; $/ = ""; # use blank lines as record seperator while ( $record = ) { if ( not ( $record =~ /@.*{/ )) { next; } # skip non-bibtex record local( $junk, $bibtex ) = split( '@', $record, 2 ); $bibtex = '@'.$bibtex; $fieldcontent = &GetField( $searchfield, $bibtex ); if ( $fieldcontent =~ /\b($term)\b/i ) { # exact match and case insensitive if ( $found == 0 ) { if ( $recent eq "" ) { print "


$aname

\n"; } $found = 1; # now have found } local( $firstline, $rest ) = split( ',', $bibtex, 2 ); local( $bibtype, $key ) = split( '{', $firstline, 2 ); $bibtype =~ s/^@(.*)\s*$/$1/; # retrieve the publication type $key =~ s/^\s*(.*)\s*$/$1/; # retrieve the key &MarkupOnePaper($key, $bibtex, $bibtype, 0 ); } } # end of while close FILE; # if ( $found == 0 ) { print "No publication found.\n"; } if ( $recent eq "" ) { if ($typeCount[0] > 0) { # Output papers for each type if ($number eq "yes" ) { print "

    \n"; } else { print "
      \n"; } &OutputPapers(0); if ($number eq "yes" ) { print "
\n"; } else { print "\n"; } } } return $found; } # **** # # ListPaper # # List papers in certain research area (first argument), and # with certain publication type (second argument). For each # entry found, it prints out html text. # # **** sub ListPaper { local( $areaid, $type ) = @_; # bib files to be processed if ( $areaid eq "all") { foreach $i (0 .. $numfiles) { $files[$i] = $bibfiles[$i * 4 + 1]; $url[$i] = $bibfiles[$i * 4 + 3]; if ($url[$i] ne "") { $areanames[$i] = "" . $bibfiles[$i * 4 + 2] . ""; } else { $areanames[$i] = $bibfiles[$i * 4 + 2]; } # print "File $i $files[$i] $areanames[$i]\n"; } } else { foreach $i (0 .. $numfiles) { if ($areaid eq $bibfiles[$i * 4]) { $files[0] = $bibfiles[$i * 4 + 1]; $url[0] = $bibfiles[$i * 4 + 3]; if ($url[0] ne "") { $areanames[0] = "" . $bibfiles[$i * 4 + 2] . ""; } else { $areanames[0] = $bibfiles[$i * 4 + 2]; } } } } # type of publications to be processed if ( $type eq "all") { @types = ("book", "journal", "conference", "report", "phd", "master"); if ( $header eq "yes" ) { if ( $areaid eq "all" ) { print "

List all publications in all research areas.

\n"; } else { print "

List all publications in the following research area.

\n"; } } } else { @types = ($type); if ( $areaid eq "all" ) { if ( $areaid eq "all" ) { print "

List $pubnames{$type} in all research areas.

\n"; } else { print "

List $pubnames{$type} in the following research area.

\n"; } } } # Set output count to 0 for each type local ( $ty ); foreach $ty (0 .. $#types) { $typeCount[$ty] = 0; $typeList[$ty][0] = ""; } # process the type of publication in each file foreach $i ( 0 .. $numfiles ) { local ( $foundarea ) = 0; foreach $j ( 0 .. $#types ) { # print "File $files[$i], Type $types[$j], J $j, FoundArea $foundarea
\n"; $foundarea = &ProcessBibFile($files[$i], $types[$j], $j, $foundarea); } if ( $foundarea && ($interleave eq "no" )) { print "


$areanames[$i]\n"; local ($k); foreach $k (0 .. $#types) { if ($typeCount[$k] > 0) { print "


$pubnames{$types[$k]}

\n"; if ($number eq "yes" ) { print "

    \n"; } else { print "
      \n"; } &OutputPapers($k); if ($number eq "yes" ) { print "
\n"; } else { print "\n"; } $typeCount[$k] = 0; $typeList[$k][0] = ""; } } } } # Output papers for each type if ( $interleave eq "yes" ) { if ( $recent ne "" ) { local ( $i, $k ); foreach $i (1 .. $#types) { if ($typeCount[$i] > 0) { foreach $k (0 .. ($typeCount[$i] - 1)) { $typeList[0][$typeCount[0]++] = $typeList[$i][$k]; } } } if ($number eq "yes" ) { print "
    \n"; } else { print "
      \n"; } &OutputPapers(0); if ($number eq "yes" ) { print "
\n"; } else { print "\n"; } } else { foreach $i (0 .. $#types) { if ($typeCount[$i] > 0) { print "


$pubnames{$types[$i]}

\n"; if ($number eq "yes" ) { print "

    \n"; } else { print "
      \n"; } &OutputPapers($i); if ($number eq "yes" ) { print "
\n"; } else { print "\n"; } } } } } } # **** # # ProcessBibFile # # Process the bib file (first argument) with specific type # of publications (second argument) for type number (third argument) # and the flag of whether this area has found at least one # paper (third argument). For each bib entry, it prints out # the correspondent html text as output. # # **** sub ProcessBibFile { local( $filename, $pubtype, $typeNum, $foundarea ) = @_; $filename = $BIBFILEDIR.$filename; open ( FILE, $filename) || print "

Couldn't open file - $filename


\n"; local( $found ) = 0; $/ = ""; # use blank lines as record seperator while ( $record = ) { if ( not ( $record =~ /@.*{/ )) { next; } # skip non-bibtex record # print "Record: $record\n"; local( $junk, $bibtex ) = split( '@', $record, 2 ); $bibtex = '@'.$bibtex; local( $firstline, $rest ) = split( ',', $bibtex, 2 ); local( $bibtype, $key ) = split( '{', $firstline, 2 ); $bibtype =~ s/^@(.*)\s*$/$1/; # retrieve the publication type $key =~ s/^\s*(.*)\s*$/$1/; # retrieve the key $bibtype = lc($bibtype); # print "$filename bibtype: $bibtype (looking for $pubtype)
\n"; # only process the correct publiction type next if ( $pubtype eq "book" ) && ( $bibtype ne "book" ) && ( $bibtype ne "inbook"); next if ( $pubtype eq "journal" ) && ( $bibtype ne "article" ); next if ( $pubtype eq "conference" ) && ( $bibtype ne "inproceedings" ); next if ( $pubtype eq "report" ) && ( $bibtype ne "techreport" ); next if ( $pubtype eq "master" ) && ( $bibtype ne "mastersthesis" ); next if ( $pubtype eq "phd" ) && ( $bibtype ne "phdthesis" ); if ( $found == 0 ) { #if ( $interleave eq "no") { # if ( $foundarea == 0 ) { # has this area found at least one paper ? #print "


$areanames[$i]\n"; # } #print "


$pubnames{$pubtype}

\n"; #} $found = 1; } &MarkupOnePaper($key, $bibtex, $bibtype, $typeNum ); } # end of while close FILE; if ( $foundarea == 0 ) { return $found; } else { return $foundarea; } } # **** # # MarkupOnePaper # # Print out html text for a paper. The first arguemnt is the key # of the bib entry (same as file name). The second arguemnt is the # whole bib entry. The third augument is the bib entry type. # The fourth argument is the paper type number. # # **** sub MarkupOnePaper { local( $key, $bibtex, $bibtype, $typeNumber ) = @_; ( $junk, $file_format ) = split( '\.', $key, 2 ); local ( $fieldcontent, $fieldname, $output, $month, $year ); $month = ""; $year = ""; $output = "

  • "; # each paper is a list item foreach $i (0 .. $#elements) { $fieldname = $elements[$i]; $fieldcontent = &GetField( $fieldname, $bibtex ); if ( $fieldcontent eq "" ) { next; } # non-exist field $filedname = lc($fieldname); # print out the html stuff for this paper if ( $fieldname eq "author" ) { $output .= &ParseAuthor($fieldcontent) . ", "; } elsif ( $fieldname eq "editor" ) { if ( $fieldcontent =~ /,/ ) { $output .= "$fieldcontent (Eds), "; } # more than one editor else { $output .= "$fieldcontent (Ed), "; } # only one editor } elsif ( $fieldname eq "title" ) { # use bold font for title $output .= $titleBold . $fieldcontent . $titleEndBold . ", "; } elsif ( $fieldname eq "booktitle" ) { if ( $bibtype eq "conference") { $output .= "In the Proceedings of $fieldcontent, "; } else { $output .= "$fieldcontent, "; } # others like books, etc. } elsif ( $fieldname eq "journal" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "edition" ) { $output .= "$fieldcontent edition, "; } elsif ( $fieldname eq "chapter" ) { $output .= "chapter $fieldcontent, "; } elsif ( $fieldname eq "volume" ) { $output .= "vol. $fieldcontent, "; } elsif ( $fieldname eq "number" ) { if ( $bibtype eq "techreport" ) { $output .= "$fieldcontent, "; } else { $output .= "num. $fieldcontent, "; } } elsif ( $fieldname eq "pages" ) { $output .= "pp. $fieldcontent, "; } elsif ( $fieldname eq "series" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "type" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "organization" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "school" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "institution" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "publisher" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "address" ) { $output .= "$fieldcontent, "; } elsif ( $fieldname eq "month" ) { $output .= "$fieldcontent, "; $month = &ParseMonth($fieldcontent); } elsif ( $fieldname eq "year" ) { $output .= "$fieldcontent. "; $year = $fieldcontent; } elsif ( $fieldname eq "note" ) { $output .= "(note: $fieldcontent) "; } } # end of foreach # link up the paper file, if it exists # if ( $key eq "null.ps" ) { if ( $key =~ /^null.*/i ) { $output .= "

    \n"; } else { $output .= "$file_format

    \n"; } if ( $year eq "" ) { $year = "1900"; } if ( $month eq "" ) { $month = "13"; } #print "Saving $output
    \n"; $typeList[$typeNumber][$typeCount[$typeNumber]++] = $year . $month . "_" . $output; #print "Setting typeList and incrementing type $typeNumber to $typeCount[$typeNumber]

    \n"; $pubcount++; } sub ParseAuthor { local( $field ) = @_; # Argument: author field $field =~ s/, and /, /g; # Convert ', and' to ', ' $field =~ s/ and /, /g; # Convert ' and' to ', ' local ( @authors ) = split( ',' , $field ); local ( $result ) = ""; local ( $first ) = 1; local ( $sep ) = ", "; local ( $final ) = ", and "; local ( $i, $contents ); local ( @name ); foreach $i (0 .. $#authors) { if ($authors[$i] =~ m/^\s*(.*)\s*$/) { # filter spaces around name $authors[$i] = $1; } # print "Author is `$authors[$i]' "; if ($shortAuthor eq "yes") { $sep = "; "; $final = "; "; @name = split( ' ', $authors[$i]); #print "Field count is $#name "; if ( $#name == 1 ) { $authors[$i] = $name[1] . ", " . &Abbrev($name[0]); } else { local ( $j ); $authors[$i] = $name[$#name] . ","; foreach $j (0 .. ($#name - 1)) { #print "Field is $name[$j] "; $authors[$i] .= " " . &Abbrev($name[$j]); } } } #print "Author is `$authors[$i]'
    "; if ($highlight ne "" ) { $contents = $authors[$i]; if ( $contents =~ /.*($highlight).*/i ) { $authors[$i] = "" . $authors[$i] . ""; } } if ( $first == 1 ) { $result = $authors[$i]; $first = 0; } else { if ( $i == $#authors) { $result .= $final . $authors[$i]; } else { $result .= $sep . $authors[$i]; } } } return $result; } sub OutputPapers { local( $idx ) = @_; # Argument: index local ( $j, $start, $end, $inc, $list, @slist, $first, $last ); $#list = 0; foreach $j (0 .. ($typeCount[$idx] - 1)) { $list[$j] = $typeList[$idx][$j]; } @slist = sort @list; $first = 0; $last = $typeCount[$idx]; #print "Type $idx, Start $first, Last $last
    "; if (($startDate ne "") || ($endDate ne "")) { #print "Checking against date range `$startDate' and `$endDate'
    "; #print "Original range is $first to $last
    "; for ($j = $first; $j != $last; $j++) { local ( $f ) = substr($slist[$j], 0, 6); #print "Comparing $j
    "; if ( $startDate ne "") { #print "Got start $startDate
    "; #print "substr $f
    "; if ( $startDate gt $f ) { #print "Found new start at $j (date is $f)
    "; $first = $j+1; } } if ( $endDate ne "") { if ( $endDate lt $f ) { #print "Found new end at $j (date is $f)
    "; $last = $j; last; } } } } if ( $recent ne "" ) { local ( $s ) = $last - $recent; #print "Recent: $recent, S: $s, first: $first, last: $last
    "; if ( $s > $first ) { $first = $s; } #print "first now is $first
    "; } if ( $order eq "reverse" ) { $start = $first; $end = $last; $inc = 1; } else { $start = $last - 1; $end = $first -1; $inc = -1; } for ($j = $start; $j != $end; $j += $inc) { # print "list value is $slist[$j]
    \n"; local ( $rest, $value ) = split ( '_', $slist[$j], 2); print $value; } } sub Abbrev { local( $name ) = @_; # Argument: name if ( index($name, '.') == -1 ) { return (substr($name, 0, 1) . "."); } else { return ($name); } } sub ParseMonth { local( $month ) = @_; # Argument: month field local( $monthField, $rest ) = split( '([ ,/])', $month, 2 ); local ( $mon ) = $months{$monthField}; # if ($mon eq "" ) { # print "Month $monthField not found
    \n"; # } else { # print "Month $monthField is $mon
    \n"; # } return $mon; } # **** # # GetField # # Gets the field specified in the first argument and strips it of quotes and/or # squiggly brackets, removes excess spaces and returns it. # # From bibsearch.pl - Copyright 1994 Andy Wood # http://www.cs.bham.ac.uk/~amw # # **** sub GetField { local( $field, $contents ) = @_; # Arguments: field name, bibtex entry $contents =~ s/\n/ /g; # Remove all \n's if ( $contents =~ /.*\b($field)\s*=\s*"([^"]*)"\s*/i ) # KaiChen: don't match "," at the end { $contents = $2; } elsif ( $contents =~ /.*\b($field)\s*=\s*{(.*)}\s*/i ) # KaiChen: don't match "," at the end { $contents = $2; # Contains remaining fields too $contents =~ s/}\s*,.*//g; # So remove everything after }, } elsif ( $contents =~ /.*\b($field)\s*=\s*(\d*)\s*/i ) # KaiChen: don't match "," at the end { $contents = $2; } else { $contents = ""; } $contents =~ s/"|{|}//g; # Remove ""`s and {}'s $contents =~ s/\s+/ /g; # Make lots of spaces into 1. return $contents; } # **** # # OutputFile # # Read and output the whole file (header and footer) which is # already formatted as html text. # # **** sub OutputFile { undef $/; open ( FILE, $_[0] ) || print "

    getpaper.pl: incorrect file $_[0]


    \n"; local ( $header ) = ; print $header; close FILE; }