int go() { int i; int *deck = XCALLOC(cards * sizeof(int)); int ret; pixel *image; /* init deck */ for (i = 0; i < cards; i++) { deck[i] = i * 360 / cards; } /* shuffle */ for (i = 0; i < reps; i++) { switch (mode) { case PILE: shuffle_pile (deck); break; case RIFFLE: shuffle_riffle(deck); break; case RANDOM: shuffle_random(deck); break; default: assert(0); } } image = flatten(deck); free(deck); ret = writeFile(file, ROWS(), COLS(), image); free(image); return ret; }
int main() { /* Create a new workbook and add a worksheet. */ lxw_workbook *workbook = workbook_new("hide_row_col.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_row_t row; /* Write some data. */ worksheet_write_string(worksheet, 0, 3, "Some hidden columns.", NULL); worksheet_write_string(worksheet, 7, 0, "Some hidden rows.", NULL); /* Hide all rows without data. */ worksheet_set_default_row(worksheet, 15, LXW_TRUE); /* Set the height of empty rows that we do want to display even if it is */ /* the default height. */ for (row = 1; row <= 6; row++) worksheet_set_row(worksheet, row, 15, NULL); /* Columns can be hidden explicitly. This doesn't increase the file size. */ lxw_row_col_options options = {.hidden = 1}; worksheet_set_column_opt(worksheet, COLS("G:XFD"), 8.43, NULL, &options); workbook_close(workbook); return 0; }
int main() { lxw_workbook *workbook = new_workbook("test_chart_bar22.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR); /* For testing, copy the randomly generated axis ids in the target file. */ chart->axis_id_1 = 43706240; chart->axis_id_2 = 43727104; worksheet_write_string(worksheet, 0, 1, "Series 1", NULL); worksheet_write_string(worksheet, 0, 2, "Series 2", NULL); worksheet_write_string(worksheet, 0, 3, "Series 3", NULL); worksheet_write_string(worksheet, 1, 0, "Category 1", NULL); worksheet_write_string(worksheet, 2, 0, "Category 2", NULL); worksheet_write_string(worksheet, 3, 0, "Category 3", NULL); worksheet_write_string(worksheet, 4, 0, "Category 4", NULL); worksheet_write_number(worksheet, 1, 1, 4.3, NULL); worksheet_write_number(worksheet, 2, 1, 2.5, NULL); worksheet_write_number(worksheet, 3, 1, 3.5, NULL); worksheet_write_number(worksheet, 4, 1, 4.5, NULL); worksheet_write_number(worksheet, 1, 2, 2.4, NULL); worksheet_write_number(worksheet, 2, 2, 4.5, NULL); worksheet_write_number(worksheet, 3, 2, 1.8, NULL); worksheet_write_number(worksheet, 4, 2, 2.8, NULL); worksheet_write_number(worksheet, 1, 3, 2, NULL); worksheet_write_number(worksheet, 2, 3, 2, NULL); worksheet_write_number(worksheet, 3, 3, 3, NULL); worksheet_write_number(worksheet, 4, 3, 5, NULL); worksheet_set_column(worksheet, COLS("A:D"), 11, NULL); chart_add_series(chart, "=Sheet1!$A$2:$A$5", "=Sheet1!$B$2:$B$5" ); chart_add_series(chart, "=Sheet1!$A$2:$A$5", "=Sheet1!$C$2:$C$5" ); chart_add_series(chart, "=Sheet1!$A$2:$A$5", "=Sheet1!$D$2:$D$5" ); worksheet_insert_chart(worksheet, CELL("E9"), chart); return workbook_close(workbook); }
int main() { lxw_workbook *workbook = new_workbook("test_outline01.xlsx"); lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, "Outlined Rows"); lxw_format *bold = workbook_add_format(workbook); format_set_bold(bold); lxw_row_col_options options1 = {.hidden = 0, .level = 2, .collapsed = 0}; lxw_row_col_options options2 = {.hidden = 0, .level = 1, .collapsed = 0}; worksheet_set_column(worksheet1, COLS("A:A"), 20, NULL); worksheet_set_row_opt(worksheet1, 1, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 2, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 3, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 4, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 5, LXW_DEF_ROW_HEIGHT, NULL, &options2); worksheet_set_row_opt(worksheet1, 6, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 7, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 8, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 9, LXW_DEF_ROW_HEIGHT, NULL, &options1); worksheet_set_row_opt(worksheet1, 10, LXW_DEF_ROW_HEIGHT, NULL, &options2); worksheet_write_string(worksheet1, CELL("A1"), "Region", bold); worksheet_write_string(worksheet1, CELL("A2"), "North" , NULL); worksheet_write_string(worksheet1, CELL("A3"), "North" , NULL); worksheet_write_string(worksheet1, CELL("A4"), "North" , NULL); worksheet_write_string(worksheet1, CELL("A5"), "North" , NULL); worksheet_write_string(worksheet1, CELL("A6"), "North Total", bold); worksheet_write_string(worksheet1, CELL("B1"), "Sales", bold); worksheet_write_number(worksheet1, CELL("B2"), 1000 , NULL); worksheet_write_number(worksheet1, CELL("B3"), 1200 , NULL); worksheet_write_number(worksheet1, CELL("B4"), 900 , NULL); worksheet_write_number(worksheet1, CELL("B5"), 1200 , NULL); worksheet_write_formula_num(worksheet1, CELL("B6"), "=SUBTOTAL(9,B2:B5)", bold, 4300); worksheet_write_string(worksheet1, CELL("A7"), "South" , NULL); worksheet_write_string(worksheet1, CELL("A8"), "South" , NULL); worksheet_write_string(worksheet1, CELL("A9"), "South" , NULL); worksheet_write_string(worksheet1, CELL("A10"), "South" , NULL); worksheet_write_string(worksheet1, CELL("A11"), "South Total", bold); worksheet_write_number(worksheet1, CELL("B7"), 400 , NULL); worksheet_write_number(worksheet1, CELL("B8"), 600 , NULL); worksheet_write_number(worksheet1, CELL("B9"), 500 , NULL); worksheet_write_number(worksheet1, CELL("B10"), 600 , NULL); worksheet_write_formula_num(worksheet1, CELL("B11"), "=SUBTOTAL(9,B7:B10)", bold, 2100); worksheet_write_string(worksheet1, CELL("A12"), "Grand Total", bold); worksheet_write_formula_num(worksheet1, CELL("B12"), "=SUBTOTAL(9,B2:B10)", bold, 6400); return workbook_close(workbook); }
/* ** Pad the requested row from the current width to 'newWidth' with spaces... */ void _DtTermPrimBufferPadLineWc ( const TermBuffer tb, const short row, const short width ) { short i; short widthInc; TermLine line; wchar_t *pwc; line = LINE_OF_TBUF(tb, row); if (isDebugFSet('i', 1)) { #ifdef BBA #pragma BBA_IGNORE #endif /*BBA*/ (void) _termBufferValidateLineWc(tb, row); } /* ** if this line is part of the selection, disown the selection... */ if (IS_IN_SELECTION(line, MIN(width, WIDTH(line)), MAX(width, WIDTH(line)))) { (void) _DtTermPrimSelectDisown(WIDGET(tb)); } widthInc = MIN(COLS(tb), width) - WIDTH(line); for (i = 0, pwc = (wchar_t *)BUFFER(line) + MAX(0, LENGTH(line)); i < widthInc; i++, pwc++) { *pwc = L' '; LENGTH(line)++; } if (CLEAR_ENH(tb)) { (*CLEAR_ENH(tb))(tb, row, WIDTH(line), widthInc); } _DtTermPrimBufferSetLineWidth(tb, row, WIDTH(line) + widthInc); if (isDebugFSet('i', 1)) { #ifdef BBA #pragma BBA_IGNORE #endif /*BBA*/ _termBufferValidateLineWc(tb, row); } }
pixel *flatten(int *deck) { int rows = ROWS(); int cols = COLS(); pixel *flat = XCALLOC(rows * cols * sizeof(pixel)); int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { pixel *pp = &flat[(i * cols) + j]; *pp = colorize(deck[j / CARD_WIDTH]); if (!(pp->red > 0 || pp->green > 0 || pp->blue > 0)) { printf("Pixel %d,%d (#%d) failed\n", i,j, j/CARD_WIDTH); } } } return flat; }
void load_input_with_image(IMAGE *img,BPNN *net) { double *units; int nr, nc, imgsize, i, j, k; nr = ROWS(img); nc = COLS(img); imgsize = nr * nc;; if (imgsize != net->input_n) { printf("LOAD_INPUT_WITH_IMAGE: This image has %d pixels,\n", imgsize); printf(" but your net has %d input units. I give up.\n", net->input_n); exit (-1); } units = net->input_units; k = 1; for (i = 0; i < nr; i++) { for (j = 0; j < nc; j++) { units[k] = ((double) img_getpixel(img, i, j)) / 255.0; k++; } } }
/* ** Print the contents of the TermBuffer. */ static void _termBufferPrintBuffer ( const TermBuffer tb ) { short i; short j; short k; if (tb == NULL) { printf("TermBuffer has been freed.\n"); return; } printf("TermBuffer dimensions:\n"); printf(" rows: %d\n", ROWS(tb)); printf(" cols: %d\n", COLS(tb)); for (i = 0; i < ROWS(tb); i++) { _termBufferPrintLine(tb, i); } }
/* ** Clear the line to the new width (just reset the line width). */ Boolean _DtTermPrimBufferClearLineWc ( const TermBuffer tb, const short row, short newWidth ) { TermLine line; TermCharInfoRec charInfo; short newLength; /* ** Some simple bounds checking. */ if (!VALID_ROW(tb, row)) { return(False); } /* ** force the width to the desired value ** ** (We take the direct approach because _DtTermPrimBufferSetLineWidth ** doesn't allow the line width to decrease.) */ line = LINE_OF_TBUF(tb, row); /* ** if this line is part of the selection, disown the selection... */ if (IS_IN_SELECTION(line, MIN(newWidth, WIDTH(line)), MAX(newWidth, WIDTH(line)))) { (void) _DtTermPrimSelectDisown(WIDGET(tb)); } /* ** Clip the new width to the buffer width. */ newWidth = MIN(newWidth, COLS(tb)); if (newWidth < WIDTH(line)) { if (newWidth == 0) { newLength = 0; } else { /* ** handle the case of clearing the second column of a two column ** character... */ _DtTermPrimGetCharacterInfo(tb, row, MAX(0, newWidth - 1), &charInfo); if ((charInfo.width == 2 ) && (charInfo.startCol == MAX(0, newWidth - 1))) { /* ** we are clearing column 2 of 2, replace column 1 of 1 with ** a space... */ *charInfo.u.pwc = L' '; } newLength = charInfo.idx + 1; } /* ** Call the helper function if it exists */ if (CLEAR_LINE(tb)) { (*CLEAR_LINE(tb))(tb, row, newWidth); } WRAPPED(line) = False; WIDTH(line) = newWidth; LENGTH(line) = newLength; } return(True); }
/* ** This is a helper function that inserts characters into the specified ** buffer in overwrite mode. */ static void _primBufferOverwriteWc ( const TermBuffer tb, const short row, short *col, wchar_t *newChars, short numChars, short *lengthInc, short *widthInc, short *widthInsert, /* width of inserted characters */ termChar *returnChars, /* pointer to overflow buffer */ short *returnLength /* count of characters in overflow buffer */ ) { short charWidth; short insertOverflow; /* # of newChars that would overflow */ short lengthInsert; short localCol; TermLine line; const char *pStart; TermCharInfoRec charInfo; TermCharInfoRec startCharInfo; line = LINE_OF_TBUF(tb, row); /* ** make a copy of *col because it may be modified by ** _patchUpChar() */ localCol = *col; /* ** first decide how many characters we can overwrite before ** running off the end of the line. */ _countWidth(newChars, numChars, COLS(tb) - localCol, &lengthInsert, widthInsert); /* ** We are overwriting: ** - determine the length and width increments ** - put any extra new characters into the overflow buffer */ if (localCol == WIDTH(line)) { /* ** we are appending to the end of the line, this is easy... */ *widthInc = *widthInsert; *lengthInc = lengthInsert; pStart = (char *)BUFFER(line) + (LENGTH(line) * sizeof(wchar_t)); } else { /* ** we are overwriting characters in the middle of the line... ** ** make sure we are not trying to overwrite the second column ** of a two column character. */ _patchUpChar(tb, row, col, &startCharInfo); /* ** see if we have to deal with the end of the line... */ if (localCol + *widthInsert < WIDTH(line)) { /* ** the line width will remain constant, but the length may ** change... */ *widthInc = 0; /* ** make sure we are not trying to overwrite the first column ** of a two column character. */ _DtTermPrimGetCharacterInfo(tb, row, localCol + *widthInsert, &charInfo); if ((charInfo.width == 2) && (charInfo.startCol == localCol + *widthInsert - 1)) { /* ** We are about to overwrite column 1 of a 2 column ** character. Replace it with a space before we proceed ** (we make adjustments later to make it look like we ** replaced the second column with a space). */ *charInfo.u.pwc = L' '; /* ** now update the charInfo (since we replaced the 2 column ** character with a single column space)... */ charInfo.width = 1; } /* ** at this point, startCharInfo points to the first ** character to replace, now we want charInfo.u.pwc ** to point to the character one past the last one ** we want to replace */ *lengthInc = lengthInsert - (charInfo.u.pwc - startCharInfo.u.pwc); if (*lengthInc != 0) { memmove(charInfo.u.pwc + *lengthInc, charInfo.u.pwc, (LENGTH(line) - charInfo.idx) * sizeof(wchar_t)); } } else { /* ** the line may get wider and longer... */ *widthInc = localCol + *widthInsert - WIDTH(line); *lengthInc = startCharInfo.idx + lengthInsert - LENGTH(line); } pStart = startCharInfo.u.pc; } /* ** now insert the new characters... */ memcpy((void *)pStart, newChars, lengthInsert * sizeof(wchar_t)); /* ** put any overflow into the overflow buffer */ *returnLength = numChars - lengthInsert; if (*returnLength > 0) { memcpy(returnChars, newChars + lengthInsert, *returnLength * sizeof(wchar_t)); } }
/* ** This is a helper function that inserts characters into the specified ** buffer in insert mode. */ static void _primBufferInsertWc ( const TermBuffer tb, const short row, short *col, wchar_t *newChars, short numChars, short *lengthInc, short *widthInc, short *widthInsert, /* width of inserted characters */ termChar *returnChars, /* pointer to overflow buffer */ short *returnLength /* count of characters in overflow buffer */ ) { short charWidth; short lengthInsert; short insertOverflow; /* # of newChars that would overflow */ short overflowLength; short overflowWidth; short localCol; TermLine line; wchar_t *pwc; TermCharInfoRec charInfo; /* ** make a copy of *col because it may be modified by ** _patchUpChar() */ localCol = *col; /* ** first decide how many characters we can insert before ** running off the end of the line... */ _countWidth(newChars, numChars, COLS(tb) - localCol, &lengthInsert, widthInsert); /* ** return any extra characters... */ *returnLength = numChars - lengthInsert; if (*returnLength > 0) { /* ** we have some overflow... */ memcpy(returnChars, newChars + lengthInsert, *returnLength * sizeof(wchar_t)); } /* ** make sure we are not trying to overwrite the second column ** of a two column character. */ _patchUpChar(tb, row, col, &charInfo); /* ** Decide how many characters we can insert before running off the ** end of the buffer... */ line = LINE_OF_TBUF(tb, row); if (WIDTH(line) + *widthInsert <= COLS(tb)) { /* ** there is no overflow, we can insert all "lengthInsert" characters... */ *widthInc = *widthInsert; *lengthInc = lengthInsert; overflowLength = 0; } else { overflowWidth = WIDTH(line) + *widthInsert - COLS(tb); /* ** inserting the new characters will overflow the line buffer, ** remove as many of the current characters on the line ** as necessary to prevent buffer overflow */ if (overflowWidth > 0) { *widthInc = *widthInsert - overflowWidth; for (pwc = ((wchar_t *)BUFFER(line)) + LENGTH(line) - 1; pwc >= charInfo.u.pwc; pwc--) { overflowWidth -= MAX(1, wcwidth(*pwc)); if (overflowWidth <= 0) { /* ** we've removed enough characters, pwc points to the ** first character to remove... */ break; } } /* ** final adjustment to widthInc (at this point overflowWidth ** is either 0 (we removed exactly "overflowWidth" worth of ** characters) or -1 (we removed "overflowWidth + 1" worth of ** characters because we removed some 2 column characters) */ *widthInc += overflowWidth; } overflowLength = ((wchar_t *)BUFFER(line)) + LENGTH(line) - pwc; if (overflowLength > 0) { *lengthInc = lengthInsert - overflowLength; /* ** copy the displaced characters from the line to the ** overflow buffer... */ memcpy(returnChars + *returnLength, pwc, overflowLength * sizeof(wchar_t)); *returnLength += overflowLength; } } /* ** Any overflow has been taken care of, now it's time to make ** room for the new characters... ** ** at this point: ** charInfo.pchar points to the character at col */ memmove(charInfo.u.pwc + lengthInsert, charInfo.u.pwc, (((LENGTH(line) - charInfo.idx) - overflowLength) * sizeof(wchar_t))); /* ** copy the new characters into the buffer */ memcpy(charInfo.u.pwc, newChars, lengthInsert * sizeof(wchar_t)); }