PMDF Programmer's Reference Manual


Previous Next Contents Index

2.5.4 Using an Input Procedure

The programs shown in Examples 2-11 and 2-12 use an input procedure as the source for the body of a message to be sent. In the Pascal program example, the procedure msg_proc will continue to read input until a blank line is entered at which point the message will be sent. In the C program example, the input proocedure msg_proc will read input until the run-time library routine fgets() signals an EOF (e.g., a control-Z has been input). In both programs, the address of the procedure msg_proc is passed to PMDF_send via a PMDF_MSG_PROC item code and PMDF_send itself repeatedly calls the procedure until a value of 0 is returned by the procedure.

Example 2-11 Using an Input Procedure (Pascal)

(* send_example7.pas -- Demonstrate the use of PMDF_MSG_PROC *) 
 
[inherit ('pmdf_exe:apidef')] program send_example7 (input, output); 
 
  type 
   string     = varying [ALFA_SIZE] of char; 
   string_ptr = ^string; 
 
  var 
    item_index : integer := 0; 
    item_list  : array [1..4] of PMDF_item_list; 
    subject    : string := 'PMDF callable SEND example'; 
    to_adr     : string := 'system'; 
 
function SYS$EXIT (%immed status   : integer := %immed 1)   : integer; extern; 
 
(* Push an entry onto the item list *) 
procedure push (code : integer; adr : unsigned; len : integer); 
 
  begin (* push *) 
    item_index := succ (item_index); 
    with item_list[item_index] do begin 
      item_code    := code; 
      item_address := adr::$stringptr; 
      item_length  := len; 
    end; (* with *) 
  end; (* push *) 
 
function msg_proc (var str_i : integer; var str_len : integer) : integer; 
 
  type 
    chars    = packed array [1..BIGALFA_SIZE] of char; 
    char_ptr = ^chars; 
 
  var 
    buffer : string; 
    i      : integer; 
    str    : char_ptr; 
 
  begin (* msg_proc *) 
    write ('input: '); 
    readln (buffer); 
    if buffer.length = 0 then begin 
      str_len  := 0; 
      msg_proc := 0; 
    end else begin 
      str := (iaddress (str_i))::char_ptr; 
      str_len := min (buffer.length, str_len); 
      for i := 1 to str_len do str^[i] := buffer[i]; 
      msg_proc := 1; 
    end; (* if *) 
  end; (* msg_proc *) 
 
begin (* send_example7 *) 
  push (PMDF_SUBJECT,  iaddress (subject.body),  subject.length); 
  push (PMDF_TO,       iaddress (to_adr.body),   to_adr.length); 
  push (PMDF_MSG_PROC, iaddress (msg_proc),      4); 
  push (PMDF_END_LIST, 0,                        0); 
  SYS$EXIT (PMDF_send ((iaddress (item_list))::PMDF_item_list_ptr)); 
end. (* send_example7 *) 

Example 2-12 Using an Input Procedure (C)

/* send_example8.c -- Demonstrate the use of PMDF_MSG_PROC */ 
 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#ifdef __VMS 
#include "pmdf_com:apidef.h" 
#else 
#include "/pmdf/include/apidef.h" 
#endif 
 
/* Push an entry onto the item list */ 
#define ITEM(item,adr,len) item_list[item_index].item_code    = (item);        \
                           item_list[item_index].item_address = (char *)(adr); \
                           item_list[item_index].item_length  = (len);         \
                           item_index++ 
 
int msg_proc (char *str, int *str_len) 
{ 
        printf ("input: "); 
        if (fgets (str, *str_len, stdin)) { 
          *str_len = strlen (str); 
          if (str[*str_len-1] == '\n') *str_len -= 1; 
          return (1); 
        } 
        else { 
          *str_len = 0; 
          return (0); 
        } 
} 
 
main () 
{ 
        int istat, item_index = 0; 
        PMDF_item_list item_list[4]; 
        char *subject = "PMDF callable SEND example"; 
#ifdef _VMS 
        char *to_adr  = "system"; 
#else 
        char *to_adr  = "root"; 
#endif 
 
        if (!(1 & (istat = PMDFinitialize (0)))) exit (istat); 
        ITEM (PMDF_SUBJECT,  subject,  strlen (subject)); 
        ITEM (PMDF_TO,       to_adr,   strlen (to_adr)); 
        ITEM (PMDF_MSG_PROC, msg_proc, 4); 
        ITEM (PMDF_END_LIST, 0,        0); 
        exit (PMDF_send (item_list)); 
} 


Previous Next Contents Index