Exemple #1
0
char *Cleanse( char *s )
{
  LYTrimLeading( s );
  LYTrimTrailing( s );
  LYLowerCase( s );
  return s;
}
Exemple #2
0
void TrimCommand( char *command )
{
  LYTrimTrailing( command );
{
  char *s = command;
  char *d = command;
  int ch;
  int c0 = 32;
  BOOLEAN escape = 0;
  BOOLEAN dquote = 0;
  BOOLEAN squote = 0;
  while ( ch = s[0], s++, ( ch != 0 ) & 255 )
  {
    if ( escape )
      escape = 0;
    else
    if ( squote )
    {
      if ( ch == 39 )
        squote = 0;
    }
    else
    if ( dquote )
    {
      if ( ch == 34 )
        dquote = 0;
    }
    else
    {
      switch ( ch )
      {
      case '"':
        dquote = 1;
        break;
      case '\'':
        squote = 1;
        break;
      case '\\':
        if ( dquote )
          escape = 1;
        break;
      }
    }
    if ( escape == 0 && dquote == 0 && squote == 0 )
    {
      if ( ch == 9 )
        ch = 32;
      if ( ch != 32 || c0 != 32 )
        goto B22;
    }
B22:;
    d[0] = ch;
    d++;
    c0 = ch;
  }
  *ebp_12 = 0;
  return;
}
}
Exemple #3
0
BOOLEAN lookup_reject( char *target )
{
  FILE *ifp;
  char *buffer = 0;
  char *line = 0;
  int len;
  int result = 0;
  ifp = fopen64( "reject.dat", "r" );
  if ( ifp == 0 )
  {
  }
  HTSprintf0( &line, "%s", target );
  while ( LYSafeGets( &buffer, ifp ) && result == 0 )
  {
    LYTrimTrailing( buffer );
    len = strlen( buffer );
    if ( len > 0 )
    {
      if ( buffer[ len + -1 ] == '*' )
      {
        if ( len != 1 && strncmp( line, buffer, len + -1 ) )
          continue;
        else
        {
          result = 1;
        }
      }
      else
      {
        if ( strcmp( line, buffer ) )
          continue;
        else
        {
          result = 1;
        }
      }
    }
  }
  if ( buffer )
  {
    free( buffer );
    buffer = 0;
  }
  if ( line )
  {
    free( line );
    line = 0;
  }
  LYCloseInput( ifp );
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "lookup_reject(%s) -> %d\n", target, result );
  }
  return (unsigned char)( result );
}
Exemple #4
0
BOOLEAN setup( char *terminal )
{
  char *term_putenv = 0;
  char *buffer = 0;
  char *cp = LYgetXDisplay( );
  if ( cp )
    HTSACopy( &x_display, cp );
  else
  if ( x_display )
  {
    free( x_display );
    x_display = 0;
  }
  if ( terminal )
  {
    HTSprintf0( &term_putenv, "TERM=%.106s", terminal );
    putenv( term_putenv );
  }
  if ( dumbterm( LYGetEnv( "TERM" ) ) )
  {
    printf( "\n\n  %s\n\n", gettext( "Your Terminal type is unknown!" ) );
    printf( "  %s [vt100] ", gettext( "Enter a terminal type:" ) );
    if ( LYSafeGets( &buffer, stdin ) )
    {
      LYTrimLeading( buffer );
      LYTrimTrailing( buffer );
    }
    if ( buffer == 0 || buffer[0] == 0 )
      HTSACopy( &buffer, "vt100" );
    HTSprintf0( &term_putenv, "TERM=%.106s", buffer );
    if ( buffer )
    {
      free( buffer );
      buffer = 0;
    }
    putenv( term_putenv );
    printf( "\n%s %s\n", gettext( "TERMINAL TYPE IS SET TO" ), LYGetEnv( "TERM" ) );
    LYSleepMsg( );
  }
  start_curses( );
  if ( strncmp( ttytype, "sun", 3 ) == 0 )
    LYnoVideo( 2 );
  LYlines = LYscreenHeight( );
  LYcols = LYscreenWidth( );
  return 1;
}
Exemple #5
0
int enable_lynxrc( char *value )
{
  Config_Type *tbl;
  char *colon = strchr( value, ebp_20 );
  if ( colon )
  {
    colon[0] = 0;
    colon++;
    LYTrimLeading( value );
    LYTrimTrailing( value );
    tbl = Config_Table;
    for ( ; tbl->name[0]; tbl++ )
    {
      if ( strcasecomp( value, &tbl->name[0] ) == 0 )
      {
        tbl->enabled = getBool( colon );
        break;
      }
      // tbl++;
    }
  }
  return 0;
}
/*
 * This procedure outputs the Visited Links list into a temporary file.  - FM
 * Returns links's number to make active (1-based), or 0 if not required.
 */
int LYShowVisitedLinks(char **newfile)
{
    static char tempfile[LY_MAXPATH] = "\0";
    char *Title = NULL;
    char *Address = NULL;
    int x, tot;
    FILE *fp0;
    VisitedLink *vl;
    HTList *cur = Visited_Links;
    int offset;
    int ret = 0;
    const char *arrow, *post_arrow;

    if (!cur)
	return (-1);

    if ((fp0 = InternalPageFP(tempfile, TRUE)) == 0)
	return (-1);

    LYLocalFileToURL(newfile, tempfile);
    LYRegisterUIPage(*newfile, UIP_VLINKS);

    LYforce_HTML_mode = TRUE;	/* force this file to be HTML */
    LYforce_no_cache = TRUE;	/* force this file to be new */

    BeginInternalPage(fp0, VISITED_LINKS_TITLE, VISITED_LINKS_HELP);

#ifndef NO_OPTION_FORMS
    fprintf(fp0, "<form action=\"%s\" method=\"post\">\n", STR_LYNXOPTIONS);
    LYMenuVisitedLinks(fp0, FALSE);
    fprintf(fp0, "<input type=\"submit\" value=\"Accept Changes\">\n");
    fprintf(fp0, "</form>\n");
    fprintf(fp0, "<P>\n");
#endif

    fprintf(fp0, "<pre>\n");
    fprintf(fp0, "<em>%s</em>\n",
	    gettext("You visited (POSTs, bookmark, menu and list files excluded):"));
    if (Visited_Links_As & VISITED_LINKS_REVERSE)
	tot = x = HTList_count(Visited_Links);
    else
	tot = x = -1;

    if (Visited_Links_As & VISITED_LINKS_AS_TREE) {
	vl = First_tree;
    } else if (Visited_Links_As & VISITED_LINKS_AS_LATEST) {
	if (Visited_Links_As & VISITED_LINKS_REVERSE)
	    vl = Latest_last.prev_latest;
	else
	    vl = Latest_first.next_latest;
	if (vl == &Latest_last || vl == &Latest_first)
	    vl = NULL;
    } else {
	if (Visited_Links_As & VISITED_LINKS_REVERSE)
	    vl = Last_by_first;
	else
	    vl = (VisitedLink *) HTList_nextObject(cur);
    }
    while (NULL != vl) {
	/*
	 * The number of the document (most recent highest), its title in a
	 * link, and its address.  - FM
	 */
	post_arrow = arrow = "";
	if (Visited_Links_As & VISITED_LINKS_REVERSE)
	    x--;
	else
	    x++;
	if (vl == PrevActiveVisitedLink) {
	    if (Visited_Links_As & VISITED_LINKS_REVERSE)
		ret = tot - x + 2;
	    else
		ret = x + 3;
	}
	if (vl == PrevActiveVisitedLink) {
	    post_arrow = "<A NAME=current></A>";
	    /* Otherwise levels 0 and 1 look the same when with arrow: */
	    arrow = (vl->level && (Visited_Links_As & VISITED_LINKS_AS_TREE))
		? "==>" : "=>";
	    StrAllocCat(*newfile, "#current");
	}
	if (Visited_Links_As & VISITED_LINKS_AS_TREE) {
	    offset = 2 * vl->level;
	    if (offset > 24)
		offset = (offset + 24) / 2;
	    if (offset > LYcols * 3 / 4)
		offset = LYcols * 3 / 4;
	} else
	    offset = (x > 99 ? 0 : x < 10 ? 2 : 1);
	if (non_empty(vl->title)) {
	    StrAllocCopy(Title, vl->title);
	    LYEntify(&Title, TRUE);
	    LYTrimLeading(Title);
	    LYTrimTrailing(Title);
	    if (*Title == '\0')
		StrAllocCopy(Title, NO_TITLE);
	} else {
	    StrAllocCopy(Title, NO_TITLE);
	}
	if (non_empty(vl->address)) {
	    StrAllocCopy(Address, vl->address);
	    LYEntify(&Address, FALSE);
	    fprintf(fp0,
		    "%-*s%s<em>%d</em>. <tab id=t%d><a href=\"%s\">%s</a>\n",
		    offset, arrow, post_arrow,
		    x, x, Address, Title);
	} else {
	    fprintf(fp0,
		    "%-*s%s<em>%d</em>. <tab id=t%d><em>%s</em>\n",
		    offset, arrow, post_arrow,
		    x, x, Title);
	}
	if (Address != NULL) {
	    StrAllocCopy(Address, vl->address);
	    LYEntify(&Address, TRUE);
	}
	fprintf(fp0, "<tab to=t%d>%s\n", x,
		((Address != NULL) ? Address : gettext("(no address)")));
	if (Visited_Links_As & VISITED_LINKS_AS_TREE)
	    vl = vl->next_tree;
	else if (Visited_Links_As & VISITED_LINKS_AS_LATEST) {
	    if (Visited_Links_As & VISITED_LINKS_REVERSE)
		vl = vl->prev_latest;
	    else
		vl = vl->next_latest;
	    if (vl == &Latest_last || vl == &Latest_first)
		vl = NULL;
	} else {
	    if (Visited_Links_As & VISITED_LINKS_REVERSE)
		vl = vl->prev_first;
	    else
		vl = (VisitedLink *) HTList_nextObject(cur);
	}
    }
    fprintf(fp0, "</pre>\n");
    EndInternalPage(fp0);

    LYCloseTempFP(fp0);
    FREE(Title);
    FREE(Address);
    return (ret);
}
/*
 * This procedure outputs the history buffer into a temporary file.
 */
int showhistory(char **newfile)
{
    static char tempfile[LY_MAXPATH] = "\0";
    char *Title = NULL;
    int x = 0;
    FILE *fp0;

    if ((fp0 = InternalPageFP(tempfile, TRUE)) == 0)
	return (-1);

    LYLocalFileToURL(newfile, tempfile);

    LYforce_HTML_mode = TRUE;	/* force this file to be HTML */
    LYforce_no_cache = TRUE;	/* force this file to be new */

    BeginInternalPage(fp0, HISTORY_PAGE_TITLE, HISTORY_PAGE_HELP);

    fprintf(fp0, "<p align=right> <a href=\"%s\">[%s]</a>\n",
	    STR_LYNXMESSAGES, STATUSLINES_TITLE);

    fprintf(fp0, "<pre>\n");

    fprintf(fp0, "<em>%s</em>\n", gettext("You selected:"));
    for (x = nhist + nhist_extra - 1; x >= 0; x--) {
	/*
	 * The number of the document in the hist stack, its title in a link,
	 * and its address.  - FM
	 */
	if (HDOC(x).title != NULL) {
	    StrAllocCopy(Title, HDOC(x).title);
	    LYEntify(&Title, TRUE);
	    LYTrimLeading(Title);
	    LYTrimTrailing(Title);
	    if (*Title == '\0')
		StrAllocCopy(Title, NO_TITLE);
	} else {
	    StrAllocCopy(Title, NO_TITLE);
	}
	fprintf(fp0,
		"%s<em>%d</em>. <tab id=t%d><a href=\"%s%d\">%s</a>\n",
		(x > 99 ? "" : x < 10 ? "  " : " "),
		x, x, STR_LYNXHIST, x, Title);
	if (HDOC(x).address != NULL) {
	    StrAllocCopy(Title, HDOC(x).address);
	    LYEntify(&Title, TRUE);
	} else {
	    StrAllocCopy(Title, gettext("(no address)"));
	}
	if (HDOC(x).internal_link) {
	    if (history[x].intern_seq_start == history[nhist - 1].intern_seq_start)
		StrAllocCat(Title, gettext(" (internal)"));
	    else
		StrAllocCat(Title, gettext(" (was internal)"));
	}
	fprintf(fp0, "<tab to=t%d>%s\n", x, Title);
    }
    fprintf(fp0, "</pre>\n");
    EndInternalPage(fp0);

    LYCloseTempFP(fp0);
    FREE(Title);
    return (0);
}
Exemple #8
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;
}