Commits

Anonymous committed e314311

Formatting

Comments (0)

Files changed (6)

 
     }
 
-    if(!argv[woptind]) {
-      append_format(stderr_buffer, L"%ls: expected event name\n", argv[0]);
-      return STATUS_BUILTIN_ERROR;
+    if (!argv[woptind])
+    {
+        append_format(stderr_buffer, L"%ls: expected event name\n", argv[0]);
+        return STATUS_BUILTIN_ERROR;
     }
     wchar_t *eventname = argv[woptind];
     wcstring_list_t args(argv + woptind + 1, argv + argc);
             break;
 
         default:
-						result = format_string(_(L"Unknown event type '0x%x'"), e.type);
+            result = format_string(_(L"Unknown event type '0x%x'"), e.type);
             break;
 
     }
 #endif
 
 /*
-    Give a more condensed description of \c event compared to \c event_get_desc. 
-    It includes what function will fire if the \c event is an event handler. 
+    Give a more condensed description of \c event compared to \c event_get_desc.
+    It includes what function will fire if the \c event is an event handler.
  */
-static wcstring event_desc_compact(const event_t &event) {
-	wcstring res;
-	wchar_t const *temp;
-	int sig; 
-	switch(event.type) {
-		case EVENT_ANY:
-			res = L"EVENT_ANY";
-			break;
-		case EVENT_VARIABLE:
- 			if(event.str_param1.c_str()) {
-				res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str());
-			} else {
-				res = L"EVENT_VARIABLE([any])";
-			}
-			break;
-		case EVENT_SIGNAL:
-			sig = event.param1.signal;
-			if(sig == EVENT_ANY_SIGNAL) {
-				temp = L"[all signals]";
-			} else if(sig == 0) {
-				temp = L"not set";
-			} else {
-				temp = sig2wcs(sig);
-			}
-			res = format_string(L"EVENT_SIGNAL(%ls)", temp);
-			break;
-		case EVENT_EXIT:
-			if(event.param1.pid == EVENT_ANY_PID) {
-				res = wcstring(L"EVENT_EXIT([all child processes])");
-			} else if (event.param1.pid > 0) {
-				res = format_string(L"EVENT_EXIT(pid %d)", event.param1.pid);
-			} else {
-				job_t *j = job_get_from_pid(-event.param1.pid);
-				if (j)
-						res = format_string(L"EVENT_EXIT(jobid %d: \"%ls\")", j->job_id, j->command_wcstr());
-				else
-						res = format_string(L"EVENT_EXIT(pgid %d)", -event.param1.pid);
-			}
-			break;
-		case EVENT_JOB_ID:
-			{
-			job_t *j = job_get(event.param1.job_id);
-			if (j)
-					res = format_string(L"EVENT_JOB_ID(job %d: \"%ls\")", j->job_id, j->command_wcstr());
-			else
-					res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id);
-			break;
-			}
-		case EVENT_GENERIC:
-			res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str());
-			break;
-		default:
-			res = format_string(L"unknown/illegal event(%x)", event.type);
-	}
-	if(event.function_name.size()) {
-		return format_string(L"%ls: \"%ls\"", res.c_str(), event.function_name.c_str());
-	} else {
-		return res;
-	}
+static wcstring event_desc_compact(const event_t &event)
+{
+    wcstring res;
+    wchar_t const *temp;
+    int sig;
+    switch (event.type)
+    {
+        case EVENT_ANY:
+            res = L"EVENT_ANY";
+            break;
+        case EVENT_VARIABLE:
+            if (event.str_param1.c_str())
+            {
+                res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str());
+            }
+            else
+            {
+                res = L"EVENT_VARIABLE([any])";
+            }
+            break;
+        case EVENT_SIGNAL:
+            sig = event.param1.signal;
+            if (sig == EVENT_ANY_SIGNAL)
+            {
+                temp = L"[all signals]";
+            }
+            else if (sig == 0)
+            {
+                temp = L"not set";
+            }
+            else
+            {
+                temp = sig2wcs(sig);
+            }
+            res = format_string(L"EVENT_SIGNAL(%ls)", temp);
+            break;
+        case EVENT_EXIT:
+            if (event.param1.pid == EVENT_ANY_PID)
+            {
+                res = wcstring(L"EVENT_EXIT([all child processes])");
+            }
+            else if (event.param1.pid > 0)
+            {
+                res = format_string(L"EVENT_EXIT(pid %d)", event.param1.pid);
+            }
+            else
+            {
+                job_t *j = job_get_from_pid(-event.param1.pid);
+                if (j)
+                    res = format_string(L"EVENT_EXIT(jobid %d: \"%ls\")", j->job_id, j->command_wcstr());
+                else
+                    res = format_string(L"EVENT_EXIT(pgid %d)", -event.param1.pid);
+            }
+            break;
+        case EVENT_JOB_ID:
+        {
+            job_t *j = job_get(event.param1.job_id);
+            if (j)
+                res = format_string(L"EVENT_JOB_ID(job %d: \"%ls\")", j->job_id, j->command_wcstr());
+            else
+                res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id);
+            break;
+        }
+        case EVENT_GENERIC:
+            res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str());
+            break;
+        default:
+            res = format_string(L"unknown/illegal event(%x)", event.type);
+    }
+    if (event.function_name.size())
+    {
+        return format_string(L"%ls: \"%ls\"", res.c_str(), event.function_name.c_str());
+    }
+    else
+    {
+        return res;
+    }
 }
 
 
 {
     event_t *e;
 
-    if(debug_level >= 3) {
+    if (debug_level >= 3)
+    {
         wcstring desc = event_desc_compact(event);
         debug(3, "register: %ls\n", desc.c_str());
     }
     size_t i;
     event_list_t new_list;
 
-    if(debug_level >= 3) {
+    if (debug_level >= 3)
+    {
         wcstring desc = event_desc_compact(criterion);
         debug(3, "unregister: %ls\n", desc.c_str());
     }
     event_list_t fire;
 
     /*
-      First we free all events that have been removed, but only if this 
-			invocation of event_fire_internal is not a recursive call. 
+      First we free all events that have been removed, but only if this
+    		invocation of event_fire_internal is not a recursive call.
     */
-		if(is_event <= 1)
-		    event_free_kills();
+    if (is_event <= 1)
+        event_free_kills();
 
     if (events.empty())
         return;
             }
         }
 
-    // debug( 1, L"Event handler fires command '%ls'", buffer.c_str() );
+        // debug( 1, L"Event handler fires command '%ls'", buffer.c_str() );
 
         /*
           Event handlers are not part of the main flow of code, so
     /*
       Free killed events
     */
-		if(is_event <= 1)
-		    event_free_kills();
+    if (is_event <= 1)
+        event_free_kills();
 
 }
 
     event.str_param1 = str;
     return event;
 }
- 
+
     event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() { }
 
     /** default copy constructor */
-		//event_t(const event_t &x); 
+    //event_t(const event_t &x);
 
 
     static event_t signal_event(int sig);
     }
 }
 
-enum word_motion_t {
+enum word_motion_t
+{
     word_motion_left,
     word_motion_right
 };
 {
     wcstring command;
     std::set<size_t> stops;
-    
+
     // Carets represent stops and should be cut out of the command
-    for (size_t i=0; i < test.size(); i++) {
+    for (size_t i=0; i < test.size(); i++)
+    {
         wchar_t wc = test.at(i);
         if (wc == L'^')
         {
             command.push_back(wc);
         }
     }
-    
+
     size_t idx, end;
     if (motion == word_motion_left)
     {
         idx = 0;
         end = command.size();
     }
-    
+
     move_word_state_machine_t sm(style);
     while (idx != end)
     {
     say(L"Testing word motion");
     test_1_word_motion(word_motion_left, move_word_style_punctuation, L"^echo ^hello_^world.^txt");
     test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ hello^_world^.txt^");
-    
+
     test_1_word_motion(word_motion_left, move_word_style_punctuation, L"echo ^foo_^foo_^foo/^/^/^/^/^    ");
     test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ foo^_foo^_foo^/^/^/^/^/    ^");
-    
+
     test_1_word_motion(word_motion_left, move_word_style_path_components, L"^/^foo/^bar/^baz/");
     test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^--foo ^--bar");
     test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^hi ^> /^dev/^null");
-    
+
     test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo /^foo/^bar{^aaa,^bbb,^ccc}^bak/");
 }
 
     builtin_init();
     reader_init();
     env_init();
-    
+
     test_word_motion();
     return 0;
 
         s_alphanumeric,
         s_end
     };
-    
+
     bool consumed = false;
     while (state != s_end && ! consumed)
     {
                 consumed = true;
                 state = s_whitespace;
                 break;
-            
+
             case s_whitespace:
                 if (iswspace(c))
                 {
                     state = s_alphanumeric;
                 }
                 break;
-            
+
             case s_alphanumeric:
                 if (iswalnum(c))
                 {
                     state = s_end;
                 }
                 break;
-                
+
             case s_end:
             default:
                 break;
         s_path_component_characters,
         s_end
     };
-    
+
     //printf("state %d, consume '%lc'\n", state, c);
     bool consumed = false;
     while (state != s_end && ! consumed)
                 }
                 state = s_whitespace;
                 break;
-            
+
             case s_whitespace:
                 if (iswspace(c))
                 {
 {
     switch (style)
     {
-        case move_word_style_punctuation: return consume_char_punctuation(c);
-        case move_word_style_path_components: return consume_char_path_components(c);
-        default: return false;
+        case move_word_style_punctuation:
+            return consume_char_punctuation(c);
+        case move_word_style_path_components:
+            return consume_char_path_components(c);
+        default:
+            return false;
     }
 }
 
 class move_word_state_machine_t
 {
 private:
-    
+
     bool consume_char_punctuation(wchar_t c);
     bool consume_char_path_components(wchar_t c);
     bool is_path_component_character(wchar_t c);
-    
+
     int state;
     move_word_style_t style;