MCPcopy Create free account
hub / github.com/git/git / init_dfa

Function init_dfa

compat/regex/regcomp.c:848–964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

846
847 return err;
848}
849
850/* Initialize DFA. We use the length of the regular expression PAT_LEN
851 as the initial length of some arrays. */
852
853static reg_errcode_t
854init_dfa (re_dfa_t *dfa, size_t pat_len)
855{
856 unsigned int table_size;
857#ifndef _LIBC
858 const char *codeset_name;
859#endif
860
861 memset (dfa, '\0', sizeof (re_dfa_t));
862
863 /* Force allocation of str_tree_storage the first time. */
864 dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
865
866 /* Avoid overflows. */
867 if (pat_len == SIZE_MAX)
868 return REG_ESPACE;
869
870 dfa->nodes_alloc = pat_len + 1;
871 dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
872
873 /* table_size = 2 ^ ceil(log pat_len) */
874 for (table_size = 1; ; table_size <<= 1)
875 if (table_size > pat_len)
876 break;
877
878 dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry));
879 dfa->state_hash_mask = table_size - 1;
880
881 dfa->mb_cur_max = MB_CUR_MAX;
882#ifdef _LIBC
883 if (dfa->mb_cur_max == 6
884 && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
885 dfa->is_utf8 = 1;
886 dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
887 != 0);
888#else
889# ifdef HAVE_LANGINFO_CODESET
890 codeset_name = nl_langinfo (CODESET);
891# else
892 codeset_name = getenv ("LC_ALL");
893 if (codeset_name == NULL || codeset_name[0] == '\0')
894 codeset_name = getenv ("LC_CTYPE");
895 if (codeset_name == NULL || codeset_name[0] == '\0')
896 codeset_name = getenv ("LANG");
897 if (codeset_name == NULL)
898 codeset_name = "";
899 else if (strchr (codeset_name, '.') != NULL)
900 codeset_name = strchr (codeset_name, '.') + 1;
901# endif
902
903 /* strcasecmp isn't a standard interface. brute force check */
904#if 0
905 if (strcasecmp (codeset_name, "UTF-8") == 0

Callers 1

re_compile_internalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected