void makesame(int p,int n,int v){ int b,t; find(p,b); splite(b,p); for(t=next[b]; t!=-1 && n>count[t];n-=count[t], t=next[t]) fillblock(t, count[t], v, next[t]); if(n && t!=-1){ splite(t,n); fillblock(t, n, v, next[t]); } maintainlist(b); }
int erase(int p,int n){ int b,e; find(p,b); splite(b,p); for(e=next[b]; e!=-1 && n > count[e]; e=next[e])n -= count[e]; if(n){splite(e,n);e=next[e];} for(int t=next[b]; t!=e; t=next[b]){ next[b]=next[t]; delnode(t); } maintainlist(b); }
int insert(int people){ int b, p = rank(frcount[people])+1; find(p, b); if(bcount[b] == BLOCKSIZE){ splite(b, p); if(p==BLOCKSIZE){ p=0; b=next[b]; if(bcount[b]==BLOCKSIZE)splite(b, p); } } for(int i=bcount[b]; i>p; --i)data[b][i]=data[b][i-1]; data[b][p]=people; ++bcount[b]; ++account; }
void reverse(int p,int n){ int b,i,t; find(p,b); splite(b,p); for(i=0,t=next[b]; n>count[t]; n-=count[t],++i,t=next[t]) list[i]=t; if(n && t!=-1){ splite(t,n); list[i++]=t; t=next[t]; } next[b]=list[--i]; for(; i>=0; --i){ next[list[i]] = i ? list[i-1] : t; reversed[list[i]] = ! reversed[list[i]]; } maintainlist(b); }
void Address::LoadFromLine(const string& line) { vector<string> lines = splite( line,"|"); for(vector<string>::iterator iter=lines.begin(); iter!=lines.end(); iter++) { string address_string=*iter; vector<string> strs=splite( line,":"); if(strs.size() != 3) continue; try { u_short controy = boost::lexical_cast<u_short>(strs[0]); u_short province = boost::lexical_cast<u_short>(strs[1]); u_short city = boost::lexical_cast<u_short>(strs[2]); } catch (...) { continue; } } }
void insert(int p,int n,int str[]){ int b,t,i; find(p,b); splite(b,p); for(i=0; i + BLOCKSIZE <= n; i+=BLOCKSIZE){ t=newnode(); fillblock(t, BLOCKSIZE, str+i, next[b]); next[b]=t; b=t; } if(n-i){ t=newnode(); fillblock(t, n-i, str+i, next[b]); next[b]=t; } maintainlist(b); }
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); }