Example #1
0
/**
 * @brief
 *		Read a bunch of strings into a NULL terminated array.
 *		The strings are regular null terminated char arrays
 *		and the string array is NULL terminated.
 *
 *		Pass in array location to hold the allocated array
 *		and return an error value if there is a problem.  If
 *		an error does occur, arrloc is not changed.
 *
 * @param[in]	stream	- socket where you reads the request.
 * @param[out]	arrloc	- NULL terminated array where strings are stored.
 *
 * @return	error code
 */
static int
read_carray(int stream, char ***arrloc)
{
	int	i, num, ret;
	char	*cp, **carr;

	if (arrloc == NULL)
		return PBSE_INTERNAL;

	num = 4;	/* keep track of the number of array slots */
	carr = (char **)calloc(sizeof(char **), num);
	if (carr == NULL)
		return PBSE_SYSTEM;

	for (i=0;; i++) {
		cp = disrst(stream, &ret);
		if ((cp == NULL) || (ret != DIS_SUCCESS)) {
			arrayfree(carr);
			if (cp != NULL)
				free(cp);
			return PBSE_SYSTEM;
		}
		if (*cp == '\0') {
			free(cp);
			break;
		}
		if (i == num-1) {
			char	**hold;

			hold = (char **)realloc(carr,
				num * 2 * sizeof(char **));
			if (hold == NULL) {
				arrayfree(carr);
				free(cp);
				return PBSE_SYSTEM;
			}
			carr = hold;

			/* zero the last half of the now doubled carr */
			memset(&carr[num], 0, num * sizeof(char **));
			num *= 2;
		}
		carr[i] = cp;
	}
	carr[i] = NULL;
	*arrloc = carr;
	return ret;
}
Example #2
0
static int 
arrowinit(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv)
{  
  int width, headlen, headwidth, miter, stroke, join, prm, type, alpha;
  struct narray *expand_points;

  if (_exeparent(obj, argv[1], inst, rval, argc, argv)) {
    return 1;
  }

  switch (argv[0][0]) {
  case 'l':			/* line */
    type = PATH_TYPE_LINE;
    break;
  case 'c':			/* curve */
    type = PATH_TYPE_CURVE;
    break;
  case 'p':			/* polygon or path */
    type = PATH_TYPE_LINE;

    prm = 1;
    if (strcmp(argv[0], "polygon") == 0) {
      _putobj(obj, "close_path", inst, &prm);
    }

    break;
  default:
    type = PATH_TYPE_LINE;
  }

  width = 40;
  headlen = 72426;
  headwidth = 60000;
  miter = 1000;
  join = JOIN_TYPE_BEVEL;
  stroke = 1;
  alpha = 255;

  if (_putobj(obj, "type",         inst, &type))      return 1;
  if (_putobj(obj, "stroke",       inst, &stroke))    return 1;
  if (_putobj(obj, "width",        inst, &width))     return 1;
  if (_putobj(obj, "miter_limit",  inst, &miter))     return 1;
  if (_putobj(obj, "arrow_length", inst, &headlen))   return 1;
  if (_putobj(obj, "arrow_width",  inst, &headwidth)) return 1;
  if (_putobj(obj, "join",         inst, &join))      return 1;
  if (_putobj(obj, "stroke_A",     inst, &alpha)) return 1;
  if (_putobj(obj, "fill_A",       inst, &alpha)) return 1;

  expand_points = arraynew(sizeof(int));
  if (expand_points == NULL) {
    return 1;
  }

  if (_putobj(obj, "_points", inst, expand_points)) {
    arrayfree(expand_points);
    return 1;
  }

  return 0;
}
Example #3
0
static struct narray *
allocate_sarray(ngraph_arg *arg)
{
  struct narray *array, *ptr;
  int i;

  if (arg == NULL) {
    return NULL;
  }

  if (arg->num < 1) {
    return NULL;
  }

  array = arraynew(sizeof(char *));
  if (array == NULL) {
    return NULL;
  }

  for (i = 0; i < arg->num; i++) {
    ptr = arrayadd2(array, arg->ary[i].str);
    if (ptr == NULL) {
      arrayfree(array);
      return NULL;
    }
  }

  return array;
}
Example #4
0
void
freetexmap(Array *map) {
    Texture **tex = map->ptr;
    for(size_t i = 0; i < map->nmemb; i++) {
        glDeleteTextures(1, &tex[i]->handle);
        freetex(tex[i]);
    }
    arrayfree(map);
}
Example #5
0
static void
free_obj_arg(const char **ary, struct objlist *obj, const char *vname, ngraph_arg *arg)
{
  int i, n, num, is_a;
  const char *arglist;

  num = arg->num;
  if (num < 1) {
    return;
  }

  arglist = chkobjarglist(obj, vname);
  if (arglist == NULL) {
    return;
  }

  n = 0;
  for (i = 0; arglist[i]; i++) {
    if (n >= num) {
      break;
    }

    is_a = (arglist[i + 1]== 'a');

    switch (arglist[i]) {
    case 'b':
    case 'c':
      break;
    case 'i':
    case 'd':
      if (is_a) {
	arrayfree((struct narray *) ary[n]);
      }
      break;
    case 's':
      if (is_a) {
	arrayfree2((struct narray *) ary[n]);
      }
      break;
    case 'p':
      break;
    case 'o':
      break;
    }

    if (is_a) {
      i++;
    }
    n++;
  }

  g_free(ary);

  return;
}
Example #6
0
static int 
regexpdone(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv)
{
  struct oregexp_local *local;

  if (_exeparent(obj,(char *)argv[1],inst,rval,argc,argv)) return 1;

  _getobj(obj, "_local", inst, &local);

  if (local->regexp) {
    g_regex_unref(local->regexp);
  }

  if (local->array) {
    del_array_element(local->array);
    arrayfree(local->array);
  }

  return 0;
}
Example #7
0
static int 
arrowbbox(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv)
{
  int minx, miny, maxx, maxy;
  int x, y, num, num2, type, intp, stroke, fill;
  struct narray *points;
  int *pdata;
  struct narray *array;
  int i, j, width;
  int headlen, headwidth;
  int head;
  int *points2;
  int x0, y0, x1, y1, x2, y2, x3, y3;
  int ap[6], ap2[6];

  array = rval->array;
  if (arraynum(array) != 0) {
    return 0;
  }

  _getobj(obj, "type", inst, &type);

  _getobj(obj, "fill",   inst, &fill);
  _getobj(obj, "stroke", inst, &stroke);
  if (fill == 0 && stroke == 0) {
    return 0;
  }

  if (type == PATH_TYPE_CURVE) {
    _getobj(obj, "interpolation", inst, &intp);
    _getobj(obj, "_points",       inst, &points);
    if (arraynum(points) == 0) {
      curve_expand_points(obj, inst, intp, points);
    }
  } else {
    _getobj(obj, "points", inst, &points);
  }

  _getobj(obj, "width",        inst, &width);
  _getobj(obj, "arrow",        inst, &head);
  _getobj(obj, "arrow_length", inst, &headlen);
  _getobj(obj, "arrow_width",  inst, &headwidth);

  num = arraynum(points) / 2;
  pdata = arraydata(points);
  points2 = g_malloc(sizeof(int) * num * 2);
  if (points2 == NULL) {
    return 1;
  }
  j = 0;
  x1 = y1 = 0;
  for (i = 0; i < num; i++) {
    x0 = pdata[2 * i];
    y0 = pdata[2 * i + 1];
    if (i == 0 || x0 != x1 || y0 != y1) {
      points2[2 * j] = x0;
      points2[2 * j + 1] = y0;
      j++;
      x1 = x0;
      y1 = y0;
    }
  }
  num2 = j;
  if (num2 < 2) {
    g_free(points2);
    return 0;
  }

  x0 = points2[0];
  y0 = points2[1];
  x1 = points2[2];
  y1 = points2[3];
  x2 = points2[2 * num2 - 4];
  y2 = points2[2 * num2 - 3];
  x3 = points2[2 * num2 - 2];
  y3 = points2[2 * num2 - 1];
  g_free(points2);

  if (head==ARROW_POSITION_BEGIN || head==ARROW_POSITION_BOTH) {
    get_arrow_pos(NULL, 0,
		  width, headlen, headwidth,
		  x0, y0, x1, y1, ap);
  }

  if (head==ARROW_POSITION_END || head==ARROW_POSITION_BOTH) {
    get_arrow_pos(NULL, 0,
		  width, headlen, headwidth,
		  x3, y3, x2, y2, ap2);
  }
  if (array == NULL && (array = arraynew(sizeof(int))) == NULL) {
    return 1;
  }

  maxx = minx = pdata[0];
  maxy = miny = pdata[1];
  arrayadd(array, &(pdata[0]));
  arrayadd(array, &(pdata[1]));

  for (i = 1; i < num; i++) {
    x = pdata[i * 2];
    y = pdata[i * 2 + 1];
    if (x < minx) minx = x;
    if (x > maxx) maxx = x;
    if (y < miny) miny = y;
    if (y > maxy) maxy = y;
  }

  if (type == PATH_TYPE_CURVE) {
    _getobj(obj, "points", inst, &points);
    num = arraynum(points) / 2;
    pdata = arraydata(points);
  }
  for (i = 1; i < num; i++) {
    x = pdata[i * 2];
    y = pdata[i * 2 + 1];
    arrayadd(array, &x);
    arrayadd(array, &y);
  }

  if (stroke) {
    if (head == ARROW_POSITION_BEGIN || head == ARROW_POSITION_BOTH) {
      for (i = 0; i < 3; i++) {
	if (ap[i * 2] < minx) minx = ap[i * 2];
	if (ap[i * 2] > maxx) maxx = ap[i * 2];
	if (ap[i * 2 + 1] < miny) miny = ap[i * 2 + 1];
	if (ap[i * 2 + 1] > maxy) maxy = ap[i * 2 + 1];
      }
    }
    if (head == ARROW_POSITION_END || head == ARROW_POSITION_BOTH) {
      for (i = 0; i < 3 ; i++) {
	if (ap2[i * 2] < minx) minx = ap2[i * 2];
	if (ap2[i * 2] > maxx) maxx = ap2[i * 2];
	if (ap2[i * 2 + 1] < miny) miny = ap2[i * 2+ 1];
	if (ap2[i * 2 + 1] > maxy) maxy = ap2[i * 2 + 1];
      }
    }

    minx -= width / 2;
    miny -= width / 2;
    maxx += width / 2;
    maxy += width / 2;
  }

  arrayins(array, &(maxy), 0);
  arrayins(array, &(maxx), 0);
  arrayins(array, &(miny), 0);
  arrayins(array, &(minx), 0);

  if (arraynum(array) == 0) {
    arrayfree(array);
    rval->array = NULL;
    return 1;
  }

  rval->array = array;

  return 0;
}
Example #8
0
void
free_br(struct batch_request *preq)
{
	delete_link(&preq->rq_link);
	reply_free(&preq->rq_reply);

	if (preq->rq_parentbr) {
		/*
		 * have a parent who has the original info, so we cannot
		 * free any data malloc-ed outside of the basic structure;
		 * decrement the reference count in the parent and when it
		 * goes to zero,  reply_send() it
		 */
		if (preq->rq_parentbr->rq_refct > 0) {
			if (--preq->rq_parentbr->rq_refct == 0)
				reply_send(preq->rq_parentbr);
		}

		if (preq->rppcmd_msgid)
			free(preq->rppcmd_msgid);

		(void)free(preq);
		return;
	}

	/*
	 * IMPORTANT - free any data that is malloc-ed outside of the
	 * basic batch_request structure below here so it is not freed
	 * when a copy of the structure (for a Array subjob) is freed
	 */
	if (preq->rq_extend)
		(void)free(preq->rq_extend);

	switch (preq->rq_type) {
		case PBS_BATCH_QueueJob:
			free_attrlist(&preq->rq_ind.rq_queuejob.rq_attr);
			break;
		case PBS_BATCH_JobCred:
			if (preq->rq_ind.rq_jobcred.rq_data)
				(void)free(preq->rq_ind.rq_jobcred.rq_data);
			break;
		case PBS_BATCH_UserCred:
			if (preq->rq_ind.rq_usercred.rq_data)
				(void)free(preq->rq_ind.rq_usercred.rq_data);
			break;
		case PBS_BATCH_GSS_Context:
			if (preq->rq_ind.rq_gssdata.rq_data)
				free(preq->rq_ind.rq_gssdata.rq_data);
			break;
		case PBS_BATCH_jobscript:
			if (preq->rq_ind.rq_jobfile.rq_data)
				(void)free(preq->rq_ind.rq_jobfile.rq_data);
			break;
		case PBS_BATCH_CopyHookFile:
			if (preq->rq_ind.rq_hookfile.rq_data)
				(void)free(preq->rq_ind.rq_hookfile.rq_data);
			break;
		case PBS_BATCH_HoldJob:
			freebr_manage(&preq->rq_ind.rq_hold.rq_orig);
			break;
		case PBS_BATCH_MessJob:
			if (preq->rq_ind.rq_message.rq_text)
				(void)free(preq->rq_ind.rq_message.rq_text);
			break;
		case PBS_BATCH_RelnodesJob:
			if (preq->rq_ind.rq_relnodes.rq_node_list)
				(void)free(preq->rq_ind.rq_relnodes.rq_node_list);
			break;
		case PBS_BATCH_PySpawn:
			arrayfree(preq->rq_ind.rq_py_spawn.rq_argv);
			arrayfree(preq->rq_ind.rq_py_spawn.rq_envp);
			break;
		case PBS_BATCH_ModifyJob:
		case PBS_BATCH_ModifyResv:
			freebr_manage(&preq->rq_ind.rq_modify);
			break;

		case PBS_BATCH_RunJob:
		case PBS_BATCH_AsyrunJob:
		case PBS_BATCH_StageIn:
		case PBS_BATCH_ConfirmResv:
			if (preq->rq_ind.rq_run.rq_destin)
				(void)free(preq->rq_ind.rq_run.rq_destin);
			break;
		case PBS_BATCH_StatusJob:
		case PBS_BATCH_StatusQue:
		case PBS_BATCH_StatusNode:
		case PBS_BATCH_StatusSvr:
		case PBS_BATCH_StatusSched:
		case PBS_BATCH_StatusHook:
		case PBS_BATCH_StatusRsc:
		case PBS_BATCH_StatusResv:
			if (preq->rq_ind.rq_status.rq_id)
				free(preq->rq_ind.rq_status.rq_id);
			free_attrlist(&preq->rq_ind.rq_status.rq_attr);
			break;
		case PBS_BATCH_CopyFiles:
		case PBS_BATCH_DelFiles:
			freebr_cpyfile(&preq->rq_ind.rq_cpyfile);
			break;
		case PBS_BATCH_CopyFiles_Cred:
		case PBS_BATCH_DelFiles_Cred:
			freebr_cpyfile_cred(&preq->rq_ind.rq_cpyfile_cred);
			break;
		case PBS_BATCH_MvJobFile:
			if (preq->rq_ind.rq_jobfile.rq_data)
				free(preq->rq_ind.rq_jobfile.rq_data);
			break;

#ifndef PBS_MOM		/* Server Only */

		case PBS_BATCH_SubmitResv:
			free_attrlist(&preq->rq_ind.rq_queuejob.rq_attr);
			break;
		case PBS_BATCH_Manager:
			freebr_manage(&preq->rq_ind.rq_manager);
			break;
		case PBS_BATCH_ReleaseJob:
			freebr_manage(&preq->rq_ind.rq_release);
			break;
		case PBS_BATCH_Rescq:
		case PBS_BATCH_ReserveResc:
		case PBS_BATCH_ReleaseResc:
			free_rescrq(&preq->rq_ind.rq_rescq);
			break;
		case PBS_BATCH_DefSchReply:
			free(preq->rq_ind.rq_defrpy.rq_id);
			free(preq->rq_ind.rq_defrpy.rq_txt);
			break;
		case PBS_BATCH_SelectJobs:
		case PBS_BATCH_SelStat:
			free_attrlist(&preq->rq_ind.rq_select.rq_selattr);
			free_attrlist(&preq->rq_ind.rq_select.rq_rtnattr);
			break;
#endif /* PBS_MOM */
	}
	if (preq->rppcmd_msgid)
		free(preq->rppcmd_msgid);
	(void)free(preq);
}
Example #9
0
int
ngraph_object_put(struct objlist *obj, const char *vname, int id, ngraph_value *val)
{
  enum ngraph_object_field_type type;
  int r;
  void *valp;
  struct narray *array;

  r = -1;

  type = chkobjfieldtype(obj, vname);
  switch (type) {
  case NVOID:
#if USE_LABEL
  case NLABEL:
#endif
  case NVFUNC:
    valp = NULL;
    r = putobj(obj, vname, id, valp);
    break;
  case NSTR:
  case NOBJ:
    if (val->str) {
      valp = g_strdup(val->str);
    } else {
      valp = NULL;
    }
    r = putobj(obj, vname, id, valp);
    if (r < 0 && valp) {
      g_free(valp);
    }
    break;
  case NPOINTER:		/* these fields may not be writable */
  case NBFUNC:
  case NIFUNC:
  case NDFUNC:
  case NSFUNC:
  case NIAFUNC:
  case NDAFUNC:
  case NSAFUNC:
    valp = NULL;
    r = putobj(obj, vname, id, valp);
    break;
  case NBOOL:
  case NINT:
  case NENUM:
    valp = &val->i;
    r = putobj(obj, vname, id, valp);
    break;
  case NDOUBLE:
    valp = &val->d;
    r = putobj(obj, vname, id, valp);
    break;
  case NIARRAY:
    array = allocate_iarray(val->ary);
    r = putobj(obj, vname, id, array);
    if (r < 0) {
      arrayfree(array);
    }
    break;
  case NDARRAY:
    array = allocate_darray(val->ary);
    r = putobj(obj, vname, id, array);
    if (r < 0) {
      arrayfree(array);
    }
    break;
  case NSARRAY:
    array = allocate_sarray(val->ary);
    r = putobj(obj, vname, id, array);
    if (r < 0) {
      arrayfree2(array);
    }
    break;
  }

  return r;
}