Beispiel #1
0
void CPhotoPubView::OnTimer(UINT_PTR nIDEvent)
{
	KillTimer(1);
	CPhotoPubDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: Add your message handler code here and/or call default
	int nFiles=m_CurFiles.size();
	set<CString> CurFiles1;
	const int nFiles1=GetAllFolderFile(m_WatchingPath, "*.jpg", CurFiles1);
	if (nFiles==nFiles1) {
		SetTimer(1,500,NULL);
		return;
	}else if (nFiles>nFiles1){
		AfxMessageBox("同步发生错误,无法恢复,请重新运行!\n");
		exit(1);
	}
	
	//Here Comes a new Photo
	//wait transfering
	Sleep(1000);
	//process
	set<CString>::iterator it1;
	for (it1=CurFiles1.begin();it1!=CurFiles1.end();++it1)
	{
		if ( m_CurFiles.find(*it1)==m_CurFiles.end() ) //not exist before
		{
			((CMainFrame*)GetParent())->ShowWindow(SW_SHOWMAXIMIZED);

			CClientDC cdc(this);
			CRect clrct;
			GetClientRect(&clrct);
			int width=clrct.Width();
			int height=clrct.Height();

			if (pDoc->m_pOpenedImage) ReleaseFImage(&pDoc->m_pOpenedImage);
			IplImage *pImg=pDoc->m_pOpenedImage=LoadFImage(m_WatchingPath+"\\"+*it1+".jpg");
			m_ratio=min(double(width)/pImg->width,double(height)/pImg->height);
			((CMainFrame*)GetParent())->SetRatio(int(m_ratio*100));
			OnUpdate(NULL,NULL,NULL);
			DrawImage(&cdc,pImg);

			CString newname;
			int res;
			do {
				GetNewName(m_InitStr,newname);
				res=rename(m_WatchingPath+"\\"+*it1+".jpg",m_WatchingPath+"\\"+newname+".jpg");
			}while( 
				(res==0) ? false : (true,
					(errno==EEXIST) ? AfxMessageBox("文件名重复!请重试"): (
						(errno==EINVAL) ? AfxMessageBox("文件名含非法字符!请重试"):AfxMessageBox("未知错误!请重试")
				) ) );
			m_CurFiles.insert(newname);
			m_InitStr=newname;
			CStringNumber snum(m_InitStr);
			snum.Increase();
			snum.ToString(m_InitStr);
			//break;
		}
	}
	
	CScrollView::OnTimer(nIDEvent);

	SetTimer(1,500,NULL);
}
Beispiel #2
0
static void
read_PK_char(struct font *fontp, wide_ubyte ch)
{
    int i, j;
    int n;
    int row_bit_pos;
    Boolean paint_switch;
    BMUNIT *cp;
    struct glyph *g;
    FILE *fp = fontp->file;
    long fpwidth;
    BMUNIT word = 0;
    int word_weight, bytes_wide;
    int rows_left, h_bit, count;

    g = &fontp->glyph[ch];
    PK_flag_byte = g->x2;
    PK_dyn_f = PK_flag_byte >> 4;
    paint_switch = ((PK_flag_byte & 8) != 0);
    PK_flag_byte &= 0x7;
    if (PK_flag_byte == 7)
	n = 4;
    else if (PK_flag_byte > 3)
	n = 2;
    else
	n = 1;

    if (debug & DBG_PK)
	Printf("loading pk char %d, char type %d ", ch, n);

    /*
     * now read rest of character preamble
     */
    if (n != 4)
	fpwidth = num(fp, 3);
    else {
	fpwidth = sfour(fp);
	(void)four(fp);	/* horizontal escapement */
    }
    (void)num(fp, n);	/* vertical escapement */
    {
	unsigned long w, h;

	w = num(fp, n);
	h = num(fp, n);
	if (w > 0x7fff || h > 0x7fff)
	    oops("Character %d too large in file %s", ch, fontp->fontname);
	g->bitmap.w = w;
	g->bitmap.h = h;
    }
    g->x = snum(fp, n);
    g->y = snum(fp, n);

    g->dvi_adv = fontp->dimconv * fpwidth;

    if (debug & DBG_PK) {
	if (g->bitmap.w != 0)
	    Printf(", size=%dx%d, dvi_adv=%ld", g->bitmap.w, g->bitmap.h,
		   g->dvi_adv);
	Putchar('\n');
    }

    alloc_bitmap(&g->bitmap);
    cp = (BMUNIT *) g->bitmap.bits;

    /*
     * read character data into *cp
     */
    bytes_wide = ROUNDUP((int)g->bitmap.w, BMBITS) * BMBYTES;
    PK_bitpos = -1;
    if (PK_dyn_f == 14) {	/* get raster by bits */
	bzero(g->bitmap.bits, (int)g->bitmap.h * bytes_wide);
	for (i = 0; i < (int)g->bitmap.h; i++) {	/* get all rows */
	    cp = ADD(g->bitmap.bits, i * bytes_wide);
#ifndef	WORDS_BIGENDIAN
	    row_bit_pos = -1;
#else
	    row_bit_pos = BMBITS;
#endif
	    for (j = 0; j < (int)g->bitmap.w; j++) {	/* get one row */
		if (--PK_bitpos < 0) {
		    word = one(fp);
		    PK_bitpos = 7;
		}
#ifndef	WORDS_BIGENDIAN
		if (++row_bit_pos >= BMBITS) {
		    cp++;
		    row_bit_pos = 0;
		}
#else
		if (--row_bit_pos < 0) {
		    cp++;
		    row_bit_pos = BMBITS - 1;
		}
#endif
		if (word & (1 << PK_bitpos))
		    *cp |= 1 << row_bit_pos;
	    }
	}
    }
    else {	/* get packed raster */
	rows_left = g->bitmap.h;
	h_bit = g->bitmap.w;
	PK_repeat_count = 0;
	word_weight = BMBITS;
	word = 0;
	while (rows_left > 0) {
	    count = PK_packed_num(fp);
	    while (count > 0) {
		if (count < word_weight && count < h_bit) {
#ifndef	WORDS_BIGENDIAN
		    if (paint_switch)
			word |= bit_masks[count] << (BMBITS - word_weight);
#endif
		    h_bit -= count;
		    word_weight -= count;
#ifdef	WORDS_BIGENDIAN
		    if (paint_switch)
			word |= bit_masks[count] << word_weight;
#endif
		    count = 0;
		}
		else if (count >= h_bit && h_bit <= word_weight) {
		    if (paint_switch)
			word |= bit_masks[h_bit] <<
#ifndef	WORDS_BIGENDIAN
			    (BMBITS - word_weight);
#else
			    (word_weight - h_bit);
#endif
		    *cp++ = word;
		    /* "output" row(s) */
		    for (i = PK_repeat_count * bytes_wide / BMBYTES; i > 0; --i) {
			*cp = *SUB(cp, bytes_wide);
			++cp;
		    }
		    rows_left -= PK_repeat_count + 1;
		    PK_repeat_count = 0;
		    word = 0;
		    word_weight = BMBITS;
		    count -= h_bit;
		    h_bit = g->bitmap.w;
		}
		else {
		    if (paint_switch)
#ifndef	WORDS_BIGENDIAN
			word |= bit_masks[word_weight] <<
			    (BMBITS - word_weight);
#else
			word |= bit_masks[word_weight];
#endif
		    *cp++ = word;
		    word = 0;
		    count -= word_weight;
		    h_bit -= word_weight;
		    word_weight = BMBITS;
		}
	    }
	    paint_switch = 1 - paint_switch;
	}
	if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
	    oops("Wrong number of bits stored:  char. %d, font %s", ch,
		 fontp->fontname);
	if (rows_left != 0 || h_bit != g->bitmap.w)
	    oops("Bad pk file (%s), too many bits", fontp->fontname);
    }
}
Beispiel #3
0
static char* 
scxnum (const char *str, const struct numfmt* pnf, 
	struct canform* pre, struct canform* pim)
{
  char *ptr, *endrp, *ptr2;
  struct canform cform1, cform2;
  size_t slen = strlen (str);

  cform1.sgn   = 0;
  cform1.ipart = stralloc (slen);
  cform1.dpart = stralloc (slen);
  cform1.expn  = 0;  
  endrp = ptr = snum (str, pnf, &cform1);
#ifdef _SCXNUM_DEBUG_
  fprintf (stderr, "%s -->\n sign = \'%c\'\n ip = \"%s\"\n dp = \"%s\"\n expn = %ld, tail = \"%s\n",
	   str, cform1.sgn, cform1.ipart, cform1.dpart, cform1.expn, endrp);
#endif
  if (ptr != str)
    {
      normalize (&cform1);
#ifdef _SCXNUM_DEBUG_
      fprintf (stderr, "After normalization:\n");    
      fprintf (stderr, "%s -->\n sign = \'%c\'\n ip = \"%s\"\n dp = \"%s\"\n expn = %ld, tail = \"%s\n",
	       str, cform1.sgn, cform1.ipart, cform1.dpart, cform1.expn, endrp);
#endif
      if (*ptr == pnf->iu)
	{
	  /*
	    We have read a pure imaginary number.
	   */
	  *pre = null;
	  *pim = cform1;
	  return ptr + 1;
	}
      else
	{
	  /*
	    We have to check if we have read 
	    a pure real number or if we can read a full
	    complex number.
	  */
	  *pre = cform1;
	  while (is_space (*ptr))
	    ptr++;
	  if (*ptr == POS_SIGN || *ptr == NEG_SIGN)
	    {
	      cform2.sgn   = 0;
	      cform2.ipart = stralloc (slen);
	      cform2.dpart = stralloc (slen);
	      cform2.expn  = 0;
	      ptr2 = snum (ptr, pnf, &cform2);
#ifdef _SCXNUM_DEBUG_
	      fprintf (stderr, "%s -->\n sign = \'%c\'\n ip = \"%s\"\n dp = \"%s\"\n expn = %ld, tail = \"%s\n",
		       ptr, cform2.sgn, cform2.ipart, cform2.dpart, cform2.expn, ptr2);
#endif
	      if (*ptr2 == pnf->iu)
		{
		  /*
		    We have read a full complex number.
		   */
		  normalize (&cform2);
#ifdef _SCXNUM_DEBUG_
		  fprintf (stderr, "After normalization:\n");    
		  fprintf (stderr, "%s -->\n sign = \'%c\'\n ip = \"%s\"\n dp = \"%s\"\n expn = %ld, tail = \"%s\n",
			   ptr, cform2.sgn, cform2.ipart, cform2.dpart, cform2.expn, ptr2);
#endif
		  *pim = cform2;
		  return ptr2 + 1;
		}
	      else
		{
		  /*
		    We have read a pure real number.
		   */
		  free ((void*) cform2.ipart);
		  free ((void*) cform2.dpart);
		  *pim = null;
		  return endrp;
		}
	    }
	  else
	    {
	      /*
		We have read a pure real number.
	      */
	      *pim = null;
	      return endrp;
	    }
	}
    }
  else
    {
      /*
	We have read no valid number,
	clean and return.
       */
      free ((void*) cform1.ipart);
      free ((void*) cform1.dpart);
      *pre = *pim = null;
      return ptr;
    }
}
Beispiel #4
0
int mpf_a2num (Real* pr, const char *q, char** endptr, const struct numfmt* pnf)
{
  struct canform cform;
  size_t slen = strlen (q);

  cform.sgn   = 0;
  cform.ipart = stralloc (slen);
  cform.dpart = stralloc (slen);
  cform.expn  = 0;  
  *endptr = snum (q, pnf, &cform);
  if (*endptr != q)
    {
      char *ptr, *str; 
      long e;
      size_t len, explen;
#ifdef HAVE_LOCALECONV
      struct lconv *plconv = localeconv(); 
      char* dec_point = plconv->decimal_point;
#else /* not HAVE_LOCALECONV */ 
      char* dec_point = ".";
#endif /* not HAVE_LOCALECONV */ 

      if (cform.ipart == NULL || cform.dpart == NULL)
	{
	  /*
	    The number contained in the string Q is zero
	  */
	  mpf_set_ui (*pr, 0);
	  return 0;
	}
      normalize (&cform);
      e = cform.expn >= 0 ? cform.expn : -cform.expn;
      for (len = 0; e != 0; len++, e /= 10);
      explen = len;
      if (cform.expn < 0)
	/* We need space for the minus sign in front of the exponent */
	len++; 
      if (cform.sgn == NEG_SIGN)
	/* We need space for the minus sign in front of the whole number */
	len++;
      /* We need space also for the decimal point and the exponent letter */
      len += strlen (cform.ipart) + strlen (cform.dpart) + strlen(dec_point) + 1;
      ptr = str = stralloc (len);

      if (cform.sgn == NEG_SIGN)
	{
	  *ptr = NEG_SIGN;
	  ptr++;
	}
      if (*cform.ipart != '\0')
	{
	  *ptr = *cform.ipart;
	  strcat (str, dec_point);
	  strcat (str, cform.ipart+1);
	  strcat (str, cform.dpart);
	}
      else
	{
	  *ptr = *cform.dpart;
	  strcat (str, dec_point);
	  strcat (str, cform.dpart+1);
	}
      if (explen > 0)
	{
	  for (ptr++; *ptr != '\0'; ptr++);
	  *ptr = ECH;
	  if (cform.expn < 0)
	    {
	      ptr++;
	      *ptr = NEG_SIGN;
	    }
	  ptr += explen;
	  for (e = cform.expn >= 0 ? cform.expn : -cform.expn; e != 0; ptr--, e /= 10)
	    *ptr = CHAR_ZERO + e % 10;
	}
      if ( mpf_set_str (*pr, str, 10) == -1 )
	{
	  /* This should never happen.  If mpf_set_str() returns -1, then */
	  /* there is something wrong with the code above.                */
	  fprintf (stderr,
		   _("The string \"%s\"\nis not a valid number, the execution of the program ends now\n"),
		   str);
	  free ((void*) cform.ipart);
	  free ((void*) cform.dpart);
	  free ((void*) str);
	  exit (EXIT_TROUBLE);
	}
      else
	{
	  free ((void*) cform.ipart);
	  free ((void*) cform.dpart);
	  free ((void*) str);
	  return 0;
	}
    } /* *endptr != q */
  else
    {
      /*
	We have read no valid number, then
	free the previously allocated memory,
	set the value pointed to by PR
	to zero and return -1
       */
      free ((void*) cform.ipart);
      free ((void*) cform.dpart);
      mpf_set_ui (*pr, 0);
      return -1;
    } /* *endptr == q */
}
Beispiel #5
0
int main(int argc, char * const argv[]) {
 //GArgs args(argc, argv, "hg:c:s:t:o:p:help;genomic-fasta=COV=PID=seq=out=disable-flag;test=");
 GArgs args(argc, argv, opts);
 fprintf(stderr, "Command line was:\n");
 args.printCmdLine(stderr);
 args.printError(USAGE, true);
 //if (args.getOpt('h') || args.getOpt("help"))
 
 if (args.getOpt(OPT_HELP))
     {
     GMessage("%s\n", USAGE);
     exit(1);
     }

 if (args.getOpt(OPT_NUM)) {
      GStr snum(args.getOpt(OPT_NUM));
      int num=snum.asInt();
      char* numstr=commaprintnum(num);
      GMessage("Number %d written with commas: %s\n", num, numstr);
      GFREE(numstr);
 }
 //---
 GHash<GVec<int> > ends;
 
 /*
 testGPVec();
 //exit(0);

 //uint pos=3;
 //GStr spos((int)pos);
 //GVec<int> *ev=ends[spos.chars()];
 
 GPVec<Gint> v;
 int r(5);
 int rr=v.Add(new Gint(3));
 //if (rr<0) {
 // GMessage("Error adding 0! (code %d)\n",rr);
 // }
 v.Add(new Gint(r));
 v.Add(new Gint(2));
 v.Add(new Gint(1));
 v.Add(new Gint(4));
 rr=v.Add(new Gint(0));
 v[rr]->v=-1;
 v.Sort(cmpGint);
 GMessage("collection has %d elements:\n",v.Count());
 for (int i=0;i<v.Count();i++) {
   GMessage("v[%d]=%d;\n",i,v[i]->v);
 }
 exit(0);
 */
 //---
 int numopts=args.startOpt();
 if (numopts)
   GMessage("#### Recognized %d option arguments:\n", numopts);
 int optcode=0;
 while ((optcode=args.nextCode())) {
   char* r=args.getOpt(optcode);
   GMessage("%14s\t= %s\n", args.getOptName(optcode), (r[0]==0)?"True":r);
   }
 int numargs=args.startNonOpt();
 if (numargs>0) {
   GMessage("\n#### Found %d non-option arguments given:\n", numargs);
   char* a=NULL;
   while ((a=args.nextNonOpt())) {
     GMessage("%s\n",a);
     }
   }
 GStr s=args.getOpt('t');
 if (!s.is_empty()) {
    GStr token;
    GMessage("Tokens in \"%s\" :\n",s.chars());
    s.startTokenize(";,: \t");
    int c=1;
    while (s.nextToken(token)) {
      GMessage("token %2d : \"%s\"\n",c,token.chars());
      c++;
      }
    }
 if (args.getOpt(OPT_BITVEC)) {
    uint numbits=4156888234;
    GBitVec bits(numbits);
    GMessage(">>> -- BitVec(%u) created (size=%u, mem=%lu) -- \n", numbits, bits.size(),
    		bits.getMemorySize());
    bits[405523342]=true;
    GMessage("      memory size: %lu , size()=%u, count()=%d \n", bits.getMemorySize(), bits.size(), bits.count());
    /*
    //GMessage(">>> -- Start BitVec Test -- \n");
    if (bits[1092]) bitError(1092);
    bits.resize(2049);
    if (bits[2048]) bitError(2048);
    bits[2048]=true;
    if (!bits[2048]) bitError(2048);
    bits.resize(4097);
    if (!bits[2048]) bitError(2048);
    if (bits[4096]) bitError(4096);
    bits[4096]=true;
    if (!bits[4096]) bitError(4096);
    GBitVec bits2(64);
    Gswap(bits, bits2);
    if (!bits2[2048]) bitError(2048);
    if (!bits2[4096]) bitError(4096);
    */
    //GMessage("<<< -- End BitVec Test (size: %d, count: %d, bits2 size=%d, count=%d) --\n",
    ///       bits.size(), bits.count(), bits2.size(), bits2.count());
    }
}