Index: coder.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder.module,v
retrieving revision 1.88.2.59.2.5
diff -u -p -r1.88.2.59.2.5 coder.module
--- coder.module	1 Oct 2008 14:08:38 -0000	1.88.2.59.2.5
+++ coder.module	19 Nov 2008 11:45:50 -0000
@@ -270,6 +270,7 @@ function _coder_settings_form($settings,
     );
 
     $in_patch = 0;
+    $leading_lines_added = 0;
     $patch = $link_contents = $textarea_contents = '';
     $patches = array();
     if (!empty($settings['coder_patch_link'])) {
@@ -301,6 +302,7 @@ function _coder_settings_form($settings,
         if ($matches[3]) {
           $current_function = $matches[3];
           $patch = 'function '. $current_function ."() {\n";
+          $leading_lines_added = 1;
         }
         $patch_line_numbers = $matches[1];
       }
@@ -322,6 +324,11 @@ function _coder_settings_form($settings,
       $patch = '';
     }
     $files = $patches;
+
+    $form['coder_patch_leading_lines_added'] = array(
+      '#type' => 'value',
+      '#value' => $leading_lines_added,
+    );
   }
   else {
     // Get the modules and theme.
@@ -376,7 +383,7 @@ function _coder_settings_form($settings,
     );
     $form['coder_what']['coder_includes_exclusion_fieldset'] = array(
       '#type' => 'fieldset',
-      '#title' => t('include file exclusions'),
+      '#title' => t('Include file exclusions'),
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
     );
@@ -771,6 +778,9 @@ function coder_page_form($form_state) {
             '#php_extensions' => $php_extensions,
             '#include_extensions' => $include_extensions,
           );
+          if (!empty($settings['coder_patches'])) {
+            $coder_args['#patch_leading_lines_added'] = $coder_form['leading_lines_added']['#value'];
+          }
           $results = do_coder_reviews($coder_args);
           $stats[$filename] = $results['#stats'];
           unset($results['#stats']);
@@ -1066,7 +1076,13 @@ function _coder_read_and_parse_file(&$co
         $in_comment = '*';
       }
       else {
-        $content = preg_replace('/^(function\s.*?(\r\n|\n)+)(\s*\*)/', '${1}/*', $content);
+        // Handle patches that begin with a comment line '*' or '*/' and which
+        // also had the function supplied by patch header prepended to the
+        // content.
+        if (preg_match('/^(function\s.*?(\r\n|\n)+)(\s*\*)/', $content)) {
+          $content = "/**\n" . $content;
+          $coder_args['#patch_leading_lines_added']++;
+        }
         $in_php = 1;
         $in_allphp = 1;
       }
@@ -1114,6 +1130,12 @@ function _coder_read_and_parse_file(&$co
     // - Strip stuff not in php,
     // - Break into lines.
     $lineno = 1;
+    // Reducing lineno value to account for extra lines added to the beginning
+    // of the patch which could be the function name if this is a patch in 'show
+    // function format' (-p) or a patch which starts with * comment.
+    if ($coder_args['#patch_leading_lines_added'] != 0) {
+      $lineno -= $coder_args['#patch_leading_lines_added'];
+    }
     for ($pos = 0; $pos < $content_length; $pos ++) {
       // Get the current character.
       $char = $content[$pos];
