Esempio n. 1
0
/* ARGSUSED */ 
static void pglpfw_browseDoneCb ( Widget wid, XtPointer clnt, XtPointer cbs )
/************************************************************************
 * pglpfw_browseDoneCb							*
 *									*
 * This is an internal callback function for the browse buttons,	*
 * Ok and Cancel.							*
 *									*
 * void pglpfw_browseDoneCb (wid, clnt, cbs)				*
 *									*
 * Input parameters:							*
 *	wid		Widget		Widget that activated callback	*
 *	clnt		XtPointer	Pointer to client data (GrInfo)	*
 *	cbs		XtPointer	Callback struct			*
 *									*
 **									*
 * Log:									*
 * T. Lee/SAIC		04/02						*
 * E. Safford/SAIC	04/02	use cfl_isdir instead of local version	*
 ***********************************************************************/
{
    int		which, ier;
    char 	*text;
    char	filepart[MXFLSZ] = "\0" , pathpart[LLPATH] = "\0";
    Widget	popup;
    FSBCBS 	*fcbs;
/*---------------------------------------------------------------------*/

    which = (long)clnt;
    if (which == 1) {	/* OK */
	fcbs = (FSBCBS *) cbs;
	XmStringGetLtoR (fcbs->value, XmFONTLIST_DEFAULT_TAG, &text);

	if ( cfl_isdir ( text )  ) {
            _fileName[0] = '\0';
            strcpy ( _dirPath, text );
        }
        else {
            cfl_path ( text, pathpart, filepart, &ier ) ;
            if ( filepart[0] != '\0' ) {
                strcpy ( _fileName, filepart );
            }
            if ( pathpart[0] != '\0' ) {
                strcpy ( _dirPath, pathpart );
            }
        }

        if ( _dirPath[ ( strlen(_dirPath) - 1 ) ] != '/' ) {
            strcat ( _dirPath, "/" );
        }

	XtFree (text);


	if ( _fileName[0] == '\0' ) {
	    popup = (XtIsManaged (_browsePopup)) ? _browsePopup : _fileSelW;
	    NxmWarn_show (popup, "Not a valid file.");
	}
	else {
	    pglpfw_openCtlBtnCb ( NULL, 0, NULL );
	}
    }
    else {	/* CANDEL */
	XtUnmanageChild (_browsePopup);
    }
}
Esempio n. 2
0
FILE *spf_create ( char *filnam, int *hlen, int *iret )
/************************************************************************
 * spf_create								*
 *									*
 * This function creates a new SPF file with an appropriate header. If  *
 * the file suffix is not ".spf", it will be added.			*
 *									*
 * Note: If the tag value contains a "<", it must be preceeded by a	*
 * backslash '\\' so as not to confuse it with the start of another tag.*
 *									*
 * FILE *spf_create ( filnam, hlen, iret )				*
 *									*
 * Input parameters:							*
 *      *filnam		char		file name with full path	*
 *									*
 * Output parameters:							*
 *	*hlen		int		Header length			*
 *	*iret		int		Return code			*
 *					0 - Normal			*
 *				       -3 - Failure to create SPF file	*
 * Return parameters:							*
 *	*spf_create	FILE		File pointer			*
 *									*
 **									*
 * Log:									*
 * J. Wu/GSC	6/01	create						*
 * J. Wu/GSC	6/01	correct cfl_aopn to cfl_wopn			*
 * J. Wu/SAIC	6/03	add comments about escaped '<'			*
 * B. Yin/SAIC	3/04	changed css_gtim calling sequences		*
 * T. Piper/SAIC	03/06	Added GROUP_PERMS_SPF logic and actions	*
 ***********************************************************************/
{
    int	    ier, ierr, ipos, itype = 0;
    char    outstr[1024], perms_prefs[16], curdat[20], *usernam;
    char    filepart[MXFLSZ], pathpart[LLPATH];
    char    exn[] = "!\n", ex[] = "!",
            linf[] = "!----------------------------------------",
            linb[] = "----------------------------------------\n",
            str1[] = "This is a stored procedure file for nmap2.",
            str2[] = "Creation date:",
	    str3[] = "Created by:",
	    esp1[] = " Note: If the tag value contains a '<', it must be ",
	    esp2[] = "preceeded by a backslash \n!        '\\' so as not to ",
	    esp3[] = "confuse it with the start of another tag.";
    FILE    *fptr;
    mode_t  mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; /*rw_rw_r*/

/*---------------------------------------------------------------------*/
    
    *iret = G_NORMAL;
    fptr = (FILE *)NULL;
    
    /*
     *  If the file suffix is not ".spf", add it.
     */
    cfl_path ( filnam, pathpart, filepart, &ier ) ;   
    cst_srch ( 0, (int)strlen(filepart), ".spf", filepart, &ipos, &ier );
    if ( ier == -4 ) {
        strcat ( filnam, ".spf" );
    }
            
    /*
     *  Create the file for writing and add the header discription.
     */
    fptr = cfl_wopn( filnam, &ier );    
    
    if ( fptr == NULL ) {
        
	*iret = -3;          /* fail to create */
	er_wmsg ( "CFL", &ier, filnam, &ierr, 3, strlen( filnam ) );
        
    }    
    else {
	ctb_pfstr ( "GROUP_PERMS_SPF", perms_prefs, &ier);
	if ( strcmp(perms_prefs, "TRUE") == 0 ) {
	    chmod(filnam, mode);
	}
	/*
         *  Write an appropriate header to the file.
         */   
        css_gtim( &itype, curdat, &ier );
        usernam = getenv("LOGNAME");
    
        sprintf( outstr, "%s%s%s%s%s%s %s\n%s%s %s\n%s%s%s%s%s \n%s%s %s\t%s\n%s%s %s\t\t%s\n%s%s%s%s%s%s", 
             linf, linb, linf, linb,
	     exn, ex, filnam, 
	     exn, ex, str1, 
	     exn, ex, esp1, esp2, esp3, 
	     exn, ex, str2, curdat, 
	     exn, ex, str3, usernam, 
	     exn, linf, linb, linf, linb, exn );
       
	*hlen = (int)(strlen( outstr ) * sizeof( char ));
	cfl_writ( fptr, *hlen, (unsigned char*)outstr, &ier );
	
	if ( ier < 0 ) {
	
	    *iret = -3;     /* fail to create */
 	    er_wmsg ( "CFL", &ier, filnam, &ierr, 3, strlen( filnam ) );
            fptr = (FILE *)NULL;
	    	
	}           	    	
	     
    }
        
    return fptr;    
    
}
Esempio n. 3
0
void srchw_fosdGetrep ( srchinfo_t *srchinfo, char *report, int *iret )
/************************************************************************
 * srchw_fosdGetrep                                                     *
 *                                                                      *
 * This routine will find the report for the requested location.        *
 *                                                                      *
 * srchw_fosdGetrep( srchinfo, report, iret )                        	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *srchinfo       srchinfo_t      Search info structure           *
 *                                                                      *
 * Output parameters:                                                   *
 *      *report         char            Report                          *
 *      *iret           int             Return code                     *
 *                               0 -- successful                        *
 *                              -1 -- no data                           *
 *                              -6 -- last file in fore/backward        *
 **                                                                     *
 * Log:                                                                 *
 * L. Williams/EAI       6/96           modified from srchb_fosdFndrepWW*
 * T. Piper/SAIC	 5/02	fixed date/time display			*
 ***********************************************************************/
{
int		ier, found, last_flg, tmp_ptr;
char		dirnam[LLPATH], filnam[MXFLSZ];
/*---------------------------------------------------------------------*/
	found = G_FALSE;
	last_flg = G_FALSE;

        tmp_ptr = srchinfo->current;

        switch( srchinfo->sflag ) {

              case 0:                   /* START OVER  */

                   srchinfo->current = 0;

                   while( srchinfo->current < stnList.nreports ) {

                      if( strcmp( reportInfo[srchinfo->current].stnid,
                                        srchinfo->srchstr ) == 0 ) {
                         strcpy( srchinfo->file_info.filnam,
                                        reportInfo[srchinfo->current].fname );
                         _getrpt( srchinfo, report, iret );
                         if( *iret != 0 ) {
                            report[0]='\0';
                            return;
                         }
                         found = G_TRUE;
                      }
                      if( found ) {
                         break;
                      }
                      (srchinfo->current)++;
                   }
                   if( srchinfo->current >= stnList.nreports - 1 ) {
                      last_flg = G_TRUE;
                   }
                   break;

              case 1:                   /* NEXT   */

                   (srchinfo->current)--;
                   while( srchinfo->current >= 0 ) {

                      if( strcmp( reportInfo[srchinfo->current].stnid,
                                        srchinfo->srchstr ) == 0 ) {
                         strcpy( srchinfo->file_info.filnam,
                                        reportInfo[srchinfo->current].fname );
                         _getrpt( srchinfo, report, iret );
                         if( *iret != 0 ) {
                            report[0]='\0';
                            return;
                         }
                            found = G_TRUE;
                      }
                      if( found ) {
                         break;
                      }
                      (srchinfo->current)--;
                   }
                   if( srchinfo->current <= 0 ) {
                      last_flg = G_TRUE;
                   }
                   break;

              case -1:                  /* PREVIOUS   */

                   (srchinfo->current)++;
                   while( srchinfo->current < stnList.nreports ) {

                      if( strcmp( reportInfo[srchinfo->current].stnid,
                                        srchinfo->srchstr ) == 0 ) {
                         strcpy( srchinfo->file_info.filnam,
                                        reportInfo[srchinfo->current].fname );
                         _getrpt( srchinfo, report, iret );
                         if( *iret != 0 ) {
                            report[0] = '\0';
                            return;
                         }
                            found = G_TRUE;
                      }
                      if( found ) {
                         break;
                      }
                      (srchinfo->current)++;
                   }
                   if( srchinfo->current >= stnList.nreports - 1 ) {
                      last_flg = G_TRUE;
                   }
                   break;

        }

        if( ! found ) {
           srchinfo->current = tmp_ptr;
           *iret = -6;
           return;
        }

/*
 * Remove the unprintable characters.
 */
        cst_unpr( report, report, iret );

/*
 * Display report date in the text window.
 */
	cfl_path(srchinfo->file_info.filnam, dirnam, filnam, &ier);
	txtw_dttmSet(filnam); 
	txtw_dsplyDateTime( &ier );

/*
x* set the return code if it is the last file in forward/backward
 */
        if ( last_flg )
                *iret = -6;
}
Esempio n. 4
0
void spf_open ( char *filnam, Boolean crt, FILE **fptr, int *flen, int *iret )
/************************************************************************
 * spf_open								*
 *									*
 * This function opens an SPF file for update. If the file doesn't 	*
 * exist and flag "crt" is TRUE, then it will be created. If the file   *
 * suffix is not ".spf", it will be added. If the user has only read    *
 * permission to the SPF file, it will be opened as "read-only".	*
 *									*
 * spf_open ( filnam, crt, fptr, flen, iret )				*
 *									*
 * Input parameters:							*
 *      *filnam		char		File name with full path	*
 *      crt		Boolean		Flag, create a new file or not	*
 *									*
 * Output parameters:							*
 *      **fptr		FILE		Pointer to a file pointer	*
 *      *flen		int		File size			*
 *	*iret		int		Return code			*
 *					1 - File opened as READ_ONLY	*
 *					0 - Normal 			*
 *				       -1 - File does not exist		*
 *				       -2 - File cannot be opened	*
 *				       -3 - Failure to create SPF file	*
 *									*
 **									*
 * Log:									*
 * J. Wu/GSC		6/01	create					*
 * J. Wu/GSC		6/01	use cst_srch()				*
 * J. Wu/GSC		7/01	allow access to read-only SPF files	*
 * E. Safford/SAIC	02/06	fix cfl_inqr call, make 3rd param long  *
 ***********************************************************************/
{
    int	    ipos, ier, ierr;
    char    newfil[FILE_FULLSZ];
    char    filepart[MXFLSZ], pathpart[LLPATH];
    long    localFlen; 
/*---------------------------------------------------------------------*/

    *iret = G_NORMAL;
    *flen = 0;
       
    /*
     *  Check if the file suffix is ".spf". If not, add it. 
     */
    cfl_path ( filnam, pathpart, filepart, &ier ) ;   
    cst_srch ( 0, strlen(filepart), ".spf", filepart, &ipos, &ier );
    if ( ier == -4 ) {
        strcat (filnam, ".spf");
    }
    
    /*
     *  Check the file status, if it exists, open it; otherwise, create
     *  it if authorized. 
     */ 
    cfl_inqr( filnam, NULL, &localFlen, newfil, &ier ); 
    *flen = ( int ) localFlen;

    if ( ier == 0 ) { 

        *fptr = cfl_aopn( filnam, &ierr );
            
	if ( *fptr == NULL ) {
                
            *fptr = cfl_ropn( filnam, NULL, &ierr );
	    
	    if ( *fptr == NULL ) {
	        *iret = -2;
	        er_wmsg ( "CFL", &ierr, filnam, &ier, 3, strlen( filnam ) );
	    }
	    else {
	       *iret = 1; 
	    }
	
	}    

    }
    else {
    
        *iret = -1;
	
	if ( crt == TRUE ) {
       
            *fptr = ( FILE *) spf_create( filnam, flen, iret ); 
	     	
	}
	         
    }
               
}
Esempio n. 5
0
void cfl_tinq ( char *table, char *type, long *flen, char *newfil, 
								int *iret )
/************************************************************************
 * cfl_tinq								*
 *									*
 * This function returns the path to a GEMPAK table file, if the table	*
 * exists.								*
 *									*
 * The table is split into the path and filename, and the file is	*
 * located by searching in the following order:				*
 *									*
 *	1. filename (local)						*
 *	2. path/filename (table as given)				*
 *	3. $NCDESK/type/filename						*
 *	4. $NCSITE/type/filename						*
 *	5. $GEMTBL/type/filename						*
 *									*
 * void cfl_tinq ( table, type, flen, newfil, iret )			*
 *									*
 * Input parameters:							*
 *	*table		char		Table file name			*
 *	*type		char		File name type				*
 *									*
 * Output parameters:							*
 *	*flen 		long		File size				*
 *	*newfil		char		Expanded file name			*
 *	*iret		int		Return code				*
 **									*
 * S. Jacobs/NCEP	 5/01	Copied from cfl_tbop			*
 * S. Chiswell/Unidata	 3/06	Modified for $LDM/etc			*
 ***********************************************************************/
{
    int		found;
    int		lenp, lenf, lent, ier;
    long	lfsize;
    char	filepart[FILE_NAMESZ], pathpart[LLPATH];
    char	actualpath[LLPATH], pathfile[FILE_FULLSZ];

/*---------------------------------------------------------------------*/

    *iret = 0;
    found = G_FALSE;
    newfil[0] = CHNULL;
    actualpath[0] = CHNULL;
    lfsize = 0;

    /*
     *	Strip GEMTBL from beginning of the table file name if present.
     */
    if ( strstr (table, "$GEMTBL/") == table ) {
	strcpy (pathfile, &table[8]);
    } else if ( strstr (table, "GEMTBL:") == table ) {
	strcpy (pathfile, &table[7]);
    } else {
	strcpy (pathfile, table);
    }

    /*
     *	Extract the filename from the end of the path.
     */
    cfl_path ( pathfile, pathpart, filepart, &ier );
    cst_lstr ( pathpart, &lenp, &ier );
    cst_lstr ( filepart, &lenf, &ier );
    cst_lstr ( type, &lent, &ier );

    /*
     *	Check to see if the file is local.
     */
    cfl_inqr (filepart, NULL, &lfsize, actualpath, iret );
    if ( *iret == 0 ) {
	found = G_TRUE;
    }

    /*
     *	Check to see if the file is in LDMHOME/etc.
     */
    if ( found == G_FALSE) {
	cfl_inqr (filepart, LDM_ETC_PATH, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file is down a path.
     */
    if ( (found == G_FALSE) && ( lenp != 0 ) ) {
	cfl_inqr (filepart, pathpart, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in NCDESK.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$NCDESK/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in NCSITE.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$NCSITE/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in GEMTBL.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$GEMTBL/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    strcpy ( newfil, actualpath );
    *flen = lfsize;

}