Cleaned up use of substring$
authorTim Pope <code@tpope.net>
Fri, 21 Nov 2003 08:15:01 +0000 (08:15 +0000)
committerTim Pope <code@tpope.net>
Fri, 21 Nov 2003 08:15:01 +0000 (08:15 +0000)
Added enquote
Reworked add.period
Switched "blank" title to a constant
Added period after type to theses

mlastyle.bst

index e2b446ac786928c92f6416b22aec299feea2ed74..ffe9e715911a967ef2591b5353c1ea83bfc8a929 100644 (file)
@@ -43,6 +43,8 @@ ENTRY
 
 INTEGERS { output.state before.all mid.sentence after.sentence after.block after.title author.different author.last author.flast citealp.used url.used }
 
+STRINGS { s t u empty.title }
+
 % Rearranged such that true values require capital letters
 FUNCTION {init.consts}
 { #-1 'after.title :=
@@ -58,23 +60,65 @@ FUNCTION {init.consts}
 
   #0 'citealp.used :=
   #0 'url.used :=
+  " \ \ \ \ \unskip\unskip\unskip\unskip\unskip " 'empty.title :=
+}
+
+FUNCTION {not}
+{   { #0 }
+    { #1 }
+  if$
+}
+
+FUNCTION {and}
+{   'skip$
+    { pop$ #0 }
+  if$
 }
 
-STRINGS { s t u } % Added u
+FUNCTION {or}
+{   { pop$ #1 }
+    'skip$
+  if$
+}
+
+INTEGERS {chars i j}
+
+% text.length$ does not include braces
+% ...this is probably unnecessary
+FUNCTION {num.chars}
+{
+  #0 'chars :=
+    { duplicate$ duplicate$ #1 chars substring$ = not }
+    { duplicate$ duplicate$ text.length$ swap$ #1 chars
+    substring$ text.length$ - chars + #1 + 'chars := }
+  while$
+    { duplicate$ duplicate$ #1 chars #1 - substring$ = }
+    { chars #1 - 'chars := }
+  while$
+  pop$ chars
+}
 
 % Puts the period inside any quotes
 FUNCTION {do.period}
-{ 
-  duplicate$ #-1 #3 substring$ "'''" =
-    { duplicate$ text.length$ #3 - text.prefix$ add.period$ "'\thinspace''" * }
-    { duplicate$ #-1 #3 substring$ "''}" =
-       { #2 global.max$ substring$ duplicate$
-         text.length$ #2 - text.prefix$ add.period$ "{" swap$ * "''}" * }
-       { duplicate$ #-1 #2 substring$ "''" =
-           { duplicate$ text.length$ #2 - text.prefix$ add.period$ "''" * }
-           { add.period$ }
-         if$
+{
+  duplicate$ #-1 #2 substring$ "''" =
+    { #2 'i :=
+       { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
+       { i #11 + 'i := }
+      while$
+      duplicate$ #-1 i - global.max$ substring$
+      add.period$ swap$ #-1 i substring$ *
+    }
+    {
+      duplicate$ #-1 #3 substring$ "''}" =
+       { #3 'i :=
+           { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
+           { i #11 + 'i := }
+         while$
+         duplicate$ #-1 i - global.max$ substring$
+         add.period$ swap$ #-1 i substring$ *
        }
+       { add.period$ }
       if$
     }
   if$
@@ -157,24 +201,6 @@ FUNCTION {new.sentence}
 %  if$
 %}
 
-FUNCTION {not}
-{   { #0 }
-    { #1 }
-  if$
-}
-
-FUNCTION {and}
-{   'skip$
-    { pop$ #0 }
-  if$
-}
-
-FUNCTION {or}
-{   { pop$ #1 }
-    'skip$
-  if$
-}
-
 FUNCTION {new.block.checka}
 { empty$
     'skip$
@@ -221,6 +247,49 @@ FUNCTION {emphasize}
   if$
 }
 
+FUNCTION {enquote}
+{ duplicate$ empty$
+    { pop$ "" }
+    {
+      #1 'i :=
+      #0 'j :=
+       { duplicate$ i #1 substring$ "" = not }
+       { duplicate$ i #1 substring$ quote$ =
+           { duplicate$ #1 i #1 - substring$ swap$
+             i #1 + global.max$ substring$
+             j
+               { swap$ duplicate$ #-1 #1 substring$ "'" =
+                   { swap$ "\thinspace'" }
+                   { swap$ "'" }
+                 if$
+                  #0 'j :=
+               }
+               { duplicate$ #1 #1 substring$ "`" =
+                   { "`\thinspace" }
+                   { "`" }
+                 if$
+               #1 'j :=
+               }
+             if$
+             swap$ * *
+           }
+           'skip$
+         if$
+         i #1 + 'i :=
+       }
+      while$
+      duplicate$ #1 #1 substring$ "`" =
+       { "``\thinspace" swap$ * }
+       { "``" swap$ *}
+      if$
+      duplicate$ #-1 #1 substring$ "'" =
+       { "\thinspace''" * }
+       { "''" *}
+      if$
+    }
+  if$
+}
+
 INTEGERS { nameptr namesleft numnames }
 
 FUNCTION {format.names.custom}
@@ -266,7 +335,7 @@ FUNCTION {format.names.beginning}
     { nameptr #1 =
        { s nameptr "{vv~}{ll}{, ff}{, jj}" format.name$
          duplicate$ #1 #1 substring$ "u" change.case$ swap$
-         duplicate$ #-1 swap$ text.length$ #1 - substring$ * 't := }
+         #2 global.max$ substring$ * 't := }
        { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := }
       if$
       nameptr #1 >
@@ -343,14 +412,7 @@ FUNCTION {format.publisher}
 
 % Changed to preserve case and use quotes
 FUNCTION {format.title}
-{ title empty$
-    { "" }
-    { title #1 text.prefix$ "`" =
-       { "``\thinspace" title * "''" * }
-       { "``" title * "''" *}
-      if$
-    }
-  if$
+{ title enquote
 }
 
 FUNCTION {n.dashify}
@@ -395,8 +457,13 @@ FUNCTION {format.date}
   if$
 }
 
+INTEGERS {xx}
 FUNCTION {format.btitle}
 { title emphasize
+  %title num.chars int.to.str$ top$
+  %#0 'xx :=
+  %{ xx title num.chars < }
+  %{ title xx #1 + duplicate$ 'xx := #1 substring$ top$ } while$
 }
 
 FUNCTION {tie.or.space.connect}
@@ -735,7 +802,7 @@ FUNCTION {cite.title}
              type$ "techreport" =
              type$ "unpublished" =
              or or or or or or
-               {"``" swap$ * "''" *  }
+               { enquote }
                {}
              if$
            }
@@ -762,7 +829,8 @@ FUNCTION {cite.label}
     { author }
   if$
   duplicate$ empty$
-    { cite.title * "( \ \ \ \ \unskip\unskip\unskip\unskip\unskip \unskip)" * }
+    { cite.title *
+    "(" * empty.title * ")" * }
     { duplicate$
       author.shared author.different =
        { "{vv~}{ll}" format.names.custom 's := }
@@ -777,8 +845,8 @@ FUNCTION {cite.label}
        }
       if$
       s
-      "( \ \ \ \ \unskip\unskip\unskip\unskip\unskip " *
-      author.duplicate { cite.title * }{ "\unskip" * } if$
+      "(" * empty.title *
+      author.duplicate { cite.title * }{} if$
       ")" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom *
     }
   if$
@@ -810,6 +878,7 @@ FUNCTION {article}
   new.block
   crossref missing$
     { journal emphasize "journal" output.check after.title 'output.state :=
+      address empty$ skip$ { "[" address * "]" * output } if$
       %format.date "year" output.check
       %edition output
       format.vol.num.year.pages output
@@ -914,7 +983,7 @@ FUNCTION {incollection}
   crossref missing$
     { 
       booktitle emphasize "booktitle" output.check
-      new.sentence
+      new.block
       format.editors.mid "editor" output.check
       new.block
       format.edition output
@@ -1031,7 +1100,7 @@ FUNCTION {mastersthesis}
   new.block
   format.title "title" output.check
   new.block
-  "Diss." format.thesis.type output.nonnull
+  "Diss." format.thesis.type do.period output.nonnull
   after.title 'output.state :=
   school "school" output.check
   address output
@@ -1066,7 +1135,7 @@ FUNCTION {phdthesis}
   new.block
   format.btitle "title" output.check
   new.block
-  "Diss." format.thesis.type output.nonnull
+  "Diss." format.thesis.type do.period output.nonnull
   after.title 'output.state :=
   school "school" output.check
   address output
@@ -1358,7 +1427,6 @@ ITERATE {presort}
 SORT
 
 STRINGS {a b}
-INTEGERS {i j}
 
 FUNCTION {init.vars}
 { #0 int.to.chr$ 'a :=