// This is a recursive function that goes through each file or folder, starting in "startingPath", and if it's a file, it adds it to the "fileNames" array, if it's a folder, it goes inside this folder and does the same thing void goInside(char* startingPath, char*** fileNames, char* extFilter, long* currentFile) { // Opens the current dir DIR* pDir = opendir (startingPath); struct dirent *pDirent; if (pDir == NULL) { printf ("Cannot open directory: '%s'\n", startingPath); exit(1); } // Writes all the file names in this dir, into the file while ((pDirent = readdir(pDir)) != NULL) { char* fileName = pDirent->d_name; //Makes sure it doesn't write stuff like "." or ".." into the file if((strcmpi(fileName,".") != 0) && (strcmpi(fileName,"..") != 0)) { //Creates the complete path (E.g. from C:\folder goes to c:\folder\something) char* completePath = buildFullPath(startingPath,fileName); // If it's a file, not a folder if (!isDirectory(completePath)) { // If there is no extension restriction or the file we are reading matches the extension restriction if ((strcmpi(extFilter,"*") == 0) || (strcmpi(getFileExt(fileName),extFilter) == 0)) { (*fileNames) = (char**) realloc((*fileNames),((*currentFile) + 1) * sizeof(char*)); (*fileNames)[(*currentFile)] = (char*) malloc(strlen(fileName) + 1); // Allocates the string strcpy((*fileNames)[(*currentFile)],fileName); // Copies the file name to that string (*currentFile)++; } } else { strcat(completePath,"\\"); goInside(completePath,fileNames,extFilter,currentFile); } } } //Closes the dir and the file closedir (pDir); }
CGEventRef processEvent(CGEventType type, CGEventRef event) { CGKeyCode keycode = (CGKeyCode) CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); CGKeyCode autorepeat = (CGKeyCode) CGEventGetIntegerValueField(event, kCGKeyboardEventAutorepeat); if (outsideMirror) { // Outside mirror... if (type == kCGEventKeyDown) { if (autorepeat) { if (marked(outside, keycode)) { return passEvent(event); } else { return remapEvent(event); } } else { if (keycode == 49) { // space goInside(event); spaceDown = CGEventCreateCopy(event); return swallowEvent(event); } else { mark(outside, keycode); return passEvent(event); } } } else if (type == kCGEventKeyUp) { if (marked(outside, keycode)) { unmark(outside, keycode); return passEvent(event); } else { unmark(inside, keycode); return remapEvent(event); } } } else { // Inside mirror if (type == kCGEventKeyDown) { if (autorepeat) { if (keycode == 49) { // space return swallowEvent(event); } else { if (marked(inside, keycode)) { return remapEvent(event); } else { return passEvent(event); } } } else { mark(inside, keycode); mirrorCount++; return remapEvent(event); } } else if (type == kCGEventKeyUp) { if (keycode == 49) { // space goOutside(); if (burst(event)) { return emitSpace(event); } else { return swallowEvent(event); } } else { if (marked(inside, keycode)) { unmark(inside, keycode); return remapEvent(event); } else { return passEvent(event); } } } } printf("Leaking events?!\n"); return event; }