Ejemplo n.º 1
0
void                    free_shell(s_shell              *shell)
{
    history_save(shell->queue_history);

    free_history_queue(shell->queue_history);
    free_variables(shell->vars);
    free_functions(shell->func);
    free_variables(shell->alias);

    mstream_close();
    mmalloc_free();

    free(shell);
}
Ejemplo n.º 2
0
Archivo: env.cpp Proyecto: mariuz/haiku
/*!	Copies the environment from its current location into a heap managed
	environment, if it's not already there.

	This is needed whenever the environment is changed, that is, when one
	of the POSIX *env() functions is called, and we either used the environment
	provided by the kernel, or by an application that changed \c environ
	directly.
*/
static status_t
copy_environ_to_heap_if_needed(void)
{
	int32 i = 0;

	if (environ == sManagedEnviron)
		return B_OK;

	// free previously used "environ" if it has been changed by an application
	free_variables();

	sManagedEnviron = (char**)malloc((count_variables() + 1) * sizeof(char *));
	if (sManagedEnviron == NULL)
		return B_NO_MEMORY;

	if (environ != NULL) {
		// copy from previous
		for (; environ[i]; i++) {
			sManagedEnviron[i] = strdup(environ[i]);
		}
	}

	sManagedEnviron[i] = NULL;
		// null terminate the array

	environ = sManagedEnviron;
	return B_OK;
}
Ejemplo n.º 3
0
Archivo: env.cpp Proyecto: mariuz/haiku
int
clearenv(void)
{
	lock_variables();

	free_variables();
	environ = NULL;

	unlock_variables();

	return 0;
}
Ejemplo n.º 4
0
static int
intr_restart(dialogMenuItem *self)
{
    int ret, fd, fdmax;

    free_variables();
    fdmax = getdtablesize();
    for (fd = 3; fd < fdmax; fd++)
	close(fd);
    ret = execl(StartName, StartName, "-restart", (char *)NULL);
    msgDebug("execl failed (%s)\n", strerror(errno));
    /* NOTREACHED */
    return -1;
}
Ejemplo n.º 5
0
const char *translate(const char *format, const void *userdata,
    const char *vars, variant args[])
{
    unsigned int i = 0;
    const char *ic = vars;
    char symbol[32];
    char *oc = symbol;
    opstack *stack = NULL;
    const char *rv;

    brelease();
    free_variables();

    assert(format);
    assert(*ic == 0 || isalnum(*ic));
    while (*ic) {
        *oc++ = *ic++;
        if (!isalnum(*ic)) {
            variant x = args[i++];
            *oc = '\0';
            oc = symbol;
            add_variable(strcpy(balloc(strlen(symbol) + 1), symbol), x);
            while (*ic && !isalnum(*ic))
                ++ic;
        }
    }

    if (format[0] == '"') {
        rv = parse(&stack, format, userdata);
    }
    else {
        rv = parse_string(&stack, format, userdata);
    }
    if (rv != NULL) {
        if (rv[0]) {
            log_error("residual data after parsing: %s\n", rv);
        }
        rv = (const char *)opop(&stack).v;
        free(stack->begin);
        free(stack);
    }
    return rv;
}
int_list *gen(analysis_block *ablock){
	if(ablock != NULL)
	{
		block* b = getBlockWithLabel(getBlocks(),ablock->label);
		if(b != NULL)
		{
			switch(b->bType)
			{ 
			case B_SKIP:
				return NULL; break;
			case B_BOOL_EXP:
			case B_ASSIGN:
				return free_variables(b);
				break;
			}
		}
	}
	return NULL;
}
Ejemplo n.º 7
0
/**
   Free all memory allocated by the program.
   This mainly means we have to free a lot of strings
   and GArrays. */
void
free_memory(void)
{
#ifdef DEBUG
    printf("free_memory\n");
#endif

    free_variables();
    free_names(FALSE);
    free_transfer_list();
    free_strategies();
    free_country(&country, FALSE);
    free_users(FALSE);
    free_bets(FALSE);
    free_lg_commentary(FALSE);
    free_news(FALSE);
    free_newspaper(FALSE);
    free_support_dirs();
    free_jobs(FALSE);

    free_g_array(&live_games);
}
Ejemplo n.º 8
0
static void
free_filters (filter_t *filter)
{
    while (filter != 0)
    {
	filter_t *next = filter->next;

	g_free(filter->name);

	if (filter->userval_infos != NULL)
	    free_userval_infos(filter->userval_infos);

	if (filter->kind == FILTER_MATHMAP && filter->v.mathmap.variables != NULL)
	    free_variables(filter->v.mathmap.variables);
	else if (filter->kind == FILTER_NATIVE)
	    g_free(filter->v.native.func_name);

	g_free(filter);

	filter = next;
    }
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]) {
    signal(SIGINT, sighandler);
    if (argc > 1) {
        #ifdef DEBUG
        print_debug("Got file argument: %s", argv[1]);
        #endif
        FILE *file = fopen(argv[1], "r");
        if (file == NULL) {
            print_error("Could not open file for reading: %s", argv[1]);
            exit(EXIT_FAILURE);
        }
        struct matrix *mat = new_matrix(4, 1);
        screen s = new_screen();
        struct matrix *trans_mat = new_matrix(4,4);
        synchronize_variables(file, trans_mat, mat, s);
        parse_file(1);
        free_variables();
        exit(EXIT_SUCCESS);
    }

    printf("Usage: ./main [script-file]\n");

    return 0;
}
Ejemplo n.º 10
0
int l1_logreg_train(dmatrix *X, double *b, double lambda, train_opts to,
                    double *initial_x, double *initial_t, double *sol,
                    int *total_ntiter, int *total_pcgiter)
{
    /* problem data */
    problem_data_t  prob;
    variables_t     vars;

    dmatrix *matX1;     /* matX1 = diag(b)*X_std */
    dmatrix *matX2;     /* matX2 = X_std.^2 (only for pcg) */
    double *ac, *ar;
    double *avg_x, *std_x;

    int m, n, ntiter, pcgiter, status;
    double pobj, dobj, gap;
    double t, s, maxAnu;

    double *g,  *h,  *z,  *expz, *expmz;
    double *x,  *v,  *w,  *u;
    double *dx, *dv, *dw, *du;
    double *gv, *gw, *gu, *gx;
    double *d1, *d2, *Aw;

    /* pcg variables */
    pcg_status_t pcgstat;
    adata_t adata;
    mdata_t mdata;
    double *precond;

    /* temporary variables */
    double *tm1, *tn1, *tn2, *tn3, *tn4, *tx1;

    /* temporary variables for dense case (cholesky) */
    dmatrix *B;     /* m x n (or m x n) */
    dmatrix *BB;    /* n x n (or m x m) */

    char format_buf[PRINT_BUF_SIZE];

#if INTERNAL_PLOT
    dmatrix *internal_plot;
    dmat_new_dense(&internal_plot, 3, MAX_NT_ITER);
    memset(internal_plot->val,0,sizeof(double)*3*MAX_NT_ITER);
    /* row 1: cum_nt_iter, row 2: cum_pcg_iter, row 3: duality gap */
#endif

    p2func_progress print_progress = NULL;

    /*
     *  INITIALIZATION
     */
    s       =  1.0;
    pobj    =  DBL_MAX;
    dobj    = -DBL_MAX;
    pcgiter =  0;
    matX1   =  NULL;
    matX2   =  NULL;

    init_pcg_status(&pcgstat);

    dmat_duplicate(X, &matX1);
    dmat_copy(X, matX1);

    m = matX1->m;
    n = matX1->n;

    if (to.sflag == TRUE)
    {
        /* standardize_data not only standardizes the data,
           but also multiplies diag(b). */
        standardize_data(matX1, b, &avg_x, &std_x, &ac, &ar);
    }
    else
    {
        /* matX1 = diag(b)*X */
        dmat_diagscale(matX1, b, FALSE, NULL, TRUE);
        avg_x = std_x = ac = ar = NULL;
    }

    if (matX1->nz >= 0)                /* only for pcg */
    {
        dmat_elemAA(matX1, &matX2);
    }
    else
    {
        matX2 = NULL;
    }

    set_problem_data(&prob, matX1, matX2, ac, ar, b, lambda, avg_x, std_x);

    create_variables(&vars, m, n);
    get_variables(&vars, &x, &v, &w, &u, &dx, &dv, &dw, &du, &gx, &gv,
                  &gw, &gu, &g, &h, &z, &expz, &expmz, &d1, &d2, &Aw);

    allocate_temporaries(m, n, (matX1->nz >= 0),
                         &tm1, &tn1, &tn2, &tn3, &tn4, &tx1, &precond, &B, &BB);

    if (initial_x == NULL)
    {
        dmat_vset(1, 0.0, v);
        dmat_vset(n, 0.0, w);
        dmat_vset(n, 1.0, u);
        dmat_vset(n+n+1, 0, dx);
        t = min(max(1.0, 1.0 / lambda), 2.0 * n / ABSTOL);
    }
    else
    {
        dmat_vcopy(n+n+1, initial_x, x);
        dmat_vset(n+n+1, 0, dx);
        t = *initial_t;
    }

    set_adata(&adata, matX1, ac, ar, b, h, d1, d2);
    set_mdata(&mdata, m, n, precond);

    /* select printing function and format according to
           verbose level and method type (pcg/direct) */

    if (to.verbose_level>=2) init_progress((matX1->nz >= 0), to.verbose_level,
                              format_buf, &print_progress);

    /*** MAIN LOOP ************************************************************/

    for (ntiter = 0; ntiter < MAX_NT_ITER; ntiter++)
    {
        /*
         *  Sets v as the optimal value of the intercept.
         */
        dmat_yAmpqx(matX1, ac, ar, w, Aw);
        optimize_intercept(v, z, expz, expmz, tm1, b, Aw, m);

        /*
         *  Constructs dual feasible point nu.
         */
        fprimes(m, expz, expmz, g, h);

        /* partially computes the gradient of phi.
           the rest part of the gradient will be completed while computing 
           the search direction. */

        gv[0] = dmat_dot(m, b, g);              /* gv = b'*g */
        dmat_yAmpqTx(matX1, ac, ar, g, gw);     /* gw = A'*g */

        dmat_waxpby(m, -1, g, 0, NULL, tm1);    /* nu = -g   */
        maxAnu = dmat_norminf(n, gw);           /* max(A'*nu) */

        if (maxAnu > lambda)
            dmat_waxpby(m, lambda / maxAnu, tm1, 0.0, NULL, tm1);

        /*
         *  Evaluates duality gap.
         */
        pobj = logistic_loss2(m,z,expz,expmz)/m + lambda*dmat_norm1(n,w);
        dobj = max(nentropy(m, tm1) / m, dobj);
        gap  = pobj - dobj;

#if INTERNAL_PLOT
        internal_plot->val[0*MAX_NT_ITER+ntiter] = (double)ntiter;
        internal_plot->val[1*MAX_NT_ITER+ntiter] = (double)pcgiter;
        internal_plot->val[2*MAX_NT_ITER+ntiter] = gap;
#endif
        if (to.verbose_level>=2)
        {
            (*print_progress)(format_buf, ntiter, gap, pobj, dobj, s, t,
                              pcgstat.flag, pcgstat.relres, pcgstat.iter);
        }

        /*
         *  Quits if gap < tolerance.
         */
        if (gap < to.tolerance ) /***********************************************/
        {
            if (sol != NULL)
            {
                /* trim solution */
                int i;
                double lambda_threshold;

                lambda_threshold = to.ktolerance*lambda;
                sol[0] = x[0];

                for (i = 0; i < n; i++)
                {
                    sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0;
                }
                /* if standardized, sol = coeff/std */
                if (to.sflag == TRUE && to.cflag == FALSE)
                {
                    dmat_elemdivi(n, sol+1, std_x, sol+1);
                    sol[0] -= dmat_dot(n, avg_x, sol+1);
                }
            }

            if (initial_x != NULL)
            {
                dmat_vcopy(n+n+1, x, initial_x);
                *initial_t = t;
            }

            if (total_pcgiter) *total_pcgiter = pcgiter;
            if (total_ntiter ) *total_ntiter  = ntiter;

            /* free memory */
            free_variables(&vars);
            free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB);
            free_problem_data(&prob);

#if INTERNAL_PLOT
            write_mm_matrix("internal_plot",internal_plot,"",TYPE_G);
#endif
            return STATUS_SOLUTION_FOUND;

        } /********************************************************************/

        /*
         *  Updates t
         */
        if (s >= 0.5)
        {
            t = max(min(2.0 * n * MU / gap, MU * t), t);
        }
        else if (s < 1e-5)
        {
            t = 1.1*t;
        }

        /*
         *  Computes search direction.
         */
        if (matX1->nz >= 0)
        {
            /* pcg */
            compute_searchdir_pcg(&prob, &vars, t, s, gap, &pcgstat, &adata, 
                                  &mdata, precond, tm1, tn1, tx1);
            pcgiter += pcgstat.iter;
        }
        else
        {
            /* direct */
            if (n > m)
            {
                /* direct method for n > m, SMW */
                compute_searchdir_chol_fat(&prob, &vars, t, B, BB,
                                           tm1, tn1, tn2, tn3, tn4);
            }
            else
            {
                /* direct method for n <= m */
                compute_searchdir_chol_thin(&prob, &vars, t, B, BB,
                                            tm1, tn1, tn2);
            }
        }

        /*
         *  Backtracking linesearch & update x = (v,w,u) and z.
         */
        s = backtracking_linesearch(&prob, &vars, t, tm1, tx1);
        if (s < 0) break; /* BLS error */
    }
    /*** END OF MAIN LOOP *****************************************************/

    /*  Abnormal termination */
    if (s < 0)
    {
        status = STATUS_MAX_LS_ITER_EXCEEDED;
    }
    else /* if (ntiter == MAX_NT_ITER) */
    {
        status = STATUS_MAX_NT_ITER_EXCEEDED;
    }

    if (sol != NULL)
    {
        /* trim solution */
        int i;
        double lambda_threshold;

        lambda_threshold = to.ktolerance*lambda;
        sol[0] = x[0];

        for (i = 0; i < n; i++)
        {
            sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0;
        }
        /* if standardized, sol = coeff/std */
        if (to.sflag == TRUE && to.cflag == FALSE)
        {
            dmat_elemdivi(n, sol+1, std_x, sol+1);
            sol[0] -= dmat_dot(n, avg_x, sol+1);
        }
    }

    if (initial_x != NULL)
    {
        dmat_vcopy(n+n+1, x, initial_x);
        *initial_t = t;
    }
    if (total_pcgiter) *total_pcgiter = pcgiter;
    if (total_ntiter ) *total_ntiter  = ntiter;

    /* free memory */
    free_variables(&vars);
    free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB);
    free_problem_data(&prob);

#if INTERNAL_PLOT
    write_mm_matrix("internal_plot",internal_plot,"",TYPE_G);
#endif
    return status;
}
Ejemplo n.º 11
0
int main(int argc, char * const *argv){
  //VirusTotal-Structs
  struct VtResponse *response;
  struct VtDomain *domain_report;
  struct VtIpAddr *ip_report;
  struct VtUrl *url_report;
  struct VtFile *file_scan;
  struct VtComments *comments;

  char* apikey = (char*)calloc(APIKEY_SIZE, APIKEY_SIZE*sizeof(char)); // TODO must be free'd
  int c; 
  char* fname = NULL;
  fname = get_homedir(); 
  if(!getapikey(apikey, fname)) return 1;

  // Print Usage if no parameter is given
  if(argc < 2){
    print_usage(argv[0]);
    free_variables(apikey);
    return 0;
  } 

  //signals for c-vtapi dunno why
  signal(SIGHUP, sighand_callback);
  signal(SIGTERM, sighand_callback);

  while(1){
    int option_index = 0;
    static struct option long_options[] = {
      {"scandomain",  required_argument, 0, 'd'},
      {"scanip",      required_argument, 0, 'i'},
      {"scanfile",    required_argument, 0, 'f'},
      {"scanurl",     required_argument, 0, 'u'},
      {"commentsget", required_argument, 0, 'g'},
      {"commentsput", required_argument, 0, 'p'},
      {"search",      required_argument, 0, 's'},
      {0,             0,                 0,  0 }
    }; // static struct option

    c = getopt_long_only(argc, argv, "", long_options, &option_index);

    if(c == -1){
      break;
    } 

    switch(c){
      case 'd':
        // scandomain wrapper
        break; 
      case 'i':
        // scanip  wrapper
        break; 
      case 'f':
        // scanfile wrapper
        break; 
      case 'u':
        // scanurl wrapper
        break; 
      case 'g':
        // commentsget wrapper
        break; 
      case 'p':
        // commentsput wrapper
        break; 
      case 's':
        // search function
        break; 
      default:
        printf("?? getopt returned character code 0%o ??\n", c);
    } 
  } 

  if (optind < argc) {
    printf("non-option ARGV-elements: ");
    while (optind < argc){
      printf("%s ", argv[optind++]);
    } 
    printf("\n");
  } 
  free_variables(apikey);
  return 0;
} 
Ejemplo n.º 12
0
/**
 * exit the gtk main loop when the main window is destroyed.
 */
static void main_window_destroy_event ( GObject* obj, gpointer data)
{
    free_variables();
    run.window = NULL;
    gtk_main_quit();
}
Ejemplo n.º 13
0
static void sighandler(int signo) {
    if (signo == SIGINT) {
        free_variables();
        exit(EXIT_SUCCESS);
    }
}