/**
  * Returns the edits array, but now filled with edits to reverse the given array
  * @todo: Add more
  */
 function reverse_edits($actions)
 {
     $reverse_edits = array();
     foreach ($actions['EDITS'] as $file => $edit_ary) {
         foreach ($edit_ary as $edit_id => $edit) {
             foreach ($edit as $find => $action_ary) {
                 foreach ($action_ary as $type => $command) {
                     // it is possible for a single edit in the install process
                     // to become more than one in the uninstall process
                     while (isset($reverse_edits['EDITS'][$file][$edit_id])) {
                         $edit_id++;
                     }
                     switch (strtoupper($type)) {
                         // for before and after adds, we use the find as a tool for more precise finds
                         // this isn't perfect, but it seems better than having
                         // finds of only a couple characters, like "/*"
                         case 'AFTER ADD':
                             $total_find = rtrim($find, "\n") . "\n" . trim($command, "\n");
                             $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find;
                             break;
                         case 'BEFORE ADD':
                             $total_find = rtrim($command, "\n") . "\n" . trim($find, "\n");
                             // replace with the find
                             $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find;
                             break;
                         case 'REPLACE WITH':
                         case 'REPLACE, WITH':
                         case 'REPLACE-WITH':
                         case 'REPLACE':
                             // replace $command (new code) with $find (original code)
                             $reverse_edits['EDITS'][$file][$edit_id][$command]['replace with'] = $find;
                             break;
                         case 'IN-LINE-EDIT':
                             $action_id = 0;
                             // build the reverse just like the normal action
                             foreach ($command as $inline_find => $inline_action_ary) {
                                 foreach ($inline_action_ary as $inline_action => $inline_command) {
                                     $inline_command = $inline_command[0];
                                     switch (strtoupper($inline_action)) {
                                         case 'IN-LINE-AFTER-ADD':
                                         case 'IN-LINE-BEFORE-ADD':
                                             // Replace with a blank string
                                             $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command]['in-line-replace'][] = '';
                                             break;
                                         case 'IN-LINE-REPLACE':
                                             // replace with the inline find
                                             $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command][$inline_action][] = $inline_find;
                                             break;
                                         default:
                                             // For the moment, we do nothing.  What about increment?
                                             break;
                                     }
                                     $action_id++;
                                 }
                             }
                             break;
                         default:
                             // again, increment
                             break;
                     }
                 }
             }
         }
     }
     if (empty($actions['SQL'])) {
         return $reverse_edits;
     }
     if (sizeof($actions['SQL']) == 1) {
         $actions['SQL'] = explode("\n", $actions['SQL'][0]);
     }
     foreach ($actions['SQL'] as $query) {
         $reverse_edits['SQL'][] = parser::reverse_query($query);
     }
     return $reverse_edits;
 }