/[anubis]/anubis/src/guile.c
ViewVC logotype

Diff of /anubis/src/guile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by gray, Wed Feb 26 16:53:08 2003 UTC revision 1.8 by gray, Thu Mar 6 18:36:16 2003 UTC
# Line 192  anubis_to_guile(struct list *list) Line 192  anubis_to_guile(struct list *list)
192          return head;          return head;
193  }  }
194    
195    static SCM
196    list_to_args(struct list *arglist)
197    {
198            char *p;
199            SCM head = SCM_EOL,
200                    tail; /* Don't let gcc fool you: tail cannot be used
201                             uninitialized */
202            SCM val;
203                    
204            list_first(arglist);
205            while (p = list_next(arglist)) {
206                    SCM cell;
207                    SCM_NEWCELL(cell);
208    
209                    if (p[0] == '#') {
210                            switch (p[1]) {
211                            case ':':
212                                    val = scm_c_make_keyword(p + 2);
213                                    break;
214    
215                            case 'f':
216                                    val = SCM_BOOL_F;
217                                    break;
218                                    
219                            case 't':
220                                    val = SCM_BOOL_T;
221                            }
222                    } else
223                            val = scm_makfrom0str(p);
224    
225                    SCM_SETCAR(cell, scm_list_2(scm_copy_tree(SCM_IM_QUOTE), val));
226                            
227                    if (head == SCM_EOL)
228                            head = cell;
229                    else
230                            SCM_SETCDR(tail, cell);
231                    tail = cell;
232            }
233            if (head != SCM_EOL)
234                    SCM_SETCDR(tail, SCM_EOL);
235            return head;
236    }
237    
238  /* (define (postproc header-list body)*/  /* (define (postproc header-list body)*/
239  void  void
240  guile_process_proc(char *procname, MESSAGE *msg)  guile_process_proc(struct list *arglist, MESSAGE *msg)
241  {  {
242            char *procname;
243          SCM arg_hdr, arg_body;          SCM arg_hdr, arg_body;
244            SCM invlist, rest_arg;
245          SCM procsym;          SCM procsym;
246          jmp_buf jmp_env;          jmp_buf jmp_env;
247          SCM res;          SCM res;
248    
249          /* Prepare the arguments */          procname = list_first(arglist);
250            if (!procname) {
251                    anubis_error(SOFT, _("missing procedure name"));
252                    return;
253            }
254            
255            /* Prepare the required arguments */
256          arg_hdr = anubis_to_guile(msg->header);          arg_hdr = anubis_to_guile(msg->header);
257          arg_body = scm_makfrom0str(msg->body);          arg_body = scm_makfrom0str(msg->body);
258    
259            /* Prepare the optional arguments */
260            rest_arg = list_to_args(arglist);
261            
262          /* Evaluate the procedure */          /* Evaluate the procedure */
263          procsym = SCM_VARIABLE_REF(scm_c_lookup(procname));          procsym = SCM_VARIABLE_REF(scm_c_lookup(procname));
264          if (scm_procedure_p(procsym) != SCM_BOOL_T) {          if (scm_procedure_p(procsym) != SCM_BOOL_T) {
# Line 219  guile_process_proc(char *procname, MESSA Line 273  guile_process_proc(char *procname, MESSA
273                  return;                  return;
274          }          }
275    
276          res = scm_internal_lazy_catch(          invlist = scm_append(
277                  SCM_BOOL_T,                       SCM_LIST2(SCM_LIST3(procsym,
278                  eval_catch_body,                                           SCM_LIST2(scm_copy_tree(SCM_IM_QUOTE),
279                  (void*) SCM_LIST3(procsym,                                                     arg_hdr),
280                                    scm_listify(scm_copy_tree(SCM_IM_QUOTE),                                           SCM_LIST2(scm_copy_tree(SCM_IM_QUOTE),
281                                                arg_hdr,                                                     arg_body)),
282                                                SCM_UNDEFINED),                                 rest_arg));
283                                    scm_listify(scm_copy_tree(SCM_IM_QUOTE),          res = scm_internal_lazy_catch(SCM_BOOL_T,
284                                                arg_body,                                        eval_catch_body,
285                                                SCM_UNDEFINED)),                                        (void*) invlist,
286                  eval_catch_handler, &jmp_env);                                        eval_catch_handler, &jmp_env);
287                    
288          if (SCM_IMP(res) && SCM_BOOLP(res)) {          if (SCM_IMP(res) && SCM_BOOLP(res)) {
289                  /* FIXME 1*/;                  /* FIXME 1*/;
# Line 241  guile_process_proc(char *procname, MESSA Line 295  guile_process_proc(char *procname, MESSA
295                          /* Preserve the headers */;                          /* Preserve the headers */;
296                  } else if (SCM_NIMP(ret_hdr) && SCM_CONSP(ret_hdr)) {                  } else if (SCM_NIMP(ret_hdr) && SCM_CONSP(ret_hdr)) {
297                          /* Replace them */                          /* Replace them */
298                          destroy_assoc_list(msg->header);                          destroy_assoc_list(&msg->header);
299                          msg->header = guile_to_anubis(ret_hdr);                          msg->header = guile_to_anubis(ret_hdr);
300                  } else                  } else
301                          anubis_error(SOFT,                          anubis_error(SOFT,
# Line 298  static struct rc_kwdef guile_rule_kw[] = Line 352  static struct rc_kwdef guile_rule_kw[] =
352  };  };
353    
354  int  int
355  guile_parser(int method, int key, char *arg, void *inv_data, void *func_data,  guile_parser(int method, int key, struct list *arglist,
356               MESSAGE *msg)               void *inv_data, void *func_data, MESSAGE *msg)
357  {  {
358            char *arg = list_item(arglist, 0);
359          switch (key) {          switch (key) {
360          case KW_GUILE_OUTPUT:          case KW_GUILE_OUTPUT:
361                  xfree(options.guile_logfile);                  xfree(options.guile_logfile);
# Line 320  guile_parser(int method, int key, char * Line 375  guile_parser(int method, int key, char *
375                  break;                  break;
376    
377          case KW_GUILE_PROCESS:          case KW_GUILE_PROCESS:
378                  guile_process_proc(arg, msg);                  guile_process_proc(arglist, msg);
379                  break;                  break;
380    
381          case KW_GUILE_REWRITE_LINE:          case KW_GUILE_REWRITE_LINE:

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26