Exemplo n.º 1
0
int 
fredloop (char **vec, int error)
{
	struct dispatch *ds;

	if ((ds = getds (strcmp (*vec, "?") ? *vec : "help")) == NULL)
		return error;
	if (network) {
		if ((ds -> ds_flags & DS_USER)
				|| ((ds -> ds_flags & DS_SYOK) && !runsys)) {
			advise (NULLCP, "unavailable operation \"%s\"", *vec);
			return error;
		}
	} else
		vec[0] = ds -> ds_name;

	switch ((*ds -> ds_fnx) (vec)) {
	case NOTOK:
		return error;

	case OK:
	default:
		return OK;

	case DONE:
		return DONE;
	}
}
Exemplo n.º 2
0
long
netsend( int lsn, char *buf, unsigned int nbytes )
{
  struct ncb      ncb;
  register struct ncb     *ncbp = &ncb;

  ncbp->ncb_com = NSESSND;
  ncbp->ncb_ret = 0;
  ncbp->ncb_done = 0;
  ncbp->ncb_lnum = 0;
#ifdef REALMODE
  ncbp->ncb_sig.lp_offset = 0;
  ncbp->ncb_sig.lp_seg = 0;
#else
  ncbp->ncb_sem = NULL;
#endif
  ncbp->ncb_lsn = (unsigned char) lsn;
  ncbp->ncb_len = (unsigned short)nbytes;
#ifdef REALMODE
  ncbp->ncb_bfr.lp_offset = (unsigned short)buf;
  ncbp->ncb_bfr.lp_seg = (unsigned short)getds();
#else
  ncbp->ncb_bfr = (char FAR *) buf;
#endif

  if ( passncb(ncbp) < 0 )
    {
      /* neterrno already set by passncb */
      return( -1L );
    }
  else
    return( (long) nbytes );        /* comand complete and OK */
}
Exemplo n.º 3
0
Arquivo: t7.c Projeto: 00001/plan9port
int
runmacro(int dot, int argc, Rune **argv)
{
	Rune *p;
	int i;
	Mac *m;
	
if(verbose && isupperrune(argv[0][0])) fprint(2, "run: %S\n", argv[0]);
	p = getds(argv[0]);
	if(p == nil){
		if(verbose)
			warn("ignoring unknown request %C%S", dot, argv[0]);
		if(verbose > 1){
			for(i=0; i<argc; i++)
				fprint(2, " %S", argv[i]);
			fprint(2, "\n");
		}
		return -1;
	}
	if(nmstack >= nelem(mstack)){
		fprint(2, "%L: macro stack overflow:");
		for(i=0; i<nmstack; i++)
			fprint(2, " %S", mstack[i].argv[0]);
		fprint(2, "\n");
		return -1;
	}
	m = &mstack[nmstack++];
	m->argc = argc;
	for(i=0; i<argc; i++)
		m->argv[i] = erunestrdup(argv[i]);
	pushinputstring(p);
	nr(L(".$"), argc-1);
	inputnotify(popmacro);
	return 0;
}
Exemplo n.º 4
0
Arquivo: t7.c Projeto: 00001/plan9port
/* .rn - rename request, macro, or string */
void
r_rn(int argc, Rune **argv)
{
	USED(argc);
	renreq(argv[1], argv[2]);
	renraw(argv[1], argv[2]);
	ds(argv[2], getds(argv[1]));
	ds(argv[1], nil);
}
Exemplo n.º 5
0
Arquivo: t7.c Projeto: 00001/plan9port
int
e_star(void)
{
	Rune *p;
	
	p = getds(getname());
	if(p)
		pushinputstring(p);
	return 0;
}
Exemplo n.º 6
0
void
r_pm(int argc, Rune **argv)
{
	int i;
	
	if(argc == 1){
		printds(0);
		return;
	}
	if(runestrcmp(argv[1], L("t")) == 0){
		printds(1);
		return;
	}
	for(i=1; i<argc; i++)
		fprint(2, "%S: %S\n", argv[i], getds(argv[i]));
}
Exemplo n.º 7
0
Arquivo: t7.c Projeto: 00001/plan9port
/* define macro - .de, .am, .ig */
void
r_de(int argc, Rune **argv)
{
	Rune *end, *p;
	Fmt fmt;
	int ignore, len;

	delreq(argv[1]);
	delraw(argv[1]);
	ignore = runestrcmp(argv[0], L("ig")) == 0;
	if(!ignore)
		runefmtstrinit(&fmt);
	end = L("..");
	if(argc >= 3)
		end = argv[2];
	if(runestrcmp(argv[0], L("am")) == 0 && (p=getds(argv[1])) != nil)
		fmtrunestrcpy(&fmt, p);
	len = runestrlen(end);
	while((p = readline(CopyMode)) != nil){
		if(runestrncmp(p, end, len) == 0 
		&& (p[len]==' ' || p[len]==0 || p[len]=='\t'
			|| (p[len]=='\\' && p[len+1]=='}'))){
			free(p);
			goto done;
		}
		if(!ignore)
			fmtprint(&fmt, "%S\n", p);
		free(p);
	}
	warn("eof in %C%S %S - looking for %#Q", dot, argv[0], argv[1], end);
done:
	if(ignore)
		return;
	p = runefmtstrflush(&fmt);
	if(p == nil)
		sysfatal("out of memory");
	ds(argv[1], p);
	free(p);
}
Exemplo n.º 8
0
int
netpname(char *pname)
{
  struct ncb ncb;
  register struct ncb *ncbp = &ncb;
  struct astat stats;

  ncbp->ncb_com = NADAPSTAT;
  ncbp->ncb_ret = 0;
  ncbp->ncb_done = 0;
  ncbp->ncb_lnum = 0;
  ncbp->ncb_rto = 0;
  ncbp->ncb_sto = 0;
#ifdef REALMODE
  ncbp->ncb_sig.lp_offset = 0;
  ncbp->ncb_sig.lp_seg = 0;
#else
  ncbp->ncb_sem = NULL;
#endif
  ncbp->ncb_rname[0] = '*';
  ncbp->ncb_lsn = 0;
  ncbp->ncb_len = sizeof(struct astat);
#ifdef REALMODE
  ncbp->ncb_bfr.lp_offset = (unsigned short) &stats;
  ncbp->ncb_bfr.lp_seg = (unsigned short) getds();
#else
  ncbp->ncb_bfr = (char FAR *) &stats;
#endif

  if ( passncb(ncbp) < 0 )
    return( -1 );
  else
    {
      memset(pname, '\0', 10);
      memcpy(pname + 10, stats.as_uid, 6);
      return( 0 );
    }
}
Exemplo n.º 9
0
/* \fcnfh
   get number of isotopes from file and set index 

   @returns number of lines read
*/
int
getmnfromfile(FILE *fp,
	      struct atm_data *at,
	      struct transit *tr,
	      int nmb)
{
  char line[maxline],*lp;
  int ison=0,i;
  struct isotopes *iso=tr->ds.iso;
  enum isodo *isodo=iso->isodo;

  //Set variable to handle proportional to isotopes
  int ipi=0,ipa=at->ipa=4;
  isolineinatm=(_Bool *)calloc(iso->n_i,sizeof(_Bool));
  isoprop=(struct atm_isoprop *)calloc(ipa,sizeof(struct atm_isoprop));

  at->begline=0;
  enum isodo atisodo;
  at->isodo = (enum isodo *)calloc(nmb,sizeof(enum isodo));
  at->isoeq = (int *)       calloc(nmb,sizeof(int));
  at->m     = (PREC_ZREC *) calloc(nmb,sizeof(PREC_ZREC));
  at->n     = (char **)     calloc(nmb,sizeof(char *));
  at->n[0]  = (char *)      calloc(nmb*maxeisoname,sizeof(char));
  at->isoeq[0]=-1;
  for(i=1;i<nmb;i++){
    at->n[i]=at->n[0]+i*maxeisoname;
    at->isoeq[i]=-1;
  }

  //while t,p data doesn't start, check for the various modifiers
  while(1){
    switch(fgetupto_err(line,maxline,fp,&atmerr,atmfilename,
			at->begline++)){
    case '\n':			//Ignore comments and
    case '#':			//  blank lines
      continue;

    case 0:			//Error if EOF
      transiterror(TERR_SERIOUS|TERR_ALLOWCONT,
		   "readatminfo:: EOF unexpectedly found at line %i\n"
		   "of file %s while no t,p data points have been read\n"
		   ,at->begline,atmfilename);
      exit(EXIT_FAILURE);
      continue;

    case 'q':			//Whether is mass or number abundance
      lp=line+1;
      while(*lp++==' ');
      lp--;
      switch(*lp|0x20){
      case 'n':
	at->mass=0;
	break;
      case 'm':
	at->mass=1;
	break;
      default:
	transiterror(TERR_SERIOUS,
		     "'q' option in the atmosphere file can only be followed\n"
		     "by 'm' (for abundances by mass) or 'n' (for abundances by\n"
		     "number). '%s' is invalid.\n"
		     ,line);
	break;
      }
      continue;

    case 'z':			//Zero radius value
      zerorad=atof(line+1);
      continue;

    case 'f':			//An isotope is to be taken as
				//proportional to other.
      lp=line+1;
      while(*lp==' '||*lp=='\t') lp++;

      if(ipi==ipa)
	isoprop=(struct atm_isoprop *)realloc(isoprop,(ipa<<=1)*
					      sizeof(struct atm_isoprop));
      isoprop[ipi].m=getds(lp,0,isoprop[ipi].n,maxeisoname-1);
      //skip over recently read field, and go to next field.
      lp=nextfield(lp);
      //skip an optional equal '=' sign
      if(*lp=='=' && lp[1]==' ')
	lp=nextfield(lp);
      //get factor, which has to be between 0 and 1
      isoprop[ipi].f=strtod(lp,NULL);
      if(isoprop[ipi].f<0 )
	transiterror(TERR_CRITICAL,
		     "Abundance ratio has to be positive in atmosphere\n"
		     "file '%s' in line: %s"
		     ,atmfilename,line);
      lp=nextfield(lp);
      //get name of reference and increase index
      i=0;
      while(*lp)
	isoprop[ipi].t[i++]=*lp++;
      isoprop[ipi].t[i]='\0';

      //now check if that isotope is one of the given in the lineinfo
      //file 
      isoprop[ipi].eq=-1;
      isisoline(isoprop[ipi].n,isoprop[ipi].m,&isoprop[ipi].eq,factor,
		iso->isof,isodo,iso->n_i);

      //advance index and go for the next line
      ipi++;
      continue;

    case 'u':			//Change factorization of radius, temp,
				//or press
      switch(line[1]){
      case 'r':
	at->rads.fct=atof(line+2);
	break;
      case 'p':
	at->atm.pfct=atof(line+2);
	break;
      case 't':
	at->atm.tfct=atof(line+2);
	break;
      default:
	transiterror(TERR_SERIOUS,
		     "Invalid unit factor indication in atmosphere file\n");
	exit(EXIT_FAILURE);
      }
      continue;

    case 'n':			//Name or identifier for file data
      storename(at,line+1);
      continue;

    case 'i':			//Isotope information
      lp=line+1;
      while(*lp==' '||*lp=='\t') lp++;
      //'i' has to come before 'f'
      if(ipi)
	transiterror(TERR_CRITICAL,
		     "In line '%s'.\n"
		     " 'f' lines have to come after all the 'i' lines in\n"
		     " atmosphere file '%s'"
		     ,line,atmfilename);

      //for each field
      while(*lp){
	atisodo=atmfile;
	//Allocate if necessary
	if(ison==nmb){
	  nmb<<=1;
	  at->isodo = (enum isodo *)realloc(at->isodo,nmb*sizeof(enum isodo));
	  at->isoeq = (int *)       realloc(at->isoeq,nmb*sizeof(int));
	  at->m     = (PREC_ZREC *) realloc(at->m,    nmb*sizeof(PREC_ZREC));
	  at->n     = (char **)     realloc(at->n,    nmb*sizeof(char *));
	  at->n[0]  = (char *)      realloc(at->n[0], nmb*maxeisoname*sizeof(char));
	  for(i=1;i<nmb;i++)
	    at->n[i]=at->n[0]+i*maxeisoname;
	  for(i=nmb/2;i<nmb;i++)
	    at->isoeq[i]=-1;
	}

	//get mass and name, checking that is correct. First see if this
	//isotope wants to be ignored.
	if(*lp=='!'){
	  lp++;
	  atisodo=ignore;
	}
	at->m[ison]=getds(lp,0,at->n[ison],maxeisoname-1);
	if(at->m[ison]<0||at->n[ison]=='\0'){
	  transiterror(TERR_SERIOUS,
		       "Invalid field in file %s, line %i while reading isotope"
		       " info at:\n%s\n"
		       ,atmfilename,at->begline,lp);
	}

	//now check if that isotope is one of the given in the lineinfo
	//file
	isisoline(at->n[ison],at->m[ison],at->isoeq+ison,atisodo,
		  iso->isof,isodo,iso->n_i);
	at->isodo[ison++]=atisodo;

	//skip over recently read field, and go to next field.
	while(*lp!=' '&&*lp!='\0') lp++;
	while(*lp==' '||*lp=='\t') lp++;
      }
      continue;

    default:			//T,P seems to be starting
      break;
    }
    break;
  }

  transitprint(3,verblevel,
	       "Read all keywords in atmosphere file without problems\n");

  //Check if there was at least an isotope identification and allocate new
  //arrays
  if(!ison)
    transiterror(TERR_SERIOUS,
		 "No isotopes were found in atmosphere file, make sure to\n"
		 "specify them in a line starting with the letter 'i'.\n"
		 "First non-comment line read:\n%s\n"
		 ,line);
  at->begpos=ftell(fp)-strlen(line)-1;

  //shorten extra length of arrays
  fonly=(struct fonly *)calloc(nfonly,sizeof(struct fonly));
  at->ipa=ipa=ipi;
  isoprop=(struct atm_isoprop *)realloc(isoprop,ipa*
					sizeof(struct atm_isoprop));

  //Makes at arrays bigger, so that they can hold the factorized values.
  nmb       = at->n_aiso = ison + ipa;
  at->isodo = (enum isodo *)realloc(at->isodo,nmb*sizeof(enum isodo)      );
  at->isoeq = (int *)       realloc(at->isoeq,nmb*sizeof(int)             );
  at->m     = (PREC_ZREC *) realloc(at->m,    nmb*sizeof(PREC_ZREC)       );
  at->n     = (char **)     realloc(at->n,    nmb*sizeof(char *)          );
  at->n[0]  = (char *)      realloc(at->n[0], nmb*maxeisoname*sizeof(char));
  for(i=1;i<nmb;i++)
    at->n[i] = at->n[0] + i * maxeisoname;

  //initialize values for the factorized elements
  for(i=ison;i<nmb;i++){
    strncpy(at->n[i],isoprop[i-ison].n,maxeisoname-1);
    at->n[i][maxeisoname-1] = '\0';
    at->isoeq[i]            = i-ison;
    at->m[i]                = isoprop[i-ison].m;
    at->isodo[i]            = factor;
  }

  //Resolve what to do with those isotopes that appear in the transition
  //database, but not in the atmosphere file.
  at->n_niso = checknonmatch(tr,at,isodo);

  //Set full isotope info in the transit structure
  nmb = iso->n_i + at->n_niso;
  iso->isodo   = (enum isodo *)realloc(iso->isodo,
				       nmb*sizeof(enum isodo));
  iso->isof    = (prop_isof *)realloc(iso->isof,
				      nmb*sizeof(prop_isof));
  iso->isof[iso->n_i].n = (char *)realloc(iso->isof[iso->n_i].n,
					  (nmb-iso->n_i)*maxeisoname*
					  sizeof(char));
  for(i=1;i<nmb-iso->n_i;i++)
    iso->isof[iso->n_i+i].n = iso->isof[iso->n_i].n + i * maxeisoname;



  //Look for isotopes who have not been associated and see whether they
  //are supposed to be ignored. 
  nmb = iso->n_i;
  ipi = 0;
  int lineignore=0;
  for(i=0 ; i<ison+ipa ; i++)
    //If the isotope is not associated to the linedb isotopes, then
    //associate it. Note that isotopes in linedb that are ignored will
    //be associated (see comments for Line \label{isodbassoc}). Hence
    //they won't be detected in this IF. Factor isotopes will also be
    //associated, and will be handled below
    if(at->isoeq[i] == -1){
      //If they are not going to be ignored then associate them with the
      //following index available of post linedb isotopes.
      if(at->isodo[i] != ignore){
	at->isoeq[i]     = nmb;
	iso->isodo[nmb]  = at->isodo[i];
	iso->isof[nmb].m = at->m[i];
	strcpy(iso->isof[nmb++].n, at->n[i]);
      }
      //otherwise, they might only be used as a reference to factor.
      else{
	at->isoeq[i] = ipi;
      	strcpy(fonly[ipi++].n, at->n[i]);
      }
    }
  //Just count the number of ignored isotopes that belonged to the line
  //isotopes.
    else if(at->isodo[i] == ignore)
      lineignore++;
  //If there is factor isotopes
    else if(at->isodo[i] == factor && isoprop[at->isoeq[i]].eq == -1){
      if(at->isodo[i]==ignore)
	transiterror(TERR_CRITICAL,
		    "Trying to ignore an factor isotope, that is not\n"
		     "posible.\n");
      isoprop[at->isoeq[i]].eq = nmb;
      iso->isodo[nmb]          = at->isodo[i];
      iso->isof[nmb].m         = at->m[i];
      strcpy(iso->isof[nmb++].n, at->n[i]);
    }

  //Reduce the array to get rid of nonline-ignored isotopes. (isov has
  //not even been allocated yet)
  iso->n_e = nmb;
  iso->isodo   = (enum isodo *)realloc(iso->isodo,
				       nmb*sizeof(enum isodo));
  iso->isof    = (prop_isof *)realloc(iso->isof,
				      nmb*sizeof(prop_isof));
  iso->isof[iso->n_i].n = (char *)realloc(iso->isof[iso->n_i].n,
					  nmb*maxeisoname*sizeof(char));
  for(i=1;i<nmb-iso->n_i;i++)
    iso->isof[iso->n_i+i].n = iso->isof[iso->n_i].n + i * maxeisoname;


  //Check that everything makes sense
  double cumulother=0;
  for(i=0 ; i<at->n_aiso ; i++)
    if(at->isodo[i]==factor){
      int feq=at->isoeq[i];
      if(strcasecmp(isoprop[feq].n,"other")==0)
	cumulother+=isoprop[feq].f;
    }
  //It doesn't make sense for cumulother to be anything different from
  //unity (except round-off error): you want to associate the
  //remainder of the atmosphere to some isotopic properties. 
  if( cumulother!=0 && (int)(cumulother*ROUNDOFF+0.5)!=(int)(ROUNDOFF+0.5) )
    transiterror(TERR_SERIOUS,
		 "If you are specifying isotopes proportional to 'other'\n"
		 "you have to complete unity (%g). It doesn't make sense\n"
		 "otherwise\n"
		 ,cumulother);

  transitASSERT(nmb+nfonly!=ison+ipa,
		"Oooops, number of ignored-nonline elements (%i), plus the\n"
		"number of ignored-line elements(%i), plus the number of\n"
		"nonignored (%i), doesn't match the number of elements\n"
		"found in fields 'i'(%i) and 'f'(%i) of the atmosphere\n"
		"file '%s'\n"
		,nfonly,lineignore,nmb-lineignore,ison,ipa,atmfilename);

  transitASSERT(nmb!=iso->n_e,
		"Uyuyuyuyu! Problem in file %s, line %i,\n"
		"assertion failed: %i != %i!!\n"
		,__FILE__,__LINE__,nmb,iso->n_e);

  //free unused array, store factor info in at structure and return line
  //where T,P start
  free(isolineinatm);
  at->isoprop=isoprop;

  return at->begline;
}