home *** CD-ROM | disk | FTP | other *** search
- Path: wupost!uunet!mcsun!unido!estevax!norisc!iain
- From: iain@norisc.UUCP (Iain Lea)
- Newsgroups: alt.sources
- Subject: tin v1.00 - YAN (Yet Another Newsreader) Part 06/08
- Message-ID: <587@norisc.UUCP>
- Date: 23 Aug 91 13:55:57 GMT
- Sender: iain@norisc.UUCP (Iain Lea)
- Organization: What organization?
- Lines: 2232
-
- Submitted-by: iain@estevax.uucp
- Archive-name: tin/part06
-
- #!/bin/sh
- # this is tin.shar.06 (part 6 of tin)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file rcfile.c continued
- #
- if touch 2>&1 | fgrep '[-amc]' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- fi
- if test ! -r shar3_seq_.tmp; then
- echo "Please unpack part 1 first!"
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 6; then
- echo "Please unpack part $Scheck next!"
- exit 1
- else
- exit 0
- fi
- ) < shar3_seq_.tmp || exit 1
- echo "x - Continuing file rcfile.c"
- sed 's/^X//' << 'SHAR_EOF' >> rcfile.c &&
- X }
- X }
- X }
- X fclose (fp);
- X return TRUE;
- X }
- X return FALSE;
- X}
- X
- X/*
- X * write_rcfile - write defaults to ~/.tin/tinrc
- X */
- X
- Xvoid write_rcfile ()
- X{
- X FILE *fp;
- X
- X if ((fp = fopen (rcfile, "w")) != NULL) {
- X wait_message (txt_saving);
- X
- X fprintf (fp, "# (-a) if ON articles/threads with Archive-name: in mail header will\n");
- X fprintf (fp, "# be automatically saved with the Archive-name & part/patch no.\n");
- X fprintf (fp, "save_archive=%s\n\n", (save_archive_name ? "ON" : "OFF"));
- X fprintf (fp, "# (-s) if ON articles of a threads will be saved to separate files\n");
- X fprintf (fp, "# otherwise the whole thread will be saved to one file\n");
- X fprintf (fp, "save_separate=%s\n\n", (save_separate ? "ON" : "OFF"));
- X fprintf (fp, "# if ON mark articles that are saved as read\n");
- X fprintf (fp, "mark_saved_read=%s\n\n", (mark_saved_read ? "ON" : "OFF"));
- X fprintf (fp, "# if ON show Subject & From otherwise just Subject\n");
- X fprintf (fp, "show_author=%s\n\n", (show_author ? "ON" : "OFF"));
- X fprintf (fp, "# if ON use -> otherwise highlighted bar for selection\n");
- X fprintf (fp, "draw_arrow=%s\n\n", (draw_arrow_mark ? "ON" : "OFF"));
- X fprintf (fp, "# if ON kill articles that match kill file\n");
- X fprintf (fp, "kill_articles=%s\n\n", (kill_articles ? "ON" : "OFF"));
- X fprintf (fp, "# if ON save articles/threads to subdir with Archive-name: under -d directory\n");
- X fprintf (fp, "print_header=%s\n\n", (print_header ? "ON" : "OFF"));
- X fprintf (fp, "# if ON post process saved articles/threads\n");
- X fprintf (fp, "post_process=%s\n\n", (post_process ? "ON" : "OFF"));
- X fprintf (fp, "# type of post processing to perform\n");
- X fprintf (fp, "post_process_type=%d\n\n", post_proc_type);
- X fprintf (fp, "# sort articles by 0) nothing 1) subject 2) from or 3) date field\n");
- X fprintf (fp, "sort_article_type=%d\n\n", sort_art_type);
- X fprintf (fp, "# (-d) directory where articles/threads are saved\n");
- X fprintf (fp, "savedir=%s\n\n", savedir);
- X fprintf (fp, "# (-M) directory where articles/threads are saved in mailbox format\n");
- X fprintf (fp, "maildir=%s\n\n", maildir);
- X fprintf (fp, "# (-p) print program with parameters used to print articles/threads\n");
- X fprintf (fp, "printer=%s\n\n", printer);
- X fprintf (fp, "# (-S) directory where news is spooled\n");
- X fprintf (fp, "spooldir=%s\n\n", spooldir);
- X
- X fprintf (fp, "# .signature file used for replies, followups\n");
- X fprintf (fp, "signature=%s\n\n", signature);
- X fprintf (fp, "# .Sig file used for postings\n");
- X fprintf (fp, "sig=%s\n\n", sig);
- X
- X fclose (fp);
- X chmod (rcfile, 0600);
- X }
- X}
- X
- X/*
- X * options menu so that the user can dynamically change parameters
- X */
- X
- Xint change_rcfile (group, kill_at_once)
- X char *group;
- X int kill_at_once;
- X{
- X char *str;
- X int ch;
- X int kill_changed = FALSE;
- X int orig_kill_state;
- X int option;
- X int ret_code = NO_KILLING;
- X
- X ClearScreen ();
- X printf("%s\r\n", nice_time()); /* time in upper left */
- X
- X StartInverse ();
- X center_line (1, txt_options_menu);
- X EndInverse ();
- X
- X MoveCursor(INDEX_TOP, 0);
- X printf ("%s%s\r\n\r\n", txt_opt_autosave, (save_archive_name ? "ON " : "OFF"));
- X printf ("%s%s\r\n\r\n", txt_opt_mark_saved_read, (mark_saved_read ? "ON " : "OFF"));
- X printf ("%s%s\r\n\r\n", txt_opt_show_author, (show_author ? "ON " : "OFF"));
- X printf ("%s%s", txt_opt_post_process, (post_process ? "ON " : "OFF"));
- X
- X MoveCursor(INDEX_TOP, COL2);
- X printf ("%s%s", txt_opt_save_separate, (save_separate ? "ON " : "OFF"));
- X MoveCursor(INDEX_TOP+2, COL2);
- X printf ("%s%s", txt_opt_kill_articles, (kill_articles ? "ON " : "OFF"));
- X MoveCursor(INDEX_TOP+4, COL2);
- X printf ("%s%s", txt_opt_draw_arrow, (draw_arrow_mark ? "ON " : "OFF"));
- X MoveCursor(INDEX_TOP+6, COL2);
- X printf ("%s%s", txt_opt_print_header, (print_header ? "ON " : "OFF"));
- X
- X
- X MoveCursor(INDEX_TOP+8, 0);
- X switch (post_proc_type) {
- X case POST_PROC_SH:
- X str = txt_post_process_sh;
- X break;
- X case POST_PROC_UUD:
- X str = txt_post_process_uud;
- X break;
- X case POST_PROC_UUD_ZOO:
- X str = txt_post_process_uud_zoo;
- X break;
- X case POST_PROC_UUD_LZH:
- X str = txt_post_process_uud_lzh;
- X break;
- X case POST_PROC_UUD_ARC:
- X str = txt_post_process_uud_arc;
- X break;
- X case POST_PROC_UUD_ZIP:
- X str = txt_post_process_uud_zip;
- X break;
- X case POST_PROC_PATCH:
- X str = txt_post_process_patch;
- X break;
- X }
- X printf ("%s%s\r\n\r\n", txt_opt_process_type, str);
- X
- X MoveCursor(INDEX_TOP+10, 0);
- X switch (sort_art_type) {
- X case SORT_BY_NONE:
- X str = txt_sort_by_none;
- X break;
- X case SORT_BY_SUBJ:
- X str = txt_sort_by_subj;
- X break;
- X case SORT_BY_FROM:
- X str = txt_sort_by_from;
- X break;
- X case SORT_BY_DATE:
- X str = txt_sort_by_date;
- X break;
- X }
- X printf ("%s%s\r\n\r\n", txt_opt_sort_type, str);
- X
- X printf ("%s%s\r\n\r\n", txt_opt_savedir, savedir);
- X printf ("%s%s\r\n\r\n", txt_opt_maildir, maildir);
- X printf ("%s%s\r\n\r\n", txt_opt_printer, printer);
- X fflush(stdout);
- X
- X while (1) {
- X show_menu_help ("Select option by entering number before text. Enter '0' to save/quit.");
- X MoveCursor (LINES, 0);
- X ch = ReadCh ();
- X if (ch == '0') {
- X option = 0;
- X } else {
- X option = parse_num (ch, "Enter option number> ");
- X }
- X switch (option) {
- X case 0:
- X write_rcfile ();
- X if (kill_changed) {
- X if (kill_at_once) {
- X if (kill_articles) {
- X read_kill_file ();
- X if (kill_any_articles (group)) {
- X reload_index_file (group, TRUE); /* kill arts */
- X }
- X } else {
- X reload_index_file (group, FALSE); /* add killed arts */
- X }
- X }
- X ret_code = KILLING;
- X }
- X clear_note_area ();
- X return ret_code;
- X
- X case 1: /* auto save */
- X show_menu_help (txt_help_autosave);
- X do {
- X MoveCursor (INDEX_TOP, strlen (txt_opt_autosave));
- X if ((ch = ReadCh()) == ' ') {
- X save_archive_name = !save_archive_name;
- X printf ("%s", (save_archive_name ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 2: /* save sperate */
- X show_menu_help (txt_help_save_separate);
- X do {
- X MoveCursor (INDEX_TOP, COL2 + (int) strlen (txt_opt_save_separate));
- X if ((ch = ReadCh()) == ' ') {
- X save_separate = !save_separate;
- X printf ("%s", (save_separate ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 3: /* mark saved articles read */
- X show_menu_help (txt_help_mark_saved_read);
- X do {
- X MoveCursor (INDEX_TOP+2, strlen (txt_opt_mark_saved_read));
- X if ((ch = ReadCh()) == ' ') {
- X mark_saved_read = !mark_saved_read;
- X printf ("%s", (mark_saved_read ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 4: /* kill articles */
- X orig_kill_state = kill_articles;
- X show_menu_help (txt_help_kill_articles);
- X do {
- X MoveCursor (INDEX_TOP+2, COL2 + (int) strlen (txt_opt_kill_articles));
- X if ((ch = ReadCh()) == ' ') {
- X kill_articles = !kill_articles;
- X kill_changed = (kill_articles != orig_kill_state ? TRUE : FALSE);
- X printf ("%s", (kill_articles ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 5: /* show subject & author / subject only */
- X show_menu_help (txt_help_show_author);
- X do {
- X MoveCursor (INDEX_TOP+4, strlen (txt_opt_show_author));
- X if ((ch = ReadCh()) == ' ') {
- X show_author = !show_author;
- X printf ("%s", (show_author ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 6: /* draw -> / highlighted bar */
- X show_menu_help (txt_help_draw_arrow);
- X do {
- X MoveCursor (INDEX_TOP+4, COL2 + (int) strlen (txt_opt_draw_arrow));
- X if ((ch = ReadCh()) == ' ') {
- X draw_arrow_mark = !draw_arrow_mark;
- X printf ("%s", (draw_arrow_mark ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 7: /* post process saved files */
- X show_menu_help (txt_help_post_process);
- X do {
- X MoveCursor (INDEX_TOP+6, strlen (txt_opt_post_process));
- X if ((ch = ReadCh()) == ' ') {
- X post_process = !post_process;
- X printf ("%s", (post_process ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 8: /* print header */
- X show_menu_help (txt_help_print_header);
- X do {
- X MoveCursor (INDEX_TOP+6, COL2 + (int) strlen (txt_opt_print_header));
- X if ((ch = ReadCh()) == ' ') {
- X print_header = !print_header;
- X printf ("%s", (print_header ? "ON " : "OFF"));
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X
- X case 9:
- X show_menu_help (txt_help_post_proc_type);
- X do {
- X MoveCursor (INDEX_TOP+8, strlen (txt_opt_process_type));
- X if ((ch = ReadCh()) == ' ') {
- X if (post_proc_type + 1 > POST_PROC_PATCH) {
- X post_proc_type = POST_PROC_SH;
- X } else {
- X post_proc_type++;
- X }
- X switch (post_proc_type) {
- X case POST_PROC_SH:
- X str = txt_post_process_sh;
- X break;
- X case POST_PROC_UUD:
- X str = txt_post_process_uud;
- X break;
- X case POST_PROC_UUD_ZOO:
- X str = txt_post_process_uud_zoo;
- X break;
- X case POST_PROC_UUD_LZH:
- X str = txt_post_process_uud_lzh;
- X break;
- X case POST_PROC_UUD_ARC:
- X str = txt_post_process_uud_arc;
- X break;
- X case POST_PROC_UUD_ZIP:
- X str = txt_post_process_uud_zip;
- X break;
- X case POST_PROC_PATCH:
- X str = txt_post_process_patch;
- X break;
- X }
- X CleartoEOLN ();
- X printf ("%s", str);
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X case 10:
- X show_menu_help (txt_help_sort_type);
- X do {
- X MoveCursor (INDEX_TOP+10, strlen (txt_opt_sort_type));
- X if ((ch = ReadCh()) == ' ') {
- X if (sort_art_type + 1 > SORT_BY_DATE) {
- X sort_art_type = SORT_BY_NONE;
- X } else {
- X sort_art_type++;
- X }
- X switch (sort_art_type) {
- X case SORT_BY_NONE:
- X str = txt_sort_by_none;
- X break;
- X case SORT_BY_SUBJ:
- X str = txt_sort_by_subj;
- X break;
- X case SORT_BY_FROM:
- X str = txt_sort_by_from;
- X break;
- X case SORT_BY_DATE:
- X str = txt_sort_by_date;
- X break;
- X }
- X CleartoEOLN ();
- X printf ("%s", str);
- X fflush(stdout);
- X }
- X } while (ch != CR);
- X break;
- X case 11:
- X show_menu_help (txt_help_savedir);
- X parse_menu_string (INDEX_TOP+12, strlen (txt_opt_savedir), savedir);
- X expand_rel_abs_pathname (INDEX_TOP+12, strlen (txt_opt_savedir), savedir);
- X break;
- X case 12:
- X show_menu_help (txt_help_maildir);
- X parse_menu_string (INDEX_TOP+14, strlen (txt_opt_maildir), maildir);
- X expand_rel_abs_pathname (INDEX_TOP+14, strlen (txt_opt_maildir), maildir);
- X break;
- X case 13:
- X show_menu_help (txt_help_printer);
- X parse_menu_string (INDEX_TOP+16, strlen (txt_opt_printer), printer);
- X expand_rel_abs_pathname (INDEX_TOP+16, strlen (txt_opt_printer), printer);
- X break;
- X }
- X }
- X}
- X
- X/*
- X * parse_menu_string
- X * get a string from the user
- X * Return TRUE if a valid string was typed, FALSE otherwise
- X */
- X
- Xvoid parse_menu_string (line, col, var)
- X int line;
- X int col;
- X char *var;
- X{
- X char buf[LEN+1];
- X char ch;
- X int len;
- X int i;
- X
- X MoveCursor (line, col);
- X buf[0] = '\0';
- X len = 0;
- X ch = ReadCh();
- X while (ch != '\n' && ch != '\r') {
- X if (ch == 8 || ch == 127) {
- X if (len) {
- X len--;
- X buf[len] = '\0';
- X putchar('\b');
- X putchar(' ');
- X putchar('\b');
- X } else {
- X strcpy (var, buf);
- X MoveCursor(line, col);
- X CleartoEOLN();
- X }
- X } else if (ch == 21) { /* control-U */
- X for (i = len;i>0;i--) {
- X putchar('\b');
- X putchar(' ');
- X putchar('\b');
- X }
- X buf[0] = '\0';
- X len = 0;
- X } else if (ch >= ' ' && len < 60) {
- X buf[len++] = ch;
- X buf[len] = '\0';
- X putchar (ch);
- X } else
- X putchar(7);
- X fflush(stdout);
- X ch = ReadCh();
- X }
- X
- X if (buf[0]) {
- X strcpy (var, buf);
- X }
- X}
- X
- X/*
- X * expand ~/News to /usr/username/News and print to screen
- X */
- X
- Xvoid expand_rel_abs_pathname (line, col, str)
- X int line;
- X int col;
- X char *str;
- X{
- X char buf[LEN+1];
- X
- X if (str[0] == '~') {
- X if (strlen (str) == 1) {
- X strcpy (str, homedir);
- X } else {
- X sprintf (buf, "%s%s", homedir, str+1);
- X strcpy (str, buf);
- X }
- X }
- X MoveCursor (line, col);
- X CleartoEOLN ();
- X puts (str);
- X fflush (stdout);
- X}
- X
- X/*
- X * show_menu_help
- X */
- X
- Xvoid show_menu_help (help_message)
- X char *help_message;
- X{
- X MoveCursor (INDEX_TOP+18, 0);
- X CleartoEOLN ();
- X center_line (INDEX_TOP+18, help_message);
- X}
- SHAR_EOF
- echo "File rcfile.c is complete" &&
- $TOUCH -am 0819090991 rcfile.c &&
- chmod 0600 rcfile.c ||
- echo "restore of rcfile.c failed"
- set `wc -c rcfile.c`;Wc_c=$1
- if test "$Wc_c" != "15340"; then
- echo original size 15340, current size $Wc_c
- fi
- # ============= save.c ==============
- echo "x - extracting save.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > save.c &&
- X/*
- X * Project : tin - a visual threaded usenet newsreader
- X * Module : save.c
- X * Author : R.Skrenta / I.Lea
- X * Created : 01-04-91
- X * Updated : 23-08-91
- X * Release : 1.0
- X * Notes :
- X * Copyright : (c) Copyright 1991 by Rich Skrenta, Iain Lea & Wayne Brandt
- X * You may freely copy or redistribute this software,
- X * so long as there is no profit made from its use, sale
- X * trade or reproduction. You may not change this copy-
- X * right notice, and it must be included in any copy made
- X */
- X
- X#include "tin.h"
- X
- X#define INITIAL 1
- X#define MIDDLE 2
- X#define OFF 3
- X#define END 4
- X
- Xint create_subdir = TRUE;
- X
- Xstruct save_t *save;
- Xint save_num=0;
- Xint max_save;
- X
- X/*
- X * types of archive programs
- X * 0=archiver, 1=extension, 2=extract option, 3=list option
- X */
- X
- Xstruct archiver_t {
- X char *name;
- X char *ext;
- X char *extract;
- X char *list;
- X};
- X
- Xstruct archiver_t archiver[] = {
- X { "", "", "", "" },
- X { "", "", "", "" },
- X { "", "", "", "" },
- X { "zoo", "zoo", "-extract", "-list" },
- X { "lharc", "lzh", "x", "l" },
- X { "arc", "arc", "x", "l" },
- X { "zip", "zip", "-x", "-l" },
- X { "", "", "", "" }
- X};
- X
- Xextern char *glob_page_group;
- Xextern char note_h_path[LEN+1]; /* Path: */
- Xextern char note_h_date[LEN+1]; /* Date: */
- Xextern FILE *note_fp; /* the body of the current article */
- Xextern int index_point;
- Xextern int note_end;
- Xextern int note_page;
- Xextern long note_mark[MAX_PAGES];
- X
- Xchar default_regex_pattern[LEN+1];
- X
- X
- Xvoid save_art_to_file (respnum, index, mailbox, filename)
- X int respnum;
- X int index;
- X int mailbox;
- X char *filename;
- X{
- X char file[LEN+1], *p;
- X char save_art_info[LEN+1];
- X FILE *fp;
- X int is_mailbox = FALSE;
- X int i = 0;
- X
- X file[0] = '\0';
- X
- X if (filename) {
- X my_strncpy (file, filename, LEN);
- X is_mailbox = mailbox;
- X i = index;
- X } else {
- X if (save_archive_name && arts[respnum].archive) {
- X my_strncpy (file, arts[respnum].archive, LEN);
- X } else {
- X if (! parse_string(txt_save_art_to_file, file)) {
- X return;
- X }
- X if (file[0] == '\0') {
- X info_message (txt_no_filename);
- X return;
- X }
- X
- X for (p = file; *p && (*p == ' ' || *p == '\t'); p++) {
- X ;
- X }
- X if (! *p) {
- X return;
- X }
- X
- X is_mailbox = create_path (file);
- X }
- X free_save_array ();
- X add_to_save_list (save_num, &arts[respnum], is_mailbox, file);
- X }
- X
- X if (! append_to_existing_file (i)) {
- X info_message(txt_art_not_saved);
- X sleep (1);
- X return;
- X }
- X
- X setuid(real_uid);
- X setgid(real_gid);
- X
- X if ((fp = fopen(save_filename (i), "a+")) == NULL) {
- X info_message(txt_art_not_saved);
- X setuid(real_uid);
- X setgid(real_gid);
- X return;
- X }
- X
- X if (! filename) {
- X wait_message (txt_saving);
- X }
- X
- X fprintf(fp, "From %s %s\n", note_h_path, note_h_date);
- X
- X if (fseek(note_fp, 0L, 0) == -1) {
- X error_message ("fseek error on \"%s\"", arts[respnum].subject);
- X }
- X copy_fp(note_fp, fp, "");
- X fputs("\n", fp);
- X fclose(fp);
- X fseek(note_fp, note_mark[note_page], 0);
- X
- X save[i].saved = TRUE;
- X
- X if (mark_saved_read) {
- X arts[respnum].unread = ART_READ;
- X }
- X
- X setuid(real_uid);
- X setgid(real_gid);
- X
- X if (! filename) {
- X if (is_mailbox) {
- X sprintf (save_art_info, txt_saved_to_mailbox, get_first_savefile ());
- X } else {
- X sprintf (save_art_info, txt_art_saved_to, get_first_savefile ());
- X }
- X info_message(save_art_info);
- X }
- X}
- X
- X
- Xvoid save_thread_to_file (respnum, group_path)
- X int respnum;
- X char *group_path;
- X{
- X char *p;
- X char file[LEN+1];
- X char save_thread_info[LEN+1];
- X char *first_savefile;
- X FILE *fp;
- X int count = 0;
- X int is_mailbox = FALSE;
- X int b, i;
- X int orig_note_end;
- X int orig_note_page;
- X
- X file[0] = '\0';
- X free_save_array ();
- X
- X b = which_base (respnum);
- X
- X if (! save_archive_name || ! arts[base[b]].archive) {
- X if (! parse_string(txt_save_thread_to, file)) {
- X return;
- X }
- X if (file[0] == '\0') {
- X info_message (txt_no_filename);
- X return;
- X }
- X
- X for (p = file; *p && (*p == ' ' || *p == '\t'); p++) {
- X ;
- X }
- X if (! *p) {
- X return;
- X }
- X
- X is_mailbox = create_path (file);
- X }
- X
- X setuid (real_uid);
- X setgid (real_gid);
- X
- X for (i = base[b] ; i >= 0 ; i = arts[i].thread) {
- X add_to_save_list (i, &arts[i], is_mailbox, file);
- X }
- X sort_save_list ();
- X
- X wait_message (txt_saving);
- X
- X orig_note_end = note_end;
- X orig_note_page = note_page;
- X note_cleanup (); /* close currently opened article */
- X
- X for (i=0 ; i < save_num ; i++) {
- X if (! append_to_existing_file (i)) {
- X info_message(txt_art_not_saved);
- X sleep (1);
- X setuid(real_uid);
- X setgid(real_gid);
- X continue;
- X } else {
- X wait_message (txt_saving);
- X }
- X
- X if ((fp = fopen (save_filename (i), "a+")) == NULL) {
- X info_message(txt_thread_not_saved);
- X goto reopen_article;
- X }
- X
- X open_note (arts[save[i].index].artnum, group_path);
- X fprintf (fp, "From %s %s\n", note_h_path, note_h_date);
- X fseek (note_fp, 0L, 0);
- X copy_fp (note_fp, fp, "");
- X note_cleanup ();
- X save[i].saved = TRUE;
- X
- X if (mark_saved_read) {
- X arts[save[i].index].unread = ART_READ;
- X }
- X
- X printf("\b\b\b\b%4d", ++count);
- X fflush(stdout);
- X fclose(fp);
- X }
- X
- X if (! (first_savefile = get_first_savefile ())) {
- X info_message(txt_thread_not_saved);
- X } else {
- X if (is_mailbox) {
- X sprintf (save_thread_info, txt_saved_to_mailbox, first_savefile);
- X } else {
- X if (save_num == 1) {
- X sprintf (save_thread_info, txt_art_saved_to, first_savefile);
- X } else {
- X if (save_separate) {
- X sprintf (save_thread_info, txt_thread_saved_to_many,
- X first_savefile, get_last_savefile ());
- X } else {
- X sprintf (save_thread_info, txt_thread_saved_to,
- X first_savefile);
- X }
- X }
- X free (first_savefile);
- X first_savefile = '\0';
- X }
- X info_message(save_thread_info);
- X }
- X
- Xreopen_article:
- X setuid(real_uid);
- X setgid(real_gid);
- X open_note(arts[respnum].artnum, group_path);
- X note_end = orig_note_end;
- X note_page = orig_note_page;
- X fseek (note_fp, note_mark[note_page], 0);
- X}
- X
- X
- Xint save_regex_arts (group_path, group)
- X char *group_path;
- X char *group;
- X{
- X char buf[LEN+1];
- X char buf2[LEN+1];
- X char dir[LEN+1];
- X char file[LEN+1];
- X char mailbox[LEN+1];
- X int i, j;
- X int is_mailbox = FALSE;
- X int save_tagged_files = FALSE;
- X
- X if (index_point < 0) {
- X info_message (txt_no_match);
- X return FALSE;
- X }
- X
- X free_save_array ();
- X clear_message ();
- X
- X /*
- X * check if tagged files and if not ask user for subject pattern
- X */
- X if (num_of_tagged_files) {
- X if (prompt_yn (LINES, "Enter 'y' to save tagged files or 'n' to enter regex pattern? (y/n): ", 'y')) {
- X save_tagged_files = TRUE;
- X }
- X }
- X
- X if (! save_tagged_files) {
- X sprintf (buf2, txt_save_pattern, default_regex_pattern);
- X
- X if (! parse_string (buf2, buf)) {
- X return FALSE;
- X }
- X if (strlen (buf)) {
- X my_strncpy (default_regex_pattern, buf, LEN);
- X } else {
- X if (default_regex_pattern[0]) {
- X my_strncpy (buf, default_regex_pattern, LEN);
- X } else {
- X info_message (txt_no_search_string);
- X return FALSE;
- X }
- X }
- X }
- X
- X /*
- X * ask user for filename
- X */
- X if (! parse_string (txt_base_file_name, file)) {
- X return FALSE;
- X }
- X
- X if (file[0] == '\0') {
- X info_message (txt_no_filename);
- X return FALSE;
- X }
- X
- X if (is_mailbox = create_path (file)) {
- X if ((int) strlen (file) > 1) {
- X my_strncpy (mailbox, file, LEN);
- X } else {
- X my_strncpy (mailbox, group, LEN);
- X }
- X my_strncpy (file, mailbox, LEN);
- X }
- X
- X if (save_tagged_files) {
- X for (i=1 ; i <= num_of_tagged_files ; i++) {
- X for (j=0 ; j < top ; j++) {
- X if (arts[j].tagged && arts[j].tagged == i) {
- X add_to_save_list (j, &arts[j], is_mailbox, file);
- X }
- X }
- X }
- X } else {
- X for (i=0 ; i < top ; i++) {
- X#ifdef DONT_USE_REGEX
- X if (str_str (arts[i].subject, buf) != 0) {
- X#else
- X if (wildmat (arts[i].subject, buf)) {
- X#endif
- X add_to_save_list (i, &arts[i], is_mailbox, file);
- X }
- X }
- X sort_save_list ();
- X }
- X
- X for (i=0 ; i < save_num ; i++) {
- X MoveCursor(LINES, 0);
- X fputs(txt_saving, stdout);
- X printf("\b\b\b\b%4d", i+1);
- X fflush(stdout);
- X
- X if (is_mailbox) {
- X strcpy (file, mailbox);
- X }else {
- X sprintf (file, "%s.%02d", save[i].file, i+1);
- X }
- X
- X open_note (arts[save[i].index].artnum, group_path);
- X save_art_to_file (save[i].index, i, is_mailbox, file);
- X note_cleanup ();
- X save[i].saved = TRUE;
- X }
- X
- X if (! save_num) {
- X info_message(txt_no_match);
- X } else {
- X if (is_mailbox) {
- X sprintf (buf, txt_saved_to_mailbox, get_first_savefile ());
- X } else {
- X sprintf (buf,txt_saved_pattern_to,
- X get_first_savefile (), get_last_savefile ());
- X }
- X info_message(buf);
- X }
- X
- X return (mark_saved_read ? TRUE : FALSE);
- X}
- X
- X
- Xint append_to_existing_file (i)
- X int i;
- X{
- X char buf[LEN+1];
- X char *file;
- X struct stat st;
- X
- X if (! save[i].is_mailbox && save_separate) {
- X file = save_filename (i);
- X if (stat(file, &st) != -1) {
- X sprintf (buf, txt_append_to_file, file);
- X if (! prompt_yn (LINES, buf, 'n')) {
- X free (file);
- X file = NULL;
- X return FALSE;
- X }
- X }
- X free (file);
- X file = NULL;
- X }
- X
- X return TRUE;
- X}
- X
- X
- Xint create_path (path)
- X char *path;
- X{
- X char buf [LEN];
- X int i, j, len;
- X struct stat st;
- X
- X /*
- X * save in mailbox format to ~/Mail/<group.name>
- X */
- X if (path[0] == '=') {
- X return TRUE;
- X }
- X
- X /*
- X * if ~/file expand (ie. /usr/homedir/file)
- X */
- X if (path[0] == '~') {
- X strcpy (buf, path+1);
- X sprintf (path, "%s%s", homedir, buf);
- X }
- X
- X /*
- X * create any directories, otherwise check
- X * errno and give appropiate error message
- X */
- X len = (int) strlen (path);
- X
- X for (i=0, j=0 ; i < len ; i++, j++) {
- X buf[j] = path[i];
- X if (i+1 < len && path[i+1] == '/') {
- X buf[j+1] = '\0';
- X if (stat (buf, &st) == -1) {
- X if (mkdir (buf, 0755) == -1) {
- X error_message ("Cannot create ", buf);
- X return FALSE;
- X }
- X }
- X }
- X }
- X return FALSE;
- X}
- X
- X
- Xint create_sub_dir (i)
- X int i;
- X{
- X char dir[LEN+1];
- X struct stat st;
- X
- X if (! save[i].is_mailbox && save[i].archive) {
- X sprintf (dir, "%s/%s", save[i].dir, save[i].archive);
- X if (stat (dir, &st) == -1) {
- X mkdir (dir, 0755);
- X return TRUE;
- X }
- X if ((st.st_mode & S_IFMT) == S_IFDIR) {
- X return TRUE;
- X } else {
- X return FALSE;
- X }
- X }
- X return FALSE;
- X}
- X
- X/*
- X * add files to be saved to save array
- X */
- X
- Xvoid add_to_save_list (index, article, is_mailbox, path)
- X int index;
- X struct header *article;
- X int is_mailbox;
- X char *path;
- X{
- X char dir[LEN+1];
- X char file[LEN+1];
- X int i;
- X
- X dir[0] = '\0';
- X file[0] = '\0';
- X
- X if (save_num == max_save-1) {
- X expand_save ();
- X }
- X
- X save[save_num].index = index;
- X save[save_num].saved = FALSE;
- X save[save_num].is_mailbox = is_mailbox;
- X save[save_num].dir = (char *) 0;
- X save[save_num].file = (char *) 0;
- X save[save_num].archive = (char *) 0;
- X save[save_num].part = (char *) 0;
- X save[save_num].patch = (char *) 0;
- X
- X save[save_num].subject = str_dup (article->subject);
- X if (article->archive) {
- X save[save_num].archive = str_dup (article->archive);
- X }
- X if (article->part) {
- X save[save_num].part = str_dup (article->part);
- X }
- X if (article->patch) {
- X save[save_num].patch = str_dup (article->patch);
- X }
- X
- X if (is_mailbox) {
- X if ((int) strlen (path) > 1) {
- X if (path[0] == '=') {
- X strcpy (file, path+1);
- X } else {
- X strcpy (file, path);
- X }
- X } else {
- X strcpy (file, glob_page_group);
- X }
- X /*
- X * convert 1st letter to uppercase
- X */
- X if (file[0] >= 'a' && file[0] <= 'z') {
- X file[0] = file[0] - 32;
- X }
- X save[save_num].dir = maildir;
- X save[save_num].file = str_dup (file);
- X } else {
- X if (path[0]) {
- X for (i=strlen (path) ; i ; i--) {
- X if (path[i] == '/') {
- X strncpy (dir, path, i);
- X dir[i] = '\0';
- X strcpy (file, path+i+1);
- X break;
- X }
- X }
- X }
- X
- X if (dir[0]) {
- X save[save_num].dir = str_dup (dir);
- X } else {
- X save[save_num].dir = str_dup (savedir);
- X }
- X
- X if (file[0]) {
- X save[save_num].file = str_dup (file);
- X } else {
- X if (path[0]) {
- X save[save_num].file = str_dup (path);
- X } else {
- X save[save_num].file = save[save_num].archive;
- X }
- X }
- X }
- X save_num++;
- X}
- X
- X/*
- X * print save array of files to be saved
- X */
- X
- Xvoid sort_save_list ()
- X{
- X qsort (save, save_num, sizeof (struct save_t), save_comp);
- X}
- X
- X/*
- X * string comparison routine for the qsort()
- X * ie. qsort(array, 5, 32, save_comp);
- X */
- X
- Xint save_comp (s1, s2)
- X struct save_t *s1;
- X struct save_t *s2;
- X{
- X /* s1->subject less than s2->subject */
- X if (strcmp (s1->subject, s2->subject) < 0) {
- X return -1;
- X }
- X /* s1->subject greater than s2->subject */
- X if (strcmp (s1->subject, s2->subject) > 0) {
- X return 1;
- X }
- X return 0;
- X}
- X
- X
- Xchar *save_filename (i)
- X int i;
- X{
- X char *filename;
- X
- X filename = (char *) my_malloc (LEN);
- X
- X if (save[i].is_mailbox) {
- X sprintf (filename, "%s/%s", save[i].dir, save[i].file);
- X return (filename);
- X }
- X
- X if (! save_separate || ! save_archive_name || (! save[i].part && ! save[i].patch)) {
- X if (! save_separate || save_num == 1) {
- X sprintf (filename, "%s/%s", save[i].dir, save[i].file);
- X } else {
- X sprintf (filename, "%s/%s.%02d", save[i].dir, save[i].file, i+1);
- X }
- X } else {
- X if (save[i].part) {
- X if (create_sub_dir (i)) {
- X sprintf (filename, "%s/%s/%s.%s%s", save[i].dir, save[i].archive, save[i].archive, LONG_PATH_PART, save[i].part);
- X } else {
- X sprintf (filename, "%s/%s.%s%s", save[i].dir, save[i].archive, LONG_PATH_PART, save[i].part);
- X }
- X } else {
- X if (save[i].patch) {
- X if (create_sub_dir (i)) {
- X sprintf (filename, "%s/%s/%s.%s%s", save[i].dir, save[i].archive, save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X } else {
- X sprintf (filename, "%s/%s.%s%s", save[i].dir, save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X }
- X } else {
- X sprintf (filename, "%s/%s", save[i].dir, save[i].file);
- X }
- X }
- X }
- X
- X return (filename);
- X}
- X
- X
- Xchar *get_first_savefile ()
- X{
- X char *file;
- X int i;
- X
- X for (i=0 ; i < save_num ; i++) {
- X if (save[i].saved) {
- X file = (char *) my_malloc (LEN);
- X if (save[i].is_mailbox) {
- X sprintf (file, "%s/%s", save[i].dir, save[i].file);
- X return (file);
- X } else {
- X if (save[i].archive && save_archive_name) {
- X if (save[i].part) {
- X if (create_subdir) {
- X sprintf (file, "%s/%s.%s%s", save[i].archive, save[i].archive, LONG_PATH_PART, save[i].part);
- X } else {
- X sprintf (file, "%s.%s%s", save[i].archive, LONG_PATH_PART, save[i].part);
- X }
- X } else {
- X if (create_subdir) {
- X sprintf (file, "%s/%s.%s%s", save[i].archive, save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X } else {
- X sprintf (file, "%s.%s%s", save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X }
- X }
- X } else {
- X if (! save_separate || save_num == 1) {
- X sprintf (file, "%s", save[i].file);
- X } else {
- X sprintf (file, "%s.%02d", save[i].file, i+1);
- X }
- X }
- X return (file);
- X }
- X }
- X }
- X return ((char *) 0);
- X}
- X
- X
- Xchar *get_last_savefile ()
- X{
- X char *file;
- X int i;
- X
- X for (i=save_num-1 ; i >= 0 ; i--) {
- X if (save[i].saved) {
- X file = (char *) my_malloc (LEN);
- X if (save[i].is_mailbox) {
- X sprintf (file, "%s/%s", save[i].dir, save[i].file);
- X return (file);
- X } else {
- X if (save[i].archive && save_archive_name) {
- X if (save[i].part) {
- X if (create_subdir) {
- X sprintf (file, "%s/%s.%s%s", save[i].archive, save[i].archive, LONG_PATH_PART, save[i].part);
- X } else {
- X sprintf (file, "%s.%s%s", save[i].archive, LONG_PATH_PART, save[i].part);
- X }
- X } else {
- X if (create_subdir) {
- X sprintf (file, "%s/%s.%s%s", save[i].archive, save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X } else {
- X sprintf (file, "%s.%s%s", save[i].archive, LONG_PATH_PATCH, save[i].patch);
- X }
- X }
- X } else {
- X if (! save_separate || save_num == 1) {
- X sprintf (file, "%s", save[i].file);
- X } else {
- X sprintf (file, "%s.%02d", save[i].file, i+1);
- X }
- X }
- X return (file);
- X }
- X }
- X }
- X return ((char *) 0);
- X}
- X
- X
- Xint post_process_files ()
- X{
- X if (post_process && save_num && ! save[save_num-1].is_mailbox) {
- X wait_message (txt_post_processing);
- X
- X switch (post_proc_type) {
- X case POST_PROC_SH:
- X post_process_sh ();
- X break;
- X
- X case POST_PROC_UUD:
- X post_process_uud (POST_PROC_UUD);
- X break;
- X
- X case POST_PROC_UUD_ZOO:
- X post_process_uud (POST_PROC_UUD_ZOO);
- X break;
- X
- X case POST_PROC_UUD_LZH:
- X post_process_uud (POST_PROC_UUD_LZH);
- X break;
- X
- X case POST_PROC_UUD_ARC:
- X post_process_uud (POST_PROC_UUD_ARC);
- X break;
- X
- X case POST_PROC_UUD_ZIP:
- X post_process_uud (POST_PROC_UUD_ZIP);
- X break;
- X
- X case POST_PROC_PATCH:
- X post_process_patch ();
- X break;
- X }
- X info_message ("-- post processing completed --");
- X sleep (1);
- X return TRUE;
- X }
- X return FALSE;
- X}
- X
- X
- Xvoid post_process_uud (pp)
- X int pp;
- X{
- X char s[LEN+1], t[LEN+1], u[LEN+1];
- X char buf[LEN+1], *file;
- X char file_out[LEN+1];
- X char file_out_dir[LEN+1];
- X FILE *fp_in, *fp_out;
- X int i, state = INITIAL;
- X int file_size = 0;
- X struct stat st;
- X
- X t[0] = '\0';
- X u[0] = '\0';
- X
- X my_strncpy (file_out_dir, save_filename (0), LEN);
- X for (i=strlen(file_out_dir) ; i > 0 ; i--) {
- X if (file_out_dir[i] == '/') {
- X file_out_dir[i] = '\0';
- X break;
- X }
- X }
- X
- X sprintf (file_out, "%s/tin.%05d", file_out_dir, getpid ());
- X
- X if ((fp_out = fopen (file_out, "a+")) == NULL) {
- X error_message (txt_cannot_open, file_out);
- X }
- X
- X
- X for (i=0 ; i < save_num ; i++) {
- X my_strncpy (buf, save_filename (i), LEN);
- X/*
- X sprintf (buf, "%s%d", txt_post_processing, i);
- X wait_message (buf);
- X*/
- X if ((fp_in = fopen (buf, "r")) != NULL) {
- X if (fgets (s, LEN, fp_in) == NULL) {
- X fclose (fp_in);
- X continue;
- X }
- X while (state != END) {
- X switch (state) {
- X case INITIAL:
- X if (! strncmp ("begin", s, 5)) {
- X state = MIDDLE;
- X fprintf (fp_out, "%s", s);
- X }
- X break;
- X
- X case MIDDLE:
- X if (s[0] == 'M') {
- X fprintf (fp_out, "%s", s);
- X } else if (strncmp("end", s, 3)) {
- X state = OFF;
- X } else { /* end */
- X state = END;
- X if (u[0] != 'M') {
- X fprintf (fp_out, "%s", u);
- X }
- X if (t[0] != 'M') {
- X fprintf (fp_out, "%s", t);
- X }
- X fprintf (fp_out, "%s\n", s);
- X }
- X break;
- X
- X case OFF:
- X if ((s[0] == 'M') && (t[0] == 'M') && (u[0] == 'M')) {
- X fprintf (fp_out, "%s", u);
- X fprintf (fp_out, "%s", t);
- X fprintf (fp_out, "%s", s);
- X state = MIDDLE;
- X } else if (! strncmp ("end", s, 3)) {
- X state = END;
- X if (u[0] != 'M') {
- X fprintf (fp_out, "%s", u);
- X }
- X if (t[0] != 'M') {
- X fprintf (fp_out, "%s", t);
- X }
- X fprintf (fp_out, "%s\n", s);
- X }
- X break;
- X
- X case END:
- X break;
- X
- X default:
- X fprintf (stderr, "\r\nerror: ASSERT - default state\n");
- X fclose (fp_in);
- X fclose (fp_out);
- X unlink (file_out);
- X return;
- X }
- X strcpy (u,t);
- X strcpy (t,s);
- X /*
- X * read next line & if error goto next file in save array
- X */
- X if (fgets (s, LEN, fp_in) == NULL) {
- X break;
- X }
- X }
- X fclose (fp_in);
- X }
- X }
- X fclose (fp_out);
- X
- X /*
- X * uudecode file
- X */
- X wait_message ("Uudecoding...");
- X/*
- X printf ("\r\nUudecoding...\r\n");
- X*/
- X
- X sprintf (buf, "cd %s; uudecode %s", file_out_dir, file_out);
- X if (invoke_cmd (buf)) {
- X /*
- X * sum file
- X */
- X if (file = get_archive_file (file_out_dir, "*")) {
- X sprintf (buf, "%s %s", DEFAULT_SUM, file);
- X printf ("\r\n\r\nChecksum of %s...\r\n\r\n", file);
- X fflush (stdout);
- X if ((fp_in = popen (buf, "r")) == NULL) {
- X printf ("Cannot execute %s\r\n", buf);
- X fflush (stdout);
- X } else {
- X if (stat (file, &st) != -1) {
- X file_size = (int) st.st_size;
- X }
- X if (fgets (buf, LEN, fp_in) != NULL) {
- X buf[strlen (buf)-1] = '\0';
- X }
- X fclose (fp_in);
- X printf ("%s %8d bytes\r\n", buf, file_size);
- X fflush (stdout);
- X }
- X free (file);
- X file = (char *) 0;
- X delete_processed_files ();
- X }
- X }
- X
- X if (pp > POST_PROC_UUD) {
- X sprintf (buf, "*.%s", archiver[pp].ext);
- X if (file = get_archive_file (file_out_dir, buf)) {
- X#ifdef EXTRACT_ARCHIVED_FILES
- X sprintf (buf, "cd %s; %s %s %s", file_out_dir,
- X archiver[pp].name, archiver[pp].list, file);
- X printf ("\r\n\r\nListing %s archive...\r\n", file);
- X#else
- X sprintf (buf, "cd %s; %s %s %s", file_out_dir,
- X archiver[pp].name, archiver[pp].extract, file);
- X printf ("\r\n\r\nExtracting %s archive...\r\n", file);
- X#endif
- X fflush (stdout);
- X free (file);
- X file = NULL;
- X if (! invoke_cmd (buf)) {
- X error_message ("post processing failed", NULL);
- X } else {
- X continue_prompt ();
- X }
- X }
- X }
- X
- X unlink (file_out);
- X}
- X
- X/*
- X * Unpack /bin/sh archives
- X */
- X
- Xvoid post_process_sh ()
- X{
- X char buf[LEN+1];
- X char file_in[LEN+1];
- X char file_out[LEN+1];
- X char file_out_dir[LEN+1];
- X char *ptr1, *ptr2;
- X FILE *fp_in, *fp_out;
- X int found_header;
- X int i, j;
- X int lineno;
- X char sh_pattern_1[16];
- X char sh_pattern_2[16];
- X
- X strcpy (sh_pattern_1, "#! /bin/sh");
- X strcpy (sh_pattern_2, "#!/bin/sh");
- X
- X my_strncpy (file_out_dir, save_filename (0), LEN);
- X for (i=strlen(file_out_dir) ; i > 0 ; i--) {
- X if (file_out_dir[i] == '/') {
- X file_out_dir[i] = '\0';
- X break;
- X }
- X }
- X
- X sprintf (file_out, "%s/tin.%05d", file_out_dir, getpid ());
- X
- X for (j=0 ; j < save_num ; j++) {
- X my_strncpy (file_in, save_filename (j), LEN);
- X
- X printf ("\r\nExtracting %s...\r\n", file_in);
- X fflush (stdout);
- X
- X found_header = FALSE;
- X lineno = 1;
- X
- X if ((fp_out = fopen (file_out, "w")) != NULL) {
- X if ((fp_in = fopen (file_in, "r")) != NULL) {
- X while (! feof (fp_in)) {
- X if (fgets (buf, LEN, fp_in)) {
- X /*
- X * find #!/bin/sh or #! /bin/sh pattern
- X */
- X if (!found_header) {
- X ptr1 = sh_pattern_1;
- X ptr2 = sh_pattern_2;
- X if (str_str (buf, ptr1) != 0 ||
- X str_str (buf, ptr2) != 0) {
- X/*
- Xprintf ("\r\n[%16s] [%04d] FOUND #/bin/sh\r\n", file_in, lineno);
- X*/
- X found_header = TRUE;
- X }
- X }
- X
- X /*
- X * Write to temp file
- X */
- X if (found_header) {
- X fputs (buf, fp_out);
- X }
- X lineno++;
- X }
- X }
- X fclose (fp_in);
- X }
- X fclose (fp_out);
- X
- X sprintf (buf, "cd %s; sh %s", file_out_dir, file_out);
- X printf ("\r\n");
- X fflush (stdout);
- X Raw (FALSE);
- X invoke_cmd (buf);
- X Raw (TRUE);
- X unlink (file_out);
- X }
- X }
- X delete_processed_files ();
- X}
- X
- X
- Xchar *get_archive_file (dir, ext)
- X char *dir;
- X char *ext;
- X{
- X char buf[LEN+1];
- X char *file = NULL;
- X FILE *fp;
- X
- X sprintf (buf, "ls -t %s/%s", dir, ext);
- X
- X if ((fp = popen (buf, "r")) == NULL) {
- X return NULL;
- X }
- X
- X if (fgets (buf, LEN, fp) != NULL) {
- X file = str_dup (buf);
- X file[strlen (file)-1] = '\0';
- X }
- X
- X fclose (fp);
- X
- X return (file);
- X}
- X
- X
- Xvoid delete_processed_files ()
- X{
- X int i;
- X
- X printf ("\r\n");
- X fflush (stdout);
- X
- X if (prompt_yn (LINES, "Delete saved files that have been post processed? (y/n): ", 'y')) {
- X wait_message (txt_deleting);
- X
- X for (i=0 ; i < save_num ; i++) {
- X unlink (save_filename (i));
- X }
- X }
- X}
- X
- X
- Xvoid post_process_patch ()
- X{
- X}
- SHAR_EOF
- $TOUCH -am 0823151891 save.c &&
- chmod 0600 save.c ||
- echo "restore of save.c failed"
- set `wc -c save.c`;Wc_c=$1
- if test "$Wc_c" != "22644"; then
- echo original size 22644, current size $Wc_c
- fi
- # ============= screen.c ==============
- echo "x - extracting screen.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > screen.c &&
- X/*
- X * Project : tin - a visual threaded usenet newsreader
- X * Module : screen.c
- X * Author : R.Skrenta / I.Lea
- X * Created : 01-04-91
- X * Updated : 10-08-91
- X * Release : 1.0
- X * Notes :
- X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
- X * You may freely copy or redistribute this software,
- X * so long as there is no profit made from its use, sale
- X * trade or reproduction. You may not change this copy-
- X * right notice, and it must be included in any copy made
- X */
- X
- X#include "tin.h"
- X
- Xextern int errno;
- X
- Xchar msg[LEN+1];
- Xstruct screen_t *screen;
- X
- X
- Xvoid info_message (msg)
- X char *msg;
- X{
- X clear_message(); /* Clear any old messages hanging around */
- X center_line(LINES, msg); /* center the message at screen bottom */
- X MoveCursor(LINES, 0);
- X}
- X
- X
- Xvoid wait_message (msg)
- X char *msg;
- X{
- X clear_message(); /* Clear any old messages hanging around */
- X printf (msg);
- X fflush (stdout);
- X}
- X
- X
- Xvoid error_message (template, msg)
- X char *template;
- X char *msg;
- X{
- X errno = 0;
- X
- X if (! update) {
- X clear_message(); /* Clear any old messages hanging around */
- X }
- X fprintf (stderr, template, msg);
- X fflush (stderr);
- X
- X /* perror (""); */
- X
- X if (! update) {
- X MoveCursor(LINES, 0);
- X }
- X sleep (1);
- X}
- X
- X
- Xvoid clear_message ()
- X{
- X MoveCursor(LINES, 0);
- X CleartoEOLN();
- X}
- X
- X
- Xvoid center_line (line, str)
- X int line;
- X char *str;
- X{
- X int pos;
- X
- X pos = (COLS - (int) strlen (str)) / 2;
- X MoveCursor (line, pos);
- X printf ("%s", str);
- X fflush (stdout);
- X}
- X
- X
- Xvoid draw_arrow (line)
- X int line;
- X{
- X MoveCursor (line, 0);
- X
- X if (draw_arrow_mark) {
- X printf ("->");
- X } else {
- X StartInverse ();
- X printf ("%s", screen[line-INDEX_TOP].col);
- X EndInverse ();
- X }
- X
- X fflush (stdout);
- X MoveCursor (LINES, 0);
- X}
- X
- X
- Xvoid erase_arrow (line)
- X int line;
- X{
- X MoveCursor (line, 0);
- X
- X if (draw_arrow_mark) {
- X printf (" ");
- X } else {
- X printf ("%s", screen[line-INDEX_TOP].col);
- X }
- X
- X fflush (stdout);
- X}
- SHAR_EOF
- $TOUCH -am 0819091091 screen.c &&
- chmod 0600 screen.c ||
- echo "restore of screen.c failed"
- set `wc -c screen.c`;Wc_c=$1
- if test "$Wc_c" != "1936"; then
- echo original size 1936, current size $Wc_c
- fi
- # ============= search.c ==============
- echo "x - extracting search.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > search.c &&
- X/*
- X * Project : tin - a visual threaded usenet newsreader
- X * Module : search.c
- X * Author : R.Skrenta / I.Lea
- X * Created : 01-04-91
- X * Updated : 22-08-91
- X * Release : 1.0
- X * Notes :
- X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
- X * You may freely copy or redistribute this software,
- X * so long as there is no profit made from its use, sale
- X * trade or reproduction. You may not change this copy-
- X * right notice, and it must be included in any copy made
- X */
- X
- X#include "tin.h"
- X
- Xextern FILE *note_fp;
- Xextern int cur_groupnum;
- Xextern int first_group_on_screen;
- Xextern int last_group_on_screen;
- Xextern int first_subj_on_screen;
- Xextern int last_subj_on_screen;
- Xextern int index_point;
- Xextern int note_line;
- Xextern int note_page;
- Xextern int note_end;
- Xextern long note_mark[MAX_PAGES];
- X
- X/*
- X * last search patterns
- X */
- X
- Xchar author_search_string[LEN+1];
- Xchar group_search_string[LEN+1];
- Xchar subject_search_string[LEN+1];
- Xchar art_search_string[LEN+1];
- X
- X
- X/*
- X * group.c & page.c
- X */
- X
- Xint search_author (current_art, forward)
- X int current_art;
- X int forward;
- X{
- X char buf[LEN+1];
- X char buf2[LEN+1];
- X int i;
- X
- X clear_message();
- X
- X if (forward) {
- X sprintf (buf2, txt_author_search_forwards, author_search_string);
- X } else {
- X sprintf (buf2, txt_author_search_backwards, author_search_string);
- X }
- X
- X
- X if (! parse_string (buf2, buf)) {
- X return -1;
- X }
- X
- X if (strlen (buf)) {
- X strcpy (author_search_string, buf);
- X } else {
- X if (author_search_string[0]) {
- X strcpy (buf, author_search_string);
- X } else {
- X info_message (txt_no_search_string);
- X return -1;
- X }
- X }
- X
- X make_lower(author_search_string, buf);
- X
- X i = current_art;
- X
- X do {
- X if (forward) {
- X i = next_response(i);
- X if (i < 0)
- X i = 0;
- X } else {
- X i = prev_response(i);
- X if (i < 0)
- X i = top - 1;
- X }
- X
- X make_lower(arts[i].from, buf2);
- X if (str_str (buf2, buf) != 0)
- X return i;
- X } while (i != current_art);
- X
- X info_message(txt_no_match);
- X return -1;
- X}
- X
- X/*
- X * select.c
- X */
- X
- Xvoid search_group (forward)
- X int forward;
- X{
- X char buf[LEN+1];
- X char buf2[LEN+1];
- X int i;
- X
- X clear_message();
- X
- X if (forward) {
- X sprintf (buf2, txt_search_forwards, group_search_string);
- X } else {
- X sprintf (buf2, txt_search_backwards, group_search_string);
- X }
- X
- X if (! parse_string (buf2, buf)) {
- X return;
- X }
- X
- X if (strlen (buf)) {
- X strcpy (group_search_string, buf);
- X } else {
- X if (group_search_string[0]) {
- X strcpy (buf, group_search_string);
- X } else {
- X info_message (txt_no_search_string);
- X return;
- X }
- X }
- X
- X i = cur_groupnum;
- X
- X make_lower(group_search_string, buf);
- X
- X do {
- X if (forward)
- X i++;
- X else
- X i--;
- X
- X if (i >= local_top)
- X i = 0;
- X if (i < 0)
- X i = local_top - 1;
- X
- X make_lower(active[my_group[i]].name, buf2);
- X if (str_str (buf2, buf) != 0) {
- X if (i >= first_group_on_screen
- X && i < last_group_on_screen) {
- X erase_group_arrow();
- X cur_groupnum = i;
- X draw_group_arrow();
- X } else {
- X cur_groupnum = i;
- X group_selection_page();
- X }
- X return;
- X }
- X } while (i != cur_groupnum);
- X
- X info_message(txt_no_match);
- X}
- X
- X/*
- X * group.c
- X */
- X
- Xvoid search_subject (forward, group)
- X int forward;
- X char *group;
- X{
- X char buf[LEN+1];
- X char buf2[LEN+1];
- X int i, j;
- X
- X if (index_point < 0) {
- X info_message (txt_no_arts);
- X return;
- X }
- X
- X clear_message();
- X
- X if (forward) {
- X sprintf (buf2, txt_search_forwards, subject_search_string);
- X } else {
- X sprintf (buf2, txt_search_backwards, subject_search_string);
- X }
- X
- X if (! parse_string (buf2, buf)) {
- X return;
- X }
- X
- X if (strlen (buf)) {
- X strcpy (subject_search_string, buf);
- X } else {
- X if (subject_search_string[0]) {
- X strcpy (buf, subject_search_string);
- X } else {
- X info_message (txt_no_search_string);
- X return;
- X }
- X }
- X
- X i = index_point;
- X
- X make_lower(subject_search_string, buf);
- X
- X do {
- X if (forward)
- X i++;
- X else
- X i--;
- X
- X if (i >= top_base)
- X i = 0;
- X if (i < 0)
- X i = top_base - 1;
- X
- X j = base[i];
- X make_lower(arts[j].subject, buf2);
- X if (str_str (buf2, buf) != 0) {
- X if (i >= first_subj_on_screen
- X && i < last_subj_on_screen) {
- X erase_subject_arrow();
- X index_point = i;
- X draw_subject_arrow();
- X } else {
- X index_point = i;
- X show_group_page(group);
- X }
- X return;
- X }
- X } while (i != index_point);
- X
- X info_message(txt_no_match);
- X}
- X
- X/*
- X * page.c (search article body)
- X */
- X
- Xint search_article (forward)
- X int forward;
- X{
- X char buf[LEN+1];
- X char buf2[LEN+1];
- X char string[LEN+1];
- X char pattern[LEN+1];
- X char *p, *q;
- X int ctrl_L;
- X int i, j;
- X int orig_note_end;
- X int orig_note_page;
- X
- X clear_message ();
- X
- X if (forward) {
- X sprintf (buf2, txt_search_forwards, art_search_string);
- X } else {
- X sprintf (buf2, txt_search_backwards, art_search_string);
- X }
- X
- X if (! parse_string (buf2, buf)) {
- X return FALSE;
- X }
- X
- X if (strlen (buf)) {
- X strcpy (art_search_string, buf);
- X } else {
- X if (art_search_string[0]) {
- X strcpy (buf, art_search_string);
- X } else {
- X info_message (txt_no_search_string);
- X return FALSE;
- X }
- X }
- X
- X make_lower (art_search_string, pattern);
- X /*
- X * save current position in article
- X */
- X orig_note_end = note_end;
- X orig_note_page = note_page;
- X
- X wait_message (txt_searching);
- X
- X while (! note_end) {
- X note_line = 1;
- X ctrl_L = FALSE;
- X
- X if (note_page == 0) {
- X note_line += 4;
- X } else {
- X note_line += 2;
- X }
- X while (note_line < LINES) {
- X if (fgets(buf, LEN, note_fp) == NULL) {
- X note_end = TRUE;
- X break;
- X }
- X buf[LEN-1] = '\0';
- X for (p = buf, q = buf2; *p && *p != '\n' && q<&buf2[LEN]; p++) {
- X if (*p == '\b' && q > buf2) {
- X q--;
- X } else if (*p == 12) { /* ^L */
- X *q++ = '^';
- X *q++ = 'L';
- X ctrl_L = TRUE;
- X } else if (*p == '\t') {
- X i = q - buf2;
- X j = (i|7) + 1;
- X
- X while (i++ < j) {
- X *q++ = ' ';
- X }
- X } else if (((*p) & 0x7F) < 32) {
- X *q++ = '^';
- X *q++ = ((*p) & 0x7F) + '@';
- X } else {
- X *q++ = *p;
- X }
- X }
- X *q = '\0';
- X
- X make_lower(buf2, string);
- X
- X if (str_str (string, pattern) != 0) {
- X fseek (note_fp, note_mark[note_page], 0);
- X return TRUE;
- X }
- X
- X note_line += ((int) strlen(buf2) / COLS) + 1;
- X
- X if (ctrl_L) {
- X break;
- X }
- X }
- X if (! note_end) {
- X note_mark[++note_page] = ftell(note_fp);
- X }
- X }
- X
- X note_end = orig_note_end;
- X note_page = orig_note_page;
- X fseek (note_fp, note_mark[note_page], 0);
- X info_message (txt_no_match);
- X return FALSE;
- X}
- X
- X/*
- X * ANSI C strstr () - Use Boyer-Moore algorithm. Downloaded from net.
- X */
- X
- Xchar *str_str (text, pattern)
- X char *text;
- X char *pattern;
- X{
- X register unsigned char *p, *t;
- X register int i, p1, j, *delta;
- X int deltaspace[256];
- X int patlen;
- X int textlen;
- X
- X textlen= strlen (text);
- X patlen = strlen (pattern);
- X
- X /* algorithm fails if pattern is empty */
- X if ((p1 = patlen) == 0)
- X return (text);
- X
- X /* code below fails (whenever i is unsigned) if pattern too long */
- X if (p1 > textlen)
- X return (NULL);
- X
- X /* set up deltas */
- X delta = deltaspace;
- X for (i = 0; i <= 255; i++)
- X delta[i] = p1;
- X for (p = (unsigned char *) pattern, i = p1; --i > 0;)
- X delta[*p++] = i;
- X
- X /*
- X * From now on, we want patlen - 1.
- X * In the loop below, p points to the end of the pattern,
- X * t points to the end of the text to be tested against the
- X * pattern, and i counts the amount of text remaining, not
- X * including the part to be tested.
- X */
- X p1--;
- X p = (unsigned char *) pattern + p1;
- X t = (unsigned char *) text + p1;
- X i = textlen - patlen;
- X for (;;) {
- X if (*p == *t && memcmp((p - p1), (t - p1), p1) == 0)
- X return ((char *)t - p1);
- X j = delta[*t];
- X if (i < j)
- X break;
- X i -= j;
- X t += j;
- X }
- X return (NULL);
- X}
- X
- X
- Xvoid make_lower (s, t)
- X char *s;
- X char *t;
- X{
- X
- X while (*s) {
- X if (isupper(*s))
- X *t = tolower(*s);
- X else
- X *t = *s;
- X s++;
- X t++;
- X }
- X *t = 0;
- X}
- SHAR_EOF
- $TOUCH -am 0822103791 search.c &&
- chmod 0600 search.c ||
- echo "restore of search.c failed"
- set `wc -c search.c`;Wc_c=$1
- if test "$Wc_c" != "7656"; then
- echo original size 7656, current size $Wc_c
- fi
- # ============= select.c ==============
- echo "x - extracting select.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > select.c &&
- X/*
- X * Project : tin - a visual threaded usenet newsreader
- X * Module : select.c
- X * Author : R.Skrenta / I.Lea
- X * Created : 01-04-91
- X * Updated : 20-08-91
- X * Release : 1.0
- X * Notes :
- X * Copyright : (c) Copyright 1991 by Rich Skrenta & Iain Lea
- X * You may freely copy or redistribute this software,
- X * so long as there is no profit made from its use, sale
- X * trade or reproduction. You may not change this copy-
- X * right notice, and it must be included in any copy made
- X */
- X
- X#include "tin.h"
- X
- X
- Xint first_group_on_screen;
- Xint last_group_on_screen;
- Xint cur_groupnum = 0;
- Xint reread_active_file = TRUE;
- Xextern int index_point;
- Xint space_mode;
- Xextern char cvers[LEN+1];
- X
- X
- X#ifdef SIGTSTP
- Xvoid select_susp (sig)
- X int sig;
- X{
- X
- X Raw(FALSE);
- X putchar('\n');
- X signal(SIGTSTP, SIG_DFL);
- X#ifdef BSD
- X sigsetmask(sigblock(0) & ~(1 << (SIGTSTP -1)));
- X#endif
- X kill(0, SIGTSTP);
- X
- X signal(SIGTSTP, select_susp);
- X
- X if (! update) {
- X Raw(TRUE);
- X }
- X
- X#ifndef USE_CLEARSCREEN
- X ClearScreen ();
- X#endif
- X mail_setup();
- X group_selection_page();
- X}
- X#endif
- X
- X
- Xvoid selection_index()
- X{
- X char ch;
- X int i, n;
- X int subscribe_num;
- X char buf[LEN+1];
- X
- X group_selection_page (); /* display group selection page */
- X
- X while (1) {
- X ch = ReadCh();
- X
- X if (ch > '0' && ch <= '9') {
- X prompt_group_num(ch);
- X } else switch (ch) {
- X case '!':
- X shell_escape();
- X group_selection_page();
- X break;
- X
- X case '$': /* show last page of groups */
- Xend_of_list:
- X cur_groupnum = local_top - 1;
- X group_selection_page();
- X break;
- X
- X case '/': /* search forward */
- X case '?': /* search backward */
- X i = (ch == '/');
- X search_group (i);
- SHAR_EOF
- echo "End of tin part 6"
- echo "File select.c is continued in part 7"
- echo "7" > shar3_seq_.tmp
- exit 0
-
- --
- NAME Iain Lea
- EMAIL norisc!iain@estevax.UUCP ...!unido!estevax!norisc!iain
- SNAIL Siemens AG, AUT 922C, Postfach 4848, Nuernberg, Germany
- PHONE +49-911-895-3853, +49-911-895-3877, +49-911-331963
-