Ejemplo n.º 1
0
// XXX Should this string handling and verbosity level be part of the
// ATF_REQUIRE_EQ macro?  It may be hard to predict sometimes that a
// string can have newlines in it, and so the error message generated
// at the moment will be bogus if there are some.
static
void
check_equal(const atf::tests::tc& tc, const std::string& str,
            const std::string& exp)
{
    if (str != exp) {
        std::cout << "String equality check failed.\n"
            "Adding >> and << to delimit the string boundaries below.\n";
        std::cout << "GOT:\n";
        print_indented(str);
        std::cout << "EXPECTED:\n";
        print_indented(exp);
        tc.fail("Constructed string differs from the expected one");
    }
}
Ejemplo n.º 2
0
void
help_command (cli_context_t *ctx, GList *cmdnames, gchar **cmd, gint num_args,
              cmd_type_t cmdtype)
{
	command_action_t *action;
	command_trie_match_type_t match;
	gint i, k;
	gint padding, max_flag_len = 0;

	match = cli_context_find_command (ctx, &cmd, &num_args, &action);
	if (match == COMMAND_TRIE_MATCH_ACTION) {
		g_printf (_("usage: %s"), action->name);
		if (action->usage) {
			g_printf (" %s", action->usage);
		}
		g_printf ("\n\n");
		print_indented (action->description, COMMAND_HELP_DESCRIPTION_INDENT);
		g_printf ("\n\n");
		if (action->argdefs && action->argdefs[0].long_name) {
			/* Find length of longest option */
			for (i = 0; action->argdefs[i].long_name; ++i) {
				if (max_flag_len < strlen (action->argdefs[i].long_name)) {
					max_flag_len = strlen (action->argdefs[i].long_name);
				}
			}

			g_printf (_("Valid options:\n"));
			for (i = 0; action->argdefs[i].long_name; ++i) {
				padding = max_flag_len - strlen (action->argdefs[i].long_name) + 2;

				if (action->argdefs[i].short_name) {
					g_printf ("  -%c, ", action->argdefs[i].short_name);
				} else {
					g_printf ("      ");
				}

				g_printf ("--%s", action->argdefs[i].long_name);

				for (k = 0; k < padding; ++k) {
					g_printf (" ");
				}
				g_printf ("%s\n", action->argdefs[i].description);
				/* FIXME: align multi-line */
			}
		}
	} else if (match == COMMAND_TRIE_MATCH_SUBTRIE) {
		help_list (cmdnames, action->name, cmdtype);
	} else {
		/* FIXME: Better handle help for subcommands! */
		g_printf (_("Unknown command: '"));
		for (i = 0; i < num_args; ++i) {
			if (i > 0) g_printf (" ");
			g_printf ("%s", cmd[i]);
		}
		g_printf (_("'\n"));
		g_printf (_("Type 'help' for the list of commands.\n"));
	}
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    unsigned int i;
    for (i = 0; i < MAX_INDENTATION; ++i)
        {
            print_indented(i, "Hello world!");
        }
    return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
static void print_help_for_flag(const SkFlagInfo* flag) {
    SkDebugf("    --%s", flag->name().c_str());
    const SkString& shortName = flag->shortName();
    if (shortName.size() > 0) {
        SkDebugf(" or -%s", shortName.c_str());
    }
    SkDebugf(":\ttype: %s", flag->typeAsString().c_str());
    if (flag->defaultValue().size() > 0) {
        SkDebugf("\tdefault: %s", flag->defaultValue().c_str());
    }
    SkDebugf("\n");
    const SkString& help = flag->help();
    print_indented(help);
    SkDebugf("\n");
}
Ejemplo n.º 5
0
static void print_extended_help_for_flag(const SkFlagInfo* flag) {
    print_help_for_flag(flag);
    print_indented(flag->extendedHelp());
    SkDebugf("\n");
}
int calc(Exp* initial_exp, int indent) {
  Exp* exp = initial_exp;
  Cont* k = new Halt();
  bool v_is_here = false;
  int v;
  print_indented(indent, "calc");

  while (true) {
    if (dynamic_cast<Numeral*>(exp) and k) {
      print_indented(indent+1, "numeral");
      v_is_here = true;
      v = dynamic_cast<Numeral*>(exp)->n;
      exp = NULL;
      continue;
    }

    if (dynamic_cast<Plus*>(exp) and k) {
      print_indented(indent+1, "plus");
      k = new Plusk1(dynamic_cast<Plus*>(exp)->right, k);
      exp = dynamic_cast<Plus*>(exp)->left;
      continue;
    }

    if (dynamic_cast<Minus*>(exp) and k) {
      print_indented(indent+1, "minus");
      k = new Minusk1(dynamic_cast<Minus*>(exp)->right, k);
      exp = dynamic_cast<Minus*>(exp)->left;
      continue;
    }

    if (dynamic_cast<Times*>(exp) and k) {
      print_indented(indent+1, "times");
      k = new Timesk1(dynamic_cast<Times*>(exp)->right, k);
      exp = dynamic_cast<Times*>(exp)->left;
      continue;
    }

    if (dynamic_cast<Divide*>(exp) and k) {
      print_indented(indent+1, "divide");
      k = new Dividek1(dynamic_cast<Divide*>(exp)->right, k);
      exp = dynamic_cast<Divide*>(exp)->left;
      continue;
    }

    if (dynamic_cast<Negate*>(exp) and k) {
      print_indented(indent+1, "negate");
      exp = new Minus(new Numeral(0), dynamic_cast<Negate*>(exp)->exp);
      continue;
    }

    if (dynamic_cast<Plusk1*>(k) and v_is_here) {
      print_indented(indent+1, "plusk1");
      exp = dynamic_cast<Plusk1*>(k)->exp;
      k = new Plusk2(v, dynamic_cast<Plusk1*>(k)->k);
      v_is_here = false;
      continue;
    }

    if (dynamic_cast<Plusk2*>(k) and v_is_here) {
      print_indented(indent+1, "plusk2");
      v = dynamic_cast<Plusk2*>(k)->v + v;
      k = dynamic_cast<Plusk2*>(k)->k;
      continue;
    }

    if (dynamic_cast<Minusk1*>(k) and v_is_here) {
      print_indented(indent+1, "minusk1");
      exp = dynamic_cast<Minusk1*>(k)->exp;
      k = new Minusk2(v, dynamic_cast<Minusk1*>(k)->k);
      v_is_here = false;
      continue;
    }

    if (dynamic_cast<Minusk2*>(k) and v_is_here) {
      print_indented(indent+1, "minusk2");
      v = dynamic_cast<Minusk2*>(k)->v - v;
      k = dynamic_cast<Minusk2*>(k)->k;
      continue;
    }

    if (dynamic_cast<Timesk1*>(k) and v_is_here) {
      print_indented(indent+1, "timesk1");
      exp = dynamic_cast<Timesk1*>(k)->exp;
      k = new Timesk2(v, dynamic_cast<Timesk1*>(k)->k);
      v_is_here = false;
      continue;
    }

    if (dynamic_cast<Timesk2*>(k) and v_is_here) {
      print_indented(indent+1, "timesk2");
      v = dynamic_cast<Timesk2*>(k)->v * v;
      k = dynamic_cast<Timesk2*>(k)->k;
      continue;
    }

    if (dynamic_cast<Dividek1*>(k) and v_is_here) {
      print_indented(indent+1, "dividek1");
      exp = dynamic_cast<Dividek1*>(k)->exp;
      k = new Dividek2(v, dynamic_cast<Dividek1*>(k)->k);
      v_is_here = false;
      continue;
    }

    if (dynamic_cast<Dividek2*>(k) and v_is_here) {
      print_indented(indent+1, "dividek2");
      v = dynamic_cast<Dividek2*>(k)->v / v;
      k = dynamic_cast<Dividek2*>(k)->k;
      continue;
    }

    if (dynamic_cast<Halt*>(k) and v_is_here) {
      print_indented(indent+1, "halt");
      return v;
    }
  }
}