static void create_piece(t_list **head, char *buf, char letter) { t_list *node; t_tetri t; gen_piece(&t); get_piece_metrics(buf, &t); t.letter = letter; t.height = t.ymax - t.ymin + 1; t.width = t.xmax - t.xmin + 1; buf_to_struct(buf, &t); if (!(node = ft_lstnew(&t, sizeof(t_tetri)))) return ; ft_lstadd(head, node); }
int main(int argc,char **argv) { FILE *fptr; int linelen; int lineno; int rowno; int retval; int type_of_line; Arb_date row_date; int num_errored_rows; int row_in_error; LCT_METRICS lct_work; if (argc != 2) { fprintf(stderr,usage); return 1; } if ((fptr = fopen(argv[1],"r")) == NULL) { fprintf(stderr,couldnt_open,argv[1]); return 2; } lineno = 0; rowno = 0; num_errored_rows = 0; printf("sys_currency_code,lct_date,gross_without_tax,net_without_tax,\ gross_with_tax,net_with_tax,invoices_generated,service_instances_billed\n"); for ( ; ; ) { retval = GetLine(fptr,lct_encrypted_hex_buf,&linelen, LCT_MAX_ENCRYPTED_HEX_BYTES); if (feof(fptr)) break; if (retval) { fprintf(stderr,"line %d is too long\n",lineno+1); return 3; } type_of_line = lineno % NUM_COLS; switch (type_of_line) { case LCT_DATE_COL: row_in_error = FALSE; if (string_to_Arbdate(lct_encrypted_hex_buf,lct_date_fmt, &row_date) != SUCCESS) { fprintf(stderr,"row %d contains an invalid date\n",rowno+1); row_in_error = TRUE; num_errored_rows++; break; } break; case LCT_METRICS_COL: if (row_in_error) break; if (encrypted_hex_buf_to_buf(lct_encrypted_hex_buf, lct_encrypted_buf,lct_buf) != SUCCESS) { fprintf(stderr,"couldn't decrypt lct_metrics of row %d\n",rowno+1); row_in_error = TRUE; num_errored_rows++; break; } if (buf_to_struct(lct_buf,&lct_work) != SUCCESS) { fprintf(stderr,"row %d contains corrupted lct_metrics\n",rowno+1); row_in_error = TRUE; num_errored_rows++; break; } /* make sure the dates match */ if (Arbdate_compare(&row_date,&lct_work.lct_date) != 0) { fprintf(stderr, "lct_date of row %d doesn't match date embedded in lct_metrics\n", rowno+1); row_in_error = TRUE; num_errored_rows++; break; } struct_to_buf(&lct_work,lct_buf,FALSE); printf("%s\n",lct_buf); break; default: if (lct_encrypted_hex_buf[0]) { if (strcmp(lct_encrypted_hex_buf,"NULL")) { fprintf(stderr,"row %d has a non-null value for in_use\n",rowno+1); if (!row_in_error) num_errored_rows++; } } rowno++; break; } lineno++; } fclose(fptr); fprintf(stderr,"num_errored_rows = %d\n",num_errored_rows); return 0; }