home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 108_01 / rtmisc.c < prev    next >
Text File  |  1985-11-14  |  4KB  |  165 lines

  1. /*
  2.     RT-11 Adapter Package for CP/M
  3.  
  4.     Rev. 1.0 -- July 1980
  5.  
  6.     Rev. 1.1 -- March 1981 consisting of adding a valid system date
  7.             word to all files placed on the RT-11 disk and
  8.             putting the volume ID on a disk when the directory
  9.             is initialized.  This will keep RT-11 versions
  10.             later than V02C from choking.
  11.  
  12.     copyright (c) 1980, William C. Colley, III
  13.  
  14. This group of functions implements enough of RT-11 to allow the rest of
  15. the package to work.  The functions are built and named as per the
  16. RT-11 Software Support Manual for version 2C of RT-11.
  17. */
  18.  
  19. #include "RT11.H"
  20.  
  21. /*
  22. Routine to return the size of a CP/M file.  This allows one to seek the
  23. appropriate size hole on the RT-11 disk.  The size is in 512-byte blocks.
  24. Any size over 501 is impossible as there are not that many blocks on a
  25. disk.  Larger sizes denote file not found.
  26. */
  27.  
  28. filesize(filename)
  29. char *filename;
  30. {
  31.     int size;
  32.     char fcb[36];
  33.     if (setfcb(fcb,filename) || bdos(OPEN_FILE,fcb) == 255) return 1000;
  34.     size = fcb[15];
  35.     while (fcb[15] == 0x80)
  36.     {
  37.         ++fcb[12];
  38.         fcb[32] = 0;
  39.         if (bdos(OPEN_FILE,fcb) == 255) break;
  40.         size += fcb[15];
  41.     }
  42.     return size % 4 ? size / 4 + 1 : size / 4;
  43. }
  44.  
  45. /*
  46. Routine to convert a number from 0 to 12 into a month name.
  47. */
  48.  
  49. getmon(mnum,buffer)
  50. int mnum;
  51. char *buffer;
  52. {
  53.     switch(mnum)
  54.     {
  55.         case  1:        strcpy(buffer,"JAN");    break;
  56.         case  2:        strcpy(buffer,"FEB");    break;
  57.         case  3:        strcpy(buffer,"MAR");    break;
  58.         case  4:        strcpy(buffer,"APR");    break;
  59.         case  5:        strcpy(buffer,"MAY");    break;
  60.         case  6:        strcpy(buffer,"JUN");    break;
  61.         case  7:        strcpy(buffer,"JUL");    break;
  62.         case  8:        strcpy(buffer,"AUG");    break;
  63.         case  9:        strcpy(buffer,"SEP");    break;
  64.         case 10:        strcpy(buffer,"OCT");    break;
  65.         case 11:        strcpy(buffer,"NOV");    break;
  66.         case 12:        strcpy(buffer,"DEC");    break;
  67.         default:        strcpy(buffer,"   ");    break;
  68.     }
  69. }
  70.  
  71. /*
  72. Routine to get a command from the user.
  73. */
  74.  
  75. getcom()
  76. {
  77.     char temp[20];
  78.     puts("\nCommand? ");
  79.     gets(temp);
  80.     return toupper(temp[0]);
  81. }
  82.  
  83. /*
  84. Routine to quiz the user for an RT-11 file name.  He gets prompted with
  85. the string prompt and quizzed until he enters a valid name.  The routine
  86. returns the name in the array of int, and a value of 0 if the name is
  87. null, 1 otherwise.
  88. */
  89.  
  90. get_RT_name(prompt,file_name)
  91. char *prompt;
  92. int *file_name;
  93. {
  94.     puts(prompt);
  95.     while (!getfd(file_name))
  96.     {
  97.         puts("Error -- illegal file name.  Try again. ");
  98.     }
  99.     if (file_name[0] == 0 && file_name[1] == 0 && file_name[2] == 0)
  100.         return 0;
  101.     return 1;
  102. }
  103.  
  104. /*
  105. Routine to convert the name of an RT-11 file from radix 50 into an
  106. ASCII string.  The file name comes over in the int array file_name
  107. and the string goes back in the char array file_string.  Illegal
  108. characters show up as *'s.  The function returns a pointer to the
  109. string.
  110. */
  111.  
  112. sprint_name(file_name,file_string)
  113. char *file_string;
  114. int *file_name;
  115. {
  116.     int i, j;
  117.     unsigned t;
  118.     file_string[10] = '\0';
  119.     file_string[6] = '.';
  120.     for (i = 0; i < 3; i++)
  121.     {
  122.         t = file_name[i];
  123.         for (j = 2; j >= 0; j--)
  124.         {
  125.             file_string[3 * i + j + (i == 2 ? 1 : 0)]
  126.                 = r50toa(t % 050);
  127.             t /= 050;
  128.         }
  129.     }
  130.     return file_string;
  131. }
  132.  
  133. /*
  134. Routine to print the name of an RT-11 file on the console.
  135. All rules as sprint_name apply here.
  136. */
  137.  
  138. print_name(file_name)
  139. int *file_name;
  140. {
  141.     char temp[11];
  142.     puts(sprint_name(file_name,temp));
  143. }
  144.  
  145. /*
  146. Routine to convert a radix 50 character into an ASCII character.
  147. The routine returns the character * if the rad 50 character is
  148. illegal.
  149. */
  150.  
  151. r50toa(rad50)
  152. char rad50;
  153. {
  154.     switch (rad50)
  155.     {
  156.         case 0:        return ' ';
  157.         case 033:    return '$';
  158.         case 034:    return '.';
  159.     }
  160.     if (rad50-- <= 031) return rad50 + 'A';
  161.     if ((rad50 -= 035) <= 9) return rad50 + '0';
  162.     return '*';
  163. }
  164.  
  165.