Exemplo n.º 1
0
int main(int argc, char** argv)
{
	if (argc > 1 && !strcmp(argv[1], "-v")) {
		g_verbose = true;
		++argv;
		--argc;
	}
	if (argc > 1 && !strcmp(argv[1], "-r")) {
		g_recursive = true;
		++argv;
		--argc;
	}
	if (argc != 3) {
		fprintf(stderr, "Usage: treecat treeLocation boxcode\n");
		exit(1);
	}

	char* boxcode = argv[2];
	g_treeLocation = argv[1];
	char fileboxcode[1000];
	strcpy(fileboxcode, boxcode);
	FILE* fp = 0;
	int fileBoxLength;
	for (fileBoxLength = strlen(boxcode); fileBoxLength >= 0; --fileBoxLength) {
		fileboxcode[fileBoxLength] = '\0';
		fp = openBox(fileboxcode);
		if (fp)
			break;
	}
	boxcode += fileBoxLength;

	char fullboxcode[1000];
	strcpy(fullboxcode, fileboxcode);
	strcat(fullboxcode, boxcode);
	char buf[10000];
	while (*boxcode && fgets(buf, sizeof(buf), fp)) {
		if (buf[0] != 'X') {
			*boxcode = '\0';
			fprintf(stderr, "box = %s\n", argv[2]);
			fputs(buf, stdout);
			exit(0);
		}
		if (*boxcode == '1')
			processTree(fp, false, boxcode);
		++boxcode;
	}
	processTree(fp, true, fullboxcode);
}
Exemplo n.º 2
0
void doit(char *filename)
{
	startup();
	FILE *fp = NULL;

	__try
	{
		char filepath[257];
		sprintf(filepath, "%s\\gdi_trial.phashc", filename);

		fopen_s(&fp, filepath, "w+");
		fprintf(fp, "%s\n", filename);

		processTree("", filename, fp);
		fclose(fp);
	}
	__finally
	{
		shutdown();
		if (fp != NULL)
		{
			fflush(fp);
			fclose(fp);
		}
	}
}
Exemplo n.º 3
0
/*
*   processes call tree.
*   runs if command, if successful run commands in then block otherwise 
*   runs commands in else block. 
*   calls itself if command is nested_if block
*   parameters: IFBLOCK* ifBlock - processes tree rooted at ifBlock 
*   returns : 0 if success otherwise 1
*/
static int processTree(IFBLOCK* ifBlock)
{
    int result;//result of processing
    COMMSEQ* node;//for linked list iteration
    IFBLOCK* currIfBlock;//poiner to nested if block
    char* command,**arglist;//for convenience
    
    result = execCommand(ifBlock->commandargs + 1);//result of if commad
    node = (result == 0) ? ifBlock->thenComSeq 
                            : ifBlock->elseComSeq;//which block to execute
    while(node != NULL)
    {
        if(node->type == COMMAND){//executable command
            command = (char*)node->cmd;
            arglist = splitline(command);//get command args
            result = execCommand(arglist);//execute command
        }
        else{//nested_if block
            currIfBlock = (IFBLOCK*)node->cmd;
            result = processTree(currIfBlock);//recursively process nested if
        }
        node = node->next;//go to next node
    }
    return result;
}
Exemplo n.º 4
0
/*
*   public function:
*   calls private function processTree() to process call tree
*   calls clearCallTree()  to destroy the tree
*   returns : 0 if success otherwise 1
*/
int processCallTree()
{
    int ret;
    
    ret = processTree(the_if_block);//process tree
    clearCallTree();//destroy tree
    return ret;
}
Exemplo n.º 5
0
// Process a directory tree: for each jpg file, calculate the phash,
// and write the hash value and file string to the output file.
void processTree(const char *path, char *basepath, FILE *fp)
{
	std::list<std::string> folders;
	std::vector<std::string> files;

	char thispath[257];
	char apath[257];

	sprintf(thispath, "%s%s", basepath, path);
	struct dirent *dent;
	DIR *srcdir = opendir(thispath);
	if (srcdir == NULL)
		return;

	while ((dent = readdir(srcdir)) != NULL)
	{
		struct stat st;

		if (dent->d_name[0] == '.')
			continue;

		if (strlen(thispath) + strlen(dent->d_name) > 256)
		{
			printf("Path too long:%s", dent->d_name);
			continue;
		}

		sprintf(apath, "%s\\%s", thispath, dent->d_name);
		stat(apath, &st);

		if (st.st_mode & _S_IFDIR) // recurse into subdirectories
		{
			sprintf(apath, "%s\\%s", path, dent->d_name);
			folders.push_back(apath);
//			processTree(apath, basepath, fp);
		}
		else
		{
			files.push_back(apath);
//			processFile(apath, basepath, fp);
		}
	}
	closedir(srcdir);

	int max = files.size();
#pragma omp parallel for
	for (int dex = 0; dex < max; dex++)
	{
		processFile((char *)(files[dex].c_str()), basepath, fp);
	}
	for (std::list<std::string>::iterator it = folders.begin(); it != folders.end(); ++it)
	{
		processTree((*it).c_str(), basepath, fp);
	}
}
/*
 * Class:     java_awt_KeyboardFocusManager
 * Method:    clearGlobalFocusOwner
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_java_awt_KeyboardFocusManager__1clearGlobalFocusOwner
    (JNIEnv *env, jobject self)
{
  /* Redirect focus to the focus proxy of the active Window. The effect
     we want is for the active Window to remain active, but for none of
     its children to be the focus owner. AWT maintains state to know
     that any key events delivered after this call (but before focus is
     re-established elsewhere) get ignored. */

    jobject activeWindow;
    Widget proxy;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return;
    }

    AWT_LOCK();

    activeWindow = (*env)->CallStaticObjectMethod
        (env, keyboardFocusManagerIDs.keyboardFocusManagerCls,
         keyboardFocusManagerIDs.markClearGlobalFocusOwnerMID);

    if (activeWindow != NULL) {
        // Setting focus owner to proxy will be equivalent haveing
        // null focus owner in Java layer while we will still be
        // able to receive key events.
        proxy = findWindowsProxy(activeWindow, env);

        if (proxy != NULL) {
            Widget curFocusWidget = XmGetFocusWidget(proxy);
            if (curFocusWidget != NULL) {
                callFocusHandler(curFocusWidget, FocusOut);
            }

            // Disable all but proxy widgets
            processTree(curFocusWidget, proxy, False);
            
            XmProcessTraversal(proxy, XmTRAVERSE_CURRENT);
        }
    }

    AWT_UNLOCK();
}
Exemplo n.º 7
0
void processTree(Node* root, int noOfCodeWords, bool firstCode, vector<codeWords>& store)
{
    int unique = noOfCodeWords/2;
    int rDepth = rightmostDepth(root);

    for(int i = 1;i < rDepth; i++)
    { 
        Node* rootCopy = copy(root);

        Node* newRoot = rotate(NULL, rootCopy, rightmostAtDepth(rootCopy, i));

        codeWords temp = codeWordsFromTree(newRoot, noOfCodeWords, firstCode);
        show(temp);
        store.push_back(temp);
        
        processTree(newRoot, noOfCodeWords, firstCode, store);
        destoryTree(newRoot);
    }
}
Exemplo n.º 8
0
void processTree(FILE* fp, bool print, char* boxcode)
{
	int boxdepth = strlen(boxcode);
	char buf[10000];
	int depth = 0;
	while (fgets(buf, sizeof(buf), fp)) {
		bool filledHole = false;
		if (g_recursive && print && buf[0] == 'H') {
			boxcode[boxdepth + depth] = '\0';
			FILE* fpH = openBox(boxcode);
			if (fpH) {
				processTree(fpH, print, boxcode);
				fclose(fpH);
				filledHole = true;
			} else {
				fprintf(stderr, "missing %s\n", boxcode);
			}
		}
		if (print && !filledHole)
			fputs(buf, stdout);
		if (buf[0] == 'X') {
			boxcode[boxdepth + depth] = '0';
			++depth;
		} else {
			for (; depth > 0 && boxcode[boxdepth + depth-1] == '1'; --depth) {
			}
			if (depth > 0) {
				boxcode[boxdepth + depth-1] = '1';
			} else {
				boxcode[boxdepth] = '\0';
				return;
			}
		}
	}
	boxcode[boxdepth + depth] = '\0';
	fprintf(stderr, "premature EOF at %s\n", boxcode);
}
Exemplo n.º 9
0
bool processTree(FILE* fp, FILE* out, bool printTree, bool printHoles, char* boxcode)
{
	int boxdepth = strlen(boxcode);
	char buf[10000];
    char fileName[10000];
	int depth = 0;
	while (fgets(buf, sizeof(buf), fp)) {
		bool filledHole = false;
        // Open HOLE file if exists. If no printing is set, we don't need to traverse HOLEs
		if (g_recursive && buf[0] == 'H' && depth > 0) {
            bool nbd_var_box = (strchr(buf,'V') != NULL); 
			FILE* fpH = openBox(boxcode, fileName);
			if (fpH) {
                FILE* outH = tmpfile();
                if (outH) {
                    bool success = processTree(fpH, outH, printTree, printHoles, boxcode);
                    fclose(fpH);
                    if (!success) {
                        fclose(outH);
                        // The tree is incomplete, so we rename the boxfile to mark as incomplete
                        // TODO: Not sure if treecat should have the power to rename files
                        if (g_mark_incomplete)
                            if (!mark(fileName,".incomplete")) fprintf(stderr, "failed to mark %s as incomplete\n", fileName);
                    } else {
                        // If the HOLE subtree is complete, print it to the output stream
                        rewind(outH);
                        bool success = putStream(out,outH);
                        fclose(outH);
                        if (!success) {
                            fprintf(stderr, "failed to print HOLE %s subtree\n", boxcode);
                            break;
                        } else {
                            filledHole = true;
                        }
                    }
                }
			}
            if (printHoles && !filledHole && ! nbd_var_box) 
                fprintf(out, "%s\n", boxcode); // Print the missing boxcode to stdout
		}
		if (printTree && !filledHole) {
			fputs(buf, out); // Print the buffer if we are printing out the filled tree
        }
		if (buf[0] == 'X') {
			boxcode[boxdepth + depth] = '0'; // Descend via left branch
			++depth;
			boxcode[boxdepth + depth] = '\0';
		} else {
            // Go up as many nodes as necessary
			for (; depth > 0 && boxcode[boxdepth + depth-1] == '1'; --depth) {}
			if (depth > 0) {
				boxcode[boxdepth + depth-1] = '1'; // Jump from left to right node
				boxcode[boxdepth + depth] = '\0'; // Truncate to keep box current
			} else {
				boxcode[boxdepth] = '\0'; // Truncate to keep box current
				return true;
			}
		}
	}
    
    // If we get to this point, the tree is incomplete
    // TODO: This may be unnecssary code as we rename incomplete trees
    if (printHoles) {
        // Print the box we "should" be at as missing
        fprintf(out, "%s\n", boxcode); // Print the missing boxcode to stdout
    
        // We list all other missing boxes
        for (int i = depth; i > 0; --i) {
            if (boxcode[boxdepth + i-1] != '1') {
                boxcode[boxdepth + i-1] = '1'; // Jump from left to right node
                boxcode[boxdepth + i] = '\0'; // Truncate to keep box current
                fprintf(out, "%s\n", boxcode); // Print the missing boxcode to stdout
            } else {
                boxcode[boxdepth + i] = '\0'; // Truncate to keep box current
            } 
        } 
    }           

    return false; 
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
    bool printTree = true;
    bool printHoles = false;
	if (argc > 1 && strcmp(argv[1], "--holes") == 0) {
        printTree = false;
        printHoles = true;
		++argv;
		--argc;
	}

	if (argc > 1 && strcmp(argv[1], "--mark") == 0) {
        g_mark_incomplete = true;
		++argv;
		--argc;
	}

	if (argc > 1 && strcmp(argv[1], "-s") == 0) {
        printTree = false;
        printHoles = false;
		++argv;
		--argc;
	}


	if (argc > 1 && strcmp(argv[1], "-v") == 0) {
		g_verbose = true;
		++argv;
		--argc;
	}

	if (argc > 1 && strcmp(argv[1], "-r") == 0) {
		g_recursive = true;
		++argv;
		--argc;
	}

	if (argc != 3) {
		fprintf(stderr, "Usage: treecat [--holes] [--mark] [-s] [-v] [-r] treeLocation boxcode\n");
		fprintf(stderr, "holes : do not print the tree but print the holes\n");
		fprintf(stderr, "mark : rename incomplete (sub)tree file(s) containing given boxcode (sub if -r)\n");
		fprintf(stderr, "s : silent, don't print trees or holes\n");
		fprintf(stderr, "v : verbose\n");
		fprintf(stderr, "r : recur over all subtree files to prince full subtree of boxcode\n");
		fprintf(stderr, "WARNING: If all --mark -r are set and boxcode is root or '', then mark any foreign tree files\n");
		exit(1);
	}
    
    // The fullboxcode parameter can specify the fileName and sequetial boxcode
    // A boxcode is just a sequence of zeros and ones giving a posiiton in a binary tree depth-first traversal
    // The treeFile will also be in pre-order depth-first
    char fullboxcode[10000];
	char fileboxcode[10000];
	strncpy(fullboxcode, argv[2], 10000);
	strncpy(fileboxcode, argv[2], 10000);
	g_treeLocation = argv[1];
  
    char fileName[10000];
	int fileBoxLength = strlen(fullboxcode);

    if ((fileBoxLength == 0) || (strncmp(fullboxcode, "root", fileBoxLength) == 0)) {
        g_start_is_root = true;
    }

    // TODO: Taging of foreign files may be dangerous 
    if (g_start_is_root && g_mark_incomplete && g_recursive) {
        DIR * dirp = opendir(g_treeLocation);
        struct dirent * dp;
        while ((dp = readdir(dirp)) != NULL) {
            if (ends_with(dp->d_name,"out")) {
	           sprintf(fileName, "%s/%s", g_treeLocation, dp->d_name);
               unopened_out_files.push_back(std::string(fileName));
            }
        }
    }   
 
    // See if a file with the tree for a prefix of the box exists
	FILE* fp = 0;
	while (fileBoxLength >= 0) {
		fileboxcode[fileBoxLength] = '\0';
		fp = openBox(fileboxcode, fileName);
		if (fp) { break; }
        --fileBoxLength;
	}

    if (!fp) exit(1);
    
    char * boxcode_const = (char *)calloc(10000, sizeof(char));
	strncpy(boxcode_const, fullboxcode+fileBoxLength, 10000);
    char * boxcode = boxcode_const;
    
	char buf[10000];
    // If the boxcode is still not empty, we traverse down the tree and print only
    // once we get to the proper node. We terminate early if the node does not exist
	while (*boxcode && fgets(buf, sizeof(buf), fp)) {
		if (buf[0] != 'X') { // If not a splitting, print the test failed by the truncated box
			*boxcode = '\0';
			fprintf(stderr, "terminal box = %s%s\n", fileboxcode, boxcode_const);
			if (printTree) fputs(buf, stdout);
            free(boxcode_const);
            fclose(fp);
			exit(0);
		}
		if (*boxcode == '1') { // Actually have to process the tree if we go right at any point in the boxcode
		    int success = processTree(fp, NULL, false, false, boxcode);
            if (!success) exit(1); // Incomplete tree or boxcode not found
        }
		++boxcode; // Keeps going left in the tree as *boxcode == 0
	}
    free(boxcode_const);
    FILE* out = tmpfile();
    if (!out) exit(1);

	bool success = processTree(fp, out, printTree, printHoles, fullboxcode);
    fclose(fp);

    if (g_start_is_root && g_mark_incomplete && g_recursive) { 
        for (std::vector<std::string>::iterator it = unopened_out_files.begin() ; it != unopened_out_files.end(); ++it) {
            fprintf(stderr, "unopened/foreign out file = %s\n", it->c_str());
            // TODO: Not sure if treecat should have the power to rename files
            if (!mark(it->c_str(),".foreign")) fprintf(stderr, "failed to mark %s as foreign\n", it->c_str());
        }
    }
    if (!success) {
        fclose(out);
        // The tree is incomplete, so we rename the boxfile to mark as incomplete
        // TODO: Not sure if treecat should have the power to rename files
        if (g_mark_incomplete) {
            if (!mark(fileName,".incomplete")) fprintf(stderr, "failed to mark %s as incomplete\n", fileName);
        }
        exit(1);
    } else {
        rewind(out);
        bool putSuccess = putStream(stdout, out);
        fclose(out);
        if (!putSuccess) exit(1);
        else exit(0); 
    }
}