Exemple #1
0
int main(int argc, char **argv, char **envp)
{

    char ts[1000];
    FILE *fp;
    size_t len;
    int cnt;

    char *bm = calloc(1, 0xFFFFFFFF / 0x8); /* about 512MB */

#if 1
    cnt = 0;
    if ((fp = fopen("dict.txt", "r"))) {
        while (fgets(ts, 1000, fp)) {
            len = strlen(ts)-2;
            ts[len] = '\0';
            if (len <= MAX_PHRASE_S_LEN) {
                cnt++;
                word_set(bm, ts);
            }
        }
        printf("%d words seted\n", cnt);
    } else {
        printf("open dict.txt failed\n");
        return 1;
    }
#endif

#if 0
    word_set(bm, "专场");
    word_set(bm, "专机");
#endif

    if (argc > 1) {
        memset(words, sizeof(words), 0x0);
        wpos = 0;

        struct timeval tv_s, tv_e;
        unsigned long usec;
        
        gettimeofday(&tv_s, NULL);
        word_split(bm, argv[1], strlen(argv[1]), on_words);
        gettimeofday(&tv_e, NULL);
        usec = (tv_e.tv_sec - tv_s.tv_sec) * 1000000ul + (tv_e.tv_usec - tv_s.tv_usec);

        printf("parse finished in %.6f seconds\n", (double)(usec / 1000000.0));
        printf("words:\n");
        out_words();
    } else {
        unsigned int i;
        cnt = 0;
        for (i = 0; i < 0xFFFFFFFF; i++) {
            if (BITMAP_GET(bm, i)) cnt++;
        }
        
        printf("%d distinct word\n", cnt);
    }

    free(bm);

    return 0;
}
Exemple #2
0
static quik_err_t
get_params(char **kernel,
           char **initrd,
           char **params,
           env_dev_t *cur_dev)
{
   char *p;
   char *q;
   int n;
   char *buf;
   char *endp;
   key_t lastkey;
   char *label = NULL;
   int timeout = DEFAULT_TIMEOUT;

   if ((bi->flags & TRIED_AUTO) == 0) {
      bi->flags ^= TRIED_AUTO;
      *params = bi->bootargs;
      *kernel = *params;

      word_split(kernel, params);
      if (!*kernel) {
         *kernel = cfg_get_default();

         /*
          * Timeout only makes sense
          * if we don't have an image name already
          * passed.
          */
         if ((bi->flags & CONFIG_VALID) &&
             (q = cfg_get_strg(0, "timeout")) != 0 && *q != 0) {
           timeout = strtol(q, NULL, 0);
         }
      } else {

         /*
          * We have something, boot immediately.
          */
         timeout = 0;
      }
   }

   printk(PROMPT);
   lastkey = KEY_NONE;
   if (timeout != -1) {
      lastkey = wait_for_key(timeout, '\n');
   }

   if (lastkey == '\n') {
      printk("%s", *kernel);
      if (*params) {
         printk(" %s", *params);
      }

      printk("\n");
   } else {
      *kernel = NULL;

      buf = cmd_edit(maintabfunc, lastkey);
      if (buf == NULL) {
         return ERR_NOT_READY;
      }

      *kernel = buf;
      word_split(kernel, params);
   }

   if (bi->flags & CONFIG_VALID) {
      *initrd = cfg_get_strg(0, "initrd");
      p = cfg_get_strg(*kernel, "image");
      if (p && *p) {
         label = *kernel;
         *kernel = p;

         p = cfg_get_strg(label, "device");
         if (p) {
            cur_dev->device = p;
         }

         p = cfg_get_strg(label, "partition");
         if (p) {
            n = strtol(p, &endp, 10);
            if (endp != p && *endp == 0) {
               env_dev_set_part(cur_dev, n);
            }
         }

         p = cfg_get_strg(label, "initrd");
         if (p) {
            *initrd = p;
         }

         if (cfg_get_strg(label, "old-kernel")) {
            bi->flags |= BOOT_PRE_2_4;
         } else {
            bi->flags &= ~BOOT_PRE_2_4;
         }

         *params = make_params(label, *params);
         if (*params == NULL) {
            return ERR_NO_MEM;
         }
      }
   }

   if (*kernel == NULL) {
      printk("<TAB> for list of bootable images, or !help\n");
      return ERR_NOT_READY;
   }

   /*
    * If we manually entered kernel path, the initrd could
    * be following in the param list...
    */
   if (label == NULL) {
      *params = chomp(*params);

      if (memcmp(*params, "-- ", 3) != 0) {
         *initrd = *params;
         word_split(initrd, params);
      } else {

         /*
          * No initrd, just kernel args.
          */
         *params = *params + 3;
      }
   }

   return ERR_NONE;
}
Exemple #3
0
quik_err_t
env_init(void)
{
   char *p;

   bi->of_bootargs_buf = malloc(ENV_SZ);
   bi->of_bootfile_buf = malloc(ENV_SZ);
   if (bi->of_bootargs_buf == NULL ||
       bi->of_bootfile_buf == NULL) {
      return ERR_NO_MEM;
   }

   prom_get_chosen("bootargs", bi->of_bootargs_buf, ENV_SZ);
   prom_get_options("boot-file", bi->of_bootfile_buf, ENV_SZ);

#ifndef CONFIG_TINY
   printk("/chosen/bootargs = '%s'\n", bi->of_bootargs_buf);
   printk("       boot-file = '%s'\n", bi->of_bootfile_buf);
#endif /* CONFIG_TINY */

   if (bi->flags & WITH_PREBOOT) {

      /*
       * Forget about the passed args, presumably boot-file was set
       * by the script (why else would you use it)?
       *
       * Keep in mind that if booting via boot-device, the boot-file gets stuffed by OF
       * in boot-args, so, we can't just use bootargs to override the preboot script,
       * and we have to ignore them.
       */
      bi->default_dev.device = bi->of_bootfile_buf;
   } else {
      bi->default_dev.device = bi->of_bootargs_buf;
   }

   word_split(&bi->default_dev.device, &bi->bootargs);

   if (!bi->default_dev.device) {
      if (bi->flags & WITH_PREBOOT) {

         /*
          * For preboot we already basically looked at boot-file, so
          * don't bother looking at it again.
          */
         return ERR_ENV_PREBOOT_BAD;
      }

      /*
       * No booting device passed via /chosen/bootargs, try
       * bi->of_bootfile_buf.
       */
      bi->default_dev.device = chomp(bi->of_bootfile_buf);
   } else {
      if (memcmp(bi->default_dev.device, "--", 2) == 0) {
         if (bi->flags & WITH_PREBOOT) {

            /*
             * Preboot wanted us to use default, but uh... it overrode the default.
             */
            return ERR_ENV_PREBOOT_BAD;
         }

         /*
          * Use the default from NVRAM in bi->of_bootfile_buf.
          */
         bi->default_dev.device = chomp(bi->of_bootfile_buf);
      }
   }

   p = strchr(bi->default_dev.device, ':');
   if (p != 0) {
      env_dev_set_part(&bi->default_dev, strtol(p + 1, NULL, 0));
      *p++ = 0;

      /* Are we given a config file path? */
      p = strchr(p, '/');
      if (p != 0) {
         bi->config_file = p;
      } else {
         bi->config_file = "/etc/quik.conf";
      }
   }

   return ERR_NONE;
}
Exemple #4
0
/*
 * Function read_init is used to read in the initial values of selfing rates (S) for MCMC updating
 * Input argument:  initialfilename is the directory of the file containing the initial values, 
 *					if it is NULL,then using random number generator to generate the INIT structure
 *					chainnum is the number of MCMC chains, determining the number of sets of initial values
 *					popnum is the number of subpopulation assumed
 *					chainnum and popnum determines the dimensions of the "initd" element of the INIT struture
 * Output argument: this application returns an INIT structure, which contains the "chainnum" sets of initial values for F per subpopulation
 * The data in the file should be ranged as:
 *	>chain_name1							each set of the initial values should begin with ">S"
 *	num1 num2..
 *
 *  >chain_name2
 *	....
 */
INIT read_init(char *initialfilename,int chainnum,int popnum,long update,long burnin,int thinning)
{
	//char sign='#';
	int i,j,temp,cnt_chn=0;
	FILE *initfp;
	char *line;
	INIT initial;
	
	initial.chainnum=chainnum;
	initial.update=update;
	initial.burnin=burnin;
	initial.thinning=thinning;
	initial.popnum=popnum;
	
	initial.initd=matrix(0,chainnum-1,0,popnum-1);
	initial.name_len=ivector(0,chainnum-1);
	initial.chn_name=cmatrix(0,chainnum-1,0,MAXLEN-1);
	
	if(initialfilename==NULL)
	{
		for(i=0;i<chainnum;i++)
		{
			for(j=0;j<popnum;j++)
				initial.initd[i][j]=ran1();
			strcpy(initial.chn_name[i],"Chain#");
			strcat(initial.chn_name[i],int_to_string(i+1));			

			initial.name_len[i]=strlen(initial.chn_name[i])+1;
	
			initial.chn_name[i][initial.name_len[i]-1]='\0';
		}
	}
	else{
		if((initfp=fopen(initialfilename,"r"))==NULL)
		{	nrerror("Cannot open inital file!");}
		line=cvector(0,MAXLINE-1);
		cnt_chn=0;
		for(i=0;i<chainnum&&(!feof(initfp));i++)
		{
			while(!feof(initfp))
			{
				fgets(line,MAXLINE,initfp);
				if(line[0]=='>') break;
			}
			for(j=1;j<strlen(line)&&line[j]!='\n';j++)
			{
				initial.chn_name[i][j-1]=line[j];
			}
			initial.chn_name[j]='\0';
			//printf("%s\n",initial.chn_name[i]);
			initial.name_len[i]=j;
			fgets(line,MAXLINE,initfp);
			temp=word_cnt(line);
			if(temp!=popnum)
			{
				nrerror("The number of initial values for selfing rates is not equal the number of subpopulation assumed!\n");
			}
			word_split(line,initial.initd[cnt_chn],popnum);
			cnt_chn++;
		}
		if(cnt_chn<=chainnum)
		{
			for(i=cnt_chn;i<chainnum;i++)
			{
				for(j=0;j<popnum;j++)
					initial.initd[i][j]=ran1();
				strcpy(initial.chn_name[i],"Chain#");
				strcat(initial.chn_name[i],int_to_string(i+1));
				
				initial.name_len[i]=strlen(initial.chn_name[i])+1;
				initial.chn_name[i][initial.name_len[i]-1]='\0';
	
			}
		}
		if(cnt_chn>chainnum)
		{
			nrerror("The number of chain starting points is greater than the number of chains!\n");
		}
		fclose(initfp);
		free_cvector(line,0,MAXLINE-1);
	}
	/*for(i=0;i<chainnum;i++)
	{
		for(j=0;j<popnum;j++)
			fprintf(stdout,"%f\t",initial.initd[i][j]);
		fprintf(stdout,"\n");
	}*/	
	return(initial);
}