home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / os2prgc.zip / testfile.c < prev    next >
C/C++ Source or Header  |  1995-03-06  |  4KB  |  135 lines

  1. #define INCL_DOS
  2. #define INCL_DOSERRORS
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include "file_io.h"
  6. #include "comm.h"
  7. #include "str.h"
  8.  
  9. void main(void)
  10. {
  11.     INT f;
  12.     unsigned long items[6];
  13.     CHAR inbuff[128], buff[128];
  14.     PSZ p;
  15.     ULONG conXY;
  16.     USHORT conMode;
  17.     ULONG ulAction = 0;
  18.     APIRET rc = 0;
  19.  
  20.     /* sample file I/O stuff */
  21.     if (InitFileIO())
  22.     {
  23.         vidStr("File I/O Test\r\n\nOpening file `TEST.TXT'.\r\n");
  24.  
  25.         f = OpenFile("test.txt", &ulAction, 0, 0,
  26.                      OPEN_ACTION_OPEN_IF_EXISTS,
  27.                      OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  28.                      NULL);
  29.  
  30.         items[0] = f;
  31.         formatStr(buff, "Returned Handle = %u.\r\n", items);
  32.         vidStr(buff);
  33.  
  34.         if (f)
  35.         {
  36.             while(!rc)
  37.             {
  38.                 rc = LineRead(f, inbuff);
  39.                 if ((!rc) || (rc==ERROR_HANDLE_EOF))
  40.                 {
  41.                     p = charinstr(inbuff, '\n');
  42.                     if (p)
  43.                         *p = 0;
  44.  
  45.                     items[0] = (unsigned long)inbuff;
  46.                     formatStr(buff, "%s\r\n", items);
  47.                     vidStr(buff);
  48.                 }
  49.             }
  50.             CloseFile(f);
  51.         }
  52.         else
  53.             vidStr("File open failed.\r\n");
  54.  
  55.         vidStr("\r\nPress any key for file write test...");
  56.         CharFromPort((HFILE)0);
  57.  
  58.         vidStr("\r\n\nOpening `JUNK.TXT' for write.\r\n");
  59.  
  60.         f = OpenFile("junk.txt", &ulAction, 0, 0,
  61.                      OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
  62.                      OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  63.                      NULL);
  64.  
  65.         items[0] = f;
  66.         formatStr(buff, "Returned Handle = %u.\r\n", items);
  67.         vidStr(buff);
  68.  
  69.         if (f)
  70.         {
  71.             items[0] = LineWrite(f, "Line 1\nLine 2\n");
  72.             formatStr(buff, "LineWrite Results: %u, ", items);
  73.             vidStr(buff);
  74.  
  75.             items[0] = LineWrite(f, "Line 3\n");
  76.             formatStr(buff, "%u, ", items);
  77.             vidStr(buff);
  78.  
  79.             items[0] = LineWrite(f, "Line 4 ");
  80.             formatStr(buff, "%u, ", items);
  81.             vidStr(buff);
  82.  
  83.             items[0] = LineWrite(f, "Line 5\n");
  84.             formatStr(buff, "%u.\r\n", items);
  85.             vidStr(buff);
  86.  
  87.             CloseFile(f);
  88.         }
  89.         else
  90.             vidStr("File open/creation failed.\r\n");
  91.  
  92.         CleanUpFileIO();
  93.     }
  94.  
  95.     vidStr("\r\nPress any key for ANSI control and console mode tests...");
  96.     CharFromPort((HFILE)0);
  97.  
  98.     conMode = vidGetConsoleMode();
  99.     vidSetConsoleMode(2);
  100.  
  101.     comClearScreen((HFILE)0);
  102.  
  103.     comSetAttributes((HFILE)0, NULL, "34", "43");
  104.     DisplayBox((HFILE)0, 2, 2, 10, 5, SINGLE_LINE_BOX, TRUE);
  105.     comSetAttributes((HFILE)0, NULL, "32", "43");
  106.     DisplayBox((HFILE)0, 4, 4, 10, 5, DOUBLE_LINE_BOX, FALSE);
  107.     comSetAttributes((HFILE)0, NULL, "33", "41");
  108.     DisplayBox((HFILE)0, 6, 6, 10, 5, DOUBLE_TOP_BOX, TRUE);
  109.     comSetAttributes((HFILE)0, NULL, "31", "45");
  110.     DisplayBox((HFILE)0, 8, 8, 10, 5, DOUBLE_SIDE_BOX, FALSE);
  111.     comSetAttributes((HFILE)0, NULL, "36", "44");
  112.     DisplayBox((HFILE)0, 10, 10, 10, 5, NO_IBMCHAR_BOX, TRUE);
  113.  
  114.     vidStr("Press any key to continue. . .");
  115.     CharFromPort((HFILE)0);
  116.  
  117.     comSetAttributes((HFILE)0, "0", NULL, NULL);
  118.     comGotoXY((HFILE)0, "1", "20");
  119.  
  120.     items[0] = vidGetConsoleMode();
  121.     formatStr(buff, "\r\nCurrent console mode = %u\r\n", items);
  122.     vidStr(buff);
  123.     conXY = vidGetConsoleXY();
  124.  
  125.     items[0] = LOUSHORT(conXY);
  126.     items[1] = HIUSHORT(conXY);
  127.     formatStr(buff, "\r\nRows = %u, Columns = %u\r\n", items);
  128.     vidStr(buff);
  129.  
  130.     vidStr("Press any key to continue. . .");
  131.     CharFromPort((HFILE)0);
  132.  
  133.     vidSetConsoleMode(conMode);
  134. }
  135.