📄 key_list.cpp
字号:
if (option[OPTIMIZE])
ACE_OS::printf (" return resword;\n");
else
{
ACE_OS::printf (option[LENTABLE] && !option[DUP]
? " if (len == key_len && %s)\n return resword;\n"
: " if (%s)\n return resword;\n", comp_buffer);
ACE_OS::printf (" return 0;\n");
}
ACE_OS::printf (" }\n");
curr = temp;
}
else // Nothing special required here.
{
int i = 0;
ACE_OS::printf (" char *s;\n\n switch (key - %d)\n {\n",
lowest_case_value);
for (temp = curr; temp && ++i <= number_of_cases; temp = temp->next)
if (option[LENTABLE])
ACE_OS::printf (" case %*d: if (len == %d) s = \"%s\"; else return 0; break;\n",
Key_List::field_width,
temp->hash_value - lowest_case_value,
temp->length,
temp->key);
else
ACE_OS::printf (" case %*d: s = \"%s\"; break;\n",
Key_List::field_width,
temp->hash_value - lowest_case_value,
temp->key);
ACE_OS::printf (" default: return 0;\n }\n ");
if (option[COMP])
ACE_OS::printf ("return %s == *s && !ACE_OS::%s;\n }\n",
option[STRCASECMP] ? "charmap[*str]" : "*str",
option[STRCASECMP] ? "strncasecmp (s + 1, str + 1, len - 1)" : "strcmp (s + 1, str + 1)");
else
ACE_OS::printf ("return %s == *s && !ACE_OS::%s;\n }\n",
option[STRCASECMP] ? "charmap[*str]" : "*str",
option[STRCASECMP] ? "strcasecmp (s + 1, str + 1, len - 1)" : "strcmp (s + 1, str + 1)");
curr = temp;
}
}
ACE_OS::printf (" }\n %s\n}\n", option[OPTIMIZE] ? "" : "}\n return 0;");
}
// Prints out a table of keyword lengths, for use with the comparison
// code in generated function ``in_word_set.''
void
Key_List::output_keylength_table (void)
{
const int max_column = 15;
int slot = 0;
int column = 0;
const char *indent = option[GLOBAL] ? "" : " ";
List_Node *temp;
if (!option[DUP] && !option[SWITCH])
{
ACE_OS::printf ("\n%sstatic %sunsigned %s lengthtable[] =\n%s%s{\n ",
indent,
option[CONSTANT] ? "const " : "",
max_key_len <= ((int) UCHAR_MAX) ? "char" : (max_key_len <= ((int) USHRT_MAX) ? "short" : "long"),
indent,
indent);
for (temp = head; temp; temp = temp->next, slot++)
{
if (slot < temp->hash_value)
for ( ; slot < temp->hash_value; slot++)
ACE_OS::printf ("%3d,%s", 0, ++column % (max_column - 1) ? "" : "\n ");
ACE_OS::printf ("%3d,%s", temp->length, ++column % (max_column - 1 ) ? "" : "\n ");
}
ACE_OS::printf ("\n%s%s};\n",
indent,
indent);
}
}
// Prints out the array containing the key words for the Gen_Perf hash
// function.
void
Key_List::output_keyword_table (void)
{
const char *l_brace = *head->rest ? "{" : "";
const char *r_brace = *head->rest ? "}," : "";
const char *indent = option[GLOBAL] ? "" : " ";
int slot = 0;
List_Node *temp;
int pointer_and_type_enabled = option[POINTER] && option[TYPE];
ACE_OS::printf ("%sstatic %s%swordlist[] =\n%s%s{\n",
indent,
option[CONSTANT] || pointer_and_type_enabled == 0 ? "const " : "",
struct_tag,
indent,
indent);
// Skip over leading blank entries if there are no duplicates.
if (0 < head->hash_value)
ACE_OS::printf (" ");
int column;
for (column = 1; slot < head->hash_value; column++)
{
ACE_OS::printf ("%s\"\",%s%s%s",
l_brace,
option.fill_default (),
r_brace,
column % 9 ? "" : "\n ");
slot++;
}
if (0 < head->hash_value && column % 10)
ACE_OS::printf ("\n");
// Generate an array of reserved words at appropriate locations.
for (temp = head ; temp; temp = temp->next, slot++)
{
temp->slot = slot;
if (!option[SWITCH] && (total_duplicates == 0 || !option[DUP]) && slot < temp->hash_value)
{
int column;
ACE_OS::printf (" ");
for (column = 1; slot < temp->hash_value; slot++, column++)
ACE_OS::printf ("%s\"\",%s%s%s",
l_brace,
option.fill_default (),
r_brace,
column % 9 ? "" : "\n ");
if (column % 10)
ACE_OS::printf ("\n");
else
{
ACE_OS::printf ("%s\"%s\", %s%s", l_brace, temp->key, temp->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
temp->hash_value,
temp->slot);
putchar ('\n');
continue;
}
}
ACE_OS::printf (" %s\"%s\", %s%s", l_brace, temp->key, temp->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
temp->hash_value,
temp->slot);
putchar ('\n');
// Deal with links specially.
if (temp->link)
for (List_Node *links = temp->link; links; links = links->link)
{
links->slot = ++slot;
ACE_OS::printf (" %s\"%s\", %s%s", l_brace, links->key, links->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
links->hash_value,
links->slot);
putchar ('\n');
}
}
ACE_OS::printf ("%s%s};\n\n", indent, indent);
}
// Generates C code for the binary search algorithm that returns
// the proper encoding for each key word
int
Key_List::output_binary_search_function (void)
{
ACE_OS::printf ("%s\n", include_src);
// Get prototype for strncmp() and strcmp().
if (!option[SKIPSTRINGH])
ACE_OS::printf ("#include \"ace/OS_NS_string.h\"\n");
// Output type declaration now, reference it later on....
if (option[TYPE] && !option[NOTYPE])
ACE_OS::printf ("%s;\n",
array_type_);
output_min_max ();
if (option[STRCASECMP])
output_strcasecmp ();
// Class definition if -M is *not* enabled.
if (option[CPLUSPLUS] && !option[SKIPCLASS])
ACE_OS::printf ("class %s {\npublic:\n"
" static %s%s%s (const char *str);\n};\n\n",
option.class_name (),
option[CONSTANT] ? "const " : "",
return_type,
option.function_name ());
// Use the inline keyword to remove function overhead.
if (option[INLINE])
ACE_OS::printf ("inline\n");
ACE_OS::printf ("%s%s\n", option[CONSTANT] ? "const " : "", return_type);
if (option[CPLUSPLUS])
ACE_OS::printf ("%s::", option.class_name ());
ACE_OS::printf (option[ANSI]
? "%s (const char *str)\n{\n"
: "%s (str)\n char *str;\n{\n",
option.function_name ());
// Use the switch in place of lookup table.
if (option[SWITCH])
output_switch ();
// Use the lookup table, in place of switch.
else
{
if (!option[GLOBAL])
{
if (option[LENTABLE])
output_keylength_table ();
output_keyword_table ();
}
}
// Logic to handle the Binary Search.
ACE_OS::printf ("int first = 0, last = 0, middle = 0;\n");
if (option[DUP] && total_duplicates > 0)
{
ACE_OS::printf ("%s*base = 0;\n",struct_tag);
}
ACE_OS::printf ("\nlast = %d;\n",total_keys - 1);
ACE_OS::printf ("while (last >= first)\n");
ACE_OS::printf ("\t{\n");
ACE_OS::printf ("\t middle = (last + first) / 2;\n");
ACE_OS::printf ("\t if (ACE_OS::strcmp (wordlist[middle].%s, str) == 0)\n break;\n", option.key_name());
ACE_OS::printf ("\t if (ACE_OS::strcmp (wordlist[middle].%s, str) < 0)\n first = middle + 1;\n", option.key_name());
ACE_OS::printf ("\t else last = middle - 1;\n");
ACE_OS::printf ("\t}\n");
ACE_OS::printf ("if (last < first)\n return 0;\n");
ACE_OS::printf ("else\n return (&wordlist[middle]);\n}\n");
if (additional_code)
{
for (;;)
{
int c = getchar ();
if (c == EOF)
break;
else
putchar (c);
}
}
ACE_OS::fflush(stdout);
return 0;
}
// Generates C code for the linear search algorithm that returns
// the proper encoding for each key word
int
Key_List::output_linear_search_function (void)
{
ACE_OS::printf ("%s\n", include_src);
// Get prototype for strncmp() and strcmp().
if (!option[SKIPSTRINGH])
ACE_OS::printf ("#include \"ace/OS_NS_string.h\"\n");
// Output type declaration now, reference it later on....
if (option[TYPE] && !option[NOTYPE])
ACE_OS::printf ("%s;\n",
array_type_);
output_min_max ();
if (option[STRCASECMP])
output_strcasecmp ();
// Class definition if -M is *not* enabled.
if (option[CPLUSPLUS] && !option[SKIPCLASS])
ACE_OS::printf ("class %s {\npublic:\n"
" static %s%s%s (const char *str);\n};\n\n",
option.class_name (),
option[CONSTANT] ? "const " : "",
return_type,
option.function_name ());
// Use the inline keyword to remove function overhead.
if (option[INLINE])
ACE_OS::printf ("inline\n");
ACE_OS::printf ("%s%s\n",
option[CONSTANT] ? "const " : "",
return_type);
if (option[CPLUSPLUS])
ACE_OS::printf ("%s::", option.class_name ());
ACE_OS::printf (option[ANSI]
? "%s (const char *str)\n{\n"
: "%s (str)\n char *str;\n{\n",
option.function_name ());
// Use the switch in place of lookup table.
if (option[SWITCH])
output_switch ();
// Use the lookup table, in place of switch.
else
{
if (!option[GLOBAL])
{
if (option[LENTABLE])
output_keylength_table ();
output_keyword_table ();
}
}
// Logic to handle the Linear Search.
ACE_OS::printf ("for (int i=0; i<=%d; i++)",total_keys-1);
ACE_OS::printf ("\t{\n");
ACE_OS::printf ("\t if (ACE_OS::strcmp (wordlist[i].%s, str) == 0)\n", option.key_name());
ACE_OS::printf ("\t return &wordlist[i];\n");
ACE_OS::printf ("\t}\n");
ACE_OS::printf ("return 0;\n}\n");
if (additional_code)
{
for (;;)
{
int c = getchar ();
if (c == EOF)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -