示例#1
0
文件: monitor.c 项目: kyuba/core
sexpr on_event (sexpr arguments, struct machine_state *state)
{
    if (eolp (state->stack))
    {
        sexpr tstate = car (arguments);

        if (truep(equalp(tstate, sym_always)) ||
                ((init_state == gs_power_on) &&
                 truep(equalp(tstate, sym_power_on))) ||
                ((init_state == gs_power_down) &&
                 truep(equalp(tstate, sym_power_down))) ||
                ((init_state == gs_power_reset) &&
                 truep(equalp(tstate, sym_power_reset))) ||
                ((init_state == gs_ctrl_alt_del) &&
                 truep(equalp(tstate, sym_ctrl_alt_del))))
        {
            state->code = cdr (state->code);
            return sx_nonexistent;
            /* makes the seteh code execute the remainder of the script */
        }
        else
        {
            return sx_false;
            // wrong state
        }
    }
    else
    {
        return sx_true;
    }
}
示例#2
0
文件: text.c 项目: hankem/jed
static int is_paragraph_sep(void) /*{{{*/
{
   int ret;
   Jed_Buffer_Hook_Type *h = CBuf->buffer_hooks;

   if ((h != NULL)
       && (h->par_sep != NULL))
     {
	if ((-1 == SLexecute_function(h->par_sep))
	    || (-1 == SLang_pop_integer(&ret)))
	  ret = -1;

	return ret;
     }

   push_spot ();
   (void) bol ();
   jed_skip_whitespace ();
   if (eolp ())
     {
	pop_spot ();
	return 1;
     }
   pop_spot ();
   return 0;
}
示例#3
0
文件: cmds.c 项目: hankem/jed
int newline_cmd (void)
{
#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine)
       || ((CLine->next != NULL)
	   && eolp () && check_line_attr_no_modify (CLine->next)))
     return 0;
#endif
   return newline ();
}
示例#4
0
文件: server-seteh.c 项目: kyuba/core
static void handle_external_mod_update
    (struct kyu_module *newdef, struct kyu_module *mydef)
{
    sexpr c, a, module, rv = sx_nil, flags = newdef->schedulerflags;

    c = sx_set_difference (mydef->schedulerflags, newdef->schedulerflags);

    if (eolp (c))
    {
        return;
    }

    while (consp (c) && nilp (rv))
    {
        a = car (c);

        if (truep (equalp (a, sym_enabling)))
        {
            if (falsep (sx_set_memberp (mydef->schedulerflags, sym_enabling)))
            {
                rv = handle_enable_request (mydef);

                if (falsep (rv))
                {
                    flags = sx_set_add (mydef->schedulerflags, sym_blocked);
                }
            }
        }
        else if (truep (equalp (a, sym_disabling)))
        {
            if (falsep (sx_set_memberp (mydef->schedulerflags, sym_disabling)))
            {
                rv = handle_disable_request (mydef);
            }
        }
        else if (consp (a) &&
                 falsep (sx_set_memberp (mydef->schedulerflags, a)))
        {
            rv = handle_action (mydef, cdr (a));
        }

        c = cdr (c);
    }

    module = kyu_make_module
            (mydef->name, mydef->description, mydef->provides,
             mydef->requires, mydef->before, mydef->after, mydef->conflicts,
             flags, mydef->functions);

    my_modules = lx_environment_unbind (my_modules, mydef->name);
    my_modules = lx_environment_bind   (my_modules, mydef->name, module);

    kyu_command (cons (sym_update, cons (native_system,
                 cons (module, sx_end_of_list))));
}
示例#5
0
文件: text.c 项目: hankem/jed
/* returns 0 if to wrapped, 1 if wrapped, -1 if error */
static int wrap_line1(int format, int trim) /*{{{*/
{
   unsigned char *p, *pmin;
   int col;

   if (format)
     pmin = text_format_line();
   else
     {
	bol ();
	/* Ignore leading whitespace */
	pmin = jed_skip_whitespace ();
	/* pmin = CLine->data; */
     }
   if (pmin == NULL)
     return -1;

   point_column(Buffer_Local.wrap_column - 1);
   col = calculate_column();
   if ((col < Buffer_Local.wrap_column) && eolp ())
     return 0;

   p = CLine->data + Point;

   while(p > pmin)
     {
	if ((*p == ' ') || (*p == '\t')) break;
	p--;
     }

   if (p == pmin)
     {
	/* that failed, so go the other way */
	p = CLine->data + CLine->len;
	while(pmin < p)
	  {
	     if ((*pmin == ' ') || (*pmin == '\t')) break;
	     pmin++;
	  }
	if (p == pmin) return 0;
	p = pmin;
     }

   jed_position_point (p);

   if (trim && (-1 == jed_trim_whitespace()))
     return -1;

   if (-1 == jed_insert_newline())
     return -1;

   jed_up(1);
   return 1;
}
示例#6
0
文件: timer.c 项目: fywtat/curie
static void event_dispatch
    (struct event *e, struct event **p, unsigned long long ts)
{
    sexpr t = e->then;
    e->queue_time = dt_from_unix (ts);
    output (e->output);
    event_repeat (e, p);

    if (!eolp (t))
    {
        event_add (t);
    }

    event_queue ();
}
示例#7
0
static int kill_line(int literally)
{
  if (!eolp()) {
    if (warn_if_readonly_buffer())
      return FALSE;

    undo_save(UNDO_INSERT_BLOCK, cur_bp->pt,
              astr_len(cur_bp->pt.p->item) - cur_bp->pt.o, 0);
    undo_nosave = TRUE;
    while (!eolp()) {
      kill_ring_push(following_char());
      FUNCALL(delete_char);
    }
    undo_nosave = FALSE;

    thisflag |= FLAG_DONE_KILL;

    if (!literally)
      return TRUE;
  }

  if (list_next(cur_bp->pt.p) != cur_bp->lines) {
    if (!FUNCALL(delete_char))
      return FALSE;

    kill_ring_push('\n');

    thisflag |= FLAG_DONE_KILL;

    return TRUE;
  }

  minibuf_error("End of buffer");

  return FALSE;
}
示例#8
0
文件: cmds.c 项目: hankem/jed
int jed_trim_whitespace ()
{
   int n;
   unsigned char *p;

   /* CHECK_READ_ONLY */

   p = CLine->data + Point;
   if ((0 == eolp ()) && (0 == IS_WHITESPACE(p)))
     return 0;

   (void) jed_skip_whitespace ();
   n = Point;

   (void) jed_bskip_whitespace ();
   if (-1 == jed_del_nbytes (n - Point))
     return -1;

   return 1;
}
示例#9
0
文件: cmds.c 项目: hankem/jed
/*{{{ newline_and_indent */
int newline_and_indent ()
{
   static int in_function;
   if (in_function) return -1;

#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine)
       || ((CLine->next != NULL)
	   && eolp () && check_line_attr_no_modify (CLine->next)))
     return 0;
#endif

   if ((CBuf->buffer_hooks != NULL)
       && (CBuf->buffer_hooks->newline_indent_hook != NULL))
     {
	in_function = 1;
	SLexecute_function(CBuf->buffer_hooks->newline_indent_hook);
	in_function = 0;
	return 1;
     }
   if (0 == jed_insert_newline ())
     indent_line();
   return(1);
}
示例#10
0
文件: server-seteh.c 项目: kyuba/core
static sexpr action_dispatch
    (sexpr arguments, struct machine_state *state)
{
    if (eolp (state->stack))
    {
        state->stack = cons(lx_foreign_mu (sym_action_dispatch,
                                           action_dispatch),
                            state->stack);

        state->stack = cons (car (state->code), state->stack);
        state->code  = cdr (state->code);
        state->stack = cons (car (state->code), state->stack);
        state->code  = cdr (state->code);

        return sx_nonexistent;
    }
    else
    {
        sexpr meta = car (arguments), code, env;

        arguments = cdr (arguments);
        code = car (arguments);
        env = car (cdr (arguments));

        state->stack = sx_end_of_list;
        state->code  = cons (cons (sym_action_wrap, cons (meta, code)),
                             sx_end_of_list);

        if (environmentp (env))
        {
            state->environment = lx_environment_join (state->environment, env);
        }

        return sx_unquote;
    }
}
示例#11
0
文件: cmds.c 项目: hankem/jed
/*{{{ ins_char_cmd */
int ins_char_cmd (void)
{
   unsigned char ch;
   int wrap = Buffer_Local.wrap_column;
   int do_blink;
   int did_abbrev = 0;
   SLang_Name_Type *wrapok_hook;

   CHECK_READ_ONLY
#if 0
     ;
#endif
#if JED_HAS_LINE_ATTRIBUTES
   if (check_line_attr_no_modify (CLine))
     return 0;
#endif

   ch = SLang_Last_Key_Char;

   if (ch == '\n')
     {
	newline();
	return(1);
     }

#if JED_HAS_ABBREVS
   if (CBuf->flags & ABBREV_MODE)
     {
	if (-1 == (did_abbrev = jed_expand_abbrev (ch)))
	  return -1;
     }
#endif

   if ((CBuf->flags & OVERWRITE_MODE) && !eolp())
     {
	/* FIXME: jed_del_wchar should be called for the last byte of a
	 * UTF-8 sequence
	 */
	if ((did_abbrev == 0)
	    && (-1 == jed_del_wchar ()))
	  return -1;
     }

   /* It is ok to use Point as an estimator of the current column.  This
    * avoids the more expensive call to calculate_column.
    */
   if (CBuf->buffer_hooks != NULL)
     wrapok_hook = CBuf->buffer_hooks->wrapok_hook;
   else
     wrapok_hook = NULL;

   if (((ch == ' ') || (Point >= wrap))
       && ((CBuf->modes & WRAP_MODE) || (wrapok_hook != NULL))
       && (calculate_column() > wrap)
       && ((wrapok_hook == NULL)
	   || (1 == execute_is_ok_hook (wrapok_hook))))
     {
	unsigned int this_line_num = LineNum;

	if ((did_abbrev == 0)
	    && (-1 == jed_insert_byte (ch)))
	  return -1;

	if (1 != wrap_line(0))	       /* do not format--- just wrap */
	  return -1;		       /* line isn't wrapable */

	/* There is a bug involving wrapping a very long line containing
	 * no whitespace and then we try to insert a character.  This work
	 * arounds the bug.
	 */
	if ((this_line_num == LineNum)
	    && (ch == ' '))
	    /* && (calculate_column () > wrap)) */
	  {
	     if (0 == jed_right (1))
	       newline ();
	  }

	if ((CBuf->buffer_hooks != NULL)
	    && (CBuf->buffer_hooks->wrap_hook != NULL))
	  SLexecute_function(CBuf->buffer_hooks->wrap_hook);
	else if (Indented_Text_Mode) indent_line ();

	return(1);
     }

   do_blink = ((((CBuf->syntax_table != NULL)
		 && ((CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX)))
		|| ((ch == ')') || (ch == '}') || (ch == ']')))
	       && !input_pending(&Number_Zero));
   if (did_abbrev == 0)
     (void) jed_insert_byte (ch);
   if (do_blink) blink_match ();
   return 1;
}
示例#12
0
文件: server-seteh.c 项目: kyuba/core
static void on_script_file_read (sexpr sx, struct sexpr_io *io, void *p)
{
    if (consp (sx))
    {
        sexpr a = car (sx), mt, b, c;
        struct kyu_module *mo;
        char daemon = 0;

        if (truep (equalp (sym_init_script, a)) ||
            (daemon = truep (equalp (sym_daemon, a))))
        {
            sexpr name           = sx_nonexistent,
                  description    = sx_nonexistent,
                  provides       = sx_end_of_list,
                  requires       = sx_end_of_list,
                  before         = sx_end_of_list,
                  after          = sx_end_of_list,
                  conflicts      = sx_end_of_list,
                  schedulerflags = sx_end_of_list,
                  functions      = sx_end_of_list,
                  functiondata   = sx_end_of_list,
                  binary         = sx_end_of_list,
                  pidfile        = sx_end_of_list,
                  startcommand   = sx_end_of_list,
                  stopcommand    = sx_true,
                  parameters     = sx_end_of_list,
                  module;

            if (daemon)
            {
                functions = cons (sym_stop, cons (sym_start, functions));
            }

            a = cdr (sx);
            name        = car (a); a = cdr (a);
            description = car (a); a = cdr (a);

            while (consp (a))
            {
                sexpr v  = car (a);
                sexpr va = car (v);

                if (truep (equalp (sym_provides, va)))
                {
                    provides = sx_set_merge (provides, cdr (v));
                }
                else if (truep (equalp (sym_requires, va)))
                {
                    requires = sx_set_merge (requires, cdr (v));
                }
                else if (truep (equalp (sym_conflicts_with, va)))
                {
                    conflicts = sx_set_merge (conflicts, cdr (v));
                }
                else if (truep (equalp (sym_before, va)))
                {
                    before = sx_set_merge (before, cdr (v));
                }
                else if (truep (equalp (sym_after, va)))
                {
                    after = sx_set_merge (after, cdr (v));
                }
                else if (truep (equalp (sym_schedule_limitations, va)))
                {
                    schedulerflags = sx_set_merge (schedulerflags, cdr (v));
                }
                else if (truep (equalp (sym_functions, va)))
                {
                    functiondata = sx_set_merge (functiondata, cdr (v));
                }
                else if (truep (equalp (sym_pid_file, va)))
                {
                    pidfile = sx_set_merge (pidfile, cdr (v));
                }
                else if (truep (equalp (sym_binary, va)))
                {
                    binary = sx_set_merge (binary, cdr (v));
                }
                else if (truep (equalp (sym_parameters, va)))
                {
                    parameters = sx_set_merge (parameters, cdr (c));
                }

                a = cdr (a);
            }

            if (!eolp (binary))
            {
                for (a = binary; consp (a); a = cdr (a))
                {
                    b = car (a);

                    if (falsep ((c = which (b))))
                    {
                        kyu_command (cons (sym_warning,
                                       cons (sym_binary_not_found,
                                         cons (native_system,
                                           cons (name,
                                             cons (b,
                                                   sx_end_of_list))))));

                        return;
                    }

                    if (daemon)
                    {
                        startcommand =
                            cons (cons (sym_run, cons (c, parameters)),
                                  startcommand);

                        if (!eolp(pidfile) && truep(stopcommand))
                        {
                            stopcommand = sx_list1
                                (sx_list2(sym_kill_via_pid_file, pidfile));
                        }
                    }
                }
            }

            if (daemon)
            {
                functiondata = cons (cons (sym_start, startcommand),
                                     cons (cons (sym_stop, stopcommand),
                                           functiondata));
            }

            mt = lx_environment_lookup (my_modules, name);
            if (!nexp (mt))
            {
                mo = (struct kyu_module *)mt;

                schedulerflags =
                    sx_set_merge (schedulerflags, mo->schedulerflags);
            }

            module = kyu_make_module
                    (name, description, provides, requires, before, after,
                     conflicts, schedulerflags, functions);

            my_modules = lx_environment_unbind (my_modules, name);
            my_modules = lx_environment_bind   (my_modules, name, module);

            mod_functions =
                lx_environment_unbind (mod_functions, name);
            mod_functions =
                lx_environment_bind   (mod_functions, name, functiondata);

            mod_metadata =
                lx_environment_unbind (mod_metadata,  name);
            mod_metadata =
                lx_environment_bind   (mod_metadata,  name, cons (binary,
                                                                  pidfile));

            kyu_command (cons (sym_update, cons (native_system,
                         cons (module, sx_end_of_list))));
        }
    }
    else if (eofp (sx))
    {
        open_config_files--;
        if (open_config_files == 0)
        {
            update_status_from_pid_files ();

            kyu_command (cons (sym_initialised,
                         cons (sym_server_seteh, sx_end_of_list)));
        }
    }
}
示例#13
0
文件: server-seteh.c 项目: kyuba/core
static sexpr action_wrap
    (sexpr arguments, struct machine_state *state)
{
    if (eolp (state->stack))
    {
        state->stack = cons(lx_foreign_mu (sym_action_wrap, action_wrap),
                            state->stack);
 
        state->stack = cons (car (state->code), state->stack);
        state->code  = cdr (state->code);

        return sx_nonexistent;
    }
    else
    {
        sexpr meta = car (arguments), v = sx_true, name = car (meta),
              act = cdr (meta), t, module;
        struct kyu_module *mod;

        t = lx_environment_lookup (my_modules, name);

        if (!kmodulep (t))
        {
            return sx_false;
        }

        mod = (struct kyu_module *)t;
        t = mod->schedulerflags;

        arguments = cdr (arguments);

        while (consp (arguments))
        {
            v = car (arguments);
            arguments = cdr (arguments);
        }

        if (truep (equalp (act, sym_start)))
        {
            t = sx_set_remove (t, sym_enabling); 

            if (truep (v))
            {
                t = sx_set_add (t, sym_enabled);
            }
            else
            {
                t = sx_set_add (t, sym_blocked);
            }
        }
        else if (truep (equalp (act, sym_stop)))
        {
            t = sx_set_remove (t, sym_enabled); 
            t = sx_set_remove (t, sym_disabling); 
        }
        else
        {
            t = sx_set_remove (t, cons (sym_action, act)); 
        }

        module = kyu_make_module
                (mod->name, mod->description, mod->provides, mod->requires,
                 mod->before, mod->after, mod->conflicts, t, mod->functions);

        my_modules = lx_environment_unbind (my_modules, name);
        my_modules = lx_environment_bind   (my_modules, name, module);

        kyu_command (cons (sym_update, cons (native_system,
                     cons (module, sx_end_of_list))));

        return sx_true;
    }
}