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 wmsysmon_routine(int argc, char **argv) { int i; XEvent Event; FILE *fp; int xfd; struct pollfd pfd; createXBMfromXPM(wmsysmon_mask_bits, wmsysmon_master_xpm, wmsysmon_mask_width, wmsysmon_mask_height); xfd = openXwindow(argc, argv, wmsysmon_master_xpm, wmsysmon_mask_bits, wmsysmon_mask_width, wmsysmon_mask_height); if (xfd < 0) exit(1); pfd.fd = xfd; pfd.events = (POLLIN); /* init ints */ bzero(&_last_ints, sizeof(_last_ints)); bzero(&_ints, sizeof(_ints)); bzero(&int_peaks, sizeof(int_peaks)); /* init uptime */ fp = fopen("/proc/uptime", "r"); if (fp) { if (fscanf(fp, "%ld", &start_time) < 1) fprintf(stderr, "warning: could not read uptime\n"); fclose(fp); start_uptime = time(NULL); } statfp = fopen("/proc/stat", "r"); memfp = fopen("/proc/meminfo", "r"); /* here we find tags in /proc/stat & /proc/meminfo and note their * lines, for faster lookup throughout execution. */ /* /proc/meminfo */ for (i = 0; fgets(buf, 1024, memfp); i++) { if(strstr(buf, "Mem:")) Mem_l = i; else if(strstr(buf, "Swap:")) Swap_l = i; } /* /proc/stat */ for (i = 0; fgets(buf, 1024, statfp); i++) { if (strstr(buf, "disk_wio")) wio_l = i; else if (strstr(buf, "disk_rio")) rio_l = i; else if (strstr(buf, "page")) page_l = i; else if (strstr(buf, "swap")) swap_l = i; else if (strstr(buf, "intr")) intr_l = i; } while (1) { curtime = time(0); DrawUptime(); DrawStuff(); DrawMem(); RedrawWindow(); /* X Events */ poll(&pfd, 1, update_rate); while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: DirtyWindow(Event.xexpose.x, Event.xexpose.y, Event.xexpose.width, Event.xexpose.height); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; #ifdef MONDEBUG default: printf("got: %i\n", Event.type); #endif break; } } } }
int main( int argc, char** argv ) { int opt = 0; const struct option longopts[] = { {"display", required_argument, NULL, 0}, {"geometry", required_argument, NULL, 0}, {0, 0, 0, 0} }; #ifdef USE_MTRACE mtrace(); #endif /* USE_MTRACE */ signal( SIGINT, dockapp_exit ); signal( SIGSEGV, dockapp_crash ); opt = getopt_long_only( argc, argv, "hv", longopts, NULL); while ( -1 != opt ) { switch ( opt ) { case 'h': { dockapp_show_help( argv[0] ); exit( 1 ); /* Never reached. */ } case 'v': { dockapp_show_version(); exit( 1 ); /* Never reached. */ } } opt = getopt_long_only( argc, argv, "hv", longopts, NULL); } createXBMfromXPM( wmmisc_mask_bits, wmmisc_master_xpm, wmmisc_mask_width, wmmisc_mask_height ); openXwindow( argc, argv, wmmisc_master_xpm, wmmisc_mask_bits, wmmisc_mask_width, wmmisc_mask_height ); RedrawWindow(); dockapp_draw_small_str( "USERS", 4, 4 ); dockapp_draw_small_str( "PROCS", 4, 11 ); dockapp_draw_small_str( "ACTIVE", 4, 18 ); dockapp_draw_small_str( "UP", 4, 28 ); dockapp_draw_small_str( "DAYS", 4, 37 ); dockapp_draw_small_str( "WEEKS", 4, 44 ); dockapp_draw_small_str( "LOAD", 4, 53 ); do { dockapp_draw_data(); usleep( 250000L ); } while( 1 ); return 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); } }
int main(int argc,char *argv[]) { FILE *file; char line[256]; char xx[256]; int revision=0,release=0,patchlevel=0; XEvent event; int opt; scale_width=xpm_scale_width; scale_height=xpm_scale_height; scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; mem_correction=0; dev_name="hda"; while((opt=getopt(argc,argv,"hmt:d:"))!=-1) { switch(opt) { case 'd': dev_name=optarg; break; case 'm': mem_correction=1; break; case 't': switch(atoi(optarg)) { case 4: scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_2_b_x; scale_b_y=xpm_scale_2_b_y; break; case 3: scale_f_x=xpm_scale_1_f_x; scale_f_y=xpm_scale_1_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; break; case 2: scale_f_x=xpm_scale_1_f_x; scale_f_y=xpm_scale_1_f_y; scale_b_x=xpm_scale_2_b_x; scale_b_y=xpm_scale_2_b_y; break; case 1: default: scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; } break; case 'h': default: usage(argv[0]); exit(0); } } file=fopen("/proc/version","r"); fgets(line,sizeof(line),file); sscanf(line,"%s %s %d.%d.%d%s",xx,xx,&revision,&release,&patchlevel,xx); fclose(file); createXBMfromXPM(wmsm_mask_bits,wmsm_master_xpm,wmsm_mask_width,wmsm_mask_height); openXwindow(argc,argv,wmsm_master_xpm,wmsm_mask_bits,wmsm_mask_width,wmsm_mask_height); RedrawWindowXY(0,0); get_values(1,(revision<<16)+(release<<8)+patchlevel); while(1) { while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindowXY(0,0); break; case DestroyNotify: XCloseDisplay(display); exit(0); } } get_values(0,(revision<<16)+(release<<8)+patchlevel); usleep(150000L); } }