home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / lemming / part01 / lemio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-05  |  2.0 KB  |  105 lines

  1. /*
  2.  * lemio.c - I/O routines
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include "lem.h"
  8.  
  9. writefile()
  10.     {
  11.     int i;
  12.     char *fname;
  13.     FILE *f;
  14.     if (lastobj == 1) return;    /* nothing on display -- fast return */
  15.     fname = prompt("output file: ");
  16.     f = (fname && (strlen(fname) > 1)) ? fopen(fname, "w") : 0;
  17.     if (f)
  18.     {
  19.     fprintf(f, "LEMMING %d\n", VERNO);
  20.     forobjects
  21.         {
  22.         if (Onotdel)
  23.         {
  24.         fprintf(f, "%c %d %d %d %d %d %c %c",
  25.           Otype, Oxs, Oys, Oxe, Oye, Osize, Oalign, Oemph);
  26.         if (Otext && strlen(Otext)) fprintf(f, " \\%s", Otext);
  27.         fprintf(f, "\n");
  28.         }
  29.         }
  30.     fclose(f);
  31.     changes = 0;
  32.     msgpost("output done");
  33.     }
  34.     else msgpost("output failed");
  35.     free(fname);
  36.     }
  37.  
  38. readfileint(fname)
  39.     char *fname;
  40.     {
  41.     int i, g, ver;
  42.     char *s, fline[MAXCHAR+50];
  43.     FILE *f;
  44.     f = 0;
  45.     if (fname && (strlen(fname) > 0))
  46.     {
  47.     f = fopen(fname, "r");
  48.     if (!f)
  49.         {
  50.         char filename[100];
  51.         sprintf(filename, "%s.%s", fname, LEMEXTN);
  52.         f = fopen(filename, "r");
  53.         }
  54.     }
  55.     if (f)
  56.     {
  57.     fgets(fline, sizeof(fline), f);
  58.     if ((sscanf(fline, "LEMMING %d", &ver) == 1) && (ver == VERNO))
  59.         {
  60.         g = uniquegroup();
  61.         while (1)
  62.         {
  63.         int x0, y0, x1, y1, size;
  64.         fgets(fline, sizeof(fline), f);
  65.         if (feof(f)) break;
  66.         i = objalloc(0);
  67.         sscanf(fline, "%c %d %d %d %d %d %c %c", &Otype, &x0, &y0,
  68.             &x1, &y1, &size, &Oalign, &Oemph);
  69.         Oxs = x0;
  70.         Oys = y0;
  71.         Oxe = x1;
  72.         Oye = y1;
  73.         Osize = size;
  74. /*
  75.  * possible input text
  76.  */
  77.         s = fline;
  78.         while ((*s) && (*s != '\\')) s++;
  79.         if (*s == '\\') s++;
  80.         if (*s) s[strlen(s)-1] = '\0';    /* snuff trailing CR */
  81.         Otext = (s && strlen(s)) ? salloc(s) : 0;
  82. /*
  83.  * now assign attributes
  84.  */
  85.         Ogroup = g;
  86.         Ostat = DEL;
  87.         objresize(i);
  88.         objectop(i, DEL, SEL);
  89.         }
  90.         fclose(f);
  91.         msgpost("input done");
  92.         }
  93.     else msgpost("bogus input file");
  94.     }
  95.     else msgpost("input not found");
  96.     }
  97.  
  98. readfile()
  99.     {
  100.     char *fname;
  101.     fname = prompt("input file: ");
  102.     readfileint(fname);
  103.     free(fname);
  104.     }
  105.