Merge pull request #1479 from Pyrohh/fix_comments_and_use_stdbool

{farsi.c,arabic.c}: Fix comments and use stdbool
This commit is contained in:
Justin M. Keyes 2014-11-16 20:24:31 -05:00
commit 0fcb867981
2 changed files with 76 additions and 100 deletions

View File

@ -96,7 +96,6 @@
// i -> initial // i -> initial
// m -> medial // m -> medial
// f -> final // f -> final
//
#define a_s_FATHATAN 0xfe70 #define a_s_FATHATAN 0xfe70
#define a_m_TATWEEL_FATHATAN 0xfe71 #define a_m_TATWEEL_FATHATAN 0xfe71
#define a_s_DAMMATAN 0xfe72 #define a_s_DAMMATAN 0xfe72
@ -246,7 +245,8 @@
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "arabic.c.generated.h" # include "arabic.c.generated.h"
#endif #endif
// Returns True if c is an ISO-8859-6 shaped ARABIC letter (user entered).
// Returns true if c is an ISO-8859-6 shaped ARABIC letter (user entered).
static bool A_is_a(int cur_c) static bool A_is_a(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
@ -293,7 +293,7 @@ static bool A_is_a(int cur_c)
return false; return false;
} }
// Returns True if c is an Isolated Form-B ARABIC letter // Returns true if c is an Isolated Form-B ARABIC letter
static bool A_is_s(int cur_c) static bool A_is_s(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
@ -339,7 +339,7 @@ static bool A_is_s(int cur_c)
return false; return false;
} }
// Returns True if c is a Final shape of an ARABIC letter // Returns true if c is a Final shape of an ARABIC letter
static bool A_is_f(int cur_c) static bool A_is_f(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
@ -1259,12 +1259,11 @@ static int chg_c_f2m(int cur_c)
tempc = a_m_YEH; tempc = a_m_YEH;
break; break;
/* NOTE: these encodings are multi-positional, no ? // NOTE: these encodings are multi-positional, no ?
case a_f_LAM_ALEF_MADDA_ABOVE: // case a_f_LAM_ALEF_MADDA_ABOVE:
case a_f_LAM_ALEF_HAMZA_ABOVE: // case a_f_LAM_ALEF_HAMZA_ABOVE:
case a_f_LAM_ALEF_HAMZA_BELOW: // case a_f_LAM_ALEF_HAMZA_BELOW:
case a_f_LAM_ALEF: // case a_f_LAM_ALEF:
*/
default: default:
tempc = 0; tempc = 0;
} }
@ -1272,9 +1271,7 @@ static int chg_c_f2m(int cur_c)
return tempc; return tempc;
} }
/* // Change shape - from Combination (2 char) to an Isolated.
* Change shape - from Combination (2 char) to an Isolated
*/
static int chg_c_laa2i(int hid_c) static int chg_c_laa2i(int hid_c)
{ {
int tempc; int tempc;
@ -1303,9 +1300,7 @@ static int chg_c_laa2i(int hid_c)
return tempc; return tempc;
} }
/* // Change shape - from Combination-Isolated to Final.
* Change shape - from Combination-Isolated to Final
*/
static int chg_c_laa2f(int hid_c) static int chg_c_laa2f(int hid_c)
{ {
int tempc; int tempc;
@ -1334,9 +1329,7 @@ static int chg_c_laa2f(int hid_c)
return tempc; return tempc;
} }
/* // Do "half-shaping" on character "c". Return zero if no shaping.
* Do "half-shaping" on character "c". Return zero if no shaping.
*/
static int half_shape(int c) static int half_shape(int c)
{ {
if (A_is_a(c)) { if (A_is_a(c)) {
@ -1349,27 +1342,25 @@ static int half_shape(int c)
return 0; return 0;
} }
/* // Do Arabic shaping on character "c". Returns the shaped character.
* Do Arabic shaping on character "c". Returns the shaped character. // out: "ccp" points to the first byte of the character to be shaped.
* out: "ccp" points to the first byte of the character to be shaped. // in/out: "c1p" points to the first composing char for "c".
* in/out: "c1p" points to the first composing char for "c". // in: "prev_c" is the previous character (not shaped)
* in: "prev_c" is the previous character (not shaped) // in: "prev_c1" is the first composing char for the previous char
* in: "prev_c1" is the first composing char for the previous char // (not shaped)
* (not shaped) // in: "next_c" is the next character (not shaped).
* in: "next_c" is the next character (not shaped).
*/
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
int next_c) int next_c)
{ {
/* Deal only with Arabic character, pass back all others */ // Deal only with Arabic character, pass back all others
if (!A_is_ok(c)) { if (!A_is_ok(c)) {
return c; return c;
} }
/* half-shape current and previous character */ // half-shape current and previous character
int shape_c = half_shape(prev_c); int shape_c = half_shape(prev_c);
/* Save away current character */ // Save away current character
int curr_c = c; int curr_c = c;
int curr_laa = A_firstc_laa(c, *c1p); int curr_laa = A_firstc_laa(c, *c1p);
@ -1383,7 +1374,7 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
curr_c = chg_c_laa2i(curr_laa); curr_c = chg_c_laa2i(curr_laa);
} }
/* Remove the composing character */ // Remove the composing character
*c1p = 0; *c1p = 0;
} else if (!A_is_valid(prev_c) && A_is_valid(next_c)) { } else if (!A_is_valid(prev_c) && A_is_valid(next_c)) {
curr_c = chg_c_a2i(c); curr_c = chg_c_a2i(c);
@ -1397,8 +1388,8 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
curr_c = chg_c_a2s(c); curr_c = chg_c_a2s(c);
} }
/* Sanity check -- curr_c should, in the future, never be 0. // Sanity check -- curr_c should, in the future, never be 0.
* We should, in the future, insert a fatal error here. */ // We should, in the future, insert a fatal error here.
if (curr_c == NUL) { if (curr_c == NUL) {
curr_c = c; curr_c = c;
} }
@ -1406,12 +1397,12 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
if ((curr_c != c) && (ccp != NULL)) { if ((curr_c != c) && (ccp != NULL)) {
char_u buf[MB_MAXBYTES + 1]; char_u buf[MB_MAXBYTES + 1];
/* Update the first byte of the character. */ // Update the first byte of the character
(*mb_char2bytes)(curr_c, buf); (*mb_char2bytes)(curr_c, buf);
*ccp = buf[0]; *ccp = buf[0];
} }
/* Return the shaped character */ // Return the shaped character
return curr_c; return curr_c;
} }
@ -1441,11 +1432,9 @@ bool arabic_maycombine(int two)
return false; return false;
} }
/* // A_firstc_laa returns first character of LAA combination if it ex.ists
* A_firstc_laa returns first character of LAA combination if it exists // in: "c" base character
* in: "c" base character // in: "c1" first composing character
* in: "c1" first composing character
*/
static int A_firstc_laa(int c, int c1) static int A_firstc_laa(int c, int c1)
{ {
if ((c1 != NUL) && (c == a_LAM) && !A_is_harakat(c1)) { if ((c1 != NUL) && (c == a_LAM) && !A_is_harakat(c1)) {
@ -1454,19 +1443,15 @@ static int A_firstc_laa(int c, int c1)
return 0; return 0;
} }
/* // A_is_harakat returns true if 'c' is an Arabic Harakat character.
* A_is_harakat returns TRUE if 'c' is an Arabic Harakat character // (harakat/tanween)
* (harakat/tanween)
*/
static bool A_is_harakat(int c) static bool A_is_harakat(int c)
{ {
return c >= a_FATHATAN && c <= a_SUKUN; return c >= a_FATHATAN && c <= a_SUKUN;
} }
/* // A_is_iso returns true if 'c' is an Arabic ISO-8859-6 character.
* A_is_iso returns TRUE if 'c' is an Arabic ISO-8859-6 character // (alphabet/number/punctuation)
* (alphabet/number/punctuation)
*/
static bool A_is_iso(int c) static bool A_is_iso(int c)
{ {
return (c >= a_HAMZA && c <= a_GHAIN) || return (c >= a_HAMZA && c <= a_GHAIN) ||
@ -1474,10 +1459,8 @@ static bool A_is_iso(int c)
c == a_MINI_ALEF; c == a_MINI_ALEF;
} }
/* // A_is_formb returns true if 'c' is an Arabic 10646-1 FormB character.
* A_is_formb returns TRUE if 'c' is an Arabic 10646-1 FormB character // (alphabet/number/punctuation)
* (alphabet/number/punctuation)
*/
static bool A_is_formb(int c) static bool A_is_formb(int c)
{ {
return (c >= a_s_FATHATAN && c <= a_s_DAMMATAN) || return (c >= a_s_FATHATAN && c <= a_s_DAMMATAN) ||
@ -1486,27 +1469,21 @@ static bool A_is_formb(int c)
c == a_BYTE_ORDER_MARK; c == a_BYTE_ORDER_MARK;
} }
/* // A_is_ok returns true if 'c' is an Arabic 10646 (8859-6 or Form-B).
* A_is_ok returns TRUE if 'c' is an Arabic 10646 (8859-6 or Form-B)
*/
static bool A_is_ok(int c) static bool A_is_ok(int c)
{ {
return A_is_iso(c) || A_is_formb(c); return A_is_iso(c) || A_is_formb(c);
} }
/* // A_is_valid returns true if 'c' is an Arabic 10646 (8859-6 or Form-B),
* A_is_valid returns TRUE if 'c' is an Arabic 10646 (8859-6 or Form-B) // with some exceptions/exclusions.
* with some exceptions/exclusions
*/
static bool A_is_valid(int c) static bool A_is_valid(int c)
{ {
return A_is_ok(c) && !A_is_special(c); return A_is_ok(c) && !A_is_special(c);
} }
/* // A_is_special returns true if 'c' is not a special Arabic character.
* A_is_special returns TRUE if 'c' is not a special Arabic character. // Specials don't adhere to most of the rules.
* Specials don't adhere to most of the rules.
*/
static bool A_is_special(int c) static bool A_is_special(int c)
{ {
return c == a_HAMZA || c == a_s_HAMZA; return c == a_HAMZA || c == a_s_HAMZA;

View File

@ -1,8 +1,8 @@
/// @file farsi.c /// @file farsi.c
/// ///
/// Functions for Farsi language /// Functions for Farsi language
///
#include <stdbool.h>
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/edit.h" #include "nvim/edit.h"
@ -26,7 +26,7 @@
#define AT_CURSOR 0 #define AT_CURSOR 0
// special Farsi text messages // Special Farsi text messages
const char_u farsi_text_1[] = { const char_u farsi_text_1[] = {
YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M', YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M',
@ -59,6 +59,7 @@ const char_u farsi_text_5[] = {
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "farsi.c.generated.h" # include "farsi.c.generated.h"
#endif #endif
/// Convert the given Farsi character into a _X or _X_ type /// Convert the given Farsi character into a _X or _X_ type
/// ///
/// @param c The character to convert. /// @param c The character to convert.
@ -287,8 +288,8 @@ int toF_TyA(int c)
/// @param src /// @param src
/// @param offset /// @param offset
/// ///
/// @return TRUE if the character under the cursor+offset is a join type. /// @return true if the character under the cursor+offset is a join type.
static int F_is_TyB_TyC_TyD(int src, int offset) static bool F_is_TyB_TyC_TyD(int src, int offset)
{ {
int c; int c;
@ -330,17 +331,17 @@ static int F_is_TyB_TyC_TyD(int src, int offset)
case _IE: case _IE:
case _HE_: case _HE_:
case _HE: case _HE:
return TRUE; return true;
} }
return FALSE; return false;
} }
/// Is the Farsi character one of the terminating only type. /// Is the Farsi character one of the terminating only type.
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if the Farsi character is one of the terminating only types. /// @return true if the Farsi character is one of the terminating only types.
static int F_is_TyE(int c) static bool F_is_TyE(int c)
{ {
switch (c) { switch (c) {
case ALEF_A: case ALEF_A:
@ -353,17 +354,17 @@ static int F_is_TyE(int c)
case WAW: case WAW:
case WAW_H: case WAW_H:
case HAMZE: case HAMZE:
return TRUE; return true;
} }
return FALSE; return false;
} }
/// Is the Farsi character one of the none leading type. /// Is the Farsi character one of the none leading type.
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if the Farsi character is one of the none-leading types. /// @return true if the Farsi character is one of the none-leading types.
static int F_is_TyC_TyD(int c) static bool F_is_TyC_TyD(int c)
{ {
switch (c) { switch (c) {
case ALEF_: case ALEF_:
@ -377,9 +378,9 @@ static int F_is_TyC_TyD(int c)
case IE_: case IE_:
case TEE_: case TEE_:
case YEE_: case YEE_:
return TRUE; return true;
} }
return FALSE; return false;
} }
/// Convert a none leading Farsi char into a leading type. /// Convert a none leading Farsi char into a leading type.
@ -2081,8 +2082,8 @@ static int toF_Rjoin(int c)
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if the character can join via its left edj. /// @return true if the character can join via its left edj.
static int canF_Ljoin(int c) static bool canF_Ljoin(int c)
{ {
switch (c) { switch (c) {
case _BE: case _BE:
@ -2146,17 +2147,17 @@ static int canF_Ljoin(int c)
case F_HE: case F_HE:
case _HE: case _HE:
case _HE_: case _HE_:
return TRUE; return true;
} }
return FALSE; return false;
} }
/// Can a given Farsi character join via its right edj. /// Can a given Farsi character join via its right edj.
/// ///
/// @param c /// @param c
/// ///
/// @return TRUE if the character can join via its right edj. /// @return true if the character can join via its right edj.
static int canF_Rjoin(int c) static bool canF_Rjoin(int c)
{ {
switch (c) { switch (c) {
case ALEF: case ALEF:
@ -2172,9 +2173,8 @@ static int canF_Rjoin(int c)
case TEE_: case TEE_:
case WAW: case WAW:
case WAW_H: case WAW_H:
return TRUE; return true;
} }
return canF_Ljoin(c); return canF_Ljoin(c);
} }
@ -2182,8 +2182,8 @@ static int canF_Rjoin(int c)
/// ///
/// @param c /// @param c
/// ///
/// @return TRUE if the character is a terminating type. /// @return true if the character is a terminating type.
static int F_isterm(int c) static bool F_isterm(int c)
{ {
switch (c) { switch (c) {
case ALEF: case ALEF:
@ -2199,10 +2199,9 @@ static int F_isterm(int c)
case WAW_H: case WAW_H:
case TEE: case TEE:
case TEE_: case TEE_:
return TRUE; return true;
} }
return false;
return FALSE;
} }
/// Convert the given Farsi character into an ending type. /// Convert the given Farsi character into an ending type.
@ -2915,34 +2914,34 @@ int cmdl_fkmap(int c)
return c; return c;
} }
/// F_isalpha returns TRUE if 'c' is a Farsi alphabet /// F_isalpha returns true if 'c' is in the Farsi alphabet.
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if 'c' is a Farsi alphabet character. /// @return true if 'c' is a Farsi alphabet character.
int F_isalpha(int c) bool F_isalpha(int c)
{ {
return (c >= TEE_ && c <= _YE) return (c >= TEE_ && c <= _YE)
|| (c >= ALEF_A && c <= YE) || (c >= ALEF_A && c <= YE)
|| (c >= _IE && c <= YE_); || (c >= _IE && c <= YE_);
} }
/// F_isdigit returns TRUE if 'c' is a Farsi digit /// F_isdigit returns true if 'c' is a Farsi digit
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if 'c' is a Farsi digit. /// @return true if 'c' is a Farsi digit.
int F_isdigit(int c) bool F_isdigit(int c)
{ {
return c >= FARSI_0 && c <= FARSI_9; return c >= FARSI_0 && c <= FARSI_9;
} }
/// F_ischar returns TRUE if 'c' is a Farsi character. /// F_ischar returns true if 'c' is a Farsi character.
/// ///
/// @param c The character to check. /// @param c The character to check.
/// ///
/// @return TRUE if 'c' is a Farsi character. /// @return true if 'c' is a Farsi character.
int F_ischar(int c) bool F_ischar(int c)
{ {
return c >= TEE_ && c <= YE_; return c >= TEE_ && c <= YE_;
} }