home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / util / wnders22 / winders.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  12KB  |  428 lines

  1. /*
  2.  
  3. Written By:    Earl W. Hartsell
  4.  
  5. Date:        8 - 16 - 92
  6.  
  7. Name:        WINDERS
  8.  
  9. Version:        2.2
  10.  
  11. Use:        WINDERS allows the user to choose to automatically run
  12.         Windows or exit to DOS upon startup or reboot.
  13.         It allows the user to specify a length of time to
  14.         countdown before Windows 3.X is loaded.
  15.         Windows may be loaded before the countdown
  16.          is complete by pressing one of the modifier keys
  17.         ([SHIFT], [ALT], or [CTRL]), the user may also
  18.         exit to DOS pressing any other key.
  19.  
  20. The syntax for the command is as follows:
  21.  
  22. d:\<path>\WINDERS [num] [/A <args>] [/B] [/D <d:>] [/I] [/P] [/N <filename>] [/W]
  23. d:\<path>\WINDERS /H
  24. d:\<path>\WINDERS /V
  25. d:\<path>\WINDERS /?
  26.  
  27. d:\<path>\     is drive and directory path where WINDERS executable is
  28.         located.
  29.  
  30. num         is length of pause before loading windows.  It must be
  31.         first argument and may be range of 1 to 32767 in seconds.
  32.         The default pause is 5 seconds.  0 seconds defaults to 5.
  33.  
  34. /A <args>    are the arguments to be passed to windows. The arguments are
  35.         not optional and will generate an error if not found after
  36.         the /a. There also must be a space between the /a and the
  37.         <args> and multiple arguments must be placed inside
  38.         quotes.  If you have problems getting this to work
  39.                 try using full path names on the executables.
  40.  
  41. /B        beep on countdown, default no beep.
  42.  
  43.  
  44. /D <d:>         is to specify drive in where WINDOWS is located.
  45.         The default is C:.
  46.  
  47. /P <path>       If executable file to start WINDOWS is not in \WINDOWS\ use
  48.         this option to specify the path.
  49.         Examples:
  50.  
  51.         \DIR1\DIR2\...\DIRn\WINDOWS\
  52.         \WIN\  If WINDOWS is in a directory called WIN.
  53.  
  54.         NOTE: The final back-slash on the path is required.
  55.  
  56. /N <filename>   Used to specify the name of the file to be executed
  57.         if it is not WIN.COM.
  58.         Example:
  59.            Use /N WINDERS.BAT  if you want to execute a batch file
  60.            before entering windows.
  61.            This would be an easy way to disable a DOS screen saver
  62.            before starting Windows.
  63.            (See WINDERS.BAT)
  64.         Note: If you change the name a new shell will 
  65.         and the batch file will run from that shell which is
  66.         not as efficient memory efficient as running 
  67.         WIN.COM directly.
  68.  
  69. /I         suppress loading Windows into screen. Default show intro screen.
  70.  
  71. /H or /?    help screen.
  72.  
  73. /V        prints out version information.
  74.  
  75. /W        supress display of WINDERS countdown banner.
  76.  
  77.  
  78. Copyright (c)1992 By Earl W. Hartsell
  79. This is a Freeware program.
  80.  
  81. Windows is a registered trademark of Microsoft Corporation.
  82.  
  83. */
  84.  
  85.  
  86. #include "winders.h"
  87.  
  88. struct text_info ti;
  89.  
  90. int main(argc, argv)
  91. int argc;
  92. char *argv[];
  93. {
  94.   int  i = 0, k = 0, j = 0;             /* counters */
  95.   int  pause = 5;                /* default pause */
  96.  
  97.   char w_banner = 1;                    /* print banner flag */
  98.   char beep = 0;                /* set default beep off */
  99.   char buffer[100];                 /* buffer for sprintf */
  100.   char show_intro = 1;            /* turn intro screen off */
  101.   char name_changed = 0;
  102.  
  103.   char drive[3], path[256], name[16], args[256];
  104.  
  105.   time_t start, new;            /* long int */
  106.  
  107.  
  108.   fflush(stdin);             /* clear the kbd buffer */
  109.  
  110.   NIL(args);                            /* clear out arguments to WINDOWS */
  111.  
  112.   strcpy(drive,"C:");             /* default drive C: */
  113.   strcpy(path,"\\WINDOWS\\");           /* default directory */
  114.   strcpy(name,"WIN.COM");               /* default executable */
  115.  
  116.   if (atoi(argv[1]) > 0)          /* take first argument as number */
  117.   {
  118.     j = 2; 
  119.     pause = atoi(argv[1]);
  120.   }
  121.   else
  122.   {
  123.    j = 1;
  124.     pause = 5;                     /* set default pause to 5 seconds. */
  125.   }
  126.   for (; j < argc; j++)
  127.   {
  128.     switch (argv[j][1])
  129.     { 
  130.  
  131.      /* arguments */
  132.       case 'a': case 'A':
  133.     if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  134.     {
  135.       argerror(argv[0], "A" , 0);
  136.       /* Error no argument found */
  137.     }
  138.     else
  139.     {
  140.       strcpy(args, argv[++j]); /* pass arguments */
  141.     }
  142.       break;
  143.       /* arguments */
  144.  
  145.       /* beep */
  146.       case 'b': case 'B':
  147.     beep = 1;  /* set beep on */
  148.       break;
  149.       /* beep */
  150.  
  151.       /* drive */
  152.       case 'd': case 'D':
  153.     if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  154.     {
  155.       argerror(argv[0], "D" , 0);
  156.       /* error no argument found */
  157.     }
  158.     else
  159.     {
  160.       strcpy(drive, argv[++j]); /* pass arguments */
  161.     }
  162.       break;
  163.       /* drive */
  164.  
  165.       /* help screen */
  166.       case 'h': case 'H': case '?':
  167.     highvideo();
  168.     printf("\n");
  169.     center("WINDERS HELP  VERSION 2.2\r\n\r\n");
  170.     lowvideo();
  171.     center("Copyright (c)1992 By Earl W. Hartsell\r\n");
  172.     center("This is a Freeware program.\r\n");
  173.     printf("%s [num] [/A <args>] [/B] [/D <d:>] [/P <path>] [/N] [/I] [/W]\n",argv[0]);
  174.     printf("%s /V or /H or /?\n",argv[0]);
  175.     printf("num is duration of countdown, default is 5 seconds.\n");
  176.     printf("Num must be the first argument to WINDERS.\n");
  177.     printf("/A  is the argument(s) to be passed to Windows.\n");
  178.     printf("/B  causes beeping during countdown.\n");
  179.     printf("/D  drive where windows is located, C: is the default.\n");
  180.     printf("/P  path to Windows, default \\WINDOWS\\ \n");
  181.     printf("/N  used to specify the filename of Windows executable, default WIN.COM\n");
  182.     printf("/I  suppresses showing Windows intro screen.\n");
  183.     printf("/H  or /? to print out this screen.\n");
  184.     printf("/V  display WINDERS version and copyright information.\n");
  185.     printf("/W  used to turn off WINDERS countdown banner.\n");
  186.     printf("Pressing [SHIFT], or [ALT], or [CTRL] during the countdown\n");
  187.     printf("will cause Windows to load without continuing the countdown.\n");
  188.     printf("Pressing any other key will cause WINDERS to exit to DOS.\n");
  189.     printf("\n");
  190.     printf("Windows is a registered trademark of Microsoft Corporation.\n");
  191.     exit(HLP);
  192.       break;
  193.       /* help screen */
  194.  
  195.       /* intro screen */
  196.       case 'i': case 'I':
  197.     show_intro = 0;  /* turn on intro screen */
  198.       break;
  199.       /* intro screen */
  200.  
  201.       /* path */
  202.       case 'p' : case 'P':
  203.     if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  204.     {
  205.       argerror(argv[0], "P", 0);
  206.       /* Error no argument found */
  207.     }
  208.     else
  209.     {
  210.       strcpy(path, argv[++j]); /* pass arguments */
  211.     }
  212.       break;
  213.  
  214.       /* name */
  215.       case 'n': case 'N':
  216.     if ( argv[j+1] == NULL || argv[j+1][0] == '/' )
  217.     {
  218.       argerror(argv[0], "N", 0);
  219.       /* error no argument found to pass to windows */
  220.     }
  221.     else
  222.     {
  223.           name_changed = 1;
  224.       strcpy(name, argv[++j]); /* pass arguments */
  225.     }
  226.       break;
  227.  
  228.       /* version screen */
  229.       case 'v': case 'V':
  230.         clrscr();
  231.         fprintf(stderr,"\n");
  232.     highvideo();
  233.     center("WINDERS VERSION 2.2\r\n");
  234.     lowvideo();
  235.     center("Copyright (c) 1992 By Earl W. Hartsell\r\n");
  236.     center("This is a Freeware program.\r\n");
  237.     printf("\n");
  238.     printf("\n");
  239.     center("Windows is a registered trademark of Microsoft Corporation.\r\n");
  240.     exit(VER);
  241.       break;
  242.       /* version screen */
  243.  
  244.       /* WINDERS banner */
  245.       case 'w': case 'W':
  246.     w_banner = 0; /* don't print WINDERS countdown banner */
  247.       break;
  248.       /* WINDERS banner */
  249.  
  250.       /* ERROR in arguments */
  251.       default:
  252.     fprintf(stderr,"\n%s: Error: Unrecognized Switch %s Will Be Ignored.",argv[0],argv[j]);
  253.     DELAY_SECONDS(2);
  254.       break;
  255.       /* ERROR in arguments */
  256.     }
  257.   }
  258.  
  259.   k = keyhit();     /* check and see if key has already been selected */
  260.  
  261.   if (k == 1) Winf(drive,path,name,args,show_intro, name_changed);
  262.   if (k == 2) Dosf();     /* exit to dos if key is pressed */
  263.  
  264.   clrscr(); /* clear screen */
  265.   if (w_banner)
  266.   {
  267.   highvideo();
  268.   textattr(WHITE + (BLUE << 4));
  269.   center("╔═══════════════════════════╗");
  270.   cprintf("\r\n");
  271.   center("║      Winders Countdown    ║");
  272.   textattr(DARKGRAY);
  273.   cprintf("░\r\n");
  274.   textattr(WHITE + (BLUE << 4));
  275.   center("╚═══════════════════════════╝");
  276.   textattr(DARKGRAY);
  277.   cprintf("░\r\n");
  278.   printf("\t\t\t   ");
  279.   textattr(DARKGRAY);
  280.   cprintf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░\r\n");
  281.   cprintf("\r\n");
  282.   lowvideo();
  283.   }
  284.   textattr(LIGHTGRAY);
  285.   sprintf(buffer, "Loading Windows in %d seconds.\r\n",pause);
  286.   center(buffer);
  287.   center("Press [SHIFT], or [ALT], or [CTRL] to load Windows now.\r\n");
  288.   center("Press any other key to exit to DOS.\r\n");
  289.   center("Counting");
  290.   start = time(NULL); /* get initial time in seconds */
  291.   for (i=1 ;(i <= pause && !k);i++)
  292.   {
  293.     new = time(NULL);         /* get new time */
  294.     while(new - start == 0)     /* start time = new time second not elapsed */
  295.     {
  296.       new = time(NULL);     /* get new time again */
  297.       k = keyhit();  if (k) break;
  298.     }
  299.     if (k == 1) Winf(drive,path,name,args,show_intro, name_changed);
  300.     if (k == 2) Dosf();     /* exit to dos if key is pressed */
  301.     if (new - start != 0)
  302.     {
  303.       if (beep)
  304.     printf("\a.");
  305.       else
  306.     printf(".");
  307.     }
  308.     start = new;
  309.   }
  310.   Winf(drive, path, name, args, show_intro, name_changed);
  311.   return (0); /* keeping the compiler happy */
  312. }
  313.  
  314.  
  315. /* 
  316.     keyhit- function returns 0,1, or 2 depending on the key pressed
  317.     0 - if no key has been pressed
  318.     1 - if SHIFT, CTRL, or ALT has been pressed
  319.     2 - if a key other than the ones above has been pressed
  320. */
  321. int keyhit(void)
  322. {
  323.   int modifiers;
  324.  
  325.   modifiers = bioskey(2);
  326.   if (modifiers)
  327.   {
  328.     if (modifiers & RIGHT) return(1);
  329.     if (modifiers & LEFT)  return(1);
  330.     if (modifiers & CTRL)  return(1);
  331.     if (modifiers & ALT)   return(1);
  332.   }
  333.   if (bioskey(1)) return(2);
  334.   return(0);
  335. }
  336.  
  337.  
  338. /* Dosf - return to DOS and clear screen */
  339.  
  340. void Dosf()
  341. {
  342.     fflush(stdout);
  343.     clrscr();
  344.     exit(DOS);
  345. }
  346.  
  347.  
  348. /* Winf - execute win.com and pass arguments to it.
  349.  
  350.    args - argumentents to be passed to windows
  351.  
  352.    drive - drive where Windows resides.
  353.  
  354.    path -  directory path where windows resides.
  355.  
  356.    name -  filename of executable that will run Windows.
  357.  
  358.    intro - 0 will by pass Windows intro using command win :
  359.        1 (default) Will show intro screen
  360.  
  361.    changed - 0 name of executable has not been changed.
  362.          1 name has changed.
  363.  
  364.    Note: execl was used in the hope that the progam would be
  365.          cleared from memory and not take up any space in Windows.
  366. */
  367.  
  368. void Winf(drive, path, name, args, intro, changed)
  369. char *drive, *path, *name, *args;
  370. char intro, changed;
  371. {
  372.   highvideo();
  373.   center("Loading Windows...\r\n");
  374.   lowvideo();
  375.  
  376.   strcat(drive,path);
  377.   strcat(drive,name);
  378.  
  379.   if (changed)
  380.   {
  381.     if(!(intro))
  382.       strcat(drive," :");
  383.     system(drive);
  384.     if (errno)
  385.     {
  386.       printf("%s",sys_errlist[errno]);
  387.     }
  388.     exit(errno);
  389.    }
  390.   else
  391.   {
  392.     if (intro) /* to show into or not to show intro */
  393.       execl(drive, name, args, NULL); /* to show */
  394.     else
  395.       execl(drive, name, ":", args, NULL);  /* not to show */
  396.   }
  397.   printf("%s",sys_errlist[errno]);
  398.   exit(errno);
  399. }
  400.  
  401. int argerror(argv, option, Dlay)
  402. char *argv;
  403. char option[5];
  404. int Dlay;
  405. {
  406.   if (Dlay == 0)
  407.     Dlay = 2;
  408.   fprintf(stderr,"\n%s: Error: Argument Missing Option /%s Ignored, Default Will Be Used.\n",argv,option);
  409.   DELAY_SECONDS(Dlay);
  410.   return(0);
  411. }
  412.  
  413. /* center text on screen using CPRINTF */
  414. /* input string of characters to be centered */
  415.  
  416. int center (string)
  417. char *string;
  418. {
  419.   int length, posx = 0;
  420.  
  421.   gettextinfo(&ti);
  422.   length = strlen(string);
  423.   if (length > ti.screenwidth) return(-1);
  424.   posx = (ti.screenwidth /2) - (length /2);
  425.   gotoxy(posx,wherey());
  426.   cprintf("%s", string);
  427.   return(0);
  428. }