File: command.c

package info (click to toggle)
mgetty 1.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,880 kB
  • sloc: ansic: 42,728; sh: 6,487; perl: 6,262; makefile: 1,457; tcl: 756; lisp: 283
file content (103 lines) | stat: -rw-r--r-- 2,648 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * command.c
 *
 * Execute the given command and wait for an answer.
 *
 * $Id: command.c,v 1.4 1998/09/09 21:07:27 gert Exp $
 *
 */

#include "../include/voice.h"

int voice_command(char *command, char *expected_answer)
     {
     char buffer[VOICE_BUF_LEN];
     int result = VMA_FAIL;

     lprintf(L_NOISE, "voice command: '%s' -> '%s'", command,
      expected_answer);

     if (cvd.command_delay.d.i != 0)
          delay(cvd.command_delay.d.i);

     if (strlen(command) != 0)
          {

          if (voice_write("%s", command) != OK)
               {
               voice_flush(1);
               return(VMA_FAIL);
               };

          if (cvd.enable_command_echo.d.i)

               do
                    {

                    if (voice_read(buffer) != OK)
                         {
                         voice_flush(1);
                         return(VMA_FAIL);
                         };

                    result = voice_analyze(buffer, command, TRUE);

                    if (result == VMA_FAIL)
                         {
                         lprintf(L_WARN,
                          "%s: Modem did not echo the command", program_name);
                         voice_flush(1);
                         return(VMA_FAIL);
                         };

                    if (result == VMA_ERROR)
                         {
                         lprintf(L_WARN, "%s: Modem returned ERROR",
                          program_name);
                         voice_flush(1);
                         return(VMA_FAIL);
                         };

                    }
               while (result != VMA_USER_1);

          result = OK;
          };

     if (strlen(expected_answer) != 0)
          {

          do
               {

               if (voice_read(buffer) != OK)
                    {
                    voice_flush(1);
                    return(VMA_FAIL);
                    };

               result = voice_analyze(buffer, expected_answer, FALSE);

               if (result == VMA_FAIL)
                    {
                    lprintf(L_WARN, "%s: Invalid modem answer",
                     program_name);
                    voice_flush(1);
                    return(VMA_FAIL);
                    };

               if (result == VMA_ERROR)
                    {
                    lprintf(L_WARN, "%s: Modem returned ERROR",
                     program_name);
                    voice_flush(1);
                    return(VMA_FAIL);
                    };

               }
          while ((result & VMA_USER) != VMA_USER);

          };

     return(result);
     }