Esempio n. 1
0
static void print_stmt_flow(stmt_flow *t)
{
	idt_printf("for parts:\n");

	gen_str_indent++;
	PRINT_IF(t, for_init,      print_expr);
	PRINT_IF(t, for_while,     print_expr);
	PRINT_IF(t, for_inc,       print_expr);
	gen_str_indent--;
}
Esempio n. 2
0
void print_stmt(stmt *t)
{
	idt_printf("statement: %s\n", t->f_str());

	if(t->flow){
		gen_str_indent++;
		print_stmt_flow(t->flow);
		gen_str_indent--;
	}

	PRINT_IF(t, expr, print_expr);
	PRINT_IF(t, lhs,  print_stmt);
	PRINT_IF(t, rhs,  print_stmt);
	PRINT_IF(t, rhs,  print_stmt);

	if(stmt_kind(t, code)){
		idt_printf("structs/unions/enums:\n");
		gen_str_indent++;
		print_sues_static_asserts(t->symtab);
		gen_str_indent--;

		if(t->symtab){
			decl **iter;

			idt_printf("stack space %d\n", t->symtab->auto_total_size);
			idt_printf("decls:\n");

			for(iter = t->symtab->decls; iter && *iter; iter++){
				decl *d = *iter;

				gen_str_indent++;
				print_decl(d, PDECL_INDENT
						| PDECL_NEWLINE
						| PDECL_SYM_OFFSET
						| PDECL_ATTR
						| PDECL_PINIT);
				gen_str_indent--;
			}
		}

		if(t->bits.code.stmts){
			stmt **iter;

			idt_printf("code:\n");

			for(iter = t->bits.code.stmts; *iter; iter++){
				gen_str_indent++;
				print_stmt(*iter);
				gen_str_indent--;
			}
		}
	}
}
Esempio n. 3
0
int main(int argc, char* argv[])
{
    if (argc > 6)
    {
        print_usage();
        return 2; 
    }

    char* eventFilePath = NULL;

    int repeat = 1;
    int interval = -1;

    int repeatInterval = 1000;

    for (int i = 1; i < argc; i++)
    {
        char* arg = *(argv + i);
        if (!strncmp(arg, "-r:", 3))
        {
            repeat = atoi(arg + 3);
        }
        else if (!strncmp(arg, "-i:", 3))
        {
            interval = atoi(arg + 3) * 1000;
        }
        else if (!strncmp(arg, "-ri:", 4))
        {
            repeatInterval = atoi(arg + 4) * 1000;
        }
        else if (!strcmp(arg, "-d"))
        {
            gDebug = 1;
        }
        else if (!strcmp(arg, "-h"))
        {
            print_usage();
            return 0;
        }
        else if (!strcmp(arg, "-rec"))
        {
            return recordEvent("./event_queue");
        }
        else if (!strncmp(arg, "-rec:", 5))
        {
            return recordEvent(arg + 5);
        }
        else
        {
            if (i == 1 && strncmp(arg, "-", 1))
            {
                eventFilePath = argv[1];
            }
            else
            {
                printf("Unkown parameter %s\n", arg);
                print_usage();
                return 2;
            }
        }
    }

    memset(gFds, 0, sizeof(device_fd_map_t) * MAX_FD);

    if (repeat >= MAX_REPEAT)
    {
        printf("Repeat times %d limit exceed.\n", MAX_REPEAT - 1);
    }

    printf("Play with REPEATE=%d, INTERVAL=%d\n", repeat, interval);

    // control the repeat
    for (int r = 0; r != repeat; r = (r + 1) % MAX_REPEAT)
    {
        // open recorded event queue.
        FILE* file = NULL;

        if (eventFilePath)
        {
            file = fopen(eventFilePath, "rt");
            if (!file)
            {
                printf("Can not open file %s, is it exists?\n", eventFilePath);
                return 1;
            }
        }
        else
        {
            printf(">> No event file specified. Using stdin instead. <<\n");
            file = stdin;
            if (repeat != 1)
            {
                printf("WARNING: -r parameters can not be used while using stdin.\n");
                printf("         Reseting to -r:1\n");
                repeat = 1;
            }
        }

        char* first,* last;
        char buffer[1024];
        int sec = 0, usec = 0;
        char devicePath[256];
        unsigned int type = 0, code = 0, arg = 0;
        usecs_t timeOffset = 0;
        bool timeOffsetSet = false;
        usecs_t lastEventTime = 0;

        // starts playback
        while (fgets(buffer, 1024, file) != NULL)
        {
            sec = usec = -1;
            PRINT_IF(gDebug, "Parsing %s\n", buffer);
            splite(buffer, &first, &last);

            // try android 4.0 output style
            sscanf(first, "%d-%d: %s", &sec, &usec, devicePath);

            if (sec == -1 || usec == -1)
            {
                //try android 4.1 & 4.2 output style
                sscanf(first, "[%d.%d] %s", &sec, &usec, devicePath);
                if (sec == -1 || usec == -1)
                {
                    printf("Skiping invalid line: %s\n", buffer);
                    continue;  // This line is not a valid event record
                }
            }

            sscanf(last, "%x %x %x", &type, &code, &arg);

            PRINT_IF(gDebug, "Event Timestamp=%d.%ds\n", sec, usec);
            int fd = getOrOpenFd(devicePath);
            // Calculating times to sleep
            usecs_t sleepTime = 0;

            // event time stamp
            usecs_t time = combineTime(sec, usec);

            if (!timeOffsetSet)
            {
                timeOffsetSet = true;
                timeOffset = systemTime() - time;
            }

            sleepTime = (time + timeOffset) - systemTime();

            if (interval > 0)
            {
                usleep(interval);
            }
            else if (interval == 0)
            {
            }
            else if (sleepTime > 0)
            {
                PRINT_IF(gDebug || sleepTime > 1000000 /* 1s */, "Sleep %lld.%llds\n", sleepTime / 1000000, sleepTime % 1000000);
                usleep(sleepTime);
            }

            PRINT_IF(gDebug, "-> %s: %d, %d, %d\n", devicePath, type, code, arg);

            if (sendevent(fd, type ,code, arg) != 0)
                exit(0);
        }
        fclose(file);
        if (repeat < 0)
            printf ("Done playback [ %d / Forever ]\n", r + 1);
        else
            printf ("Done playback [ %d / %d ]\n", r + 1, repeat);
        if (repeatInterval > 0 && r + 1 != repeat)
            usleep(repeatInterval);
    }
    clearFds();
    printf("All done\n");
    exit(0);
}