+-+-+-+ Beginning of part 8 +-+-+-+
X`009    2L, 0L, 0, PRC$M_DETACH `124 PRC$M_NOUAF);
X
X    if (status != SS$_NORMAL) `123
X`009report_error("Sys$Creprc failed", status);
X    `125
X
X    /* And reset everything to "nothing to write out" */
X
X    timer_reset();`009`009`009/* Kick the timer */
X
X    new_count = 0;`009`009`009/* Nothing unwritten */
X`125
X
X/* Open the .COM file for writing new stuff */
X
XFILE * com_open(void)
X`123
X    SYSTIM cur_time;
X    struct $NUMTIM t;
X
X    /* Are we opening this for the first time? */
X
X    if (!new_count) `123
X
X`009/* Get time information to build the file name */
X
X`009get_time(cur_time);
X`009get_numtim(&t, cur_time);
X
X`009/* So, now build the file name */
X
X`009sprintf(com_fn, "%sNOTERUN-%04d-%04d%04d.COM",
X`009`009scratch_dir.dsc$a_pointer, t.month * 100 + t.day,
X`009`009t.hour * 100 + t.minute, t.second * 100 + t.h_second);
X
X#ifdef DEBUG
X`009strcpy(log_fn, com_fn);
X
X`009log_fn[strlen(log_fn)-4] = '\0';
X`009strcat(log_fn, ".LOG");
X#endif
X
X`009/* Open it for initial commands */
X
X`009com_file = fopen(com_fn, "w", "ctx=rec", "rat=cr", "rfm=var");
X`009fputs("$ define notes$command nl:\n", com_file);
X`009fprintf(com_file, "$ define notes$notebook %snotes$notebook.note\n",
X`009`009root_dir.dsc$a_pointer);
X`009fprintf(com_file, "$ define sys$scratch bboard_scratch_dir\n");
X`009fprintf(com_file, "$ setuname :== $%sSETUNAME.EXE\n",
X`009`009root_dir.dsc$a_pointer);
X`009fputs("$ oldname == f$getjpi(\"\",\"USERNAME\")\n", com_file);
X
X`009/* Haven't used SETUNAME yet */
X
X`009setuname_used = FALSE;
X
X    `125 else `123
X
X`009/* Just open the file, otherwise */
X
X`009com_file = fopen(com_fn, "a+");
X
X    `125
X    return(com_file);
X`125
X
X/* Close the .COM file and update the un-written note count */
X
Xvoid com_close(int upd_count)
X`123
X    /* Close the file first off */
X
X    fclose(com_file);
X
X    /* Update the un-written note count */
X
X    if (upd_count < 0) `123
X`009new_count = upd_count;
X    `125 else if (upd_count > 0) `123
X`009if (new_count >= 0) `123
X`009    new_count += upd_count;
X`009`125
X    `125
X`125
X
X/* Check if there's another posting job running */
X
Xint post_job_running(void)
X`123
X    long context;`009`009`009/* What PID are we talking about */
X    static char prcnam[16];`009`009/* Place to stuff the process name */
X    static long job_type;`009`009/* What job type? */
X    static struct itm_lst `123
X`009short buf_len;
X`009short item_code;
X`009void * buffer;
X`009long * ret_len_addr;
X    `125 item_list[3] = `123
X`009`123 15, JPI$_PRCNAM, prcnam, 0`125,
X`009`123 sizeof(job_type), JPI$_JOBTYPE, &job_type, 0`125,
X`009`123 0, 0`125
X    `125;
X
X    context = -1L;
X
X    while (TRUE) `123`009`009`009/* Search through all of them */
X`009status = sys$getjpiw(0, &context, 0, item_list, 0, 0, 0);
X`009if (status == SS$_NOPRIV `124`124 status == SS$_SUSPENDED) `123
X`009    continue;
X`009`125
X`009if (status == SS$_NOMOREPROC `124`124 !(status & 1)) `123
X`009    break;
X`009`125
X`009if (job_type) `009`009`009continue;
X`009if (strncmp(prcnam, "BB_Post_", 8))`009continue;
X`009return (TRUE);
X    `125
X    return (FALSE);
X`125
$ GOSUB UNPACK_FILE

$ FILE_IS = "DIGEST.C"
$ CHECKSUM_IS = 1715425472
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X#include <stdio.h>
X#include <string.h>
X#include <ctype.h>
X#include <descrip.h>
X#include "bboard.h"
X
X#define SEPARATOR "\xff"
X
Xstatic void dig_build_topic(FILE * note, FILE * com_file, struct list_info *
X`009list, char * subj);
Xstatic int dig_build_reply(FILE * note, FILE * com_file, struct list_info *
X`009list, int cur_count);
Xstatic void dig_kill_files(FILE * com_file);
Xstatic void new_dlg_fn(char * name, char * conf, int count);
Xstatic void copy_with_scan(FILE * o, FILE * i, int trg, int err, char
X`009scan_char);
X
Xstatic char * files_to_del;
X
Vvoid digest_run(FILE * note, struct rule_info * rule, struct list_info * list
X)
X`123
X    char * top_subj;`009`009`009/* Topic subject */
X    FILE * com_file;`009`009`009/* Command file */
X    int i;`009`009`009`009/* Counter for text files */
X
X    /* Get the subject for the topic */
X
X    top_subj = find_source(rule->id_subj);
X#ifdef DEBUG
X    printf("digest_run: top_subj = %ld\n", top_subj);
X    if (top_subj) `123
X`009printf("digest_run: top_subj = >%s<\n", top_subj);
X    `125
X#endif
X
X    if (!top_subj)`009`009`009top_subj = "";
X    subj_text_fondle(top_subj);
X
X    /* Open the command file */
X
X    com_file = com_open();
X
X    /* Need a string for text files that we need to delete */
X
X    files_to_del = xmalloc(10000);
X
X    /* Set the name and jump into Notes */
X
X    if (list->conf_user[0]) `123
X`009fprintf(com_file, "$ setuname %s\n", list->conf_user);
X`009setuname_used = TRUE;
X    `125
X
X    fprintf(com_file, "$ notes/nonotebook 0::%s\n", list->conf_name);
X    fputs("set moderator\n", com_file);
X
X    /* Build the topic, first off */
X
X    dig_build_topic(note, com_file, list, top_subj);
X
X    /* Now on to the serious stuff... */
X    /* Do it until we fall off the end... */
X
X    for (i = 1; !feof(note); i++) `123
X
X`009/* See if we've received any interactive messages to fondle. */
X
X`009process_message();
X
X`009/* Now go build another reply */
X
X`009if (!dig_build_reply(note, com_file, list, i)) `123
X`009    break;
X`009`125
X    `125
X
X    /* Close up time */
X
X    fputs("exit\n", com_file);
X
X    /* Build commands to delete files */
X
X    dig_kill_files(com_file);
X
X    /* Lose the allocated memory */
X
X    xfree(files_to_del);
X
X    /* And we've added a lot of notes */
X
X    com_close(i+1);
X`125
X
X/* Build the initial topic for a new digest */
X
Xstatic void dig_build_topic(FILE * note, FILE * com_file, struct list_info *
X`009list, char * subj)
X`123
X    char text_fn[200];`009`009`009/* File name of file to write to */
X    FILE * text_file;
X
X    /* Open the topic text file */
X
X    new_dlg_fn(text_fn, list->conf_name, 0);
X    text_file = fopen(text_fn, "w", "ctx=rec", "rat=cr", "rfm=var");
X
X    /* Copy until we get to the divider */
X
X    copy_with_scan(text_file, note, 70, 11, '-');
X
X    fclose(text_file);
X
X    /* Start generating commands */
X
X    fputs("set prof/temp/pers=\"Notes Poster Daemon\"\n", com_file);
X    fprintf(com_file, "write/noed %s\n", text_fn);
X    fprintf(com_file, "%s\n", subj);
X    fputs("yes\n", com_file);
X
X    /* Need to delete the text file */
X
X    strcpy(files_to_del, text_fn);
X    strcat(files_to_del, SEPARATOR);
X`125
X
X/* We'll hold onto the header information here... */
X
X#define SUBJ_LEN 99
X#define FROM_LEN 255
X#define END_LEN 80
X
Xstatic char subj_text[SUBJ_LEN+SLOP_LEN];
Xstatic char from_text[FROM_LEN+SLOP_LEN];
Xstatic char end_text[END_LEN+SLOP_LEN];
X
X/* Header information to pull in */
X
Xstatic struct source_info dig_src[] = `123
X    `123 "SB", "subject:", SUBJ_LEN, subj_text `125,
X    `123 "FR", "from:",    FROM_LEN, from_text `125,
X    `123 "EN", "end of ",  END_LEN,  end_text `125,
X    `123 "",   "",         0,   NULL`125
X`125;
X
X/* Build an individual reply */
X
Xstatic int dig_build_reply(FILE * note, FILE * com_file, struct list_info *
X`009list, int cur_count)
X`123
X    char text_fn[200];`009`009`009/* File name of text file */
X    FILE * text_file;
X    int trig_level;
X    int error_level;
X
X    /* Fill in the header information */
X
X    scan_header(note, dig_src);
X
X    /* Did we reach the "End of ...." message? */
X
X    if (end_text[0] && !subj_text[0] && !from_text[0]) `123
X`009return (FALSE);
X    `125
X
X    /* Fix the From and Subj lines */
X
X#ifdef DEBUG
X    printf("Digest: From = >%s<\n", from_text);
X    printf("Digest: Subject = >%s<\n", subj_text);
X#endif
X
X    from_text_fondle(from_text);
X    subj_text_fondle(subj_text);
X
X#ifdef DEBUG
X    printf("Digest: Fondled from = >%s<\n", from_text);
X    printf("Digest: Fondled subj = >%s<\n", subj_text);
X#endif
X
X    /* Time to build a new text file */
X
X    new_dlg_fn(text_fn, list->conf_name, cur_count);
X    text_file = fopen(text_fn, "w", "ctx=rec", "rat=cr", "rfm=var");
X
X    /* Figure out what we need to look for */
X
V    if (!digest_find(list->new_topic_interval, &trig_level, &error_level)) `1
X23
X`009trig_level = 30;`009`009/* If not found, use defaults */
X`009error_level = 1;
X    `125
X
X    /* Now copy over the text */
X
X    copy_with_scan(text_file, note, trig_level, error_level, '-');
X
X    fclose(text_file);
X
X    /* Now let's build the appropriate commands */
X
X    fprintf(com_file, "set prof/temp/pers=\"%s\"\n", from_text);
X    fprintf(com_file, "reply/noed %s\n", text_fn);
X    fprintf(com_file, "%s\n", subj_text);
X    fputs("yes\n", com_file);
X
X    /* Need to delete the text file */
X
X    strcat(files_to_del, text_fn);
X    strcat(files_to_del, SEPARATOR);
X
X    /* Yes, we really did something */
X
X    return (TRUE);
X`125
X
X/* Write commands to delete all of the text files that we came up with */
X
Xstatic void dig_kill_files(FILE * com_file)
X`123
X    char * next_file;
X
X    /* Start searching through the list of files to delete */
X
X    next_file = strtok(files_to_del, SEPARATOR);
X
X    while (next_file) `123
X`009fprintf(com_file, "$ delete %s;*\n", next_file);
X`009next_file = strtok(NULL, SEPARATOR);
X    `125;
X`125
X
X/* Build a filename for a digest text file */
X
Xstatic void new_dlg_fn(char * name, char * conf, int count)
X`123
X    SYSTIM cur_time;
X    struct $NUMTIM t;
X
X    get_time(cur_time);
X    get_numtim(&t, cur_time);
X
X    sprintf(name, "%s%s.%04d-%04d%02d-%d", scratch_dir.dsc$a_pointer, conf,
X`009    t.month * 100 + t.day, t.hour * 100 + t.minute, t.second,
X`009    count);
X`125
X
X/* Copy text until a separator is found */
X
Xstatic void copy_with_scan(FILE * o, FILE * i, int trg, int err,
X`009char scan_char)
X`123
X    int cur_count;`009`009`009/* How many found? */
X    char * t;`009`009`009`009/* Search through separator line */
X
X    while (TRUE) `123
X`009if (!fgets(temp, 255, i)) `123`009/* Got a line? */
X`009    return;`009`009`009/* Nope, it's all over... */
X`009`125
X
X`009/* Might we have found a separator? */
X
X`009if (temp[0] == scan_char) `123
X
X`009    /* We don't want trailing blanks */
X
X`009    strcpy(temp+256, temp);
X`009    trim_end(temp+256);
X
X`009    /* How many contiguous characters are there? */
X
X`009    for (cur_count = 0, t = temp+256; *t == scan_char; t++, cur_count++);
X
X`009    /* Is there anything after the contiguous scan_char's? */
X
X`009    if (*t && *t != '\n') `123
X`009`009goto copy_with_scan_write;
X`009    `125
X
X`009    /* Did we find enough? */
X
X`009    if ((cur_count >= trg-err) && (cur_count <= trg+err)) `123
X`009`009return;
X`009    `125
X`009`125
X    copy_with_scan_write:
X`009fputs(temp, o); `009`009/* And, finally, write it out. */
X    `125
X`125
$ GOSUB UNPACK_FILE

$ FILE_IS = "HOOKS.C"
$ CHECKSUM_IS = 1448206857
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X#include <descrip.h>
X#include <stdio.h>
X#include "bboard.h"
X
Xstatic struct `123 `009`009`009/* Used in all of the GETJNI() calls */
X    char n_name[9];
X    char l_name[9];
X    char l_daemon[33];
X    char ln_name[9];
X    int node_type;
X    int link_pid;
X    int link_status;
X    int link_qcnt;
X    int line_status;
X    int line_tot;
X    int line_err;
X    int line_tmo;
X    int context;
X    int mask;
X`125 jinf;
X
Xstatic int init = 0;`009`009`009/* Flag for use of rou_init_route() */
X
X/* Descriptors for buffers */
X
Xstatic struct dsc$descriptor_s
X    node_name`009= `123 8, DSC$K_DTYPE_T, DSC$K_CLASS_S, &jinf.n_name`125,
X    link_daemon = `12332, DSC$K_DTYPE_T, DSC$K_CLASS_S, &jinf.l_daemon`125,
X    line_name`009= `123 8, DSC$K_DTYPE_T, DSC$K_CLASS_S, &jinf.ln_name`125;
X
X
X/* Check if the hook already in use? */
X
Xint check_for_hook(char * hook)
X`123
X    static struct dsc$descriptor_s
X`009link_name   = `123 8, DSC$K_DTYPE_T, DSC$K_CLASS_S, &jinf.l_name`125;
X
X    jinf.context = -1;`009`009`009/* Unknown */
X    jinf.mask = 0x0a;`009`009`009/* Want LINKs and HOOKs */
X
X    if (init++ == 0) `123`009`009`009/* First time through */
X`009status = rou_init_route();
X#ifdef`009DEBUG
X`009printf("rou_init_route() = %08X\n", status);
X#endif`009/* DEBUG */
X    `125
X
X    strupr(strcpy(temp, hook)); `009/* Need it uppercase and temporary */
X
X    /* Do it to it */
X
X#ifdef`009DEBUG
X`009printf("nodename t linkname linkpid  s linkdaem linename\n");
X`009printf("-------- - -------- -------- - -------- --------\n");
X#endif`009/* DEBUG */
X
X    while (rou_getjni(&jinf.context, &jinf.mask, &node_name, &jinf.node_type,
X`009    &link_name, &jinf.link_pid, &jinf.link_status, &jinf.link_qcnt,
X`009    &link_daemon, &line_name, &jinf.line_status, &jinf.line_tot,
X`009    &jinf.line_err, &jinf.line_tmo) & 1) `123
X
X#ifdef`009DEBUG
X`009jinf.n_name[8]='\0';
X`009jinf.l_name[8]='\0';
X`009jinf.l_daemon[8]='\0';
X`009jinf.ln_name[8]='\0';
X
X`009printf("%8s %1d %8s %08X %1d %8s %8s\n", jinf.n_name, jinf.node_type,
X`009    jinf.l_name, jinf.link_pid, jinf.link_status, jinf.l_daemon,
X`009    jinf.ln_name);
X#endif`009/* DEBUG */
X
X`009/* Did we find it? */
X
X`009if (!strncmp(temp, strupr(jinf.l_name), strlen(temp))) `123
X`009    return (TRUE);
X`009`125
X    `125
X    return (FALSE);
X`125
X
X/* What's the name of the host? */
X
Xvoid load_host_name(char * host)
X`123
X    static struct dsc$descriptor_s link_name;
X
X    jinf.context = -1;`009`009`009/* Unknown */
X    jinf.mask = 0x01;`009`009`009/* Want HOST information */
X
X    if (init++ == 0) `123`009`009`009/* First time through */
X`009status = rou_init_route();
X#ifdef`009DEBUG
X`009printf("rou_init_route() = %08X\n", status);
X#endif`009/* DEBUG */
X    `125
X
X    strcpy(host, "--------");           /* Something to initialize */
X    str_desc(&link_name, host); `009/* Build a descriptor */
X
X    /* Get the information */
X
X    rou_getjni(&jinf.context, &jinf.mask, &node_name, &jinf.node_type,
X`009    &link_name, &jinf.link_pid, &jinf.link_status, &jinf.link_qcnt,
X`009    &link_daemon, &line_name, &jinf.line_status, &jinf.line_tot,
X`009    &jinf.line_err, &jinf.line_tmo);
X
X    host[8] = '\0';                     /* Terminate the string */
X    strip(host);`009`009`009/* Remove trailing blanks */
X`125
X
X/* Is everything ready for us to go away? */
X
Xchar * check_links_down(void)
X`123
X    static struct dsc$descriptor_s
X`009link_name   = `123 8, DSC$K_DTYPE_T, DSC$K_CLASS_S, &jinf.l_name`125;
X
X    jinf.context = -1;`009`009`009/* Unknown */
X    jinf.mask = 0x02;`009`009`009/* Want LINKs */
X
X    if (init++ == 0) `123`009`009`009/* First time through */
X`009status = rou_init_route();
X#ifdef`009DEBUG
X`009printf("rou_init_route() = %08X\n", status);
X#endif`009/* DEBUG */
X    `125
X
X    /* Start searching */
X
-+-+-+-+-+ End of part 8 +-+-+-+-+-