![]() |
|
|||
0001 /** 0002 * @brief Go language support - format the GO package with field constants 0003 * 0004 * @file golang.c 0005 */ 0006 /* ----------------------------------------------------------------------------- 0007 * Enduro/X Middleware Platform for Distributed Transaction Processing 0008 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 0009 * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved. 0010 * This software is released under one of the following licenses: 0011 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use. 0012 * See LICENSE file for full text. 0013 * ----------------------------------------------------------------------------- 0014 * AGPL license: 0015 * 0016 * This program is free software; you can redistribute it and/or modify it under 0017 * the terms of the GNU Affero General Public License, version 3 as published 0018 * by the Free Software Foundation; 0019 * 0020 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0022 * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3 0023 * for more details. 0024 * 0025 * You should have received a copy of the GNU Affero General Public License along 0026 * with this program; if not, write to the Free Software Foundation, Inc., 0027 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0028 * 0029 * ----------------------------------------------------------------------------- 0030 * A commercial use license is available from Mavimax, Ltd 0031 * contact@mavimax.com 0032 * ----------------------------------------------------------------------------- 0033 */ 0034 0035 /*---------------------------Includes-----------------------------------*/ 0036 0037 #include <unistd.h> 0038 #include <stdio.h> 0039 #include <errno.h> 0040 #include <stdlib.h> 0041 #include <atmi.h> 0042 0043 #include <ubf.h> 0044 #include <ubf_int.h> 0045 #include <ferror.h> 0046 #include <fieldtable.h> 0047 #include <fdatatype.h> 0048 0049 #include <ndrstandard.h> 0050 #include <ndebug.h> 0051 #include "mkfldhdr.h" 0052 /*---------------------------Externs------------------------------------*/ 0053 /*---------------------------Macros-------------------------------------*/ 0054 /*---------------------------Enums--------------------------------------*/ 0055 /*---------------------------Typedefs-----------------------------------*/ 0056 /*---------------------------Globals------------------------------------*/ 0057 /*---------------------------Statics------------------------------------*/ 0058 /*---------------------------Prototypes---------------------------------*/ 0059 0060 /** 0061 * Get the c lang output file name 0062 * @param data 0063 */ 0064 expublic void go_get_fullname(char *data) 0065 { 0066 sprintf(data, "%s/%s.go", G_output_dir, G_active_file); 0067 } 0068 0069 /** 0070 * Write text line to output file 0071 * @param text 0072 * @return 0073 */ 0074 expublic int go_put_text_line (char *text) 0075 { 0076 int ret=EXSUCCEED; 0077 0078 if (0==strncmp(text, "#ifndef", 7) || 0079 0==strncmp(text, "#define", 7) || 0080 0==strncmp(text, "#endif", 6)) 0081 { 0082 /* just ignore these special C lines */ 0083 goto out; 0084 } 0085 0086 fprintf(G_outf, "%s", text); 0087 0088 /* Check errors */ 0089 if (ferror(G_outf)) 0090 { 0091 ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", strerror(errno)); 0092 EXFAIL_OUT(ret); 0093 } 0094 0095 out: 0096 return ret; 0097 } 0098 0099 /** 0100 * Process the baseline 0101 * @param base 0102 * @return 0103 */ 0104 expublic int go_put_got_base_line(char *base) 0105 { 0106 0107 int ret=EXSUCCEED; 0108 0109 fprintf(G_outf, "/*\tfname\tbfldid */\n" 0110 "/*\t-----\t----- */\n" 0111 "const (\n" 0112 ); 0113 0114 /* Check errors */ 0115 if (ferror(G_outf)) 0116 { 0117 ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", strerror(errno)); 0118 ret=EXFAIL; 0119 } 0120 0121 return ret; 0122 } 0123 0124 /** 0125 * Write definition to output file 0126 * @param def 0127 * @return 0128 */ 0129 expublic int go_put_def_line (UBF_field_def_t *def) 0130 { 0131 int ret=EXSUCCEED; 0132 int type = def->bfldid>>EFFECTIVE_BITS; 0133 BFLDID number = def->bfldid & EFFECTIVE_BITS_MASK; 0134 0135 fprintf(G_outf, "\t%s = %d /* number: %d type: %s */\n", 0136 def->fldname, def->bfldid, number, 0137 G_dtype_str_map[type].fldname); 0138 0139 /* Check errors */ 0140 if (ferror(G_outf)) 0141 { 0142 ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", strerror(errno)); 0143 ret=EXFAIL; 0144 } 0145 0146 return ret; 0147 } 0148 0149 /** 0150 * Output file have been open 0151 * @param fname 0152 * @return 0153 */ 0154 expublic int go_file_open (char *fname) 0155 { 0156 0157 if (EXEOS!=G_privdata[0]) 0158 { 0159 fprintf(G_outf, "package %s\n\n", G_privdata); 0160 } 0161 else 0162 { 0163 fprintf(G_outf, "package %s\n\n", G_active_file); 0164 } 0165 0166 return EXSUCCEED; 0167 } 0168 0169 /** 0170 * Output file have been closed 0171 * @param fname 0172 * @return 0173 */ 0174 expublic int go_file_close (char *fname) 0175 { 0176 fprintf(G_outf, ")\n"); 0177 0178 /* Check errors */ 0179 if (ferror(G_outf)) 0180 { 0181 ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", 0182 strerror(errno)); 0183 return EXFAIL; 0184 } 0185 0186 return EXSUCCEED; 0187 } 0188 0189 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |