int main(int argc, char* argv[]){ //for index or etc int n; //for option extern char* optarg; extern int optind; struct option longOptArgs[] = { {"all", 0, NULL, 'a'}, {"inode", 0, NULL, 'i'}, {"format", 1, NULL, 'l'}, {"recursive", 0, NULL, 'R'}, {NULL, 0, NULL, 0} }; int allSet = 0; int inodeSet = 0; int listSet = 0; int recurSet = 0; while (( n = getopt_long(argc, argv, "ailR", longOptArgs, NULL)) != -1){ switch (n) { case 'a': allSet = 1; break; case 'i': inodeSet = 1; break; case 'l': if (optarg == NULL){ listSet = 1; break; } if ( (strcmp("verbose", optarg) == 0) || (strcmp("long", optarg) == 0 ) ) listSet = 1; break; case 'R': recurSet = 1; break; default: break; } } if(argv[optind] == NULL){ lsDir(".", ".", allSet, inodeSet, listSet, recurSet); } else { lsDir(argv[optind], argv[optind], allSet, inodeSet, listSet, recurSet); } return 0; }
/* argv[1] = dirName; */ int main(int argc, char *argv[]){ FILE* dirFile= fopen("fileData.txt", "w"); char *message= (char*)malloc(MAXMESSAGESIZE); lsDir(dirFile, argv[1]); fclose(dirFile); FILE* readFile = fopen("fileData.txt","r"); int counter = 0; while (!feof(readFile)){ strcpy(message, getFrametoSend(readFile)); //printf("%s", message); } //printf("ok\n"); fclose(readFile); free(message); }
void AssetManager::loadAllLanguageSupport() { QDir lsDir(LIBS_FILEPATH + "/language_support"); QFileInfoList allLs = lsDir.entryInfoList(); foreach (QFileInfo fileI, allLs){ // if is a file and is a cfg file if (!fileI.isDir() && fileI.completeSuffix() == "cfg") { // open and begin reading each file QFile file(fileI.filePath()); if (!file.exists()) { QMessageBox::information(0, "Error", "Unable to load language support file: " + fileI.fileName()); continue; } file.open( QFile::ReadOnly ); QTextStream fileStream(&file); // load into variables loadLanguageSupportFile(fileStream, fileI.baseName()); file.close(); } } }
void lsDir(const char* dirName, const char* preDir, int allSet, int inodeSet, int listSet, int recurSet){ //for dir and file list struct dirent** myfile; struct stat mystat; int i, n; int kind; char autho[10]; mode_t mode; struct passwd* pw; struct group* grp; time_t t; time_t t2; struct tm* tms; int inodeLen = 0; int linkLen = 0; int unameLen = 0; int gnameLen = 0; int sizeLen = 0; int filenameLen = 0; char lengBuf[100]; char dirBuf[100]; char cwd[100]; char previousDir[100]; char tempBuf[100]; int newlineCount = 0; getcwd(cwd, sizeof(cwd)); chdir(dirName); n = scandir(".", &myfile, 0, alphasort); if(recurSet){ printf("%s:\n", preDir); } //for padding for(i = 0; i < n; i++){ if ( myfile[i]->d_name[0] == '.' && !allSet){ continue; } stat(myfile[i]->d_name, &mystat); sprintf(lengBuf, "%d", (int)mystat.st_ino); if (inodeLen < (int) strlen(lengBuf)) inodeLen = (int) strlen(lengBuf); sprintf(lengBuf, "%d", (int)mystat.st_nlink); if (linkLen < (int) strlen(lengBuf)) linkLen = (int) strlen(lengBuf); strcpy(lengBuf, getpwuid(mystat.st_uid)->pw_name); if (unameLen < (int) strlen(lengBuf)) unameLen = (int) strlen(lengBuf); strcpy(lengBuf, getgrgid(mystat.st_gid)->gr_name); if (gnameLen < (int) strlen(lengBuf)) gnameLen = (int) strlen(lengBuf); sprintf(lengBuf, "%d", (int)mystat.st_size); if (sizeLen < (int) strlen(lengBuf)) sizeLen = (int) strlen(lengBuf); strcpy(lengBuf, myfile[i]->d_name); if (filenameLen < (int) strlen(lengBuf)) filenameLen = (int) strlen(lengBuf); } if (listSet){ for(i = 0; i < n; i++){ if ( myfile[i]->d_name[0] == '.' && !allSet){ continue; } //stat stat(myfile[i]->d_name, &mystat); //mode mode = mystat.st_mode; //uid, gid pw = getpwuid(mystat.st_uid); grp = getgrgid(mystat.st_gid); //time t = mystat.st_ctime; tms = gmtime(&t); time(&t2); t2 = t2 - t; getAutho(autho, mode); if (inodeSet){ printf("%*d ", inodeLen, (int)mystat.st_ino); } printf("%c%s ", getKind(mode), autho); printf("%*d ", linkLen, (int)mystat.st_nlink); printf("%*s ", unameLen, pw->pw_name); printf("%*s ", gnameLen, grp->gr_name); printf("%*d ", sizeLen, (int)mystat.st_size); if (t2 < 15811200) printf("%02d월 %02d %02d:%02d ", tms->tm_mon, tms->tm_mday, tms->tm_hour, tms->tm_min); else printf("%02d월 %02d %5d ", tms->tm_mon, tms->tm_mday, tms->tm_year + 1900); printf("%s ", myfile[i]->d_name); if (i < n+1) printf("\n"); } } else { for(i = 0; i < n; i++){ if ( myfile[i]->d_name[0] == '.' && !allSet){ continue; } stat(myfile[i]->d_name, &mystat); if (inodeSet){ printf("%*d %-*s ", inodeLen, (int)mystat.st_ino, filenameLen, myfile[i]->d_name); sprintf(tempBuf, "%d", (int)mystat.st_ino); newlineCount += (inodeLen + filenameLen); } else { printf("%-*s ", filenameLen, myfile[i]->d_name); newlineCount += filenameLen; } if ( newlineCount > 80){ printf("\n"); newlineCount = 0; } } printf("\n"); } if (recurSet){ for(i = 0; i < n; i++){ if ( myfile[i]->d_name[0] == '.' && !allSet){ continue; } stat(myfile[i]->d_name, &mystat); mode = mystat.st_mode; if (getKind(mode) == 'd' && !( strcmp(".", myfile[i]->d_name) == 0 || strcmp("..", myfile[i]->d_name) == 0)){ printf("\n"); sprintf(dirBuf, "%s",myfile[i]->d_name); sprintf(previousDir, "%s/%s", preDir, myfile[i]->d_name); lsDir(dirBuf, previousDir, allSet, inodeSet, listSet, recurSet); } } } chdir(cwd); }
void wrapInFunction() { //! [0] QDir("/home/user/Documents") QDir("C:/Documents and Settings") //! [0] //! [1] QDir("images/landscape.png") //! [1] //! [2] QDir("Documents/Letters/Applications").dirName() // "Applications" QDir().dirName() // "." //! [2] //! [3] QDir directory("Documents/Letters"); QString path = directory.filePath("contents.txt"); QString absolutePath = directory.absoluteFilePath("contents.txt"); //! [3] //! [4] QDir dir("example"); if (!dir.exists()) qWarning("Cannot find the example directory"); //! [4] //! [5] QDir dir = QDir::root(); // "/" if (!dir.cd("tmp")) { // "/tmp" qWarning("Cannot find the \"/tmp\" directory"); } else { QFile file(dir.filePath("ex1.txt")); // "/tmp/ex1.txt" if (!file.open(QIODevice::ReadWrite)) qWarning("Cannot create the file %s", file.name()); } //! [5] //! [6] QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin QDir binDir(bin); QString canonicalBin = binDir.canonicalPath(); // canonicalBin now equals "/usr/bin" QString ls = "/local/bin/ls"; // where ls is the executable "ls" QDir lsDir(ls); QString canonicalLs = lsDir.canonicalPath(); // canonicalLS now equals "/usr/bin/ls". //! [6] //! [7] QDir dir("/home/bob"); QString s; s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg" s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt" //! [7] //! [8] QDir::setSearchPaths("icons", QStringList(QDir::homePath() + "/images")); QDir::setSearchPaths("docs", QStringList(":/embeddedDocuments")); ... QPixmap pixmap("icons:undo.png"); // will look for undo.png in QDir::homePath() + "/images" QFile file("docs:design.odf"); // will look in the :/embeddedDocuments resource path //! [8] //! [9] QDir dir("/tmp/root_link"); dir = dir.canonicalPath(); if (dir.isRoot()) qWarning("It is a root link"); //! [9] //! [10] // The current directory is "/usr/local" QDir d1("/usr/local/bin"); QDir d2("bin"); if (d1 == d2) qDebug("They're the same"); //! [10] //! [11] // The current directory is "/usr/local" QDir d1("/usr/local/bin"); d1.setFilter(QDir::Executable); QDir d2("bin"); if (d1 != d2) qDebug("They differ"); //! [11] //! [12] C:/Documents and Settings/Username //! [12] //! [13] Q_INIT_RESOURCE(myapp); //! [13] //! [14] inline void initMyResource() { Q_INIT_RESOURCE(myapp); }
void CSetPgDebug::debugLogShell(DWORD nParentPID, CESERVER_REQ_ONCREATEPROCESS* pInfo) { CSetPgDebug* pDbgPg = (CSetPgDebug*)gpSetCls->GetPageObj(thi_Debug); if (!pDbgPg) return; if ((pDbgPg->GetActivityLoggingType() != glt_Processes) && (pDbgPg->GetActivityLoggingType() != glt_Shell)) return; LPCWSTR pszFile = pInfo->wsValue + pInfo->nActionLen; LPCWSTR pszParam = pInfo->wsValue + pInfo->nActionLen+pInfo->nFileLen; DebugLogShellActivity *shl = (DebugLogShellActivity*)calloc(sizeof(DebugLogShellActivity),1); shl->nParentPID = nParentPID; shl->nParentBits = pInfo->nSourceBits; wcscpy_c(shl->szFunction, pInfo->sFunction); shl->pszAction = lstrdup(pInfo->wsValue); shl->pszFile = lstrdup(pszFile); shl->pszParam = lstrdup(pszParam); shl->bDos = (pInfo->nImageBits == 16) && (pInfo->nImageSubsystem == IMAGE_SUBSYSTEM_DOS_EXECUTABLE); shl->nImageBits = pInfo->nImageBits; shl->nImageSubsystem = pInfo->nImageSubsystem; shl->nShellFlags = pInfo->nShellFlags; shl->nCreateFlags = pInfo->nCreateFlags; shl->nStartFlags = pInfo->nStartFlags; shl->nShowCmd = pInfo->nShowCmd; shl->hStdIn = (DWORD)pInfo->hStdIn; shl->hStdOut = (DWORD)pInfo->hStdOut; shl->hStdErr = (DWORD)pInfo->hStdErr; // Append directory and bat/tmp files contents to pszParam { LPCWSTR pszDir = (pInfo->wsValue+pInfo->nActionLen+pInfo->nFileLen+pInfo->nParamLen); LPCWSTR pszAppFile = NULL; wchar_t*& pszParamEx = shl->pszParam; if (pszDir && *pszDir) { CEStr lsDir((pszParamEx && *pszParamEx) ? L"\r\n\r\n" : NULL, L"CD: \"", pszDir, L"\""); lstrmerge(&pszParamEx, lsDir); } if (shl->pszFile) { LPCWSTR pszExt = PointToExt(shl->pszFile); if (pszExt && (!lstrcmpi(pszExt, L".bat") || !lstrcmpi(pszExt, L".cmd"))) debugLogShellText(pszParamEx, (pszAppFile = shl->pszFile)); } if (pszParam && *pszParam) { LPCWSTR pszNext = pszParam; CEStr szArg; while (0 == NextArg(&pszNext, szArg)) { if (!*szArg || (*szArg == L'-') || (*szArg == L'/')) continue; LPCWSTR pszExt = PointToExt(szArg); // Perhaps process *.tmp files too? (used with VC RC compilation?) if (pszExt && (!lstrcmpi(pszExt, L".bat") || !lstrcmpi(pszExt, L".cmd") /*|| !lstrcmpi(pszExt, L".tmp")*/) && (!pszAppFile || (lstrcmpi(szArg, pszAppFile) != 0))) { debugLogShellText(pszParamEx, szArg); } else if (szArg[0] == L'@') { CEStr lsPath; if (IsFilePath(szArg.Mid(1), true)) { // Full path to "arguments file" lsPath.Set(szArg.Mid(1)); } else if ((szArg[1] != L'\\' && szArg[1] != L'/') && (pszDir && *pszDir)) { // Relative path to "arguments file" lsPath = JoinPath(pszDir, szArg.Mid(1)); } if (!lsPath.IsEmpty()) { debugLogShellText(pszParamEx, lsPath); } } } } } // end of "Append directory and bat/tmp files contents to pszParam" PostMessage(pDbgPg->Dlg(), DBGMSG_LOG_ID, DBGMSG_LOG_SHELL_MAGIC, (LPARAM)shl); }