Ejemplo n.º 1
0
Tile::Tile(std::string in) :
	img(""), sprite("none"), slowness(1,1),
	jumping(false), solid(true), shading(false)
{
	raw = in;
	std::vector<std::string> toks = split(raw,';');
	for (unsigned int i = 0; i < toks.size(); i++)
	{
		std::vector<std::string> kv = split(stripspaces(toks[i]),':',2);
		if (kv.size() != 2) continue;
		std::string key = kv[0], value = kv[1];
		if (key == "img") img = value;
		if (key == "sprite") sprite = value;
		if (key == "slowness"){
			std::vector<std::string> toks = split(value,',');
			if (toks.size() != 2) continue;
			slowness = vec2(toint(toks[0]),toint(toks[1]));
		}
		if (key == "jumping") jumping = tobool(value);
		if (key == "solid") solid = tobool(value);
		if (key == "shading") shading = tobool(value);
		if (startswith(key,"on_")) scripts[key] = value;
	}
	updateImage();
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
void
CPostEffectLoader::ParsePostEffectPass( TiXmlNode* xmlNode, const CPostEffectPtr& postEffect )
{
	CPostEffectPassPtr pass = new CPostEffectPass();
	string target = xmlNode->ToElement()->Attribute("target");
	bool clear = tobool(xmlNode->ToElement()->Attribute("clear"));

	DWORD vsID = POST_VS_ID | MakeGroupID(4) | SSI_BASE_VS_SYSTEM_ID;
	DWORD psID = atoi(xmlNode->ToElement()->Attribute("effectId"))|MakeGroupID(4)|SSI_BASE_PS_SYSTEM_ID;
	
	if ( NULL != CGpuProgramMgr::GetInst()->getGpuProgram(vsID) &&
		 NULL != CGpuProgramMgr::GetInst()->getGpuProgram(psID) )
	{
		SHADER_HANDLE shader_handle;
		shader_handle  = vsID;
		shader_handle |= psID;

		pass->SetEffect(shader_handle);
		pass->SetTargetNeedClear(clear);
		pass->SetTarget(this->ParseRenderTexture(target));

		// sources
		for (TiXmlNode* node = xmlNode->FirstChild(); node != NULL;
			node = node->NextSibling())
		{
			if (!node->ToElement())
				continue;
			string source = node->ToElement()->Attribute("name");
			pass->AddSource(this->ParseRenderTexture(source));
		}
		postEffect->AddPass(pass);
	}
}
Ejemplo n.º 3
0
/*
 * Save an array subscript - returns true if matching bracket found, false
 * if eof or newline was found.
 * (Returned string double null terminated)
 */
static bool
arraysub(char **strp)
{
	XString ws;
	char *wp, c;
	/* we are just past the initial [ */
	unsigned int depth = 1;

	Xinit(ws, wp, 32, ATEMP);

	do {
		c = getsc();
		Xcheck(ws, wp);
		*wp++ = c;
		if (c == '[')
			depth++;
		else if (c == ']')
			depth--;
	} while (depth > 0 && c && c != '\n');

	*wp++ = '\0';
	*strp = Xclose(ws, wp);

	return (tobool(depth == 0));
}
Ejemplo n.º 4
0
/*
 * define function. Returns 1 if function is being undefined (t == 0) and
 * function did not exist, returns 0 otherwise.
 */
int
define(const char *name, struct op *t)
{
	uint32_t nhash;
	struct tbl *tp;
	bool was_set = false;

	nhash = hash(name);

	if (t != NULL && !tobool(t->u.ksh_func)) {
		/* drop same-name aliases for POSIX functions */
		if ((tp = ktsearch(&aliases, name, nhash)))
			ktdelete(tp);
	}

	while (/* CONSTCOND */ 1) {
		tp = findfunc(name, nhash, true);
		/* because findfunc:create=true */
		mkssert(tp != NULL);

		if (tp->flag & ISSET)
			was_set = true;
		/*
		 * If this function is currently being executed, we zap
		 * this table entry so findfunc() won't see it
		 */
		if (tp->flag & FINUSE) {
			tp->name[0] = '\0';
			/* ensure it won't be found */
			tp->flag &= ~DEFINED;
			tp->flag |= FDELETE;
		} else
			break;
	}

	if (tp->flag & ALLOC) {
		tp->flag &= ~(ISSET|ALLOC);
		tfree(tp->val.t, tp->areap);
	}

	if (t == NULL) {
		/* undefine */
		ktdelete(tp);
		return (was_set ? 0 : 1);
	}

	tp->val.t = tcopy(t->left, tp->areap);
	tp->flag |= (ISSET|ALLOC);
	if (t->u.ksh_func)
		tp->flag |= FKSH;

	return (0);
}
Ejemplo n.º 5
0
/* set variable to string value */
int
setstr(struct tbl *vq, const char *s, int error_ok)
{
	char *salloc = NULL;
	bool no_ro_check = tobool(error_ok & 0x4);

	error_ok &= ~0x4;
	if ((vq->flag & RDONLY) && !no_ro_check) {
		warningf(true, "read-only: %s", vq->name);
		if (!error_ok)
			errorfxz(2);
		return (0);
	}
	if (!(vq->flag&INTEGER)) {
		/* string dest */
		if ((vq->flag&ALLOC)) {
#ifndef MKSH_SMALL
			/* debugging */
			if (s >= vq->val.s &&
			    s <= vq->val.s + strlen(vq->val.s)) {
				internal_errorf(
				    "setstr: %s=%s: assigning to self",
				    vq->name, s);
			}
#endif
			afree(vq->val.s, vq->areap);
		}
		vq->flag &= ~(ISSET|ALLOC);
		vq->type = 0;
		if (s && (vq->flag & (UCASEV_AL|LCASEV|LJUST|RJUST)))
			s = salloc = formatstr(vq, s);
		if ((vq->flag&EXPORT))
			exportprep(vq, s);
		else {
			strdupx(vq->val.s, s, vq->areap);
			vq->flag |= ALLOC;
		}
	} else {
		/* integer dest */
		if (!v_evaluate(vq, s, error_ok, true))
			return (0);
	}
	vq->flag |= ISSET;
	if ((vq->flag&SPECIAL))
		setspec(vq);
	afree(salloc, ATEMP);
	return (1);
}
Ejemplo n.º 6
0
static const unsigned char *
gmatch_cclass(const unsigned char *p, unsigned char sub)
{
	unsigned char c, d;
	bool notp, found = false;
	const unsigned char *orig_p = p;

	if ((notp = tobool(ISMAGIC(*p) && *++p == '!')))
		p++;
	do {
		c = *p++;
		if (ISMAGIC(c)) {
			c = *p++;
			if ((c & 0x80) && !ISMAGIC(c)) {
				/* extended pattern matching: *+?@! */
				c &= 0x7F;
				/* XXX the ( char isn't handled as part of [] */
				if (c == ' ')
					/* simile for @: plain (..) */
					c = '(' /*)*/;
			}
		}
		if (c == '\0')
			/* No closing ] - act as if the opening [ was quoted */
			return (sub == '[' ? orig_p : NULL);
		if (ISMAGIC(p[0]) && p[1] == '-' &&
		    (!ISMAGIC(p[2]) || p[3] != ']')) {
			/* MAGIC- */
			p += 2;
			d = *p++;
			if (ISMAGIC(d)) {
				d = *p++;
				if ((d & 0x80) && !ISMAGIC(d))
					d &= 0x7f;
			}
			/* POSIX says this is an invalid expression */
			if (c > d)
				return (NULL);
		} else
			d = c;
		if (c == sub || (c <= sub && sub <= d))
			found = true;
	} while (!(ISMAGIC(p[0]) && p[1] == ']'));

	return ((found != notp) ? p+2 : NULL);
}
Ejemplo n.º 7
0
static void
vwarningf(unsigned int flags, const char *fmt, va_list ap)
{
	if (fmt) {
		if (flags & VWARNINGF_INTERNAL)
			shf_fprintf(shl_out, Tf_sD_, "internal error");
		if (flags & VWARNINGF_ERRORPREFIX)
			error_prefix(tobool(flags & VWARNINGF_FILELINE));
		if ((flags & VWARNINGF_BUILTIN) &&
		    /* not set when main() calls parse_args() */
		    builtin_argv0 && builtin_argv0 != kshname)
			shf_fprintf(shl_out, Tf_sD_, builtin_argv0);
		shf_vfprintf(shl_out, fmt, ap);
		shf_putchar('\n', shl_out);
	}
	shf_flush(shl_out);
}
Ejemplo n.º 8
0
static int
call_builtin(struct tbl *tp, const char **wp, const char *where, bool resetspec)
{
	int rv;

	if (!tp)
		internal_errorf("%s: %s", where, wp[0]);
	builtin_argv0 = wp[0];
	builtin_spec = tobool(!resetspec &&
	    /*XXX odd use of KEEPASN */
	    ((tp->flag & SPEC_BI) || (Flag(FPOSIX) && (tp->flag & KEEPASN))));
	shf_reopen(1, SHF_WR, shl_stdout);
	shl_stdout_ok = true;
	ksh_getopt_reset(&builtin_opt, GF_ERROR);
	rv = (*tp->val.f)(wp);
	shf_flush(shl_stdout);
	shl_stdout_ok = false;
	builtin_argv0 = NULL;
	builtin_spec = false;
	return (rv);
}
Ejemplo n.º 9
0
/*
 * run the commands from the input source, returning status.
 */
int
shell(Source * volatile s, volatile int level)
{
	struct op *t;
	volatile bool wastty = tobool(s->flags & SF_TTY);
	volatile uint8_t attempts = 13;
	volatile bool interactive = (level == 0) && Flag(FTALKING);
	volatile bool sfirst = true;
	Source *volatile old_source = source;
	int i;

	newenv(level == 2 ? E_EVAL : E_PARSE);
	if (interactive)
		really_exit = false;
	switch ((i = kshsetjmp(e->jbuf))) {
	case 0:
		break;
	case LBREAK:
	case LCONTIN:
		if (level != 2) {
			source = old_source;
			quitenv(NULL);
			internal_errorf(Tf_cant_s, Tshell,
			    i == LBREAK ? Tbreak : Tcontinue);
			/* NOTREACHED */
		}
		/* assert: interactive == false */
		/* FALLTHROUGH */
	case LINTR:
		/* we get here if SIGINT not caught or ignored */
	case LERROR:
	case LSHELL:
		if (interactive) {
			if (i == LINTR)
				shellf("\n");
			/*
			 * Reset any eof that was read as part of a
			 * multiline command.
			 */
			if (Flag(FIGNOREEOF) && s->type == SEOF && wastty)
				s->type = SSTDIN;
			/*
			 * Used by exit command to get back to
			 * top level shell. Kind of strange since
			 * interactive is set if we are reading from
			 * a tty, but to have stopped jobs, one only
			 * needs FMONITOR set (not FTALKING/SF_TTY)...
			 */
			/* toss any input we have so far */
			yyrecursive_pop(true);
			s->start = s->str = null;
			retrace_info = NULL;
			herep = heres;
			break;
		}
		/* FALLTHROUGH */
	case LEXIT:
	case LLEAVE:
	case LRETURN:
		source = old_source;
		quitenv(NULL);
		/* keep on going */
		unwind(i);
		/* NOTREACHED */
	default:
		source = old_source;
		quitenv(NULL);
		internal_errorf(Tunexpected_type, Tunwind, Tshell, i);
		/* NOTREACHED */
	}
	while (/* CONSTCOND */ 1) {
		if (trap)
			runtraps(0);

		if (s->next == NULL) {
			if (Flag(FVERBOSE))
				s->flags |= SF_ECHO;
			else
				s->flags &= ~SF_ECHO;
		}
		if (interactive) {
			j_notify();
			set_prompt(PS1, s);
		}
		t = compile(s, sfirst, true);
		if (interactive)
			histsave(&s->line, NULL, HIST_FLUSH, true);
		sfirst = false;
		if (!t)
			goto source_no_tree;
		if (t->type == TEOF) {
			if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
				shellf("Use 'exit' to leave mksh\n");
				s->type = SSTDIN;
			} else if (wastty && !really_exit &&
			    j_stopped_running()) {
				really_exit = true;
				s->type = SSTDIN;
			} else {
				/*
				 * this for POSIX which says EXIT traps
				 * shall be taken in the environment
				 * immediately after the last command
				 * executed.
				 */
				if (level == 0)
					unwind(LEXIT);
				break;
			}
		} else if ((s->flags & SF_MAYEXEC) && t->type == TCOM)
			t->u.evalflags |= DOTCOMEXEC;
		if (!Flag(FNOEXEC) || (s->flags & SF_TTY))
			exstat = execute(t, 0, NULL) & 0xFF;

		if (t->type != TEOF && interactive && really_exit)
			really_exit = false;

 source_no_tree:
		reclaim();
	}
	quitenv(NULL);
	source = old_source;
	return (exstat & 0xFF);
}
Ejemplo n.º 10
0
FILE *fopenC( char  *filename, 
              bool  *appended )
/*--------------------------------------------------*/
/* Open file to write data extern. The              */
/* macro 'fmake' must be available.                 */
/*--------------------------------------------------*/
{
   bool     append;
   bool     fileexist;
   fint     dfault;
   fint     n;
   fint     nitems;
   fint     agreed;
   FILE     *fp = NULL;


   *appended = NO;
   dfault = HIDDEN;
   do 
   {
      fchar  Filename;
      fmake( Filename, FILENAMELEN );      
      
      n = usertext_c( Filename,
                      &dfault,
                      KEY_FILENAME,
                      MES_FILENAME );
      if (n == 0) 
         return( NULL );

      /* Copy string and add a nul */
      filename[  sprintf( filename, "%.*s", nelc_c(Filename), Filename.a )  ]; 
     
      fp = fopen( filename, "r" );
      fileexist = (fp != NULL);
      
      if (fileexist) 
      {                                   /* The file exists */
         nitems = 1;
         append = toflog(YES);            /* Default is appending to existing file */
         dfault = REQUEST;
         n = userlog_c( &append,
                        &nitems,
                        &dfault,
                        KEY_APPEND,
                        MES_APPEND );
         append = tobool( append );
         fclose( fp );
         cancel_c( KEY_APPEND );
      }
      else
         append = NO;
         
      if (fileexist && !append) 
      {
          cancel_c( KEY_FILENAME );
          agreed = NO;
      }
      else 
      {
         fp = fopen(filename, "a");      /* Open for appending */
         agreed = (fp != NULL);
         if (!agreed) 
            reject_c( KEY_FILENAME, tofchar("Cannot open, try another!") );
      }
      dfault = REQUEST;                  /* If something went wrong, unhide keywords */
   } 
   while (!agreed);
   
   *appended = append;
   return( fp );
}
Ejemplo n.º 11
0
fint	ftsd_mkhead_c( fchar	set     ,	/* name of set */
                       fint8	*cwblo  ,	/* lower cw of subset frame */
                       fint8	*cwbhi  ,	/* upper cw of subset frame */
                       bool	*blocked ,	/* blocked tape ? */
                       fchar	header  ,	/* the fits header */
                       fint	*maxrec )	/* maximum number of records */
{
   char		bval[FITSSTRINGLEN+1];		/* buffer */
   char		record[FITSRECORDLEN+1];	/* buffer for one FITS record */
   double	dval;				/* double precision dummy */
   fchar	cval;				/* f character */
   fint8		cwfhi;				/* c.w. upper frame */
   fint8		cwflo;				/* c.w. lower frame */
   fint8		*gbhi;				/* grids upper box */
   fint8		*gblo;				/* grids lower box */
   fint 	gerror = 0;			/* GDS error return code */
   fint8		*gfhi;				/* grids upper frame */
   fint8		*gflo;				/* grids lower frame */
   fint8		level = 0;			/* level in set */
   fint		naxis;				/* number of axes */
   fint		*perm;				/* axis permutation */
   fint		r = 0;				/* return value */
   fint		setdim;				/* dimension of set */
   fint8		subset;				/* subset level */
   fint		subdim;				/* dimension of subset */
   int		inhead = 0;			/* number of characters */
   int		n;				/* counter */
   int		nd;				/* number of axis descriptors */
   int		ni;				/* inside subset counter */
   int		no;				/* outside subset counter */

   cval.a = bval;				/* address */
   cval.l = FITSSTRINGLEN;			/* length */
   bval[FITSSTRINGLEN] = 0;			/* trailing zero byte */
   if (!tobool(gds_exist_c( set, &gerror ))) {	/* set does not exist */
      return( -1 );				/* code: set doesn not exist */
   }
   setdim = gdsc_ndims_c( set, &level );	/* dimension of set */
						/* get subset level */
   subset = gdsc_substruct_c( set, cwblo, cwbhi, &gerror );
   subdim = gdsc_ndims_c( set, &subset );	/* dimensions of subset */
						/* get frame of set */
   gdsc_range_c( set, &level, &cwflo, &cwfhi, &gerror );
   gbhi = calloc( sizeof( fint ), setdim );	/* allocate memory */
   if (gbhi == NULL) {				/* allocation problems */
      return( -2 );				/* code: allocation error */
   }
   gblo = calloc( sizeof( fint ), setdim );	/* allocate memory */
   if (gblo == NULL) {				/* allocation problems */
      free( gbhi );				/* deallocate */
      return( -2 );				/* code: allocation error */
   }
   gfhi = calloc( sizeof( fint ), setdim );	/* allocate memory */
   if (gfhi == NULL) {				/* allocation problems */
      free( gbhi );				/* deallocate */
      free( gblo );				/* deallocate */
      return( -2 );				/* code: allocation error */
   }
   gflo = calloc( sizeof( fint ), setdim );	/* allocate memory */
   if (gflo == NULL) {				/* allocation problems */
      free( gbhi );				/* deallocate */
      free( gblo );				/* deallocate */
      free( gfhi );				/* deallocate */
      return( -2 );				/* code: allocation error */
   }
   perm = calloc( sizeof( fint ), setdim );	/* allocate memory */
   if (perm == NULL) {				/* allocation problems */
      free( gbhi );				/* deallocate */
      free( gblo );				/* deallocate */
      free( gfhi );				/* deallocate */
      free( gflo );				/* deallocate */
      return( -2 );				/* code: allocation error */
   }
						/* loop to get axis order */
   for (ni = 0, no = subdim, n = 0; n < setdim; n++) {
      fint	axnum = n + 1;			/* axis sequence number */
      fint	grid;
      fint	idx;				/* axis index */

      grid = gdsc_grid_c( set, &axnum, &subset, &gerror );
      if (gerror) {				/* inside subset */
         idx = ni++;
         gerror = 0;
         gbhi[idx] = gdsc_grid_c( set, &axnum, cwbhi, &gerror );
         gblo[idx] = gdsc_grid_c( set, &axnum, cwblo, &gerror );
      } else {					/* outside subset */
         idx = no++;
         gbhi[idx] = gblo[idx] = grid;
      }
      perm[n] = idx;				/* set permutation */
      gfhi[idx] = gdsc_grid_c( set, &axnum, &cwfhi, &gerror );
      gflo[idx] = gdsc_grid_c( set, &axnum, &cwflo, &gerror );
   }
   
   FITS_INT_DSC( record, "NAXIS", (int) setdim, " / NUMBER OF AXES" );
   if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   for (n = 0; n < setdim; n++) {
      char	dsco[FITSNAMELEN+1];

      (void) sprintf( dsco, "NAXIS%d", n + 1 );
      naxis = gbhi[n] - gblo[n] + 1;
      FITS_INT_DSC( record, dsco, (int) naxis, " / LENGTH OF AXIS" );
      if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   }
   FITS_LOG_DSC( record, "BLOCKED", *blocked, " / TAPE MAY BE BLOCKED" );
   if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   for (nd = 1, n = 0; nd; n++) {
      char	dsci[FITSNAMELEN+1];
      char	dsco[FITSNAMELEN+1];
      int	axnumi;
      int	axnumo = n + 1;

      nd = 0;
      if (n < setdim) {
         axnumi = perm[n] + 1;
      } else {
         axnumi = axnumo;
      }
      if (n < setdim) {
         nd += 1;
      }
      (void) sprintf( dsci, "CDELT%d", axnumi );
      (void) sprintf( dsco, "CDELT%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / PRIMARY PIXEL SEPARATION" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "CROTA%d", axnumi );
      (void) sprintf( dsco, "CROTA%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / PRIMARY ROTATION OF AXIS" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "CRPIX%d", axnumi );
      (void) sprintf( dsco, "CRPIX%d", axnumo );
      if (n < setdim) {
         gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      } else {
         fint	axnumber = axnumi;

         dval = gdsc_origin_c( set, &axnumber, &gerror );
      }
      if (!gerror) {
         nd += 1;
         if (n < setdim) {
            dval += ( gflo[n] - gblo[n] );
         }
         FITS_DBLE_DSC( record, dsco, dval, " / PRIMARY REFERENCE PIXEL" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "CRVAL%d", axnumi );
      (void) sprintf( dsco, "CRVAL%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / PRIMARY REFERENCE VALUE" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "CTYPE%d", axnumi );
      (void) sprintf( dsco, "CTYPE%d", axnumo );
      gdsd_rchar_c( set, tofchar( dsci ), &level, cval, &gerror );
      if (!gerror) 
      {
         /* Number of programs follow the AIPS convention i.e the   */
         /* axis names must be filled up to 4 positions with dashes */
         /* followed by a dash and the projection.                  */
         /* Only RA and DEC have to be checked.                     */

         nd += 1;
         if (strncmp(bval,"RA",2)==0 || strncmp(bval,"DEC",3)==0)
         {
            char  buf[FITSSTRINGLEN+1];
            int   i = 0, j = 0;            
            while (i < nelc_c(cval) )
            {
               if (bval[i] != '-')
               {
                  buf[j++] = bval[i++];
               }
               else
               {
                  while (j < 5)
                     buf[j++] = '-';
                  while (bval[i] == '-')
                     i++;
               }
            }
            buf[j] = '\0';
            FITS_CHAR_DSC( record, dsco, buf, " / PRIMARY AXIS NAME" );
         }
         else
         {
            FITS_CHAR_DSC( record, dsco, bval, " / PRIMARY AXIS NAME" );
         }

         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "CUNIT%d", axnumi );
      (void) sprintf( dsco, "CUNIT%d", axnumo );
      gdsd_rchar_c( set, tofchar( dsci ), &level, cval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_CHAR_DSC( record, dsco, bval, " / PRIMARY AXIS UNITS" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DDELT%d", axnumi );
      (void) sprintf( dsco, "DDELT%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / SECONDARY PIXEL SEPARATION" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DROTA%d", axnumi );
      (void) sprintf( dsco, "DROTA%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / SECONDARY ROTATION OF AXIS" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DRPIX%d", axnumi );
      (void) sprintf( dsco, "DRPIX%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         if (n < setdim) {
            dval += ( gflo[n] - gblo[n] );
         }
         FITS_DBLE_DSC( record, dsco, dval, " / SECONDARY REFERENCE PIXEL" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DRVAL%d", axnumi );
      (void) sprintf( dsco, "DRVAL%d", axnumo );
      gdsd_rdble_c( set, tofchar( dsci ), &level, &dval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_DBLE_DSC( record, dsco, dval, " / SECONDARY REFERENCE VALUE" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DTYPE%d", axnumi );
      (void) sprintf( dsco, "DTYPE%d", axnumo );
      gdsd_rchar_c( set, tofchar( dsci ), &level, cval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_CHAR_DSC( record, dsco, bval, " / SECONDARY AXIS NAME" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
      (void) sprintf( dsci, "DUNIT%d", axnumi );
      (void) sprintf( dsco, "DUNIT%d", axnumo );
      gdsd_rchar_c( set, tofchar( dsci ), &level, cval, &gerror );
      if (!gerror) {
         nd += 1;
         FITS_CHAR_DSC( record, dsco, bval, " / SECONDARY AXIS UNITS" );
         if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
      }
      gerror = 0;
   }
   gdsd_rdble_c( set, tofchar( "EPOCH" ), &level, &dval, &gerror );
   if (!gerror) {
      FITS_DBLE_DSC( record, "EPOCH", dval, " / EPOCH" );
      if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   }
   gerror = 0;
   gdsd_rdble_c( set, tofchar( "FREQ0" ), &level, &dval, &gerror );
   if (!gerror) {
      FITS_DBLE_DSC( record, "FREQ0", dval, " / REST FREQUENCY" );
      if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   }
   gerror = 0;
   gdsd_rchar_c( set, tofchar( "INSTRUME" ), &level, cval, &gerror );
   if (!gerror) {
      FITS_CHAR_DSC( record, "INSTRUME", bval, " / INSTRUMENT" );
      if (r++ < *maxrec) ADD_RECORD( record, header, inhead );
   }
   free( gbhi );				/* deallocate */
   free( gblo );				/* deallocate */
   free( gfhi );				/* deallocate */
   free( gflo );				/* deallocate */
   free( perm );				/* deallocate */
   if (r > *maxrec) r = -3;			/* header too small */
   return( r );					/* return to caller */
}
Ejemplo n.º 12
0
static void delete_set( fchar Setin )
/*------------------------------------------------------------*/
/* PURPOSE: Delete set, but ask for confirmation first.       */
/*------------------------------------------------------------*/
{
   bool  ok;                  /* Confirm the deleting */
   char  messbuf[BIGSTORE];
   fint  nitems;
   fint  dfault;
   fint  r;
   int   slen = nelc_c(Setin);



   r = 0;
   if ( !(tobool(gds_exist_c(Setin, &r))) )
   {
      fchar  Errstr;
      fmake( Errstr, BIGSTORE );
      if (r < 0)
      {
         gds_errstr_c( Errstr, &r );
         anyoutf( 1, "Set [%.*s] is not a valid GIPSY set! (%.*s)",
                  slen,  Setin.a,
                  nelc_c(Errstr), Errstr.a );
         sprintf( messbuf, "Invalid GIPSY set, delete anyway?   Y/[N]" );
      }
      else
      {
         anyoutf( 1, "Set [%.*s] does not exist!",
                  slen,  Setin.a );
         return;
      }
   }
   else
   /*--------------------------------------------------*/
   /* How many characters are left to display the file */
   /* name in the process area?                        */
   /*--------------------------------------------------*/
   {
      int   messlen;         /* Length of message without set name */

      messlen = strlen("Ok to delete  ?       Y/[N]");
      if (slen+messlen+1 < PROCESS_AREA_LEN)
         sprintf( messbuf, "Ok to delete %.*s ?       Y/[N]",
                  slen, Setin.a );
      else
         sprintf( messbuf, "Ok to delete %.*s...?       Y/[N]",
                  PROCESS_AREA_LEN-messlen-5, Setin.a );
   }

   /* Ask confirmation */

   ok     = toflog( NO );
   dfault = REQUEST;
   nitems = 1;
   r      = userlog_c( &ok, &nitems, &dfault,
                       KEY_OK, tofchar(messbuf) );
   ok = tobool( ok );

   r = 0;
   if (ok)
   {
      gds_delete_c( Setin, &r );
      if (r < 0)
      {
         fchar   Errstr;
         fmake( Errstr, BIGSTORE );
         gds_errstr_c( Errstr, &r );
         anyoutf( 1, "Set [%.*s] could not be deleted! (%.*s)",
                  slen,
                  Setin.a,
                  nelc_c(Errstr),
                  Errstr.a );
      }
   }
   cancel_c( KEY_OK );
}
Ejemplo n.º 13
0
/*
 * Parse command line and set command arguments. Returns the index of
 * non-option arguments, -1 if there is an error.
 */
int
parse_args(const char **argv,
    /* OF_CMDLINE or OF_SET */
    int what,
    bool *setargsp)
{
	static const char cmd_opts[] =
#define SHFLAGS_NOT_SET
#define SHFLAGS_OPTCS
#include "sh_flags.gen"
#undef SHFLAGS_NOT_SET
	    ;
	static const char set_opts[] =
#define SHFLAGS_NOT_CMD
#define SHFLAGS_OPTCS
#include "sh_flags.gen"
#undef SHFLAGS_NOT_CMD
	    ;
	bool set;
	const char *opts;
	const char *array = NULL;
	Getopt go;
	size_t i;
	int optc, arrayset = 0;
	bool sortargs = false;
	bool fcompatseen = false;

	if (what == OF_CMDLINE) {
		const char *p = argv[0], *q;
		/*
		 * Set FLOGIN before parsing options so user can clear
		 * flag using +l.
		 */
		if (*p != '-')
			for (q = p; *q; )
				if (*q++ == '/')
					p = q;
		Flag(FLOGIN) = (*p == '-');
		opts = cmd_opts;
	} else if (what == OF_FIRSTTIME) {
		opts = cmd_opts;
	} else
		opts = set_opts;
	ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
	while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
		set = tobool(!(go.info & GI_PLUS));
		switch (optc) {
		case 'A':
			if (what == OF_FIRSTTIME)
				break;
			arrayset = set ? 1 : -1;
			array = go.optarg;
			break;

		case 'o':
			if (what == OF_FIRSTTIME)
				break;
			if (go.optarg == NULL) {
				/*
				 * lone -o: print options
				 *
				 * Note that on the command line, -o requires
				 * an option (ie, can't get here if what is
				 * OF_CMDLINE).
				 */
				printoptions(set);
				break;
			}
			i = option(go.optarg);
			if ((i == FPOSIX || i == FSH) && set && !fcompatseen) {
				/*
				 * If running 'set -o posix' or
				 * 'set -o sh', turn off the other;
				 * if running 'set -o posix -o sh'
				 * allow both to be set though.
				 */
				Flag(FPOSIX) = 0;
				Flag(FSH) = 0;
				fcompatseen = true;
			}
			if ((i != (size_t)-1) && (set ? 1U : 0U) == Flag(i))
				/*
				 * Don't check the context if the flag
				 * isn't changing - makes "set -o interactive"
				 * work if you're already interactive. Needed
				 * if the output of "set +o" is to be used.
				 */
				;
			else if ((i != (size_t)-1) && (OFF(i) & what))
				change_flag((enum sh_flag)i, what, set);
			else {
				bi_errorf("%s: %s", go.optarg, "bad option");
				return (-1);
			}
			break;

#ifdef KSH_CHVT_FLAG
		case 'T':
			if (what != OF_FIRSTTIME)
				break;
#ifndef KSH_CHVT_CODE
			errorf("no TIOCSCTTY ioctl");
#else
			change_flag(FTALKING, OF_CMDLINE, true);
			chvt(&go);
			break;
#endif
#endif

		case '?':
			return (-1);

		default:
			if (what == OF_FIRSTTIME)
				break;
			/* -s: sort positional params (AT&T ksh stupidity) */
			if (what == OF_SET && optc == 's') {
				sortargs = true;
				break;
			}
			for (i = 0; i < NELEM(options); i++)
				if (optc == OFC(i) &&
				    (what & OFF(i))) {
					change_flag((enum sh_flag)i, what, set);
					break;
				}
			if (i == NELEM(options))
				internal_errorf("parse_args: '%c'", optc);
		}
	}
	if (!(go.info & GI_MINUSMINUS) && argv[go.optind] &&
	    (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
	    argv[go.optind][1] == '\0') {
		/* lone - clears -v and -x flags */
		if (argv[go.optind][0] == '-') {
			Flag(FVERBOSE) = 0;
			change_xtrace(0, false);
		}
		/* set skips lone - or + option */
		go.optind++;
	}
	if (setargsp)
		/* -- means set $#/$* even if there are no arguments */
		*setargsp = !arrayset && ((go.info & GI_MINUSMINUS) ||
		    argv[go.optind]);

	if (arrayset) {
		const char *ccp = NULL;

		if (*array)
			ccp = skip_varname(array, false);
		if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {
			bi_errorf("%s: %s", array, "is not an identifier");
			return (-1);
		}
	}
	if (sortargs) {
		for (i = go.optind; argv[i]; i++)
			;
		qsort(&argv[go.optind], i - go.optind, sizeof(void *),
		    xstrcmp);
	}
	if (arrayset)
		go.optind += set_array(array, tobool(arrayset > 0),
		    argv + go.optind);

	return (go.optind);
}
Ejemplo n.º 14
0
int
c_cd(const char **wp)
{
	int optc, rv, phys_path;
	bool physical = tobool(Flag(FPHYSICAL));
	/* was a node from cdpath added in? */
	int cdnode;
	/* show where we went?, error for $PWD */
	bool printpath = false, eflag = false;
	struct tbl *pwd_s, *oldpwd_s;
	XString xs;
	char *dir, *allocd = NULL, *tryp, *pwd, *cdpath;

	while ((optc = ksh_getopt(wp, &builtin_opt, "eLP")) != -1)
		switch (optc) {
		case 'e':
			eflag = true;
			break;
		case 'L':
			physical = false;
			break;
		case 'P':
			physical = true;
			break;
		case '?':
			return (2);
		}
	wp += builtin_opt.optind;

	if (Flag(FRESTRICTED)) {
		bi_errorf("restricted shell - can't cd");
		return (2);
	}

	pwd_s = global("PWD");
	oldpwd_s = global("OLDPWD");

	if (!wp[0]) {
		/* No arguments - go home */
		if ((dir = str_val(global("HOME"))) == null) {
			bi_errorf("no home directory (HOME not set)");
			return (2);
		}
	} else if (!wp[1]) {
		/* One argument: - or dir */
		strdupx(allocd, wp[0], ATEMP);
		if (ksh_isdash((dir = allocd))) {
			afree(allocd, ATEMP);
			allocd = NULL;
			dir = str_val(oldpwd_s);
			if (dir == null) {
				bi_errorf("no OLDPWD");
				return (2);
			}
			printpath = true;
		}
	} else if (!wp[2]) {
		/* Two arguments - substitute arg1 in PWD for arg2 */
		size_t ilen, olen, nlen, elen;
		char *cp;

		if (!current_wd[0]) {
			bi_errorf("can't determine current directory");
			return (2);
		}
		/*
		 * substitute arg1 for arg2 in current path.
		 * if the first substitution fails because the cd fails
		 * we could try to find another substitution. For now
		 * we don't
		 */
		if ((cp = strstr(current_wd, wp[0])) == NULL) {
			bi_errorf("bad substitution");
			return (2);
		}
		/*-
		 * ilen = part of current_wd before wp[0]
		 * elen = part of current_wd after wp[0]
		 * because current_wd and wp[1] need to be in memory at the
		 * same time beforehand the addition can stay unchecked
		 */
		ilen = cp - current_wd;
		olen = strlen(wp[0]);
		nlen = strlen(wp[1]);
		elen = strlen(current_wd + ilen + olen) + 1;
		dir = allocd = alloc(ilen + nlen + elen, ATEMP);
		memcpy(dir, current_wd, ilen);
		memcpy(dir + ilen, wp[1], nlen);
		memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
		printpath = true;
	} else {
		bi_errorf("too many arguments");
		return (2);
	}

#ifdef MKSH__NO_PATH_MAX
	/* only a first guess; make_path will enlarge xs if necessary */
	XinitN(xs, 1024, ATEMP);
#else
	XinitN(xs, PATH_MAX, ATEMP);
#endif

	cdpath = str_val(global("CDPATH"));
	do {
		cdnode = make_path(current_wd, dir, &cdpath, &xs, &phys_path);
		if (physical)
			rv = chdir(tryp = Xstring(xs, xp) + phys_path);
		else {
			simplify_path(Xstring(xs, xp));
			rv = chdir(tryp = Xstring(xs, xp));
		}
	} while (rv < 0 && cdpath != NULL);

	if (rv < 0) {
		if (cdnode)
			bi_errorf("%s: %s", dir, "bad directory");
		else
			bi_errorf("%s: %s", tryp, cstrerror(errno));
		afree(allocd, ATEMP);
		Xfree(xs, xp);
		return (2);
	}

	rv = 0;

	/* allocd (above) => dir, which is no longer used */
	afree(allocd, ATEMP);
	allocd = NULL;

	/* Clear out tracked aliases with relative paths */
	flushcom(false);

	/*
	 * Set OLDPWD (note: unsetting OLDPWD does not disable this
	 * setting in AT&T ksh)
	 */
	if (current_wd[0])
		/* Ignore failure (happens if readonly or integer) */
		setstr(oldpwd_s, current_wd, KSH_RETURN_ERROR);

	if (!mksh_abspath(Xstring(xs, xp))) {
		pwd = NULL;
	} else if (!physical) {
		goto norealpath_PWD;
	} else if ((pwd = allocd = do_realpath(Xstring(xs, xp))) == NULL) {
		if (eflag)
			rv = 1;
 norealpath_PWD:
		pwd = Xstring(xs, xp);
	}

	/* Set PWD */
	if (pwd) {
		char *ptmp = pwd;

		set_current_wd(ptmp);
		/* Ignore failure (happens if readonly or integer) */
		setstr(pwd_s, ptmp, KSH_RETURN_ERROR);
	} else {
		set_current_wd(null);
		pwd = Xstring(xs, xp);
		/* XXX unset $PWD? */
		if (eflag)
			rv = 1;
	}
	if (printpath || cdnode)
		shprintf("%s\n", pwd);

	afree(allocd, ATEMP);
	Xfree(xs, xp);
	return (rv);
}
Ejemplo n.º 15
0
/*
 * print a command tree
 */
static void
ptree(struct op *t, int indent, struct shf *shf)
{
	const char **w;
	struct ioword **ioact;
	struct op *t1;
	int i;

 Chain:
	if (t == NULL)
		return;
	switch (t->type) {
	case TCOM:
		prevent_semicolon = false;
		/*
		 * special-case 'var=<<EOF' (rough; see
		 * exec.c:execute() for full code)
		 */
		if (
		    /* we have zero arguments, i.e. no programme to run */
		    t->args[0] == NULL &&
		    /* we have exactly one variable assignment */
		    t->vars[0] != NULL && t->vars[1] == NULL &&
		    /* we have exactly one I/O redirection */
		    t->ioact != NULL && t->ioact[0] != NULL &&
		    t->ioact[1] == NULL &&
		    /* of type "here document" (or "here string") */
		    (t->ioact[0]->flag & IOTYPE) == IOHERE) {
			fptreef(shf, indent, "%S", t->vars[0]);
			break;
		}

		if (t->vars) {
			w = (const char **)t->vars;
			while (*w)
				fptreef(shf, indent, "%S ", *w++);
		} else
			shf_puts("#no-vars# ", shf);
		if (t->args) {
			w = t->args;
			while (*w)
				fptreef(shf, indent, "%S ", *w++);
		} else
			shf_puts("#no-args# ", shf);
		break;
	case TEXEC:
		t = t->left;
		goto Chain;
	case TPAREN:
		fptreef(shf, indent + 2, "( %T) ", t->left);
		break;
	case TPIPE:
		fptreef(shf, indent, "%T| ", t->left);
		t = t->right;
		goto Chain;
	case TLIST:
		fptreef(shf, indent, "%T%;", t->left);
		t = t->right;
		goto Chain;
	case TOR:
	case TAND:
		fptreef(shf, indent, "%T%s %T",
		    t->left, (t->type == TOR) ? "||" : "&&", t->right);
		break;
	case TBANG:
		shf_puts("! ", shf);
		prevent_semicolon = false;
		t = t->right;
		goto Chain;
	case TDBRACKET:
		w = t->args;
		shf_puts("[[", shf);
		while (*w)
			fptreef(shf, indent, " %S", *w++);
		shf_puts(" ]] ", shf);
		break;
	case TSELECT:
	case TFOR:
		fptreef(shf, indent, "%s %s ",
		    (t->type == TFOR) ? "for" : Tselect, t->str);
		if (t->vars != NULL) {
			shf_puts("in ", shf);
			w = (const char **)t->vars;
			while (*w)
				fptreef(shf, indent, "%S ", *w++);
			fptreef(shf, indent, "%;");
		}
		fptreef(shf, indent + INDENT, "do%N%T", t->left);
		fptreef(shf, indent, "%;done ");
		break;
	case TCASE:
		fptreef(shf, indent, "case %S in", t->str);
		for (t1 = t->left; t1 != NULL; t1 = t1->right) {
			fptreef(shf, indent, "%N(");
			w = (const char **)t1->vars;
			while (*w) {
				fptreef(shf, indent, "%S%c", *w,
				    (w[1] != NULL) ? '|' : ')');
				++w;
			}
			fptreef(shf, indent + INDENT, "%N%T%N;%c", t1->left,
			    t1->u.charflag);
		}
		fptreef(shf, indent, "%Nesac ");
		break;
#ifdef DEBUG
	case TELIF:
		internal_errorf("TELIF in tree.c:ptree() unexpected");
		/* FALLTHROUGH */
#endif
	case TIF:
		i = 2;
		t1 = t;
		goto process_TIF;
		do {
			t1 = t1->right;
			i = 0;
			fptreef(shf, indent, "%;");
 process_TIF:
			/* 5 == strlen("elif ") */
			fptreef(shf, indent + 5 - i, Telif_pT + i, t1->left);
			t1 = t1->right;
			if (t1->left != NULL) {
				fptreef(shf, indent, "%;");
				fptreef(shf, indent + INDENT, "%s%N%T",
				    "then", t1->left);
			}
		} while (t1->right && t1->right->type == TELIF);
		if (t1->right != NULL) {
			fptreef(shf, indent, "%;");
			fptreef(shf, indent + INDENT, "%s%N%T",
			    "else", t1->right);
		}
		fptreef(shf, indent, "%;fi ");
		break;
	case TWHILE:
	case TUNTIL:
		/* 6 == strlen("while "/"until ") */
		fptreef(shf, indent + 6, "%s %T",
		    (t->type == TWHILE) ? "while" : "until",
		    t->left);
		fptreef(shf, indent, "%;");
		fptreef(shf, indent + INDENT, "do%N%T", t->right);
		fptreef(shf, indent, "%;done ");
		break;
	case TBRACE:
		fptreef(shf, indent + INDENT, "{%N%T", t->left);
		fptreef(shf, indent, "%;} ");
		break;
	case TCOPROC:
		fptreef(shf, indent, "%T|& ", t->left);
		prevent_semicolon = true;
		break;
	case TASYNC:
		fptreef(shf, indent, "%T& ", t->left);
		prevent_semicolon = true;
		break;
	case TFUNCT:
		fpFUNCTf(shf, indent, tobool(t->u.ksh_func), t->str, t->left);
		break;
	case TTIME:
		fptreef(shf, indent, "%s %T", "time", t->left);
		break;
	default:
		shf_puts("<botch>", shf);
		prevent_semicolon = false;
		break;
	}
	if ((ioact = t->ioact) != NULL) {
		bool need_nl = false;

		while (*ioact != NULL)
			pioact(shf, *ioact++);
		/* Print here documents after everything else... */
		ioact = t->ioact;
		while (*ioact != NULL) {
			struct ioword *iop = *ioact++;

			/* heredoc is NULL when tracing (set -x) */
			if ((iop->flag & (IOTYPE | IOHERESTR)) == IOHERE &&
			    iop->heredoc) {
				shf_putc('\n', shf);
				shf_puts(iop->heredoc, shf);
				fptreef(shf, indent, "%s",
				    iop->flag & IONDELIM ? "<<" :
				    evalstr(iop->delim, 0));
				need_nl = true;
			}
		}
		/*
		 * Last delimiter must be followed by a newline (this
		 * often leads to an extra blank line, but it's not
		 * worth worrying about)
		 */
		if (need_nl) {
			shf_putc('\n', shf);
			prevent_semicolon = true;
		}
	}
}
Ejemplo n.º 16
0
void initplot( void )
/*------------------------------------------------------------------------------
 * Description: Initialize plot software. Set viewport and output dimensions.
 *              If output device is a printer, ask user for line width.
 *------------------------------------------------------------------------------
 */
{
   static fint    Funit;                  /* Ignored by 'pgbeg', use 0 */
   static fchar   Ffile;                  /* Device specification */
   static fint    Fnxysub[2];             /* Number of subdivisions */
   static float   width;                  /* Width of output on paper */
   static float   aspect;                 /* Aspect ratio of output on paper */
   static float   uservals[2];            /* Array version of above */
   static fint    Fnumitems;              /* Use in userxxx routines */
   static fint    Fdfault;                /* Use in userxxx routines */
   static fint    Fr1;                    /* Return value or level */
   static fint    len;                    /* Length of a string */
   static fint    Flinewidth;             /* Width of lines on output device */
   static fchar   devtype;                /* Device specified in 'pgbeg' */
   static fint    Ferrlev;
   static fint    Foff;



   Funit = 0;                             /* Ignored by 'pgbeg' */
   fmake( Ffile, 10 );
   Ffile = tofchar( "?" );                /* 'pgbeg' will prompt the user
                                             to supply a string. */
   Fnxysub[0] = 1;                        /* Default no subdivisions in plot */
   Fnxysub[1] = 1;
   Fnumitems  = 2;
   Fdfault    = HIDDEN;
   Fr1 = userint_c( Fnxysub,
                    &Fnumitems,
                    &Fdfault,
                    KEY_SUBDIV,
                    MES_SUBDIV );


   /* Set window and viewport */
   Fr1 = pgbeg_c( &Funit, Ffile, &Fnxysub[0], &Fnxysub[1] );
   if (Fr1 != 1) {
      Ferrlev = 4;
      error_c( &Ferrlev, tofchar("Cannot open output device") );
   }


   /* No NEXTPAGE= keyword */
   Foff = tobool( 0 );
   (void) pgask_c( &Foff );

   /* Change size of the view surface to a specified width */
   /* and aspect ratio (=height/width) */

   Fnumitems = 2;
   Fdfault = HIDDEN;
   uservals[0] = 0.0;
   uservals[1] = 1.0;
   Fr1 = userreal_c( uservals,
                     &Fnumitems,
                     &Fdfault,
                     tofchar("PAPER="),
                     tofchar("Give width(cm), aspect ratio: [0.0,1.0]") );
   if (Fr1 > 0) {
      /* If width = 0.0 then the program will select the largest */
      /* view surface */
      width  = uservals[0];
      /* Convert from cm to inches */
      width /= 2.54;
      aspect = uservals[1];
      (void) pgpap_c( &width, &aspect );
   }

   /* Get device-type code name of the current PGPLOT device */
   /* If the destination is a printer (=every destination  */
   /* except the Tektronix device), use thick lines in the plot */

   len = 20;
   finit(devtype, len);
   (void) pgqinf_c( tofchar("TYPE"), devtype, &len );
   if (strncmp(devtype.a, "TEK4010", 6) == 0) {
      /* It is a Tektronix */
   }
   else {
      Fnumitems = 1;
      Fdfault = HIDDEN;
      do {
         Flinewidth = 2;
         Fr1 = userint_c( &Flinewidth,
                          &Fnumitems,
                          &Fdfault,
                          tofchar("LINEWIDTH="),
                          tofchar("Give line width (1-21):  [2]") );
         agreed = ((Flinewidth >= 1) && (Flinewidth <= 21));
         if (!agreed) {
            (void) reject_c( tofchar("LINEWIDTH="),
                             tofchar("Invalid number") );
         }
      } while  (!agreed);
      (void) pgslw_c( &Flinewidth );
   }
   { /* Set viewport */
     static float Xl, Xr, Yb, Yt;

     Xl = 0.2;
     Xr = 0.9;
     Yb = 0.1;
     Yt = 0.9;
     (void) pgsvp_c(&Xl, &Xr, &Yb, &Yt);
   }
}
Ejemplo n.º 17
0
static void
getsc_line(Source *s)
{
	char *xp = Xstring(s->xs, xp), *cp;
	bool interactive = Flag(FTALKING) && s->type == SSTDIN;
	bool have_tty = tobool(interactive && (s->flags & SF_TTY));

	/* Done here to ensure nothing odd happens when a timeout occurs */
	XcheckN(s->xs, xp, LINE);
	*xp = '\0';
	s->start = s->str = xp;

	if (have_tty && ksh_tmout) {
		ksh_tmout_state = TMOUT_READING;
		alarm(ksh_tmout);
	}
	if (interactive)
		change_winsz();
#ifndef MKSH_NO_CMDLINE_EDITING
	if (have_tty && (
#if !MKSH_S_NOVI
	    Flag(FVI) ||
#endif
	    Flag(FEMACS) || Flag(FGMACS))) {
		int nread;

		nread = x_read(xp);
		if (nread < 0)
			/* read error */
			nread = 0;
		xp[nread] = '\0';
		xp += nread;
	} else
#endif
	  {
		if (interactive)
			pprompt(prompt, 0);
		else
			s->line++;

		while (/* CONSTCOND */ 1) {
			char *p = shf_getse(xp, Xnleft(s->xs, xp), s->u.shf);

			if (!p && shf_error(s->u.shf) &&
			    shf_errno(s->u.shf) == EINTR) {
				shf_clearerr(s->u.shf);
				if (trap)
					runtraps(0);
				continue;
			}
			if (!p || (xp = p, xp[-1] == '\n'))
				break;
			/* double buffer size */
			/* move past NUL so doubling works... */
			xp++;
			XcheckN(s->xs, xp, Xlength(s->xs, xp));
			/* ...and move back again */
			xp--;
		}
		/*
		 * flush any unwanted input so other programs/builtins
		 * can read it. Not very optimal, but less error prone
		 * than flushing else where, dealing with redirections,
		 * etc.
		 * TODO: reduce size of shf buffer (~128?) if SSTDIN
		 */
		if (s->type == SSTDIN)
			shf_flush(s->u.shf);
	}
	/*
	 * XXX: temporary kludge to restore source after a
	 * trap may have been executed.
	 */
	source = s;
	if (have_tty && ksh_tmout) {
		ksh_tmout_state = TMOUT_EXECUTING;
		alarm(0);
	}
	cp = Xstring(s->xs, xp);
	rndpush(cp);
	s->start = s->str = cp;
	strip_nuls(Xstring(s->xs, xp), Xlength(s->xs, xp));
	/* Note: if input is all nulls, this is not eof */
	if (Xlength(s->xs, xp) == 0) {
		/* EOF */
		if (s->type == SFILE)
			shf_fdclose(s->u.shf);
		s->str = NULL;
	} else if (interactive && *s->str) {
		if (cur_prompt != PS1)
			histsave(&s->line, s->str, HIST_APPEND, true);
		else if (!ctype(*s->str, C_IFS | C_IFSWS))
			histsave(&s->line, s->str, HIST_QUEUE, true);
#if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY
		else
			goto check_for_sole_return;
	} else if (interactive && cur_prompt == PS1) {
 check_for_sole_return:
		cp = Xstring(s->xs, xp);
		while (*cp && ctype(*cp, C_IFSWS))
			++cp;
		if (!*cp) {
			histsave(&s->line, NULL, HIST_FLUSH, true);
			histsync();
		}
#endif
	}
	if (interactive)
		set_prompt(PS2, NULL);
}
Ejemplo n.º 18
0
/*
 * print a command tree
 */
static void
ptree(struct op *t, int indent, struct shf *shf)
{
	const char **w;
	struct ioword **ioact;
	struct op *t1;
	int i;
	const char *ccp;

 Chain:
	if (t == NULL)
		return;
	switch (t->type) {
	case TCOM:
		prevent_semicolon = false;
		/* special-case 'var=<<EOF' (cf. exec.c:execute) */
		if (t->args &&
		    /* we have zero arguments, i.e. no program to run */
		    t->args[0] == NULL &&
		    /* we have exactly one variable assignment */
		    t->vars[0] != NULL && t->vars[1] == NULL &&
		    /* we have exactly one I/O redirection */
		    t->ioact != NULL && t->ioact[0] != NULL &&
		    t->ioact[1] == NULL &&
		    /* of type "here document" (or "here string") */
		    (t->ioact[0]->ioflag & IOTYPE) == IOHERE &&
		    /* the variable assignment begins with a valid varname */
		    (ccp = skip_wdvarname(t->vars[0], true)) != t->vars[0] &&
		    /* and has no right-hand side (i.e. "varname=") */
		    ccp[0] == CHAR && ((ccp[1] == '=' && ccp[2] == EOS) ||
		    /* or "varname+=" */ (ccp[1] == '+' && ccp[2] == CHAR &&
		    ccp[3] == '=' && ccp[4] == EOS))) {
			fptreef(shf, indent, Tf_S, t->vars[0]);
			break;
		}

		if (t->vars) {
			w = (const char **)t->vars;
			while (*w)
				fptreef(shf, indent, Tf_S_, *w++);
		} else
			shf_puts("#no-vars# ", shf);
		if (t->args) {
			w = t->args;
			if (*w && **w == CHAR) {
				char *cp = wdstrip(*w++, WDS_TPUTS);

				if (valid_alias_name(cp))
					shf_putc('\\', shf);
				shf_puts(cp, shf);
				shf_putc(' ', shf);
				afree(cp, ATEMP);
			}
			while (*w)
				fptreef(shf, indent, Tf_S_, *w++);
		} else
			shf_puts("#no-args# ", shf);
		break;
	case TEXEC:
		t = t->left;
		goto Chain;
	case TPAREN:
		fptreef(shf, indent + 2, "( %T) ", t->left);
		break;
	case TPIPE:
		fptreef(shf, indent, "%T| ", t->left);
		t = t->right;
		goto Chain;
	case TLIST:
		fptreef(shf, indent, "%T%;", t->left);
		t = t->right;
		goto Chain;
	case TOR:
	case TAND:
		fptreef(shf, indent, "%T%s %T",
		    t->left, (t->type == TOR) ? "||" : "&&", t->right);
		break;
	case TBANG:
		shf_puts("! ", shf);
		prevent_semicolon = false;
		t = t->right;
		goto Chain;
	case TDBRACKET:
		w = t->args;
		shf_puts("[[", shf);
		while (*w)
			fptreef(shf, indent, Tf__S, *w++);
		shf_puts(" ]] ", shf);
		break;
	case TSELECT:
	case TFOR:
		fptreef(shf, indent, "%s %s ",
		    (t->type == TFOR) ? "for" : Tselect, t->str);
		if (t->vars != NULL) {
			shf_puts("in ", shf);
			w = (const char **)t->vars;
			while (*w)
				fptreef(shf, indent, Tf_S_, *w++);
			fptreef(shf, indent, Tft_end);
		}
		fptreef(shf, indent + INDENT, "do%N%T", t->left);
		fptreef(shf, indent, "%;done ");
		break;
	case TCASE:
		fptreef(shf, indent, "case %S in", t->str);
		for (t1 = t->left; t1 != NULL; t1 = t1->right) {
			fptreef(shf, indent, "%N(");
			w = (const char **)t1->vars;
			while (*w) {
				fptreef(shf, indent, "%S%c", *w,
				    (w[1] != NULL) ? '|' : ')');
				++w;
			}
			fptreef(shf, indent + INDENT, "%N%T%N;%c", t1->left,
			    t1->u.charflag);
		}
		fptreef(shf, indent, "%Nesac ");
		break;
	case TELIF:
		internal_errorf(TELIF_unexpected);
		/* FALLTHROUGH */
	case TIF:
		i = 2;
		t1 = t;
		goto process_TIF;
		do {
			t1 = t1->right;
			i = 0;
			fptreef(shf, indent, Tft_end);
 process_TIF:
			/* 5 == strlen("elif ") */
			fptreef(shf, indent + 5 - i, Telif_pT + i, t1->left);
			t1 = t1->right;
			if (t1->left != NULL) {
				fptreef(shf, indent, Tft_end);
				fptreef(shf, indent + INDENT, "%s%N%T",
				    "then", t1->left);
			}
		} while (t1->right && t1->right->type == TELIF);
		if (t1->right != NULL) {
			fptreef(shf, indent, Tft_end);
			fptreef(shf, indent + INDENT, "%s%N%T",
			    "else", t1->right);
		}
		fptreef(shf, indent, "%;fi ");
		break;
	case TWHILE:
	case TUNTIL:
		/* 6 == strlen("while "/"until ") */
		fptreef(shf, indent + 6, Tf_s_T,
		    (t->type == TWHILE) ? "while" : "until",
		    t->left);
		fptreef(shf, indent, Tft_end);
		fptreef(shf, indent + INDENT, "do%N%T", t->right);
		fptreef(shf, indent, "%;done ");
		break;
	case TBRACE:
		fptreef(shf, indent + INDENT, "{%N%T", t->left);
		fptreef(shf, indent, "%;} ");
		break;
	case TCOPROC:
		fptreef(shf, indent, "%T|& ", t->left);
		prevent_semicolon = true;
		break;
	case TASYNC:
		fptreef(shf, indent, "%T& ", t->left);
		prevent_semicolon = true;
		break;
	case TFUNCT:
		fpFUNCTf(shf, indent, tobool(t->u.ksh_func), t->str, t->left);
		break;
	case TTIME:
		fptreef(shf, indent, Tf_s_T, Ttime, t->left);
		break;
	default:
		shf_puts("<botch>", shf);
		prevent_semicolon = false;
		break;
	}
	if ((ioact = t->ioact) != NULL) {
		bool need_nl = false;

		while (*ioact != NULL)
			pioact(shf, *ioact++);
		/* Print here documents after everything else... */
		ioact = t->ioact;
		while (*ioact != NULL) {
			struct ioword *iop = *ioact++;

			/* heredoc is NULL when tracing (set -x) */
			if ((iop->ioflag & (IOTYPE | IOHERESTR)) == IOHERE &&
			    iop->heredoc) {
				shf_putc('\n', shf);
				shf_puts(iop->heredoc, shf);
				fptreef(shf, indent, Tf_s,
				    evalstr(iop->delim, 0));
				need_nl = true;
			}
		}
		/*
		 * Last delimiter must be followed by a newline (this
		 * often leads to an extra blank line, but it's not
		 * worth worrying about)
		 */
		if (need_nl) {
			shf_putc('\n', shf);
			prevent_semicolon = true;
		}
	}
}
Ejemplo n.º 19
0
fint	ecdset_c( fchar string, fchar set, fint subsets[], fint *nsubs )
{
   ax_struct	*ax = NULL;			/* the ax struct */
   fint		count;				/* counter */
   fint		gerror = 0;			/* gds error return */
   fint		nc = 0;				/* number of characters shipped */
   fint		m, n;				/* loop counters */
   fint		naxis;				/* number of axes */
   fint		ndef = 0;			/* number of defined axes */
   fint		subset;				/* subset number */
   fint		toplevel = 0;			/* whole set */

   for ( n = 0; n < string.l; string.a[n++] = ' ' );
   if ( !tobool( gds_exist_c( set, &gerror ) ) || gerror ) {
      return( -1 );
   }
   naxis = gdsc_ndims_c( set, &toplevel );	/* dimension of set */
   subset = subsets[0];				/* first subset */
   for ( n = 0; n < naxis; n++ ) {		/* loop to get defined axes */
      fint	axnum;				/* the axis number */
      fint	grid;				/* grid number */

      axnum = n + 1;				/* current axis number */
      gerror = 0;				/* reset */
      grid = gdsc_grid_c( set, &axnum, &subset, &gerror );
      if ( gerror == 0 ) {			/* axis defined */
         fchar	ctype;				/* points to buffer for axis name */

         ax = realloc( ax, sizeof( ax_struct ) * ( ndef + 1 ) );
         if ( ax == NULL ) RETURN( -2 );	/* error */
         ax[ndef].axnum = axnum;		/* axis sequence number */
         ax[ndef].nstep = 0;
         ax[ndef].ngrid = 0;
         ax[ndef].grid = NULL;
         ax[ndef].step = NULL;
         ax[ndef].user = NULL;
         ctype.a = ax[ndef].ctype;
         ctype.l = MAXCTYPELEN;
         gdsc_name_c( ctype, set, &axnum, &gerror );
         ctype.a[nelc_c( ctype )] = 0;
         ndef++;
      }
   }
   gerror = 0;
   nc = nelc_c( set );
   if ( nc > string.l ) RETURN( -3 );
   strncpy( string.a, set.a, nc );
   if ( ndef == 0 ) {
      if ( (*nsubs) != 1 ) RETURN( -4 );
      RETURN( 0 );
   }
   for ( m = 0; m < ndef; m++ ) {
      ax[m].grid = calloc( (*nsubs), sizeof( fint ) );
      if ( ax[m].grid == NULL ) RETURN( -2 );
      ax[m].step = calloc( (*nsubs), sizeof( fint ) );
      if ( ax[m].step == NULL ) RETURN( -2 );
      ax[m].user = calloc( (*nsubs), sizeof( fint ) );
      if ( ax[m].user == NULL ) RETURN( -2 );
   }
   for ( n = 0; n < (*nsubs); n++ ) {
      for ( m = 0; m < ndef; m++ ) {
         ax[m].grid[n] = gdsc_grid_c( set, &ax[m].axnum, &subsets[n], &gerror );
      }
   }
   for ( m = 0; m < ndef; m++ ) {
      fint	okay;
      fint	n1, n2;
      fint	ns = 1;
      fint	nt = (*nsubs);

      ax[m].nsequ = ns;
      while ( ns < (*nsubs) ) {
         ns++;
         if ( ( (*nsubs) % ns ) == 0 ) {
            nt = (*nsubs) / ns;
            for ( okay = 1, n1 = 0; n1 < nt && okay; n1++ ) {
               for ( n2 = 1; n2 < ns && okay; n2++ ) {
                  okay = ( ax[m].grid[n1] == ax[m].grid[n1+nt*n2] );
               }
            }
            if ( okay ) ax[m].nsequ = ns;
         }
      }
   }
   qsort( ax, ndef, sizeof( ax_struct ), compar );
   if ( ( ax[0].nsequ == (*nsubs) ) && ( ndef > 1 ) ) {
      ax_struct	save;

      ax[0].nsequ = 1;
      save = ax[0];
      for ( n = 1; n < ndef; n++ ) {
         ax[n-1] = ax[n];
      }
      ax[ndef-1] = save;
   }
   count = (*nsubs);
   ax[0].ngrid = count / ax[0].nsequ;
   count /= ax[0].ngrid;
   for ( n = 0; n < ax[0].ngrid; n++ ) {
      ax[0].user[n] = ax[0].grid[n];
   }
   for ( m = 1; m < ndef; m++ ) {
      ax[m].ngrid = ax[m-1].nsequ / ax[m].nsequ;
      count /= ax[m].ngrid;
      if ( m == ( ndef - 1 ) && count != 1 ) ax[m].ngrid *= count;
      for ( n = 0; n < ax[m].ngrid; n++ ) {
         ax[m].user[n] = ax[m].grid[n*((*nsubs)/ax[m-1].nsequ)];
      }
   }
   for ( m = 0; m < ndef; m++ ) {
      char	text[MAXSTRINGLEN];
      int	l = 0;
      int	ndone = 0;

      SHIP( " " );
      SHIP( ax[m].ctype );
      for ( n = 1; n < ax[m].ngrid; n++ ) {
         ax[m].step[n] = ax[m].user[n] - ax[m].user[n-1];
      }
      while ( ndone < ax[m].ngrid ) {
         l += sprintf( &text[l], " %d", ax[m].user[ndone++] );
         for ( n = ndone+1; n < ax[m].ngrid && ax[m].step[ndone] == ax[m].step[n]; n++ );
         if ( n > ( ndone + 1 ) ) {
            if ( ax[m].step[ndone] == 1 ) {
               l += sprintf( &text[l], ":%d", ax[m].user[n-1] );
            } else if ( ax[m].step[ndone] == 0 ) {
               l += sprintf( &text[l], "::%d", n - ndone + 1 );
            } else {
               l += sprintf( &text[l], ":%d:%d", ax[m].user[n-1], ax[m].step[ndone] );
            }
            ndone = n;
         }
      }
      SHIP( text );
   }
   RETURN( 0 );
}
Ejemplo n.º 20
0
/*
 * lookup variable (according to (set&LOCAL)), set its attributes
 * (INTEGER, RDONLY, EXPORT, TRACE, LJUST, RJUST, ZEROFIL, LCASEV,
 * UCASEV_AL), and optionally set its value if an assignment.
 */
struct tbl *
typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
{
	struct tbl *vp;
	struct tbl *vpbase, *t;
	char *tvar;
	const char *val;
	size_t len;
	bool vappend = false;
	enum namerefflag new_refflag = SRF_NOP;

	if ((set & (ARRAY | ASSOC)) == ASSOC) {
		new_refflag = SRF_ENABLE;
		set &= ~(ARRAY | ASSOC);
	}
	if ((clr & (ARRAY | ASSOC)) == ASSOC) {
		new_refflag = SRF_DISABLE;
		clr &= ~(ARRAY | ASSOC);
	}

	/* check for valid variable name, search for value */
	val = skip_varname(var, false);
	if (val == var) {
		/* no variable name given */
		return (NULL);
	}
	if (*val == '[') {
		if (new_refflag != SRF_NOP)
			errorf("%s: %s", var,
			    "reference variable can't be an array");
		len = array_ref_len(val);
		if (len == 0)
			return (NULL);
		/*
		 * IMPORT is only used when the shell starts up and is
		 * setting up its environment. Allow only simple array
		 * references at this time since parameter/command
		 * substitution is performed on the [expression] which
		 * would be a major security hole.
		 */
		if (set & IMPORT) {
			size_t i;

			for (i = 1; i < len - 1; i++)
				if (!ksh_isdigit(val[i]))
					return (NULL);
		}
		val += len;
	}
	if (val[0] == '=') {
		strndupx(tvar, var, val - var, ATEMP);
		++val;
	} else if (set & IMPORT) {
		/* environment invalid variable name or no assignment */
		return (NULL);
	} else if (val[0] == '+' && val[1] == '=') {
		strndupx(tvar, var, val - var, ATEMP);
		val += 2;
		vappend = true;
	} else if (val[0] != '\0') {
		/* other invalid variable names (not from environment) */
		return (NULL);
	} else {
		/* just varname with no value part nor equals sign */
		strdupx(tvar, var, ATEMP);
		val = NULL;
		/* handle foo[*] => foo (whole array) mapping for R39b */
		len = strlen(tvar);
		if (len > 3 && tvar[len - 3] == '[' && tvar[len - 2] == '*' &&
		    tvar[len - 1] == ']')
			tvar[len - 3] = '\0';
	}

	if (new_refflag == SRF_ENABLE) {
		const char *qval, *ccp;

		/* bail out on 'nameref foo+=bar' */
		if (vappend)
			errorf("appending not allowed for nameref");
		/* find value if variable already exists */
		if ((qval = val) == NULL) {
			varsearch(e->loc, &vp, tvar, hash(tvar));
			if (vp == NULL)
				goto nameref_empty;
			qval = str_val(vp);
		}
		/* check target value for being a valid variable name */
		ccp = skip_varname(qval, false);
		if (ccp == qval) {
			if (ksh_isdigit(qval[0])) {
				int c;

				if (getn(qval, &c))
					goto nameref_rhs_checked;
			} else if (qval[1] == '\0') switch (qval[0]) {
			case '$':
			case '!':
			case '?':
			case '#':
			case '-':
				goto nameref_rhs_checked;
			}
 nameref_empty:
			errorf("%s: %s", var, "empty nameref target");
		}
		len = (*ccp == '[') ? array_ref_len(ccp) : 0;
		if (ccp[len]) {
			/*
			 * works for cases "no array", "valid array with
			 * junk after it" and "invalid array"; in the
			 * latter case, len is also 0 and points to '['
			 */
			errorf("%s: %s", qval,
			    "nameref target not a valid parameter name");
		}
 nameref_rhs_checked:
		/* prevent nameref loops */
		while (qval) {
			if (!strcmp(qval, tvar))
				errorf("%s: %s", qval,
				    "expression recurses on parameter");
			varsearch(e->loc, &vp, qval, hash(qval));
			qval = NULL;
			if (vp && ((vp->flag & (ARRAY | ASSOC)) == ASSOC))
				qval = str_val(vp);
		}
	}

	/* prevent typeset from creating a local PATH/ENV/SHELL */
	if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 ||
	    strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))
		errorf("%s: %s", tvar, "restricted");

	innermost_refflag = new_refflag;
	vp = (set & LOCAL) ? local(tvar, tobool(set & LOCAL_COPY)) :
	    global(tvar);
	if (new_refflag == SRF_DISABLE && (vp->flag & (ARRAY|ASSOC)) == ASSOC)
		vp->flag &= ~ASSOC;
	else if (new_refflag == SRF_ENABLE) {
		if (vp->flag & ARRAY) {
			struct tbl *a, *tmp;

			/* free up entire array */
			for (a = vp->u.array; a; ) {
				tmp = a;
				a = a->u.array;
				if (tmp->flag & ALLOC)
					afree(tmp->val.s, tmp->areap);
				afree(tmp, tmp->areap);
			}
			vp->u.array = NULL;
			vp->flag &= ~ARRAY;
		}
		vp->flag |= ASSOC;
	}

	set &= ~(LOCAL|LOCAL_COPY);

	vpbase = (vp->flag & ARRAY) ? global(arrayname(tvar)) : vp;

	/*
	 * only allow export flag to be set; AT&T ksh allows any
	 * attribute to be changed which means it can be truncated or
	 * modified (-L/-R/-Z/-i)
	 */
	if ((vpbase->flag & RDONLY) &&
	    (val || clr || (set & ~EXPORT)))
		/* XXX check calls - is error here ok by POSIX? */
		errorfx(2, "read-only: %s", tvar);
	afree(tvar, ATEMP);

	/* most calls are with set/clr == 0 */
	if (set | clr) {
		bool ok = true;

		/*
		 * XXX if x[0] isn't set, there will be problems: need
		 * to have one copy of attributes for arrays...
		 */
		for (t = vpbase; t; t = t->u.array) {
			bool fake_assign;
			char *s = NULL;
			char *free_me = NULL;

			fake_assign = (t->flag & ISSET) && (!val || t != vp) &&
			    ((set & (UCASEV_AL|LCASEV|LJUST|RJUST|ZEROFIL)) ||
			    ((t->flag & INTEGER) && (clr & INTEGER)) ||
			    (!(t->flag & INTEGER) && (set & INTEGER)));
			if (fake_assign) {
				if (t->flag & INTEGER) {
					s = str_val(t);
					free_me = NULL;
				} else {
					s = t->val.s + t->type;
					free_me = (t->flag & ALLOC) ? t->val.s :
					    NULL;
				}
				t->flag &= ~ALLOC;
			}
			if (!(t->flag & INTEGER) && (set & INTEGER)) {
				t->type = 0;
				t->flag &= ~ALLOC;
			}
			t->flag = (t->flag | set) & ~clr;
			/*
			 * Don't change base if assignment is to be
			 * done, in case assignment fails.
			 */
			if ((set & INTEGER) && base > 0 && (!val || t != vp))
				t->type = base;
			if (set & (LJUST|RJUST|ZEROFIL))
				t->u2.field = field;
			if (fake_assign) {
				if (!setstr(t, s, KSH_RETURN_ERROR)) {
					/*
					 * Somewhat arbitrary action
					 * here: zap contents of
					 * variable, but keep the flag
					 * settings.
					 */
					ok = false;
					if (t->flag & INTEGER)
						t->flag &= ~ISSET;
					else {
						if (t->flag & ALLOC)
							afree(t->val.s, t->areap);
						t->flag &= ~(ISSET|ALLOC);
						t->type = 0;
					}
				}
				if (free_me)
					afree(free_me, t->areap);
			}
		}
		if (!ok)
			errorfz();
	}

	if (val != NULL) {
		char *tval;

		if (vappend) {
			tval = shf_smprintf("%s%s", str_val(vp), val);
			val = tval;
		} else
			tval = NULL;

		if (vp->flag&INTEGER) {
			/* do not zero base before assignment */
			setstr(vp, val, KSH_UNWIND_ERROR | 0x4);
			/* done after assignment to override default */
			if (base > 0)
				vp->type = base;
		} else
			/* setstr can't fail (readonly check already done) */
			setstr(vp, val, KSH_RETURN_ERROR | 0x4);

		if (tval != NULL)
			afree(tval, ATEMP);
	}

	/* only x[0] is ever exported, so use vpbase */
	if ((vpbase->flag&EXPORT) && !(vpbase->flag&INTEGER) &&
	    vpbase->type == 0)
		exportprep(vpbase, (vpbase->flag&ISSET) ? vpbase->val.s : null);

	return (vp);
}
Ejemplo n.º 21
0
// -----------------------------------------------------------------------------
const CRenderTexturePtr&
CPostEffectLoader::ParseRenderTexture( const string& name )
{
	if ( NoneTarget == name.c_str() || PreviousTarget == name.c_str() )
	{
		static const CRenderTexturePtr nullPtr;
		return nullPtr;
	}
	// search existed
	GMap<GString, CRenderTexturePtr>::iterator it = renderTargetMap.find(name.c_str());
	if (it != renderTargetMap.end())
		return it->second;

	// parse RTT's parameters
	TiXmlNode* xmlNode = NULL;
	TiXmlElement* pElement = NULL;
	GString rttName;
	for (xmlNode = xmlConfig->FirstChild(); xmlNode != NULL; xmlNode = xmlNode->NextSibling())
	{
		pElement = xmlNode->ToElement();
		if (!pElement || pElement->ValueStr() != "RenderTexture")
			continue;
		rttName = pElement->Attribute("name");
		if (rttName == name.c_str())
			break;
	}

	uint width, height;
	if ( (pElement->Attribute("width")) 
		&& (pElement->Attribute("height") ))
	{
		width = atoi(pElement->Attribute("width"));
		height = atoi(pElement->Attribute("height"));
	}
	else
	{
		// relative width & height
		CIRect rect;
		CMainWindowTarget::GetInst()->GetRect(rect);
		width  = uint(rect.Width() * atof(pElement->Attribute("relWidth")));
		height = uint(rect.Height() * atof(pElement->Attribute("relHeight")));
	}
	_texFORMAT format = RTTFormat_Kit::FromString(pElement->Attribute("format"));

	bool isUseDepth = tobool(pElement->Attribute("depth"));
	bool msaa		= false;
	if (pElement->Attribute("msaa"))
	{
		msaa = tobool(pElement->Attribute("msaa"));
	}
	// create RTT
	CRenderTexturePtr renderTarget = CGraphic::GetInst()->CreateRenderTarget();
	renderTarget->SetWidth(width);
	renderTarget->SetHeight(height);
	renderTarget->SetFormat(format);
	renderTarget->SetUseDepthBuffer(isUseDepth);
	renderTarget->SetAntiAlias(msaa);
	renderTarget->Create();
	renderTarget->Release();// set reference count to 1

	return renderTargetMap.insert(make_pair(name.c_str(), renderTarget)).first->second;
}