home *** CD-ROM | disk | FTP | other *** search
- /*
- * lemio.c - I/O routines
- *
- * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
- */
-
- #include "lem.h"
-
- writefile()
- {
- int i;
- char *fname;
- FILE *f;
- if (lastobj == 1) return; /* nothing on display -- fast return */
- fname = prompt("output file: ");
- f = (fname && (strlen(fname) > 1)) ? fopen(fname, "w") : 0;
- if (f)
- {
- fprintf(f, "LEMMING %d\n", VERNO);
- forobjects
- {
- if (Onotdel)
- {
- fprintf(f, "%c %d %d %d %d %d %c %c",
- Otype, Oxs, Oys, Oxe, Oye, Osize, Oalign, Oemph);
- if (Otext && strlen(Otext)) fprintf(f, " \\%s", Otext);
- fprintf(f, "\n");
- }
- }
- fclose(f);
- changes = 0;
- msgpost("output done");
- }
- else msgpost("output failed");
- free(fname);
- }
-
- readfileint(fname)
- char *fname;
- {
- int i, g, ver;
- char *s, fline[MAXCHAR+50];
- FILE *f;
- f = 0;
- if (fname && (strlen(fname) > 0))
- {
- f = fopen(fname, "r");
- if (!f)
- {
- char filename[100];
- sprintf(filename, "%s.%s", fname, LEMEXTN);
- f = fopen(filename, "r");
- }
- }
- if (f)
- {
- fgets(fline, sizeof(fline), f);
- if ((sscanf(fline, "LEMMING %d", &ver) == 1) && (ver == VERNO))
- {
- g = uniquegroup();
- while (1)
- {
- int x0, y0, x1, y1, size;
- fgets(fline, sizeof(fline), f);
- if (feof(f)) break;
- i = objalloc(0);
- sscanf(fline, "%c %d %d %d %d %d %c %c", &Otype, &x0, &y0,
- &x1, &y1, &size, &Oalign, &Oemph);
- Oxs = x0;
- Oys = y0;
- Oxe = x1;
- Oye = y1;
- Osize = size;
- /*
- * possible input text
- */
- s = fline;
- while ((*s) && (*s != '\\')) s++;
- if (*s == '\\') s++;
- if (*s) s[strlen(s)-1] = '\0'; /* snuff trailing CR */
- Otext = (s && strlen(s)) ? salloc(s) : 0;
- /*
- * now assign attributes
- */
- Ogroup = g;
- Ostat = DEL;
- objresize(i);
- objectop(i, DEL, SEL);
- }
- fclose(f);
- msgpost("input done");
- }
- else msgpost("bogus input file");
- }
- else msgpost("input not found");
- }
-
- readfile()
- {
- char *fname;
- fname = prompt("input file: ");
- readfileint(fname);
- free(fname);
- }
-