Skip to main content
Mild grammar fix
Source Link
user34073
user34073
  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately, you didn't show your font file. Also, I'm 95% sure thatthe init and print files are identical modulo font name. If I'm correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your font file. Also, I'm 95% sure that init and print files are identical modulo font name. If I'm correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately, you didn't show your font file. Also, I'm 95% sure the init and print files are identical modulo font name. If I'm correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your another font file. I amAlso, I'm 95% sure that init and print files are identical modulo font name. If I amI'm correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your another font file. I am 95% sure that init and print files are identical modulo font name. If I am correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your font file. Also, I'm 95% sure that init and print files are identical modulo font name. If I'm correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

added 72 characters in body
Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144
  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your another font file. I am 95% sure that init and print files are identical modulo font name. If I am correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your another font file. I am 95% sure that init and print files are identical modulo font name. If I am correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me. I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

  • fonts/Makefile

    Each object depends only on the corresponding source. It means that header modifications wouldn't trigger recompilation. You may fix it by explicitly spelling out dependencies:

      whimsy.o: whimsy.c whimsy.h core.h
    

    In general it is a good habit to have dependencies auto generated: even in your not very complicated case it is easy to miss the core.h dependency. Take a look at -M family of gcc options.

  • include/whimsy.h

    Do not define objects (like struct font whimsy) in the header file. You never know how many times the client would happen to #include "whimsy.h" in different places of their project. Better practice is to have the definition in the .c file, and declare it in the header as

      extern struct font whimsy;
    
  • DRY?

    Unfortunately you didn't show your another font file. I am 95% sure that init and print files are identical modulo font name. If I am correct, you need to unify them, and have the unified version in core.c.

  • Allocation

    Allocating glyphs dynamically and copying them from a static area looks like a waste for me (it would make sense should you read glyphs from the text file instead). I would have a

      struct glyph {
          int width;
          char * appearance;
      };
    

    (strictly speaking, glyph.width is redundant: given a font height and appearance length you may calculate width at runtime); an array of glyphs as a part of struct font:

      struct font {
          ....
          struct glyph typeface[128];
          ....
      }
    

    and a static initialization of each font like

      static struct font whimsy = {
          ....
          .typeface = {
              ....
              ['a'] = (struct glyph) {
                  .width = 10,
                  .appearance =
                      "          "
                      "          "
                      "          "
                      " d888b8b  "
                      "d8P' ?88  "
                      "88b  ,88b "
                      "`?88P'`88b"
                      "          "
                      "          "
                      "          ";
              },
              ....    
          },
          ....
      };
    

    Beware that such partial array initialization is a gcc extension.

  • More abstraction

    Now you may take advantage of appearance being default initialized to an NULL, and conclude that such glyph is not implemented. An allowed method becomes a trivial test, and is easily abstracted out of the font specifics.

Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144
Loading