Exemple #1
0
/************************************************************************
*									*
*  Update the file list from the current directory.  The files might be	*
*  added or deleted.							*
*									*/
void
filelist_update(void)
{
    if (fhdl && fhdl->filename){
	xv_set(fhdl->filename, PANEL_VALUE, "", NULL);
	(void) file_listing(dirname);
    }
}
Exemple #2
0
static void process_filespecs(void)
   {
   char* strptr ;
   unsigned i, j, k ;

   /***********************************************************************/
   /*************************  loop on filespecs  *************************/
   /***********************************************************************/

   //***********************************************************************
   //  when tree listing is selected, it is assumed that each specified
   //  argument is a separate path, and that no wildcards nor specific 
   //  filenames were provided.
   //  If such anomalies are presented, unpredictable results will occur.
   //***********************************************************************
   if (n.tree == 1  ||  n.tree == 4  ||  n.tree == 5) {
      tree_listing() ;
   }
   else if (tcount == 1  &&  !n.exec_only) {
      start = finish = 0 ;

      //  check for validity of long_filename functions
      dname[0] = (char) *target[start] ;

      // if (n.lfn_off == 1) 
      //    lfn_supported = 0 ;
      // else 
      //    IFF (is_lfn_available(dname, (char far *) fsn_bfr) != 0) 
      //    THENN 0  
      //    ELSSE 1 ;
      // lfn_supported = 1 ;
      lfn_supported = 1 - n.lfn_off ;

      //  in lfn format, convert /3 to /4
      if (lfn_supported != 0  &&  columns == 3) 
         columns = 4 ;

      //  Extract base path from first filespec,
      //  and strip off filename
      strcpy(base_path, target[start]) ;
      strptr = strrchr(base_path, '\\') ;
      if (strptr != 0) {
          strptr++ ;  //lint !e613  skip past backslash, to filename
         *strptr = 0 ;  //  strip off filename
      }
      base_len = strlen(base_path) ;

      //**************************************************
      // get_volume_label(base_path[0]) ;
      get_disk_info(base_path) ;

      //**************************************************
      //  initialize file pointer and filecount,
      //  in case of multiple filespecs.
      //**************************************************
      if (ftop != NULL)
         {
         ffdata *ftemp = ftop ;
         ffdata *fkill ;
         while (ftemp != NULL)
            {
            fkill = ftemp ;
            ftemp = ftemp->next ;
            free(fkill) ;
            }
         ftop = NULL ;
         }
      filecount = 0 ;

      //**************************************************
      //  Call directory_tree or file_listing routines,
      //  as specified by flags.
      //**************************************************
      file_listing() ;
      }
   else 
      {
      int temp_columns = columns ;

      start = 0 ;
      while (1)
         {
         //  Extract base path from first filespec,
         //  and strip off filename
         j = start ;

         //  check for validity of long_filename functions
         dname[0] = *target[start] ;
         // if (n.lfn_off == 1) 
         //    lfn_supported = 0 ;
         // else 
         //    lfn_supported =  
         //       IFF (is_lfn_available(dname, (char far *) fsn_bfr) != 0) 
         //       THENN 0  
         //       ELSSE 1 ;
         lfn_supported = 1 ;

         //  in lfn format, convert /3 to /4
         if (lfn_supported != 0  &&  columns == 3) 
            columns = 4 ;

         //  Extract base path from first filespec,
         //  and strip off filename
         strcpy(base_path, target[start]) ;
         //lint -esym(613,strptr) 
         strptr = strrchr(base_path, '\\') ;
         if (strptr != 0) {
            strptr++ ;  // skip past backslash, to filename
            *strptr = 0 ;  //  strip off filename
         }
         base_len = strlen(base_path) ;

         //**************************************************
         get_disk_info(base_path) ;

         //  seek out all other filespecs with same path
         j++ ;
         while (1) {
            if (j >= tcount) {
               finish = j-1 ;
               break;
            }
            else {
               //  strip filename from next argument
               strcpy(tempstr, target[j]) ;
               strptr = strrchr(tempstr, '\\') ;   //lint !e613
               strptr++ ;
               *strptr = 0 ;

               //  now see if they are equal
               if (strcmp(base_path, tempstr) != 0) {
                  finish = j-1 ;
                  break;
               }
               else 
                  j++ ;
            }
         }

         //********************************************************
         //  DELETE DUPLICATE FILESPECS from target array.
         //  Delete record if no differences found.   
         //  Compare file and ext separately.         
         //  This routine uses selection sort, because the list
         //  usually only has a couple of items in it.
         //********************************************************
         for (i=start ; i< finish ; i++)
         for (j=i+1   ; j<=finish ; j++) {
            //  extract filename and extension file target string
            //  to compare for duplicate filespecs.
            strcpy(fi_name, &target[i][base_len]) ;
            strptr = strrchr(fi_name, '.') ; //lint !e613
            if (strptr != 0) {
               *strptr++ = 0 ;   //lint !e613
               strcpy(fi_ext, strptr) ;
            } else {
               fi_ext[0] = 0 ;
            }

            strcpy(fj_name, &target[j][base_len]) ;
            strptr = strrchr(fj_name, '.') ; //lint !e613
            if (strptr != 0) {
               *strptr++ = 0 ;   //lint !e613
               strcpy(fj_ext, strptr) ;
            } else {
               fj_ext[0] = 0 ;
            }

            //  Scan file name and extension for equality.
            //  If both filename and extension are equal, delete one.
            if (strcmpiwc(fi_name, fj_name)  &&  strcmpiwc(fi_ext, fj_ext)) {
               strptr = target[j] ;
               for (k=j+1; k<tcount; k++)
                   target[k] = target[k+1] ;
               tcount-- ;
               finish-- ;
               j-- ;
               free(strptr) ; // release allocated struct.
            }
         }
         // Ndir32.cpp  414  Info 850: for loop index variable 'j' 
         // whose type category is 'integral' 
         // is modified in body of the for loop that began at 'line 375'

         //**************************************************
         //  initialize file pointer and filecount,
         //  in case of multiple filespecs.
         //**************************************************
         if (ftop != NULL) //lint !e850
            {
            ffdata *ftemp = ftop ;
            ffdata *fkill ;
            while (ftemp != NULL)
               {
               fkill = ftemp ;
               ftemp = ftemp->next ;
               free(fkill) ;
               }
            ftop = NULL ;
            }
         filecount = 0 ;

         //**************************************************
         //  Call directory_tree or file_listing routines,
         //  as specified by flags.
         //**************************************************
         if (n.tree == 1)
            tree_listing() ;
         else
            file_listing() ;

         start = finish + 1 ;
         if (start >= tcount) 
            break;
         ncrlf() ;

         columns = temp_columns ;
         }  //  while not done

      }  //  if multiple filespecs are present
   } /*  end  process_filespecs() */
Exemple #3
0
/************************************************************************
*									*
*  User has entered a filename.  If it is a directory, go into that     *
*  directory and list all directory files.  Otherwise, return to        *
*  the user function call.						*
*									*/
static void
file_execute_proc(void)
{
    static char markers[] = "/"; /* List of spurious symbols at end of names */
    char fullname[MAXPATHLEN];
    char filename[MAXPATHLEN];
    char *p;				/* Temp */
    char *q;
    char *uname;			/* user seleted filename */
    int i;
    struct stat statbuf;		/* status of a file */

    uname = (char *) xv_get(fhdl->filename, PANEL_VALUE);
    if (*uname == NULL){
	err_msg("No file name entered");
	return;
    }
    if (expand_filename(uname, filename) == NULL){
	err_msg("Can't expand filename");
	return;
    }

    // Strip off any trailing markers
    while ( (p=strpbrk(filename+strlen(filename)-1, markers))
	   && (p > filename))	// Don't remove everything
    {
	*p = 0;
    }

    if (*filename == '/'){
	// We have given a full path name
	strcpy(fullname, filename);
    }else{
	strcpy(fullname, dirname);
	strcat(fullname, "/");
	strcat(fullname, filename);
    }
    
    // Avoid uncontrolled pathname growth

    // Remove excess slashes ("//" is same as "/")
    while (p=strstr(fullname, "//")){
	// Move portion of string beyond first "/" down one place
	do{
	    *p = *(p+1);
	} while (*p++);
    }

    // Remove "/./" elements
    while (p=strstr(fullname, "/./")){
	// Move portion of string beyond "/." down two places
	do{
	    *p = *(p+2);
	} while (*p++);
    }

    // Remove trailing "/."
    i = strlen(fullname);
    if (strcmp(fullname+i-2, "/.") == 0){
	// Filename ends in "/."; cut it off
	fullname[i-2] = 0;
    }

    // Remove "/../" elements (along with preceding element)
    while (p=strstr(fullname, "/../")){
	q = p + 3;				// Point to following "/"
	while ( (*(--p) != '/') && (p > fullname) ); // Point to previous "/"
	do{
	    *p = *q++;			// Move following stuff down
	} while (*p++);
    }

    // Remove trailing "/.." (along with preceding element)
    i = strlen(fullname);
    if (strcmp(fullname+i-3, "/..") == 0){
	// Filename ends in "/.."; cut off last two elements
	for (i=0; (i<2) && (p=strrchr(fullname, '/')); i++){
	    *p = 0;
	}
    }

    // Make sure something is left of the name
    if ( *fullname == 0 ){
	strcpy(fullname, "/");
    }

    int staterr;
    if ((staterr=stat(fullname, &statbuf)) == 0
	&& (statbuf.st_mode & S_IFMT) == S_IFDIR)
    {
	strcpy(dirname, fullname);
	
	/* Get the files */
	if (file_listing(dirname) == NOT_OK){
	    err_msg("Error in file_listing");
	    return;
	}

	/* Update the directory message */
	show_dir_path(short_path(dirname));
	xv_set(fhdl->filename, PANEL_VALUE, "", NULL);

	/* Remember new default directory */
	if (curfinfo){
	    free(curfinfo->dirpath);
	    curfinfo->dirpath = strdup(dirname);
	}
    }else{
	if (curfinfo == NULL){
	    err_msg("No registered function");
	    return;
	}
	/* in this case we will only load/save one file */
	if (xv_get(fhdl->load_but, PANEL_SHOW_ITEM) == TRUE){
	    if (staterr){
		err_msg("Can't find file: %s", short_path(fullname));
		return;
	    }else if ((statbuf.st_mode & S_IFMT) != S_IFREG){
		err_msg("Error: Invalid file or directory.");
		return;
	    }else{
		if (curfinfo->loadfunc){
		    curfinfo->loadfunc(dirname, filename);
		}
	    }
	}else{
	    if (curfinfo->savefunc && (staterr||confirm_overwrite(filename))){
		curfinfo->savefunc(dirname, filename);
	    }
	}
    }
}
Exemple #4
0
/************************************************************************
*									*
*  Pop up the filelist frame.						*
*  Note that "state" indicates the file-browser for loading or saving.	*
*  The "dir_path" indicates go to the specified directory.  If it is	*
*  NULL, use the default directory (which is kept in Fileinfo).		*
*  The title name will be shown in the title window. If it is NULL,	*
*  the title "File Browser" will be shown.				*
*									*/
void
filelist_win_show(long id,		/* which filelist */
		  Flist_state state,	/* FILELIST_LOAD, FILELIST_LOAD_ALL, */
					/* or FILELIST_SAVE */
		  char *dir_path,	/* destination directory */
		  char *title,		/* Title of file-browser */
		  char *button_name)	/* string to put in button */
{					
    Fileinfo *newcurfinfo;		/* new current curfinfo */
    char dest_dir[MAXPATHLEN];		/* destination directory to list */
    char temp[1024];			/* temporary buffer */

    /* Create filelist window if it is not created */
    if (fhdl->popup == NULL){
	file_create_win();
    }

    err_msg("");

    if (state == FILELIST_LOAD){
	xv_set(fhdl->load_but, PANEL_SHOW_ITEM, TRUE, NULL);
	xv_set(fhdl->load_all_but, PANEL_SHOW_ITEM, FALSE, NULL);
	xv_set(fhdl->save_but, PANEL_SHOW_ITEM, FALSE, NULL);
	xv_set(fhdl->filemsg, PANEL_LABEL_STRING, LOAD_FILE_MSG, NULL);
	/* Change the button name  */
	xv_set(fhdl->load_but, PANEL_LABEL_STRING,
	       button_name ? button_name : "Load", NULL);

    }else if (state == FILELIST_LOAD_ALL){
	xv_set(fhdl->load_but, PANEL_SHOW_ITEM, TRUE, NULL);
	xv_set(fhdl->load_all_but, PANEL_SHOW_ITEM, TRUE, NULL);
	xv_set(fhdl->save_but, PANEL_SHOW_ITEM, FALSE, NULL);
	xv_set(fhdl->filemsg, PANEL_LABEL_STRING, LOAD_FILE_MSG, NULL);
	strcpy(temp, button_name ? button_name : "Load");
	xv_set(fhdl->load_but, PANEL_LABEL_STRING, temp, NULL);
	xv_set(fhdl->load_all_but, PANEL_LABEL_STRING,
	       strcat(temp, " All"), NULL);
    }else if (state == FILELIST_SAVE){
	xv_set(fhdl->load_but, PANEL_SHOW_ITEM, FALSE, NULL);
	xv_set(fhdl->load_all_but, PANEL_SHOW_ITEM, FALSE, NULL);
	xv_set(fhdl->save_but, PANEL_SHOW_ITEM, TRUE, NULL);
	xv_set(fhdl->filemsg, PANEL_LABEL_STRING, SAVE_FILE_MSG, NULL);
	xv_set(fhdl->save_but, PANEL_LABEL_STRING,
	       button_name ? button_name : "Save", NULL);
    }else{
	STDERR_1("filelist_win_show:No known state: %d", state);
	return;
    }

    /* Change the title */
    xv_set(fhdl->popup, FRAME_LABEL, title ? title : "File Browser", NULL);

    /* Find the requested ID */
    for (newcurfinfo=finfoheader; newcurfinfo; newcurfinfo=newcurfinfo->next){
	if (newcurfinfo->id == id){
	    break;
	}
    }

    if (newcurfinfo == NULL){
	STDERR_1("filelist_win_show:No such ID registered: %d", id);
	return;
    }
    if (dir_path){
	(void) strcpy(dest_dir, dir_path);	/* Use requested directory */
    }else{
	(void) strcpy(dest_dir, newcurfinfo->dirpath);	/* Use default dir. */
    }

    strcpy(dirname, dest_dir);

    /* Listing the files */
    file_listing(dirname);

    /* Update the directory message */
    show_dir_path(short_path(dirname));

    /* Update the current curfinfo */
    curfinfo = newcurfinfo;

    xv_set(fhdl->popup,
	   FRAME_CMD_PUSHPIN_IN, TRUE,
	   XV_SHOW, TRUE,
	   NULL);
}