I was playing around with some Qt bindings and was most miffed when an update to one class caused the _entire_ PyQt library to be built. I modified gencode.c so after generating a file it checks if it is identical to the existing one. If it is, don't do the update. --pete P.S. This includes the change to va_arg(ap, int) I sent earlier diff -u sip-0.13pre1/sip/gencode.c sip/gencode.c *** sip-0.13pre1/sip/gencode.c Tue May 23 13:25:05 2000 --- sip/gencode.c Fri May 26 15:54:38 2000 *************** *** 112,118 **** static int countVirtuals(classVersDef *); static int skipOverload(overDef *,memberDef *,classVersDef *,classVersDef *,int); static FILE *createFile(char *,char *,char *); ! static void closeFile(FILE *); static void prcode(FILE *,char *,...); --- 112,118 ---- static int countVirtuals(classVersDef *); static int skipOverload(overDef *,memberDef *,classVersDef *,classVersDef *,int); static FILE *createFile(char *,char *,char *); ! static void closeFile(FILE *, const char *); static void prcode(FILE *,char *,...); *************** *** 141,146 **** --- 141,147 ---- generateCpp(pt,codeDir); generatePython(pt,codeDir); } + putchar ('\n'); } *************** *** 203,209 **** "}\n" ); ! closeFile(fp); free(vfile); } --- 204,210 ---- "}\n" ); ! closeFile(fp, vfile); free(vfile); } *************** *** 254,260 **** "};\n" ); ! closeFile(fp); free(hfile); } --- 255,261 ---- "};\n" ); ! closeFile(fp, hfile); free(hfile); } *************** *** 273,279 **** for (cb = pt -> docs; cb != NULL; cb = cb -> next) fputs(cb -> frag,fp); ! closeFile(fp); } --- 274,280 ---- for (cb = pt -> docs; cb != NULL; cb = cb -> next) fputs(cb -> frag,fp); ! closeFile(fp, docFile); } *************** *** 357,363 **** for (cb = pt -> makefile; cb != NULL; cb = cb -> next) prcode(fp,"\n%s",cb -> frag); ! closeFile(fp); } --- 358,364 ---- for (cb = pt -> makefile; cb != NULL; cb = cb -> next) prcode(fp,"\n%s",cb -> frag); ! closeFile(fp, makeFile); } *************** *** 467,473 **** for (cb = pt -> pycode; cb != NULL; cb = cb -> next) prcode(fp,"\n%s",cb -> frag); ! closeFile(fp); free(pyfile); } --- 468,474 ---- for (cb = pt -> pycode; cb != NULL; cb = cb -> next) prcode(fp,"\n%s",cb -> frag); ! closeFile(fp, pyfile); free(pyfile); } *************** *** 939,945 **** "#endif\n" ); ! closeFile(fp); free(hfile); } --- 940,946 ---- "#endif\n" ); ! closeFile(fp, hfile); free(hfile); } *************** *** 1309,1315 **** "}\n" ,mname); ! closeFile(fp); free(cppfile); /* Generate the class source and header files. */ --- 1310,1316 ---- "}\n" ,mname); ! closeFile(fp, cppfile); free(cppfile); /* Generate the class source and header files. */ *************** *** 2004,2010 **** for (cvd = cd -> cvds; cvd != NULL; cvd = cvd -> next) generateClassVersCpp(cvd,pt,fp); ! closeFile(fp); free(cppfile); } --- 2005,2011 ---- for (cvd = cd -> cvds; cvd != NULL; cvd = cvd -> next) generateClassVersCpp(cvd,pt,fp); ! closeFile(fp, cppfile); free(cppfile); } *************** *** 3902,3908 **** "#endif\n" ); ! closeFile(fp); free(wfile); } --- 3903,3909 ---- "#endif\n" ); ! closeFile(fp, wfile); free(wfile); } *************** *** 5891,5901 **** static FILE *createFile(char *fname,char *commentStr,char *description) { FILE *fp; /* Create the file. */ ! if ((fp = fopen(fname,"w")) == NULL) ! fatal("Unable to create file \"%s\"\n",fname); currentLineNr = 1; currentFileName = fname; --- 5892,5903 ---- static FILE *createFile(char *fname,char *commentStr,char *description) { FILE *fp; + char *newfilename = concat (fname, ".new", NULL); /* Create the file. */ ! if ((fp = fopen(newfilename,"w+")) == NULL) ! fatal("Unable to create file \"%s\"\n",newfilename); currentLineNr = 1; currentFileName = fname; *************** *** 5910,5918 **** prcode(fp,"%s %s\n",commentStr,description); prcode(fp,"%s\n",commentStr); ! prcode(fp,"%s Generated by SIP v%s on %s",commentStr,sipVersion,ctime(&now)); } ! return fp; } --- 5912,5920 ---- prcode(fp,"%s %s\n",commentStr,description); prcode(fp,"%s\n",commentStr); ! prcode(fp,"%s Generated by SIP v%s",commentStr,sipVersion); } ! free (newfilename); return fp; } *************** *** 5921,5928 **** * Close a file and report any errors. */ ! static void closeFile(FILE *fp) { if (ferror(fp)) fatal("Error writing to \"%s\"\n",currentFileName); --- 5923,5972 ---- * Close a file and report any errors. */ ! static void closeFile(FILE *fp, const char *fname) { + char *newfilename = concat ((char *) fname, ".new", NULL); + FILE *oldfp; /* the original file */ + int different = 0; /* if the old and new files are different */ + + oldfp = fopen (fname, "r"); + if (!oldfp) { + different = 2; /* indicate file did not exist */ + if (rename (newfilename, fname) < 0) + fatal ("Error renaming \"%s\" to \"%s\"\n", newfilename, +fname); + } + else { + char oldch, newch; + int where = 0; + clearerr (fp); + if (fseek (fp, 0, SEEK_SET) < 0) + perror (newfilename); + while (!different) { + oldch = fgetc (oldfp); + newch = fgetc (fp); + if (oldch != newch) { + different = 1; + break; + } + if (oldch == EOF) + break; + where++; + } + fclose (oldfp); + if (different) { + if (rename (newfilename, fname) < 0) + fatal ("Error renaming \"%s\" to \"%s\"\n", +newfilename, fname); + } + } + (void) unlink (newfilename); + free (newfilename); + if (different == 0) + putchar ('.'); + else if (different == 1) + putchar ('!'); + else + putchar ('+'); + fflush (stdout); if (ferror(fp)) fatal("Error writing to \"%s\"\n",currentFileName); *************** *** 5951,5961 **** { case 'c': { ! char c = va_arg(ap,char); if (c == '\n') ++currentLineNr; - fputc(c,fp); break; } --- 5995,6004 ---- { case 'c': { ! char c = va_arg(ap,int); if (c == '\n') ++currentLineNr; fputc(c,fp); break; } *************** *** 5968,5974 **** { if (*cp == '\n') ++currentLineNr; - fputc(*cp,fp); ++cp; } --- 6011,6016 ----