home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / install / windows.c < prev    next >
C/C++ Source or Header  |  1997-10-09  |  969b  |  53 lines

  1. #include <errno.h>
  2. #include <newt.h>
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #include "windows.h"
  9.  
  10. void errorWindow(char * str) {
  11.     char * a;
  12.  
  13.     a = alloca(strlen(str) + 5);
  14.     strcpy(a, str);
  15.     strcat(a, ": %s");
  16.  
  17.     newtWinMessage("Error", "Ok", str, strerror(errno));
  18. }
  19.  
  20. void winStatus(int width, int height, char * title,
  21.         char * text, ...) {
  22.     newtComponent t, f;
  23.     char * buf = NULL;
  24.     int size = 0;
  25.     int i = 0;
  26.     va_list args;
  27.  
  28.     va_start(args, text);
  29.  
  30.     do {
  31.     size += 1000;
  32.     if (buf) free(buf);
  33.     buf = malloc(size);
  34.     i = vsnprintf(buf, size, text, args);
  35.     } while (i == size);
  36.  
  37.     va_end(args);
  38.  
  39.     newtCenteredWindow(width, height, title);
  40.  
  41.     t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
  42.     newtTextboxSetText(t, buf);
  43.     f = newtForm(NULL, NULL, 0);
  44.  
  45.     free(buf);
  46.  
  47.     newtFormAddComponent(f, t);
  48.  
  49.     newtDrawForm(f);
  50.     newtRefresh();
  51.     newtFormDestroy(f);
  52. }
  53.