DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦96f867d32⟧ TextFile

    Length: 5038 (0x13ae)
    Types: TextFile
    Names: »getplace.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Gb/getplace.c« 

TextFile

/*
 * Galactic Bloodshed (Robert Chansky, smq@b)
 *  Getplace -- returns directory level from string and current Dir
 *  Dispplace -- returns string from directory level
 */

#include "vars.h"
#include <ctype.h>
#include "ships.h"
char Disps[PLACENAMESIZE];
placetype Getplace2();
extern int God;


placetype Getplace(string, ignoreexpl)
char *string;
int ignoreexpl;
{
 bool error;
 int getplace_shdata;
 placetype where;	/* return value */

 Bzero(where);

 switch (*string) {
	  case '/':
		   where.level=LEVEL_UNIV;	/* scope = root (universe) */
		   where.snum=0;
		   where.pnum= where.shipno=0;
		   return(Getplace2(string+1,&where,ignoreexpl));
	 case '#':
		   sscanf(++string,"%hd",&where.shipno);
		   openshdata(&getplace_shdata);
		   if (!getship(getplace_shdata,&where.shipptr,where.shipno)) {
			close(getplace_shdata);
			DontOwnErr(where.shipno);
			where.err = 1;
			return where;
		   }
		   close(getplace_shdata);
		   if ( (where.shipptr->owner==Playernum || ignoreexpl)
						&& !where.shipptr->is_dead) {
			   where.level = LEVEL_SHIP;
			   where.snum = where.shipptr->storbits;
			   where.pnum = where.shipptr->pnumorbits;
			/* where.shipno already taken care of */
			   while (isdigit(*string)) 
				string++;
			   if (*string=='/')
				 return Getplace2(string+1,&where, ignoreexpl);
			   else
				 return where;
		   } else {
			where.err = 1;
			DontOwnErr(where.shipno);
			return where;
		   }

	 case '-':
			/* no destination */
		   where.level = LEVEL_UNIV;
		   return where;

	default:
			/* copy current scope to scope */
		   where.level = Dir.level;
		   where.snum = Dir.snum;
		   where.pnum = Dir.pnum;
		   if (where.level==LEVEL_SHIP) {
			   where.shipno = Dir.shipno;
			   openshdata(&getplace_shdata);
			   getship(getplace_shdata,&(where.shipptr),where.shipno);
			   close(getplace_shdata);
		   }
		   if (*string==CHAR_CURR_SCOPE)
			return where;
		   else 
			return Getplace2(string,&where, ignoreexpl);
 }

}



placetype Getplace2(string,where, ignoreexpl)
char *string;
placetype *where;
int ignoreexpl;
{
char substr[NAMESIZE];
planettype *p;
shiptype *s;
register int i,l;
int shdata,tick;
int getplace2_pdata;

 /*printf("getplace2:looking for '%s'\n",string);*/

 if (where->err || *string=='\0' || *string=='\n')
	return(*where);		/* base cases */

 else if (*string=='.') {
    if (where->level==LEVEL_UNIV) {
	printf("Can't go higher.\n");
	where->err=1;
	return(*where);
    } else {
	if (where->level==LEVEL_SHIP)
		where->level = where->shipptr->whatorbits;
	else 
		where->level--;
	while (*string=='.') string++;
	while (*string=='/') string++;
	return(Getplace2(string,where,ignoreexpl));
    }
 } else {
		/* is a char string, name of something */
    /*printf("before scanf str=`%s`\n",string);*/
    sscanf(string,"%[^/ \n]",substr);
    /*printf("after scanf sub=`%s`\n",substr);*/

    do {
       /*if (isupper(*string) )
		(*string) = tolower(*string);*/
       string++;
    } while (*string!='/' && *string!='\n' && *string!='\0');

    l=strlen(substr);
    if (where->level==LEVEL_UNIV) {
	for (i=0; i<Sdata.numstars; i++)
	   if (!strncmp(substr,Stars[i]->name,l)) {
		 where->level=LEVEL_STAR;
		 where->snum = i;
		 if (ignoreexpl || isset(Stars[where->snum]->explored, Playernum) || God) {
			 tick = (*string=='/');
			 return(Getplace2(string+tick,where,ignoreexpl));
		 }
		 printf("You have not explored %s yet.\n",
						Stars[where->snum]->name);
		 where->err = 1;
		 return(*where);
	   }
	if (i>=Sdata.numstars) {
		printf("No such star %s.\n",substr);
		where->err=1;
		return(*where);
	}
    } else if (where->level==LEVEL_STAR) {
	for (i=0; i<Stars[where->snum]->numplanets; i++)
	   if (!strncmp(substr,Stars[where->snum]->pnames[i],l)) {
		 where->level=LEVEL_PLAN;
		 where->pnum = i;
		 openpdata(&getplace2_pdata);
		 getplanet(getplace2_pdata, &p, Stars[where->snum]->planetpos[i]);
		 close(getplace2_pdata);
		 if (ignoreexpl || p->info[Playernum-1].explored || God) {
			 free(p);
			 tick = (*string=='/');
			 return(Getplace2(string+tick,where,ignoreexpl));
		 }
		 printf("You have not explored %s yet.\n",Stars[where->snum]->pnames[i]);
		 where->err = 1;
		 free(p);
		 return(*where);
	   }
	if (i >= Stars[where->snum]->numplanets) {
		printf("No such planet %s.\n",substr);
		where->err=1;
		return(*where);
	}
    } else if (where->level==LEVEL_PLAN) {
	printf("Can't descend to %s.\n",substr);
	where->err=1;
	return(*where);
    }
 }
}



char *Dispplace(where)
placetype *where;
{

 switch (where->level) {
      case LEVEL_STAR:
	     sprintf(Disps,"/%s",Stars[where->snum]->name);
	     return(Disps);
      case LEVEL_PLAN:
	     sprintf(Disps,"/%s/%s",Stars[where->snum]->name, Stars[where->snum]->pnames[where->pnum]);
	     return(Disps);
      case LEVEL_SHIP:
	     sprintf(Disps,"#%d",where->shipno);
	     return(Disps);
      case LEVEL_UNIV:
	     return("-");
      default:
	     printf("illegal Dispplace val = %d\n",where->level);
	     where->err = 1;
	     return("/");
	     break;
 }
}