⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.cc

📁 早期freebsd实现
💻 CC
📖 第 1 页 / 共 2 页
字号:
{  search_default = 0;}static void bibliography_command(int argc, argument *argv){  const char *saved_filename = current_filename;  int saved_lineno = current_lineno;  int saved_label_in_text = label_in_text;  label_in_text = 0;  if (!accumulate)    fputs(".]<\n", stdout);  for (int i = 0; i < argc; i++)    do_bib(argv[i].s);  if (accumulate)    output_references();  else    fputs(".]>\n", stdout);  current_filename = saved_filename;  current_lineno = saved_lineno;  label_in_text = saved_label_in_text;}static void annotate_command(int argc, argument *argv){  if (argc > 0)    annotation_field = argv[0].s[0];  else    annotation_field = 'X';  if (argc == 2)    annotation_macro = argv[1].s;  else    annotation_macro = "AP";}static void no_annotate_command(int, argument *){  annotation_macro.clear();  annotation_field = -1;}static void reverse_command(int, argument *argv){  reverse_fields = argv[0].s;}static void no_reverse_command(int, argument *){  reverse_fields.clear();}static void abbreviate_command(int argc, argument *argv){  abbreviate_fields = argv[0].s;  period_before_initial = argc > 1 ? argv[1].s : ". ";  period_before_last_name = argc > 2 ? argv[2].s : ". ";  period_before_other = argc > 3 ? argv[3].s : ". ";  period_before_hyphen = argc > 4 ? argv[4].s : ".";}static void no_abbreviate_command(int, argument *){  abbreviate_fields.clear();}string search_ignore_fields;static void search_ignore_command(int argc, argument *argv){  if (argc > 0)    search_ignore_fields = argv[0].s;  else    search_ignore_fields = "XYZ";  search_ignore_fields += '\0';  linear_ignore_fields = search_ignore_fields.contents();}static void no_search_ignore_command(int, argument *){  linear_ignore_fields = "";}static void search_truncate_command(int argc, argument *argv){  if (argc > 0)    linear_truncate_len = argv[0].n;  else    linear_truncate_len = 6;}static void no_search_truncate_command(int, argument *){  linear_truncate_len = -1;}static void discard_command(int argc, argument *argv){  if (argc == 0)    discard_fields = "XYZ";  else    discard_fields = argv[0].s;  accumulate = 1;}static void no_discard_command(int, argument *){  discard_fields.clear();}static void label_command(int, argument *argv){  set_label_spec(argv[0].s);}static void abbreviate_label_ranges_command(int argc, argument *argv){  abbreviate_label_ranges = 1;  label_range_indicator = argc > 0 ? argv[0].s : "-";}static void no_abbreviate_label_ranges_command(int, argument *){  abbreviate_label_ranges = 0;}static void label_in_reference_command(int, argument *){  label_in_reference = 1;}static void no_label_in_reference_command(int, argument *){  label_in_reference = 0;}static void label_in_text_command(int, argument *){  label_in_text = 1;}static void no_label_in_text_command(int, argument *){  label_in_text = 0;}static void sort_adjacent_labels_command(int, argument *){  sort_adjacent_labels = 1;}static void no_sort_adjacent_labels_command(int, argument *){  sort_adjacent_labels = 0;}static void date_as_label_command(int argc, argument *argv){  if (set_date_label_spec(argc > 0 ? argv[0].s : "D%a*"))    date_as_label = 1;}static void no_date_as_label_command(int, argument *){  date_as_label = 0;}static void short_label_command(int, argument *argv){  if (set_short_label_spec(argv[0].s))    short_label_flag = 1;}static void no_short_label_command(int, argument *){  short_label_flag = 0;}static void compatible_command(int, argument *){  compatible_flag = 1;}static void no_compatible_command(int, argument *){  compatible_flag = 0;}static void join_authors_command(int argc, argument *argv){  join_authors_exactly_two = argv[0].s;  join_authors_default = argc > 1 ? argv[1].s : argv[0].s;  join_authors_last_two = argc == 3 ? argv[2].s : argv[0].s;}static void bracket_label_command(int, argument *argv){  pre_label = argv[0].s;  post_label = argv[1].s;  sep_label = argv[2].s;}static void separate_label_second_parts_command(int, argument *argv){  separate_label_second_parts = argv[0].s;}static void et_al_command(int argc, argument *argv){  et_al = argv[0].s;  et_al_min_elide = argv[1].n;  if (et_al_min_elide < 1)    et_al_min_elide = 1;  et_al_min_total = argc >= 3 ? argv[2].n : 0;}static void no_et_al_command(int, argument *){  et_al.clear();  et_al_min_elide = 0;}typedef void (*command_t)(int, argument *);/* arg_types is a string describing the numbers and types of arguments.s means a string, i means an integer, f is a list of fields, F isa single field,? means that the previous argument is optional, * means that theprevious argument can occur any number of times. */struct {  const char *name;  command_t func;  const char *arg_types;} command_table[] = {  "include", include_command, "s",  "echo", echo_command, "s*",  "capitalize", capitalize_command, "f?",  "accumulate", accumulate_command, "",  "no-accumulate", no_accumulate_command, "",  "move-punctuation", move_punctuation_command, "",  "no-move-punctuation", no_move_punctuation_command, "",  "sort", sort_command, "s?",  "no-sort", no_sort_command, "",  "articles", articles_command, "s*",  "database", database_command, "ss*",  "default-database", default_database_command, "",  "no-default-database", no_default_database_command, "",  "bibliography", bibliography_command, "ss*",  "annotate", annotate_command, "F?s?",  "no-annotate", no_annotate_command, "",  "reverse", reverse_command, "s",  "no-reverse", no_reverse_command, "",  "abbreviate", abbreviate_command, "ss?s?s?s?",  "no-abbreviate", no_abbreviate_command, "",  "search-ignore", search_ignore_command, "f?",  "no-search-ignore", no_search_ignore_command, "",  "search-truncate", search_truncate_command, "i?",  "no-search-truncate", no_search_truncate_command, "",  "discard", discard_command, "f?",  "no-discard", no_discard_command, "",  "label", label_command, "s",  "abbreviate-label-ranges", abbreviate_label_ranges_command, "s?",  "no-abbreviate-label-ranges", no_abbreviate_label_ranges_command, "",  "label-in-reference", label_in_reference_command, "",  "no-label-in-reference", no_label_in_reference_command, "",  "label-in-text", label_in_text_command, "",  "no-label-in-text", no_label_in_text_command, "",  "sort-adjacent-labels", sort_adjacent_labels_command, "",  "no-sort-adjacent-labels", no_sort_adjacent_labels_command, "",  "date-as-label", date_as_label_command, "s?",  "no-date-as-label", no_date_as_label_command, "",  "short-label", short_label_command, "s",  "no-short-label", no_short_label_command, "",  "compatible", compatible_command, "",  "no-compatible", no_compatible_command, "",  "join-authors", join_authors_command, "sss?",  "bracket-label", bracket_label_command, "sss",  "separate-label-second-parts", separate_label_second_parts_command, "s",  "et-al", et_al_command, "sii?",  "no-et-al", no_et_al_command, "",};static int check_args(const char *types, const char *name,		      int argc, argument *argv){  int argno = 0;  while (*types) {    if (argc == 0) {      if (types[1] == '?')	break;      else if (types[1] == '*') {	assert(types[2] == '\0');	break;      }      else {	input_stack::error("missing argument for command `%1'", name);	return 0;      }    }    switch (*types) {    case 's':      break;    case 'i':      {	char *ptr;	long n = strtol(argv->s, &ptr, 10);	if ((n == 0 && ptr == argv->s)	    || *ptr != '\0') {	  input_stack::error("argument %1 for command `%2' must be an integer",			     argno + 1, name);	  return 0;	}	argv->n = (int)n;	break;      }    case 'f':      {	for (const char *ptr = argv->s; *ptr != '\0'; ptr++)	  if (!cs_field_name(*ptr)) {	    input_stack::error("argument %1 for command `%2' must be a list of fields",			     argno + 1, name);	    return 0;	  }	break;      }    case 'F':      if (argv->s[0] == '\0' || argv->s[1] != '\0'	  || !cs_field_name(argv->s[0])) {	input_stack::error("argument %1 for command `%2' must be a field name",			   argno + 1, name);	return 0;      }      break;    default:      assert(0);    }    if (types[1] == '?')      types += 2;    else if (types[1] != '*')      types += 1;    --argc;    ++argv;    ++argno;  }  if (argc > 0) {    input_stack::error("too many arguments for command `%1'", name);    return 0;  }  return 1;}static void execute_command(const char *name, int argc, argument *argv){  for (int i = 0; i < sizeof(command_table)/sizeof(command_table[0]); i++)    if (strcmp(name, command_table[i].name) == 0) {      if (check_args(command_table[i].arg_types, name, argc, argv))	(*command_table[i].func)(argc, argv);      return;    }  input_stack::error("unknown command `%1'", name);}static void command_loop(){  string command;  for (;;) {    command.clear();    int res = get_word(command);    if (res != 1) {      if (res == 0)	continue;      break;    }    int argc = 0;    command += '\0';    while ((res = get_word(command)) == 1) {      argc++;      command += '\0';    }    argument *argv = new argument[argc];    const char *ptr = command.contents();    for (int i = 0; i < argc; i++)      argv[i].s = ptr = strchr(ptr, '\0') + 1;    execute_command(command.contents(), argc, argv);    a_delete argv;    if (res == -1)      break;  }}void process_commands(const char *file){  input_stack::init();  input_stack::push_file(file);  command_loop();}void process_commands(string &s, const char *file, int lineno){  input_stack::init();  input_stack::push_string(s, file, lineno);  command_loop();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -