]> andersk Git - moira.git/blob - lib/nfsparttype.c
eliminate use of the `register' keyword: let the compiler decide
[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
15
16 #include <mit-copyright.h>
17 #include <moira.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <ctype.h>
21 #include <stdlib.h>
22
23 extern char *strsave();
24 extern char *strtrim();
25
26 struct pair {
27   int type;
28   char *name;
29 };
30
31 /*
32  * Table of fs type names.
33  */
34
35 static struct pair fs_names[] = {
36   { MR_FS_STUDENT, "Student" },
37   { MR_FS_FACULTY, "Faculty" },
38   { MR_FS_STAFF, "Staff" },
39   { MR_FS_MISC, "Other" },
40   { MR_FS_GROUPQUOTA, "GroupQuota" },
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 *format_filesys_type(char *fs_status)
50 {
51   char buf[BUFSIZ];
52   struct pair *pp;
53
54   int n_names = 0;
55   int stat = atoi(fs_status);
56
57   buf[0] = '\0';
58
59   for (pp = fs_names; pp->type; pp++)
60     {
61       if (stat & pp->type)
62         {
63           if (n_names)
64             strcat(buf, ", ");
65           strcat(buf, pp->name);
66           n_names++;
67           stat &= ~pp->type;
68         }
69     }
70   if (stat)
71     {
72       char buf1[100];
73
74       if (n_names)
75         strcat(buf, ", ");
76       sprintf(buf1, "Unknown bits 0x%x", stat);
77       strcat(buf, buf1);
78     }
79   if (!n_names)
80     strcpy(buf, "none");
81   return strsave(buf);
82 }
83
84 /*
85  * Given a string describing a filesystem allocation type, return the
86  * numeric value.
87  */
88 char *parse_filesys_type(char *fs_type_name)
89 {
90   struct pair *pp;
91   char *cp = fs_type_name;
92   char temp[BUFSIZ];
93   int flags = 0;
94
95   do
96     {
97       /* Copy next component of type to temp */
98       char *t = strchr(cp, ',');
99       if (t)
100         {
101           memcpy(temp, cp, t - cp);
102           temp[t - cp] = '\0';
103           cp = t + 1; /* one after the comma */
104         }
105       else
106         {
107           strcpy(temp, cp);
108           cp = NULL;
109         }
110
111       t = strtrim(temp);        /* nuke leading and trailing whitespace */
112
113       for (pp = fs_names; pp->type; pp++)
114         {
115           if (!strcasecmp(pp->name, t))
116             {
117               flags |= pp->type;
118               break;
119             }
120         }
121     }
122   while (cp);
123   sprintf(temp, "%d", flags);
124   return strsave(temp);
125 }
This page took 0.139802 seconds and 5 git commands to generate.