xref: /386bsd/usr/src/libexec/uucp/parse.c (revision a2142627)
1 /* parse.c
2    Parse a UUCP command string.
3 
4    Copyright (C) 1991, 1992 Ian Lance Taylor
5 
6    This file is part of the Taylor UUCP package.
7 
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12 
13    This program 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    General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; 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 ian@airs.com or
23    c/o AIRS, P.O. Box 520, Waltham, MA 02254.
24 
25    $Log: parse.c,v $
26    Revision 1.3  1992/02/08  03:54:18  ian
27    Include <string.h> only in <uucp.h>, added 1992 copyright
28 
29    Revision 1.2  1991/11/11  02:10:39  ian
30    Forget to set pseq field to NULL
31 
32    Revision 1.1  1991/09/10  19:40:31  ian
33    Initial revision
34 
35    */
36 
37 #include "uucp.h"
38 
39 #if USE_RCS_ID
40 char parse_rcsid[] = "$Id: parse.c,v 1.3 1992/02/08 03:54:18 ian Rel $";
41 #endif
42 
43 /* Parse a UUCP command string into an scmd structure.  This is called
44    by the 'g' protocol and the UNIX command file reading routines.  It
45    destroys the string it is passed, and the scmd string pointers are
46    left pointing into it.  It returns TRUE if the string is
47    successfully parsed, FALSE otherwise.  */
48 
49 boolean
fparse_cmd(zcmd,qcmd)50 fparse_cmd (zcmd, qcmd)
51      char *zcmd;
52      struct scmd *qcmd;
53 {
54   char *z;
55 
56   z = strtok (zcmd, " \t\n");
57   if (z == NULL)
58     return FALSE;
59 
60   qcmd->bcmd = *z;
61   if (qcmd->bcmd != 'S'
62       && qcmd->bcmd != 'R'
63       && qcmd->bcmd != 'X'
64       && qcmd->bcmd != 'H')
65     return FALSE;
66 
67   qcmd->pseq = NULL;
68 
69   /* Handle hangup commands specially.  If it's just "H", return
70      the command 'H' to indicate a hangup request.  If it's "HY"
71      return 'Y' and if it's "HN" return 'N'.  */
72 
73   if (qcmd->bcmd == 'H')
74     {
75       if (z[1] == '\0')
76 	return TRUE;
77       else if (z[1] == 'Y')
78 	{
79 	  qcmd->bcmd = 'Y';
80 	  return TRUE;
81 	}
82       else if (z[1] == 'N')
83 	{
84 	  qcmd->bcmd = 'N';
85 	  return TRUE;
86 	}
87       else
88 	return FALSE;
89     }
90 
91   if (z[1] != '\0')
92     return FALSE;
93 
94   z = strtok ((char *) NULL, " \t\n");
95   if (z == NULL)
96     return FALSE;
97   qcmd->zfrom = z;
98 
99   z = strtok ((char *) NULL, " \t\n");
100   if (z == NULL)
101     return FALSE;
102   qcmd->zto = z;
103 
104   z = strtok ((char *) NULL, " \t\n");
105   if (z == NULL)
106     return FALSE;
107   qcmd->zuser = z;
108 
109   z = strtok ((char *) NULL, " \t\n");
110   if (z == NULL || *z != '-')
111     return FALSE;
112   qcmd->zoptions = z + 1;
113 
114   z = strtok ((char *) NULL, " \t\n");
115   if (z != NULL)
116     qcmd->ztemp = z;
117   else if (qcmd->bcmd == 'S')
118     return FALSE;
119   else
120     qcmd->ztemp = "";
121 
122   z = strtok ((char *) NULL, " \t\n");
123   if (z != NULL)
124     {
125       char *zend;
126 
127       qcmd->imode = (int) strtol (z, &zend, 8);
128       if (*zend != '\0')
129 	return FALSE;
130     }
131   else if (qcmd->bcmd == 'S')
132     return FALSE;
133   else
134     qcmd->imode = 0666;
135 
136   z = strtok ((char *) NULL, " \t\n");
137   if (z != NULL)
138     qcmd->znotify = z;
139   else
140     qcmd->znotify = "";
141 
142   /* If the notify string is "", there may be a number of bytes.  */
143   qcmd->cbytes = -1;
144   if (strcmp (qcmd->znotify, "\"\"") == 0)
145     {
146       z = strtok ((char *) NULL, " \t\n");
147       if (z != NULL)
148 	{
149 	  char *zend;
150 
151 	  qcmd->znotify = "";
152 	  qcmd->cbytes = strtol (z, &zend, 10);
153 	  if (*zend != '\0')
154 	    return FALSE;
155 	}
156     }
157 
158   return TRUE;
159 }
160