Пример #1
0
void start_dl(proj) {

	arg_init(&proj);

	CHAIN_FUNCTION(opt, init, htsshow_init, &proj);
	CHAIN_FUNCTION(opt, uninit, htsshow_uninit, &proj);
	CHAIN_FUNCTION(opt, start, htsshow_start, &proj);
	CHAIN_FUNCTION(opt, end, htsshow_end, &proj);
	CHAIN_FUNCTION(opt, chopt, htsshow_chopt, &proj);
	CHAIN_FUNCTION(opt, preprocess, htsshow_preprocesshtml, &proj);
	CHAIN_FUNCTION(opt, postprocess, htsshow_postprocesshtml, &proj);
	CHAIN_FUNCTION(opt, check_html, htsshow_checkhtml, &proj);
	CHAIN_FUNCTION(opt, query, htsshow_query, &proj);
	CHAIN_FUNCTION(opt, query2, htsshow_query2, &proj);
	CHAIN_FUNCTION(opt, query3, htsshow_query3, &proj);
	CHAIN_FUNCTION(opt, loop, htsshow_loop, &proj);
	CHAIN_FUNCTION(opt, check_link, htsshow_check, &proj);
	CHAIN_FUNCTION(opt, check_mime, htsshow_check_mime, &proj);
	CHAIN_FUNCTION(opt, pause, htsshow_pause, &proj);
	CHAIN_FUNCTION(opt, filesave, htsshow_filesave, &proj);
	CHAIN_FUNCTION(opt, filesave2, htsshow_filesave2, &proj);
	CHAIN_FUNCTION(opt, linkdetected, htsshow_linkdetected, &proj);
	CHAIN_FUNCTION(opt, linkdetected2, htsshow_linkdetected2, &proj);
	CHAIN_FUNCTION(opt, xfrstatus, htsshow_xfrstatus, &proj);
	CHAIN_FUNCTION(opt, savename, htsshow_savename, &proj);
	CHAIN_FUNCTION(opt, sendhead, htsshow_sendheader, &proj);
	CHAIN_FUNCTION(opt, receivehead, htsshow_receiveheader, &proj);

	if (hts_main2(proj.argc, proj.argv, opt)) {
		fprintf(stderr, "hts_main2 with error %s\n", hts_errmsg(opt));
	}
}
Пример #2
0
main(int argc,char *argv[]){
	int x=0;
	arg_init(getenv("test_arg"),argc,argv);
	do{
		x=arg_next();
		printf("r=%d (%d)'%s'\n",x,argarg,argarg);
	}while(x >= 0);
}
Пример #3
0
static void modules_init()
{
  int i;

  /* sanity checks for modules */
  module_sanity_check();

  /* initialize format modules */
  for (i=0;st_formats[i];i++) {
    arg_init(st_formats[i]);
  }
}
Пример #4
0
int trap_send_v3(TrapReceiver *tRcv, TrapList *tV3UserList, TrapData *tData)
{
	#if 0
	struct arg arg;
	TrapNode *tV3UserNode, *tParamNode;
	TrapParam *tParam;
	TrapV3User *tV3User;

	for (tV3UserNode = tV3UserList->first; tV3UserNode; tV3UserNode = tV3UserNode->next) {
		tV3User = tV3UserNode->data;
		arg_init(&arg, 100, 20);
		arg_append(&arg, "snmptrap");
		arg_append(&arg, "-v");
		arg_append(&arg, "3");
		arg_append(&arg, "-u");
		arg_append(&arg, tV3User->username);
		if (strlen(tV3User->auth_type) > 0 && strlen(tV3User->auth_passwd) > 0){
			arg_append(&arg, "-a");
			arg_append(&arg, tV3User->auth_type);
			arg_append(&arg, "-A");
			arg_append(&arg, tV3User->auth_passwd);
		}
		if (strlen(tV3User->priv_type) > 0 && strlen(tV3User->priv_passwd) > 0){
			arg_append(&arg, "-x");
			arg_append(&arg, tV3User->priv_type);
			arg_append(&arg, "-X");
			arg_append(&arg, tV3User->priv_passwd);
		}
		char addr[100];
		snprintf(addr, sizeof(addr), "%s:%hd", tRcv->rcv_ip, 162);
		arg_append(&arg, addr);
		
		char tm[100];
		snprintf(tm, sizeof(tm), "%ul", time(0)*100);
		arg_append(&arg, tm);
		arg_append(&arg, tData->oid);

		for (tParamNode = tData->paramList.first; tParamNode; tParamNode = tParamNode->next){
			tParam = tParamNode->data;
			arg_append(&arg, tParam->oid);
			char buf[10];
			sprintf(buf, "%c", tParam->type);
			arg_append(&arg, buf);
			arg_append(&arg, tParam->value);
		}
	
		trap_exec(arg.argc, arg.argv);

		arg_destroy(&arg);
	}
	#endif
	return 0;
}
Пример #5
0
int arg_match(struct arg *arg_, const struct arg_def *def, char **argv)
{
    struct arg arg;

    if (!argv[0] || argv[0][0] != '-')
        return 0;

    arg = arg_init(argv);

    if (def->short_name
            && strlen(arg.argv[0]) == strlen(def->short_name) + 1
            && !strcmp(arg.argv[0] + 1, def->short_name))
    {

        arg.name = arg.argv[0] + 1;
        arg.val = def->has_val ? arg.argv[1] : NULL;
        arg.argv_step = def->has_val ? 2 : 1;
    }
    else if (def->long_name)
    {
        int name_len = strlen(def->long_name);

        if (strlen(arg.argv[0]) >= name_len + 2
                && arg.argv[0][1] == '-'
                && !strncmp(arg.argv[0] + 2, def->long_name, name_len)
                && (arg.argv[0][name_len+2] == '='
                    || arg.argv[0][name_len+2] == '\0'))
        {

            arg.name = arg.argv[0] + 2;
            arg.val = arg.name[name_len] == '=' ? arg.name + name_len + 1 : NULL;
            arg.argv_step = 1;
        }
    }

    if (arg.name && !arg.val && def->has_val)
        die("Error: option %s requires argument.\n", arg.name);

    if (arg.name && arg.val && !def->has_val)
        die("Error: option %s requires no argument.\n", arg.name);

    if (arg.name
            && (arg.val || !def->has_val))
    {
        arg.def = def;
        *arg_ = arg;
        return 1;
    }

    return 0;
}
Пример #6
0
Файл: arg.c Проект: lh3/fastARG
arg_t *arg_dup(const arg_t *a)
{
	int i;
	arg_t *aa;
	aa = arg_init();
	*aa = *a;
	aa->max_size = a->root + 1;
	aa->rootseq = calloc((a->m + 63)/64, 8);
	memcpy(aa->rootseq, a->rootseq, (a->m+63)/64*8);
	aa->node = calloc(a->root+1, sizeof(argnode_t));
	memcpy(aa->node, a->node, (a->root+1) * sizeof(argnode_t));
	for (i = 0; i <= a->root; ++i) {
		argnode_t *p = aa->node + i;
		if (p->n_mut > 0) {
			p->mut = malloc(p->n_mut * sizeof(int));
			memcpy(p->mut, a->node[i].mut, p->n_mut * sizeof(int));
		}
	}
	return aa;
}
Пример #7
0
int main(int argc, char *argv[])
{
    arg_init(argc,argv);
#else
int main(void)
{
#endif
    sched_init(); //init scheduler--THIS MUST BE FIRST
    mos_led_init(); //init leds early, to allow led debugging elsewhere
    com_init(); //init com system

#ifdef MOS_DEBUG
    mos_debug_init();
#endif
    mos_thread_new(pre_start, START_STACK_SIZE, PRIORITY_NORMAL);

    //start the scheduler (never returns)
    mos_sched_start();

    return 0;
}
Пример #8
0
void FFI_HIDDEN
ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
			void *stack)
{
  ffi_cif *cif = closure->cif;
  void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
  void *rvalue = NULL;
  int i;
  struct arg_state state;

  arg_init (&state, ALIGN(cif->bytes, 16));

  for (i = 0; i < cif->nargs; i++)
    {
      ffi_type *ty = cif->arg_types[i];

      switch (ty->type)
	{
	case FFI_TYPE_VOID:
	  FFI_ASSERT (0);
	  break;

	case FFI_TYPE_UINT8:
	case FFI_TYPE_SINT8:
	case FFI_TYPE_UINT16:
	case FFI_TYPE_SINT16:
	case FFI_TYPE_UINT32:
	case FFI_TYPE_SINT32:
	case FFI_TYPE_INT:
	case FFI_TYPE_POINTER:
	case FFI_TYPE_UINT64:
	case FFI_TYPE_SINT64:
	case  FFI_TYPE_FLOAT:
	case  FFI_TYPE_DOUBLE:
#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
	case  FFI_TYPE_LONGDOUBLE:
	  avalue[i] = allocate_to_register_or_stack (context, stack,
						     &state, ty->type);
	  break;
#endif

	case FFI_TYPE_STRUCT:
	  if (is_hfa (ty))
	    {
	      unsigned n = element_count (ty);
	      if (available_v (&state) < n)
		{
		  state.nsrn = N_V_ARG_REG;
		  avalue[i] = allocate_to_stack (&state, stack, ty->alignment,
						 ty->size);
		}
	      else
		{
		  switch (get_homogeneous_type (ty))
		    {
		    case FFI_TYPE_FLOAT:
		      {
			/* Eeek! We need a pointer to the structure,
			   however the homogeneous float elements are
			   being passed in individual S registers,
			   therefore the structure is not represented as
			   a contiguous sequence of bytes in our saved
			   register context. We need to fake up a copy
			   of the structure laid out in memory
			   correctly. The fake can be tossed once the
			   closure function has returned hence alloca()
			   is sufficient. */
			int j;
			UINT32 *p = avalue[i] = alloca (ty->size);
			for (j = 0; j < element_count (ty); j++)
			  memcpy (&p[j],
				  allocate_to_s (context, &state),
				  sizeof (*p));
			break;
		      }

		    case FFI_TYPE_DOUBLE:
		      {
			/* Eeek! We need a pointer to the structure,
			   however the homogeneous float elements are
			   being passed in individual S registers,
			   therefore the structure is not represented as
			   a contiguous sequence of bytes in our saved
			   register context. We need to fake up a copy
			   of the structure laid out in memory
			   correctly. The fake can be tossed once the
			   closure function has returned hence alloca()
			   is sufficient. */
			int j;
			UINT64 *p = avalue[i] = alloca (ty->size);
			for (j = 0; j < element_count (ty); j++)
			  memcpy (&p[j],
				  allocate_to_d (context, &state),
				  sizeof (*p));
			break;
		      }

#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
		    case FFI_TYPE_LONGDOUBLE:
			  memcpy (&avalue[i],
				  allocate_to_v (context, &state),
				  sizeof (*avalue));
		      break;
#endif

		    default:
		      FFI_ASSERT (0);
		      break;
		    }
		}
	    }
	  else if (ty->size > 16)
	    {
	      /* Replace Composite type of size greater than 16 with a
		 pointer.  */
	      memcpy (&avalue[i],
		      allocate_to_register_or_stack (context, stack,
						     &state, FFI_TYPE_POINTER),
		      sizeof (avalue[i]));
	    }
	  else if (available_x (&state) >= (ty->size + 7) / 8)
	    {
	      avalue[i] = get_x_addr (context, state.ngrn);
	      state.ngrn += (ty->size + 7) / 8;
	    }
	  else
	    {
	      state.ngrn = N_X_ARG_REG;

	      avalue[i] = allocate_to_stack (&state, stack, ty->alignment,
					     ty->size);
	    }
	  break;

	default:
	  FFI_ASSERT (0);
	  break;
	}
    }

  /* Figure out where the return value will be passed, either in
     registers or in a memory block allocated by the caller and passed
     in x8.  */

  if (is_register_candidate (cif->rtype))
    {
      /* Register candidates are *always* returned in registers. */

      /* Allocate a scratchpad for the return value, we will let the
         callee scrible the result into the scratch pad then move the
         contents into the appropriate return value location for the
         call convention.  */
      rvalue = alloca (cif->rtype->size);
      (closure->fun) (cif, rvalue, avalue, closure->user_data);

      /* Copy the return value into the call context so that it is returned
         as expected to our caller.  */
      switch (cif->rtype->type)
        {
        case FFI_TYPE_VOID:
          break;

        case FFI_TYPE_UINT8:
        case FFI_TYPE_UINT16:
        case FFI_TYPE_UINT32:
        case FFI_TYPE_POINTER:
        case FFI_TYPE_UINT64:
        case FFI_TYPE_SINT8:
        case FFI_TYPE_SINT16:
        case FFI_TYPE_INT:
        case FFI_TYPE_SINT32:
        case FFI_TYPE_SINT64:
        case FFI_TYPE_FLOAT:
        case FFI_TYPE_DOUBLE:
#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
        case FFI_TYPE_LONGDOUBLE:
#endif
	  {
	    void *addr = get_basic_type_addr (cif->rtype->type, context, 0);
	    copy_basic_type (addr, rvalue, cif->rtype->type);
            break;
	  }
        case FFI_TYPE_STRUCT:
          if (is_hfa (cif->rtype))
	    {
	      int j;
	      unsigned short type = get_homogeneous_type (cif->rtype);
	      unsigned elems = element_count (cif->rtype);
	      for (j = 0; j < elems; j++)
		{
		  void *reg = get_basic_type_addr (type, context, j);
		  copy_basic_type (reg, rvalue, type);
		  rvalue += get_basic_type_size (type);
		}
	    }
          else if ((cif->rtype->size + 7) / 8 < N_X_ARG_REG)
            {
              size_t size = ALIGN (cif->rtype->size, sizeof (UINT64)) ;
              memcpy (get_x_addr (context, 0), rvalue, size);
            }
          else
            {
              FFI_ASSERT (0);
            }
          break;
        default:
          FFI_ASSERT (0);
          break;
        }
    }
  else
    {
      memcpy (&rvalue, get_x_addr (context, 8), sizeof (UINT64));
      (closure->fun) (cif, rvalue, avalue, closure->user_data);
    }
}
Пример #9
0
static unsigned
aarch64_prep_args (struct call_context *context, unsigned char *stack,
		   extended_cif *ecif)
{
  int i;
  struct arg_state state;

  arg_init (&state, ALIGN(ecif->cif->bytes, 16));

  for (i = 0; i < ecif->cif->nargs; i++)
    {
      ffi_type *ty = ecif->cif->arg_types[i];
      switch (ty->type)
	{
	case FFI_TYPE_VOID:
	  FFI_ASSERT (0);
	  break;

	/* If the argument is a basic type the argument is allocated to an
	   appropriate register, or if none are available, to the stack.  */
	case FFI_TYPE_FLOAT:
	case FFI_TYPE_DOUBLE:
#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
	case FFI_TYPE_LONGDOUBLE:
#endif
	case FFI_TYPE_UINT8:
	case FFI_TYPE_SINT8:
	case FFI_TYPE_UINT16:
	case FFI_TYPE_SINT16:
	case FFI_TYPE_UINT32:
	case FFI_TYPE_INT:
	case FFI_TYPE_SINT32:
	case FFI_TYPE_POINTER:
	case FFI_TYPE_UINT64:
	case FFI_TYPE_SINT64:
	  copy_to_register_or_stack (context, stack, &state,
				     ecif->avalue[i], ty->type);
	  break;

	case FFI_TYPE_STRUCT:
	  if (is_hfa (ty))
	    {
	      copy_hfa_to_reg_or_stack (ecif->avalue[i], ty, context,
					stack, &state);
	    }
	  else if (ty->size > 16)
	    {
	      /* If the argument is a composite type that is larger than 16
		 bytes, then the argument has been copied to memory, and
		 the argument is replaced by a pointer to the copy.  */

	      copy_to_register_or_stack (context, stack, &state,
					 &(ecif->avalue[i]), FFI_TYPE_POINTER);
	    }
	  else if (available_x (&state) >= (ty->size + 7) / 8)
	    {
	      /* If the argument is a composite type and the size in
		 double-words is not more than the number of available
		 X registers, then the argument is copied into consecutive
		 X registers.  */
	      int j;
	      for (j = 0; j < (ty->size + 7) / 8; j++)
		{
		  memcpy (allocate_to_x (context, &state),
			  &(((UINT64 *) ecif->avalue[i])[j]),
			  sizeof (UINT64));
		}
	    }
	  else
	    {
	      /* Otherwise, there are insufficient X registers. Further X
		 register allocations are prevented, the NSAA is adjusted
		 (by allocate_to_stack ()) and the argument is copied to
		 memory at the adjusted NSAA.  */
	      state.ngrn = N_X_ARG_REG;

	      memcpy (allocate_to_stack (&state, stack, ty->alignment,
					 ty->size), ecif->avalue + i, ty->size);
	    }
	  break;

	default:
	  FFI_ASSERT (0);
	  break;
	}
    }

  return ecif->cif->aarch64_flags;
}
Пример #10
0
static int
_steph_Cmd_ (ClientData clientData,
	  Tcl_Interp *interp,
	  int        argc,
	  char       **argv)
{ 
  /* Command line definition */
  char * options[] = {
    "",
    "cmdlist", "",
    NULL
  };

  char * helpMsg = {
    (
     " List the C-defined commands of the package.\n"
     "\n"
     "Parameters :\n"
     "  none."
     )
  };

  /* Command's parameters */

  /* Options's presence */
  int isCmdlist;

  /* Options's parameters */

  /* Other variables */
  register cmdInfo *cmdInfoPtr;

  /* Command line analysis */
  if (arg_init (interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get (0) == TCL_ERROR)
    return TCL_ERROR;

  isCmdlist = arg_present (1);

  /* Parameters validity and initialisation */

  /* Treatement */
  if (isCmdlist) {
    Tcl_AppendResult (interp, "{", (char *) NULL);

    cmdInfoPtr = StephCmdInfoArray;
    Tcl_AppendResult (interp, cmdInfoPtr->name, (char *) NULL);
    for (cmdInfoPtr++;
	 cmdInfoPtr->name != NULL;
	 cmdInfoPtr++) {
      Tcl_AppendResult (interp, " ", cmdInfoPtr->name, (char *) NULL);
    }
    Tcl_AppendResult (interp, "}", (char *) NULL);
  } else {
    sprintf (interp->result, "The steph package blablabla.");
  }

  return TCL_OK;
}
Пример #11
0
static int
_bic_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      

{

  /* Command line definition */
  char * options[] = {
    "SSSs",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by with a bic model (correlation functions of fractionnal brownian).\n"
     " y=s^2*pow(fabs(x+d),2.*h)+pow(fabs(x-d),2.*h)-2.*pow(fabs(x),2.*h)/2.\n"
     "\n"
     "Arguments :\n"
     "  3 signals - signal to fit, \n"
     "              signal containing the incertaity for each point, \n"
     "              signal containing the initial values (s,h,d).\n"
     "  string    - name of the result (s,h,d,chisq,goodness,covar --> size=14)\n."
     "\n"
     "Options :\n"
     "   -fit   : signal containing the x-value (REALY)\n" 
     "            --> return the bic fit in this signal (REALXY).\n"
     )
  };

  Signal *datasignal,*sigmasignal, *valsignal;
  Signal *result, *xsignal = NULL;
  char   *resultName;
  int i,j,size;
  
  real *X;
  int ma;
  int *ia;
  real *a,**covar,**alpha;
  real chisq;
  
  int u;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &sigmasignal, &valsignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  size = datasignal->size;
  if(sigmasignal->size != size) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }
  
  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->x0 + i*datasignal->dx;
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->dataX[i]; 
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }

  ma = valsignal->size;
  if (ma != 3) {
    Tcl_AppendResult (interp,
		      "Bad number of initial value (we need 3 values s,h and d).",
		      (char *) NULL);
    return TCL_ERROR;
  }
  NonLinFitInit(&a,&ia,ma,&covar,&alpha);
  for(i=0;i<valsignal->size;i++)
	{
	  a[i+1]=valsignal->dataY[i];
	  ia[i+1] = 1;
	}
  NonLinFit(X-1,datasignal->dataY-1,sigmasignal->dataY-1,size,a,ia,ma,covar,alpha,
		&chisq,&BrowIncrCorr);


  result = sig_new (REALY, 0, ma+ma*ma+1);
  result->x0 = 0.0;
  result->dx = 1;
  u =0;
  for(i=1;i<=ma;i++) {
    result->dataY[u]=a[i];
    u=u+1;
  }
  result->dataY[u++]=chisq;
  result->dataY[u++]=NonLinFitConfidence(chisq,size,ma);
  for(i=1;i<=ma;i++) {
    	  for(j=1;j<=ma;j++)
	    {	      
	      result->dataY[u++]=covar[i][j];
	    }
  }


  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(1)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      sig_realy2realxy(xsignal);
      sig_put_y_in_x(xsignal);
      for (i=0;i<xsignal->size;i++) 
	BrowIncrCorr(xsignal->dataX[i],a,&(xsignal->dataY[i]),NULL,ma);

    }


  }

  NonLinFitDelete(a,ia,ma,covar,alpha);

  return TCL_OK;

}
Пример #12
0
static int
_mwc_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      

{

  /* Command line definition */
  char * options[] = {
    "SSSs",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by with a mwc model (model for tensio-actif membrane).\n"
     "  (y=f0*prefactor*(85*(h0/x-0.5 +0.1 -x^5/(h0^5*320)- 0.5 + x^2/(h0^2*8.))\n"
     " + 0.5*(h0-x/2.+h0*log(2.*h0/x)) - (h0-x/2.)/10. + (64.*h0^6 - x^6)/(3840.*h0^5)\n"
     " + (h0-x/2.)/2. - (8*h0^3-x^3)/(48*h0^2)).\n"
     "\n"
     "Arguments :\n"
     "  3 signals - signal to fit, \n"
     "              signal containing the incertaity for each point, \n"
     "              signal containing the initial values (h0,f0).\n"
     "  string    - name of the result (h0,f0,chisq,goodness,covar --> size=8)\n."
     "\n"
     "Options :\n"
     "   -fit   : signal containing the x-value (REALY)\n" 
     "            --> return the mwc fit in this signal (REALXY).\n"
     )
  };

  Signal *datasignal,*sigmasignal, *valsignal;
  Signal *result, *xsignal = NULL;
  char   *resultName;
  int i,j,size;
  
  real *X;
  int ma;
  int *ia;
  real *a,**covar,**alpha;
  real chisq;
  
  int u;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &sigmasignal, &valsignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  size = datasignal->size;
  if(sigmasignal->size != size) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }
  
  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->x0 + i*datasignal->dx;
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) 
	X[i] = datasignal->dataX[i]; 
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }

  ma = valsignal->size;
  if (ma != 2) {
    Tcl_AppendResult (interp,
		      "Bad number of initial value (we need 2 values h0 and f0).",
		      (char *) NULL);
    return TCL_ERROR;
  }
  NonLinFitInit(&a,&ia,ma,&covar,&alpha);
  for(i=0;i<valsignal->size;i++)
	{
	  a[i+1]=valsignal->dataY[i];
	  ia[i+1] = 1;
	}
  NonLinFit(X-1,datasignal->dataY-1,sigmasignal->dataY-1,size,a,ia,ma,covar,alpha,
		&chisq,&MWC);


  result = sig_new (REALY, 0, ma+ma*ma+1);
  result->x0 = 0.0;
  result->dx = 1;
  u =0;
  for(i=1;i<=ma;i++) {
    result->dataY[u]=a[i];
    u=u+1;
  }
  result->dataY[u++]=chisq;
  result->dataY[u++]=NonLinFitConfidence(chisq,size,ma);
  for(i=1;i<=ma;i++) {
    	  for(j=1;j<=ma;j++)
	    {	      
	      result->dataY[u++]=covar[i][j];
	    }
  }


  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(1)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      sig_realy2realxy(xsignal);
      sig_put_y_in_x(xsignal);
      for (i=0;i<xsignal->size;i++) 
	MWC(xsignal->dataX[i],a,&(xsignal->dataY[i]),NULL,ma);

    }


  }

  NonLinFitDelete(a,ia,ma,covar,alpha);

  return TCL_OK;

}
Пример #13
0
static int
_lf_Cmd_ (ClientData clientData,
	   Tcl_Interp *interp,
	   int        argc,
	   char       **argv)      
{
  /* Command line definition */
  char * options[] = {
    "Ss",
    "-x","ff",
    "-sigma","S",
    "-fit","S",
    NULL
  };

  char * helpMsg = {
    (
     "  Fit the data by a straight line (y=ax+b)."
     "\n"
     "Arguments :\n"
     "  1 signal - signal to fit.\n"
     "  string    - name of the result (a, b,siga,sigb,chi2,goodness-of-fit)\n."
     "\n"
     "Options :\n"
     "   -x     : domain to fit.\n"
     "   -sigma : signal containing the dy of each points of the signal to fit.\n"
     "   -fit   : signal containing the x-value (REALY)\n"
     "            --> return y=ax+b in this signal (REALXY).\n"
     )
  };

  /* Command's parameters */
  Signal *datasignal,*sigmasignal =  NULL, *result, *xsignal = NULL;
  char   *resultName;
  real   xMin,xMax;
  int flagWithWeight=0;
  int size,i;
  real *X, *sigmaY;
  real a,b,siga,sigb,chi2,q;
  int iMin, iMax;


  xMin=1.0;
  xMax=-1.0;

  if (arg_init(interp, argc, argv, options, helpMsg))
    return TCL_OK;
  
  if (arg_get(0, &datasignal, &resultName) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(1, &xMin, &xMax) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(2, &sigmasignal) == TCL_ERROR)
    return TCL_ERROR;

  if (arg_get(3, &xsignal) == TCL_ERROR)
    return TCL_ERROR;

  if ((arg_present(2) && (datasignal->size != sigmasignal ->size))) {
    Tcl_AppendResult (interp,
		      "The sigma signal should be of the same size as the input signal.",
		      (char *) NULL);
    return TCL_ERROR;
  }


  size = datasignal->size;

  if (datasignal->type == REALY) 
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) { 
	X[i] = datasignal->x0 + i*datasignal->dx;
      }
    }
  else if (datasignal->type == REALXY)
    {
      X = (float *) malloc(sizeof(float)*size);
      for(i=0;i<size;i++) { 
	X[i] = datasignal->dataX[i];
      }
    }
  else {
        Tcl_AppendResult (interp,
		      "Bad type for the signal (only REALY or REALXY).",
		      (char *) NULL);
    return TCL_ERROR;
  }
    
  if (arg_present(2))
    {
      sigmaY = sigmasignal->dataY - 1;
      flagWithWeight = 1;
    }
  else
    {
      sigmaY = NULL;
      flagWithWeight = 0;
    }

    
  iMin =0;
  iMax = size -1;

  if (arg_present(1)) {
    if (xMin >= xMax) {
      Tcl_AppendResult (interp,
			"xmin should be smaller than xmax",
			(char *) NULL);
      return TCL_ERROR;
    }
    iMin = IsigCeil(datasignal,xMin);
    iMax = IsigFloor(datasignal,xMax);
  }

  size = iMax - iMin + 1;
  printf("imin=%d %d\n",iMin,iMax);
  
  if(size <= 1) {
    Tcl_AppendResult (interp,
		      "Can't fit on less than two points!!",
		      (char *) NULL);
    return TCL_ERROR;
  }

  fit(X-1+iMin,datasignal->dataY-1+iMin,size,
      ((sigmaY == NULL) ? sigmaY : sigmaY + iMin),
      flagWithWeight,&a,&b,&siga,&sigb,&chi2,&q);
 
  free(X);

  result = sig_new (REALY, 0, 5);
  result->x0 = 0.0;
  result->dx = 1;
  result->dataY[0]=a;
  result->dataY[1]=b;
  result->dataY[2]=siga;
  result->dataY[3]=sigb;
  result->dataY[4]=chi2;
  result->dataY[5]=q;
  if (!result)
    return TCL_ERROR;
  
  store_signal_in_dictionary(resultName, result);
  
  if (arg_present(3)) {
    if (xsignal->type != REALY) {
      Tcl_AppendResult (interp,
			"Type for xsignal must be REALY!!",
			(char *) NULL);
      return TCL_ERROR;
    }
    else {
      /*    DEMAIN REGARDER COMMENT CHANGER REALY EN REALXY
	    size=xsignal->size;
    X = (float *) malloc(sizeof(float)*size);      
    X = xsignal->dataY;
    sig_free(xsignal);
    */
    }


  }
  return TCL_OK;
}
Пример #14
0
int
_my_iinssig_Cmd_ (ClientData clientData,
		       Tcl_Interp *interp,
		       int        argc,
		       char       **argv)
{ 
  /* Command line definition */
  char * options[] =
  {
    "ISd",
    "-y", "",
    "-45","",
    "-m45","",
    NULL
  };

  char * help_msg =
  {
    (" Insert a signal in an image at a given position.\n"
     "\n"
     "Parameters :\n"
     "  Image   - image to treat.\n"
     "  Signal  - signal to add.\n"
     "  integer - position.\n"
     "\n"
     "Options :\n"
     "  -y   : Add in the y-direction.\n"
     "  -45  : The direction of insertion is 45 degree.\n"
     "  -m45 : The direction of insertion is m45 degree.")
  };

  /* Command's parameters */
  Image  *im;
  Signal *sig;
  int    position;

  /* Options's presence */
  int is_y,is_45, is_m45;


  /* Other variables */
  int i;
  int lx,ly;
  int x;

  /* Command line analysis */
  if (arg_init (interp, argc, argv, options, help_msg))
    return TCL_OK;
  
  if (arg_get (0, &im, &sig, &position) == TCL_ERROR)
    return TCL_ERROR;

  is_y = arg_present(1);
  is_45 = arg_present(2);
  is_m45 = arg_present(3);

  /* Parameters validity and initialisation */
  if (is_y) {
    if (sig->size > im->ly) {
      sprintf(interp->result,
	      "The signal size (%d) must be lesser than the image heigth (%d).",
	      sig->size, im->ly);
      return TCL_ERROR;
    } 
  }
  else {
    if (sig->size > im->lx) {
      sprintf(interp->result,
	      "The signal size (%d) must be lesser than the image width (%d).",
	      sig->size, im->lx);
      return TCL_ERROR;
    }
  }
  
  /* Treatement */

  lx = im->lx;
  ly = im->ly;
  for (i = 0; i < sig->size; i++) {
    x = i;
    if (is_y) {
      if ((position >= 0) && (position < ly)) {
	if (is_m45) {
	  im->data[position+lx*(ly-x-1)] = sig->dataY[i];
	} else {
	  im->data[position+lx*x] = sig->dataY[i];
	}
      }
      position = (is_45 ? position+1 : position);
      position = (is_m45 ? position+1 : position);
    } else {
      if ((position >= 0) && (position < lx)) 
	im->data[x+lx*position] = sig->dataY[i];
      position = (is_45 ? position+1 : position);
      position = (is_m45 ? position-1 : position);
    }
  }

  return TCL_OK;
}
Пример #15
0
arg_t* function_newarg(function_t *func, long long size) {
    func->args = arg_init(size, func->stack_offset, func->args);

    func->stack_offset += size;
    return func->args;
}
Пример #16
0
int BootHomebrew()
{

    char* abuf;
    size_t asize;

    if(homebrewsize == 0)
        return -1;

    entrypoint entry;
    u32 cpu_isr;

	arg_init();

	if (wiiload_args)
	{
		abuf = temp_arg;
		asize = strlen(abuf);
		while (asize != 0)
		{
			xprintf("argument = %s\n",abuf);
			arg_add(abuf);
			abuf+=asize;
			abuf+=1;
			asize = strlen(abuf);
		}
	}
	else
	{
		arg_add(filepath.c_str()); // argv[0] = filepath
		while(parser(Settings.forwarder_arg, "<arg>", "</arg>") != "")
		{
			arg_add(parser(Settings.forwarder_arg, "<arg>", "</arg>").c_str());
			Settings.forwarder_arg.erase(0, Settings.forwarder_arg.find("</arg>") +1);
		}
	}

	if ( valid_elf_image(homebrewbuffer) == 1 )
		entry = (entrypoint) load_elf_image(homebrewbuffer);
	else
		entry = (entrypoint) load_dol(homebrewbuffer, &args);

    if (!entry)
        return -1;

	//ExitApp();
//we can't use check_uneek_fs
//as we already shut down the uneek_fs system
//so it will always return false

	if (in_neek == false)
	{
		xprintf("Booting Homebrew");
		if(wiiload)
		{
			xprintf(" via wiiload\n");

			if(Options.wiiload_ahb == 2)
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Options.wiiload_ahb != 0)
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(Options.wiiload_ios);
			}
			else
				xprintf("without reloading IOS\n");
		}
		else
		{
			xprintf(" from storage device\n");
			if(Settings.force_reload == "HW_AHBPROT")
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Settings.force_reload != "NORELOAD")
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(SelectedIOS());
			}
			else
				xprintf("without IOS reload\n");
		}
	}

	wiiload_args = 0;

	/*this will also be called when wiiloading an application
	will need to check if it's expected behavour? */

/*
	if(!wiiload_args)
	{

		if(SelectedIOS() != IOS_GetVersion() || Settings.force_reload != "")
		{
			//keep ahbprot rights in new ios
			Patch_ahbprot();
			IOS_ReloadIOS(SelectedIOS());
		}
	}
    wiiload_args = 0;
*/
    SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
    _CPU_ISR_Disable (cpu_isr);
    __exception_closeall();
    entry();
    _CPU_ISR_Restore (cpu_isr);

    return 0;
}
Пример #17
0
Файл: arg.c Проект: lh3/fastARG
arg_t *arg_load(gzFile fp)
{
	kstream_t *ks;
	kstring_t *str;
	int dret, lineno = 0;
	arg_t *a;
	a = arg_init();
	ks = ks_init(fp);
	str = (kstring_t*)calloc(1, sizeof(kstring_t));
	while (ks_getuntil(ks, 0, str, &dret) >= 0) {
		int n1, n2, i;
		++lineno;
		if (str->l != 1) {
			fprintf(stderr, "[arg_load] invalid initial character at line %d\n", lineno);
			exit(1);
		}
		if (str->s[0] == 'C' || str->s[0] == 'R') {
			argnode_t *an1, *an2;
			int beg, end, n_mut;
			// read
			ks_getuntil(ks, 0, str, &dret); n1 = atoi(str->s);
			ks_getuntil(ks, 0, str, &dret); n2 = atoi(str->s);
			if (n1 <= n2) {
				fprintf(stderr, "[arg_load] invalid edge (%d)\n", lineno);
				exit(1);
			}
			// add to the node array
			if (n1 + 1 > a->max_size) {
				int old_size = a->max_size;
				a->max_size = n1 + 1;
				kroundup32(a->max_size);
				a->node = (argnode_t*)realloc(a->node, sizeof(argnode_t) * a->max_size);
				memset(a->node + old_size, 0, (a->max_size - old_size) * sizeof(argnode_t));
			}
			an1 = a->node + n1; an2 = a->node + n2;
			an1->nid = n1; an2->nid = n2;
			if (an1->n_nei == 3 || an2->n_nei == 3) {
				fprintf(stderr, "[arg_load] multifurcated node: %d or %d (%d)\n", n1, n2, lineno);
				exit(1);
			}
			an1->nei[an1->n_nei++] = n2; an2->nei[an2->n_nei++] = n1;
			// read intervals
			ks_getuntil(ks, 0, str, &dret); beg = atoi(str->s);
			ks_getuntil(ks, 0, str, &dret); end = atoi(str->s);
			if (an2->end) { // a recombination node
				if (an2->end == beg) an2->x = an2->end, an2->end = end;
				else if (an2->beg == end) { // and also swap
					int x = an2->nei[1]; an2->nei[1] = an2->nei[2]; an2->nei[2] = x;
					an2->x = an2->beg, an2->beg = beg;
				} else {
					fprintf(stderr, "[arg_load] inconsisten interval at node %d (%d)\n", n2, lineno);
					exit(1);
				}
			} else an2->beg = beg, an2->end = end;
			// read mutations
			ks_getuntil(ks, 0, str, &dret); n_mut = atoi(str->s);
			if (n_mut) {
				an2->mut = (int*)realloc(an2->mut, sizeof(int) * (an2->n_mut + n_mut));
				for (i = 0; i < n_mut; ++i) {
					ks_getuntil(ks, 0, str, &dret);
					an2->mut[an2->n_mut++] = atoi(str->s);
				}
			}
			// save interval and swap if necessary
		} else if (str->s[0] == 'N') {
			ks_getuntil(ks, 0, str, &dret); a->n = atoi(str->s);
			ks_getuntil(ks, 0, str, &dret); a->m = atoi(str->s);
		} else if (str->s[0] == 'S') {
			ks_getuntil(ks, 0, str, &dret); a->root = atoi(str->s);
			ks_getuntil(ks, 0, str, &dret);
			if (str->l != a->m) {
				fprintf(stderr, "[arg_load] inconsistent root sequence (%d)\n", lineno);
				exit(1);
			}
			a->rootseq = (uint64_t*)calloc((a->m + 63) / 64, 8);
			for (i = 0; i < a->m; ++i)
				if (str->s[i] == '1') arg_setseq1(a->rootseq, i);
		} else ks_getuntil(ks, '\n', str, &dret);
	}
	free(str->s); free(str);
	ks_destroy(ks);
	return a;
}
Пример #18
0
int main(int argc, char **argv)
{    
    uint8_t i;
    arg_init();

    if (argc<1)
    {
        usage_show();
    }
    else
    {
        i=1; //argv[0] is the command itself

        argc--; //get the real number of arguments
        while (i<=argc)
        {
            //check arguments
            if (!(strcmp("-h",argv[i])))
            {
                usage_show();
                stop_pgm("");
            }
            else if (!(strcmp("-d",argv[i])))
            {
                if (i++==argc) stop_pgm("Argument missed for option -d\n");
                memcpy(arg_dst,argv[i],strlen((const char*)argv[i])+1);
                i++;
                continue;
            }
            else if (!(strcmp("-p",argv[i])))
            {
                if (i++==argc) stop_pgm("Argument missed for option -p\n");
                arg_port=atoi(argv[i]);
                i++;
                continue;
            }
            else if (!(strcmp("-dp",argv[i])))
            {
                if (i++==argc) stop_pgm("Argument missed for option -dp\n");
                arg_dport=atoi(argv[i]);
                i++;
                continue;
            }
            else
            {
                usage_show();
                stop_pgm("\n--- Argument error ---\n");
            }

        }
    }

    pthread_t threads[NUMTHREADS];
    for (int index = 0; index < NUMTHREADS; index++) {        
        pthread_create(&threads[index], NULL, create_endpoint, (void *) &index);        
        sleep(1);
    }

    for (int i = 0; i < NUMTHREADS; i) {
        pthread_join(threads[i], NULL);
    }
    exit(0);
}