/** Function oyConfigs_FromDomain * @memberof oyConfigs_s * @brief Send a request to a configuration module * * The convention an empty options argument should be send an Warning message * containing intructions on how to talk with the module as a fallback for * programmers. Otherwise the calls are pure convention and depend on the usage * and agreement of the partners. * * For the convention to call to colour devices * @see oyX1Configs_FromPatternUsage(). * * @param[in] registration_domain the module to call to * @param[in] options options to specify the calling into modules * messages are bound to this object * @param[out] configs the returned configurations * @param[in] object a optional user object * @return 0 - good, 1 <= error, -1 >= issues, * look for messages * * @version Oyranos: 0.1.10 * @since 2009/01/16 (Oyranos: 0.1.10) * @date 2009/01/19 */ OYAPI int OYEXPORT oyConfigs_FromDomain ( const char * registration_domain, oyOptions_s * options, oyConfigs_s ** configs, oyObject_s object ) { oyConfigs_s * s = 0; oyConfig_s * config = 0; int error = !registration_domain, l_error = 0; oyCMMapi8_s_ * cmm_api8 = 0; int i, n; oyExportStart_(EXPORT_CHECK_NO); /** * 1. first we search for oyCMMapi8_s complex config support matching to our * registration_domain * 2. if we find a module, we ask for the options * 3. add the options to the config (in the module) */ if(error <= 0) { cmm_api8 = (oyCMMapi8_s_*) oyCMMsGetFilterApi_( 0, registration_domain, oyOBJECT_CMM_API8_S ); error = !cmm_api8; } if(error <= 0) error = !cmm_api8->oyConfigs_FromPattern; if(error <= 0) error = cmm_api8->oyConfigs_FromPattern( registration_domain, options, &s ); if(error <= 0) { n = oyConfigs_Count( s ); for(i = 0; i < n && error <= 0; ++i) { config = oyConfigs_Get( s, i ); l_error = oyOptions_SetSource( oyConfigPriv_m(config)->backend_core, oyOPTIONSOURCE_FILTER); OY_ERR l_error = oyOptions_SetSource( oyConfigPriv_m(config)->data, oyOPTIONSOURCE_FILTER ); OY_ERR oyConfig_Release( &config ); } } if(error <= 0 && configs) { *configs = s; s = 0; } else oyConfigs_Release( &s ); oyExportEnd_(); return error; }
/** Function oyConfigDomainList * @memberof oyConfigs_s * @brief Count and show the global oyConfigs_s suppliers * * @verbatim uint32_t count = 0, * rank_list = 0; char ** texts = 0, * temp = 0, ** attributes = 0, * device_class = 0; int i,j, attributes_n; // get all configuration filters oyConfigDomainList("//"OY_TYPE_STD"/config", &texts, &count,&rank_list ,0 ); for( i = 0; i < count; ++i ) { attributes_n = 0; // pick the filters name and remove the common config part temp = oyFilterRegistrationToText( texts[i], oyFILTER_REG_APPLICATION, malloc ); attributes = oyStringSplit_( temp, '.', &attributes_n, malloc ); free(temp); temp = malloc(1024); temp[0] = 0; for(j = 0; j < attributes_n; ++j) { if(strcmp(attributes[j], "config") == 0) continue; if(j && temp[0]) sprintf( &temp[strlen(temp)], "." ); sprintf( &temp[strlen(temp)], "%s", attributes[j]); } // The string in temp can be passed as the device_class argument to // oyDevicesGet() printf("%d: %s \"%s\"\n", i, texts[i], temp); oyStringListRelease_( &attributes, attributes_n, free ); free (device_class); free(temp); } @endverbatim * * @param[in] registration_pattern a optional filter * @param[out] list the list with full filter registrations * @param[out] count the list count * @param[out] rank_list the rank fitting to list * @param[in] allocateFunc the user allocator for list * @return 0 - good, >= 1 - error, <= -1 unknown * * @version Oyranos: 0.1.10 * @since 2009/01/19 (Oyranos: 0.1.10) * @date 2009/01/19 */ OYAPI int OYEXPORT oyConfigDomainList ( const char * registration_pattern, char *** list, uint32_t * count, uint32_t ** rank_list, oyAlloc_f allocateFunc ) { oyCMMapiFilters_s * apis = 0; oyCMMapiFilter_s_ * api = 0; int error = !list || !count; char ** reg_lists = 0; int i = 0, reg_list_n = 0; uint32_t apis_n = 0; oyExportStart_(EXPORT_CHECK_NO); if(error <= 0) { apis = oyCMMsGetFilterApis_( 0, registration_pattern, oyOBJECT_CMM_API8_S, rank_list, &apis_n); error = !apis; } if(error <= 0) { if(!allocateFunc) allocateFunc = oyAllocateFunc_; for(i = 0; i < apis_n; ++i) { api = (oyCMMapiFilter_s_*)oyCMMapiFilters_Get( apis, i ); oyStringListAddStaticString_( ®_lists, ®_list_n, oyNoEmptyString_m_( api->registration ), oyAllocateFunc_, oyDeAllocateFunc_ ); if(api->release) api->release( (oyStruct_s**)&api ); } if(reg_list_n && reg_lists) *list = oyStringListAppend_( (const char**)reg_lists, reg_list_n, 0,0, ®_list_n, allocateFunc ); oyStringListRelease_( ®_lists, reg_list_n, oyDeAllocateFunc_ ); } if(count) *count = reg_list_n; oyCMMapiFilters_Release( &apis ); oyExportEnd_(); return error; }
int main( int argc , char** argv ) { int error = 0; int list_profiles = 0, list_profile_full_names = 0, list_profile_internal_names = 0, list_paths = 0, user_path = 0, oyranos_path = 0, system_path = 0, machine_path = 0, v2 = 0, v4 = 0, no_repair = 0, duplicates = 0; int color_space = 0, display = 0, input = 0, output = 0, abstract = 0, named_color = 0, device_link = 0; const char * install = 0; int is_device_profile = 0; int show_gui = 0; const char * taxi_id = NULL, * path = NULL, * meta = NULL; #ifdef USE_GETTEXT setlocale(LC_ALL,""); #endif oyExportStart_(EXPORT_CHECK_NO); oyjlOptions_s * opts; oyjlOption_s * o; oyjlUi_s * ui; oyjlUiHeaderSection_s * info; const char * export = NULL; int help = 0; int verbose = 0; int state = 0; opts = oyjlOptions_New( argc, (const char**)argv ); /* nick, name, description, help */ oyjlOptionChoice_s env_vars[]={{"OY_DEBUG", _("set the Oyranos debug level."), _("Alternatively the -v option can be used."), _("Valid integer range is from 1-20.")}, {"XDG_DATA_HOME XDG_DATA_DIRS", _("route Oyranos to top directories containing resources. The derived paths for ICC profiles have a \"color/icc\" appended. http://www.oyranos.com/wiki/index.php?title=OpenIccDirectoryProposal"), "", ""}, {"","","",""}}; oyjlOptionChoice_s examples[]={{_("List all installed profiles by internal name"), "oyranos-profiles", "-le", ""}, {_("List all installed profiles of the display and output device classes"), "oyranos-profiles", "-l -od", ""}, {_("List all installed profiles in user path"), "oyranos-profiles", "-lfu", ""}, {_("Install a profile for the actual user and show error messages in a GUI"), "oyranos-profiles", "--install profilename -u --gui", ""}, {_("Install a profile for the actual user and show error messages in a GUI"), "oyranos-profiles", "--install - --taxi=taxi_id/0 --gui -d -u", ""}, {_("Show file infos"),"SAVEIFS=$IFS ; IFS=$'\\n\\b'; profiles=(`oyranos-profiles -ldf`); IFS=$SAVEIFS; for file in \"${profiles[@]}\"; do ls \"$file\"; done", "", ""}, {"","","",""}}; oyjlOptionChoice_s effect_meta[]={{"EFFECT_class;sepia","","",""},{"","","",""}}; oyjlOption_s oarray[] = { /* type, flags, o, option, key, name, description, help, value_name, value_type, values, var_type, variable */ {"oiwi", 0, '2', "icc-version-2", NULL, _("ICC Version 2"), _("Select ICC v2 Profiles"), NULL, NULL, oyjlOPTIONTYPE_NONE, {}, oyjlINT, {.i=&v2} },
/** Function oyConfigs_SelectSimilars * @memberof oyConfigs_s * @brief Filter similar configs compared by a pattern * * This is a simple convenience function to select from a list existing * configurations. * * @verbatim const char * pattern[][2] = {{"device_name",0}, {"manufacturer",0}, {"model",0}, {"serial",0}, {0,0}}; oyConfigs_s * devices = 0, * filtered = 0; int error = oyConfigs_FromDB( registration, &devices, 0 ); error = oyConfigs_SelectSimilars( devices, pattern, &filtered ) * @endverbatim * * @param[in] list the list * @param[in] pattern user supplied zero terminated pattern * list; The first element is a mandadory * key to meet. The second element is the * optional value. Each * @param[out] filtered the result * @return error * * @version Oyranos: 0.1.10 * @since 2009/02/26 (Oyranos: 0.1.10) * @date 2009/02/26 */ OYAPI int OYEXPORT oyConfigs_SelectSimilars ( oyConfigs_s * list, const char * pattern[][2], oyConfigs_s ** filtered ) { int error = !list; int i,j, matches = 0, n, required = 0; oyConfigs_s * s = list, * result = 0; oyConfig_s * device = 0; const char * ct = 0; if(!s) return 0; if(s) oyCheckType__m( oyOBJECT_CONFIGS_S, return 0 ) /** 0. setup Elektra */ oyExportStart_(EXPORT_PATH | EXPORT_SETTING); result = oyConfigs_New(0); n = oyConfigs_Count( list ); for(i = 0; i < n; ++i) { device = oyConfigs_Get( list, i ); j = 0; matches = 0; required = 0; while(pattern[j][0]) { ct = oyConfig_FindString( device, pattern[j][0], 0); if(pattern[j][1]) { ++required; if(ct && strcmp(ct,pattern[j][1]) == 0) ++matches; } else { ++required; ++matches; } ++j; } if(required == matches) error = oyConfigs_MoveIn( result, &device, -1 ); oyConfig_Release( &device ); } *filtered = result; return error; }
/** Function oyConfigs_Modify * @memberof oyConfigs_s * @brief Ask a module for device informations or other direct calls * * * @param[in,out] configs The passed configs first member is used * to obtain a registration string and * select a appropriate module. * Regarding the module the * configs need to be homogenous. * All configs are passed at once to the * module. Mixing configs from different * modules is not defined. * @param[in] options options to pass to the module; With zero * the usage instructions are requested. * @return 0 - good, >= 1 - error, issue <= -1 * * @version Oyranos: 0.1.10 * @since 2009/08/21 (Oyranos: 0.1.10) * @date 2009/08/25 */ OYAPI int OYEXPORT oyConfigs_Modify ( oyConfigs_s * configs, oyOptions_s * options ) { int error = !oyConfigs_Count( configs ); oyConfig_s_ * config = 0; oyConfigs_s * s = configs; int i; uint32_t count = 0, * rank_list = 0; char ** texts = 0, * registration_domain = 0; oyCMMapi8_s_ * cmm_api8 = 0; if(error > 0) { WARNc_S( "\n No devices provided. Give up" ); return 0; } oyCheckType__m( oyOBJECT_CONFIGS_S, return 1 ) oyExportStart_(EXPORT_CHECK_NO); if(error <= 0) { /** 1. pick the first device to select a registration */ config = (oyConfig_s_*)oyConfigs_Get( configs, 0 ); /** 1.2 get all device class module names from the firsts oyConfig_s * registration */ error = oyConfigDomainList ( config->registration, &texts, &count, &rank_list, 0 ); oyConfig_Release( (oyConfig_s**)&config ); } /** 2. call each modules oyCMMapi8_s::oyConfigs_Modify */ for( i = 0; i < count; ++i ) { registration_domain = texts[i]; if(error <= 0) { cmm_api8 = (oyCMMapi8_s_*) oyCMMsGetFilterApi_( 0, registration_domain, oyOBJECT_CMM_API8_S ); error = !cmm_api8; } if(error <= 0) error = !cmm_api8->oyConfigs_Modify; if(error <= 0) error = cmm_api8->oyConfigs_Modify( configs, options ); } oyStringListRelease_( &texts, count, oyDeAllocateFunc_ ); if(rank_list) oyDeAllocateFunc_( rank_list ); oyExportEnd_(); return error; }
/** Function oyConfigs_FromDB * @memberof oyConfigs_s * @brief Get all oyConfigs_s from DB * * @param[in] registration the filter * @param[out] configs the found configuration list * @param[in] object a optional user object * @return error * * @version Oyranos: 0.1.10 * @since 2009/01/23 (Oyranos: 0.1.10) * @date 2010/02/25 */ OYAPI int OYEXPORT oyConfigs_FromDB ( const char * registration, oyConfigs_s ** configs, oyObject_s object ) { oyConfigs_s * s = 0; oyConfig_s_ * config = 0; oyOption_s * o = 0; char ** texts = 0, ** key_set_names = 0, ** config_key_names = 0; uint32_t count = 0, * d_rank_list = 0; int error = !registration; int i, j, k, n = 0, k_n = 0; oyCMMapi8_s_ * cmm_api8 = 0; /** 0. setup Elektra */ oyExportStart_(EXPORT_PATH | EXPORT_SETTING); if(error <= 0) { /** 1. get all module names for the registration pattern */ error = oyConfigDomainList( registration, &texts, &count, &d_rank_list, 0 ); if(count) s = oyConfigs_New( 0 ); if(error <= 0 && count && texts) cmm_api8 = (oyCMMapi8_s_*) oyCMMsGetFilterApi_( 0, texts[0], oyOBJECT_CMM_API8_S ); for(i = 0; i < count; ++i) { /** 2. obtain the directory structure for configurations */ key_set_names = oyKeySetGetNames_( texts[i], &n ); if(error <= 0) for(j = 0; j < n; ++j) { /** 3. obtain all keys from one configuration directory */ config_key_names = oyKeySetGetNames_( key_set_names[j], &k_n ); config = (oyConfig_s_*)oyConfig_New( texts[i], object ); error = !config; for(k = 0; k < k_n; ++k) { /** 4. create a oyOption_s for each Elektra DB key/value pair */ if(error <= 0) o = oyOption_FromDB( config_key_names[k], object ); error = !o; if(error <= 0) error = oyOptions_Add( config->db, o, -1, 0 ); else { WARNcc1_S( (oyStruct_s*) object, "Could not generate key %s", config_key_names[k] ); break; } oyOption_Release( &o ); } /* add information about the data's origin */ oyConfig_AddDBData( (oyConfig_s*)config, "key_set_name", key_set_names[j], OY_CREATE_NEW ); /* add a rank map to allow for comparisions */ if(cmm_api8) config->rank_map = oyRankMapCopy( cmm_api8->rank_map, config->oy_->allocateFunc_ ); oyConfigs_MoveIn( s, (oyConfig_s**)&config, -1 ); } } oyStringListRelease_( &texts, count, oyDeAllocateFunc_ ); } if(configs) *configs = s; else oyConfigs_Release( &s ); oyExportEnd_(); return error; }
int main( int argc , char** argv ) { int error = 0; const char* save_policy = NULL, * import_policy = NULL; oySCOPE_e scope = oySCOPE_USER; size_t size = 0; char * xml = NULL; char * import_policy_fn = NULL; int current_policy = 0, list_policies = 0, list_paths = 0, dump_policy = 0; int long_help = 0, internal_name = 0, file_name = 0; int verbose = 0; #ifdef USE_GETTEXT setlocale(LC_ALL,""); #endif oyExportStart_(EXPORT_CHECK_NO); if(argc >= 2) { int pos = 1, i; char *wrong_arg = 0; DBG_PROG1_S("argc: %d\n", argc); while(pos < argc) { switch(argv[pos][0]) { case '-': for(i = 1; i < strlen(argv[pos]); ++i) switch (argv[pos][i]) { case 'c': current_policy = 1; break; case 'd': dump_policy = 1; break; case 'e': internal_name = 1; break; case 'f': file_name = 1; break; case 'i': OY_PARSE_STRING_ARG(import_policy); break; case 'l': list_policies = 1; break; case 'p': list_paths = 1; break; case 's': OY_PARSE_STRING_ARG(save_policy); break; case 'v': if(verbose) oy_debug += 1; verbose = 1; break; case '-': if(i == 1) { if(OY_IS_ARG("help")) { long_help = 1; i=100; break; } else if(OY_IS_ARG("path")) { list_paths = 1; i=100; break; } else if(OY_IS_ARG("system-wide")) { scope = oySCOPE_SYSTEM; i=100; break; } } case 'h': default: printfHelp(argc, argv); exit (0); break; } break; default: printfHelp(argc, argv); exit (0); break; } if( wrong_arg ) { fprintf(stderr, "%s %s\n", _("wrong argument to option:"), wrong_arg); printfHelp(argc, argv); exit(1); } ++pos; } } else { printfHelp(argc, argv); exit (0); } if(verbose) fprintf( stderr, " Oyranos v%s\n", oyNoEmptyName_m_(oyVersionString(1,0))); /* check the default paths */ /*oyPathAdd( OY_PROFILE_PATH_USER_DEFAULT );*/ /* load the policy file into memory */ import_policy_fn = oyMakeFullFileDirName_(import_policy); if(oyIsFile_(import_policy_fn)) { xml = oyReadFileToMem_( oyMakeFullFileDirName_(import_policy), &size, oyAllocateFunc_ ); oyDeAllocateFunc_( import_policy_fn ); } /* parse and set policy */ if(xml) { oyReadXMLPolicy( oyGROUP_ALL, xml ); oyDeAllocateFunc_( xml ); } else if ( import_policy ) { error = oyPolicySet( import_policy, 0 ); if(error) fprintf( stderr, "%s:%d could not read file: %s\n",__FILE__,__LINE__, import_policy); return 1; } if(save_policy) { error = oyPolicySaveActual( oyGROUP_ALL, scope, save_policy ); if(!error) fprintf( stdout, "%s \"%s\"\n", _("installed new policy"), save_policy); else fprintf( stdout, "\"%s\" %s %d\n", save_policy, _("installation of new policy file failed with error:"), error); } else if(current_policy || list_policies || list_paths) { const char ** names = NULL; int count = 0, i, current = -1; oyOptionChoicesGet( oyWIDGET_POLICY, &count, &names, ¤t ); if(list_policies) for(i = 0; i < count; ++i) { if(file_name) { char * full_name = NULL; error = oyPolicyFileNameGet_( names[i], &full_name, oyAllocateFunc_ ); if(error) fprintf(stderr, "%s error: %d\n", names[i], error); if(internal_name) fprintf(stdout, "%s (%s)\n", names[i], full_name); else fprintf(stdout, "%s\n", full_name); oyFree_m_( full_name ); } else fprintf(stdout, "%s\n", names[i]); } if(current_policy) { fprintf( stderr, "%s\n", _("Currently active policy:")); if(current >= 0 && file_name) { char * full_name = NULL; error = oyPolicyFileNameGet_( names[current], &full_name, oyAllocateFunc_ ); if(internal_name) fprintf(stdout, "%s (%s)\n", names[current], full_name); else fprintf(stdout, "%s\n", full_name); oyFree_m_( full_name ); } else fprintf( stdout, "%s\n", current>=0?names[current]:"---"); } if(list_paths) { char ** path_names = oyDataPathsGet_( &count, "color/settings", oyALL, oySCOPE_USER_SYS, oyAllocateFunc_ ); fprintf(stdout, "%s:\n", _("Policy search paths")); for(i = 0; i < count; ++i) fprintf(stdout, "%s\n", path_names[i]); oyStringListRelease_(&path_names, count, oyDeAllocateFunc_); } } else if(dump_policy) { size = 0; xml = oyPolicyToXML( oyGROUP_ALL, 1, oyAllocateFunc_ ); DBG_PROG2_S("%s:%d new policy:\n\n",__FILE__,__LINE__); fprintf(stdout, "%s\n", xml); if(xml) oyDeAllocateFunc_( xml ); } else if(long_help) { const char * opts[] = {"add_html_header","1", "add_oyranos_title","1", "add_oyranos_copyright","1", NULL}; size = 0; xml = oyDescriptionToHTML( oyGROUP_ALL, opts, oyAllocateFunc_ ); fprintf(stdout, "%s\n", xml); if(xml) oyDeAllocateFunc_( xml ); } oyFinish_( FINISH_IGNORE_I18N | FINISH_IGNORE_CACHES ); return error; }
int main( int argc , char** argv ) { int error = 0; int flags = OY_NO_REPAIR, list_tags = 0, list_hash = 0, tag_pos = -1, remove_tag = 0, dump_openicc_json = 0, dump_chromaticities = 0, verbose = 0; const char * file_name = 0, * profile_desc = 0, * tag_name = 0, * name_space = 0, * json_name = 0, * format = "openicc", * profile_name = 0; const char * prefixes[24] = {0}; int pn = 0; const char * device_class = "unknown"; int read_stdin = 0; oyProfile_s * p; oyProfileTag_s * tag; int simple = 0; #ifdef USE_GETTEXT setlocale(LC_ALL,""); #endif oyExportStart_(EXPORT_CHECK_NO); if(argc >= 2) { int pos = 1; unsigned i; char *wrong_arg = 0; DBG_PROG1_S("argc: %d\n", argc); while(pos < argc) { switch(argv[pos][0]) { case '-': for(i = 1; pos < argc && i < strlen(argv[pos]); ++i) switch (argv[pos][i]) { case '2': flags |= OY_ICC_VERSION_2; break; case '4': flags |= OY_ICC_VERSION_4; break; case 'c': OY_PARSE_STRING_ARG(device_class); break; case 'f': OY_PARSE_STRING_ARG(format); break; case 'i': read_stdin = 1; break; case 'j': OY_PARSE_STRING_ARG(json_name); break; case 'l': list_tags = 1; break; case 'm': list_hash = 1; break; case 'n': OY_PARSE_STRING_ARG(tag_name); break; case 'o': dump_openicc_json = 1; break; case 'p': OY_PARSE_INT_ARG( tag_pos ); break; case 'r': OY_PARSE_INT_ARG( tag_pos ); remove_tag = 1; break; case 's': OY_PARSE_STRING_ARG(name_space); if(name_space) { int n = pn - 1, found = 0; while(n >= 0) if(strcmp( prefixes[n--], name_space ) == 0) found = 1; if( !found ) prefixes[pn++] = name_space; } break; case 'v': if(!verbose) verbose = 1; else oy_debug += 1; break; case 'w': OY_PARSE_STRING_ARG(profile_name); break; case 'h': case '-': if(i == 1) { if(OY_IS_ARG("ppmcie")) { dump_chromaticities = 1; i=100; break; } else if(OY_IS_ARG("path")) { simple = 2; i=100; break;} else if(OY_IS_ARG("short")) { simple = 1; i=100; break;} } OY_FALLTHROUGH default: printfHelp(argc, argv); exit (0); break; } break; default: file_name = argv[pos]; break; } if( wrong_arg ) { fprintf(stderr, "%s %s\n", _("wrong argument to option:"), wrong_arg); printfHelp(argc, argv); exit(1); } ++pos; } } else