From 63680c39395df87cb60cd6a096ffc48d72675b18 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Wed, 9 Aug 2017 23:03:56 +0430 Subject: [PATCH] eqn: more comments --- box.c | 1 + eqn.c | 9 +++++++++ tok.c | 22 ++++++++++------------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/box.c b/box.c index 112fa3a..057a3f2 100644 --- a/box.c +++ b/box.c @@ -1,3 +1,4 @@ +/* equation boxes */ #include #include #include diff --git a/eqn.c b/eqn.c index 389030a..c7f3b08 100644 --- a/eqn.c +++ b/eqn.c @@ -133,6 +133,7 @@ static int typenum(char *s) return T_ORD; } +/* read chartype command arguments and perform it */ static void eqn_chartype(void) { char gl[GNLEN], type[NMLEN]; @@ -142,6 +143,7 @@ static void eqn_chartype(void) def_typeput(gl, typenum(type)); } +/* read breakcost command arguments and perform it */ static void eqn_breakcost(void) { char tok[NMLEN]; @@ -153,6 +155,7 @@ static void eqn_breakcost(void) def_brcostput(type, cost); } +/* read general eqn commands */ static int eqn_commands(void) { char var[LNLEN]; @@ -209,6 +212,7 @@ static int eqn_commands(void) return 1; } +/* read user-specified spaces */ static int eqn_gaps(struct box *box, int szreg) { if (!tok_jmp("~")) { @@ -228,6 +232,7 @@ static int eqn_gaps(struct box *box, int szreg) return 1; } +/* return the font of the given token type */ static char *tok_font(int tok, char *fn) { if (fn && fn[0]) @@ -237,6 +242,7 @@ static char *tok_font(int tok, char *fn) return grfont; } +/* check the next token */ static void tok_expect(char *s) { if (tok_jmp(s)) { @@ -246,6 +252,7 @@ static void tok_expect(char *s) } } +/* read pile command */ static void eqn_pile(struct box *box, int sz0, char *fn0, int adj) { struct box *pile[NPILES] = {NULL}; @@ -265,6 +272,7 @@ static void eqn_pile(struct box *box, int sz0, char *fn0, int adj) box_free(pile[i]); } +/* read matrix command */ static void eqn_matrix(struct box *box, int sz0, char *fn0) { struct box *cols[NPILES][NPILES] = {{NULL}}; @@ -309,6 +317,7 @@ static void eqn_matrix(struct box *box, int sz0, char *fn0) box_free(cols[i][j]); } +/* return nonzero if fn is italic */ static int italic(char *fn) { return (!strcmp("I", fn) || !strcmp("2", fn) || diff --git a/tok.c b/tok.c index 319293f..7a09f5a 100644 --- a/tok.c +++ b/tok.c @@ -265,19 +265,17 @@ void tok_eqnout(char *s) /* return the length of a utf-8 character based on its first byte */ static int utf8len(int c) { - if (c > 0 && c <= 0x7f) + if (~c & 0x80) + return c > 0; + if (~c & 0x40) return 1; - if (c >= 0xfc) - return 6; - if (c >= 0xf8) - return 5; - if (c >= 0xf0) - return 4; - if (c >= 0xe0) - return 3; - if (c >= 0xc0) + if (~c & 0x20) return 2; - return c != 0; + if (~c & 0x10) + return 3; + if (~c & 0x08) + return 4; + return 1; } /* return the type of a token */ @@ -425,7 +423,7 @@ int tok_type(void) return tok[0] ? tok_curtype : 0; } -/* return nonzero if current token is a chops the equation */ +/* return nonzero if current token chops the equation */ int tok_chops(int soft) { if (!tok_get() || tok_curtype == T_KEYWORD) -- 2.11.4.GIT