aboutsummaryrefslogtreecommitdiff
path: root/ls_minify_identgen.h
blob: 27272bb9f21b245463e1ee7978d4c020a7c4c921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This software disclaims copyright. Do what you want with it. Be gay, do
// crime. Originally written by Alexis Lockwood in 2021. Ⓐ

#ifndef LS_MINIFY_IDENTGEN_H
#define LS_MINIFY_IDENTGEN_H

// --- DEPENDENCIES ------------------------------------------------------------

// Supporting modules

// Standard headers
#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>
#include <stdio.h>

// --- PUBLIC MACROS -----------------------------------------------------------
// --- PRIVATE DATATYPES -------------------------------------------------------
// --- PUBLIC DATATYPES --------------------------------------------------------
// --- PUBLIC CONSTANTS --------------------------------------------------------
// --- PUBLIC VARIABLES --------------------------------------------------------
// --- PUBLIC FUNCTIONS --------------------------------------------------------

/// Generate a unique minimized identifier based on a long-form identifier.
/// If the given identifier has already been minified once, it will always
/// return the same value.
char const * ls_minify_identgen(char const * ident);

/// Emit an idents table for later un-minification
///
/// This emits a long special REM-comment. This starts with an unmistakable
/// magic number consisting of "MIT" (Minifier Ident Table) with each byte
/// or'd with 0x80. Then, each ident is emitted in the order they were
/// originally passed to ls_minify_identgen(), delimited by 0x80-or'ing the
/// first byte of each.
void ls_minify_emit_mit(FILE * f);

/// Load an idents table emitted by ls_minify_emit_mit().
///
/// Loads the internal hash table "backwards" so that ls_minify_identgen()
/// will un-minify.
///
/// @param code - source code to search and load from
/// @param plen - length of code. Will be modified to the length of the code
///    up to but not including the MIT.
///
/// @return whether a table was found
bool ls_minify_load_mit(uint8_t const * code, size_t * plen);

#endif // !defined(LS_MINIFY_IDENTGEN_H)