コード例 #1
0
ファイル: io.c プロジェクト: jaz303/lispy
void pretty_print(env_t *env, VALUE v, int i) {
    if (VALUE_IS_ERROR(v)) {
        printf("<error>\n");
    } else if (IS_LIST(v)) {
        printf("(\n");
		int j;
		for (j = 0; j < list_len(v); j++) {
            indent(i + 1); pretty_print(env, list_get(v, j), i + 1);
		}
		indent(i); printf(")\n");
    } else {
        if (VALUE_IS_INT(v)) {
    		printf("%lld\n", INTVAL(v));
    	} else if (VALUE_IS_BOOL(v)) {
    		printf("#%c\n", BOOLVAL(v) ? 't' : 'f');
        } else if (VALUE_IS_NIL(v)) {
            printf("#nil\n");
        } else if (VALUE_IS_IDENT(v)) {
            printf("%s\n", intern_table_get_str(&env->intern, IDENT(v)));
        } else if (VALUE_IS_ATOM(v)) {
            printf(":%s\n", intern_table_get_str(&env->intern, ATOM(v)));
        } else if (IS_STRING(v)) {
    		printf("\"%s\"\n", string_chars(v));
		} else {
            printf("<unknown %p>\n", v);
    	}
    }
}
コード例 #2
0
static void write_data(Octstr *out, int fd) {
	unsigned char buf[EVIL_BUFSIZE];
	int len;
	ssize_t ret;
	
	len = sizeof(buf);
	if (len > octstr_len(out))
		len = octstr_len(out);
	if (len == 0)
		return;
	octstr_get_many_chars(buf, out, 0, len);
	ret = write(fd, buf, len);
	if (ret > 0) {
		if (logging == LOG_data)
			pretty_print(buf, ret);
		octstr_delete(out, 0, ret);
	} else if (ret == 0) {
		warning(0, "empty write");
	} else {
		if (errno == EINTR || errno == EAGAIN)
			return;
		error(errno, "write_data");
		exit(1);
	}
}
コード例 #3
0
ファイル: solution_46.cpp プロジェクト: RichyMong/std
int main()
{
    std::vector<int> nums { 1, 2, 3 };
    auto ret = Solution::permute(nums);
    for (auto& x : ret) {
        pretty_print(x.begin(), x.end());
    }
}
コード例 #4
0
ファイル: is_bst.c プロジェクト: kalyan359/datastructures
int main(){
	bin_tree * r1 = create_binary_tree("input/non-bst.in");	
	bin_tree * r2 = create_binary_tree("input/bst2.in");
	bin_tree * r3 = create_binary_tree("input/is_bst.in");
	inorder(r1);
	puts("");
	pretty_print(r1);
	printf("%d\n\n",is_valid(check_binary_search_tree(r1)));
	inorder(r2);
	puts("");
	pretty_print(r2);
	printf("%d\n\n",is_valid(check_binary_search_tree(r2)));
	inorder(r3);
	puts("");
	pretty_print(r3);
	printf("%d\n\n",is_valid(check_binary_search_tree(r3)));
}
コード例 #5
0
ファイル: interrupt.cpp プロジェクト: fengguoqing/powertop
interrupt::interrupt(const char *_handler, int _number) : power_consumer()
{
	char buf[128];
	running_since = 0;
	number = _number;
	pt_strcpy(handler, _handler);
	raw_count = 0;
	snprintf(desc, sizeof(desc), "[%i] %s", number, pretty_print(handler, buf, 128));
}
コード例 #6
0
ファイル: eval.c プロジェクト: dkazantzas/bfs
/**
 * -print action.
 */
bool eval_print(const struct expr *expr, struct eval_state *state) {
	const struct colors *colors = state->cmdline->stdout_colors;
	if (colors) {
		fill_statbuf(state);
	}

	pretty_print(colors, state->ftwbuf);
	return true;
}
コード例 #7
0
static void pretty_print(bencode_item_t *el, GString *s) {
	bencode_item_t *chld;
	const char *sep;

	switch (el->type) {
		case BENCODE_STRING:
			g_string_append(s, "\"");
			g_string_append_len(s, el->iov[1].iov_base, el->iov[1].iov_len);
			g_string_append(s, "\"");
			break;

		case BENCODE_INTEGER:
			g_string_append_printf(s, "%lli", el->value);
			break;

		case BENCODE_LIST:
			g_string_append(s, "[ ");
			sep = "";
			for (chld = el->child; chld; chld = chld->sibling) {
				g_string_append(s, sep);
				pretty_print(chld, s);
				sep = ", ";
			}
			g_string_append(s, " ]");
			break;

		case BENCODE_DICTIONARY:
			g_string_append(s, "{ ");
			sep = "";
			for (chld = el->child; chld; chld = chld->sibling) {
				g_string_append(s, sep);
				pretty_print(chld, s);
				g_string_append(s, ": ");
				chld = chld->sibling;
				pretty_print(chld, s);
				sep = ", ";
			}
			g_string_append(s, " }");
			break;

		default:
			abort();
	}
}
コード例 #8
0
ファイル: bootstrap.c プロジェクト: jbf/tonsai-scheme
/*
 * Load shceme ibrary from "lib/lib_boot.scm" into lib or internal environment.
 */
int load_lib_scm(symbol_table *symtab, environ_t *lib, environ_t *internal) {
  cell_t *cell, *res;
  STREAM s;
  FILE *f;
  
  if (((f = fopen("lib/lib_boot.scm", "r")) == NULL) &&
      ((f = fopen("lib/lib_boot_test.scm", "r")) == NULL)) {
    perror(AT);
    DEBUGPRINT_("Can't open \"lib/lib_boot.scm\".\n");
    return 0;
  }

  /* set up a mini-repl here that aborts on any error */
  if (setjmp(__jmp_env)) {
    DEBUGPRINT_("Error evaluating \"lib/lib_boot.scm\". Exiting. \n");
    fclose(f); /* this is bad, but works for now */
    return 0;
  }

  make_filestream(&s, f);
  while ((cell = read_intern(&s, global_symtab))) {
    DEBUGPRINT_("Found form in lib/lib_boot.scm\n");

    /* mini-eval each form with internal as initial env*/
    orig_sexpr = cell;
    res = evaluate(cell, internal); // UNSAFE!
    if (res) {
#ifdef DEBUG_BOOT
      pretty_print(res);
#endif /* DEBUG_BOOT */
    } else {
      DEBUGPRINT_("Got NULL from eval of: ");
      pretty_print(orig_sexpr);
      DEBUGPRINT_("Error evaluating \"lib/lib_boot.scm\". Exiting. \n");
      fclose(f); /* this is bad, but works for now */
      return 0;
    }
    orig_sexpr = NULL;
  }

  stream_close(&s); /* this closes FILE *f as well */
  return 1;
}
コード例 #9
0
ファイル: util.cpp プロジェクト: huangxliang/uta-wbc-dreamer
    bool check_vector(char const * name,
		      jspace::Vector const & want,
		      jspace::Vector const & have,
		      double precision,
		      std::ostream & msg)
    {
      int const nelems(want.size());
      if (nelems != have.size()) {
	msg << "check_vector(" << name << ") size mismatch: have " << have.size()
	    << " elements but want " << nelems << "\n";
	return false;
      }
  
      precision = fabs(precision);
      double maxdelta(0);
      jspace::Vector delta(nelems);
      for (int ii(0); ii < nelems; ++ii) {
	delta.coeffRef(ii) = fabs(smart_delta(have[ii], want[ii]));
	if (delta.coeff(ii) > precision) {
	  maxdelta = delta.coeff(ii);
	}
      }
      double const halfmax(0.5 * maxdelta);
      double const tenprecision(10 * precision);
  
      if (maxdelta <= precision) {
	msg << "check_vector(" << name << ") OK\n";
      }
      else {
	msg << "check_vector(" << name << ") FAILED\n";
      }
      msg << "  precision = " << precision << "\n"
	  << "  maxdelta = " << maxdelta << "\n";
      pretty_print(delta, msg, "  delta", "    ");
      msg << "  error pattern\n    ";
      for (int ii(0); ii < nelems; ++ii) {
	if (delta.coeff(ii) <= precision) {
	  if (delta.coeff(ii) < halfmax) {
	    msg << ".";
	  }
	  else {
	    msg << "o";
	  }
	}
	else if (delta.coeff(ii) >= tenprecision) {
	  msg << "#";
	}
	else {
	  msg << "*";
	}
      }
      msg << "\n";
  
      return maxdelta <= precision;
    }
コード例 #10
0
ファイル: object.hpp プロジェクト: Grahack/wisp-1
 std::string operator()(object_list const& pl) const {
     std::stringstream buff;
     buff << "(";
     for (object_list::const_iterator it(pl.begin()); it != pl.end(); ++it) {
         buff << pretty_print(*it);
         if (it + 1 != pl.end()) {
             buff << " ";
         }
     }
     buff << ")";
     return buff.str();
 }
コード例 #11
0
static void pretty_print(Tree * tree){
	if(tree){
		if(tree->operator != 'o'){
			if(tree->operator == '*'){
				pretty_print(tree->left);
				printf(" %c ", tree->operator);
				pretty_print(tree->right);
			}
			else {
				printf("(");

				if(tree->left->result > tree->right->result) {
					pretty_print(tree->left);
					printf(" %c ", tree->operator);
					pretty_print(tree->right);
				}
				else {
					pretty_print(tree->right);
					printf(" %c ", tree->operator);
					pretty_print(tree->left);
				}

				printf(")");
			}
		}
		else {
			printf("%d", tree->result);
		}
	}
}
コード例 #12
0
ファイル: triangular.cpp プロジェクト: citron0xa9/Pt2
void pretty_print(int decimal)
{
	//use recursion to solve this (to flip output order)
	if (decimal > 1000) { 					//recursion end condition
		int BeforeDot = decimal/1000;
		int AfterDot = decimal % 1000;
		pretty_print(BeforeDot);
		std::cout << "." << AfterDot;
	}
	else {
		std::cout << decimal;
	}
}
コード例 #13
0
ファイル: prettyprinter.c プロジェクト: clhodapp/blip
static void pretty_print_block(lexeme tree) {
	lexeme next = get_left(tree);
	lexeme_destroy(tree);
	printf("{\n");
	tabcount++;
	printtabs();
	if (next != NULL) {
		pretty_print(next);
	}
	tabcount--;
	printtabs();
	printf("}");
}
コード例 #14
0
void pretty_print(struct node *tree, int k)
{
    int j;
    if(tree->left != NULL)
        pretty_print(tree->left, k-1);
    printf("\n");
    for(j=0; j< k-1; j++)
    {
            printf("\t");
    }
    printf("[%d,%d] ", tree->l, tree->u);
    struct list *q;
    q = tree->p;
    while(q!=NULL)
    {
        printf("%d, ", q->a);
        q = q->next;
    }
    if(tree->right != NULL)
        pretty_print(tree->right, k-1);
    return;
}
コード例 #15
0
int main(){
	/*
	* Pass the file containing, a representation of the tree. The
	* function returns the root.
	**/
	bin_tree * root = create_binary_tree("input/dll_test.txt");
	puts("");
	inorder(root);
	puts("");
	pretty_print(root);
	dll * result = convert_binary_tree_to_dll(root);
	print_list(result);
}
コード例 #16
0
int main() {
    SHOW((A<int, float>::count));

    using theB = B<int, char, float>;
    static_assert(std::is_same<std::tuple_element<0, theB::tuple_of_vector>::type, std::vector<int>>::value, "");
    static_assert(std::is_same<std::tuple_element<1, theB::tuple_of_vector>::type, std::vector<char>>::value, "");

    theB x(200,'A',3.14);
    SHOW((std::get<0>(x._data)));
    SHOW((std::get<1>(x._data)));
    SHOW((std::get<2>(x._data)));

    pretty_print(std::cout, 3.2, "hello", 42, "world");
}
コード例 #17
0
ファイル: arg.c プロジェクト: protoben/protodump
void print_flag_usage(FILE *fp, struct flag *flaglist, int nflags) {
  int i, j, k, l;
  struct flag *modes[nflags + 1], *opts[nflags + 1], *opts_wargs[nflags + 1];
  char usage[] = "Usage:", prefix[256], elements[256][256];

  for(i = j = k = l = 0; i < nflags; ++i)
    if(flaglist[i].mode)
      modes[j++] = &flaglist[i];
    else if(flaglist[i].arg == ARG_NONE)
      opts[k++] = &flaglist[i];
    else
      opts_wargs[l++] = &flaglist[i];
  modes[j] = opts[k] = opts_wargs[l] = NULL;

  for(i = 0, k = 0; modes[i]; ++i, k = 0) {
    snprintf(prefix, 256, "%-7s%s -%c", usage, NAME, modes[i]->name);
    usage[0] = '\0';

    for(j = 0; opts_wargs[j]; ++j)
      if(!modes[i]->mode_blacklist
         || !strchr(modes[i]->mode_blacklist, opts_wargs[j]->name))
        snprintf(elements[k++], 256, "[-%c <%s>]"
                                     , opts_wargs[j]->name
                                     , argtype_names[opts_wargs[j]->arg]);

    if(opts[0]) {
      elements[k][0] = '[';
      elements[k][1] = '-';
      for(j = 0, l = 2; opts[j] && l < 254; ++j)
        if(!modes[i]->mode_blacklist
           || !strchr(modes[i]->mode_blacklist, opts[j]->name))
          elements[k][l++] = opts[j]->name;
      elements[k][l++] = ']';
      elements[k][l] = '\0';
      ++k;
    }

    elements[k][0] = '\0';
    pretty_print(fp, prefix, elements);
  }

  putc('\n', fp);
  for(i = 0; modes[i]; ++i)
    fprintf(fp, "\t-%c\t%s\n", modes[i]->name, modes[i]->description);
  for(i = 0; opts_wargs[i]; ++i)
    fprintf(fp, "\t-%c\t%s\n", opts_wargs[i]->name, opts_wargs[i]->description);
  for(i = 0; opts[i]; ++i)
    fprintf(fp, "\t-%c\t%s\n", opts[i]->name, opts[i]->description);
}
コード例 #18
0
ファイル: xml.c プロジェクト: elambert/honeycomb
/* Sacha thinks we should omit the element name, but this is more in line with SAX */
hcerr_t end_element (xml_writer *xml_writer,
		     char *element_name){
  hc_simple_xml_writer_t *writer = (hc_simple_xml_writer_t*) xml_writer;
  char *current_open_element = writer->tag_stack->tag;

  require_ok(pretty_print(writer, FALSE));
  if (strcmp(current_open_element, element_name) != 0)
    HC_ERR_LOG(("expected '%s', closing '%s'\n", current_open_element, element_name));

  require_ok(hc_write(writer, "</"));
  require_ok(hc_write(writer, element_name));
  require_ok(hc_write(writer, ">"));
  pop_tag (&writer->tag_stack);
  return HCERR_OK;
}
コード例 #19
0
int main()
{
    int l, u, n, i, k, j, m, height;
    srand(time(NULL));
    printf("\nEnter the values of l, u and n : ");
    scanf("%d %d %d", &l, &u, &n);
    struct node *tree = create_interval_tree(l,u,n);
    printf("\nEnter the number of integers i : ");
    scanf("%d", &i);
    for (k = 0; k < i; ++k)
    {
        j = rand()%(u-l+1) + l;
        insert(tree, j);
    }
    height = get_height(tree);
    printf("\nThe original tree : ");
    pretty_print(tree, height);
    printf("\n\nEnter the value of m (< %d) : ", n);
    scanf("%d", &m);
    int step = (u-l+1)/m;
    k = l;
    i=0;
    while(i < m)
    {
        if((k+step-1) <= u && (i != m-1))
            tree = merge(tree, k, (k+step-1));
        else
            tree = merge(tree, k, u);
        k += step;
        i++;
        height = get_height(tree);
        printf("\n\nThe tree after the %dth iteration : ", i);
        pretty_print(tree, height);
    }
    return 0;
}
コード例 #20
0
RawBot::msg_vector RawBot::OnGameInit(const jsoncons::json& msg) {
  const auto& data = msg.get("data", jsoncons::json(""));

  std::cout << "Server: Game Init" << std::endl;

  if (FLAGS_print_track) {
    std::cout << pretty_print(msg) << std::endl;
  }

  game::Race race;
  race.ParseFromJson(data["race"]);

  visualizer_.set_race(race);
  bot_->NewRace(race);
  return ping();
}
コード例 #21
0
ファイル: ops.c プロジェクト: noahv/orcm
int
main(int argc, char *argv[])
{
    int ret, exit_status = ORTE_SUCCESS;
    orte_ps_mpirun_info_t hnpinfo;

    /***************
     * Initialize
     ***************/
    if (ORTE_SUCCESS != (ret = orte_ps_init(argc, argv))) {
        exit_status = ret;
        goto cleanup;
    }

    /* gather info from the scheduler */
    opal_output_verbose(10, orte_ps_globals.output,
                        "orte_ps: Gathering Information");
        
    OBJ_CONSTRUCT(&hnpinfo, orte_ps_mpirun_info_t);
    if (ORTE_SUCCESS == (ret = gather_information(&hnpinfo))) {
        /* Print the information */
        if (orte_ps_globals.parseable) {
            if (ORTE_SUCCESS != (ret = parseable_print(&hnpinfo))) {
                exit_status = ret;
            }
        } else {
            if(ORTE_SUCCESS != (ret = pretty_print(&hnpinfo)) ) {
                exit_status = ret;
            }
        }
    } else {
        /* this could be due to a stale session directory - if so,
         * just skip this entry, but don't abort
         */
        if (ORTE_ERR_SILENT != ret) {
            orte_show_help("help-orte-ps.txt", "stale-hnp", true);
        }
    }

 cleanup:
    /***************
     * Cleanup
     ***************/
    orcm_finalize();

    return exit_status;
}
コード例 #22
0
int main(int argc, char* argv[]){
  char *input = NULL;
  int len;
  // Use input from command line parameters. The first argument is the name of
  // the program.
  if(argc <= 1 || argc > 2){
    fprintf(stderr, "Usage: \n %s <word to print>\n", argv[0]);
    exit(1);
  }
  len = strlen(argv[1]);
  if(len%2 == 0){
    fprintf(stderr, "Length of the string must be odd\n");
    exit(1);
  }
  pretty_print(argv[1]);
  return 0;
}
コード例 #23
0
ファイル: driver.cpp プロジェクト: theyoucheng/cbmc
 structured_error_testt(
   const std::string &file,
   const std::string &function,
   int line,
   const std::string &backtrace,
   int code,
   const std::string &_description):
   invariant_failedt(
     file,
     function,
     line,
     backtrace,
     pretty_print(code, _description)),
   error_code(code),
   description(_description)
 {
 }
コード例 #24
0
ファイル: symtab.c プロジェクト: seokjunbing/Basic-C-Compiler
/*
 * Print symbol table, with indentation to denote parent-child relations.
 */
void pretty_print(symhashtable_t *root, int depth) {

 /* Print two spaces for every level of depth. */
  int i;
  for (i = 0; i < depth; i++)
    printf("  ");

  /* Print the node type. */
  printf("(%d-%d) contains:\n", root->level, root->sibno);

  for(int j = 0; j < HASHSIZE; j++ ) {
    for(symnode_t *node = root->table[j]; node != NULL; node = node->next) {
      for (i = 0; i < depth + 1; i++) {
        printf("  ");
      }
      printf("%s %s", TYPE_NAME(node->type), node->name);

      if(node->type == FUNC_VOID_T || node->type == FUNC_INT_T) {
        printf(" (%d params:", node->num_parameters);
        for(int k = 0; k < node->num_parameters; k++) {
          printf(" %s ", TYPE_NAME(node->parameters[k]));
        }
          printf(")");
          printf("space needed: %d", node->needed_space);
      }
      if(node->type == VAR_INT_T){
        // printf(" (val: %d, offset: %d)", node->num_val, node->offset);
        printf(" (offset: %d or addr: %d)", node->offset, node->addr);
      }
      if(node->type == VAR_ARRAY_INT_T) {
        printf(" (length: %d, offset: %d or addr: %d), sym_length = %d ",
          node->abnode->array_length, node->offset, node->addr, node->array_length);
      }

        printf("\n");
      }
    }

  /* Recurse on each child of the subtree root, with a depth one
     greater than the root's depth. */
    symhashtable_t *child;
    for (child = root->child; child != NULL; child = child->rightsib)
      pretty_print(child, depth + 1);

  }
コード例 #25
0
ファイル: test_cimd2.c プロジェクト: armic/erpts
static void read_data(Octstr *in, int fd) {
	unsigned char buf[EVIL_BUFSIZE];
	int ret;

	ret = read(fd, buf, sizeof(buf));
	if (ret > 0) {
		octstr_append_data(in, buf, ret);
		if (logging == LOG_data)
			pretty_print(buf, ret);
	} else if (ret == 0) {
		fprintf(stderr, "Client closed socket\n");
		exit(0);
	} else {
		if (errno == EINTR || errno == EAGAIN)
			return;
		error(errno, "read_data");
		exit(1);
	}
}
コード例 #26
0
ファイル: json11.cpp プロジェクト: cdecl/json11
static void pretty_print(const Json::object &values, string &out, PrettyPrintOptions &options) {
    options.current_indentation += options.indent_increment;
    string indent_str(options.current_indentation, ' ');

    bool first = true;
    out += "{\n";
    for (const auto &kv : values) {
        if (!first)
            out += ",\n";
        out += indent_str;
        pretty_print(kv.first, out, options);
        out += ": ";
        kv.second.pretty_print(out, options);
        first = false;
    }
    out += "\n";
    options.current_indentation -= options.indent_increment;
    out += string(options.current_indentation, ' ');
    out += "}";
}
コード例 #27
0
ファイル: CBBOC2015.hpp プロジェクト: altoplano/cpp
		std::string toJSonString() const {

			jsoncons::json result;

			jsoncons::json training( jsoncons::json::an_array );
			for( size_t i=0; i<trainingResults.size(); ++i ) {
				const Result& r = trainingResults[ i ];
				jsoncons::json elem;
				elem["remainingEvaluations"] = r.remainingEvaluations;
				elem["remainingEvaluationsWhenBestReached"] = r.remainingEvaluationsWhenBestReached;
				elem["bestValue"] = r.bestValue;
				training.add( elem );
			}

			jsoncons::json testing( jsoncons::json::an_array );
			for( size_t i=0; i<testingResults.size(); ++i ) {
				const Result& r = testingResults[ i ];
				jsoncons::json elem;
				elem["remainingEvaluations"] = r.remainingEvaluations;
				elem["remainingEvaluationsWhenBestReached"] = r.remainingEvaluationsWhenBestReached;
				elem["bestValue"] = r.bestValue;
				testing.add( elem );
			}

			result["competitorName"] = competitorName;
			result["competitorLanguage"] = competitorLanguage;
			result["problemClassName"] = problemClassName;
			std::ostringstream ostc;
			ostc << trainingCategory;
			const std::string trainingCategoryStr( ostc.str() );
			result["trainingCategory"] = trainingCategoryStr;
			result["datetime"] = datetime;
			result["trainingResults" ] = std::move( training );
			result["trainingWallClockUsage"] = trainingWallClockUsage;
			result["testingResults" ] = std::move( testing );
			result["testingWallClockUsage"] = testingWallClockUsage;

			std::ostringstream os;
			os << pretty_print( result ) << std::endl;
			return os.str();
		}
コード例 #28
0
 void ClassicTaskPostureController::
 dbg(std::ostream & os,
     std::string const & title,
     std::string const & prefix) const
 {
   if ( ! title.empty()) {
     os << title << "\n";
   }
   pretty_print(jpos_, os, prefix + "jpos", prefix + "  ");
   pretty_print(jvel_, os, prefix + "jvel", prefix + "  ");
   pretty_print(fstar_, os, prefix + "fstar", prefix + "  ");
   pretty_print(lambda_, os, prefix + "lambda", prefix + "  ");
   pretty_print(jbar_, os, prefix + "jbar", prefix + "  ");
   pretty_print(gamma_, os, prefix + "gamma", prefix + "  ");
 }
コード例 #29
0
int main(int argc, char * argv[]){
	static int * numbers;
	unsigned int i;
	Tree ** Arbres;

	closest = new_tree(-1, 'f');
	srand(time(NULL));

	//Usage
	if(argc < 2) {
		printf("Usage: %s filename or %s N p [Int_list]\n", argv[0], argv[0]);
		return 0;
	}

	/* Acquisition */

	//From a file:
	if (argc == 2) {
		numbers = acquire_from_file(argv[1]);
	}

	//From the CL:
	if (argc > 2) {
		numbers = acquire_from_command(argc,argv);
	}

	//End of acquisition
	Arbres = transform(numbers);
	cover(Arbres, p);
	printf("Target: %d\n", N);
	printf("Available numbers: ");

	for(i = 0; i < p; ++i){
		printf("%d ", numbers[i]);
  }
	printf("\nResult:\n");
	pretty_print(closest);
	printf(" = %d\n", closest->result);

	return 0;
}
コード例 #30
0
ファイル: utils.c プロジェクト: fragrans/http-skeleton
int get_ip_int(url u)
{
	struct hostent * h;
	int i = 0;
	int result;
	char *temp;

	h = (struct hostent *) malloc (sizeof (struct hostent));

	if (UTILS_DEBUG) 
	{
		printf("hostname looking for is %s \n", u -> hostname);
		printf("g1\n");
		pretty_print(u);
	}

	h = gethostbyname(u -> hostname);
	if (UTILS_DEBUG) printf("g2\n");

	if (h == NULL)
	{
		printf("Host ""%s"": \n", u -> hostname); 
		herror("Got an error trying to look up the host ");
		return(-1);
	}	

	if (UTILS_DEBUG) printf("Host name is %s \n", h -> h_name);

	temp = (char *) inet_ntoa(*((struct in_addr *) h -> h_addr));

	if (UTILS_DEBUG) printf("IP address is %s\n", temp);

	result = inet_addr(temp);

	if (UTILS_DEBUG) printf("IP as an int is %x\n", result);
	
	return(result);
}