Exemplo n.º 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);

}
Exemplo n.º 2
0
STATUS
disp_diff(STATUS acmmt,i4 canons)
{
    STATUS                 ioerr ;
    STATUS                 up_canon = FAIL ;
    char                   cmmtfile [50] ;
    char                   canon_upd = '\0' ;
    char                   junk ;
    char                   menu_ans ;
    bool                   conditional_exp ;

    /* initialize diff window */

    conditional_exp = FALSE;
#ifndef NT_GENERIC
    TEwrite(CL,STlength(CL));
    TEflush();
#endif
    diffW = TDnewwin(MAIN_ROWS,MAIN_COLS,FIRST_MAIN_ROW,FIRST_MAIN_COL);
    diffstW = TDnewwin(STATUS_ROWS,STATUS_COLS,FIRST_STAT_ROW,FIRST_MAIN_COL);
    TDrefresh(diffstW);
    TDrefresh(diffW);

    screenLine = 0;
    old_page = 0;
    bottom_page = 0;
    myPages = NULL;
    ioerr = OK;

    STprintf(cmmtfile,ERx("ct%s.stf"),SEPpidstr);
    diffPtr = sepDiffer->_fptr;

    /*
    **	display diff
    */

    page_down(0);
    if (updateMode)
	    up_canon = OK;

    for (;;)
    {
	if (updateMode)
	{
	    if (editCAns == '\0')
		disp_prompt(DIFF_MENU_M,&menu_ans,DIFF_MENU_AM);
	    else
		menu_ans = 'e';
	}
	else
	    disp_prompt(DIFF_MENU,&menu_ans,DIFF_MENU_A);

	switch (menu_ans)
	{
	   case 'A': case 'a':
		    ioerr = FAIL;
		    break;
	   case 'P': case 'p':
		    page_up();
		    break;
	   case 'N': case 'n':
		    page_down(0);
		    break;
	   case 'C': case 'c':
		    if (acmmt == FAIL && !updateMode)
			disp_prompt(ERx("no comments attached to this command"),
			    &junk,NULL);
		    else
		    {
			edit_file(cmmtfile);
			TDtouchwin(diffW);
			TDrefresh(diffW);
		    }
		    break;
	   case 'E': case 'e':
		    if (up_canon == OK)
		    {
			if (editCAns == '\0')
			{
			    disp_prompt(UPD_CANON,&canon_upd,UPD_CANON_A);
			}
			else
			{
			    canon_upd = editCAns;
			    menu_ans = 'q';
			}

			if (canon_upd == 'M' || canon_upd == 'A' ||
			    canon_upd == 'm' || canon_upd == 'a' )
			    conditional_exp = ask_for_conditional(diffstW,
								  editCAns);

			up_canon = FAIL;
		    }
		    break;
	}
	if (menu_ans == 'Q' || menu_ans == 'q' ||
	    menu_ans == 'A' || menu_ans == 'a' ||
	    menu_ans == 'D' || menu_ans == 'd')
	{
	    disp_prompt(NULLSTR,NULL,NULL);
	    SEPdisconnect = (menu_ans == 'A' || menu_ans == 'a' ||
			     menu_ans == 'D' || menu_ans == 'd');
	    break;
	}
    }

    /*
    **	update test
    */

    if (updateMode)
    {
	LOCATION	cmmtloc;
	short	count;

	/* add comments */

	LOfroms(FILENAME & PATH,cmmtfile,&cmmtloc);
	if (SEP_LOexists(&cmmtloc))
	{
	    append_line(OPEN_COMMENT,1);
	    append_file(cmmtfile);
	    append_line(CLOSE_COMMENT,1);
	    LOdelete(&cmmtloc);
	}

	/* add canons   */
	    
	switch (canon_upd)
	{
	   case 'I':
	   case 'i':
		    append_line(OPEN_CANON,1);
		    append_line(SKIP_SYMBOL,1);
		    append_line(CLOSE_CANON,1);
		    break;
	   case 'M':
	   case 'm':
		    SEPrewind(sepResults, FALSE);
		    if (conditional_exp == TRUE)
		    {
			append_line(OPEN_CANON,0);
			append_line(conditional_prompt,1);
		    }
 		    else
			append_line(OPEN_CANON,1);

		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    append_sepfile(sepGCanons);
		    break;
	   case 'O':
	   case 'o':
		    SEPrewind(sepResults, FALSE);
		    append_line(OPEN_CANON,1);
		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    break;
	   case '\0':
	   case 'E':
	   case 'e':
		    append_sepfile(sepGCanons);
		    break;
	   case 'A':
	   case 'a':
		    append_sepfile(sepGCanons);
		    SEPrewind(sepResults, FALSE);
		    if (conditional_exp == TRUE)
		    {
			append_line(OPEN_CANON,0);
			append_line(conditional_prompt,1);
		    }
		    else
			append_line(OPEN_CANON,1);

		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    break;
	}
    }
    MEtfree(SEP_ME_TAG_PAGES);
    TDdelwin(diffW);
    TDdelwin(diffstW);
    return(ioerr);
}
Exemplo n.º 3
0
int
QAdiff(SEPFILE **canFile,SEPFILE **resFile,SEPFILE *diffFile,i4 max_d)
{
    char                  *toktype = NULL ;

    register i4            i ;
    i4                     memerr ;

    STATUS                 ret_val ;

    register FILE_TOKENS  *t = NULL ;
    E_edit                 ed_res ;


    totaldiffs = no_tokens = failMem = 0;
    list_head = list_tail = NULL;
    SEPrewind(diffFile, TRUE);

    if (grammar_methods&GRAMMAR_SED_C)
    {
	if( (ret_val = Run_SED_on_file(canFile,&SEPcanloc)) != OK )
	{
	    char               tempbuffer[TEST_LINE+1];

	    clean_token_blocks();
	    IISTmove(ERx("ERROR: SED command failed"),' ',
		   TEST_LINE, tempbuffer);
	    tempbuffer[TEST_LINE] = '\0';
	    SEPputrec(tempbuffer, diffFile);
	    return(1);
	}
    }
    if (grammar_methods&GRAMMAR_LEX)
    {
	SEPrewind(*canFile, TRUE);
	currSEPptr = *canFile;
	yylex();
    }

    if (failMem)
    {
	char               tempbuffer[TEST_LINE+1];

	clean_token_blocks();
	IISTmove(ERx("ERROR: lack of memory while lexing"),' ',
	       TEST_LINE, tempbuffer);
	tempbuffer[TEST_LINE] = '\0';
	SEPputrec(tempbuffer, diffFile);
	return(1);
    }
    list1 = list_head;
    numtokens1 = no_tokens;
    size_tokarray(1, numtokens1+1);
    for (i = 1, t = list1; t != NULL; i++, t = t->next)
	tokarray1[i] = t;

    if (tracing & TRACE_TOKENS)
	Trace_Token_List(ERx("Canon"), ++no_cans, numtokens1, tokarray1);

    failMem = no_tokens = 0;
    list_head = list_tail = NULL;

    if (grammar_methods&GRAMMAR_SED_R)
    {
	if( (ret_val = Run_SED_on_file(resFile,& SEPresloc)) != OK )
	{
	    char               tempbuffer[TEST_LINE+1];

	    clean_token_blocks();
	    IISTmove(ERx("ERROR: SED command failed"),' ',
		   TEST_LINE, tempbuffer);
	    tempbuffer[TEST_LINE] = '\0';
	    SEPputrec(tempbuffer, diffFile);
	    return(1);
	}
    }
    if (grammar_methods&GRAMMAR_LEX)
    {
	SEPrewind(*resFile, FALSE);
	currSEPptr = *resFile;
	yylex();
    }

    if (failMem)
    {
	char               tempbuffer[TEST_LINE+1];

	clean_token_blocks();
	IISTmove(ERx("ERROR: lack of memory while lexing"),' ',
	       TEST_LINE, tempbuffer);
	tempbuffer[TEST_LINE] = '\0';
	SEPputrec(tempbuffer, diffFile);
	return(1);
    }
    list2 = list_head;
    numtokens2 = no_tokens;
    size_tokarray(2, numtokens2+1);
    for (i = 1, t = list2 ; t != NULL ; i++, t = t->next)
	tokarray2[i] = t;

    if (tracing & TRACE_TOKENS)
	Trace_Token_List(ERx("Result"), ++no_res, numtokens2, tokarray2);

    ed_res = G_do_miller(numtokens1,numtokens2,max_d,&memerr);
    if (memerr)
    {
	char               tempbuffer[TEST_LINE+1];

	clean_edit_blocks();
	IISTmove(ERx("ERROR: lack of memory while diffing"),' ',
	       TEST_LINE, tempbuffer);
	tempbuffer[TEST_LINE] = '\0';
	SEPputrec(tempbuffer, diffFile);
	return(1);
    }
    if (totaldiffs)
	O_output(ed_res, 0, totaldiffs, diffFile);

    free_tokens();
    SEPrewind(*canFile, FALSE);
    SEPrewind(*resFile, FALSE);

    return(totaldiffs);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
i4
Read_TCresults(	TCFILE *tcoutptr,TCFILE *tcinptr,i4 waiting,bool *fromBOS,
		i4 *sendEOQ_ptr,bool waitforit,STATUS *tcerr)
{
    i4                     c = 0 ;
    i4                     lastc = 0 ;
    i4                     last_TC = 0 ;
    i4                     tmp_waiting = waiting ;
    bool                   keepgoing = TRUE ;
    bool                   nothing_yet = TRUE ;
    bool                   timeout_try_again = TRUE ;


    simple_trace_if(TRACE_DIALOG,"Read_TCresults> dialog fm fe (recording) >\n");

    for (*tcerr = OK; (keepgoing && (*tcerr == OK)); lastc = c)
    {
	if (!waitforit)
	    if (TCempty(tcoutptr))
	    {
		keepgoing = FALSE;
		continue;
	    }

	c = SEP_TCgetc_trace(tcoutptr, tmp_waiting);
	tmp_waiting = waiting; /* reset to timeout value */

	if (((c == TC_EQR)||(c == TC_EOF)) &&
	    (lastc != '\n'))
	{
	    simple_trace_if(TRACE_DIALOG,"\n");
	}

	switch (c)
	{
	   case TC_EQR:
			keepgoing = nothing_yet;

			tmp_waiting = (keepgoing&&(waiting > TC_RETRY_TIMEOUT))
				    ? TC_RETRY_TIMEOUT : waiting;

			last_TC = c;
			break;

	   case TC_EOF:
			keepgoing = (SEPtcsubs == 0) ? FALSE : keepgoing;
			*fromBOS  = FALSE;

			if (SEPtcsubs <= 0)
			{
			    *tcerr = INGRES_FAIL;
			}
			else if (*sendEOQ_ptr == SEPtcsubs)
			{
			    endOfQuery(SEPtcinptr,ERx("Read_TC1"));
			    *sendEOQ_ptr = 0;
			}

			last_TC = c;
			break;

	   case TC_TIMEDOUT:

			if (nothing_yet && last_TC == TC_EQR)
			{
			    c = last_TC;
			    keepgoing = FALSE;
			}
			else if (timeout_try_again)
			{
			    keepgoing = TRUE;
			    endOfQuery(SEPtcinptr,ERx("Read_TC2"));
			    timeout_try_again = FALSE;
			}
			else
			{
			    last_TC = c;
			    keepgoing = FALSE;
			}

			break;

	   case TC_EOQ:
			last_TC = c;
			break;

	   case TC_BOS:
			endOfQuery(tcinptr,ERx("Read_TC2"));
			*fromBOS = TRUE;
			last_TC = c;
			break;

	   default:
			nothing_yet = FALSE;
			SEPputc(c, sepResults);
			break;
	}
    }

    SEPputc(SEPENDFILE, sepResults);
    SEPrewind(sepResults, TRUE);
    simple_trace_if(TRACE_DIALOG,"Read_TCresults> End.>\n");
    return (c);
}