Beispiel #1
0
char *process_cmd(char *p)
{
    switch(*p)
    {
        case 'b': 
            col = 0; 
            return p + 1;
        
        case 'c': 
            memset(map, 32, sizeof(map)); 
            return p + 1;
        
        case 'd':
            if ( row < 9 )
                row++;
            return p + 1;
        
        case 'e':
            memset(&map[row][col], 0, 10 - col);
            return p + 1;
        
        case 'h':
            col = 0;
            row = col;
            return p + 1;
        
        case 'i':
            insert_mode = false;
            return p + 1;
        
        case 'l':
            if ( col > 0 )
                col--;
            return p + 1;
            
        case 'o':
            insert_mode = true;
            return p + 1;
        
        case 'r':
            if ( col < 9 )
                col++;
            return p + 1;
        
        case 'u':
            if ( row > 0 )
                row--;
            return p + 1;
        
        case '^':
            format_map('^');
            return p + 1;
    }
    
    row = *p - '0';
    col = *(p + 1) - '0';
    
    return p + 2;
}
Beispiel #2
0
int main()
{
    int n, ncase = 1;
    char *p, line[500];
    
    while(scanf("%d%*c", &n), n > 0)
    {
        insert_mode = true;
        row = col = 0;
        
        memset(map, ' ', sizeof(map));
        
        while(n-- > 0)
        {
            p = fgets(line, 500, stdin);
            
            while(*p != '\n')
            {
                if(*p == '^')
                    p = process_cmd(p + 1);
                else
                    format_map(*p++);
            }
        }

        printf("Case %d\n", ncase++);

        puts("+----------+");

        for(int i = 0; i < 10; i++)
            printf("|%.10s|\n", map[i]);

        puts("+----------+");
    }
    
    return 0;
}
Beispiel #3
0
int main(int argc, char* argv[]) {

  bool all = false;
  bool string = false;
  bool stringdata = false;
  bool type = false;
  bool proto = false;
  bool field = false;
  bool meth = false;
  bool clsdef = false;
  bool clsdata = false;
  bool code = false;
  bool enarr = false;
  bool anno = false;
  bool debug = false;
  uint32_t ddebug_offset = 0;

  char c;
  static const struct option options[] = {
    { "all", no_argument, nullptr, 'a' },
    { "string", no_argument, nullptr, 's' },
    { "stringdata", no_argument, nullptr, 'S' },
    { "type", no_argument, nullptr, 't' },
    { "proto", no_argument, nullptr, 'p' },
    { "field", no_argument, nullptr, 'f' },
    { "meth", no_argument, nullptr, 'm' },
    { "clsdef", no_argument, nullptr, 'c' },
    { "clsdata", no_argument, nullptr, 'C' },
    { "code", no_argument, nullptr, 'x' },
    { "enarr", no_argument, nullptr, 'e' },
    { "anno", no_argument, nullptr, 'A' },
    { "debug", no_argument, nullptr, 'd' },
    { "ddebug", required_argument, nullptr, 'D' },
    { "clean", no_argument, (int*)&clean, 1 },
    { "help", no_argument, nullptr, 'h' },
    { nullptr, 0, nullptr, 0 },
  };

  while ((c = getopt_long(
            argc,
            argv,
            "asStpfmcCxeAdDh",
            &options[0],
            nullptr)) != -1) {
    switch (c) {
      case 'a':
        all = true;
        break;
      case 's':
        string = true;
        break;
      case 'S':
        stringdata = true;
        break;
      case 't':
        type = true;
        break;
      case 'p':
        proto = true;
        break;
      case 'f':
        field = true;
        break;
      case 'm':
        meth = true;
        break;
      case 'c':
        clsdef = true;
        break;
      case 'C':
        clsdata = true;
        break;
      case 'x':
        code = true;
        break;
      case 'e':
        enarr = true;
        break;
      case 'A':
        anno = true;
        break;
      case 'd':
        debug = true;
        break;
      case 'D':
        sscanf(optarg, "%x", &ddebug_offset);
        break;
      case 'h':
        puts(ddump_usage_string);
        return 0;
      case '?':
        return 1; // getopt_long has printed an error
      case 0:
        // we're handling a long-only option
        break;
      default:
        abort();
    }
  }

  if (optind == argc) {
    fprintf(stderr, "%s: no dex files given; use -h for help\n", argv[0]);
    return 1;
  }

  while (optind < argc) {
    const char* dexfile = argv[optind++];
    ddump_data rd;
    open_dex_file(dexfile, &rd);
    redump(format_map(&rd).c_str());
    if (string || all) {
      dump_strings(&rd);
    }
    if (stringdata || all) {
      dump_stringdata(&rd);
    }
    if (type || all) {
      dump_types(&rd);
    }
    if (proto || all) {
      dump_protos(&rd);
    }
    if (field || all) {
      dump_fields(&rd);
    }
    if (meth || all) {
      dump_methods(&rd);
    }
    if (clsdef || all) {
      dump_clsdefs(&rd);
    }
    if (clsdata || all) {
      dump_clsdata(&rd);
    }
    if (code || all) {
      dump_code(&rd);
    }
    if (enarr || all) {
      dump_enarr(&rd);
    }
    if (anno || all) {
      dump_anno(&rd);
    }
    if (debug || all) {
      dump_debug(&rd);
    }
    if (ddebug_offset != 0) {
      disassemble_debug(&rd, ddebug_offset);
    }
    fprintf(stdout, "\n");
    fflush(stdout);
  }

  return 0;
}
Beispiel #4
0
int main()
{
    // A basic CGI request auto-parses everything (including POST data).
    cgi::request req;
    cgi::response resp;

    // You can also stream text to a response. 
    // All of this just prints out the form 
    resp<< "<html>"
        "<head>"
        "<title>CGI Echo Example</title>"
        "<style type=\"text/css\">"
        <<       gCSS_text <<
        "</style>"
        "<head>"
        "<body>"
        "Request ID = " << req.id() << "<br />"
        "<form method=post enctype=\"multipart/form-data\">"
        "<input type=text name=name value='"
        <<         req.post["name"] << "' />"
        "<br />"
        "<input type=checkbox name=checks value='one'"
        << (req.post.matches("checks", "one") ? " checked='checked'" : "") << " />One"
        "<br />"
        "<input type=checkbox name=checks value='two'"
        << (req.post.matches("checks", "two") ? " checked='checked'" : "") << " />Two"
        "<br />"
        "<input type=checkbox name=checks value='six'"
        << (req.post.matches("checks", "six") ? " checked='checked'" : "") << " />Six"
        "<br />"
        "<input type=checkbox name=checks value='ten'"
        << (req.post.matches("checks", "ten") ? " checked='checked'" : "") << " />Ten"
        "<br />"
        "<input type=text name=hello value='"
        <<         req.post["hello"] << "' />"
        "<br />"
        "<input type=file name=user_file /><br />"
        "<input type=file name=user_file />"
        "<input type=hidden name=cmd value=multipart_test />"
        "<br />";
    // Access file uploads (which are saved to disk).
    if (req.uploads.count("user_file")) {
        cgi::common::form_part& part = req.uploads["user_file"];
        if (!part.filename.empty())
            resp<< "Saved uploaded file to: " << part.path << "<br />";
    }
    resp<< "<input type=submit value=submit />"
        "<br />";
    "</form><p />";

    format_map(resp, req, req.env, "Environment Variables");
    //format_map(resp, req, req.get, "GET Variables");
    format_map(resp, req, req.form, "Form [" + req.method() + "] Variables");
    format_map(resp, req, req.cookies, "Cookie Variables");
    format_map(resp, req, req.uploads, "Uploaded Files");

    // Note that this (and any other) HTTP header can go either before or after
    // the response contents.
    resp<< cgi::content_type("text/html");

    // Send the response to the client that made the request.
    return cgi::commit(req, resp);
}