#include <sys/types.h>
#include <stdio.h>
#include <strings.h>
#include <sys/param.h>
#include <users.h>
#include <userdefs.h>
#include <project.h>
#include <errno.h>
#include "messages.h"
static projid_t projlist[NPROJECTS_MAX + 1];
static int nproj_max = NPROJECTS_MAX;
int **
valid_lproject(char *list)
{
int n_invalid = 0;
int i = 0;
int j;
char *ptr;
struct project projent;
int warning;
char mybuf[PROJECT_BUFSZ];
if (!list || !*list)
return ((int **)NULL);
while ((ptr = strtok((i || n_invalid) ? NULL : list, ","))) {
switch (valid_project(ptr, &projent, mybuf, sizeof (mybuf),
&warning)) {
case INVALID:
errmsg(M_INVALID, ptr, "project id");
n_invalid++;
break;
case TOOBIG:
errmsg(M_TOOBIG, "projid", ptr);
n_invalid++;
break;
case UNIQUE:
errmsg(M_PROJ_NOTUSED, ptr);
n_invalid++;
break;
case NOTUNIQUE:
if (!i)
projlist[i++] = projent.pj_projid;
else {
for (j = 0; j < i; j++)
if (projent.pj_projid == projlist[j])
break;
if (j == i)
projlist[i++] = projent.pj_projid;
}
break;
}
if (warning)
warningmsg(warning, ptr);
if (i >= nproj_max) {
errmsg(M_MAXPROJECTS, nproj_max);
break;
}
}
projlist[i] = -1;
if (n_invalid)
exit(EX_BADARG);
return ((int **)projlist);
}