int main (int argc, char *argv[]) { GRegex *filename_regex; GSList *files; int result; #if !GLIB_CHECK_VERSION(2,36,0) g_type_init (); #endif suite_options = g_key_file_new (); g_assert (g_key_file_load_from_file (suite_options, SUITE_OPTION_FILE, G_KEY_FILE_NONE, NULL)); g_test_init (&argc, &argv, NULL); filename_regex = g_regex_new ("\\.(svg|mml)$", 0, 0, NULL); files = build_file_list (SUITE_DATA_DIRECTORY, filename_regex); g_slist_foreach (files, add_render_tests, NULL); result = g_test_run(); g_slist_foreach (files, (GFunc) g_free, NULL); g_slist_free (files); g_regex_unref (filename_regex); g_key_file_free (suite_options); lsm_shutdown (); return result; }
int main (int argc, char *argv[]) { GRegex *filename_regex; GSList *files; int i; int result; g_type_init (); g_test_init (&argc, &argv, NULL); filename_regex = g_regex_new ("\\.(svg|mml)$", 0, 0, NULL); files = build_file_list (SUITE_DATA_DIRECTORY, filename_regex); g_slist_foreach (files, add_render_tests, NULL); result = g_test_run(); g_slist_foreach (files, (GFunc) g_free, NULL); g_slist_free (files); g_regex_unref (filename_regex); lsm_shutdown (); return result; }
/** * Send the list of currently available user files to the client */ void send_file_list(int sockfd) { int n; char *filelist_buf = malloc(sizeof(struct UserFile)*FILELIST_LEN); build_file_list(filelist_buf); n = send(sockfd,filelist_buf,strlen(filelist_buf),0); if (n < 0) error("ERROR writing to socket"); }
/* --------------------------------------------------------------------- * Callback when the menu item is clicked. * --------------------------------------------------------------------- */ static void menu_item_activate(guint key_id) { GtkWidget* dialog; GtkWidget* dialog_new = NULL; GtkWidget* dialog_entry; GtkTreeModel* completion_list; GeanyDocument* current_doc = document_get_current(); gchar *chosen_path; const gchar *chosen_file; gint response; log_func(); if(current_doc == NULL || current_doc->file_name == NULL || current_doc->file_name[0] == '\0') return; /* Build current directory listing */ directory_ref = g_path_get_dirname(current_doc->file_name); completion_list = build_file_list(directory_ref, ""); /* Create the user dialog and get response */ dialog_entry = create_dialog(&dialog, completion_list); response = gtk_dialog_run(GTK_DIALOG(dialog)); /* Filename */ chosen_file = gtk_entry_get_text(GTK_ENTRY(dialog_entry)); /* Path + Filename */ chosen_path = g_build_filename(directory_ref, chosen_file, NULL); if ( response == GTK_RESPONSE_ACCEPT ) { log_debug("Trying to open: %s", chosen_path); if ( ! g_file_test(chosen_path, G_FILE_TEST_EXISTS) ) { log_debug("File not found."); dialog_new = gtk_message_dialog_new(GTK_WINDOW(geany_data->main_widgets->window), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, _("%s not found, create it?"), chosen_file); gtk_window_set_title(GTK_WINDOW(dialog_new), "Geany"); if(gtk_dialog_run(GTK_DIALOG(dialog_new)) == GTK_RESPONSE_OK) { document_new_file(chosen_path, current_doc->file_type, NULL); document_set_text_changed(document_get_current(), TRUE); } gtk_widget_destroy(dialog_new); } else document_open_file(chosen_path, FALSE, NULL, NULL); } /* Freeing memory */ gtk_widget_destroy(dialog); g_free(directory_ref); g_object_unref (completion_list); }
/* --------------------------------------------------------------------- * Entry callback function for sub-directory search * --------------------------------------------------------------------- */ static void directory_check(GtkEntry* entry, GtkEntryCompletion* completion) { static GtkTreeModel *old_model = NULL; GtkTreeModel* completion_list; static gchar *curr_dir = NULL; gchar *new_dir, *new_dir_path; const gchar *text; text = gtk_entry_get_text(entry); gint dir_sep = strrpos(text, G_DIR_SEPARATOR_S); /* No subdir found */ if (dir_sep == -1) { if (old_model != NULL) { /* Restore the no-sub-directory model */ log_debug("Restoring old model!"); gtk_entry_completion_set_model (completion, old_model); old_model = NULL; g_free(curr_dir); curr_dir = NULL; } return; } new_dir = g_strndup (text, dir_sep+1); /* I've already inserted new model completion for sub-dir elements? */ if ( g_strcmp0 (new_dir, curr_dir) == 0 ) return; if ( curr_dir != NULL ) g_free(curr_dir); curr_dir = new_dir; /* Save the completion_mode for future restore. */ if (old_model == NULL) old_model = gtk_entry_completion_get_model(completion); log_debug("New completion list!"); if ( g_path_is_absolute(new_dir) ) new_dir_path = new_dir; else new_dir_path = g_build_filename(directory_ref, new_dir, NULL); /* Build the new file list for completion */ completion_list = build_file_list(new_dir_path, new_dir); gtk_entry_completion_set_model (completion, completion_list); g_object_unref(completion_list); }
void DirHandler::new_Files() { sleep(1); // Give some copy operations time to finish before futher processing char fname[MAX_PATH_LENGTH]; int nCount = build_file_list(&nFiles); int found = 0; // Check new list against the previous for new files for(int i = 0; i < nCount; i++) { found = 0; for (int j = 0; j < pFilesCnt; j++) { if ( strncmp(nFiles[i]->d_name, pFiles[j]->d_name, strlen(nFiles[i]->d_name)) == 0 ) { found = 1; break; } } if (!found) { // Build full path filename strncpy(fname, pathname, strlen(pathname)); strncpy(fname + strlen(pathname), nFiles[i]->d_name, strlen(nFiles[i]->d_name)); fname[strlen(pathname) + strlen(nFiles[i]->d_name)] = '\0'; cout << fname << endl; // Do preprocessing of images Pre_Create(fname); } } // Free prev list if needed if (pFiles) free(pFiles); pFiles = nFiles; pFilesCnt = nCount; return; }
static GSList * build_file_list (const char *path, GRegex *filename_regex) { GSList *files = NULL; GDir *directory; GError *error = NULL; const char *entry; char *filename; directory = g_dir_open (path, 0, &error); if (error != NULL) { if (directory != NULL) g_dir_close (directory); g_error_free (error); return NULL; } do { entry = g_dir_read_name (directory); if (entry != NULL && strstr (entry, "ignore-") != entry && strcmp (entry, "images") != 0) { filename = g_build_filename (path, entry, NULL); if (g_file_test (filename, G_FILE_TEST_IS_DIR)) files = g_slist_concat (files, build_file_list (filename, filename_regex)); else if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) && g_regex_match (filename_regex, filename, 0, NULL) && !g_key_file_get_boolean (suite_options, entry, "ignore", NULL)) { files = g_slist_prepend (files, g_strdup (filename)); } g_free (filename); } } while (entry != NULL); g_dir_close (directory); return files; }
void build_file_list(char *file, short recurse) { char *thisdir; DIR *dir; struct dirent *entry; #ifdef __DJGPP__ /* chdir() doesn't accept dir names ending in '\\' */ if(file[strlen(file)-1] == '\\') file[strlen(file)-1] = '/'; #endif /* check for stack overflow */ recursionDepth++; #ifdef OVERFLOW_CHECK if ((recursionDepth * BYTES_PER_DEPTH + BASESIZE) > STACKSIZE) { fprintf(stderr,"%s: Exceeded permitted nesting depth (%d levels)\n" "Aborted.\n",program_name,recursionDepth); exit(EXIT_FAILURE); } #endif if (stat(file,&tstat)!=0) { fprintf(stderr,"%s: Couldn't stat %s. File skipped\n",program_name,file); --recursionDepth; return; } if (recurse && S_ISDIR(tstat.st_mode)) { char tstr[2]; /* * It is a directory. recurse through it. */ /* save our state */ tstr[0] = dirbrk; tstr[1] = '\0'; if (*currentDirectory) { thisdir = strdup(currentDirectory); } else { thisdir = malloc(1); if (thisdir != NULL) *thisdir='\0'; } if (thisdir == NULL) { perror("Couldn't duplicate current directory"); exit (EXIT_FAILURE); } if (*currentDirectory) strcat(currentDirectory,tstr); strcat(currentDirectory,file); if (currentDirectory[strlen(currentDirectory)-1] == dirbrk) currentDirectory[strlen(currentDirectory)-1] = '\0'; /* recurse */ if ((dir = opendir(file)) == NULL) { fprintf(stderr,"%s: Couldn't open %s. Directory skipped.\n", program_name,currentDirectory); } else { if (chdir(file) !=0) { fprintf(stderr,"couldn't cd to %s\n",currentDirectory); exit (EXIT_FAILURE); } #ifdef READDIR_RETURNS_DOT entry = readdir(dir); /* for "." */ entry = readdir(dir); /* for ".." */ #endif while ((entry = readdir(dir))!=NULL) { /* ignore hidden files */ #ifdef BROKEN_DIRENT_STRUCT if (*(entry->d_name)!='.') build_file_list((entry->d_name)-2,1); #else if (*(entry->d_name)!='.') build_file_list(entry->d_name,1); #endif } if (*thisdir) { if ((chdir(rootdir)!=0) || (chdir(thisdir)!=0)) { fprintf(stderr,"couldn't cd to %s\n",thisdir); exit (EXIT_FAILURE); } } else { if (chdir(rootdir)!=0) { fprintf(stderr,"couldn't cd to calling directory\n"); exit (EXIT_FAILURE); } } } /* restore our state */ strcpy(currentDirectory,thisdir); free(thisdir); } else if (S_ISREG(tstat.st_mode)) { /* It is a normal file. Add it to the pathList */ add_to_pathList(currentDirectory, file); } --recursionDepth; return; }
int main(int argc,char *argv[]) { struct timeval currTime; int sockfd; int port; //check arguments here if (argc != 3) { printf("usage: %s <port#> <logFile>\n", argv[0]); return 0; } // set port number var port = atoi(argv[1]); // copy log file name into log_filename memcpy(log_filename,argv[2],strlen(argv[2])); // log the start of the server gettimeofday(&currTime,NULL); _log(log_filename,"Server started"); /* * Open a TCP socket (an Internet stream socket). */ sockfd = setup_socket(port); /* * here you should listen() on your TCP socket */ listen(sockfd,5); SELECT_INIT(); for ( ; ; ) //endless loop { SELECT(); if(s == 0) { // timeout, do nothing } if (s > 0) { // something ready for read, probably a client connection request int n, r; socklen_t clilen; int newsockfd; struct sockaddr_in cli_addr; char buffer[100]; char welcome_msg[100]; pthread_t th; clilen = sizeof(cli_addr); // accept connection newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); FD_SET(newsockfd, &rdset); max_fd = newsockfd + 1; // check select to see if client is sending their username s = select(max_fd, &rdset, &wrset, NULL, &selectTimeout); if (s == -1) { printf("ERROR: Socket error. Exiting.\n"); exit(1); } if (s > 0) { bzero(buffer,100); n = recv(newsockfd,buffer,100,0); if (n < 0) error("ERROR reading from socket"); // since a new user connected, let's review the current file list char *filelist_buf = malloc(sizeof(struct UserFile)*FILELIST_LEN); build_file_list(filelist_buf); printf("%s just started connecting. This is the updated file list from all clients:\n%s\n",buffer,filelist_buf); // add user to users hash pthread_mutex_lock(&mutex); struct User *user = malloc(sizeof(struct User)); strcpy(user->name,buffer); memcpy(&(user->addr),&cli_addr,sizeof(struct sockaddr_in)); user->sockfd = newsockfd; add_user(user); pthread_mutex_unlock(&mutex); // send welcome message strcpy(welcome_msg,"Welcome, "); strcat(welcome_msg, buffer); strcat(welcome_msg,". You are now connected."); n = send(newsockfd,welcome_msg,strlen(welcome_msg),0); // notify other users that a new user has joined /* struct User *u; char *new_user_msg = malloc(128); strcpy(new_user_msg,"New user connected: "); for(u = users; u != NULL; u = u->hh.next) { if (strcmp(u->name,buffer) != 0) { sprintf(new_user_msg,"A new user has joined: %s\n",buffer); n = send(u->sockfd,new_user_msg,strlen(new_user_msg),0); } } */ r = pthread_create(&th, 0, connection, (void *)user); if (r != 0) { fprintf(stderr, "thread create failed\n"); } } if (s == 0) { printf("Client did not send username\n"); } } } //if you've accepted the connection, you'll probably want to //check "select()" to see if they're trying to send data, //like their name, and if so //recv() whatever they're trying to send //since you're talking nicely now.. probably a good idea send them //a message to welcome them to the new client. //if there are others connected to the server, probably good to notify them //that someone else has joined. //pthread_mutex_lock(&mutex); //now add your new user to your global list of users //pthread_mutex_unlock(&mutex); //now you need to start a thread to take care of the //rest of the messages for that client //r = pthread_create(&th, 0, connection, (void *)newsockfd); //if (r != 0) { fprintf(stderr, "thread create failed\n"); } //A requirement for 5273 students: //at this point... //whether or not someone connected, you should probably //look for clients that should be timed out //and kick them out //oh, and notify everyone that they're gone. }
MStatus VDBQueryCmd::doIt(const MArgList& args) { MStatus status = MS::kSuccess; MArgDatabase arg_data(syntax(), args); // always open new files to simplify code, it's cheap anyhow std::vector<std::string> vdb_paths; if (arg_data.isFlagSet(node_short_flag)) { MSelectionList slist; arg_data.getFlagArgument(node_short_flag, 0, slist); MObject node; slist.getDependNode(0, node); MFnDependencyNode dnode(node, &status); if (!status) return status; if (dnode.typeName() != VDBVisualizerShape::typeName) { MGlobal::displayError("[openvdb] Wrong node was passed to the command : " + dnode.name()); return MS::kFailure; } if (arg_data.isFlagSet(current_frame_short_flag)) vdb_paths.push_back(MPlug(node, VDBVisualizerShape::s_out_vdb_path).asString().asChar()); else { build_file_list(MPlug(node, VDBVisualizerShape::s_vdb_path).asString().asChar(), MPlug(node, VDBVisualizerShape::s_cache_playback_start).asInt(), MPlug(node, VDBVisualizerShape::s_cache_playback_end).asInt(), vdb_paths); } } else if (arg_data.isFlagSet(file_short_flag)) { MString vdb_path; arg_data.getFlagArgument(file_short_flag, 0, vdb_path); if (arg_data.isFlagSet(current_frame_short_flag)) { const int current_frame = static_cast<int>(MAnimControl::currentTime().as(MTime::uiUnit())); build_file_list(vdb_path.asChar(), current_frame, current_frame, vdb_paths); } else { int start_frame = 0; int end_frame = 0; if (arg_data.isFlagSet(start_frame_short_flag)) arg_data.getFlagArgument(start_frame_short_flag, 0, start_frame); else start_frame = static_cast<int>(MAnimControl::animationStartTime().as(MTime::uiUnit())); if (arg_data.isFlagSet(end_frame_short_flag)) arg_data.getFlagArgument(end_frame_short_flag, 0, end_frame); else end_frame = static_cast<int>(MAnimControl::animationEndTime().as(MTime::uiUnit())); build_file_list(vdb_path.asChar(), start_frame, end_frame, vdb_paths); } } else { MGlobal::displayError("[openvdb] No cache was passed to the command, use the -file(f) or the -node(n) flags"); return MS::kFailure; } if (vdb_paths.size() == 0) { MGlobal::displayError("[openvdb] No paths are passed to the command."); return MS::kFailure; } std::vector<openvdb::io::File*> vdb_files; vdb_files.reserve(vdb_paths.size()); MString query_type = ""; if (arg_data.isFlagSet(query_short_flag)) arg_data.getFlagArgument(query_short_flag, 0, query_type); else { MGlobal::displayError("[openvdb] No query is specified."); return MS::kFailure; } auto get_array_from_flag = [&](const char* flag_name, std::vector<std::string>& out_values) { if (arg_data.isFlagSet(flag_name)) { MString flag_data; arg_data.getFlagArgument(flag_name, 0, flag_data); MStringArray flags; if (flag_data.index(',')) flag_data.split(',', flags); else if (flag_data.index(';')) flag_data.split(';', flags); else if (flag_data.index(':')) flag_data.split(':', flags); else if (flag_data.index(' ')) flag_data.split(' ', flags); else flags.append(flag_data); const unsigned int flag_count = flags.length(); out_values.reserve(flag_count); for (unsigned int f = 0; f < flag_count; ++f) out_values.push_back(flags[f].asChar()); } }; std::vector<std::string> queries; get_array_from_flag(query_short_flag, queries); if (queries.size() == 0) { MGlobal::displayError("[openvdb] No queries are specified!"); return MS::kFailure; } for (auto vdb_path : vdb_paths) { openvdb::io::File* vdb_file = new openvdb::io::File(vdb_path); vdb_file->open(false); if (vdb_file->isOpen()) vdb_files.push_back(vdb_file); else delete vdb_file; } if (vdb_files.size() == 0) { MGlobal::displayError("[openvdb] No vdb files can be opened."); return MS::kFailure; } std::vector<std::string> grid_names; get_array_from_flag(grid_short_flag, grid_names); std::vector<std::string> grid_types; get_array_from_flag(grid_type_short_flag, grid_types); const bool all_grids = grid_names.size() == 0 && grid_types.size() == 0; auto grid_required = [&](openvdb::GridBase::ConstPtr grid) -> bool { if (all_grids) return true; else { return std::find(grid_names.begin(), grid_names.end(), grid->getName()) != grid_names.end() || std::find(grid_types.begin(), grid_types.end(), grid->valueType()) != grid_types.end(); } }; for (auto query : queries) { if (query == query_type_bbox) { MBoundingBox bbox; for (auto vdb_file : vdb_files) { openvdb::GridPtrVecPtr grids = vdb_file->readAllGridMetadata(); for (openvdb::GridPtrVec::const_iterator it = grids->begin(); it != grids->end(); ++it) { if (openvdb::GridBase::ConstPtr grid = *it) { if (grid_required(grid)) read_transformed_bounding_box(grid, bbox); } } } const MPoint min = bbox.min(); const MPoint max = bbox.max(); appendToResult(min.x); appendToResult(min.y); appendToResult(min.z); appendToResult(max.x); appendToResult(max.y); appendToResult(max.z); } else if (query == query_type_min_max) { std::vector<double> mins; std::vector<double> maxs; for (auto vdb_file : vdb_files) { openvdb::GridPtrVecPtr grids = vdb_file->readAllGridMetadata(); for (openvdb::GridPtrVec::const_iterator it = grids->begin(); it != grids->end(); ++it) { if (openvdb::GridBase::ConstPtr grid = *it) { if (grid_required(grid)) { // TODO: check for the minimum and maximum metadata if (grid->valueType() == "float") { if (mins.size() < 1) mins.resize(1, std::numeric_limits<double>::max()); if (maxs.size() < 1) maxs.resize(1, std::numeric_limits<double>::min()); openvdb::FloatGrid::ConstPtr grid_data = openvdb::gridConstPtrCast<openvdb::FloatGrid>(vdb_file->readGrid(grid->getName())); for (auto iter = grid_data->beginValueOn(); iter; ++iter) { const double value = static_cast<double>(iter.getValue()); mins[0] = std::min(mins[0], value); maxs[0] = std::max(maxs[0], value); } } else if (grid->valueType() == "vec3s") { if (mins.size() < 3) mins.resize(3, std::numeric_limits<double>::max()); if (maxs.size() < 3) maxs.resize(3, std::numeric_limits<double>::min()); openvdb::Vec3SGrid::ConstPtr grid_data = openvdb::gridConstPtrCast<openvdb::Vec3SGrid>(vdb_file->readGrid(grid->getName())); for (auto iter = grid_data->beginValueOn(); iter; ++iter) { const openvdb::Vec3d value = iter.getValue(); mins[0] = std::min(mins[0], value.x()); mins[1] = std::min(mins[1], value.y()); mins[2] = std::min(mins[2], value.z()); maxs[0] = std::max(maxs[0], value.x()); maxs[1] = std::max(maxs[1], value.y()); maxs[2] = std::max(maxs[2], value.z()); } } } } } } for (auto mn : mins) appendToResult(mn); for (auto mx : maxs) appendToResult(mx); } } for (auto vdb_file : vdb_files) delete vdb_file; return status; }