]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZReadZcode.c
c9fc2f1d4aae6c819eac7886f8f98efcf3db2d7c
[1ts-debian.git] / zephyr / lib / ZReadZcode.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZReadZcode function.
3  *
4  *      Created by:     Jeffrey Hutzelman
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987, 1990, 2002 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #ifndef lint
14 static char rcsid_ZReadZcode_c[] = "$Id$";
15 #endif /* lint */
16
17 #include <internal.h>
18 #include <assert.h>
19
20
21 Code_t
22 ZReadZcode(unsigned char *ptr,
23            unsigned char *field,
24            int max,
25            int *len)
26 {
27     int n = 0;
28
29     if (*ptr++ != 'Z')
30         return ZERR_BADFIELD;
31
32     while (*ptr && n < max) {
33         if (*ptr == 0xff) {
34             ptr++;
35             switch (*ptr++) {
36                 case 0xf0: field[n++] = 0x00; continue;
37                 case 0xf1: field[n++] = 0xff; continue;
38                 default:   return ZERR_BADFIELD;
39             }
40         } else {
41             field[n++] = *ptr++;
42         }
43     }
44     if (*ptr)
45         return (ZERR_BADFIELD);
46     *len = n;
47     return (ZERR_NONE);
48 }