slw2gmi

Конвертор из slweb-а у Џемини
git clone https://git.sr.ht/~strahinja/slw2gmi
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

defs.h (4030B)


      1 /* This program is licensed under the terms of GNU GPL v3 or (at your option)
      2  * any later version. Copyright (C) 2021-2024  Страхиња Радић.
      3  * See the file LICENSE for exact copyright and license details. */
      4 
      5 #ifndef __DEFS_H
      6 #define __DEFS_H
      7 
      8 #include <ctype.h>
      9 #include <dirent.h>
     10 #include <errno.h>
     11 #include <signal.h>
     12 #include <stdarg.h>
     13 #include <stdio.h>
     14 #include <stdlib.h>
     15 #include <stdint.h>
     16 #include <string.h>
     17 #include <sys/stat.h>
     18 #include <sys/types.h>
     19 #include <sys/wait.h>
     20 #include <unistd.h>
     21 
     22 #ifndef strlcpy
     23 size_t strlcpy(char* dst, const char* src, size_t dsize);
     24 #endif
     25 #ifndef strlcat
     26 size_t strlcat(char* dst, const char* src, size_t dsize);
     27 #endif
     28 
     29 #include "version.h"
     30 #include "utf8.h"
     31 
     32 #define COPYRIGHTYEAR "2021-2024"
     33 #define MADEBY_URL    "gemini://gemini.strahinja.org/slw2gmi/"
     34 
     35 #define BUFSIZE	      1024
     36 #define KEYSIZE	      256
     37 #define SMALL_ARGSIZE 256
     38 #define DATEBUFSIZE   12
     39 
     40 static const char timestamp_format[]	 = "y-m-d";
     41 static const char timestamp_output_ext[] = ".gmi";
     42 
     43 static const char CMD_GIT_LOG[]	      = "xargs";
     44 static const char* CMD_GIT_LOG_ARGS[] = {"xargs", "-I{}", "git", "log", "-1",
     45 	"--pretty=format:{} %h %ci (%cn) %d", NULL};
     46 
     47 #define ALL(var, mask) (((var) & (mask)) == (mask))
     48 #define ANY(var, mask) (((var) & (mask)) != 0)
     49 #define IN(var, mask)  ALL(var, mask)
     50 
     51 #define MIN(a, b) ((a < b) ? (a) : (b))
     52 
     53 typedef unsigned char UBYTE;
     54 typedef unsigned long ULONG;
     55 typedef unsigned long long ULLONG;
     56 
     57 typedef enum {
     58 	CMD_NONE,
     59 	CMD_BODY_ONLY,
     60 	CMD_BASEDIR,
     61 	CMD_HELP,
     62 	CMD_LINK_PREFIX,
     63 	CMD_VERSION,
     64 	CMD_FULL_VERSION
     65 } Command;
     66 
     67 typedef struct {
     68 	u8* key;
     69 	u8* value;
     70 	size_t value_size;
     71 } KeyValue;
     72 
     73 typedef int (*csv_callback_t)(FILE* output, u8** csv_header, u8** csv_register);
     74 typedef int (*tsv_callback_t)(FILE* output, u8** tsv_header, u8** tsv_register);
     75 
     76 #ifdef __GNUC__
     77 #pragma GCC diagnostic push
     78 #pragma GCC diagnostic ignored "-Wunused-const-variable"
     79 #endif
     80 #define MAX_HEADING_LEVEL 4
     81 #define MAX_CSV_REGISTERS 9
     82 #define MAX_TSV_REGISTERS 9
     83 
     84 #define ST_NONE		       0
     85 #define ST_YAML		       1
     86 #define ST_YAML_VAL	       ((ULLONG)1 << 1)
     87 #define ST_PARA_OPEN	       ((ULLONG)1 << 2)
     88 #define ST_TAG		       ((ULLONG)1 << 3)
     89 #define ST_HEADING	       ((ULLONG)1 << 4)
     90 #define ST_HEADING_TEXT	       ((ULLONG)1 << 5)
     91 #define ST_BOLD		       ((ULLONG)1 << 6)
     92 #define ST_ITALIC	       ((ULLONG)1 << 7)
     93 #define ST_PRE		       ((ULLONG)1 << 8)
     94 #define ST_CODE		       ((ULLONG)1 << 9)
     95 #define ST_BLOCKQUOTE	       ((ULLONG)1 << 10)
     96 #define ST_LINK		       ((ULLONG)1 << 11)
     97 #define ST_LINK_SECOND_ARG     ((ULLONG)1 << 12)
     98 #define ST_LINK_SECOND_ARG_END ((ULLONG)1 << 13)
     99 #define ST_LINK_SPAN	       ((ULLONG)1 << 14)
    100 #define ST_LINK_MACRO	       ((ULLONG)1 << 15)
    101 #define ST_IMAGE	       ((ULLONG)1 << 16)
    102 #define ST_IMAGE_SECOND_ARG    ((ULLONG)1 << 17)
    103 #define ST_MACRO_BODY	       ((ULLONG)1 << 18)
    104 #define ST_CSV_BODY	       ((ULLONG)1 << 19)
    105 #define ST_TSV_BODY	       ((ULLONG)1 << 20)
    106 #define ST_HTML_TAG	       ((ULLONG)1 << 21)
    107 #define ST_KBD		       ((ULLONG)1 << 22)
    108 #define ST_LIST		       ((ULLONG)1 << 23)
    109 #define ST_NUMLIST	       ((ULLONG)1 << 24)
    110 #define ST_FOOTNOTE	       ((ULLONG)1 << 25)
    111 #define ST_FOOTNOTE_TEXT       ((ULLONG)1 << 26)
    112 #define ST_INLINE_FOOTNOTE     ((ULLONG)1 << 27)
    113 #define ST_FORMULA	       ((ULLONG)1 << 28)
    114 #define ST_DISPLAY_FORMULA     ((ULLONG)1 << 29)
    115 #define ST_TABLE_HEADER	       ((ULLONG)1 << 30)
    116 #define ST_TABLE_LINE	       ((ULLONG)1 << 31)
    117 #define ST_TABLE	       ((ULLONG)1 << 32)
    118 #define ST_STRIKE	       ((ULLONG)1 << 33)
    119 #define ST_SUMMARY	       ((ULLONG)1 << 34)
    120 #define ST_INCDIR	       ((ULLONG)1 << 35)
    121 #define ST_ENT		       ((ULLONG)1 << 36)
    122 
    123 #define ST_CS_NONE	    0
    124 #define ST_CS_HEADER	    1
    125 #define ST_CS_REGISTER	    (1 << 2)
    126 #define ST_CS_QUOTE	    (1 << 3)
    127 #define ST_CS_COND	    (1 << 4)
    128 #define ST_CS_COND_NONEMPTY (1 << 5)
    129 #define ST_CS_COND_EMPTY    (1 << 6)
    130 #define ST_CS_ESCAPE	    (1 << 7)
    131 #ifdef __GNUC__
    132 #pragma GCC diagnostic pop
    133 #endif
    134 
    135 #endif /* __DEFS_H */