Esempio n. 1
0
void view_event(icalcomponent* calendar)
{
  //Ask user if they want null fields in addition to filled ones
  bool show_null_fields_too = yes_no_prompt("Do you want to view empty fields? (y/n)");
    
  icalcomponent* event = find_event(calendar);
  
  if (event == NULL)
  {
    append_action_to_closed_log("View event", false);
  }
  
  //Once user selects desired one, displays all needed fields  
  icalproperty* p;
  for(p = icalcomponent_get_first_property(event,ICAL_ANY_PROPERTY); p != 0; p = icalcomponent_get_next_property(event,ICAL_ANY_PROPERTY))
  {
    if ((icalproperty_get_comment(p) != NULL) || (show_null_fields_too))
    {
      cout << icalproperty_get_x_name(p) << ": ";
      cout << icalproperty_get_comment(p) << endl;
    }
  }
  
  append_action_to_closed_log("View event", true);
}
Esempio n. 2
0
Datum
dbms_alert_remove(PG_FUNCTION_ARGS)
{
	text *name = PG_GETARG_TEXT_P(0);

	alert_event *ev;
	int ev_id;
	int cycle = 0;
	float8 endtime;
	float8 timeout = 2;

	WATCH_PRE(timeout, endtime, cycle);
	if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES,MAX_EVENTS,MAX_LOCKS,false))
	{
		ev = find_event(name, false, &ev_id);
		if (NULL != ev)
		{
			find_and_remove_message_item(ev_id, sid,
							 false, true, true, NULL, NULL);
			unregister_event(ev_id, sid);
		}
		LWLockRelease(shmem_lock);
		PG_RETURN_VOID();
	}
	WATCH_POST(timeout, endtime, cycle);
	LOCK_ERROR();
	PG_RETURN_VOID();
}
// load controls with structure data
void CMessageEditorDlg::update_cur_message()
{
	int node, enable = TRUE, enable2 = TRUE;

	if (m_cur_msg < 0)
	{
		enable = enable2 = FALSE;
		m_message_name = _T("");
		m_message_text = _T("");
		m_avi_filename = _T("");
		m_wave_filename = _T("");
		m_tree.clear_tree();
		m_persona = 0;
		m_sender = m_priority = -1;

	} else {
		m_message_name = Messages[m_cur_msg].name;
		m_message_text = Messages[m_cur_msg].message;
		if (Messages[m_cur_msg].avi_info.name)
			m_avi_filename = _T(Messages[m_cur_msg].avi_info.name);
		else
			m_avi_filename = _T("");

		if (Messages[m_cur_msg].wave_info.name)
			m_wave_filename = _T(Messages[m_cur_msg].wave_info.name);
		else
			m_wave_filename = _T("");

		// add persona id
		if ( Messages[m_cur_msg].persona_index != -1 )
			m_persona = Messages[m_cur_msg].persona_index + 1;		// add one for the "none" at the beginning of the list
		else
			m_persona = 0;

		m_event_num = find_event();
		if (m_event_num < 0) {
			node = -1;
			m_sender = m_priority = 0;

		} else
			node = CADR(Mission_events[m_event_num].formula);

		m_tree.load_tree(node, "false");
	}

	if (m_cur_msg < Num_builtin_messages)
		enable = FALSE;

	GetDlgItem(IDC_NAME)->EnableWindow(enable);
	GetDlgItem(IDC_MESSAGE_TEXT)->EnableWindow(enable);
	GetDlgItem(IDC_AVI_FILENAME)->EnableWindow(enable);
	GetDlgItem(IDC_WAVE_FILENAME)->EnableWindow(enable);
	GetDlgItem(IDC_DELETE)->EnableWindow(enable);
	GetDlgItem(IDC_TREE)->EnableWindow(enable2);
	GetDlgItem(IDC_SENDER)->EnableWindow(enable2);
	GetDlgItem(IDC_PRIORITY)->EnableWindow(enable2);
	GetDlgItem(IDC_PERSONA_NAME)->EnableWindow(enable);
	UpdateData(FALSE);
}
Esempio n. 4
0
Datum
dbms_alert_waitone(PG_FUNCTION_ARGS)
{
	text *name;
	float8 timeout;
	TupleDesc   tupdesc;
	AttInMetadata       *attinmeta;
	HeapTuple   tuple;
	Datum       result;
	int message_id;
	char *str[2] = {NULL,"1"};
	char *event_name;
	int cycle = 0;
	float8 endtime;
	TupleDesc	btupdesc;

	if (PG_ARGISNULL(0))
		ereport(ERROR,
				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
				 errmsg("event name is NULL"),
				 errdetail("Eventname may not be NULL.")));

	if (PG_ARGISNULL(1))
		timeout = TDAYS;
	else
		timeout = PG_GETARG_FLOAT8(1);

	name = PG_GETARG_TEXT_P(0);

	WATCH_PRE(timeout, endtime, cycle);
	if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false))
	{
		if (NULL != find_event(name, false, &message_id))
		{
			str[0] = find_and_remove_message_item(message_id, sid,
								  false, false, false, NULL, &event_name);
			if (event_name != NULL)
			{
				str[1] = "0";
				pfree(event_name);
				LWLockRelease(shmem_lock);
				break;
			}
		}
		LWLockRelease(shmem_lock);
	}
	WATCH_POST(timeout, endtime, cycle);

	get_call_result_type(fcinfo, NULL, &tupdesc);
	btupdesc = BlessTupleDesc(tupdesc);
	attinmeta = TupleDescGetAttInMetadata(btupdesc);
	tuple = BuildTupleFromCStrings(attinmeta, str);
	result = HeapTupleGetDatum(tuple);

	if (str[0])
		pfree(str[0]);

	return result;
}
Esempio n. 5
0
void epoll::update(const io::channel *context) {
    auto *event = find_event(context);
    if (event) {
        event->events = context->flags;
        if (-1 == epoll_ctl(efd_, EPOLL_CTL_MOD, context->socket->get_fd(), event)) {
            // WTF?
        }
    }
}
Esempio n. 6
0
static void
register_event(text *event_name)
{
	alert_event *ev;
	int *new_receivers;
	int first_free;
	int i;

	find_lock(sid, true);
	ev = find_event(event_name, true, NULL);

	first_free = NOT_FOUND;
	for (i = 0; i < ev->max_receivers; i++)
	{
		if (ev->receivers[i] == sid)
			return;   /* event is registered */
		if (ev->receivers[i] == NOT_USED && first_free == NOT_FOUND)
			first_free = i;
	}

	/*
	 * I can have a maximum of MAX_LOCKS receivers for one event.
	 * Array receivers is increased for 16 fields
	 */
	if (first_free == NOT_FOUND)
	{
		if (ev->max_receivers + 16 > MAX_LOCKS)
			ereport(ERROR,
    				(errcode(ERRCODE_ORA_PACKAGES_LOCK_REQUEST_ERROR),
        			 errmsg("lock request error"),
					 errdetail("Failed to create session lock."),
        			 errhint("There are too many collaborating sessions. Increase MAX_LOCKS in 'pipe.h'.")));

		/* increase receiver's array */

		new_receivers = (int*)salloc((ev->max_receivers + 16)*sizeof(int));

		for (i = 0; i < ev->max_receivers + 16; i++)
		{
			if (i < ev->max_receivers)
				new_receivers[i] = ev->receivers[i];
			else
				new_receivers[i] = NOT_USED;
		}

		ev->max_receivers += 16;
		if (ev->receivers)
			ora_sfree(ev->receivers);

		ev->receivers = new_receivers;

		first_free = ev->max_receivers - 16;
	}

	ev->receivers_number += 1;
	ev->receivers[first_free] = sid;
}
Esempio n. 7
0
static void
init_hwc_ctr(const char *arg, struct argp_state *state)
{
    assert(is_hwc_event(arg));
    const char *ctr = arg + sizeof(prefix_hwc_event) - 1;
    const event_name_id_t *event = find_event(hwc_events, ctr, 1);

    if (event) {
        const int event_name_len = strlen(event->name);
        const char *cur = ctr + event_name_len;
        uint8_t cache_id = (uint8_t)event->id;
        uint8_t op_id;
        uint8_t res_id;

        if (cur[0] != ':' || cur[1] == '\0')
            argp_error(state, "No cache op specified.\n");

        switch (*(++cur)) {
        case 'r':
            op_id = PERF_COUNT_HW_CACHE_OP_READ;
            break;
        case 'w':
            op_id = PERF_COUNT_HW_CACHE_OP_WRITE;
            break;
        case 'p':
            op_id = PERF_COUNT_HW_CACHE_OP_PREFETCH;
            break;
        default:
            argp_error(state, "Invalid cache op specified.\n");
        }

        cur++;
        if (cur[0] != ':' || cur[1] == '\0')
            argp_error(state, "No cache result specified.\n");

        switch (*(++cur)) {
        case 'a':
            res_id = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
            break;
        case 'm':
            res_id = PERF_COUNT_HW_CACHE_RESULT_MISS;
            break;
        default:
            argp_error(state, "Invalid cache result specified.\n");
        }

        cur++;
        if (cur[0] != '\0')
            argp_error(state, "Illegal HWC string specified.\n");

        init_ctr(PERF_TYPE_HW_CACHE,
                 (res_id << 16) | (op_id << 8) | cache_id);
    } else
        argp_error(state, "Invalid cache specified.\n");
}
Esempio n. 8
0
void remove_lsa(struct ospf_lsa *lsa) {
	struct replay_nlist *item;
	struct ospf_event *event;
	item = find_in_nlist(ospf0->lsdb->lsa_list[lsa->header->type],(void *)lsa);
	ospf0->lsdb->lsa_list[lsa->header->type] = remove_from_nlist(ospf0->lsdb->lsa_list[lsa->header->type],item);
	ospf0->lsdb->count--;
	event = find_event((void *)lsa,OSPF_EVENT_LSA_AGING);
	remove_event(event);
	free(lsa->header);
	free(lsa);
}
Esempio n. 9
0
static void
init_hw_ctr(const char *arg, struct argp_state *state)
{
    assert(is_hw_event(arg));
    const char *ctr = arg + sizeof(prefix_hw_event) - 1;
    const event_name_id_t *event = find_event(hw_events, ctr, 0);

    if (event)
        init_ctr(PERF_TYPE_HARDWARE, event->id);
    else
        argp_error(state, "Invalid hardware event specified.\n");
}
Esempio n. 10
0
/** 
 * find_rtas_end
 * @brief Find the ending of a RTAS event.
 * 
 * @param textstart pointer to starting point of search
 * @param textend pointer to ending point of search
 * @return pointer to RTAS event end on success, NULL on failure.
 */
char *
find_rtas_end(char *textstart, char *textend)
{
	if (textstart == NULL)
		return NULL;

	if (bad_char_end[0] == -1)
		setup_bc(RTAS_END, strlen(RTAS_END), bad_char_end);
	
	return find_event(RTAS_END, strlen(RTAS_END), textstart,
			  textend - textstart, bad_char_end);
}
Esempio n. 11
0
/** 
 * find_rtas_start
 * @brief Find the beginning of a RTAS event.
 *
 * @param textstart pointer to starting point of search
 * @param textend pointer to ending point of search
 * @return pointer to RTAS event start on success, NULL on failure.
 */
char *
find_rtas_start(char *textstart, char *textend) 
{
	if (textstart == NULL)
		return NULL;

	if (bad_char_start[0] == -1)
		setup_bc(RTAS_START, strlen(RTAS_START), bad_char_start);

	return find_event(RTAS_START, strlen(RTAS_START), textstart,
			  textend - textstart, bad_char_start);
}
Esempio n. 12
0
bool machine_t::cancel_by_cookie(cookie_t c) // XXX need some clean up here?
{
  pause_t x(this) ;

  if(event_t *e = find_event(c))
  {
    cancel_event(e) ;
    return true ;
  }
  else
  {
    log_error("[%d]: cookie not found", c.value()) ;
    return false ;
  }
}
Esempio n. 13
0
void delete_event(icalcomponent* calendar)
{
  icalcomponent* event = find_event(calendar);
   
  if (!yes_no_prompt("Are you sure you want to delete this event? (y/n"))
  {
    return;
  }
  
  //Find the event in the components
  icalcomponent* c = icalcomponent_get_first_component(calendar, ICAL_VEVENT_COMPONENT);
  
  bool found_event = false;
  
  while((c=icalcomponent_get_current_component(c)) != 0 )
  { 
    if(icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT)
    {
      if (c == event)
      {
        icalcomponent_remove_component(calendar, c);
        found_event = true;
      }
    }else
    { 
      icalcomponent_get_next_component(calendar, ICAL_VEVENT_COMPONENT); 
    }
  }
  
  if (!found_event)
  {
    append_action_to_closed_log("Delete event", false);
    return;
  }
  
  append_action_to_closed_log("Delete event", true);
}
Esempio n. 14
0
// Compute the dependencies of a given event.  Returns a list of (thread,kind,event) triples.
vector<Tuple<int,int,history_t>> event_dependencies(const vector<vector<Array<const history_t>>>& event_sorted_history, const int direction, const int thread, const int kind, const history_t source) {
  vector<Tuple<int,int,history_t>> deps;
  for (const auto kind_event : dependencies(direction,time_kind_t(kind),source.event)) {
    const int dep_kind = kind_event.x;
    const event_t dep_event = kind_event.y;
    // Search for event in each thread
    bool found = false;
    for (const int t : range((int)event_sorted_history.size())) {
      const auto& sorted_events = event_sorted_history.at(t).at(dep_kind);
      for (const int i : range(find_event(sorted_events,dep_event),sorted_events.size())) {
        const history_t& event = sorted_events[i];
        if (event.event != dep_event)
          break;
        GEODE_ASSERT(!found || dep_kind==compute_kind);
        found = true;
        deps.push_back(tuple(t,dep_kind,event));
      }
    }
    if (!found) {
      int count = 0;
      for (const int t : range((int)event_sorted_history.size())) {
        const auto& events = event_sorted_history[t].at(dep_kind);
        for (const int i : range(max(0,events.size()-1)))
          if (events[i].event > events[i+1].event)
            THROW(RuntimeError,"event_dependencies: order failure: thread %d, kind %d, i %d (%d), events %lld %lld",t,dep_kind,i,events.size(),events[i].event,events[i+1].event);
        for (auto& e : events)
          if (e.event==dep_event)
            count++;
      }
      THROW(RuntimeError,"event_dependencies: dependency not found, direction = %d, count %d, source = %d %s %s, dependency = %s %s",
        direction,count,
        thread,time_kind_names().at(kind),str_event(source.event),
        time_kind_names().at(dep_kind),str_event(dep_event));
    }
  }
  return deps;
}
Esempio n. 15
0
DLLSYM WINDOW def_await_event(                           /*wait for event */
                              WINDOW win,                /*window to wait on */
                              BOOL8 wait,                /*waiting flag */
                              INT8 event_type,           /*type to wait for */
                              GRAPHICS_EVENT *out_event  /*output event */
                             ) {
  GRAPHICS_EVENT *event;         /*return event */
  INT16 fd;                      //file descriptor

  if (win == NULL)
    fd = 0;
  else
    fd = win->get_fd ();
                                 /*look for one */
  event = find_event (fd, wait, event_type);
  if (event == NULL)
    return NULL;                 /*not found */
  else {
    *out_event = *event;         /*copy event */
    if (event->type != DESTROY_EVENT)
      delete event;              //free the element
    return out_event->fd;
  }
}
Esempio n. 16
0
void VMEvent::exception_event(Throwable *exception,
                                   JavaFrame *catch_frame,
                                   DebuggerEvent *d_event, int catch_offset)
{
  check_notify_wanted(Dbg_EventKind_EXCEPTION);

  UsingFastOops fast_oops;

  VMEvent::Fast ep, ep_2;
  jlong throw_offset = 0;
  int event_count = 0;
  jbyte suspend_policy = JDWP_SuspendPolicy_NONE;
  InstanceClass::Fast ic;
  LocationModifier::Fast location;
  Method::Fast catch_method;
  Method::Fast throw_method;
  int data_len = JDWP_EVENT_LEN;

  ep = ep_2 = get_event_request(d_event, event_count, suspend_policy);
  if (ep.is_null()) {
    return;
  }
  // Flush any packets waiting in the queue.  This helps avoid a race
  // condition where we may have a resume command in the queue for a
  // previous event, we send this event, process the resume command
  // out of order
  JavaDebugger::dispatch(0);

  // Calculate packet length
  data_len += (JDWP_EVENT_EXCEPTION_LEN * event_count);

  Transport::Fast transport = ep().transport();
  PacketOutputStream out(&transport, data_len, JDWP_COMMAND_SET(Event),
                         JDWP_COMMAND(Event, Composite));
  // Create a buffered output stream so we can asynchronously send an error
  // Calculate the size based on half of the items being 'longs'
  UsingFastOops fast_oops_2;

  Thread::Fast thread = JavaDebugger::get_thread_by_id(d_event->thread_id());
  VMEventModifier::deoptimize_frame(&thread, true);


  VMEvent::Fast info_event = find_event((jbyte)VM_EXCEPTION_INFO_EVENT);
  if (!info_event.is_null()) {
    location = get_modifier(&info_event,
        JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly);
    GUARANTEE(!location.is_null(), "No location modifier in info event");
    throw_method = location().method();
    throw_offset = location().offset();
    remove_event_request(&info_event);
  } else {
    UsingFastOops fast_oops_3;
    ObjArray::Fast trace, methods;
    TypeArray::Fast offsets;
    trace = exception->backtrace();
    if (!trace.is_null()) {
      methods = trace().obj_at(0);
      offsets = trace().obj_at(1);
      if (!methods.is_null() && !offsets.is_null()) {
        throw_method = methods().obj_at(0);
        throw_offset = (jlong)(offsets().int_at(0));
      }
    }
  }

  DEBUGGER_EVENT(("Exception"));
  out.write_byte(suspend_policy);
  out.write_int(event_count);
  while (ep.not_null()) {
    out.write_byte(JDWP_EventKind_EXCEPTION);        
    out.write_int(ep().event_id());

    // thread with exception
    out.write_int(d_event->thread_id());

    // location of exception throw
    if (throw_method.not_null()) {
      ic = throw_method().holder();
    }
    DebuggerEvent throw_event(JDWP_EventKind_EXCEPTION,
                              0, // don't need thread
                              JavaDebugger::get_object_id_by_ref(&ic),
                              JavaDebugger::get_method_id(&ic, &throw_method),
                              (jlong)throw_offset);
    throw_event.write_as_location(&out);

    // thrown exception 
    out.write_byte('L');
    out.write_object(exception);

    // location of catch, or 0 if not caught

    if (catch_frame == NULL) {
      LocationModifier::write_null_location(&out);
    } else {
      catch_method = catch_frame->method();
      ic = catch_method().holder();
      DebuggerEvent catch_event(JDWP_EventKind_EXCEPTION,
                                0, // don't need thread
                                JavaDebugger::get_object_id_by_ref(&ic),
                                JavaDebugger::get_method_id(&ic, &catch_method),
                                (jlong)catch_offset);
      catch_event.write_as_location(&out);
    }
    ep = ep().send_next();
  }
  out.send_packet();
  JavaDebugger::process_suspend_policy(suspend_policy, &thread,
                                      true);
}
Esempio n. 17
0
static void
create_message(text *event_name, text *message)
{
	int event_id;
	alert_event *ev;
	message_item *msg_item = NULL;
	int i,j,k;

	find_event(event_name, false, &event_id);

	/* process event only when any recipient exitsts */
	if (NULL != (ev = find_event(event_name, false, &event_id)))
	{
		if (ev->receivers_number > 0)
		{
			msg_item = ev->messages;
			while (msg_item != NULL)
			{
				if (msg_item->message == NULL && message == NULL)
				    return;
				if (msg_item->message != NULL && message != NULL)
					if (0 == textcmpm(message,msg_item->message))
						return;

				msg_item = msg_item->next_message;
			}

			msg_item = salloc(sizeof(message_item));

			msg_item->receivers = salloc( ev->receivers_number*sizeof(int));
			msg_item->receivers_number = ev->receivers_number;


			if (message != NULL)
				msg_item->message = ora_scstring(message);
			else
				msg_item->message = NULL;

			msg_item->message_id = event_id;
			for (i = j = 0; j < ev->max_receivers; j++)
			{
				if (ev->receivers[j] != NOT_USED)
				{
					msg_item->receivers[i++] = ev->receivers[j];
					for (k = 0; k < MAX_LOCKS; k++)
						if (locks[k].sid == ev->receivers[j])
						{
							/* create echo */

							message_echo *echo = salloc(sizeof(message_echo));
							echo->message = msg_item;
							echo->message_id = event_id;
							echo->next_echo = NULL;

							if (locks[k].echo == NULL)
								locks[k].echo = echo;
							else
							{
								message_echo *p;
								p = locks[k].echo;

								while (p->next_echo != NULL)
									p = p->next_echo;

								p->next_echo = echo;
							}
						}

				}
			}

			msg_item->next_message = NULL;
			if (ev->messages == NULL)
			{
				msg_item->prev_message = NULL;
				ev->messages = msg_item;
			}
			else
			{
				message_item *p;
				p = ev->messages;
				while (p->next_message != NULL)
					p = p->next_message;

				p->next_message = msg_item;
				msg_item->prev_message = p;
			}

		}
	}
}
Esempio n. 18
0
File: main.c Progetto: pamolloy/dzen
int main( int ac, char *av[] )
{
	int i;

	set_dzen();	// Default values
	x_connect();
	x_read_resources();
	parse_opts(ac, av);

	if(dzen.tsupdate && !dzen.slave_win.max_lines)
		dzen.tsupdate = False;

	if(!dzen.title_win.width)
		dzen.title_win.width = dzen.slave_win.width;

	if(!setlocale(LC_ALL, "") || !XSupportsLocale())
		puts("dzen: locale not available, expect problems with fonts.\n");

	if(action_string)
		fill_ev_table(action_string);
	else {
		if(!dzen.slave_win.max_lines) {
			char edef[] = "button3=exit:13";
			fill_ev_table(edef);
		}
		else if(dzen.slave_win.ishmenu) {
			char edef[] = "enterslave=grabkeys;leaveslave=ungrabkeys;"
				"button4=scrollup;button5=scrolldown;"
				"key_Left=scrollup;key_Right=scrolldown;"
				"button1=menuexec;button3=exit:13;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
		else {
			char edef[]  = "entertitle=uncollapse,grabkeys;"
				"enterslave=grabkeys;leaveslave=collapse,ungrabkeys;"
				"button1=menuexec;button2=togglestick;button3=exit:13;"
				"button4=scrollup;button5=scrolldown;"
				"key_Up=scrollup;key_Down=scrolldown;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
	}

	if((find_event(onexit) != -1)
			&& (setup_signal(SIGTERM, catch_sigterm) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGTERM\n");

	if((find_event(sigusr1) != -1)
			&& (setup_signal(SIGUSR1, catch_sigusr1) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR1\n");

	if((find_event(sigusr2) != -1)
		&& (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR2\n");

	if(setup_signal(SIGALRM, catch_alrm) == SIG_ERR)
		fprintf(stderr, "dzen: error hooking SIGALARM\n");

	x_create_windows(use_ewmh_dock);

	if(!dzen.slave_win.ishmenu)
		x_map_window(dzen.title_win.win);
	else {
		XMapRaised(dzen.dpy, dzen.slave_win.win);
		for(i=0; i < dzen.slave_win.max_lines; i++)
			XMapWindow(dzen.dpy, dzen.slave_win.line[i]);
	}

	if( fnpre != NULL )
		font_preload(fnpre);

	do_action(onstart);

	event_loop();	// Main loop

	do_action(onexit);
	clean_up();

	if(dzen.ret_val)
		return dzen.ret_val;

	exit(EXIT_SUCCESS);
}
Esempio n. 19
0
int main()
{
  vector<string> classes; //the first line of the ics7 file contains the elements of this
  
  icalproperty_set_x_name(ical_x_class_prop, "X-CLASS");

  icalcomponent* calendar = NULL;
  struct icaltimetype atime;
  struct icalperiodtype rtime;

  //FIXME Later versions will try to load from the default file here
  
  //If we don't have a saved calendar, make a new one
  if (calendar == NULL)
  {
    atime = icaltime_from_timet( time(0),0);

    rtime.start = icaltime_from_timet( time(0),0);
    rtime.end = icaltime_from_timet( time(0),0);
    rtime.end.hour++;
    
    calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
  }
  
  //FIXME Find all non-school days by prompt?
  
  //FIXME Ask for start/end of semester
  
  //Actually manipulating the calendar
  while (true)
  {
    //Prompt for user action
    cout << "What would you like to do?\n" <<
      "1. Add a class\n" <<
      "2. Add an event\n" <<
      "3. Delete an event\n" <<
      "4. Edit an event\n" <<
      "5. Find an event\n" <<
      "6. View an event\n" << 
      "7. Delete a class\n" <<
      "8. Exit the program\n" << endl;
    cout << "Enter the integer corresponding to your choice" << endl;
    
    string user_choice = "";
    cin >> user_choice;
    
    bool user_choice_flag = true;
    
    //Check the string is all digits
    for (int i = 0; i < user_choice.size(); i++)
    {
      if (!isdigit(user_choice[i]))
      {
        cout << "Invalid selection (Not all digits)" << endl;
        user_choice_flag = false;
        break;
      }
    }
    
    if (!user_choice_flag)
    {
      continue;
    }
    
    //Given the choice, perform the desired action
    switch (atoi(user_choice.c_str()))
    {
      //ADD CLASS
      case 1:
      {
        add_class(calendar, classes);
        break;
      }
      
      //ADD EVENT (for a class or in general)
      case 2:
      {
        add_event(calendar);
        break;
      }
      
      //DELETE SINGLE EVENT
      case 3:
      {
        delete_event(calendar);
        break;
      }
      
      //EDIT EVENT (class or general)
      case 4:
      {
        edit_event(calendar);
        break;
      }
      
      //FIND EVENT
      case 5:
      {
        icalcomponent* event = find_event(calendar);
        if (event == NULL)
        {
          append_action_to_closed_log("Find event", false);
        }else
        {
          append_action_to_closed_log("Find event", true);
        }
        break;
      }
      
      //VIEW EVENT
      case 6:
      {
        view_event(calendar);
        break;
      }
      
      //DELETE CLASS
      //FIXME Not implemented in this sprint
      case 7:
      {
        //FIXME Ask for class name
        //FIXME Scan through first level of components for class
        //FIXME Print all matches and get the one to delete
        //FIXME Warn that all events for that class will be deleted
        //FIXME Delete class after user okay
        
        cout << "This feature is not implemented in this sprint." << endl;
        break;
      }
      
      //EXIT
      case 8:
      {
        //Prompt for okay
        if (yes_no_prompt("Your calendar data will not be saved. Continue? (y/n)"))
        {
          return 0;
        }
        
        break;
      }
      
      default:
      {
        cout << "Invalid selection (Not between 1 and 8 inclusive)" << endl;
        break;
      }
    }
  }
  
  return 0;
}
/**
 * pevent_filter_add_filter_str - add a new filter
 * @filter: the event filter to add to
 * @filter_str: the filter string that contains the filter
 * @error_str: string containing reason for failed filter
 *
 * Returns 0 if the filter was successfully added
 *   -1 if there was an error.
 *
 * On error, if @error_str points to a string pointer,
 * it is set to the reason that the filter failed.
 * This string must be freed with "free".
 */
int pevent_filter_add_filter_str(struct event_filter *filter,
				 const char *filter_str,
				 char **error_str)
{
	struct pevent *pevent = filter->pevent;
	struct event_list *event;
	struct event_list *events = NULL;
	const char *filter_start;
	const char *next_event;
	char *this_event;
	char *event_name = NULL;
	char *sys_name = NULL;
	char *sp;
	int rtn = 0;
	int len;
	int ret;

	/* clear buffer to reset show error */
	pevent_buffer_init("", 0);

	if (error_str)
		*error_str = NULL;

	filter_start = strchr(filter_str, ':');
	if (filter_start)
		len = filter_start - filter_str;
	else
		len = strlen(filter_str);


	do {
		next_event = strchr(filter_str, ',');
		if (next_event &&
		    (!filter_start || next_event < filter_start))
			len = next_event - filter_str;
		else if (filter_start)
			len = filter_start - filter_str;
		else
			len = strlen(filter_str);

		this_event = malloc_or_die(len + 1);
		memcpy(this_event, filter_str, len);
		this_event[len] = 0;

		if (next_event)
			next_event++;

		filter_str = next_event;

		sys_name = strtok_r(this_event, "/", &sp);
		event_name = strtok_r(NULL, "/", &sp);

		if (!sys_name) {
			show_error(error_str, "No filter found");
			/* This can only happen when events is NULL, but still */
			free_events(events);
			free(this_event);
			return -1;
		}

		/* Find this event */
		ret = find_event(pevent, &events, strim(sys_name), strim(event_name));
		if (ret < 0) {
			if (event_name)
				show_error(error_str,
					   "No event found under '%s.%s'",
					   sys_name, event_name);
			else
				show_error(error_str,
					   "No event found under '%s'",
					   sys_name);
			free_events(events);
			free(this_event);
			return -1;
		}
		free(this_event);
	} while (filter_str);

	/* Skip the ':' */
	if (filter_start)
		filter_start++;

	/* filter starts here */
	for (event = events; event; event = event->next) {
		ret = filter_event(filter, event->event, filter_start,
				   error_str);
		/* Failures are returned if a parse error happened */
		if (ret < 0)
			rtn = ret;

		if (ret >= 0 && pevent->test_filters) {
			char *test;
			test = pevent_filter_make_string(filter, event->event->id);
			printf(" '%s: %s'\n", event->event->name, test);
			free(test);
		}
	}

	free_events(events);

	if (rtn >= 0 && pevent->test_filters)
		exit(0);

	return rtn;
}
Esempio n. 21
0
void event_message_process(char *eventbuf)
{
    int retVal = 0;
    EvtMessage *current = NULL;
    char source[64];
    char cmd[64];
    char buf[512];              /* Longest legal IRC command line */
    char *s;
    int ac;                     /* Parameters for the command */
    char **av;
    EvtMessage *evm;

    /* zero out the buffers before we do much else */
    *buf = '\0';
    *source = '\0';
    *cmd = '\0';

    strscpy(buf, eventbuf, sizeof(buf));

    doCleanBuffer((char *) buf);

    /* Split the buffer into pieces. */
    if (*buf == ':') {
        s = strpbrk(buf, " ");
        if (!s)
            return;
        *s = 0;
        while (isspace(*++s));
        strscpy(source, buf + 1, sizeof(source));
        memmove(buf, s, strlen(s) + 1);
    } else {
        *source = 0;
    }
    if (!*buf)
        return;
    s = strpbrk(buf, " ");
    if (s) {
        *s = 0;
        while (isspace(*++s));
    } else
        s = buf + strlen(buf);
    strscpy(cmd, buf, sizeof(cmd));
    ac = split_buf(s, &av, 1);

    /* Do something with the message. */
    evm = find_event(cmd);
    if (evm) {
        char *mod_current_module_name_save = mod_current_module_name;
        Module *mod_current_module_save = mod_current_module;
        if (evm->func) {
            mod_current_module_name = evm->mod_name;
            mod_current_module = findModule(evm->mod_name);
            retVal = evm->func(source, ac, av);
            if (retVal == MOD_CONT) {
                current = evm->next;
                while (current && current->func && retVal == MOD_CONT) {
                    mod_current_module_name = current->mod_name;
                    mod_current_module = findModule(current->mod_name);
                    retVal = current->func(source, ac, av);
                    current = current->next;
                }
            }
            mod_current_module_name = mod_current_module_name_save;
            mod_current_module = mod_current_module_save;
        }
    }
    /* Free argument list we created */
    free(av);
}
/*ARGSUSED*/
static int
opt_pcbe_configure(uint_t picnum, char *event, uint64_t preset, uint32_t flags,
    uint_t nattrs, kcpc_attr_t *attrs, void **data, void *token)
{
	opt_pcbe_config_t	*cfg;
	amd_event_t		*evp;
	amd_event_t		ev_raw = { "raw", 0};
	amd_generic_event_t	*gevp;
	int			i;
	uint64_t		evsel = 0, evsel_tmp = 0;

	/*
	 * If we've been handed an existing configuration, we need only preset
	 * the counter value.
	 */
	if (*data != NULL) {
		cfg = *data;
		cfg->opt_rawpic = preset & MASK48;
		return (0);
	}

	if (picnum >= 4)
		return (CPC_INVALID_PICNUM);

	if ((evp = find_event(event)) == NULL) {
		if ((gevp = find_generic_event(event)) != NULL) {
			evp = find_event(gevp->event);
			ASSERT(evp != NULL);

			if (nattrs > 0)
				return (CPC_ATTRIBUTE_OUT_OF_RANGE);

			evsel |= gevp->umask << OPT_PES_UMASK_SHIFT;
		} else {
			long tmp;

			/*
			 * If ddi_strtol() likes this event, use it as a raw
			 * event code.
			 */
			if (ddi_strtol(event, NULL, 0, &tmp) != 0)
				return (CPC_INVALID_EVENT);

			ev_raw.emask = tmp;
			evp = &ev_raw;
		}
	}

	/*
	 * Configuration of EventSelect register. While on some families
	 * certain bits might not be supported (e.g. Guest/Host on family
	 * 11h), setting these bits is harmless
	 */

	/* Set GuestOnly bit to 0 and HostOnly bit to 1 */
	evsel &= ~OPT_PES_HOST;
	evsel &= ~OPT_PES_GUEST;

	/* Set bits [35:32] for extended part of Event Select field */
	evsel_tmp = evp->emask & 0x0f00;
	evsel |= evsel_tmp << 24;

	evsel |= evp->emask & 0x00ff;

	if (flags & CPC_COUNT_USER)
		evsel |= OPT_PES_USR;
	if (flags & CPC_COUNT_SYSTEM)
		evsel |= OPT_PES_OS;
	if (flags & CPC_OVF_NOTIFY_EMT)
		evsel |= OPT_PES_INT;

	for (i = 0; i < nattrs; i++) {
		if (strcmp(attrs[i].ka_name, "edge") == 0) {
			if (attrs[i].ka_val != 0)
				evsel |= OPT_PES_EDGE;
		} else if (strcmp(attrs[i].ka_name, "pc") == 0) {
			if (attrs[i].ka_val != 0)
				evsel |= OPT_PES_PC;
		} else if (strcmp(attrs[i].ka_name, "inv") == 0) {
			if (attrs[i].ka_val != 0)
				evsel |= OPT_PES_INV;
		} else if (strcmp(attrs[i].ka_name, "cmask") == 0) {
			if ((attrs[i].ka_val | OPT_PES_CMASK_MASK) !=
			    OPT_PES_CMASK_MASK)
				return (CPC_ATTRIBUTE_OUT_OF_RANGE);
			evsel |= attrs[i].ka_val << OPT_PES_CMASK_SHIFT;
		} else if (strcmp(attrs[i].ka_name, "umask") == 0) {
			if ((attrs[i].ka_val | OPT_PES_UMASK_MASK) !=
			    OPT_PES_UMASK_MASK)
				return (CPC_ATTRIBUTE_OUT_OF_RANGE);
			evsel |= attrs[i].ka_val << OPT_PES_UMASK_SHIFT;
		} else
			return (CPC_INVALID_ATTRIBUTE);
	}

	cfg = kmem_alloc(sizeof (*cfg), KM_SLEEP);

	cfg->opt_picno = picnum;
	cfg->opt_evsel = evsel;
	cfg->opt_rawpic = preset & MASK48;

	*data = cfg;
	return (0);
}
Esempio n. 23
0
int
main(int argc, char *argv[]) {
	int i, use_ewmh_dock=0;
	char *action_string = NULL;
	char *endptr, *fnpre = NULL;

	/* default values */
	dzen.title_win.name = "dzen title";
	dzen.slave_win.name = "dzen slave";
	dzen.cur_line  = 0;
	dzen.ret_val   = 0;
	dzen.title_win.x = dzen.slave_win.x = 0;
	dzen.title_win.y = 0;
	dzen.title_win.width = dzen.slave_win.width = 0;
	dzen.title_win.alignment = ALIGNCENTER;
	dzen.slave_win.alignment = ALIGNLEFT;
	dzen.fnt = FONT;
	dzen.bg  = BGCOLOR;
	dzen.fg  = FGCOLOR;
	dzen.slave_win.max_lines  = 0;
	dzen.running = True;
	dzen.xinescreen = 0;
	dzen.tsupdate = 0;
	dzen.line_height = 0;
	dzen.title_win.expand = noexpand;

	/* Connect to X server */
	x_connect();
	x_read_resources();

	/* cmdline args */
	for(i = 1; i < argc; i++)
		if(!strncmp(argv[i], "-l", 3)){
			if(++i < argc) {
				dzen.slave_win.max_lines = atoi(argv[i]);
				if(dzen.slave_win.max_lines)
					init_input_buffer();
			}
		}
		else if(!strncmp(argv[i], "-geometry", 10)) {
			if(++i < argc) {
				int t;
				int tx, ty;
				unsigned int tw, th;

				t = XParseGeometry(argv[i], &tx, &ty, &tw, &th);

				if(t & XValue)
					dzen.title_win.x = tx;
				if(t & YValue) {
					dzen.title_win.y = ty;
					if(!ty && (t & YNegative))
						/* -0 != +0 */
						dzen.title_win.y = -1;
				}
				if(t & WidthValue)
					dzen.title_win.width = (signed int) tw;
				if(t & HeightValue)
					dzen.line_height = (signed int) th;
			}
		}
		else if(!strncmp(argv[i], "-u", 3)){
			dzen.tsupdate = True;
		}
		else if(!strncmp(argv[i], "-expand", 8)){
			if(++i < argc) {
				switch(argv[i][0]){
					case 'l':
						dzen.title_win.expand = left;
						break;
					case 'c':
						dzen.title_win.expand = both;
						break;
					case 'r':
						dzen.title_win.expand = right;
						break;
					default:
						dzen.title_win.expand = noexpand;
				}
			}
		}
		else if(!strncmp(argv[i], "-p", 3)) {
			dzen.ispersistent = True;
			if (i+1 < argc) {
				dzen.timeout = strtoul(argv[i+1], &endptr, 10);
				if(*endptr)
					dzen.timeout = 0;
				else
					i++;
			}
		}
		else if(!strncmp(argv[i], "-ta", 4)) {
			if(++i < argc) dzen.title_win.alignment = alignment_from_char(argv[i][0]);
		}
		else if(!strncmp(argv[i], "-sa", 4)) {
			if(++i < argc) dzen.slave_win.alignment = alignment_from_char(argv[i][0]);
		}
		else if(!strncmp(argv[i], "-m", 3)) {
			dzen.slave_win.ismenu = True;
			if(i+1 < argc) {
				if( argv[i+1][0] == 'v') {
					++i;
					break;
				}
				dzen.slave_win.ishmenu = (argv[i+1][0] == 'h') ? ++i, True : False;
			}
		}
		else if(!strncmp(argv[i], "-fn", 4)) {
			if(++i < argc) dzen.fnt = argv[i];
		}
		else if(!strncmp(argv[i], "-e", 3)) {
			if(++i < argc) action_string = argv[i];
		}
		else if(!strncmp(argv[i], "-title-name", 12)) {
			if(++i < argc) dzen.title_win.name = argv[i];
		}
		else if(!strncmp(argv[i], "-slave-name", 12)) {
			if(++i < argc) dzen.slave_win.name = argv[i];
		}
		else if(!strncmp(argv[i], "-bg", 4)) {
			if(++i < argc) dzen.bg = argv[i];
		}
		else if(!strncmp(argv[i], "-fg", 4)) {
			if(++i < argc) dzen.fg = argv[i];
		}
		else if(!strncmp(argv[i], "-x", 3)) {
			if(++i < argc) dzen.title_win.x = dzen.slave_win.x = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-y", 3)) {
			if(++i < argc) dzen.title_win.y = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-w", 3)) {
			if(++i < argc) dzen.slave_win.width = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-h", 3)) {
			if(++i < argc) dzen.line_height= atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-tw", 4)) {
			if(++i < argc) dzen.title_win.width = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-fn-preload", 12)) {
			if(++i < argc) {
				fnpre = estrdup(argv[i]);
			}
		}
#ifdef DZEN_XINERAMA
		else if(!strncmp(argv[i], "-xs", 4)) {
			if(++i < argc) dzen.xinescreen = atoi(argv[i]);
		}
#endif
		else if(!strncmp(argv[i], "-dock", 6))
			use_ewmh_dock = 1;
		else if(!strncmp(argv[i], "-v", 3)) {
			printf("dzen-"VERSION", (C)opyright 2007-2009 Robert Manea\n");
			printf(
			"Enabled optional features: "
#ifdef DZEN_XMP
			" XPM "
#endif
#ifdef DZEN_XFT
			" XFT"
#endif
#ifdef DZEN_XINERAMA
			" XINERAMA "
#endif
			"\n"
			);
			return EXIT_SUCCESS;
		}
		else
			eprint("usage: dzen2 [-v] [-p [seconds]] [-m [v|h]] [-ta <l|c|r>] [-sa <l|c|r>]\n"
                   "             [-x <pixel>] [-y <pixel>] [-w <pixel>] [-h <pixel>] [-tw <pixel>] [-u]\n"
				   "             [-e <string>] [-l <lines>]  [-fn <font>] [-bg <color>] [-fg <color>]\n"
				   "             [-geometry <geometry string>] [-expand <left|right>] [-dock]\n"
				   "             [-title-name <string>] [-slave-name <string>]\n"
#ifdef DZEN_XINERAMA
				   "             [-xs <screen>]\n"
#endif
				  );

	if(dzen.tsupdate && !dzen.slave_win.max_lines)
		dzen.tsupdate = False;

	if(!dzen.title_win.width)
		dzen.title_win.width = dzen.slave_win.width;

	if(!setlocale(LC_ALL, "") || !XSupportsLocale())
		puts("dzen: locale not available, expect problems with fonts.\n");

	if(action_string)
		fill_ev_table(action_string);
	else {
		if(!dzen.slave_win.max_lines) {
			char edef[] = "button3=exit:13";
			fill_ev_table(edef);
		}
		else if(dzen.slave_win.ishmenu) {
			char edef[] = "enterslave=grabkeys;leaveslave=ungrabkeys;"
				"button4=scrollup;button5=scrolldown;"
				"key_Left=scrollup;key_Right=scrolldown;"
				"button1=menuexec;button3=exit:13;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
		else {
			char edef[]  = "entertitle=uncollapse,grabkeys;"
				"enterslave=grabkeys;leaveslave=collapse,ungrabkeys;"
				"button1=menuexec;button2=togglestick;button3=exit:13;"
				"button4=scrollup;button5=scrolldown;"
				"key_Up=scrollup;key_Down=scrolldown;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
	}

	if((find_event(onexit) != -1)
			&& (setup_signal(SIGTERM, catch_sigterm) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGTERM\n");

	if((find_event(sigusr1) != -1)
			&& (setup_signal(SIGUSR1, catch_sigusr1) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR1\n");

	if((find_event(sigusr2) != -1)
		&& (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR2\n");

	if(setup_signal(SIGALRM, catch_alrm) == SIG_ERR)
		fprintf(stderr, "dzen: error hooking SIGALARM\n");

	if(dzen.slave_win.ishmenu &&
			!dzen.slave_win.max_lines)
		dzen.slave_win.max_lines = 1;


	x_create_windows(use_ewmh_dock);

	if(!dzen.slave_win.ishmenu)
		x_map_window(dzen.title_win.win);
	else {
		XMapRaised(dzen.dpy, dzen.slave_win.win);
		for(i=0; i < dzen.slave_win.max_lines; i++)
			XMapWindow(dzen.dpy, dzen.slave_win.line[i]);
	}

	/* Reposition the window back to where it should be */
	XMoveWindow(dzen.dpy,dzen.title_win.win,dzen.title_win.x,dzen.title_win.y);

	if( fnpre != NULL )
		font_preload(fnpre);

	do_action(onstart);

	/* main loop */
	event_loop();

	do_action(onexit);
	clean_up();

	if(dzen.ret_val)
		return dzen.ret_val;

	return EXIT_SUCCESS;
}
Esempio n. 24
0
int
main(int argc, char *argv[]) {
	int i;
	char *action_string = NULL;
	char *endptr;

	/* default values */
	dzen.cur_line  = 0;
	dzen.ret_val   = 0;
	dzen.title_win.x = dzen.slave_win.x = 0;
	dzen.title_win.y = 0;
	dzen.title_win.width = dzen.slave_win.width = 0;
	dzen.title_win.alignment = ALIGNCENTER;
	dzen.slave_win.alignment = ALIGNLEFT;
	dzen.fnt = FONT;
	dzen.bg  = BGCOLOR;
	dzen.fg  = FGCOLOR;
	dzen.slave_win.max_lines  = 0;
	dzen.running = True;
	dzen.xinescreen = 0;
	dzen.tsupdate = 0;
	dzen.line_height = 0;

	/* cmdline args */
	for(i = 1; i < argc; i++)
		if(!strncmp(argv[i], "-l", 3)){
			if(++i < argc) {
				dzen.slave_win.max_lines = atoi(argv[i]);
				init_input_buffer();
			}
		}
		else if(!strncmp(argv[i], "-u", 3)){
			dzen.tsupdate = True;
		}
		else if(!strncmp(argv[i], "-p", 3)) {
			dzen.ispersistent = True;
			if (i+1 < argc) {
				dzen.timeout = strtoul(argv[i+1], &endptr, 10);
				if(*endptr)
					dzen.timeout = 0;
				else
					i++;
			}
		}
		else if(!strncmp(argv[i], "-ta", 4)) {
			if(++i < argc) dzen.title_win.alignment = argv[i][0];
		}
		else if(!strncmp(argv[i], "-sa", 4)) {
			if(++i < argc) dzen.slave_win.alignment = argv[i][0];
		}
		else if(!strncmp(argv[i], "-m", 3)) {
			dzen.slave_win.ismenu = True;
			if(i+1 < argc) 
				dzen.slave_win.ishmenu = (argv[i+1][0] == 'h') ? ++i, True : False;
		}
		else if(!strncmp(argv[i], "-fn", 4)) {
			if(++i < argc) dzen.fnt = argv[i];
		}
		else if(!strncmp(argv[i], "-e", 3)) {
			if(++i < argc) action_string = argv[i];
		}
		else if(!strncmp(argv[i], "-bg", 4)) {
			if(++i < argc) dzen.bg = argv[i];
		}
		else if(!strncmp(argv[i], "-fg", 4)) {
			if(++i < argc) dzen.fg = argv[i];
		}
		else if(!strncmp(argv[i], "-x", 3)) {
			if(++i < argc) dzen.title_win.x = dzen.slave_win.x = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-y", 3)) {
			if(++i < argc) dzen.title_win.y = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-w", 3)) {
			if(++i < argc) dzen.slave_win.width = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-h", 3)) {
			if(++i < argc) dzen.line_height= atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-tw", 4)) {
			if(++i < argc) dzen.title_win.width = atoi(argv[i]);
		}
#ifdef DZEN_XINERAMA
		else if(!strncmp(argv[i], "-xs", 4)) {
			if(++i < argc) dzen.xinescreen = atoi(argv[i]);
		}
#endif
		else if(!strncmp(argv[i], "-v", 3)) 
			eprint("dzen-"VERSION", (C)opyright 2007 Robert Manea\n");
		else
			eprint("usage: dzen2 [-v] [-p [seconds]] [-m [v|h]] [-ta <l|c|r>] [-sa <l|c|r>]\n"
                   "             [-x <pixel>] [-y <pixel>] [-w <pixel>] [-tw <pixel>] [-u] \n"
				   "             [-e <string>] [-l <lines>]  [-fn <font>] [-bg <color>] [-fg <color>]\n"
#ifdef DZEN_XINERAMA
				   "             [-xs <screen>]\n"
#endif
				  );

	if(dzen.tsupdate && !dzen.slave_win.max_lines)
		dzen.tsupdate = False;

	if(!dzen.title_win.width)
		dzen.title_win.width = dzen.slave_win.width;

	if(!setlocale(LC_ALL, "") || !XSupportsLocale())
		puts("dzen: locale not available, expect problems with fonts.\n");

	if(action_string) 
		fill_ev_table(action_string);
	else {
		if(!dzen.slave_win.max_lines) {
			char edef[] = "button3=exit:13";
			fill_ev_table(edef);
		}
		else if(dzen.slave_win.ishmenu) {
			char edef[] = "enterslave=grabkeys;leaveslave=ungrabkeys;"
				"button4=scrollup;button5=scrolldown;"
				"key_Left=scrollup;key_Right=scrolldown;"
				"button1=menuexec;button3=exit:13;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
		else {
			char edef[]  = "entertitle=uncollapse,grabkeys;"
				"enterslave=grabkeys;leaveslave=collapse,ungrabkeys;"
				"button1=menuexec;button2=togglestick;button3=exit:13;"
				"button4=scrollup;button5=scrolldown;"
				"key_Up=scrollup;key_Down=scrolldown;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
	}

	if((find_event(onexit) != -1) 
			&& (setup_signal(SIGTERM, catch_sigterm) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGTERM\n");

	if((find_event(sigusr1) != -1) 
			&& (setup_signal(SIGUSR1, catch_sigusr1) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR1\n");
	
	if((find_event(sigusr2) != -1) 
		&& (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR2\n");
	
	if(setup_signal(SIGALRM, catch_alrm) == SIG_ERR)
		fprintf(stderr, "dzen: error hooking SIGALARM\n");

	set_alignment();
	
	if(dzen.slave_win.ishmenu &&
			!dzen.slave_win.max_lines)
		dzen.slave_win.max_lines = 1;

	x_create_windows();
	
	if(!dzen.slave_win.ishmenu)
		x_map_window(dzen.title_win.win);
	else {
		XMapRaised(dzen.dpy, dzen.slave_win.win);
		for(i=0; i < dzen.slave_win.max_lines; i++)
			XMapWindow(dzen.dpy, dzen.slave_win.line[i]);
	}

	do_action(onstart);

	/* main loop */
	event_loop();

	do_action(onexit);
	clean_up();

	if(dzen.ret_val)
		return dzen.ret_val;

	return EXIT_SUCCESS;
}
Esempio n. 25
0
bool Traces::parse(const char *filename, int verbose) {
  xmlDocPtr doc = xmlParseFile(filename);
  
  if (doc == NULL) {
    cout << "Error parsing the "<< filename << " !" << endl;
    goto err;
  }
  
  xmlNodePtr node;
  
  node = doc->children; 
  
  XMLASSERT(node->type == XML_ELEMENT_NODE && 
            !strcmp((const char*)node->name, "gltrace"));
  
  { // parse tracelist
    xmlNodePtr xmllist = get_child_element(node, "tracelist"); 
    
    XMLASSERT(xmllist);
    
    for(xmlNodePtr tracenode = xmllist->children; tracenode; tracenode = tracenode->next) {
      if(tracenode->type == XML_TEXT_NODE) continue; 
      XMLASSERT(tracenode->type == XML_ELEMENT_NODE && 
                !strcmp((const char*)tracenode->name, "trace"));
      
      const char *object = get_element_attribute(tracenode, "object"); 
      const char *name = get_element_attribute(tracenode, "name"); 
      XMLASSERT(object && name);
      xmlNodePtr shot = get_child_element(tracenode, "shot"); 
      XMLASSERT(shot);
      const char *id_str = get_element_attribute(shot, "id"); 
      XMLASSERT(id_str); 
      int id; 
      XMLASSERT(sscanf(id_str, "%d", &id) == 1); 
      while((int)tracelist.size() <= id) {
        tracelist.push_back(TracedEvent());           
      }
      tracelist[id].name = name;
      tracelist[id].obj = object;        
    }        
    if(verbose) printf("loaded %ld traces\n", tracelist.size());
  }      
  
  { // load links      
    xmlNodePtr linklist = get_child_element(node, "linklist");
    XMLASSERT(linklist);
    for(xmlNodePtr linknode = linklist->children; linknode; linknode = linknode->next) {
      if(linknode->type == XML_TEXT_NODE) continue; 

      Link link;
      
      XMLASSERT(linknode->type == XML_ELEMENT_NODE && 
                !strcmp((const char*)linknode->name, "link"));
      
      xmlNodePtr source = get_child_element(linknode, "source");
      xmlNodePtr destination = get_child_element(linknode, "destination");
      XMLASSERT(source && destination); 
      
      string sourcecol = get_element_attribute(source, "name"); 
      string destcol = get_element_attribute(destination, "name");       
      XMLASSERT(sourcecol.size() && destcol.size()); 
      

      link.source = sourcecol.substr(0, sourcecol.find(':'));
      link.sourceport = sourcecol.substr(sourcecol.find(':') + 1);
      link.dest = destcol.substr(0, destcol.find(':'));
      link.destport = destcol.substr(destcol.find(':') + 1);

      // printf("size %d %p\n", links.size(), &links[0]);
      links.push_back(link);
      // printf("osize %d %s\n", links.size(), links[0].source.c_str());
    }
    if(verbose)  printf("%ld links\n", links.size());
  }
  
  { // fill in nextEvents
    for(int i = 0; i < tracelist.size(); i++) {
      TracedEvent &ev = tracelist[i];
      Link *waitBeginLink = NULL; 
      bool recorded = false; 
      for(int l = 0; l < links.size(); l++) {
        Link & link = links[l];

        if(link.source == ev.obj && link.sourceport == ev.name) {
          int dest_ev = find_event(link.dest, link.destport); 
          ev.links.push_back(&link);
          if(dest_ev >= 0) {
            ev.nextEvents.push_back(dest_ev); 
            recorded = true;
          }
        }
        if(link.source == ev.obj && link.sourceport == "waitBegin")
          waitBeginLink = &link;

        if(link.dest == ev.obj && link.destport == ev.name &&
           link.destport != "waitEnd") {
          ev.links.push_back(&link);
          recorded = true;
        }
      }
      
      if(!recorded) { //  probably a user event
        if(waitBeginLink) {
          ev.links.push_back(waitBeginLink);
        } else {
          printf("could not find waitBegin/waitEnd where trace %d %s:%s fits\n", 
                 i, ev.obj.c_str(), ev.name.c_str());
        }
      }

      if(verbose) {
        printf("tev %d %s:%s, nextEvents = [", i, ev.obj.c_str(), ev.name.c_str()); 
        for(int j = 0; j < ev.nextEvents.size(); j++) 
          printf("%d ", ev.nextEvents[j]);
        printf("] links = [");
        for(int j = 0; j < ev.links.size(); j++) {
          Link & link = *ev.links[j];
          printf("%s:%s->%s:%s ", 
                 link.source.c_str(), link.sourceport.c_str(), 
                 link.dest.c_str(), link.destport.c_str());
        }
        printf("]\n");
      }
    }
  }
  
  { // load actual trace data
    xmlNodePtr xmlfiles = get_child_element(node, "filelist");
    XMLASSERT(xmlfiles);
    vector<Chunk> chunks;  

    for(xmlNodePtr filenode = xmlfiles->children; filenode; filenode = filenode->next) {
      
      if(filenode->type == XML_TEXT_NODE || 
         (filenode->type == XML_ELEMENT_NODE && 
          !strcmp((const char*)filenode->name, "pingresults"))) continue;
      
      XMLASSERT(filenode->type == XML_ELEMENT_NODE && 
                !strcmp((const char*)filenode->name, "tracefile"));
      
      const char *chunkfilename = get_element_attribute(filenode, "file"); 
      XMLASSERT(chunkfilename);
      
      {
        FILE *chunkfile = fopen(chunkfilename, "r"); 
        XMLASSERT(chunkfile);
        size_t file_size; 
        {
          struct stat sbuf;
          fstat(fileno(chunkfile), &sbuf);
          file_size = sbuf.st_size;
        }
        XMLASSERT(file_size % sizeof(Chunk) == 0);
        size_t nelt = file_size / sizeof(Chunk);
        size_t n0 = chunks.size();
        chunks.resize(n0 + nelt); 
        fread(&chunks[n0], nelt, sizeof(Chunk), chunkfile);
        fclose(chunkfile);
      }

    }
    if(verbose) printf("loaded %ld chunks\n", chunks.size());
    
    chunks_to_evlists(chunks, tracelist, t0, t1);

    {// also record all timestamps
      double t_prev = -10; 
      for(int i = 0; i < chunks.size(); i++) {
        double t = chunks[i].tv_sec + chunks[i].tv_usec * 1e-6;
        if(t > t_prev) 
          timestamps.push_back(t); 
        t_prev = t;        
      }
    }


  }
  xmlFreeDoc(doc);  

  return true;
 err:
  xmlFreeDoc(doc);
  return false; 
}
Esempio n. 26
0
void edit_event(icalcomponent* calendar)
{
  icalcomponent* event = find_event(calendar);
  
  if (event == NULL)
  {
    append_action_to_closed_log("Edit event", false);
  }
  
  //Once event found by property, display all fields and prompt for which to edit
  cout << "Which fields would you like to edit?" << endl;
  
  string properties;
  cin >>properties;
  
  char* c_properties = new char[properties.size()+1];
  strcpy(c_properties, properties.c_str());
  
  char * sel_props_c = strtok(c_properties, ";");
  vector<string> sel_props;
  vector<int> sel_props_pos;
  while (sel_props_c != NULL)
  {
    sel_props.push_back(sel_props_c);
    sel_props_pos.push_back(0);
    sel_props_c = strtok(c_properties, ";");
  }
  
  string all_props[] = {"ATTACH", "ATTENDEE", "CATEGORIES", "CLASS", "COMMENT", "CONTACT", "CREATED", "DESCRIPTION", "DTEND", "DTSTAMP", "DTSTART", "DURATION", "EXDATE", "EXRULE", "GEO", "LAST-MOD", "LOCATION", "ORGANIZER", "PRIORITY", "RDATE", "RECURID", "RELATED", "RESOURCES", "RRULE", "RSTATUS", "SEQ", "STATUS", "SUMMARY", "TRANSP", "UID", "URL"};
  
  for (int i = 0; i < sel_props.size(); i++)
  {
    for (int j = 0; j < 31; j++)
    {
      if (sel_props[i] == all_props[j])
      {
        sel_props_pos[i] = j;
        break;
      }
    }
    
    if (sel_props[i] == "X-CLASS")
    {
      sel_props_pos[i] = 32; //beyond the end of all_props
    }
  }
  
  //Update fields
  vector<string> values;
  cout << "Enter values for: " << endl;
  for (int i = 0; i < sel_props.size(); i++)
  {
    cout << sel_props[i] << ": ";
    flush(cout);
    string value;
    cin >> value; //FIXME error check for type
    values.push_back(value);
  }
  
  //Check that we are in the right property
  icalcomponent *c;
  
  for (c = icalcomponent_get_first_component(event,ICAL_VEVENT_COMPONENT); c != 0; 	c = icalcomponent_get_next_component(event,ICAL_VEVENT_COMPONENT))
  {
    bool is_match = true;
    //Check each of the properties
    for (int i = 0; i < sel_props.size(); i++)
    {
      if (sel_props_pos[i] == 32)
      {
        icalproperty* p = icalcomponent_get_first_property(event, ICAL_X_PROPERTY);
        icalproperty_set_x(ical_x_class_prop, values[i].c_str());
      }else
      {
        icalproperty* p;
        
        for( 	p = icalcomponent_get_first_property(event,ICAL_ANY_PROPERTY); 	p != 0; 	p = icalcomponent_get_next_property(event,ICAL_ANY_PROPERTY))
        {
          //FIXME no support for multi-parameter properties yet
          //FIXME also no value checking, which matters
          //FIXME use void icalproperty_set_value(icalproperty* prop, icalvalue* value);
        }
      }
    }
  }
  
  append_action_to_closed_log("Edit event", true);
}