home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 06user / tstreply.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.7 KB  |  86 lines

  1. /*
  2.  *    tstreply -- test the getreply function
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <local\std.h>
  8. #include <local\video.h>
  9. #include "linebuf.h"
  10.  
  11. #define INPUT_ROW    0
  12. #define INPUT_COL    40
  13. #define WIDTH        40
  14.  
  15. int Apage = 0;
  16. BOOLEAN Silent = FALSE;
  17.  
  18. main(argc, argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.     unsigned int r, c, ch, attr, revattr;
  23.     char reply[MAXPATH + 1];
  24.     LINEBUF buf;
  25.  
  26.     extern char *getreply(short, short, short,
  27.         char *, LINEBUF *, short, short, short);
  28.  
  29.     /* process command line */
  30.     if (argc == 2 && strcmp(argv[1], "-s") == 0)
  31.         Silent = TRUE;
  32.     else if (argc > 2) {
  33.         fprintf(stderr, "Usage: tstreply [-s]\n");
  34.         exit(1);
  35.     }
  36.  
  37.     /* initial setup */
  38.     getstate();
  39.     readca(&ch, &attr, Apage);
  40.     revattr = ((attr << 4) | (attr >> 4)) & 0x77;
  41.     clrscrn(attr);
  42.     putcur(0, 0, Apage);
  43.     writestr("TSTREPLY", Apage);
  44.     putcur(1, 0, Apage);
  45.     writec(HLINE, Maxcol[Vmode] - 1, Apage);
  46.     buf.l_buf = reply;
  47.     buf.l_next = buf.l_prev = (LINEBUF *)NULL;
  48.  
  49.     /* demo getreply() */
  50.     
  51.     if (getreply(INPUT_ROW, INPUT_COL, WIDTH, "File: ", &buf,
  52.         MAXPATH, revattr, 0) == NULL) {
  53.         putcur(INPUT_ROW, INPUT_COL, Apage);
  54.         writeca(' ', attr, WIDTH, Apage);
  55.         putcur(2, 0, Apage);
  56.         fprintf(stderr, "input aborted\n");
  57.         exit(1);
  58.     }
  59.     putcur(INPUT_ROW, INPUT_COL, Apage);
  60.     writeca(' ', attr, WIDTH, Apage);
  61.     putcur(2, 0, Apage);
  62.     fprintf(stderr, "reply = %s\n", reply);
  63.     exit(0);
  64. }
  65.  
  66. #define MSG_ROW    24
  67. #define MSG_COL    0
  68.  
  69. int
  70. errmsg(mesg)
  71. char *mesg;
  72. {
  73.     int n;
  74.     extern void sound(unsigned int, float);
  75.  
  76.     putcur(MSG_ROW, MSG_COL, Apage);
  77.     if ((n = strlen(mesg)) > 0) {
  78.         writestr(mesg, Apage);
  79.         if (Silent == FALSE)
  80.             sound(100, 0.2);
  81.     }
  82.     else
  83.         writec(' ', Maxcol[Vmode] - 1 - MSG_COL, Apage);
  84.     return (n);
  85. }
  86.