예제 #1
0
PUBLIC void HTMLSRC_init_caches ARGS1(
	BOOL,	dont_exit)
{
    int i;
    char* p;
    char buf[1000];

    for (i = 0; i < HTL_num_lexemes; ++i) {
	/*we assume that HT_tagspecs was NULLs at when program started*/
	LYstrncpy(buf,
		  HTL_tagspecs[i]
		  ? HTL_tagspecs[i]
		  : HTL_tagspecs_defaults[i],
		  sizeof(buf) - 1);
	StrAllocCopy(HTL_tagspecs[i], buf);

	if ((p = strchr(buf, ':')) != 0)
	    *p = '\0';
	if (html_src_parse_tagspec(buf, i, FALSE, TRUE) && !dont_exit ) {
	    fprintf(stderr, "internal error while caching 1st tagspec of %d lexeme", i);
	    exit_immediately(EXIT_FAILURE);
	}
	if (html_src_parse_tagspec( p ? p+1 : NULL , i, FALSE, FALSE) && !dont_exit) {
	    fprintf(stderr, "internal error while caching 2nd tagspec of %d lexeme", i);
	    exit_immediately(EXIT_FAILURE);
	}
    }
}
예제 #2
0
void failed_init( char *tag, int lexeme )
{
    fprintf( stderr, gettext( "parse-error while caching %s tagspec of lexeme %d\n" ), tag, lexeme );
    fprintf( stderr, gettext( "Use -trace -trace-mask=8 to see details in log.\n" ) );
    exit_immediately( 1 );
    return;
}
예제 #3
0
void append_close_tag( char *tagname, HT_tagspec **head, HT_tagspec **tail )
{
    int idx = html_src_tag_index( tagname ), nattr;
    HTTag *tag = &tags[ idx ];
    HT_tagspec *subj;
    nattr = tag->number_of_attributes;
    if ( idx == -1 )
    {
        fprintf( stderr, "internal error: previous check didn't find bad HTML tag %s", tagname );
        exit_immediately( 1 );
    }
    subj = calloc( 1, sizeof( HT_tagspec ) );
    subj->element = idx;
    subj->present = calloc( nattr, 1 );
    subj->value = calloc( nattr, 4 );
    subj->start = 0;
    subj->class_name = 0;
    if ( head[0] == 0 )
    {
        head[0] = subj;
        tail[0] = subj;
    }
    else
    {
        tail[0] = subj;
        tail[0] = subj;
    }
    return;
}
예제 #4
0
PRIVATE void append_close_tag ARGS3(
	    char*,	  tagname,
	    HT_tagspec**, head,
	    HT_tagspec**, tail)
{
    int idx, nattr;
    HTTag* tag;
    HT_tagspec* subj;

    idx = html_src_tag_index(tagname);
    tag = HTML_dtd.tags+idx;
    nattr = tag->number_of_attributes;

    if (idx == -1) {
	fprintf(stderr,
	"internal error: previous check didn't find bad HTML tag %s", tagname);
	exit_immediately(EXIT_FAILURE);
    }

    subj = typecalloc(HT_tagspec);
    subj->element = idx;
    subj->present = typecallocn(BOOL, nattr);
    subj->value = typecallocn(char *, nattr);
    subj->start = FALSE;
#ifdef USE_COLOR_STYLE
    subj->class_name = NULL;
#endif

    if (!*head) {
	*head = subj; *tail = subj;
    } else {
	(*tail)->next = subj; *tail = subj;
    }
}
예제 #5
0
int ExitWithError( char *txt )
{
  if ( txt )
  {
    fprintf( TraceFP( ), "Lynx: %s\n", txt );
  }
  exit_immediately( 1 );
  return -1;
}
예제 #6
0
static int HTVMSclosedir(DIR *dirp)
{
    long status;

    status = lib$find_file_end(&(dirp->context));
    if (!(status & 0x01))
	exit_immediately(status);
    dirp->context = 0;
    return (0);
}
예제 #7
0
파일: LYMail.c 프로젝트: avsm/openbsd-lynx
/*
**  mailmsg() sends a message to the owner of the file, if one is defined,
**  telling of errors (i.e., link not available).
*/
PUBLIC void mailmsg ARGS4(
	int,		cur,
	char *,		owner_address,
	char *,		filename,
	char *,		linkname)
{
    FILE *fd, *fp;
    char *address = NULL;
    char *searchpart = NULL;
    char *cmd = NULL, *cp;
#ifdef ALERTMAIL
    BOOLEAN skip_parsing = FALSE;
#endif
#if !CAN_PIPE_TO_MAILER
    char *ccaddr;
    char subject[128];
    char my_tmpfile[LY_MAXPATH];
#endif
#if USE_VMS_MAILER
    BOOLEAN isPMDF = LYMailPMDF();
    char hdrfile[LY_MAXPATH];
    char *command = NULL;

    CTRACE((tfp, "mailmsg(%d, \"%s\", \"%s\", \"%s\")\n", cur,
	NONNULL(owner_address),
	NONNULL(filename),
	NONNULL(linkname)));

#endif /* VMS */

    if (!LYSystemMail())
	return;

#ifdef ALERTMAIL
    if (owner_address == NULL) {
	owner_address = ALERTMAIL;
	skip_parsing = TRUE;
    }
#endif

    if (isEmpty(owner_address))
	return;
    if ((cp = (char *)strchr(owner_address,'\n')) != NULL) {
#ifdef ALERTMAIL
	if (skip_parsing)
	    return;		/* invalidly defined - ignore - kw */
#else
	*cp = '\0';
#endif
    }
    if (!strncasecomp(owner_address, "lynx-dev@", 9)) {
	/*
	 *  Silently refuse sending bad link messages to lynx-dev.
	 */
	return;
    }
    StrAllocCopy(address, owner_address);

#ifdef ALERTMAIL
    /*
     *  If we are using a fixed address given by ALERTMAIL, it is
     *  supposed to already be in usable form, without URL-isms like
     *  ?-searchpart and URL-escaping.  So skip some code. - kw
     */
    if (!skip_parsing)
#endif
    {
	/*
	 *	Check for a ?searchpart. - FM
	 */
	if ((cp = strchr(address, '?')) != NULL) {
	    StrAllocCopy(searchpart, cp);
	    *cp = '\0';
	    cp = (searchpart + 1);
	    if (*cp != '\0') {
		/*
		 * Seek and handle to=address(es) fields.
		 * Appends to address.  We ignore any other
		 * headers in the ?searchpart.  - FM
		 */
		extract_field(&address, searchpart, "to=");
	    }
	}

	convert_explorer(address);

	/*
	 *  Unescape the address field. - FM
	 */
	SafeHTUnEscape(address);
    }

    if (trim_comma(address)) {
	FREE(address);
	CTRACE((tfp, "mailmsg: No address in '%s'.\n", owner_address));
	return;
    }

#if CAN_PIPE_TO_MAILER
    if ((fd = LYPipeToMailer()) == 0) {
	FREE(address);
	CTRACE((tfp, "mailmsg: '%s' failed.\n", cmd));
	return;
    }

    fprintf(fd, "To: %s\n", address);
    fprintf(fd, "Subject: Lynx Error in %s\n", filename);
    if (!isEmpty(personal_mail_address)) {
	fprintf(fd, "Cc: %s\n", personal_mail_address);
    }
    fprintf(fd, "X-URL: %s\n", filename);
    fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION);
#else
    if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) {
	CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", my_tmpfile));
	FREE(address);
	return;
    }
    sprintf(subject, "Lynx Error in %.56s", filename);
    ccaddr = personal_mail_address;
#if USE_VMS_MAILER
    if (isPMDF) {
	FILE *hfd;
	if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) {
	    CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", hdrfile));
	    FREE(address);
	    return;
	}

	if (!isEmpty(personal_mail_address)) {
	    fprintf(fd, "Cc: %s\n", personal_mail_address);
	}
	fprintf(fd, "X-URL: %s\n", filename);
	fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION);
	/*
	 *  For PMDF, put the subject in the
	 *  header file and close it. - FM
	 */
	fprintf(hfd, "Subject: Lynx Error in %.56s\n\n", filename);
	LYCloseTempFP(hfd);
    }
#endif /* USE_VMS_MAILER */
#endif /* CAN_PIPE_TO_MAILER */

    fprintf(fd, gettext("The link   %s :?: %s \n"),
		links[cur].lname, links[cur].target);
    fprintf(fd, gettext("called \"%s\"\n"), LYGetHiliteStr(cur, 0));
    fprintf(fd, gettext("in the file \"%s\" called \"%s\"\n"), filename, linkname);
    fprintf(fd, "%s\n\n", gettext("was requested but was not available."));
    fprintf(fd, "%s\n\n", gettext("Thought you might want to know."));

    fprintf(fd, "%s\n", gettext("This message was automatically generated by"));
    fprintf(fd, "%s %s", LYNX_NAME, LYNX_VERSION);
    if ((LynxSigFile != NULL) &&
	(fp = fopen(LynxSigFile, TXT_R)) != NULL) {
	fputs("-- \n", fd);
	while (LYSafeGets(&cmd, fp) != NULL)
	    fputs(cmd, fd);
	LYCloseInput(fp);
    }
#if CAN_PIPE_TO_MAILER
    pclose(fd);
#else
    LYCloseTempFP(fd);
#if USE_VMS_MAILER
    if (isPMDF) {
	/*
	 *  Now set up the command. - FM
	 */
	HTSprintf0(&command,
		"%s %s %s,%s ",
		system_mail,
		system_mail_flags,
		hdrfile,
		my_tmpfile);
    } else {
	/*
	 *  For "generic" VMS MAIL, include the
	 *  subject in the command. - FM
	 */
	HTSprintf0(&command,
		"%s %s/self/subject=\"Lynx Error in %.56s\" %s ",
		system_mail,
		system_mail_flags,
		filename,
		my_tmpfile);
    }
    vms_append_addrs(&command, address, "");

    LYSystem(command);	/* VMS */
    FREE(command);
    FREE(cmd);
    LYRemoveTemp(my_tmpfile);
    if (isPMDF) {
	LYRemoveTemp(hdrfile);
    }
#else /* DOS */
    LYSendMailFile (
	address,
	my_tmpfile,
	subject,
	ccaddr,
	"");
    LYRemoveTemp(my_tmpfile);
#endif /* USE_VMS_MAILER */
#endif /* CAN_PIPE_TO_MAILER */

    if (traversal) {
	FILE *ofp;

	if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) {
	    if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) {
		perror(NOOPEN_TRAV_ERR_FILE);
		exit_immediately(EXIT_FAILURE);
	    }
	}

	fprintf(ofp, "%s\t%s \tin %s\n",
		     links[cur].lname, links[cur].target, filename);
	LYCloseOutput(ofp);
    }

    FREE(address);
    return;
}
예제 #8
0
/*
 * Interrupt handler.  Stop curses and exit gracefully.
 */
void cleanup_sig(int sig)
{
#ifdef IGNORE_CTRL_C
    if (sig == SIGINT) {
	/*
	 * Need to rearm the signal.
	 */
#ifdef DJGPP
	if (wathndlcbrk) {
	    sig_handler_watt(sig);	/* Use WATT-32 signal handler */
	}
#endif /* DJGPP */
	signal(SIGINT, cleanup_sig);
	sigint = TRUE;
#ifdef DJGPP
	_eth_release();
	_eth_init();
#endif /* DJGPP */
	return;
    }
#endif /* IGNORE_CTRL_C */

#ifdef VMS
    if (!dump_output_immediately) {
	int c;

	/*
	 * Reassert the AST.
	 */
	(void) signal(SIGINT, cleanup_sig);
	if (!LYCursesON)
	    return;

	/*
	 * Refresh screen to get rid of "cancel" message, then query.
	 */
	lynx_force_repaint();
	LYrefresh();

	/*
	 * Ask if exit is intended.
	 */
	if (LYQuitDefaultYes == TRUE) {
	    c = HTConfirmDefault(REALLY_EXIT, YES);
	} else {
	    c = HTConfirmDefault(REALLY_EXIT, NO);
	}
	HadVMSInterrupt = TRUE;
	if (LYQuitDefaultYes == TRUE) {
	    if (c == NO) {
		return;
	    }
	} else if (c != YES) {
	    return;
	}
    }
#endif /* VMS */

    /*
     * Ignore further interrupts.  - mhc:  11/2/91
     */
#ifndef NOSIGHUP
    (void) signal(SIGHUP, SIG_IGN);
#endif /* NOSIGHUP */

#ifdef VMS
    /*
     * Use ttclose() from cleanup() for VMS if not dumping.
     */
    if (dump_output_immediately)
#else /* Unix: */
    (void) signal(SIGINT, SIG_IGN);
#endif /* VMS */

    (void) signal(SIGTERM, SIG_IGN);

    if (traversal)
	dump_traversal_history();

#ifndef NOSIGHUP
    if (sig != SIGHUP) {
#endif /* NOSIGHUP */

	if (!dump_output_immediately) {
	    /*
	     * cleanup() also calls cleanup_files().
	     */
	    cleanup();
	}
	if (sig != 0) {
	    SetOutputMode(O_TEXT);
	    printf("\n\n%s %d\n\n",
		   gettext("Exiting via interrupt:"),
		   sig);
	    fflush(stdout);
	}
#ifndef NOSIGHUP
    } else {
	cleanup_files();
    }
#endif /* NOSIGHUP */

    if (sig != 0) {
	exit_immediately(EXIT_SUCCESS);
    } else {
	reset_signals();
    }
}
예제 #9
0
void HTFWriter_free( HTStream *me )
{
  int len;
  char *path = 0;
  char *addr = 0;
  int status;
  BOOLEAN use_zread = 0;
  BOOLEAN found = 0;
  if ( me->fp )
    fflush( &me->fp );
  if ( me->end_command )
  {
    LYCloseTempFP( &me->fp );
    if ( me->input_format == HTAtom_for( "www/compressed" ) )
    {
      if ( me->anchor->FileCache )
      {
        BOOLEAN skip_loadfile = me->viewer_command != 0;
        HTSACopy( &path, &me->anchor->FileCache );
        len = strlen( path );
        if ( len > 3 && ( strcasecomp( &path[ len + -2 ], "gz" ) == 0 || strcasecomp( &path[ len + -2 ], "zz" ) == 0 ) )
        {
          if ( skip_loadfile == 0 )
            use_zread = 1;
          else
          {
            path[ len + -3 ] = 0;
            remove( path );
          }
        }
        else
        if ( len > 4 && strcasecomp( &path[ len + -3 ], "bz2" ) == 0 )
        {
          path[ len + -4 ] = 0;
          remove( path );
        }
        else
        if ( len > 2 && strcasecomp( &path[ len + -1 ], "Z" ) == 0 )
        {
          path[ len + -2 ] = 0;
          remove( path );
        }
        if ( use_zread == 0 )
        {
          if ( dump_output_immediately == 0 )
          {
            mustshow = 1;
            HTProgress( &me->end_command );
          }
          if ( me->end_command && me->end_command[0] )
            LYSystem( &me->end_command );
          found = LYCanReadFile( &me->anchor->FileCache );
        }
        if ( found )
        {
          if ( dump_output_immediately == 0 )
          {
            lynx_force_repaint( );
            LYrefresh( );
          }
          HTAlert( gettext( "Error uncompressing temporary file!" ) );
          LYRemoveTemp( &me->anchor->FileCache );
          if ( me->anchor->FileCache )
          {
            free( &me->anchor->FileCache );
            me->anchor->FileCache = 0;
          }
        }
        else
        {
          LYLocalFileToURL( &addr, path );
          if ( use_zread == 0 )
          {
            LYRenamedTemp( &me->anchor->FileCache, path );
            HTSACopy( &me->anchor->FileCache, path );
            HTSACopy( &me->anchor->content_encoding, "binary" );
          }
          if ( path )
          {
            free( path );
            path = 0;
          }
          if ( skip_loadfile == 0 )
          {
            if ( HTAnchor_getUCLYhndl( &me->anchor, 1 ) < 0 )
              HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, 2 );
            HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, -1 );
          }
          if ( dump_output_immediately == 0 )
          {
            LYstore_message2( gettext( "Using %s" ), addr );
          }
          if ( skip_loadfile )
          {
            if ( me->end_command )
            {
              free( &me->end_command );
              *(int*)&me->end_command = 0;
            }
            HTAddParam( &me->end_command, &me->viewer_command, 1, &me->anchor->FileCache );
            HTEndParam( &me->end_command, &me->viewer_command, 1 );
            if ( dump_output_immediately == 0 )
            {
              HTProgress( &me->end_command );
              stop_curses( );
            }
            LYSystem( &me->end_command );
            if ( me->remove_command && me->remove_command )
            {
              free( &me->remove_command );
              *(int*)&me->remove_command = 0;
            }
            if ( dump_output_immediately == 0 )
              start_curses( );
          }
          else
          {
            status = HTLoadFile( addr, &me->anchor, &me->output_format, &me->sink );
          }
          if ( dump_output_immediately && me->output_format == HTAtom_for( "www/present" ) )
          {
            if ( addr )
            {
              free( addr );
              addr = 0;
            }
            remove( &me->anchor->FileCache );
            if ( me->anchor->FileCache )
            {
              free( &me->anchor->FileCache );
              me->anchor->FileCache = 0;
            }
            if ( me->remove_command )
            {
              free( &me->remove_command );
              *(int*)&me->remove_command = 0;
            }
            if ( me->end_command )
            {
              free( &me->end_command );
              *(int*)&me->end_command = 0;
            }
            if ( me->viewer_command )
            {
              free( &me->viewer_command );
              *(int*)&me->viewer_command = 0;
            }
            if ( me == 0 )
            {
              return;
            }
            free( me );
            me = 0;
            return;
          }
        }
        if ( addr )
        {
          free( addr );
          addr = 0;
        }
      }
      if ( me->remove_command && me->remove_command )
      {
        free( &me->remove_command );
        *(int*)&me->remove_command = 0;
      }
    }
    else
    {
      if ( strcmp( &me->end_command, "SaveToFile" ) )
      {
        if ( dump_output_immediately == 0 )
        {
          mustshow = 1;
          HTProgress( &me->end_command );
          stop_curses( );
        }
        LYSystem( &me->end_command );
        if ( me->remove_command && me->remove_command )
        {
          free( &me->remove_command );
          *(int*)&me->remove_command = 0;
        }
        if ( dump_output_immediately == 0 )
          start_curses( );
      }
      else
      {
        if ( me->remove_command && me->remove_command )
        {
          free( &me->remove_command );
          *(int*)&me->remove_command = 0;
        }
        if ( dump_output_immediately == 0 )
          start_curses( );
      }
    }
    if ( me->end_command )
    {
      free( &me->end_command );
      *(int*)&me->end_command = 0;
    }
  }
  if ( me->viewer_command )
  {
    free( &me->viewer_command );
    *(int*)&me->viewer_command = 0;
  }
  if ( dump_output_immediately )
  {
    if ( me->anchor->FileCache )
      remove( &me->anchor->FileCache );
    if ( me )
    {
      free( me );
      me = 0;
    }
    if ( persistent_cookies )
      LYStoreCookies( LYCookieSaveFile );
    exit_immediately( 0 );
  }
  if ( me == 0 )
  {
    return;
  }
  free( me );
  me = 0;
  return;
}
예제 #10
0
void exit_with_perror( char *msg )
{
  final_perror( msg, ebp_4 );
  exit_immediately( 1 );
  return;
}
예제 #11
0
void start_curses( void )
{
  int keypad_on = 0;
  if ( isatty( fileno( stdout ) ) && LYReopenInput( ) < 0 )
  {
    fwrite( "Cannot open tty input\n", 1, 22, stderr );
    exit_immediately( 1 );
  }
  if ( LYscreen == 0 )
  {
    BOOLEAN savesize = recent_sizechange;
    size_change( 0 );
    recent_sizechange = savesize;
    if ( WWW_TraceFlag )
    {
      fprintf( TraceFP( ), "Screen size: %s()\n", "initscr" );
    }
    LYscreen = initscr( );
    if ( LYscreen == 0 )
    {
      fprintf( TraceFP( ), "%s\n", gettext( "Terminal initialisation failed - unknown terminal type?" ) );
      exit_immediately( 1 );
    }
    lynx_called_initscr = 1;
    LYlines = LYscreenHeight( );
    LYcols = LYscreenWidth( );
    size_change( 0 );
    recent_sizechange = 0;
    if ( WWW_TraceFlag )
    {
      fprintf( TraceFP( ), "Screen size is now %d x %d\n", LYlines, LYcols );
    }
    if ( LYuseCursesPads )
    {
      LYwin = newpad( LYlines, 1014 );
      LYshiftWin = 0;
      LYwideLines = 0;
    }
    else
      LYwin = stdscr;
    keypad( LYwin, 1 );
    keypad_on = 1;
    if ( lynx_initialize_keymaps( ) == -1 )
    {
      endwin( );
      exit_immediately( 1 );
    }
    if ( has_colors( ) & 255 )
    {
      lynx_has_color = 1;
      start_color( );
      if ( COLORS > 16 )
        COLORS = 16;
      if ( COLORS <= 7 )
        COLORS = 2;
      if ( COLORS > 8 && COLORS != 16 )
        COLORS = 8;
      if ( LYuse_default_colors )
      {
        if ( assume_default_colors( default_fg, default_bg ) )
        {
          default_fg = 7;
          default_bg = 0;
        }
        if ( WWW_TraceFlag )
        {
          fprintf( TraceFP( ), "initializing default colors %d/%d\n", default_fg, default_bg );
        }
        if ( default_fg >= 0 || default_bg >= 0 )
        {
          unsigned int n = 0;
          for ( ; n <= 7; n++ )
          {
            if ( default_fg >= 0 && lynx_color_cfg[ n ].fg < 0 )
              lynx_color_cfg[ n ].fg = default_fg;
            if ( default_bg >= 0 && lynx_color_cfg[ n ].bg < 0 )
              lynx_color_cfg[ n ].bg = default_bg;
            if ( WWW_TraceFlag )
            {
              fprintf( TraceFP( ), "color_cfg[%u] = %d/%d\n", n, lynx_color_cfg[ n ].fg, lynx_color_cfg[ n ].bg );
            }
            // n++;
          }
          lynx_setup_colors( );
        }
      }
    }
    if ( lynx_lss_file && lynx_lss_file[0] && ( LYCanReadFile( lynx_lss_file ) & 255 ) )
      style_readFromFile( lynx_lss_file );
    parse_userstyles( );
    lynx_init_colors( );
  }
  cbreak( );
  signal( 2, &cleanup_sig );
  noecho( );
  if ( keypad_on == 0 )
    keypad( LYwin, 1 );
  lynx_enable_mouse( 1 );
  fflush( stdin );
  fflush( stdout );
  fflush( stderr );
  LYCursesON = 1;
  if ( WWW_TraceFlag )
  {
    fprintf( TraceFP( ), "start_curses: done.\n" );
  }
  return;
}