?? RIGHT := 110 ??
?? TITLE := 'NOS/VE Broken_Job Dump_Task' ??
MODULE osm$broken_job_dump_task;
?? PUSH (LISTEXT := ON) ??
*copyc amt$term_option
*copyc oss$job_paged_literal
*copyc pfe$error_condition_codes
*copyc pmt$program_parameters
*copyc syc$monitor_request_codes
*copyc tmc$wait_times
?? POP ??
?? NEWTITLE := '  External procedures and variables referenced in this module', EJECT ??
*copyc amp$close
*copyc amp$file
*copyc amp$get_segment_pointer
*copyc amp$open
*copyc amp$put_next
*copyc amp$put_partial
*copyc amp$return
*copyc amp$set_segment_eoi
*copyc clp$scan_command_line
*copyc i#move
*copyc osp$dump_broken_task
*copyc osp$generate_log_message
*copyc pfp$define
*copyc pmp$log
*copyc pmp$wait
*copyc tmp$set_task_priority
*copyc jmv$executing_within_system_job
*copyc osv$debugger_output_disposition
?? OLDTITLE ??
?? NEWTITLE := '  CONST definitions used in this module', EJECT ??
  CONST
    pfn = 'broken_job_pfn_lfn             ',
    lfn = 'broken_job_data_scratch        ';

?? OLDTITLE ??
?? NEWTITLE := '  OSP$BROKEN_JOB_DUMP_TASK', EJECT ??
  PROCEDURE [XDCL, #GATE] osp$broken_job_dump_task
    (    p: pmt$program_parameters;
     VAR status: ost$status);

    VAR
      command_line: string (90),
      dump_in_progress: boolean,
      ignore_status: ost$status,
      lfn_fid: amt$file_identifier,
      pa: ^array [1 .. 0fffffff(16)] of 0 .. 0ff(16),
      pfsp: amt$segment_pointer,
      pfn_fid: amt$file_identifier,
      total: integer;

    IF NOT jmv$executing_within_system_job THEN
      RETURN;
    IFEND;

    amp$return (lfn, status);
    amp$open (lfn, amc$segment, NIL, lfn_fid, status);
    IF NOT status.normal THEN
      osp$generate_log_message($pmt$ascii_logset[pmc$system_log,pmc$job_log], status, ignore_status);
      RETURN;
    IFEND;
    amp$get_segment_pointer (lfn_fid, amc$cell_pointer, pfsp, status);
    IF NOT status.normal THEN
      osp$generate_log_message($pmt$ascii_logset[pmc$system_log,pmc$job_log], status, ignore_status);
      RETURN;
    IFEND;

  /wait_for_broken_task/
    WHILE TRUE DO
      total := 0;
      REPEAT
        osp$dump_broken_task (pfsp.cell_pointer, dump_in_progress, total);
      UNTIL NOT dump_in_progress;
      IF total = 0 THEN
        pmp$wait (tmc$infinite_wait, tmc$infinite_wait);
        CYCLE /wait_for_broken_task/;
      ELSE
        pa := pfsp.cell_pointer;
        pfsp.cell_pointer := #LOC (pa^ [total]);
        amp$set_segment_eoi (lfn_fid, pfsp, status);
        pfsp.cell_pointer := pa;
        create_dump_file (pfn_fid, status);
        IF NOT status.normal THEN
          osp$generate_log_message($pmt$ascii_logset[pmc$system_log,pmc$job_log],status,ignore_status);
          CYCLE /wait_for_broken_task/;
        IFEND;
        copy_dump (pa, pfn_fid, total, status);
        IF NOT status.normal THEN
          osp$generate_log_message($pmt$ascii_logset[pmc$system_log,pmc$job_log], status,ignore_status);
          CYCLE /wait_for_broken_task/;
        IFEND;
        pmp$log (' **** BROKEN TASK DUMPED **** ', status);
        amp$close (pfn_fid, status);

        IF osv$debugger_output_disposition.output_destination = syc$dod_write_for_print THEN
          clp$scan_command_line ('$SYSTEM.PRIF $LOCAL.BROKEN_JOB_PFN_LFN', status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;

        IF osv$debugger_output_disposition.output_destination = syc$dod_save_on_pf THEN
          clp$scan_command_line ('$SYSTEM.CREC $SYSTEM.DUMPS', status);
          IF (NOT status.normal) AND (status.condition <> pfe$name_already_subcatalog) THEN
            clp$scan_command_line ('$SYSTEM.PRIF $LOCAL.BROKEN_JOB_PFN_LFN', ignore_status);
            RETURN;
          IFEND;

{!       '$SYSTEM.COPF $LOCAL.BROKEN_JOB_PFN_LFN $SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000.$NEXT
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.COPF $LOCAL.BROKEN_JOB_PFN_LFN $SYSTEM.DUMPS.DEBUG_OF_';
          command_line (63, *) := osv$debugger_output_disposition.job_and_file_name;
          command_line (82, *) := '.$NEXT';
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            clp$scan_command_line ('$SYSTEM.PRIF $LOCAL.BROKEN_JOB_PFN_LFN', ignore_status);
            RETURN;
          IFEND;

{!       '$SYSTEM.CHAFA RA=(11 11 11) F=$SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.CHAFA RA=(11 11 11) F=$SYSTEM.DUMPS.DEBUG_OF_';
          command_line (54, *) := osv$debugger_output_disposition.job_and_file_name;
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

{!       '$SYSTEM.CHACE NR=14 F=$SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.CHACE NR=14 F=$SYSTEM.DUMPS.DEBUG_OF_';
          command_line (46, *) := osv$debugger_output_disposition.job_and_file_name;
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;

        IF osv$debugger_output_disposition.output_destination = syc$dod_save_and_print THEN

          clp$scan_command_line ('$SYSTEM.PRIF $LOCAL.BROKEN_JOB_PFN_LFN', status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

          clp$scan_command_line ('$SYSTEM.CREC $SYSTEM.DUMPS', status);
          IF (NOT status.normal) AND (status.condition <> pfe$name_already_subcatalog) THEN
            RETURN;
          IFEND;

{!       '$SYSTEM.COPF $LOCAL.BROKEN_JOB_PFN_LFN $SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000.$NEXT'
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.COPF $LOCAL.BROKEN_JOB_PFN_LFN $SYSTEM.DUMPS.DEBUG_OF_';
          command_line (63, *) := osv$debugger_output_disposition.job_and_file_name;
          command_line (82, *) := '.$NEXT';
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            clp$scan_command_line ('$SYSTEM.PRIF $LOCAL.BROKEN_JOB_PFN_LFN', ignore_status);
            RETURN;
          IFEND;

{!       '$SYSTEM.CHAFA RA=(11 11 11) F=$SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.CHAFA RA=(11 11 11) F=$SYSTEM.DUMPS.DEBUG_OF_';
          command_line (54, *) := osv$debugger_output_disposition.job_and_file_name;
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

{!       '$SYSTEM.CHACE NR=14 F=$SYSTEM.DUMPS.DEBUG_OF_$0000_0000_AAA_0000
{!        1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
{!                 1         2         3         4         5         6         7         8         9         0
          command_line := ' ';
          command_line (1, *) := '$SYSTEM.CHACE NR=14 F=$SYSTEM.DUMPS.DEBUG_OF_';
          command_line (46, *) := osv$debugger_output_disposition.job_and_file_name;
          clp$scan_command_line (command_line, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;

        amp$return (pfn, status);
      IFEND;
    WHILEND /wait_for_broken_task/;

  PROCEND osp$broken_job_dump_task;
?? OLDTITLE ??
?? NEWTITLE := '  CREATE_DUMP_FILE', EJECT ??
  PROCEDURE create_dump_file (VAR fid: amt$file_identifier;
    VAR status: ost$status);


    VAR
      file_attrs: ^amt$file_attributes;

    PUSH file_attrs: [1 .. 1];
    file_attrs^ [1].key := amc$file_contents;
    file_attrs^ [1].file_contents := 'LIST';
    amp$file (pfn, file_attrs^, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
    amp$open (pfn, amc$record, NIL, fid, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
  PROCEND create_dump_file;
?? OLDTITLE ??
?? NEWTITLE := '  COPY_DUMP', EJECT ??
  PROCEDURE copy_dump (p: ^array [1 .. 00fffffff(16)] OF 0 .. 0ff(16);
        fid: amt$file_identifier;
        total: integer;
    VAR status: ost$status);

    VAR
      current: integer,
      ll: 0 .. 0ffff(16),
      len: 0 .. 0ffff(16),
      c: ^char,
      blank: string (130),
      page: string (60),
      pcount: integer,
      leng: integer,
      heading: string (60),
      sp: string (1),
      hd: string (1),
      count: integer,
      bad: amt$file_byte_address;

    current := 0;
    count := 0;
    pcount := 0;
    heading := '    ';
    blank := '            ';
    sp := ' ';
    hd := '1';
    WHILE current < total DO
      page := '    ';
      current := current + 1;
      IF p^ [current] = 1 THEN
        i#move (#LOC (p^ [current + 1]), #LOC (len), #SIZE (len));
        current := current + #SIZE (len);
        i#move (#LOC (p^ [current + 1]), #LOC (heading), len);
        current := current + len;
        pcount := pcount + 1;
        STRINGREP (page, leng, '                           PAGE', pcount: 5);
        amp$put_partial (fid, #LOC (hd), #SIZE (hd), bad, amc$start, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        amp$put_partial (fid, #LOC (heading), len, bad, amc$continue, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        amp$put_partial (fid, #LOC (page), #SIZE (page), bad, amc$terminate,
         status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        amp$put_next (fid, #LOC (blank), #SIZE (blank), bad, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        count := 0;
      ELSE

        IF (count = 60) THEN
          pcount := pcount + 1;
          STRINGREP (page, leng, '                           PAGE', pcount: 5);
          amp$put_partial (fid, #LOC (hd), #SIZE (hd), bad, amc$start, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          amp$put_partial (fid, #LOC (heading), len, bad, amc$continue,
                status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          amp$put_partial (fid, #LOC (page), #SIZE (page), bad, amc$terminate,
                status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          amp$put_next (fid, #LOC (blank), #SIZE (blank), bad, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          count := 0;
        IFEND;

        i#move (#LOC (p^ [current + 1]), #LOC (ll), #SIZE (ll));
        current := current + #SIZE (ll);
        c := #LOC (p^ [current + 1]);
        IF (c^ <> ' ') THEN
          amp$put_partial (fid, #LOC (sp), #SIZE (sp), bad, amc$start, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          amp$put_partial (fid, #LOC (p^ [current + 1]), ll, bad,
                amc$terminate, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          current := current + ll;
          count := count + 1;
        ELSE

          amp$put_next (fid, #LOC (p^ [current + 1]), ll, bad, status);
          current := current + ll;
          count := count + 1;
        IFEND;

        IF NOT status.normal THEN
          RETURN;
        IFEND;

      IFEND;

    WHILEND;

  PROCEND copy_dump;
?? OLDTITLE, OLDTITLE ??
MODEND osm$broken_job_dump_task
