/** 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; }
/** 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; }
int DeviceAttributes_ ( ppd_file_t * ppd, oyOptions_s * options, oyConfig_s * device, const char * ppd_file_location ) { oyOption_s * o = 0; int error = !device; oyOption_s * value3 = oyOptions_Find( options, "device_context", oyNAME_PATTERN ); const char * device_name = oyConfig_FindString( device, "device_name", 0 ); if(!error) { char * manufacturer= 0, * model=0, * serial=0, * device_settings = 0; const char * system_port = 0, * host = 0; const char * keyword = 0; ppd_attr_t * attrs = 0; int attr_n, i, j; char ** color_key_words = 0, * tmp = 0; int color_key_words_n = 0; if(!device_name && !value3 && !ppd_file_location && !ppd) { message(oyMSG_WARN, (oyStruct_s*)options, _DBG_FORMAT_ "The \"device_name\" and \"device_context\" is\n" " missed to select a appropriate device.", _DBG_ARGS_ ); error = 1; return error; } if(!ppd) { message( oyMSG_DBG, (oyStruct_s*)0, _DBG_FORMAT_ "\n" "No PPD obtained for ", _DBG_ARGS_, device_name ); error = -1; return error; } manufacturer = ppd->manufacturer; model = ppd->modelname; serial = 0; /* Not known at this time. */ system_port = device_name; host = cupsServer(); attrs = ppdFindAttr(ppd, "cupsICCProfile", 0); if(attrs && attrs->text) device_settings = attrs->text; if(error <= 0) { size_t size = 0; char * data = 0; oyConfig_s * d = device; oyRankMap * rank_map = oyRankMapCopy( oyConfig_GetRankMap( device ), oyAllocateFunc_ ); if(!rank_map) rank_map = oyRankMapCopy( _api8.rank_map, oyAllocateFunc_ ); OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), manufacturer ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), model ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), serial ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), system_port ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), host ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), device_settings ) if (value3) { /* open the PPD data */ if(ppd_file_location) { FILE * fp = fopen( ppd_file_location, "r" ); size_t lsize = 0; /* Find the total size. */ fseek(fp , 0, SEEK_END); lsize = ftell(fp); rewind (fp); /* Create buffer to read contents into a profile. */ data = (char*) malloc (sizeof(char)*lsize + 1); if (data == NULL) fputs ("Unable to open PPD size.",stderr); size = fread( data, 1, lsize, fp); data[size] = 0; } if(!error && data && size) { o = oyOption_FromRegistration( CMM_BASE_REG OY_SLASH "device_context.PPD.text", 0 ); error = !o; if(!error) error = oyOption_SetFromData( o, data, size ); if(!error) oyOptions_MoveIn( *oyConfig_GetOptions(device,"data"), &o, -1 ); } } /* Collect all ColorKeyWords. */ attr_n = ppd->num_attrs; for(i = 0; i < attr_n; i++) { char key[16]; keyword = ppd->attrs[i]->name; /* we support keys beginning with ColorKeyWords, e.g. "ColorKeyWords" "ColorKeyWords" ... */ snprintf( &key[0], 16, "%s", keyword ); key[14] = 0; if (strcmp(key, "ColorKeyWords") == 0) { if( tmp && tmp[oyStrlen_(tmp) - 1] != ';' ) STRING_ADD( tmp, ";" ); STRING_ADD( tmp, ppd->attrs[i]->value ); } } if(tmp) { color_key_words = oyStringSplit( tmp, ';', &color_key_words_n, oyAllocateFunc_); oyDeAllocateFunc_( tmp ); tmp = 0; } /* add the key/value pairs to the devices backend_core options. */ for(j = 0; j < color_key_words_n; ++j) { const char * keyword = color_key_words[j], * value = NULL; ppd_choice_t * c = ppdFindMarkedChoice( ppd, keyword ); ppd_option_t * o = ppdFindOption( ppd, keyword ); char * reg_name = 0; /* take the marked choice */ if(c) value = c->choice; /* fall back to a default */ else if(o) value = o->defchoice; else /* Scan PPD attributes for matching the ColorKeyWords and */ for(i = 0; i < attr_n; i++) if(oyStrcmp_( ppd->attrs[i]->name, keyword ) == 0) value = ppd->attrs[i]->value; STRING_ADD( reg_name, CMM_BASE_REG OY_SLASH ); STRING_ADD( reg_name, keyword ); if(value) { error= oyOptions_SetFromText( oyConfig_GetOptions(d,"backend_core"), reg_name, value, OY_CREATE_NEW ); oyRankMapAppend( &rank_map, reg_name, 2, -2, 0, 0,0 ); } if(reg_name) oyDeAllocateFunc_( reg_name ); reg_name = 0; } if( color_key_words && color_key_words_n) oyStringListRelease_( &color_key_words, color_key_words_n, oyDeAllocateFunc_ ); else { ppd_option_t * o; while((o = ppdNextOption(ppd)) != 0) { const char * value = 0; char * reg_name = 0; keyword = o->keyword; STRING_ADD( reg_name, CMM_BASE_REG OY_SLASH ); STRING_ADD( reg_name, keyword ); /* take the marked choice */ for(i = 0; i < o->num_choices; ++i) if(o->choices[i].marked) { value = o->choices[i].choice; break; } if(!value) value = o->defchoice; if(value) { error = oyOptions_SetFromText( oyConfig_GetOptions(d,"backend_core"), reg_name, value, OY_CREATE_NEW ); oyRankMapAppend( &rank_map, reg_name, 2, -2, 0, 0,0 ); } if(reg_name) oyDeAllocateFunc_( reg_name ); reg_name = 0; } } oyConfig_SetRankMap( device, rank_map ); oyRankMapRelease( &rank_map, oyDeAllocateFunc_ ); }
/** 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; }