]> andersk Git - moira.git/blob - lib/nfsparttype.c
improve default zephyr format
[moira.git] / lib / nfsparttype.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  *
10  */
11
12 #ifndef lint
13 static char *rcsid_nfsparttype_c = "$Header$";
14 #endif lint
15
16 #include <mit-copyright.h>
17 #include <moira.h>
18 #include <stdio.h>
19 #include <strings.h>
20 #include <ctype.h>
21
22 extern char *strsave();
23 extern char *strtrim();
24
25 struct pair {
26     int type;
27     char *name;
28 };
29
30 /*
31  * Table of fs type names.
32  */
33
34 static struct pair fs_names[] = {
35     { MR_FS_STUDENT, "Student" },
36     { MR_FS_FACULTY, "Faculty/Project" },
37     { MR_FS_FACULTY, "Faculty" },
38     { MR_FS_FACULTY, "Project" },
39     { MR_FS_STAFF, "Staff" },
40     { MR_FS_MISC, "Other" },
41     /* Insert new entries before the 0,0 pair */
42     { 0, 0 },
43 };
44
45 /*
46  * Given a numeric string containing a filesystem status value, return
47  * a string indicating what allocation type it is.
48  */
49 char *
50 format_filesys_type(fs_status)
51     char *fs_status;
52 {
53     char buf[BUFSIZ];
54     register struct pair *pp;
55     
56     int n_names = 0;
57     int stat = atoi(fs_status);
58     
59     buf[0] = '\0';
60
61     for (pp = fs_names; pp->type; pp++) {
62         if (stat & pp->type) {
63             if (n_names) (void) strcat(buf, ", ");
64             (void) strcat(buf, pp->name);
65             n_names++;
66             stat &= ~pp->type;
67         }
68     }
69     if (stat) {
70         char buf1[100];
71         
72         if (n_names) (void) strcat (buf, ", ");
73         (void) sprintf(buf1, "Unknown bits 0x%x", stat);
74         (void) strcat (buf, buf1);
75     }
76     if (!n_names) (void) strcpy(buf, "none");
77     return strsave(buf);
78 }
79
80 /*
81  * Given a string describing a filesystem allocation type, return the
82  * numeric value.
83  */
84 char *
85 parse_filesys_type(fs_type_name)
86     char *fs_type_name;
87 {
88     register struct pair *pp;
89     register char *cp = fs_type_name;
90     char temp[BUFSIZ];
91     int flags = 0;
92     
93     do {
94         /* Copy next component of type to temp */
95         char *t = index (cp, ',');
96         if (t) {
97             bcopy(cp, temp, t-cp);
98             temp[t-cp]='\0';
99             cp = t + 1; /* one after the comma */
100         } else {
101             (void) strcpy(temp, cp);
102             cp = NULL;
103         }
104
105         t = strtrim(temp);      /* nuke leading and trailing whitespace */
106
107         for (pp = fs_names; pp->type; pp++) {
108             if (cistrcmp(pp->name, t) == 0) {
109                 flags |= pp->type;
110                 break;
111             }
112         }
113     } while (cp);
114     (void) sprintf(temp, "%d", flags);
115     return strsave(temp);
116 }
This page took 0.082087 seconds and 5 git commands to generate.