UbuntuのOpenCOBOLでソースをCで出力
UbuntuのOpenCOBOLでソースをコンパイルして実行 - developer's diaryでコンパイルしたソースをCで出力する
Cにするソースは、http://www12.ocn.ne.jp/~peg/1_1.html#c10より。
IDENTIFICATION DIVISION. PROGRAM-ID. hello. PROCEDURE DIVISION. DISPLAY "Hello World!". STOP RUN.
そしてCに。
[xxx@/src/cobol]$ cobc -C --free hello.cob [xxx@/src/cobol]$ ls hello.c hello.c.h hello.cob
以下できあがったソース
hello.c
/* Generated from hello.cob by cobc version 1.0 patch level 0 */ #define __USE_STRING_INLINES 1 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <libcob.h> #define COB_SOURCE_FILE "hello.cob" #define COB_PACKAGE_VERSION "1.0" #define COB_PATCH_LEVEL 0 /* function prototypes */ static int hello_ (const int); int hello (void); /* functions */ int hello () { return hello_ (0); } /* end functions */ static int hello_ (const int entry) { #include "hello.c.h" /* local variables */ static int initialized = 0; static cob_field *cob_user_parameters[COB_MAX_FIELD_PARAMS]; static cob_module module = { NULL, NULL, NULL, NULL, cob_user_parameters, 0, '.', '$', ',', 1, 1, 1, 0}; /* perform frame stack */ int frame_index; struct frame { int perform_through; void *return_address; } frame_stack[255]; /* Start of function code */ if (unlikely(entry < 0)) { if (!initialized) { return 0; } initialized = 0; return 0; } module.next = cob_current_module; cob_current_module = &module; if (unlikely(initialized == 0)) { if (!cob_initialized) { cob_fatal_error (COB_FERROR_INITIALIZED); } cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL); if (module.next) cob_set_cancel ((const char *)"hello", (void *)hello, (void *)hello_); (*(int *) (b_1)) = 0; (*(int *) (b_2)) = 0; (*(int *) (b_3)) = 0; initialized = 1; } /* initialize frame stack */ frame_index = 0; frame_stack[0].perform_through = -1; /* initialize number of call params */ (*(int *) (b_3)) = cob_call_params; cob_save_call_params = cob_call_params; goto l_2; /* PROCEDURE DIVISION */ /* hello: */ l_2:; /* MAIN SECTION: */ /* MAIN PARAGRAPH: */ /* hello.cob:4: DISPLAY */ { cob_new_display (0, 1, 1, &c_1); } /* hello.cob:5: STOP */ { cob_stop_run ((*(int *) (b_1))); } cob_current_module = cob_current_module->next; return (*(int *) (b_1)); } /* end function stuff */
hello.c.h
/* Generated from hello.cob by cobc version 1.0 patch level 0 */ /* PROGRAM-ID : hello */ static unsigned char b_1[4] __attribute__((aligned)); /* RETURN-CODE */ static unsigned char b_2[4] __attribute__((aligned)); /* SORT-RETURN */ static unsigned char b_3[4] __attribute__((aligned)); /* NUMBER-OF-CALL-PARAMETERS */ /* attributes */ static cob_field_attr a_1 = {33, 0, 0, 0, NULL}; /* constants */ static cob_field c_1 = {12, (unsigned char *)"Hello World!", &a_1}; /* ---------------------------------------------- */