repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gamma_test | static void
gamma_test(png_modifier *pmIn, PNG_CONST png_byte colour_typeIn,
PNG_CONST png_byte bit_depthIn, PNG_CONST int palette_numberIn,
PNG_CONST int interlace_typeIn,
PNG_CONST double file_gammaIn, PNG_CONST double screen_gammaIn,
PNG_CONST png_byte sbitIn, PNG_CONST int threshold_testIn,
PNG_CONST char *name,
PNG_CONST int use_input_precisionIn, PNG_CONST int scale16In,
PNG_CONST int expand16In, PNG_CONST int do_backgroundIn,
PNG_CONST png_color_16 *bkgd_colorIn, double bkgd_gammaIn)
{
gamma_display d;
context(&pmIn->this, fault);
gamma_display_init(&d, pmIn, FILEID(colour_typeIn, bit_depthIn,
palette_numberIn, interlace_typeIn, 0, 0, 0),
file_gammaIn, screen_gammaIn, sbitIn,
threshold_testIn, use_input_precisionIn, scale16In,
expand16In, do_backgroundIn, bkgd_colorIn, bkgd_gammaIn);
Try
{
png_structp pp;
png_infop pi;
gama_modification gama_mod;
srgb_modification srgb_mod;
sbit_modification sbit_mod;
/* For the moment don't use the png_modifier support here. */
d.pm->encoding_counter = 0;
modifier_set_encoding(d.pm); /* Just resets everything */
d.pm->current_gamma = d.file_gamma;
/* Make an appropriate modifier to set the PNG file gamma to the
* given gamma value and the sBIT chunk to the given precision.
*/
d.pm->modifications = NULL;
gama_modification_init(&gama_mod, d.pm, d.file_gamma);
srgb_modification_init(&srgb_mod, d.pm, 127 /*delete*/);
if (d.sbit > 0)
sbit_modification_init(&sbit_mod, d.pm, d.sbit);
modification_reset(d.pm->modifications);
/* Get a png_struct for writing the image. */
pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);
standard_palette_init(&d.this);
/* Introduce the correct read function. */
if (d.pm->this.progressive)
{
/* Share the row function with the standard implementation. */
png_set_progressive_read_fn(pp, &d, gamma_info, progressive_row,
gamma_end);
/* Now feed data into the reader until we reach the end: */
modifier_progressive_read(d.pm, pp, pi);
}
else
{
/* modifier_read expects a png_modifier* */
png_set_read_fn(pp, d.pm, modifier_read);
/* Check the header values: */
png_read_info(pp, pi);
/* Process the 'info' requirements. Only one image is generated */
gamma_info_imp(&d, pp, pi);
sequential_row(&d.this, pp, pi, -1, 0);
if (!d.this.speed)
gamma_image_validate(&d, pp, pi);
else
d.this.ps->validated = 1;
}
modifier_reset(d.pm);
if (d.pm->log && !d.threshold_test && !d.this.speed)
fprintf(stderr, "%d bit %s %s: max error %f (%.2g, %2g%%)\n",
d.this.bit_depth, colour_types[d.this.colour_type], name,
d.maxerrout, d.maxerrabs, 100*d.maxerrpc);
/* Log the summary values too. */
if (d.this.colour_type == 0 || d.this.colour_type == 4)
{
switch (d.this.bit_depth)
{
case 1:
break;
case 2:
if (d.maxerrout > d.pm->error_gray_2)
d.pm->error_gray_2 = d.maxerrout;
break;
case 4:
if (d.maxerrout > d.pm->error_gray_4)
d.pm->error_gray_4 = d.maxerrout;
break;
case 8:
if (d.maxerrout > d.pm->error_gray_8)
d.pm->error_gray_8 = d.maxerrout;
break;
case 16:
if (d.maxerrout > d.pm->error_gray_16)
d.pm->error_gray_16 = d.maxerrout;
break;
default:
png_error(pp, "bad bit depth (internal: 1)");
}
}
else if (d.this.colour_type == 2 || d.this.colour_type == 6)
{
switch (d.this.bit_depth)
{
case 8:
if (d.maxerrout > d.pm->error_color_8)
d.pm->error_color_8 = d.maxerrout;
break;
case 16:
if (d.maxerrout > d.pm->error_color_16)
d.pm->error_color_16 = d.maxerrout;
break;
default:
png_error(pp, "bad bit depth (internal: 2)");
}
}
else if (d.this.colour_type == 3)
{
if (d.maxerrout > d.pm->error_indexed)
d.pm->error_indexed = d.maxerrout;
}
}
Catch(fault)
modifier_reset((png_modifier*)fault);
} | /* A single test run checking a gamma transformation.
*
* maxabs: maximum absolute error as a fraction
* maxout: maximum output error in the output units
* maxpc: maximum percentage error (as a percentage)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L8543-L8696 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_gamma_errors | static void
init_gamma_errors(png_modifier *pm)
{
pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
pm->error_color_8 = 0;
pm->error_indexed = 0;
pm->error_gray_16 = pm->error_color_16 = 0;
} | /* READ_BACKGROUND || READ_ALPHA_MODE */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L9056-L9063 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | if | else if (strcmp(*argv, "--gamma") == 0)
{
/* Just do two gamma tests here (2.2 and linear) for speed: */
pm.ngamma_tests = 2U;
pm.test_gamma_threshold = 1;
pm.test_gamma_transform = 1;
pm.test_gamma_sbit = 1;
pm.test_gamma_scale16 = 1;
pm.test_gamma_background = 1;
pm.test_gamma_alpha_mode = 1;
} | /* PNG_READ_TRANSFORMS_SUPPORTED */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L9822-L9832 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | png_log8bit | static png_uint_32 png_log8bit(unsigned x)
{
if (x > 0)
return (png_uint_32)floor(.5-log(x/255.)*L2INV);
return 0xffffffff;
} | /* For speed testing, need the internal functions too: */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/tarith.c#L737-L743 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | validation_gamma | int validation_gamma(int argc, char **argv)
{
double gamma[9] = { 2.2, 1.8, 1.52, 1.45, 1., 1/1.45, 1/1.52, 1/1.8, 1/2.2 };
double maxerr;
int i, silent=0, onlygamma=0;
/* Silence the output with -s, just test the gamma functions with -g: */
while (--argc > 0)
if (strcmp(*++argv, "-s") == 0)
silent = 1;
else if (strcmp(*argv, "-g") == 0)
onlygamma = 1;
else
{
fprintf(stderr, "unknown argument %s\n", *argv);
return 1;
}
if (!onlygamma)
{
/* First validate the log functions: */
maxerr = 0;
for (i=0; i<256; ++i)
{
double correct = -log(i/255.)/log(2.)*65536;
double error = png_log8bit(i) - correct;
if (i != 0 && fabs(error) > maxerr)
maxerr = fabs(error);
if (i == 0 && png_log8bit(i) != 0xffffffff ||
i != 0 && png_log8bit(i) != floor(correct+.5))
{
fprintf(stderr, "8 bit log error: %d: got %u, expected %f\n",
i, png_log8bit(i), correct);
}
}
if (!silent)
printf("maximum 8 bit log error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<65536; ++i)
{
double correct = -log(i/65535.)/log(2.)*65536;
double error = png_log16bit(i) - correct;
if (i != 0 && fabs(error) > maxerr)
maxerr = fabs(error);
if (i == 0 && png_log16bit(i) != 0xffffffff ||
i != 0 && png_log16bit(i) != floor(correct+.5))
{
if (error > .68) /* By experiment error is less than .68 */
{
fprintf(stderr, "16 bit log error: %d: got %u, expected %f"
" error: %f\n", i, png_log16bit(i), correct, error);
}
}
}
if (!silent)
printf("maximum 16 bit log error = %f\n", maxerr);
/* Now exponentiations. */
maxerr = 0;
for (i=0; i<=0xfffff; ++i)
{
double correct = exp(-i/65536. * log(2.)) * (65536. * 65536);
double error = png_exp(i) - correct;
if (fabs(error) > maxerr)
maxerr = fabs(error);
if (fabs(error) > 1883) /* By experiment. */
{
fprintf(stderr, "32 bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp(i), correct, error);
}
}
if (!silent)
printf("maximum 32 bit exp error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<=0xfffff; ++i)
{
double correct = exp(-i/65536. * log(2.)) * 255;
double error = png_exp8bit(i) - correct;
if (fabs(error) > maxerr)
maxerr = fabs(error);
if (fabs(error) > .50002) /* By experiment */
{
fprintf(stderr, "8 bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp8bit(i), correct, error);
}
}
if (!silent)
printf("maximum 8 bit exp error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<=0xfffff; ++i)
{
double correct = exp(-i/65536. * log(2.)) * 65535;
double error = png_exp16bit(i) - correct;
if (fabs(error) > maxerr)
maxerr = fabs(error);
if (fabs(error) > .524) /* By experiment */
{
fprintf(stderr, "16 bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp16bit(i), correct, error);
}
}
if (!silent)
printf("maximum 16 bit exp error = %f\n", maxerr);
} /* !onlygamma */
/* Test the overall gamma correction. */
for (i=0; i<9; ++i)
{
unsigned j;
double g = gamma[i];
png_fixed_point gfp = floor(g * PNG_FP_1 + .5);
if (!silent)
printf("Test gamma %f\n", g);
maxerr = 0;
for (j=0; j<256; ++j)
{
double correct = pow(j/255., g) * 255;
png_byte out = png_gamma_8bit_correct(j, gfp);
double error = out - correct;
if (fabs(error) > maxerr)
maxerr = fabs(error);
if (out != floor(correct+.5))
{
fprintf(stderr, "8bit %d ^ %f: got %d expected %f error %f\n",
j, g, out, correct, error);
}
}
if (!silent)
printf("gamma %f: maximum 8 bit error %f\n", g, maxerr);
maxerr = 0;
for (j=0; j<65536; ++j)
{
double correct = pow(j/65535., g) * 65535;
png_uint_16 out = png_gamma_16bit_correct(j, gfp);
double error = out - correct;
if (fabs(error) > maxerr)
maxerr = fabs(error);
if (fabs(error) > 1.62)
{
fprintf(stderr, "16bit %d ^ %f: got %d expected %f error %f\n",
j, g, out, correct, error);
}
}
if (!silent)
printf("gamma %f: maximum 16 bit error %f\n", g, maxerr);
}
return 0;
} | /* FLOATING_ARITHMETIC */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/tarith.c#L769-L939 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char *argv[])
{
FILE *fp_rd = stdin;
FILE *fp_wr = stdout;
FILE *fp_al = NULL;
BOOL raw = TRUE;
BOOL alpha = FALSE;
int argi;
for (argi = 1; argi < argc; argi++)
{
if (argv[argi][0] == '-')
{
switch (argv[argi][1])
{
case 'n':
raw = FALSE;
break;
case 'r':
raw = TRUE;
break;
case 'a':
alpha = TRUE;
argi++;
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]);
exit (1);
}
break;
case 'h':
case '?':
usage();
exit(0);
break;
default:
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
usage();
exit(1);
break;
} /* end switch */
}
else if (fp_rd == stdin)
{
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
exit (1);
}
}
else if (fp_wr == stdout)
{
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: can not create file %s\n", argv[argi]);
exit (1);
}
}
else
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: too many parameters\n");
usage();
exit(1);
}
} /* end for */
#ifdef __TURBOC__
/* set stdin/stdout if required to binary */
if (fp_rd == stdin)
{
setmode (STDIN, O_BINARY);
}
if ((raw) && (fp_wr == stdout))
{
setmode (STDOUT, O_BINARY);
}
#endif
/* call the conversion program itself */
if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n");
exit(1);
}
/* close input file */
fclose (fp_rd);
/* close output file */
fclose (fp_wr);
/* close alpha file */
if (alpha)
fclose (fp_al);
return 0;
} | /*
* main
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/png2pnm.c#L61-L161 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | usage | void usage()
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, " by Willem van Schaik, 1999\n");
#ifdef __TURBOC__
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
#else
fprintf (stderr, " for Linux (and Unix) compilers\n");
#endif
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
fprintf (stderr, " or: ... | png2pnm [options]\n");
fprintf (stderr, "Options:\n");
fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
fprintf (stderr, " -h | -? print this help-information\n");
} | /*
* usage
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/png2pnm.c#L167-L183 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | png2pnm | BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha)
{
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
png_byte buf[8];
png_byte *png_pixels = NULL;
png_byte **row_pointers = NULL;
png_byte *pix_ptr = NULL;
png_uint_32 row_bytes;
png_uint_32 width;
png_uint_32 height;
int bit_depth;
int channels;
int color_type;
int alpha_present;
int row, col;
int ret;
int i;
long dep_16;
/* read and check signature in PNG file */
ret = fread (buf, 1, 8, png_file);
if (ret != 8)
return FALSE;
ret = png_sig_cmp (buf, 0, 8);
if (ret)
return FALSE;
/* create png and info structures */
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (!png_ptr)
return FALSE; /* out of memory */
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
png_destroy_read_struct (&png_ptr, NULL, NULL);
return FALSE; /* out of memory */
}
if (setjmp (png_jmpbuf(png_ptr)))
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
/* set up the input control for C streams */
png_init_io (png_ptr, png_file);
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
/* read the file information */
png_read_info (png_ptr, info_ptr);
/* get size and bit-depth of the PNG-image */
png_get_IHDR (png_ptr, info_ptr,
&width, &height, &bit_depth, &color_type,
NULL, NULL, NULL);
/* set-up the transformations */
/* transform paletted images into full-color rgb */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand (png_ptr);
/* expand images to bit-depth 8 (only applicable for grayscale images) */
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand (png_ptr);
/* transform transparency maps into full alpha-channel */
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand (png_ptr);
#ifdef NJET
/* downgrade 16-bit images to 8 bit */
if (bit_depth == 16)
png_set_strip_16 (png_ptr);
/* transform grayscale images into full-color */
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
/* only if file has a file gamma, we do a correction */
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
#endif
/* all transformations have been registered; now update info_ptr data,
* get rowbytes and channels, and allocate image memory */
png_read_update_info (png_ptr, info_ptr);
/* get the new color-type and bit-depth (after expansion/stripping) */
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
NULL, NULL, NULL);
/* check for 16-bit files */
if (bit_depth == 16)
{
raw = FALSE;
#ifdef __TURBOC__
pnm_file->flags &= ~((unsigned) _F_BIN);
#endif
}
/* calculate new number of channels and store alpha-presence */
if (color_type == PNG_COLOR_TYPE_GRAY)
channels = 1;
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
channels = 2;
else if (color_type == PNG_COLOR_TYPE_RGB)
channels = 3;
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
channels = 4;
else
channels = 0; /* should never happen */
alpha_present = (channels - 1) % 2;
/* check if alpha is expected to be present in file */
if (alpha && !alpha_present)
{
fprintf (stderr, "PNG2PNM\n");
fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
exit (1);
}
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
free (png_pixels);
png_pixels = NULL;
return FALSE;
}
/* set the individual row_pointers to point at the correct offsets */
for (i = 0; i < (height); i++)
row_pointers[i] = png_pixels + i * row_bytes;
/* now we can go ahead and just read the whole image */
png_read_image (png_ptr, row_pointers);
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end (png_ptr, info_ptr);
/* clean up after the read, and free any memory allocated - REQUIRED */
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
/* write header of PNM file */
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
{
fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
}
else if ((color_type == PNG_COLOR_TYPE_RGB) ||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
{
fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
}
/* write header of PGM file with alpha channel */
if ((alpha) &&
((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
{
fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
}
/* write data to PNM file */
pix_ptr = png_pixels;
for (row = 0; row < height; row++)
{
for (col = 0; col < width; col++)
{
for (i = 0; i < (channels - alpha_present); i++)
{
if (raw)
fputc ((int) *pix_ptr++ , pnm_file);
else
if (bit_depth == 16){
dep_16 = (long) *pix_ptr++;
fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
}
else
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
}
if (alpha_present)
{
if (!alpha)
{
pix_ptr++; /* alpha */
if (bit_depth == 16)
pix_ptr++;
}
else /* output alpha-channel as pgm file */
{
if (raw)
fputc ((int) *pix_ptr++ , alpha_file);
else
if (bit_depth == 16){
dep_16 = (long) *pix_ptr++;
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
}
else
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
}
} /* if alpha_present */
if (!raw)
if (col % 4 == 3)
fprintf (pnm_file, "\n");
} /* end for col */
if (!raw)
if (col % 4 != 0)
fprintf (pnm_file, "\n");
} /* end for row */
if (row_pointers != (unsigned char**) NULL)
free (row_pointers);
if (png_pixels != (unsigned char*) NULL)
free (png_pixels);
return TRUE;
} | /*
* png2pnm
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/png2pnm.c | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char *argv[])
{
FILE *fp_rd = stdin;
FILE *fp_al = NULL;
FILE *fp_wr = stdout;
BOOL interlace = FALSE;
BOOL alpha = FALSE;
int argi;
for (argi = 1; argi < argc; argi++)
{
if (argv[argi][0] == '-')
{
switch (argv[argi][1])
{
case 'i':
interlace = TRUE;
break;
case 'a':
alpha = TRUE;
argi++;
if ((fp_al = fopen (argv[argi], "rb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
argv[argi]);
exit (1);
}
break;
case 'h':
case '?':
usage();
exit(0);
break;
default:
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
usage();
exit(1);
break;
} /* end switch */
}
else if (fp_rd == stdin)
{
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
exit (1);
}
}
else if (fp_wr == stdout)
{
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]);
exit (1);
}
}
else
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: too many parameters\n");
usage();
exit (1);
}
} /* end for */
#ifdef __TURBOC__
/* set stdin/stdout to binary, we're reading the PNM always! in binary format */
if (fp_rd == stdin)
{
setmode (STDIN, O_BINARY);
}
if (fp_wr == stdout)
{
setmode (STDOUT, O_BINARY);
}
#endif
/* call the conversion program itself */
if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, "Error: unsuccessful converting to PNG-image\n");
exit (1);
}
/* close input file */
fclose (fp_rd);
/* close output file */
fclose (fp_wr);
/* close alpha file */
if (alpha)
fclose (fp_al);
return 0;
} | /*
* main
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c#L62-L160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | usage | void usage()
{
fprintf (stderr, "PNM2PNG\n");
fprintf (stderr, " by Willem van Schaik, 1999\n");
#ifdef __TURBOC__
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
#else
fprintf (stderr, " for Linux (and Unix) compilers\n");
#endif
fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
fprintf (stderr, " or: ... | pnm2png [options]\n");
fprintf (stderr, "Options:\n");
fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
fprintf (stderr, " -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
fprintf (stderr, " -h | -? print this help-information\n");
} | /*
* usage
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c#L166-L181 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pnm2png | BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha)
{
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
png_byte *png_pixels = NULL;
png_byte **row_pointers = NULL;
png_byte *pix_ptr = NULL;
png_uint_32 row_bytes;
char type_token[16];
char width_token[16];
char height_token[16];
char maxval_token[16];
int color_type;
unsigned long ul_width, ul_alpha_width;
unsigned long ul_height, ul_alpha_height;
unsigned long ul_maxval;
png_uint_32 width, alpha_width;
png_uint_32 height, alpha_height;
png_uint_32 maxval;
int bit_depth = 0;
int channels;
int alpha_depth = 0;
int alpha_present;
int row, col;
BOOL raw, alpha_raw = FALSE;
png_uint_32 tmp16;
int i;
/* read header of PNM file */
get_token(pnm_file, type_token);
if (type_token[0] != 'P')
{
return FALSE;
}
else if ((type_token[1] == '1') || (type_token[1] == '4'))
{
raw = (type_token[1] == '4');
color_type = PNG_COLOR_TYPE_GRAY;
bit_depth = 1;
}
else if ((type_token[1] == '2') || (type_token[1] == '5'))
{
raw = (type_token[1] == '5');
color_type = PNG_COLOR_TYPE_GRAY;
get_token(pnm_file, width_token);
sscanf (width_token, "%lu", &ul_width);
width = (png_uint_32) ul_width;
get_token(pnm_file, height_token);
sscanf (height_token, "%lu", &ul_height);
height = (png_uint_32) ul_height;
get_token(pnm_file, maxval_token);
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
if (maxval <= 1)
bit_depth = 1;
else if (maxval <= 3)
bit_depth = 2;
else if (maxval <= 15)
bit_depth = 4;
else if (maxval <= 255)
bit_depth = 8;
else /* if (maxval <= 65535) */
bit_depth = 16;
}
else if ((type_token[1] == '3') || (type_token[1] == '6'))
{
raw = (type_token[1] == '6');
color_type = PNG_COLOR_TYPE_RGB;
get_token(pnm_file, width_token);
sscanf (width_token, "%lu", &ul_width);
width = (png_uint_32) ul_width;
get_token(pnm_file, height_token);
sscanf (height_token, "%lu", &ul_height);
height = (png_uint_32) ul_height;
get_token(pnm_file, maxval_token);
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
if (maxval <= 1)
bit_depth = 1;
else if (maxval <= 3)
bit_depth = 2;
else if (maxval <= 15)
bit_depth = 4;
else if (maxval <= 255)
bit_depth = 8;
else /* if (maxval <= 65535) */
bit_depth = 16;
}
else
{
return FALSE;
}
/* read header of PGM file with alpha channel */
if (alpha)
{
if (color_type == PNG_COLOR_TYPE_GRAY)
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
if (color_type == PNG_COLOR_TYPE_RGB)
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
get_token(alpha_file, type_token);
if (type_token[0] != 'P')
{
return FALSE;
}
else if ((type_token[1] == '2') || (type_token[1] == '5'))
{
alpha_raw = (type_token[1] == '5');
get_token(alpha_file, width_token);
sscanf (width_token, "%lu", &ul_alpha_width);
alpha_width=(png_uint_32) ul_alpha_width;
if (alpha_width != width)
return FALSE;
get_token(alpha_file, height_token);
sscanf (height_token, "%lu", &ul_alpha_height);
alpha_height = (png_uint_32) ul_alpha_height;
if (alpha_height != height)
return FALSE;
get_token(alpha_file, maxval_token);
sscanf (maxval_token, "%lu", &ul_maxval);
maxval = (png_uint_32) ul_maxval;
if (maxval <= 1)
alpha_depth = 1;
else if (maxval <= 3)
alpha_depth = 2;
else if (maxval <= 15)
alpha_depth = 4;
else if (maxval <= 255)
alpha_depth = 8;
else /* if (maxval <= 65535) */
alpha_depth = 16;
if (alpha_depth != bit_depth)
return FALSE;
}
else
{
return FALSE;
}
} /* end if alpha */
/* calculate the number of channels and store alpha-presence */
if (color_type == PNG_COLOR_TYPE_GRAY)
channels = 1;
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
channels = 2;
else if (color_type == PNG_COLOR_TYPE_RGB)
channels = 3;
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
channels = 4;
else
channels = 0; /* should not happen */
alpha_present = (channels - 1) % 2;
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
return FALSE;
/* read data from PNM file */
pix_ptr = png_pixels;
for (row = 0; row < height; row++)
{
for (col = 0; col < width; col++)
{
for (i = 0; i < (channels - alpha_present); i++)
{
if (raw)
*pix_ptr++ = get_data (pnm_file, bit_depth);
else
if (bit_depth <= 8)
*pix_ptr++ = get_value (pnm_file, bit_depth);
else
{
tmp16 = get_value (pnm_file, bit_depth);
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
pix_ptr++;
*pix_ptr = (png_byte) (tmp16 & 0xFF);
pix_ptr++;
}
}
if (alpha) /* read alpha-channel from pgm file */
{
if (alpha_raw)
*pix_ptr++ = get_data (alpha_file, alpha_depth);
else
if (alpha_depth <= 8)
*pix_ptr++ = get_value (alpha_file, bit_depth);
else
{
tmp16 = get_value (alpha_file, bit_depth);
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
}
} /* if alpha */
} /* end for col */
} /* end for row */
/* prepare the standard PNG structures */
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
return FALSE;
}
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return FALSE;
}
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
if (setjmp (png_jmpbuf(png_ptr)))
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return FALSE;
}
/* initialize the png structure */
png_init_io (png_ptr, png_file);
/* we're going to write more or less the same PNG as the input file */
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
(!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* write the file header information */
png_write_info (png_ptr, info_ptr);
/* if needed we will allocate memory for an new array of row-pointers */
if (row_pointers == (unsigned char**) NULL)
{
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return FALSE;
}
}
/* set the individual row_pointers to point at the correct offsets */
for (i = 0; i < (height); i++)
row_pointers[i] = png_pixels + i * row_bytes;
/* write out the entire image data in one call */
png_write_image (png_ptr, row_pointers);
/* write the additional chuncks to the PNG file (not really needed) */
png_write_end (png_ptr, info_ptr);
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
if (row_pointers != (unsigned char**) NULL)
free (row_pointers);
if (png_pixels != (unsigned char*) NULL)
free (png_pixels);
return TRUE;
} | /*
* pnm2png
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_token | void get_token(FILE *pnm_file, char *token)
{
int i = 0;
/* remove white-space */
do
{
token[i] = (unsigned char) fgetc (pnm_file);
}
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
/* read string */
do
{
i++;
token[i] = (unsigned char) fgetc (pnm_file);
}
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
token[i] = '\0';
return;
} | /* end of pnm2png */
/*
* get_token() - gets the first string after whitespace
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c#L460-L482 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_data | png_uint_32 get_data (FILE *pnm_file, int depth)
{
static int bits_left = 0;
static int old_value = 0;
static int mask = 0;
int i;
png_uint_32 ret_value;
if (mask == 0)
for (i = 0; i < depth; i++)
mask = (mask >> 1) | 0x80;
if (bits_left <= 0)
{
old_value = fgetc (pnm_file);
bits_left = 8;
}
ret_value = old_value & mask;
for (i = 1; i < (8 / depth); i++)
ret_value = ret_value || (ret_value >> depth);
old_value = (old_value << depth) & 0xFF;
bits_left -= depth;
return ret_value;
} | /*
* get_data() - takes first byte and converts into next pixel value,
* taking as much bits as defined by bit-depth and
* using the bit-depth to fill up a byte (0Ah -> AAh)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c#L490-L516 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_value | png_uint_32 get_value (FILE *pnm_file, int depth)
{
static png_uint_32 mask = 0;
png_byte token[16];
unsigned long ul_ret_value;
png_uint_32 ret_value;
int i = 0;
if (mask == 0)
for (i = 0; i < depth; i++)
mask = (mask << 1) | 0x01;
get_token (pnm_file, (char *) token);
sscanf ((const char *) token, "%lu", &ul_ret_value);
ret_value = (png_uint_32) ul_ret_value;
ret_value &= mask;
if (depth < 8)
for (i = 0; i < (8 / depth); i++)
ret_value = (ret_value << depth) || ret_value;
return ret_value;
} | /*
* get_value() - takes first (numeric) string and converts into number,
* using the bit-depth to fill up a byte (0Ah -> AAh)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/pngminus/pnm2png.c#L523-L546 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | png_cexcept_error | static void
png_cexcept_error(png_structp png_ptr, png_const_charp msg)
{
if(png_ptr)
;
#ifdef PNG_CONSOLE_IO_SUPPORTED
fprintf(stderr, "libpng error: %s\n", msg);
#endif
{
Throw msg;
}
} | /* cexcept interface */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/PngFile.c#L35-L46 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PngFileInitialize | void PngFileInitialize (HWND hwnd)
{
static TCHAR szFilter[] = TEXT ("PNG Files (*.PNG)\0*.png\0")
TEXT ("All Files (*.*)\0*.*\0\0");
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = NULL;
ofn.lpstrFilter = szFilter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = NULL; /* Set in Open and Close functions */
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFileTitle = NULL; /* Set in Open and Close functions */
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.Flags = 0; /* Set in Open and Close functions */
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = TEXT ("png");
ofn.lCustData = 0;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
} | /* Windows open-file functions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/PngFile.c#L50-L75 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PngLoadImage | BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)
{
static FILE *pfFile;
png_byte pbSig[8];
int iBitDepth;
int iColorType;
double dGamma;
png_color_16 *pBackground;
png_uint_32 ulChannels;
png_uint_32 ulRowBytes;
png_byte *pbImageData = *ppbImageData;
static png_byte **ppbRowPointers = NULL;
int i;
/* open the PNG input file */
if (!pstrFileName)
{
*ppbImageData = pbImageData = NULL;
return FALSE;
}
if (!(pfFile = fopen(pstrFileName, "rb")))
{
*ppbImageData = pbImageData = NULL;
return FALSE;
}
/* first check the eight byte PNG signature */
fread(pbSig, 1, 8, pfFile);
if (png_sig_cmp(pbSig, 0, 8))
{
*ppbImageData = pbImageData = NULL;
return FALSE;
}
/* create the two png(-info) structures */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
if (!png_ptr)
{
*ppbImageData = pbImageData = NULL;
return FALSE;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
*ppbImageData = pbImageData = NULL;
return FALSE;
}
Try
{
/* initialize the png structure */
#ifdef PNG_STDIO_SUPPORTED
png_init_io(png_ptr, pfFile);
#else
png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data);
#endif
png_set_sig_bytes(png_ptr, 8);
/* read all PNG info up to image data */
png_read_info(png_ptr, info_ptr);
/* get width, height, bit-depth and color-type */
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
&iColorType, NULL, NULL, NULL);
/* expand images of all color-type and bit-depth to 3x8-bit RGB */
/* let the library process alpha, transparency, background, etc. */
#ifdef PNG_READ_16_TO_8_SUPPORTED
if (iBitDepth == 16)
# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr);
# else
png_set_strip_16(png_ptr);
# endif
#endif
if (iColorType == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (iBitDepth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
if (iColorType == PNG_COLOR_TYPE_GRAY ||
iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/* set the background color to draw transparent and alpha images over */
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
{
png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
pBkgColor->red = (byte) pBackground->red;
pBkgColor->green = (byte) pBackground->green;
pBkgColor->blue = (byte) pBackground->blue;
}
else
{
pBkgColor = NULL;
}
/* if required set gamma conversion */
if (png_get_gAMA(png_ptr, info_ptr, &dGamma))
png_set_gamma(png_ptr, (double) 2.2, dGamma);
/* after the transformations are registered, update info_ptr data */
png_read_update_info(png_ptr, info_ptr);
/* get again width, height and the new bit-depth and color-type */
png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
&iColorType, NULL, NULL, NULL);
/* row_bytes is the width x number of channels */
ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);
ulChannels = png_get_channels(png_ptr, info_ptr);
*piChannels = ulChannels;
/* now we can allocate memory to store the image */
if (pbImageData)
{
free (pbImageData);
pbImageData = NULL;
}
if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight)
* sizeof(png_byte))) == NULL)
{
png_error(png_ptr, "Visual PNG: out of memory");
}
*ppbImageData = pbImageData;
/* and allocate memory for an array of row-pointers */
if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)
* sizeof(png_bytep))) == NULL)
{
png_error(png_ptr, "Visual PNG: out of memory");
}
/* set the individual row-pointers to point at the correct offsets */
for (i = 0; i < (*piHeight); i++)
ppbRowPointers[i] = pbImageData + i * ulRowBytes;
/* now we can go ahead and just read the whole image */
png_read_image(png_ptr, ppbRowPointers);
/* read the additional chunks in the PNG file (not really needed) */
png_read_end(png_ptr, NULL);
/* and we're done */
free (ppbRowPointers);
ppbRowPointers = NULL;
/* yepp, done */
}
Catch (msg)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
*ppbImageData = pbImageData = NULL;
if(ppbRowPointers)
free (ppbRowPointers);
fclose(pfFile);
return FALSE;
}
fclose (pfFile);
return TRUE;
} | /* PNG image handler functions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/PngFile.c#L99-L292 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | WinMain | int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HACCEL hAccel;
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int ixBorders, iyBorders;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szIconName) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = NULL; /* (HBRUSH) GetStockObject (GRAY_BRUSH); */
wndclass.lpszMenuName = szProgName;
wndclass.lpszClassName = szProgName;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Error: this program requires Windows NT!"),
szProgName, MB_ICONERROR);
return 0;
}
/* if filename given on commandline, store it */
if ((szCmdLine != NULL) && (*szCmdLine != '\0'))
if (szCmdLine[0] == '"')
strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);
else
strcpy (szCmdFileName, szCmdLine);
else
strcpy (szCmdFileName, "");
/* calculate size of window-borders */
ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +
GetSystemMetrics (SM_CXDLGFRAME));
iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +
GetSystemMetrics (SM_CYDLGFRAME)) +
GetSystemMetrics (SM_CYCAPTION) +
GetSystemMetrics (SM_CYMENUSIZE) +
1; /* WvS: don't ask me why? */
hwnd = CreateWindow (szProgName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,
/* CW_USEDEFAULT, CW_USEDEFAULT, */
NULL, NULL, hInstance, NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
hAccel = LoadAccelerators (hInstance, szProgName);
while (GetMessage (&msg, NULL, 0, 0))
{
if (!TranslateAccelerator (hwnd, hAccel, &msg))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return msg.wParam;
} | /* MAIN routine */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L79-L145 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | CenterAbout | BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
{
RECT rChild, rParent, rWorkArea;
int wChild, hChild, wParent, hParent;
int xNew, yNew;
BOOL bResult;
/* Get the Height and Width of the child window */
GetWindowRect (hwndChild, &rChild);
wChild = rChild.right - rChild.left;
hChild = rChild.bottom - rChild.top;
/* Get the Height and Width of the parent window */
GetWindowRect (hwndParent, &rParent);
wParent = rParent.right - rParent.left;
hParent = rParent.bottom - rParent.top;
/* Get the limits of the 'workarea' */
bResult = SystemParametersInfo(
SPI_GETWORKAREA, /* system parameter to query or set */
sizeof(RECT),
&rWorkArea,
0);
if (!bResult) {
rWorkArea.left = rWorkArea.top = 0;
rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
}
/* Calculate new X position, then adjust for workarea */
xNew = rParent.left + ((wParent - wChild) /2);
if (xNew < rWorkArea.left) {
xNew = rWorkArea.left;
} else if ((xNew+wChild) > rWorkArea.right) {
xNew = rWorkArea.right - wChild;
}
/* Calculate new Y position, then adjust for workarea */
yNew = rParent.top + ((hParent - hChild) /2);
if (yNew < rWorkArea.top) {
yNew = rWorkArea.top;
} else if ((yNew+hChild) > rWorkArea.bottom) {
yNew = rWorkArea.bottom - hChild;
}
/* Set it, and return */
return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |
SWP_NOZORDER);
} | /*---------------
* CenterAbout
*---------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L459-L507 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | BuildPngList | BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
int *pFileIndex)
{
static TCHAR szImgPathName [MAX_PATH];
static TCHAR szImgFileName [MAX_PATH];
static TCHAR szImgFindName [MAX_PATH];
WIN32_FIND_DATA finddata;
HANDLE hFind;
static TCHAR szTmp [MAX_PATH];
BOOL bOk;
int i, ii;
int j, jj;
/* free previous file-list */
if (*ppFileList != NULL)
{
free (*ppFileList);
*ppFileList = NULL;
}
/* extract foldername, filename and search-name */
strcpy (szImgPathName, pstrPathName);
strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1);
strcpy (szImgFindName, szImgPathName);
*(strrchr (szImgFindName, '\\') + 1) = '\0';
strcat (szImgFindName, "*.png");
/* first cycle: count number of files in directory for memory allocation */
*pFileCount = 0;
hFind = FindFirstFile(szImgFindName, &finddata);
bOk = (hFind != (HANDLE) -1);
while (bOk)
{
*pFileCount += 1;
bOk = FindNextFile(hFind, &finddata);
}
FindClose(hFind);
/* allocation memory for file-list */
*ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);
/* second cycle: read directory and store filenames in file-list */
hFind = FindFirstFile(szImgFindName, &finddata);
bOk = (hFind != (HANDLE) -1);
i = 0;
ii = 0;
while (bOk)
{
strcpy (*ppFileList + ii, szImgPathName);
strcpy (strrchr(*ppFileList + ii, '\\') + 1, finddata.cFileName);
if (strcmp(pstrPathName, *ppFileList + ii) == 0)
*pFileIndex = i;
ii += MAX_PATH;
i++;
bOk = FindNextFile(hFind, &finddata);
}
FindClose(hFind);
/* finally we must sort the file-list */
for (i = 0; i < *pFileCount - 1; i++)
{
ii = i * MAX_PATH;
for (j = i+1; j < *pFileCount; j++)
{
jj = j * MAX_PATH;
if (strcmp (*ppFileList + ii, *ppFileList + jj) > 0)
{
strcpy (szTmp, *ppFileList + jj);
strcpy (*ppFileList + jj, *ppFileList + ii);
strcpy (*ppFileList + ii, szTmp);
/* check if this was the current image that we moved */
if (*pFileIndex == i)
*pFileIndex = j;
else
if (*pFileIndex == j)
*pFileIndex = i;
}
}
}
return TRUE;
} | /*----------------
* BuildPngList
*----------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L513-L611 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SearchPngList | BOOL SearchPngList (
TCHAR *pFileList, int FileCount, int *pFileIndex,
PTSTR pstrPrevName, PTSTR pstrNextName)
{
if (FileCount > 0)
{
/* get previous entry */
if (pstrPrevName != NULL)
{
if (*pFileIndex > 0)
*pFileIndex -= 1;
else
*pFileIndex = FileCount - 1;
strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));
}
/* get next entry */
if (pstrNextName != NULL)
{
if (*pFileIndex < FileCount - 1)
*pFileIndex += 1;
else
*pFileIndex = 0;
strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH));
}
return TRUE;
}
else
{
return FALSE;
}
} | /*----------------
* SearchPngList
*----------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L618-L654 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | LoadImageFile | BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
png_byte **ppbImage, int *pxImgSize, int *pyImgSize,
int *piChannels, png_color *pBkgColor)
{
static TCHAR szTmp [MAX_PATH];
/* if there's an existing PNG, free the memory */
if (*ppbImage)
{
free (*ppbImage);
*ppbImage = NULL;
}
/* Load the entire PNG into memory */
SetCursor (LoadCursor (NULL, IDC_WAIT));
ShowCursor (TRUE);
PngLoadImage (pstrPathName, ppbImage, pxImgSize, pyImgSize, piChannels,
pBkgColor);
ShowCursor (FALSE);
SetCursor (LoadCursor (NULL, IDC_ARROW));
if (*ppbImage != NULL)
{
sprintf (szTmp, "VisualPng - %s", strrchr(pstrPathName, '\\') + 1);
SetWindowText (hwnd, szTmp);
}
else
{
MessageBox (hwnd, TEXT ("Error in loading the PNG image"),
szProgName, MB_ICONEXCLAMATION | MB_OK);
return FALSE;
}
return TRUE;
} | /*-----------------
* LoadImageFile
*-----------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L661-L699 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | DisplayImage | BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
BYTE **ppDiData, int cxWinSize, int cyWinSize,
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
BOOL bStretched)
{
BYTE *pDib = *ppDib;
BYTE *pDiData = *ppDiData;
/* BITMAPFILEHEADER *pbmfh; */
BITMAPINFOHEADER *pbmih;
WORD wDIRowBytes;
png_color bkgBlack = {0, 0, 0};
png_color bkgGray = {127, 127, 127};
png_color bkgWhite = {255, 255, 255};
/* allocate memory for the Device Independant bitmap */
wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;
if (pDib)
{
free (pDib);
pDib = NULL;
}
if (!(pDib = (BYTE *) malloc (sizeof(BITMAPINFOHEADER) +
wDIRowBytes * cyWinSize)))
{
MessageBox (hwnd, TEXT ("Error in displaying the PNG image"),
szProgName, MB_ICONEXCLAMATION | MB_OK);
*ppDib = pDib = NULL;
return FALSE;
}
*ppDib = pDib;
memset (pDib, 0, sizeof(BITMAPINFOHEADER));
/* initialize the dib-structure */
pbmih = (BITMAPINFOHEADER *) pDib;
pbmih->biSize = sizeof(BITMAPINFOHEADER);
pbmih->biWidth = cxWinSize;
pbmih->biHeight = -((long) cyWinSize);
pbmih->biPlanes = 1;
pbmih->biBitCount = 24;
pbmih->biCompression = 0;
pDiData = pDib + sizeof(BITMAPINFOHEADER);
*ppDiData = pDiData;
/* first fill bitmap with gray and image border */
InitBitmap (pDiData, cxWinSize, cyWinSize);
/* then fill bitmap with image */
if (pbImage)
{
FillBitmap (
pDiData, cxWinSize, cyWinSize,
pbImage, cxImgSize, cyImgSize, cImgChannels,
bStretched);
}
return TRUE;
} | /*----------------
* DisplayImage
*----------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L705-L767 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | InitBitmap | BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
{
BYTE *dst;
int x, y, col;
/* initialize the background with gray */
dst = pDiData;
for (y = 0; y < cyWinSize; y++)
{
col = 0;
for (x = 0; x < cxWinSize; x++)
{
/* fill with GRAY */
*dst++ = 127;
*dst++ = 127;
*dst++ = 127;
col += 3;
}
/* rows start on 4 byte boundaries */
while ((col % 4) != 0)
{
dst++;
col++;
}
}
return TRUE;
} | /*--------------
* InitBitmap
*--------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L773-L801 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | FillBitmap | BOOL FillBitmap (
BYTE *pDiData, int cxWinSize, int cyWinSize,
BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
BOOL bStretched)
{
BYTE *pStretchedImage;
BYTE *pImg;
BYTE *src, *dst;
BYTE r, g, b, a;
const int cDIChannels = 3;
WORD wImgRowBytes;
WORD wDIRowBytes;
int cxNewSize, cyNewSize;
int cxImgPos, cyImgPos;
int xImg, yImg;
int xWin, yWin;
int xOld, yOld;
int xNew, yNew;
if (bStretched)
{
cxNewSize = cxWinSize - 2 * MARGIN;
cyNewSize = cyWinSize - 2 * MARGIN;
/* stretch the image to it's window determined size */
/* the following two are mathematically the same, but the first
* has side-effects because of rounding
*/
/* if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) */
if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))
{
cyNewSize = cxNewSize * cyImgSize / cxImgSize;
cxImgPos = MARGIN;
cyImgPos = (cyWinSize - cyNewSize) / 2;
}
else
{
cxNewSize = cyNewSize * cxImgSize / cyImgSize;
cyImgPos = MARGIN;
cxImgPos = (cxWinSize - cxNewSize) / 2;
}
pStretchedImage = malloc (cImgChannels * cxNewSize * cyNewSize);
pImg = pStretchedImage;
for (yNew = 0; yNew < cyNewSize; yNew++)
{
yOld = yNew * cyImgSize / cyNewSize;
for (xNew = 0; xNew < cxNewSize; xNew++)
{
xOld = xNew * cxImgSize / cxNewSize;
r = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 0);
g = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 1);
b = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 2);
*pImg++ = r;
*pImg++ = g;
*pImg++ = b;
if (cImgChannels == 4)
{
a = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld)
+ 3);
*pImg++ = a;
}
}
}
/* calculate row-bytes */
wImgRowBytes = cImgChannels * cxNewSize;
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
/* copy image to screen */
for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)
{
if (yWin >= cyWinSize - cyImgPos)
break;
src = pStretchedImage + yImg * wImgRowBytes;
dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
for (xImg = 0, xWin = cxImgPos; xImg < cxNewSize; xImg++, xWin++)
{
if (xWin >= cxWinSize - cxImgPos)
break;
r = *src++;
g = *src++;
b = *src++;
*dst++ = b; /* note the reverse order */
*dst++ = g;
*dst++ = r;
if (cImgChannels == 4)
{
a = *src++;
}
}
}
/* free memory */
if (pStretchedImage != NULL)
{
free (pStretchedImage);
pStretchedImage = NULL;
}
}
/* process the image not-stretched */
else
{
/* calculate the central position */
cxImgPos = (cxWinSize - cxImgSize) / 2;
cyImgPos = (cyWinSize - cyImgSize) / 2;
/* check for image larger than window */
if (cxImgPos < MARGIN)
cxImgPos = MARGIN;
if (cyImgPos < MARGIN)
cyImgPos = MARGIN;
/* calculate both row-bytes */
wImgRowBytes = cImgChannels * cxImgSize;
wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
/* copy image to screen */
for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)
{
if (yWin >= cyWinSize - MARGIN)
break;
src = pbImage + yImg * wImgRowBytes;
dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
for (xImg = 0, xWin = cxImgPos; xImg < cxImgSize; xImg++, xWin++)
{
if (xWin >= cxWinSize - MARGIN)
break;
r = *src++;
g = *src++;
b = *src++;
*dst++ = b; /* note the reverse order */
*dst++ = g;
*dst++ = r;
if (cImgChannels == 4)
{
a = *src++;
}
}
}
}
return TRUE;
} | /*--------------
* FillBitmap
*--------------
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/visupng/VisualPng.c#L807-L965 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | do_close | static void
do_close(rfobject *self)
{
if (self->isclosed ) return;
(void)FSCloseFork(self->fRefNum);
self->isclosed = 1;
} | /* ---------------------------------------------------------------- */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/MacOS.c#L60-L66 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | my_eventProc | static pascal void
my_eventProc(NavEventCallbackMessage callBackSelector,
NavCBRecPtr callBackParms,
NavCallBackUserData callbackUD)
{
PyObject *dict = (PyObject *)callbackUD;
PyObject *pyfunc;
PyObject *rv;
if (!dict) return;
if ( (pyfunc = PyDict_GetItemString(dict, "eventProc")) == NULL ) {
PyErr_Print();
return;
}
if ( pyfunc == Py_None ) {
return;
}
rv = PyObject_CallFunction(pyfunc, "ls#", (long)callBackSelector,
(void *)callBackParms, sizeof(NavCBRec));
if ( rv )
Py_DECREF(rv);
else {
PySys_WriteStderr("Nav: exception in eventProc callback\n");
PyErr_Print();
}
} | /* Callback functions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/Nav.c#L45-L70 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | filldialogoptions | static int
filldialogoptions(PyObject *d,
AEDesc **defaultLocationP,
NavDialogOptions *opt,
NavEventUPP *eventProcP,
NavPreviewUPP *previewProcP,
NavObjectFilterUPP *filterProcP,
NavTypeListHandle *typeListP,
OSType *fileTypeP,
OSType *fileCreatorP)
{
Py_ssize_t pos = 0;
PyObject *key, *value;
char *keystr;
AEDesc *defaultLocation_storage;
NavGetDefaultDialogOptions(opt);
while ( PyDict_Next(d, &pos, &key, &value) ) {
if ( !key || !value || !PyString_Check(key) ) {
PyErr_SetString(ErrorObject, "DialogOption has non-string key");
return 0;
}
keystr = PyString_AsString(key);
if( strcmp(keystr, "defaultLocation") == 0 ) {
if ( (defaultLocation_storage = PyMem_NEW(AEDesc, 1)) == NULL ) {
PyErr_NoMemory();
return 0;
}
if ( !PyArg_Parse(value, "O&", AEDesc_Convert, defaultLocation_storage) ) {
PyMem_DEL(defaultLocation_storage);
return 0;
}
*defaultLocationP = defaultLocation_storage;
} else if( strcmp(keystr, "version") == 0 ) {
if ( !PyArg_Parse(value, "H", &opt->version) )
return 0;
} else if( strcmp(keystr, "dialogOptionFlags") == 0 ) {
if ( !PyArg_Parse(value, "k", &opt->dialogOptionFlags) )
return 0;
} else if( strcmp(keystr, "location") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetPoint, &opt->location) )
return 0;
} else if( strcmp(keystr, "clientName") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->clientName) )
return 0;
} else if( strcmp(keystr, "windowTitle") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->windowTitle) )
return 0;
} else if( strcmp(keystr, "actionButtonLabel") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->actionButtonLabel) )
return 0;
} else if( strcmp(keystr, "cancelButtonLabel") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->cancelButtonLabel) )
return 0;
} else if( strcmp(keystr, "savedFileName") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->savedFileName) )
return 0;
} else if( strcmp(keystr, "message") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->message) )
return 0;
} else if( strcmp(keystr, "preferenceKey") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, &opt->preferenceKey) )
return 0;
} else if( strcmp(keystr, "popupExtension") == 0 ) {
if ( !PyArg_Parse(value, "O&", ResObj_Convert, &opt->popupExtension) )
return 0;
} else if( eventProcP && strcmp(keystr, "eventProc") == 0 ) {
*eventProcP = my_eventProcUPP;
} else if( previewProcP && strcmp(keystr, "previewProc") == 0 ) {
*previewProcP = my_previewProcUPP;
} else if( filterProcP && strcmp(keystr, "filterProc") == 0 ) {
*filterProcP = my_filterProcUPP;
} else if( typeListP && strcmp(keystr, "typeList") == 0 ) {
if ( !PyArg_Parse(value, "O&", ResObj_Convert, typeListP) )
return 0;
} else if( fileTypeP && strcmp(keystr, "fileType") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, fileTypeP) )
return 0;
} else if( fileCreatorP && strcmp(keystr, "fileCreator") == 0 ) {
if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, fileCreatorP) )
return 0;
} else {
PyErr_Format(ErrorObject, "Unknown DialogOption key: %s", keystr);
return 0;
}
}
return 1;
} | /* ----------------------------------------------------- */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/Nav.c#L125-L213 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | initNav | void
initNav(void)
{
#ifdef __LP64__
PyErr_SetString(PyExc_ImportError, "Navigation Services not available in 64-bit mode");
return;
#else /* !__LP64__ */
PyObject *m, *d;
if (PyErr_WarnPy3k("In 3.x, the Nav module is removed.", 1))
return;
/* Test that we have NavServices */
if ( !NavServicesAvailable() ) {
PyErr_SetString(PyExc_ImportError, "Navigation Services not available");
return;
}
/* Create the module and add the functions */
m = Py_InitModule4("Nav", nav_methods,
Nav_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("Nav.error");
PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Set UPPs */
my_eventProcUPP = NewNavEventUPP(my_eventProc);
my_previewProcUPP = NewNavPreviewUPP(my_previewProc);
my_filterProcUPP = NewNavObjectFilterUPP(my_filterProc);
#endif /* !__LP64__ */
} | /* !__LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/Nav.c#L930-L966 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_App | void init_App(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
#endif /* !__LP64__ */
m = Py_InitModule("_App", App_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
App_Error = PyMac_GetOSErrException();
if (App_Error == NULL ||
PyDict_SetItemString(d, "Error", App_Error) != 0)
return;
ThemeDrawingState_Type.ob_type = &PyType_Type;
if (PyType_Ready(&ThemeDrawingState_Type) < 0) return;
Py_INCREF(&ThemeDrawingState_Type);
PyModule_AddObject(m, "ThemeDrawingState", (PyObject *)&ThemeDrawingState_Type);
/* Backward-compatible name */
Py_INCREF(&ThemeDrawingState_Type);
PyModule_AddObject(m, "ThemeDrawingStateType", (PyObject *)&ThemeDrawingState_Type);
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/app/_Appmodule.c#L1806-L1829 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | EventTypeSpec_Convert | static int
EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
{
if (PyArg_Parse(v, "(O&l)",
PyMac_GetOSType, &(out->eventClass),
&(out->eventKind)))
return 1;
return 0;
} | /********** EventTypeSpec *******/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/carbonevt/_CarbonEvtmodule.c#L30-L38 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | EventHotKeyID_Convert | static int
EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
{
if (PyArg_ParseTuple(v, "ll", &out->signature, &out->id))
return 1;
return 0;
} | /********** end HIPoint *******/
/********** EventHotKeyID *******/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/carbonevt/_CarbonEvtmodule.c#L64-L70 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_CarbonEvt | void init_CarbonEvt(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
#endif /* !__LP64__ */
m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);
#ifndef __LP64__
myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
d = PyModule_GetDict(m);
CarbonEvents_Error = PyMac_GetOSErrException();
if (CarbonEvents_Error == NULL ||
PyDict_SetItemString(d, "Error", CarbonEvents_Error) != 0)
return;
EventRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventRef_Type) < 0) return;
Py_INCREF(&EventRef_Type);
PyModule_AddObject(m, "EventRef", (PyObject *)&EventRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventRef_Type);
PyModule_AddObject(m, "EventRefType", (PyObject *)&EventRef_Type);
EventQueueRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventQueueRef_Type) < 0) return;
Py_INCREF(&EventQueueRef_Type);
PyModule_AddObject(m, "EventQueueRef", (PyObject *)&EventQueueRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventQueueRef_Type);
PyModule_AddObject(m, "EventQueueRefType", (PyObject *)&EventQueueRef_Type);
EventLoopRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventLoopRef_Type) < 0) return;
Py_INCREF(&EventLoopRef_Type);
PyModule_AddObject(m, "EventLoopRef", (PyObject *)&EventLoopRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventLoopRef_Type);
PyModule_AddObject(m, "EventLoopRefType", (PyObject *)&EventLoopRef_Type);
EventLoopTimerRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventLoopTimerRef_Type) < 0) return;
Py_INCREF(&EventLoopTimerRef_Type);
PyModule_AddObject(m, "EventLoopTimerRef", (PyObject *)&EventLoopTimerRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventLoopTimerRef_Type);
PyModule_AddObject(m, "EventLoopTimerRefType", (PyObject *)&EventLoopTimerRef_Type);
EventHandlerRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventHandlerRef_Type) < 0) return;
Py_INCREF(&EventHandlerRef_Type);
PyModule_AddObject(m, "EventHandlerRef", (PyObject *)&EventHandlerRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventHandlerRef_Type);
PyModule_AddObject(m, "EventHandlerRefType", (PyObject *)&EventHandlerRef_Type);
EventHandlerCallRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventHandlerCallRef_Type) < 0) return;
Py_INCREF(&EventHandlerCallRef_Type);
PyModule_AddObject(m, "EventHandlerCallRef", (PyObject *)&EventHandlerCallRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventHandlerCallRef_Type);
PyModule_AddObject(m, "EventHandlerCallRefType", (PyObject *)&EventHandlerCallRef_Type);
EventTargetRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventTargetRef_Type) < 0) return;
Py_INCREF(&EventTargetRef_Type);
PyModule_AddObject(m, "EventTargetRef", (PyObject *)&EventTargetRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventTargetRef_Type);
PyModule_AddObject(m, "EventTargetRefType", (PyObject *)&EventTargetRef_Type);
EventHotKeyRef_Type.ob_type = &PyType_Type;
if (PyType_Ready(&EventHotKeyRef_Type) < 0) return;
Py_INCREF(&EventHotKeyRef_Type);
PyModule_AddObject(m, "EventHotKeyRef", (PyObject *)&EventHotKeyRef_Type);
/* Backward-compatible name */
Py_INCREF(&EventHotKeyRef_Type);
PyModule_AddObject(m, "EventHotKeyRefType", (PyObject *)&EventHotKeyRef_Type);
#endif /* !__LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/carbonevt/_CarbonEvtmodule.c#L2141-L2215 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OptionalCFURLRefObj_Convert | int
OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
{
if ( v == Py_None ) {
p_itself = NULL;
return 1;
}
return CFURLRefObj_Convert(v, p_itself);
} | /* Optional CFURL argument or None (passed as NULL) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/cf/_CFmodule.c#L103-L111 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCF_Python2CF | int
PyCF_Python2CF(PyObject *src, CFTypeRef *dst) {
if (PyString_Check(src) || PyUnicode_Check(src))
return PyCF_Python2CF_simple(src, dst);
if (PySequence_Check(src))
return PyCF_Python2CF_sequence(src, (CFArrayRef *)dst);
if (PyMapping_Check(src))
return PyCF_Python2CF_mapping(src, (CFDictionaryRef *)dst);
return PyCF_Python2CF_simple(src, dst);
} | /* ---------------------------------------- */
/* Python objects to CoreFoundation objects */
/* ---------------------------------------- */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/cf/pycfbridge.c#L146-L156 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | DataBrowserTableViewColumnDesc_Convert | static int
DataBrowserTableViewColumnDesc_Convert(PyObject *v, DataBrowserTableViewColumnDesc *itself)
{
return PyArg_Parse(v, "(lO&l)",
&itself->propertyID,
PyMac_GetOSType, &itself->propertyType,
&itself->propertyFlags);
} | /*
** generate DataBrowserListViewColumnDesc records
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/ctl/_Ctlmodule.c#L78-L85 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Ctl | void init_Ctl(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
mytracker_upp = NewControlActionUPP(mytracker);
myactionproc_upp = NewControlActionUPP(myactionproc);
mykeydownproc_upp = NewControlUserPaneKeyDownUPP(mykeydownproc);
myfocusproc_upp = NewControlUserPaneFocusUPP(myfocusproc);
mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc);
myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc);
myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc);
mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
#endif /* !__LP64__ */
m = Py_InitModule("_Ctl", Ctl_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Ctl_Error = PyMac_GetOSErrException();
if (Ctl_Error == NULL ||
PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
return;
Control_Type.ob_type = &PyType_Type;
if (PyType_Ready(&Control_Type) < 0) return;
Py_INCREF(&Control_Type);
PyModule_AddObject(m, "Control", (PyObject *)&Control_Type);
/* Backward-compatible name */
Py_INCREF(&Control_Type);
PyModule_AddObject(m, "ControlType", (PyObject *)&Control_Type);
#endif /* !__LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/ctl/_Ctlmodule.c#L5777-L5812 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Dlg | void init_Dlg(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New);
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert);
#endif /* !__LP64__ */
m = Py_InitModule("_Dlg", Dlg_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Dlg_Error = PyMac_GetOSErrException();
if (Dlg_Error == NULL ||
PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
return;
Dialog_Type.ob_type = &PyType_Type;
if (PyType_Ready(&Dialog_Type) < 0) return;
Py_INCREF(&Dialog_Type);
PyModule_AddObject(m, "Dialog", (PyObject *)&Dialog_Type);
/* Backward-compatible name */
Py_INCREF(&Dialog_Type);
PyModule_AddObject(m, "DialogType", (PyObject *)&Dialog_Type);
#endif /* !__LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/dlg/_Dlgmodule.c#L1577-L1606 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Drag | void init_Drag(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
#endif /* !__LP64__ */
m = Py_InitModule("_Drag", Drag_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Drag_Error = PyMac_GetOSErrException();
if (Drag_Error == NULL ||
PyDict_SetItemString(d, "Error", Drag_Error) != 0)
return;
DragObj_Type.ob_type = &PyType_Type;
if (PyType_Ready(&DragObj_Type) < 0) return;
Py_INCREF(&DragObj_Type);
PyModule_AddObject(m, "DragObj", (PyObject *)&DragObj_Type);
/* Backward-compatible name */
Py_INCREF(&DragObj_Type);
PyModule_AddObject(m, "DragObjType", (PyObject *)&DragObj_Type);
dragglue_TrackingHandlerUPP = NewDragTrackingHandlerUPP(dragglue_TrackingHandler);
dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerUPP(dragglue_ReceiveHandler);
dragglue_SendDataUPP = NewDragSendDataUPP(dragglue_SendData);
#if 0
dragglue_InputUPP = NewDragInputUPP(dragglue_Input);
dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
#endif
#endif /* !__LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/drag/_Dragmodule.c#L1117-L1155 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Evt | void init_Evt(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
#endif /* __LP64__ */
m = Py_InitModule("_Evt", Evt_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Evt_Error = PyMac_GetOSErrException();
if (Evt_Error == NULL ||
PyDict_SetItemString(d, "Error", Evt_Error) != 0)
return;
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/evt/_Evtmodule.c#L538-L556 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | UTCDateTime_Convert | static int
UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr)
{
return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction);
} | /*
** UTCDateTime records
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/file/_Filemodule.c#L69-L73 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | myPyMac_GetOptFSRefPtr | static int
myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
{
if (v == Py_None) {
*ref = NULL;
return 1;
}
return PyMac_GetFSRef(v, *ref);
} | /* !__LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/file/_Filemodule.c#L96-L104 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyMac_GetFSRef | int
PyMac_GetFSRef(PyObject *v, FSRef *fsr)
{
OSStatus err;
#ifndef __LP64__
FSSpec fss;
#endif /* !__LP64__ */
if (FSRef_Check(v)) {
*fsr = ((FSRefObject *)v)->ob_itself;
return 1;
}
/* On OSX we now try a pathname */
if ( PyString_Check(v) || PyUnicode_Check(v)) {
char *path = NULL;
if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
return 0;
if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
PyMac_Error(err);
PyMem_Free(path);
return !err;
}
/* XXXX Should try unicode here too */
#ifndef __LP64__
/* Otherwise we try to go via an FSSpec */
if (FSSpec_Check(v)) {
fss = ((FSSpecObject *)v)->ob_itself;
if ((err=FSpMakeFSRef(&fss, fsr)) == 0)
return 1;
PyMac_Error(err);
return 0;
}
#endif /* !__LP64__ */
PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
return 0;
} | /* !__LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/file/_Filemodule.c#L3290-L3328 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | FMRec_Convert | static int
FMRec_Convert(PyObject *v, FMetricRec *p_itself)
{
return PyArg_ParseTuple(v, "O&O&O&O&O&",
PyMac_GetFixed, &itself->ascent,
PyMac_GetFixed, &itself->descent,
PyMac_GetFixed, &itself->leading,
PyMac_GetFixed, &itself->widMax,
ResObj_Convert, &itself->wTabHandle);
} | /* Not needed... */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/fm/_Fmmodule.c#L39-L48 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Fm | void init_Fm(void)
{
PyObject *m;
#if !defined(__LP64__) && !defined(MAC_OS_X_VERSION_10_7)
PyObject *d;
#endif /* __LP64__ */
m = Py_InitModule("_Fm", Fm_methods);
#if !defined(__LP64__) && !defined(MAC_OS_X_VERSION_10_7)
d = PyModule_GetDict(m);
Fm_Error = PyMac_GetOSErrException();
if (Fm_Error == NULL ||
PyDict_SetItemString(d, "Error", Fm_Error) != 0)
return;
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/fm/_Fmmodule.c#L347-L365 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OptCFStringRefObj_Convert | static int
OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
{
if (v == Py_None) {
*spec = NULL;
return 1;
}
return CFStringRefObj_Convert(v, spec);
} | /*
** Optional CFStringRef. None will pass NULL
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/launch/_Launchmodule.c#L27-L35 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_List | void init_List(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
myListDefFunctionUPP = NewListDefUPP((ListDefProcPtr)myListDefFunction);
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
#endif /* __LP64__ */
m = Py_InitModule("_List", List_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
List_Error = PyMac_GetOSErrException();
if (List_Error == NULL ||
PyDict_SetItemString(d, "Error", List_Error) != 0)
return;
List_Type.ob_type = &PyType_Type;
if (PyType_Ready(&List_Type) < 0) return;
Py_INCREF(&List_Type);
PyModule_AddObject(m, "List", (PyObject *)&List_Type);
/* Backward-compatible name */
Py_INCREF(&List_Type);
PyModule_AddObject(m, "ListType", (PyObject *)&List_Type);
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/list/_Listmodule.c#L1106-L1136 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OptMenuObj_Convert | int OptMenuObj_Convert(PyObject *v, MenuRef *p_itself)
{
if ( v == Py_None ) {
*p_itself = NULL;
return 1;
}
return MenuObj_Convert(v, p_itself);
} | /* Alternative version of MenuObj_Convert, which returns NULL for a None argument */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/menu/_Menumodule.c#L46-L53 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OptFSSpecPtr_Convert | static int
OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
{
static FSSpec fss;
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
*p_itself = &fss;
return PyMac_GetFSSpec(v, *p_itself);
} | /*
** Parse an optional fsspec
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/mlte/_Mltemodule.c#L39-L50 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OptGWorldObj_Convert | static int
OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
{
if (v == Py_None)
{
*p_itself = NULL;
return 1;
}
return GWorldObj_Convert(v, p_itself);
} | /*
** Parse an optional GWorld
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/mlte/_Mltemodule.c#L55-L64 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Qd | void init_Qd(void)
{
PyObject *m;
#if !defined(__LP64__) && !defined(MAC_OS_X_VERSION_10_7)
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(BitMapPtr, BMObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BitMapPtr, BMObj_Convert);
PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafPtr, GrafObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafPtr, GrafObj_Convert);
PyMac_INIT_TOOLBOX_OBJECT_NEW(RGBColorPtr, QdRGB_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(RGBColor, QdRGB_Convert);
#endif /* __LP64__ */
m = Py_InitModule("_Qd", Qd_methods);
#if !defined(__LP64__) && !defined(MAC_OS_X_VERSION_10_7)
d = PyModule_GetDict(m);
Qd_Error = PyMac_GetOSErrException();
if (Qd_Error == NULL ||
PyDict_SetItemString(d, "Error", Qd_Error) != 0)
return;
GrafPort_Type.ob_type = &PyType_Type;
if (PyType_Ready(&GrafPort_Type) < 0) return;
Py_INCREF(&GrafPort_Type);
PyModule_AddObject(m, "GrafPort", (PyObject *)&GrafPort_Type);
/* Backward-compatible name */
Py_INCREF(&GrafPort_Type);
PyModule_AddObject(m, "GrafPortType", (PyObject *)&GrafPort_Type);
BitMap_Type.ob_type = &PyType_Type;
if (PyType_Ready(&BitMap_Type) < 0) return;
Py_INCREF(&BitMap_Type);
PyModule_AddObject(m, "BitMap", (PyObject *)&BitMap_Type);
/* Backward-compatible name */
Py_INCREF(&BitMap_Type);
PyModule_AddObject(m, "BitMapType", (PyObject *)&BitMap_Type);
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/qd/_Qdmodule.c#L7112-L7151 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyMac_AutoDisposeHandle | static void
PyMac_AutoDisposeHandle(Handle h)
{
DisposeHandle(h);
} | /* Function to dispose a resource, with a "normal" calling sequence */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/res/_Resmodule.c#L31-L35 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyMac_GetUFixed | static int
PyMac_GetUFixed(PyObject *v, Fixed *f)
{
double d;
unsigned long uns;
if( !PyArg_Parse(v, "d", &d))
return 0;
uns = (unsigned long)(d * 0x10000);
*f = (Fixed)uns;
return 1;
} | /* Convert Python object to unsigned Fixed */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndihooks.c#L53-L64 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SndCmd_Convert | static int
SndCmd_Convert(PyObject *v, SndCommand *pc)
{
int len;
pc->param1 = 0;
pc->param2 = 0;
if (PyTuple_Check(v)) {
if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
return 1;
PyErr_Clear();
return PyArg_ParseTuple(v, "Hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
}
return PyArg_Parse(v, "H", &pc->cmd);
} | /* Convert a SndCommand argument */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndmodule.c#L22-L35 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SndCh_CallCallBack | static int
SndCh_CallCallBack(void *arg)
{
SndChannelObject *p = (SndChannelObject *)arg;
PyObject *args;
PyObject *res;
args = Py_BuildValue("(O(hhl))",
p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
res = PyEval_CallObject(p->ob_callback, args);
Py_DECREF(args);
if (res == NULL)
return -1;
Py_DECREF(res);
return 0;
} | /* Routine passed to Py_AddPendingCall -- call the Python callback */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndmodule.c#L1061-L1075 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SndCh_UserRoutine | static pascal void
SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
{
SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
if (p->ob_callback != NULL) {
long A5 = SetA5(p->ob_A5);
p->ob_cmd = *cmd;
Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
SetA5(A5);
}
} | /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndmodule.c#L1078-L1088 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SPB_CallCallBack | static int
SPB_CallCallBack(void *arg)
{
SPBObject *p = (SPBObject *)arg;
PyObject *args;
PyObject *res;
if ( p->ob_thiscallback == 0 ) return 0;
args = Py_BuildValue("(O)", p);
res = PyEval_CallObject(p->ob_thiscallback, args);
p->ob_thiscallback = 0;
Py_DECREF(args);
if (res == NULL)
return -1;
Py_DECREF(res);
return 0;
} | /* SPB callbacks - Schedule callbacks to Python */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndmodule.c#L1091-L1107 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Snd | void init_Snd(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
#endif /* __LP64__ */
m = Py_InitModule("_Snd", Snd_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Snd_Error = PyMac_GetOSErrException();
if (Snd_Error == NULL ||
PyDict_SetItemString(d, "Error", Snd_Error) != 0)
return;
SndChannel_Type.ob_type = &PyType_Type;
if (PyType_Ready(&SndChannel_Type) < 0) return;
Py_INCREF(&SndChannel_Type);
PyModule_AddObject(m, "SndChannel", (PyObject *)&SndChannel_Type);
/* Backward-compatible name */
Py_INCREF(&SndChannel_Type);
PyModule_AddObject(m, "SndChannelType", (PyObject *)&SndChannel_Type);
SPB_Type.ob_type = &PyType_Type;
if (PyType_Ready(&SPB_Type) < 0) return;
Py_INCREF(&SPB_Type);
#if 0
PyModule_AddObject(m, "SPB", (PyObject *)&SPB_Type);
#endif
/* Backward-compatible name */
Py_INCREF(&SPB_Type);
PyModule_AddObject(m, "SPBType", (PyObject *)&SPB_Type);
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/snd/_Sndmodule.c#L1125-L1160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyMac_AutoDisposeWindow | static void
PyMac_AutoDisposeWindow(WindowPtr w)
{
DisposeWindow(w);
} | /* Function to dispose a window, with a "normal" calling sequence */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/win/_Winmodule.c#L36-L40 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_Win | void init_Win(void)
{
PyObject *m;
#ifndef __LP64__
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
#endif /* __LP64__ */
m = Py_InitModule("_Win", Win_methods);
#ifndef __LP64__
d = PyModule_GetDict(m);
Win_Error = PyMac_GetOSErrException();
if (Win_Error == NULL ||
PyDict_SetItemString(d, "Error", Win_Error) != 0)
return;
Window_Type.ob_type = &PyType_Type;
if (PyType_Ready(&Window_Type) < 0) return;
Py_INCREF(&Window_Type);
PyModule_AddObject(m, "Window", (PyObject *)&Window_Type);
/* Backward-compatible name */
Py_INCREF(&Window_Type);
PyModule_AddObject(m, "WindowType", (PyObject *)&Window_Type);
#endif /* __LP64__ */
} | /* __LP64__ */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Mac/Modules/win/_Winmodule.c#L3235-L3262 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | clean_environ | void
clean_environ(void)
{
char **p;
extern char **environ;
for (p = environ; *p; p++) {
if (strncmp(*p, "LD_", 3) == 0)
**p = 'X';
else if (strncmp(*p, "_RLD", 4) == 0)
**p = 'X';
else if (strncmp(*p, "PYTHON", 6) == 0)
**p = 'X';
else if (strncmp(*p, "IFS=", 4) == 0)
*p = def_IFS;
else if (strncmp(*p, "CDPATH=", 7) == 0)
*p = def_CDPATH;
else if (strncmp(*p, "ENV=", 4) == 0)
*p = def_ENV;
}
putenv(def_PATH);
} | /*
This function changes all environment variables that start with LD_
into variables that start with XD_. This is important since we
don't want the script that is executed to use any funny shared
libraries.
The other changes to the environment are, strictly speaking, not
needed here. They can safely be done in the script. They are done
here because we don't trust the script writer (just like the script
writer shouldn't trust the user of the script).
If IFS is set in the environment, set it to space,tab,newline.
If CDPATH is set in the environment, set it to ``.''.
Set PATH to a reasonable default.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Misc/setuid-prog.c#L101-L122 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _DB_get_type | static int _DB_get_type(DBObject* self)
{
DBTYPE type;
int err;
err = self->db->get_type(self->db, &type);
if (makeDBError(err)) {
return -1;
}
return type;
} | /* Return the access method type of the DBObject */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L372-L382 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | make_dbt | static int make_dbt(PyObject* obj, DBT* dbt)
{
CLEAR_DBT(*dbt);
if (obj == Py_None) {
/* no need to do anything, the structure has already been zeroed */
}
else if (!PyArg_Parse(obj, "s#", &dbt->data, &dbt->size)) {
PyErr_SetString(PyExc_TypeError,
#if (PY_VERSION_HEX < 0x03000000)
"Data values must be of type string or None.");
#else
"Data values must be of type bytes or None.");
#endif
return 0;
}
return 1;
} | /* Create a DBT structure (containing key and data values) from Python
strings. Returns 1 on success, 0 on an error. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L387-L403 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | make_key_dbt | static int
make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags)
{
db_recno_t recno;
int type;
CLEAR_DBT(*key);
if (keyobj == Py_None) {
type = _DB_get_type(self);
if (type == -1)
return 0;
if (type == DB_RECNO || type == DB_QUEUE) {
PyErr_SetString(
PyExc_TypeError,
"None keys not allowed for Recno and Queue DB's");
return 0;
}
/* no need to do anything, the structure has already been zeroed */
}
else if (PyBytes_Check(keyobj)) {
/* verify access method type */
type = _DB_get_type(self);
if (type == -1)
return 0;
if (type == DB_RECNO || type == DB_QUEUE) {
PyErr_SetString(
PyExc_TypeError,
#if (PY_VERSION_HEX < 0x03000000)
"String keys not allowed for Recno and Queue DB's");
#else
"Bytes keys not allowed for Recno and Queue DB's");
#endif
return 0;
}
/*
* NOTE(gps): I don't like doing a data copy here, it seems
* wasteful. But without a clean way to tell FREE_DBT if it
* should free key->data or not we have to. Other places in
* the code check for DB_THREAD and forceably set DBT_MALLOC
* when we otherwise would leave flags 0 to indicate that.
*/
key->data = malloc(PyBytes_GET_SIZE(keyobj));
if (key->data == NULL) {
PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
return 0;
}
memcpy(key->data, PyBytes_AS_STRING(keyobj),
PyBytes_GET_SIZE(keyobj));
key->flags = DB_DBT_REALLOC;
key->size = PyBytes_GET_SIZE(keyobj);
}
else if (NUMBER_Check(keyobj)) {
/* verify access method type */
type = _DB_get_type(self);
if (type == -1)
return 0;
if (type == DB_BTREE && pflags != NULL) {
/* if BTREE then an Integer key is allowed with the
* DB_SET_RECNO flag */
*pflags |= DB_SET_RECNO;
}
else if (type != DB_RECNO && type != DB_QUEUE) {
PyErr_SetString(
PyExc_TypeError,
"Integer keys only allowed for Recno and Queue DB's");
return 0;
}
/* Make a key out of the requested recno, use allocated space so DB
* will be able to realloc room for the real key if needed. */
recno = NUMBER_AsLong(keyobj);
key->data = malloc(sizeof(db_recno_t));
if (key->data == NULL) {
PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
return 0;
}
key->ulen = key->size = sizeof(db_recno_t);
memcpy(key->data, &recno, sizeof(db_recno_t));
key->flags = DB_DBT_REALLOC;
}
else {
PyErr_Format(PyExc_TypeError,
#if (PY_VERSION_HEX < 0x03000000)
"String or Integer object expected for key, %s found",
#else
"Bytes or Integer object expected for key, %s found",
#endif
Py_TYPE(keyobj)->tp_name);
return 0;
}
return 1;
} | /* Recno and Queue DBs can have integer keys. This function figures out
what's been given, verifies that it's allowed, and then makes the DBT.
Caller MUST call FREE_DBT(key) when done. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L410-L505 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_partial_dbt | static int add_partial_dbt(DBT* d, int dlen, int doff) {
/* if neither were set we do nothing (-1 is the default value) */
if ((dlen == -1) && (doff == -1)) {
return 1;
}
if ((dlen < 0) || (doff < 0)) {
PyErr_SetString(PyExc_TypeError, "dlen and doff must both be >= 0");
return 0;
}
d->flags = d->flags | DB_DBT_PARTIAL;
d->dlen = (unsigned int) dlen;
d->doff = (unsigned int) doff;
return 1;
} | /* Add partial record access to an existing DBT data struct.
If dlen and doff are set, then the DB_DBT_PARTIAL flag will be set
and the data storage/retrieval will be done using dlen and doff. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L511-L526 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | our_strlcpy | unsigned int our_strlcpy(char* dest, const char* src, unsigned int n)
{
unsigned int srclen, copylen;
srclen = strlen(src);
if (n <= 0)
return srclen;
copylen = (srclen > n-1) ? n-1 : srclen;
/* populate dest[0] thru dest[copylen-1] */
memcpy(dest, src, copylen);
/* guarantee null termination */
dest[copylen] = 0;
return srclen;
} | /* a safe strcpy() without the zeroing behaviour and semantics of strncpy. */
/* TODO: make this use the native libc strlcpy() when available (BSD) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L530-L544 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | makeDBError | static int makeDBError(int err)
{
char errTxt[2048]; /* really big, just in case... */
PyObject *errObj = NULL;
PyObject *errTuple = NULL;
int exceptionRaised = 0;
unsigned int bytes_left;
switch (err) {
case 0: /* successful, no error */
return 0;
case DB_KEYEMPTY: errObj = DBKeyEmptyError; break;
case DB_KEYEXIST: errObj = DBKeyExistError; break;
case DB_LOCK_DEADLOCK: errObj = DBLockDeadlockError; break;
case DB_LOCK_NOTGRANTED: errObj = DBLockNotGrantedError; break;
case DB_NOTFOUND: errObj = DBNotFoundError; break;
case DB_OLD_VERSION: errObj = DBOldVersionError; break;
case DB_RUNRECOVERY: errObj = DBRunRecoveryError; break;
case DB_VERIFY_BAD: errObj = DBVerifyBadError; break;
case DB_NOSERVER: errObj = DBNoServerError; break;
#if (DBVER < 52)
case DB_NOSERVER_HOME: errObj = DBNoServerHomeError; break;
case DB_NOSERVER_ID: errObj = DBNoServerIDError; break;
#endif
case DB_PAGE_NOTFOUND: errObj = DBPageNotFoundError; break;
case DB_SECONDARY_BAD: errObj = DBSecondaryBadError; break;
case DB_BUFFER_SMALL: errObj = DBNoMemoryError; break;
case ENOMEM: errObj = PyExc_MemoryError; break;
case EINVAL: errObj = DBInvalidArgError; break;
case EACCES: errObj = DBAccessError; break;
case ENOSPC: errObj = DBNoSpaceError; break;
case EAGAIN: errObj = DBAgainError; break;
case EBUSY : errObj = DBBusyError; break;
case EEXIST: errObj = DBFileExistsError; break;
case ENOENT: errObj = DBNoSuchFileError; break;
case EPERM : errObj = DBPermissionsError; break;
case DB_REP_HANDLE_DEAD : errObj = DBRepHandleDeadError; break;
#if (DBVER >= 44)
case DB_REP_LOCKOUT : errObj = DBRepLockoutError; break;
#endif
#if (DBVER >= 46)
case DB_REP_LEASE_EXPIRED : errObj = DBRepLeaseExpiredError; break;
#endif
#if (DBVER >= 47)
case DB_FOREIGN_CONFLICT : errObj = DBForeignConflictError; break;
#endif
case DB_REP_UNAVAIL : errObj = DBRepUnavailError; break;
default: errObj = DBError; break;
}
if (errObj != NULL) {
bytes_left = our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt));
/* Ensure that bytes_left never goes negative */
if (_db_errmsg[0] && bytes_left < (sizeof(errTxt) - 4)) {
bytes_left = sizeof(errTxt) - bytes_left - 4 - 1;
assert(bytes_left >= 0);
strcat(errTxt, " -- ");
strncat(errTxt, _db_errmsg, bytes_left);
}
_db_errmsg[0] = 0;
errTuple = Py_BuildValue("(is)", err, errTxt);
if (errTuple == NULL) {
Py_DECREF(errObj);
return !0;
}
PyErr_SetObject(errObj, errTuple);
Py_DECREF(errTuple);
}
return ((errObj != NULL) || exceptionRaised);
} | /* make a nice exception object to raise for errors. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L649-L727 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | makeTypeError | static void makeTypeError(char* expected, PyObject* found)
{
PyErr_Format(PyExc_TypeError, "Expected %s argument, %s found.",
expected, Py_TYPE(found)->tp_name);
} | /* set a type exception */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L732-L736 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | checkTxnObj | static int checkTxnObj(PyObject* txnobj, DB_TXN** txn)
{
if (txnobj == Py_None || txnobj == NULL) {
*txn = NULL;
return 1;
}
if (DBTxnObject_Check(txnobj)) {
*txn = ((DBTxnObject*)txnobj)->txn;
return 1;
}
else
makeTypeError("DBTxn", txnobj);
return 0;
} | /* verify that an obj is either None or a DBTxn, and set the txn pointer */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L740-L753 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _DB_delete | static int _DB_delete(DBObject* self, DB_TXN *txn, DBT *key, int flags)
{
int err;
MYDB_BEGIN_ALLOW_THREADS;
err = self->db->del(self->db, txn, key, 0);
MYDB_END_ALLOW_THREADS;
if (makeDBError(err)) {
return -1;
}
return 0;
} | /* Delete a key from a database
Returns 0 on success, -1 on an error. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L758-L769 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _DB_put | static int _DB_put(DBObject* self, DB_TXN *txn, DBT *key, DBT *data, int flags)
{
int err;
MYDB_BEGIN_ALLOW_THREADS;
err = self->db->put(self->db, txn, key, data, flags);
MYDB_END_ALLOW_THREADS;
if (makeDBError(err)) {
return -1;
}
return 0;
} | /* Store a key into a database
Returns 0 on success, -1 on an error. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L774-L785 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _addIntToDict | static void _addIntToDict(PyObject* dict, char *name, int value)
{
PyObject* v = NUMBER_FromLong((long) value);
if (!v || PyDict_SetItemString(dict, name, v))
PyErr_Clear();
Py_XDECREF(v);
} | /* add an integer to a dictionary using the given name as a key */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L847-L854 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _addTimeTToDict | static void _addTimeTToDict(PyObject* dict, char *name, time_t value)
{
PyObject* v;
/* if the value fits in regular int, use that. */
#ifdef PY_LONG_LONG
if (sizeof(time_t) > sizeof(long))
v = PyLong_FromLongLong((PY_LONG_LONG) value);
else
#endif
v = NUMBER_FromLong((long) value);
if (!v || PyDict_SetItemString(dict, name, v))
PyErr_Clear();
Py_XDECREF(v);
} | /* The same, when the value is a time_t */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L857-L871 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _addDb_seq_tToDict | static void _addDb_seq_tToDict(PyObject* dict, char *name, db_seq_t value)
{
PyObject* v = PyLong_FromLongLong(value);
if (!v || PyDict_SetItemString(dict, name, v))
PyErr_Clear();
Py_XDECREF(v);
} | /* add an db_seq_t to a dictionary using the given name as a key */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L874-L881 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | DB_length | Py_ssize_t DB_length(PyObject* _self)
{
int err;
Py_ssize_t size = 0;
void* sp;
DBObject* self = (DBObject*)_self;
if (self->db == NULL) {
PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed");
if (t) {
PyErr_SetObject(DBError, t);
Py_DECREF(t);
}
return -1;
}
MYDB_BEGIN_ALLOW_THREADS;
err = self->db->stat(self->db, /*txnid*/ NULL, &sp, 0);
MYDB_END_ALLOW_THREADS;
/* All the stat structures have matching fields upto the ndata field,
so we can use any of them for the type cast */
size = ((DB_BTREE_STAT*)sp)->bt_ndata;
if (err)
return -1;
free(sp);
return size;
} | /*-------------------------------------------------------------- */
/* Mapping and Dictionary-like access routines */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L3535-L3564 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _close_transaction_cursors | static void _close_transaction_cursors(DBTxnObject* txn)
{
PyObject *dummy;
while(txn->children_cursors) {
PyErr_Warn(PyExc_RuntimeWarning,
"Must close cursors before resolving a transaction.");
dummy=DBC_close_internal(txn->children_cursors);
Py_XDECREF(dummy);
}
} | /* --------------------------------------------------------------------- */
/* DBTxn methods */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_bsddb.c#L8072-L8082 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | deque_del_item | static int
deque_del_item(dequeobject *deque, Py_ssize_t i)
{
PyObject *item;
assert (i >= 0 && i < deque->len);
if (_deque_rotate(deque, -i) == -1)
return -1;
item = deque_popleft(deque, NULL);
assert (item != NULL);
Py_DECREF(item);
return _deque_rotate(deque, i);
} | /* delitem() implemented in terms of rotate for simplicity and reasonable
performance near the end points. If for some reason this method becomes
popular, it is not hard to re-implement this using direct data movement
(similar to code in list slice assignment) and achieve a two or threefold
performance boost.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_collectionsmodule.c#L705-L719 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_save_field | static int
parse_save_field(ReaderObj *self)
{
PyObject *field;
field = PyString_FromStringAndSize(self->field, self->field_len);
if (field == NULL)
return -1;
self->field_len = 0;
if (self->numeric_field) {
PyObject *tmp;
self->numeric_field = 0;
tmp = PyNumber_Float(field);
if (tmp == NULL) {
Py_DECREF(field);
return -1;
}
Py_DECREF(field);
field = tmp;
}
PyList_Append(self->fields, field);
Py_DECREF(field);
return 0;
} | /*
* READER
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_csv.c#L536-L560 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | join_reset | static void
join_reset(WriterObj *self)
{
self->rec_len = 0;
self->num_fields = 0;
} | /*
* WRITER
*/
/* ---------------------------------------------------------------- */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_csv.c#L970-L975 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | join_append_data | static int
join_append_data(WriterObj *self, char *field, int quote_empty,
int *quoted, int copy_phase)
{
DialectObj *dialect = self->dialect;
int i, rec_len;
char *lineterm;
#define ADDCH(c) \
do {\
if (copy_phase) \
self->rec[rec_len] = c;\
rec_len++;\
} while(0)
lineterm = PyString_AsString(dialect->lineterminator);
if (lineterm == NULL)
return -1;
rec_len = self->rec_len;
/* If this is not the first field we need a field separator */
if (self->num_fields > 0)
ADDCH(dialect->delimiter);
/* Handle preceding quote */
if (copy_phase && *quoted)
ADDCH(dialect->quotechar);
/* Copy/count field data */
for (i = 0;; i++) {
char c = field[i];
int want_escape = 0;
if (c == '\0')
break;
if (c == dialect->delimiter ||
c == dialect->escapechar ||
c == dialect->quotechar ||
strchr(lineterm, c)) {
if (dialect->quoting == QUOTE_NONE)
want_escape = 1;
else {
if (c == dialect->quotechar) {
if (dialect->doublequote)
ADDCH(dialect->quotechar);
else
want_escape = 1;
}
if (!want_escape)
*quoted = 1;
}
if (want_escape) {
if (!dialect->escapechar) {
PyErr_Format(error_obj,
"need to escape, but no escapechar set");
return -1;
}
ADDCH(dialect->escapechar);
}
}
/* Copy field character into record buffer.
*/
ADDCH(c);
}
/* If field is empty check if it needs to be quoted.
*/
if (i == 0 && quote_empty) {
if (dialect->quoting == QUOTE_NONE) {
PyErr_Format(error_obj,
"single empty field record must be quoted");
return -1;
}
else
*quoted = 1;
}
if (*quoted) {
if (copy_phase)
ADDCH(dialect->quotechar);
else
rec_len += 2;
}
return rec_len;
#undef ADDCH
} | /* Calculate new record length or append field to record. Return new
* record length.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_csv.c#L982-L1069 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | insert_lop | static int
insert_lop(PyCursesPanelObject *po)
{
list_of_panels *new;
if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) {
PyErr_NoMemory();
return -1;
}
new->po = po;
new->next = lop;
lop = new;
return 0;
} | /* Insert a new panel object into lop */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_curses_panel.c#L87-L100 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | remove_lop | static void
remove_lop(PyCursesPanelObject *po)
{
list_of_panels *temp, *n;
temp = lop;
if (temp->po == po) {
lop = temp->next;
free(temp);
return;
}
while (temp->next == NULL || temp->next->po != po) {
if (temp->next == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"remove_lop: can't find Panel Object");
return;
}
temp = temp->next;
}
n = temp->next->next;
free(temp->next);
temp->next = n;
return;
} | /* Remove the panel object from lop */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_curses_panel.c#L103-L126 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | Panel_NoArgNoReturnFunction | Panel_NoArgNoReturnFunction(bottom_panel)
Panel_NoArgNoReturnFunction(hide_panel)
Panel_NoArgNoReturnFunction(show_panel)
Panel_NoArgNoReturnFunction(top_panel)
Panel_NoArgTrueFalseFunction(panel_hidden)
Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x")
/* Allocation and deallocation of Panel Objects */
static PyObject *
PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
{
PyCursesPanelObject *po;
po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type);
if (po == NULL) return NULL;
po->pan = pan;
if (insert_lop(po) < 0) {
po->wo = NULL;
Py_DECREF(po);
return NULL;
}
po->wo = wo;
Py_INCREF(wo);
return (PyObject *)po;
} | /* ------------- PANEL routines --------------- */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_curses_panel.c#L164-L189 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_curses_panel | PyMODINIT_FUNC
init_curses_panel(void)
{
PyObject *m, *d, *v;
/* Initialize object type */
Py_TYPE(&PyCursesPanel_Type) = &PyType_Type;
import_curses();
/* Create the module and add the functions */
m = Py_InitModule("_curses_panel", PyCurses_methods);
if (m == NULL)
return;
d = PyModule_GetDict(m);
/* For exception _curses_panel.error */
PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */
v = PyString_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
} | /* Initialization function for the module */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_curses_panel.c#L466-L491 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | func_PyCursesSetupTermCalled | static int func_PyCursesSetupTermCalled(void)
{
PyCursesSetupTermCalled;
return 1;
} | /* Function versions of the 3 functions for testing whether curses has been
initialised or not. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_cursesmodule.c#L211-L215 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | expat_default_handler | static void
expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
int data_len)
{
PyObject* key;
PyObject* value;
PyObject* res;
if (data_len < 2 || data_in[0] != '&')
return;
key = makestring(data_in + 1, data_len - 2);
if (!key)
return;
value = PyDict_GetItem(self->entity, key);
if (value) {
if (TreeBuilder_CheckExact(self->target))
res = treebuilder_handle_data(
(TreeBuilderObject*) self->target, value
);
else if (self->handle_data)
res = PyObject_CallFunction(self->handle_data, "O", value);
else
res = NULL;
Py_XDECREF(res);
} else if (!PyErr_Occurred()) {
/* Report the first error, not the last */
char message[128];
sprintf(message, "undefined entity &%.100s;", PyString_AS_STRING(key));
expat_set_error(
message,
EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser)
);
}
Py_DECREF(key);
} | /* -------------------------------------------------------------------- */
/* handlers */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_elementtree.c#L2183-L2222 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | expat_parse | LOCAL(PyObject*)
expat_parse(XMLParserObject* self, char* data, int data_len, int final)
{
int ok;
ok = EXPAT(Parse)(self->parser, data, data_len, final);
if (PyErr_Occurred())
return NULL;
if (!ok) {
expat_set_error(
EXPAT(ErrorString)(EXPAT(GetErrorCode)(self->parser)),
EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser)
);
return NULL;
}
Py_RETURN_NONE;
} | /* -------------------------------------------------------------------- */
/* methods (in alphabetical order) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_elementtree.c#L2595-L2615 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | EVP_dealloc | static void
EVP_dealloc(EVPobject *self)
{
#ifdef WITH_THREAD
if (self->lock != NULL)
PyThread_free_lock(self->lock);
#endif
EVP_MD_CTX_cleanup(&self->ctx);
Py_XDECREF(self->name);
PyObject_Del(self);
} | /* Internal methods for a hash object */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hashopenssl.c#L120-L130 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | unpack_packed_int | static int
unpack_packed_int(LogReaderObject *self, int *pvalue, int discard)
{
int c;
int accum = 0;
int bits = 0;
int cont;
do {
/* read byte */
if ((c = fgetc(self->logfp)) == EOF)
return ERR_EOF;
accum |= ((c & 0x7F) >> discard) << bits;
bits += (7 - discard);
cont = c & 0x80;
discard = 0;
} while (cont);
*pvalue = accum;
return 0;
} | /* Unpack a packed integer; if "discard" is non-zero, unpack a modified
* packed integer with "discard" discarded bits.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L277-L298 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | unpack_string | static int
unpack_string(LogReaderObject *self, PyObject **pvalue)
{
int i;
int len;
int err;
int ch;
char *buf;
if ((err = unpack_packed_int(self, &len, 0)))
return err;
buf = (char *)malloc(len);
if (!buf) {
PyErr_NoMemory();
return ERR_EXCEPTION;
}
for (i=0; i < len; i++) {
ch = fgetc(self->logfp);
buf[i] = ch;
if (ch == EOF) {
free(buf);
return ERR_EOF;
}
}
*pvalue = PyString_FromStringAndSize(buf, len);
free(buf);
if (*pvalue == NULL) {
return ERR_EXCEPTION;
}
return 0;
} | /* Unpack a string, which is encoded as a packed integer giving the
* length of the string, followed by the string data.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L303-L335 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pack_modified_packed_int | static inline int
pack_modified_packed_int(ProfilerObject *self, int value,
int modsize, int subfield)
{
const int maxvalues[] = {-1, 1, 3, 7, 15, 31, 63, 127};
int bits = 7 - modsize;
int partial = value & maxvalues[bits];
unsigned char b = subfield | (partial << modsize);
if (partial != value) {
b |= 0x80;
self->buffer[self->index] = b;
self->index++;
return pack_packed_int(self, value >> bits);
}
self->buffer[self->index] = b;
self->index++;
return 0;
} | /* Encode a modified packed integer, with a subfield of modsize bits
* containing the value "subfield". The value of subfield is not
* checked to ensure it actually fits in modsize bits.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L602-L621 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tracer_callback | static int
tracer_callback(ProfilerObject *self, PyFrameObject *frame, int what,
PyObject *arg)
{
int fileno;
switch (what) {
case PyTrace_CALL:
fileno = get_fileno(self, frame->f_code);
if (fileno < 0)
return -1;
return pack_enter(self, fileno,
self->frametimings ? get_tdelta(self) : -1,
frame->f_code->co_firstlineno);
case PyTrace_RETURN:
return pack_exit(self, get_tdelta(self));
case PyTrace_LINE: /* we only get these events if we asked for them */
if (self->linetimings)
return pack_lineno_tdelta(self, frame->f_lineno,
get_tdelta(self));
else
return pack_lineno(self, frame->f_lineno);
default:
/* ignore PyTrace_EXCEPTION */
break;
}
return 0;
} | /* The workhorse: the profiler callback function. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L858-L888 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | profiler_dealloc | static void
profiler_dealloc(ProfilerObject *self)
{
do_stop(self);
if (self->logfp != NULL)
fclose(self->logfp);
Py_XDECREF(self->filemap);
Py_XDECREF(self->logfilename);
PyObject_Del((PyObject *)self);
} | /* Python API support. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L1159-L1168 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | write_header | static int
write_header(ProfilerObject *self)
{
char *buffer;
char cwdbuffer[PATH_MAX];
PyObject *temp;
Py_ssize_t i, len;
buffer = get_version_string();
if (buffer == NULL) {
PyErr_NoMemory();
return -1;
}
pack_add_info(self, "hotshot-version", buffer);
pack_add_info(self, "requested-frame-timings",
(self->frametimings ? "yes" : "no"));
pack_add_info(self, "requested-line-events",
(self->lineevents ? "yes" : "no"));
pack_add_info(self, "requested-line-timings",
(self->linetimings ? "yes" : "no"));
pack_add_info(self, "platform", Py_GetPlatform());
pack_add_info(self, "executable", Py_GetProgramFullPath());
free(buffer);
buffer = (char *) Py_GetVersion();
if (buffer == NULL)
PyErr_Clear();
else
pack_add_info(self, "executable-version", buffer);
#ifdef MS_WINDOWS
PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%I64d", frequency.QuadPart);
pack_add_info(self, "reported-performance-frequency", cwdbuffer);
#else
PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", rusage_diff);
pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", timeofday_diff);
pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
#endif
pack_add_info(self, "current-directory",
getcwd(cwdbuffer, sizeof cwdbuffer));
temp = PySys_GetObject("path");
if (temp == NULL || !PyList_Check(temp)) {
PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list");
return -1;
}
len = PyList_GET_SIZE(temp);
for (i = 0; i < len; ++i) {
PyObject *item = PyList_GET_ITEM(temp, i);
buffer = PyString_AsString(item);
if (buffer == NULL) {
pack_add_info(self, "sys-path-entry", "<non-string-path-entry>");
PyErr_Clear();
}
else {
pack_add_info(self, "sys-path-entry", buffer);
}
}
pack_frame_times(self);
pack_line_times(self);
return 0;
} | /* Write out a RFC 822-style header with various useful bits of
* information to make the output easier to manage.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_hotshot.c#L1422-L1485 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _Py_acosh | double
_Py_acosh(double x)
{
if (Py_IS_NAN(x)) {
return x+x;
}
if (x < 1.) { /* x < 1; return a signaling NaN */
errno = EDOM;
#ifdef Py_NAN
return Py_NAN;
#else
return (x-x)/(x-x);
#endif
}
else if (x >= two_pow_p28) { /* x > 2**28 */
if (Py_IS_INFINITY(x)) {
return x+x;
}
else {
return log(x)+ln2; /* acosh(huge)=log(2x) */
}
}
else if (x == 1.) {
return 0.0; /* acosh(1) = 0 */
}
else if (x > 2.) { /* 2 < x < 2**28 */
double t = x*x;
return log(2.0*x - 1.0 / (x + sqrt(t - 1.0)));
}
else { /* 1 < x <= 2 */
double t = x - 1.0;
return m_log1p(t + sqrt(2.0*t + t*t));
}
} | /* acosh(x)
* Method :
* Based on
* acosh(x) = log [ x + sqrt(x*x-1) ]
* we have
* acosh(x) := log(x)+ln2, if x is large; else
* acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
* acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
*
* Special cases:
* acosh(x) is NaN with signal if x<1.
* acosh(NaN) is NaN without signal.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_math.c#L41-L74 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _Py_asinh | double
_Py_asinh(double x)
{
double w;
double absx = fabs(x);
if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) {
return x+x;
}
if (absx < two_pow_m28) { /* |x| < 2**-28 */
return x; /* return x inexact except 0 */
}
if (absx > two_pow_p28) { /* |x| > 2**28 */
w = log(absx)+ln2;
}
else if (absx > 2.0) { /* 2 < |x| < 2**28 */
w = log(2.0*absx + 1.0 / (sqrt(x*x + 1.0) + absx));
}
else { /* 2**-28 <= |x| < 2= */
double t = x*x;
w = m_log1p(absx + t / (1.0 + sqrt(1.0 + t)));
}
return copysign(w, x);
} | /* asinh(x)
* Method :
* Based on
* asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
* we have
* asinh(x) := x if 1+x*x=1,
* := sign(x)*(log(x)+ln2)) for large |x|, else
* := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
* := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_math.c#L88-L112 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _Py_atanh | double
_Py_atanh(double x)
{
double absx;
double t;
if (Py_IS_NAN(x)) {
return x+x;
}
absx = fabs(x);
if (absx >= 1.) { /* |x| >= 1 */
errno = EDOM;
#ifdef Py_NAN
return Py_NAN;
#else
return x/zero;
#endif
}
if (absx < two_pow_m28) { /* |x| < 2**-28 */
return x;
}
if (absx < 0.5) { /* |x| < 0.5 */
t = absx+absx;
t = 0.5 * m_log1p(t + t*absx / (1.0 - absx));
}
else { /* 0.5 <= |x| <= 1.0 */
t = 0.5 * m_log1p((absx + absx) / (1.0 - absx));
}
return copysign(t, x);
} | /* atanh(x)
* Method :
* 1.Reduced x to positive by atanh(-x) = -atanh(x)
* 2.For x>=0.5
* 1 2x x
* atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * -------)
* 2 1 - x 1 - x
*
* For x<0.5
* atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
*
* Special cases:
* atanh(x) is NaN if |x| >= 1 with signal;
* atanh(NaN) is that NaN with no signal;
*
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_math.c#L131-L160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _Py_expm1 | double
_Py_expm1(double x)
{
/* For abs(x) >= log(2), it's safe to evaluate exp(x) - 1 directly; this
also works fine for infinities and nans.
For smaller x, we can use a method due to Kahan that achieves close to
full accuracy.
*/
if (fabs(x) < 0.7) {
double u;
u = exp(x);
if (u == 1.0)
return x;
else
return (u - 1.0) * x / log(u);
}
else
return exp(x) - 1.0;
} | /* Mathematically, expm1(x) = exp(x) - 1. The expm1 function is designed
to avoid the significant loss of precision that arises from direct
evaluation of the expression exp(x) - 1, for x near 0. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_math.c#L166-L186 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | genrand_int32 | static unsigned long
genrand_int32(RandomObject *self)
{
unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
unsigned long *mt;
mt = self->state;
if (self->index >= N) { /* generate N words at one time */
int kk;
for (kk=0;kk<N-M;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
self->index = 0;
}
y = mt[self->index++];
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
} | /* Random methods */
/* generates a random number on [0,0xffffffff]-interval */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_randommodule.c#L94-L126 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_genrand | static void
init_genrand(RandomObject *self, unsigned long s)
{
int mti;
unsigned long *mt;
mt = self->state;
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
self->index = mti;
return;
} | /* initializes mt[N] with a seed */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_randommodule.c#L145-L165 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.