Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int TDAcurrPos = 0;
- typedef struct vertexData {
- char fileName[100];
- char directoryName[1000];
- int deadlock; // 0 - false 1 - true;
- int minotaur; // 0 - false 1 - true;
- int arrayOfEdges[200]; // -1 if null
- } vertexData;
- vertexData tempDataArray[200];
- void readDataOutside(char* fileName, char* directoryName,int deadlock,int minotaur, int arrayOfEdges,int size){
- strcpy(tempDataArray[TDAcurrPos].fileName,fileName);
- strcpy(tempDataArray[TDAcurrPos].directoryName,directoryName);
- if(minotaur == 1){
- tempDataArray[TDAcurrPos].minotaur = 1;
- tempDataArray[TDAcurrPos].deadlock = 0;
- tempDataArray[TDAcurrPos].arrayOfEdges[0] = -1;
- }
- if(deadlock == 1){
- tempDataArray[TDAcurrPos].minotaur = 0;
- tempDataArray[TDAcurrPos].deadlock = 1;
- tempDataArray[TDAcurrPos].arrayOfEdges[0] = -1;
- }
- if(deadlock == 0 && minotaur == 0){
- tempDataArray[TDAcurrPos].minotaur = 0;
- tempDataArray[TDAcurrPos].deadlock = 0;
- //TODO вынести в отдельную функцию
- for(int i=0; i<size; i++ )
- tempDataArray[TDAcurrPos].arrayOfEdges[i] = arrayOfEdges[i];
- }
- }
- char* parseInsideDataAndADD(char* fileName, char* dirPath, char* readBuffer, int iterator){
- // if(readBuffer[0] == 'D') return "Deadlock";
- // if(readBuffer[0] == 'M']) return "Minotaur";
- // int len = strlen(readBuffer);
- // char* ret[200];
- // for(int i = 0; i < len; i++){
- // if (!isdigit(readBuffer[0])) exit(666);
- // return readBuffer;
- // }
- if(readBuffer[0] == 'M') readDataOutside(fileName, dirPath, 0, 1, -1, 0);
- if(readBuffer[0] == 'D') readDataOutside(fileName, dirPath, 1, 0, -1, 0);
- if(isdigit(readBuffer[0])) {
- //int edges[200] = parseInt(readBuffer,iterator);
- int edges[200] = { 0, 1 , 2 ,4 ,5};
- readDataOutside(fileName, dirPath, 0, 0, edges, iterator);
- }
- }
- // int* parseInt(char* readBuffer, int size){
- // for(int i = 0; i< iterator; i++){
- // }
- // return intArray;
- // }
- void listdir(const char *name, int indent)
- {
- DIR *dir;
- struct dirent *entry;
- char path[1024];
- if (!(dir = opendir(name)))
- return;
- while ((entry = readdir(dir)) != NULL) {
- if (entry->d_type == DT_DIR) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
- snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
- // printf("%*s[%s]\n", indent, "", entry->d_name);
- listdir(path, indent + 2);
- //printf("%s\n",path);
- }
- else {
- char ch,readBuffer[200], file_name[25],dirPath[200], fileName[200],tempStr[200];
- printf("%s/\n", name);
- printf("%s\n", entry->d_name);
- strcpy(dirPath, name);
- strcpy(fileName, entry->d_name);
- strcat(dirPath, "/");
- strcpy(tempStr, dirPath);
- strcat(tempStr, fileName);
- /*------------------------------------------------------*/
- FILE* fp = fopen(tempStr,"r"); // read mode
- int iterator = 0;
- if( fp == NULL )
- {
- perror("Error while opening the file.\n");
- exit(EXIT_FAILURE);
- }
- printf("The contents of %s file are :\n", file_name);
- while( ( ch = fgetc(fp) ) != EOF ){
- printf("%c",ch);
- readBuffer[iterator++] = ch;
- }
- fclose(fp);
- /*------------------------------------------------------*/
- parseInsideDataAndADD(fileName, dirPath, readBuffer, iterator);
- }
- }
- // printf("%s\n",path);
- closedir(dir);
- }
- int main(void) {
- listdir("LIST DIR", 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement