Ejemplo n.º 1
0
void ViewTableListWidget::getViews()
{
    QDir rootdir("view//");
    rootdir.setFilter(rootdir.filter()|QDir::NoDotAndDotDot);
    QStringList strings;
    strings<<"*";
    list = rootdir.entryInfoList(strings);
    qDebug()<<list.length();
    //QFileInfoList list = rootdir.entryInfoList(strings);
   // qDebug()<<*list.begin();

    QFileInfoList::iterator i = list.begin();
    QFileInfo tempinfo;
    while(i != list.end())
    {
        tempinfo = *i;
        if(tempinfo.completeBaseName()==QString(tr("纯C程序题")))
        {
            //qDebug()<<tr("相等");
         //   rename("view//asdsagashg","view//newfilename");
           // tempinfo.setFile("haha");
        }
      //  qDebug()<<tempinfo.completeBaseName();
        i++;
    }
   /* list.clear();
    qDebug()<<list.length();*/
}
Ejemplo n.º 2
0
/***********************************************************************//**
 * @brief Initalisation constructor
 *
 * @param[in] pathname Calibration database root directory.
 *
 * This constructor sets the calibration database using the specified root
 * directory. Unless the specified pathname is not empty, any existing CALDB
 * environment variables will be ignored.
 ***************************************************************************/
GCaldb::GCaldb(const std::string& pathname)
{
    // Initialise members
    init_members();

    // If pathname is not empty then use it as root pathname
    if (pathname.length() > 0) {
        rootdir(gammalib::expand_env(pathname));
    }

    // Return
    return;
}
Ejemplo n.º 3
0
int main(void)
{
    //[enumerate_example
    std::shared_ptr<boost::afio::async_file_io_dispatcher_base> dispatcher=
        boost::afio::make_async_file_io_dispatcher();
    
    // Schedule an opening of the root directory
    boost::afio::async_io_op rootdir(dispatcher->dir(boost::afio::async_path_op_req("/")));
    
    std::pair<std::vector<boost::afio::directory_entry>, bool> list;
    // This is used to reset the enumeration to the start
    bool restart=true;
    do
    {
        // Schedule an enumeration of an open directory handle
        // Note it returns a future to the results and an op ref 
        std::pair<
            boost::afio::future<std::pair<std::vector<boost::afio::directory_entry>, bool>>,
            boost::afio::async_io_op
        >  enumeration(
            dispatcher->enumerate(boost::afio::async_enumerate_op_req(
                /* This is the handle to enumerate */
                rootdir,
                /* This is the maximum entries to enumerate. Note
                the use of compatibility_maximum() which is the
                same value your libc uses. The problem with smaller
                enumerations is that the directory contents can change
                out from underneath you more frequently. */
                boost::afio::directory_entry::compatibility_maximum(),
                /* True if to reset enumeration */
                restart)));
        restart=false;
        
        // People using AFIO often forget that futures can be waited
        // on normally without needing to wait on the op handle
        list=enumeration.first.get();
        for(boost::afio::directory_entry &i : list.first)
        {
#ifdef WIN32
            std::wcout << i.name();
#else
            std::cout << i.name();
#endif
            std::cout << " type " << static_cast<int>(i.st_type()) << std::endl;
        }
    } while(list.second);
    //]
}
Ejemplo n.º 4
0
int
__statfsx64 (const char *file, struct statfsx64 *buf)
{
	char *RootDirectory = rootdir (file);
	int res = 0;
	
	if ((RootDirectory == NULL) ) {// || access (file, F_OK)) { // || (GetDriveType(RootDirectory) == DRIVE_REMOVABLE)) {
//   	fprintf(stderr, "__statfsx64: RootDirectory: %s\n", RootDirectory);
		buf = NULL;
		_set_errno(ENOENT);
		res = -1;
	}
	else
		res = __rstatfsx64 ((const char *) RootDirectory, buf);
	free (RootDirectory);
	return res;
}
Ejemplo n.º 5
0
/***********************************************************************//**
 * @brief Return path to calibration directory
 *
 * @param[in] mission Mission name (case insensitive).
 * @param[in] instrument Instrument name (case insensitive; optional).
 *
 * @exception GException::directory_not_found
 *            Calibration directory not found.
 * @exception GException::directory_not_accessible
 *            No read permission granted to calibration directory.
 *
 * The calibration directory path is given by one of the following
 *
 *     $CALDB/data/<mission>
 *     $CALDB/data/<mission>/<instrument>
 *
 * where \<mission\> is the name of the mission and \<instrument\> is the
 * optional instrument name (all lower case). The arguments provided to the
 * method are transformed to lower case.
 ***************************************************************************/
std::string GCaldb::path(const std::string& mission, const std::string& instrument)
{
    // Verify that mission name is valid and directory is accessible
    std::string path = rootdir() + "/data/" + gammalib::tolower(mission);
    if (!gammalib::dir_exists(path)) {
        throw GException::directory_not_found(G_PATH, path,
              "Requested mission \""+gammalib::toupper(mission)+"\" not found in"
              " calibration database.");
    }
    if (access(path.c_str(), R_OK) != 0) {
        throw GException::directory_not_accessible(G_PATH, path,
              "Requested read permission not granted for mission \""+
              gammalib::toupper(mission)+"\".");
    }

    // If an instrument has been specified, verify that instrument name is
    // valid and directory is accessible
    if (instrument.length() > 0) {

        // Add instrument to path
        path += "/" + gammalib::tolower(instrument);

        // Verify path
        if (!gammalib::dir_exists(path)) {
            throw GException::directory_not_found(G_PATH, path,
                  "Requested instrument \""+gammalib::toupper(instrument)+"\" on"
                  " mission \""+gammalib::toupper(mission)+"\" not found in"
                  " calibration database.");
        }
        if (access(path.c_str(), R_OK) != 0) {
            throw GException::directory_not_accessible(G_PATH, path,
                "Requested read permission not granted for instrument \""+
                gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+
                "\".");
        }
        
    } // endif: instrument has been specified
    
    // Return path
    return path;
}
Ejemplo n.º 6
0
void ViewTableListWidget::addViewName(QString str)
{
    qDebug()<<tr("信号发射成功")<<str;
    QDir rootdir("view//");
    rootdir.setFilter(rootdir.filter()|QDir::NoDotAndDotDot);
    QStringList strings;
    strings<<str;
     QFileInfo tempinfo = *(rootdir.entryInfoList(strings).begin());
     qDebug()<<tempinfo.absolutePath();
    this->insertRow(rowCount());
    int temprow = rowCount()-1;
    QTableWidgetItem * item = new QTableWidgetItem(QIcon("images/historicalcurve.jpg"),tempinfo.fileName());
    item->setToolTip(item->text());
    this->setItem(temprow,0,item);
    this->setItem(temprow,1,new QTableWidgetItem(tempinfo.suffix()));
    item = new QTableWidgetItem("0");
    item->setTextAlignment(Qt::AlignCenter);
    this->setItem(temprow,2,item);
    item = new QTableWidgetItem(tempinfo.lastModified().toString("yyyy-MM-dd hh:mm"));
    item->setTextAlignment(Qt::AlignCenter);
    this->setItem(temprow,3,item);
    modifyViewTable();
}
Ejemplo n.º 7
0
/***********************************************************************//**
 * @brief Print calibration database information
 *
 * @param[in] chatter Chattiness (defaults to NORMAL).
 * @return String containing calibration database information.
 ***************************************************************************/
std::string GCaldb::print(const GChatter& chatter) const
{
    // Initialise result string
    std::string result;

    // Continue only if chatter is not silent
    if (chatter != SILENT) {

        // Append Header
        result.append("=== GCaldb ===");

        // Append information
        result.append("\n"+gammalib::parformat("Database root"));
        try {
            result.append(rootdir());
        }
        catch (std::exception& e) {
            result.append("undefined");
        }

        // Append information about opened database
        if (m_cif != NULL) {
            result.append("\n"+gammalib::parformat("Selected Mission"));
            result.append(gammalib::toupper(m_mission));
            result.append("\n"+gammalib::parformat("Selected Instrument"));
            result.append(gammalib::toupper(m_instrument));
            result.append("\n"+gammalib::parformat("Calibration Index File"));
            result.append(m_cifname);
            result.append("\n"+gammalib::parformat("Number of entries"));
            result.append(gammalib::str(size()));
        }

    } // endif: chatter was not silent
    
    // Return
    return result;
}
Ejemplo n.º 8
0
/*================================================================
 *                    mkfs  -  make filesystem
 *===============================================================*/
int
main(int argc, char *argv[])
{
  int nread, mode, usrid, grpid, ch, extra_space_percent, Tflag = 0;
  block_t blocks, maxblocks, bblocks;
  ino_t inodes, root_inum;
  char *token[MAX_TOKENS], line[LINE_LEN], *sfx;
  struct fs_size fssize;
  int insertmode = 0;

  progname = argv[0];

  /* Process switches. */
  blocks = 0;
  inodes = 0;
  bblocks = 0;
#ifndef MFS_STATIC_BLOCK_SIZE
  block_size = 0;
#endif
  zone_shift = 0;
  extra_space_percent = 0;
  while ((ch = getopt(argc, argv, "B:b:di:ltvx:z:I:T:")) != EOF)
	switch (ch) {
#ifndef MFS_STATIC_BLOCK_SIZE
	    case 'B':
		block_size = strtoul(optarg, &sfx, 0);
		switch(*sfx) {
		case 'b': case 'B': /* bytes; NetBSD-compatible */
		case '\0':	break;
		case 'K':
		case 'k':	block_size*=1024; break;
		case 's': 	block_size*=SECTOR_SIZE; break;
		default:	usage();
		}
		break;
#else
	    case 'B':
		if (block_size != strtoul(optarg, (char **) NULL, 0))
			errx(4, "block size must be exactly %d bytes",
			    MFS_STATIC_BLOCK_SIZE);
		break;
		(void)sfx;	/* shut up warnings about unused variable...*/
#endif
	    case 'I':
		fs_offset_bytes = strtoul(optarg, (char **) NULL, 0);
		insertmode = 1;
		break;
	    case 'b':
		blocks = bblocks = strtoul(optarg, (char **) NULL, 0);
		break;
	    case 'T':
		Tflag = 1;
		current_time = strtoul(optarg, (char **) NULL, 0);
		break;
	    case 'd':
		dflag = 1;
		break;
	    case 'i':
		inodes = strtoul(optarg, (char **) NULL, 0);
		break;
	    case 'l':	print = 1;	break;
	    case 't':	donttest = 1;	break;
	    case 'v':	++verbose;	break;
	    case 'x':	extra_space_percent = atoi(optarg); break;
	    case 'z':	zone_shift = atoi(optarg);	break;
	    default:	usage();
	}

  if (argc == optind) usage();

  /* Get the current time, set it to the mod time of the binary of
   * mkfs itself when the -d flag is used. The 'current' time is put into
   * the i_mtimes of all the files.  This -d feature is useful when
   * producing a set of file systems, and one wants all the times to be
   * identical. First you set the time of the mkfs binary to what you
   * want, then go.
   */
  if(Tflag) {
    if(dflag)
	errx(1, "-T and -d both specify a time and so are mutually exclusive");
  } else if(dflag) {
	struct stat statbuf;
	if (stat(progname, &statbuf)) {
		err(1, "stat of itself");
	}
	current_time = statbuf.st_mtime;
  } else {
	  current_time = time((time_t *) 0);	/* time mkfs is being run */
  }

  /* Percentage of extra size must be nonnegative.
   * It can legitimately be bigger than 100 but has to make some sort of sense.
   */
  if(extra_space_percent < 0 || extra_space_percent > 2000) usage();

#ifdef DEFAULT_BLOCK_SIZE
  if(!block_size) block_size = DEFAULT_BLOCK_SIZE;
#endif
  if (block_size % SECTOR_SIZE)
	errx(4, "block size must be multiple of sector (%d bytes)", SECTOR_SIZE);
#ifdef MIN_BLOCK_SIZE
  if (block_size < MIN_BLOCK_SIZE)
	errx(4, "block size must be at least %d bytes", MIN_BLOCK_SIZE);
#endif
#ifdef MAX_BLOCK_SIZE
  if (block_size > MAX_BLOCK_SIZE)
	errx(4, "block size must be at most %d bytes", MAX_BLOCK_SIZE);
#endif
  if(block_size%INODE_SIZE)
	errx(4, "block size must be a multiple of inode size (%d bytes)", INODE_SIZE);

  if(zone_shift < 0 || zone_shift > 14)
	errx(4, "zone_shift must be a small non-negative integer");
  zone_per_block = 1 << zone_shift;	/* nr of blocks per zone */

  inodes_per_block = INODES_PER_BLOCK(block_size);
  indir_per_block = INDIRECTS(block_size);
  indir_per_zone = INDIRECTS(block_size) << zone_shift;
  /* number of file zones we can address directly and with a single indirect*/
  nr_indirzones = NR_DZONES + indir_per_zone;
  zone_size = block_size << zone_shift;
  /* Checks for an overflow: only with very big block size */
  if (zone_size <= 0)
	errx(4, "Zones are too big for this program; smaller -B or -z, please!");

  /* now that the block size is known, do buffer allocations where
   * possible.
   */
  zero = alloc_block();

  fs_offset_blocks = roundup(fs_offset_bytes, block_size) / block_size;

  /* Determine the size of the device if not specified as -b or proto. */
  maxblocks = sizeup(argv[optind]);
  if (bblocks != 0 && bblocks + fs_offset_blocks > maxblocks && !insertmode) {
	errx(4, "Given size -b %d exeeds device capacity(%d)\n", bblocks, maxblocks);
  }

  if (argc - optind == 1 && bblocks == 0) {
  	blocks = maxblocks;
  	/* blocks == 0 is checked later, but leads to a funny way of
  	 * reporting a 0-sized device (displays usage).
  	 */
  	if(blocks < 1) {
  		errx(1, "zero size device.");
	}
  }

  /* The remaining args must be 'special proto', or just 'special' if the
   * no. of blocks has already been specified.
   */
  if (argc - optind != 2 && (argc - optind != 1 || blocks == 0)) usage();

  if (maxblocks && blocks > maxblocks && !insertmode) {
 	errx(1, "%s: number of blocks too large for device.", argv[optind]);
  }

  /* Check special. */
  check_mtab(argv[optind]);

  /* Check and start processing proto. */
  optarg = argv[++optind];
  if (optind < argc && (proto = fopen(optarg, "r")) != NULL) {
	/* Prototype file is readable. */
	lct = 1;
	get_line(line, token);	/* skip boot block info */

	/* Read the line with the block and inode counts. */
	get_line(line, token);
	if (bblocks == 0){
		blocks = strtol(token[0], (char **) NULL, 10);
	} else {
		if(bblocks < strtol(token[0], (char **) NULL, 10)) {
 			errx(1, "%s: number of blocks given as parameter(%d)"
				" is too small for given proto file(%d).", 
				argv[optind], bblocks, 
				strtol(token[0], (char **) NULL, 10));
		};
	}
	inodes = strtol(token[1], (char **) NULL, 10);

	/* Process mode line for root directory. */
	get_line(line, token);
	mode = mode_con(token[0]);
	usrid = atoi(token[1]);
	grpid = atoi(token[2]);

	if(blocks <= 0 && inodes <= 0){
		detect_fs_size(&fssize);
		blocks = fssize.blockcount;
		inodes = fssize.inocount;
		blocks += blocks*extra_space_percent/100;
		inodes += inodes*extra_space_percent/100;
/* XXX is it OK to write on stdout? Use warn() instead? Also consider using verbose */
		fprintf(stderr, "dynamically sized filesystem: %u blocks, %u inodes\n",
		    (unsigned int) blocks, (unsigned int) inodes);
	}
  } else {
	lct = 0;
	if (optind < argc) {
		/* Maybe the prototype file is just a size.  Check. */
		blocks = strtoul(optarg, (char **) NULL, 0);
		if (blocks == 0) errx(2, "Can't open prototype file");
	}

	/* Make simple file system of the given size, using defaults. */
	mode = 040777;
	usrid = BIN;
	grpid = BINGRP;
	simple = 1;
  }

  if (inodes == 0) {
	long long kb = ((unsigned long long)blocks*block_size) / 1024;

	inodes = kb / 2;
	if (kb >= 100000) inodes = kb / 4;
	if (kb >= 1000000) inodes = kb / 6;
	if (kb >= 10000000) inodes = kb / 8;
	if (kb >= 100000000) inodes = kb / 10;
	if (kb >= 1000000000) inodes = kb / 12;
/* XXX check overflow: with very large number of blocks, this results in insanely large number of inodes */
/* XXX check underflow (if/when ino_t is signed), else the message below will look strange */

	/* round up to fill inode block */
	inodes += inodes_per_block - 1;
	inodes = inodes / inodes_per_block * inodes_per_block;
  }

  if (blocks < 5) errx(1, "Block count too small");
  if (inodes < 1) errx(1, "Inode count too small");

  nrblocks = blocks;
  nrinodes = inodes;

  umap_array_elements = 1 + blocks/8;
  if(!(umap_array = malloc(umap_array_elements)))
	err(1, "can't allocate block bitmap (%u bytes).",
		(unsigned)umap_array_elements);

  /* Open special. */
  special(argv[--optind], insertmode);

  if (!donttest) {
	uint16_t *testb;
	ssize_t w;

	testb = alloc_block();

	/* Try writing the last block of partition or diskette. */
	mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
	testb[0] = 0x3245;
	testb[1] = 0x11FF;
	testb[block_size/2-1] = 0x1F2F;
	w=mkfs_write(testb, block_size);
	sync();			/* flush write, so if error next read fails */
	mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
	testb[0] = 0;
	testb[1] = 0;
	testb[block_size/2-1] = 0;
	nread = read(fd, testb, block_size);
	if (nread != block_size || testb[0] != 0x3245 || testb[1] != 0x11FF ||
	    testb[block_size/2-1] != 0x1F2F) {
		warn("nread = %d\n", nread);
		warnx("testb = 0x%x 0x%x 0x%x\n",
		    testb[0], testb[1], testb[block_size-1]);
		errx(1, "File system is too big for minor device (read)");
	}
	mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
	testb[0] = 0;
	testb[1] = 0;
	testb[block_size/2-1] = 0;
	mkfs_write(testb, block_size);
	mkfs_seek(0L, SEEK_SET);
	free(testb);
  }

  /* Make the file-system */

  put_block(BOOT_BLOCK, zero);		/* Write a null boot block. */
  put_block(BOOT_BLOCK+1, zero);	/* Write another null block. */

  super(nrblocks >> zone_shift, inodes);

  root_inum = alloc_inode(mode, usrid, grpid);
  rootdir(root_inum);
  if (simple == 0) eat_dir(root_inum);

  if (print) print_fs();
  else if (verbose > 1) {
	  if (zone_shift)
		fprintf(stderr, "%d inodes used.     %u zones (%u blocks) used.\n",
		    (int)next_inode-1, next_zone, next_zone*zone_per_block);
	  else
		fprintf(stderr, "%d inodes used.     %u zones used.\n",
		    (int)next_inode-1, next_zone);
  }

  if(insertmode) printf("%ld\n", written_fs_size);

  return(0);

  /* NOTREACHED */
}				/* end main */
Ejemplo n.º 9
0
/***********************************************************************//**
 * @brief Return calibration file name based on selection parameters
 *
 * @param[in] detector Detector name (not used if empty).
 * @param[in] filter Filter name (not used if empty).
 * @param[in] codename Code name (not used if empty).
 * @param[in] date Date in yyyy-mm-dd format (not used if empty).
 * @param[in] time Time in hh:mm:ss format (not used if empty).
 * @param[in] expr Boolean selection expression (not used if empty).
 * @return Calibration filename (empty if not found).
 *
 * Returns a calibration file name based on selection parameters. If more
 * files satisfy the specified selection parameters, the first file will
 * be returned.
 *
 * @todo data should support "now" and probably be implemented using < condition.
 * @todo time should support "now" and probably be implemented using < condition.
 * @todo expr should support arbitrary Boolean expressions.
 ***************************************************************************/
GFilename GCaldb::filename(const std::string& detector,
                           const std::string& filter,
                           const std::string& codename,
                           const std::string& date,
                           const std::string& time,
                           const std::string& expr)
{
    // Initialise empty filename
    GFilename filename;

    // Continue only if CIF is opened
    if (m_cif != NULL) {

        // Loop over all CIF entries
        for (int i = 0; i < size(); ++i) {

            // Initialise selection flags
            bool match_detector = false;
            bool match_filter   = false;
            bool match_codename = false;
            bool match_date     = false;
            bool match_time     = false;
            bool match_expr     = false;

            // Check for detector
            if (detector.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["DETNAM"];
                if (gammalib::toupper(detector) ==
                    gammalib::toupper(column->string(i))) {
                    match_detector = true;
                }
            }
            else {
                match_detector = true;
            }

            // Check for filter
            if (filter.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["FILTER"];
                if (gammalib::toupper(filter) ==
                    gammalib::toupper(column->string(i))) {
                    match_filter = true;
                }
            }
            else {
                match_filter = true;
            }

            // Check for code name
            if (codename.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["CAL_CNAM"];
                if (gammalib::toupper(codename) ==
                    gammalib::toupper(column->string(i))) {
                    match_codename = true;
                }
            }
            else {
                match_codename = true;
            }

            // Check for date
            if (date.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["CAL_VSD"];
                if (gammalib::toupper(date) ==
                    gammalib::toupper(column->string(i))) {
                    match_date = true;
                }
            }
            else {
                match_date = true;
            }

            // Check for time
            if (time.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["CAL_VST"];
                if (gammalib::toupper(time) ==
                    gammalib::toupper(column->string(i))) {
                    match_time = true;
                }
            }
            else {
                match_time = true;
            }

            // Check for expression
            if (expr.length() > 0) {
                const GFitsTableCol* column = (*m_cif)["CAL_CBD"];
                int num_columns = column->elements(i);
                for (int k = 0; k < num_columns; ++k) {
                    if (gammalib::toupper(expr) ==
                        gammalib::toupper(column->string(i,k))) {
                        match_expr = true;
                        break;
                    }
                }
            }
            else {
                match_expr = true;
            }

            // Select file if all selection match
            if (match_detector && match_filter && match_codename &&
                match_date && match_time && match_expr) {
                const GFitsTableCol* cal_dir  = (*m_cif)["CAL_DIR"];
                const GFitsTableCol* cal_file = (*m_cif)["CAL_FILE"];
                std::string path              = rootdir();
                if (path.empty()) {
                    filename = cal_dir->string(i) + "/" +
                               cal_file->string(i);
                }
                else {
                    filename = path + "/" +
                               cal_dir->string(i) + "/" +
                               cal_file->string(i);
                }
                break;
            }

        } // endfor: looped over all CIF entries
        
    } // endif: CIF has been opened

    // Return filename
    return filename;
}