Example #1
0
void
nntprefreshall(Netbuf *n)
{
	char *f[10], *p;
	int hi, lo, nf;
	Group *g;

	if(nntpcmd(n, "LIST", 21) < 0)
		return;

	while((p = Nrdline(n)) != nil){
		if(strcmp(p, ".")==0)
			break;

		nf = getfields(p, f, nelem(f), 1, "\t\r\n ");
		if(nf != 4){
			int i;
			for(i=0; i<nf; i++)
				fprint(2, "%s%s", i?" ":"", f[i]);
			fprint(2, "\n");
			fprint(2, "syntax error in group list, line %d", n->lineno);
			return;
		}
		g = findgroup(root, f[0], 1);
		hi = strtol(f[1], 0, 10)+1;
		lo = strtol(f[2], 0, 10);
		if(g->hi != hi){
			g->hi = hi;
			if(g->lo==0)
				g->lo = lo;
			g->canpost = f[3][0] == 'y';
			g->mtime = time(0);
		}
	}
}
Example #2
0
void
b_order( game *aGame, player *P, strlist **s )
{
    group *g;                   /* pointer to named group */
    group *g2;                  /* pointer to new group */
    int i;                      /* int value for number of ships */
    char *ns;                   /* char value for number of ships */

    DBUG_ENTER( "b_order" );

    /* find the named group */
    g = findgroup( P, getstr( 0 ) );
    if ( !g ) {
        mistake( P, INFO, *s, "Group not recognized." );
        DBUG_VOID_RETURN;
    }

    /* check to see if we're detaching from a fleet */
    ns = getstr( 0 );
    if ( noCaseStrncmp( ns, "fleet", 5 ) == 0 ) {
        if ( !epsilon( g->dist, 0.0, 0.0001 ) ) {
            mistake( P, WARNING, *s, "Fleet is in hyperspace." );
            DBUG_VOID_RETURN;
        }
        g->thefleet = 0;
        DBUG_VOID_RETURN;
    }

    /* are there enough ships to detach? */
    i = atoi( ns );
    if ( i > g->ships ) {       /* FS Dec 1998 */
        mistake( P, INFO, *s, "Not enough ships in group." );
        DBUG_VOID_RETURN;
    }

    /* this was an odd problem */
    if ( i < 0 ) {              /* KDW July 1999 */
        mistake( P, WARNING, *s, "Can't have negative number of ships." );
        DBUG_VOID_RETURN;
    }

    /* create a new group for what's being broken off and add it to
     * the list of groups the player owns
     */
    g2 = allocStruct( group );
    *g2 = *g;
    g2->ships = i;
    g->ships -= i;
    g2->thefleet = 0;
    g2->next = NULL;
    numberGroup( P, g2 );
    g2->name = ( char * ) malloc( 8 );
    sprintf( g2->name, "%d", g2->number );
    addList( &P->groups, g2 );

    DBUG_VOID_RETURN;
}
Example #3
0
void
x_order( game *aGame, player *P, strlist **s )
{
    group *g;
    group *g2;
    int i;
    int j;

    DBUG_ENTER( "x_order" );

    g = findgroup( P, getstr( 0 ) );
    if ( !g ) {
        mistake( P, ERROR, *s, "Group not recognized." );
        DBUG_VOID_RETURN;
    }
    if ( g->dist > 0.0 ) {
        mistake( P, ERROR, *s, "Group is in hyperspace." );
        DBUG_VOID_RETURN;
    }
    if ( g->loadtype == CG_COL && g->where->owner && g->where->owner != P ) {
        mistake( P, ERROR, *s,
                 "Can't unload colonists onto an alien planet." );
        DBUG_VOID_RETURN;
    }
    i = g->ships;
    if ( ( j = atoi( getstr( 0 ) ) ) != 0 ) {
        i = j;
        if ( i > g->ships ) {
            mistake( P, ERROR, *s, "Not enough ships, all available used." );
            i = g->ships;
        }
        if ( i <= 0 ) {         /* KDW July 1999 */
            mistake( P, ERROR, *s,
                     "You must specify more than 0 ships, all available used." );
            i = g->ships;
        }
        if ( i != g->ships ) {
            g2 = allocStruct( group );

            *g2 = *g;
            g2->next = NULL;
            numberGroup( P, g2 );
            g2->name = ( char * ) malloc( 8 );
            sprintf( g2->name, "%d", g2->number );
            addList( &P->groups, g2 );
            g->ships -= i;
            g2->ships = i;
            g = g2;
        }
    }
    unloadgroup( g, P, g->load );
    g->where->mat += shipmass( g ) * g->ships;
    g->ships = 0;
    DBUG_VOID_RETURN;
}
Example #4
0
/*
 * Put add users to a group.
 */
int
group(char **argv)
{
    struct grouphead *gh;
    struct group *gp;
    char **ap, *gname, **p;
    int h, s;

    if (*argv == NULL) {
        for (h = 0, s = 1; h < HSHSIZE; h++)
            for (gh = groups[h]; gh != NULL; gh = gh->g_link)
                s++;
        ap = (char **)salloc(s * sizeof(*ap));
        for (h = 0, p = ap; h < HSHSIZE; h++)
            for (gh = groups[h]; gh != NULL; gh = gh->g_link)
                *p++ = gh->g_name;
        *p = NULL;
        sort(ap);
        for (p = ap; *p != NULL; p++)
            printgroup(*p);
        return (0);
    }
    if (argv[1] == NULL) {
        printgroup(*argv);
        return (0);
    }
    gname = *argv;
    h = hash(gname);
    if ((gh = findgroup(gname)) == NULL) {
        gh = calloc(sizeof(*gh), 1);
        gh->g_name = vcopy(gname);
        gh->g_list = NULL;
        gh->g_link = groups[h];
        groups[h] = gh;
    }

    /*
     * Insert names from the command list into the group.
     * Who cares if there are duplicates?  They get tossed
     * later anyway.
     */

    for (ap = argv+1; *ap != NULL; ap++) {
        gp = calloc(sizeof(*gp), 1);
        gp->ge_name = vcopy(*ap);
        gp->ge_link = gh->g_list;
        gh->g_list = gp;
    }
    return (0);
}
Example #5
0
static struct name *
name_expand(char *sname, int ntype)
{
	struct grouphead *gh;
	struct name *np;

	if ((gh = findgroup(sname)) != NULL) {
		np = gexpand(NULL, gh, 0, ntype);
	}
	else {
		np = csalloc(1, sizeof(*np));
		np->n_name = sname;
		np->n_type = ntype;
	}
	return np;
}
Example #6
0
int main (int argc, char *argv [])
{
    int
	argn,
	argmax,
	max,
	used,
	i,
	j,
	k,
	n;
    char
	*p;
    GROUP_
	*gr;

    no_mem_buffer = (char *) malloc (1024);

    get_programname (argv [0]);

    while (argc > 1 && argv [1][0] == '-') {
	if (! strcmp (argv [1], "-o")) {
	    argc--;
	    argv++;
	    outfile = argv [1];
	} else if (! strcmp (argv [1], "-l")) {
	    argc--;
	    argv++;
	    listfile = argv [1];
	}
	argc--;
	argv++;
    }

    if (argc < 2 && ! listfile)
	syntax ();

    if (listfile) {
	argc = 1;
	argmax = 256;
	p = argv [0];
	argv = (char **) s_malloc (argmax * sizeof (char *));
	argv [0] = p;
	fileopen (listfile);
	while (mygetline (FALSE)) {
	    if (argc == argmax) {
		argmax += 256;
		argv = (char **) s_realloc (argv, argmax * sizeof (char *));
	    }
	    argv [argc++] = s_strdup (buffer);
	}
    }
    
    fileopen (argv [1]);
    while (mygetline (FALSE)) {
	if (buffer [0] == 'l' || buffer [0] == 'L') {
	    if (n_lbls == max_lbls) {
		max_lbls += 256;
		lbls = (char **) s_realloc (lbls, max_lbls * sizeof (char *));
	    }
	    i = 1;
	    while (buffer [i] && isspace ((unsigned char) buffer [i]))
		i++;
	    lbls [n_lbls++] = s_strdup (buffer + i);
	}
    }
    fclose (fp);

    qsort (lbls, n_lbls, sizeof (char *), scmp);

    if (outfile) {
	fpout = fopen (outfile, "w");
	if (! fpout)
	    errit ("Creating file \"%s\": %s", outfile, strerror (errno));
    } else
	fpout = stdout;

    fprintf (fpout, "# Number of cluster files:\n%i\n# Number of labels:\n%i\n# Labels:\n", argc - 1, n_lbls);
    for (i = 0; i < n_lbls; i++)
	fprintf (fpout, "%s\n", lbls [i]);
    fprintf (fpout, "# Cluster count, cluster members, average cophenetic distance:\n");

    max = n_lbls - 1;
    cl = (CLUSTER_ *) s_malloc (max * sizeof (CLUSTER_));

    members = (char *) s_malloc ((n_lbls + 1) * sizeof (char));
    members [n_lbls] = '\0';

    for (argn = 1; argn < argc; argn++) {
	fileopen (argv [argn]);
	for (used = 0; used < max; used++) {
	    mygetline (TRUE);
	    if (sscanf (buffer, "%i %f%n", &(cl [used].index), &(cl [used].value), &i) < 2)
		errit ("Syntax error in \"%s\", line %i: \"%s\"", filename, inputline, buffer);
	    for (n = 0; n < 2; n++) {
		mygetline (TRUE);
		switch (buffer [0]) {
                    case 'l':
                    case 'L':
			cl [used].node [n] = LBL;
			i = 1;
			while (buffer [i] && isspace ((unsigned char) buffer [i]))
			    i++;
			p = bsearch (buffer + i, lbls, n_lbls, sizeof (char *), lscmp);
			if (! p)
			    errit ("Unknown label in \"%s\", line %i: \"%s\"", filename, inputline, buffer + i);
			cl [used].n [n].label = ((char **)p) - lbls;
			break;
                    case 'c':
                    case 'C':
			cl [used].node [n] = CLS;
			if (sscanf (buffer + 1, "%i", &(cl [used].n [n].cluster)) != 1)
			    errit ("Missing cluster number at line %i", inputline);
			break;
                    default:
			errit ("Syntax error at line %i: \"%s\"", inputline, buffer);
		}
	    }
	}

	/* replace indexes */
	for (i = 0; i < max; i++)
	    for (j = 0; j < 2; j++)
		if (cl [i].node [j] == CLS)
		    for (k = 0; k < max; k++)
			if (cl [i].n [j].cluster == cl [k].index) {
			    cl [i].n [j].cluster = k;
			    break;
			}

	for (i = 0; i < max; i++) {
	    for (j = 0; j < n_lbls; j++)
		members [j] = '-';
	    walk (i);

	    gr = findgroup ();
	    gr->n++;
	    gr->value += cl [i].value;

	}
	fclose (fp);
    }

    walkgroups (root);

    if (outfile)
	fclose (fpout);

    return 0;
}
Example #7
0
static char*
fswalk1(Fid *fid, char *name, Qid *qid)
{
	char *p;
	int i, isdotdot, n;
	Aux *a;
	Group *ng;

	isdotdot = strcmp(name, "..")==0;

	a = fid->aux;
	if(a->s)	/* file */
		return "protocol botch";
	if(a->n != -1){
		if(isdotdot){
			*qid = (Qid){PATH(a->g->num, 0), 0, QTDIR};
			fid->qid = *qid;
			a->n = -1;
			return nil;
		}
		for(i=0; i<Nfile; i++){
			if(strcmp(name, filename[i])==0){
				if((a->s = nntpget(net, a->g, a->n, nntpname[i])) != nil){
					*qid = (Qid){PATH(a->g->num, a->n), Qbody, 0};
					fid->qid = *qid;
					a->file = i;
					return nil;
				}else
					return "file does not exist";
			}
		}
		return "file does not exist";
	}

	if(isdotdot){
		a->g = a->g->parent;
		*qid = (Qid){PATH(a->g->num, 0), 0, QTDIR};
		fid->qid = *qid;
		return nil;
	}

	if(a->g->isgroup && !readonly && a->g->canpost
	&& strcmp(name, "post")==0){
		a->ispost = 1;
		*qid = (Qid){PATH(a->g->num, 0), 0, 0};
		fid->qid = *qid;
		return nil;
	}

	if((ng = findgroup(a->g, name, 0)) != nil){
		a->g = ng;
		*qid = (Qid){PATH(a->g->num, 0), 0, QTDIR};
		fid->qid = *qid;
		return nil;
	}

	n = strtoul(name, &p, 0);
	if('0'<=name[0] && name[0]<='9' && *p=='\0' && a->g->lo<=n && n<a->g->hi){
		a->n = n;
		*qid = (Qid){PATH(a->g->num, n+1-a->g->lo), 0, QTDIR};
		fid->qid = *qid;
		return nil;
	}

	return "file does not exist";
}