home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / aterminfo.lha / resize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.3 KB  |  68 lines

  1. ;/* Execute me in order to compile me.
  2. sc resize nostackcheck data=far stringmerge optimize
  3. slink resize.o to resize lib lib:amiga.lib  sc sd nd
  4. quit
  5. */
  6.  
  7. #include <string.h>
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10. #include <clib/alib_stdio_protos.h>
  11.  
  12. /* This program asks the console device for a string which describes the number
  13. of lines and columns available in the current CLI. Then, it sets the local variables
  14. LINES and COLUMNS to those values. */
  15.  
  16. int _main(void) {
  17.  
  18.     int i;
  19.     unsigned char buf[64], *p, *q;
  20.     struct Library *DOSBase;
  21.  
  22.     if (!(DOSBase = OpenLibrary("dos.library\0$VER: resize 37.1 (24.10.93)", 37))) return(30);
  23.  
  24.     SetMode(Input(), 1);
  25.  
  26.     Write(Output(), "\2330 q", 4);
  27.  
  28.     i = Read(Input(), buf, sizeof(buf)-1);
  29.     if (i>=0) buf[i] = 0;
  30.  
  31.     SetMode(Input(), 0);
  32.  
  33.     p = buf;
  34.  
  35.     while(*p && *p != '\233') p++;
  36.  
  37.     if (strlen(p)<9 || p[1] != '1' || p[2] != ';' || p[3] != '1' || p[4] != ';' ) {
  38.         PutStr("Unknown character, exiting\n");
  39.         goto GameOver;
  40.     }
  41.  
  42.     q = (p += 5);
  43.  
  44.     while(*p>='0' && *p<='9' || *p == ' ') p++;
  45.  
  46.     if (*p != ';') {
  47.         PutStr("Unknown character, exiting\n");
  48.         goto GameOver;
  49.     }
  50.  
  51.     SetVar("LINES", q, p-q, 0);
  52.  
  53.     q = ++p;
  54.  
  55.     while(*p>='0' && *p<='9' || *p == ' ') p++;
  56.  
  57.     if (*p != 'r') {
  58.         PutStr("Unknown character, exiting\n");
  59.         goto GameOver;
  60.     }
  61.  
  62.     SetVar("COLUMNS", q, p-q, 0);
  63.  
  64. GameOver:
  65.     CloseLibrary(DOSBase);
  66.     return(0);
  67. }
  68.