Sorry, the previous post of this had the real stuff missing! $! ...................... Cut between dotted lines and save. ..................... $!............................................................................. $! VAX/VMS archive file created by VMS_SHARE V06.03 20-Oct-1988. $! $! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from $! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au). $! $! To unpack, simply save, concatinate all parts into one file and $! execute (@) that file. $! $! This archive was created by user SYSTEM $! on 19-APR-1991 14:15:37.55. $! $! It contains the following 2 files: $! PPROC.C $! PPROC_TEST.C $! $!============================================================================== $ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL ) $ VERSION = F$GETSYI( "VERSION" ) $ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK $ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", - "VMS_SHARE V06.03 20-Oct-1988 requires VMS V4.4 or higher." $ EXIT 44 $VERSION_OK: $ GOTO START $ $UNPACK_FILE: $ WRITE SYS$OUTPUT "Creating ''FILE_IS'" $ DEFINE/USER_MODE SYS$OUTPUT NL: $ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION - VMS_SHARE_DUMMY.DUMMY b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) ); s_file_spec := GET_INFO( COMMAND_LINE, "output_file" );SET( OUTPUT_FILE , b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" );i_errors := 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN & "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; pat_trail := " " & LINE_END;POSITION( BEGINNING_OF( b_part ) ); LOOP b := SEARCH( pat_trail, FORWARD); EXITIF b=0; POSITION( END_OF( b ) ) ; LOOP MOVE_HORIZONTAL( -1 ); EXITIF CURRENT_CHARACTER <> ' '; ERASE_CHARACTER ( 1 ); EXITIF CURRENT_OFFSET=0; ENDLOOP; ENDLOOP; POSITION( BEGINNING_OF ( b_part ) ); i_append_line := 0; LOOP EXITIF MARK( NONE ) = END_OF( b_part ) ; s_x := ERASE_CHARACTER( 1 ); IF s_x = "+" THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip < > 0 THEN s_x := ""; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF; ENDIF; IF s_x = "-" THEN r_skip := SEARCH( pat_end, FORWARD, EXACT ); IF r_skip < > 0 THEN s_x := ""; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip := MARK( NONE ) ; r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip <> 0 THEN POSITION ( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET ); MOVE_VERTICAL( 1 ) ; MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part ) ); ENDIF; ERASE ( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF; IF s_x = "V" THEN s_x := ""; IF i_append_line <> 0 THEN APPEND_LINE; MOVE_HORIZONTAL ( -CURRENT_OFFSET ); ENDIF; i_append_line := 1; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = "X" THEN s_x := ""; IF i_append_line <> 0 THEN APPEND_LINE; MOVE_HORIZONTAL ( -CURRENT_OFFSET ); ENDIF; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> "" THEN i_errors := i_errors + 1; s_text := CURRENT_LINE; POSITION ( b_errors ); COPY_TEXT( "The following line could not be unpacked properly:" ) ; SPLIT_LINE; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ) ; MOVE_VERTICAL( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ) ; ERASE_CHARACTER( 1 ); IF CURRENT_CHARACTER = "`" THEN MOVE_HORIZONTAL( 1 ); ELSE COPY_TEXT( ASCII ( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDIF; ENDLOOP; IF i_errors = 0 THEN SET ( NO_WRITE, b_errors, ON ); ELSE POSITION( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO( "The following !UL errors were detected while unpacking !AS" , i_errors, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" );ENDIF; EXIT; $ DELETE VMS_SHARE_DUMMY.DUMMY;* $ CHECKSUM 'FILE_IS $ WRITE SYS$OUTPUT " CHECKSUM ", - F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!,passed." ) $ RETURN $ $START: $ FILE_IS = "PPROC.C" $ CHECKSUM_IS = 1028300878 $ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY X/* Implement unix popen and pclose in vms by using mailboxes X and lib$spawn. X 17-APR-91 -GJC@MITECH.COM version 1.0 X*/ X X#include X#include X#include X#include X XFILE *popen(); Xint pclose(); X Xglobalvalue CLI$M_NOWAIT; X Xvoid p_describe(); /* a non-unix function */ X Xstatic struct dsc$descriptor *set_dsc_cst(); Xstatic int create_mbx(); X X#define mailbox_size (512) X#define mailbox_byte_quota (3*mailbox_size) X#define mailbox_protection_mask (0x0000F000) X Xstruct popen_cell X`123FILE *fp; X char *mbx_name; X short mbx_chan; X long pid; X long completed; X long comp_status; X struct popen_cell *next; X struct popen_cell *prev;`125; X Xstatic struct popen_cell *popen_list = NULL; X Xstatic struct popen_cell *find_popen_cell(fp) X FILE *fp; X`123struct popen_cell *l; X for(l=popen_list;l != NULL; l = l->next) X if (l->fp == fp) return(l); X return(NULL);`125 X Xvoid p_describe(fp) X FILE *fp; X`123struct popen_cell *cell; X if (!(cell = find_popen_cell(fp))) X `123printf("File pointer is not from popen, or it has been closed\n"); X return;`125 X printf("FILE *fp = %08X\n",cell->fp); X printf("char *mbx_name = %s\n",cell->mbx_name); X printf("short mbx_chan = %d\n",cell->mbx_chan); X printf("long pid = %08X\n",cell->pid); X printf("long completed = %d\n",cell->completed); X printf("long comp_status = %d\n",cell->comp_status); X printf("struct popen_cell *next = %08X\n",cell->next); X printf("struct popen_cell *prev = %08X\n",cell->prev);`125 X Xstatic void proc_exit_ast(cell) X struct popen_cell *cell; X`123cell->completed = 1;`125 X Xstatic void pclose_cleanup(cell) X struct popen_cell *cell; X`123sys$dassgn(cell->mbx_chan); X free(cell->mbx_name); X if (!cell->completed) X sys$delprc(&cell->pid,0); X memset(cell,0,sizeof(struct popen_cell)); X free(cell);`125 X Xstatic void pclose_delq(cell) X struct popen_cell *cell; X`123if (cell->prev) X `123cell->prev->next = cell->next; X if (cell->next) X cell->next->prev = cell->prev;`125 X else X `123popen_list = cell->next; X if (cell->next) X cell->next->prev = NULL;`125`125 X Xstatic void popen_push(cell) X struct popen_cell *cell; X`123if (popen_list) X popen_list->prev = cell; X cell->prev = NULL; X cell->next = popen_list; X popen_list = cell;`125 X Xint pclose(fp) X FILE *fp; X`123int i; X struct popen_cell *cell; X i = fclose(fp); X if (cell = find_popen_cell(fp)) X `123pclose_delq(cell); X pclose_cleanup(cell);`125 X return(i);`125 X XFILE *popen(command,mode) X char *command,*mode; X`123char *temp; X struct popen_cell *cell; X int readp,n,mask,ret; X char *name,*prompt,*in,*out; X struct dsc$descriptor comm_d,in_d,out_d,name_d,prompt_d; X`032 X if (strcmp(mode,"r") == 0) X readp = 1; X else if (strcmp(mode,"w") == 0) X readp = 0; X else X return(NULL); X X temp = mktemp("POPEN_MB_XXXXXXXXXX"); X n = strlen(temp); X cell = (struct popen_cell *) malloc(sizeof(struct popen_cell)); X cell->mbx_name = (char *) malloc(n+1); X strcpy(cell->mbx_name,temp); X if ((cell->mbx_chan = create_mbx(cell->mbx_name)) < 0) X `123cell->completed = 1; X pclose_cleanup(cell); X return(NULL);`125 X X if (readp) X `123in = "NL:"; X out = cell->mbx_name;`125 X else X `123in = cell->mbx_name; X out = "NL:";`125 X X name = 0; X prompt = 0; X mask = CLI$M_NOWAIT; X X cell->completed = 0; X X ret = lib$spawn((command) ? set_dsc_cst(&comm_d,command) : 0, X (in) ? set_dsc_cst(&in_d,in) : 0, X (out) ? set_dsc_cst(&out_d,out) : 0, X &mask, X (name) ? set_dsc_cst(&name_d,name) : 0, X &cell->pid, X &cell->comp_status, X 0, /* event flag */ X`009`009 proc_exit_ast, X`009`009 cell, X (prompt) ? set_dsc_cst(&prompt_d,prompt) : 0, X 0 /* cli */ X ); X`032 X if (ret != SS$_NORMAL) X `123cell->completed = 1; X pclose_cleanup(cell); X return(NULL);`125 X X if (!(cell->fp = fopen(cell->mbx_name,mode))) X `123pclose_cleanup(cell); X return(NULL);`125 X X popen_push(cell); X X return(cell->fp);`125 X Xstatic struct dsc$descriptor *set_dsc_cst(x,buff) X struct dsc$descriptor *x; X char *buff; X`123(*x).dsc$w_length = strlen(buff); X (*x).dsc$a_pointer = buff; X (*x).dsc$b_class = DSC$K_CLASS_S; X (*x).dsc$b_dtype = DSC$K_DTYPE_T; X return(x);`125 X Xstatic int create_mbx(name) X char *name; X`123short chan; X int prmflg,maxmsg,bufquo,promsk,acmode,iflag,retval; X struct dsc$descriptor lognam; X prmflg = 0; X maxmsg = mailbox_size; X bufquo = mailbox_byte_quota; X promsk = mailbox_protection_mask; X acmode = 0; X set_dsc_cst(&lognam,name); X retval = sys$crembx(prmflg,&chan,maxmsg,bufquo,promsk,acmode,&lognam); X if (retval != SS$_NORMAL) return(-1); X return(chan);`125 $ GOSUB UNPACK_FILE $ FILE_IS = "PPROC_TEST.C" $ CHECKSUM_IS = 88563949 $ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY X#include X XFILE *popen(); Xint pclose(); X Xmain() X`123FILE *f; X int j; X char *buffer; X buffer = (char *) malloc(512); X f = popen("show proc","r"); X p_describe(f); X while(fgets(buffer,512,f)) puts(buffer); X p_describe(f); X pclose(f); X f = popen("create test.data","w"); X p_describe(f); X for(j=0;j<5;++j) X fprintf(f,"This is some data, line number %d\n",j); X p_describe(f); X pclose(f);`125 $ GOSUB UNPACK_FILE $ EXIT