home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol181 / rtmisc.cq / RTMISC.C
Encoding:
C/C++ Source or Header  |  1985-02-10  |  3.9 KB  |  171 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 "B:RT11.H"
  20.  
  21. #include "B:STDIO.H"
  22.  
  23. #include "B:PORTAB.H"
  24.  
  25. #include "B:CTYPE.H"
  26.  
  27. /*
  28. Routine to return the size of a CP/M file.  This allows one to seek the
  29. appropriate size hole on the RT-11 disk.  The size is in 512-byte blocks.
  30. Any size over 501 is impossible as there are not that many blocks on a
  31. disk.  Larger sizes denote file not found.
  32. */
  33.  
  34. filesize(filename)
  35. char *filename;
  36. {
  37.     int size;
  38.     char fcb[36];
  39.     if (SETFCB(fcb,filename) || BDOS(OPEN_FILE,fcb) == 255) return 1000;
  40.     size = fcb[15];
  41.     while (fcb[15] == 0x80)
  42.     {
  43.         ++fcb[12];
  44.         fcb[32] = 0;
  45.         if (BDOS(OPEN_FILE,fcb) == 255) break;
  46.         size += fcb[15];
  47.     }
  48.     return size % 4 ? size / 4 + 1 : size / 4;
  49. }
  50.  
  51. /*
  52. Routine to convert a number from 0 to 12 into a month name.
  53. */
  54.  
  55. getmon(mnum,buffer)
  56. int mnum;
  57. char *buffer;
  58. {
  59.     switch(mnum)
  60.     {
  61.         case  1:        strcpy(buffer,"JAN");    break;
  62.         case  2:        strcpy(buffer,"FEB");    break;
  63.         case  3:        strcpy(buffer,"MAR");    break;
  64.         case  4:        strcpy(buffer,"APR");    break;
  65.         case  5:        strcpy(buffer,"MAY");    break;
  66.         case  6:        strcpy(buffer,"JUN");    break;
  67.         case  7:        strcpy(buffer,"JUL");    break;
  68.         case  8:        strcpy(buffer,"AUG");    break;
  69.         case  9:        strcpy(buffer,"SEP");    break;
  70.         case 10:        strcpy(buffer,"OCT");    break;
  71.         case 11:        strcpy(buffer,"NOV");    break;
  72.         case 12:        strcpy(buffer,"DEC");    break;
  73.         default:        strcpy(buffer,"   ");    break;
  74.     }
  75. }
  76.  
  77. /*
  78. Routine to get a command from the user.
  79. */
  80.  
  81. getcom()
  82. {
  83.     char temp[20];
  84.     puts("\nCommand? ");
  85.     gets(temp);
  86.     return toupper(temp[0]);
  87. }
  88.  
  89. /*
  90. Routine to quiz the user for an RT-11 file name.  He gets prompted with
  91. the string prompt and quizzed until he enters a valid name.  The routine
  92. returns the name in the array of int, and a value of 0 if the name is
  93. null, 1 otherwise.
  94. */
  95.  
  96. get_RT_name(prompt,file_name)
  97. char *prompt;
  98. int *file_name;
  99. {
  100.     puts(prompt);
  101.     while (!getfd(file_name))
  102.     {
  103.         puts("Error -- illegal file name.  Try again. ");
  104.     }
  105.     if (file_name[0] == 0 && file_name[1] == 0 && file_name[2] == 0)
  106.         return 0;
  107.     return 1;
  108. }
  109.  
  110. /*
  111. Routine to convert the name of an RT-11 file from radix 50 into an
  112. ASCII string.  The file name comes over in the int array file_name
  113. and the string goes back in the char array file_string.  Illegal
  114. characters show up as *'s.  The function returns a pointer to the
  115. string.
  116. */
  117.  
  118. sprint_name(file_name,file_string)
  119. char *file_string;
  120. int *file_name;
  121. {
  122.     int i, j;
  123.     unsigned t;
  124.     file_string[10] = '\0';
  125.     file_string[6] = '.';
  126.     for (i = 0; i < 3; i++)
  127.     {
  128.         t = file_name[i];
  129.         for (j = 2; j >= 0; j--)
  130.         {
  131.             file_string[3 * i + j + (i == 2 ? 1 : 0)]
  132.                 = r50toa(t % 050);
  133.             t /= 050;
  134.         }
  135.     }
  136.     return file_string;
  137. }
  138.  
  139. /*
  140. Routine to print the name of an RT-11 file on the console.
  141. All rules as sprint_name apply here.
  142. */
  143.  
  144. print_name(file_name)
  145. int *file_name;
  146. {
  147.     char temp[11];
  148.     printf("%10s",sprint_name(file_name,temp));
  149. }
  150.  
  151. /*
  152. Routine to convert a radix 50 character into an ASCII character.
  153. The routine returns the character * if the rad 50 character is
  154. illegal.
  155. */
  156.  
  157. r50toa(rad50)
  158. char rad50;
  159. {
  160.     switch (rad50)
  161.     {
  162.         case 0:        return ' ';
  163.         case 033:    return '$';
  164.         case 034:    return '.';
  165.     }
  166.     if (rad50-- <= 031) return rad50 + 'A';
  167.     if ((rad50 -= 035) <= 9) return rad50 + '0';
  168.     return '*';
  169. }
  170.  
  171.