The following example program uses only the IEDTCMD interface.
/********************************************************************/ /* */ /* Example 1 */ /* */ /* This example uses only the IEDTCMD */ /* interface to execute EDT statements. */ /* */ /* The example program performs the following actions: */ /* */ /* 1) Read a selection criterion (CCSN) */ /* 2) Output a table of contents to work file 0 */ /* using the @SHOW statement (Format 1). */ /* 3) Delete all the lines which do not contain the search */ /* criterion with the @ON statement (Format 10). */ /* 4) Set work file 0 and then switch to the F mode */ /* dialog by means of a @SETF statement followed by a */ /* @DIALOG statement. */ /* 5) The user can now edit the lines that are output */ /* and after that terminate EDT and consequently also this */ /* example program. */ /* */ /********************************************************************/ #include <string.h> #include <stdlib.h> #include <stdio.h> /* Include files of the EDT subroutine interface */ #define EDT_V17 /*-------------------------- (1) */ #include <iedtgle.h> /*--------------------------- (2) */ /* Create and initialize the EDT subroutine interface data */ /* structures required for this example. */
static iedglcb glcb = IEDGLCB_INIT;
static iedupcb upcb = IEDUPCB_INIT;
static iedbuff *command = NULL;
static iedbuff *message1 = NULL;
static iedbuff *message2 = NULL;
/********************************************************************/
/* Function: printrc */
/* */
/* Task: */
/* If EDT has returned an error message, then the error message */
/* is output by this function. */
/* */
/* Parameter: errmsg (IN) Pointer to the additional error */
/* message to be output if an error occurs*/
/* */
/* Return value: none */
/********************************************************************/
static void
printrc(char *errmsg)
{
char message[81];
if ((glcb.rc.structured_rc.mc.maincode != 0) &&
(glcb.return_message.structured_msg.rmsgl > 0))
{
printf("%s\n",errmsg); /* Output the passed error message */
strncpy(message,(char*)glcb.return_message.structured_msg.rmsgf,
glcb.return_message.structured_msg.rmsgl);
message[glcb.return_message.structured_msg.rmsgl] = 0x00;
printf("Meldungstext: %s\n",message); /* Output EDT message */
exit(1);
}
}
/********************************************************************/
/* Function: fill_buff */
/* */
/* Task: */
/* This function enters content and the record length field in a */
/* record of variable length. */
/* */
/* Parameter: p: (IN) Pointer to a structure of type */
/* iedbuff, which contains the variable */
/* length record to be set. */
/* textp: (IN) Points to a string which contains the */
/* text to be entered. The length */
/* of the string implicitly defines the */
/* record length (length of string + 4). */
/* */
/* Return value: none */
/********************************************************************/
static void
fill_buff(iedbuff *p,char *textp)
{
size_t l_text; /* Length of string */
if ((l_text = strlen(textp)) > 2044) /*---------- (3) */
l_text = 2044; /* Restrict length to 2044 characters */
strncpy((char *)p->text,textp,l_text); /* Enter text */
p->length = l_text + 4; /* Enter record length */
}
/********************************************************************/
/* Function: edtcmd */
/* */
/* Task: */
/* This function enters the passed strings in records of */
/* variable lengths (DMS format) and then calls the EDT's */
/* CMD interface. */
/* */
/* Parameter: cmd: (IN) Pointer to a string which contains */
/* the EDT statement(s) that are to be */
/* executed. The length of the string */
/* implicitly defines the record length */
/* (String length + 4). */
/* msg1: (IN) Pointer to a string which contains the */
/* text to be entered. The length */
/* of the string implicitly defines the */
/* record length (length of string + 4). */
/* msg2: (IN) Pointer to a string which contains the */
/* text to be entered. The length */
/* of the string implicitly defines the */
/* record length (length of string + 4). */
/* */
/* Return value: none */
/********************************************************************/
static void
edtcmd(char *cmd,char *msg1,char *msg2)
{
fill_buff(command,cmd);
fill_buff(message1,msg1);
fill_buff(message2,msg2);
IEDTCMD(&glcb,&upcb,command,message1,message2);
}
/********************************************************************/
/* Main program */
/********************************************************************/
int
main(void)
{
char input[81]; /* Input area */
char ccsn[9]; /* Entered CCSN */
char cmd[257]; /* Area for the construction of EDT statements */
/* Provide buffer */
command = (iedbuff *)malloc(2048);
message1 = (iedbuff *)malloc(2048);
message2 = (iedbuff *)malloc(2048);
printf("\nStart Beispiel1\n\n");
/* Read in CCSN */
printf("Bitte CCSN eingeben (UTFE,UTF16,EDFxxx): ");
scanf("%s",input);
if (strlen(input) < 1 || strlen(input) > 8)
{
printf("Eingabe zu kurz oder zu lang!");
exit(1);
}
strupper(ccsn,input); /* Conv. CCSN into uppercase */
/* Output table of contents to work file 0 */
edtcmd("SHOW F=* TO 1 LONG","","");
printrc("Fehler bei der @SHOW-Anweisung!");
/* Delete all the lines which do not correspond to the search */
/* criterion (CCSN) and renumber the remaining lines */
sprintf(cmd,"ON &:100-107: FIND NOT '%s' DELETE;RENUMBER",ccsn);
edtcmd(cmd,"","");
printrc("Fehler bei der @ON- oder der @RENUMBER-Anweisung!");
/* Go to work file 0 and switch to the */
/* F mode dialog */
edtcmd("SETF(0);DIALOG","Beispiel 1 fuer die UP-Schnittstelle","");
printrc("Fehler bei der @SETF- oder der @DIALOG-Anweisung!");
edtcmd("HALT","","");
printf("\nEnde Beispiel1\n\n");
return 0;
}
Explanations
(1) | #define specifies that the V17 variant of the interface is to be generated. This causes EDT to be automatically started in Unicode mode. |
| (2) | In EDT V17.0, all that is required is an #include statement for iedtgle.h. This header file causes the inclusion of the other required headers. |
| (3) | In this program, the malloc for the buffer areas causes the restriction to 2044. EDT itself would accept 32767 bytes. |
If the procedure explained in the section on producing main programs in C is stored in a file named CC.DO in BS2000 and the source file is stored as the S element BEISPIEL1.C in the library EDT.BEISPIELE then the above program can be compiled and linked with
/CALL-PROC CC.DO,(1).
The generated program can then be executed using
/START-EXECUTABLE-PROGRAM (E=BSP1C,L=EDT.BEISPIELE)
When CC.DO runs, the following or similar output is generated by the system or the compiler:
% BLS0523 ELEMENT 'SDFCC', VERSION '031', TYPE 'L' FROM LIBRARY ':MARS:$TSOS.SYSLNK.CPP-RS.031' IN PROCESS % BLS0524 LLM 'SDFCC', VERSION '03.1A40' OF '2005-02-03 16:16:36' LOADED % BLS0551 COPYRIGHT (C) Fujitsu Siemens Computers GmbH 2005. ALL RIGHTS RESERVED % CDR9992 : BEGIN C/C++(BS2000/OSD) VERSION 03.1A40 % CDR9907 : NOTES: 0 WARNINGS: 0 ERRORS: 0 FATALS: 0 % CDR9937 : MODULES GENERATED, CPU TIME USED = 2.4800 SEC % BND3102 SOME WEAK EXTERNS UNRESOLVED % BND1501 LLM FORMAT: '1' % BND1101 BINDER NORMALLY TERMINATED. SEVERITY CLASS: 'UNRESOLVED EXTERNAL' % CDR9936 : END; SUMMARY: NOTES: 0 WARNINGS: 0 ERRORS: 0 FATALS: 0 % CCM0998 CPU TIME USED: 3.4223 SECONDS
When /START-EXECUTABLE-PROGRAM (E=BSP1C,L=EDT.BEISPIELE) is called, the following or similar messages are displayed:
% BLS0523 ELEMENT 'BSP1C', VERSION '@', TYPE 'L' FROM LIBRARY ':A:$USER.EDT.BEISPIELE' IN PROCESS % BLS0524 LLM '$LIB-ELEM$EDT$BEISPIELE$$BSP1C$$',VERSION' 'OF'2007-05-03 14 :42:12' LOADED Start Beispiel1 Bitte CCSN eingeben (UTFE, UTF16, EDFxxx):
If UTF is entered here, i.e. if all the files coded in a Unicode character set are selected, the program next switches to the EDT dialog and the following screen is displayed:
Entering @INDEX OFF; @DELETE&:1-24 makes it possible to restrict the output to the relevant information and displays the following screen:

