void wmkeys_routine(int argc, char **argv) { int i; XEvent Event; int but_stat = -1; openXwindow(argc, argv, wmkeys_master_xpm, wmkeys_mask_bits, 64, 64); enable_configuration(0); /* add mouse region */ AddMouseRegion(0, 5, 5, 58, 122); while (1) { waitpid(0, NULL, WNOHANG); RedrawWindow(); while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: current_config++; if(current_config == num_configs) current_config = 0; enable_configuration(current_config); break; } } break; } } /* Sleep 0.3 seconds */ usleep(300000L); } }
int main(int argc, char *argv[]) { int n, show_days = 0, but_stat = 0, microtm = 0, running = 0, force = 0; time_t last_time = 0; char *geometry = NULL, *xdisplay = NULL; static int signals[] = {SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0}; XEvent Event; assert(sizeof(char) == 1); umask(077); do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force); path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1; if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) { fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } snprintf(dirName, path_len, "%s/.wmwork", getenv("HOME")); snprintf(logname, path_len, "%s/worklog", dirName); snprintf(lockname, path_len, "%s/.#LOCK", dirName); if (chdir(dirName) < 0) { if (errno == ENOENT) { if (mkdir(dirName, 0777)) { fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } compat(); } else { fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } } for (n = 0; signals[n]; n++) { if (signal(signals[n], handler) == SIG_ERR) { fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); } } make_lock(force); atexit(at_exit); read_log(); current = first; initXwindow(xdisplay); createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64); openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL); AddMouseRegion(BUT_START, 5, 48, 22, 58); AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58); AddMouseRegion(BUT_STOP, 41, 48, 58, 58); AddMouseRegion(BUT_PREV, 5, 33, 16, 43); AddMouseRegion(BUT_NEXT, 47, 33, 58, 43); drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); while (1) { last_time = now.tv_sec; gettimeofday(&now, &tz); if (running) { current->time += now.tv_sec - last_time; sess_time += now.tv_sec - last_time; microtm = now.tv_usec; drawTime(current->time, sess_time, microtm, show_days, running); RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); case ButtonPress: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (n) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonDown(n); break; } but_stat = n; RedrawWindow(); break; case ButtonRelease: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (but_stat) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonUp(but_stat); break; } if (but_stat && n == but_stat) { switch (but_stat) { case BUT_START: running = 1; break; case BUT_PAUSE: running = 0; break; case BUT_STOP: write_log(); write_record(); running = 0; sess_time = 0; break; case BUT_PREV: if (!running && sess_time == 0) current = current->prev; break; case BUT_NEXT: if (!running && sess_time == 0) current = current->next; break; } drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); } RedrawWindow(); but_stat = 0; break; } } usleep(50000L); if (do_exit) exit(0); } }
void yawmppp_routine (int argc, char **argv) { int i, j; int but_stat; long currenttime; long lasttime; long waittime; long ppptime; int hour, minute; long timetolog; long ppp_send, ppp_sl = -1; long ppp_recv, ppp_rl = -1; long ppp_sbytes, ppp_rbytes; long ppp_osbytes, ppp_orbytes; struct stat st; pid_t stop_child = 0; pid_t start_child = 0; int status; int isonline = 0; XEvent Event; int speed_ind = 10; /* Initialize some stuff */ get_statistics (active_interface, &ppp_rl, &ppp_sl, &ppp_orbytes, &ppp_osbytes); if (caution>0) close_ppp(); grab_isp_info(1); /* Open the display */ createXBMfromXPM (dock_mask_bits, dockxpm_xpm, dock_mask_width, dock_mask_height); openXwindow (argc, argv, dockxpm_xpm, dock_mask_bits, dock_mask_width, dock_mask_height); /* V Button */ AddMouseRegion (0, 35, 48, 46, 58); /* x Button */ AddMouseRegion (1, 47, 48, 58, 58); /* < Button */ AddMouseRegion (2, 5, 48, 16, 58); /* > Button */ AddMouseRegion (3, 17, 48, 28, 58); /* ISP display */ AddMouseRegion (4, 5, 6, 59, 43); starttime = 0; currenttime = time (0); ppptime = 0; but_stat = -1; waittime = 0; timetolog=0; /* 888k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); DrawISPName (); while (1) { lasttime = currenttime; currenttime = time (0); /* Check if any child has left the playground */ i = waitpid (0, &status, WNOHANG); if (i == stop_child && stop_child != 0) { starttime = 0; SetOffLED (LED_PPP_POWER); SetOffLED (LED_PPP_RX); SetOffLED (LED_PPP_TX); /* 888k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); RedrawWindow (); stop_child = 0; } if (i == start_child && start_child != 0) { if (WIFEXITED (status)) { if (WEXITSTATUS (status) == 10) { starttime = 0; /* 88k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); SetOffLED (LED_PPP_POWER); DrawTime (0, 1); RedrawWindow (); } start_child = 0; } } /* On-line detectie! 1x per second */ if (currenttime != lasttime) { i = 0; if (stillonline (active_interface)) { i = 1; if (!starttime) { starttime = currenttime; if (stat (STAMP_FILE, &st) == 0) starttime = st.st_mtime; SetOnLED (LED_PPP_POWER); waittime = 0; /* 88k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); if (IspData[current_isp].SpeedAction) DrawSpeedInd (IspData[current_isp].SpeedAction); speed_ind = currenttime + 10; RedrawWindow (); } } if (!i && starttime) { starttime = 0; SetErrLED (LED_PPP_POWER); logconn.status=1; /* Error */ copyXPMArea (ERR_SRC_X, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); if (IspData[current_isp].IfDownAction) execCommand (IspData[current_isp].IfDownAction); RedrawWindow (); } } if (waittime && waittime <= currenttime) { SetOffLED (LED_PPP_POWER); RedrawWindow (); waittime = 0; } if ((starttime)&&(!isonline)) { isonline=1; logconn.start=time(NULL); logconn.status=0; strcpy(logconn.longname,IspData[current_isp].LongName); strcpy(logconn.shortname,IspData[current_isp].ShortName); strcpy(logconn.user,IspData[current_isp].User); strcpy(logconn.phone,IspData[current_isp].Phone); if (!strlen(logconn.shortname)) strcpy(logconn.shortname,"empty"); if (!strlen(logconn.longname)) strcpy(logconn.longname,"empty"); if (!strlen(logconn.user)) strcpy(logconn.user,"empty"); if (!strlen(logconn.phone)) strcpy(logconn.phone,"empty"); make_guards(); } if ((!starttime)&&(isonline)) { isonline=0; logconn.end=time(NULL); write_log(); if (got_sched) make_delayed_update(); if (caution>0) close_ppp(); } /* If we are on-line. Print the time we are */ if (starttime) { i = currenttime - starttime; i /= TimerDivisor; if (TimerDivisor == 1) if (i > 59 * 60 + 59) i /= 60; minute = i % 60; hour = (i / 60) % 100; i = hour * 100 + minute; DrawTime (i, currenttime % 2); /* We are online, so we can check for send/recv packets */ get_statistics (active_interface, &ppp_recv, &ppp_send, &ppp_rbytes, &ppp_sbytes); if (caution>1) close_ppp(); if (ppp_send != ppp_sl) SetOnLED (LED_PPP_TX); else SetOffLED (LED_PPP_TX); if (ppp_recv != ppp_rl) SetOnLED (LED_PPP_RX); else SetOffLED (LED_PPP_RX); ppp_sl = ppp_send; ppp_rl = ppp_recv; /* Every five seconds we check to load on the line */ if (currenttime - timetolog >= 0) { timetolog=currenttime + 60; make_guards(); } if ((currenttime - ppptime >= 0) || (ppptime == 0)) { ppptime = currenttime + updaterate; ppp_history[PPP_STATS_HIS][0] = ppp_rbytes - ppp_orbytes; ppp_history[PPP_STATS_HIS][1] = ppp_sbytes - ppp_osbytes; ppp_orbytes = ppp_rbytes; ppp_osbytes = ppp_sbytes; DrawStats (54, 17, 5, 32); for (j = 1; j < 55; j++) { ppp_history[j - 1][0] = ppp_history[j][0]; ppp_history[j - 1][1] = ppp_history[j][1]; } if (currenttime > speed_ind) { DrawLoadInd ((ppp_history[54][0] + ppp_history[54][1]) / updaterate); } } RedrawWindow (); } while (XPending (display)) { XNextEvent (display, &Event); switch (Event.type) { case Expose: RedrawWindow (); break; case DestroyNotify: XCloseDisplay (display); while (start_child | stop_child) { i = waitpid (0, &status, WNOHANG); if (i == stop_child) stop_child = 0; if (i == start_child) start_child = 0; usleep (50000l); } exit (0); break; case ButtonPress: i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y); switch (i) { case 0: ButtonDown (BUT_V); break; case 1: ButtonDown (BUT_X); break; case 2: ButtonDown (BUT_REW); break; case 3: ButtonDown (BUT_FF); break; } but_stat = i; RedrawWindow (); break; case ButtonRelease: i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y); // Button but_stat omhoogdoen! switch (but_stat) { case 0: ButtonUp (BUT_V); break; case 1: ButtonUp (BUT_X); break; case 2: ButtonUp (BUT_REW); break; case 3: ButtonUp (BUT_FF); break; } if (i == but_stat && but_stat >= 0) { switch (i) { case 0: if (!starttime) { /* 888k8 */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); DrawTime (0, 1); start_child = execCommand (IspData[current_isp].StartAction); SetWaitLED (LED_PPP_POWER); waittime = ORANGE_LED_TIMEOUT + currenttime; } break; case 1: if (stop_child == 0) { stop_child = execCommand (IspData[current_isp].StopAction); } break; case 2: if (!starttime) { current_isp--; if (current_isp < 0) current_isp = num_isps - 1; if (current_isp < 0) current_isp=0; DrawISPName (); } break; case 3: if (!starttime) { current_isp++; if (current_isp == num_isps) current_isp = 0; DrawISPName (); } break; case 4: if (Event.xbutton.button==Button1) run_pref_app(); else run_log_app(); break; } } RedrawWindow (); but_stat = -1; break; default: break; } } usleep (50000L); } }
void wmtime_routine(int argc, char **argv) { rckeys wmtime_keys[] = { { "left", &left_action }, { "right", &right_action }, { "middle", &middle_action }, { NULL, NULL } }; int i; XEvent Event; int but_stat = -1; struct tm *time_struct; long starttime; long curtime; char *conffile = NULL; /* Scan through ~/.wmtimerc for the mouse button actions. */ if (default_left_action) left_action = strdup(default_left_action); if (default_middle_action) middle_action = strdup(default_middle_action); if (default_right_action) right_action = strdup(default_right_action); /* Scan through the .rc files */ if (asprintf(&conffile, "/etc/wmtimerc") >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } if (asprintf(&conffile, "%s/.wmtimerc", getenv("HOME")) >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } if (asprintf(&conffile, "/etc/wmtimerc.fixed") >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } /* set user-defined colors */ if (color[0] != 0) { Window Root; XColor col; XWindowAttributes attributes; int screen; Pixel pixel; #define NUMSYMBOLS 10 XpmColorSymbol user_color[NUMSYMBOLS] = { {NULL, "#2081B2CAAEBA", 0}, /* O */ {NULL, "#000049244103", 0}, /* + */ {NULL, "#00007DF771C6", 0}, /* @ */ {NULL, "#18618A288617", 0}, /* # */ {NULL, "#18619A699658", 0}, /* ; */ {NULL, "#0820861779E7", 0}, /* : */ {NULL, "#000071C66185", 0}, /* > */ {NULL, "#000061855144", 0}, /* , */ {NULL, "#00004D344103", 0}, /* < */ {NULL, "#10407DF779E7", 0} /* 1 */ }; /* code based on GetColor() from wmgeneral.c */ /* we need a temporary display to parse the color */ display = XOpenDisplay(NULL); screen = DefaultScreen(display); Root = RootWindow(display, screen); XGetWindowAttributes(display, Root, &attributes); col.pixel = 0; if (!XParseColor(display, attributes.colormap, color, &col)) { fprintf(stderr, "wmtime: can't parse %s.\n", color); goto draw_window; } else if (!XAllocColor(display, attributes.colormap, &col)) { fprintf(stderr, "wmtime: can't allocate %s.\n", color); goto draw_window; } pixel = col.pixel; /* replace colors from wmtime-master.xpm */ user_color[0].pixel = pixel; user_color[1].pixel = scale_pixel(pixel, .4); user_color[2].pixel = scale_pixel(pixel, .7); user_color[3].pixel = scale_pixel(pixel, .8); user_color[4].pixel = scale_pixel(pixel, .9); user_color[5].pixel = scale_pixel(pixel, .8); user_color[6].pixel = scale_pixel(pixel, .6); user_color[7].pixel = scale_pixel(pixel, .5); user_color[8].pixel = scale_pixel(pixel, .4); user_color[9].pixel = scale_pixel(pixel, .7); wmgen.attributes.valuemask |= XpmColorSymbols; wmgen.attributes.numsymbols = NUMSYMBOLS; wmgen.attributes.colorsymbols = user_color; XCloseDisplay(display); } draw_window: openXwindow(argc, argv, wmtime_master_xpm, (char*)wmtime_mask_bits, 128, 64); /* Mask out the right parts of the clock */ copyXPMArea(0, 0, 128, 64, 0, 98); /* Draw the borders */ copyXPMArea(0, 0, 64, 64, 64, 0); /* Draw the clock face */ copyXPMArea(64, 98, 64, 64, 0, 0); /* Draw the LCD background */ setMaskXY(0, 0); /* add mouse region */ AddMouseRegion(0, 5, 48, 58, 60); AddMouseRegion(1, 5, 5, 58, 46); starttime = time(0); curtime = time(0); time_struct = localtime(&curtime); while (1) { curtime = time(0); waitpid(0, NULL, WNOHANG); time_struct = localtime(&curtime); if (curtime >= starttime) { if (!digital) { /* Now to update the seconds */ DrawWijzer(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } else { DrawTime(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: digital = 1-digital; if (digital) { copyXPMArea(64, 98, 64, 64, 0, 0); DrawTime(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } else { copyXPMArea(0, 98, 64, 64, 0, 0); DrawWijzer(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } RedrawWindow(); break; case 1: switch (Event.xbutton.button) { case 1: if (left_action) execCommand(left_action); break; case 2: if (middle_action) execCommand(middle_action); break; case 3: if (right_action) execCommand(right_action); break; } } } break; } } /* Sleep 0.3 seconds */ usleep(300000L); } }
int main(int argc, char *argv[]) { int i=0,debug=0,r,j=0,x=0,selected=-1; long int gi=0,gf=0; int colord=66,colorg=71; struct dirent **namelist; int ls=0,metnum=0; unsigned char buf[516] ; char * tmpdir = NULL; for (i=1; i<argc; i++) { char *arg = argv[i]; if (*arg=='-') { switch (arg[1]) { case 't' : tmpdir = argv[i+1]; printf("Using temp dir %s\n",tmpdir); break; case 'w' : if (argc>i+1){ if (!strcasecmp(argv[i+1],"red")) colord=71; else if (!strcasecmp(argv[i+1],"blue")) colord=76; else if (!strcasecmp(argv[i+1],"yellow")) colord=81; else if (!strcasecmp(argv[i+1],"white")) colord=86; else if (!strcasecmp(argv[i+1],"cyan")) colord=91; else if (!strcasecmp(argv[i+1],"black")) colord=96; else if (!strcasecmp(argv[i+1],"blank")) colord=101; else printf("Invalid color %s\n",argv[i+1]); }else {usage();exit(-1);} break; case 'g' : if (argc>i+1){ if (!strcasecmp(argv[i+1],"green")) colorg=66; else if (!strcasecmp(argv[i+1],"blue")) colorg=76; else if (!strcasecmp(argv[i+1],"yellow")) colorg=81; else if (!strcasecmp(argv[i+1],"white")) colorg=86; else if (!strcasecmp(argv[i+1],"cyan")) colorg=91; else if (!strcasecmp(argv[i+1],"black")) colorg=96; else if (!strcasecmp(argv[i+1],"blank")) colorg=101; else printf("Invalid color %s\n",argv[i+1]); }else {usage();exit(-1);} break; case 'v' : printversion(); exit(0); break; case 'd' : debug=1; printf("Debuggin mode: \n"); break; default: usage(); exit(0); break; } } } if (!tmpdir) { usage(); exit(-1);} openXwindow(argc, argv, wmdonkeymon_master_xpm, wmdonkeymon_mask_bits, wmdonkeymon_mask_width, wmdonkeymon_mask_height); copyXPMArea(5,60,52,54,5,3); RedrawWindow(); splash(); r = 0; while (1) { if (!r) { FILE * met; unsigned char type; short int len=0,vlen=0; int gaps=0, firstgap = 0x7fffffff, miss=0, fsize=0,metcount=0; long int fileSize=0, num =0; char nvalue[516],value[516]; j =0; metnum=0; // Search for files in temp directory ls = scandir(tmpdir, &namelist, 0, alphasort); if (ls < 0){ printf("Can't find files in %s",tmpdir); exit(-1); } else { while(ls-- && (metcount<4)) { char * pt; pt = strstr(namelist[ls]->d_name,".part.met"); if (pt && !strcmp(pt,".part.met")) { if(debug)printf("File: %s\n",namelist[ls]->d_name); strcpy(files[metcount].metname,namelist[ls]->d_name); metcount++; } free(namelist[ls]); } free(namelist); } for (metnum=0; metnum < metcount; metnum++) { i=0; sprintf(buf,"%s%s",tmpdir,files[metnum].metname); files[metnum].t_miss=0; if(debug)printf("opening %s\n",buf); if ( (met = fopen(buf,"rb")) != NULL) {} else {printf("Nada\n");}; // Version i += fread(buf,1,1,met); if(debug){ printf("Version: %x\n",buf[0]); } // Date ?? i += fread(buf,1,4,met); if(debug) { printf("Date: %x %x %x %x \n",buf[0],buf[1],buf[2],buf[3]); } // Hash i += fread(buf,1,16,met); if(debug){ printf("Hash: "); for (j=0;j<16;j++) printf("%x ",buf[j]); printf("\n"); } // Partial Hashes i += fread(buf,1,2,met); memcpy(&j,buf,2); if(debug) printf("Num of Hashes: %d\n",j); // Hashes for (i=0;i<j;i++){ fread(buf,1,16,met); if(debug){printf("Hash %d: ",i+1); for (x=0;x<16;x++) printf("%x ",buf[x]); printf("\n");} } // Num of Meta Tags i = fread(buf,1,4,met); memcpy(&num,buf,4); if(debug){printf("Num of Meta Tags: %ld\n",num);} x = 0; // Meta Tags for (i=0;i<num;i++){ fread(&type,1,1,met); fread(&len,2,1,met); fread(nvalue,1,len,met); if (type==2){ // String Tag fread(&vlen,1,2,met); fread(value,1,vlen,met); value[vlen] = '\0'; if (len==1){ // Special Tag switch (nvalue[0]){ case 1: strcpy(files[metnum].name,value); if(debug){printf("File Name: %s\n",value);} break; case 3: if(debug){printf("File Type: %s\n",value);} strcpy(files[metnum].type,value); break; case 4: if(debug){printf("File Format: %s\n",value);} break; case 18: if(debug){printf("Temp file: %s\n",value);} break; } } else if (debug)printf("Unknow String Tag %d: %s",nvalue[0],value); }else if (type==3){ fread(&fsize,1,4,met); if (len==1){ // Special Tag switch (nvalue[0]){ case 2: if(debug)printf("File Size: %d KB\n",fsize/(1024)); fileSize = fsize; break; case 8: if(debug)printf("Copied so Far: %d KB\n",fsize/(1024)); files[metnum].copied=fsize; break; case 19: if(debug) printf("Priority: %d\n",fsize); break; case 20: if(debug)printf("Status: %d\n",fsize); files[metnum].status = fsize; break; default: if(debug)printf("Unknow Tag %d: %d\n",nvalue[0],fsize); break; } } else { if (nvalue[0]==9){ nvalue[len]='\0'; if(debug)printf("gap %3s from %10d", &nvalue[1], fsize); gaps = fsize; if (gaps < firstgap) firstgap = gaps; }else if (nvalue[0]==10){ miss = fsize - gaps; gi = (long int)((SLOT_SIZE * (gaps/1024)) / (fileSize/1024)); gf = (long int)((SLOT_SIZE * (fsize/1024)) / (fileSize/1024)); if (gf>=gi){ files[metnum].gappos[x][0] = gi; files[metnum].gappos[x][1] = gf; x++; } files[metnum].t_miss += miss; if(debug)printf(" to %10d = %10d Size(%d) Gaprel: %d-%d\n",fsize,miss,9728000,files[metnum].gappos[x][0],files[metnum].gappos[x][1]); } } } } files[metnum].gapnum = x; files[metnum].firstgap = firstgap; files[metnum].lastsize = files[metnum].copied; files[metnum].size = fileSize; // sort gaps /* don'n needed * for (i=0; i<x; i++) for (j=0; j<x; j++) { if (files[0].gappos[i][0]<files[0].gappos[j][0]) { z = files[0].gappos[i][0]; files[0].gappos[i][0] = files[0].gappos[j][0]; files[0].gappos[j][0] = z; z = files[0].gappos[i][1]; files[0].gappos[i][1] = files[0].gappos[j][1]; files[0].gappos[j][1] = z; } } if(debug)for (i=0; i<x; i++){ printf("[%d-%d]",files[0].gappos[i][0],files[0].gappos[i][1]); } */ if(debug)printf("%d bytes = %.2f mb missing\n", files[metnum].t_miss, (double)files[metnum].t_miss/(1024*1024)); if(debug)if (firstgap < 0x7fffffff) printf("first gap starts at %d (%d blocks are complete)\n", firstgap, firstgap/(9500*1024)); fclose(met); } } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { if (selected>-1) selected=-1; else selected=i; } break; } } for (j=0;j<15;j++) DelMouseRegion(j); if (metnum==0){ splash(); showString("NO FILES",8); showString("FOUND IN",9); showString("TEMP DIR",10); }else if (selected>-1){ char out[30]; char unit[4] = " KMG"; long int s,c; int sk=0,ck=0; copyXPMArea(5,60,52,54,5,3); AddMouseRegion(0,5,5,54,54); showString(files[selected].name,1); s=files[selected].size; while (s>1024){s/=1024;sk++;} c=files[selected].copied; while (c>1024){c/=1024;ck++;} sprintf(out,"%ld%c/%ld%c",c,unit[ck],s,unit[sk]); showString(out,4); sprintf(out,"%s",files[selected].type); showString(out,5); // ************** // Donwload Rate // Don't work unless edonkey update met files more frequently // // s = (files[selected].copied) - (files[selected].lastsize); // sprintf(out,"%ld B/S",(s/REF_RATE)); // showString(out,8); //************************ //STATUS //status tag is always "Looking..." :( // //getStatus(files[selected].status,out); //showString(out,9); sprintf(out,"%.3f%%", (( 1.0 * files[selected].copied / files[selected].size))*100); showString(out,8); copyXPMArea(66,colord,52,5,5,11); for (i=0; i < files[selected].gapnum ; i++) { copyXPMArea(66,colorg,files[selected].gappos[i][1]-files[selected].gappos[i][0],5,files[selected].gappos[i][0]+5 ,11); } }else{ copyXPMArea(5,60,52,54,5,3); for (j=0; j<metnum; j++){ showString(files[j].name,(j*2)+1+j); copyXPMArea(66,colord,52,5,5,(j+1)*10+(j*5) ); // printf("top: %d\n",((j+1)*10+(j*5))); for (i=0; i < files[j].gapnum ; i++) { copyXPMArea(66,colorg,files[j].gappos[i][1]-files[j].gappos[i][0],5,files[j].gappos[i][0]+5 ,(j+1)*10+(j*5)); } AddMouseRegion(j,5,(j+1)*5,52,(j+1)*10+(j*5)+5); } } RedrawWindow(); sleep(1); r++; if (r==REF_RATE) r=0; } }
void wmifs_routine(int argc, char **argv) { rckeys wmifs_keys[] = { { "left", &left_action }, { "middle", &middle_action }, { "right", &right_action }, { NULL, NULL } }; int i, j; XEvent Event; int but_stat = -1; int stat_online; int stat_current; int first_time = 1; unsigned int curtime; unsigned int nexttime; struct timeval tv, tv2; long ipacket, opacket, istat, ostat; char temp[BUFFER_SIZE]; char *p; for (i = 0; i < MAX_STAT_DEVICES; i++) { stat_devices[i].name[0] = 0; for (j = 0; j < 48; j++) { stat_devices[i].his[j][0] = 0; stat_devices[i].his[j][1] = 0; } } stat_online = checknetdevs(); stat_current = 0; if (active_interface) { int isauto = !strcmp(active_interface, "auto"); for (i = 0; i < stat_online; i++) { if ((isauto && stillonline(stat_devices[i].name)) || !strcmp(stat_devices[i].name, active_interface)) { stat_current = i; break; } } } #ifdef LEFT_ACTION left_action = strdup(LEFT_ACTION); #endif #ifdef MIDDLE_ACTION middle_action = strdup(MIDDLE_ACTION); #endif #ifdef RIGHT_ACTION right_action = strdup(RIGHT_ACTION); #endif /* Scan throught the .rc files */ parse_rcfile(CONF"/wmifsrc", wmifs_keys); p = getenv("HOME"); if (p == NULL || *p == 0) { fprintf(stderr, "Unknown $HOME directory, please check your environment\n"); return; } strncpy(temp, p, BUFFER_SIZE - 10); strcat(temp, "/.wmifsrc"); parse_rcfile(temp, wmifs_keys); parse_rcfile(CONF"/wmifsrc.fixed", wmifs_keys); /* set user-defined colors */ if (color[0] != 0) { Window Root; XColor col; XWindowAttributes attributes; int screen; Pixel pixel; #define NUMSYMBOLS 4 XpmColorSymbol user_color[NUMSYMBOLS] = { {NULL, "#2081B2CAAEBA", 0}, /* + */ {NULL, "#28A23CF338E3", 0}, /* O */ {NULL, "#000049244103", 0}, /* @ */ {NULL, "#18618A288617", 0}, /* # */ }; /* code based on GetColor() from wmgeneral.c */ /* we need a temporary display to parse the color */ display = XOpenDisplay(NULL); screen = DefaultScreen(display); Root = RootWindow(display, screen); XGetWindowAttributes(display, Root, &attributes); col.pixel = 0; if (!XParseColor(display, attributes.colormap, color, &col)) { fprintf(stderr, "wmtime: can't parse %s.\n", color); goto draw_window; } else if (!XAllocColor(display, attributes.colormap, &col)) { fprintf(stderr, "wmtime: can't allocate %s.\n", color); goto draw_window; } pixel = col.pixel; /* replace colors from wmtime-master.xpm */ user_color[0].pixel = pixel; user_color[1].pixel = scale_pixel(pixel, .3); user_color[2].pixel = scale_pixel(pixel, .4); user_color[3].pixel = scale_pixel(pixel, .8); wmgen.attributes.valuemask |= XpmColorSymbols; wmgen.attributes.numsymbols = NUMSYMBOLS; wmgen.attributes.colorsymbols = user_color; XCloseDisplay(display); } draw_window: openXwindow(argc, argv, wmifs_master_xpm, (char*)wmifs_mask_bits, wmifs_mask_width, wmifs_mask_height); /* > Button */ AddMouseRegion(0, 5, 5, 35, 15); AddMouseRegion(1, 5, 20, 58, 58); gettimeofday(&tv2, NULL); nexttime = ScrollSpeed; DrawActiveIFS(stat_devices[stat_current].name); while (1) { struct timespec ts; gettimeofday(&tv, NULL); curtime = (tv.tv_sec - tv2.tv_sec) * 1000 + (tv.tv_usec - tv2.tv_usec) / 1000; waitpid(0, NULL, WNOHANG); for (i = 0; i < stat_online; i++) { get_statistics(stat_devices[i].name, &ipacket, &opacket, &istat, &ostat); if (first_time) { first_time = 0; } else { stat_devices[i].his[53][0] += istat - stat_devices[i].istatlast; stat_devices[i].his[53][1] += ostat - stat_devices[i].ostatlast; } if (i == stat_current) { if (!stillonline(stat_devices[i].name)) SetErrLED(LED_NET_POWER); else SetOnLED(LED_NET_POWER); if (stat_devices[i].istatlast == istat) SetOffLED(LED_NET_RX); else SetOnLED(LED_NET_RX); if (stat_devices[i].ostatlast == ostat) SetOffLED(LED_NET_TX); else SetOnLED(LED_NET_TX); } stat_devices[i].istatlast = istat; stat_devices[i].ostatlast = ostat; } RedrawWindow(); if (curtime >= nexttime) { nexttime = curtime + ScrollSpeed; DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); for (i = 0; i < stat_online; i++) { if (stillonline(stat_devices[i].name)) { for (j = 1; j < 54; j++) { stat_devices[i].his[j-1][0] = stat_devices[i].his[j][0]; stat_devices[i].his[j-1][1] = stat_devices[i].his[j][1]; } stat_devices[i].his[53][0] = 0; stat_devices[i].his[53][1] = 0; } } RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: /* re-read the table */ strcpy(temp, stat_devices[stat_current].name); stat_online = checknetdevs(); stat_current = 0; for (i = 0; i < stat_online; i++) { if (!strcmp(temp, stat_devices[i].name)) stat_current = i; } stat_current++; if (stat_current == stat_online) stat_current = 0; DrawActiveIFS(stat_devices[stat_current].name); DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); break; case 1: switch (Event.xbutton.button) { case 1: if (left_action) execCommand(left_action); break; case 2: if (middle_action) execCommand(middle_action); break; case 3: if (right_action) execCommand(right_action); break; } break; } } but_stat = -1; RedrawWindow(); break; } } ts.tv_sec = 0; ts.tv_nsec = SampleInt * 1000000; nanosleep(&ts, NULL); } }