#include #include "infodefs.h" #define RMS$_EOF 0x0001827A int term=0, indexed_file=0, ioflag, inlength; char term_buf[132]; /* Function to return the number of input characters last */ /* obtained from reading a particular file. */ int input_count( int file_variable ) { int num_chars_read; /* Utilizing the file information subroutine RMS_INFO, */ /* Get "RSZ" from the RAB of file that did the read */ rms_info( file_variable, RMS__RSZ, &num_chars_read); return num_chars_read; } int odd(int ioflag) { return (ioflag & 1); } void file_error( int *file_id, int *status) { print_file_info(*file_id); exit(*status); } void dump_the_file() { int input_status; /* Rewind the indexed file */ rms_rewind( ifi_( &indexed_file ), krf_(0), err_(file_error) ); /* Tell user sorted output is coming. */ rms_putseq( term, "Sorted Output...", 16); input_status = 1; /* Read records from indexed file and print on terminal */ while (odd(input_status)) { input_status = rms_getseq( indexed_file, term_buf, sizeof(term_buf)); inlength = input_count( indexed_file ); if (inlength > 0) rms_put( ifi_(&term), rbf_(term_buf), rsz_(inlength) ); } } /* main program */ main() { /* Define the key for the file */ rms_keydef( ifi_( &indexed_file ), ref_(0), siz_(32), dtp_("stg"), flg_("dup") ); /* Define the FAB */ rms_fabdef( ifi_( &indexed_file ), fnm_("example.dat"), org_("idx"), rat_("cr"), fop_("mxv"), fac_("put,get") ); /* Create the file. Specify protection and Expiration */ /* date and time. */ rms_create( ifi_( &indexed_file ), xabpro_( pro_( "s:r,o:rwed,g,w" )), xabdat_( edt_( "30-JUN-1995" )), err_(file_error) ); /* Open sys$input/sys$output (the terminal) */ rms_open( ifi_( &term ), fnm_("tt"), fac_("put,get"), rat_("cr"), err_(file_error) ); /* Tell the user what to do */ fprintf(stderr, "Enter lines of text, each at least 8 characters long.\n"); fprintf(stderr,"Type control-z when you are done ...\n"); /* Fill up the indexed file with term input */ ioflag=1; while (odd(ioflag)) { /* Read from terminal */ ioflag = rms_getseq( term, term_buf, sizeof(term_buf)); /* Write the record to disk file if terminal read */ /* was successful. */ if (odd(ioflag) ) rms_put( ifi_( &indexed_file ), rbf_(term_buf), rsz_( input_count( term )), rac_("key"), err_(file_error) ); else if (ioflag == RMS$_EOF) dump_the_file(); else print_file_info(term); } exit(1); }