Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. /*
  2. * COMP1917: Computing 1
  3. * Assignment 2: Image Processing using Quadtrees
  4. * File: hw2.c
  5. * Written by: Alan Blair
  6. */
  7.  
  8. // System include files
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. // Local include files
  15. #include "quadtree.h"
  16.  
  17. // Constants
  18. #define MAXLENGTH 200
  19.  
  20.  
  21. // Main function
  22. int main( void ) {
  23. char command[MAXLENGTH];
  24. char c;
  25. QTnode *qt;
  26. int dim;
  27. char *filename;
  28. int count = 0;
  29. QTnode *current;
  30.  
  31.  
  32.  
  33. /********************************************************************
  34. * YOU WILL NEED TO COMPLETE THE FOLLOWING SECTION FOR STAGES 2 - 5 *
  35. *******************************************************************/
  36.  
  37. printPrompt();
  38.  
  39. while( fgets( command, MAXLENGTH, stdin ) != NULL ) {
  40.  
  41. int imgNum;
  42. char *p;
  43.  
  44.  
  45.  
  46. if(( p=strrchr( command, '\n')) != NULL ) {
  47. *p = '\0'; // remove '\n' at end of line
  48. }
  49. // find the first non-space character in the command
  50. /*
  51. while(isspace(*command)) {
  52. printf("inside while isspace \n");
  53. command++;
  54. }
  55. */
  56.  
  57. p = strtok (command," ");
  58. if (p != NULL) {
  59.  
  60. filename = strtok (NULL, " ");
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. c = tolower(*p);
  69.  
  70. if( isdigit(c)) {
  71. if( sscanf( command, "%d", &imgNum ) == 1 ) {
  72.  
  73. // INSERT CODE FOR <k> COMMAND
  74. }
  75. }
  76. else switch( c ) {
  77.  
  78. case 'h': // help
  79.  
  80. printf(" A - Add image\n" );
  81. printf(" I - Index\n" );
  82. printf(" P - Print image\n" );
  83. printf(" F - Forward\n" );
  84. printf(" B - Back\n" );
  85. printf("<k>- make image number k the current image\n");
  86. printf(" D - Delete image\n" );
  87. printf(" L - Look for image\n" );
  88. printf(" R - Rotate image counterclockwise\n" );
  89. printf(" M - Mirror image (reflect vertically)\n" );
  90. printf("NE - zoom into North East corner\n" );
  91. printf("NW - zoom into North West corner\n" );
  92. printf("SW - zoom into South West corner\n" );
  93. printf("SE - zoom into South East corner\n" );
  94. printf(" O - zoom Out\n" );
  95. printf(" U - Undo\n" );
  96. printf(" H - Help\n" );
  97. printf(" Q - Quit\n" );
  98. break;
  99.  
  100. // INSERT CODE FOR OTHER COMMANDS
  101.  
  102. case 'a': // Add image
  103.  
  104. if(filename != NULL) {
  105. qt = getImage(filename, &dim);
  106. current = qt;
  107. count++;
  108. printf("*%d [%d] %s \n", count, dim, filename);
  109. }
  110. break;
  111.  
  112. case 'p': //Print Image
  113.  
  114. printImage(qt, dim);
  115. break;
  116.  
  117. case 'w'://zoom NE corner
  118. printImage(current->ne, dim);
  119. current = current->ne;
  120. break;
  121.  
  122. case 'x'://zoom NW corner
  123. printImage(current->nw, dim);
  124. current = current->nw;
  125. break;
  126.  
  127. case 'y'://zoom SW corner
  128. printImage(current->sw, dim);
  129. current = current->sw;
  130. break;
  131.  
  132. case 'z'://zoom SE corner
  133. printImage(current->se, dim);
  134. current = current->se;
  135. break;
  136.  
  137.  
  138.  
  139.  
  140. case 'q': // quit program
  141. printf("Bye!\n");
  142. return 0;
  143. break;
  144.  
  145. default:
  146. printf("Unrecognized command: %s\n", command );
  147. break;
  148. }
  149.  
  150. printPrompt();
  151. }
  152.  
  153. return 0;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement