Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
added 70 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Ascii arts ASCII art generator in C

I have written an ASCII art generator library and. I was a practice onpracticing data abstraction and code abstraction and I wanted to know if there is something that can bebe improved first of all the file tree.

   |         |--Makefile
   |--fonts--|--StarStrips.c
   |         |--whimsy.c
   |
   |           |--core.h 
---|--include--|--StarStrips.h
   |           |--whimsy.h
   |
   |--Makefile

File tree:

   |         |--Makefile
   |--fonts--|--StarStrips.c
   |         |--whimsy.c
   |
   |           |--core.h 
---|--include--|--StarStrips.h
   |           |--whimsy.h
   |
   |--Makefile
sharedlib: whimsy.o StarStrips.o
    @echo Building the Shared Library;  \
    gcc  -shared -fPIC -o ascii-arts.so whimsy.o StarStrips.o;  
StarStrips.o : StarStrips.c
    @echo building StarStrips;          \
    gcc -c -fPIC StarStrips.c -o StarStrips.o -std=c99 -I../include 
whimsy.o : whimsy.c
    @echo building whimsy;          \
    gcc -c -fPIC whimsy.c -o whimsy.o -std=c99 -I../include 
sharedlib: whimsy.o StarStrips.o
    @echo Building the Shared Library;  \
    gcc  -shared -fPIC -o ascii-arts.so whimsy.o StarStrips.o;  
StarStrips.o : StarStrips.c
    @echo building StarStrips;          \
    gcc -c -fPIC StarStrips.c -o StarStrips.o -std=c99 -I../include 
whimsy.o : whimsy.c
    @echo building whimsy;          \
    gcc -c -fPIC whimsy.c -o whimsy.o -std=c99 -I../include 
#include <whimsy.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int whimsy_allowed(int c)
{
    return islower(c) || c == ' ';
}

int whimsy_index (int c)
{
    return  islower(c)? c -'a'+1 :0;
}

int whimsy_init(void){
    font_alloc(whimsy,10,27);
    d_alloc(whimsy,space,' ',5,ARRAY({
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    "          }));
    d_alloc(whimsy,a,'a',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,b,'b',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88,  d88",
            "d88'`?88P'",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,c,'c',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8P' `P",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,d,'d',11,ARRAY({
            "      d8b ",
            "      88P ",
            "     d88  ",
            " d888888  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,e,'e',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8b_,dP",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,f,'f',11,ARRAY({
            "   ,d8888b",
            "   88P'   ",
            "d888888P  ",
            "  ?88'    ",
            "  88P     ",
            " d88      ",
            "d88'      ",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,g,'g',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "       )88",
            "      ,88P",
            "  `?8888P "        }));
    d_alloc(whimsy,h,'h',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,i,'i',6,ARRAY({
            "  d8,",
            " `8P ",
            "     ",
            "  88b",
            "  88P",
            " d88 ",
            "d88' ",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,j,'j',8,ARRAY({
            "   d8, ",
            "  `8P  ",
            "       ",
            "  d88  ",
            "  ?88  ",
            "   88b ",
            "   `88b",
            "    )88",
            "   ,88P",
            "`?888P "       }));
    d_alloc(whimsy,k,'k',12,ARRAY({
            " d8b       ",
            " ?88       ",
            "  88b      ",
            "  888  d88'",
            "  888bd8P' ",
            " d88888b   ",
            "d88' `?88b,",
            "           ",
            "           ",
            "           "       }));
    d_alloc(whimsy,l,'l',6,ARRAY({
            " d8b ",
            " 88P ",
            "d88  ",
            "888  ",
            "?88  ",
            " 88b ",
            "  88b",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,m,'m',15,ARRAY({
            "              ",
            "              ",
            "              ",
            "  88bd8b,d88b ",
            "  88P'`?8P'?8b",
            " d88  d88  88P",
            "d88' d88'  88b",
            "              ",
            "              ",
            "              "    }));
    d_alloc(whimsy,n,'n',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "  88bd88b ",
            "  88P' ?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,o,'o',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " d8888b ",
            "d8P' ?88",
            "88b  d88",
            "`?8888P'",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,p,'p',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88,.d88b,",
            "`?88'  ?88",
            "  88b  d8P",
            "  888888P'",
            "  88P'    ",
            " d88      ",
            " ?8P      "        }));
    d_alloc(whimsy,q,'q',11,ARRAY({
            "          ",
            "          ",
            "          ",
            ".d88b,.88P",
            "88P  `88P'",
            "?8b  d88  ",
            "`?888888  ",
            "    `?88  ",
            "      88b ",
            "      ?8P "        }));
    d_alloc(whimsy,r,'r',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "  88bd88b",
            "  88P'  `",
            " d88     ",
            "d88'     ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,s,'s',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " .d888b,",
            " ?8b,   ",
            "   `?8b ",
            "`?888P' ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,t,'t',9,ARRAY({
            "        ",
            "   d8P  ",
            "d888888P",
            "  ?88'  ",
            "  88P   ",
            "  88b   ",
            "  `?8b  ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,u,'u',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88   88 ",
            "?8(  d88 ",
            "`?88P'?8b",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,v,'v',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88  d8P'",
            "?8b ,88' ",
            "`?888P'  ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,w,'w',16,ARRAY({
            "               ",
            "               ",
            "               ",
            " ?88   d8P  d8P",
            " d88  d8P' d8P'",
            " ?8b ,88b ,88' ",
            " `?888P'888P'  ",
            "               ",
            "               ",
            "               "   }));
    d_alloc(whimsy,x,'x',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88,  88P",
            " `?8bd8P'",
            " d8P?8b, ",
            "d8P' `?8b",
            "         ",
            "         ",
            "         "
                        }));
    d_alloc(whimsy,y,'y',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88   d8P ",
            "d88   88  ",
            "?8(  d88  ",
            "`?88P'?8b ",
            "       )88",
            "      ,d8P",
            "   `?888P'"        }));
    d_alloc(whimsy,z,'z',9,ARRAY({
            "        ",
            "        ",
            "        ",
            "d88888P ",
            "   d8P' ",
            " d8P'   ",
            "d88888P'",
            "        ",
            "        ",
            "        "      }));
    return 0;
}
int whimsy_exit(void){
    for(int i=0;i<whimsy.d_n;i++)
        for(int j=0;j<whimsy.c;j++)
            free(whimsy.d[i][j]);
    for(int i=0;i<whimsy.d_n;i++)
        free(whimsy.d[i]);
    free(whimsy.d);
    free(whimsy.r);
}
int whimsy_print(const char* s){
    int n = strlen(s);
    for(int i=0;i<n;i++)
                if(whimsy.allowed(s[i]) != 1)
                        return -1;
    for (int i=0;i<whimsy.c;i++)
        {
                for(int j=0;j<n;j++)
                        fputs(whimsy.d[whimsy.index(s[j])][i],stdout);
                putchar('\n');
        }

}
#include <whimsy.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int whimsy_allowed(int c)
{
    return islower(c) || c == ' ';
}

int whimsy_index (int c)
{
    return  islower(c)? c -'a'+1 :0;
}

int whimsy_init(void){
    font_alloc(whimsy,10,27);
    d_alloc(whimsy,space,' ',5,ARRAY({
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    "          }));
    d_alloc(whimsy,a,'a',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,b,'b',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88,  d88",
            "d88'`?88P'",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,c,'c',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8P' `P",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,d,'d',11,ARRAY({
            "      d8b ",
            "      88P ",
            "     d88  ",
            " d888888  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,e,'e',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8b_,dP",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,f,'f',11,ARRAY({
            "   ,d8888b",
            "   88P'   ",
            "d888888P  ",
            "  ?88'    ",
            "  88P     ",
            " d88      ",
            "d88'      ",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,g,'g',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "       )88",
            "      ,88P",
            "  `?8888P "        }));
    d_alloc(whimsy,h,'h',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,i,'i',6,ARRAY({
            "  d8,",
            " `8P ",
            "     ",
            "  88b",
            "  88P",
            " d88 ",
            "d88' ",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,j,'j',8,ARRAY({
            "   d8, ",
            "  `8P  ",
            "       ",
            "  d88  ",
            "  ?88  ",
            "   88b ",
            "   `88b",
            "    )88",
            "   ,88P",
            "`?888P "       }));
    d_alloc(whimsy,k,'k',12,ARRAY({
            " d8b       ",
            " ?88       ",
            "  88b      ",
            "  888  d88'",
            "  888bd8P' ",
            " d88888b   ",
            "d88' `?88b,",
            "           ",
            "           ",
            "           "       }));
    d_alloc(whimsy,l,'l',6,ARRAY({
            " d8b ",
            " 88P ",
            "d88  ",
            "888  ",
            "?88  ",
            " 88b ",
            "  88b",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,m,'m',15,ARRAY({
            "              ",
            "              ",
            "              ",
            "  88bd8b,d88b ",
            "  88P'`?8P'?8b",
            " d88  d88  88P",
            "d88' d88'  88b",
            "              ",
            "              ",
            "              "    }));
    d_alloc(whimsy,n,'n',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "  88bd88b ",
            "  88P' ?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,o,'o',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " d8888b ",
            "d8P' ?88",
            "88b  d88",
            "`?8888P'",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,p,'p',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88,.d88b,",
            "`?88'  ?88",
            "  88b  d8P",
            "  888888P'",
            "  88P'    ",
            " d88      ",
            " ?8P      "        }));
    d_alloc(whimsy,q,'q',11,ARRAY({
            "          ",
            "          ",
            "          ",
            ".d88b,.88P",
            "88P  `88P'",
            "?8b  d88  ",
            "`?888888  ",
            "    `?88  ",
            "      88b ",
            "      ?8P "        }));
    d_alloc(whimsy,r,'r',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "  88bd88b",
            "  88P'  `",
            " d88     ",
            "d88'     ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,s,'s',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " .d888b,",
            " ?8b,   ",
            "   `?8b ",
            "`?888P' ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,t,'t',9,ARRAY({
            "        ",
            "   d8P  ",
            "d888888P",
            "  ?88'  ",
            "  88P   ",
            "  88b   ",
            "  `?8b  ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,u,'u',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88   88 ",
            "?8(  d88 ",
            "`?88P'?8b",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,v,'v',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88  d8P'",
            "?8b ,88' ",
            "`?888P'  ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,w,'w',16,ARRAY({
            "               ",
            "               ",
            "               ",
            " ?88   d8P  d8P",
            " d88  d8P' d8P'",
            " ?8b ,88b ,88' ",
            " `?888P'888P'  ",
            "               ",
            "               ",
            "               "   }));
    d_alloc(whimsy,x,'x',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88,  88P",
            " `?8bd8P'",
            " d8P?8b, ",
            "d8P' `?8b",
            "         ",
            "         ",
            "         "
                        }));
    d_alloc(whimsy,y,'y',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88   d8P ",
            "d88   88  ",
            "?8(  d88  ",
            "`?88P'?8b ",
            "       )88",
            "      ,d8P",
            "   `?888P'"        }));
    d_alloc(whimsy,z,'z',9,ARRAY({
            "        ",
            "        ",
            "        ",
            "d88888P ",
            "   d8P' ",
            " d8P'   ",
            "d88888P'",
            "        ",
            "        ",
            "        "      }));
    return 0;
}
int whimsy_exit(void){
    for(int i=0;i<whimsy.d_n;i++)
        for(int j=0;j<whimsy.c;j++)
            free(whimsy.d[i][j]);
    for(int i=0;i<whimsy.d_n;i++)
        free(whimsy.d[i]);
    free(whimsy.d);
    free(whimsy.r);
}
int whimsy_print(const char* s){
    int n = strlen(s);
    for(int i=0;i<n;i++)
                if(whimsy.allowed(s[i]) != 1)
                        return -1;
    for (int i=0;i<whimsy.c;i++)
        {
                for(int j=0;j<n;j++)
                        fputs(whimsy.d[whimsy.index(s[j])][i],stdout);
                putchar('\n');
        }

}

I wontwon't show you /font/StarStrips.c because I itit's similar lengthy code and the goal of reviewing the code is not giving opinions about the fonts it self.

#ifndef _ascii_arts_core_
#define _ascii_arts_core_
/*
r rows
c columns
d design
char_n number of characters
*/
struct font{
unsigned int c;
unsigned int *r;
unsigned int d_n;
int (*allowed)(int);
int (*index)(int);
int (*init)(void);
int (*exit)(void);
int (*print)(const char*);
char ***d;
};
#define XX(a,b,c) a##b##c
#define font_alloc(font,column,nofdesigns)              \
    do{                             \
        font.d_n = nofdesigns;                  \
        font.c = column;                    \
        font.r = malloc(sizeof(int)*font.d_n);          \
            font.d = malloc(sizeof(char***)*font.d_n);      \
        for(int i=0;i<font.d_n;i++)             \
            font.d[i] =malloc(sizeof(char**)*font.c);   \
    }while(0)
#define ARRAY(...) __VA_ARGS__
#define d_alloc(font,__tok,_char,row,design)                \
    do{                             \
        font.r[font.index(_char)] = row;            \
        for(int j=0;j<font.c;j++)               \
            font.d[font.index(_char)][j] =          \
            malloc(sizeof(char*)*font.r[font.index(_char)]);\
        char * temp[]  = design;                \
        for(int i=0;i<font.c;i++)               \
            strcpy(font.d[font.index(_char)][i],temp[i]);   \
    }while(0)
#endif
#ifndef _ascii_arts_core_
#define _ascii_arts_core_
/*
r rows
c columns
d design
char_n number of characters
*/
struct font{
unsigned int c;
unsigned int *r;
unsigned int d_n;
int (*allowed)(int);
int (*index)(int);
int (*init)(void);
int (*exit)(void);
int (*print)(const char*);
char ***d;
};
#define XX(a,b,c) a##b##c
#define font_alloc(font,column,nofdesigns)              \
    do{                             \
        font.d_n = nofdesigns;                  \
        font.c = column;                    \
        font.r = malloc(sizeof(int)*font.d_n);          \
            font.d = malloc(sizeof(char***)*font.d_n);      \
        for(int i=0;i<font.d_n;i++)             \
            font.d[i] =malloc(sizeof(char**)*font.c);   \
    }while(0)
#define ARRAY(...) __VA_ARGS__
#define d_alloc(font,__tok,_char,row,design)                \
    do{                             \
        font.r[font.index(_char)] = row;            \
        for(int j=0;j<font.c;j++)               \
            font.d[font.index(_char)][j] =          \
            malloc(sizeof(char*)*font.r[font.index(_char)]);\
        char * temp[]  = design;                \
        for(int i=0;i<font.c;i++)               \
            strcpy(font.d[font.index(_char)][i],temp[i]);   \
    }while(0)
#endif
#ifndef _whimsy_font_
#define _whimsy_font_
#include <core.h>
int whimsy_allowed(int c);
int whimsy_index(int c);
int whimsy_init(void);
int whimsy_exit(void);
int whimsy_print(const char* s);
struct font whimsy = {
    .allowed = whimsy_allowed,
    .index = whimsy_index,
    .init = whimsy_init,
    .exit = whimsy_exit,
    .print = whimsy_print
};
#endif
#ifndef _whimsy_font_
#define _whimsy_font_
#include <core.h>
int whimsy_allowed(int c);
int whimsy_index(int c);
int whimsy_init(void);
int whimsy_exit(void);
int whimsy_print(const char* s);
struct font whimsy = {
    .allowed = whimsy_allowed,
    .index = whimsy_index,
    .init = whimsy_init,
    .exit = whimsy_exit,
    .print = whimsy_print
};
#endif
uninstall:
    @echo Uninstalling library;     \
    rm /usr/lib/libaarts.so -f;     \
    cd /usr/include         \
    rm whimsy.h core.h StarStrips.h -f
install: lib
    @echo Installing library;   \
    cp include/*.h /usr/include/;   \
    cp libaarts.so /usr/lib/
lib:
    @cd fonts;          \
    make sharedlib;         \
    mv ascii-arts.so ../libaarts.so
    
clean:
    @rm *.so -f;            \
    cd fonts;           \
    rm *.o -f;          \
    cd ../demo;         \
    rm *.d -f;
demos:
    @cd demo;           \
    make whimsy
uninstall:
    @echo Uninstalling library;     \
    rm /usr/lib/libaarts.so -f;     \
    cd /usr/include         \
    rm whimsy.h core.h StarStrips.h -f
install: lib
    @echo Installing library;   \
    cp include/*.h /usr/include/;   \
    cp libaarts.so /usr/lib/
lib:
    @cd fonts;          \
    make sharedlib;         \
    mv ascii-arts.so ../libaarts.so
    
clean:
    @rm *.so -f;            \
    cd fonts;           \
    rm *.o -f;          \
    cd ../demo;         \
    rm *.d -f;
demos:
    @cd demo;           \
    make whimsy

littleLittle notes first of all the main goal of this library was to provide data structure to hold fonts for ascii-arts characters and maybe ascii arts drawings (ie converting png image to an ascii arts (not yet done)).

First of all, the main goal of this library was to provide a data structure to hold fonts for ASCII art characters and maybe ASCII art drawings (i.e. converting a PNG image to ASCII arts (not yet done)).

in the d_alloc macro the __tok parameter is useless and it is there just for backwordbackwards comptiability with previous versions of the same library.

Ascii arts generator in C

I have written an ASCII art generator library and I was a practice on data abstraction and code abstraction and I wanted to know if there is something that can be improved first of all the file tree

   |         |--Makefile
   |--fonts--|--StarStrips.c
   |         |--whimsy.c
   |
   |           |--core.h 
---|--include--|--StarStrips.h
   |           |--whimsy.h
   |
   |--Makefile
sharedlib: whimsy.o StarStrips.o
    @echo Building the Shared Library;  \
    gcc  -shared -fPIC -o ascii-arts.so whimsy.o StarStrips.o;  
StarStrips.o : StarStrips.c
    @echo building StarStrips;          \
    gcc -c -fPIC StarStrips.c -o StarStrips.o -std=c99 -I../include 
whimsy.o : whimsy.c
    @echo building whimsy;          \
    gcc -c -fPIC whimsy.c -o whimsy.o -std=c99 -I../include 
#include <whimsy.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int whimsy_allowed(int c)
{
    return islower(c) || c == ' ';
}

int whimsy_index (int c)
{
    return  islower(c)? c -'a'+1 :0;
}

int whimsy_init(void){
    font_alloc(whimsy,10,27);
    d_alloc(whimsy,space,' ',5,ARRAY({
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    "          }));
    d_alloc(whimsy,a,'a',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,b,'b',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88,  d88",
            "d88'`?88P'",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,c,'c',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8P' `P",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,d,'d',11,ARRAY({
            "      d8b ",
            "      88P ",
            "     d88  ",
            " d888888  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,e,'e',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8b_,dP",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,f,'f',11,ARRAY({
            "   ,d8888b",
            "   88P'   ",
            "d888888P  ",
            "  ?88'    ",
            "  88P     ",
            " d88      ",
            "d88'      ",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,g,'g',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "       )88",
            "      ,88P",
            "  `?8888P "        }));
    d_alloc(whimsy,h,'h',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,i,'i',6,ARRAY({
            "  d8,",
            " `8P ",
            "     ",
            "  88b",
            "  88P",
            " d88 ",
            "d88' ",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,j,'j',8,ARRAY({
            "   d8, ",
            "  `8P  ",
            "       ",
            "  d88  ",
            "  ?88  ",
            "   88b ",
            "   `88b",
            "    )88",
            "   ,88P",
            "`?888P "       }));
    d_alloc(whimsy,k,'k',12,ARRAY({
            " d8b       ",
            " ?88       ",
            "  88b      ",
            "  888  d88'",
            "  888bd8P' ",
            " d88888b   ",
            "d88' `?88b,",
            "           ",
            "           ",
            "           "       }));
    d_alloc(whimsy,l,'l',6,ARRAY({
            " d8b ",
            " 88P ",
            "d88  ",
            "888  ",
            "?88  ",
            " 88b ",
            "  88b",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,m,'m',15,ARRAY({
            "              ",
            "              ",
            "              ",
            "  88bd8b,d88b ",
            "  88P'`?8P'?8b",
            " d88  d88  88P",
            "d88' d88'  88b",
            "              ",
            "              ",
            "              "    }));
    d_alloc(whimsy,n,'n',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "  88bd88b ",
            "  88P' ?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,o,'o',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " d8888b ",
            "d8P' ?88",
            "88b  d88",
            "`?8888P'",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,p,'p',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88,.d88b,",
            "`?88'  ?88",
            "  88b  d8P",
            "  888888P'",
            "  88P'    ",
            " d88      ",
            " ?8P      "        }));
    d_alloc(whimsy,q,'q',11,ARRAY({
            "          ",
            "          ",
            "          ",
            ".d88b,.88P",
            "88P  `88P'",
            "?8b  d88  ",
            "`?888888  ",
            "    `?88  ",
            "      88b ",
            "      ?8P "        }));
    d_alloc(whimsy,r,'r',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "  88bd88b",
            "  88P'  `",
            " d88     ",
            "d88'     ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,s,'s',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " .d888b,",
            " ?8b,   ",
            "   `?8b ",
            "`?888P' ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,t,'t',9,ARRAY({
            "        ",
            "   d8P  ",
            "d888888P",
            "  ?88'  ",
            "  88P   ",
            "  88b   ",
            "  `?8b  ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,u,'u',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88   88 ",
            "?8(  d88 ",
            "`?88P'?8b",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,v,'v',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88  d8P'",
            "?8b ,88' ",
            "`?888P'  ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,w,'w',16,ARRAY({
            "               ",
            "               ",
            "               ",
            " ?88   d8P  d8P",
            " d88  d8P' d8P'",
            " ?8b ,88b ,88' ",
            " `?888P'888P'  ",
            "               ",
            "               ",
            "               "   }));
    d_alloc(whimsy,x,'x',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88,  88P",
            " `?8bd8P'",
            " d8P?8b, ",
            "d8P' `?8b",
            "         ",
            "         ",
            "         "
                        }));
    d_alloc(whimsy,y,'y',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88   d8P ",
            "d88   88  ",
            "?8(  d88  ",
            "`?88P'?8b ",
            "       )88",
            "      ,d8P",
            "   `?888P'"        }));
    d_alloc(whimsy,z,'z',9,ARRAY({
            "        ",
            "        ",
            "        ",
            "d88888P ",
            "   d8P' ",
            " d8P'   ",
            "d88888P'",
            "        ",
            "        ",
            "        "      }));
    return 0;
}
int whimsy_exit(void){
    for(int i=0;i<whimsy.d_n;i++)
        for(int j=0;j<whimsy.c;j++)
            free(whimsy.d[i][j]);
    for(int i=0;i<whimsy.d_n;i++)
        free(whimsy.d[i]);
    free(whimsy.d);
    free(whimsy.r);
}
int whimsy_print(const char* s){
    int n = strlen(s);
    for(int i=0;i<n;i++)
                if(whimsy.allowed(s[i]) != 1)
                        return -1;
    for (int i=0;i<whimsy.c;i++)
        {
                for(int j=0;j<n;j++)
                        fputs(whimsy.d[whimsy.index(s[j])][i],stdout);
                putchar('\n');
        }

}

I wont show you /font/StarStrips.c because I it similar lengthy code and the goal of reviewing the code is not giving opinions about the fonts it self.

#ifndef _ascii_arts_core_
#define _ascii_arts_core_
/*
r rows
c columns
d design
char_n number of characters
*/
struct font{
unsigned int c;
unsigned int *r;
unsigned int d_n;
int (*allowed)(int);
int (*index)(int);
int (*init)(void);
int (*exit)(void);
int (*print)(const char*);
char ***d;
};
#define XX(a,b,c) a##b##c
#define font_alloc(font,column,nofdesigns)              \
    do{                             \
        font.d_n = nofdesigns;                  \
        font.c = column;                    \
        font.r = malloc(sizeof(int)*font.d_n);          \
            font.d = malloc(sizeof(char***)*font.d_n);      \
        for(int i=0;i<font.d_n;i++)             \
            font.d[i] =malloc(sizeof(char**)*font.c);   \
    }while(0)
#define ARRAY(...) __VA_ARGS__
#define d_alloc(font,__tok,_char,row,design)                \
    do{                             \
        font.r[font.index(_char)] = row;            \
        for(int j=0;j<font.c;j++)               \
            font.d[font.index(_char)][j] =          \
            malloc(sizeof(char*)*font.r[font.index(_char)]);\
        char * temp[]  = design;                \
        for(int i=0;i<font.c;i++)               \
            strcpy(font.d[font.index(_char)][i],temp[i]);   \
    }while(0)
#endif
#ifndef _whimsy_font_
#define _whimsy_font_
#include <core.h>
int whimsy_allowed(int c);
int whimsy_index(int c);
int whimsy_init(void);
int whimsy_exit(void);
int whimsy_print(const char* s);
struct font whimsy = {
    .allowed = whimsy_allowed,
    .index = whimsy_index,
    .init = whimsy_init,
    .exit = whimsy_exit,
    .print = whimsy_print
};
#endif
uninstall:
    @echo Uninstalling library;     \
    rm /usr/lib/libaarts.so -f;     \
    cd /usr/include         \
    rm whimsy.h core.h StarStrips.h -f
install: lib
    @echo Installing library;   \
    cp include/*.h /usr/include/;   \
    cp libaarts.so /usr/lib/
lib:
    @cd fonts;          \
    make sharedlib;         \
    mv ascii-arts.so ../libaarts.so
    
clean:
    @rm *.so -f;            \
    cd fonts;           \
    rm *.o -f;          \
    cd ../demo;         \
    rm *.d -f;
demos:
    @cd demo;           \
    make whimsy

little notes first of all the main goal of this library was to provide data structure to hold fonts for ascii-arts characters and maybe ascii arts drawings (ie converting png image to an ascii arts (not yet done)).

in the d_alloc macro the __tok parameter is useless and it is there just for backword comptiability with previous versions of the same library

ASCII art generator in C

I have written an ASCII art generator library. I was practicing data abstraction and code abstraction and I wanted to know if there is something that can be improved.

File tree:

   |         |--Makefile
   |--fonts--|--StarStrips.c
   |         |--whimsy.c
   |
   |           |--core.h 
---|--include--|--StarStrips.h
   |           |--whimsy.h
   |
   |--Makefile
sharedlib: whimsy.o StarStrips.o
    @echo Building the Shared Library;  \
    gcc  -shared -fPIC -o ascii-arts.so whimsy.o StarStrips.o;  
StarStrips.o : StarStrips.c
    @echo building StarStrips;          \
    gcc -c -fPIC StarStrips.c -o StarStrips.o -std=c99 -I../include 
whimsy.o : whimsy.c
    @echo building whimsy;          \
    gcc -c -fPIC whimsy.c -o whimsy.o -std=c99 -I../include 
#include <whimsy.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int whimsy_allowed(int c)
{
    return islower(c) || c == ' ';
}

int whimsy_index (int c)
{
    return  islower(c)? c -'a'+1 :0;
}

int whimsy_init(void){
    font_alloc(whimsy,10,27);
    d_alloc(whimsy,space,' ',5,ARRAY({
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    "          }));
    d_alloc(whimsy,a,'a',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,b,'b',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88,  d88",
            "d88'`?88P'",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,c,'c',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8P' `P",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,d,'d',11,ARRAY({
            "      d8b ",
            "      88P ",
            "     d88  ",
            " d888888  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,e,'e',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8b_,dP",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,f,'f',11,ARRAY({
            "   ,d8888b",
            "   88P'   ",
            "d888888P  ",
            "  ?88'    ",
            "  88P     ",
            " d88      ",
            "d88'      ",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,g,'g',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "       )88",
            "      ,88P",
            "  `?8888P "        }));
    d_alloc(whimsy,h,'h',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,i,'i',6,ARRAY({
            "  d8,",
            " `8P ",
            "     ",
            "  88b",
            "  88P",
            " d88 ",
            "d88' ",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,j,'j',8,ARRAY({
            "   d8, ",
            "  `8P  ",
            "       ",
            "  d88  ",
            "  ?88  ",
            "   88b ",
            "   `88b",
            "    )88",
            "   ,88P",
            "`?888P "       }));
    d_alloc(whimsy,k,'k',12,ARRAY({
            " d8b       ",
            " ?88       ",
            "  88b      ",
            "  888  d88'",
            "  888bd8P' ",
            " d88888b   ",
            "d88' `?88b,",
            "           ",
            "           ",
            "           "       }));
    d_alloc(whimsy,l,'l',6,ARRAY({
            " d8b ",
            " 88P ",
            "d88  ",
            "888  ",
            "?88  ",
            " 88b ",
            "  88b",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,m,'m',15,ARRAY({
            "              ",
            "              ",
            "              ",
            "  88bd8b,d88b ",
            "  88P'`?8P'?8b",
            " d88  d88  88P",
            "d88' d88'  88b",
            "              ",
            "              ",
            "              "    }));
    d_alloc(whimsy,n,'n',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "  88bd88b ",
            "  88P' ?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,o,'o',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " d8888b ",
            "d8P' ?88",
            "88b  d88",
            "`?8888P'",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,p,'p',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88,.d88b,",
            "`?88'  ?88",
            "  88b  d8P",
            "  888888P'",
            "  88P'    ",
            " d88      ",
            " ?8P      "        }));
    d_alloc(whimsy,q,'q',11,ARRAY({
            "          ",
            "          ",
            "          ",
            ".d88b,.88P",
            "88P  `88P'",
            "?8b  d88  ",
            "`?888888  ",
            "    `?88  ",
            "      88b ",
            "      ?8P "        }));
    d_alloc(whimsy,r,'r',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "  88bd88b",
            "  88P'  `",
            " d88     ",
            "d88'     ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,s,'s',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " .d888b,",
            " ?8b,   ",
            "   `?8b ",
            "`?888P' ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,t,'t',9,ARRAY({
            "        ",
            "   d8P  ",
            "d888888P",
            "  ?88'  ",
            "  88P   ",
            "  88b   ",
            "  `?8b  ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,u,'u',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88   88 ",
            "?8(  d88 ",
            "`?88P'?8b",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,v,'v',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88  d8P'",
            "?8b ,88' ",
            "`?888P'  ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,w,'w',16,ARRAY({
            "               ",
            "               ",
            "               ",
            " ?88   d8P  d8P",
            " d88  d8P' d8P'",
            " ?8b ,88b ,88' ",
            " `?888P'888P'  ",
            "               ",
            "               ",
            "               "   }));
    d_alloc(whimsy,x,'x',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88,  88P",
            " `?8bd8P'",
            " d8P?8b, ",
            "d8P' `?8b",
            "         ",
            "         ",
            "         "
                        }));
    d_alloc(whimsy,y,'y',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88   d8P ",
            "d88   88  ",
            "?8(  d88  ",
            "`?88P'?8b ",
            "       )88",
            "      ,d8P",
            "   `?888P'"        }));
    d_alloc(whimsy,z,'z',9,ARRAY({
            "        ",
            "        ",
            "        ",
            "d88888P ",
            "   d8P' ",
            " d8P'   ",
            "d88888P'",
            "        ",
            "        ",
            "        "      }));
    return 0;
}
int whimsy_exit(void){
    for(int i=0;i<whimsy.d_n;i++)
        for(int j=0;j<whimsy.c;j++)
            free(whimsy.d[i][j]);
    for(int i=0;i<whimsy.d_n;i++)
        free(whimsy.d[i]);
    free(whimsy.d);
    free(whimsy.r);
}
int whimsy_print(const char* s){
    int n = strlen(s);
    for(int i=0;i<n;i++)
                if(whimsy.allowed(s[i]) != 1)
                        return -1;
    for (int i=0;i<whimsy.c;i++)
        {
                for(int j=0;j<n;j++)
                        fputs(whimsy.d[whimsy.index(s[j])][i],stdout);
                putchar('\n');
        }

}

I won't show you /font/StarStrips.c because it's similar lengthy code and the goal of reviewing the code is not giving opinions about the fonts self.

#ifndef _ascii_arts_core_
#define _ascii_arts_core_
/*
r rows
c columns
d design
char_n number of characters
*/
struct font{
unsigned int c;
unsigned int *r;
unsigned int d_n;
int (*allowed)(int);
int (*index)(int);
int (*init)(void);
int (*exit)(void);
int (*print)(const char*);
char ***d;
};
#define XX(a,b,c) a##b##c
#define font_alloc(font,column,nofdesigns)              \
    do{                             \
        font.d_n = nofdesigns;                  \
        font.c = column;                    \
        font.r = malloc(sizeof(int)*font.d_n);          \
            font.d = malloc(sizeof(char***)*font.d_n);      \
        for(int i=0;i<font.d_n;i++)             \
            font.d[i] =malloc(sizeof(char**)*font.c);   \
    }while(0)
#define ARRAY(...) __VA_ARGS__
#define d_alloc(font,__tok,_char,row,design)                \
    do{                             \
        font.r[font.index(_char)] = row;            \
        for(int j=0;j<font.c;j++)               \
            font.d[font.index(_char)][j] =          \
            malloc(sizeof(char*)*font.r[font.index(_char)]);\
        char * temp[]  = design;                \
        for(int i=0;i<font.c;i++)               \
            strcpy(font.d[font.index(_char)][i],temp[i]);   \
    }while(0)
#endif
#ifndef _whimsy_font_
#define _whimsy_font_
#include <core.h>
int whimsy_allowed(int c);
int whimsy_index(int c);
int whimsy_init(void);
int whimsy_exit(void);
int whimsy_print(const char* s);
struct font whimsy = {
    .allowed = whimsy_allowed,
    .index = whimsy_index,
    .init = whimsy_init,
    .exit = whimsy_exit,
    .print = whimsy_print
};
#endif
uninstall:
    @echo Uninstalling library;     \
    rm /usr/lib/libaarts.so -f;     \
    cd /usr/include         \
    rm whimsy.h core.h StarStrips.h -f
install: lib
    @echo Installing library;   \
    cp include/*.h /usr/include/;   \
    cp libaarts.so /usr/lib/
lib:
    @cd fonts;          \
    make sharedlib;         \
    mv ascii-arts.so ../libaarts.so
    
clean:
    @rm *.so -f;            \
    cd fonts;           \
    rm *.o -f;          \
    cd ../demo;         \
    rm *.d -f;
demos:
    @cd demo;           \
    make whimsy

Little notes

First of all, the main goal of this library was to provide a data structure to hold fonts for ASCII art characters and maybe ASCII art drawings (i.e. converting a PNG image to ASCII arts (not yet done)).

in the d_alloc macro the __tok parameter is useless and it is there just for backwards comptiability with previous versions of the same library.

Source Link
u185619
  • 937
  • 1
  • 7
  • 23

Ascii arts generator in C

I have written an ASCII art generator library and I was a practice on data abstraction and code abstraction and I wanted to know if there is something that can be improved first of all the file tree

   |         |--Makefile
   |--fonts--|--StarStrips.c
   |         |--whimsy.c
   |
   |           |--core.h 
---|--include--|--StarStrips.h
   |           |--whimsy.h
   |
   |--Makefile

/fonts/Makefile

sharedlib: whimsy.o StarStrips.o
    @echo Building the Shared Library;  \
    gcc  -shared -fPIC -o ascii-arts.so whimsy.o StarStrips.o;  
StarStrips.o : StarStrips.c
    @echo building StarStrips;          \
    gcc -c -fPIC StarStrips.c -o StarStrips.o -std=c99 -I../include 
whimsy.o : whimsy.c
    @echo building whimsy;          \
    gcc -c -fPIC whimsy.c -o whimsy.o -std=c99 -I../include 

/font/whimsy.c

#include <whimsy.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int whimsy_allowed(int c)
{
    return islower(c) || c == ' ';
}

int whimsy_index (int c)
{
    return  islower(c)? c -'a'+1 :0;
}

int whimsy_init(void){
    font_alloc(whimsy,10,27);
    d_alloc(whimsy,space,' ',5,ARRAY({
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    ",
            "    "          }));
    d_alloc(whimsy,a,'a',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,b,'b',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88,  d88",
            "d88'`?88P'",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,c,'c',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8P' `P",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,d,'d',11,ARRAY({
            "      d8b ",
            "      88P ",
            "     d88  ",
            " d888888  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,e,'e',8,ARRAY({
            "       ",
            "       ",
            "       ",
            " d8888b",
            "d8b_,dP",
            "88b    ",
            "`?888P'",
            "       ",
            "       ",
            "       "       }));
    d_alloc(whimsy,f,'f',11,ARRAY({
            "   ,d8888b",
            "   88P'   ",
            "d888888P  ",
            "  ?88'    ",
            "  88P     ",
            " d88      ",
            "d88'      ",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,g,'g',11,ARRAY({
            "          ",
            "          ",
            "          ",
            " d888b8b  ",
            "d8P' ?88  ",
            "88b  ,88b ",
            "`?88P'`88b",
            "       )88",
            "      ,88P",
            "  `?8888P "        }));
    d_alloc(whimsy,h,'h',11,ARRAY({
            " d8b      ",
            " ?88      ",
            "  88b     ",
            "  888888b ",
            "  88P `?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,i,'i',6,ARRAY({
            "  d8,",
            " `8P ",
            "     ",
            "  88b",
            "  88P",
            " d88 ",
            "d88' ",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,j,'j',8,ARRAY({
            "   d8, ",
            "  `8P  ",
            "       ",
            "  d88  ",
            "  ?88  ",
            "   88b ",
            "   `88b",
            "    )88",
            "   ,88P",
            "`?888P "       }));
    d_alloc(whimsy,k,'k',12,ARRAY({
            " d8b       ",
            " ?88       ",
            "  88b      ",
            "  888  d88'",
            "  888bd8P' ",
            " d88888b   ",
            "d88' `?88b,",
            "           ",
            "           ",
            "           "       }));
    d_alloc(whimsy,l,'l',6,ARRAY({
            " d8b ",
            " 88P ",
            "d88  ",
            "888  ",
            "?88  ",
            " 88b ",
            "  88b",
            "     ",
            "     ",
            "     "         }));
    d_alloc(whimsy,m,'m',15,ARRAY({
            "              ",
            "              ",
            "              ",
            "  88bd8b,d88b ",
            "  88P'`?8P'?8b",
            " d88  d88  88P",
            "d88' d88'  88b",
            "              ",
            "              ",
            "              "    }));
    d_alloc(whimsy,n,'n',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "  88bd88b ",
            "  88P' ?8b",
            " d88   88P",
            "d88'   88b",
            "          ",
            "          ",
            "          "        }));
    d_alloc(whimsy,o,'o',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " d8888b ",
            "d8P' ?88",
            "88b  d88",
            "`?8888P'",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,p,'p',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88,.d88b,",
            "`?88'  ?88",
            "  88b  d8P",
            "  888888P'",
            "  88P'    ",
            " d88      ",
            " ?8P      "        }));
    d_alloc(whimsy,q,'q',11,ARRAY({
            "          ",
            "          ",
            "          ",
            ".d88b,.88P",
            "88P  `88P'",
            "?8b  d88  ",
            "`?888888  ",
            "    `?88  ",
            "      88b ",
            "      ?8P "        }));
    d_alloc(whimsy,r,'r',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "  88bd88b",
            "  88P'  `",
            " d88     ",
            "d88'     ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,s,'s',9,ARRAY({
            "        ",
            "        ",
            "        ",
            " .d888b,",
            " ?8b,   ",
            "   `?8b ",
            "`?888P' ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,t,'t',9,ARRAY({
            "        ",
            "   d8P  ",
            "d888888P",
            "  ?88'  ",
            "  88P   ",
            "  88b   ",
            "  `?8b  ",
            "        ",
            "        ",
            "        "      }));
    d_alloc(whimsy,u,'u',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88   88 ",
            "?8(  d88 ",
            "`?88P'?8b",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,v,'v',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88   d8P",
            "d88  d8P'",
            "?8b ,88' ",
            "`?888P'  ",
            "         ",
            "         ",
            "         "     }));
    d_alloc(whimsy,w,'w',16,ARRAY({
            "               ",
            "               ",
            "               ",
            " ?88   d8P  d8P",
            " d88  d8P' d8P'",
            " ?8b ,88b ,88' ",
            " `?888P'888P'  ",
            "               ",
            "               ",
            "               "   }));
    d_alloc(whimsy,x,'x',10,ARRAY({
            "         ",
            "         ",
            "         ",
            "?88,  88P",
            " `?8bd8P'",
            " d8P?8b, ",
            "d8P' `?8b",
            "         ",
            "         ",
            "         "
                        }));
    d_alloc(whimsy,y,'y',11,ARRAY({
            "          ",
            "          ",
            "          ",
            "?88   d8P ",
            "d88   88  ",
            "?8(  d88  ",
            "`?88P'?8b ",
            "       )88",
            "      ,d8P",
            "   `?888P'"        }));
    d_alloc(whimsy,z,'z',9,ARRAY({
            "        ",
            "        ",
            "        ",
            "d88888P ",
            "   d8P' ",
            " d8P'   ",
            "d88888P'",
            "        ",
            "        ",
            "        "      }));
    return 0;
}
int whimsy_exit(void){
    for(int i=0;i<whimsy.d_n;i++)
        for(int j=0;j<whimsy.c;j++)
            free(whimsy.d[i][j]);
    for(int i=0;i<whimsy.d_n;i++)
        free(whimsy.d[i]);
    free(whimsy.d);
    free(whimsy.r);
}
int whimsy_print(const char* s){
    int n = strlen(s);
    for(int i=0;i<n;i++)
                if(whimsy.allowed(s[i]) != 1)
                        return -1;
    for (int i=0;i<whimsy.c;i++)
        {
                for(int j=0;j<n;j++)
                        fputs(whimsy.d[whimsy.index(s[j])][i],stdout);
                putchar('\n');
        }

}

I wont show you /font/StarStrips.c because I it similar lengthy code and the goal of reviewing the code is not giving opinions about the fonts it self.

/include/core.h

#ifndef _ascii_arts_core_
#define _ascii_arts_core_
/*
r rows
c columns
d design
char_n number of characters
*/
struct font{
unsigned int c;
unsigned int *r;
unsigned int d_n;
int (*allowed)(int);
int (*index)(int);
int (*init)(void);
int (*exit)(void);
int (*print)(const char*);
char ***d;
};
#define XX(a,b,c) a##b##c
#define font_alloc(font,column,nofdesigns)              \
    do{                             \
        font.d_n = nofdesigns;                  \
        font.c = column;                    \
        font.r = malloc(sizeof(int)*font.d_n);          \
            font.d = malloc(sizeof(char***)*font.d_n);      \
        for(int i=0;i<font.d_n;i++)             \
            font.d[i] =malloc(sizeof(char**)*font.c);   \
    }while(0)
#define ARRAY(...) __VA_ARGS__
#define d_alloc(font,__tok,_char,row,design)                \
    do{                             \
        font.r[font.index(_char)] = row;            \
        for(int j=0;j<font.c;j++)               \
            font.d[font.index(_char)][j] =          \
            malloc(sizeof(char*)*font.r[font.index(_char)]);\
        char * temp[]  = design;                \
        for(int i=0;i<font.c;i++)               \
            strcpy(font.d[font.index(_char)][i],temp[i]);   \
    }while(0)
#endif

/include/whimsy.h

#ifndef _whimsy_font_
#define _whimsy_font_
#include <core.h>
int whimsy_allowed(int c);
int whimsy_index(int c);
int whimsy_init(void);
int whimsy_exit(void);
int whimsy_print(const char* s);
struct font whimsy = {
    .allowed = whimsy_allowed,
    .index = whimsy_index,
    .init = whimsy_init,
    .exit = whimsy_exit,
    .print = whimsy_print
};
#endif

/Makefile

uninstall:
    @echo Uninstalling library;     \
    rm /usr/lib/libaarts.so -f;     \
    cd /usr/include         \
    rm whimsy.h core.h StarStrips.h -f
install: lib
    @echo Installing library;   \
    cp include/*.h /usr/include/;   \
    cp libaarts.so /usr/lib/
lib:
    @cd fonts;          \
    make sharedlib;         \
    mv ascii-arts.so ../libaarts.so
    
clean:
    @rm *.so -f;            \
    cd fonts;           \
    rm *.o -f;          \
    cd ../demo;         \
    rm *.d -f;
demos:
    @cd demo;           \
    make whimsy

little notes first of all the main goal of this library was to provide data structure to hold fonts for ascii-arts characters and maybe ascii arts drawings (ie converting png image to an ascii arts (not yet done)).

in the d_alloc macro the __tok parameter is useless and it is there just for backword comptiability with previous versions of the same library