Exemplo n.º 1
0
/*******************************************************************************************************************
*	FUNCTION NAME : main.c
*
*	DESCRIPTON : calls other functions
*
*	RETURN VALUE : SUCCESS
*
***********************************************************************************************************************/
int main(int argc, char *argv[])
{
	/*error handling for command line arguments*/
	if(NULL == argv[1])
	{
		printf("please provide first input file name\n");
		exit(FAILURE);
	}
	if(NULL == argv[2])
	{
		printf("please provide second input file name\n");
		exit(FAILURE);
	}
	if(NULL == argv[3])
	{
		printf("please provide output file name\n");
		exit(FAILURE);
	}

	FILE *fp1;//file pointer for first input file
	FILE *fp2;//file pointer for second input file
	FILE *fp3;//file pointer for output file

	char input[MAX];//for storing strings read from the file
	memset(input, 0, MAX*sizeof(char));//initializing input to null

	char keyword[10];//for storing keywors read from the file
	memset(keyword, 0, 10*sizeof(char));//initializing keyword to null

	node *start = NULL;//start pointer for the list

	file_open(&fp1, argv[1], "r"); //open first input file for reading
	file_open(&fp2, argv[2], "r"); //open second input file for reading
	file_open(&fp3, argv[3], "w"); //open output file for writing

	/*reading from input1.txt and storing it into the linked list*/
	while(1)
	{
		fgets(input, (MAX-1)*sizeof(char), fp1); //using fgets to read full line
		if(feof(fp1))
		{
			break;
		}
		remove_new_line(input);
		insert_list(&start, input);
	}

	printf("\n*************LIST CONTENTS***************\n");
	display_list(&start); //display the linked list

	/*reading the keyword from input2.txt, searching in linked list and if found printing it in output.txt*/
	while(1)
	{
		/*use only fscanf to read the keyword, else you won't get the correct output*/
		fscanf(fp2, "%s", keyword); 
		if(feof(fp2))
		{
			break;
		}
		search_keyword(&start, keyword, &fp3);
	}
	
	/*closing all input files*/
	file_close(&fp1);
	file_close(&fp2);
	file_close(&fp3);

	/*free the linked list*/
	free_list(&start);

	return SUCCESS;
}
Exemplo n.º 2
0
bool mysqld_help(THD *thd, const char *mask)
{
  Protocol *protocol= thd->protocol;
  SQL_SELECT *select;
  st_find_field used_fields[array_elements(init_used_fields)];
  TABLE_LIST *leaves= 0;
  TABLE_LIST tables[4];
  List<String> topics_list, categories_list, subcategories_list;
  String name, description, example;
  int count_topics, count_categories, error;
  uint mlen= strlen(mask);
  size_t i;
  MEM_ROOT *mem_root= thd->mem_root;
  DBUG_ENTER("mysqld_help");

  bzero((char *)((uchar*)tables),sizeof(tables));
  tables[0].alias= tables[0].table_name= (char*) "help_topic";
  tables[0].lock_type= TL_READ;
  tables[0].next_global= tables[0].next_local= 
    tables[0].next_name_resolution_table= &tables[1];
  tables[1].alias= tables[1].table_name= (char*) "help_category";
  tables[1].lock_type= TL_READ;
  tables[1].next_global= tables[1].next_local= 
    tables[1].next_name_resolution_table= &tables[2];
  tables[2].alias= tables[2].table_name= (char*) "help_relation";
  tables[2].lock_type= TL_READ;
  tables[2].next_global= tables[2].next_local= 
    tables[2].next_name_resolution_table= &tables[3];
  tables[3].alias= tables[3].table_name= (char*) "help_keyword";
  tables[3].lock_type= TL_READ;
  tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";

  Open_tables_state open_tables_state_backup;
  if (open_system_tables_for_read(thd, tables, &open_tables_state_backup))
    goto error2;

  /*
    Init tables and fields to be usable from items
    tables do not contain VIEWs => we can pass 0 as conds
  */
  thd->lex->select_lex.context.table_list=
    thd->lex->select_lex.context.first_name_resolution_table= &tables[0];
  if (setup_tables(thd, &thd->lex->select_lex.context,
                   &thd->lex->select_lex.top_join_list,
                   tables, &leaves, FALSE))
    goto error;
  memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields));
  if (init_fields(thd, tables, used_fields, array_elements(used_fields)))
    goto error;
  for (i=0; i<sizeof(tables)/sizeof(TABLE_LIST); i++)
    tables[i].table->file->init_table_handle_for_HANDLER();

  if (!(select=
	prepare_select_for_name(thd,mask,mlen,tables,tables[0].table,
				used_fields[help_topic_name].field,&error)))
    goto error;

  count_topics= search_topics(thd,tables[0].table,used_fields,
			      select,&topics_list,
			      &name, &description, &example);
  delete select;

  if (count_topics == 0)
  {
    int UNINIT_VAR(key_id);
    if (!(select=
          prepare_select_for_name(thd,mask,mlen,tables,tables[3].table,
                                  used_fields[help_keyword_name].field,
                                  &error)))
      goto error;

    count_topics= search_keyword(thd,tables[3].table, used_fields, select,
                                 &key_id);
    delete select;
    count_topics= (count_topics != 1) ? 0 :
                  get_topics_for_keyword(thd,tables[0].table,tables[2].table,
                                         used_fields,key_id,&topics_list,&name,
                                         &description,&example);
  }

  if (count_topics == 0)
  {
    int16 category_id;
    Field *cat_cat_id= used_fields[help_category_parent_category_id].field;
    if (!(select=
          prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
                                  used_fields[help_category_name].field,
                                  &error)))
      goto error;

    count_categories= search_categories(thd, tables[1].table, used_fields,
					select,
					&categories_list,&category_id);
    delete select;
    if (!count_categories)
    {
      if (send_header_2(protocol,FALSE))
	goto error;
    }
    else if (count_categories > 1)
    {
      if (send_header_2(protocol,FALSE) ||
	  send_variant_2_list(mem_root,protocol,&categories_list,"Y",0))
	goto error;
    }
    else
    {
      Field *topic_cat_id= used_fields[help_topic_help_category_id].field;
      Item *cond_topic_by_cat=
	new Item_func_equal(new Item_field(topic_cat_id),
			    new Item_int((int32)category_id));
      Item *cond_cat_by_cat=
	new Item_func_equal(new Item_field(cat_cat_id),
			    new Item_int((int32)category_id));
      if (!(select= prepare_simple_select(thd, cond_topic_by_cat,
                                          tables[0].table, &error)))
        goto error;
      get_all_items_for_category(thd,tables[0].table,
				 used_fields[help_topic_name].field,
				 select,&topics_list);
      delete select;
      if (!(select= prepare_simple_select(thd, cond_cat_by_cat,
                                          tables[1].table, &error)))
        goto error;
      get_all_items_for_category(thd,tables[1].table,
				 used_fields[help_category_name].field,
				 select,&subcategories_list);
      delete select;
      String *cat= categories_list.head();
      if (send_header_2(protocol, TRUE) ||
	  send_variant_2_list(mem_root,protocol,&topics_list,       "N",cat) ||
	  send_variant_2_list(mem_root,protocol,&subcategories_list,"Y",cat))
	goto error;
    }
  }
  else if (count_topics == 1)
  {
    if (send_answer_1(protocol,&name,&description,&example))
      goto error;
  }
  else
  {
    /* First send header and functions */
    if (send_header_2(protocol, FALSE) ||
	send_variant_2_list(mem_root,protocol, &topics_list, "N", 0))
      goto error;
    if (!(select=
          prepare_select_for_name(thd,mask,mlen,tables,tables[1].table,
                                  used_fields[help_category_name].field,&error)))
      goto error;
    search_categories(thd, tables[1].table, used_fields,
		      select,&categories_list, 0);
    delete select;
    /* Then send categories */
    if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0))
      goto error;
  }
  my_eof(thd);

  close_system_tables(thd, &open_tables_state_backup);
  DBUG_RETURN(FALSE);

error:
  close_system_tables(thd, &open_tables_state_backup);

error2:
  DBUG_RETURN(TRUE);
}
Exemplo n.º 3
0
void
put_declaration(void)
{
  int i;
  int simple_varargs;

  put_lineno();
  the_env_defined = 1;
  fprintf(out, "\tconst cl_env_ptr the_env = ecl_process_env();\n");
  for (i = 0;  i < nopt;  i++) {
    put_lineno();
    fprintf(out, "\tcl_object %s;\n", optional[i].o_var);
  }
  for (i = 0;  i < nopt;  i++)
    if (optional[i].o_svar != NULL) {
      put_lineno();
      fprintf(out, "\tbool %s;\n", optional[i].o_svar);
    }
  if (key_flag) {
    put_lineno();
    if (nkey) {
      fprintf(out, "\tstatic cl_object KEYS[%d] = {", nkey);
      for (i = 0; i < nkey; i++) {
        if (i > 0)
          fprintf(out, ", ");
        fprintf(out, "(cl_object)(cl_symbols+%d)", search_keyword(keyword[i].k_key));
      }
      fprintf(out, "};\n");
    } else {
      fprintf(out, "\tcl_object *KEYS = NULL;\n");
    }
  }
  for (i = 0;  i < nkey;  i++) {
    fprintf(out, "\tcl_object %s;\n", keyword[i].k_var);
    if (keyword[i].k_svar != NULL)
      fprintf(out, "\tbool %s;\n", keyword[i].k_svar);
  }
  for (i = 0;  i < naux;  i++) {
    put_lineno();
    fprintf(out, "\tcl_object %s;\n", aux[i].a_var);
  }
  if (nopt == 0 && !rest_flag && !key_flag) {
    put_lineno();
    fprintf(out, "\tif (ecl_unlikely(narg!=%d))", nreq);
    fprintf(out, "\t   FEwrong_num_arguments(ecl_make_fixnum(%d));\n",
            function_code);
  } else {
    simple_varargs = !rest_flag && !key_flag && ((nreq + nopt) < 32);
    if (key_flag) {
      put_lineno();
      /* We do this because Microsoft VC++ does not support arrays of zero size */
      if (nkey) {
        fprintf(out, "\tcl_object KEY_VARS[%d];\n", 2*nkey);
      } else {
        fprintf(out, "\tcl_object *KEY_VARS = NULL;\n");
      }
    }
    put_lineno();
    if (simple_varargs)
        fprintf(out,"\tva_list %s;\n\tva_start(%s, %s);\n",
                rest_var, rest_var, ((nreq > 0) ? required[nreq-1] : "narg"));
    else
        fprintf(out,"\tecl_va_list %s;\n\tecl_va_start(%s, %s, narg, %d);\n",
                rest_var, rest_var, ((nreq > 0) ? required[nreq-1] : "narg"),
                nreq);
    put_lineno();
    fprintf(out, "\tif (ecl_unlikely(narg < %d", nreq);
    if (nopt > 0 && !rest_flag && !key_flag) {
      fprintf(out, "|| narg > %d", nreq + nopt);
    }
    fprintf(out, ")) FEwrong_num_arguments(ecl_make_fixnum(%d));\n", function_code);
    for (i = 0;  i < nopt;  i++) {
      put_lineno();
      fprintf(out, "\tif (narg > %d) {\n", nreq+i);
      put_lineno();
      fprintf(out, simple_varargs?
              "\t\t%s = va_arg(%s,cl_object);\n":
              "\t\t%s = ecl_va_arg(%s);\n",
              optional[i].o_var, rest_var);
      if (optional[i].o_svar) {
        put_lineno();
        fprintf(out, "\t\t%s = TRUE;\n", optional[i].o_svar);
      }
      put_lineno();
      fprintf(out, "\t} else {\n");
      put_lineno();
      fprintf(out, "\t\t%s = %s;\n",
              optional[i].o_var,
              optional[i].o_init == NULL ? "ECL_NIL" : optional[i].o_init);
      if (optional[i].o_svar) {
        put_lineno();
        fprintf(out, "\t\t%s = FALSE;\n", optional[i].o_svar);
      }
      put_lineno();
      fprintf(out, "\t}\n");
    }
    if (key_flag) {
      put_lineno();
      fprintf(out, "\tcl_parse_key(ARGS, %d, KEYS, KEY_VARS, NULL, %d);\n",
              nkey, allow_other_keys_flag);
      for (i = 0;  i < nkey;  i++) {
        put_lineno();
        fprintf(out, "\tif (KEY_VARS[%d]==ECL_NIL) {\n", nkey+i);
        if (keyword[i].k_init != NULL) {
          put_lineno();
          fprintf(out, "\t  %s = %s;\n", keyword[i].k_var, keyword[i].k_init);
        } else {
          put_lineno();
          fprintf(out, "\t  %s = ECL_NIL;\n", keyword[i].k_var);
        }
        if (keyword[i].k_svar != NULL) {
          put_lineno();
          fprintf(out, "\t  %s = FALSE;\n", keyword[i].k_svar);
        }
        fprintf(out, "\t} else {\n");
        if (keyword[i].k_svar != NULL) {
          put_lineno();
          fprintf(out, "\t  %s = TRUE;\n", keyword[i].k_svar);
        }
        put_lineno();
        fprintf(out, "\t  %s = KEY_VARS[%d];\n\t}\n", keyword[i].k_var, i);
      }
    }
  }
  for (i = 0;  i < naux;  i++) {
    put_lineno();
    fprintf(out, "\t%s = %s;\n", aux[i].a_var,
            aux[i].a_init == NULL ? "ECL_NIL" : aux[i].a_init);
  }
}