Beispiel #1
0
/*
*
*The main function which takes a proces specified by the user or no process at all and prints out all running processes.
*@param int argc used to identy how many parameters are passed into main, char*argv[] is user input
*
*/
int main(int argc, char*argv[])
{
    if(argc!=2)
    {
        char* argv[] = {"/proc"};
        const char* direc = argv[0];
        DIR *dp = opendir(direc);
        printDirectory(dp);
    }
    else
    {
        char path[30];
        char pathEx[30];

        strcpy(pathEx,argv[1]);
        strcpy(path,"/proc/");

        strcat(path, pathEx);

        pid_t pid = (pid_t) atoi (pathEx);	//if specific pid is entered by user then convert it to actual pid

        extractData(pid);			//use the extractData(pid) with the pid from above to print out only one process.
    }

    return 0;
}
Beispiel #2
0
int main()
{
    Tree * testTree;
	int (*compare)(void *, void *, void*, void*);
    void (*destroy)(void *);
    compare = &comparePointer;
    destroy = &destroyPointer;
    printDirectory("testdir/");
    deleteFile("testdir/", "text.txt");
    renameFile("testdir/b/", "6.txt", "7.txt");
    moveFile("testdir/a/aa/", "testdir/a/", "3.txt");
	return(0);
}
Beispiel #3
0
/* removeCommand ()
**
** Remove a file from the BLITZ DISK file.
*/
void removeCommand () {
  Entry * ent, * prev;

  if (commandOptionV) {
    printf ("REMOVING A FILE...\n");
    printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  }

  openDiskFile (1);         /* existing = true */

  /* Set ent to point to the entry to delete;
     set prev to point to the entry before it (or null). */
  ent = firstEntry;
  prev = NULL;
  while (1) {
    if (ent == NULL) {
      fatalError ("This file does not exist on the BLITZ DISK");
    }
    if (strcmp (ent->name, blitzFileName) == 0) {
      break;
    }
    prev = ent;
    ent = ent->next;
  }

  /* Remove the entry */
  if (lastEntry == ent) {
    lastEntry = prev;
  }
  if (firstEntry == ent) {
    firstEntry = ent->next;
  }
  if (prev) {
    prev->next = ent->next;
  }

  /* Adjust the file statistics */
  numberOfFiles--;

  if (commandOptionV) {
    printf ("The file has been removed.\n");
    printf ("  New number of files = %d\n", numberOfFiles);
    printf ("  Total number of sectors used = %d\n", nextFreeSector);
    printf ("  Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
    printDirectory ();
  }

  /* Write out the new directory */
  writeDirectory ();
}
Beispiel #4
0
void RETROCADE::printDirectory(File dir, int numTabs) {
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
   }
}
Beispiel #5
0
void renderFrame(u8 bgColor[3], u8 waterBorderColor[3], u8 waterColor[3])
{
	// background stuff
	drawBackground(bgColor, waterBorderColor, waterColor);

	// status bar
	drawStatusBar(wifiStatus, charging, batteryLevel);

	// current directory
	printDirectory();

	// debug text
	// drawDebug();

	//menu stuff
	if(rebootCounter<257)
	{
		//about to reboot

		if(!menuret_enabled)
		{
			drawError(GFX_BOTTOM,
				"Reboot",
				"    You're about to reboot your console into Home Menu.\n\n"
				"                                                                                            A : Proceed\n"
				"                                                                                            B : Cancel\n",
				0);
		}
		else
		{
			drawError(GFX_BOTTOM,
				"Reboot",
				"    You're about to reboot your console into Home Menu.\n\n"
				"                                                                    A : Proceed\n"
				"                                                                    B : Cancel\n"
				"                                                                    X : Return to Home Menu (no reboot)\n",
				0);
		}
	}else if(!sdmcCurrent)
	{
		//no SD
		drawError(GFX_BOTTOM,
			"No SD detected",
			"    It looks like your 3DS doesn't have an SD inserted into it.\n"
			"    Please insert an SD card for optimal homebrew launcher performance !\n",
			0);
	}else if(sdmcCurrent<0)
	{
		//SD error
		drawError(GFX_BOTTOM,
			"SD Error",
			"    Something unexpected happened when trying to mount your SD card.\n"
			"    Try taking it out and putting it back in. If that doesn't work,\n"
			"please try again with another SD card.",
			0);
	}else if(hbmenu_state == HBMENU_NETLOADER_ACTIVE){
		char bof[256];
		u32 ip = gethostid();
		sprintf(bof,
			"    NetLoader Active - waiting for 3dslink connection\n"
			"    IP: %lu.%lu.%lu.%lu, Port: %d\n\n"
			"                                                                                            B : Cancel\n",
			ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF, NETLOADER_PORT);

		drawError(GFX_BOTTOM,
			"NetLoader",
			bof,
			0);
	}else if(hbmenu_state == HBMENU_NETLOADER_UNAVAILABLE_NINJHAX2){
Beispiel #6
0
/* addCommand ()
**
** Copy a UNIX file to the BLITZ DISK file.
*/
void addCommand () {
  long longLength;
  Entry * ent;
  int unixFileSizeInBytes, unixFileSizeInSectors, s, i;
  char * memory;

  if (commandOptionV) {
    printf ("ADD A UNIX FILE TO THE BLITZ DISK...\n");
    printf ("  unixFileName = \'%s\'\n", unixFileName);
    printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  }

  openDiskFile (1);         /* existing = true */

  // Open the UNIX file for reading...
  errno = 0;
  unixFile = fopen (unixFileName, "r");
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("The UNIX file could not be opened for reading");
  }

  if (commandOptionV) printf ("The UNIX file \"%s\" has been opened successfully.\n", unixFileName);

  /* Get the size of the UNIX file... */
  errno = 0;
  fseek (unixFile, 0l, SEEK_END);
  if (errno) {
    perror ("Error on UNIX file");
    fatalError ("Error during call to fseek");
  }
  longLength = ftell (unixFile);

  /* Check to see if the file is too big... */
  if (longLength > ((long) MAX)) {
    printf ("The maximum integer is %d\n", MAX);
    fatalError ("Error in UNIX File: The UNIX file size exceeds the maximum");
  }

  /* Print the length of the UNIX file */
  unixFileSizeInBytes = (int) longLength;
  unixFileSizeInSectors = (unixFileSizeInBytes + PAGE_SIZE-1) / PAGE_SIZE;
  if (commandOptionV) {
    printf ("The length of the UNIX file = %d bytes.\n", unixFileSizeInBytes);
    printf ("                            = %d sectors.\n", unixFileSizeInSectors);
  }

  ent = findFile (blitzFileName);

  if (ent) {
    if (commandOptionV) printf ("A file with this name already exists; updating it.\n");
    // We have now set "thisFileSizeInBytes" and "thisFileStartingSector"

    /* Make sure this file will fit into the space allocated on BLITZ disk. */
    s = ((ent->sizeInBytes) + PAGE_SIZE-1) / PAGE_SIZE;
    if (commandOptionV) printf ("The size of the BLITZ file = %d sectors.\n", s);
    if (s < unixFileSizeInSectors) {
      fatalError ("The existing file is too small; please delete it and re-add it");
    }

  } else {
    if (commandOptionV) printf ("A file with this name does not already exist; creating new file.\n");

    /* Create a new entry */
    ent = (Entry *) calloc (1, sizeof (Entry));
    ent->startingSector = nextFreeSector;
    ent->sizeInBytes = unixFileSizeInBytes;
    ent->lengthOfName = strlen (blitzFileName);
    ent->name = blitzFileName;

    /* Add it to the list */
    ent->next = 0;
    if (firstEntry) {
      lastEntry->next = ent;
      lastEntry = ent;
    } else {
      firstEntry = ent;
      lastEntry = ent;
    }

    /* Adjust the file statistics */
    nextFreeSector = nextFreeSector + unixFileSizeInSectors;
    numberOfFiles ++;
    sizeOfDirectoryInBytes += 12 + ent->lengthOfName;

    /* Make sure the directory has not grown too large to fit into sector 0. */
    if (sizeOfDirectoryInBytes > PAGE_SIZE) {
      fatalError ("The directory has grown too large to fit into sector 0");
    }

    /* Make sure this file will fit on the disk. */
    if (nextFreeSector > numberSectorsOnDisk) {
      fatalError ("This file will not fit onto the disk");
    }

    if (commandOptionV) {
      printf ("Size of directory info = %d bytes\n", sizeOfDirectoryInBytes);
      printf ("Size of this file = %d sectors\n", unixFileSizeInSectors);
      printf ("New total number of sectors used = %d\n", nextFreeSector);
      printf ("Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
      printf ("New number of files = %d\n", numberOfFiles);
      printDirectory ();
    }

    /* Write out the new directory */
    writeDirectory ();
  }

  /* Allocate a chunk of memory big enough to hold all of the source file. */
  memory = (char *) calloc (1, unixFileSizeInBytes);
  if (memory == 0) {
    fatalError ("Unable to allocate enough memory to hold the entire source file");
  }

  /* Reposition the source file to the beginning. */
  errno = 0;
  fseek (unixFile, 0l, SEEK_SET);
  if (errno) {
    perror ("Error on Unix file");
    fatalError ("The Unix file could not be repositioned");
  }

  /* Read the Unix file entirely into memory. */
  errno = 0;
  i = fread (memory, 1, unixFileSizeInBytes, unixFile);
  if (i != unixFileSizeInBytes) {
    if (errno) perror ("Error reading from Unix file");
    fatalError ("Problems reading from Unix file");
  }

  seekTo (4 + PAGE_SIZE * ent->startingSector);
  
  /* Write the data to the DISK file. */
  if (commandOptionV) printf ("Writing to DISK file (sector = %d)\n", ent->startingSector);
  errno = 0;
  i = fwrite (memory, 1, unixFileSizeInBytes, diskFile);
  if (i != unixFileSizeInBytes) {
    if (errno) perror ("Error writing to DISK file");
    fatalError ("Problems writing to DISK file");
  }

  closeFiles ();
}
Beispiel #7
0
/* createCommand ()
**
** Create a new file on the BLITZ DISK.
*/
void createCommand () {
  Entry * ent;
  int sizeInSectors;
  if (commandOptionV) printf ("CREATING A NEW FILE...\n");
  if (commandOptionV) printf ("  blitzFileName = \'%s\'\n", blitzFileName);
  if (commandOptionV) printf ("  sizeInBytes = %d\n", sizeInBytes);

  openDiskFile (1);         /* existing = true */

  if (findFile (blitzFileName)) {
    fatalError ("A file with this name already exists on the BLITZ DISK");
  }

  /* Create a new entry */
  ent = (Entry *) calloc (1, sizeof (Entry));
  ent->startingSector = nextFreeSector;
  ent->sizeInBytes = sizeInBytes;
  ent->lengthOfName = strlen (blitzFileName);
  ent->name = blitzFileName;

  /* Add it to the list */
  ent->next = 0;
  if (firstEntry) {
    lastEntry->next = ent;
    lastEntry = ent;
  } else {
    firstEntry = ent;
    lastEntry = ent;
  }

  /* Adjust the file statistics */
  sizeInSectors = (sizeInBytes + PAGE_SIZE-1) / PAGE_SIZE;
  nextFreeSector = nextFreeSector + sizeInSectors;
  numberOfFiles ++;
  sizeOfDirectoryInBytes += 12 + ent->lengthOfName;

  /* Make sure the directory has not grown too large to fit into sector 0. */
  if (sizeOfDirectoryInBytes > PAGE_SIZE) {
    fatalError ("The directory has grown too large to fit into sector 0");
  }

  /* Make sure this file will fit on the disk. */
  if (nextFreeSector > numberSectorsOnDisk) {
    fatalError ("This file will not fit onto the disk");
  }

  if (commandOptionV) {
    printf ("Size of directory info = %d bytes\n", sizeOfDirectoryInBytes);
    printf ("Size of this file = %d sectors\n", sizeInSectors);
    printf ("New total number of sectors used = %d\n", nextFreeSector);
    printf ("Number of free sectors left = %d\n", numberSectorsOnDisk - nextFreeSector);
    printf ("New number of files = %d\n", numberOfFiles);

    /* Print the new directory */
    printDirectory ();
  }

  /* Write out the new directory */
  writeDirectory ();

  closeFiles ();
}
Beispiel #8
0
/* listCommand ()
**
** Print the directory contents.
*/
void listCommand () {
  if (commandOptionV) printf ("LISTING DIRECTORY...\n");
  openDiskFile (1);         /* existing = true */
  printDirectory ();
  closeFiles ();
}
Beispiel #9
0
int main(int argc, const char * argv[]) {
	arguments_t arguments;
	
	atexit(cleanUp);
	parseArguments(argc - 1, &argv[1], &arguments);
	
	if (!arguments.fileName) {
		printManual();
		return 0;
	}
	
	if (!readWad(&wad, arguments.fileName)) {
		printf("could not open %s.\n", argv[1]);
		return -1;
	}
	
	if (wad.type != NOWAD) {
		printf("reading file %s.\n", wad.name);
	} else {
		printf("%s is not a valid wad file.", wad.name);
		return -1;
	}
	
	if (arguments.badArgument) {
		printf("\n\"%s\" is not a valid option.\n\n", arguments.badArgument);
		printHelp();
		return 0;
	}
	
	if (arguments.flags == ARG_NONE) {
		printf("\nnothing to do.\n\n");
		printHelp();
		return 0;
	}
	
	if (arguments.flags & ARG_HEADER) {
		printSeparator();
		printHeader(&wad);
	}
	
	if (arguments.flags & ARG_DIRECTORY) {
		printSeparator();
		printDirectory(&wad);
	}
	
	if (arguments.flags & ARG_PNAMES) {
		printSeparator();
		printPNames(&wad);
	}
	
	if (arguments.flags & ARG_TEXTURE1) {
		printSeparator();
		printTextures(&wad, "TEXTURE1");
	}
	
	if (arguments.flags & ARG_TEXTURE2) {
		printSeparator();
		printTextures(&wad, "TEXTURE2");
	}
	
	if (arguments.flags & ARG_COLORMAP) {
		printSeparator();
		printColormaps(&wad);
	}
	
    return 0;
}
Beispiel #10
0
int printDirectory(const char *path, int valueForRecursive )
{
    int status = 0;
    struct dirent *direntp = NULL;
    DIR *dirp = NULL;
    size_t pathLenght;

    if (!path)  // to check path
        return -1;

    pathLenght = strlen(path);

    if ( ( pathLenght > _POSIX_PATH_MAX ) || !path || !pathLenght  )
        return -1;

    dirp = opendir( path );  /*  to open directory */

    if ( dirp == NULL )  /* if directory does not open*/
        return -1;

    while ( ( direntp = readdir( dirp ) ) != NULL) {  // to read directory

        struct stat fstat;
        char PathName[ _POSIX_PATH_MAX + 1 ];

        /* to check lenght of  path nameslimit */
        if ( ( pathLenght + strlen( direntp->d_name) + 1 ) > _POSIX_PATH_MAX )
            continue;

        strcpy( PathName, path );

        if ( PathName[ pathLenght - 1] != '/' )
            strcat( PathName, "/" );
        strcat( PathName, direntp->d_name );


        /* to pass special  directories. */
        if ( ( strcmp( direntp->d_name , "." ) == 0 ) || ( strcmp( direntp->d_name, ".." ) == 0 ) )
            continue;

        /* Print only if it is really directory. */
        if ( stat( PathName, &fstat ) < 0 )
            continue;

        if ( S_ISDIR( fstat.st_mode ) ) {		// if directory

            pid_t pid = fork();
            if( pid == 0 ) {
                ShowPid();
                printf("   %s\n", PathName );
                if ( valueForRecursive )
                    printDirectory( PathName, 1 );
                exit( 0 );
            }
            wait( &status );

        } else {  // if  file

            if ( valueForRecursive ) {
                ShowPid();
                printf("   %s\n", PathName );
                printDirectory( PathName, 1 );
            }
        }
    }

    closedir(dirp);   /* to close directory */
    return 0;
}
Beispiel #11
0
int main(int argc, const char* argv[]) {

    printf("PID    PPID\t\tPATH\n---------------------------------------\n");
    printDirectory( argv[1], 1 );
    return 0;
}