#include #define X11CFG "/etc/X11/XF86Config" #define X11CFG1 "/tmp/XF86Config" #define X11CFG2 "/tmp/XF86Config.new" FILE *x11cfg; FILE *x11cfg1; FILE *x11cfg2; FILE *curfile; char line[80]; char status; const char str1[] = "Section \"Device\"\n"; const char str2[] = "Section \"Monitor\"\n"; char *curstr; int main() { truncate (X11CFG, 0); x11cfg = fopen (X11CFG, "a"); x11cfg1 = fopen (X11CFG1, "r"); x11cfg2 = fopen (X11CFG2, "r"); curfile = x11cfg1; while (fgets (line, 80, curfile) != NULL ) { if (!strcmp (line, str1)) curstr = str1; else if (!strcmp (line, str2)) curstr = str2; else if (!strcmp (line, "EndSection\n") && status) { status = 0; curfile = x11cfg1; fputs (line, x11cfg); while ( fgets (line, 80, curfile) && \ strcmp (line, "EndSection\n")); continue; } else { fputs (line, x11cfg); continue; } status = 1; curfile = x11cfg2; while (fgets (line, 80, curfile) && strcmp (line, curstr)); fputs (line, x11cfg); } fclose (x11cfg); fclose (x11cfg1); fclose (x11cfg2); exit (0); }