コード例 #1
0
ファイル: X_keymaps.c プロジェクト: ccarcel/dosemu2
/* This function is borrowed from Wine (LGPL'ed)
   http://source.winehq.org/source/dlls/x11drv/keyboard.c
   with adjustments to match dosemu

   The idea is, if $_layout="auto", to match each keyboard map with
   the X keymap and choose the one that matches best.

   It is used when we can access display, not just for xdosemu,
   but also in xterms. Remote users using terminals will have
   to specify $_layout explicitly though.

   The console map is just another map in this scheme that may
   or may not be the best one.
*/
int X11_DetectLayout (void)
{
  Display *display;
  unsigned match, mismatch, seq, i, alternate;
  int score, keyc, key, pkey, ok = 0;
  KeySym keysym;
  unsigned max_seq[3] = {0, 0};
  int max_score[3] = {INT_MIN, INT_MIN};
  int ismatch = 0;
  int min_keycode, max_keycode;
  t_unicode ckey[2] = {0, 0};
  t_keysym lkey[2] = {0, 0};
  struct keytable_entry *kt;
  struct char_set_state X_charset;

  char *display_name = config.X_display ? config.X_display : getenv("DISPLAY");
  display = XOpenDisplay(display_name);
  if (display == NULL) return 1;

  XDisplayKeycodes(display, &min_keycode, &max_keycode);

#ifndef HAVE_XKB
  int keysyms_per_keycode;
  KeySym *key_mapping;

  /* get data for keycode from X server */
  key_mapping = XGetKeyboardMapping(display, min_keycode,
			    max_keycode + 1 - min_keycode,
			    &keysyms_per_keycode);
#endif

  init_charset_state(&X_charset, lookup_charset("X_keysym"));
  for (kt = keytable_list, alternate = 0; kt->name; ) {
    k_printf("Attempting to match against \"%s\"\n", kt->name);
    match = 0;
    mismatch = 0;
    score = 0;
    seq = 0;
    pkey = -1;
    for (keyc = min_keycode; keyc <= max_keycode; keyc++) {

      for (i = 0; i < 2; i++) {
#ifdef HAVE_XKB
	keysym = XkbKeycodeToKeysym(display, keyc, alternate, i);
#else
	keysym = X11_KeycodeToKeysym(key_mapping, keysyms_per_keycode,
			min_keycode, keyc, alternate, i);
#endif
	charset_to_unicode(&X_charset, &ckey[i],
                (const unsigned char *)&keysym, sizeof(keysym));
      }

      if (ckey[0] != U_VOID && (ckey[0] & 0xf000) != 0xe000) {
        /* search for a match in layout table */
        /* right now, we just find an absolute match for defined positions */
        /* (undefined positions are ignored, so if it's defined as "3#" in */
        /* the table, it's okay that the X server has "3#£", for example) */
        /* however, the score will be higher for longer matches */
        for (key = 0; key < kt->sizemap; key++) {
	  lkey[0] = keysym_to_unicode(kt->key_map[key]);
	  lkey[1] = keysym_to_unicode(kt->shift_map[key]);
          for (ok = 0, i = 0; (ok >= 0) && (i < 2); i++) {
            if (lkey[i] != U_VOID) {
	      if (lkey[i] == ckey[i])
		ok++;
	      else if (ckey[i] != U_VOID)
		ok = -1;
	    }
          }
	  if (debug_level('k') > 5)
	    k_printf("key: % 3d score % 2d for keycode % 3d, %04x %04x, "
		     "got %04x %04x\n",
		     key, ok, keyc, lkey[0], lkey[1], ckey[0], ckey[1]);
          if (ok > 0) {
            score += ok;
            break;
          }
        }
        /* count the matches and mismatches */
        if (ok > 0) {
          match++;
          /* and how much the keycode order matches */
          if (key > pkey) seq++;
          pkey = key;
        } else {
          /* print spaces instead of \0's */
          for (i = 0; i < ARRAY_SIZE(ckey); i++) if (!ckey[i]) ckey[i] = ' ';
          mismatch++;
          score -= 2;
        }
      }
    }
    k_printf("matches=%d, mismatches=%d, seq=%d, score=%d\n",
           match, mismatch, seq, score);
    if (score > max_score[alternate] ||
       (score == max_score[alternate] &&
	((seq > max_seq[alternate]) ||
	 (seq == max_seq[alternate] && kt->keyboard == KEYB_AUTO)))) {
      /* best match so far */
      if (alternate) {
	/* alternate keyboards are optional so a threshold is used */
	if (score > 20) config.altkeytable = kt;
      }
      else
	config.keytable = kt;
      max_score[alternate] = score;
      max_seq[alternate] = seq;
      ismatch = !mismatch;
    }
    alternate = !alternate;
    if (!alternate)
      kt++;
  }
  cleanup_charset_state(&X_charset);

#ifndef HAVE_XKB
  XFree(key_mapping);
#endif

  /* we're done, report results if necessary */
  if (!ismatch)
    k_printf("Using closest match (%s) for scan/virtual codes mapping.\n",
	   config.keytable->name);

  c_printf("CONF: detected layout is \"%s\"\n", config.keytable->name);
  if (config.altkeytable)
    c_printf("CONF: detected alternate layout: %s\n", config.altkeytable->name);
  XCloseDisplay(display);
  return 0;
}
コード例 #2
0
ファイル: KalignAdapter.cpp プロジェクト: ggrekhov/ugene
void KalignAdapter::alignUnsafe(const MultipleSequenceAlignment& ma, MultipleSequenceAlignment& res, TaskStateInfo& ti) {
    ti.progress = 0;
    int* tree = 0;
    quint32 a, b, c;

    struct alignment* aln = 0;
    struct parameters* param = 0;
    struct aln_tree_node* tree2 = 0;

    param = (parameters*)malloc(sizeof(struct parameters));

    param =  interface(param,0,0);

    kalign_context *ctx = get_kalign_context();
    unsigned int &numseq = ctx->numseq;
    unsigned int &numprofiles = ctx->numprofiles;

    if (ma->getNumRows() < 2){
        if (!numseq){
            k_printf("No sequences found.\n\n");
        } else {
            k_printf("Only one sequence found.\n\n");
        }
        free_param(param);
        throw KalignException("Can't align less then 2 sequences");
    }

    if(ctx->gpo != -1) {
        param->gpo = ctx->gpo;
    }
    if(ctx->gpe != -1) {
        param->gpe = ctx->gpe;
    }
    if(ctx->tgpe != -1) {
        param->tgpe = ctx->tgpe;
    }
    if(ctx->secret != -1) {
        param->secret = ctx->secret;
    }

    /************************************************************************/
    /* Convert MA to aln                                                    */
    /************************************************************************/
    k_printf("Prepare data");
    numseq = ma->getNumRows();
    numprofiles = (numseq << 1) - 1;
    aln = aln_alloc(aln);
    for(quint32 i = 0 ; i < numseq; i++) {
        const MultipleSequenceAlignmentRow row= ma->getMsaRow(i);
        aln->sl[i] = row->getUngappedLength();
        aln->lsn[i] = row->getName().length();
    }

    for (quint32 i = 0; i < numseq;i++) {
        try {
            aln->s[i] = (int*) malloc(sizeof(int)*(aln->sl[i]+1));
            checkAllocatedMemory(aln->s[i]);
            aln->seq[i] = (char*)malloc(sizeof(char)*(aln->sl[i]+1));
            checkAllocatedMemory(aln->seq[i]);
            aln->sn[i] = (char*)malloc(sizeof(char)*(aln->lsn[i]+1));
            checkAllocatedMemory(aln->sn[i]);
        } catch (...) {
            cleanupMemory(NULL, numseq, NULL, aln, param);
            throw;
        }
    }

    int aacode[26] = {0,1,2,3,4,5,6,7,8,-1,9,10,11,12,23,13,14,15,16,17,17,18,19,20,21,22};
    for(quint32 i = 0; i < numseq; i++) {
        const MultipleSequenceAlignmentRow row= ma->getMsaRow(i);
        qstrncpy(aln->sn[i], row->getName().toLatin1(), row->getName().length() + 1); //+1 to include '\0'
        QString gapless = QString(row->getCore()).remove('-');
        qstrncpy(aln->seq[i], gapless.toLatin1(), gapless.length() + 1);	//+1 to include '\0'
        for (quint32 j = 0; j < aln->sl[i]; j++) {
            if (isalpha((int)aln->seq[i][j])){
                aln->s[i][j] = aacode[toupper(aln->seq[i][j])-65];
            } else {
                aln->s[i][j] = -1;
            }
        }
        aln->s[i][aln->sl[i]] = 0;
        aln->seq[i][aln->sl[i]] = 0;
        aln->sn[i][aln->lsn[i]] = 0;
    }

    /*for(int i=0;i<numseq;i++) {
        for(int j=0;j<aln->sl[i];j++)
            printf("%d  ", aln->s[i][j]);
    }*/

    //aln_dump(aln);

    //aln = detect_and_read_sequences(aln,param);

    if(param->ntree > (int)numseq){
        param->ntree = (int)numseq;
    }

    //DETECT DNA
    if(param->dna == -1){
        for (quint32 i = 0; i < numseq;i++){
            param->dna = byg_detect(aln->s[i],aln->sl[i]);
            if(param->dna){
                break;
            }
        }
    }
    //param->dna = 0;
    //k_printf("DNA:%d\n",param->dna);
    //exit(0);

    if(param->dna == 1){
        //brief sanity check...
        for (quint32 i = 0; i < numseq;i++){
            if(aln->sl[i] < 6){
                //k_printf("Dna/Rna alignments are only supported for sequences longer than 6.");
                free(param);
                free_aln(aln);
                throw KalignException("Dna/Rna alignments are only supported for sequences longer than 6.");
            }
        }
        aln =  make_dna(aln);
    }

    //int j;

    //fast distance calculation;
    float** submatrix = 0;
    submatrix = read_matrix(submatrix,param); // sets gap penalties as well.....

    //if(byg_start(param->alignment_type,"profPROFprofilePROFILE") != -1){
    //	profile_alignment_main(aln,param,submatrix);
    //}

    float** dm = 0;
    if(param->ntree > 1){
        //if(byg_start(param->distance,"pairclustalPAIRCLUSTAL") != -1){
        //	if(byg_start(param->tree,"njNJ") != -1){
        //		dm = protein_pairwise_alignment_distance(aln,dm,param,submatrix,1);
        //	}else{
        //		dm = protein_pairwise_alignment_distance(aln,dm,param,submatrix,0);
        //	}
        //}else if(byg_start("wu",param->alignment_type) != -1){
        //	dm =  protein_wu_distance2(aln,dm,param);
        //	//	param->feature_type = "wumanber";
        if(param->dna == 1){
        //	if(byg_start(param->tree,"njNJ") != -1){
        //		dm =  dna_distance(aln,dm,param,1);
        //	}else{
                dm =  dna_distance(aln,dm,param,0);
        //	}
        }else{
            //if(byg_start(param->tree,"njNJ") != -1){
            //	dm =  protein_wu_distance(aln,dm,param,1);
            //}else{
            try {
                dm =  protein_wu_distance(aln,dm,param,0);
            } catch (const KalignException &) {
                cleanupMemory(submatrix, numseq, dm, aln, param);
                throw;
            }
            //}
        }
        if(check_task_canceled(ctx)) {
            cleanupMemory(submatrix, numseq, dm, aln, param);
            throwCancellingException();
        }
        /*int j;
        for (int i = 0; i< numseq;i++){
        for (j = 0; j< numseq;j++){
        k_printf("%f	",dm[i][j]);
        }
        k_printf("\n");
        }*/

        //if(byg_start(param->tree,"njNJ") != -1){
        //	tree2 = real_nj(dm,param->ntree);
        //}else{
            tree2 = real_upgma(dm,param->ntree);
        //}
        //if(param->print_tree){
        //	print_tree(tree2,aln,param->print_tree);
        //}
    }

    tree = (int*) malloc(sizeof(int)*(numseq*3+1));
    for (quint32 i = 1; i < (numseq*3)+1;i++){
        tree[i] = 0;
    }
    tree[0] = 1;

    if(param->ntree < 2){
        tree[0] = 0;
        tree[1] = 1;

        c = numseq;
        tree[2] = c;
        a = 2;
        for (quint32 i = 3; i < (numseq-1)*3;i+=3){
            tree[i] = c;
            tree[i+1] = a;
            c++;
            tree[i+2] = c;
            a++;
        }
    }else if(param->ntree > 2){
        ntreeify(tree2,param->ntree);
    }else{
        tree = readtree(tree2,tree);
        for (quint32 i = 0; i < (numseq*3);i++){
            tree[i] = tree[i+1];
        }
        free(tree2->links);
        free(tree2->internal_lables);
        free(tree2);
    }

    //get matrices...
    //struct feature_matrix* fm = 0;

    //struct ntree_data* ntree_data = 0;

    int** map = 0;
    //if(param->ntree > 2){
    //	ntree_data = (struct ntree_data*)malloc(sizeof(struct ntree_data));
    //	ntree_data->realtree = tree2;
    //	ntree_data->aln = aln;
    //	ntree_data->profile = 0;
    //	ntree_data->map = 0;
    //	ntree_data->ntree = param->ntree;
    //	ntree_data->submatrix = submatrix;
    //	ntree_data->tree = tree;

    //	ntree_data = ntree_alignment(ntree_data);
    //	map = ntree_data->map;
    //	tree = ntree_data->tree;
    //	for (int i = 0; i < (numseq*3);i++){
    //		tree[i] = tree[i+1];
    //	}
    //	free(ntree_data);
    //}else if (param->feature_type){
    //	fm = get_feature_matrix(fm,aln,param);
    //	if(!fm){
    //		for (int i = 32;i--;){
    //			free(submatrix[i]);
    //		}
    //		free(submatrix);
    //		free_param(param);
    //		free(map);
    //		free(tree);
    //		throw KalignException("getting feature matrix error");
    //	}

    //	map = feature_hirschberg_alignment(aln,tree,submatrix,map,fm);
    //	//exit(0);
    //	//map =  feature_alignment(aln,tree,submatrix, map,fm);

    //}else if (byg_start("pairwise",param->alignment_type) != -1){
    //	if(param->dna == 1){
    //		map = dna_alignment_against_a(aln,tree,submatrix, map,param->gap_inc);
    //	}else{
    //		map = hirschberg_alignment_against_a(aln,tree,submatrix, map,param->smooth_window,param->gap_inc);
    //	}
    //	//map =  default_alignment(aln,tree,submatrix, map);
    //}else if (byg_start("fast",param->alignment_type) != -1){
    //	map =  default_alignment(aln,tree,submatrix, map);
    if(param->dna == 1){
            map =  dna_alignment(aln,tree,submatrix, map,param->gap_inc);

    //	/*}else if (byg_start("test",param->alignment_type) != -1){
    //	map =  test_alignment(aln,tree,submatrix, map,param->internal_gap_weight,param->smooth_window,param->gap_inc);
    //	}else if (param->aa){
    //	map =  aa_alignment(aln,tree,submatrix, map,param->aa);
    //	}else if (param->alter_gaps){
    //	map = alter_gaps_alignment(aln,tree,submatrix,map,param->alter_gaps,param->alter_range,param->alter_weight);
    //	}else if (byg_start("altergaps",param->alignment_type) != -1){
    //	map = alter_gaps_alignment(aln,tree,submatrix,map,param->alter_gaps,param->alter_range,param->alter_weight);
    //	}else if(byg_start("simple",param->alignment_type) != -1){
    //	map =  simple_hirschberg_alignment(aln,tree,submatrix, map);*/
    //}else if(byg_start("advanced",param->alignment_type) != -1){
    //	map =  advanced_hirschberg_alignment(aln,tree,submatrix, map,param->smooth_window,param->gap_inc,param->internal_gap_weight);
    }else{
        map =  hirschberg_alignment(aln,tree,submatrix, map,param->smooth_window,param->gap_inc);
    }
    if (map == NULL) {
        throw KalignException("Failed to build alignment.");
    }
    if(check_task_canceled(ctx)) {
        free_param(param);
        free_aln(aln);
        free(map);
        free(tree);
        throwCancellingException();
    }

    //clear up sequence array to be reused as gap array....
    int *p = 0;
    for (quint32 i = 0; i < numseq;i++){
        p = aln->s[i];
        for (a = 0; a < aln->sl[i];a++){
            p[a] = 0;
        }
    }
    //clear up

    for (quint32 i = 0; i < (numseq-1)*3;i +=3){
        a = tree[i];
        b = tree[i+1];
        aln = make_seq(aln,a,b,map[tree[i+2]]);
    }

    //for (int i = 0; i < numseq;i++){
    //	k_printf("%s	%d\n",aln->sn[i],aln->nsip[i]);
    //}


    for (quint32 i = 0; i < numseq;i++){
        aln->nsip[i] = 0;
    }

    aln =  sort_sequences(aln,tree,param->sort);

    //for (int i = 0; i < numseq;i++){
    //	k_printf("%d	%d	%d\n",i,aln->nsip[i],aln->sip[i][0]);
    //}

    /************************************************************************/
    /* Convert aln to MA                                                    */
    /************************************************************************/
    res->setAlphabet(ma->getAlphabet());
    for (quint32 i = 0; i < numseq;i++){
        int f = aln->nsip[i];
        QString seq;
        for(quint32 j=0;j<aln->sl[f];j++) {
            seq += QString(aln->s[f][j],'-') + aln->seq[f][j];
        }
        seq += QString(aln->s[f][aln->sl[f]],'-');
        res->addRow(QString(aln->sn[f]), seq.toLatin1());
    }

    //output(aln,param);
    /*	if(!param->format){
    fasta_output(aln,param->outfile);
    }else{
    if (byg_start("msf",param->format) != -1){
    msf_output(aln,param->outfile);
    }else if (byg_start("clustal",param->format) != -1){
    clustal_output(aln,param->outfile);
    }else if (byg_start("macsim",param->format) != -1){
    macsim_output(aln,param->outfile,param->infile[0]);
    }
    }
    */
    free_param(param);
    free_aln(aln);
    free(map);
    free(tree);
    //KalignContext* ctx = getKalignContext();
}
コード例 #3
0
ファイル: kernel_main.c プロジェクト: malcolmspiteri/Liax
void k_main()
{	
	k_printf("Hi!\nWelcome to MalcOS", 10);
};
コード例 #4
0
ファイル: kek.c プロジェクト: bozhink/Code-Chunks
k_main() // like main in a normal C program
{
	k_clear_screen();
	k_printf("Hi!\nHow's this for a starter OS?", 0);
};
コード例 #5
0
struct ntree_data* ntree_sub_alignment(struct ntree_data* ntree_data,int* tree,int num)
{
	struct dp_matrix *dp = 0;
	struct alignment* aln = 0;
	int i,j,g,a,b,c;
	int len_a;
	int len_b;
	float** local_profile = 0;
	float* profa = 0;
	float* profb = 0;

	int** local_map = 0;
	int* local_sl = 0;
	int* local_nsip = 0;
	int** local_sip = 0;
	
	int* which_to_alloc = 0;

	unsigned int numseq;
	unsigned int numprofiles;

	struct kalign_context *ctx = get_kalign_context();
	numseq = ctx->numseq;
	numprofiles = ctx->numprofiles;
	
	aln = ntree_data->aln;
	
	which_to_alloc = malloc(sizeof(int*)*numprofiles);
	for ( i = 0;i< numprofiles;i++){
		which_to_alloc[i] = 0;
	}
	
	local_profile = malloc(sizeof(float*)*numprofiles);
	local_sl = malloc(sizeof(int)*numprofiles);
	local_nsip = malloc(sizeof(int)*numprofiles);
	local_sip = malloc(sizeof(int*)*numprofiles);
	
	
	for (i = 0; i < num-1;i++){
		a = tree[i*3+1];
		if(!which_to_alloc[a]){
			which_to_alloc[a] = 1;
		}
		b = tree[i*3+2];
		if(!which_to_alloc[b]){
			which_to_alloc[b] = 1;
		}
		c = tree[i*3+3];
		if(!which_to_alloc[c]){
			which_to_alloc[c] = 2;
		}
	}
	//for ( i = 0;i< numprofiles;i++){
	//	k_printf("alloc?:%d	%d\n",i,which_to_alloc[i]);
	//}
	
//	exit(0);
	for ( i = 0;i< numprofiles;i++){
		if(which_to_alloc[i] == 1){
			local_profile[i] = ntree_data->profile[i];
			local_sl[i] = aln->sl[i];
			local_nsip[i] = aln->nsip[i];
			local_sip[i] =  malloc(sizeof(int*)*aln->nsip[i]);
			for(j = 0;j < aln->nsip[i];j++){
				local_sip[i][j] = aln->sip[i][j];
			}
		}else{
			local_profile[i] = 0;
			local_sl[i] = 0;
			local_nsip[i] = 0;
			local_sip[i] = 0;
		}
	}
	/*
	for ( i = 0;i< numprofiles;i++){
		local_profile[i] = ntree_data->profile[i];
		local_sl[i] = aln->sl[i];
		local_nsip[i] = aln->nsip[i];
		if(aln->sip[i]){
			k_printf("Allocing..:%d\n",aln->nsip[i]);
			local_sip[i] =  malloc(sizeof(int*)*aln->nsip[i]);
			for(j = 0;j < aln->nsip[i];j++){
				local_sip[i][j] = aln->sip[i][j];
			}
		}else{
			local_sip[i] = 0;
		}
	}*/

	local_map = malloc(sizeof(int*)*numprofiles);
	for ( i = 0;i < numprofiles;i++){
		local_map[i] = 0;
	}
	
	
	dp = dp_matrix_alloc(dp,511,511);
	c = numseq;
	for (i = 0; i < num-1;i++){
		a = tree[i*3+1];
		b = tree[i*3+2];
		c = tree[i*3+3];
	//	k_printf("Aligning:%d %d->%d\n",a,b,c);
		len_a = local_sl[a];
		len_b = local_sl[b];
		dp = dp_matrix_realloc(dp,len_a,len_b);
	
		local_map[c] = malloc(sizeof(int) * (len_a+len_b+2));
		for (j = len_a+len_b+2;j--;){
			local_map[c][j] = 0;
		}
		if (a < numseq){
			local_profile[a] = make_profile(local_profile[a],aln->s[a],len_a,ntree_data->submatrix);
		}
		if (b < numseq){
			local_profile[b] = make_profile(local_profile[b],aln->s[b],len_b,ntree_data->submatrix);
		}
		profa = local_profile[a];
		profb = local_profile[b];
	
		set_gap_penalties(profa,len_a,local_nsip[b],0,local_nsip[a]);
		set_gap_penalties(profb,len_b,local_nsip[a],0,local_nsip[b]);

		if(local_nsip[a] == 1){
			if(local_nsip[b] == 1){
				local_map[c] = ss_dyn(ntree_data->submatrix,local_map[c],dp,aln->s[a],aln->s[b],len_a,len_b);
			}else{
				local_map[c] = ps_dyn(local_map[c],dp,profb,aln->s[a],len_b,len_a,local_nsip[b]);
				local_map[c] = mirror_path(local_map[c]);
			}
		}else{
			if(local_nsip[b] == 1){
				local_map[c] = ps_dyn(local_map[c],dp,profa,aln->s[b],len_a,len_b,local_nsip[a]);
			}else{
				if (len_a > len_b){
					local_map[c] = pp_dyn(local_map[c],dp,profa,profb,len_a,len_b);
				}else{
					local_map[c] = pp_dyn(local_map[c],dp,profb,profa,len_b,len_a);
					local_map[c] = mirror_path(local_map[c]);
				}
			}
		}
			
		local_profile[c] = malloc(sizeof(float)*64*(len_a+len_b+2));
		local_profile[c] = update(profa,profb,local_profile[c],local_map[c],local_nsip[a],local_nsip[b]);
	
		local_sl[c] = local_map[c][0];
	
		local_nsip[c] = local_nsip[a] + local_nsip[b];
		local_sip[c] = malloc(sizeof(int)*(local_nsip[a] + local_nsip[b]));
		g =0;
		for (j = local_nsip[a];j--;){
			local_sip[c][g] = local_sip[a][j];
			g++;
		}
		for (j = local_nsip[b];j--;){
			local_sip[c][g] = local_sip[b][j];
			g++;
		}
	//	free(profa);
	//	free(profb);
	}
	
	if(ntree_data->profile[c]){
		if(ntree_data->map[c][ntree_data->map[c][0]+2]  < local_map[c][local_map[c][0]+2]){
			k_printf("%d\n",local_map[c][local_map[c][0]+2]);
			//remove old map,profile,etc..
			for (i = 0; i < num-1;i++){
				c = tree[i*3+3];
				free(ntree_data->map[c]);
				free(ntree_data->profile[c]);
				free(aln->sip[c]);
				ntree_data->map[c] = malloc(sizeof(int)*(local_map[c][0]+3));
				for (j = 0; j < local_map[c][0]+3;j++){
					ntree_data->map[c][j] = local_map[c][j];
				}
				aln->sip[c] = malloc(sizeof(int)*local_nsip[c]);
				aln->nsip[c] = local_nsip[c];
				for (j = 0; j < local_nsip[c];j++){
					aln->sip[c][j] = local_sip[c][j];
				}
				aln->sl[c] = local_sl[c];
				
			}
			ntree_data->profile[c] = malloc(sizeof(int)*64*(aln->sl[c]+1));
			for (i = 0; i < (64*(aln->sl[c]+1));i++){
				ntree_data->profile[c][i] = local_profile[c][i];
			}
			ntree_data->tree[0] -= (tree[0]-1);
			for (j = 1; j < tree[0];j++){
				ntree_data->tree[ntree_data->tree[0]+j-1] = tree[j];
			}
			ntree_data->tree[0] += (tree[0]-1);

		}else{
			k_printf("no improvement\n");
		}
	}else{
		k_printf("%d\n",local_map[c][local_map[c][0]+2]);
		for (i = 0; i < num-1;i++){
			c = tree[i*3+3];
			ntree_data->map[c] = malloc(sizeof(int)*(local_map[c][0]+3));
			for (j = 0; j < local_map[c][0]+3;j++){
				ntree_data->map[c][j] = local_map[c][j];
			}

			aln->sip[c] = malloc(sizeof(int)*local_nsip[c]);
			aln->nsip[c] = local_nsip[c];
			for (j = 0; j < local_nsip[c];j++){
				aln->sip[c][j] = local_sip[c][j];
			}
			aln->sl[c] = local_sl[c];
		}
		ntree_data->profile[c] = malloc(sizeof(int)*64*(aln->sl[c]+1));
		for (i = 0; i < (64*(aln->sl[c]+1));i++){
			ntree_data->profile[c][i] = local_profile[c][i];
		}
		for (j = 1; j < tree[0];j++){
			ntree_data->tree[ntree_data->tree[0]+j-1] = tree[j];
		}
		ntree_data->tree[0] += tree[0]-1;
	}

	for ( i = 0;i< numprofiles;i++){
		if(which_to_alloc[i] == 1){
			free(local_sip[i]);
			if(i < numseq){
				free(local_profile[i]);	
			}
		}
		if(which_to_alloc[i] == 2){
			free(local_profile[i]);
			free(local_map[i]);
			free(local_sip[i]);
		}
		
	}

	free(which_to_alloc);
	free(local_map);
	free(local_sip);
	free(local_nsip);
	free(local_profile);
	free(local_sl);
	
	dp_matrix_free(dp);
	return ntree_data;
}
コード例 #6
0
ファイル: console.c プロジェクト: jschwartzenberg/dosemu2
static int console_post_init(void)
{
  int kdmode;

  set_vc_screen_page();
  set_process_control();
  k_printf("KBD: Taking mouse control\n");  /* Actually only in KD_GRAPHICS... */
  /* Some escape sequences don't work in KD_GRAPHICS... */
  kdmode = config.vga? KD_GRAPHICS: KD_TEXT;
  ioctl(console_fd, KDSETMODE, kdmode);

  /* Clear the Linux console screen. The console recognizes these codes:
   * \033[?25h = show cursor.
   * \033[0m = reset color.
   * \033[H = Move cursor to upper-left corner of screen.
   * \033[2J = Clear screen.
   */
  if (!config.vga) {
    int co, li;
    gettermcap(0, &co, &li);
    fprintf(stdout,"\033[?25h\033[0m\033[H\033[2J");
    vga_emu_setmode(config.cardtype == CARD_MDA ? 7 : 3, co, li);
  }
  scr_state.mapped = 0;
  allow_switch();

  /*
     Switch to dosemu VT if config.forcevtswitch is set.
     The idea of this action is that in case of config.console_video
     dosemu need to work at active VT (at least at start) for accessing
     video memory. So to be able to run dosemu for instance
     through cron we need config option like forcevtswitch.
     The action seems sensible only if config.console_video.
                                                   [email protected]
  */

  if (config.force_vt_switch && !vc_active()) {
    if (ioctl(console_fd, VT_ACTIVATE, scr_state.console_no)<0)
      v_printf("VID: error VT switching %s\n", strerror(errno));
  }

  /* XXX - get this working correctly! */
#define OLD_SET_CONSOLE 1
#ifdef OLD_SET_CONSOLE
  init_get_video_ram(WAIT);
  scr_state.mapped = 1;
#endif
  if (vc_active()) {
    int other_no = (scr_state.console_no == 1 ? 2 : 1);
    v_printf("VID: we're active, waiting...\n");
#ifndef OLD_SET_CONSOLE
    init_get_video_ram(WAIT);
    scr_state.mapped = 1;
#endif
    if (!config.vga) {
      ioctl(console_fd, VT_ACTIVATE, other_no);
/*
 *    Fake running signal_handler() engine to process release/acquire
 *    vt's.
 */
      while(vc_active())
        coopth_wait();
      ioctl(console_fd, VT_ACTIVATE, scr_state.console_no);
      while(!vc_active())
        coopth_wait();
    }
  }
  else
    v_printf("VID: not active, going on\n");

  allow_switch();
  return 0;
}
コード例 #7
0
ファイル: debug.c プロジェクト: Fluray/lencer0.3.1
}

void creat_lseek_read_write_open_close_file_test(void)
{
	int count = 0;
	char buff_in[100] = "Hello world!\nI'm writing a small OS.\nThanks.";
	char buff_out[100] = {0};
	char filename[50] = {0};
	unsigned short oldfs;

	/* 已创建了内核默认的最多磁盘存储文件数,则停止 */
	while((++count) < NR_D_INODE) {

		_k_printf("This is the content will be written: \n%s\n\n", buff_in);

		
		sprintf(filename, "/hello--%d.txt", count);
		_k_printf("%s\n", filename);
		/* 创建文件并写入 */
		oldfs = set_fs_kernel();
		FILEDESC desc = sys_creat(filename, FILE_FILE | FILE_RW);
		set_fs(oldfs);
		if(-1 == desc) {
			k_printf("creat_lseek_...: Create file failed!");
			return;
		}
		d_printf("Create file return.\n");
		if(-1 == sys_lseek(desc, 995920, SEEK_SET)) {
			k_printf("creat_lseek_...: Lseek file failed!");
			return;
		}
		d_printf("Lseek file return.\n");
		oldfs = set_fs_kernel();
		if(-1 == sys_write(desc, buff_in, 1 + strlen(buff_in))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Write file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Write file return.\n");
		if(-1 == sys_close(desc)) {
			k_printf("creat_lseek_...: Close file failed!");
			return;
		}
		d_printf("Close file return.\n");


		/* 打印根目录含有的文件 */
		print_dir("/");

		/* 打开之前创建的文件,读取 */
		oldfs = set_fs_kernel();
		if(-1 == (desc = sys_open(filename, O_RW))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Open file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Open file return.\n");
		if(-1 == sys_lseek(desc, 995920, SEEK_SET)) {
			k_printf("creat_lseek_...: Lseek file failed!");
			return;
		}
		d_printf("Lseek file return.\n");
		oldfs = set_fs_kernel();
		if(-1 == sys_read(desc, buff_out, 1 + strlen(buff_in))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Read file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Read file return.\n");
		if(-1 == sys_close(desc)) {
			k_printf("creat_lseek_...: Close file failed!");
			return;
		}
		d_printf("Close file return.\n");

		
		_k_printf("This is the content of READ file: \n%s\n\n", buff_out);
コード例 #8
0
ファイル: dosemu_keys.c プロジェクト: andrewbird/dosemu2
Boolean handle_dosemu_keys(Boolean make, t_keysym key)
{
	Boolean result = TRUE;
	switch(key) {
	/* C-A-D is disabled */
	case DKY_DOSEMU_REBOOT:
		if (make) {
			k_printf("KBD: Ctrl-Alt-Del: rebooting dosemu\n");
			dos_ctrl_alt_del();
		}
		break;
	case DKY_DOSEMU_EXIT:
		if (make) {
			k_printf("KBD: Ctrl-Alt-PgDn: bye bye!\n");
			leavedos_once(0);
		}
		break;

	case DKY_DOSEMU_FREEZE:
		if (make) {
			if (!dosemu_frozen) {
				freeze_dosemu_manual();
			} else {
				unfreeze_dosemu();
			}
		}
		break;

	case DKY_DOSEMU_VT_1:
	case DKY_DOSEMU_VT_2:
	case DKY_DOSEMU_VT_3:
	case DKY_DOSEMU_VT_4:
	case DKY_DOSEMU_VT_5:
	case DKY_DOSEMU_VT_6:
	case DKY_DOSEMU_VT_7:
	case DKY_DOSEMU_VT_8:
	case DKY_DOSEMU_VT_9:
	case DKY_DOSEMU_VT_10:
	case DKY_DOSEMU_VT_11:
	case DKY_DOSEMU_VT_12:
		if (make) {
			int vc_num;
			vc_num = (key - DKY_DOSEMU_VT_1) +1;
			result = switch_to_console(vc_num);
		}
		break;

	case DKY_MOUSE_UP:
	case DKY_MOUSE_DOWN:
	case DKY_MOUSE_LEFT:
	case DKY_MOUSE_RIGHT:
	case DKY_MOUSE_UP_AND_LEFT:
	case DKY_MOUSE_UP_AND_RIGHT:
	case DKY_MOUSE_DOWN_AND_LEFT:
	case DKY_MOUSE_DOWN_AND_RIGHT:
	case DKY_MOUSE_BUTTON_LEFT:
	case DKY_MOUSE_BUTTON_MIDDLE:
	case DKY_MOUSE_BUTTON_RIGHT:
		mouse_keyboard(make, key);        /* mouse emulation keys */
		break;

	case DKY_DOSEMU_HELP:
	case DKY_DOSEMU_REDRAW:
	case DKY_DOSEMU_SUSPEND:
	case DKY_DOSEMU_RESET:
	case DKY_DOSEMU_MONO:
	case DKY_DOSEMU_PAN_UP:
	case DKY_DOSEMU_PAN_DOWN:
	case DKY_DOSEMU_PAN_LEFT:
	case DKY_DOSEMU_PAN_RIGHT:
		if (Keyboard->handle_keys) {
			Keyboard->handle_keys(make, key);
		} else
		{
			result = FALSE;
		}
		break;

#if 0
	case DKY_MOUSE_GRAB:
		if (Keyboard == &Keyboard_X) {
			handle_X_keys(make, key);
		} else {
			result = FALSE;
		}
#endif

	default:
		result = FALSE;
		break;
	}
	return result;
}