/[pengfork]/pengfork/src/modem/script.c
ViewVC logotype

Diff of /pengfork/src/modem/script.c

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

revision 1.3 by chupa, Sat Nov 30 10:28:52 2002 UTC revision 1.4 by chupa, Sun Dec 1 01:19:07 2002 UTC
# Line 20  Line 20 
20   *                   *                
21   */   */
22    
23    #include "config.h"
24    
25    #include <stdlib.h>
26  #include <guile/gh.h>  #include <guile/gh.h>
27  #include <string.h>  #include <string.h>
28    
29    #include "gettext.h"
30  #include "options.h"  #include "options.h"
31  #include "log.h"  #include "log.h"
32  #include "utils.h"  #include "utils.h"
# Line 33  Line 37 
37  SCM  SCM
38  chat_success (void)  chat_success (void)
39  {  {
40    log(LOG_NOTICE, "Script: Chat success\n");    log (LOG_NOTICE, gettext ("Script: Chat success\n"));
41    return SCM_BOOL_T;    return SCM_BOOL_T;
42  }  }
43    
44  SCM  SCM
45  chat_failure (void)  chat_failure (void)
46  {  {
47    log(LOG_NOTICE, "Script: Chat failure\n");    log (LOG_NOTICE, gettext ("Script: Chat failure\n"));
48    return SCM_BOOL_F;    return SCM_BOOL_F;
49  }  }
50    
# Line 48  SCM Line 52  SCM
52  chat_send (string)  chat_send (string)
53       SCM string;       SCM string;
54  {  {
55    char *text;    char *text, *print, *p;
56    int len;    int len;
57    
58    text = gh_scm2newstr (string, &len);    text = gh_scm2newstr (string, &len);
59    log(LOG_NOTICE, "Script: Send %s\n", text);    print = strdup(text);
60      p=print;
61      while(*p != '\0')
62        {
63          if(*p < 32 || *p > 127)
64            *p=' ';
65          p++;
66        }
67      log (LOG_NOTICE, gettext ("Script: Send '%s'\n"), print);
68      free(print);
69    modem_sync_write (text, len);    modem_sync_write (text, len);
70    return SCM_UNDEFINED;    return SCM_UNDEFINED;
71  }  }
# Line 76  compare_elem (buffer, elem, result) Line 89  compare_elem (buffer, elem, result)
89    eval = gh_lookup ("eval");    eval = gh_lookup ("eval");
90    
91    text = gh_scm2newstr (gh_car (elem), &len);    text = gh_scm2newstr (gh_car (elem), &len);
92    /* duplicate and lowerize all strings to become case insensitive*/    /* duplicate and lowerize all strings to become case insensitive */
93    bufmin = strdup (buffer);    bufmin = strdup (buffer);
94    textmin = strdup (text);    textmin = strdup (text);
95    lowerize (bufmin);    lowerize (bufmin);
# Line 84  compare_elem (buffer, elem, result) Line 97  compare_elem (buffer, elem, result)
97    
98    if (strstr (bufmin, textmin))    if (strstr (bufmin, textmin))
99      {      {
100        log(LOG_NOTICE, "Script: String '%s' matched\n", text);        log (LOG_NOTICE, gettext ("Script: String '%s' matched\n"), text);
101        /* evaluate next elem */        /* evaluate next elem */
102        *result = gh_call1 (eval, gh_car (gh_cdr (elem)));        *result = gh_call1 (eval, gh_car (gh_cdr (elem)));
103        match = 1;        match = 1;
# Line 113  compare_buf (buffer, first, others, resu Line 126  compare_buf (buffer, first, others, resu
126    remainder = others;    remainder = others;
127    do    do
128      {      {
129        found = compare_elem(buffer,elem, result);        found = compare_elem (buffer, elem, result);
130        elem = gh_car (remainder);        elem = gh_car (remainder);
131        remainder = gh_cdr (remainder);        remainder = gh_cdr (remainder);
132      }      }
133    while (gh_length (remainder) > 0 && !found);    while (gh_length (remainder) > 0 && !found);
134      
135    /* treat the last element only if it isn't an else */    /* treat the last element only if it isn't an else */
136    if (!found && gh_string_p (elem))    if (!found && gh_string_p (elem))
137      {      {
138        found = compare_elem(buffer,elem, result);        found = compare_elem (buffer, elem, result);
139      }      }
140    
141    return found;    return found;
# Line 133  do_else (others, result) Line 146  do_else (others, result)
146       SCM others;       SCM others;
147       SCM *result;       SCM *result;
148  {  {
149    SCM  elem;    SCM elem;
150    log(LOG_NOTICE, "Script: No string matched\n");    log (LOG_NOTICE, gettext ("Script: No string matched\n"));
151    if (gh_length(others) > 0)    if (gh_length (others) > 0)
152      {      {
153        elem = gh_car(gh_reverse(others));          elem = gh_car (gh_reverse (others));
154      }      }
155    return 0;    return 0;
156  }  }
157    
158  /*  /*
159    Scheme function (chat-try)    Scheme function (chat-try)
# Line 173  chat_try (timeout, first, others) Line 186  chat_try (timeout, first, others)
186            nread++;            nread++;
187            p++;            p++;
188            *p = '\0';            *p = '\0';
189            
190          end = compare_buf (buffer, first, others, &result);            end = compare_buf (buffer, first, others, &result);
191          }          }
192        else        else
193          {          {
194          /* treat the else case */            /* treat the else case */
195          do_else(others, result);            do_else (others, result);
196            end = 1;            end = 1;
197          }          }
198      }      }
# Line 205  chat_connect () Line 218  chat_connect ()
218    gh_new_procedure ("chat-try", chat_try, 2, 0, 1);    gh_new_procedure ("chat-try", chat_try, 2, 0, 1);
219    
220    gh_eval_file (PARAM_MODEM_CHAT_SCRIPT);    gh_eval_file (PARAM_MODEM_CHAT_SCRIPT);
221    connect = gh_lookup("chat-connect");    connect = gh_lookup ("chat-connect");
222    result = gh_call0(connect);    result = gh_call0 (connect);
223    
224    if (!gh_boolean_p(result))    if (!gh_boolean_p (result))
225      {      {
226        log (LOG_ERR, "%s: returned value isn't a boolean.\n",        log (LOG_ERR, gettext ("%s: returned value isn't a boolean.\n"),
227             PARAM_MODEM_CHAT_SCRIPT);             PARAM_MODEM_CHAT_SCRIPT);
228        log (LOG_ERR, "Couldn't continue, exiting.\n");        log (LOG_ERR, gettext ("Couldn't continue, exiting.\n"));
229        exit (1);        exit (1);
230      }      }
231    
232    if(result == SCM_BOOL_T) return 1;    if (result == SCM_BOOL_T)
233    else if(result == SCM_BOOL_F) return 0;      return 1;
234    else return -1;    else if (result == SCM_BOOL_F)
235        return 0;
236      else
237        return -1;
238  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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