Change struct names "struct foo -> typedef struct Foo"

laumann
Oct 7, 2022, 8:54 PM
2U7P5SFQG3AVALKMPJF4WMZE6PXIXXZYOMZ3RZKILBUJ4UMFXVIAC

Dependencies

  • [2] DKX3RO3L base32: Add encoding of hashes, print base32-encoded hashes
  • [3] WGGDK6VO change: use bincode decoder for decoding offsets
  • [4] QYRJIOYP change: separate decoding and printing of hashed struct
  • [5] PSIORGCK Update README
  • [6] JAGXXSR7 change: initial work on decoding hunks
  • [7] AEMTSEJX change: simplify readout of offsets
  • [8] FB67XX5E add argument parsing setup
  • [9] FMYCPGKD change: extract hash list decoding into reused function
  • [10] KDJUAAAL change: prefix function names with change_
  • [11] WABDGHPO hash: fix unused variable warning
  • [12] WMFNGOYT change: reduce printed noise, rework some code
  • [13] LCEKN25G change: parse authors
  • [14] B3XLVPNC Add ani.c and initial Makefile
  • [15] GCZYAURZ update README
  • [16] IS5A7VT6 change: print hashes
  • [17] FD4A7HCM base32: describe known limitations
  • [18] AHIXA5ZE Get rid of all warnings, rework init code. How do I do multiline messages?
  • [19] WQSKMNHR change: reformat line
  • [20] YG4DZB3A add representation of hash, decode dependencies
  • [21] RIWSVVAS change: decompress the 'contents' with zstd_seekable
  • [22] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change
  • [23] LVX6U4EK change: decode metadata bytes
  • [24] QEFCNNVC change: display offsets for given change file
  • [25] XTKRT6OQ format the codebase
  • [26] OBKF6SII change: decompress the hashed section too
  • [27] 733PFZJ5 prefix header guard names with ANI_
  • [28] VXGUQZIV bincode: rework so functions advance pointer
  • [29] Y26WT3ZF change: decode message, description and timestamp
  • [30] RRUEU4S3 init
  • [31] 3FT3XTJM change: support -v/-h flags
  • [32] VKLGQREY change: add base32 decode, initial deconstruction of hashed
  • [33] 4RYULBDD bincode: introduce a bincode_state struct
  • [34] WNZP5NXY Update README
  • [*] PEUS54XQ

Change contents

  • replacement in vertex.h at line 20
    [6.396][6.396:416]()
    struct position {};
    [6.396]
    [6.416]
    typedef struct {
    } Position;
  • replacement in vertex.h at line 27
    [6.539][6.539:555]()
    struct vertex {
    [6.539]
    [6.555]
    typedef struct {
  • replacement in vertex.h at line 30
    [6.621][6.621:624]()
    };
    [6.621]
    [6.624]
    } Vertex;
  • edit in init.c at line 4
    [7.339]
    [7.339]
    #include "common.h"
  • replacement in hunk.h at line 4
    [6.704][6.704:735]()
    struct local {
    char *path;
    };
    [6.704]
    [6.735]
    typedef struct {
    str path;
    } Local;
  • replacement in hunk.h at line 8
    [6.736][6.736:757]()
    enum basehunk_type {
    [6.736]
    [6.757]
    typedef enum {
  • replacement in hunk.h at line 22
    [6.961][6.961:964]()
    };
    [6.961]
    [6.964]
    } basehunktype;
  • replacement in hunk.h at line 24
    [6.965][6.965:1000]()
    struct file_move {
    char *path;
    };
    [6.965]
    [6.1000]
    typedef struct {
    str path;
    } Filemove;
  • replacement in hunk.h at line 28
    [6.1001][6.1001:1015]()
    struct edit {
    [6.1001]
    [6.1015]
    typedef struct {
  • replacement in hunk.h at line 30
    [6.1031][6.1031:1034]()
    };
    [6.1031]
    [6.1034]
    } Edit;
  • replacement in hunk.h at line 32
    [6.1035][6.1035:1056]()
    struct replacement {
    [6.1035]
    [6.1056]
    typedef struct {
  • replacement in hunk.h at line 35
    [6.1095][6.1095:1119]()
    struct local local;
    };
    [6.1095]
    [6.1119]
    Local local;
    } Replacement;
  • replacement in hunk.h at line 38
    [6.1120][6.1120:1169]()
    struct basehunk {
    enum basehunk_type hunk_type;
    [6.1120]
    [6.1169]
    typedef struct {
    basehunktype hunktype;
  • replacement in hunk.h at line 41
    [6.1178][6.1178:1263]()
    struct file_move file_move;
    struct edit edit;
    struct replacement replacement;
    [6.1178]
    [6.1263]
    Filemove filemove;
    Edit edit;
    Replacement replacement;
  • replacement in hunk.h at line 45
    [6.1272][6.1272:1275]()
    };
    [6.1272]
    [6.1275]
    } Basehunk;
  • replacement in hunk.h at line 47
    [6.1276][6.1276:1332]()
    const char *hunk_basehunk_type_str(enum basehunk_type);
    [6.1276]
    [6.1332]
    const char *hunk_basehunk_type_str(basehunktype);
  • edit in hunk.c at line 3
    [6.1413]
    [6.1413]
    #include "common.h"
  • replacement in hunk.c at line 8
    [6.1445][6.1445:1498]()
    hunk_basehunk_type_str(enum basehunk_type hunk_type)
    [6.1445]
    [6.1498]
    hunk_basehunk_type_str(basehunktype hunk_type)
  • replacement in hash.h at line 9
    [7.131][7.131:145]()
    struct hash {
    [7.131]
    [7.145]
    typedef struct {
  • replacement in hash.h at line 12
    [7.225][7.225:228]()
    };
    [7.225]
    [7.228]
    } Hash;
  • replacement in hash.h at line 14
    [7.229][7.229:248]()
    struct hash_list {
    [7.229]
    [7.248]
    typedef struct {
  • replacement in hash.h at line 16
    [7.261][7.261:287]()
    struct hash *entries;
    };
    [7.261]
    [7.287]
    Hash *entries;
    } Hashlist;
  • replacement in hash.h at line 19
    [7.288][7.288:320]()
    void hash_print(struct hash *);
    [7.288]
    [7.320]
    void hashprint(Hash *);
  • edit in hash.c at line 6
    [7.421]
    [7.421]
    #include "common.h"
  • replacement in hash.c at line 11
    [7.445][7.445:475]()
    hash_print(struct hash *hash)
    [7.445]
    [7.475]
    hashprint(Hash *hash)
  • replacement in hash.c at line 21
    [7.578][2.88:132]()
    base32_encode_hash(b32hash, hash->bytes);
    [7.578]
    [2.132]
    base32_hashencode(b32hash, hash->bytes);
  • file addition: common.h (----------)
    [36.1]
    #ifndef ANI_COMMON_H
    #define ANI_COMMON_H
    typedef char * str;
    /* Banned functions */
    /*
    * This header lists functions that have been banned from our code base,
    * because they're too easy to misuse (and even if used correctly,
    * complicate audits). Including this header turns them into compile-time
    * errors.
    */
    #define BANNED(func) sorry_##func##_is_a_banned_function
    #undef strcpy
    #define strcpy(x, y) BANNED(strcpy)
    #undef strcat
    #define strcat(x, y) BANNED(strcat)
    #undef strncpy
    #define strncpy(x, y, n) BANNED(strncpy)
    #undef strncat
    #define strncat(x, y, n) BANNED(strncat)
    #undef sprintf
    #undef vsprintf
    #define sprintf(...) BANNED(sprintf)
    #define vsprintf(...) BANNED(vsprintf)
    #undef gmtime
    #define gmtime(t) BANNED(gmtime)
    #undef localtime
    #define localtime(t) BANNED(localtime)
    #undef ctime
    #define ctime(t) BANNED(ctime)
    #undef ctime_r
    #define ctime_r(t, buf) BANNED(ctime_r)
    #undef asctime
    #define asctime(t) BANNED(asctime)
    #undef asctime_r
    #define asctime_r(t, buf) BANNED(asctime_r)
    #endif
  • replacement in change.h at line 15
    [7.307][7.307:324]()
    struct offsets {
    [7.307]
    [7.324]
    typedef struct {
  • replacement in change.h at line 23
    [7.409][7.634:637](),[7.634][7.634:637]()
    };
    [7.409]
    [7.637]
    } Offsets;
  • replacement in change.h at line 35
    [7.810][7.0:108]()
    /**
    * A list of key-value collections (BTreeMap)
    */
    struct authors {
    size_t len;
    struct author *map;
    };
    [7.810]
    [7.108]
    typedef struct {
    str key;
    str value;
    } Authorentry;
  • replacement in change.h at line 41
    [7.169][7.169:185]()
    struct author {
    [7.169]
    [7.185]
    typedef struct {
  • replacement in change.h at line 43
    [7.198][7.198:232]()
    struct author_entry *entries;
    };
    [7.198]
    [7.232]
    Authorentry *entries;
    } Author;
  • replacement in change.h at line 46
    [7.233][7.233:284]()
    struct author_entry {
    char *key;
    char *value;
    };
    [7.233]
    [7.284]
    /**
    * A list of key-value collections (BTreeMap)
    */
    typedef struct {
    size_t len;
    Author *map;
    } Authors;
  • replacement in change.h at line 54
    [7.285][7.0:173](),[7.810][7.0:173](),[7.173][7.410:477](),[7.353][7.209:212](),[7.477][7.209:212](),[7.573][7.209:212](),[7.209][7.209:212]()
    struct change_header {
    char *message; /* the "commit" message */
    char *description; /* the other undescribed part of a change */
    char *timestamp; /* yes, as a string */
    struct authors authors; /* a list of "key"="value" collections */
    };
    [7.285]
    [7.212]
    typedef struct {
    str message; /* the "commit" message */
    str description; /* the other undescribed part of a change */
    str timestamp; /* yes, as a string */
    Authors authors; /* a list of "key"="value" collections */
    } Changeheader;
  • replacement in change.h at line 68
    [7.458][7.458:474]()
    struct hashed {
    [7.458]
    [7.478]
    typedef struct {
  • replacement in change.h at line 70
    [7.542][7.538:568](),[7.538][7.538:568](),[7.568][7.543:659](),[7.659][7.661:664](),[7.817][7.661:664](),[7.661][7.661:664]()
    struct change_header header;
    struct hash_list dependencies; /* array of hashes */
    struct hash_list extra_known; /* another array of hashes */
    };
    [7.542]
    [7.664]
    Changeheader header;
    Hashlist dependencies; /* array of hashes */
    Hashlist extraknown; /* another array of hashes */
    } Hashed;
  • replacement in change.h at line 81
    [7.959][7.959:1005]()
    int decode_offsets(int fd, struct offsets *);
    [7.959]
    [7.1005]
    int decode_offsets(int fd, Offsets *);
  • edit in change.c at line 10
    [7.1192]
    [7.574]
    #include "common.h"
  • edit in change.c at line 18
    [7.618][6.2151:2152]()
  • edit in change.c at line 38
    [7.3][7.3:15](),[7.15][7.0:21](),[7.21][7.36:78](),[7.36][7.36:78](),[7.78][7.0:3](),[7.238][7.0:3]()
    static void
    cmd_change_usage()
    {
    printf("ani change [-h] [-v] <hash>\n");
    }
  • replacement in change.c at line 49
    [7.1493][7.0:51]()
    change_decode_offsets(int fd, struct offsets *off)
    [7.1493]
    [7.1537]
    change_decode_offsets(int fd, Offsets *off)
  • replacement in change.c at line 53
    [7.1587][3.0:31]()
    struct bincode_state binstat;
    [7.1587]
    [7.1603]
    Bincode binstat;
  • replacement in change.c at line 156
    [7.6][7.6:86]()
    change_decode_hashlist(struct bincode_state *binstat, struct hash_list *target)
    [7.6]
    [7.86]
    change_decode_hashlist(Bincode *binstat, Hashlist *target)
  • replacement in change.c at line 163
    [7.162][7.162:217]()
    target->entries = xmalloc(sizeof(struct hash) * len);
    [7.162]
    [7.1067]
    target->entries = xmalloc(sizeof(Hash) * len);
  • replacement in change.c at line 184
    [6.2257][6.2257:2311]()
    change_decode_position(struct bincode_state *binstat)
    [6.2257]
    [6.2311]
    change_decode_position(Bincode *binstat)
  • replacement in change.c at line 186
    [6.2313][6.2313:2380]()
    uint64_t change_position; /* FIXME this should be its own type */
    [6.2313]
    [6.2380]
    uint64_t changepos; /* FIXME this should be its own type */
  • replacement in change.c at line 189
    [6.2412][6.2412:2432]()
    struct hash hash;
    [6.2412]
    [6.2432]
    Hash hash;
  • replacement in change.c at line 202
    [6.2670][6.2670:2691]()
    hash_print(&hash);
    [6.2670]
    [6.2691]
    hashprint(&hash);
  • replacement in change.c at line 204
    [6.2694][6.2694:2789]()
    change_position = bincode_getu64(binstat);
    printf("ChangePosition(%lu)\n", change_position);
    [6.2694]
    [6.2789]
    changepos = bincode_getu64(binstat);
    printf("ChangePosition(%lu)\n", changepos);
  • replacement in change.c at line 209
    [6.2797][6.2797:2850]()
    change_decode_newedge(struct bincode_state *binstat)
    [6.2797]
    [6.2850]
    change_decode_newedge(Bincode *binstat)
  • replacement in change.c at line 226
    [6.3269][6.3269:3319]()
    change_decode_atom(struct bincode_state *binstat)
    [6.3269]
    [6.3319]
    change_decode_atom(Bincode *binstat)
  • replacement in change.c at line 255
    [6.3802][6.3802:3853]()
    change_decode_hunks(struct bincode_state *binstat)
    [6.3802]
    [6.3853]
    change_decode_hunks(Bincode *binstat)
  • replacement in change.c at line 262
    [6.3940][6.3940:3998]()
    enum basehunk_type hunk_type = bincode_getu32(binstat);
    [6.3940]
    [6.3998]
    basehunktype hunk_type = bincode_getu32(binstat);
  • replacement in change.c at line 293
    [7.1059][4.0:47]()
    uint8_t *expected_hash, struct hashed *hashed
    [7.1059]
    [7.1083]
    uint8_t *expected_hash, Hashed *hashed
  • replacement in change.c at line 302
    [7.648][7.0:31]()
    struct bincode_state binstat;
    [7.648]
    [7.2591]
    Bincode binstat;
  • replacement in change.c at line 358
    [4.358][4.358:426]()
    hashed->header.authors.map = xmalloc(sizeof(struct author) * len);
    [4.358]
    [7.513]
    hashed->header.authors.map = xmalloc(sizeof(Author) * len);
  • replacement in change.c at line 364
    [4.522][7.1290:1331](),[7.1290][7.1290:1331]()
    xmalloc(sizeof(struct author) * len);
    [4.522]
    [4.523]
    xmalloc(sizeof(Author) * len);
  • replacement in change.c at line 380
    [7.1575][4.790:847]()
    change_decode_hashlist(&binstat, &hashed->extra_known);
    [7.1575]
    [7.226]
    change_decode_hashlist(&binstat, &hashed->extraknown);
  • replacement in change.c at line 410
    [7.1722][7.1722:1772]()
    change_read_contents(int fd, struct offsets *off)
    [7.1722]
    [7.1772]
    change_read_contents(int fd, Offsets *off)
  • replacement in change.c at line 426
    [7.121][7.2233:2254](),[7.2233][7.2233:2254]()
    struct offsets off;
    [7.121]
    [7.2600]
    Offsets off;
  • replacement in change.c at line 432
    [7.2126][4.895:918]()
    struct hashed hashed;
    [7.2126]
    [7.2254]
    Hashed hashed;
  • replacement in change.c at line 447
    [7.2474][7.1430:1472]()
    base32_decode_hash(contents_hash, hash);
    [7.2474]
    [7.2474]
    base32_hashdecode(contents_hash, hash);
  • replacement in change.c at line 493
    [4.2072][4.2072:2119]()
    hash_print(&hashed.dependencies.entries[i]);
    [4.2072]
    [4.2119]
    hashprint(&hashed.dependencies.entries[i]);
  • replacement in change.c at line 495
    [4.2122][4.2122:2170]()
    for (i = 0; i < hashed.extra_known.len; i++) {
    [4.2122]
    [4.2170]
    for (i = 0; i < hashed.extraknown.len; i++) {
  • replacement in change.c at line 497
    [4.2185][4.2185:2231]()
    hash_print(&hashed.extra_known.entries[i]);
    [4.2185]
    [4.2231]
    hashprint(&hashed.extraknown.entries[i]);
  • edit in change.c at line 517
    [7.2996]
    [7.2996]
    }
    static void
    cmd_change_usage()
    {
    printf("ani change [-h] [-v] <hash>\n");
  • replacement in bincode.h at line 20
    [7.1998][7.786:809]()
    struct bincode_state {
    [7.1998]
    [7.2365]
    typedef struct {
  • replacement in bincode.h at line 23
    [7.867][7.867:870]()
    };
    [7.867]
    [7.1998]
    } Bincode;
  • replacement in bincode.h at line 31
    [7.2156][7.871:1065]()
    uint8_t bincode_getu8(struct bincode_state *);
    uint16_t bincode_getu16(struct bincode_state *);
    uint32_t bincode_getu32(struct bincode_state *);
    uint64_t bincode_getu64(struct bincode_state *);
    [7.2156]
    [7.2264]
    uint8_t bincode_getu8(Bincode *);
    uint16_t bincode_getu16(Bincode *);
    uint32_t bincode_getu32(Bincode *);
    uint64_t bincode_getu64(Bincode *);
  • replacement in bincode.h at line 44
    [7.2502][7.1066:1120](),[7.1120][6.4819:4885]()
    char *bincode_getstr(struct bincode_state *, size_t);
    void bincode_getbytes(struct bincode_state *, uint8_t *, size_t);
    [7.2502]
    [7.2543]
    char *bincode_getstr(Bincode *, size_t);
    void bincode_getbytes(Bincode *, uint8_t *, size_t);
  • edit in bincode.c at line 5
    [7.2812]
    [7.2812]
    #include "common.h"
  • replacement in bincode.c at line 11
    [7.1130][7.1130:1169]()
    bincode_getu8(struct bincode_state *s)
    [7.1130]
    [7.1169]
    bincode_getu8(Bincode *s)
  • replacement in bincode.c at line 23
    [7.2866][7.1252:1292]()
    bincode_getu16(struct bincode_state *s)
    [7.2866]
    [7.2893]
    bincode_getu16(Bincode *s)
  • replacement in bincode.c at line 37
    [7.2953][7.1339:1379]()
    bincode_getu32(struct bincode_state *s)
    [7.2953]
    [7.2980]
    bincode_getu32(Bincode *s)
  • replacement in bincode.c at line 52
    [7.3092][7.1426:1466]()
    bincode_getu64(struct bincode_state *s)
    [7.3092]
    [7.3119]
    bincode_getu64(Bincode *s)
  • replacement in bincode.c at line 69
    [7.3329][7.1513:1565]()
    bincode_getstr(struct bincode_state *s, size_t len)
    [7.3329]
    [7.3368]
    bincode_getstr(Bincode *s, size_t len)
  • replacement in bincode.c at line 85
    [6.4891][6.4891:4960]()
    bincode_getbytes(struct bincode_state *s, uint8_t *dest, size_t len)
    [6.4891]
    [7.430]
    bincode_getbytes(Bincode *s, uint8_t *dest, size_t len)
  • replacement in base32.h at line 10
    [7.1831][7.1831:1886]()
    void base32_decode_hash(uint8_t *dst, char const *in);
    [7.1831]
    [2.266]
    void base32_hashdecode(uint8_t *dst, char const *in);
  • replacement in base32.h at line 12
    [2.267][2.267:322]()
    void base32_encode_hash(char *dst, uint8_t const *in);
    [2.267]
    [7.1886]
    void base32_hashencode(char *dst, uint8_t const *in);
  • edit in base32.c at line 2
    [7.1949]
    [2.323]
    #include "common.h"
  • replacement in base32.c at line 49
    [7.3080][7.3080:3129]()
    base32_decode_hash(uint8_t *dst, char const *in)
    [7.3080]
    [7.3129]
    base32_hashdecode(uint8_t *dst, char const *in)
  • replacement in base32.c at line 88
    [2.983][2.983:1034]()
    base32_encode_hash(char *dst, uint8_t const *hash)
    [2.983]
    [2.1034]
    base32_hashencode(char *dst, uint8_t const *hash)
  • replacement in atom.h at line 10
    [6.5201][6.5201:5218]()
    enum atom_type {
    [6.5201]
    [6.5218]
    typedef enum {
  • replacement in atom.h at line 13
    [6.5241][6.5241:5244]()
    };
    [6.5241]
    [6.5244]
    } atomtype;
  • replacement in atom.h at line 15
    [6.5245][6.5245:5342]()
    struct new_vertex {
    struct hash up_context; /* FIXME Option<Hash> */
    struct hash down_context;
    [6.5245]
    [6.5342]
    typedef struct {
    Hash upcontext; /* FIXME Option<Hash> */
    Hash downcontext;
  • replacement in atom.h at line 22
    [6.5530][6.5530:5533]()
    };
    [6.5530]
    [6.5533]
    } Newvertex;
    typedef struct {
    } Edgemap;
  • replacement in atom.h at line 28
    [6.5548][6.5548:5575]()
    enum atom_type atom_type;
    [6.5548]
    [6.5575]
    atomtype atomtype;
  • replacement in atom.h at line 30
    [6.5584][6.5584:5616]()
    struct new_vertex new_vertex;
    [6.5584]
    [6.5616]
    Newvertex newvertex;
    Edgemap edgemap;
  • edit in ani.c at line 4
    [7.1130]
    [7.1130]
    #include "common.h"
  • replacement in ani.c at line 17
    [7.3226][7.1173:1186](),[7.174][7.1173:1186]()
    struct cmd {
    [7.3226]
    [7.1186]
    typedef struct {
  • replacement in ani.c at line 20
    [7.1237][7.1237:1240]()
    };
    [7.1237]
    [7.1240]
    } Cmd;
  • replacement in ani.c at line 22
    [7.1241][7.1241:1274]()
    static struct cmd commands[] = {
    [7.1241]
    [7.1274]
    static Cmd commands[] = {
  • replacement in ani.c at line 37
    [7.1354][7.1354:1374]()
    static struct cmd *
    [7.1354]
    [7.1374]
    static Cmd *
  • replacement in ani.c at line 41
    [7.1408][7.1408:1424]()
    struct cmd *p;
    [7.1408]
    [7.1424]
    Cmd *p;
  • replacement in ani.c at line 54
    [7.350][7.1606:1628](),[7.1606][7.1606:1628]()
    struct cmd *command;
    [7.350]
    [7.1628]
    Cmd *command;
  • edit in README.md at line 34
    [5.327]
    [7.0]
    ### Header files
    Simple rule: include files should never include include files (see
    [pikestyle][pikestyle]). Instead they state (in comments or implicitly)
    what files they need to have included first, the problem of deciding which
    files to include is pushed to the user. (vendored header files are exempted
    from this rule to make it easier to update a vendored dependency.)
  • replacement in README.md at line 43
    [7.1][5.328:346]()
    ### Include files
    [7.1]
    [7.278]
    In addition, system include files should be grouped first before any user
    include files, and the first user include file _must_ be common.h. All .c
    files in this project _must_ include common.h As an example, this is the
    correct way to include files:
    #include <stdlib.h>
    #include <stdint.h>
    #include <stdio.h>
  • replacement in README.md at line 52
    [7.279][7.279:505]()
    Simple rule: include files should never include include files. Instead they
    state (in comments or implicitly) what files they need to have included first,
    the problem of deciding which files to include is pushed to the user.
    [7.279]
    [7.505]
    #include "common.h"
    #include "atom.h"
    Prefer to leave a blank line in between the system includes and user includes.
    ### Type declarations
  • replacement in README.md at line 59
    [7.506][5.347:423]()
    [ the above is listed straight from pikestyle, see [pikestyle][pikestyle] ]
    [7.506]
    [7.571]
    Structs are the only types that should be declared with a capital
    letter. Simple types should be declared with lowercase letters.