Esempio n. 1
0
gboolean
macro_insert (MacroPlugin * plugin, const gchar *keyword)
{
	GtkTreeIter parent;
	GtkTreeIter cur_cat;
	GtkTreeModel *model = macro_db_get_model (plugin->macro_db);
	
	gtk_tree_model_get_iter_first (model, &parent);
	do
	{
		if (gtk_tree_model_iter_children (model, &cur_cat, &parent))
		{
		do
		{
			GtkTreeIter cur_macro;
			if (gtk_tree_model_iter_children
			    (model, &cur_macro, &cur_cat))
			{
				do
				{
					gboolean predefined;
					gtk_tree_model_get (model, &cur_macro,
						    MACRO_PREDEFINED,
						    &predefined, -1);
					if (predefined)
					{
						if (match_keyword (plugin, &cur_macro, keyword))
						{
							return TRUE;
						}
					}
				}
				while (gtk_tree_model_iter_next
				       (model, &cur_macro));
			}
			else
			{
				gboolean is_category;
				gtk_tree_model_get (model, &cur_cat,
						    MACRO_IS_CATEGORY,
						    &is_category, -1);
				if (is_category)
					continue;
				
				if (match_keyword (plugin, &cur_cat, keyword))
				{
					return TRUE;
				}
			}
		}
		while (gtk_tree_model_iter_next (model, &cur_cat));
		}
	}
	while (gtk_tree_model_iter_next (model, &parent));
	return TRUE;
}
Esempio n. 2
0
static void findBasicTags (void)
{
	const char *line;
	KeyWord *keywords;

	keywords = freebasic_keywords;

	while ((line = (const char *) readLineFromInputFile ()) != NULL)
	{
		const char *p = line;
		KeyWord const *kw;

		while (isspace (*p))
			p++;

		/* Empty line or comment? */
		if (!*p || *p == '\'')
			continue;

		/* In Basic, keywords always are at the start of the line. */
		for (kw = keywords; kw->token; kw++)
			if (match_keyword (p, kw)) break;

		/* Is it a label? */
		match_colon_label (p);
	}
}
Esempio n. 3
0
static int
scan_keyword(struct misc_file_buffer* file, enum scan_keyword_id* id, int line)
{
	unsigned int i;

	for (i=0; i < ARRAY_SIZE(keyword_list); i++)
		if (match_keyword(file, keyword_list[i].keyword) == 0) {
			file->pos += strlen(keyword_list[i].keyword);
			*id = keyword_list[i].id;
			return 0;
		}
	error_reason("Line %d: unknown keyword", line);
	return -1;
}
Esempio n. 4
0
		std::unique_ptr<Token> Lexer::alpha()
		{
			std::wstring value;
			while (file_->good() && (iswalnum(current_char_) || current_char_ == L'_'))
			{
				value += current_char_;
				consume();
			}

			auto keyword = match_keyword(value);
			if (keyword != nullptr)
				return keyword;

			return std::make_unique<Token>(TokenType::Identifier, value, line_number_, file_->get_file_name());
		}
Esempio n. 5
0
static C_RESULT parse_I(FILE* f)
{
  char keyword[KW_MAX_LEN];

  while( SUCCEED(fetch_char(f)) && is_separator(next_c) );

  while( !is_eol(next_c) ) {
    keyword_t kw;

    parse_string( f, keyword, KW_MAX_LEN );
    if( SUCCEED( match_keyword( keyword, &kw ) ) )
    {
      parse_keyword( f, kw );
    }
  }

  return C_OK;
}
Esempio n. 6
0
void conf_file(FILE *f)
{
	char *line;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case Devices:
			devline(line);
			break;
		case Array:
			arrayline(line);
			break;
		case Mailaddr:
			mailline(line);
			break;
		case Mailfrom:
			mailfromline(line);
			break;
		case Program:
			programline(line);
			break;
		case CreateDev:
			createline(line);
			break;
		case Homehost:
			homehostline(line);
			break;
		case AutoMode:
			autoline(line);
			break;
		case Policy:
			policyline(line, rule_policy);
			break;
		case PartPolicy:
			policyline(line, rule_part);
			break;
		default:
			pr_err("Unknown keyword %s\n", line);
		}
		free_line(line);
	}
}
Esempio n. 7
0
static void findBasicTags (void)
{
	const char *line;
	const char *extension = fileExtension (getInputFileName ());
	KeyWord *keywords;

	if (strcmp (extension, "bb") == 0)
		keywords = blitzbasic_keywords;
	else if (strcmp (extension, "pb") == 0)
		keywords = purebasic_keywords;
	else
		keywords = freebasic_keywords;

	while ((line = (const char *) readLineFromInputFile ()) != NULL)
	{
		const char *p = line;
		KeyWord const *kw;

		while (isspace (*p))
			p++;

		/* Empty line? */
		if (!*p)
			continue;

		/* In Basic, keywords always are at the start of the line. */
		for (kw = keywords; kw->token; kw++)
			if (match_keyword (p, kw)) break;

		/* Is it a label? */
		if (strcmp (extension, "bb") == 0)
			match_dot_label (p);
		else
			match_colon_label (p);
	}
}
Esempio n. 8
0
File: Cdlib.c Progetto: dhaley/dcp
void main (int argc, char **argv)
{ char line[2048];
  cd_library my_cds;

  FILE *cd_file;
  cd_title *cd_p, *prev_cd_p, *cd_p_2;
  char cd_info_path[PATH_MAX], *lp;
  int tr;

  if (argc == 1)
    sprintf (cd_info_path, "%s/.workmandb", getenv ("HOME"));
  else
    strcpy (cd_info_path, argv[1]);

  cd_file = fopen (cd_info_path, "r");
  if (cd_file == NULL) {
    printf ("Error opening file %s\n", cd_info_path);
    exit (1); }

  my_cds.count = 0;
  my_cds.first = NULL;

  while (fgets (line, sizeof(line), cd_file) != NULL) {
    line[strlen(line) - 1] = '\0';
    if (lp = match_keyword ("tracks", line)) {
      cd_p = (cd_title *) malloc (sizeof (cd_title));

      cd_p->name = NULL;
      cd_p->artist = NULL;
      cd_p->count = parse_int (&lp);
      cd_p->track = (cd_track *)malloc (sizeof(cd_track) * cd_p->count);
      for (tr = 0; tr < cd_p->count; tr++) {
	cd_p->track[tr].start = parse_int(&lp) / 75;
	cd_p->track[tr].name = NULL; 
      }
      cd_p->time = parse_int(&lp); 
      cd_p->next = NULL;

      if (my_cds.first == NULL)
	my_cds.first = cd_p;
      else
	prev_cd_p->next = cd_p;

      prev_cd_p = cd_p;
      my_cds.count++;
      tr = 0; 
    }
    else
    if (lp = match_keyword ("cdname", line))
      cd_p->name = strdup (lp);
    else
    if (lp = match_keyword ("artist", line))
      cd_p->artist = strdup (lp);
    else
    if (lp = match_keyword ("track", line)) {
      if (tr < cd_p->count - 1) {
	cd_p->track[tr].time = 
	  cd_p->track[tr + 1].start - cd_p->track[tr].start;
	cd_p->track[tr].next = &cd_p->track[tr + 1];
      }
      else
	cd_p->track[tr].time = cd_p->time - cd_p->track[tr].start;
      cd_p->track[tr++].name = strdup (lp);
    }
  }
  
  {
    int total_time = 0, longest = 0, shortest = 0;
    char *long_title, *short_title;

    printf ("\nCD Library Statistics:\n\n");
    printf (" Titles:         %d\n\n", my_cds.count);
    for (cd_p = my_cds.first; cd_p != NULL; cd_p = cd_p->next) {
      total_time += cd_p->time;
      if (cd_p->time > longest) {
	longest = cd_p->time;
	long_title = cd_p->name;
      }
      if (cd_p->time < shortest || shortest == 0) {
	shortest = cd_p->time;
	short_title = cd_p->name;
      }
    }
    printf (" Total time:   %s\n", format_time (total_time));
    printf (" Average time: %s\n\n", format_time (total_time / my_cds.count));
    printf (" Longest CD:   %s  %s\n", format_time (longest), long_title);
    printf (" Shortest CD:  %s  %s\n", format_time (shortest), short_title);
  }
  for (cd_p = my_cds.first; cd_p != NULL; ) {
    cd_title *temp = cd_p;
    my_cds.first = temp->next;
    my_cds.count--;
    for (tr = 0; tr < temp->count; tr++)
      free (temp->track[tr].name);
    free (temp->name);
    free (temp->artist);
    free (temp->track);
    cd_p = cd_p->next;
    free (temp);
  }
}
Esempio n. 9
0
void load_conffile(char *conffile)
{
	FILE *f;
	char *line;

	if (loaded) return;
	if (conffile == NULL)
		conffile = DefaultConfFile;

	if (strcmp(conffile, "none") == 0) {
		loaded = 1;
		return;
	}
	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
		loaded = 1;
		return;
	}
	f = fopen(conffile, "r");
	/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
	 * To allow Debian users to compile from clean source and still
	 * have a working mdadm, we read /etc/mdadm/mdadm.conf
	 * if /etc/mdadm.conf doesn't exist
	 */
	if (f == NULL &&
	    conffile == DefaultConfFile) {
		f = fopen(DefaultAltConfFile, "r");
		if (f)
			conffile = DefaultAltConfFile;
	}
	if (f == NULL)
		return;

	loaded = 1;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case 0: /* DEVICE */
			devline(line);
			break;
		case 1: /* ARRAY */
			arrayline(line);
			break;
		case 2: /* MAIL */
			mailline(line);
			break;
		case 3: /* PROGRAM */
			programline(line);
			break;
		default:
			fprintf(stderr, Name ": Unknown keyword %s\n", line);
		}
		free_line(line);
	}
    
	fclose(f);

/*    printf("got file\n"); */
}
Esempio n. 10
0
File: lex.c Progetto: jkdewar/rook
/*----------------------------------------------------------------------*/
static int next_token(lex_state_t *l) {
    token_t *token;
    char c;
    char cn;
    token = &l->out->tokens[l->out->token_count];
    skip_comments_and_whitespace(l);
    token->source_pos = l->ptr - l->in->source;
    c  = *(l->ptr + 0);
    cn = *(l->ptr + 1);
    if (c == '\0') {
        return 0;
    } else if (c == '\"') {
        read_string(l, token);
    } else if (is_decimal_digit(c)) {
        read_number(l, token);
    } else if (is_identifier_char(c)) {
        read_identifier(l, token);
        match_keyword(token);
    } else if (c == '<' && cn == '=') {
        token->type = TK_LESS_EQUAL;
        l->ptr += 2;
    } else if (c == '=' && cn == '=') {
        token->type = TK_EQUALS_EQUALS;
        l->ptr += 2;
    } else if (c == '>' && cn == '=') {
        token->type = TK_GREATER_EQUAL;
        l->ptr += 2;
    } else if (c == '+') {
        token->type = TK_PLUS;
        ++l->ptr;
    } else if (c == '-') {
        token->type = TK_MINUS;
        ++l->ptr;
    } else if (c == '*') {
        token->type = TK_STAR;
        ++l->ptr;
    } else if (c == '/') {
        token->type = TK_SLASH;
        ++l->ptr;
    } else if (c == '=') {
        token->type = TK_EQUALS;
        ++l->ptr;
    } else if (c == '<') {
        token->type = TK_LESS;
        ++l->ptr;
    } else if (c == '>') {
        token->type = TK_GREATER;
        ++l->ptr;
    } else if (c == '(') {
        token->type = TK_LBRACKET;
        ++l->ptr;
    } else if (c == ')') {
        token->type = TK_RBRACKET;
        ++l->ptr;
    } else if (c == ',') {
        token->type = TK_COMMA;
        ++l->ptr;
    } else if (c == ':') {
        token->type = TK_COLON;
        ++l->ptr;
    } else if (c == ';') {
        token->type = TK_SEMICOLON;
        ++l->ptr;
    } else {
        error(l);
    }
    return 1;
}
Esempio n. 11
0
void load_conffile(void)
{
	FILE *f;
	char *line;

	if (loaded) return;
	if (conffile == NULL)
		conffile = DefaultConfFile;

	if (strcmp(conffile, "none") == 0) {
		loaded = 1;
		return;
	}
	if (strcmp(conffile, "partitions")==0) {
		char *list = dl_strdup("DEV");
		dl_init(list);
		dl_add(list, dl_strdup("partitions"));
		devline(list);
		free_line(list);
		loaded = 1;
		return;
	}
	f = fopen(conffile, "r");
	/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
	 * To allow Debian users to compile from clean source and still
	 * have a working mdadm, we read /etc/mdadm/mdadm.conf
	 * if /etc/mdadm.conf doesn't exist
	 */
	if (f == NULL &&
	    conffile == DefaultConfFile) {
		f = fopen(DefaultAltConfFile, "r");
		if (f)
			conffile = DefaultAltConfFile;
	}
	if (f == NULL)
		return;

	loaded = 1;
	while ((line=conf_line(f))) {
		switch(match_keyword(line)) {
		case Devices:
			devline(line);
			break;
		case Array:
			arrayline(line);
			break;
		case Mailaddr:
			mailline(line);
			break;
		case Mailfrom:
			mailfromline(line);
			break;
		case Program:
			programline(line);
			break;
		case CreateDev:
			createline(line);
			break;
		case Homehost:
			homehostline(line);
			break;
		default:
			fprintf(stderr, Name ": Unknown keyword %s\n", line);
		}
		free_line(line);
	}
    
	fclose(f);

/*    printf("got file\n"); */
}