/* Read and parse one included syntax file. */ static void parse_one_include(char *file) { FILE *rcstream; /* Don't open directories, character files, or block files. */ if (!is_good_file(file)) return; /* Open the included syntax file. */ rcstream = fopen(file, "rb"); if (rcstream == NULL) { rcfile_error(_("Error reading %s: %s"), file, strerror(errno)); return; } /* Use the name and line number position of the included syntax file * while parsing it, so we can know where any errors in it are. */ nanorc = file; lineno = 0; #ifdef DEBUG fprintf(stderr, "Parsing file \"%s\"\n", file); #endif parse_rcfile(rcstream, TRUE); }
/* Read and parse additional syntax files. */ void parse_include(char *ptr) { struct stat rcinfo; FILE *rcstream; char *option, *nanorc_save = nanorc, *expanded; size_t lineno_save = lineno; option = ptr; if (*option == '"') option++; ptr = parse_argument(ptr); /* Can't get the specified file's full path cause it may screw up our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */ /* Don't open directories, character files, or block files. */ if (stat(option, &rcinfo) != -1) { if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || S_ISBLK(rcinfo.st_mode)) { rcfile_error(S_ISDIR(rcinfo.st_mode) ? _("\"%s\" is a directory") : _("\"%s\" is a device file"), option); } } expanded = real_dir_from_tilde(option); /* Open the new syntax file. */ if ((rcstream = fopen(expanded, "rb")) == NULL) { rcfile_error(_("Error reading %s: %s"), expanded, strerror(errno)); return; } /* Use the name and line number position of the new syntax file * while parsing it, so we can know where any errors in it are. */ nanorc = expanded; lineno = 0; #ifdef DEBUG fprintf(stderr, "Parsing file \"%s\" (expanded from \"%s\")\n", expanded, option); #endif parse_rcfile(rcstream #ifdef ENABLE_COLOR , TRUE #endif ); /* We're done with the new syntax file. Restore the original * filename and line number position. */ nanorc = nanorc_save; lineno = lineno_save; }
/* Read and parse additional syntax files. */ static void _parse_include(char *file) { struct stat rcinfo; FILE *rcstream; /* Can't get the specified file's full path because it may screw up * our cwd depending on the parent directories' permissions (see * Savannah bug #25297). */ /* Don't open directories, character files, or block files. */ if (stat(file, &rcinfo) != -1) { if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || S_ISBLK(rcinfo.st_mode)) { rcfile_error(S_ISDIR(rcinfo.st_mode) ? _("\"%s\" is a directory") : _("\"%s\" is a device file"), file); } } /* Open the new syntax file. */ if ((rcstream = fopen(file, "rb")) == NULL) { rcfile_error(_("Error reading %s: %s"), file, strerror(errno)); return; } /* Use the name and line number position of the new syntax file * while parsing it, so we can know where any errors in it are. */ nanorc = file; lineno = 0; #ifdef DEBUG fprintf(stderr, "Parsing file \"%s\"\n", file); #endif parse_rcfile(rcstream, TRUE); }
/* The main rcfile function. It tries to open the system-wide rcfile, * followed by the current user's rcfile. */ void do_rcfile(void) { struct stat rcinfo; FILE *rcstream; nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc"); /* Don't open directories, character files, or block files. */ if (stat(nanorc, &rcinfo) != -1) { if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || S_ISBLK(rcinfo.st_mode)) rcfile_error(S_ISDIR(rcinfo.st_mode) ? _("\"%s\" is a directory") : _("\"%s\" is a device file"), nanorc); } #ifdef DEBUG fprintf(stderr, "Parsing file \"%s\"\n", nanorc); #endif /* Try to open the system-wide nanorc. */ rcstream = fopen(nanorc, "rb"); if (rcstream != NULL) parse_rcfile(rcstream #ifdef ENABLE_COLOR , FALSE #endif ); #ifdef DISABLE_ROOTWRAPPING /* We've already read SYSCONFDIR/nanorc, if it's there. If we're * root, and --disable-wrapping-as-root is used, turn wrapping off * now. */ if (geteuid() == NANO_ROOT_UID) SET(NO_WRAP); #endif get_homedir(); if (homedir == NULL) rcfile_error(N_("I can't find my home directory! Wah!")); else { #ifndef RCFILE_NAME #define RCFILE_NAME ".nanorc" #endif nanorc = charealloc(nanorc, strlen(homedir) + strlen(RCFILE_NAME) + 2); sprintf(nanorc, "%s/%s", homedir, RCFILE_NAME); /* Don't open directories, character files, or block files. */ if (stat(nanorc, &rcinfo) != -1) { if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || S_ISBLK(rcinfo.st_mode)) rcfile_error(S_ISDIR(rcinfo.st_mode) ? _("\"%s\" is a directory") : _("\"%s\" is a device file"), nanorc); } /* Try to open the current user's nanorc. */ rcstream = fopen(nanorc, "rb"); if (rcstream == NULL) { /* Don't complain about the file's not existing. */ if (errno != ENOENT) rcfile_error(N_("Error reading %s: %s"), nanorc, strerror(errno)); } else parse_rcfile(rcstream #ifdef ENABLE_COLOR , FALSE #endif ); } free(nanorc); nanorc = NULL; if (errors && !ISSET(QUIET)) { errors = FALSE; fprintf(stderr, _("\nPress Enter to continue starting nano.\n")); while (getchar() != '\n') ; } #ifdef ENABLE_COLOR set_colorpairs(); #endif }
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); } }
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); } }