root/paper-tape-project/trunk/schriften/papertapefont.h

Revision 14, 4.6 kB (checked in by sven, 4 years ago)

Added HTML documentation (this shall be the homepage of the project, in development) and bufxies for
the papertapefont structures.

Line 
1/**
2 * The Paper Tape Project -- Font subproject
3 * PaperTapeFont C Library
4 *
5 * (c) 2008 Sven Köppel
6 *
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the GNU General
9 * Public License as published by the Free Software
10 * Foundation; either version 3 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY; without even the
15 * implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General
20 * Public License along with this program; if not, see
21 * http://www.gnu.org/licenses/.
22 *
23 **/
24
25#ifndef __PAPERTAPE_FONT_H__
26#define __PAPERTAPE_FONT_H__
27
28#include <stdlib.h>
29#include <stdio.h>
30
31/**
32 * We use "char" in three situations:
33 *   1. As normal (ASCII) characters/letters, like in    char ascii_id = 'a';
34 *   2. As strings, like in                             char* line = "hello";
35 *   3. As byte arrays, like in  unsigned char *bytes = { 0x12, 0x23, 0x45 };
36 *
37 * To make this a bit more clearer, here is a quite common typedef:
38 **/
39typedef unsigned char   byte_t;
40
41/**
42 * This is the structure of one link from the linked list. It represents exactly
43 * one character, how it is punched on the papertape. It's called
44 * PAPERTAPE_FONT_CHAR everywhere in the program, by using a typedef.
45 *
46 * The PAPERTAPE_FONT struct itself is nothing else than the start element of the
47 * linked list. Therefore it's just the same data structure.
48 **/
49struct _papertape_font_char {
50        char ascii_id;
51        char *name;
52        byte_t* bytes;
53        int bytes_n;
54
55        struct _papertape_font_char* next;
56};
57
58typedef struct _papertape_font_char PAPERTAPE_FONT_CHAR;
59typedef struct _papertape_font_char PAPERTAPE_FONT;
60
61/**
62 * These defines are the names which are used in the Papertape font files
63 * for the specific special characters.
64 **/
65#define PAPERTAPE_FONT_CHARACTER_SPACING_NAME   "character_spacing"
66#define PAPERTAPE_FONT_WHITE_SPACE_NAME         "white_space"
67
68/**
69 * The content of this definition is written at the very first lines at every
70 * papertape font file which is changed by the routines.
71 *
72 **/
73#define PAPERTAPE_FONT_WRITE_FIRST_LINES \
74        "The Paper Tape Project -- PAPERTAPE_FONT file.\n" \
75        "The content of this file describes a paper tape font. You can edit it\n" \
76        "with a text editor. Lines like this ones are comments.\n" \
77        "See http://dev.technikum29.de/svn/paper-tape-project/\n" \
78        "See this small key how the document is structured:"\
79        "\n" \
80        " bits     |identification\n" \
81        " 123.45678|char/string\n" \
82        "|   .     |\n"
83
84/**
85 * These definitions define characters which are used when writing papertape
86 * files. They should not be changed unless the data format changes one day.
87 **/
88#define PAPERTAPE_FONT_WRITE_LOGICAL_1   '+'
89#define PAPERTAPE_FONT_FEED_HOLE         '.'
90#define PAPERTAPE_FONT_BORDER            '|'
91/**
92 * This is the magic id. It's quite very important.
93 *
94 **/
95#define PAPERTAPE_FONT_SPECIAL_ID        (" =")
96
97/**
98 * The default schematics used for import and export. It should contain
99 * the most important characters, like /[0-9a-z]/i (as regex)
100 **/
101#define PAPERTAPE_FONT_SCHEMATICS_DEFAULT "abcdefghijklmnopqrstuvwxyz0123456789"
102
103
104// Create and load functions
105#define papertape_font_new()    ((PAPERTAPE_FONT*)malloc(sizeof(PAPERTAPE_FONT)))
106PAPERTAPE_FONT* papertape_font_new_from_file(const char* filename);
107void papertape_font_load_file(PAPERTAPE_FONT* font, FILE* fh);
108void papertape_font_load_schematics(PAPERTAPE_FONT* font, const char *schematics, const byte_t *contents, int content_len);
109void papertape_font_destroy(PAPERTAPE_FONT* font);
110
111
112// Read functions
113byte_t* papertape_font_get_label(PAPERTAPE_FONT* font, const char* string, int *size);
114int papertape_font_string_is_printable(PAPERTAPE_FONT *font, const char* string);
115void papertape_font_dump(PAPERTAPE_FONT *font, FILE* fh);
116PAPERTAPE_FONT_CHAR* papertape_font_low_get_char(PAPERTAPE_FONT* font, char ascii_id);
117PAPERTAPE_FONT_CHAR* papertape_font_low_get_special(PAPERTAPE_FONT* font, const char* name);
118
119// Write functions
120PAPERTAPE_FONT_CHAR* papertape_font_set_char(PAPERTAPE_FONT* font, char ascii_id, const byte_t* bytes, int bytes_n);
121PAPERTAPE_FONT_CHAR* papertape_font_set_special(PAPERTAPE_FONT* font, const char* name, const byte_t* bytes, int bytes_n);
122int papertape_font_del_char(PAPERTAPE_FONT* font, char ascii_id);
123int papertape_font_del_special(PAPERTAPE_FONT* font, const char* name);
124int papertape_font_write_to_file(PAPERTAPE_FONT* font, FILE *fh);
125
126
127#endif /* __PAPERTAPE_FONT_H__ */
Note: See TracBrowser for help on using the browser.
© 2008 - 2010 Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License