deps/kb_meme/meme-5.0.1/src/html-monolith.c
/*
 * Echo the file to the dest in base64 with the specified mime type.
 */
Echo the file to the dest in base64 with the specified mime type.
Echo the file to the dest in base64 with the specified mime type .
static void base64enc_file(HTMLWR_T* htmlwr, char *mimetype, char *binary_source) {
  char *src_path;
  FILE *src_file;
  int32_t bits24;
  int i, c, pad;
  src_path = make_path_to_file(htmlwr->search_dir, binary_source);
  src_file = fopen(src_path, "r");
  if (src_file) {
    fprintf(htmlwr->dest, "data:%s;base64,", mimetype);
    while (!feof(src_file) && !ferror(src_file)) {
      bits24 = 0;
      pad = 0;
      for (i = 0; i < 3; i++) {
        c = fgetc(src_file);
        if (c == EOF) {
          pad = 3 - i;
          bits24 = bits24 << (8 * pad);
          break;
        }
        bits24 = (bits24 << 8) | c;
      }
      switch (pad) {
        case 0:
          fputc(b64_enc[(bits24 >> 18) & 0x3F], htmlwr->dest);
          fputc(b64_enc[(bits24 >> 12) & 0x3F], htmlwr->dest);
          fputc(b64_enc[(bits24 >> 6) & 0x3F], htmlwr->dest);
          fputc(b64_enc[bits24 & 0x3F], htmlwr->dest);
          break;
        case 1:
          fputc(b64_enc[(bits24 >> 18) & 0x3F], htmlwr->dest);
          fputc(b64_enc[(bits24 >> 12) & 0x3F], htmlwr->dest);
          fputc(b64_enc[(bits24 >> 6) & 0x3F], htmlwr->dest);
          fputc('=', htmlwr->dest);
          break;
        case 2:
          fputc(b64_enc[(bits24 >> 18) & 0x3F], htmlwr->dest);
          fputc(b64_enc[(bits24 >> 12) & 0x3F], htmlwr->dest);
          fputc('=', htmlwr->dest);
          fputc('=', htmlwr->dest);
          break;
      }
    }
    if (ferror(src_file)) {
      fprintf(stderr, "Error reading included file \"%s\".\n", src_path);
    }
    fclose(src_file);
  } else {
    fprintf(stderr, "Can not open included file \"%s\".\n", src_path);
  }
  free(src_path);
}
static void base64enc_file ( HTMLWR_T * htmlwr , char * mimetype , char * binary_source ) { char * src_path ; FILE * src_file ; int32_t bits24 ; int i , c , pad ; src_path = make_path_to_file ( htmlwr -> search_dir , binary_source ) ; src_file = fopen ( src_path , " " ) ; if ( src_file ) { fprintf ( htmlwr -> dest , " " , mimetype ) ; while ( ! feof ( src_file ) && ! ferror ( src_file ) ) { bits24 = 0 ; pad = 0 ; for ( i = 0 ; i < 3 ; i ++ ) { c = fgetc ( src_file ) ; if ( c == EOF ) { pad = 3 - i ; bits24 = bits24 << ( 8 * pad ) ; break ; } bits24 = ( bits24 << 8 ) | c ; } switch ( pad ) { case 0 : fputc ( b64_enc [ ( bits24 >> 18 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ ( bits24 >> 12 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ ( bits24 >> 6 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ bits24 & 0x3F ] , htmlwr -> dest ) ; break ; case 1 : fputc ( b64_enc [ ( bits24 >> 18 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ ( bits24 >> 12 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ ( bits24 >> 6 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( ' ' , htmlwr -> dest ) ; break ; case 2 : fputc ( b64_enc [ ( bits24 >> 18 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( b64_enc [ ( bits24 >> 12 ) & 0x3F ] , htmlwr -> dest ) ; fputc ( ' ' , htmlwr -> dest ) ; fputc ( ' ' , htmlwr -> dest ) ; break ; } } if ( ferror ( src_file ) ) { fprintf ( stderr , " \" \" \n " , src_path ) ; } fclose ( src_file ) ; } else { fprintf ( stderr , " \" \" \n " , src_path ) ; } free ( src_path ) ; }
Echo the file to the dest in base64 with the specified mime type.
Echo the file to the dest in base64 with the specified mime type .
// create a number containing 3 bytes // can't find it, issue a warning