Beispiel #1
0
int64_t parse_int_skip(const char **cp)
{
  skipblanks(cp);
  int64_t val = 0;
  int neg = 0;

  if(**cp == '-') {
    ++(*cp);
    neg = 1;
  } else if(**cp == '~') {
    ++(*cp);
    neg = 2;
  }

  if(**cp == '$') {
    ++(*cp);
    val = parse_hex_skip(cp);
  } else if(**cp == '0' && (cp[0][1] == 'x' || cp[0][1] == 'X')) {
    (*cp) += 2;
    val = parse_hex_skip(cp);
  } else while(**cp) {
      if(**cp >= '0' && **cp <= '9') {
        val *= 10;
        val += **cp - '0';
      } else if(**cp == '*') {
        ++(*cp);
        int64_t second = parse_int_skip(cp);
        val *= second;
        break;
      } else {
        break;
      }

      ++(*cp);
    }

  if(neg == 1) {
    val = neint(val);
  } else if(neg == 2) {
    val = not_int(val);
  }

  return val;
}
Beispiel #2
0
#include <type_traits>
#include <tick/integral_constant.h>
#include <tick/requires.h>

struct not_int {};

TICK_STATIC_TEST_CASE()
{
    template<class T, TICK_REQUIRES(std::is_integral<T>::value)>
    static std::true_type check_requires(T);

    template<class T, TICK_REQUIRES(!std::is_integral<T>::value)>
    static std::false_type check_requires(T);

    STATIC_ASSERT_SAME(decltype(check_requires(1)), std::true_type);
    STATIC_ASSERT_SAME(decltype(check_requires(not_int())), std::false_type);
};

TICK_STATIC_TEST_CASE()
{
    template<class T, TICK_REQUIRES(std::is_integral<T>::value)>
    static std::true_type check_requires(T);

    template<class T, TICK_REQUIRES(!std::is_integral<T>::value)>
    static std::true_type check_requires(T);

    STATIC_ASSERT_SAME(decltype(check_requires(1)), std::true_type);
    STATIC_ASSERT_SAME(decltype(check_requires(not_int())), std::true_type);
};

TICK_STATIC_TEST_CASE()
Beispiel #3
0
static void read_output_opt (void)
{
    static int alldone = 0;

    if (alldone)
        return;

    zvalue.spec_found = 0;
    scale.spec_found = 0;
    post.spec_found = 0;
    contour.spec_found = 0;
    maplabel.nspec = 0;
    maplabel.maplab = NULL;
    mapline.nspec = 0;
    mapline.maplin = NULL;
    selects.nspec = 0;
    selects.condition = NULL;

    while (1)
    {
		char **field;
        int nspec;
	
		nspec = nextspecs (&field);
		if (! nspec) 
			break;

		if (_stricmp (field[0], "zvalue") == 0)
		{
			if (zvalue.spec_found)
				error_stop (field[0],
		                "specified more than once in file output.opt");
			if (nspec != 3)
				error_stop (field[0], 
		           "has the wrong number of fields in file output.opt");
			zvalue.spec_found = 1;
			zvalue.zname = field[1];
			zvalue.digits = atoi (field[2]);
			if (not_int (field[2]) || zvalue.digits < 0 || zvalue.digits > 10)
				error_stop ("invalid digits field in output.opt ZVALUE:",
		                                                      field[2]);
		}
		else if (_stricmp (field[0], "scale") == 0)
		{
			if (scale.spec_found)
				error_stop (field[0],
		                "specified more than once in file output.opt");
			if (nspec != 2)
				error_stop (field[0], 
		          "has the wrong number of fields in file output.opt");
			scale.spec_found = 1;
			scale.ratio = atol (field[1]);
			if (not_int (field[1]) || scale.ratio < 1 || scale.ratio > 1000000)
				error_stop ("invalid ratio field in output.opt SCALE:",
		                                                      field[1]);
		}
		else if (_stricmp (field[0], "post") == 0)
		{
			if (post.spec_found)
				error_stop (field[0],
		                "specified more than once in file output.opt");
			if (nspec != 4)
				error_stop (field[0], 
		          "has the wrong number of fields in file output.opt");
			post.spec_found = 1;
			post.labelfont = field[1];
			post.labelsize = atoi (field[2]);
			if (not_int (field[2]) || post.labelsize < 1 ||
	                                                  post.labelsize > 100)
				error_stop ("invalid labelsize field in output.opt POST:",
		                                                      field[2]);
			post.labelrotate = atoi (field[3]);
			if (not_int (field[3]))
				error_stop ("invalid labelrotate field in output.opt POST:",
								      field[3]);
		}
		else if (_stricmp (field[0], "contour") == 0)
		{
			if (contour.spec_found)
				error_stop (field[0],
		                "specified more than once in file output.opt");
			if (nspec < 6)
				error_stop (field[0], 
		          "has the wrong number of fields in file output.opt");
			contour.spec_found = 1;
			contour.meshsize = atof (field[1]);
			if (not_float (field[1]) || contour.meshsize <= 0)
				error_stop ("invalid meshsize field in output.opt CONTOUR:", 
		                                                      field[1]);
			contour.gridmethod = atoi (field[2]);
			if (not_int (field[2]) || contour.gridmethod < 1 ||
	                                                contour.gridmethod > 20)
				error_stop ("invalid gridmethod field in output.opt CONTOUR:", 
		                                                      field[2]);
			if (_stricmp (field[3], "SIZE") == 0)
			{
				contour.intervalsize = atof (field[4]);
				contour.numberoflevels = 0;
				if (not_float (field[4]) || contour.intervalsize <= 0)
					error_stop (
						"invalid intervalsize field in output.opt CONTOUR:", 
		                                                      field[4]);
			}
			else if (_stricmp (field[3], "LEVELS") == 0)
			{
				contour.intervalsize = 0;
				contour.numberoflevels = atoi (field[4]);
				if (not_int (field[4]) || contour.numberoflevels <= 0)
					error_stop (
						"invalid numberoflevels field in output.opt CONTOUR:", 
		                                                      field[4]);
			}
			else
				error_stop (
					"intervalspec is not SIZE or LEVELS in output.opt CONTOUR:",
		                                                     field[3]);

			if (_stricmp (field[5], "LINEAR") == 0)
			{
				contour.smoothmethod = 'L';
				if (nspec != 6)
					error_stop (field[0], 
						"has the wrong number of fields in file output.opt");
				contour.approx_pts = 0;
				contour.bs_order = 0;
			}
			else if (_stricmp (field[5], "CUBIC_SPLINE") == 0)
			{
				contour.smoothmethod = 'C';
				if (nspec != 7)
					error_stop (field[0], 
						"has the wrong number of fields in file output.opt");
				contour.approx_pts = atoi (field[6]);
				if (not_int (field[6]) || contour.approx_pts < 4 || 
		                                        contour.approx_pts > 20)
					error_stop ("invalid npoints field in output.opt CONTOUR:",
		                                                      field[6]);
				contour.bs_order = 0;
			}
			else if (_stricmp (field[5], "BSPLINE") == 0)
			{
				contour.smoothmethod = 'B';
				if (nspec != 8)
					error_stop (field[0], 
						"has the wrong number of fields in file output.opt");
				contour.bs_order = atoi (field[6]);
				if (not_int (field[6]) || contour.bs_order < 2 ||
		                                         contour.bs_order > 10)
					error_stop (
						"invalid bspline order field in output.opt CONTOUR:",
		                                                      field[6]);
				contour.approx_pts = atoi (field[7]);
				if (not_int (field[7]) || contour.approx_pts < 4 || 
		                                        contour.approx_pts > 20)
					error_stop ("invalid npoints field in output.opt CONTOUR:",
		                                                      field[7]);
			}
			else
				error_stop ("invalid smoothmethod in output.opt CONTOUR:", 
		                                                     field[5]);
		}
		else if (_stricmp (field[0], "maplabel") == 0)
		{
			MAPLABEL *ml;

			++maplabel.nspec; 
			maplabel.maplab = (MAPLABEL *) realloc (maplabel.maplab, 
	                        (unsigned) maplabel.nspec * sizeof (MAPLABEL));
			if (maplabel.maplab == NULL)
				error_stop ("cannot reallocate MAPLABEL space", "");
			ml = maplabel.maplab + maplabel.nspec - 1;
			if (nspec != 7)
				error_stop (field[0], 
						"has the wrong number of fields in file output.opt");
			ml->label = field[1];
			ml->xpos = atof (field[2]);
			if (not_float (field[2]))
				error_stop ("invalid xpos field in output.opt MAPLABEL:", 
		                                                      field[2]);
			ml->ypos = atof (field[3]);
			if (not_float (field[3]))
				error_stop ("invalid ypos field in output.opt MAPLABEL:", 
		                                                      field[3]);
			ml->font = field[4];
			ml->fontsize = atoi (field[5]);
			if (not_int (field[5]) || ml->fontsize < 1 || ml->fontsize > 100)
				error_stop ("invalid fontsize field in output.opt MAPLABEL:",
		                                                      field[5]);
			ml->rotate = atoi (field[6]);
			if (not_int (field[6]))
				error_stop ("invalid rotate field in output.opt MAPLABEL:",
		                                                      field[6]);
		}
		else if (_stricmp (field[0], "mapline") == 0)
		{
			int i, k;
			MAPLINE *ml;

			++mapline.nspec; 
			mapline.maplin = (MAPLINE *) realloc (mapline.maplin, 
								(unsigned) mapline.nspec * sizeof (MAPLINE));
			if (mapline.maplin == NULL)
				error_stop ("cannot reallocate MAPLINE space", "");
			ml = mapline.maplin + mapline.nspec - 1;
			if (nspec < 3)
				error_stop (field[0], 
					"has the wrong number of fields in file output.opt");
			ml->width = atoi (field[1]);
			if (not_int (field[1]) || ml->width < 1 || ml->width > 100)
					error_stop ("invalid width field in output.opt MAPLINE:",
		                                                      field[1]);
			ml->intensity = atof (field[2]);
			if (not_float (field[2]))
				error_stop ("invalid intensity field in output.opt MAPLINE:",
		                                                      field[2]);
			ml->npoint = (nspec - 3) / 2;
			if (ml->npoint < 2 || ml->npoint * 2 + 3 != nspec)
				error_stop ("invalid coordinate pairs in output.opt MAPLINE",
		                                                            "");
			ml->x = (double *) malloc ((unsigned) ml->npoint * sizeof (double));
			ml->y = (double *) malloc ((unsigned) ml->npoint * sizeof (double));
			if (ml->x == NULL || ml->y == NULL)
				error_stop ("cannot allocate space for MAPLINE coordinates","");
			k = 3;
			for (i = 0; i < ml->npoint; i++)
			{
				ml->x[i] = atof (field[k++]);
				ml->y[i] = atof (field[k++]);
			}
		}
		else if (_stricmp (field[0], "select") == 0)
		{
			SELECT *sel;
			int nclause = 0;
			int k = 0;

			if (nspec == 4)
				nclause = 1;
			else if (nspec == 8)
				nclause = 2;
			else
				error_stop (field[0], 
		                "has the wrong number of fields in output.opt");
	
			while (nclause--)
			{
				++selects.nspec; 
				selects.condition = (SELECT *) realloc (selects.condition, 
	                           (unsigned) selects.nspec * sizeof (SELECT));
				if (selects.condition == NULL)
					error_stop ("cannot reallocate SELECT space", "");
				sel = selects.condition + selects.nspec - 1;
				++k;
				{
					DATATYPE dt;
					dt = CODE;
					if (_stricmp (field[k], "code") == 0)
						dt = CODE;
					else if (_stricmp (field[k], "obs") == 0)
						dt = OBS;
					else if (_stricmp (field[k], "x") == 0)
						dt = X;
					else if (_stricmp (field[k], "y") == 0)
						dt = Y;
					else if (_stricmp (field[k], "fit") == 0)
						dt = FIT;
					else if (_stricmp (field[k], "resid") == 0)
						dt = RESID;
					else
						error_stop ("invalid datatype in output.opt SELECT:",
								     field[k]);
					sel->datatype = dt;
				}
				++k;
				{
					LOG_OPERATOR op;

					op = LT;
					if (_stricmp (field[k], "<") == 0)
						op = LT;
					else if (_stricmp (field[k], "<=") == 0)
						op = LE;
					else if (_stricmp (field[k], "=") == 0)
						op = EQ;
					else if (_stricmp (field[k], "!=") == 0)
						op = NE;
					else if (_stricmp (field[k], ">") == 0)
						op = GT;
					else if (_stricmp (field[k], ">=") == 0)
						op = GE;
					else
						error_stop ("invalid operator in output.opt SELECT:",
								     field[k]);
					sel->logop = op;
				}
				++k;
				sel->value = atof (field[k]);
				if (not_float (field[k]))
					error_stop ("invalid value field in output.opt SELECT:",
		                                                      field[k]);
				sel->or_next = nclause;
				if (nclause)
				{
					++k;
					if (_stricmp (field[k], "OR") != 0)
						error_stop ("OR not found in output.opt SELECT:",
		                                                      field[k]);
				}
			}
		}
		else
			error_stop ("unknown output.opt type:", field[0]);

	}

    alldone = 1;
}