void cmdwrite(int wcom, Map *map) { ADDR savdot; char *format; int pass; if (wcom == 'w') format = "x"; else format = "X"; expr(1); pass = 0; do { pass++; savdot=dot; exform(1, 1, format, map, 0, pass); dot=savdot; if (wcom == 'W') { if (put4(map, dot, expv) <= 0) error(badwrite); } else { if (put2(map, dot, expv) <= 0) error(badwrite); } savdot=dot; dprint("=%8t"); exform(1, 0, format, map, 0, pass); newline(); } while (expr(0)); dot=savdot; }
void wr_int2(int fd, int i) { char buf[2]; put2(i, buf); wr_bytes(fd, buf, 2L); }
int win(int a[]){ int b[11]; int i=0 ; int ret= 0; set(b); for(i=0 ; i< 11 ; i++){ if ( valid1(i,a) ){ copy(b,a); put1(i,b); ret|= !win(b); } if ( valid2(i,a) ){ copy(b,a); put2(i,b); ret|= !win(b); } if ( valid3(i,a) ){ copy(b,a); put3(i,b); ret|= !win(b); } } return ret; }
void rput(Map *map, char *name, vlong v) { Reglist *rp; int ret; rp = rname(name); if (!rp) error("invalid register name"); if (rp->rflags & RRDONLY) error("register is read-only"); switch (rp->rformat) { case 'x': ret = put2(map, rp->roffs, (ushort) v); break; case 'X': case 'f': case 'F': ret = put4(map, rp->roffs, (long) v); break; case 'Y': ret = put8(map, rp->roffs, v); break; default: ret = -1; } if (ret < 0) error("can't write register"); }
wr_int2(fd, i) { char buf[2]; put2(i, buf); wr_bytes(fd, buf, 2L); }
int puthdr(unsigned char *buf, unsigned long index, unsigned char type, unsigned int tag, unsigned long size) { put4(buf, index, size); buf[index++] = type; put2(buf, index, tag); return index; }
int main(void) { put1("If I'd as much money"); put1(" as I could spend, \n"); printf("I count %d characters.\n",put2("I never would cry old chairs to mend. ")); return 0; }
void dateToString(char *lcd_str) { #if EFI_RTC || defined(__DOXYGEN__) // todo: // re-implement this along the lines of chvprintf("%04u-%02u-%02u %02u:%02u:%02u\r\n", timp.tm_year + 1900, timp.tm_mon + 1, timp.tm_mday, timp.tm_hour, // timp.tm_min, timp.tm_sec); // this would require a temporary mem stream - see datalogging and other existing usages strcpy(lcd_str, "00/00 00:00:00\0"); struct tm timp; rtcGetTimeTm(&RTCD1, &timp); // get RTC date/time put2(0, lcd_str, timp.tm_mon + 1); put2(3, lcd_str, timp.tm_mday); put2(6, lcd_str, timp.tm_hour); put2(9, lcd_str, timp.tm_min); put2(12, lcd_str, timp.tm_sec); #else lcd_str[0] = 0; #endif /* EFI_RTC */ }
int mkerr(unsigned char *buffer, unsigned char tag, char *errstr) { int index; int slen = strlen(errstr); int size = slen + 9; index = puthdr(buffer, 0, RError, tag, size); put2(buffer, index, slen); memcpy(&buffer[index], errstr, slen); return size; }
bool dateToStringShort(char *lcd_str) { #if EFI_RTC || defined(__DOXYGEN__) strcpy(lcd_str, "0000_000000\0"); struct tm timp; rtcGetTimeTm(&RTCD1, &timp); if (timp.tm_year < 116 || timp.tm_year > 130) { // 2016 to 2030 is the valid range lcd_str[0] = 0; return false; } put2(0, lcd_str, timp.tm_mon + 1); put2(2, lcd_str, timp.tm_mday); put2(5, lcd_str, timp.tm_hour); put2(7, lcd_str, timp.tm_min); put2(9, lcd_str, timp.tm_sec); return true; #else lcd_str[0] = 0; return false; #endif }
// Can also be used to rehash hash_t *HASH_copy(const hash_t *hash){ hash_t *ret = HASH_create(hash->num_elements); ret->version = hash->version; int i; for(i=0;i<hash->elements_size;i++){ hash_element_t *element = hash->elements[i]; while(element!=NULL){ hash_element_t *element_copy = copy_element(element); put2(ret, element->key, element->i, element_copy); element=element->next; } } return ret; }
int putstat(unsigned char *buffer, unsigned long index, Stat *stat) { unsigned int namelen = strlen(stat->name); unsigned int uidlen = strlen(stat->uid); unsigned int gidlen = strlen(stat->gid); unsigned int muidlen = strlen(stat->muid); unsigned int size = 2 + 4 + (1 + 4 + 8) + 4 + 4 + 4 + 8 + (2 * 4) + namelen + uidlen + gidlen + muidlen; put2(buffer, index, size); put2(buffer, index, stat->type); put4(buffer, index, stat->dev); buffer[index++] = stat->qid.type; put4(buffer, index, stat->qid.version); put8(buffer, index, stat->qid.path, 0); put4(buffer, index, stat->mode); put4(buffer, index, stat->atime); put4(buffer, index, stat->mtime); put8(buffer, index, stat->length, 0); put2(buffer, index, namelen); memcpy(&buffer[index], stat->name, namelen); index += namelen; put2(buffer, index, uidlen); memcpy(&buffer[index], stat->uid, uidlen); index += uidlen; put2(buffer, index, gidlen); memcpy(&buffer[index], stat->gid, gidlen); index += gidlen; put2(buffer, index, muidlen); memcpy(&buffer[index], stat->muid, muidlen); index += muidlen; return (size + 2); }
static void put(hash_t *hash, const char *raw_key, int i, hash_element_t *element){ const char *key = STRING_get_utf8_chars(raw_key); put2(hash, key, i, element); }
dfile(char *si,int i) { FILE *fp; char fo[80],c[900]; if(i==0) put_char(12); setmci(1); strcpy(fo,config.gfiledir); strcat(fo,si); if(access(fo,0)!=0) { if(i<2) { nl(); print("%s not found",fo); nl(); } return(-1); } fp=fopen(fo,"r"); while(1) { if(feof(fp)!=0) { fclose(fp); updatestat(); return; } if(kbhit()) if(getch()==32) { if(user.menutype > 1) { nl(); put2("[0m"); updatestat(); } setmci(0); return; } if(comm_avail()) if(comm_getc(1)==32) { if(user.menutype > 1) { nl(); put2("[0m"); updatestat(); } setmci(0); return; } fgets(c,800,fp); put2(c); c[0]=0; } fclose(fp); if(user.menutype > 1) put2("[0m"); setmci(1); updatestat(); }
int main(int argc, char **argv) { int com; int n1, n2, n; char *bp; int lfd = -1; int rfd = -1; if (signal(SIGHUP, SIG_IGN) != SIG_IGN) (void) signal((int)SIGHUP, (void (*)(int))onintr); if (signal(SIGINT, SIG_IGN) != SIG_IGN) (void) signal((int)SIGINT, (void (*)(int))onintr); if (signal(SIGPIPE, SIG_IGN) != SIG_IGN) (void) signal((int)SIGPIPE, (void (*)(int))onintr); if (signal(SIGTERM, SIG_IGN) != SIG_IGN) (void) signal((int)SIGTERM, (void (*)(int))onintr); (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); while (--argc > 1 && **++argv == '-') { switch (*++*argv) { case 'w': /* -w# instead of -w # */ if (*++*argv) llen = atoi(*argv); else { argc--; llen = atoi(*++argv); } if (llen < WLEN) error(gettext("Wrong line length %s"), *argv); if (llen > LMAX) llen = LMAX; break; case 'l': leftonly++; break; case 's': silent++; break; case 'o': oflag++; argc--; ofile = *++argv; break; default: error(gettext("Illegal argument: %s"), *argv); } } if (argc != 2) { (void) fprintf(stderr, gettext( "Usage: sdiff [-l] [-s] [-o output] [-w #] file1 file2\n")); return (2); } file1 = *argv++; file2 = *argv; file1 = filename(file1, file2); file2 = filename(file2, file1); hlen = (llen - WGUTTER +1)/2; if ((fdes1 = fopen(file1, "r")) == NULL) error(gettext("Cannot open: %s"), file1); if ((fdes2 = fopen(file2, "r")) == NULL) error(gettext("Cannot open: %s"), file2); if (oflag) { if (tempfd == -1) { temp = strdup("/tmp/sdiffXXXXXX"); tempfd = mkstemp(temp); if (tempfd == -1) { error(gettext( "Cannot open/create temp %s"), temp); free(temp); temp = 0; } } ltemp = strdup("/tmp/sdifflXXXXXX"); if ((lfd = mkstemp(ltemp)) == -1 || (left = fdopen(lfd, "w")) == NULL) error(gettext( "Cannot open/create temp %s"), ltemp); rtemp = strdup("/tmp/sdiffrXXXXXX"); if ((rfd = mkstemp(rtemp)) == -1 || (right = fdopen(rfd, "w")) == NULL) error(gettext( "Cannot open/create temp file %s"), rtemp); if ((odes = fopen(ofile, "w")) == NULL) error(gettext("Cannot open output %s"), ofile); } /* Call DIFF command */ (void) strcpy(diffcmd, DIFF); (void) strcat(diffcmd, file1); (void) strcat(diffcmd, " "); (void) strcat(diffcmd, file2); diffdes = popen(diffcmd, "r"); num1 = num2 = 0; /* * Read in diff output and decode commands * "change" is used to determine character to put in gutter * num1 and num2 counts the number of lines in file1 and 2 */ n = 0; while ((bp = fgetline(diffdes)) != NULL) { change = ' '; com = cmd(bp); /* * handles all diff output that is not cmd * lines starting with <, >, ., --- */ if (com == 0) continue; /* Catch up to from1 and from2 */ rcode = 1; n1 = from1 - num1; n2 = from2 - num2; n = n1 > n2 ? n2 : n1; if (com == 'c' && n > 0) n--; if (silent) (void) fputs(bp, stdout); while (n-- > 0) { (void) put1(); (void) put2(); if (!silent) (void) putc('\n', stdout); midflg = 0; } /* Process diff cmd */ switch (com) { case 'a': change = '>'; while (num2 < to2) { (void) put2(); (void) putc('\n', stdout); midflg = 0; } break; case 'd': change = '<'; while (num1 < to1) { (void) put1(); (void) putc('\n', stdout); midflg = 0; } break; case 'c': n1 = to1 - from1; n2 = to2 - from2; n = n1 > n2 ? n2 : n1; change = '|'; do { (void) put1(); (void) put2(); (void) putc('\n', stdout); midflg = 0; } while (n--); change = '<'; while (num1 < to1) { (void) put1(); (void) putc('\n', stdout); midflg = 0; } change = '>'; while (num2 < to2) { (void) put2(); (void) putc('\n', stdout); midflg = 0; } break; default: (void) fprintf(stderr, gettext( "%c: cmd not found\n"), cmd); break; } if (oflag == 1 && com != 0) { cmdin(); if ((left = fopen(ltemp, "w")) == NULL) error(gettext( "main: Cannot open temp %s"), ltemp); if ((right = fopen(rtemp, "w")) == NULL) error(gettext( "main: Cannot open temp %s"), rtemp); } } /* put out remainder of input files */ while (put1()) { (void) put2(); if (!silent) (void) putc('\n', stdout); midflg = 0; } if (odes) (void) fclose(odes); sremove(); return (rcode); }
unsigned long proc9p(unsigned char *msg, unsigned long size, Callbacks *cb) { Fcall ifcall; Fcall *ofcall = NULL; unsigned long slen; unsigned long index; unsigned char i; index = 4; ifcall.type = msg[index++]; get2(msg, index, ifcall.tag); if (size > MAX_MSG) { strcpy_P(pgmbuf, Etoobig); index = mkerr(msg, ifcall.tag, pgmbuf); goto END; } // if it isn't here, it isn't implemented switch(ifcall.type) { case TVersion: i = index; index = 7; get4(msg, i, ifcall.msize); get2(msg, i, slen); if (ifcall.msize > MAX_MSG) ifcall.msize = MAX_MSG; put4(msg, index, ifcall.msize); put2(msg, index, slen); index += slen; puthdr(msg, 0, RVersion, ifcall.tag, index); break; case TAttach: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.afid); get2(msg, index, slen); ifcall.uname = (char*)&msg[index]; index += slen; get2(msg, index, slen); msg[index-2] = '\0'; ifcall.aname = (char*)&msg[index]; index += slen; msg[index-2] = '\0'; ofcall = cb->attach(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = 7; msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); puthdr(msg, 0, RAttach, ifcall.tag, index); break; case TWalk: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.newfid); get2(msg, index, ifcall.nwname); if (ifcall.nwname > MAX_WELEM) ifcall.nwname = MAX_WELEM; for (i = 0; i < ifcall.nwname; i++) { get2(msg, index, slen); msg[index-2] = '\0'; ifcall.wname[i] = (char*)&msg[index]; index += slen; } msg[index] = '\0'; ofcall = cb->walk(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RWalk, ifcall.tag, 9 + ofcall->nwqid * 13); put2(msg, index, ofcall->nwqid); for (i = 0; i < ofcall->nwqid; i++) { msg[index++] = ofcall->wqid[i].type; put4(msg, index, ofcall->wqid[i].version); put8(msg, index, ofcall->wqid[i].path, 0); } break; case TStat: get4(msg, index, ifcall.fid); ofcall = cb->stat(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } slen = putstat(msg, 9, &(ofcall->stat)); index = puthdr(msg, 0, RStat, ifcall.tag, slen + 9); put2(msg, index, slen); // bleh? index += slen; break; case TClunk: get4(msg, index, ifcall.fid); ofcall = cb->clunk(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RClunk, ifcall.tag, 7); break; case TOpen: get4(msg, index, ifcall.fid); ifcall.mode = msg[index++]; ofcall = cb->open(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, ROpen, ifcall.tag, 24); msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); put4(msg, index, MAX_IO); break; case TRead: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.offset); index += 4; // :( get4(msg, index, ifcall.count); ofcall = cb->read(&ifcall, &msg[11]); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } // No response if (ofcall == NULL) { index = 0; goto END; } index = puthdr(msg, 0, RRead, ifcall.tag, 11 + ofcall->count); put4(msg, index, ofcall->count); index += ofcall->count; break; case TCreate: get4(msg, index, ifcall.fid); get2(msg, index, slen); ifcall.name = (char*)&msg[index]; index += slen; get4(msg, index, ifcall.perm); msg[index-4] = '\0'; ifcall.mode = msg[index++]; ofcall = cb->create(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RCreate, ifcall.tag, 24); msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); put4(msg, index, MAX_IO); break; case TWrite: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.offset); index += 4; // bleh... again get4(msg, index, ifcall.count); ofcall = cb->write(&ifcall, &msg[index]); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RWrite, ifcall.tag, 11); put4(msg, index, ofcall->count); break; case TRemove: get4(msg, index, ifcall.fid); ofcall = cb->remove(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RRemove, ifcall.tag, 7); break; case TFlush: get2(msg, index, ifcall.oldtag); ofcall = cb->flush(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RFlush, ifcall.tag, 7); break; default: strcpy_P(pgmbuf, Ebadtype); index = mkerr(msg, ifcall.tag, pgmbuf); break; } END: if (index > MAX_MSG) { strcpy_P(pgmbuf, Etoobig); index = mkerr(msg, ifcall.tag, pgmbuf); } return index; }
void put4( byte *c ) { put2( c ); put2( c+2 ); }
int main(void) { fb_info_t fb; mevent_t mevent; int fd, mfd; int m_x, m_y; if((fd = open("/dev/fb0", O_RDWR)) < 0) { perror("open /dev/fb0 error:"); exit(1); } if(-1L == ioctl(fd, FBIOGET_VSCREENINFO, &(fb.fb_var))) { printf("ioctl FBIOGET_VSCREENINFO\n"); exit(1); } fb.w = fb.fb_var.xres; fb.h = fb.fb_var.yres; fb.bpp = fb.fb_var.bits_per_pixel; fb.fd = fd; fb.fb_mem = mmap(NULL, fb.w*fb.h*fb.bpp/8, PROT_READ|PROT_WRITE, MAP_SHARED, fb.fd,0); if(MAP_FAILED == fb.fb_mem) { printf("mmap error!"); exit(1); } m_x = fb.w / 2; m_y = fb.h / 2; put1(&fb,0xFFFF); put2(&fb,0xFFFF); put3(&fb,0xFFFF); //Step 1 mouse_save(&fb, m_x, m_y); //Step 2 mouse_draw_take(&fb, m_x, m_y); mfd = open("/dev/input/mice", O_RDWR | O_NONBLOCK); if(mfd < 0) { perror("open /dev/input/mice error:"); exit(1); } while(1) { if(mouse_parse(mfd, &mevent) == 0) { //Step 3 mouse_restore(&fb, m_x, m_y); m_x += mevent.dx; m_y += mevent.dy; if(m_x < 0) m_x = 0; if(m_x > (fb.w-C_WIDTH-1)) m_x = fb.w - C_WIDTH-1; if(m_y < 0) m_y = 0; if(m_y > (fb.h-C_HEIGHT-1)) m_y = fb.h-C_HEIGHT-1; if((m_x > x_start_l)&&(m_x < x_start_r)&&(m_y > y_start_l)&&(m_y < y_start_r)) { mouse_save(&fb, m_x, m_y); mouse_draw_load(&fb, m_x, m_y); if(mevent.button == 1) { /*开始*/ printf("star\n"); // exit(1); } } else if((m_x > x_list_l)&&(m_x < x_list_r)&&(m_y > y_list_l)&&(m_y < y_list_r)) { mouse_save(&fb, m_x, m_y); mouse_draw_load(&fb, m_x, m_y); if(mevent.button == 1) { /*列表*/ printf("list\n"); // exit(1); } } else if((m_x > x_quit_l)&&(m_x < x_quit_r)&&(m_y > y_quit_l)&&(m_y < y_quit_r)) { mouse_save(&fb, m_x, m_y); mouse_draw_load(&fb, m_x, m_y); if(mevent.button == 1) { /*退出*/ printf("exit\n"); // exit(1); } } else { mouse_save(&fb, m_x, m_y); mouse_draw_take(&fb, m_x, m_y); } } } close(fb.fd); munmap(fb.fb_mem,fb.w*fb.h*fb.bpp/8); return 0; }
void put6( byte *c ) { put4( c ); put2( c+4 ); }
void put4( unsigned char *c ) { put2( c ); put2( c+2 ); }
void put6( unsigned char *c ) { put4( c ); put2( c+4 ); }