Beispiel #1
0
STATUS
append_sepfile(SEPFILE	*sepptr)
{
    STATUS                 ioerr ;
    char                   buffer [SCR_LINE] ;
    FILE                  *fptr = sepptr->_fptr ;
    char                  *endptr, prev_char=EOS ;
    i4                     count, i ;
#ifdef NT_GENERIC
    char                  *ptr = NULL;
    i4                     buffCount, count2;
    bool                   more_found;
#endif

    SEPrewind(sepptr, FALSE);

/*
**  special case if dealing with diff output because
**  (a) lines are padded with spaces to TEST_LINE
**  (b) do not have `\n'
**  (c) first character of last line is SEPENDFILE
**      because of the skewing of the canon & result files
**      especially when special characters are found in those
**      files, the SEPENDFILE character may NOT appear in the
**      second character of a line after the slash '\'.
*/

    if (sepptr == sepDiffer)
    {
	for (;;)
	{
	    ioerr = SIread(fptr, TEST_LINE, &count, buffer);
#ifdef VMS
	    if (ioerr != OK)
		break;
#endif
#ifdef UNIX
	    if (ioerr != OK && ioerr != ENDFILE)
		break;

	    /* Detect EOF if we miss the trailing '\',0xFF */
	    if( count == 0 )
	    {
		ioerr = ENDFILE;
		break;
	    }

#endif
#ifdef NT_GENERIC
	    if (ioerr != OK && ioerr != ENDFILE)
		break;

	    ptr = buffer;
	    i = count = 0;
	    count2 = TEST_LINE;
	    more_found = TRUE;
	    while ((more_found == TRUE) && (ioerr == OK || ioerr == ENDFILE))
	    {
	      count2 = count2 + count;
	      buffCount = 0;
	      while (i != count2)
	      {
		if (buffer[i] == SEP_ESCAPE)
		{
		  CMnext(ptr);
		  i++;
		  if (i == count2)
		  {
		    if (fptr->_ptr[0] == SEP_ESCAPE)
		      buffCount++;
		  }
		  else
		    if (buffer[i] == SEP_ESCAPE)
		      buffCount++;
		}
		if (i != count2)
		{
		  i++;
		  CMnext(ptr);
		}
	      }

	      if (buffCount > 0)
	        ioerr = SIread(fptr, buffCount, &count, ptr);
	      else
		more_found = FALSE;
	    }
	    if (ioerr != OK && ioerr != ENDFILE)
		break;
#endif

	    /* Detect EOF if '\', 0xFF split across two reads */
	    if( buffer[0] == SEPENDFILE &&  prev_char == '\\' )
	    {
		ioerr = ENDFILE;
		break;
	    }
	    prev_char = buffer[81];
	    /* Detect EOF if '\', 0xFF are in consecutive bytes in the buffer */
	    for(i=0, endptr=buffer; i < TEST_LINE; ++i, ++endptr)
	    {
		if( i > 0 && *endptr == SEPENDFILE && *(endptr-1) == '\\' )
			break;
	    }
	    if( i > 0 && *endptr == SEPENDFILE && *(endptr-1) == '\\' )
	    {
		ioerr = ENDFILE;
		break;
	    }
	    buffer[TEST_LINE] = '\0';
 	    SEPtranslate(buffer, SCR_LINE);
	    STtrmwhite(buffer);
	    append_line(buffer, 1);
	}
    }
    else
    {
	while ((ioerr = SEPgetrec(buffer, sepptr)) == OK)
	    append_line(buffer, 0);
    }
    return(ioerr == ENDFILE ? OK : FAIL);

}
Beispiel #2
0
STATUS
Run_SED_on_file(SEPFILE **Sep_file,LOCATION *Sep_Loc)
{
    STATUS                 ret_val ;
    CL_ERR_DESC            cl_err;

    LOCATION              *sedtmploc = NULL ;
    LOCATION              *filtmploc = NULL ;

    char                  *SEDbuffer = NULL ;
    char                  *sedtmp = NULL ;
    char                  *filtmp = NULL ;
    char                  *cmd_line = NULL ;
    char                  *sed_dev = NULL ;
    char                  *sed_path = NULL ;
    char                  *sed_name = NULL ;
    char                  *sed_type = NULL ;
    char                  *sed_vers = NULL ;
    char                  *fptr1 = NULL ;
    char                  *fptr2 = NULL ;

    FILE                  *SEDfptr = NULL ;
    FILE                  *fptr = NULL ;

    bool                   Sep_file_empty ;

    sed_dev  = SEP_MEalloc(SEP_ME_TAG_SED, LO_DEVNAME_MAX+1,  TRUE, NULL);
    sed_path = SEP_MEalloc(SEP_ME_TAG_SED, LO_PATH_MAX+1,     TRUE, NULL);
    sed_name = SEP_MEalloc(SEP_ME_TAG_SED, LO_FPREFIX_MAX+1,  TRUE, NULL);
    sed_type = SEP_MEalloc(SEP_ME_TAG_SED, LO_FSUFFIX_MAX+1,  TRUE, NULL);
    sed_vers = SEP_MEalloc(SEP_ME_TAG_SED, LO_FVERSION_MAX+1, TRUE, NULL);

    SEDbuffer = SEP_MEalloc(SEP_ME_TAG_SED, SCR_LINE+1, TRUE, NULL);

    /*
    ** Create Sed output file names.
    */
    sedtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION),
					TRUE, NULL);
    filtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION),
					TRUE, NULL);
    sedtmp    = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);
    filtmp    = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);

    LOtos(Sep_Loc, &fptr2);
    STcopy(fptr2, sedtmp);
    STcopy(fptr2, filtmp);
    LOfroms(FILENAME & PATH, sedtmp, sedtmploc);
    LOfroms(FILENAME & PATH, filtmp, filtmploc);
    LOdetail(sedtmploc, sed_dev, sed_path, sed_name, sed_type, sed_vers);
    STcopy(ERx("sed"),sed_type);
    SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, sedtmploc);
    STcopy(ERx("sdr"),sed_type);
    SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, filtmploc);

    /*
    ** Copy Sep SI_RACC file to a SI_TXT file.
    */
    SEPrewind(*Sep_file, FALSE);
    if ((ret_val = SIfopen(filtmploc,ERx("w"), SI_TXT, SCR_LINE, &fptr))
	!= OK)
	return(ret_val);

    for (Sep_file_empty = TRUE;
	 (ret_val = SEPgetrec(SEDbuffer, *Sep_file)) == OK;
	 SIputrec(SEDbuffer, fptr))
	if (Sep_file_empty)
	    Sep_file_empty = FALSE;

    SIclose(fptr);

    if (Sep_file_empty == FALSE)
    {   /*
	** Create command line for sed command.
	*/
	LOtos(SED_loc, &fptr1);
	LOtos(filtmploc, &fptr2);
	cmd_line = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);
	IISTprintf(cmd_line, "sed -f %s %s", fptr1, fptr2);

	/*
	** Close Sep file and run the SED.
	*/
	SEPclose(*Sep_file);
	ret_val = PCcmdline(NULL, cmd_line, PC_WAIT, sedtmploc, &cl_err);
	if(ret_val != OK)
	{
	    SEPopen(Sep_Loc, SCR_LINE, Sep_file);
	    del_floc(sedtmploc);
	    del_floc(filtmploc);
	    MEtfree(SEP_ME_TAG_SED);
	    return(1);
	}

	/*
	** Recreate Sep file.
	*/
#ifdef NT_GENERIC
	LOdelete(Sep_Loc);
#else
	del_floc(Sep_Loc);
#endif
	if ((ret_val = SIfopen(Sep_Loc, ERx("w"), SI_RACC, SCR_LINE, &fptr))
	    != OK)
	    return(ret_val);
	SIclose(fptr);
	SEPopen(Sep_Loc, SCR_LINE, Sep_file);

	/*
	** Open Sed output file.
	*/
	if ((ret_val = SIfopen(sedtmploc, ERx("r"), SI_TXT, SCR_LINE, &SEDfptr))
	    != OK)
	    return(ret_val);

	/*
	** Copy the Sed output file to the Sep file.
	*/
	while((ret_val = SIgetrec(SEDbuffer, SCR_LINE, SEDfptr)) == OK)
	    SEPputrec(SEDbuffer, *Sep_file);

	SEPclose(*Sep_file);
	SIclose(SEDfptr);

	/*
	** Reopen the sep file.
	*/
	SEPopen(Sep_Loc, SCR_LINE, Sep_file);

	/*
	** Clean up.
	*/
	del_floc(sedtmploc);
    }
    del_floc(filtmploc);
    MEtfree(SEP_ME_TAG_SED);
    return(OK);
}