示例#1
0
size_t
oyReadFileSize_(const char* name)
{
  FILE *fp = 0;
  const char* filename = name;
  size_t size = 0;

  DBG_MEM_START

  {
    fp = fopen(filename, "rb");
    DBG_MEM2_S ("fp = %d filename = %s\n", (int)(intptr_t)fp, filename)

    if (fp)
    {
      /* get size */
      fseek(fp,0L,SEEK_END); 
      {
        int sz = ftell (fp);
        if(sz == -1)
        {
          switch(errno)
          {
            case EBADF:        WARNc1_S("Not a seekable stream: %s", name); break;
            case EINVAL:       WARNc1_S("Wrong argument: %s", name); break;
            default:           WARNc2_S("%s: %s", strerror(errno), name); break;
          }
        } else
          size = sz;
      }
      fclose (fp);

    } else
      WARNc2_S( "%s: %s", _("Could not open profile"), filename );
  }

  DBG_MEM_ENDE
  return size;
}
示例#2
0
/** @internal
 *  Function oyFilterGraph_New_
 *  @memberof oyFilterGraph_s_
 *  @brief   allocate a new oyFilterGraph_s_  object
 *
 *  @version Oyranos: 
 *  @since   2010/04/26 (Oyranos: 0.1.10)
 *  @date    2010/04/26
 */
oyFilterGraph_s_ * oyFilterGraph_New_ ( oyObject_s object )
{
  /* ---- start of common object constructor ----- */
  oyOBJECT_e type = oyOBJECT_FILTER_GRAPH_S;
  int error = 0;
  oyObject_s    s_obj = oyObject_NewFrom( object );
  oyFilterGraph_s_ * s = 0;

  if(s_obj)
    s = (oyFilterGraph_s_*)s_obj->allocateFunc_(sizeof(oyFilterGraph_s_));
  else
  {
    WARNc_S(_("MEM Error."));
    return NULL;
  }

  if(!s)
  {
    if(s_obj)
      oyObject_Release( &s_obj );
    WARNc_S(_("MEM Error."));
    return NULL;
  }

  error = !memset( s, 0, sizeof(oyFilterGraph_s_) );
  if(error)
    WARNc_S( "memset failed" );

  memcpy( s, &type, sizeof(oyOBJECT_e) );
  s->copy = (oyStruct_Copy_f) oyFilterGraph_Copy;
  s->release = (oyStruct_Release_f) oyFilterGraph_Release;

  s->oy_ = s_obj;

  
  /* ---- start of custom FilterGraph constructor ----- */
  error += !oyObject_SetParent( s_obj, oyOBJECT_FILTER_GRAPH_S, (oyPointer)s );
  /* ---- end of custom FilterGraph constructor ------- */
  
  
  
  
  /* ---- end of common object constructor ------- */
  if(error)
    WARNc_S( "oyObject_SetParent failed" );


  
  

  
  /* ---- start of custom FilterGraph constructor ----- */
  error += oyFilterGraph_Init__Members( s );
  /* ---- end of custom FilterGraph constructor ------- */
  
  
  
  

  if(!oy_filtergraph_init_)
  {
    oy_filtergraph_init_ = 1;
    oyStruct_RegisterStaticMessageFunc( type,
                                        oyFilterGraph_StaticMessageFunc_ );
  }

  if(error)
    WARNc1_S("%d", error);

  if(oy_debug_objects >= 0)
    oyObject_GetId( s->oy_ );

  return s;
}
/** Function  oyFilterNode_GetConnectorPos
 *  @memberof oyFilterNode_s
 *  @brief    Get a oyFilterSocket_s or oyFilterPlug_s position from a FilterNode
 *
 *  @param         node                filter node
 *  @param         is_input            1 - plugs; 0 - sockets
 *  @param         pattern             the pattern to be found in the
 *                                     oyConnector_s::connector_type of the
 *                                     searched plug or socket. Its a
 *                                     @ref registration string. E.g. a typical
 *                                     data connection: "//" OY_TYPE_STD "/data"
 *  @param         nth_of_type         the position in the group of the
 *                                     connector type for this filter; Note
 *                                     this parameter makes only sense for the
 *                                     last filter defined connector, as only
 *                                     this one can occure multiple times.
 *  @param         flags               specify which status to return
 *                                     - zero means: take all into account
 *                                     - ::OY_FILTEREDGE_FREE: next free available
 *                                     - ::OY_FILTEREDGE_CONNECTED: consider used
 *  @return                            the absolute position
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/02/26 (Oyranos: 0.1.10)
 *  @date    2009/11/02
 */
OYAPI int  OYEXPORT
               oyFilterNode_GetConnectorPos (
                                       oyFilterNode_s    * node,
                                       int                 is_input,
                                       const char        * pattern,
                                       int                 nth_of_type,
                                       int                 flags )
{
  oyFilterNode_s_ * s = (oyFilterNode_s_*)node;
  int pos = -1,
      i, j, n, n2,
      nth = -1;

  oyCheckType__m( oyOBJECT_FILTER_NODE_S, return pos )

  if(!pattern)
  {
    WARNc1_S("no ID argument given %s", s->relatives_ );
    return pos;
  }

  if(nth_of_type == -1)
    nth_of_type = 0;

  /* plugs */
  if(is_input)
  {
    n = s->api7_->plugs_n;
    for( i = 0; i < n; ++i )
    {
      if(oyFilterRegistrationMatch( oyConnector_GetReg(s->api7_->plugs[i]),
                                    pattern, 0))
      {
        if( i == n - 1 && s->api7_->plugs_last_add)
          n2 = s->api7_->plugs_last_add;
        else
          n2 = 0;

        for( j = 0; j <= n2; ++j )
        {
          if(oyToFilterEdge_Free_m(flags))
          {
            if( s->plugs[i + j] && s->plugs[i + j]->remote_socket_ )
              continue;
            else
              ++nth;

          } else
          if(oyToFilterEdge_Connected_m(flags))
          {
            if( s->plugs[i + j] && s->plugs[i + j]->remote_socket_ )
              ++nth;
            else
              continue;

          } else
            ++nth;

          if( nth == nth_of_type )
          {
            pos = i + j;
            return pos;
          }
        }
      }
    }
  } else
  /* ... or sockets */
  {
    /* 1. count possible connectors */
    n = s->api7_->sockets_n;
    for( i = 0; i < n; ++i )
    {
      /* 2. compare pattern argument with the socket type */
      if(oyFilterRegistrationMatch( oyConnector_GetReg(s->api7_->sockets[i]),
                                    pattern, 0))
      {

        /* 3. iterate through at least connectors or connectors that where added
              to the last one */
        if( i == n - 1 && s->api7_->sockets_last_add)
          n2 = s->api7_->sockets_last_add;
        else
          n2 = 0;

        for( j = 0; j <= n2; ++j )
        {
          /* 3.1 check only unused connectors */
          if(oyToFilterEdge_Free_m(flags))
          {
            if( s->sockets[i + j] &&
                oyFilterPlugs_Count( s->sockets[i + j]->requesting_plugs_ ) )
              continue;
            else
              ++nth;

          } else
          /* 3.2 check only used connectors */
          if(oyToFilterEdge_Connected_m(flags))
          {
            if( s->sockets[i + j] &&
                oyFilterPlugs_Count( s->sockets[i + j]->requesting_plugs_ ) )
              ++nth;
            else
              continue;

          } else
          /* 3.3 count all connectors */
            ++nth;

          /* 4. check the type relative positional parameter */
          if( nth == nth_of_type )
          {
            /* 4.1 return as we otherwise would need to leave two loops */
            pos = i + j;
            return pos;
          }
        }
      }
    }
  }

  return pos;
}
示例#4
0
/** @internal
 *  Function oyOption_New_
 *  @memberof oyOption_s_
 *  @brief   allocate a new oyOption_s_  object
 *
 *  @version Oyranos: 
 *  @since   2010/04/26 (Oyranos: 0.1.10)
 *  @date    2010/04/26
 */
oyOption_s_ * oyOption_New_ ( oyObject_s object )
{
  /* ---- start of common object constructor ----- */
  oyOBJECT_e type = oyOBJECT_OPTION_S;
  int error = 0;
  oyObject_s    s_obj = oyObject_NewFrom( object );
  oyOption_s_ * s = 0;

  if(s_obj)
    s = (oyOption_s_*)s_obj->allocateFunc_(sizeof(oyOption_s_));

  if(!s || !s_obj)
  {
    WARNc_S(_("MEM Error."));
    return NULL;
  }

  error = !memset( s, 0, sizeof(oyOption_s_) );
  if(error)
    WARNc_S( "memset failed" );

  memcpy( s, &type, sizeof(oyOBJECT_e) );
  s->copy = (oyStruct_Copy_f) oyOption_Copy;
  s->release = (oyStruct_Release_f) oyOption_Release;

  s->oy_ = s_obj;

  
  /* ---- start of custom Option constructor ----- */
  error += !oyObject_SetParent( s_obj, oyOBJECT_OPTION_S, (oyPointer)s );
  /* ---- end of custom Option constructor ------- */
  
  
  
  
  /* ---- end of common object constructor ------- */
  if(error)
    WARNc_S( "oyObject_SetParent failed" );


  
  

  
  /* ---- start of custom Option constructor ----- */
  error += oyOption_Init__Members( s );
  /* ---- end of custom Option constructor ------- */
  
  
  
  

  if(!oy_option_init_)
  {
    oy_option_init_ = 1;
    oyStruct_RegisterStaticMessageFunc( type,
                                        oyOption_StaticMessageFunc_ );
  }

  if(error)
    WARNc1_S("%d", error);

  if(oy_debug)
    oyObject_GetId( s->oy_ );

  return s;
}
示例#5
0
char *       oyReadFilepToMem_       ( FILE              * fp,
                                       size_t            * size,
                                       oyAlloc_f           allocate_func)
{
  char* mem = NULL;

  DBG_MEM_START

  DBG_MEM

  {
    if (fp)
    {
      int sz;
      /* get size */
      fseek(fp,0L,SEEK_END); 
      sz = ftell (fp);
      if(sz == -1)
      {
        switch(errno)
        {
          case EBADF:        WARNc_S("Not a seekable stream"); break;
          case EINVAL:       WARNc_S("Wrong argument"); break;
          default:           WARNc1_S("%s", strerror(errno)); break;
        }
        *size = 0;
        return NULL;
      }
      /* read file possibly partitial */
      if(!*size || *size > (size_t)ftell(fp))
        *size = sz;
      rewind(fp);

      DBG_MEM1_S("%u\n",((unsigned int)((size_t)size)));

      if(!*size)
        return mem;

      /* allocate memory */
      oyAllocHelper_m_( mem, char, *size+1, oyAllocateFunc_, return 0);

      /* check and read */
      if ((fp != 0)
       && mem
       && *size)
      {
        int s = fread(mem, sizeof(char), *size, fp);

        DBG_MEM

        /* check again */
        if ((size_t)s != *size)
        { *size = 0;
          oyFree_m_ (mem)
          mem = 0;
        } else {
          mem = oyReAllocFromStdMalloc_( mem, size, allocate_func );
        }
      }
    }
  }