Annotation of coherent/g/usr/lib/uucp/tay104/uuconf/chatc.c, revision 1.1.1.1

1.1       root        1: /* chatc.c
                      2:    Subroutines to handle chat script commands.
                      3: 
                      4:    Copyright (C) 1992 Ian Lance Taylor
                      5: 
                      6:    This file is part of the Taylor UUCP uuconf library.
                      7: 
                      8:    This library is free software; you can redistribute it and/or
                      9:    modify it under the terms of the GNU Library General Public License
                     10:    as published by the Free Software Foundation; either version 2 of
                     11:    the License, or (at your option) any later version.
                     12: 
                     13:    This library is distributed in the hope that it will be useful, but
                     14:    WITHOUT ANY WARRANTY; without even the implied warranty of
                     15:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     16:    Library General Public License for more details.
                     17: 
                     18:    You should have received a copy of the GNU Library General Public
                     19:    License along with this library; if not, write to the Free Software
                     20:    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     21: 
                     22:    The author of the program may be contacted at [email protected] or
                     23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
                     24:    */
                     25: 
                     26: #include "uucnfi.h"
                     27: 
                     28: #if USE_RCS_ID
                     29: const char _uuconf_chatc_rcsid[] = "$Id: chatc.c,v 1.1 93/07/30 08:07:03 bin Exp Locker: bin $";
                     30: #endif
                     31: 
                     32: #include <ctype.h>
                     33: #include <errno.h>
                     34: 
                     35: static int icchat P((pointer pglobal, int argc, char **argv,
                     36:                     pointer pvar, pointer pinfo));
                     37: static int icchat_fail P((pointer pglobal, int argc, char **argv,
                     38:                          pointer pvar, pointer pinfo));
                     39: static int icunknown P((pointer pglobal, int argc, char **argv,
                     40:                        pointer pvar, pointer pinfo));
                     41: 
                     42: /* The chat script commands.  */
                     43: 
                     44: static const struct cmdtab_offset asChat_cmds[] =
                     45: {
                     46:   { "chat", UUCONF_CMDTABTYPE_FN,
                     47:       offsetof (struct uuconf_chat, uuconf_pzchat), icchat },
                     48:   { "chat-program", UUCONF_CMDTABTYPE_FULLSTRING,
                     49:       offsetof (struct uuconf_chat, uuconf_pzprogram), NULL },
                     50:   { "chat-timeout", UUCONF_CMDTABTYPE_INT,
                     51:       offsetof (struct uuconf_chat, uuconf_ctimeout), NULL },
                     52:   { "chat-fail", UUCONF_CMDTABTYPE_FN | 2,
                     53:       offsetof (struct uuconf_chat, uuconf_pzfail), icchat_fail },
                     54:   { "chat-seven-bit", UUCONF_CMDTABTYPE_BOOLEAN,
                     55:       offsetof (struct uuconf_chat, uuconf_fstrip), NULL },
                     56:   { NULL, 0, 0, NULL }
                     57: };
                     58: 
                     59: #define CCHAT_CMDS (sizeof asChat_cmds / sizeof asChat_cmds[0])
                     60: 
                     61: /* Handle a chat script command.  The chat script commands are entered
                     62:    as UUCONF_CMDTABTYPE_PREFIX, and the commands are routed to this
                     63:    function.  We copy the command table onto the stack and repoint it
                     64:    at qchat in order to make the function reentrant.  The return value
                     65:    can include UUCONF_CMDTABRET_KEEP, but should not include
                     66:    UUCONF_CMDTABRET_EXIT.  */
                     67: 
                     68: int
                     69: _uuconf_ichat_cmd (qglobal, argc, argv, qchat, pblock)
                     70:      struct sglobal *qglobal;
                     71:      int argc;
                     72:      char **argv;
                     73:      struct uuconf_chat *qchat;
                     74:      pointer pblock;
                     75: {
                     76:   char *zchat;
                     77:   struct uuconf_cmdtab as[CCHAT_CMDS];
                     78:   int iret;
                     79: 
                     80:   /* This is only invoked when argv[0] will contain the string "chat";
                     81:      the specific chat script command comes after that point.  */
                     82:   for (zchat = argv[0]; *zchat != '\0'; zchat++)
                     83:     if ((*zchat == 'c' || *zchat == 'C')
                     84:        && strncasecmp (zchat, "chat", sizeof "chat" - 1) == 0)
                     85:       break;
                     86:   if (*zchat == '\0')
                     87:     return UUCONF_SYNTAX_ERROR;
                     88:   argv[0] = zchat;
                     89: 
                     90:   _uuconf_ucmdtab_base (asChat_cmds, CCHAT_CMDS, (char *) qchat, as);
                     91: 
                     92:   iret = uuconf_cmd_args ((pointer) qglobal, argc, argv, as, pblock,
                     93:                          icunknown, 0, pblock);
                     94:   return iret &~ UUCONF_CMDTABRET_EXIT;
                     95: }
                     96: 
                     97: /* Handle the "chat" command.  This breaks up substrings in expect
                     98:    strings, and sticks the arguments into a NULL terminated array.  */
                     99: 
                    100: static int
                    101: icchat (pglobal, argc, argv, pvar, pinfo)
                    102:      pointer pglobal;
                    103:      int argc;
                    104:      char **argv;
                    105:      pointer pvar;
                    106:      pointer pinfo;
                    107: {
                    108:   struct sglobal *qglobal = (struct sglobal *) pglobal;
                    109:   char ***ppz = (char ***) pvar;
                    110:   pointer pblock = pinfo;
                    111:   int i;
                    112: 
                    113:   *ppz = NULL;
                    114: 
                    115:   for (i = 1; i < argc; i += 2)
                    116:     {
                    117:       char *z, *zdash;
                    118:       int iret;
                    119: 
                    120:       /* Break the expect string into substrings.  */
                    121:       z = argv[i];
                    122:       zdash = strchr (z, '-');
                    123:       while (zdash != NULL)
                    124:        {
                    125:          *zdash = '\0';
                    126:          iret = _uuconf_iadd_string (qglobal, z, TRUE, FALSE, ppz,
                    127:                                      pblock);
                    128:          if (iret != UUCONF_SUCCESS)
                    129:            return iret;
                    130:          *zdash = '-';
                    131:          z = zdash;
                    132:          zdash = strchr (z + 1, '-');
                    133:        }
                    134: 
                    135:       iret = _uuconf_iadd_string (qglobal, z, FALSE, FALSE, ppz, pblock);
                    136:       if (iret != UUCONF_SUCCESS)
                    137:        return iret;
                    138: 
                    139:       /* Add the send string without breaking it up.  If it starts
                    140:         with a dash we must replace it with an escape sequence, to
                    141:         prevent it from being interpreted as a subsend.  */
                    142: 
                    143:       if (i + 1 < argc)
                    144:        {
                    145:          if (argv[i + 1][0] != '-')
                    146:            iret = _uuconf_iadd_string (qglobal, argv[i + 1], FALSE,
                    147:                                        FALSE, ppz, pblock);
                    148:          else
                    149:            {
                    150:              size_t clen;
                    151: 
                    152:              clen = strlen (argv[i + 1]);
                    153:              z = uuconf_malloc (pblock, clen + 2);
                    154:              if (z == NULL)
                    155:                {
                    156:                  qglobal->ierrno = errno;
                    157:                  return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
                    158:                }
                    159:              z[0] = '\\';
                    160:              memcpy ((pointer) (z + 1), (pointer) argv[i + 1], clen + 1);
                    161:              iret = _uuconf_iadd_string (qglobal, z, FALSE, FALSE, ppz,
                    162:                                          pblock);
                    163:            }
                    164:          if (iret != UUCONF_SUCCESS)
                    165:            return iret;
                    166:        }
                    167:     }
                    168: 
                    169:   return UUCONF_CMDTABRET_KEEP;
                    170: }
                    171: 
                    172: /* Add a new chat failure string.  */
                    173: 
                    174: /*ARGSUSED*/
                    175: static int
                    176: icchat_fail (pglobal, argc, argv, pvar, pinfo)
                    177:      pointer pglobal;
                    178:      int argc;
                    179:      char **argv;
                    180:      pointer pvar;
                    181:      pointer pinfo;
                    182: {
                    183:   struct sglobal *qglobal = (struct sglobal *) pglobal;
                    184:   char ***ppz = (char ***) pvar;
                    185:   pointer pblock = pinfo;
                    186: 
                    187:   return _uuconf_iadd_string (qglobal, argv[1], TRUE, FALSE, ppz, pblock);
                    188: }
                    189: 
                    190: /* Return a syntax error for an unknown command.  */
                    191: 
                    192: /*ARGSUSED*/
                    193: static int
                    194: icunknown (pglobal, argc, argv, pvar, pinfo)
                    195:      pointer pglobal;
                    196:      int argc;
                    197:      char **argv;
                    198:      pointer pvar;
                    199:      pointer pinfo;
                    200: {
                    201:   return UUCONF_SYNTAX_ERROR;
                    202: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.