Exemple #1
0
/******************************************************************************
** Name: MEsmdestroy()	- Destroy a shared memory segment
**
** Description:
**	Remove the shared memory segment specified by shared memory identifier
**	"key" from the system and destroy any system data structure associated
**	with it.
**
**	Note: The shared memory pages are not necessarily removed from
**	processes which have the segment mapped.  It is up to the clients to
**	detach the segment via MEfree_pages prior to destroying it.
**
**	Protection Note: The caller of this routine must have protection to
**	destroy the shared memory segment.  Protections are enforced by the
**	underlying Operating System.  In general, this routine can only be
**	guaranteed to work when executed by a user running with the same
**	effective privledges as the user who created the shared memory segment.
**
** Inputs:
**	user_key			identifier which was previosly
**				      used in a successful MEget_pages() call
**				      (not necessarily a call in this process)
**
** Outputs:
**	err_code 		System specific error information.
**
**	Returns:
**	    OK
**	    ME_NO_PERM		    No permission to destroy shared memory
**				            segment.
**	    ME_NO_SUCH_SEGMENT	indicated shared memory segment does not
**				            exist.
**	    ME_NO_SHARED	    No shared memory in this CL.
**	    ME_BAD_ADVICE	    call was made during ME_USER_ALLOC
**
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
******************************************************************************/
STATUS
MEsmdestroy(char        *user_key,
            CL_ERR_DESC *err_code)
{
	LOCATION        location;
	LOCATION        temp_loc;
	char            loc_buf[MAX_LOC + 1];
	STATUS          ret_val = OK;

	CLEAR_ERR(err_code);

	/*
	 * Get location of ME files for shared memory segments.
	 */

# ifdef MCT
	gen_Psem(&NM_loc_sem);
# endif /* MCT */
	ret_val = NMloc(FILES,
	                PATH,
	                (char *) NULL,
	                &temp_loc);
	if (!ret_val)
	{
		LOcopy(&temp_loc,
		       loc_buf,
		       &location);
		LOfaddpath(&location,
		           ME_SHMEM_DIR,
		           &location);
		LOfstfile(user_key,
		          &location);

		if (LOexist(&location) != OK)
			ret_val = FAIL;
		else {
			ret_val = LOdelete(&location);
			switch (ret_val) {
			case OK:
			case ME_NO_PERM:
				break;;

			default:
				ret_val = ME_NO_SUCH_SEGMENT;
				break;;
			}
		}
	}
# ifdef MCT
	gen_Vsem(&NM_loc_sem);
# endif /* MCT */
	return (ret_val);
}
Exemple #2
0
/*{
** Name:	RSblob_ppCallback - IIsw_putParms callback for blobs
**
** Description:
**	If the blob is smaller than DB_MAXTUP-2 bytes, set the blob size and
**	return.  Otherwise, open a temporary file in II_TEMPORARY and write the
**	blob segments to it.
**
** Inputs:
**	closure		- closure (unused)
**	parmBlock	- IIAPI_PUTPARMPARM parameter block
**
** Outputs:
**	RS_BLOB buffer is updated.
**
** Returns:
**	none
*/
II_VOID II_FAR II_CALLBACK
RSblob_ppCallback(
II_PTR	closure,
II_PTR	parmBlock)
{
	IIAPI_PUTPARMPARM	*putParm = (IIAPI_PUTPARMPARM *)parmBlock;
	RS_BLOB			*blob =
				(RS_BLOB *)putParm->pp_parmData[0].dv_value;
	LOCATION		loc;
	i4			cnt;
	STATUS			status;

	if (!blob->fp)
	{
		/* If there is only one segment, indicate this and return */
		if (blob->size <= sizeof blob->buf)
		{
			putParm->pp_moreSegments = FALSE;
			return;
		}
		/* Open the temporary file */
		LOfroms(PATH & FILENAME, blob->filename, &loc);
		if (SIfopen(&loc, ERx("r"), SI_VAR, sizeof blob->buf, &blob->fp)
			!= OK)
		{
			putParm->pp_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY;
			return;
		}
	}
	/*
	** Read the next segment from the file. If it's the last segment, close
	** the temporary file.
	*/
	status = SIread(blob->fp, sizeof blob->buf, &cnt, blob->buf);
	putParm->pp_moreSegments = TRUE;
	blob->len = (short)cnt;
	if (status == ENDFILE)
	{
		SIclose(blob->fp);
		blob->fp = NULL;
		putParm->pp_moreSegments = FALSE;
		LOfroms(PATH & FILENAME, blob->filename, &loc);
		LOdelete(&loc);
	}
	else if (status != OK)
	{
		putParm->pp_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY;
	}
}
Exemple #3
0
/*
** Name: del_floc
**
** Description:
**      Delete a file location.
**
** Inputs:
**      floc    pointer to location structure with file to delete.
**
** Outputs:
**      None:
**
** Return:
**      OK
**
** History:
**      30-Jul-98 (fanra01)
**          Changed while to an if.  Otherwise we may loop here indefinitely
**          waiting for another app to close the file.
**
*/
STATUS
del_floc(LOCATION *floc)
{
    STATUS                 ret_val = OK ;

    /*
    ** This is a "while" rather than an "if" so that we can clean up multiple
    ** versions of a file on OS's that have versioning. Suggested by EGM. --MCA
    */

    if (SEP_LOexists(floc))
    {
	LOdelete(floc);
    }

    return (ret_val);
}
Exemple #4
0
VOID
gca_save( GCA_SVC_PARMS *svc_parms )
{
    GCA_ACB		*acb = svc_parms->acb;
    GCA_SV_PARMS        *sv_parms = (GCA_SV_PARMS *)svc_parms->parameter_list;
    GCA_SAVE_DATA	save_data;
    PTR			user_buf = sv_parms->gca_ptr_user_data;
    i4			user_size = sv_parms->gca_length_user_data;
    char		cl_buf[ GCA_MAX_CL_SAVE_SIZE ];
    i4			cl_size;
    LOCATION		file_loc;
    LOCATION		tmp_loc;
    char		loc_buf[ MAX_LOC ];
    FILE		*save_file;
    char		*save_ptr;
    char		file_id[ MAX_LOC ];
    i4			j;

    /* Initialize status in service invoker's parameter list  */

    sv_parms->gca_status = E_GCFFFF_IN_PROCESS;

    /* Get CL save info */

    svc_parms->gc_parms.svc_buffer = (PTR)cl_buf;
    svc_parms->gc_parms.reqd_amount = sizeof( cl_buf );
    GCsave( &svc_parms->gc_parms );

    if ( svc_parms->gc_parms.status != OK )
	goto complete;

    cl_size = svc_parms->gc_parms.rcv_data_length;

    /* Format GCA_SAVE_DATA structure */

    save_data.save_level_major = GCA_SAVE_LEVEL_MAJOR;
    save_data.save_level_minor = GCA_SAVE_LEVEL_MINOR;
    save_data.cl_save_size = cl_size;
    save_data.user_save_size = user_size;
    save_data.assoc_id = acb->assoc_id;
    save_data.size_advise = acb->size_advise;
    save_data.heterogeneous = acb->flags.heterogeneous;

    /* Create the save file name.  */

    file_id[0] = '\0';

    (VOID) LOfroms(PATH & FILENAME, file_id, &tmp_loc);
    (VOID) LOuniq("IIGC", "TMP", &tmp_loc);
    (VOID) NMloc(TEMP, FILENAME, file_id, &tmp_loc);
    (VOID) LOcopy( &tmp_loc, loc_buf, &file_loc );
    (VOID) LOtos( &file_loc, &save_ptr );
    (VOID) STcopy( save_ptr, sv_parms->gca_save_name );

    /* Open save file. */

    if( SIfopen( &file_loc, "w", SI_VAR, 0, &save_file ) != OK )
    {
	GCA_DEBUG_MACRO(1)( "gca_send bad file open\n" );
	svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL;
	goto complete;
    }

    /* Write GCA, CL, and user data to save file. */

    if( SIwrite( sizeof( save_data ), (PTR)&save_data, &j, save_file ) != OK 
     || cl_size && SIwrite( cl_size, (PTR)cl_buf, &j, save_file ) != OK 
     || user_size && SIwrite( user_size, user_buf, &j, save_file ) != OK
     || SIclose( save_file ) != OK )
    {
	GCA_DEBUG_MACRO(1)( "gca_send bad file write/close\n" );
	(VOID) SIclose( save_file );
	(VOID) LOdelete( &file_loc );
	svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL;
    }

complete:

    return;
}
Exemple #5
0
void 
main(int argc, char *argv[])
{
#define 	MAXBUF	4095
#define 	MAX_NAME  32	

	char 		buf[ MAXBUF+1 ];
	char 		repbuf[ MAXBUF+1 ];
	int		iarg, ibuf, ichr;
	char		*database = NULL;
	char 		username[MAX_NAME] = {""};
	LOCATION	tloc;
	LOCATION        loc_out;
	LOCATION        loc_in;
	char            loc_buf[MAX_LOC + 1];
	char            tmp_buf[MAX_LOC + 1];
	char			otmp_buf[MAX_LOC + 1];
	char		dev[MAX_LOC + 1];
	char		path[MAX_LOC + 1];
	char		fprefix[MAX_LOC + 1];
	char		fsuffix[MAX_LOC + 1];
	char		version[MAX_LOC + 1];
	char            odev[MAX_LOC + 1];
	char            opath[MAX_LOC + 1];
	char            ofprefix[MAX_LOC + 1];
	char            ofsuffix[MAX_LOC + 1];
	char            oversion[MAX_LOC + 1];
	char            *new_filename;
	char		*temploc;
	CL_ERR_DESC 	err_code;
	char 		*p1 = NULL;
	bool		usergiven = FALSE;
	bool		Repmod = FALSE;
	bool		nowait = TRUE;
	char	 	waitflag[3];
	
	
	if (argc < 2) 
	{
		usage();
	    PCexit(FAIL);
	}
	
	/* Get the temporary path location */	
	NMloc(TEMP, PATH, NULL, &tloc);		
	LOcopy(&tloc, tmp_buf, &loc_in);
	LOtos(&tloc, &temploc);
	LOcopy(&tloc, otmp_buf, &loc_out);
	     	
	/* Get the new filename for path location */	
	LOuniq(ERx("usrmod"), ERx("sql"), &loc_in);	
	LOtos(&loc_in, &new_filename);
	
	LOuniq(ERx("usrmod"), ERx("out"), &loc_out);

	/* Get just the filename for copydb code   */	
	LOdetail(&loc_in, dev, path, fprefix, fsuffix, version); 
	if ( *fsuffix !=  '\0' )
	{
	    STcat(fprefix, ".");
	    STcat(fprefix, fsuffix);
	}
       /* Get just the filename for copydb code   */
         LOdetail(&loc_out, odev, opath, ofprefix, ofsuffix,oversion);
		STcat(ofprefix, ".");
		STcat(ofprefix, ofsuffix);
	

	STprintf(buf, 
        ERx("copydb -with_modify -nodependency_check -with_index -with_comments -no_persist -parallel -no_repmod -group_tab_idx -no_warn -d\"%s\" -infile=\"%s\" -outfile=\"%s\""
	), temploc, fprefix,ofprefix);
	ibuf = STlength(buf); 

	for (iarg = 1; (iarg < argc) && (ibuf < MAXBUF); iarg++) 
	{

	    if( STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) == 0 )
		{
			p1 = argv[ iarg ]; 
			(void) CMnext( p1 );

			if ( (STlength(p1) == 0) || 
			  !(((STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) ||
			  (STscompare( p1, 5, ERx( "noint" ), 5 ) == 0 ) || 
			  (STscompare( p1, 6, ERx( "repmod" ), 6 ) == 0 ) || 
			  (STscompare( p1, 1, ERx( "w" ), 6 ) == 0 ) ||
			  (STscompare( p1, 6, ERx( "online"), 6 ) == 0 )) &&
			  ( argc > 2 ) ))
			{
				usage(); 
				PCexit(FAIL);
			}
			/*
			** Get the username if the -u flag is passed in
			** with the input
			*/
			
			if (STscompare( p1, 1, ERx( "u" ), 1 ) == 0 )
			{
				STcopy(&argv[iarg][2] , (char *)&username);
				usergiven = TRUE;
			}
			else if (STscompare( p1, 1, ERx( "r" ), 1 ) == 0 )
			{ 	
				Repmod = TRUE;
				continue;
			}
			else if (STscompare( p1, 1, ERx( "w"), 1 ) == 0)	
			{	
				nowait = TRUE;
				continue;
			}	
                }              	
		
        if( STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) == 0 )
		{
			p1 = argv[ iarg ];
			(void) CMnext( p1 );
			if (STscompare( p1, 1, ERx( "w" ), 1 ) == 0 )
			{
				nowait = FALSE;	
				continue;
			}
			else
			{
				usage();
				PCexit(FAIL); 
			}
		}

        if((database == NULL) &&
           (STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) != 0) &&
           (STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) != 0))
        {
            database =  argv[ iarg ];
        }

	buf[ibuf++] = ' ';
		for (ichr = 0; (argv[iarg][ichr] != '\0') && (ibuf < MAXBUF); 
			ichr++, ibuf++)
		{
			buf[ibuf] = argv[iarg][ichr];
		}
		buf[ibuf] = '\0';
	}

	/*
	**	Execute the command.
	*/

	if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
			(LOCATION *) NULL, &err_code) != OK )
	    PCexit(FAIL);

	/*
	**	we should run the sql script 
	**	  sql dbname < new_filename
	**	if -u flag given then run:
	**	  sql -uusername dbname < new_filename	
	*/

	if (usergiven)
	  STprintf(buf, ERx( "sql -u%s -s %s <%s" ),
			username, database, new_filename );
	else
	  STprintf(buf, ERx( "sql -s %s <%s" ),
				database, new_filename );

	/*
	**	Execute the command.
	*/

        if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
                        (LOCATION *) NULL, &err_code) != OK )
        {
            STprintf(buf, ERx(" Warning: Non-persistent objects associated with the base table\n in the failed query may have been lost. Please refer to\n %s\n to determine whether any corrective action is required.\n"), new_filename);
            SIfprintf(stdout, buf);
	    PCexit(FAIL);
        }

	/* Now execute the repmod command if the replicator 
	** modify is also required by the user (-repmod)
	*/
	
	if (Repmod)
	{
		
	  if (nowait)
	    STcopy("-w", waitflag) ;
	  else
	    STcopy("+w", waitflag) ;
		
	  if (usergiven)
	    STprintf(repbuf, ERx( "repmod -u%s %s %s" ), 
		username, database, waitflag );
	  else
	    STprintf(repbuf, ERx( "repmod %s %s" ), 
		database, waitflag );
            	
	
	  if( PCcmdline((LOCATION *) NULL, repbuf, PC_WAIT,
                 (LOCATION *) NULL, &err_code) != OK )
     	    PCexit(FAIL);

	}	
	/*
	**	Delete the location
	*/
	LOdelete(&loc_in); 
	LOdelete(&loc_out);
	PCexit(OK);
}
Exemple #6
0
int
main(int argc, char *argv[])
{
#define 	MAXBUF	4095

	char 	buf[ MAXBUF+1 ];
	int	iarg, ibuf, ichr;
	bool	debug = FALSE;
        CL_ERR_DESC     err_code;
        char		*p1 = NULL;
        char		pid[MAXBUF];
        char    	*database = ERx("");
        char    	*user = ERx("");
        char    	*xmlfile = ERx("");
        char    	sql_fname[LO_NM_LEN + 1];
        char    	*work_dir = NULL;
        char    	directory[MAX_LOC + 1]; 
        char    	*tmp_dir = NULL;
        char		tmp_buf[MAX_LOC + 1];
        char		subdir_buf[MAX_LOC + 1];
        char		sql_loc_buf[MAX_LOC + 1];
	char		*progname; 
        LOCATION    tmp_dir_loc;
        LOCATION    tmp_subdir_loc;
        LOCATION    tmp_buff_loc;
        LOCATION    curr_loc;
        LOCATION    sql_file_loc;
	char        *password = ERx("");
	char        *groupid = ERx("");
	ARGRET  rarg;
        i4      pos;
	LOCATION    xmlfile_loc;
	FILE	    *xmlfile_read;
	STATUS	    stat = FAIL;
	char	    dbuf[256];
	char	    encode[32];
        u_i4        tmppid;
        TM_STAMP    tm_stamp;


	/* Tell EX this is an ingres tool. */
   	(void) EXsetclient(EX_INGRES_TOOL);

	/* Call IIUGinit to initialize character set attribute table */
	if ( IIUGinit() != OK)
	    PCexit(FAIL);

	progname = ERget(F_XM0006_IMPXML);
	FEcopyright(progname, ERx("2001")); 

	/*
	** Get arguments from command line
	*/

	/* required parameters */

	if (FEutaopen(argc, argv, ERx("xmlimport")) != OK)
          PCexit(FAIL);

	/* database name is required */
	if (FEutaget(ERx("database"), 0, FARG_PROMPT, &rarg, &pos) != OK)
          PCexit(FAIL);
	database = rarg.dat.name;

        if (FEutaget(ERx("xmlfile"), 0, FARG_PROMPT, &rarg, &pos) != OK)
            PCexit(FAIL);
        xmlfile = rarg.dat.name;

        if (FEutaget(ERx("user"), 0, FARG_FAIL, &rarg, &pos) == OK)
            user = rarg.dat.name;

        if (FEutaget(ERx("password"), 0, FARG_FAIL, &rarg, &pos) == OK)
        {
            char *IIUIpassword();

            if ((password = IIUIpassword(ERx("-P"))) == NULL)
            {
                FEutaerr(BADARG, 1, ERx(""));
                PCexit(FAIL);
            }
        }

        if (FEutaget(ERx("groupid"), 0, FARG_FAIL, &rarg, &pos) == OK)
          groupid = rarg.dat.name;

        if (FEutaget(ERx("debug"), 0, FARG_FAIL, &rarg, &pos) == OK)
	  debug = TRUE;

        ibuf = STlength(buf); 

        /* b121678: pid is no longer based on process id, but it's
        ** a random number instead.
        */
        PCpid(&tmppid);
        TMget_stamp(&tm_stamp);
        MHsrand2(tmppid * tm_stamp.tms_usec);
        STprintf(pid, "%x", MHrand2());

#ifdef xDEBUG
        SIprintf(" the pid is: %s \n", pid);
#endif

        /* create the sql file */
	/* Avoid a name like "foo.xml.sql" on VMS, use pid.sql instead */
        STcopy(pid, sql_fname); 
        STcat(sql_fname, ".sql");

        /* 
        ** create in the temp location a directory 
        ** with the name pid. set this directory 
        ** as the working directory for impxml
        */

      NMloc (TEMP, PATH, NULL, &tmp_dir_loc);	
      /* make a location for TMP loc */
      /* print location name */
      LOcopy (&tmp_dir_loc, tmp_buf, &tmp_buff_loc);
      LOtos (&tmp_buff_loc, &tmp_dir);

#ifdef xDEBUG
      SIprintf ("temploc: %s \n", tmp_dir);
#endif

      /* make a subdir location with filename, pid */
      STcopy (pid, subdir_buf);				
      /* Initialize result loc so that everyone is happy */
      LOcopy (&tmp_dir_loc, sql_loc_buf, &sql_file_loc); 
      /* Generate location for temp subdirectory */
      if (LOfaddpath (&tmp_dir_loc, subdir_buf, &sql_file_loc) != OK)
      {
	 IIUGerr(E_XM0007_Locname_Failed, UG_ERR_FATAL, 2, tmp_dir, subdir_buf);
	 /* NOTREACHED */
      }

      /* print the location name */
      LOcopy (&sql_file_loc, tmp_buf, &tmp_buff_loc);    
      LOtos (&tmp_buff_loc, &work_dir);

#ifdef xDEBUG
	SIprintf ("work dir loc: %s \n", work_dir);
#endif

      /* create the subdir */
      if (LOcreate (&sql_file_loc) != OK) {
	 IIUGerr(E_XM0008_Create_Temp_Dir, UG_ERR_ERROR, 1, work_dir);
	 PCexit(FAIL);
      }

      STcopy(work_dir, directory);

#ifdef xDEBUG
      SIprintf ("sql file name: %s \n", sql_fname);
      SIprintf ("xml file name: %s \n", xmlfile);
#endif

      /* Execute the command impxml */	
      STprintf (buf, ERx( "impxml -d=\"%s\" -o=\"%s\" " ),  directory, sql_fname);

      /* encoding? */
      if ( (LOfroms(PATH & FILENAME, xmlfile, &xmlfile_loc) != OK)
          ||
	  (SIopen(&xmlfile_loc, "r", &xmlfile_read) != OK)
	  ||
	  (xmlfile_read == NULL)
	 )
      {
	  IIUGerr(E_XM0009_Cannot_Open_File, UG_ERR_ERROR, 1, xmlfile);
          PCexit(FAIL);
      }

      /* scan XML declaration for encoding, if any */
      if (stat = SIgetrec(dbuf, sizeof(dbuf) - 1, xmlfile_read) == OK)
      {
	  char 	*d = dbuf;
	  i4	i = 0;

	  for (d = dbuf; d != (dbuf + sizeof(dbuf)); d++)
	  {
	      if (MEcmp(d, ERx("encoding="), sizeof(ERx("encoding=")) - 1) == 0)
	      {
		  d += sizeof(ERx("encoding="));
		  while (MEcmp (d, "\'", sizeof(char)) && MEcmp(d, "\"", sizeof(char)))
		      MEcopy(d++, sizeof(char), &encode[i++]);
		  encode[i++] = MIN_CHAR;
		  encode[i] = EOS;
		  STcat(buf, ERx("-x="));
		  STcat(buf, encode);
		  break;
	      }
	  }
      }
      else if (stat != ENDFILE)
      {
          /* unable to read file, report error */
	  IIUGerr(E_XM000A_Cannot_Read_File, UG_ERR_ERROR, 1, xmlfile);
	  PCexit(FAIL);
      }

      stat = SIclose(xmlfile_read);

      STcat(buf, xmlfile);

#ifdef xDEBUG
      SIprintf ( " query send: %s \n", buf);
#endif

      /* 	Execute the command.  
      */

      if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
  		(LOCATION *)NULL, &err_code) != OK )
      {
	if (!debug)
	    LOdelete(&sql_file_loc);
	PCexit(FAIL);
      }

      /*
      **	we should run the sql script 
      **	sql dbname < new_filename
      */
      
      /* save the current location */
      LOcopy(&sql_file_loc, tmp_buf, &curr_loc);

      /* make a full location path to the location first */
      LOfroms(FILENAME, sql_fname, &tmp_buff_loc);
      LOstfile(&tmp_buff_loc, &curr_loc);
      LOcopy (&curr_loc, tmp_buf, &tmp_buff_loc);
      LOtos (&tmp_buff_loc, &tmp_dir);

#ifdef xDEBUG
      SIprintf ("sql file is: %s \n", tmp_dir);
#endif

      /* No space between < and input file for VMS */
      STprintf(buf, ERx( "sql -s %s %s %s %s <%s" ),
			database, user, password, groupid, tmp_dir);
#ifdef xDEBUG
      SIprintf (" query send: %s \n", buf);
#endif

      /*
      **	Execute the command.
      */

      if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
              (LOCATION *)NULL, &err_code) != OK )
      {
	if (!debug)
	    LOdelete(&sql_file_loc);
        PCexit(FAIL); 
      }

      /*
      **    Delete the location
      */
      if (!debug)
	LOdelete(&sql_file_loc);

      PCexit(OK);
}
Exemple #7
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);
}
Exemple #8
0
bool
r_rep_do()
{
	char	  *_Retrieving	= ERget(F_RW0003_Retrieving_data);
	LOCATION  loc;		/* file where the report will be written */
        char      title[80+1];      /* the help title buffer */
	char      help_scr[80+1];   /* the help screen buffer */
        char      pr_title[80+1];   /* print report title */
	char      file_title[80+1]; /* file report title */


	/*	
	** The following is for scrollable output.
	*/
FUNC_EXTERN	BCB	*IIUFint_Init();
FUNC_EXTERN	bool	IIUFmro_MoreOutput();
		bool	scrl_fl;


	r_rep_set(&loc);

	if (St_ing_error != 0)
		return FALSE;

	if (!St_silent)
	{	/* give message while waiting for retrieve */
		SIprintf(_Retrieving);
		SIflush(stdout);
	}
	if (St_to_term)
	{
		if( Warning_count != 0 )
		{
			r_prompt(ERget(S_RW0025_Hit_RETURN_when_done), FALSE);
		}

		/* 
		** If output is the terminal, then initialize forms to do
		** scrollable output.
		*/
		if  (r_init_frms() != OK)
		{
			return FALSE;						    
		}
		/* set up the bcb (buffer control block) */
		STprintf (title, ERget(S_RW1400_report_title), En_report);
		En_bcb = IIUFint_Init((char *)NULL, title);
		if (En_bcb == NULL)	/* IIUFint_Init failed */
		{
			return FALSE;  
		}
		/* initialize bcb */
		En_bcb->nxrec = r_scroll;  /* routine to handle scrolling */
		En_bcb->req_begin = TRUE;
		En_bcb->req_complete = FALSE;
		En_bcb->eor_warning = FALSE;
		LOdelete(&En_bcb->bfloc);  /* check directory is writable */
		En_bcb->nrecs = 0;
		En_bcb->mxcol = 0;
		En_bcb->print_time = FALSE;
		if (En_bcb->rd_ahead)
		{
			MEfree(En_bcb->rd_ahead);
			En_bcb->rd_ahead = NULL;
		}
		/* get first screen to display */
		if (!IIUFmro_MoreOutput(En_bcb, En_bcb->mx_rows-2, NULL))
		{
			r_end_frms();
			/* suppress message if undocumented flag is used */
			if (!St_copyright)
			{
				SIprintf(ERget(S_RW0045_No_data_in_table));
			}
			SIflush(stdout);
			return FALSE;  
		}
		STcopy (ERx("rwoutput.hlp"), help_scr);
		STcopy (ERget(S_RW13F1_RW_output_helpfile), title);
		STcopy (ERget(S_RW1408_print_report_title), pr_title);
		STcopy (ERget(S_RW1409_file_report_title), file_title);

		/* If there is nothing to display, then just exit */
		if (En_bcb->rows_added != 0) 
		{
			/*
			** If the pagelength is equal to screen display size
			** (4 less lines for the report title, status line, 
			** solid line and menu line in the scrollable output)
			** then do NOT scroll keeping the current line visible.
			** This is the default behavior.  Want to scroll a 
			** full page at a time.
			*/
			if (St_p_length == (En_lines-4))
				/* 
				** page length is the same as window size, so 
				** want page scrolling 
				*/
				scrl_fl = FALSE;
			else
				/*
				** different page size so want to scroll, 
				** leaving the one line for context.
				*/
				scrl_fl = TRUE;
			if (!IIUFdsp_Display(En_bcb, NULL, help_scr, title, 
				scrl_fl, pr_title, file_title, FALSE))
			{
				return FALSE;  
			}			
		}
		IIUFdone (En_bcb);
	}
	else 
	{ 
		while (r_getrow() == OK)
		{
			r_nxt_row();	/* process next row */
		}
		return (r_do_end(&loc));
	} 
	return TRUE;
}
Exemple #9
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);
}