Changeset 14 in projects


Ignore:
Timestamp:
Sep 7, 2008, 4:20:56 PM (11 years ago)
Author:
sven
Message:

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

Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • schriften/papertapefont.c

    r13 r14  
    144144
    145145                // if we are still at the same byte like the last one...
    146                 if(new_character || ascii_id == last_ascii_id ||
     146                if(ascii_id == last_ascii_id || //new_character ||
    147147                   ( ascii_id == 0 && (strcmp(name, last_name) == 0) )
    148                    ) {
     148                  ) {
    149149                        //fprintf(stderr, "Save line for 0x%x as no. %i\n", ascii_id, bytes_n+1);
    150150                        // ...then add this byte to the current char byte array
     
    152152                             // only store if enough place in bytes[] array
    153153                             bytes[bytes_n++] = papertape_font_line2byte(line);
    154                         // leave "last_" values as they are, because they haven't changed anyway
     154                        // first byte stored, no more new character
     155                        new_character = 0;
    155156                } else {
    156157                        // we are at a new char, so let's push the last char to the list
     
    168169
    169170                // Don't force to read in any more.
    170                 if(last_ascii_id == ascii_id)
    171                         new_character = 0;
     171                //if(last_ascii_id == ascii_id)
     172                //      new_character = 0;
    172173                last_ascii_id = ascii_id;
    173174                strcpy(last_name, name);
     
    267268        // allocate the new character structure
    268269        PAPERTAPE_FONT_CHAR *buf;
    269         buf = malloc(sizeof(PAPERTAPE_FONT_CHAR));
     270        buf = (PAPERTAPE_FONT_CHAR*) malloc(sizeof(PAPERTAPE_FONT_CHAR));
    270271
    271272        // copy all values to structure
    272273        buf->ascii_id = 0x0;
    273274        buf->bytes_n = bytes_n;
    274         buf->bytes = malloc(bytes_n);
     275        buf->bytes = (byte_t*) malloc(bytes_n);
    275276        memcpy(buf->bytes, bytes, bytes_n);
    276         buf->name = malloc(strlen(name));
     277        buf->name = (char*) malloc(strlen(name));
    277278        strcpy(buf->name, name);
    278279       
     
    303304        // allocate the new character structure
    304305        PAPERTAPE_FONT_CHAR *buf;
    305         buf = malloc(sizeof(PAPERTAPE_FONT_CHAR));
     306        buf = (PAPERTAPE_FONT_CHAR*) malloc(sizeof(PAPERTAPE_FONT_CHAR));
    306307
    307308        // copy all values to structure
    308309        buf->ascii_id = ascii_id;
    309310        buf->bytes_n = bytes_n;
    310         buf->bytes = malloc(bytes_n);
     311        buf->bytes = (byte_t*) malloc(bytes_n);
    311312        memcpy(buf->bytes, bytes, bytes_n);
    312313        buf->name = NULL;
     
    454455        byte_t* output;
    455456        int output_pos;  // current position in output array
    456         int clen = strlen(string)*2 -1; // length of characters stack array
     457        int clen = strlen(string)*2 - 1; // length of characters stack array
    457458        // dynamic stack arrays are ISO C99, compare http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variable-Length.html
    458459        PAPERTAPE_FONT_CHAR *characters[ clen ];
     
    466467                else
    467468                        characters[cpos] = papertape_font_low_get_char(font, string[x]);
     469
    468470                if(characters[cpos] == NULL) {
    469                         fprintf(stderr, "papertape_font_get_label: Character \"%c\" in \"%s\" not printable\n",
    470                                 string[x], string);
     471                        fprintf(stderr, "papertape_font_get_label: Character \"%c\" at position %i in \"%s\" not printable\n",
     472                                string[x], x+1, string);
     473                        // tell the malloc loop (see below) to loop not over the complete
     474                        // characters[] array, because one character is missing. That is,
     475                        // pop the array for 1 value.
     476                        clen--;
     477                        // don't increase cpos, we want to overwrite this character in the
     478                        // next loop.
    471479                        continue;
    472                 }
    473 
    474                 size += characters[cpos]->bytes_n;
     480                } else if(characters[cpos]->bytes == NULL) {
     481                        // for all possibilities... this character is empty.
     482                        // Make sure bytes_n is it, too.
     483                        if(characters[cpos]->bytes_n != 0)
     484                                fprintf(stderr, "papertape_font_get_label: Bad font parsed! Character 0x%x (%c) not really empty!\n",
     485                                        characters[cpos]->ascii_id, characters[cpos]->ascii_id);
     486                }
     487
     488                *size += characters[cpos]->bytes_n;
    475489                cpos++;
    476490               
     
    482496                }
    483497        }
    484 
     498       
    485499        // now malloc the output byte array and generate it
    486         output = malloc(*size);
    487         for(cpos=0,output_pos=0; cpos < clen; cpos++, output_pos += characters[cpos]->bytes_n)
    488                 memcpy(output+output_pos, characters[cpos], characters[cpos]->bytes_n);
     500        output = (byte_t*) malloc(*size);
     501        for(cpos=0,output_pos=0; cpos < clen && output_pos < *size; output_pos += characters[cpos++]->bytes_n)
     502                memcpy(output+output_pos, characters[cpos]->bytes, characters[cpos]->bytes_n);
    489503
    490504        // we are done.
     
    636650
    637651        if(total_allocated == 0)
    638                 str = malloc(1); // something empty. Just to be not NULL...
     652                str = (byte_t*) malloc(1); // something empty. Just to be not NULL...
    639653        //str[total_bytes] = '\0'; // wenns ein string wäre.
    640654
     
    751765                }
    752766
    753                 bytes = papertape_font_get_label(font, argc == 4 ? argv[3] : PAPERTAPE_FONT_SCHEMATICS_DEFAULT, &size);
    754                 fwrite(bytes, size, sizeof(byte_t), stdout);
     767                bytes = papertape_font_get_label(font, argc == 4 ? argv[2] : PAPERTAPE_FONT_SCHEMATICS_DEFAULT, &size);
     768                fwrite(bytes, size, sizeof(byte_t), stdout);   
    755769                return 0;
    756770        } else if(strcasecmp(argv[1], "set") == 0 || strcasecmp(argv[1], "del") == 0) {
  • schriften/papertapefont.h

    r13 r14  
    103103
    104104// Create and load functions
    105 #define papertape_font_new()    (malloc(sizeof(PAPERTAPE_FONT)))
     105#define papertape_font_new()    ((PAPERTAPE_FONT*)malloc(sizeof(PAPERTAPE_FONT)))
    106106PAPERTAPE_FONT* papertape_font_new_from_file(const char* filename);
    107107void papertape_font_load_file(PAPERTAPE_FONT* font, FILE* fh);
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • 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