nobody@KODAK.COM (Jeff Gerstenberger) (12/22/89)
I have received several requests to post my GNU Emacs macros which emulate the TDS folding editor. The macros will be posted in a separate item to the newsgroup. The remainder of this item has general information on the macros and source code for a conversion program to prepare "listed" TDS files for editting with the Emacs macros. As stated in my earlier posting, the macros originated elsewhere and I have made modifications to them to get them to emulate our version of TDS more closely. We use the macros on Sun workstations for editing Toolset source files. The right keypad is used for invoking the fold-related operations. (some of the operations are prefaced by hitting the "Alternate" key). The key bindings of these operations are accessible through Emacs (as well as by just looking at the source code), and obviously can be changed to suit your own needs. The editor macros make extensive use of Emacs' point and mark which, strictly speaking, is a no-no. Experienced users of Emacs may find this to be a nuisance, in which case they may wish to fix it (hint, hint)! (I haven't gotten around to it yet, and probably won't have the time for quite a while.) If anyone does make changes and/or improvements, I'd like to know about them. Following the (usual) disclaimer below and my signature, is C source for a program which takes files that have been "listed" using the TDS utilities and slightly changes them for the Emacs macros. (It mostly reduces the number of fold-mark characters that appear on fold lines). It makes going from TDS to the Toolset quite easy. DISCLAIMER: This software is NOT a supported product of Eastman Kodak. Kodak assumes no responsibility for maintaining this software and is not liable for any damage it may cause during its use. We're happy to let you use it, but don't blame us if it acts up! Jeff Gerstenberger gerst@gerst.kodak.com Digital Technology Center (716) 726-7003 Eastman Kodak Company Rochester, NY 14653-5324 ------------------------------------------------------------------------ #include <string.h> #include <stdio.h> main(argc, argv) int argc; char *argv[]; { char file_in[50], file_out[50]; char line[256]; char answer[20], command[100]; FILE *ifp, *ofp; int i, j, len; printf("\nFile to be converted for Emacs folding editor: "); scanf("%s", file_in); strcpy(file_out, file_in); strcat(file_out, "_cvt"); if ((ifp = fopen(file_in, "r")) == NULL) { printf("Error: Unable to open input file.\n"); exit(1); } if (fopen(file_out, "r") != NULL) { printf("Error: Output file already exists.\n"); exit(1); } if ((ofp = fopen(file_out, "w")) == NULL) { printf("Error: Unable to create output file.\n"); exit(1); } line[0] = '\0'; strcat(line, "--{"); strcat(line, file_in); strcat(line, ":"); strcat(line, file_in); strcat(line, "\n"); fputs(line, ofp); while (fgets(line, 256, ifp) != NULL) { len = strlen(line); for (i=0; i<len-4; i++) { if (strncmp(&line[i], "--{{{", 5) == 0) { line[i+3] = ':'; for (j=i+5; j<=len; j++) line[j-1] = line[j]; i += 3; } if (strncmp(&line[i], "--}}}", 5) == 0) { for (j=i+5; j<=len; j++) line[j-2] = line[j]; i += 2; } } fputs(line, ofp); } line[0] = '\0'; strcat(line, "--}\n"); fputs(line, ofp); fclose(ifp); fclose(ofp); sprintf(command, "mv %s %s\n", file_out, file_in); printf("Conversion done. OK to overwrite input file? "); scanf("%s", answer); if (strlen(answer) == 1) { if ((answer[0] == 'y') || (answer[0] == 'Y')) system(command); else printf("Output written to '%s'.\n", file_out); } else if (strlen(answer) == 3) { if ((strcmp(answer, "yes") == 0) || (strcmp(answer, "YES") == 0)) system(command); else printf("Output written to '%s'.\n", file_out); } else printf("Output written to '%s'.\n", file_out); }