Beispiel #1
0
int main(int argc, char**argv)
{
    char user_input[1000];
    ATM *atm = atm_create();
    char *atmPath;
    FILE *atmFile;
    char *second;
    int filenamelen = 0;


    if(argc == 1) {
    printf("Usage: ATM <filename>\n");
    return 62; 
    } //user fails to provide exactly one argument

    second = argv[1];

    filenamelen = strlen(second);

    atmPath = malloc(1 + filenamelen + 4);

    strncpy(atmPath, second, strlen(second));

    atmPath[filenamelen] = '.';
    atmPath[filenamelen+1] = 'a';
    atmPath[filenamelen+2] = 't';
    atmPath[filenamelen+3] = 'm';
    atmPath[filenamelen+4] = 0;

    atmFile = fopen(atmPath, "r");

    if(atmFile == NULL){
    printf("Error opening atm initialization file\n");
    return 64;
    }

    fclose(atmFile);

    printf("%s", prompt);
    fflush(stdout);

    while (fgets(user_input, 10000,stdin) != NULL)
    {
        atm_process_command(atm, user_input);

        if(atm->currentUser != NULL) {
            printf("ATM (%s): ", atm->currentUser->name);
        }
        else {
            printf("%s", prompt);
        }
        
        fflush(stdout);
    }
	return EXIT_SUCCESS;
}
Beispiel #2
0
int main(int arg, char **argv)
{
    char user_input[1000];
    if (arg != 2) {
        printf("Error opening atm initialization file\n");
        return 64;
    }
    char *token;
   char argv_cp[1024];
   strcpy(argv_cp, argv[1]);
   strtok(argv_cp, ".");
   token = strtok(NULL, ".");
   if (strcmp(token, "atm") != 0) {
    printf("Error opening atm initialization file\n");
    return 64;
   }

    ATM *atm = atm_create();
   
    //Check for command line arguements
     FILE *fp;
     fp = fopen(argv[1],"r");
    if(fp ==NULL) {
    	printf("Error opening atm initialization file\n");
	return 64;
    }
    strcpy(atm->symm_key, argv[1]);
    fclose(fp);
    printf("%s", prompt);
    fflush(stdout);

    while (fgets(user_input, 10000,stdin) != NULL)
    {
        atm_process_command(atm, user_input);
	if(atm->session == 1) {
		printf("ATM (%s): ",atm->username);	
	} else {
        printf("%s", prompt);
	}
        fflush(stdout);
    }   
	atm_free(atm);
	return EXIT_SUCCESS;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    char user_input[1000];
    FILE *atm_file;

    if(argc != 2) {
      printf("Usage: atm <filename>\n");
      exit(62);
    }

    if(strncmp(argv[1]+strlen(argv[1])-4, ".atm", 4) != 0) {
      printf("Error opening ATM initialization file\n");
      exit(64);
    }

    atm_file = fopen(argv[1], "r");
    if(!atm_file) {
      printf("Error opening ATM initialization file\n");
      exit(64);
    }

    ATM *atm = atm_create();
    fread(atm->key, sizeof(char), BLOCK_SIZE, atm_file);
    fread(atm->iv, sizeof(char), BLOCK_SIZE, atm_file);

    printf("%s", prompt);
    fflush(stdout);

    while (fgets(user_input, 10000,stdin) != NULL)
    {
        if(strlen(user_input) > 0 && strcmp(user_input, "\n") == 0) continue;
        atm_process_command(atm, user_input);
        if(atm->session) {
          printf("ATM (<%s>): ", atm->cur_user);
        } else {
          printf("%s", prompt);
        }
        fflush(stdout);
    }
    atm_free(atm);

    return EXIT_SUCCESS;
}