]> andersk Git - moira.git/blob - lib/nfsparttype.c
missing coma in last change, causes compile_et to coredump
[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 <string.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" },
37     { MR_FS_STAFF, "Staff" },
38     { MR_FS_MISC, "Other" },
39     { MR_FS_GROUPQUOTA, "GroupQuota" },
40     /* Insert new entries before the 0,0 pair */
41     { 0, 0 },
42 };
43
44 /*
45  * Given a numeric string containing a filesystem status value, return
46  * a string indicating what allocation type it is.
47  */
48 char *
49 format_filesys_type(fs_status)
50     char *fs_status;
51 {
52     char buf[BUFSIZ];
53     register struct pair *pp;
54     
55     int n_names = 0;
56     int stat = atoi(fs_status);
57     
58     buf[0] = '\0';
59
60     for (pp = fs_names; pp->type; pp++) {
61         if (stat & pp->type) {
62             if (n_names) (void) strcat(buf, ", ");
63             (void) strcat(buf, pp->name);
64             n_names++;
65             stat &= ~pp->type;
66         }
67     }
68     if (stat) {
69         char buf1[100];
70         
71         if (n_names) (void) strcat (buf, ", ");
72         (void) sprintf(buf1, "Unknown bits 0x%x", stat);
73         (void) strcat (buf, buf1);
74     }
75     if (!n_names) (void) strcpy(buf, "none");
76     return strsave(buf);
77 }
78
79 /*
80  * Given a string describing a filesystem allocation type, return the
81  * numeric value.
82  */
83 char *
84 parse_filesys_type(fs_type_name)
85     char *fs_type_name;
86 {
87     register struct pair *pp;
88     register char *cp = fs_type_name;
89     char temp[BUFSIZ];
90     int flags = 0;
91     
92     do {
93         /* Copy next component of type to temp */
94         char *t = strchr (cp, ',');
95         if (t) {
96             memcpy(temp, cp, t-cp);
97             temp[t-cp]='\0';
98             cp = t + 1; /* one after the comma */
99         } else {
100             (void) strcpy(temp, cp);
101             cp = NULL;
102         }
103
104         t = strtrim(temp);      /* nuke leading and trailing whitespace */
105
106         for (pp = fs_names; pp->type; pp++) {
107             if (strcasecmp(pp->name, t) == 0) {
108                 flags |= pp->type;
109                 break;
110             }
111         }
112     } while (cp);
113     (void) sprintf(temp, "%d", flags);
114     return strsave(temp);
115 }
This page took 0.448471 seconds and 5 git commands to generate.