void log_rotation_background_thread() { while(thread_running) { // set up the current logger std::string current_log_file = make_file_name(log_base_name, log_counter); global_logger().set_log_file(current_log_file); unlink(symlink_name.c_str()); symlink(current_log_file.c_str(), symlink_name.c_str()); // if our counter exceeds the truncate limit, delete earlier files if (truncate_limit > 0 && log_counter >= truncate_limit) { // delete oldest files std::string oldest_log_file = make_file_name(log_base_name, log_counter - truncate_limit); unlink(oldest_log_file.c_str()); } // sleep for the log interval period. // We maintain our own additional timer to prevent spurious wakeups timer ti; ti.start(); lock.lock(); while (thread_running && ti.current_time() < log_interval) { cond.timedwait(lock, log_interval); } lock.unlock(); ++log_counter; } }
static inline char * make_session_filedir (ASSession * session, const char *source, Bool use_depth, int mode ) { char *realfilename = NULL; if( session->overriding_file ) return mystrdup(session->overriding_file) ; if( source ) { char *filename = (char*)source ; if( session->scr->screen != 0 ) { filename = safemalloc( strlen((char*)source) + 1 + 32 + 32 ); if( use_depth ) sprintf( filename, "%s.scr%ld.%dbpp", source, session->scr->screen, session->colordepth ); else sprintf( filename, "%s.scr%ld", source, session->scr->screen ); realfilename = (char *)make_file_name (session->ashome, filename); free( filename ); filename = (char*)source ; } if( realfilename == NULL || check_file_mode(realfilename, mode) != 0 ) { if( use_depth ) { filename = safemalloc( strlen((char*)source) + 1 + 32 ); sprintf( filename, "%s.%dbpp", source, session->colordepth ); } if( realfilename ) free( realfilename ); realfilename = (char *)make_file_name (session->ashome, filename); if (check_file_mode(realfilename, mode) != 0) { free (realfilename); realfilename = make_file_name (session->asshare, filename); if (check_file_mode(realfilename, mode) != 0) { free (realfilename); realfilename = NULL; } } } if( filename != source ) free( filename ); } return realfilename ; }
char * find_workspace_file( ASSession *session ) { char *fname, *full_fname ; if( session->scr == NULL || session->scr->screen == 0 ) return make_file_name( session->ashome, AFTER_SAVE ); fname = safemalloc( strlen( AFTER_SAVE ) + 4 + 15 + 1 ); sprintf( fname, AFTER_SAVE ".scr%ld", session->scr->screen ); full_fname = make_file_name (session->ashome, fname); free( fname ); return full_fname; }
char *make_session_webcache_file (ASSession *session, const char *url) { char *fullfilename = NULL; if( url != NULL && session && session->webcache) { int len = 0, i; char* escapedUrl; for (i = 0 ; url[i] ; ++i) { if (url[i] == '_') ++len; ++len; } escapedUrl = safemalloc (len +1); len = 0; for (i = 0 ; url[i] ; ++i) { if (url[i] == '_') escapedUrl[len++] = '_'; if (url[i] != '.' && url[i] != '_' && !isalnum(url[i])) escapedUrl[len++] = '_'; else escapedUrl[len++] = url[i]; } escapedUrl[len] = '\0'; fullfilename = make_file_name (session->webcache, escapedUrl); free (escapedUrl); } return fullfilename; }
void http::server::list_directory(const http::server::request &req, http::server::reply &reply, const std::string &doc_root) { try { boost::filesystem::path root = doc_root + req.uri; std::ostringstream stream; stream << "<h1>Directory listing of " + req.uri + "</h1>"; stream << parent_directory_anchor(req.uri, doc_root); std::vector<boost::filesystem::path> files_in_folder; std::copy(boost::filesystem::directory_iterator(root), boost::filesystem::directory_iterator(), std::back_inserter(files_in_folder)); std::sort(files_in_folder.begin(), files_in_folder.end(), [](const auto &p1, const auto &p2) { return boost::filesystem::last_write_time(p1) > boost::filesystem::last_write_time(p2); }); std::stable_partition(files_in_folder.begin(), files_in_folder.end(), [](const auto &p) { return boost::filesystem::is_regular_file(p); }); for (const auto &p : files_in_folder) { try { stream << "<a href=\""; stream << make_link(req.uri, p) << "\">"; stream << trim_quotes(make_file_name(p)); stream << "</a><br/>"; } catch (const std::logic_error &) { continue; } } reply.content = stream.str(); reply.add_header("Cache-Control", "max-age=60"); reply.add_header("Content-Type", "text/html"); } catch (...) { reply.status = reply::status_type::internal_server_error; reply.add_header("Cache-Control", "no-cache"); } }
int check_xml_contents( const char *syntax_dir, const char *file ) { char *source_file ; char *doc_str ; int size = 0 ; source_file = make_file_name( syntax_dir, file ); doc_str = load_file(source_file); if( doc_str != NULL ) { xml_elem_t* doc; size = strlen( doc_str ); doc = xml_parse_doc(doc_str, DocBookVocabulary); if( doc->child ) { if( doc->child->tag_id == DOCBOOK_section_ID && doc->child->child == NULL ) size = 0 ; else if( doc->child->child ) { if( doc->child->child->tag_id == XML_CDATA_ID && doc->child->child->next == NULL ) size = 0; } } /* Delete the xml. */ LOCAL_DEBUG_OUT( "xml_elem_delete for doc %p", doc ); xml_elem_delete(NULL, doc); free( doc_str ); } free( source_file ); return size; }
LogFileOutput::LogFileOutput(const char* name) : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)), _file_name(NULL), _archive_name(NULL), _archive_name_len(0), _current_size(0), _rotate_size(0), _current_file(1), _file_count(0), _rotation_lock(Mutex::leaf, "LogFileOutput rotation lock", true, Mutex::_safepoint_check_sometimes) { _file_name = make_file_name(name, _pid_str, _vm_start_time_str); }
ASSession * create_assession ( ScreenInfo *scr, char *ashome, char *asshare) { ASSession *session = (ASSession *) safecalloc (1, sizeof (ASSession)); session->scr = ( scr == NULL )?ASDefaultScr:scr ; /* sensible default */ session->colordepth = session->scr->d_depth ; session->ashome = ashome ; session->asshare = asshare ; session->defaults = create_desk_session (); session->defaults->desk = INVALID_DESK ; session->defaults->look_file = find_default_look_file (session); session->defaults->feel_file = find_default_feel_file (session); session->defaults->background_file = find_default_background_file (session); session->defaults->theme_file = find_default_theme_file (session); session->defaults->colorscheme_file = find_default_colorscheme_file (session); session->workspace_state = find_workspace_file(session); session->webcache = make_file_name (ashome, WEBCACHE_DIR); session->desks_used = 0 ; session->desks_allocated = 4 ; session->desks = safecalloc(session->desks_allocated, sizeof( ASDeskSession*)); session->changed = False; return session; }
Read::Read(string file_name, bool is_arch) : _bits_count_read(0), _end_file(false), _buffer_in_size(0) { _file_name_str = file_name; _file_name = new char[128]; if (is_arch) { make_file_name(); } else { strcpy(_file_name, _file_name_str.c_str()); } fin.open(_file_name); _file_open = fin.is_open(); _buffer_in = new unsigned char[CONST_BUFFER_SIZE]; char tmp[1]; int i = 0; while (fin.eof() == false and i != CONST_BUFFER_SIZE) { fin.read(tmp, 1); _buffer_in[i] = (unsigned char)tmp[0]; i++; } if (fin.eof()) { i--; } _buffer_in_size = i; }
bool AudioTestSource::init() { shmpath_ = make_file_name("audio"); // FIXME make_file name should work in ctor... g_object_set(G_OBJECT(audiotestsrc_.get_raw()), "is-live", TRUE, nullptr); g_object_set(G_OBJECT(audiotestsrc_.get_raw()), "samplesperbuffer", 512, nullptr); g_object_set(G_OBJECT(shmdatasink_.get_raw()), "socket-path", shmpath_.c_str(), nullptr); // registering install_property(G_OBJECT(audiotestsrc_.get_raw()), "volume", "volume", "Volume"); install_property(G_OBJECT(audiotestsrc_.get_raw()), "freq", "freq", "Frequency"); install_property(G_OBJECT(audiotestsrc_.get_raw()), "wave", "wave", "Signal Form"); gst_bin_add_many(GST_BIN(gst_pipeline_->get_pipeline()), audiotestsrc_.get_raw(), shmdatasink_.get_raw(), nullptr); gst_element_link(audiotestsrc_.get_raw(), shmdatasink_.get_raw()); if (!audiotestsrc_) { g_warning("audiotestsrc creation failed"); return false; } if (!shmdatasink_) { g_warning("shmdatasink creation failed"); return false; } return true; }
void gen_faq_doc( const char *source_dir, const char *dest_dir, ASDocType doc_type ) { ASXMLInterpreterState state; char *faq_dir = NULL ; ASFlagType doc_class_mask = DOC_CLASS_None ; struct direntry **list = NULL; int list_len, i ; faq_dir = make_file_name( source_dir, "FAQ" ); if( !start_doc_file( dest_dir, "afterstep_faq", NULL, doc_type, "afterstep_faq", "AfterStep FAQ", "This document is an ever growing set of questions, statements, ideas and complaints about AfterStep version 2.0", &state, doc_class_mask, DocClass_FAQ ) ) return ; /* BODY *************************************************************************/ set_flags( state.flags, ASXMLI_OrderSections ); list_len = my_scandir ((char*)faq_dir, &list, ignore_dots, NULL); for (i = 0; i < list_len; i++) { if ( !S_ISDIR (list[i]->d_mode) ) convert_xml_file( faq_dir, list[i]->d_name, &state ); free(list[i]); } if( list ) free( list ); /* FOOTER ***********************************************************************/ end_doc_file( &state ); free( faq_dir ); }
LogFileOutput::LogFileOutput(const char* name) : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)), _file_name(NULL), _archive_name(NULL), _archive_name_len(0), _rotate_size(DefaultFileSize), _file_count(DefaultFileCount), _current_size(0), _current_file(0), _rotation_semaphore(1) { assert(strstr(name, Prefix) == name, "invalid output name '%s': missing prefix: %s", name, Prefix); _file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str); }
static char * find_default_file (ASSession *session, const char *filename, Bool check_shared) { char *fullfilename; fullfilename = make_file_name (session->ashome, filename); if (CheckFile (fullfilename) == 0) return fullfilename; free (fullfilename); if (check_shared) { fullfilename = make_file_name (session->asshare, filename); if (CheckFile (fullfilename) == 0) return fullfilename; free (fullfilename); } return NULL; }
Bool convert_xml_file( const char *syntax_dir, const char *file, ASXMLInterpreterState *state ) { char *source_file ; char *doc_str ; Bool empty_file = False ; source_file = make_file_name( syntax_dir, file ); doc_str = load_file(source_file); LOCAL_DEBUG_OUT( "file %s loaded", source_file ); /*LOCAL_DEBUG_OUT( "file %s loaded into {%s}", source_file, doc_str ); */ if( doc_str != NULL ) { xml_elem_t* doc; xml_elem_t* ptr; if( file[0] == '_' && !get_flags( state->flags, ASXMLI_ProcessingOptions )) state->pre_options_size += strlen(doc_str) ; else set_flags( state->flags, ASXMLI_ProcessingOptions ); doc = xml_parse_doc(doc_str, DocBookVocabulary); LOCAL_DEBUG_OUT( "file %s parsed, child is %p", source_file, doc->child ); if( doc->child ) { LOCAL_DEBUG_OUT( "child tag = \"%s\", childs child = %p", doc->child->tag, doc->child->child); empty_file = ( doc->child->tag_id == DOCBOOK_section_ID && doc->child->child == NULL ); if( doc->child->child ) { empty_file = ( doc->child->child->tag_id == XML_CDATA_ID && doc->child->child->next == NULL ); LOCAL_DEBUG_OUT( "childs child tag = \"%s\", parm = \"%s\"", doc->child->child->tag, doc->child->child->parm); } } LOCAL_DEBUG_OUT( "file %s %s", source_file, empty_file?"empty":"not empty" ); if( !empty_file ) { for (ptr = doc->child ; ptr ; ptr = ptr->next) { LOCAL_DEBUG_OUT( "converting child <%s>", ptr->tag ); convert_xml_tag( ptr, NULL, state ); LOCAL_DEBUG_OUT( "done converting child <%s>", ptr->tag ); } } /* Delete the xml. */ LOCAL_DEBUG_OUT( "deleting xml %p", doc ); xml_elem_delete(NULL, doc); LOCAL_DEBUG_OUT( "freeing doc_str %p", doc_str ); free( doc_str ); } LOCAL_DEBUG_OUT( "done with %s", source_file ); free( source_file ); fprintf( state->dest_fp, "\n" ); return !empty_file; }
bool GstVideoEncoder::init() { codecs_ = std::make_unique<GstVideoCodec>( static_cast<Quiddity*>(this), std::string(), make_file_name("video-encoded")); shmcntr_.install_connect_method( [this](const std::string& shmpath) { return this->on_shmdata_connect(shmpath); }, [this](const std::string&) { return this->on_shmdata_disconnect(); }, [this]() { return this->on_shmdata_disconnect(); }, [this](const std::string& caps) { return this->can_sink_caps(caps); }, 1); return true; }
static FILE *open_trace_file( const char * source_file, TRACE_FILES kind_of_trace) { char trace_file[ PATH_MAX ]; make_file_name(trace_file, source_file, vscript_ctx->output_dir ? vscript_ctx->output_dir : "", kind_of_trace ); return fopen( trace_file, kind_of_trace == TRACE_FILE_OUTPUT_FILE ? "wb" : "w" ); }
char * make_session_apps_path ( ASSession * session ) { char *apps_path = NULL ; int len = 0 ; char *priv_apps, *shared_apps ; if( session == NULL ) return NULL; priv_apps = (char *)make_file_name (session->ashome, AFTERSTEP_APPS_DIR); if (check_file_mode(priv_apps, S_IFDIR) != 0) destroy_string(&priv_apps); else len += strlen(priv_apps); shared_apps = (char *)make_file_name (session->asshare, AFTERSTEP_APPS_DIR); if (check_file_mode(shared_apps, S_IFDIR) != 0) destroy_string(&shared_apps); else { if( len > 0 ) ++len ; len += strlen(shared_apps); } if( len > 0 ) { apps_path = safemalloc( len + 1 ); if( priv_apps && shared_apps ) sprintf( apps_path, "%s:%s", priv_apps, shared_apps ); else if( priv_apps ) strcpy( apps_path, priv_apps ); else if( shared_apps ) strcpy( apps_path, shared_apps ); destroy_string(&priv_apps); destroy_string(&shared_apps); } return apps_path ; }
void HTTPSDPDec::configure_shmdatasink(GstElement* element, const std::string& media_type, const std::string& media_label) { auto count = counter_.get_count(media_label + media_type); std::string media_name = media_type; if (count != 0) media_name.append("-" + std::to_string(count)); std::string shmpath; if (media_label.empty()) shmpath = make_file_name(media_name); else shmpath = make_file_name(media_label + "-" + media_name); g_object_set(G_OBJECT(element), "socket-path", shmpath.c_str(), nullptr); shm_subs_.emplace_back(std::make_unique<GstShmdataSubscriber>( element, [this, shmpath](const std::string& caps) { this->graft_tree( ".shmdata.writer." + shmpath, ShmdataUtils::make_tree(caps, ShmdataUtils::get_category(caps), ShmdataStat())); }, ShmdataStat::make_tree_updater(this, ".shmdata.writer." + shmpath))); }
parameter_cache(const device &device) : m_dirty(false), m_device_name(device.name()) { #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // get offline cache file name (e.g. /home/user/.boost_compute/tune/device.json) m_file_name = make_file_name(); // load parameters from offline cache file (if it exists) if(boost::filesystem::exists(m_file_name)){ read_from_disk(); } #endif // BOOST_COMPUTE_USE_OFFLINE_CACHE }
V_EXPORT VSCRIPT_STATUS VSCRIPT_VM_run(VSCRIPT_VM_CTX *ctx, const char *source_file, const char *output_directory, int trace ) { VSCRIPTVM *vm = (VSCRIPTVM *) ctx; VSCRIPTVM_STATUS ret; char bytecode_file[ PATH_MAX ]; make_file_name(bytecode_file, source_file, output_directory, TRACE_FILE_OUTPUT_FILE); ret = VSCRIPTVM_open( vm, bytecode_file, trace); if (ret != VSCRIPT_STATUS_OK) { return ret; } return VSCRIPTVM_run(vm); }
void check_option_source( const char *syntax_dir, const char *option, SyntaxDef *sub_syntax, const char *module_name) { char *filename = make_file_name( syntax_dir, option ); if( CheckFile( filename ) != 0 || mystrcasecmp( option, StandardOptionsEntry ) == 0) { FILE *f = fopen( filename, "w" ); if( f ) { if( option[0] != '_' ) { fprintf( f, "<varlistentry id=\"options.%s\">\n" " <term>%s</term>\n" " <listitem>\n" " <para>FIXME: add proper description here.</para>\n", option, option ); if( sub_syntax ) fprintf( f, " <para>See Also: " "<ulink url=\"%s#synopsis\">%s</ulink> for further details.</para>\n", sub_syntax->doc_path, sub_syntax->display_name ); fprintf( f, " </listitem>\n" "</varlistentry>\n" ); }else { fprintf( f, "<section label=\"%s\" id=\"%s\">\n", &(option[1]), &(option[1]) ); if( module_name ) { if( mystrcasecmp( &(option[1]), "synopsis" ) == 0 ) { fprintf( f, "<cmdsynopsis>\n" "<command>%s</command> [<ulink url=\"%s#standard_options_list\">standard options</ulink>] \n" "</cmdsynopsis>\n", module_name, AfterStepName ); }else if( mystrcasecmp( option, StandardOptionsEntry ) == 0 ) { write_standard_options_source( f ); } } fprintf( f, "</section>\n" ); } fclose(f); } show_progress( "Option %s is missing - created empty source \"%s\".", option, filename ); } free( filename ); }
void on_list_add_clicked(GtkButton *button, gpointer user_data) { ASGtkImageDir *id = ASGTK_IMAGE_DIR(user_data); ASImageListEntry *entry = asgtk_image_dir_get_selection( id ); if( entry ) { ASGtkImageDir *backs_list = ASGTK_IMAGE_DIR(WallpaperState.backs_list); char *new_filename = make_file_name( backs_list->fulldirname, entry->name ); if( CheckFile( new_filename ) == 0 ) { if( !asgtk_yes_no_question1( WallpaperState.main_window, "Private background with the name \"%s\" already exists. Would you like to replace it ???", entry->name ) ) { free( new_filename ); return; } } copy_file (entry->fullfilename, new_filename); free( new_filename ); if( backs_list->mini_extension != NULL && entry->preview != NULL ) { char *mini_filename, *mini_fullfilename ; Bool do_mini = True ; asgtk_image_dir_make_mini_names( backs_list, entry->name, &mini_filename, &mini_fullfilename ); if( CheckFile( mini_fullfilename ) == 0 ) { if( !asgtk_yes_no_question1( WallpaperState.main_window, "Overwrite minipixmap \"%s\" with the new one ?", mini_filename ) ) do_mini = False ; } if( do_mini ) make_mini_for_image_entry( id, entry, mini_fullfilename); free( mini_fullfilename ); free( mini_filename ); } asgtk_info2( WallpaperState.main_window, "New background \"%s\" added.", entry->name, NULL ); unref_asimage_list_entry( entry ); asgtk_image_dir_refresh( backs_list ); } }
bool OscToShmdata::start() { // creating a shmdata shm_ = std2::make_unique<ShmdataWriter>(this, make_file_name("osc"), 4096, "application/x-libloserialized-osc"); if(!shm_.get()) { g_warning("OscToShmdata failed to start"); shm_.reset(nullptr); return false; } osc_thread_ = lo_server_thread_new(std::to_string(port_).c_str(), osc_error); if (nullptr == osc_thread_) return false; /* add method that will match any path and args */ lo_server_thread_add_method(osc_thread_, nullptr, nullptr, osc_handler, this); lo_server_thread_start(osc_thread_); return true; }
void execute_save(char* command, ListT* tasks, TaskT** current_task) { char* filename; int write_result; if (tasks != NULL && tasks->size > 0) { char* user_filename = NULL; char* input_msg = NULL; filename = make_file_name(); input_msg = malloc(strlen(filename) + strlen(kFilenamePromptFormat) + 1); sprintf(input_msg, kFilenamePromptFormat, filename); get_user_input_msg(&user_filename, input_msg); if (user_filename != NULL && strlen(user_filename) > 0) { char* user_filename_with_dir; user_filename_with_dir = malloc(6 + 1 + strlen(user_filename)); sprintf(user_filename_with_dir, "tasks/%s", user_filename); free(filename); free(user_filename); filename = user_filename_with_dir; } write_result = task_write(tasks, filename); if (task_write < 0) { printf("Failed to write tasks to %s\n", filename); } free(filename); } }
bool PulseSrc::init() { init_startable(this); if (!pulsesrc_ || !shmsink_) return false; shmpath_ = make_file_name("audio"); g_object_set(G_OBJECT(pulsesrc_.get_raw()), "client-name", get_name().c_str(), nullptr); g_object_set(G_OBJECT(shmsink_.get_raw()), "socket-path", shmpath_.c_str(), nullptr); std::unique_lock<std::mutex> lock(devices_mutex_); GstUtils::g_idle_add_full_with_context(mainloop_->get_main_context(), G_PRIORITY_DEFAULT_IDLE, async_get_pulse_devices, this, nullptr); // waiting for devices to be updated devices_cond_.wait(lock); if (!connected_to_pulse_) { g_message("ERROR:Not connected to pulse, cannot initialize."); return false; } volume_id_ = pmanage<MPtr(&PContainer::push)>( "volume", GPropToProp::to_prop(G_OBJECT(pulsesrc_.get_raw()), "volume")); mute_id_ = pmanage<MPtr(&PContainer::push)>( "mute", GPropToProp::to_prop(G_OBJECT(pulsesrc_.get_raw()), "mute")); return true; }
int main (int argc, char **argv) { int i ; char *source_dir = NULL ; const char *destination_dir = NULL ; Bool do_data = False; ASDocType target_type = DocType_Source ; /* Save our program name - for error messages */ set_DeadPipe_handler(DeadPipe); InitMyApp (CLASS_ASDOCGEN, argc, argv, NULL, asdocgen_usage, 0 ); LinkAfterStepConfig(); InitSession(); for( i = 1 ; i< argc ; ++i) { LOCAL_DEBUG_OUT( "argv[%d] = \"%s\", original argv[%d] = \"%s\"", i, argv[i]?argv[i]:"(null)", i, MyArgs.saved_argv[i]); if( argv[i] != NULL ) { if( (strcmp( argv[i], "-t" ) == 0 || strcmp( argv[i], "--target" ) == 0) && i+1 < argc && argv[i+1] != NULL ) { ++i ; if( mystrcasecmp( argv[i], "plain" ) == 0 || mystrcasecmp( argv[i], "text" ) == 0) target_type = DocType_Plain ; else if( mystrcasecmp( argv[i], "html" ) == 0 ) target_type = DocType_HTML ; else if( mystrcasecmp( argv[i], "php" ) == 0 ) target_type = DocType_PHP ; else if( mystrcasecmp( argv[i], "xml" ) == 0 ) target_type = DocType_XML ; else if( mystrcasecmp( argv[i], "nroff" ) == 0 ) target_type = DocType_NROFF ; else if( mystrcasecmp( argv[i], "source" ) == 0 ) target_type = DocType_Source ; else show_error( "unknown target type \"%s\"" ); }else if( (strcmp( argv[i], "-s" ) == 0 || strcmp( argv[i], "--css" ) == 0) && i+1 < argc && argv[i+1] != NULL ) { ++i ; HTML_CSS_File = argv[i] ; }else if( strcmp( argv[i], "--faq-css" ) == 0 && i+1 < argc && argv[i+1] != NULL ) { ++i ; FAQ_HTML_CSS_File = argv[i] ; }else if( strcmp( argv[i], "--html-data-back" ) == 0 && i+1 < argc && argv[i+1] != NULL ) { ++i ; if( strcasecmp( argv[i], "none") == 0 ) HTML_DATA_BACKGROUND_File = NULL ; else HTML_DATA_BACKGROUND_File = argv[i] ; }else if( (strcmp( argv[i], "-d" ) == 0 || strcmp( argv[i], "--data" ) == 0) ) { do_data = True ; }else if( (strcmp( argv[i], "-S" ) == 0 || strcmp( argv[i], "--source" ) == 0) && i+1 < argc && argv[i+1] != NULL ) { ++i ; source_dir = argv[i] ; }else if( (strcmp( argv[i], "-D" ) == 0 || strcmp( argv[i], "--dst" ) == 0) && i+1 < argc && argv[i+1] != NULL ) { ++i ; destination_dir = argv[i] ; } } } if( destination_dir == NULL ) destination_dir = do_data?"data":ASDocTypeExtentions[target_type] ; if( source_dir == NULL ) source_dir = do_data?"../../afterstep":"source" ; #if 0 ConnectAfterStep ( mask_reg, 0); SendInfo ( "Nop \"\"", 0); #endif ProcessedSyntaxes = create_ashash( 7, pointer_hash_value, NULL, NULL ); Glossary = create_ashash( 4096, string_hash_value, string_compare, string_destroy ); Index = create_ashash( 4096, string_hash_value, string_compare, string_destroy ); UserLinks = create_ashash( 4096, string_hash_value, string_compare, string_destroy ); APILinks = create_ashash( 4096, string_hash_value, string_compare, string_destroy ); Links = UserLinks; GlossaryName = UserGlossaryName ; TopicIndexName = UserTopicIndexName ; if( target_type < DocType_Source ) { time_t curtime; struct tm *loctime; DocBookVocabulary = create_ashash( 7, casestring_hash_value, casestring_compare, string_destroy_without_data ); for( i = 1 ; i < DOCBOOK_SUPPORTED_IDS ; ++i ) add_hash_item( DocBookVocabulary, AS_HASHABLE(SupportedDocBookTagInfo[i].tag), (void*)(SupportedDocBookTagInfo[i].tag_id)); /* Get the current time. */ curtime = time (NULL); /* Convert it to local time representation. */ loctime = localtime (&curtime); strftime(CurrentDateLong, DATE_SIZE, "%b %e %Y", loctime); strftime(CurrentDateShort, DATE_SIZE, "%m/%d/%Y", loctime); } i = 0 ; LOCAL_DEBUG_OUT( "Starting main action... %s", "" ); if( target_type >= DocType_Source ) /* 1) generate HTML doc structure */ { while( TopLevelSyntaxes[i] ) { /* create directory structure for source docs and all the missing files */ check_syntax_source( source_dir, TopLevelSyntaxes[i], (i >= MODULE_SYNTAX_START) ); ++i ; } check_syntax_source( source_dir, NULL, True ); }else if( do_data ) { char *env_path1 = NULL, *env_path2 = NULL ; ASColorScheme *cs = NULL ; if ((dpy = XOpenDisplay (MyArgs.display_name))) { set_current_X_display (dpy); Scr.MyDisplayWidth = DisplayWidth (dpy, Scr.screen); Scr.MyDisplayHeight = DisplayHeight (dpy, Scr.screen); Scr.asv = create_asvisual (dpy, Scr.screen, DefaultDepth(dpy,Scr.screen), NULL); }else { Scr.asv = create_asvisual(NULL, 0, 32, NULL); } asxml_var_insert("xroot.width", 640); asxml_var_insert("xroot.height", 480); env_path1 = getenv( "IMAGE_PATH" ) ; env_path2 = getenv( "PATH" ); if( env_path1 == NULL ) { env_path1 = env_path2; env_path2 = NULL ; } Scr.image_manager = create_image_manager( NULL, 2.2, env_path1, env_path2, NULL ); set_xml_image_manager( Scr.image_manager ); env_path1 = getenv( "FONT_PATH" ) ; Scr.font_manager = create_font_manager( dpy, env_path1, NULL ); set_xml_font_manager( Scr.font_manager ); /*ReloadASEnvironment( NULL, NULL, NULL, False ); */ cs = make_default_ascolor_scheme(); populate_ascs_colors_rgb( cs ); populate_ascs_colors_xml( cs ); free( cs ); TopicIndexName = NULL ; CurrHtmlBackFile = HTML_DATA_BACKGROUND_File ; gen_data_doc( source_dir, destination_dir?destination_dir:"data", "", "Installed data files - fonts, images and configuration", target_type ); flush_ashash( Glossary ); flush_ashash( Index ); }else { char *api_dest_dir ; api_dest_dir = make_file_name( destination_dir, "API" ); GlossaryName = UserGlossaryName ; TopicIndexName = UserTopicIndexName ; Links = UserLinks; DocGenerationPass = 2 ; while( --DocGenerationPass >= 0 ) { gen_code_doc( "../../libAfterImage", destination_dir, "asimagexml.c", "AfterImage XML", "XML schema to be used for scripting image manipulation by AfterStep and ascompose", target_type ); /* we need to generate some top level files for afterstep itself : */ gen_syntax_doc( source_dir, destination_dir, NULL, target_type ); for( i = 0 ; TopLevelSyntaxes[i] ; ++i ) gen_syntax_doc( source_dir, destination_dir, TopLevelSyntaxes[i], target_type ); if( DocGenerationPass == 0 ) { gen_faq_doc( source_dir, destination_dir, target_type ); gen_glossary( destination_dir, "Glossary", target_type ); gen_index( destination_dir, "index", target_type, True ); } flush_ashash( ProcessedSyntaxes ); } flush_ashash( Glossary ); flush_ashash( Index ); GlossaryName = APIGlossaryName ; TopicIndexName = APITopicIndexName ; Links = APILinks; DocGenerationPass = 2 ; CurrentManType = 3 ; while( --DocGenerationPass >= 0 ) { int s ; for( s = 0 ; libAfterImage_Sources[s].src_file != NULL ; ++s ) { gen_code_doc( "../../libAfterImage", api_dest_dir, libAfterImage_Sources[s].src_file, libAfterImage_Sources[s].descr_short, libAfterImage_Sources[s].descr_long, target_type ); } if( DocGenerationPass == 0 ) { gen_glossary( api_dest_dir, "Glossary", target_type ); gen_index( api_dest_dir, "index", target_type, False ); } flush_ashash( Glossary ); flush_ashash( Index ); } } if( dpy ) XCloseDisplay (dpy); return 0; }
void check_syntax_source( const char *source_dir, SyntaxDef *syntax, Bool module ) { int i ; char *syntax_dir = NULL ; char *obsolete_dir ; struct direntry **list = NULL; int list_len ; if( syntax ) { if( get_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ) == ASH_Success ) return ; if( syntax->doc_path != NULL && syntax->doc_path[0] != '\0' ) syntax_dir = make_file_name (source_dir, syntax->doc_path); } if( syntax_dir == NULL ) syntax_dir = mystrdup( source_dir ); obsolete_dir = make_file_name (syntax_dir, "obsolete" ); if( CheckDir(syntax_dir) != 0 ) if( !make_doc_dir( syntax_dir ) ) { free( syntax_dir ); return; } if( syntax ) { add_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ); /* pass one: lets see which of the existing files have no related options : */ list_len = my_scandir ((char*)syntax_dir, &list, ignore_dots, NULL); for (i = 0; i < list_len; i++) { int k ; if (!S_ISDIR (list[i]->d_mode)) { char *name = list[i]->d_name ; show_progress( "checking \"%s\" ... ", name ); if( name[0] != '_' ) { for (k = 0; syntax->terms[k].keyword; k++) if( mystrcasecmp(name, syntax->terms[k].keyword ) == 0 ) break; if( syntax->terms[k].keyword == NULL || get_flags( syntax->terms[k].flags, TF_OBSOLETE) ) { /* obsolete option - move it away */ char *obsolete_fname = make_file_name (obsolete_dir, name ); char *fname = make_file_name (syntax_dir, name ); Bool no_dir = False ; if( CheckDir(obsolete_dir) != 0 ) no_dir = !make_doc_dir( obsolete_dir ) ; if( !no_dir ) { copy_file (fname, obsolete_fname); show_progress( "Option \"%s\" is obsolete - moving away!", name ); unlink(fname); } free( fname ); free( obsolete_fname ); } } } free( list[i] ); } if( list ) free (list); /* pass two: lets see which options are missing : */ for (i = 0; syntax->terms[i].keyword; i++) { if( !get_flags( syntax->terms[i].flags, TF_OBSOLETE) ) { SyntaxDef *sub_syntax = syntax->terms[i].sub_syntax ; if( sub_syntax == pPopupFuncSyntax ) sub_syntax = pFuncSyntax ; if (sub_syntax) check_syntax_source( source_dir, sub_syntax, False ); if( isalnum( syntax->terms[i].keyword[0] ) ) check_option_source( syntax_dir, syntax->terms[i].keyword, sub_syntax, module?syntax->doc_path:NULL ) ; } } for (i = module?0:1; StandardSourceEntries[i] != NULL ; ++i) check_option_source( syntax_dir, StandardSourceEntries[i], NULL, module?syntax->doc_path:NULL ) ; if( module ) { check_option_source( syntax_dir, BaseOptionsEntry, NULL, syntax->doc_path ) ; check_option_source( syntax_dir, MyStylesOptionsEntry, NULL, syntax->doc_path ) ; } }else generate_main_source( syntax_dir ); free( obsolete_dir ); free( syntax_dir ); }
void gen_syntax_doc( const char *source_dir, const char *dest_dir, SyntaxDef *syntax, ASDocType doc_type ) { ASXMLInterpreterState state; const char *doc_path = AfterStepName ; char *syntax_dir = NULL ; int i ; ASFlagType doc_class_mask = 0 ; if( syntax ) { if( get_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ) == ASH_Success ) return ; doc_path = syntax->doc_path ; } if( syntax != NULL && syntax->doc_path != NULL && syntax->doc_path[0] != '\0' ) syntax_dir = make_file_name (source_dir, syntax->doc_path); if( syntax_dir == NULL ) syntax_dir = mystrdup( source_dir ); if( doc_type == DocType_PHP ) { int overview_size = 0 ; int tmp ; /* we generate upto 4 files in PHP mode : overview, Base config, MyStyles and Config Options * Overview and Config Options are always present. Others may be ommited if source is missing * If Overview is too small - say < 1024 bytes - it could be bundled with Config Options */ set_flags( doc_class_mask, DOC_CLASS_Overview ); LOCAL_DEBUG_OUT( "Checking what parts to generate ...%s", ""); if( (tmp = check_xml_contents( syntax_dir, MyStylesOptionsEntry )) > 0) set_flags( doc_class_mask, DOC_CLASS_MyStyles ); LOCAL_DEBUG_OUT( "MyStyle size = %d", tmp ); if((tmp = check_xml_contents( syntax_dir, BaseOptionsEntry )) > 0) set_flags( doc_class_mask, DOC_CLASS_BaseConfig ); LOCAL_DEBUG_OUT( "Base size = %d", tmp ); for( i = 0 ; StandardSourceEntries[i] ; ++i ) overview_size += check_xml_contents( syntax_dir, StandardSourceEntries[i] ); if( syntax == NULL ) overview_size += 0 ; LOCAL_DEBUG_OUT( "overview size = %d", overview_size ); if( overview_size > OVERVIEW_SIZE_THRESHOLD ) set_flags( doc_class_mask, DOC_CLASS_Options ); }else doc_class_mask = DOC_CLASS_None ; if( !start_doc_file( dest_dir, doc_path, NULL, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_Overview ) ) return ; if( doc_type != DocType_PHP ) { /* BODY *************************************************************************/ i = 0 ; if( syntax == NULL ) { convert_xml_file( syntax_dir, StandardSourceEntries[0], &state ); ++i ; convert_xml_file( syntax_dir, StandardOptionsEntry, &state ); } for( ; i < OPENING_PARTS_END ; ++i ) convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ); if( syntax ) { convert_xml_file( syntax_dir, BaseOptionsEntry, &state ); convert_xml_file( syntax_dir, MyStylesOptionsEntry, &state ); } }else { i = 0 ; if( syntax == NULL ) { convert_xml_file( syntax_dir, StandardSourceEntries[0], &state ); ++i ; convert_xml_file( syntax_dir, StandardOptionsEntry, &state ); } for( ; StandardSourceEntries[i] ; ++i ) { if (( convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ) == True) && ( i == 0 ) ) fprintf( state.dest_fp, "<hr>\n" ); } if( get_flags( doc_class_mask, DOC_CLASS_Options ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, "_options", doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_Options ); fprintf( state.dest_fp, "<UL>\n" ); } } LOCAL_DEBUG_OUT( "starting config_options%s", "" ); if( syntax && state.dest_fp ) { write_options_header( &state ); write_options_keywords(source_dir, syntax_dir, syntax, &state ); write_options_footer( &state ); } LOCAL_DEBUG_OUT( "done with config_options%s", "" ); if( doc_type != DocType_PHP ) { for( i = OPENING_PARTS_END ; StandardSourceEntries[i] ; ++i ) convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ); }else if( state.dest_fp ) { if( state.doc_class == DocClass_Options ) fprintf( state.dest_fp, "</UL>\n" ); if( get_flags( doc_class_mask, DOC_CLASS_BaseConfig ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, BaseOptionsEntry, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_BaseConfig ); convert_xml_file( syntax_dir, BaseOptionsEntry, &state ); } if( get_flags( doc_class_mask, DOC_CLASS_MyStyles ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, MyStylesOptionsEntry, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_MyStyles ); convert_xml_file( syntax_dir, MyStylesOptionsEntry, &state ); } } /* FOOTER ***********************************************************************/ end_doc_file( &state ); if( syntax ) add_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ); free( syntax_dir ); }
void check_AfterStep_dirtree ( char * ashome, Bool create_non_conf ) { char *fullfilename; /* Create missing directories & put there defaults */ if (CheckDir (ashome) != 0) { CheckOrCreate (ashome); #if defined(DO_SEND_POSTCARD) /*&& defined(HAVE_POPEN) */ /* send some info to sasha @ aftercode.net */ { FILE *p; char *filename = make_file_name(ashome, ".postcard"); /*p = popen ("mail -s \"AfterStep installation info\" [email protected]", "w");*/ p = fopen( filename, "wt" ); free(filename); if (p) { fprintf( p, "AfterStep_Version=\"%s\";\n", VERSION ); fprintf( p, "CanonicalBuild=\"%s\";\n", CANONICAL_BUILD ); fprintf( p, "CanonicalOS=\"%s\";\n", CANONICAL_BUILD_OS ); fprintf( p, "CanonicalCPU=\"%s\";\n", CANONICAL_BUILD_CPU ); fprintf( p, "CanonicalVendor=\"%s\";\n", CANONICAL_BUILD_VENDOR ); if( dpy ) { fprintf (p, "X_DefaultScreenNumber=%d;\n", DefaultScreen (dpy)); fprintf (p, "X_NumberOfScreens=%d;\n", ScreenCount (dpy)); fprintf (p, "X_Display=\"%s\";\n", DisplayString (dpy)); fprintf (p, "X_ProtocolVersion=%d.%d;\n", ProtocolVersion (dpy), ProtocolRevision (dpy)); fprintf (p, "X_Vendor=\"%s\";\n", ServerVendor (dpy)); fprintf (p, "X_VendorRelease=%d;\n", VendorRelease (dpy)); if (strstr(ServerVendor (dpy), "XFree86")) { int vendrel = VendorRelease(dpy); fprintf(p, "X_XFree86Version="); if (vendrel < 336) { fprintf(p, "%d.%d.%d", vendrel / 100, (vendrel / 10) % 10, vendrel % 10); } else if (vendrel < 3900) { fprintf(p, "%d.%d", vendrel / 1000, (vendrel / 100) % 10); if (((vendrel / 10) % 10) || (vendrel % 10)) { fprintf(p, ".%d", (vendrel / 10) % 10); if (vendrel % 10) fprintf(p, ".%d", vendrel % 10); } } else if (vendrel < 40000000) { fprintf(p, "%d.%d", vendrel/1000, (vendrel/10) % 10); if (vendrel % 10) fprintf(p, ".%d", vendrel % 10); } else { fprintf(p, "%d.%d.%d", vendrel/10000000,(vendrel/100000)%100, (vendrel/1000)%100); if (vendrel % 1000) fprintf(p, ".%d", vendrel % 1000); } fprintf(p, ";\n"); } if( ASDefaultScrWidth > 0 ) { fprintf( p, "AS_Screen=%ld;\n", ASDefaultScr->screen ); fprintf( p, "AS_RootGeometry=%dx%d;\n", ASDefaultScrWidth, ASDefaultScrHeight ); } if( ASDefaultVisual ) { fprintf( p, "AS_Visual=0x%lx;\n", ASDefaultVisual->visual_info.visualid ); fprintf( p, "AS_Colordepth=%d;\n", ASDefaultVisual->visual_info.depth ); fprintf( p, "AS_RedMask=0x%lX;\n", ASDefaultVisual->visual_info.red_mask ); fprintf( p, "AS_GreenMask=0x%lX;\n", ASDefaultVisual->visual_info.green_mask ); fprintf( p, "AS_BlueMask=0x%lX;\n", ASDefaultVisual->visual_info.blue_mask ); fprintf( p, "AS_ByteOrdering=%s;\n", (ImageByteOrder(ASDefaultVisual->dpy)==MSBFirst)?"MSBFirst":"LSBFirst" ); } } fclose(p); /*pclose (p);*/ /*p = popen ("mail -s \"AfterStep installation info\" [email protected]", "w");*/ } } #endif } fullfilename = make_file_name (ashome, AFTER_SAVE); CheckOrCreateFile (fullfilename); free( fullfilename ); #if 0 fullfilename = make_file_name (ashome, THEME_FILE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, LOOK_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, FEEL_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, THEME_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, COLORSCHEME_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, BACK_DIR); CheckOrCreate(fullfilename); free( fullfilename ); #endif fullfilename = make_file_name (ashome, DESKTOP_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, ICON_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, FONT_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, TILE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, WEBCACHE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); if( create_non_conf ) { char *postcard_fname ; FILE *f ; fullfilename = make_file_name (ashome, AFTER_NONCF); /* legacy non-configurable dir: */ CheckOrCreate(fullfilename); postcard_fname = make_file_name( fullfilename, "send_postcard.sh" ); free( fullfilename ); f = fopen( postcard_fname, "wt" ); if( f ) { fprintf( f, "#!/bin/sh\n\n" ); fprintf( f, "if [ -r %s/.postcard ] \nthen echo -n \nelse rm %s \nexit\nfi\n", ashome, postcard_fname ); fprintf( f, "x-terminal-emulator -e \"%s/tools/postcard.sh\"\n", AFTER_SHAREDIR ); fprintf( f, "if [ -r %s/.postcard ] \nthen echo -n \nelse rm %s \nfi\n", ashome, postcard_fname ); fclose( f ); } chmod (postcard_fname, 0700); free(postcard_fname); } char *cachefilename = make_file_name(ashome, THUMBNAILS_DIR); CheckOrCreate(cachefilename); extern void set_asimage_thumbnails_cache_dir(const char*); set_asimage_thumbnails_cache_dir(cachefilename); free( cachefilename ); }
bool PostureMerge::connect(std::string shmdata_socket_path) { unique_lock<mutex> connectLock(connect_mutex_); int index = source_id_; source_id_ += 1; int shmreader_id = shmreader_id_; shmreader_id_++; auto reader = std2::make_unique<ShmdataFollower>(this, shmdata_socket_path, [=] (void *data, size_t size) { // If another thread is trying to get the merged cloud, stock him and don't bother if (!mutex_.try_lock()) { unique_lock<mutex> lock(stock_mutex_); stock_[index] = vector<char> ((char*)data, (char*) data + size); return; } // Test if we already received the type auto typeIt = cloud_readers_caps_.find(shmreader_id); if (typeIt == cloud_readers_caps_.end()) { mutex_.unlock(); return; } string type = typeIt->second; if (merger_ == nullptr || (type != string(POINTCLOUD_TYPE_BASE) && type != string(POINTCLOUD_TYPE_COMPRESSED))) { mutex_.unlock(); return; } if (reload_calibration_) merger_->reloadCalibration(); // Setting input clouds is thread safe, so lets do it { unique_lock<mutex> lock(stock_mutex_); for (auto it = stock_.begin(); it != stock_.end(); ++it) { merger_->setInputCloud(it->first, it->second, type != string(POINTCLOUD_TYPE_BASE)); } stock_.clear(); } merger_->setInputCloud(index, vector<char>((char*)data, (char*) data + size), type != string(POINTCLOUD_TYPE_BASE)); auto cloud = vector<char>(); merger_->getCloud(cloud); if (cloud_writer_.get() == nullptr || cloud.size() > cloud_writer_->writer(&shmdata::Writer::alloc_size)) { auto data_type = compress_cloud_ ? string(POINTCLOUD_TYPE_COMPRESSED) : string(POINTCLOUD_TYPE_BASE); cloud_writer_.reset(); cloud_writer_ = std2::make_unique<ShmdataWriter>(this, make_file_name("cloud"), std::max(cloud.size() * 2, (size_t)1024), data_type); } cloud_writer_->writer(&shmdata::Writer::copy_to_shm, const_cast<char*>(cloud.data()), cloud.size()); cloud_writer_->bytes_written(cloud.size()); mutex_.unlock(); }, [=](string caps) { unique_lock<mutex> lock(mutex_); cloud_readers_caps_[shmreader_id] = caps; }); cloud_readers_[shmdata_socket_path] = std::move(reader); return true; }