Sample Program : Sample C Program

Sample C Program

The sample C program is as follows:

#include <stdio.h>

#include "dataport.h"
#define GET_STR(S)
{int i;for(i=0;(S[i++]=getchar())!=’\n’;);
S[--i]=’\0’;}

int status=0;
FILE *fd;
char array[80];

void draw_line (color, x1, y1, x2, y2)
stm_color color;
stm_coordinate x1, y1, x2, y2;
{
printf("\n line from %f, %f to %f, %f in color %d",
x1, y1, x2, y2, color);
}

void draw_string (s, color, x1, y1)
char *s;
stm_color color;
stm_coordinate x1,y1;
{
printf ("\n string %s at %f, %f in color %d\n",
s, x1, y1, color);
}
static char *activity_type (search_for)
stm_activity_typesearch_for;
{

static struct search_activity_type {
stm_activity_typeact_type;
char *name;
} ActivityType[] = {
{stm_ac_diagram, ”DIAGRAM” },
{stm_ac_reference, ”REFERENCE” },
{stm_ac_internal, ”INTERNAL” },
{stm_ac_instance, ”INSTANCE” },
{stm_ac_control, ”CONTROL” },
{stm_ac_control_instance, ”CONTROL_INSTANCE” },
{stm_ac_external, ”EXTERNAL” },
{NULL, ”NULL”},
}
struct search_activity_type *sat;

for (sat = ActivityType; sat->name != NULL; sat++)
if (sat->act_type == search_for)
return sat->name;
return ””; /* error! */
}

static char *activity_termination_type(search_for)
stm_activity_terminationsearch_for;
{
static struct search_activity_termination {
stm_activity_terminationact_term_type;
char *name;
} ActivityTerminationType[] = {
{stm_ac_missing, ”MISSING” },
{stm_ac_self_termination, ”SELF_TERMINATION” },
{stm_ac_controlled_termination,
”CONTROLLED_TERMINATION”},
{NULL, ”NULL” },
}
struct search_activity_termination *sat;
for (sat = ActivityTerminationType;
sat->name != NULL;sat++)
if (sat->act_term_type == search_for)
return sat->name;
return ""; /* error! */
}

void activity_text_output(ac_text)
stm_ac_text_ptr ac_text;
{
printf("\n\n\n\n\n activity textual information\n");
printf("============================\n");
printf("\n activity name: %s", ac_text->ac_name);
printf("\n activity in chart: %d",
ac_text->ac_chart);
printf("\n activityuniquename:%s",
ac_text->ac_uniquename);
printf("\n activity synonym: %s",
ac_text->ac_synonym);
printf("\n activity type: %s",(ac_text->ac_type));
printf("\n activity termination: %s",
activity_termination_type (ac_text->ac_termination));
printf("\n activity short description: %s",
ac_text->ac_short_des);
printf("\n activity long description:\n\n");
if ((fd=fopen(ac_text->ac_long_des, "r")) == ZNIL)
printf("\n\n cannot open file for printing");
while (fgets(array,81,fd)!=ZNIL) printf("%s",array);
}
void activity_graphic_output (ac_graphic, ac_name)
stm_ac_graphic_ptr ac_graphic;
stm_name ac_name;

{
int i = 0;
stm_coordinate prev_x;
stm_coordinate prev_y;
printf("\n\n activity graphical information\n");
printf("==============================\n");

draw_string (ac_name, ac_graphic->ac_name_color,
ac_graphic->ac_x_coor, ac_graphic->ac_y_coor);
 
for (i=1; i<=ac_graphic->ac_polygon.points_no;i++)
{
prev_x = ac_graphic->ac_polygon.outline[i-1].x;
prev_y = ac_graphic->ac_polygon.outline[i-1].y;
draw_line(ac_graphic->ac_color,prev_x,prev_y,
ac_graphic->ac_polygon.outline
[i % ac_graphic->ac_polygon.points_no].x,
ac_graphic->ac_polygon.outline
[i % ac_graphic->ac_polygon.points_no].y);
}
}

void activities_info (ac_list)
stm_list ac_list;
{
stm_ac_text_ptr ac_textual;
stm_ac_graphic_ptr ac_graphical;
stm_id el;

for (el = (stm_id) stm_list_first_element (ac_list, &status);
status == stm_success;
el= (stm_id)stm_list_next_element (ac_list, &status))
{

ac_textual = stm_r_ac_text (el, &status);
if (status == stm_success)
activity_text_output (ac_textual);

ac_graphical=stm_r_ac_graphic(el,&status);
if (status == stm_success)
activity_graphic_output(ac_graphical, ac_textual->ac_name);
}
}

void activity_boxes()
{
char ac_name[32];
stm_id ac_id;
stm_list ac_list,acs_list;
printf("\n enter activity name: ");
GET_STR(ac_name);
ac_id=stm_r_ac(ac_name,&status);
if (status!=stm_success)
{
printf("illegal activity name"); return;
}

ac_list=stm_list_create(ac_id,end_of_list,&status);
acs_list=stm_r_ac_physical_sub_of_ac(ac_list,&status);

if (status!=stm_success)
{
printf("error during execution"); return;
}
acs_list=stm_list_union(ac_list, acs_list, &status);
activities_info(acs_list);
}

main( )
{
char pname[32];

printf("enter name of project: ");
GET_STR(pname);
success=stm_init_uad(pname, "/usr/sam/proj",
self_transaction, &status);
if (success)
{
stm_start_transaction();
activity_boxes();
stm_commit_transaction();
}
else
printf(cause of failure 15:%d,status);
stm_finish_uad();
}