peter@ficc.uu.net (Peter da Silva) (02/09/90)
This adds a new command to browse, 's' loads a saved macro file. The format of the macro file is also slightly changed. This is based on the version I posted this morning, but should work as applied to most versions of browse, since I haven't changed this code recently. Have fun! ------8<------- Tear along dotted line ----------------------------------- *** baseline/browse.c --- browse.c *************** *** 1324,1329 **** --- 1324,1332 ---- case 'S': savedefs(); break; + case 's': + loaddefs(); + break; case 'U'-'@': prev(nlines/2); break; *************** *** 2212,2217 **** --- 2215,2221 ---- char filename[MAXLINE]; static char lastfile[MAXLINE] = "/usr/tmp/macros"; FILE *fp; + char *p; cmdline(); outs("Save macros as "); *************** *** 2228,2237 **** return; } ! for(i=1; i<CHARSET; i++) ! if(macbuf[i]) ! fprintf(fp, "[%c%s]\n", i, macbuf[i]); fclose(fp); } --- 2232,2321 ---- return; } ! for(i=1; i<CHARSET; i++) { ! if(macbuf[i]) { ! putc('[', fp); ! putc(i, fp); ! for(p = macbuf[i]; *p; p++) { ! switch(*p) { ! case ']': ! case '\\': ! case '\n': ! putc('\\', fp); ! } ! putc(*p, fp); ! } ! putc(']', fp); ! putc('\n', fp); ! } ! } + fclose(fp); + } + + loaddefs() + { + int i; + char buf[MAXLINE]; + static char lastfile[MAXLINE] = "/usr/tmp/macros"; + FILE *fp; + char *p; + char c; + char *s; + + cmdline(); + outs("Load macros from "); + + if(inps(buf, lastfile, '\033')=='\033') { + killcmd(); + return; + } + + strcpy(lastfile, buf); + + if(!(fp = fopen(buf, "r"))) { + wperror(buf); + return; + } + + while(!feof(fp)) { + i = getc(fp); + if(i == EOF) + break; + if(i != '[') + continue; + i = getc(fp); + if(i == EOF) + break; + if(i <= 0 || i >= CHARSET) { + cmdline(); + outs("Not a legal macro character: "); + printf("\\%03o", i & 0xFF); + break; + } + s = buf; + while(!feof(fp)) { + c = getc(fp); + if(feof(fp)) + break; + if(c == '\n' || c == ']') + break; + if(c=='\\') { + c = getc(fp); + if(feof(fp)) + break; + } + *s++ = c; + } + if(c != ']') { + cmdline(); + outs("Unterminated macro: "); + ctloutc(i); + break; + } + *s = 0; + defent(i, buf); + } fclose(fp); } *** baseline/browse.doc --- browse.doc *************** *** 18,23 **** --- 18,24 ---- P,^B Go up 20 lines. R Rename a file. S Save definitions. + s Load definitions. dd Delete file(s). (ask for verification) DD Delete file(s). h Place cursor at beginning of line. -- _--_|\ Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>. / \ \_.--._/ Xenix Support -- it's not just a job, it's an adventure! v "Have you hugged your wolf today?" `-_-'