Index: scripts/coder_format/coder_format.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/coder_format.inc,v
retrieving revision 1.2.4.9
diff -u -r1.2.4.9 coder_format.inc
--- scripts/coder_format/coder_format.inc	21 Jan 2008 04:15:27 -0000	1.2.4.9
+++ scripts/coder_format/coder_format.inc	21 Jan 2008 17:07:11 -0000
@@ -2,7 +2,6 @@
 // $Id: coder_format.inc,v 1.2.4.9 2008/01/21 04:15:27 sun Exp $
 
 
-
 /**
  * Recursively process .module and .inc files in directory with coder_format_file().
  *
@@ -192,7 +191,7 @@
  *   $in_multiline
  *      Array of parenthesis level to whether or not the structure
  *      is multiline.
- * 
+ *
  * Context flags:
  *   These variables give information about what tokens have just been
  *   processed so that operations can change their behavior depending on
@@ -200,7 +199,7 @@
  *   formed result. Most of these are ad hoc and have a very specific
  *   purpose in the program. It would probably be a good idea to generalize
  *   this facility.
- *   
+ *
  *   $after_semicolon
  *      Is the token being processed on the same line as a semicolon? This
  *      allows for the semicolon processor to unconditionally add a newline
@@ -247,35 +246,35 @@
   $in_do_while    = false;
 
   // Whitespace controls:
-  $in_object       = FALSE;
-  $in_at           = FALSE;
-  $in_php          = FALSE;
-  $in_quote        = FALSE;
-  $inline_if       = FALSE;
-  $in_array        = array();
-  $in_multiline    = array();
-  
+  $in_object    = FALSE;
+  $in_at        = FALSE;
+  $in_php       = FALSE;
+  $in_quote     = FALSE;
+  $inline_if    = FALSE;
+  $in_array     = array();
+  $in_multiline = array();
+
   // Context flags:
-  $after_semicolon            = FALSE;
-  $after_case                 = FALSE;
-  $after_comment              = FALSE;
-  $after_initial_comment      = FALSE;
-  $after_visibility_modifier  = FALSE;
-  $after_return_in_case       = FALSE;
-  $after_php                  = FALSE;
+  $after_semicolon = FALSE;
+  $after_case = FALSE;
+  $after_comment = FALSE;
+  $after_initial_comment = FALSE;
+  $after_visibility_modifier = FALSE;
+  $after_return_in_case = FALSE;
+  $after_php = FALSE;
 
   // Whether or not a function token was encountered:
   $in_function_declaration = FALSE;
-  
+
   // The position of the last character of the last non-whitespace
   // non-comment token, e.g. it would be:
-  // function foo() {   // bar
+  // function foo() { // bar
   //                ^ this character
   $position_last_significant_token = 0;
 
-  $result = '';
+  $result    = '';
   $lasttoken = array(0);
-  $tokens = token_get_all($code);
+  $tokens    = token_get_all($code);
 
   // Mask T_ML_COMMENT (PHP4) as T_COMMENT (PHP5).
   if (!defined('T_ML_COMMENT')) {
@@ -295,7 +294,7 @@
           // Write curly braces at the end of lines followed by a line break if
           // not in quotes (""), object ($foo->{$bar}) or in variables (${foo}).
           // (T_DOLLAR_OPEN_CURLY_BRACES exists but is never assigned.)
-          if (!$in_variable && !$in_quote && !$in_object && substr(rtrim($result), -1) != '$') {
+          if (!$in_variable && !$in_quote && !$in_object && substr(rtrim($result), -1) != '$' || substr(rtrim($result), -1) == ')') {
             if ($in_case) {
               ++$braces_in_case;
             }
@@ -494,17 +493,16 @@
           $result .= $text;
           break;
       }
-      
+
       // All text possibilities are significant:
       $position_last_significant_token = strlen(rtrim($result)) - 1;
-      
+
       // Because they are all significant, we cannot possibly be after
       // a comment now.
       $after_comment = FALSE;
       $after_initial_comment = FALSE;
-      
+
       // TODO: Make resetting context flags easier to do.
-      
     }
     else {
       // If we get here, then we have found not a single char, but a token.
@@ -520,6 +518,7 @@
       }
       */
 
+
       switch ($id) {
         case T_ARRAY:
           // Write array in lowercase.
@@ -537,13 +536,19 @@
           if (substr(rtrim($result), -2) == '?>') {
             coder_br($result);
           }
+          $nl = substr_count($text, "\n");
           $result .= trim($text);
           if ($first_php_tag) {
             coder_br($result);
             $first_php_tag = FALSE;
           }
           else {
-            $result .= ' ';
+            if ($nl) {
+              coder_br($result, $parenthesis);
+            }
+            else {
+              $result .= ' ';
+            }
           }
           break;
 
@@ -611,10 +616,10 @@
           // If there were newlines present, move inline comments above.
           if ($cc) {
             $after_semicolon = FALSE;
-            $after_case = FALSE;
-            $after_php = FALSE;
+            $after_case      = FALSE;
+            $after_php       = FALSE;
           }
-          
+
           $in_variable = FALSE;
           break;
 
@@ -718,7 +723,7 @@
           $result .= trim($text) .' ';
           $after_visibility_modifier = TRUE;
           break;
-          
+
         case T_FUNCTION:
           $in_function_declaration = TRUE;
           // Fall through.
@@ -858,7 +863,7 @@
               $position_last_significant_token = strlen(rtrim($result, " \n")) - 1;
             }
             else {
-              if (strpos($text, '$'.'Id$') === FALSE) {
+              if (strpos($text, '$' . 'Id$') === FALSE) {
                 $after_comment = TRUE;
               }
               else {
@@ -893,7 +898,7 @@
 
       // Store last token.
       $lasttoken = $token;
-      
+
       // Excluding comments and whitespace, set the position of the
       // last significant token's last character to the length of the
       // string minus one.
@@ -903,16 +908,16 @@
         case T_ML_COMMENT:
         case T_DOC_COMMENT:
           break;
+
         default:
           $position_last_significant_token = strlen(rtrim($result, " \n")) - 1;
           break;
       }
-      
+
       if ($id !== T_COMMENT && $id !== T_ML_COMMENT) {
         $after_comment = FALSE;
       }
       if ($after_initial_comment && $id !== T_WHITESPACE) $after_initial_comment--;
-      
     }
   }
   return $result;
@@ -946,7 +951,7 @@
     // Non-whitespace was encountered, no changes necessary.
     break;
   }
-  
+
   if ($parenthesis) {
     // Add extra indent for each parenthesis in multiline definitions (f.e. arrays).
     $_coder_indent = $_coder_indent + $parenthesis;
Index: scripts/coder_format/coder_format.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/coder_format.php,v
retrieving revision 1.2.4.3
diff -u -r1.2.4.3 coder_format.php
--- scripts/coder_format/coder_format.php	21 Jan 2008 03:40:33 -0000	1.2.4.3
+++ scripts/coder_format/coder_format.php	21 Jan 2008 04:35:01 -0000
@@ -1,10 +1,11 @@
 <?php
 // $Id: coder_format.php,v 1.2.4.3 2008/01/21 03:40:33 sun Exp $
 
+
 /**
  * @file
  * Coder format shell invocation script.
- * 
+ *
  * @param string $sourcefile
  * 	 The file containing the source code to process, optionally including a
  *   filepath.
@@ -22,23 +23,23 @@
  *   The full path to file.inc in a Drupal installation. Only needed if the
  *   path provided for --batch-replace or --undo is not the root directory of a
  *   Drupal installation. Allows to recursively format a CVS checkout folder.
- * 
+ *
  * @usage
  *   php coder_format.php <sourcefile> <targetfile>
  *   php coder_format.php --batch-replace <path> [--file-inc <path_to_file.inc>]
  *   php coder_format.php --undo <path> [--file-inc <path_to_file.inc>]
- * 
+ *
  * @example
  *   php coder_format.php node.module node.module.formatted
  *   php coder_format.php node.module node.module
  *   php coder_format.php --batch-replace /home/drupal
  *   php coder_format.php --undo /home/drupal
- * 
+ *
  * If either --batch-replace or --undo parameter is given, Coder Format assumes
  * that the specified path is the root of a Drupal installation. Coder Format
  * needs includes/file.inc for batch processing. You can optionally specify the
  * location of file.inc with the --file-inc parameter.
- * 
+ *
  * Notes:
  * - Encapsulate file and path arguments with double quotes on Windows.
  */
@@ -51,11 +52,11 @@
 if (!empty($_SERVER['argv'])) {
   // Remove self-reference.
   array_shift($_SERVER['argv']);
-  
+
   $files    = array();
   $undo     = false;
   $file_inc = null;
-  
+
   for ($c = 0, $cc = count($_SERVER['argv']); $c < $cc; ++$c) {
     switch ($_SERVER['argv'][$c]) {
       case '--undo':
@@ -63,23 +64,23 @@
         $root = $_SERVER['argv'][$c];
         $undo = true;
         break;
-        
+
       case '--batch-replace':
         ++$c;
         $root = $_SERVER['argv'][$c];
         break;
-        
+
       case '--file-inc':
         ++$c;
         $file_inc = $_SERVER['argv'][$c];
         break;
-      
+
       default:
         $files[] = $_SERVER['argv'][$c];
         break;
     }
   }
-  
+
   if (isset($root)) {
     coder_format_recursive($root, $undo, $file_inc);
   }
@@ -87,9 +88,8 @@
     // Process a single file
     $sourcefile = $files[0];
     $targetfile = $files[1];
-    
+
     coder_format_file($sourcefile, $targetfile);
   }
 }
 
-
Index: scripts/coder_format/tests/tests/control.phpt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/tests/tests/Attic/control.phpt,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 control.phpt
--- scripts/coder_format/tests/tests/control.phpt	21 Jan 2008 01:37:41 -0000	1.1.2.3
+++ scripts/coder_format/tests/tests/control.phpt	21 Jan 2008 05:08:58 -0000
@@ -76,3 +76,11 @@
   }
 }
 
+--INPUT--
+foreach ($update as $key){
+  $foo;
+}
+--EXPECT--
+foreach ($update as $key) {
+  $foo;
+}
Index: scripts/coder_format/tests/tests/tags.phpt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/tests/tests/Attic/tags.phpt,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 tags.phpt
--- scripts/coder_format/tests/tests/tags.phpt	21 Jan 2008 04:15:27 -0000	1.1.2.3
+++ scripts/coder_format/tests/tests/tags.phpt	21 Jan 2008 05:02:59 -0000
@@ -19,6 +19,9 @@
 <?php
 // $Id: tags.phpt,v 1.1.2.3 2008/01/21 04:15:27 sun Exp $
 
-?>
-<a href="<?php print $link; ?>"><?php print $title; ?></a>
+function l() {
+  ?>
+  <a href="<?php print $link; ?>"><?php print $title; ?></a>
+  <?php
+}
 
