Beispiel #1
0
 //modify by QP on 2k8-4-7
//add two parameters 
//int dis; int cri; for distance function and criteria function seperately
TRAININGSET CheckParameters(char *TSName, char *CBName, char *PAName, 
char *InName, int Minclus,int Maxclus, int ow) {
  TRAININGSET TS;
  
  /* input training set doesn't exist */
  if (!ExistFile(TSName)) 
  {
    ErrorMessage("\nERROR: Input training set doesn't exist: "
        "%s\n\n", TSName);
    ExitProcessing(FATAL_ERROR);
  }
    
  /* result codebook file exists and we are told not to overwrite */
  if (ExistFile(CBName) && !ow) 
  {
    ErrorMessage("\nERROR: Result codebook already exists: "
        "%s\n\n", CBName);
    ExitProcessing(FATAL_ERROR);
  }

  /* result partitioning file exists and we are told not to overwrite */
  if (*PAName && ExistFile(PAName) && !ow) 
  {
    ErrorMessage("\nERROR: Result partitioning already exists: "
        "%s\n\n", PAName);
    ExitProcessing(FATAL_ERROR);
  }
  
  /* initial codebook / partitioning doesn't exist */
  if (*InName && !DetermineFileName(InName))
  {
    ErrorMessage("\nERROR: Initial codebook/partitioning doesn't exist: %s\n\n", InName);
    ExitProcessing(FATAL_ERROR);
  }
   //add by QP on 2k8-4-7
  //verify whether Max is bigger than min; make sure the range is ok
    if (Maxclus < Minclus ) 
	{
		ErrorMessage("Bad range: %i < %i.\n", Maxclus, Minclus);
		ExitProcessing(FATAL_ERROR);
    } 
  
  ReadTrainingSet(TSName, &TS);

 
  //add by QP on 2k7-11-7  
  //the size of training set should be at least more than min codebook
  /* result codebook cannot contain more vectors than training set */
  if (BookSize(&TS) < Minclus)
  {
    ErrorMessage("\nERROR: Number of vectors in training set ");
    ErrorMessage("(%d) < Min number of clusters ", BookSize(&TS));
    ErrorMessage("(%d%d)!\n\n", Minclus, Maxclus);
    FreeCodebook(&TS);
    ExitProcessing(FATAL_ERROR);
  }
  
  return TS;
}  /* CheckParameters() */
Beispiel #2
0
   void CopyFile (const std::string& srcPath, const std::string& dstPath, bool removeExisting)
   {
      if (srcPath.empty())                            throw error::InvalidParam("No source path specified!", ERROR_LOCATION);
      else if (dstPath.empty())                       throw error::InvalidParam("No destination path specified!", ERROR_LOCATION);
      else if (!ExistFile(srcPath))                   throw error::NotFound("Specified source path does not exist!", ERROR_LOCATION);
      else if (ExistFile(dstPath) && !removeExisting) throw error::AlreadyExists("Specified destination path already exists!", ERROR_LOCATION);

      filesystem::copy_file(srcPath, dstPath, filesystem::copy_option::overwrite_if_exists);
   }
Beispiel #3
0
static int UbootFileExist()
{
	if ( -1 == ExistFile(UbootFileTable[0])
		|| -1 == ExistFile(UbootFileTable[1]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #4
0
static int Dm6467SingleFileExist()
{
	if ( -1 == ExistFile(DM6467_Single_FileTable[0])
		|| -1 == ExistFile(DM6467_Single_FileTable[1])
		|| -1 == ExistFile(DM6467_Single_FileTable[2])
		|| -1 == ExistFile(DM6467_Single_FileTable[3]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #5
0
static int SlaveFileExist()
{
	if ( -1 == ExistFile(S_FileTable[0])
		|| -1 == ExistFile(S_FileTable[1])
		|| -1 == ExistFile(S_FileTable[2])
		|| -1 == ExistFile(S_FileTable[3]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #6
0
static int MasterFileExist()
{
	if ( -1 == ExistFile(M_FileTable[0])
		|| -1 == ExistFile(M_FileTable[1])
		|| -1 == ExistFile(M_FileTable[2])
		|| -1 == ExistFile(M_FileTable[3]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #7
0
   void MoveFile (const std::string& srcPath, const std::string& dstPath, bool removeExisting)
   {
      if (srcPath.empty())          throw error::InvalidParam("No source path specified!", ERROR_LOCATION);
      else if (dstPath.empty())     throw error::InvalidParam("No destination path specified!", ERROR_LOCATION);
      else if (!ExistFile(srcPath)) throw error::NotFound("Specified source path does not exist!", ERROR_LOCATION);

      if (ExistFile(dstPath)) {
         if (!removeExisting)                   throw error::AlreadyExists("Specified destination path already exists!", ERROR_LOCATION);
         else if (!filesystem::remove(dstPath)) throw error::Delete("Failed to delete file!", ERROR_LOCATION);
      }

      filesystem::rename(srcPath, dstPath);
   }
Beispiel #8
0
   void RemoveFile (const std::string& path)
   {
      if (path.empty())          throw error::InvalidParam("No path specified!", ERROR_LOCATION);
      else if (!ExistFile(path)) return;

      if (!filesystem::remove(path)) throw error::Delete("Failed to delete file!", ERROR_LOCATION);
   }
Beispiel #9
0
   void CreateFile (const std::string& path, bool removeExisting)
   {
      if (path.empty())                            throw error::InvalidParam("No path specified!", ERROR_LOCATION);
      else if (ExistFile(path) && !removeExisting) return;

      Save(path, "", false, true);
   }
Beispiel #10
0
   const Binary LoadBinary (const std::string& path)
   {
      if (path.empty()) throw error::InvalidParam("No path specified!", ERROR_LOCATION);
      else if (!ExistFile(path)) throw error::NotFound("Specified path does not exist!", ERROR_LOCATION);

      HANDLE file  = nullptr;
      void* buffer = nullptr;

      base::ScopeGuard guard([&] () {
         if (buffer != nullptr) delete buffer;
         if (file != nullptr)   ::CloseHandle(file);
      });

      file = ::CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
      if (file == nullptr) throw error::Create("Failed to create file handle!", ERROR_LOCATION);

      DWORD fileSize  = ::GetFileSize(file, nullptr);
      DWORD bytesRead = 0;
      buffer          = malloc(fileSize);

      if (buffer == nullptr) throw error::OutOfMemory("Not enough memory available for binary resource!", ERROR_LOCATION);

      ZeroMemory(buffer, fileSize);

      if (!::ReadFile(file, buffer, fileSize, &bytesRead, nullptr)) throw error::Read("Failed to read from file!", ERROR_LOCATION);

      char* charBuffer = (char*)buffer;
      Binary content(charBuffer, charBuffer + fileSize);

      return content;
   }
Beispiel #11
0
static int FpgaFileExist()
{
	if ( -1 == ExistFile(M_FileTable[4]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #12
0
static int IPTFileExist()
{
	if ( -1 == ExistFile(IPTFileTable[0]) )
	{
		return -1;
	}
	return 0;
}
Beispiel #13
0
   void GraphicsManager::LoadFont (const std::string& fontFile, int size, TTF_Font** font)
   {
      if (fontFile.empty())          throw error::InvalidParam("No font file specified!", ERROR_LOCATION);
      else if (!ExistFile(fontFile)) throw error::NotFound("Specified font file does not exist!", ERROR_LOCATION);

      if (*font != nullptr) {
         TTF_CloseFont(*font);
         *font = nullptr;
      }

      *font = TTF_OpenFont(fontFile.c_str(), size);
      if (*font == nullptr) throw error::Create("Failed to create font from file \"" + fontFile + "\"!", ERROR_LOCATION);
   }
Beispiel #14
0
int DetermineFileName(char *name)
{
  char newName[MAXFILENAME], suffix[MAXFILENAME];
  int  i;
  
  /* Without extension */
  if (ExistFile(name))
  {
    return 1;
  }
 
  for (i = 0; i < 3; i++)
  {
    if (i == 0)      /* Try TS-file extension */
      strcpy(suffix, FormatNameTS);
      
    else if (i == 1)  /* Try CB-file extension */
      strcpy(suffix, FormatNameCB);
      
    else             /* Try PA-file extension */
      strcpy(suffix, FormatNamePA);
    
    if (strlen(name) < MAXFILENAME-strlen(suffix)-1)
    {
      strcpy(newName, name);
      CheckFileName(newName, suffix);
      if (ExistFile(newName))
      {
        strcpy(name, newName);
        return 1;
      }
    }
  }

  /* No luck this time */
  return 0;
}  /* DetermineFileName() */
void OnMenuClose(char *cmd, char *dep)
{
	int res=1;

	if(dep)
	{
		res=!system(dep);
		res|=ExistFile(dep);
	}
	if(cmd && res)
	{
		ShowMessage("System-Aktualisierung", "Bitte warten", 0);
		system(cmd);
	}
}
Beispiel #16
0
   void Save (const std::string& path, const std::string& content, bool append, bool removeExisting)
   {
      if (path.empty()) throw error::InvalidParam("No path specified!", ERROR_LOCATION);

      if (ExistFile(path)) {
         if (removeExisting) CreateFile(path, true);
         else if (!append)   throw error::AlreadyExists("Specified path already exists!", ERROR_LOCATION);
      }

      HANDLE file = ::CreateFile(path.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
      if (file == nullptr) throw error::Create("Failed to create file handle!", ERROR_LOCATION);

      DWORD bytesWritten = 0;

      if (!::WriteFile(file, content.c_str(), content.size(), &bytesWritten, nullptr)) {
         if (file != nullptr) ::CloseHandle(file);
         throw error::Write("Failed to write to file!", ERROR_LOCATION);
      }

      if (file != nullptr) ::CloseHandle(file);
   }
Beispiel #17
0
   GraphicsManager& GraphicsManager::AddTexture (const std::string& id, const std::string& textureFile)
   {
      if (id.empty())                               throw error::InvalidParam("No id specified!", ERROR_LOCATION);
      else if (textures.find(id) != textures.end()) throw error::AlreadyExists("Specified id \"" + id + "\" already exists in texture map!", ERROR_LOCATION);
      else if (textureFile.empty())                 throw error::InvalidParam("No texture file specified!", ERROR_LOCATION);
      else if (!ExistFile(textureFile))             throw error::NotFound("Specified texture file does not exist!", ERROR_LOCATION);

      SDL_Surface* surface = nullptr;

      ScopeGuard guard([&surface] () {
         if (surface != nullptr) { SDL_FreeSurface(surface); surface = nullptr; }
      });

      surface = IMG_Load(textureFile.c_str());
      if (surface == nullptr) throw error::Create("Failed to create surface from file \"" + textureFile + "\"!", ERROR_LOCATION);

      auto texture = SDL_CreateTextureFromSurface(device, surface);
      if (texture == nullptr) throw error::Create("Failed to create texture from surface!", ERROR_LOCATION);

      textures.insert(std::make_pair(id, texture));
      return *this;
   }
Beispiel #18
0
int main (int argc, char **argv)
{
	int tv,index,i,j,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,first=1,x0,x1,x2,x3,x4,x5,x6,x7;
	int xdir=1, ydir=1;
	double xstep=1, ystep=1; 
	double csx, cex, csy, cey;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2]={0,0};

		printf("SSaver Version %s\n",CL_VERSION);
		
		ReadConf();
	
		for(i=1; i<argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						sdat=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=(j)?1:0;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						secs=j;
					}
				}
				if(strstr(aptr,"SLOW=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						if(!j)
						{
							j=1;
						}
						slow=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
		
		if(!slow)
		{
			slow=1;
		}	
		if(slow>10)
		{
			slow=10;
		}
		
		xpos=ex/2;
		ypos=ey/2;	
		for(index=CMCST; index<=CMH; index++)
		{
			sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				tr[index-1]=(tv<<8);

			sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				bl[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_green",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				gn[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_red",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				rd[index-1]=(tv+(tv<<8));
		}
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(ioctl(fb, FBIOGETCMAP, &colormap) == -1)
		{
			printf("Clock <FBIOGETCMAP failed>\n");
			return -1;
		}

		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Clock <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("Clock <FT_Init_FreeType failed with Errorcode 0x%.2X>", error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("Clock <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("Clock <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("Clock <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
		desc.flags = FT_LOAD_MONOCHROME;
#else
		desc.font.face_id = FONT;
		desc.image_type = ftc_image_mono;
#endif
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx;
		starty = sy;
		xstep/=(double)slow;
		ystep/=(double)slow;
		
		InitRC();

	while(loop)
	{
		usleep(15000L);
		ioctl(fb, FBIOGETCMAP, &colormap);
		found=0;
		trnsp=0;
		for(i=colormap.start;i<colormap.len && found!=7;i++)
		{
			if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i])
			{
				cmc=i;
				found|=1;
			}
			if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000  && colormap.blue[i]>=0xF000 && !colormap.transp[i])
			{
				cmct=i;
				found|=2;
			}
			if(colormap.transp[i]>trnsp)
			{
				trnspi=i;
				trnsp=colormap.transp[i];
				found|=4;
			}
		}
		if(first)
		{
			first=0;
			memset(lbb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
			memset(lfb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
		}
		if(big)
		{
			x0=3;
			x1=14;
			x2=26;
			x3=BIG;
			x4=30;
			x5=60;
		}
		else
		{
			x0=7;
			x1=12;
			x2=18;
			x3=MED;
			x4=18;
			x5=40;
		}
		x6=0;
		x7=0;
		time(&atim);
		ltim=localtime(&atim);
		if(secs)
		{
			sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec);
		}
		else
		{
			sprintf(tstr,"   %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min);
			if(!sdat)
			{
				x6=3;
				x7=36+4*big;
			}
		}

		xpos+=xstep*(double)xdir;
		ypos+=ystep*(double)ydir;

		csx=xpos+x7;
		csy=ypos;
		cex=xpos+x7+100+20*big;
		cey=ypos+x2+2*(1+big)+sdat*x4;
		if(csx<0 || (sx+cex)>=ex)
		{
			xdir*=-1;
			xpos+=xstep*(double)xdir;
			csx=xpos+x7;
			cex=xpos+x7+100+20*big;
			xstep=rand()&3;
			if(!xstep)
			{
				xstep=1;
			}
			xstep/=(double)slow;
		}
		if(csy<0 || (sy+cey)>=ey)
		{
			ydir*=-1;
			ypos+=ystep*(double)ydir;
			csy=ypos;
			cey=ypos+x2+2*(1+big)+sdat*x4;
			ystep=rand()&3;
			if(!ystep || (ystep==3 && ydir==1))
			{
				ystep=1;
			}
			ystep/=(double)slow;
		}

		for(i=x6; i<strlen(tstr); i++)
		{
			*dstr=tstr[i];
			RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
		}

		if(sdat)
		{
			sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100);
			for(i=0; i<strlen(tstr); i++)
			{
				*dstr=tstr[i];
				RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
			}
		}

		for(i=0;i<=((sdat)?40:20)*(1+big);i++)
		{
			j=(starty+ypos+i)*var_screeninfo.xres+xpos+startx;
			if((j+100+20*big)<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, 100+20*big);
			}
		}
		
		RenderBox(csx, csy, cex, cey, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));

		if(++loop>10)
		{
			if(RCKeyPressed()||ExistFile("/tmp/.ssaver_kill"))
			{
				loop=0;
			}
		}	
	}	

	cmct=0;
	cmc=0;
	for(i=colormap.start;i<colormap.len;i++)
	{
		if(colormap.transp[i]>cmct)
		{
			cmc=i;
			cmct=colormap.transp[i];
		}
	}
	memset(lfb, cmc, var_screeninfo.xres*var_screeninfo.yres);
	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	CloseRC();
	remove("/tmp/.ssaver_kill");
	return 0;
}
int AddListEntry(MENU *m, char *line, int pos)
{
	int i,found=0,pfound=0;
	PLISTENTRY entr;
	char *ptr1,*ptr2,*ptr3,*ptr4, *wstr;

	if(!strlen(line))
	{
		return 1;
	}
	//printf("AddListEntry: %s\n",line);
	wstr=strdup(line);

	if(m->num_entrys>=m->max_entrys)
	{
		if((m->list=realloc(m->list,(m->max_entrys+LIST_STEP)*sizeof(PLISTENTRY)))==NULL)
		{
			printf(NOMEM);
			Clear_List(m,0);
			free(wstr);
			return 0;
		}
		for(i=m->num_entrys; i<m->num_entrys+LIST_STEP; i++)
		{
			if((entr=calloc(1,sizeof(LISTENTRY)))==NULL)
				{
				printf(NOMEM);
				Clear_List(m,0);
				free(wstr);
				return -1;
				}
			m->list[i]=entr;
		}
		m->max_entrys+=LIST_STEP;
	}

	entr=m->list[m->num_entrys];
	entr->underline=entr->stay=entr->showalways=0;

	for(i=TYP_MENU; !found && i<=TYP_SHELLRESOFF; i++)
	{
		ptr4=NULL;
		if((ptr1=strstr(wstr,TYPESTR[i]))==wstr)
		{
			ptr1=strchr(wstr,'=');
			ptr1++;
			ptr2=ptr1;
			while(*ptr2 && ((*ptr2=='*') || (*ptr2=='&') || (*ptr2==0302) || (*ptr2==0247) || (*ptr2=='+') || (*ptr2=='-') || (*ptr2=='!') || (*ptr2=='_')))
			{
				switch(*ptr2)
				{
					case '*': entr->underline=1; break;
					case '!': entr->underline=2; break;
					case '+': entr->showalways=1; break;
					case '-': entr->showalways=2; break;
					case '&': entr->stay=1; break;
					case 0302: if (*(ptr2 + 1) != 0247) break; // UTF-8 value of paragraph symbol
						ptr2++;
					case 0247: entr->stay=2; break;
				}
				while(*(++ptr2))
				{
					*(ptr2-1)=*ptr2;
				}
				*(ptr2-1)=0;
				ptr2=ptr1;
			}
			switch (i)
			{
				case TYP_EXECUTE:
				case TYP_MENUDON:
				case TYP_MENUDOFF:
				case TYP_MENUFON:
				case TYP_MENUFOFF:
					if((ptr2=strxchr(ptr1,','))!=NULL)
					{
						if((ptr4=strstr(ptr1,",ICON="))!=NULL)
						{
							*ptr4=0;
						}
						if((ptr4=strxchr(ptr2+1,','))!=NULL)
						{
							*ptr4=0;
							entr->message=strdup(ptr4+1);
						}
					}
				break;

				case TYP_MENU:
					if((ptr2=strstr(ptr1,",ICON="))!=NULL)
					{
						*ptr2=0;
					}
					if((ptr2=strxchr(ptr1,','))!=NULL)
					{
						*ptr2=0;
						entr->message=strdup(ptr2+1);
					}
				break;
			}
			switch (i)
			{
				case TYP_EXECUTE:
				case TYP_MENU:
				case TYP_COMMENT:
					entr->type=i;
					entr->entry=strdup(ptr1);
					entr->headerpos=pos;
					m->num_entrys++;
					found=1;
					break;

				case TYP_DEPENDON:
				case TYP_DEPENDOFF:
				case TYP_MENUDON:
				case TYP_MENUDOFF:
				case TYP_FILCONTON:
				case TYP_FILCONTOFF:
				case TYP_MENUFON:
				case TYP_MENUFOFF:
					if((ptr2=strstr(ptr1,",ICON="))!=NULL)
					{
						*ptr2=0;
					}
					if((ptr2=strxchr(ptr1,','))!=NULL)
					{
						if(i<TYP_EXECUTE)
						{
							ptr3=ptr2;
						}
						else
						{
							ptr2++;
							ptr3=strxchr(ptr2,',');
							ptr4=strxchr(ptr3+1,',');
						}
						if(ptr3!=NULL)
						{
							*ptr3=0;
							ptr3++;
							found=1;
							if(ptr4)
							{
								*ptr4=0;
							}
							if((i==TYP_FILCONTON) || (i==TYP_FILCONTOFF) || (i==TYP_MENUFON) || (i==TYP_MENUFOFF))
							{
								pfound=FileContainText(ptr3);
							}
							else
							{
								pfound=ExistFile(ptr3);
							}
							if((((i==TYP_DEPENDON)||(i==TYP_MENUDON)||(i==TYP_FILCONTON)||(i==TYP_MENUFON)) && pfound) || (((i==TYP_DEPENDOFF)||(i==TYP_MENUDOFF)||(i==TYP_FILCONTOFF)||(i==TYP_MENUFOFF)) && !pfound))
							{
								entr->type=(i<TYP_EXECUTE)?TYP_MENU:((strlen(ptr2))?TYP_EXECUTE:TYP_INACTIVE);
								entr->entry=strdup(ptr1);
								if(ptr4)
								{
									entr->message=strdup(ptr4+1);
								}
								entr->headerpos=pos;
								m->num_entrys++;
							}
							else
							{
								if(entr->showalways)
								{
									entr->type=TYP_INACTIVE;
									entr->entry=strdup(ptr1);
									entr->headerpos=pos;
									m->num_entrys++;
								}
							}
						}
					}
					break;

				case TYP_SHELLRESON:
				case TYP_SHELLRESOFF:
				case TYP_MENUSON:
				case TYP_MENUSOFF:
					if((ptr2=strstr(ptr1,",ICON="))!=NULL)
					{
						*ptr2=0;
					}
					if((ptr2=strxchr(ptr1,','))!=NULL)
					{
						if(i<TYP_EXECUTE)
						{
							ptr3=ptr2;
						}
						else
						{
							ptr2++;
							ptr3=strxchr(ptr2,',');
							ptr4=strxchr(ptr3+1,',');
						}
						if(ptr3!=NULL)
						{
							*ptr3=0;
							ptr3++;
							found=1;
							if(ptr4)
							{
								*ptr4=0;
							}
							pfound=system(ptr3);
							if((((i==TYP_SHELLRESON)||(i==TYP_MENUSON)) && !pfound) || (((i==TYP_SHELLRESOFF)||(i==TYP_MENUSOFF)) && pfound))
							{
								entr->type=(i<TYP_EXECUTE)?TYP_MENU:((strlen(ptr2))?TYP_EXECUTE:TYP_INACTIVE);
								entr->entry=strdup(ptr1);
								if(ptr4)
								{
									entr->message=strdup(ptr4+1);
								}
								entr->headerpos=pos;
								m->num_entrys++;
							}
							else
							{
								if(entr->showalways)
								{
									entr->type=TYP_INACTIVE;
									entr->entry=strdup(ptr1);
									entr->headerpos=pos;
									m->num_entrys++;
								}
							}
						}
					}
					break;
			}
			if(found && (i != TYP_COMMENT) && (i != TYP_INACTIVE))
			{
				m->num_active++;
			}
		}
	}
	free(wstr);
	return !found;
}
Beispiel #20
0
int main (int argc, char **argv)
{
	unsigned int margin_left_F, digit_width, margin_top_t, font_size, margin_top_box, margin_top_d, digits, secs_width, adj_height;
	int i = 0;
	int j = 0;
	int w = 0;
	int ms = 0;
	int mw = 0;
	int loop = 1;
	unsigned int newmail = 0;
	unsigned int mailgfx = 0;
	int xdir = 1, ydir = 1;
	double xstep = 1, ystep = 1; 
	double csx, cex, csy, cey;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2] = {0,0};
	FILE *tfh;

		printf("Clock / SSaver Version %s\n",CL_VERSION);

		for (i = 1; i < argc; i++)
		{
			if (!strncmp(argv[i], "-ss", 3))
			{
				ssaver = 1;
				continue;
			}
		}

		if (ssaver)
		{
			time(&atim);
			srand((unsigned int)atim);
			ReadConf(SCFG_FILE);
		}
		else
		{
			ReadConf(CCFG_FILE);
		}

		for (i = 1; i < argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if (!ssaver)
				{
					if(strstr(aptr,"X=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							xpos=j;
						}
					}	
					if(strstr(aptr,"Y=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							ypos=j;
						}
					}
					if(strstr(aptr,"MAIL=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							mail=j;
						}
					}
				}
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						show_date=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=(j)?1:0;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						show_sec=j;
					}
				}
				if(strstr(aptr,"BLINK=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						blink=j;
					}
				}
				if(strstr(aptr,"SLOW=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						if(!j)
						{
							j=1;
						}
						slow=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock / SSaver <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock / SSaver <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Clock / SSaver <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("Clock / SSaver <FT_Init_FreeType failed with Errorcode 0x%.2X>", error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("Clock / SSaver <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("Clock / SSaver <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("Clock / SSaver <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
#else
		desc.font.face_id = FONT;
#endif
#if FREETYPE_MAJOR  == 2 && FREETYPE_MINOR == 0
		desc.image_type = ftc_image_mono;
#else
		desc.flags = FT_LOAD_MONOCHROME;
#endif

		//init backbuffer

		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock / SSaver <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if (!slow)
			slow=1;

		if (slow>10)
			slow=10;

		if (fcol > MAXCOL && !(ssaver == 1 && fcol == 99))
			fcol = 2;
		if (bcol > 3 && !(bcol == 10))
			bcol = 1;

		if (ssaver)
		{
			memset(lbb, col[bcol], var_screeninfo.xres*var_screeninfo.yres);
			memset(lfb, col[bcol], var_screeninfo.xres*var_screeninfo.yres);
		}
		else
			memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		if (big)			//grosse Schrift (time/date)
		{
			margin_left_F = 3;			// 3
			digit_width = 14;			// 14
			margin_top_t = 26;			// 26
			font_size = BIG;			// 40
			margin_top_box = 30;		// 30
			margin_top_d = 60;			// 60
		}
		else
		{
			margin_left_F = 7;			//7  Abstand links
			digit_width = 12;			//12 Ziffernblockbreite
			margin_top_t = 19;			//19 Abstand "TimeString"-Unterkante von oben
			font_size = MED;			//30 Schriftgroesse
			margin_top_box = 20;		//20 Abstand Renderbox von oben
			margin_top_d = 40;			//40 Abstand "DateString" von oben
		}
		digits = 0;
		secs_width = 0;
		startx = sx;
		starty = sy;
		mw = (big) ? 42 : 36;			//mailwidth
		adj_height = 1 * (!big && !show_date); //max steprange == 3, so we need always a top/bottom margin of >=3

		if (!show_sec && !show_date)
		{
			digits = 3;				//3 Platzhalter ':ss'
			secs_width = digits * digit_width;
		}

		if (ssaver)
		{
			xpos = rand() %480 + 10;
			ypos = rand() %460 + 10;	
			xdir *= (rand() &1) == 0 ? -1 : 1;
			ydir *= (rand() &1) == 0 ? -1 : 1;
			xstep/=(double)slow;
			ystep/=(double)slow;
			if (fcol == 99)
			{
				cCol = 1;
				Change_Col(&fcol, &bcol);
			}
			InitRC();
		}

	while (loop)
	{
		if (ssaver)
			usleep(15000L);
		else
		{
			usleep(150000L);
			newmail = 0;
			if(mail && ExistFile(MAIL_FILE))
			{
				if((tfh = fopen(MAIL_FILE,"r")) != NULL)
				{
					if(fgets(tstr, 511, tfh))
					{
						if(sscanf(tstr, "%d", &i))
						{
							newmail = i;
						}
					}
					fclose(tfh);
				}
			}
		}

		time(&atim);
		ltim=localtime(&atim);
		if (show_sec)
		{
			sprintf(tstr,"%02d:%02d:%02d", ltim->tm_hour, ltim->tm_min, ltim->tm_sec);
		}
		else
		{
			if (blink)
				sprintf(tstr,"   %02d%c%02d", ltim->tm_hour, (ltim->tm_sec & 1)? ' ' : ':', ltim->tm_min);
			else
				sprintf(tstr,"   %02d:%02d", ltim->tm_hour, ltim->tm_min);
		}

		if (!ssaver)
		{
			if (((int)xpos >= mw) || (!show_sec))
			{
				ms = (int)xpos + ((show_sec) ? 0 : mw) - mw;	//mail left
			}
			else
			{
				ms = (int)xpos + 100 + 20 * big;		//mail right
			}
			//paint Backgroundcolor to clear digit
			RenderBox(xpos+secs_width, ypos, xpos+secs_width+100+20*big, ypos+margin_top_box + adj_height, FILL, col[bcol]);
		}

		if (ssaver)
		{
			xpos += xstep * (double)xdir;
			ypos += ystep * (double)ydir;

			csx = xpos + secs_width;
			csy = ypos;
			cex = xpos + secs_width + 100 + 20 * big;
			cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height;

			if ((int)csx < 0 || (sx + (int)cex) > ex)
			{
				if (cCol)
					Change_Col(&fcol, &bcol);
				xdir *= -1;
				xpos += xstep * (double)xdir;
				csx = xpos + secs_width;
				cex = xpos + secs_width + 100 + 20 * big;
				xstep = rand() &3;
				if (!xstep)
				{
					xstep = 1;
				}
				xstep /= (double)slow;
			}
			if ((int)csy < 0 || (sy + (int)cey) > ey)
			{
				if (cCol)
					Change_Col(&fcol, &bcol);
				ydir *= -1;
				ypos += ystep * (double)ydir;
				csy = ypos;
				cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height;	
				ystep = rand() &3;
				if (!ystep)
				{
					ystep = 1;
				}
				ystep /= (double)slow;
			}
			RenderBox(csx, csy, cex, cey, FILL, col[bcol]);
		}

		for (i = digits; i < strlen(tstr); i++)
		{
			*dstr = tstr[i];
			RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_t, 30, CENTER, font_size, col[fcol]);
		}

		if (show_date)
		{
			sprintf(tstr, "%02d.%02d.%02d", ltim->tm_mday, ltim->tm_mon + 1, ltim->tm_year - 100);
			if (!ssaver)
			{
			//Backgroundbox color Date
			RenderBox(xpos, ypos + margin_top_box, xpos + 100 + 20 * big, ypos + margin_top_d, FILL, col[bcol]);
			}
			for(i = 0; i < strlen(tstr); i++)
			{
				*dstr = tstr[i];
				RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_d - 2 - (2 * big), 30, CENTER, font_size, col[fcol]);
			}
		}

		if (ssaver)
		{
			w = 100 + 20 * big + ((show_sec) ? 0 : - secs_width);
			for (i = 0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
			{
				j = (starty + (int)ypos + i) * var_screeninfo.xres + (int)xpos + ((show_sec) ? 0 : secs_width) + startx;
				if ((j + w) < var_screeninfo.xres * var_screeninfo.yres)
				{
					memcpy(lfb+j, lbb+j, w);
				}
			}
		}
		else
		{
			if (newmail > 0)
			{
				mailgfx = 1;

				//Background mail, left site from clock
				RenderBox(ms, ypos, ms+mw, ypos+margin_top_box + adj_height, FILL, col[bcol]); //bcol

				if(!(ltim->tm_sec & 1))
				{
					RenderBox (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big), GRID,	col[fcol]);
					DrawLine  (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big),			col[fcol]);
					DrawLine  (ms+8, ypos+margin_top_box+adj_height-2-(3*big), ms+mw-8, ypos+5+(1+big),			col[fcol]);
					DrawLine  (ms+(9+1*big), ypos+4+(1+big), ms+(mw/2), ypos+1,                  				col[fcol]);
					DrawLine  (ms+(9+1*big), ypos+5+(1+big), ms+(mw/2), ypos+2,                  				col[fcol]);
					DrawLine  (ms+(mw/2), ypos+1, ms+mw-(9+1*big), ypos+4+(1+big),               				col[fcol]);
					DrawLine  (ms+(mw/2), ypos+2, ms+mw-(9+1*big), ypos+5+(1+big),               				col[fcol]);
				}
				else
				{
					sprintf(tstr,"%d",newmail);
					RenderString(tstr, ms, ypos+margin_top_t, mw, CENTER, font_size, col[fcol]);
				}
			}
			else
			{
				if (mailgfx > 0)
					RenderBox(ms, ypos, ms+mw, ypos + margin_top_box + adj_height, FILL, (!show_date || show_sec) ? TRANSP : col[bcol]);
				else
					ms=(int)xpos;
			}

			w = 100 + 20 * big + ((mailgfx) ? ((show_sec) ? mw : 0) : - secs_width);
			for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
			{
				j = (starty + (int)ypos + i) * var_screeninfo.xres + ( ((ms < (int)xpos) ? ms : (int)xpos) + ((show_sec) ? 0 : ((mailgfx) ? 0 : secs_width)) ) + startx;			
				if ((j + w) < var_screeninfo.xres * var_screeninfo.yres)
				{
					memcpy(lfb+j, lbb+j, w);
				}
			}
			if (newmail == 0 && mailgfx > 0)
				mailgfx = 0;
		}

		if (++loop > 10)
		{
			if ( (ssaver && (RCKeyPressed() || ExistFile("/tmp/.ssaver_kill")))
				|| (!ssaver && ExistFile("/tmp/.clock_kill")) )
				loop = 0;
		}
	}


/****************************
 * close down Clock / SSaver
 ****************************/
	if (ssaver)
	{
		memset(lfb, 0, var_screeninfo.xres*var_screeninfo.yres);
		remove("/tmp/.ssaver_kill");
		CloseRC();
	}
	else
	{
		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);
		remove("/tmp/.clock_kill");
		for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
		{
			j=(starty+(int)ypos+i)*var_screeninfo.xres+((ms<(int)xpos)?ms:(int)xpos)+((show_sec)?0:((mailgfx)?0:secs_width))+startx;
			if((j+100+20*big+((mail)?mw:0))<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, w);
			}
		}
	}

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);

	return 0;
}
Beispiel #21
0
int main (int argc, char **argv)
{
	int tv,index,i,j,k,w,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,x0,x1,x2,x3,x4,x5,x6,x7,ms,mw,newmail=0;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2]={0,0};
	FILE *tfh;

		printf("Clock Version %s\n",CL_VERSION);
		
		ReadConf();
	
		for(i=1; i<argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"X=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						xpos=j;
					}
				}
				if(strstr(aptr,"Y=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						ypos=j;
					}
				}
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						sdat=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=j;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						secs=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
				if(strstr(aptr,"MAIL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						mail=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
			
		for(index=CMCST; index<=CMH; index++)
		{
			sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				tr[index-1]=(tv<<8);

			sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				bl[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_green",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				gn[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_red",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				rd[index-1]=(tv+(tv<<8));
		}
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(ioctl(fb, FBIOGETCMAP, &colormap) == -1)
		{
			printf("Clock <FBIOGETCMAP failed>\n");
			return -1;
		}

		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Clock <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("Clock <FT_Init_FreeType failed with Errorcode 0x%.2X>", error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("Clock <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("Clock <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("Clock <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
#else
		desc.font.face_id = FONT;
#endif
#if FREETYPE_MAJOR  == 2 && FREETYPE_MINOR == 0
		desc.image_type = ftc_image_mono;
#else
		desc.flags = FT_LOAD_MONOCHROME;
#endif

	//init backbuffer

		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx;
		starty = sy;
		mw=(big)?40:30;

	while(loop)
	{
		usleep(150000L);
		newmail=0;
		if(mail && ExistFile(MAIL_FILE))
		{
			if((tfh=fopen(MAIL_FILE,"r"))!=NULL)
			{
				if(fgets(tstr,511,tfh))
				{
					if(sscanf(tstr,"%d",&i))
					{
						newmail=i;
					}
				}
				fclose(tfh);
			}
		}
		ioctl(fb, FBIOGETCMAP, &colormap);
		found=0;
		trnsp=0;
		for(i=colormap.start;i<colormap.len && found!=7;i++)
		{
			if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i])
			{
				cmc=i;
				found|=1;
			}
			if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000  && colormap.blue[i]>=0xF000 && !colormap.transp[i])
			{
				cmct=i;
				found|=2;
			}
			if(colormap.transp[i]>trnsp)
			{
				trnspi=i;
				trnsp=colormap.transp[i];
				found|=4;
			}
		}	

		if(big)
		{
			x0=3;
			x1=14;
			x2=26;
			x3=BIG;
			x4=30;
			x5=60;
		}
		else
		{
			x0=7;
			x1=12;
			x2=18;
			x3=MED;
			x4=18;
			x5=40;
		}
		x6=0;
		x7=0;
		time(&atim);
		ltim=localtime(&atim);
		if(secs)
		{
			sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec);
		}
		else
		{
			sprintf(tstr,"   %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min);
			if(!sdat)
			{
				x6=3;
				x7=36+4*big;
			}
		}
		if((xpos>=mw)||(!secs))
		{
			ms=xpos+((secs)?0:36+4*big)-mw;
		}
		else
		{
			ms=xpos+100+20*big;
		}
		k=((ms>xpos)&&mail)?mw:0;
		RenderBox(xpos+x7, ypos, xpos+x7+100+20*big, ypos+x2+2*(1+big), FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
		for(i=x6; i<strlen(tstr); i++)
		{
			*dstr=tstr[i];
			RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
		}

		if(sdat)
		{
			sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100);
			RenderBox(xpos, ypos+x4, xpos+100+20*big, ypos+x5, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
			for(i=0; i<strlen(tstr); i++)
			{
				*dstr=tstr[i];
				RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
			}
		}
		if(mail)
		{
			if(newmail)
			{
				RenderBox(ms, ypos, ms+mw, ypos+x2+2*(1+big), FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
				if(!(ltim->tm_sec & 1))
				{
					RenderBox(ms+5, ypos+5+(1+big), ms+mw-5, ypos+x2+(1+big)-2, GRID, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+5+(1+big), ms+mw-5, ypos+x2+(1+big)-2, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+x2+(1+big)-2, ms+mw-5, ypos+5+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+5+(1+big), ms+((mw-2)/2), ypos+2, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+6, ypos+6+(1+big), ms+((mw-2)/2)+1, ypos+3, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+((mw-2)/2), ypos+2, ms+mw-5, ypos+5+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+((mw-2)/2)+1, ypos+3, ms+mw-6, ypos+6+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
				}
				else
				{
					sprintf(tstr,"%d",newmail);
					RenderString(tstr, ms, ypos+x2, mw, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
				}
			}
			else
			{
				if(!sdat || secs)
				{
					RenderBox(ms+((ms>(xpos+100))?1:0), ypos, ms+mw-((k)?0:1), ypos+x2+2*(1+big), FILL, trnspi);
				}
			}
		}
		else
		{
			ms=xpos;
		}
		
		w=100+20*big+((mail)?5*big+((secs)?mw:0):0)+k-((k&&!sdat)?mw:0);
		for(i=0;i<=((sdat)?40:20)*(1+big);i++)
		{
			j=(starty+ypos+i)*var_screeninfo.xres+((ms<xpos)?ms:xpos)+startx;
			if((j+w)<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, w);
			}
		}
		if(++loop>5)
		{
			if(ExistFile("/tmp/.clock_kill"))
			{
				loop=0;
			}
		}	
	}	

	cmct=0;
	cmc=0;
	for(i=colormap.start;i<colormap.len;i++)
	{
		if(colormap.transp[i]>cmct)
		{
			cmc=i;
			cmct=colormap.transp[i];
		}
	}
	memset(lbb, cmc, var_screeninfo.xres*var_screeninfo.yres);
	for(i=0;i<=((sdat)?40:20)*(1+big);i++)
	{
		j=(starty+ypos+i)*var_screeninfo.xres+((ms<xpos)?ms:xpos)+startx;
		if((j+100+20*big+((mail)?mw:0))<var_screeninfo.xres*var_screeninfo.yres)
		{
			memcpy(lfb+j, lbb+j, w);
		}
	}
	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	remove("/tmp/.clock_kill");
	return 0;
}