Commits

JanKanis  committed 8a446f4

include fixes and suggestions from code review

  • Participants
  • Parent commits 30392bf

Comments (0)

Files changed (8)

 
     }
 
-    wcstring_list_t args;
-    wchar_t *eventname = argv[woptind];
-    for (woptind++; woptind < argc; woptind++)
-    {
-        args.push_back(argv[woptind]);
+    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);
     event_fire_generic(eventname, &args);
 
     return STATUS_BUILTIN_OK;
 }
 #endif
 
-  
-wcstring event_type_str(const event_t &event) {
+/*
+    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; 
 {
     event_t *e;
 
-    if(debug_level >= 3)
-        debug(3, "register: %ls\n", event_type_str(event).c_str());
+    if(debug_level >= 3) {
+        wcstring desc = event_desc_compact(event);
+        debug(3, "register: %ls\n", desc.c_str());
+    }
 
     e = new event_t(event);
 
     signal_unblock();
 }
 
-void event_remove(event_t &criterion)
+void event_remove(const event_t &criterion)
 {
 
     size_t i;
     event_list_t new_list;
 
-		if(debug_level >= 3)
-				debug(3, "unregister: %ls\n", event_type_str(criterion).c_str());
+    if(debug_level >= 3) {
+        wcstring desc = event_desc_compact(criterion);
+        debug(3, "unregister: %ls\n", desc.c_str());
+    }
 
     /*
       Because of concurrency issues (env_remove could remove an event
         prev_status = proc_get_last_status();
         parser_t &parser = parser_t::principal_parser();
 
-        block_t *block = new event_block_t((const event_t*)&event);
+        block_t *block = new event_block_t(event);
         parser.push_block(block);
         parser.eval(buffer, io_chain_t(), TOP);
         parser.pop_block();
           Set up
         */
         event_t e = event_t::signal_event(0);
+        e.arguments.resize(1);
         lst = &sig_list[1-active_list];
 
         if (lst->overflow)
 
    May not be called by a signal handler, since it may free allocated memory.
 */
-void event_remove(event_t &event);
+void event_remove(const event_t &event);
 
 /**
    Return all events which match the specified event class
 wcstring event_get_desc(const event_t &e);
 
 /**
-   Returns a string describing the event. This version is more concise and
-   more detailed than event_get_desc.
-*/
-wcstring event_type_str(const event_t &e);
-
-/**
    Fire a generic event with the specified name
 */
 void event_fire_generic(const wchar_t *name, wcstring_list_t *args = NULL);
           This is an event handler
         */
         const event_block_t *eb = static_cast<const event_block_t *>(b);
-        wcstring description = event_get_desc(*eb->event);
+        wcstring description = event_get_desc(eb->event);
         append_format(buff, _(L"in event handler: %ls\n"), description.c_str());
         buff.append(L"\n");
 
 {
 }
 
-event_block_t::event_block_t(const event_t *evt) :
+event_block_t::event_block_t(const event_t &evt) :
     block_t(EVENT),
     event(evt)
 {
 
 struct event_block_t : public block_t
 {
-    const event_t * const event;
-    event_block_t(const event_t *evt);
+    event_t const &event;
+    event_block_t(const event_t &evt);
 };
 
 struct function_block_t : public block_t

File tests/test9.err

+emit: expected event name

File tests/test9.in

 end
 
 emit test3 foo bar
+
+# test empty argument
+emit

File tests/test9.status

-0
+1