home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 210_01 / logonr.c < prev    next >
Encoding:
Text File  |  1985-11-13  |  12.9 KB  |  586 lines

  1. /* LOGONR.C  VERS:- 03.00  DATE:- 09/26/86  TIME:- 09:39:11 PM */
  2. /*
  3. cp b:$1 -e -s0
  4. z80asm $1.bb
  5. slrnk b:$1, b:sys1call/s, b:$1/n/e/*
  6. */
  7. Description: 
  8.  
  9. Logon routine, for ZCPR2 system:
  10.     load SYSIO.IO at iobuf;
  11.     load NAMES.DIR at ndbase;
  12.     display ruler line and prompts for operator logon information;
  13.     fill time and date arrays from Hayes clock;
  14.     display time, date, message, etc on crt;
  15.     timestmp logon information given by the operator;
  16.         append it to the LOG file.
  17.  
  18. Special requirements:
  19.     sysicall.mac/rel = call and return from a program, here used in
  20.         initializing the system through a call to bios.
  21.  
  22. By J.A. Rupley, Tucson, Arizona
  23. Coded for the Eco-C Compiler, version 3.40
  24. */
  25.  
  26.  
  27. #include <stdio.h>
  28.  
  29. #include <ctrlcnst.h>
  30.  
  31. #define BUF_SIZE    80        /* Screen parameters used in typer*/
  32. #define SCREEN_HEIGHT    23
  33.  
  34. char line_buf[BUF_SIZE];        /* Buffer sent to printer or file */
  35.  
  36. char time[] = "hh:mm:ss XM \0";
  37. char date[] = "mm/dd/yy \0";
  38. char day[] = "Wednesday \0";
  39. char month[] = "September \0";
  40. char date_mes[80] = "";
  41. char log_mes[80] = "";
  42.  
  43.  
  44. main()
  45. {
  46.     int fclose(),putc();
  47.     void log_typer(), printf(), fputs(), exit();
  48.     void chrono(), ldsysio(), ldnames(),user_mes();
  49.  
  50.     FILE *fptr, *fopen();        /* Buffered IO file pointer    */
  51.  
  52.  
  53.                 /* Reverse video            */
  54.     INTOREV;
  55. è                /* Load SYSIO.IO at IOBUF
  56.                     End with call to TINIT
  57.                     to initialize new io drivers    */
  58.     ldsysio();
  59.  
  60.  
  61.                 /* Load NAMES.DIR at NDBASE, with
  62.                     appropriate editing of file    */
  63.     ldnames();
  64.  
  65.  
  66.  
  67.                 /* Fill line_buf with one-line entry for
  68.                     logon description.
  69.                     Entry ended by CR, LF, or ^Z.
  70.                     Abort logon process with ^C.    */
  71.     log_typer();            
  72.  
  73.  
  74.  
  75.                 /* Fill time and date arrays        */
  76.     chrono();
  77.  
  78.  
  79.  
  80.                 /* Open the LOG file            */
  81.  
  82.     if ((fptr = fopen("LOG", "a")) == NULL){
  83.         printf("\nSorry, I can\'t open the file.\n");
  84.         exit(ERROR);
  85.     }
  86.  
  87.  
  88.                 /* Append logon header and logon descriptor
  89.                     to LOG file            */
  90.     putc('\n', fptr);
  91.     fputs(log_mes, fptr);
  92.     putc('\n', fptr);
  93.     fputs(line_buf, fptr);
  94.  
  95.  
  96.                     
  97.                 /* Display time and date on crt
  98.                     and display user message    */
  99.     CLEARS;
  100.     INTOREV;
  101.     puts("\n");
  102.     puts(date_mes);
  103.  
  104.     user_mes();
  105.     OUTAREV;
  106.  
  107.  
  108.                 /* Write eof, close file, and exit    */
  109.     putc(CPMEOF,fptr);è    if (fclose(fptr) == ERROR) {
  110.         printf("\n\nerror in closing file\n");
  111.         exit(ERROR);
  112.     }
  113.  
  114.     exit(OK);
  115. }                    /* END OF MAIN            */
  116.  
  117.     /* page eject */
  118.  
  119.  
  120.                     /* Primary typer routine.
  121.                        Create logon string in line_buf.
  122.                        One line of input, terminated by
  123.                         CR, LF or ^Z
  124.                        ^C aborts logon process by
  125.                         jump to wboot.        */
  126. void log_typer(fptr)
  127. {
  128.     void ruler();
  129.     int getchar(), putchar();
  130.     int c;
  131.     int i, j, m, vert;        
  132.                     /* i is the line_buffer subscript
  133.                        m is the screen image cursor positn
  134.                        j is for loop indexing
  135.                        vert is the vertical line counter */
  136.     
  137.     i = m = NULL;            /* Reset character counter    */
  138.     vert = 22;               /* Begin at line >> #1        */
  139.     ruler();
  140.     CURSOR(vert,m);
  141.  
  142.     while ((c = getchar()) != EOF && c != CPMEOF){
  143.                 /* Get characters one at a time        */
  144.  
  145.                 /* Display if displayable        */
  146.         if (c >= SPACE && c <= 126){       /* Displayable?        */
  147.             if (m >= (BUF_SIZE - 1)){    /* End of line?    */
  148.                        putchar(BKSP);    /* Delete last char on crt */
  149.                 putchar(SPACE);
  150.                 putchar(BKSP);
  151.                 continue;
  152.             }
  153.             line_buf[i] = c; /* Put char into buffer    */
  154.             ++m; ++i;    /* And increment pointers    */
  155.         }
  156.  
  157.  
  158.                 /* Perform various ctrl-char operations    */
  159.         elsσ iµ (π =╜ BKSP)√    /¬ Backspacσ            */
  160.             if (i == 0)    /* If beginning of line        */
  161.                 putchar(CTRLL); /* Move right        */
  162.             else{        /* Not beginning of line    */
  163.                 putchar(SPACE);    /* Write a space    */
  164.                 putchar(BKSP); /* Backspace        */
  165.                 --m; --i;    /* Decrement subscript    */
  166.             }
  167.         }
  168.         else if (c == CTRLU){     /* Cancel line_buf contents    */
  169.             m = m - i;    /* Delete line_buf contents on screen*/
  170.             if (m > 0){
  171.                 CURSOR(vert,--m);è                putchar(ESC);    /* Delete line right    */
  172.                 putchar('T');    /* For televideo 920     */
  173.                 putchar(CTRLL);    /* Advance cursor     */
  174.                 m++;        /* And pointer        */
  175.             }
  176.             else{
  177.                 CURSOR(vert, 0);/* Ditto for first colmn*/
  178.                 putchar(ESC);
  179.                 putchar('T');
  180.                 putchar(SPACE);
  181.                 CURSOR(vert, 0);
  182.             }
  183.             i = NULL;    /* Zero line_buf         */
  184.         }
  185.         else if (c == '\n' || c == CR){     /* CRLF        */
  186.             break;
  187.         }
  188.         else if (c == CTRLC)    /* Abort            */
  189.             exit(ERROR);
  190.  
  191.                 /* Adjust cursor if necessary        */
  192.         if (m < 0)
  193.             m = 0;
  194.         else if (m > (BUF_SIZE - 1)){
  195.             m = (BUF_SIZE - 1);
  196.         }
  197.  
  198.         CURSOR(vert, m);
  199.     }
  200.  
  201.                     /* Terminate line and return    */
  202.     if (i > 78) {
  203.         i = 78;
  204.     }
  205.     line_buf[i] = '\n';
  206.     line_buf[++i] = '\0';
  207.  
  208.  
  209. }                    /* END OF TYPER            */
  210.  
  211.  
  212.  
  213. void ruler()                /* Put ruler line at screen top    */
  214. {
  215.     void puts();
  216.     int i;
  217.  
  218.     static char *rul_mes[] = {
  219. "\nPlease type in a login message, of the following form:\n",
  220. "<initials>  <description of what you will do with the computer>\n",
  221. "The message can be only one line.",
  222. "It is terminated by  <return>  or  <line feed>  or  <ctrl-Z>.\n",
  223. "Type  <ctrl-C>  to abort logon process, by a warm boot.\n",
  224. "L----!----!----!----!----!----!----!----!----!----!----!----!----!----!-------R",
  225. NULLè    };
  226.  
  227.     for (i = 0; rul_mes[i] != NULL; i++) {
  228.         puts(rul_mes[i]);
  229.     }
  230.  
  231.     OUTAREV;    
  232. }                    /* END OF RULER            */
  233.  
  234.  
  235.                     /* Display message for user    */
  236. void user_mes()
  237. {
  238.     void puts();
  239.     int i;
  240.     static char *array[] = {
  241. "\n\nYou are now logged into the system:\n\n",
  242. "            drive   A:",
  243. "            user area  0  =  directory START\n\n\n",
  244. "If you need help, please type:\n",
  245. "            MENU\n\n",
  246. "When you are done, please remember to LOGOFF\n\n",
  247. NULL
  248.     };
  249.  
  250.     for (i = 0; array[i] != NULL; i++)
  251.         puts(array[i]);
  252. }                    /* END OF USER_MES        */
  253.  
  254.  
  255.     /* page eject */
  256.  
  257. /*
  258. Load NAMES.DIR file of current directory into memory at NDBASE.
  259.  
  260. NAMES.DIR, created by MKDIR.COM, is a list of 11-character entries:
  261.      <drive letter><user number><filename, padded to 8 char with NULLS><NULL>
  262.  
  263. The area above NDBASE is structured as follows:
  264.     NDBASE+0  =  max number of entries allowed
  265.     NDBASE+1  =  number of entries read into area from NAMES.DIR
  266.     NDBASE+2  =  start of first entry
  267.              each entry is 10 characters (the ending NULL of the
  268.             NAMES.DIR entry is deleted
  269. */
  270.  
  271. ldnames()
  272. {
  273.     FILE *fopen();
  274.     int getc();
  275.     void printf(), exit();
  276.  
  277.     int char_max, num_max;
  278.     char *px, *py;
  279.     register FILE *fptr;
  280.     register int c, j, k;
  281.  
  282.  
  283.                 /* Setup for read of NAMES.DIR        */
  284.     fptr = fopen("NAMES.DIR", "r");
  285.     if (fptr == NULL) {
  286.         printf("\n\ncannot open file NAMES.DIR-- sorry\n\n");
  287.         exit(ERROR);
  288.     }
  289.  
  290.                 /* Setup locations filled with NAMES.DIR*/
  291.     px = NDBASE;
  292.     py = px + 2;            /* Start of name entries     */
  293.     num_max = *px;            /* Max number names allowed    */
  294.     char_max = num_max * 11;
  295.  
  296.                 /* Loop to read from NAMES.DIR and store
  297.                     above NDBASE.  Because of differences
  298.                     in the structure of the entries in
  299.                     memory and the file, editing is
  300.                     carried out.            */
  301.                     /* Increment address py with j    */
  302.     for (j = 0; j < char_max; j++, py++) {
  303.                     /* k = ordinal of char in entry    */
  304.         k = j % 11;
  305.                     /* Read byte from NAMES.DIR    */
  306.         if ((c = getc(fptr)) == ERROR) {
  307.             printf("\n\nerror in reading file\n\n");
  308.             exit(ERROR);
  309.         }è                    /* Exit on eof            */
  310.         if (c == EOF || c == CPMEOF)
  311.             break;
  312.                     /* Editing of NAMES.DIR input    */
  313.                     /* Pad with spaces, not nulls    */
  314.         else if (k > 2 && c == NULL)
  315.             c = SPACE;
  316.                     /* Convert drive letter to number*/
  317.         else if (k == NULL)
  318.             c = c - 'A';   
  319.                     /* Exit if no filename        */
  320.         else if (k == 2 && c == NULL) {
  321.             break;
  322.         }
  323.                     /* Put edited character in memory*/
  324.                     /* Pass over 11th character    */
  325.         if (k == 10)
  326.             py--;
  327.         else
  328.             *py = c;
  329.     }
  330.                     /* Set NDBASE+1 at number of
  331.                         names read = number of char
  332.                         less (k = 2) for exit test
  333.                         over char per entry    */
  334.                         
  335.     *(px+1) = (j - 2) / 11;
  336.  
  337.  
  338.                 /* Print completion message        */
  339.     printf("\1load of NAMES.DIR completed:\n");
  340.     printf("        %d entries read of %d entries allowed\n", *(px+1), *px);
  341.  
  342.                 /* Close file and exit            */
  343.     if (fclose(fptr) == ERROR) {
  344.         printf("\n\nerror in closing file\n\n");
  345.         exit(ERROR);
  346.     }
  347.  
  348. }                /* END OF LDNAMES            */
  349.  
  350.  
  351.     /* page eject */
  352.  
  353. /* 
  354. Load SYSIO.IO from current directory into memory at IOBASE.
  355. */
  356.  
  357.  
  358. ldsysio()
  359. {
  360.     int read(), close(), open();
  361.     void printf(), exit();
  362.     in⌠ x, count, fdes;
  363.     int *px, *py;
  364.     char *io_buffer, *tinit;
  365.     
  366.                 /* Extract address of IOBASE
  367.                     mix pointers to integers and integers
  368.                     to carry out proper arithmetic    */
  369.     px = 1;                /* WBOOT address at mem loc 1    */    
  370.     x = *px;            
  371.     py  = x -3 +IOBASE_PNTR;    /* Offset from start of BIOS    */
  372.     io_buffer = *py;        /* Extract IOBASE        */
  373.     x = io_buffer;            /* Offset to obtain TINIT    */
  374.     tinit = x + 9;
  375.  
  376.  
  377.                 /* Open SYSIO.IO            */    
  378.     if ((fdes = open("SYSIO.IO", 0)) == ERROR) {
  379.         printf("\n\ncould not open SYSIO.IO-- sorry\n\n");
  380.         exit(ERROR);
  381.     }
  382.  
  383.                 /* Read SYSIO.IO.  Set count at more bytes
  384.                     than in file, 
  385.                         letting eof stop read    */
  386.     count = 0x1000;
  387.     count = read(fdes, io_buffer, count);
  388.  
  389.  
  390.                 /* Print completion message        */
  391.     printf("load of SYSIO.IO completed:\n");
  392.     printf("        %x bytes read at IOBASE = %x\n", count, io_buffer);
  393.  
  394.                 /* Close file                 */
  395.     if(close(fdes) == ERROR) {
  396.         printf("\n\nerror in closing file\n\n");
  397.         exit(ERROR);
  398.     }
  399.  
  400.  
  401.                 /* Initialize SYSIO devices by call
  402.                     to TINIT = IOBASE + 9        */
  403.     sys1call(tinit);
  404.  
  405. è}                /* END OF LDSYSIO            */
  406.  
  407.     /* page eject */
  408.  
  409. /* 
  410. Read Hayes Chronograph, as device PUN:/RDR:.
  411. Return strings for time, date, day of week, month, and displayable 
  412.     summary of these data.
  413. Also, construct a logon header message (see arrays declared as external).
  414. */
  415.  
  416.                 /* Fill time and date strings        */
  417. void chrono()
  418. {
  419.     void set_time(), date_set(), day_set(), set_month();
  420.     void mes_set(), set_log();
  421.  
  422.     set_time();
  423.  
  424.     date_set();
  425.  
  426.     day_set();
  427.  
  428.     set_month();
  429.  
  430.     mes_set();
  431.  
  432.     set_log();
  433.  
  434.  
  435. }                /* END OF CHRONO                */
  436.  
  437.  
  438.                 /* Fill time string            */
  439. void set_time()
  440. {
  441.     void hayes_chrono();
  442.     char clock_in[12];
  443.     int i,j;
  444.  
  445.     hayes_chrono("RT\r", clock_in);
  446.                     /* Clock_in gives hhmmss x    */
  447.                     /* Convert to     hh:mm:ss: xm    */
  448.     for (j = 0, i = 0; clock_in[i] != NULL; j++, i++){
  449.         if (i == 2 || i == 4 || i == 6) j++;
  450.         time[j] = clock_in[i];
  451.     }
  452. }                /*END OF SET_TIME            */
  453.  
  454.  
  455.                 /* Fill date string            */
  456. void date_set()
  457. {
  458.     void hayes_chrono(), swap();
  459.     char clock_in[12];
  460.     int i,j;
  461. è    hayes_chrono("RD\r", clock_in);
  462.                      /* Clock_in gives yymmdd    */
  463.                     /* Convert to     mm/dd/yy    */
  464.     for (j = 6, i = 0; clock_in[i] != NULL; j++, i++){
  465.         if (j == 8) j = 0;
  466.         if (i == 4) j++;
  467.         date[j] = clock_in[i];
  468.     }
  469.  
  470. }                /*END OF DATE_SET            */
  471.  
  472.  
  473.                 /* Fill day string            */
  474. void day_set()
  475. {
  476.     int atoi();
  477.     char *strcpy();
  478.     void hayes_chrono();
  479.                     /* Clock_in gives  d = acsii #    */
  480.                     /* Convert to int ptr to string    */
  481.                     /* Monday is  d = '0'        */
  482.     char clock_in[12];
  483.     int i;
  484.     static char *weekday[]={
  485.         "Monday",
  486.         "Tuesday",
  487.         "Wednesday",
  488.         "Thursday",
  489.         "Friday",
  490.         "Saturday",
  491.         "Sunday",
  492.         "Illegal"
  493.     };
  494.  
  495.     hayes_chrono("RW\r", clock_in);
  496.     i = atoi(clock_in);
  497.     if (i < 0 || i > 6) i = 7;
  498.     strcpy(day, weekday[i]);
  499. }                /*END OF DAY_SET            */
  500.  
  501.  
  502.                 /* Fill month string            */
  503. void set_month()
  504. {
  505.     char *strcpy(), *strncpy();
  506.     int atoi();
  507.     char c[3];
  508.     int i;
  509.     static char *year_month[]={
  510.         "Illegal",
  511.         "January",
  512.         "February",
  513.         "March",
  514.         "April",
  515.         "May",è        "June",
  516.         "July",
  517.         "August",
  518.         "September",
  519.         "October",
  520.         "November",
  521.         "December",
  522.     };
  523.  
  524.     strncpy(c, date, 2);
  525.     i = atoi(c);
  526.     if (i < 1 || i > 12) i = 0;
  527.     strcpy(month, year_month[i]);
  528. }                /*END OF SET_MONTH            */
  529.  
  530.  
  531.                 /* Fill message string            */
  532. void mes_set()
  533. {
  534.     char *strcat(), *strcpy(), *strncat();
  535.  
  536.     strcpy(date_mes, time);
  537.     strcat(date_mes, "  on ");
  538.     strcat(date_mes, day);
  539.     strcat(date_mes, " ");
  540.     strcat(date_mes, month);
  541.     strcat(date_mes, " ");
  542.     strncat(date_mes, &date[3], 2);
  543.     strcat(date_mes, ", 19");
  544.     strncat(date_mes, &date[6], 2);
  545. }                /*END OF SET_MES            */
  546.  
  547.  
  548.                 /* Fill logon string            */
  549. void set_log()
  550. {
  551.  
  552.  
  553.  
  554.     char *strcat(), *strcpy();
  555.  
  556.     strcpy(log_mes, "LOGON     DATE:- ");
  557.     strcat(log_mes, date);
  558.     strcat(log_mes, "  TIME:- ");
  559.     strcat(log_mes, time);
  560. }                /*END OF SET_LOG            */
  561.  
  562.  
  563.                 /* Send command to clock 
  564.                     and return with string        */
  565. void hayes_chrono(command, buffer)
  566. char *command, *buffer;
  567. {
  568.     char *strcpy(), *strcat();
  569.     int bios();è    char temp[12];
  570.     int i;
  571.     strcpy(temp,"AT");
  572.     strcat(temp,command);        /* Form command            */
  573.  
  574.     for (i = 0; temp[i] != NULL; i++)
  575.         bios(PUNCH, temp[i]);    /* Use direct bios call        */
  576.  
  577.     for (i = 0; i <= 11; i++){
  578.         temp[i] = bios(READER, 0);
  579.         if (temp[i] == CR) break;
  580.     }
  581.     temp[i] = '\0';
  582.  
  583.     strcpy(buffer, temp);
  584. }                /* END OF HAYES_CHRONO            */
  585.  
  586.