From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 22-NOV-1988 02:43
To:	MRGATE::"ARISIA::EVERHART"
Subj:	STRIP part 1 of 2


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Mon, 21 NOV 88 13:41:05 PDT
Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Mon, 21 Nov 88 12:54:15 PST
Received: from HUTRUU51.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 9486; Mon, 21 Nov 88 16:03:16 EDT
Date:     Mon, 21 Nov 88 16:54 N
From:     <MOS%HUTRUU51.BITNET@CUNYVM.CUNY.EDU> (Henk Mos /Fysisch Lab RU Utrecht/)
Subject:  STRIP part 1 of 2
To:       info-vax@kl.sri.com
X-Original-To:  info-vax@kl.sri.com, MOS


Here is the source code for STRIP. It runs under VMS (VAXC) en IBM PC (MSC).
It's coming in 2 parts. STRIP is not the ultimate file convert facility but
works nice and easy for simple manipulations like converting the output
of commands like show memory/output=file.txt, replacing or inserting
TAB's and removing leading and trailing spaces.

Read the comment in the source how to use STRIP. COMPILE.COM is a very
simple procedure to compile and link STRIP.

Have fun, Henk

---------------------------------------------------------------------------
+ Henk J. Mos           +  Phone:  30 532239                              +
+ University of Utrecht +  MOS@HUTRUU51 (BITNET)                          +
+ Physics Laboratory    +  RUUNSC::MOS (SURFNET)                          +
+ Computer Department   +  PSI%13401480610::MOS                           +
+ P.O. Box 80.000       +  MOS%HUTRUU51.BITNET@CUNYVM.CUNY.EDU (INTERNET) +
+ 3508 TA  Utrecht      + ----------------------------------------------- +
+ The Netherlands       + ----------------------------------------------- +
---------------------------------------------------------------------------

$! ...................... 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 MOS
$! on 21-NOV-1988 11:50:35.16.
$!
$! ATTENTION: To keep each article below 31 blocks (15872 bytes), this
$!            program has been transmitted in 2 parts.  You should
$!            concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 3 files:
$!        C.OPT
$!        COMPILE.COM
$!        STRIP.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 = "C.OPT"
$ CHECKSUM_IS = 1392527948
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
Xsys$share:vaxcrtl.exe/share
$ GOSUB UNPACK_FILE
$ FILE_IS = "COMPILE.COM"
$ CHECKSUM_IS = 693783857
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ WRITE SYS$OUTPUT "Creating STRIP.EXE"
X$ CC/LIST STRIP
X$ LINK STRIP,C/OPT
X$ WRITE SYS$OUTPUT "See comments in STRIP.C how to use STRIP"
X$ EXIT
$ GOSUB UNPACK_FILE
$ FILE_IS = "STRIP.C"
$ CHECKSUM_IS = 119857547
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X/*
X========================================================
X=                     S T R I P                        =
X========================================================
X
XPurpose: To perform various functions on a text file.
X
XEnvironment:   VAX/VMS 4.7 or MSDOS 3.2
XLanguage:      VAXC or MSC 4.0
XCreated:       87.10.16
X
X       Henk J. Mos (MOS@HUTRUU51.BITNET)
X       University of Utrecht
X       Physics Department
X       The Netherlands
X
X-------------------------------------------------------------------------
XTHIS PROGRAM MAY FREELY BE COPIED. PLEASE INFORM THE AUTHOR WHEN YOU MAKE
XANY IMPROVEMENTS.
X-------------------------------------------------------------------------
X              `032
XUpdated:  88.02.14 STRIP now creates normal RMS files for output
X          88.05.25 New start format and strip leading and trailing
X          spaces feature added.
X          88.06.01 New feature added: Truncate input lines.
X          88.07.09 Main function reorganized and adapted for MSDOS.
X          88.11.19 Some minor facelift changes added.
X
X---------------------------------------------------------------
XStrip must be defined as a foreign command, for example:
X
XSTRIP == "$DISK:[DIRECTORY]STRIP.EXE"
X
X(You can put this in [SY]LOGIN.COM for example)
X
X---------------------------------------------------------------
X
XUsage: STRIP [option [option]] inputfile [outputfile] (VMS)
X   or  STRIP [option [option]] inputfile outputfile (MSDOS)
X
X     inputfile  >> file to be converted
X     outputfile >> converted file (optional)
X                 if no outputfile is given then
X                 outputfile = inputfile with new version number.
X     Outputfile is a variable record file. Inputfile may be any
X     file type. (VMS)
X
X  options: -f    remove embedded carriage returns and linefeeds
X                 like <CR> and <LF> when using EDT.
X                 (default option)
X           -t  remove trailing spaces
X           -l  remove leading spaces
X           -a  convert to 7 bit ascii
X           -u  convert to uppercase
X           -d  convert to lowercase
X           -e[#] expand tabs to # spaces (default is 7 spaces)
X           -c[#] convert # contigious spaces to a tab
X                        (default is 7 spaces)
X           -k[#] Insert a newline every # (def is 80) characters.
X           -m[#] Truncate every line after # (80) characters.
X
X--------------------------------------------------------------------
X*/
X
X#include <stdio.h>              /* <.h> needed for MSC */
X#include <math.h>
X#include <stdlib.h>
X#include <string.h>
X
X#define version "Version 2.3 /88.11.19/"
X
X#define MSDOS 0     /* VMS version. Must be 1 for MSDOS */
X
X#define TRUE 1
X#define FALSE 0
X
X#define CR  0x0D
X#define LF  0x0A
X#define TAB 0x09
X
X#define S_COPY   0x0001
X#define S_TSPACE 0x0002
X#define S_LSPACE 0x0004
X#define S_CRLF   0x0008
X#define S_ASCII  0x0010
X#define S_UPPER  0x0020
X#define S_LOWER  0x0040
X#define S_EXPND  0x0080
X#define S_COMPR  0x0100
X#define S_NLINS  0x0200
X#define S_TRUNC  0x0400
X
Xchar tab_str[81];
Xint tab_len = 7;
X
X/*======================== S T R U P =============================
X
XPurpose: Convert a string to uppercase
X*/
X
Xstrup(strng_in)
X
Xchar *strng_in;
X
X`123
Xint i;
X
Xi = 0;
Xwhile (strng_in[i] != 0)
X`123
X strng_in[i] = toupper(strng_in[i]);
X i++;
X`125
X`125
X
X/*======================= S T R L O W =============================
X
XPurpose: Convert a string to lowercase.
X*/
X
Xstrlow(strng_in)
X
Xchar *strng_in;
X
X`123
Xint i;
X
Xi = 0;
Xwhile (strng_in[i] != 0)
X`123
X strng_in[i] = tolower(strng_in[i]);
X i++;
X`125
X`125
X
X/*===================== S T R I C M P =============================
X
XPurpose: Check for substring in string.
X
XCalling: STRICMP(strng1,strng2)
X
X     strng1 => string
X     strng2 => substring
X
XReturn: Position of substring
X        -1 if no match
X*/
X
Xstricmp(strng1,strng2)
X
Xchar *strng1,*strng2;
X
X`123
Xint i,j;
X
Xj = strlen(strng1) - strlen(strng2);
Xfor (i = 0; i <= j; i++)
X`123
X if (strncmp(strng1 + i,strng2,strlen(strng2)) == 0)
X  return(i);
X `125
Xreturn(-1);
X`125
X
X/*==================== S T R I P _ L S P A C E S =====================
X
XPurpose: Remove leading spaces.
X*/
X
Xstrip_lspaces(strng_in)
X
Xchar *strng_in;
X
X`123
Xint i,j;
X
Xi = j = 0;
Xwhile (strng_in[i] == ' ') i++; /* scan through leading spaces */
Xwhile (strng_in[i] != 0)
X strng_in[j++] = strng_in[i++];
Xstrng_in[j] = 0;
X`125
X
X/*==================== S T R I P _ T S P A C E S =====================
X
XPurpose: Remove trailing spaces.
X*/
X
Xstrip_tspaces(strng_in)
X
Xchar *strng_in;
X
X`123
Xint i;
X
Xi = strlen(strng_in) - 1;
Xwhile (( i >= 0) && (strng_in[i] == ' '))
X i--;                  /* scan through trailing spaces */
Xstrng_in[i + 1] = 0;
X`125
X
X/*======================= E X P _ T A B ======================
X
XPurpose: Replace every tab with string <tab_str>.
X*/
X
Xexp_tab(strng_in)
X
Xchar *strng_in;
X
X`123
Xint i,j;
Xchar strng_out[300];
X
Xi = j = 0;
Xstrng_out[j] = 0;
Xwhile (strng_in[i] != 0)
X`123
X if (strng_in[i] == TAB)         /* check for TAB character */
X `123
X  strcat(strng_out,tab_str);     /* copy spaces string to output string */
X  j += strlen(tab_str);
X `125
X else                            /* else just copy character */
X  strng_out[j++] = strng_in[i];
X i++;
X strng_out[j] = 0;
X`125
Xstrcpy(strng_in,strng_out);
X`125
X
X/*=================== C O M P _ T A B ========================
X
XPurpose: Replace every occurrence of <tab_str> with a tab.
X*/
X
Xcomp_tab(strng_in)
X
Xchar *strng_in;
X
X`123
Xint k;
X
Xwhile ((k = stricmp(strng_in,tab_str)) >= 0) /* check for contigious spaces */
X`123
X strng_in[k] = TAB;         /*replace with TAB */
X do                    /* delete remaining spaces */
X `123
X  strng_in[k + 1] = strng_in[k + tab_len];
X `125
X while (strng_in[(k++) + tab_len] != 0);
X`125
X`125
X
X/*================== I N F O ======================*/
X
Xinfo()
X
X`123
X printf ("File convert utility STRIP %s\n\n",version);
X if (MSDOS)
X  printf ("Usage: STRIP [option [option]] inputfile outputfile\n");
X else
X  printf ("Usage: STRIP [option [option]] inputfile [outputfile]\n");
X printf ("Purpose: To perform various functions on a text file.\n\n");
X printf ("Inputfile:  file to be converted\n");
X printf ("Outputfile: converted file (optional)\n");
X printf ("            (if no outputfile is given then\n");
X printf ("             outputfile = inputfile with higher version number)\n");
X printf ("Options: -a     convert file to 7 bit ascii\n");
X printf ("         -u     convert file to UPPERCASE\n");
X printf ("         -d     CONVERT FILE TO lowercase\n");
X printf ("         -c[#]  compress # (def = 7) contigious spaces to a tab.\n");
X printf ("         -e[#]  expand tabs to # (def = 7) spaces.\n");
X printf ("         -f     remove embedded carriage returns and linefeeds\n");
X printf ("                (this is the default option)\n");
X printf ("         -k[#]  Insert a newline every # (def = 80) characters.\n");
X printf ("         -m[#]  Truncate every line to # (def = 80 ) characters\n");
X printf ("         -l     remove leading spaces\n");
X printf ("         -t     remove trailing spaces\n");
X`125
X
X/*================== M A I N ======================*/
X
Xmain(argc,argv)
X
Xint argc;
Xchar **argv;
X
X`123
Xint  i,j,k,
X     line_cnt = 0,
X     mode = 0,
X     trunc_len = 299;
X
Xchar file_in[132],
X     file_out[132],
X     status,
X     *chrptr,
X     ifile_set = FALSE,
X     ofile_set = FALSE,
X     strng_in[300],
X     strng_out[300];
X
XFILE *fp1,*fp2;
X
X
Xfile_in[0] = 0;          /* clear input- and outputfilename */
Xfile_out[0] = 0;
X
X/* check arguments */
X
Xif (argc <= 1) /* We DO need a filename. So argc must be >= 2 */
X`123
X if (MSDOS)
X  printf ("\nUsage: STRIP [option [option]] inputfile outputfile\n");
X else
X  printf ("\nUsage: STRIP [option [option]] inputfile [outputfile]\n");
X printf ("Execute STRIP ? for more information\n\n");
X exit(1);
X`125
X
X/* if any arg is ? write info to screen */
X
Xstatus = FALSE;
Xfor (i = 1; i < argc; i++)
X if (argv[i][0] == '?') status = TRUE;
X
Xif ( status )  /* Aha, a ?. Give info */
X`123
X info();
X exit(1);
X`125
X
X/* Process command line
X   ==================== */
Xfor (i = 1; i < argc; i++)    /* scan through arguments */
X`123
X if (argv[i][0] != '-')       /* Check for options */
X `123                            /* No option, must be filename. */
X  if (!ifile_set)             /* Inputfile already defined? */
X  `123
X   strcpy(file_in,argv[i]);   /* No */
X   ifile_set = TRUE;
X  `125
X  else if (!ofile_set)        /* Yes, Must be outputfile. Check */
X  `123                           /* if already defined */
X   strcpy(file_out,argv[i]);  /* No. */
X   ofile_set = TRUE;
X  `125
X  else                        /* Yes, We are in trouble */
X  `123
X   printf("Error in command line. Too many filenames.\n");
X   printf("Use STRIP ? for more info.\n\n");
X   exit(1);
X  `125
X `125
X else                        /* Argument was option */
X `123
X  switch (tolower(argv[i][1]))     /* scan through options list */
X  `123
X   case 'f': mode `124= S_CRLF;
X             break;
X   case 't': mode `124= S_TSPACE;
X             break;
X   case 'l': mode `124= S_LSPACE;
X             break;
X   case 'a': mode `124= S_ASCII;
X             break;
X   case 'u': if (mode & S_LOWER)   /* You can't convert to upper */
X             `123                     /* AND lowercase */
X              printf("Error: Upper/Lowercase conflict.\n");
X              exit(1);
X             `125
X             mode `124= S_UPPER;
X             break;
X   case 'd': if (mode & S_UPPER)   /* same comment as 'u' option */
X             `123
X              printf("Error: Upper/Lowercase conflict.\n");
X              exit(1);
X             `125
X             mode `124= S_LOWER;
X             break;
X   case 'e': if (mode & S_COMPR)   /* you can't expand AND compress */
X             `123
X              printf("Error: Expand/Compress conflict.\n");
X              exit(1);
X             `125
X             if (argv[i][2] != 0)
X              tab_len = atoi(argv[i] + 2);
X             if ((tab_len > 80) `124`124 (tab_len < 1)) /* check min and max */
-+-+-+-+-+ End of part 1 +-+-+-+-+-

