From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 21-NOV-1988 20:39
To:	MRGATE::"ARISIA::EVERHART"
Subj:	STRIP part 2 of 2


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

+-+-+-+ Beginning of part 2 +-+-+-+
X             `123
X              printf("Error in number of spaces (1 < # < 80).\n");
X              exit(1);
X             `125
X             for (k = 0; k < tab_len; k++)   /*create spaces string*/
X              tab_str[k] = ' ';
X             tab_str[tab_len] = 0;
X             mode `124= S_EXPND;
X             break;
X   case 'c': if (mode & S_EXPND)
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))
X             `123
X              printf("Error in number of spaces. (1 < # < 80)\n");
X              exit(1);
X             `125
X             for (k = 0; k < tab_len; k++)
X              tab_str[k] = ' ';
X             tab_str[tab_len] = 0;
X             mode `124= S_COMPR;
X             break;
X   case 'k': if (mode & S_TRUNC)
X             `123
X              printf("Error: Truncate/Wrap conflict.\n");
X              exit(1);
X             `125
X             if (argv[i][2] != 0)
X              trunc_len = atoi(argv[i] + 2);
V             if ((trunc_len <= 1) `124`124 (trunc_len >= 300)) /* check min and
X max */
X             `123
X              printf("Error in string length (must be < 300).\n");
X              exit(1);
X             `125
X             mode `124= S_NLINS;
X             break;
X
X   case 'm': if (mode & S_NLINS)
X             `123
X              printf("Error: Truncate/Wrap conflict.\n");
X              exit(1);
X             `125
X             if (argv[i][2] != 0)
X              trunc_len = atoi(argv[i] + 2);
V             if ((trunc_len <= 1) `124`124 (trunc_len >= 300)) /* check min and
X max */
X             `123
X              printf("Error in string length (must be < 300).\n");
X              exit(1);
X             `125
X             mode `124= S_TRUNC;
X             break;
X
X   default : printf("Unknown option /%s/\n",argv[i]);
X             printf("Use STRIP ? for more info.\n\n");
X             exit(1);
X  `125
X `125
X`125
X
X/* check file info and options */
X
Xif (!ifile_set)               /* check if there is a input filename */
X`123                             /* if not ... */
X printf("No inputfile specified.\n");
X exit(1);
X`125
X
Xif (!ofile_set)                /* check for output filename */
X  strcpy(file_out,file_in);    /* if not use input filename */
X
Xif (!mode)                     /* if no option present then */
X mode = S_CRLF;                /* strip <cr> and <lf> */
X
X/* open input- en output file */
X
Xstrup(file_in);                /* uppercase */
Xif ((fp1 = fopen(file_in,"rt")) == NULL) /* open input file */
X`123                                        /* hmm... no success */
X printf("Can't open %s for input\n",file_in); /* tell them */
X perror("");
X exit(1);
X`125
Xstrup(file_out);               /* uppercase */
Xif ((chrptr = strchr(file_out,';')) != 0)    /* check voor ';' */
X *chrptr = 0;                  /* No version info in outputfile (VMS) */
X
X/* Open output file. */
X
Xif (MSDOS)
X`123
X if (!strcmp(file_in,file_out))
X `123
X  printf("Error: Output filename can't be input filename.\n");
X  fclose(fp1);
X  exit(1);
X `125
X fp2 = fopen(file_out,"wt");
X`125
Xelse
X fp2 = fopen(file_out,"wt","rfm=var","rat=cr"); /* VMS version */
X
Xif (!fp2)                     /* check fopen */
X`123
X printf("Can't open %s for output\n",file_out);
X perror("");
X exit(1);
X`125
X
X/* read data from inputfile until EOF */
X
Xwhile ( fgets(strng_in, (trunc_len + 1), fp1) != NULL ) /* read string */
X`123
X status = FALSE;
X if (strng_in[strlen(strng_in) - 1] == 10)   /* line completely read? */
X `123
X  strng_in[strlen(strng_in) - 1] = 0;        /* remove linefeed from fgets */
X  status = TRUE;
X `125
X
X line_cnt += 1;                         /* update line_counter */
X
X if ((mode & S_TRUNC) && !status )
X  while( !feof(fp1) && (fgetc(fp1) != 10) ); /* discard remaining of line */
X
X if ( mode & S_ASCII )        /* strip bit 8 */
X `123
X  for (i=0; strng_in[i] != 0; i++)
X   strng_in[i] = (strng_in[i] & 0x7F);
X `125
X
X if (mode & S_CRLF) /* strip cr & lf at end of line */
X `123
X  i = j = 0;
X  while (strng_in[i] != 0)
X   if ((strng_in[i] != CR) && (strng_in[i] != LF))
X    strng_out[j++] = strng_in[i++];
X  strng_out[j] = 0;
X  strcpy(strng_in,strng_out);
X `125
X
X if (mode & S_LSPACE)    /* strip leading spaces */
X  strip_lspaces(strng_in);
X
X if (mode & S_TSPACE)    /* strip trailing spaces */
X  strip_tspaces(strng_in);
X
X if (mode & S_UPPER)     /* convert to uppercase */
X  strup(strng_in);
X
X if (mode & S_LOWER)     /* convert to lowercase */
X  strlow(strng_in);
X
X if (mode & S_EXPND)     /* expand tabs */
X  exp_tab(strng_in);
X
X if (mode & S_COMPR)     /* convert spaces to tabs */
X  comp_tab(strng_in);
X
X if(!fprintf(fp2,"%s\n",strng_in))     /* write result to outputfile */
X `123
X  printf("Error while writing %s.\n",file_out);
X  perror("");
X  exit(1);
X `125
X`125
Xfclose (fp1);  /* close input and output file */
Xfclose (fp2);
Xprintf("Strip: %d lines processed.\n");
X`125
$ GOSUB UNPACK_FILE
$ EXIT
-+-+-+-+-+ End of part 2 +-+-+-+-+-

