コード例 #1
0
char *GetCommand( char *s, char **t )
{
  char *s2;
  int quoted = 0;
  s = LYSkipBlanks( s );
  s2 = malloc( ( ( strlen( s ) * 2 ) + 1 ) * sizeof( char ) );
  if ( s2 == 0 )
  {
    ExitWithError( gettext( "Memory exhausted!  Program aborted!" ) );
  }
  t[0] = s2;
  while ( s && s[0] )
  {
    if ( quoted )
    {
      if ( s[0] == '%' )
      {
        s2[0] = '%';
        s2++;
      }
      s2[0] = s[0];
      s2++;
      s++;
      quoted = 0;
    }
    else
    if ( s[0] == ';' )
    {
      s2[0] = 0;
      s++;
      return s;
    }
    if ( s[0] == '\\' )
    {
      quoted = 1;
      s++;
    }
    else
    {
      s2[0] = s[0];
      s2++;
      s++;
    }
  }
  s2[0] = 0;
  return 0;
}
コード例 #2
0
int ProcessMailcapEntry( FILE *fp, struct MailcapEntry *mc, AcceptMedia media )
{
  size_t rawentryalloc = 2000;
  size_t len;
  size_t need;
  char *rawentry, *s, *t;
  char *LineBuf = 0;
  rawentry = malloc( ( rawentryalloc ) * sizeof( char ) );
  if ( rawentry == 0 )
  {
    ExitWithError( gettext( "Memory exhausted!  Program aborted!" ) );
  }
  rawentry[0] = 0;
  while ( LYSafeGets( &LineBuf, fp ) == 0 )
  {
    LYTrimNewline( LineBuf );
    if ( LineBuf[0] != '#' && LineBuf[0] )
    {
      len = strlen( LineBuf );
      need = len + strlen( rawentry ) + 1;
      if ( rawentryalloc < need )
      {
        rawentryalloc = rawentryalloc + need + 2000;
        rawentry = realloc( rawentry, ( rawentryalloc ) * sizeof( char ) );
        if ( rawentry == 0 )
        {
          ExitWithError( gettext( "Memory exhausted!  Program aborted!" ) );
        }
      }
      if ( len && LineBuf[ len + -1 ] == '\\' )
      {
        LineBuf[ len + -1 ] = 0;
        strcat( rawentry, LineBuf );
      }
      else
      {
        strcat( rawentry, LineBuf );
        break;
      }
    }
  }
  if ( LineBuf )
  {
    free( LineBuf );
    LineBuf = 0;
  }
  t = s = LYSkipBlanks( rawentry );
  if ( s[0] == 0 )
  {
    if ( rawentry )
    {
      free( rawentry );
      rawentry = 0;
    }
    return 0;
  }
  else
  {
    s = strchr( rawentry, ';' );
    if ( s == 0 )
    {
      if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
      {
        fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring invalid mailcap entry: %s\n", rawentry );
      }
      if ( rawentry )
      {
        free( rawentry );
        rawentry = 0;
      }
      return 0;
    }
    else
    {
      s[0] = 0;
      s++;
      if ( strncasecomp( t, "text/html", 9 ) == 0 || strncasecomp( t, "text/plain", 10 ) == 0 )
      {
        s = &s[ -1 ];
        s[0] = ';';
        if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
        {
          fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring mailcap entry: %s\n", rawentry );
        }
        if ( rawentry )
        {
          free( rawentry );
          rawentry = 0;
        }
        return 0;
      }
      else
      {
        LYRemoveBlanks( rawentry );
        LYLowerCase( rawentry );
        *(int*)&mc->needsterminal = 0;
        *(int*)&mc->copiousoutput = 0;
        *(int*)&mc->needtofree = 1;
        *(int*)&mc->testcommand = 0;
        *(int*)&mc->label = 0;
        *(int*)&mc->printcommand = 0;
        *(int*)&mc->contenttype[0] = 0;
        HTSACopy( &mc->contenttype, rawentry );
        *(int*)&mc->quality = 0x3f800000;
        *(int*)&mc->maxbytes = 0;
        t = GetCommand( s, &mc->command );
        if ( t )
        {
          s = LYSkipBlanks( t );
          for ( ; s;  )
          {
            char *arg, *eq, *mallocd_string;
            t = GetCommand( s, &mallocd_string );
            arg = mallocd_string;
            eq = strchr( arg, '=' );
            if ( eq )
            {
              eq[0] = 0;
              eq++;
              eq = LYSkipBlanks( eq );
            }
            if ( arg && arg[0] )
            {
              arg = Cleanse( arg );
              if ( strcmp( arg, "needsterminal" ) == 0 )
                *(int*)&mc->needsterminal = 1;
              else
              {
                if ( strcmp( arg, "copiousoutput" ) == 0 )
                  *(int*)&mc->copiousoutput = 1;
                else
                if ( eq && strcmp( arg, "test" ) == 0 )
                {
                  *(int*)&mc->testcommand = 0;
                  HTSACopy( &mc->testcommand, eq );
                  TrimCommand( &mc->testcommand );
                  if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
                  {
                    fprintf( TraceFP( ), "ProcessMailcapEntry: Found testcommand:%s\n", &mc->testcommand );
                  }
                }
                else
                if ( eq && strcmp( arg, "description" ) == 0 )
                  mc->label = eq;
                else
                if ( eq && strcmp( arg, "label" ) == 0 )
                  mc->label = eq;
                else
                if ( eq && strcmp( arg, "print" ) == 0 )
                  mc->printcommand = eq;
                else
                if ( eq == 0 || strcmp( arg, "textualnewlines" ) )
                {
                  if ( eq && strcmp( arg, "q" ) == 0 )
                  {
                    mc->quality = atof( eq );
                    if ( mc->quality > 0 && mc->quality < 0.001000000000 )
                      *(int*)&mc->quality = 0x3a83126f;
                  }
                  else
                  if ( eq && strcmp( arg, "mxb" ) == 0 )
                  {
                    mc->maxbytes = atol( eq );
                    if ( mc->maxbytes < 0 )
                      *(int*)&mc->maxbytes = 0;
                  }
                  else
                  {
                    if ( strcmp( arg, "notes" ) && arg[0] && WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
                    {
                      fprintf( TraceFP( ), "ProcessMailcapEntry: Ignoring mailcap flag '%s'.\n", arg );
                    }
                  }
                }
              }
            }
            if ( mallocd_string )
            {
              free( mallocd_string );
              mallocd_string = 0;
            }
            s = t;
          }
        }
        if ( rawentry )
        {
          free( rawentry );
          rawentry = 0;
        }
        if ( PassesTest( mc ) )
        {
          if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
          {
            fprintf( TraceFP( ), "ProcessMailcapEntry Setting up conversion %s : %s\n", &mc->contenttype[0], &mc->command );
          }
          HTSetPresentation( &mc->contenttype[0], &mc->command, &mc->testcommand, mc->quality, 3.000000000000, 0.000000000000, mc->maxbytes, media );
        }
        if ( mc->command )
        {
          free( &mc->command );
          *(int*)&mc->command = 0;
        }
        if ( mc->testcommand )
        {
          free( &mc->testcommand );
          *(int*)&mc->testcommand = 0;
        }
        if ( mc->contenttype[0] )
        {
          free( &mc->contenttype[0] );
          *(int*)&mc->contenttype[0] = 0;
        }
        return 1;
      }
    }
  }
}
コード例 #3
0
void read_rc( FILE *fp )
{
  char *buffer = 0;
  char rcfile[256];
  char MBM_line[256];
  int n;
  if ( fp == 0 )
  {
    LYAddPathToHome( rcfile, 256, ".lynxrc" );
    fp = fopen64( rcfile, "r" );
    if ( fp )
    {
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "read_rc opened %s\n", rcfile );
        while ( LYSafeGets( &buffer, fp ) == 0 )
        {
          char *name, *value, *notes;
          Config_Type *tbl;
          ParseUnion *q;
          LYTrimTrailing( buffer );
          name = LYSkipBlanks( buffer );
          if ( !( *(short*)(*(int*)(__ctype_b_loc( )) + ( name[0] * 2 )) & 4 ) && name[0] )
          {
            value = strchr( name, '=' );
            if ( value == 0 )
            {
              if ( WWW_TraceFlag )
              {
                fprintf( TraceFP( ), "LYrcFile: missing '=' %s\n", name );
              }
            }
            else
            {
              value[0] = 0;
              value++;
              LYTrimTrailing( name );
              value = LYSkipBlanks( value );
              if ( WWW_TraceFlag && ( WWW_TraceMask & 8 ) )
              {
                fprintf( TraceFP( ), "LYrcFile %s:%s\n", name, value );
              }
              tbl = lookup_config( name );
              if ( tbl->name[0] == 0 )
              {
                char *special = "multi_bookmark";
                if ( strncasecomp( name, special, strlen( special ) ) == 0 )
                {
                  tbl = lookup_config( special );
                }
                if ( tbl->name[0] == 0 )
                {
                  if ( WWW_TraceFlag )
                  {
                    fprintf( TraceFP( ), "LYrcFile: ignored %s=%s\n", name, value );
                  }
                }
              }
              q = &tbl->value;
              switch ( tbl->type )
              {
              case 0:
                break;
              case 2:
                if ( q->add_value[0] )
                {
                  q->override_primary_action = getBool( value );
                }
                break;
              case 3:
                if ( q->add_value[0] )
                {
                  ;
                }
                break;
              case 1:
                n = 0;
                for ( ; tbl->strings[ n ]; n++ )
                {
                  if ( strcasecomp( value, &tbl->strings[ n ] ) == 0 )
                  {
                    q->add_value = &n;
                  }
                  else
                  {
                    // n++;
                  }
                }
                break;
              case 5:
                if ( tbl->table )
                {
                  LYgetEnum( &tbl->table, value, (int*)q->add_value[0] );
                }
                break;
              case 4:
                if ( q->add_value[0] && sscanf( value, value, "%d", ival ) == 1 )
                {
                  q->add_value = &ival;
                }
                break;
              case 6:
                if ( q->add_value[0] )
                {
                  if ( q->add_value )
                    HTSACat( (int)( &q->add_value[0]->next ), "," );
                  HTSACat( (int)( &q->add_value[0]->next ), value );
                }
                break;
              case 7:
                n = 1;
                for ( ; n <= 25; n++ )
                {
                  sprintf( MBM_line, "multi_bookmark%c", LYindex2MBM( n ) );
                  if ( strcasecomp( name, MBM_line ) == 0 )
                  {
                    notes = strchr( value, ',' );
                    if ( notes )
                    {
                      notes = 0;
                      notes++;
                      LYTrimTrailing( value );
                      notes = LYSkipBlanks( notes );
                    }
                    else
                    {
                      notes = value + strlen( value );
                    }
                    HTSACopy( &MBM_A_subbookmark[ n ], value );
                    HTSACopy( &MBM_A_subdescript[ n ], notes );
                  }
                  else
                  {
                    // n++;
                  }
                }
                break;
              case 8:
                if ( q->add_value[0] )
                {
                  HTSACopy( (int)( &q->add_value[0]->next ), value );
                }
                break;
              }
            }
          }
        }
      }
    }
  }
  else
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "read_rc used passed-in stream\n" );
  }
  return;
}