User Tools

Site Tools


cdc:nos2.source:nam5871:xdrstr

XDRSTR

Table Of Contents

  • [00003] PROC XDRSTR (BUFFER, BUFPOS, STRING, STRLEN, OPERATION)
  • [00005] XDRSTR CONVERT BETWEEN DISPLAY AND ASCII IN XDR FORMAT
  • [00063] PROC XDRBYTE
  • [00064] PROC XDRINT

Source Code

XDRSTR.txt
  1. *DECK XDRSTR
  2. USETEXT TEXTXDR
  3. PROC XDRSTR (BUFFER, BUFPOS, STRING, STRLEN, OPERATION);
  4. *CALL COPYRITE CDCNET - COPYRIGHT CONTROL DATA. 1992.
  5. # TITLE XDRSTR CONVERT BETWEEN DISPLAY AND ASCII IN XDR FORMAT #
  6.  
  7. BEGIN # XDRSTR #
  8. #
  9. **** XDRSTR - CONVERT BETWEEN DISPLAY AND ASCII IN XDR FORMAT.
  10. *
  11. * THIS PROCEDURE WILL READ DATA OUT OF *BUFFER*, OR WRITE DATA INTO
  12. * *BUFFER* DEPENDING ON THE *OPERATION* PARAMETER. THE DATA IN
  13. * *BUFFER* IS IN ASCII CHARACTER XDR (EXTERNAL DATA REPRESENTATION)
  14. * FORMAT, PACKED 7.5 CHARACTERS/CYBER WORD. THE FIRST 4 BYTES
  15. * CONTAIN THE STRING LENGTH. IF THE LENGTH IS NOT A MULTIPLE OF
  16. * BYTES, THEN 0 TO 3 BYTES OF ZEROS ARE ADDED TO THE MESSAGE TO MAKE
  17. * THE NUMBER OF BYTES A MULTIPLE OF FOUR. STRING IS A ZERO BYTE
  18. * TERMINATED STRING.
  19. *
  20. * PROC XDRSTR (BUFFER, BUFPOS, STRING, STRLEN, OPERATION)
  21. *
  22. * ENTRY BUFFER = INTEGER ARRAY PACKED 7.5 BYTES/WORD.
  23. * BUFPOS = INDEX OF NEXT BYTE TO BE READ OR WRITTEN.
  24. * STRING = DISPLAY CHARACTER ARRAY.
  25. * OPERATION = EITHER *READ* FROM OR *WRITE* TO *BUFFER*.
  26. *
  27. * EXIT BUFFER = DATA READ OUT OR WRITTEN TO.
  28. * BUFPOS = BYTE POSITION IN *BUFFER* AFTER OPERATION.
  29. * STRING = CHARACTERS READ OUT OR WRITTEN TO.
  30. * STRLEN = NUMBER OF CHARACTERS READ FROM *BUFFER* OR
  31. * WRITTEN TO *BUFFER*.
  32. *
  33. * METHOD IF OPERATION IS *READ*, XDRINT IS CALLED TO DETERMINE THE
  34. * VALUE OF *STRLEN*. *STRLEN* CHARACTERS ARE THEN READ FROM
  35. * FROM *BUFFER*.
  36. * IF THE OPERATION IS *WRITE*, CHARACTERS ARE WRITTEN TO
  37. * *STRING* UNTIL A ZERO BYTE IS ENCOUNTERED. WHEN THE ZERO
  38. * BYTE IS ENCOUNTERED, *STRLEN* IS DETERMINED AND WRITTEN
  39. * TO THE BEGINNING OF THE STRING IN *BUFFER*.
  40. * *BUFPOS* IS UPDATED TO THE NEXT READ/WRITE BYTE POSITION.
  41. * THE ARITHMETIC MODULO BASE 60 FUNCTION IS PERFORMED ON
  42. * *BUFPOS* MULTIPLIED BY EIGHT TO DETERMINE THE BIT
  43. * POSITION WITHIN BUFFER. IF THE POSITION IS 56, THE
  44. * BYTE IS SPLIT ACROSS TWO WORDS. THE CHARACTERS IN
  45. * *BUFFER* ARE 7-BIT ASCII CHARACTERS TERMINATED WITH A
  46. * ZERO BYTE, THE CHARACTERS IN STRING ARE IN DISPLAY CODE.
  47. * IF CONVERTING ASCII TO DISPLAY, THE ASCII INTEGER VALUE
  48. * IS THE OFFSET INTO THE ASCII TO DISPLAY CONVERSION ARRAY.
  49. * IF CONVERTING DISPLAY TO ASCII, THE DISPLAY INTEGER VALUE
  50. * IS USED TO DETERMINE THE WORD AND BIT OFFSET INTO THE
  51. * DISPLAY TO ASCII ARRAY.
  52. * THE CALLER IS RESPONSIBLE FOR MAKING SURE THAT THE
  53. * DESTINATION ARRAY IS LARGE ENOUGH TO HOLD THE NUMBER
  54. * OF VALUES SPECIFIED.
  55. *
  56. #
  57.  
  58. #
  59. **** PROC XDRSTR - XREF LIST
  60. #
  61. XREF
  62. BEGIN
  63. PROC XDRBYTE; # CONVERT BYTE TO XDR DATA #
  64. PROC XDRINT; # CONVERT INTEGER TO XDR DATA #
  65. END
  66.  
  67. #
  68. **
  69. #
  70. DEF CHARNUL$ # 0 #; # NULL CHARACTER #
  71.  
  72. ARRAY BUFFER [0:0] S(1); # ARRAY OF DATA, 7.5 BYTES/WORD #
  73. ITEM BUF$WRD U(00,00,60); # WORD REFERENCE #
  74. ITEM BUFPOS I; # CUR BYTE POSITION IN BUFFER #
  75. ARRAY STRING [0:0] S(240);
  76. ITEM STR$CHAR C(00,00,240); # CHARACTER REFERENCE #
  77. ITEM STRLEN I; # NUMBER OF CHARS TO BE PROCESSD#
  78. ITEM OPERATION S:XDROPER; # OPERATION TO PERFORM ON BUFFER#
  79.  
  80. ITEM ARRAYBIT I; # BIT OFFSET INTO *DACONVER* WRD#
  81. ITEM ARRAYWRD I; # WORD OFFSET INTO *DACONVER* #
  82. ITEM BITPOS I; # BIT POSITION IN BUFFER #
  83. ITEM INDEX I; # NUMBER OF CHARACTERS READ #
  84. ITEM LENPOS I; # STRING LENGTH POSITION IN BUF #
  85. ITEM SRCHAR I; # INPUT SOURCE CHARACTER #
  86. ITEM WORDPOS I; # WORD POSITION IN BUFFER #
  87. ITEM ZEROBYTE I; # NUMBER OF ZERO BYTES TO ADD #
  88.  
  89. #
  90. **** ARRAY THAT DEFINES THE ASCII TO DISPLAY CODE CONVERSION TABLE
  91. #
  92. ARRAY ADCONVER [00:12] S(1);
  93. BEGIN # ASCII TO DISPLAY CONVERSION #
  94. ITEM AD$CHAR C(00,00,127); # CHARACTER REFERENCE #
  95. ITEM AD$WORD U(00,00,60) =
  96. [O"00000000000000000000", # 00,01,02,03,04,05,06,07,08,09 #
  97. O"00000000000000000000", # 0A,0B,0C,0D,0E,0F,10,11,12,13 #
  98. O"00000000000000000000", # 14,15,16,17,18,19,1A,1B,1C,1D #
  99. O"00005566646053636770", # 1E,1F,20,21,22,23,24,25,26,27 #
  100. O"51524745564657503334", # 28,29,2A,2B,2C,2D,2E,2F,30,31 #
  101. O"35363740414243440077", # 32,33,34,35,36,37,38,39,3A,3B #
  102. O"72547371740102030405", # 3C,3D,3E,3F,40,41,42,43,44,45 #
  103. O"06071011121314151617", # 46,47,48,49,4A,4B,4C,4D,4E,4F #
  104. O"20212223242526273031", # 50,51,52,53,54,55,56,57,58,59 #
  105. O"32617562766500010203", # 5A,5B,5C,5D,5E,5F,60,61,62,63 #
  106. O"04050607101112131415", # 64,65,66,67,68,69,6A,6B,6C,6D #
  107. O"16172021222324252627", # 6E,6F,70,71,72,73,74,75,76,77 #
  108. O"30313200000000000000"]; # 78,79,7A,7B,7C,7D,7E,7F #
  109. END
  110. #
  111. **** ARRAYS THAT DEFINES THE DISPLAY TO ASCII CONVERSION
  112. #
  113.  
  114. ARRAY DACONVER [00:12] S(1);
  115. BEGIN # DISPLAY TO ASCII CONVERSION #
  116. ITEM DA$WORD U(00,00,60) =
  117. [X"03A041042043044", # 00,01,02,03,04 : A B C D #
  118. X"045046047048049", # 05,06,07,10,11 E F G H I #
  119. X"04A04B04C04D04E", # 12,13,14,15,16 J K L M N #
  120. X"04F050051052053", # 17,20,21,22,23 O P Q R S #
  121. X"054055056057058", # 24,25,26,27,30 T U V W X #
  122. X"05905A030031032", # 31,32,33,34,35 Y Z 0 1 2 #
  123. X"033034035036037", # 36,37,40,41,42 3 4 5 6 7 #
  124. X"03803902B02D02A", # 43,44,45,46,47 8 9 + - * #
  125. X"02F02802902403D", # 50,51,52,53,54 / ( ) $ = #
  126. X"02002C02E02305B", # 55,56,57,60,61 , . PD [ #
  127. X"05D02502205F021", # 62,63,64,65,66 ] % " _ ! #
  128. X"02602703F03C03E", # 67,70,71,72,73 & ' ? < > #
  129. X"04005C05E03B000"]; # 74,75,76,77 AT \ CF SC #
  130. END
  131. CONTROL EJECT;
  132. #
  133. **** START MAIN PROCEDURE
  134. #
  135.  
  136. SWITCH OPER$:XDROPER OPER$READ:READ,
  137. OPER$WRITE:WRITE;
  138.  
  139. GOTO OPER$ [OPERATION];
  140. BEGIN # OPERATION TYPE #
  141.  
  142. OPER$READ:
  143.  
  144. INDEX = 1; # READ/WRITE ONE INTEGER #
  145. XDRINT (BUFFER, BUFPOS, STRLEN, INDEX, OPERATION);
  146. ZEROBYTE = XDRMODU (STRLEN, 4);
  147. IF ZEROBYTE NQ 0
  148. THEN
  149. BEGIN # ACTUAL NUMBER OF ZERO BYTES #
  150. ZEROBYTE = 4 - ZEROBYTE;
  151. END
  152.  
  153. BITPOS = XDRMODU (BUFPOS * 8, 60);# INITIAL BIT POSITION IN BUF#
  154. WORDPOS = (BUFPOS * 2) / 15; # INITIAL WORD INDEX WITHIN BUF #
  155.  
  156. FOR INDEX = 0 STEP 1 UNTIL (STRLEN - 1)
  157. DO
  158. BEGIN # LOOP THROUGH REQUESTED CHARS #
  159. IF BITPOS EQ 56
  160. THEN
  161. BEGIN # BYTE SPLIT BETWEEN WORDS #
  162. SRCHAR = B<56,4>BUF$WRD [WORDPOS] * 16 +
  163. B<0,4>BUF$WRD [WORDPOS +1];
  164. WORDPOS = WORDPOS + 1;
  165. BITPOS = 4;
  166. END
  167. ELSE
  168. BEGIN # BYTE IN SINGLE CM WORD #
  169. SRCHAR = B<BITPOS,8>BUF$WRD [WORDPOS];
  170. BITPOS = BITPOS + 8;
  171. IF BITPOS GQ 60
  172. THEN
  173. BEGIN
  174. BITPOS = 0;
  175. WORDPOS = WORDPOS + 1;
  176. END
  177. END
  178.  
  179. SRCHAR = SRCHAR LAN X"7F"; # MASK UPPER BIT, ONLY 127 CHARS#
  180. C<INDEX,1>STR$CHAR [0] = C<SRCHAR,1>AD$CHAR [0];
  181. END # LOOP THROUGH REQUESTED CHARS #
  182.  
  183. BUFPOS = BUFPOS + STRLEN + ZEROBYTE;# NEXT READ POSITION #
  184. C<STRLEN,1>STR$CHAR [0] = CHARNUL$;
  185.  
  186. GOTO OPER$END;
  187.  
  188. OPER$WRITE:
  189.  
  190. LENPOS = BUFPOS;
  191. BUFPOS = BUFPOS + 4;
  192. BITPOS = XDRMODU (BUFPOS * 8, 60);# INITIAL BIT POSITION IN BUF#
  193. WORDPOS = (BUFPOS * 2) / 15; # INITIAL WORD INDEX WITHIN BUF #
  194.  
  195. SRCHAR = C<0,1>STR$CHAR [0]; # DISPLAY CHAR TO CONVERT #
  196.  
  197. FOR STRLEN = 1 STEP 1
  198. WHILE SRCHAR NQ CHARNUL$
  199. DO
  200. BEGIN # LOOP THROUGH REQUESTED CHARS #
  201. ARRAYWRD = SRCHAR / 5; # WORD OFFSET IN *DACONVER* #
  202. ARRAYBIT = XDRMODU (SRCHAR * 12, 60) + 4; # BIT OFFSET IN WRD#
  203.  
  204. IF BITPOS EQ 56
  205. THEN
  206. BEGIN # BYTE SPLIT BETWEEN WORDS #
  207. B<56,4>BUF$WRD [WORDPOS] = B<ARRAYBIT,4>DA$WORD [ARRAYWRD];
  208. B<0,4>BUF$WRD [WORDPOS + 1] =
  209. B<ARRAYBIT + 4,4>DA$WORD [ARRAYWRD];
  210. WORDPOS = WORDPOS + 1;
  211. BITPOS = 4;
  212. END
  213. ELSE
  214. BEGIN # BYTE IN SINGLE CM WORD #
  215. B<BITPOS,8>BUF$WRD [WORDPOS] =
  216. B<ARRAYBIT,8>DA$WORD [ARRAYWRD];
  217. BITPOS = BITPOS + 8;
  218. IF BITPOS GQ 60
  219. THEN
  220. BEGIN
  221. BITPOS = 0;
  222. WORDPOS = WORDPOS + 1;
  223. END
  224. END
  225. SRCHAR = C<STRLEN,1>STR$CHAR [0];# DISPLAY CHAR TO CONVERT #
  226. END # LOOP THROUGH REQUESTED CHARS #
  227.  
  228. INDEX = 1;
  229. STRLEN = STRLEN - 1;
  230. XDRINT (BUFFER, LENPOS, STRLEN, INDEX, OPERATION);
  231.  
  232. BUFPOS = BUFPOS + STRLEN; # NEXT BUFFER LOCATION #
  233. ZEROBYTE = XDRMODU (STRLEN, 4);
  234. IF ZEROBYTE NQ 0
  235. THEN
  236. BEGIN # ACTUAL NUMBER OF ZERO BYTES #
  237. ZEROBYTE = 4 - ZEROBYTE;
  238. END
  239. XDRBYTE (BUFFER, BUFPOS, ADCONVER, ZEROBYTE, XDROPER"WRITE");
  240.  
  241. GOTO OPER$END;
  242.  
  243. END # OPERATION TYPE #
  244.  
  245. OPER$END:
  246.  
  247. RETURN; # RETURN TO CALLER #
  248.  
  249. END # XDRSTR #
  250.  
  251. TERM
  252. *WEOR
cdc/nos2.source/nam5871/xdrstr.txt ยท Last modified: 2023/08/05 17:23 by Site Administrator