SCRN2NDX.MOD 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. IMPLEMENTATION MODULE Scrn2Ndx;
  2. (*
  3. * REPERTOIRE
  4. * Release 1.6
  5. * By Charles Bradford and Cole Brecheen
  6. * (c) Copyright 1985-1992 PMI
  7. * Green Bay, Wisconsin
  8. * All rights reserved
  9. * (414) 468-6040
  10. *
  11. * $Header: D:/logfiles/mods/scrn2ndx.mov 1.5 10 Mar 1991 15:32:02 coleb $
  12. *
  13. *)
  14. IMPORT ControlUtils;
  15. IMPORT GenLists;
  16. IMPORT LowLevel;
  17. IMPORT M2Strings;
  18. IMPORT NdxBones;
  19. IMPORT NdxFiles;
  20. IMPORT NdxTypes;
  21. IMPORT ScrnTypes;
  22. IMPORT ScrnUtl1;
  23. IMPORT StrEdit;
  24. IMPORT SYSTEM;
  25. VAR
  26. Initialized : BOOLEAN;
  27. PROCEDURE Init();
  28. BEGIN
  29. IF Initialized THEN
  30. RETURN;
  31. ELSE
  32. Initialized := TRUE;
  33. END;
  34. ControlUtils.Init();
  35. GenLists.Init();
  36. LowLevel.Init();
  37. M2Strings.Init();
  38. NdxBones.Init();
  39. NdxFiles.Init();
  40. NdxTypes.Init();
  41. ScrnTypes.Init();
  42. ScrnUtl1.Init();
  43. StrEdit.Init();
  44. END Init;
  45. PROCEDURE PutScrRec( VAR NdxFile: NdxTypes.NdxFileType; VAR
  46. TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR;
  47. KeyField: ARRAY OF CHAR): BOOLEAN;
  48. (* Puts current screen data in out as a record. If RecName is
  49. not null, it contains the record name to use. If RecName is
  50. null, KeyField contains the name of the field on the screen
  51. to use as the Record Name. RecName will always return the
  52. record name used. *)
  53. VAR
  54. FoundAny: BOOLEAN;
  55. FileStr: ARRAY [0..255] OF CHAR;
  56. TmpList, TmpList2: GenLists.GenList;
  57. FieldCount: CARDINAL;
  58. FieldRec: ScrnTypes.InputFieldRecord;
  59. ImageRec: ScrnTypes.ImageElement;
  60. BEGIN
  61. FoundAny := FALSE;
  62. IF M2Strings.Length( RecName) = 0 THEN
  63. (* read record name from field named in KeyField *)
  64. ControlUtils.ReadInput( TheFrame, RecName, KeyField);
  65. END;
  66. StrEdit.CrunchBlanks( RecName );
  67. FieldCount := 1;
  68. REPEAT
  69. (* flip through the named fields on screen and put
  70. their values in the record if they are in the
  71. structure *)
  72. ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec );
  73. ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec );
  74. IF M2Strings.Length( FieldRec.fnam) # 0 THEN
  75. (* for each named field *)
  76. IF FieldRec.typ # ScrnTypes.GroupMember THEN
  77. (* for any field except a group *)
  78. IF FieldRec.typ = ScrnTypes.EditorCode THEN
  79. (*We store editor fields as sublists.*)
  80. IF ScrnUtl1.ListFromEdField( TheFrame, FieldCount, TmpList ) THEN
  81. GenLists.CopyList( TmpList, TmpList2 );
  82. FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam,
  83. GenLists.ListCode, TmpList2) OR FoundAny;
  84. END;
  85. ELSE
  86. StrEdit.CutTrailingChars( ' ', ImageRec.text );
  87. FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam,
  88. GenLists.StrCode, ImageRec.text ) OR FoundAny;
  89. END;
  90. ELSIF FieldRec.selected THEN
  91. (* for selected members of a group put a ONE *)
  92. FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam,
  93. GenLists.StrCode, '1') OR FoundAny;
  94. ELSE
  95. (* for non-selected members of a group put a NULL *)
  96. FoundAny := NdxFiles.PutField( NdxFile, RecName, FieldRec.fnam,
  97. GenLists.StrCode, '') OR FoundAny;
  98. END;
  99. END;
  100. INC( FieldCount );
  101. UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame );
  102. RETURN FoundAny;
  103. END PutScrRec;
  104. PROCEDURE FillScr( VAR NdxFile: NdxTypes.NdxFileType; VAR
  105. TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR;
  106. KeyField: ARRAY OF CHAR): BOOLEAN;
  107. (* Fills the current screen with the data from the record named
  108. in RecName if RecName is not null. If RecName is null, KeyField
  109. contains the name of the field on the screen to use as the
  110. Record Name. RecName will always return the record name used.*)
  111. VAR
  112. FoundAny: BOOLEAN;
  113. FileStr, BlankStr: ARRAY [0..255] OF CHAR;
  114. FileLeng, ScrLeng, TheType: CARDINAL;
  115. TmpList, TmpList2: GenLists.GenList;
  116. FieldCount: CARDINAL;
  117. FieldRec: ScrnTypes.InputFieldRecord;
  118. ImageRec: ScrnTypes.ImageElement;
  119. BEGIN
  120. LowLevel.Fill( SYSTEM.ADR( BlankStr), HIGH(BlankStr) + 1, ' ');
  121. FoundAny := FALSE;
  122. IF M2Strings.Length( RecName) = 0 THEN
  123. (* read record name from field named in KeyField *)
  124. ControlUtils.ReadInput( TheFrame, RecName, KeyField);
  125. END;
  126. StrEdit.CrunchBlanks( RecName );
  127. FieldCount := 1;
  128. REPEAT
  129. (* flip through the named fields on screen and extract
  130. their value from the file if they exist there *)
  131. ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec );
  132. ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec );
  133. IF (M2Strings.Length( FieldRec.fnam) # 0) AND
  134. NdxFiles.GetField( NdxFile, RecName, FieldRec.fnam,
  135. TheType, FileStr) THEN
  136. (* for each named field we can get from the file *)
  137. IF FieldRec.typ # ScrnTypes.GroupMember THEN
  138. (* for any field except a group *)
  139. FoundAny := TRUE;
  140. IF TheType = GenLists.StrCode THEN
  141. FileLeng := M2Strings.Length( FileStr);
  142. ScrLeng := M2Strings.Length( ImageRec.text);
  143. IF FileLeng < ScrLeng THEN
  144. (*We need to pad out stored string with blanks to
  145. match length of screen field.*)
  146. StrEdit.SetLength( BlankStr, ScrLeng - FileLeng);
  147. StrEdit.Append( FileStr, BlankStr);
  148. END;
  149. IF FieldRec.typ # ScrnTypes.EditorCode THEN
  150. StrEdit.AssignStr( FileStr, ImageRec.text);
  151. ELSE
  152. GenLists.NewList( TmpList );
  153. GenLists.ListInsert( FileStr, GenLists.StrCode, TmpList, 1 );
  154. IF NOT ScrnUtl1.ListToEdField( TmpList, TheFrame,
  155. FieldCount ) THEN
  156. HALT();
  157. END;
  158. END;
  159. ELSIF TheType = GenLists.ListCode THEN
  160. IF FieldRec.typ = ScrnTypes.EditorCode THEN
  161. (*Make sure it's an editor field before we fill
  162. it with a list.*)
  163. IF NdxFiles.GetField( NdxFile, RecName,
  164. FieldRec.fnam, TheType, TmpList ) THEN
  165. GenLists.CopyList( TmpList, TmpList2 );
  166. IF NOT ScrnUtl1.ListToEdField( TmpList2, TheFrame,
  167. FieldCount ) THEN
  168. HALT();
  169. END;
  170. END;
  171. END;
  172. (*You could add additional data conversion operations
  173. here.*)
  174. END;
  175. ELSE
  176. (* for members of a group *)
  177. FoundAny := TRUE;
  178. FieldRec.selected := M2Strings.Length( FileStr) # 0;
  179. (* this simple logic assumes that the groups are the
  180. same on input and display screens *)
  181. END;
  182. ScrnUtl1.PutFieldImageRec( ImageRec, TheFrame, FieldCount );
  183. ScrnUtl1.PutFieldRec( FieldRec, TheFrame, FieldCount );
  184. END;
  185. INC( FieldCount );
  186. UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame );
  187. RETURN FoundAny;
  188. END FillScr;
  189. PROCEDURE PutScrFast( VAR NdxFile: NdxTypes.NdxFileType; VAR
  190. TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR;
  191. KeyField: ARRAY OF CHAR): BOOLEAN;
  192. (* Works like PutScrRec except that it requires an exact match
  193. between all named fields in the screen and the file record *)
  194. VAR
  195. Selctd: BOOLEAN;
  196. FileStr: ARRAY [0..255] OF CHAR;
  197. TmpList, TmpList2: GenLists.GenList;
  198. FileCntr, FileStructLen: CARDINAL;
  199. FieldCount: CARDINAL;
  200. FieldRec: ScrnTypes.InputFieldRecord;
  201. ImageRec: ScrnTypes.ImageElement;
  202. BEGIN
  203. IF M2Strings.Length( RecName) = 0 THEN
  204. (* read record name from field named in KeyField *)
  205. ControlUtils.ReadInput( TheFrame, RecName, KeyField);
  206. END;
  207. StrEdit.CrunchBlanks( RecName );
  208. IF NOT NdxBones.InitBuffer( NdxFile, RecName) THEN
  209. (* Loads file buffer with desired record; false result
  210. probably indicates we're creating a new record, but
  211. could actually indicate an error. We trust that we
  212. will catch an error below. *)
  213. END;
  214. FieldCount := 1;
  215. FileCntr := 0;
  216. (* used to count fields written to record *)
  217. FileStructLen := GenLists.ListLength( NdxFile^.ListBuf);
  218. REPEAT
  219. (* flip through the named fields on screen and store
  220. each in the record *)
  221. ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec );
  222. ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec );
  223. IF M2Strings.Length( FieldRec.fnam) # 0 THEN
  224. (* for each named field *)
  225. INC( FileCntr);
  226. (* go to next field in file *)
  227. IF FileCntr > FileStructLen THEN
  228. RETURN FALSE;
  229. END;
  230. IF FieldRec.typ # ScrnTypes.GroupMember THEN
  231. (* for any field except a group *)
  232. IF FieldRec.typ = ScrnTypes.EditorCode THEN
  233. (*We store editor fields as sublists.*)
  234. IF ScrnUtl1.ListFromEdField( TheFrame, FieldCount, TmpList ) THEN
  235. GenLists.CopyList( TmpList, TmpList2 );
  236. GenLists.ListReplace( TmpList2, GenLists.ListCode,
  237. NdxFile^.ListBuf, FileCntr);
  238. END;
  239. ELSE
  240. StrEdit.CutTrailingChars( ' ', ImageRec.text );
  241. GenLists.ListReplace( ImageRec.text, GenLists.StrCode,
  242. NdxFile^.ListBuf, FileCntr);
  243. END;
  244. ELSIF FieldRec.selected THEN
  245. (* for selected members of a group put a ONE *)
  246. GenLists.ListReplace( '1', GenLists.StrCode,
  247. NdxFile^.ListBuf, FileCntr);
  248. ELSE
  249. (* for non-selected members of a group put a NULL *)
  250. GenLists.ListReplace( '', GenLists.StrCode,
  251. NdxFile^.ListBuf, FileCntr);
  252. END;
  253. END;
  254. INC( FieldCount );
  255. UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame );
  256. RETURN TRUE;
  257. END PutScrFast;
  258. PROCEDURE FillScrFast( VAR NdxFile: NdxTypes.NdxFileType; VAR
  259. TheFrame: ScrnTypes.DisplayFrame; VAR RecName: ARRAY OF CHAR;
  260. KeyField: ARRAY OF CHAR): BOOLEAN;
  261. (* Fills the current screen with the data from a record. Works
  262. like FillScr except that it requires an exact match between all
  263. named fields in the screen and the fields in the file record *)
  264. VAR
  265. Selctd : BOOLEAN;
  266. FileStr, BlankStr: ARRAY [0..255] OF CHAR;
  267. FileLeng, ScrLeng, TheType, FileCntr,
  268. FileStructLen: CARDINAL;
  269. TmpList, TmpList2: GenLists.GenList;
  270. FieldCount: CARDINAL;
  271. FieldRec: ScrnTypes.InputFieldRecord;
  272. ImageRec: ScrnTypes.ImageElement;
  273. BEGIN
  274. LowLevel.Fill( SYSTEM.ADR( BlankStr), HIGH(BlankStr) + 1, ' ');
  275. IF M2Strings.Length( RecName) = 0 THEN
  276. (* read record name from field named in KeyField *)
  277. ControlUtils.ReadInput( TheFrame, RecName, KeyField);
  278. END;
  279. StrEdit.CrunchBlanks( RecName );
  280. IF NOT NdxBones.InitBuffer( NdxFile, RecName) THEN
  281. (* loads file buffer with desired record *)
  282. RETURN FALSE;
  283. END;
  284. FieldCount := 1;
  285. FileCntr := 0;
  286. FileStructLen := GenLists.ListLength( NdxFile^.ListBuf);
  287. REPEAT
  288. (* flip through the named fields on screen and, for
  289. each, extract the next field in the file record *)
  290. ScrnUtl1.GetFieldRec( TheFrame, FieldCount, FieldRec );
  291. ScrnUtl1.GetImageRec( TheFrame, FieldRec.ImageNum, ImageRec );
  292. IF M2Strings.Length( FieldRec.fnam) # 0 THEN
  293. (* for each named field *)
  294. INC( FileCntr);
  295. (* go to next field in file *)
  296. IF FileCntr > FileStructLen THEN
  297. RETURN FALSE;
  298. END;
  299. GenLists.GetElmt( NdxFile^.ListBuf, FileCntr, FileStr, TheType);
  300. (*Read file value.*)
  301. IF FieldRec.typ # ScrnTypes.GroupMember THEN
  302. (* for any field except a group *)
  303. IF TheType = GenLists.StrCode THEN
  304. FileLeng := M2Strings.Length( FileStr);
  305. ScrLeng := M2Strings.Length( ImageRec.text);
  306. IF FileLeng < ScrLeng THEN
  307. (*We need to pad out stored string with blanks to
  308. match length of screen field.*)
  309. StrEdit.SetLength( BlankStr, ScrLeng - FileLeng);
  310. StrEdit.Append( FileStr, BlankStr);
  311. END;
  312. IF FieldRec.typ # ScrnTypes.EditorCode THEN
  313. StrEdit.AssignStr( FileStr, ImageRec.text);
  314. ELSE
  315. GenLists.NewList( TmpList );
  316. GenLists.ListInsert( FileStr, GenLists.StrCode, TmpList, 1 );
  317. IF NOT ScrnUtl1.ListToEdField( TmpList, TheFrame,
  318. FieldCount ) THEN
  319. HALT();
  320. END;
  321. END;
  322. ELSIF TheType = GenLists.ListCode THEN
  323. IF FieldRec.typ = ScrnTypes.EditorCode THEN
  324. (*Make sure it's an editor field before we fill
  325. it with a list.*)
  326. GenLists.GetChildList( NdxFile^.ListBuf, FileCntr, TmpList);
  327. GenLists.CopyList( TmpList, TmpList2 );
  328. IF NOT ScrnUtl1.ListToEdField( TmpList2, TheFrame,
  329. FieldCount ) THEN
  330. HALT();
  331. END;
  332. END;
  333. (*You could add additional data conversion operations
  334. here.*)
  335. END;
  336. ELSE
  337. (* for members of a group *)
  338. FieldRec.selected := M2Strings.Length( FileStr) # 0;
  339. (* this simple logic assumes that the groups are the
  340. same on input and display screens *)
  341. END;
  342. ScrnUtl1.PutFieldImageRec( ImageRec, TheFrame, FieldCount );
  343. ScrnUtl1.PutFieldRec( FieldRec, TheFrame, FieldCount );
  344. END;
  345. INC( FieldCount );
  346. UNTIL FieldCount > ScrnUtl1.FieldListTotal( TheFrame );
  347. RETURN TRUE;
  348. END FillScrFast;
  349. BEGIN
  350. Initialized := FALSE;
  351. Init();
  352. END Scrn2Ndx.