Ejemplo n.º 1
0
std::string
CommandEventHandler::power()
{
  std::ostringstream ret;

  ret << "Power status:" << ENDL;
  ret << "\tCurrent %: ";
  ret << readTextFile("/sys/class/power_supply/battery/capacity");
  ret << "\tStatus: ";
  ret << readTextFile("/sys/class/power_supply/battery/status");

  return ret.str();
}
Ejemplo n.º 2
0
 /**
  * Constructor
  */
 Shader::Shader(const std::string& filename, GLenum shaderType)
 : _handle   (0)
 {
    std::string source = readTextFile(filename);
    const GLchar* sourcePtr0 = source.c_str();
    const GLchar** sourcePtr = &sourcePtr0;
    
    // Set the source and attempt compilation
    _handle = glCreateShader(shaderType);
    GL_ERR_CHECK();
    
    glShaderSource(_handle, 1, sourcePtr, NULL);
    GL_ERR_CHECK();
    
    glCompileShader(_handle);
    GL_ERR_CHECK();
    
    if(!getCompileStatus())
    {
       std::stringstream err;
       err << "Failed to compile shader file: " << filename << std::endl;
       err << getLog() << std::endl;
       throw std::runtime_error(err.str());
    }
 }
Ejemplo n.º 3
0
	VkShaderModule loadShaderGLSL(const char *fileName, VkDevice device, VkShaderStageFlagBits stage)
	{
		std::string shaderSrc = readTextFile(fileName);
		const char *shaderCode = shaderSrc.c_str();
		size_t size = strlen(shaderCode);
		assert(size > 0);

		VkShaderModule shaderModule;
		VkShaderModuleCreateInfo moduleCreateInfo;
		VkResult err;

		moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
		moduleCreateInfo.pNext = NULL;

		moduleCreateInfo.codeSize = 3 * sizeof(uint32_t) + size + 1;
		moduleCreateInfo.pCode = (uint32_t*)malloc(moduleCreateInfo.codeSize);
		moduleCreateInfo.flags = 0;

		// Magic SPV number
		((uint32_t *)moduleCreateInfo.pCode)[0] = 0x07230203; 
		((uint32_t *)moduleCreateInfo.pCode)[1] = 0;
		((uint32_t *)moduleCreateInfo.pCode)[2] = stage;
		memcpy(((uint32_t *)moduleCreateInfo.pCode + 3), shaderCode, size + 1);

		err = vkCreateShaderModule(device, &moduleCreateInfo, NULL, &shaderModule);
		assert(!err);

		return shaderModule;
	}
Ejemplo n.º 4
0
void WinImage::slotOpen()
{
    //if ( maybeSave()) {
    QString fileName = QFileDialog::getOpenFileName(this, "Open image or text file", ".", "*.bmp *.jpg *.txt");

    _filenameStem = fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1);
    _filenameStem = _filenameStem.left(_filenameStem.lastIndexOf('.'));

    qDebug() << fileName;

    if (fileName.endsWith("txt"))
    {
        _data = readTextFile(fileName.toStdString().data(), &_count);
        if (!_data) return;

        _scale = _a_number->value();
        _image = loadDataImage(_image, _data, _count, _scale);
        //_imageOrig = QImage( _image);
        update();

        int H = _image.height(), W = _image.width();
        resize (W + 2 * _offset.x(), H + 2 * _offset.y());
    }
    else if (!fileName.isEmpty()) loadImage(fileName);
    //}
}
Ejemplo n.º 5
0
LumiFile::LumiFile(const char* FileName) :
	_fileName(QFileInfo(FileName).fileName()),
	_series(), 
	_error(),
	_isCSFile(false)
{
	ifstream in(FileName);
	if (!in) 
	{
		_error.append(new LumiError(QString("Could not open file %1").arg(fileName()))); 
		return;
	}
	switch (in.peek())
	{
		case ('\0') : {readLumicycle (FileName); break;}
		case (236)  : {readChronostar(FileName); break;}
		default     : {readTextFile  (in);}
	}
	in.close();
// 	if (nTimes() == 0) throw ZeroTimesInFile();
// 	if (nSeries() == 0) throw ZeroSeriesInFile();
// 	_td->makeTime24Data();
// 	double endTime = ceil(maxTime()*24.0)/24.0;
// 	for (unsigned int i = 0; i < nSeries(); i++) 
// 	{
// 		TimeSeries *ts = series(i);
// 		if (ts->stopMean()  < 0) ts->_stopMean  = endTime;
// 		if (ts->stopTrend() < 0) ts->_stopTrend = endTime;
// 		if (ts->stopFit()   < 0) ts->_stopFit   = endTime;
// 		ts->setLog(defaultLog, true); // smooth, fit and calcMean are called by this function
// 	}
}
Ejemplo n.º 6
0
int editAppList(){
	appList_add("app5");
	appList_remove("app2");
	char* str = readTextFile("/usr/lib/nwjs/appList"); //This is run in chroot environment, initializad by a previous test.
	int result = strcmp(str, "app1\napp3\napp4\napp5\n") == 0;
	free(str);
	return result;
}
Ejemplo n.º 7
0
void
GLSLProgram::loadFromFiles(const char *vFilename,  const char *gFilename, const char *fFilename,
                           GLenum gsInput, GLenum gsOutput, int maxVerts)
{
    char *vsource = readTextFile(vFilename);
    char *gsource = 0;
    if (gFilename) {
        gsource = readTextFile(gFilename);
    }
    char *fsource = readTextFile(fFilename);

    mProg = compileProgram(vsource, gsource, fsource, gsInput, gsOutput, maxVerts);

    delete [] vsource;
    if (gsource) delete [] gsource;
    delete [] fsource;
}
Ejemplo n.º 8
0
/* Create shader instance and read source from file system */ 
GLuint loadShader(const char * srcPath, GLenum shaderType)
{
	GLuint shader = glCreateShader(shaderType);
	FILE * fp = fopen(srcPath, "rb");
	char *src = readTextFile(fp);
	fclose(fp);
	glShaderSource(shader,1,(const GLchar**)&src,NULL);
	free(src);
	return shader;
} 
Ejemplo n.º 9
0
bool GLSLProgram::setIncludeFromFile(const char *includeName, const char* filename)
{
    char tmpstr[200];
    sprintf(tmpstr, "%s/%s", filename, includeName);
    char * incStr = readTextFile(tmpstr);
    if(!incStr)
        return false;
    sprintf(tmpstr, "/%s", includeName);
    glNamedStringARB(GL_SHADER_INCLUDE_ARB, strlen(tmpstr), tmpstr, strlen(incStr), incStr);
    return false;
}
Ejemplo n.º 10
0
// this is not cross platform
std::string
CommandEventHandler::uptimemillis()
{
  std::string uptime_file = readTextFile("/proc/uptime");
  double uptime;
  sscanf(&uptime_file[0], "%lf", &uptime);
  uptime *= 1000;
  std::ostringstream out;
  out << (int) uptime;
  return out.str();
}
Ejemplo n.º 11
0
int main(uint32_t startloc) {
	cpu_clock_init();
	ssp_clock_init();
	systickInit();

//	cpu_clock_set(204);

	SETUPgout(EN_VDD);
	SETUPgout(MIXER_EN);
	SETUPgout(MIC_AMP_DIS);

	SETUPgout(LED1);
	SETUPgout(LED2);
	SETUPgout(LED3);
	SETUPgout(LED4);
	inputInit();
	flashInit();

	lcdInit();
	fsInit();
	lcdFill(0xff); /* Display BL Image here */

	sli=startloc;

	if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ 
        char filename[FLEN];
        switch(getInputRaw()){
            case BTN_LEFT:
                getInputWaitRelease();
                doRealExec(1);
                break;
            case BTN_UP:
                doMSC();
            default:
            case BTN_NONE:
                readTextFile(BOOTCFG, filename, FLEN);
                lcdPrintln("Booting:");
                lcdPrintln(filename);
                bootFile(filename);
                break;
		};
	};
	static const struct MENU main={ "Bootloader", {
		{ "Exec Firmware", &doExec},
		{ "MSC", &doMSC},
		{ "Flash Boot Ldr", &doFlash},
		{ "Info", &doInfo},
		{NULL,NULL}
	}};
	do {
		handleMenu(&main);
	}while(1);
}
Ejemplo n.º 12
0
QString Renderer::readShader(const QString &fileName)
{
  QString newCode;
  QString code = readTextFile(fileName);
  QStringList lines = code.split("\n");

  foreach (QString line, lines)
  {
    QString pragma = "#pragma include";
    int i = line.indexOf(pragma);

    if (i >= 0)
    {
      line = line.mid(pragma.size()).simplified();
      line = line.remove("\"");

      line = readTextFile(line);
    }

    newCode += line + "\n";
  }
Ejemplo n.º 13
0
int writeReadTextFile(){
	char *str = "this\nis\na\ntest\nstring";
	int result = writeTextFile("testTextFile.txt", str);
	if(!result)
		return 0;
	char *readStr = readTextFile("testTextFile.txt");
	if(!readStr)
		return 0;
	result = strcmp(str, readStr);
	free(readStr);
	return result == 0;
}
Ejemplo n.º 14
0
GLuint
GLSLProgram::compileProgramFromFiles(const char *vFilename,  const char *gFilename, const char *fFilename,
                           GLenum gsInput, GLenum gsOutput, int maxVerts)
{
    char *vsource = readTextFile(vFilename);
    char *gsource = 0;
    if (gFilename) {
        gsource = readTextFile(gFilename);
    }
    char *fsource = readTextFile(fFilename);
    if(vsource)
    {
        GLSLProgram::setShaderNames(NULL, vFilename, gFilename, fFilename);
        mProg = compileProgram(vsource, gsource, fsource, gsInput, gsOutput, maxVerts);
        delete [] vsource;
        if (gsource) delete [] gsource;
        delete [] fsource;
        return mProg;
    }
    return 0;
}
Ejemplo n.º 15
0
void createProgram() {
    const GLchar* vertexShaderSource = readTextFile("tutorial08.vert");
    int vertexShaderSourceLength = strlen(vertexShaderSource);
    GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShaderId, 1, &vertexShaderSource, &vertexShaderSourceLength);
    glCompileShader(vertexShaderId);
	checkShaderCompileStatus(vertexShaderId);

    const GLchar* fragmentShaderSource = readTextFile("tutorial08.frag");
    int fragmentShaderSourceLength = strlen(fragmentShaderSource);
    GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShaderId, 1, &fragmentShaderSource, &fragmentShaderSourceLength);
    glCompileShader(fragmentShaderId);
	checkShaderCompileStatus(fragmentShaderId);

    programId = glCreateProgram();
    glAttachShader(programId, vertexShaderId);
    glAttachShader(programId, fragmentShaderId);
    glBindAttribLocation(programId, POSITION_ATTRIBUTE_INDEX, "vPosition");
    glBindAttribLocation(programId, NORMAL_ATTRIBUTE_INDEX, "vNormal");
    glLinkProgram(programId);
    checkProgramLinkStatus(programId);
}
Ejemplo n.º 16
0
/**
* Creates the output HTML file.
**/
void writeOutput(const std::list<Event>& list, std::list<TimedBlock*>& blockResults, std::list<TimedBlock*>& functionResults)
{
	msg("Generating the output file...\n");

	std::string pluginDir = ::idadir("plugins");
	std::string hotchDir = pluginDir + "/hotch";

	char filename[40] = {0};

	sprintf(filename, "results.html");
//	sprintf(filename, "results-%d.html", currentTime);

	std::string templateString;
	
	if (!readTextFile(hotchDir + "/template.htm", templateString))
	{
		msg("Could not read template file\n");
		return;
	}

	IdaFile file;

	unsigned int functions = file.getNumberOfFunctions();
	unsigned int hitFunctions = countHitBlocks(functionResults);
	unsigned int unhitFunctions = functions - hitFunctions;

	unsigned int blocks = file.getDebugger().getNumberOfBreakpoints();
	unsigned int hitBlocks = countHitBlocks(blockResults);
	unsigned int unhitBlocks = blocks - hitBlocks;	

	replaceString(templateString, "%FILENAME%", file.getInputfilePath());
	replaceString(templateString, "%NUMBER_OF_FUNCTIONS%", toString(functions));
	replaceString(templateString, "%NUMBER_OF_HIT_FUNCTIONS%", toString(hitFunctions));
	replaceString(templateString, "%NUMBER_OF_HIT_FUNCTIONS_PERCENTAGE%", floatToString(100.0 * hitFunctions / functions));
	replaceString(templateString, "%NUMBER_OF_NOT_HIT_FUNCTIONS%", toString(unhitFunctions));
	replaceString(templateString, "%NUMBER_OF_NOT_HIT_FUNCTIONS_PERCENTAGE%", floatToString(100.0 * unhitFunctions / functions));
	replaceString(templateString, "%NUMBER_OF_BLOCKS%", toString(blocks));
	replaceString(templateString, "%NUMBER_OF_HIT_BLOCKS%", toString(hitBlocks));
	replaceString(templateString, "%NUMBER_OF_HIT_BLOCKS_PERCENTAGE%", floatToString(100.0 * hitBlocks / blocks));
	replaceString(templateString, "%NUMBER_OF_NOT_HIT_BLOCKS%", toString(unhitBlocks));
	replaceString(templateString, "%NUMBER_OF_NOT_HIT_BLOCKS_PERCENTAGE%", floatToString(100.0 * unhitBlocks / blocks));
	replaceString(templateString, "%FUNCTIONS_BY_HITS%", generateFunctionTable(functionResults, sortByHits));
	replaceString(templateString, "%FUNCTIONS_BY_TIME%", generateFunctionTable(functionResults, sortByTime));
	replaceString(templateString, "%FUNCTIONS_BY_AVERAGE_TIME%", generateFunctionTable(functionResults, sortByAverageTime));
	replaceString(templateString, "%BLOCKS_BY_HITS%", generateBlocksTable(blockResults, sortByHits));
	replaceString(templateString, "%BLOCKS_BY_TIME%", generateBlocksTable(blockResults, sortByTime));
	replaceString(templateString, "%ALL_EVENTS%", generateEventsTable(list));

	writeOutput(hotchDir + "/" + filename, templateString);
}
Ejemplo n.º 17
0
	void FastXmlDocument::getXMLAsLines(string path, vector<FastXmlLine*> *lines) {
		
		char *data = readTextFile(path);
		char *head = data;
		head = nextTag(head);
		bool foundData = false;
		while(head<end) {
			
			head = nextData(head, foundData);
			if(foundData) lines->push_back(new FastXmlLine(tagBuffer));
			head = nextTag(head);
			lines->push_back(new FastXmlLine(tagBuffer));
			
		}
		delete [] data;
	}
Ejemplo n.º 18
0
int main(uint32_t startloc) {
	cpu_clock_init();
	ssp_clock_init();
	systick_set_reload(208000);
	systick_set_clocksource(0);
	systick_interrupt_enable();
	systick_counter_enable();

//	cpu_clock_pll1_max_speed();

	SETUPgout(EN_VDD);
	SETUPgout(MIXER_EN);

	SETUPgout(LED1);
	SETUPgout(LED2);
	SETUPgout(LED3);
	SETUPgout(LED4);
	inputInit();
	flashInit();

    lcdInit();
	fsInit();
    lcdFill(0xff); /* Display BL Image here */

	sli=startloc;

	if (startloc != (uintptr_t)&_app_start){ /* not booted via DFU, do autoboot */ 
		if (getInputRaw()!=BTN_LEFT){
			char filename[FLEN];
			readTextFile(BOOTCFG, filename, FLEN);
			lcdPrintln("Fname");
			lcdPrintln(filename);
			bootFile(filename,0);
		};
	};
	static const struct MENU main={ "Bootloader", {
		{ "Info", &doInfo},
		{ "Exec", &doExec},
		{ "Flash", &doFlash},
		{NULL,NULL}
	}};
	handleMenu(&main);
	return 0;
}
Ejemplo n.º 19
0
void MShaderRef::update(void)
{
	MEngine * engine = MEngine::getInstance();
	MLevel * level = engine->getLevel();
	MRenderingContext * render = engine->getRenderingContext();

	char * text = readTextFile(getFilename());
	if(text)
	{
		// gen shader if null
		if(m_shaderId == 0)
		{
			switch(m_type)
			{
			case M_SHADER_VERTEX:
				render->createVertexShader(&m_shaderId);
				break;
			case M_SHADER_PIXEL:
				render->createPixelShader(&m_shaderId);
				break;
			}
		}

		// send shader source
		render->sendShaderSource(m_shaderId, text);
		SAFE_FREE(text);

		MFXManager * FXManager = level->getFXManager();

		unsigned int i;
		unsigned int size = FXManager->getFXRefsNumber();
		for(i=0; i<size; i++)
		{
			MFXRef * FXRef = FXManager->getFXRef(i);
			if((FXRef->getPixelShaderRef() == this) || (FXRef->getVertexShaderRef() == this))
			{
				unsigned int FXId = FXRef->getFXId();
				render->updateFX(FXId);
			}
		}
	}
}
Ejemplo n.º 20
0
void InitializeParameters::load() {
  try {
    InitializeParameters defaultValues;
    RegistryKey key = getKey();
    m_elementCount        =  key.getInt(   _T("elementcount")    , (UINT)defaultValues.m_elementCount);
    m_elementSize         =  key.getInt(   _T("elementsize")     , defaultValues.m_elementSize );
    String initMethodName =  key.getString(_T("initmethod")      , _T("random")                    );
    m_initMethod = nameToInitMethod(initMethodName);

    m_randomizationMethod = (RandomizationMethod)key.getInt(    _T("randomize")       , defaultValues.m_randomizationMethod);
    m_seed                = key.getUint(   _T("seed")            , defaultValues.m_seed        );
    m_periodCount         = key.getUint(   _T("periodcount")     , defaultValues.m_periodCount );
    m_fileName            = key.getString( _T("filename")        , defaultValues.m_fileName    );
    if(m_initMethod == IDC_RADIO_FILEDATA) {
      readTextFile(m_fileName);
    }
  } catch(Exception e) {
    setDefault();
  }
}
Ejemplo n.º 21
0
void DelimitedFile::read(const std::string& fileName)
{
  m_lines.clear();
  m_lines.clear();
  std::string s = readTextFile(fileName);
  s += '\n';
  std::string ss;
  for(std::string::size_type i = 0;i < s.length();i++)
    {
      if (s[i] == '\r')
	continue;
      if (s[i] == '\n')
	{
	  ss = cutComment(ss);
	  if (!trim(ss).empty())
	    m_lines.push_back(ss);
	  ss.erase();
	  continue;
	} // if '\n';
      ss+= s[i];
    } // for;
}
Ejemplo n.º 22
0
//  clipWatcherWndProc
//
static LRESULT CALLBACK clipWatcherWndProc(
    HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
{
    //fwprintf(stderr, L"msg: %x, hWnd=%p, wParam=%p\n", uMsg, hWnd, wParam);

    switch (uMsg) {
    case WM_CREATE:
    {
        // Initialization.
        CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
        ClipWatcher* watcher = (ClipWatcher*)(cs->lpCreateParams);
        if (watcher != NULL) {
            SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)watcher);
            if (logfp != NULL) {
                fwprintf(logfp, L"watcher: %s\n", watcher->name);
            }
            // Start watching the clipboard content.
            AddClipboardFormatListener(hWnd);
            SetTimer(hWnd, watcher->blink_timer_id, ICON_BLINK_INTERVAL, NULL);
            SetTimer(hWnd, watcher->check_timer_id, FILESYSTEM_INTERVAL, NULL);
            SendMessage(hWnd, WM_TASKBAR_CREATED, 0, 0);
        }
        return FALSE;
    }

    case WM_DESTROY:
    {
        // Clean up.
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        if (watcher != NULL) {
            KillTimer(hWnd, watcher->blink_timer_id);
            KillTimer(hWnd, watcher->check_timer_id);
            // Stop watching the clipboard content.
            RemoveClipboardFormatListener(hWnd);
            // Unregister the icon.
            NOTIFYICONDATA nidata = {0};
            nidata.cbSize = sizeof(nidata);
            nidata.hWnd = hWnd;
            nidata.uID = watcher->icon_id;
            Shell_NotifyIcon(NIM_DELETE, &nidata);
        }
        PostQuitMessage(0);
        return FALSE;
    }

    case WM_CLIPBOARDUPDATE:
    {
        // Clipboard change detected.
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        if (watcher != NULL) {
            DWORD seqno = GetClipboardSequenceNumber();
            if (watcher->seqno < seqno) {
                watcher->seqno = seqno;
                if (logfp != NULL) {
                    fwprintf(logfp, L"updated clipboard: seqno=%d\n", seqno);
                }
                for (int i = 0; i < CLIPBOARD_RETRY; i++) {
                    Sleep(CLIPBOARD_DELAY);
                    if (OpenClipboard(hWnd)) {
                        if (GetClipboardData(CF_ORIGIN) == NULL) {
                            WCHAR path[MAX_PATH];
                            StringCchPrintf(path, _countof(path), L"%s\\%s",
                                            watcher->dstdir, watcher->name);
                            exportClipFile(path);
                        }
                        WCHAR text[256];
                        int filetype = getClipboardText(text, _countof(text));
                        if (0 <= filetype) {
                            NOTIFYICONDATA nidata = {0};
                            nidata.cbSize = sizeof(nidata);
                            nidata.hWnd = hWnd;
                            nidata.uID = watcher->icon_id;
                            nidata.uFlags = NIF_INFO;
                            nidata.dwInfoFlags = NIIF_INFO;
                            nidata.uTimeout = 1;
                            StringCchCopy(nidata.szInfoTitle,
                                          _countof(nidata.szInfoTitle),
                                          MESSAGE_UPDATED);
                            StringCchCopy(nidata.szInfo,
                                          _countof(nidata.szInfo),
                                          text);
                            Shell_NotifyIcon(NIM_MODIFY, &nidata);
                            watcher->icon_blinking = HICON_FILETYPE[filetype];
                            watcher->icon_blink_count = ICON_BLINK_COUNT;
                        }
                        CloseClipboard();
                        break;
                    }
                }
            }
        }
        return FALSE;
    }

    case WM_NOTIFY_FILE:
    {
        // File change detected.
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        if (watcher != NULL) {
            FileEntry* entry = checkFileChanges(watcher);
            if (entry != NULL) {
                if (logfp != NULL) {
                    fwprintf(logfp, L"updated file: path=%s\n", entry->path);
                }
                int index = rindex(entry->path, L'.');
                if (0 <= index) {
                    WCHAR* ext = &(entry->path[index]);
                    if (_wcsicmp(ext, FILE_EXT_TEXT) == 0) {
                        // CF_UNICODETEXT
                        int nchars;
                        LPWSTR text = readTextFile(entry->path, &nchars);
                        if (text != NULL) {
                            if (OpenClipboard(hWnd)) {
                                EmptyClipboard();
                                setClipboardOrigin(entry->path);
                                setClipboardText(text, nchars);
                                CloseClipboard();
                            }
                            free(text);
                        }
                    } else if (_wcsicmp(ext, FILE_EXT_BITMAP) == 0) {
                        // CF_DIB
                        BITMAPINFO* bmp = readBMPFile(entry->path);
                        if (bmp != NULL) {
                            if (OpenClipboard(hWnd)) {
                                EmptyClipboard();
                                setClipboardOrigin(entry->path);
                                setClipboardDIB(bmp);
                                CloseClipboard();
                            }
                            free(bmp);
                        }
                    }
                }
            }
        }
        return FALSE;
    }

    case WM_COMMAND:
    {
        // Command specified.
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        switch (LOWORD(wParam)) {
        case IDM_OPEN:
            if (watcher != NULL) {
                if (OpenClipboard(hWnd)) {
                    openClipFile();
                    CloseClipboard();
                }
            }
            break;
        case IDM_EXIT:
            SendMessage(hWnd, WM_CLOSE, 0, 0);
            break;
        }
        return FALSE;
    }

    case WM_TIMECHANGE:
    {
        // Filesytem/Network share change detected.
        // NOTICE: We wanted to check if wParam is DBT_DEVICEARRIVAL.
        //   But it doesn't work when the system is suspended.
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        if (watcher != NULL) {
            // Re-initialize the watcher object.
            StopClipWatcher(watcher);
        }
        return TRUE;
    }

    case WM_NOTIFY_ICON:
    {
        // UI event handling.
        POINT pt;
        HMENU menu = GetMenu(hWnd);
        if (menu != NULL) {
            menu = GetSubMenu(menu, 0);
        }
        switch (lParam) {
        case WM_LBUTTONDBLCLK:
            if (menu != NULL) {
                UINT item = GetMenuDefaultItem(menu, FALSE, 0);
                SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(item, 1), NULL);
            }
            break;
        case WM_LBUTTONUP:
            break;
        case WM_RBUTTONUP:
            if (GetCursorPos(&pt)) {
                SetForegroundWindow(hWnd);
                if (menu != NULL) {
                    TrackPopupMenu(menu, TPM_LEFTALIGN,
                                   pt.x, pt.y, 0, hWnd, NULL);
                }
                PostMessage(hWnd, WM_NULL, 0, 0);
            }
            break;
        }
        return FALSE;
    }

    case WM_TIMER:
    {
        LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
        ClipWatcher* watcher = (ClipWatcher*)lp;
        if (watcher != NULL) {
            UINT_PTR timer_id = wParam;
            if (timer_id == watcher->blink_timer_id) {
                // Blink the icon.
                if (watcher->icon_blink_count) {
                    watcher->icon_blink_count--;
                    BOOL on = (watcher->icon_blink_count % 2);
                    NOTIFYICONDATA nidata = {0};
                    nidata.cbSize = sizeof(nidata);
                    nidata.hWnd = hWnd;
                    nidata.uID = watcher->icon_id;
                    nidata.uFlags = NIF_ICON;
                    nidata.hIcon = (on? watcher->icon_blinking : HICON_EMPTY);
                    Shell_NotifyIcon(NIM_MODIFY, &nidata);
                }
            } else if (timer_id == watcher->check_timer_id) {
                // Check the filesystem.
                StartClipWatcher(watcher);
            }
        }
        return FALSE;
    }

    case WM_CLOSE:
        DestroyWindow(hWnd);
        return FALSE;

    default:
        if (uMsg == WM_TASKBAR_CREATED) {
            LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_USERDATA);
            ClipWatcher* watcher = (ClipWatcher*)lp;
            if (watcher != NULL) {
                // Register the icon.
                NOTIFYICONDATA nidata = {0};
                nidata.cbSize = sizeof(nidata);
                nidata.hWnd = hWnd;
                nidata.uID = watcher->icon_id;
                nidata.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
                nidata.uCallbackMessage = WM_NOTIFY_ICON;
                nidata.hIcon = HICON_EMPTY;
                StringCchPrintf(nidata.szTip, _countof(nidata.szTip),
                                MESSAGE_WATCHING, watcher->srcdir);
                Shell_NotifyIcon(NIM_ADD, &nidata);
            }
        }
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
}
Ejemplo n.º 23
0
void init_nick(void){
	readTextFile("nick.cfg",GLOBAL(nickname),MAXNICK);
	readTextFile("font.cfg",GLOBAL(nickfont),FLEN);
	readTextFile("l0nick.cfg",GLOBAL(nickl0),FLEN);
}
Ejemplo n.º 24
0
// need to figure a better way
std::string
CommandEventHandler::screen()
{
  return readTextFile("/sys/devices/virtual/graphics/fb0/modes");
}
Ejemplo n.º 25
0
void init_rgbLeds(void) {
	readTextFile("ledfile.cfg",GLOBAL(ledfile),FLEN);
	readRgbLedFile();
}
Ejemplo n.º 26
0
GLuint createProgram(char const *vshFileName, char const *fshFileName)
{
    GLint info;
    char *log;

    GLuint vsh, fsh, program;
    char *vshCode, *fshCode;

    vshCode = readTextFile(vshFileName);
    if (vshCode == NULL)
    {
        //fprintf(stderr, "Nao foi possivel ler o arquivo \"%s\"\n", vshFileName);
        return 0u;
    }

    fshCode = readTextFile(fshFileName);
    if (fshCode == NULL)
    {
        //fprintf(stderr, "Nao foi possivel ler o arquivo \"%s\"\n", fshFileName);
        return 0u;
    }

    vsh = createShader(vshCode, GL_VERTEX_SHADER);
    free(vshCode);

    if (vsh == 0u)
    {
        free(fshCode);
        return 0u;
    }

    fsh = createShader(fshCode, GL_FRAGMENT_SHADER);
    free(fshCode);

    if (fsh == 0u)
    {
        return 0u;
    }

    program = glCreateProgram();
    if (program == 0u)
    {
        //fprintf(stderr, "Nao foi possivel criar um objeto programa (shader).\n");
        glDeleteShader(vsh);
        glDeleteShader(fsh);
        return 0u;
    }

    glAttachShader(program, vsh);
    glAttachShader(program, fsh);
    glLinkProgram(program);
    glDeleteShader(vsh);
    glDeleteShader(fsh);

    glGetProgramiv(program, GL_LINK_STATUS, &info);
    if (info == GL_FALSE)
    {
        //fprintf(stderr, "Nao foi possivel linkar um programa:\n");

        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info);

        log = (char*)malloc(info);

        glGetProgramInfoLog(program, info, &info, log);
        printf("%s\n", log);

        glDeleteProgram(program);
        return 0u;
    }

    return program;
}