コード例 #1
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);
}
コード例 #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);
}
コード例 #3
0
STATUS
getLocation(char *string,char *newstr,LOCTYPE *typeOfLoc)
{
    STATUS                 ret_val ;
    LOCATION               aLoc ;
    LOCATION               bLoc ;

    LOCATION              *Locptr1 = NULL ;
    LOCATION              *Locptr2 = NULL ;
    LOCATION              *Locptr3 = NULL ;

    char                  *cptr    = NULL ;
    char                  *cptr2   = NULL ;
    char                  *next    = NULL ;
    char                  *start   = NULL ;
    char                  *tmpBuf  = NULL ;
    char                  *tmpBuf2 = NULL ;
    char                  *gl_dev  = NULL ;
    char                  *gl_path [128] ;
    char                  *gl_file = NULL ;
    char                  *resultPtr = NULL ;
    char                  *tmpaLocStr = NULL ;
    char                  *tmpbLocStr = NULL ;

    i4                     i ;

    ret_val = OK;
    for ( i=0; i<128; i++)
	gl_path[i] = NULL;

    tmpaLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    tmpbLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);

    LOfroms(FILENAME & PATH, tmpaLocStr, &aLoc);
    LOfroms(FILENAME & PATH, tmpbLocStr, &bLoc);

    if (tracing&TRACE_PARM)
    {
	SIfprintf(traceptr, ERx("getLocation00> string = %s\n"), string);
	SIfprintf(traceptr, ERx("getLocation01> newstr = %s\n"), newstr);
    }

    tmpBuf   = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    STcopy(string, tmpBuf);

    if (!(start = STindex(tmpBuf, ERx("("), 0)))
    {
	MEtfree(SEP_ME_TAG_GETLOC);
	return(FAIL);
    }

    MEfree(tmpaLocStr);
    MEfree(tmpbLocStr);

    aLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    bLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);

    next = start;
    CMnext(next);
    if (typeOfLoc)
	*typeOfLoc = NULL;

    if (CMcmpcase(next, ERx(",")))
    {
	/* There's a device specification */

	cptr = next;
	if ((next = STindex(cptr, ERx(","), 0)) == NULL)
	{
	    if ((next = STindex(cptr, ERx(")"), 0)) == NULL)
		ret_val = FAIL;
	    else
	    {	/*
		** This is really a file name in the form, @file(filename.type)
		*/
		*next = EOS;
		gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2,
				      TRUE, (STATUS *)NULL);
		STcopy(cptr, gl_file);

		if (tracing&TRACE_PARM)
		    SIfprintf(traceptr, ERx("getLocation02> file = %s\n"),
			      gl_file);
		if (typeOfLoc)
		    *typeOfLoc = FILENAME;
	    }
	}
	else
	{
	    *next = EOS;
	    gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE,
				 (STATUS *)NULL);
#ifdef UNIX
	    STpolycat(2,ERx("$"),cptr, gl_dev);

	    cptr2 = gl_dev;
	    SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC);
	    if ((tmpBuf2 == NULL)||(*tmpBuf2 == EOS))
	    {
		switch (i = SEP_CMwhatcase(cptr2))
		{
		   case  0: break;
		   case  1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
				CMtolower(cptr2,cptr2);
			    break;
		   case -1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
				CMtoupper(cptr2,cptr2);
			    break;
		}
		if (i != 0)
		{
		    cptr2 = gl_dev;
		    SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC);
		}
	    }

	    if (tmpBuf2 != NULL)
		if (*tmpBuf2 != EOS)
		{
		    MEfree(gl_dev);
		    gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC,
					 (STlength(tmpBuf2)*2)+2,
					 TRUE,(STATUS *)NULL);
		    STcopy(tmpBuf2,gl_dev);
		}
#else
#ifdef MPE
            STpolycat(2,ERx("!"),cptr, gl_dev);
            for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
                CMtoupper(cptr2,cptr2);
#else
	    /* Probably VMS */

	    STcopy(cptr, gl_dev);
#endif
#endif
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation03> dev = %s\n"), gl_dev);
	    if (typeOfLoc)
		*typeOfLoc = PATH;
	}

    }

    cptr = CMnext(next);
    next = STindex(cptr, ERx(","), 0);

    for (i = 0; next; ) /* do the paths */
    {
	*next = EOS;
	gl_path[i] = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE,
				 (STATUS *)NULL);
	STcopy(cptr, gl_path[i]);
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation04> path = %s\n"), gl_path[i]);

	if (typeOfLoc)
	    *typeOfLoc = PATH;

	cptr = CMnext(next);
	next = STindex(cptr, ERx(","), 0);
	i++;
    }
    gl_path[i] = NULL;

    Locptr1 = &aLoc;
    Locptr2 = &bLoc;


#ifndef MPE
    if (gl_dev || gl_path[0])
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation05> SEP_LOcompose()\n"));

	ret_val = SEP_LOcompose(gl_dev, gl_path[0], NULL, NULL, NULL, Locptr1);
#ifdef UNIX
	cptr2 = SEP_CMlastchar(Locptr1->string,0);
	if (*cptr2 == '/') *cptr2 = EOS;
	Locptr1->path = Locptr1->string;
#endif
    }

    for (i=1; (gl_path[i] != NULL)&&(ret_val == OK); i++)
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation06> LOfaddpath()\n"));

	if ((ret_val = LOfaddpath(Locptr1, gl_path[i], Locptr2)) != OK)
	    continue;

	Locptr3 = Locptr1;
	Locptr1 = Locptr2;
	Locptr2 = Locptr3;
    }
#endif

    if ((gl_file != NULL)&&(ret_val == OK))
    {
	/*
	** This first case catches the instance of: @file(filenane.type).
	** This was caught above in looking for a device (gl_dev).
	*/
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation07> LOfroms()\n"));

	ret_val = LOfroms( FILENAME, gl_file, Locptr1);
    }
    else
    if ((CMcmpcase(cptr, ERx(")")) != 0)&&(ret_val == OK))
    {
	/* There is a filename */

	next = STindex(cptr, ERx(")"), 0);

	*next = EOS;
	gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE,
			      (STATUS *)NULL);
	STcopy(cptr, gl_file);
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation08> file = %s\n"), gl_file);
	if (typeOfLoc)
	    *typeOfLoc = PATH & FILENAME;
	if (gl_dev || gl_path[0])
	{
#ifdef MPE
	    if (gl_dev)
	    {
		if (tracing&TRACE_PARM)
		    SIfprintf(traceptr, ERx("getLocation09> MPE's LOfroms ()\n"));

	        char *tmpMPE = NULL ;

		tmpMPE = SEP_MEalloc(SEP_ME_TAG_GETLOC,
				     (STlength(gl_file)+STlength(gl_dev)+1)*2,
				     TRUE, (STATUS *)NULL);

		STpolycat(3, gl_file, ERx("."), gl_dev, tmpMPE);
		LOfroms(FILENAME & PATH, tmpMPE, Locptr1);
	    }
#else
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation09> LOfstfile()\n"));

	    LOfstfile(gl_file, Locptr1);
#endif
	}
	else
	{
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation10> LOfroms()\n"));

	    LOfroms( FILENAME, gl_file, Locptr1);
	}
    }

    if (ret_val == OK)
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation11> LOtos()\n"));

	LOtos(Locptr1, &resultPtr);
	STcopy(resultPtr, newstr);
    }
    MEtfree(SEP_ME_TAG_GETLOC);

    if (tracing&TRACE_PARM)
    {
	if (ret_val != OK)
	    SIfprintf(traceptr,ERx("getLocation12> ret_val = %d\n"),ret_val);
	else
	    SIfprintf(traceptr,ERx("getLocation13> newstr = %s\n"),newstr);
    }

    return(ret_val);
}