Exemplo n.º 1
0
void  printfHelp (int argc, char** argv)
{
  char * version = oyVersionString(1,0);
  char * id = oyVersionString(2,0);
  char * cfg_date =  oyVersionString(3,0);
  char * devel_time = oyVersionString(4,0);

  fprintf( stderr, "\n");
  fprintf( stderr, "oyranos-policy %s\n",
                                _("is a policy administration tool"));
  fprintf( stderr, "  Oyranos v%s config: %s devel period: %s\n",
                  oyNoEmptyName_m_(version),
                  oyNoEmptyName_m_(cfg_date), oyNoEmptyName_m_(devel_time) );
  if(id)
  fprintf( stderr, "  Oyranos git id %s\n", oyNoEmptyName_m_(id) );
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",
                                           _("Hint: search paths are influenced by the XDG_CONFIG_HOME shell variable."));
  fprintf( stderr, "\n");
  fprintf( stderr, "%s\n",                 _("Usage"));
  fprintf( stderr, "  %s\n",               _("Dump out the actual settings:"));
  fprintf( stderr, "      %s -d\n",        argv[0]);
  fprintf( stderr, "  %s\n",               _("Select active policy:"));
  fprintf( stderr, "      %s -i %s\n",     argv[0], _("policy or filename"));
  fprintf( stderr, "  %s\n",               _("List available policies:"));
  fprintf( stderr, "      %s -l [-f] [-e]\n",        argv[0]);
  fprintf( stderr, "  %s\n",               _("Currently active policy:"));
  fprintf( stderr, "      %s -c [-f] [-e]\n",        argv[0]);
  fprintf( stderr, "             -f %s\n", _("full path and file name"));
  fprintf( stderr, "             -e %s\n", _("display name"));
  fprintf( stderr, "  %s\n",               _("List search paths:"));
  fprintf( stderr, "      %s -p\n",        argv[0]);
  fprintf( stderr, "  %s\n",               _("Save to a new policy:"));
  fprintf( stderr, "      %s -s %s [--system-wide]\n",     argv[0], _("policy name"));
  fprintf( stderr, "  %s\n",               _("Print a help text:"));
  fprintf( stderr, "      %s -h\n",        argv[0]);
  fprintf( stderr, "\n");
  fprintf( stderr, "\n");

  if(version) oyDeAllocateFunc_(version);
  if(id) oyDeAllocateFunc_(id);
  if(cfg_date) oyDeAllocateFunc_(cfg_date);
  if(devel_time) oyDeAllocateFunc_(devel_time);
}
Exemplo n.º 2
0
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, &current );

    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;
}
Exemplo n.º 3
0
void  printfHelp (int argc OY_UNUSED, char** argv)
{
  char * version = oyVersionString(1,0);
  char * id = oyVersionString(2,0);
  char * cfg_date =  oyVersionString(3,0);
  char * devel_time = oyVersionString(4,0);

  fprintf( stderr, "\n");
  fprintf( stderr, "oyranos-profile %s\n",
                                _("is a ICC profile information tool"));
  fprintf( stderr, "  Oyranos v%s config: %s devel period: %s\n",
                  oyNoEmptyName_m_(version),
                  oyNoEmptyName_m_(cfg_date), oyNoEmptyName_m_(devel_time) );
  if(id)
  fprintf( stderr, "  Oyranos git id %s\n", oyNoEmptyName_m_(id) );
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",
                                           _("Hint: search paths are influenced by the XDG_CONFIG_HOME shell variable."));
  fprintf( stderr, "\n");
  fprintf( stderr, "%s\n",                 _("Usage"));
  fprintf( stderr, "  %s\n",               _("List included ICC tags:"));
  fprintf( stderr, "      %s -l %s\n",        argv[0], _("ICC_FILE_NAME"));
  fprintf( stderr, "      -p %s\t%s\n",  _("NUMBER"), _("select tag"));
  fprintf( stderr, "      -n %s\t%s\n",  _("NAME"), _("select tag"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Remove included ICC tag:"));
  fprintf( stderr, "      %s -r %s %s\n",     argv[0], _("NUMBER"), _("ICC_FILE_NAME"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Dump Device Infos to OpenICC device JSON:"));
  fprintf( stderr, "      %s -o %s\n",        argv[0], _("ICC_FILE_NAME"));
  fprintf( stderr, "      -c NAME       %s scanner, monitor, printer, camera ...\n",  _("use device class") );
  fprintf( stderr, "      -f xml        %s\n",  _("use IccXML format") );
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Show Profile ID:"));
  fprintf( stderr, "      %s -m %s\n",        argv[0], _("ICC_FILE_NAME"));
  fprintf( stderr, "      -w %s\t%s\n", _("ICC_FILE_NAME"),  _("write profile with correct ID"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Show CIE*xy chromaticities:"));
  fprintf( stderr, "      %s --ppmcie %s\n",        argv[0], _("ICC_FILE_NAME"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Write to ICC profile:"));
  fprintf( stderr, "      %s -w %s [-j %s] %s\n",        argv[0], _("NAME"), _("FILE_NAME"), _("ICC_FILE_NAME"));
  fprintf( stderr, "      -w %s\t%s\n", _("NAME"),  _("use new name"));
  fprintf( stderr, "      -j %s\t%s\n", _("FILE_NAME"),  _("embed OpenICC device JSON from file"));
  fprintf( stderr, "      -s %s\t%s\n", _("NAME"),  _("add prefix"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("Print a help text:"));
  fprintf( stderr, "      %s -h\n",        argv[0]);
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s\n",               _("General options:"));
  fprintf( stderr, "      %s \t%s\n", _("ICC_FILE_NAME"), _("can be file name, internal description string, ICC profile ID or" \
                   " wildcard \"rgb\", \"cmyk\", \"gray\", \"lab\", \"xyz\", \"web\", \"rgbi\", \"cmyki\", \"grayi\", \"labi\", \"xyzi\"." \
                   " Wildcards ending with \"i\" are assumed profiles. \"web\" is a sRGB profile. The other wildcards are editing profiles."));
  fprintf( stderr, "      -v %s\n",        _("verbose"));
  fprintf( stderr, "      -i %s\n",        _("read input stream"));
  fprintf( stderr, "      -2 %s\n",        _("select a ICC v2 profile"));
  fprintf( stderr, "      -4 %s\n",        _("select a ICC v4 profile"));
  fprintf( stderr, "      --short %s\n",   _("print only the file name"));
  fprintf( stderr, "      --path %s\n",    _("print the full file name"));
  fprintf( stderr, "\n");
  fprintf( stderr, "  %s:\n",               _("Example"));
  fprintf( stderr, "      oyranos-profile -lv -p=1 sRGB.icc\n");
  fprintf( stderr, "      oyranos-profile -w test -j test.json sRGB.icc\n");
  fprintf( stderr, "      oyranos-profile -mv sRGB.icc\n");
  fprintf( stderr, "      ppmcie `oyranos-profile --ppmcie sRGB.icc` > sRGB-cie-xy.ppm\n");
  fprintf( stderr, "    %s:\n", _("Count all profiles with Lab PCS"));
  fprintf( stderr, "      LANG=en_GB; n=0; SAVEIFS=$IFS ; IFS=$'\\n\\b'; profiles=(`oyranos-profiles -ldf`); IFS=$SAVEIFS; for file in \"${profiles[@]}\"; do if [ \"`oyranos-profile -l \"$file\" | grep -a \"PCS Color Space:  Lab\"`\" != \"\" ]; then n=$((n+1)); fi; done; echo PCS-CIE*Lab: $n\n");
  fprintf( stderr, "\n");
                        printf(_("For more information read the man page:"));
                        printf("\n");
                        printf("      man oyranos-profile\n");

  if(version) oyDeAllocateFunc_(version);
  if(id) oyDeAllocateFunc_(id);
  if(cfg_date) oyDeAllocateFunc_(cfg_date);
  if(devel_time) oyDeAllocateFunc_(devel_time);
}