コード例 #1
0
 tokenizer(std::istream& is, bool skipws) :
     atf::parser::tokenizer< std::istream >
         (is, skipws, eof_type, nl_type, word_type)
 {
     add_keyword("var", var_type);
     add_keyword("loop", loop_type);
     add_keyword("endloop", endloop_type);
 }
コード例 #2
0
ファイル: Test.c プロジェクト: JammyStuff/vermont
void test1(){
	struct KTree *ktree;
	ktree = new_KTree();

	struct KTreeNode * ptr_addedKeyword;
	ptr_addedKeyword = add_keyword(ktree, "01", 2);
	ptr_addedKeyword = add_keyword(ktree, "012", 3);
	ptr_addedKeyword = add_keyword(ktree, "012", 3);
	char * string_broken = "012\n3";
	ptr_addedKeyword = add_keyword(ktree, string_broken, 5);

	trace_back_keyword(ktree, 3);

	destruct_KTree(ktree);
}
コード例 #3
0
/**
 * Loads a compound word file, adding each word to the keywords.
 */
void load_compound_words(char* name,VersatileEncodingConfig* vec,
		struct string_hash_ptr* keywords) {
U_FILE* f=u_fopen(vec,name,U_READ);
if (f==NULL) return;
Ustring* line=new_Ustring(256);
Ustring* lower=new_Ustring(256);
while (EOF!=readline(line,f)) {
	if (line->str[0]=='{') {
		/* We skip tags */
		continue;
	}
	u_strcpy(lower,line->str);
	u_tolower(lower->str);
	int index=get_value_index(lower->str,keywords,INSERT_IF_NEEDED,NULL);
	if (index==-1) {
		fatal_error("Internal error in load_tokens_by_freq\n");
	}
	KeyWord* value=(KeyWord*)keywords->value[index];
	add_keyword(&value,line->str,1);
	keywords->value[index]=value;
}
free_Ustring(line);
free_Ustring(lower);
u_fclose(f);
}
コード例 #4
0
ImapCommandItem* ImapCommands::MessageMarkAsSpam::GetExpandedQueue(IMAP4& protocol)
{
	const char* keyword_spam = "$Junk";
	const char* keyword_not_spam = "$NotJunk";

	OpAutoPtr<ImapCommands::Store> remove_keyword  (OP_NEW(ImapCommands::Store, (m_mailbox, 0, 0,
					ImapCommands::USE_UID | ImapCommands::Store::REMOVE_FLAGS | ImapCommands::Store::SILENT | ImapCommands::Store::KEYWORDS, m_mark_as_spam ? keyword_not_spam : keyword_spam)));

	OpAutoPtr<ImapCommands::Store> add_keyword (OP_NEW(ImapCommands::Store, (m_mailbox, 0, 0,
		ImapCommands::USE_UID | ImapCommands::Store::ADD_FLAGS | ImapCommands::Store::SILENT | ImapCommands::Store::KEYWORDS, m_mark_as_spam ? keyword_spam : keyword_not_spam)));

			
	if (!add_keyword.get() || !remove_keyword.get() || 
		OpStatus::IsError(remove_keyword->GetMessageSet().Copy(m_message_set)) || 
		OpStatus::IsError(add_keyword->GetMessageSet().Copy(m_message_set)))
		return NULL;

	add_keyword->DependsOn(remove_keyword.get(), protocol);

	if (m_to_folder)
	{
		ImapCommands::Move * move_to_folder = OP_NEW(ImapCommands::Move, (m_mailbox, m_to_folder, 0, 0));
		if (!move_to_folder || OpStatus::IsError(move_to_folder->GetMessageSet().Copy(m_message_set)))
		{
			OP_DELETE(move_to_folder);
			return NULL;
		}
		move_to_folder->DependsOn(add_keyword.get(), protocol);
	}

	add_keyword.release();
	return remove_keyword.release();
}
コード例 #5
0
struct Matcher * new_matcher(const char* signature_directory){
	int j,i;
	/* Read in the signatures of the signature directory */
	int numOf_SignatureClasses = 0;
	struct BayesSignature ** signatures = read_signature_files(signature_directory, &numOf_SignatureClasses);
	/* Initialize the matcher with those read-in signatures */
	struct Matcher * matcher;
	matcher = malloc(sizeof(struct Matcher));

	/* Add to matcher->signatures */
	matcher->signatures = signatures;

	/*  Add to matcher->ktree */
	matcher->ktree = new_KTree();

	for (j = 0; j < numOf_SignatureClasses; ++j){
		for (i = 0; i < matcher->signatures[j]->numOfTokens; ++i){
			//printf("j = %i, Token = \"%s\"\n", j, matcher->signatures[j]->tokens[i]->tokenstring);
			add_keyword(matcher->ktree, matcher->signatures[j]->tokens[i]->tokenstring, matcher->signatures[j]->tokens[i]->tokenlength);
		}
	}

	/* Finally set the integer values */
	matcher->numOfClasses = numOf_SignatureClasses;

	/* Now initialize the matcher->mapper with the subsumed informations from above */
	matcher->mapper = new_mapper(matcher);

	return matcher;
}
コード例 #6
0
void add_keyword(KeyWord* *list,unichar* keyword,int weight) {
if (*list==NULL) {
	*list=new_KeyWord(weight,keyword,NULL);
	return;
}
if (!u_strcmp((*list)->sequence,keyword)) {
	/* The keyword is already there, we just have to update its weight */
	(*list)->weight+=weight;
	return;
}
add_keyword(&((*list))->next,keyword,weight);
}
コード例 #7
0
ファイル: plughook.c プロジェクト: vorband/dthoneytrap
void register_plugin_confopts(const char *plugname, const char **keywords, int num) {
	int	i;
	char	full_name[264], *confopt;

	/* assemble plugin config key */
	memset(full_name, 0, 264);
	strncpy(full_name, "plugin-", 7);
	strncpy(&full_name[7], plugname, 256 < strlen(plugname) ? 256 : strlen(plugname));

	if (add_keyword(&config_keywords_tree, full_name, NULL, 0) == NULL) {
		fprintf(stderr, "  Error - Unable to add configuration keyword to tree.\n");
		exit(EXIT_FAILURE);
	}	

	DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", plugname);
	/* build tree of allowed configuration keywords */
	for (i=0; i<num; i++) {

		/* assemble full config option path */
		if ((confopt = malloc(strlen(full_name)+strlen(keywords[i])+2)) == NULL) {
			fprintf(stderr, "  Error - Unable to allocate memory: %m.\n");
			exit(EXIT_FAILURE);
		}
		memset(confopt, 0, strlen(plugname)+strlen(keywords[i])+2);
		strcat(confopt, plugname);
		strcat(confopt, ".");
		strcat(confopt, keywords[i]);

		/* add config option to tree */
		if (add_keyword(&config_keywords_tree, confopt, NULL, 0) == NULL) {
			fprintf(stderr, "  Error - Unable to add configuration keyword to tree.\n");
			exit(EXIT_FAILURE);
		}	
		free(confopt);
	}
	return;
}
コード例 #8
0
ファイル: keywords.cpp プロジェクト: jscipione/Paladin
/**
 * Loads the dynamic keywords from a file
 *
 * @param filename   The path to the file to load
 * @return           SUCCESS or FAILURE
 */
int load_keyword_file(const char *filename)
{
   FILE *pf;
   char buf[256];
   char *ptr;
   char *args[3];
   int  argc;
   int  line_no = 0;

   pf = fopen(filename, "r");
   if (pf == NULL)
   {
      LOG_FMT(LERR, "%s: fopen(%s) failed: %s (%d)\n",
              __func__, filename, strerror(errno), errno);
      cpd.error_count++;
      return(FAILURE);
   }

   while (fgets(buf, sizeof(buf), pf) != NULL)
   {
      line_no++;

      /* remove comments */
      if ((ptr = strchr(buf, '#')) != NULL)
      {
         *ptr = 0;
      }

      argc       = Args::SplitLine(buf, args, ARRAY_SIZE(args) - 1);
      args[argc] = 0;

      if (argc > 0)
      {
         if ((argc == 1) && CharTable::IsKw1(*args[0]))
         {
            add_keyword(args[0], CT_TYPE, LANG_ALL);
         }
         else
         {
            LOG_FMT(LWARN, "%s:%d Invalid line (starts with '%s')\n",
                    filename, line_no, args[0]);
            cpd.error_count++;
         }
      }
   }

   fclose(pf);
   return(SUCCESS);
}
コード例 #9
0
ファイル: Test.c プロジェクト: JammyStuff/vermont
void test1_5(){
	struct KTree *ktree;
	ktree = new_KTree();

	struct KTreeNode * ptr_addedKeyword;
	ptr_addedKeyword = add_keyword(ktree, "bist", 4);
	ptr_addedKeyword = add_keyword(ktree, "ist", 3);
	ptr_addedKeyword = add_keyword(ktree, "ist", 3);

	ptr_addedKeyword = add_keyword(ktree, "abcdef", 6);

	printf("find_string: %i\n", find_string(ktree, "012"));

	int * matches;
	char *  flow = "istn\n \0\12\n30130123\n012313230103";
	matches = match(ktree, flow, strlen(flow));

	int i;
	for (i = 0; i < ktree->numofkeywords_actual; ++i)
		printf("%i : ", matches[i]);
	printf("\n");

	destruct_KTree(ktree);
}
コード例 #10
0
ファイル: x-vala.c プロジェクト: Distrotech/gettext
void
x_vala_keyword (const char *name)
{
  add_keyword (name, &keywords);
}
コード例 #11
0
ファイル: colvarparse.cpp プロジェクト: athomps/lammps
bool colvarparse::key_lookup(std::string const &conf,
                             char const *key_in,
                             std::string &data,
                             size_t &save_pos)
{
  // add this keyword to the register (in its camelCase version)
  add_keyword(key_in);

  // use the lowercase version from now on
  std::string const key(to_lower_cppstr(key_in));

  // "conf_lower" is only used to lookup the keyword, but its value
  // will be read from "conf", in order not to mess up file names
  std::string const conf_lower(to_lower_cppstr(conf));

  // by default, there is no value, unless we found one
  data = "";

  // when the function is invoked without save_pos, ensure that we
  // start from zero
  colvarparse::dummy_pos = 0;

  // start from the first occurrence of key
  size_t pos = conf_lower.find(key, save_pos);

  // iterate over all instances until it finds the isolated keyword
  while (true) {

    if (pos == std::string::npos) {
      // no valid instance of the keyword has been found
      return false;
    }

    bool b_isolated_left = true, b_isolated_right = true;

    if (pos > 0) {
      if ( std::string("\n"+white_space+
                       "}").find(conf[pos-1]) ==
           std::string::npos ) {
        // none of the valid delimiting characters is on the left of key
        b_isolated_left = false;
      }
    }

    if (pos < conf.size()-key.size()-1) {
      if ( std::string("\n"+white_space+
                       "{").find(conf[pos+key.size()]) ==
           std::string::npos ) {
        // none of the valid delimiting characters is on the right of key
        b_isolated_right = false;
      }
    }

    // check that there are matching braces between here and the end of conf
    bool const b_not_within_block = brace_check(conf, pos);

    bool const b_isolated = (b_isolated_left && b_isolated_right &&
                             b_not_within_block);

    if (b_isolated) {
      // found it
      break;
    } else {
      // try the next occurrence of key
      pos = conf_lower.find(key, pos+key.size());
    }
  }

  // save the pointer for a future call (when iterating over multiple
  // valid instances of the same keyword)
  save_pos = pos + key.size();

  // get the remainder of the line
  size_t pl = conf.rfind("\n", pos);
  size_t line_begin = (pl == std::string::npos) ? 0 : pos;
  size_t nl = conf.find("\n", pos);
  size_t line_end = (nl == std::string::npos) ? conf.size() : nl;
  std::string line(conf, line_begin, (line_end-line_begin));

  size_t data_begin = (to_lower_cppstr(line)).find(key) + key.size();
  data_begin = line.find_first_not_of(white_space, data_begin+1);

  //   size_t data_begin_absolute = data_begin + line_begin;
  //   size_t data_end_absolute   = data_begin;

  if (data_begin != std::string::npos) {

    size_t data_end = line.find_last_not_of(white_space) + 1;
    data_end = (data_end == std::string::npos) ? line.size() : data_end;
    //     data_end_absolute = data_end + line_begin;

    if (line.find('{', data_begin) != std::string::npos) {

      size_t brace_count = 1;
      size_t brace = line.find('{', data_begin);  // start from the first opening brace

      while (brace_count > 0) {

        // find the matching closing brace
        brace = line.find_first_of("{}", brace+1);
        while (brace == std::string::npos) {
          // add a new line
          if (line_end >= conf.size()) {
            cvm::fatal_error("Parse error: reached the end while "
                             "looking for closing brace; until now "
                             "the following was parsed: \"\n"+
                             line+"\".\n");
            return false;
          }
          size_t const old_end = line.size();
          //           data_end_absolute += old_end+1;

          line_begin = line_end;
          nl = conf.find('\n', line_begin+1);
          if (nl == std::string::npos)
            line_end = conf.size();
          else
            line_end = nl;
          line.append(conf, line_begin, (line_end-line_begin));

          brace = line.find_first_of("{}", old_end);
        }

        if (line[brace] == '{') brace_count++;
        if (line[brace] == '}') brace_count--;
      }

      // set data_begin after the opening brace
      data_begin = line.find_first_of('{', data_begin) + 1;
      data_begin = line.find_first_not_of(white_space,
                                          data_begin);
      // set data_end before the closing brace
      data_end = brace;
      data_end = line.find_last_not_of(white_space+"}",
                                       data_end) + 1;
      //       data_end_absolute = line_end;

      if (data_end > line.size())
        data_end = line.size();
    }

    data.append(line, data_begin, (data_end-data_begin));

    if (data.size() && save_delimiters) {
      data_begin_pos.push_back(conf.find(data, pos+key.size()));
      data_end_pos.push_back(data_begin_pos.back()+data.size());
      //       std::cerr << "key = " << key << ", data = \""
      //                 << data << "\", data_begin, data_end = "
      //                 << data_begin_pos.back() << ", " << data_end_pos.back()
      //                 << "\n";
    }
  }

  save_pos = line_end;

  return true;
}
コード例 #12
0
ファイル: conftree.c プロジェクト: adepasquale/honeytrap
/* insert new node into config tree and return a pointer to it
 * if *tree is NULL, it will be set to point to the root node */
conf_node *add_keyword(conf_node **tree, const char *keyword, const void *data, ssize_t size) {
	conf_node	*new_node, *cur_node;
	char		*key, *subkey;

	cur_node	= *tree;
	new_node	= NULL;
	key		= NULL;
	subkey		= NULL;


	if (!keyword) {
		logmsg(LOG_WARN, 1, "Warning - Unable to extend configuration tree: No keyword given.\n");
		return(*tree);
	}

	// check whether a prefix does already exist and if not, add it recursively
	if ((key = strdup(keyword)) ==  NULL) {
		logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n");
		return(NULL);
	}

	/* add recursively */
	if ((cur_node = check_keyword(*tree, key)) == NULL) {
		if ((subkey = strrchr(key, '.')) != NULL) {
			subkey[0] = 0;		// zero-terminate first half
			subkey++;		// pointer to second half
			if (isdigit(subkey[0])) {
				if ((cur_node = check_keyword(*tree, key)) == NULL)
					if ((cur_node = add_keyword(tree, key, NULL, 0)) == NULL) return(NULL);
				if (add_list_item(cur_node, data, size) == NULL) {
					fprintf(stderr, "  Error - Unable to add list item for %s.\n", key);
					return(NULL);
				}
				return(cur_node);
			}
			if ((cur_node = add_keyword(tree, key, NULL, 0)) == NULL) return(NULL);
		}
	} else return(cur_node);

	// create new node and insert it into tree
	if ((new_node = malloc(sizeof(conf_node))) == NULL) {
		logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n");
		free(key);
		return(NULL);
	}
	memset(new_node, 0, sizeof(conf_node));
	// if keyword is a toplevel key, add it, else add subkey
	if ((new_node->keyword = strdup(subkey ? subkey : key)) == NULL) {
		logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n");
		free(key);
		return(NULL);
	}
	free(key);

	if (size) {
		if (add_list_item(new_node, data, size) == NULL) {
			fprintf(stderr, "  Error - Unable to add list item for %s.\n", keyword);
			return(NULL);
		}
	}

	/* insert new node into tree */
	if (cur_node) {
		/* it's an internal node */
		if (cur_node->first_leaf) {
			cur_node = cur_node->first_leaf;
			while (cur_node->next) cur_node = cur_node->next;
			cur_node->next = new_node;
		} else cur_node->first_leaf = new_node;
	} else {
		/* it's a top level node */
		if (!(*tree)) (*tree) = new_node;
		/* it's a root's neighbor */
		else {
			cur_node = *tree;
			while (cur_node->next) cur_node = cur_node->next;
			cur_node->next = new_node;
		}
	}
	if (*tree == NULL) *tree = cur_node;

	return(new_node);
}
コード例 #13
0
ファイル: x-c.c プロジェクト: alan707/senuti
void
x_objc_keyword (const char *name)
{
  add_keyword (name, &objc_keywords);
}
コード例 #14
0
ファイル: x-c.c プロジェクト: alan707/senuti
void
x_c_keyword (const char *name)
{
  add_keyword (name, &c_keywords);
}
コード例 #15
0
ファイル: megahal_string.c プロジェクト: lp0/sqlhal
int megahal_keywords(brain_t brain, const list_t *words, dict_t **keywords) {
	dict_t *keywords_p;
	uint_fast32_t i;
	uint32_t size;
	int ret;

	WARN_IF(words == NULL);
	WARN_IF(keywords == NULL);

	*keywords = dict_alloc();
	if (*keywords == NULL) return -ENOMEM;
	keywords_p = *keywords;

	ret = list_size(words, &size);
	if (ret) return ret;

	for (i = 0; i < size; i++) {
		word_t word;

		ret = list_get(words, i, &word);
		if (ret) return ret;

		ret = db_map_get(brain, MAP_SWAP, word, &word);
		if (ret != OK && ret != -ENOTFOUND) return ret;

		ret = db_list_contains(brain, LIST_BAN, word);
		if (ret == OK) continue;
		if (ret != -ENOTFOUND) return ret;

		ret = db_list_contains(brain, LIST_AUX, word);
		if (ret == OK) continue;
		if (ret != -ENOTFOUND) return ret;

		ret = db_model_contains(brain, word);
		if (ret == -ENOTFOUND) continue;
		if (ret != OK) return ret;

		ret = add_keyword(keywords_p, word);
		if (ret) return ret;
	}

	ret = dict_size(keywords_p, &size);
	if (ret) return ret;

	if (size == 0)
		return OK;

	ret = list_size(words, &size);
	if (ret) return ret;

	for (i = 0; i < size; i++) {
		word_t word;

		ret = list_get(words, i, &word);
		if (ret) return ret;

		ret = db_map_get(brain, MAP_SWAP, word, &word);
		if (ret != OK && ret != -ENOTFOUND) return ret;

		ret = db_list_contains(brain, LIST_AUX, word);
		if (ret == -ENOTFOUND) continue;
		if (ret != OK) return ret;

		ret = db_model_contains(brain, word);
		if (ret == -ENOTFOUND) continue;
		if (ret != OK) return ret;

		ret = add_keyword(keywords_p, word);
		if (ret) return ret;
	}

	return OK;
}
コード例 #16
0
ファイル: uncrustify.cpp プロジェクト: GerHobbelt/uncrustify
int main(int argc, char *argv[])
{
   string     cfg_file;
   const char *parsed_file = NULL;
   const char *source_file = NULL;
   const char *output_file = NULL;
   const char *source_list = NULL;
   log_mask_t mask;
   int        idx;
   const char *p_arg;

   /* If ran without options... check keyword sort and show the usage info */
   if (argc == 1)
   {
      keywords_are_sorted();
      usage_exit(NULL, argv[0], EXIT_SUCCESS);
   }

   /* Build options map */
   register_options();

   Args arg(argc, argv);

   if (arg.Present("--version") || arg.Present("-v"))
   {
      version_exit();
   }
   if (arg.Present("--help") || arg.Present("-h") ||
       arg.Present("--usage") || arg.Present("-?"))
   {
      usage_exit(NULL, argv[0], EXIT_SUCCESS);
   }

   if (arg.Present("--show-config"))
   {
      print_options(stdout, true);
      return(0);
   }

#ifdef WIN32
   /* tell windoze not to change what I write to stdout */
   (void)_setmode(_fileno(stdout), _O_BINARY);
#endif

   /* Init logging */
   log_init(stderr);
   if (arg.Present("-q"))
   {
      logmask_from_string("", mask);
      log_set_mask(mask);
   }
   if (((p_arg = arg.Param("-L")) != NULL) ||
       ((p_arg = arg.Param("--log")) != NULL))
   {
      logmask_from_string(p_arg, mask);
      log_set_mask(mask);
   }
   cpd.frag = arg.Present("--frag");

   if ((p_arg = arg.Param("--decode")) != NULL)
   {
      log_pcf_flags(LSYS, strtoul(p_arg, NULL, 16));
      exit(EXIT_SUCCESS);
   }

   /* Get the config file name */
   if (((p_arg = arg.Param("--config")) != NULL) ||
       ((p_arg = arg.Param("-c")) != NULL))
   {
      cfg_file = p_arg;
   }

   /* Try to file a config at an alternate location */
   if (cfg_file.empty())
   {
      if (!unc_getenv("UNCRUSTIFY_CONFIG", cfg_file))
      {
         string home;

         if (unc_homedir(home))
         {
            struct stat tmp_stat;
            string      path;

            path = home + "/uncrustify.cfg";
            if (stat(path.c_str(), &tmp_stat) == 0)
            {
               cfg_file = path;
            }
            else
            {
               path = home + "/.uncrustify.cfg";
               if (stat(path.c_str(), &tmp_stat) == 0)
               {
                  cfg_file = path;
               }
            }
         }
      }
   }

   /* Get the parsed file name */
   if (((parsed_file = arg.Param("--parsed")) != NULL) ||
       ((parsed_file = arg.Param("-p")) != NULL))
   {
      LOG_FMT(LNOTE, "Will export parsed data to: %s\n", parsed_file);
   }

   /* Enable log sevs? */
   if (arg.Present("-s") || arg.Present("--show"))
   {
      log_show_sev(true);
   }

   /* Load the config file */
   set_option_defaults();

   /* Load type files */
   idx = 0;
   while ((p_arg = arg.Params("-t", idx)) != NULL)
   {
      load_keyword_file(p_arg);
   }

   /* add types */
   idx = 0;
   while ((p_arg = arg.Params("--type", idx)) != NULL)
   {
      add_keyword(p_arg, CT_TYPE);
   }

   /* Load define files */
   idx = 0;
   while ((p_arg = arg.Params("-d", idx)) != NULL)
   {
      load_define_file(p_arg);
   }

   /* add defines */
   idx = 0;
   while ((p_arg = arg.Params("--define", idx)) != NULL)
   {
      add_define(p_arg, NULL);
   }

   /* Check for a language override */
   if ((p_arg = arg.Param("-l")) != NULL)
   {
      cpd.lang_flags = language_from_tag(p_arg);
      if (cpd.lang_flags == 0)
      {
         LOG_FMT(LWARN, "Ignoring unknown language: %s\n", p_arg);
      }
      else
      {
         cpd.lang_forced = true;
      }
   }

   /* Get the source file name */
   if (((source_file = arg.Param("--file")) == NULL) &&
       ((source_file = arg.Param("-f")) == NULL))
   {
      // not using a single file, source_file is NULL
   }

   if (((source_list = arg.Param("--files")) == NULL) &&
       ((source_list = arg.Param("-F")) == NULL))
   {
      // not using a file list, source_list is NULL
   }

   const char *prefix = arg.Param("--prefix");
   const char *suffix = arg.Param("--suffix");

   bool no_backup        = arg.Present("--no-backup");
   bool replace          = arg.Present("--replace");
   bool keep_mtime       = arg.Present("--mtime");
   bool update_config    = arg.Present("--update-config");
   bool update_config_wd = arg.Present("--update-config-with-doc");
   bool detect           = arg.Present("--detect");

   /* Grab the output override */
   output_file = arg.Param("-o");

   LOG_FMT(LDATA, "config_file = %s\n", cfg_file.c_str());
   LOG_FMT(LDATA, "output_file = %s\n", (output_file != NULL) ? output_file : "null");
   LOG_FMT(LDATA, "source_file = %s\n", (source_file != NULL) ? source_file : "null");
   LOG_FMT(LDATA, "source_list = %s\n", (source_list != NULL) ? source_list : "null");
   LOG_FMT(LDATA, "prefix      = %s\n", (prefix != NULL) ? prefix : "null");
   LOG_FMT(LDATA, "suffix      = %s\n", (suffix != NULL) ? suffix : "null");
   LOG_FMT(LDATA, "replace     = %d\n", replace);
   LOG_FMT(LDATA, "no_backup   = %d\n", no_backup);
   LOG_FMT(LDATA, "detect      = %d\n", detect);

   if (replace || no_backup)
   {
      if ((prefix != NULL) || (suffix != NULL))
      {
         usage_exit("Cannot use --replace with --prefix or --suffix", argv[0], 66);
      }
      if ((source_file != NULL) || (output_file != NULL))
      {
         usage_exit("Cannot use --replace or --no-backup with -f or -o", argv[0], 66);
      }
   }
   else
   {
      if ((prefix == NULL) && (suffix == NULL))
      {
         suffix = ".uncrustify";
      }
   }

   /* Try to load the config file, if available.
    * It is optional for "--universalindent" and "--detect", but required for
    * everything else.
    */
   if (!cfg_file.empty())
   {
      cpd.filename = cfg_file.c_str();
      if (load_option_file(cpd.filename) < 0)
      {
         usage_exit("Unable to load the config file", argv[0], 56);
      }
   }

   if (arg.Present("--universalindent"))
   {
      FILE *pfile = stdout;

      if (output_file != NULL)
      {
         pfile = fopen(output_file, "w");
         if (pfile == NULL)
         {
            fprintf(stderr, "Unable to open %s for write: %s (%d)\n",
                    output_file, strerror(errno), errno);
            return(EXIT_FAILURE);
         }
      }

      print_universal_indent_cfg(pfile);

      return(EXIT_SUCCESS);
   }

   if (detect)
   {
      file_mem fm;

      if ((source_file == NULL) || (source_list != NULL))
      {
         fprintf(stderr, "The --detect option requires a single input file\n");
         return(EXIT_FAILURE);
      }

      /* Do some simple language detection based on the filename extension */
      if (!cpd.lang_forced || (cpd.lang_flags == 0))
      {
         cpd.lang_flags = language_from_filename(source_file);
      }

      /* Try to read in the source file */
      if (load_mem_file(source_file, fm) < 0)
      {
         LOG_FMT(LERR, "Failed to load (%s)\n", source_file);
         cpd.error_count++;
         return(EXIT_FAILURE);
      }

      uncrustify_start(fm.data);
      detect_options();
      uncrustify_end();

      redir_stdout(output_file);
      save_option_file(stdout, update_config_wd);
      return(EXIT_SUCCESS);
   }

   /* Everything beyond this point requires a config file, so complain and
    * bail if we don't have one.
    */
   if (cfg_file.empty())
   {
      usage_exit("Specify the config file with '-c file' or set UNCRUSTIFY_CONFIG",
                 argv[0], 58);
   }

   /*
    *  Done parsing args
    */

   if (update_config || update_config_wd)
   {
      redir_stdout(output_file);
      save_option_file(stdout, update_config_wd);
      return(0);
   }

   /* Check for unused args (ignore them) */
   idx   = 1;
   p_arg = arg.Unused(idx);

   /* Check args - for multifile options */
   if ((source_list != NULL) || (p_arg != NULL))
   {
      if (source_file != NULL)
      {
         usage_exit("Cannot specify both the single file option and a multi-file option.",
                    argv[0], 67);
      }

      if (output_file != NULL)
      {
         usage_exit("Cannot specify -o with a multi-file option.",
                    argv[0], 68);
      }
   }

   /* This relies on cpd.filename being the config file name */
   load_header_files();

   if ((source_file == NULL) && (source_list == NULL) && (p_arg == NULL))
   {
      /* no input specified, so use stdin */
      if (cpd.lang_flags == 0)
      {
         cpd.lang_flags = LANG_C;
      }

      redir_stdout(output_file);

      file_mem fm;
      if (!read_stdin(fm))
      {
         LOG_FMT(LERR, "Failed to read stdin\n");
         return(100);
      }

      cpd.filename = "stdin";

      /* Done reading from stdin */
      LOG_FMT(LSYS, "Parsing: %d bytes (%d chars) from stdin as language %s\n",
              (int)fm.raw.size(), (int)fm.data.size(),
              language_to_string(cpd.lang_flags));

      uncrustify_file(fm, stdout, parsed_file);
   }
   else if (source_file != NULL)
   {
      /* Doing a single file */
      do_source_file(source_file, output_file, parsed_file, no_backup, keep_mtime);
   }
   else
   {
      /* Doing multiple files */
      if (prefix != NULL)
      {
         LOG_FMT(LSYS, "Output prefix: %s/\n", prefix);
      }
      if (suffix != NULL)
      {
         LOG_FMT(LSYS, "Output suffix: %s\n", suffix);
      }

      /* Do the files on the command line first */
      idx = 1;
      while ((p_arg = arg.Unused(idx)) != NULL)
      {
         char outbuf[1024];
         do_source_file(p_arg,
                        make_output_filename(outbuf, sizeof(outbuf), p_arg, prefix, suffix),
                        NULL, no_backup, keep_mtime);
      }

      if (source_list != NULL)
      {
         process_source_list(source_list, prefix, suffix, no_backup, keep_mtime);
      }
   }

   clear_keyword_file();
   clear_defines();

   return((cpd.error_count != 0) ? 1 : 0);
}