// ファイルリストを作成する(top level)
int makeFileListTop(const char* top_dir)
{
	int		res;

	for (int i = 0; i < _countof(s_exp_list); i++) {
		if ((res = makeFileList(top_dir, "", s_exp_list[i])) != 0)
			return res;
	}
	return 0;
}
// ファイルリストを作成する
int makeFileList(std::string top_dir, std::string dir, SExpList sexp)
{
	std::string			path;
	std::string			fl_nm;
	HANDLE				hFind;
	WIN32_FIND_DATAA	ffData;

	path = top_dir + "/" + dir;
	if (dir != "") {
		path += "/";
	}
	path = path + "*" + sexp.exp;

	hFind = ::FindFirstFileA(path.c_str(), &ffData);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			if (sexp.type == EXP_DIR) {
				// search subdirectory
				if ((ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
						(strcmp(ffData.cFileName, ".") != 0 && strcmp(ffData.cFileName, "..") != 0)) {

					fl_nm = ffData.cFileName;
					if (dir != "") {
						fl_nm = dir + "/" + fl_nm;
					}

					// search subdirectory
					int		res;
					for (int i = 0; i < _countof(s_exp_list); i++) {
						if ((res = makeFileList(top_dir, fl_nm, s_exp_list[i])) != 0) {
							::FindClose(hFind);
							return res;
						}
					}
				}
			}
			else {
				std::string fl_nm;

				fl_nm = ffData.cFileName;
				fl_nm.resize(fl_nm.size() - strlen(sexp.exp));	// 拡張子削除
				if (dir != "") {
					fl_nm = dir + "/" + fl_nm;
				}

				//add to list
				file_list.push_back( fl_nm );
			}
		} while(::FindNextFileA(hFind, &ffData));
		::FindClose(hFind);
	}
	return 0;
}
Ejemplo n.º 3
0
int main(int argv, char** argc)
{
    File* hw;
    Marker* markers;
    Marker* it;
    const char* markersPath;
    const char* hwPath;
    FILE* outFile;

    if (argv != 3)
    {
        printf("Usage: %s markers homeworks\n", argc[0]);
        printf("markers: Markers file path.\n");
        printf("files: HW files path.\n");
        exit(EXIT_FAILURE);
    }

    markersPath = argc[1];
    hwPath = argc[2];

    markers = readMarkers(markersPath);

    srand(time(NULL));
    rand();
    rand();

    hw = makeFileList(hwPath);
    markers = distribute(hw, markers);
    markers = sortMarkers(markers, numMarkers(markers));
    for (it = markers; it; it = it->next)
    {
        it->files = sortFiles(it->files, numFiles(it->files));
    }

    printMarkers(markers);

    for (it = markers; it; it = it->next)
    {
        free((void*)it->name);
    }

    freeMarkers(markers);
    freeFiles(hw);

    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    Mpr         *mpr;
    MprList     *files;
    char        *argp, *prefix, *romName;
    int         nextArg, err;

    mpr = mprCreate(argc, argv, 0);

    err = 0;
    prefix = "";
    romName = "defaultRomFiles";
    files = mprCreateList(mpr);

    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-') {
            break;
        }

        if (strcmp(argp, "--prefix") == 0) {
            if (nextArg >= argc) {
                err++;
            } else {
                prefix = argv[++nextArg];
            }

        } else if (strcmp(argp, "--name") == 0) {
            if (nextArg >= argc) {
                err++;
            } else {
                romName = argv[++nextArg];
            }

        } else if (strcmp(argp, "--files") == 0) {
            if (nextArg >= argc) {
                err++;
            } else {
                if (makeFileList(mpr, files, argv[++nextArg]) < 0) {
                    exit(2);
                }
            }
        }
    }
    if (nextArg >= argc) {
        err++;
    }

    if (err) {
        printUsage(mpr);
        exit(2);
    }   

    while (nextArg < argc) {
        mprAddItem(files, argv[nextArg++]);
    }

    if (binToC(mpr, files, romName, prefix) < 0) {
        return MPR_ERR;
    }
    return 0;
}
Ejemplo n.º 5
0
void doLLSCommand(int sid)
{
    printf("Got: [\n%s]\n",makeFileList("."));
}
int initFat()
{
	MBR_structTypedef mbr;
	BiosParameterBlockFAT16_structTypedef biosParameterBlock;

	memset((void*)&fat, 0, sizeof(fat_typedef));
	memset((void*)&cursor, 0, sizeof(cursor_typedef));

	memcpy((char*)fat.currentDirName, (char*)root_str, sizeof(root_str));

	if(!cardInfo.ready){
		return -1;
	}

	SDBlockRead(&mbr, 0); // read mbr

	int i, j, part_id = -1;
	for(j = 0;j < 4;j++){ // search fat partition
		for(i = 0;i < sizeof(partition_system_id) / sizeof(partition_system_id[0]);i++){
			if(mbr.partition_table[j].systemID == partition_system_id[i]){
				part_id = j;
				if(partition_system_id[i] == 0xb || partition_system_id[i] == 0xc){
					fat.fsType = FS_TYPE_FAT32;
				} else {
					fat.fsType = FS_TYPE_FAT16;
				}
			}
		}
		if(part_id != -1){
			break;
		}
	}

	if(part_id == -1){
		return FS_ERROR_TYPE;
	}

	fat.biosParameterBlock = mbr.partition_table[part_id].relative_sectors; // bios parameter block start sector

	SDBlockRead(&biosParameterBlock, fat.biosParameterBlock); // read bios parameter block

	if(biosParameterBlock.bytesPerSector != 512){ // bytes/cluster must be 512B
		debug.printf("\r\nbiosParameterBlock.bytesPerSector:%d", biosParameterBlock.bytesPerSector);
		return FS_ERROR_BYTES_PER_CLUSTER;
	}

	if((fat.sectorsPerCluster = biosParameterBlock.sectorsPerCluster) < 1){ // cluster size
		return FS_ERROR_CLUSTER_SIZE;
	}

	fat.bytesPerCluster = fat.sectorsPerCluster * 512;	// bytes/cluster

	fat.clusterDenomShift = 0;
	while(!(fat.bytesPerCluster & (1 << fat.clusterDenomShift++))){}; // Cluster bytes right shift denominator
	fat.clusterDenomShift = fat.clusterDenomShift - 1;

	fat.reservedSectors = biosParameterBlock.reservedSectors;

	if(fat.fsType == FS_TYPE_FAT16){
		fat_func.getNCluster = getNClusterCache;

		fat.sectorsPerFAT = biosParameterBlock.sectorsPerFAT; // sectors/FAT

		fat.rootDirEntry = fat.biosParameterBlock + fat.reservedSectors + fat.sectorsPerFAT * 2; // root directory entry
		fat.userDataSector = fat.rootDirEntry + 0x20;	// user data sector
	} else {
		fat_func.getNCluster = getNClusterCache;

		BiosParameterBlockFAT32_structTypedef *biosParameterBlockFAT32;
		biosParameterBlockFAT32 = (BiosParameterBlockFAT32_structTypedef*)&biosParameterBlock;

		fat.sectorsPerFAT = biosParameterBlockFAT32->bigSectorsPerFAT; // sectors/FAT

		fat.userDataSector = fat.biosParameterBlock + fat.reservedSectors + fat.sectorsPerFAT * 2;	// user data sector

		fat.rootDirEntry = (uint32_t)(biosParameterBlockFAT32->rootDirStrtClus - 2) * fat.sectorsPerCluster + fat.userDataSector; // root directory entry
	}
	fat.fatTable = fat.biosParameterBlock + fat.reservedSectors;

	fat.currentDirEntry = fat.rootDirEntry;

	makeFileList();

	return 0;
}