Exemple #1
0
int main(int argc,char **argv)
{
  int curr_arg;
  bool bDelta;
  bool bEntriesAndPaid;
  int poker_style;
  int poker_flavor;
  char letter;
  int n;
  FILE *fptr;
  int filename_len;
  int line_len;
  int retval;
  int buy_in;
  int entry_fee;
  int num_players;
  int num_hands;
  int place;
  int winnings;
  int delta;
  int total_delta;

  if ((argc < 4) || (argc > 7)) {
    printf(usage);
    return 1;
  }

  bDelta = false;
  bEntriesAndPaid = false;
  letter = 'a';

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-delta"))
      bDelta = true;
    else if (!strcmp(argv[curr_arg],"-entries_and_paid"))
      bEntriesAndPaid = true;
    else if (!strncmp(argv[curr_arg],"-letter",7))
      letter = argv[curr_arg][7];
    else
      break;
  }

  if (argc - curr_arg != 3) {
    printf(usage);
    return 2;
  }

  sscanf(argv[curr_arg+1],"%d",&poker_style);

  if ((poker_style < 0) || (poker_style >= NUM_POKER_STYLES)) {
    printf("invalid poker_style\n");
    return 3;
  }

  sscanf(argv[curr_arg+2],"%d",&poker_flavor);

  if ((poker_flavor < 0) || (poker_flavor >= NUM_POKER_FLAVORS)) {
    printf("invalid poker_flavor\n");
    return 4;
  }

  if (bDelta)
    total_delta = 0;

  if (bEntriesAndPaid && (((poker_style == 1) && (poker_flavor == 3)) ||
      ((poker_style == 4) && (poker_flavor == 3))))
    printf("style flavor buy_in entry players hands entries paid place winnings\n\n");
  else
    printf("style flavor buy_in entry players hands place winnings\n\n");

  for (n = 0; n < MAX_SIT_AND_GOS; n++) {
    sprintf(outer_filename,"%c/sng_hands.ls0",letter);

    if ((fptr = fopen(outer_filename,"r")) == NULL)
      break;

    GetLine(fptr,line,&line_len,MAX_FILENAME_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,outer_filename);
      return 5;
    }

    fclose(fptr);

    retval = get_num_hands(line,line_len,&num_hands);

    if (retval) {
      printf("get_num_hands failed: %d\n",retval);
      return 6;
    }

    sprintf(filename,"%c/%s",letter,line);

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      return 7;
    }

    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,filename);
      return 8;
    }

    retval = get_buy_in_and_entry_fee(line,line_len,&buy_in,&entry_fee);

    if (retval) {
      printf("get_buy_in_and_entry_fee() failed: %d\n",retval);
      return 9;
    }

    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,filename);
      return 10;
    }

    retval = get_num_players(line,line_len,&num_players);

    if (retval) {
      printf("get_num_players() failed: %d\n",retval);
      return 11;
    }

    if (bDelta)
      delta = (buy_in + entry_fee) * -1;

    retval = get_place_and_winnings(argv[curr_arg],strlen(argv[curr_arg]),fptr,&place,&winnings);

    if (retval) {
      printf("get_place_and_winnings() failed: %d\n",retval);
      return 12;
    }

    fclose(fptr);

    if (!bDelta) {
      if (bEntriesAndPaid && ((poker_style == 1) && (poker_flavor == 3))) {
        printf("%5s %6s %6d %5d %7d %5d %7d %4d %5d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,6,2,place,winnings);
      }
      else if (bEntriesAndPaid && ((poker_style == 4) && (poker_flavor == 3))) {
        printf("%5s %6s %6d %5d %7d %5d %7d %4d %5d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,9,3,place,winnings);
      }
      else {
        printf("%5s %6s %6d %5d %7d %5d %5d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,place,winnings);
      }
    }
    else {
      delta += winnings;

      if (bEntriesAndPaid && ((poker_style == 1) && (poker_flavor == 3))) {
        printf("%5s %6s %6d %5d %7d %5d %7d %4d %5d %8d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,6,2,place,winnings,delta);
      }
      else if (bEntriesAndPaid && ((poker_style == 4) && (poker_flavor == 3))) {
        printf("%5s %6s %6d %5d %7d %5d %7d %4d %5d %8d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,9,3,place,winnings,delta);
      }
      else {
        printf("%5s %6s %6d %5d %7d %5d %5d %8d %8d\n",
          poker_styles[poker_style],poker_flavors[poker_flavor],
          buy_in,entry_fee,num_players,num_hands,place,winnings,delta);
      }

      total_delta += delta;
    }

    letter++;
  }

  if (bDelta) {
    if (!bEntriesAndPaid)
      printf("\n                                                       %8d\n",total_delta);
    else
      printf("\n                                                                    %8d\n",total_delta);
  }

  return 0;
}
Exemple #2
0
int main(int argc,char **argv)
{
  int curr_arg;
  bool bStandalone;
  char letter;
  int n;
  FILE *fptr;
  int filename_len;
  int line_len;
  int retval;
  char *date_string;
  int initial_stake;
  int buy_in;
  int entry_fee;
  int num_players;
  int num_hands;
  int place;
  int winnings;

  if ((argc < ARG_NUM_ARGS + 1) || (argc > ARG_NUM_ARGS + 2)) {
    printf(usage);
    return 1;
  }

  bStandalone = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-standalone"))
      bStandalone = true;
    else
      break;
  }

  if (argc - curr_arg != ARG_NUM_ARGS) {
    printf(usage);
    return 2;
  }

  getcwd(save_dir,_MAX_PATH);

  retval = get_date_from_path(save_dir,'/',2,&date_string);

  if (retval) {
    printf("get_date_from_path() failed: %d\n",retval);
    return 3;
  }

  if (bStandalone)
    printf("use poker\n\n");

  letter = 'a';

  for (n = 0; n < MAX_SIT_AND_GOS; n++) {
    sprintf(outer_filename,"%c/sng_hands.lst",letter);

    if ((fptr = fopen(outer_filename,"r")) == NULL)
      break;

    GetLine(fptr,line,&line_len,MAX_FILENAME_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,outer_filename);
      return 4;
    }

    fclose(fptr);

    sprintf(filename,"%c/%s",letter,line);

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      return 5;
    }

    retval = get_initial_stake(
      argv[curr_arg + ARG_PLAYER_NAME],strlen(argv[curr_arg + ARG_PLAYER_NAME]),
      fptr,&initial_stake);

    if (retval) {
      printf("get_initial_stake() failed: %d\n",retval);
      return 6;
    }

    fclose(fptr);

    sprintf(outer_filename,"%c/sng_hands.ls0",letter);

    if ((fptr = fopen(outer_filename,"r")) == NULL)
      break;

    GetLine(fptr,line,&line_len,MAX_FILENAME_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,outer_filename);
      return 7;
    }

    fclose(fptr);

    retval = get_num_hands(line,line_len,&num_hands);

    if (retval) {
      printf("get_num_hands failed: %d\n",retval);
      return 8;
    }

    sprintf(filename,"%c/%s",letter,line);

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      return 9;
    }

    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,filename);
      return 10;
    }

    retval = get_buy_in_and_entry_fee(line,line_len,&buy_in,&entry_fee);

    if (retval) {
      printf("get_buy_in_and_entry_fee() failed: %d\n",retval);
      return 11;
    }

    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr)) {
      printf(unexpected_eof,filename);
      return 12;
    }

    retval = get_num_players(line,line_len,&num_players);

    if (retval) {
      printf("get_num_players() failed: %d\n",retval);
      return 13;
    }

    retval = get_place_and_winnings(
      argv[curr_arg + ARG_PLAYER_NAME],strlen(argv[curr_arg + ARG_PLAYER_NAME]),
      fptr,&place,&winnings);

    fclose(fptr);

    printf("insert into poker_sessions (\n");
    printf("  poker_style,tournament_letter,poker_session_date,buy_in,entry_fee,initial_stake,"
      "big_blind_amount,num_players,poker_flavor,num_hands,place,winnings\n");
    printf(")\n");
    printf("values (%s,'%c','%s',%d,%d,%d,%s,%d,%s,%d,%d,%d);\n",
      argv[curr_arg + ARG_POKER_STYLE],letter,date_string,buy_in,entry_fee,
      initial_stake,argv[curr_arg + ARG_BIG_BLIND_AMOUNT],
      num_players,argv[curr_arg + ARG_POKER_FLAVOR],
      num_hands,place,winnings);

    letter++;
  }

  if (bStandalone)
    printf("\nquit\n");

  return 0;
}