#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* in each case, function returns 0 if successful,
   or 1 if some error occurred */

/* read a PGMA file and store data into imageData array */
int readPGMA(char *filename, int imageData[80][80]);

/* write image data to a PGMA file */
int writePGMA(char *filename, int imageData[80][80]);

/* rotate part of image to right by 90 degrees */
int rotateRight(int imageData[80][80], int sx, int sy, int size);

/* rotate part of image to left by 90 degrees */
int rotateLeft(int imageData[80][80], int sx, int sy, int size);
/* rotate part of image by 180 degrees */

int upsideDown(int imageData[80][80], int sx, int sy, int size);

/* flip part of image around its vertical axis
   NOTE: this means the vertical axis of the specified portion,
   not the entire image */
int flipVertical(int imageData[80][80], int sx, int sy, int size);

/* flip the image around its horizontal axis
   NOTE: this means the horizontal axis of the specified portion,
   not the entire image*/
int flipHorizontal(int imageData[80][80], int sx, int sy, int size);

/* invert grayscale color of part of image */
int invertGray(int imageData[80][80], int sx, int sy, int size);

int main(int argc, char** argv) {
  int image[80][80] ;
  int quit = 0 ;
  while (!quit) {
    char command[3], filename[17] ;
    int sx, sy, size ;
    scanf("%s", command) ;
    if (strcmp(command, "rf")==0) {
      scanf("%s", filename) ;
      quit = readPGMA(filename, image);
    } else if (strcmp(command, "wf")==0) {
      scanf("%s", filename) ;
      quit = writePGMA(filename, image);
    } else if (strcmp(command, "rr")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) rotateRight(image, sx, sy, size) ;
    } else if (strcmp(command, "rl")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) rotateLeft(image, sx, sy, size) ;
    } else if (strcmp(command, "ru")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) upsideDown(image, sx, sy, size) ;
    } else if (strcmp(command, "fv")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) flipVertical(image, sx, sy, size) ;
    } else if (strcmp(command, "fh")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) flipHorizontal(image, sx, sy, size) ;
    } else if (strcmp(command, "ig")==0) {
      scanf("%d%d%d", &sx, &sy, &size) ;
      (void) invertGray(image, sx, sy, size) ;
    } else if (strcmp(command, "qq")==0) {
      quit = 1 ;
    } else {
      while (getchar() != '\n') ;
    }
  }

  return (EXIT_SUCCESS);
}

/* These three global variables are used to transmit
 * information about the image to all the routines.
 * They are set by readPGMA.
 */
static int imageWidth ;
static int imageHeight ;
static int maxGrayscale ;

int readPGMA(char *filename, int imageData[80][80]) {
  return 0 ;
}

int writePGMA(char *filename, int imageData[80][80]) {
  return 0 ;
}

int rotateRight(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}

int rotateLeft(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}

int upsideDown(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}

int flipVertical(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}

int flipHorizontal(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}

int invertGray(int imageData[80][80], int sx, int sy, int size) {
  return 0 ;
}
