oster@dewey.soe.berkeley.edu (David Phillip Oster) (08/12/87)
I've been using xpostit, and I don't like the data file format. The format is: <A geometry Spec> <A character count> <The body of the file> example: =160x120+674+26 15 This is a Test. It is obnoxious to have a character count, as this prevents me from editing the file with a standard text editor. What follows is a fix for this problem. It requires the "stat" system call, and requires that the structure defined in stdio.h keep a count of how many characters remain in the buffer. I use it on Suns. After this fix is applied to the file "file.c" in xpostit, the file format of xpostit becomes: <A geometry Spec> <The body of the file> example: =160x120+674+26 This is a Test. You must remember to modify the Makefile, so that CFLAGS line becomes: CFLAGS= -O -I../include -DUNIX Here are the diffs to file.c: ------------------------------------------- 9a10,11 > * changes: David Oster July, '87 - removed explicit char count from files > * since change uses Unix system calls, make them #ifdef UNIX 12a15,16 > #include <sys/file.h> > #include <sys/stat.h> 90,91c94 < * Print the geometry and the number of characters in the < * note to the file. --- > * Print the geometry to the file. 94d96 < fprintf(fp, "%d\n", n->nchars); 95a98 > #ifndef UNIX 96a100,105 > * Print the size to the file > */ > fprintf(fp, "%s\n", n->notetext); > #endif > > /* 191c200 < * Read in the number of characters in the note. --- > * Get the number of characters in the note. 193,194d201 < fgets(buf, sizeof(buf), fp); < sscanf(buf, "%d", &size); 195a203,204 > size = GetRemainingSize(fp); > 244a254,278 > > > /* GetRemainingSize - given a FILE, return the number of chars remaining > * in the file. > */ > int GetRemainingSize(fp)FILE *fp;{ > #ifdef UNIX > struct stat buf; > > fstat(fileno(fp), &buf); > return fp->_cnt + buf.st_size - lseek(fileno(fp), 0L, L_INCR); > > #else > > char buf[512]; > int size; > > fgets(buf, sizeof(buf), fp); > sscanf(buf, "%d", &size); > return size; > #endif > > } > > --- David Phillip Oster --My Good News: "I'm a perfectionist." Arpa: oster@dewey.soe.berkeley.edu --My Bad News: "I don't charge by the hour." Uucp: {seismo,decvax,...}!ucbvax!oster%dewey.s i i ir oir oi y