/**=========== Example of Use =============**/ int main(int argc, char * argv[]) { if (argc < 2) { std::cout << "Use: '-read' or '-write'" << std::endl; return -1; } string file_path = "example.txt"; ///Write if (strcmp(argv[1],"-write") == 0) { if (write_comment(file_path, 1, "//Example File Config") == -1)//if file does not exist return -1 { cout << "File Does Not Exist!" << std::endl; return -1; } write_comment(file_path, 2, ""); write_comment(file_path, 3, "//Video Config"); write_variable(file_path, "width", "1024"); write_variable(file_path, "height", "720"); write_variable(file_path, "mode", "fullscreen"); return 0; } ///Read if (strcmp(argv[1],"-read") == 0) { int width; int height; string mode; width = atoi(read_variable(file_path, "width").c_str()); height = atoi(read_variable(file_path, "height").c_str()); mode = read_variable(file_path, "mode");//if file does not exist return "null" std::cout << "Width = " << width << std::endl; std::cout << "Height = " << height << std::endl; std::cout << "Mode = " << mode << std::endl; return 0; } //invalid else { std::cout << "Use: '-read' or '-write'" << std::endl; return -1; } }
COPYING3_SHORT_MACRO void language_writer::WriteLicense() { for(unsigned int row=0; row < COPYING3_SHORT_NROW; ++row) { write_comment(std::string(COPYING3_SHORT[row])); } }
int ss_conf_getnstr(const ss_conf_data_t *conf, const char *conf_name, char *conf_value, const size_t n, const char *comment, const char *default_value) { if (NULL == conf || NULL == conf_name || NULL == conf_value || 0 == n) { return SS_CONF_NULL; } if (conf->build != SS_CONF_READCONF) { if (write_comment(conf->conf_file, comment) == SS_CONF_SUCCESS) { if (default_value != NULL) { fprintf(conf->conf_file, "#[default configure(string), %s : %s]\n%s : %s", conf_name, conf_value, conf_name, conf_value); } else { fprintf(conf->conf_file, "%s : ", conf_name); } return SS_CONF_SUCCESS; } return SS_CONF_NULL; } int ret; ret = load_str(conf, conf_name, conf_value, n); if (ret == SS_CONF_LOST) { if (default_value != NULL) { snprintf(conf_value, n, "%s", default_value); SS_LOG_WARNING("load string [%s] fail, use default value [%s]", conf_name, default_value); return SS_CONF_DEFAULT; } SS_LOG_WARNING("load string fail, not found[%s]", conf_name); return SS_CONF_LOST; } if (check_str(conf, conf_name, conf_value) != SS_CONF_CHECKSUCCESS) { return SS_CONF_CHECKFAIL; } SS_LOG_TRACE("get string value [%s : %s]", conf_name, conf_value); return ret; }
FILE *RB_TROFF_Generate_Header_Start( FILE *dest_doc, struct RB_header *cur_header ) { static char *manpage = NULL; int sec_item; if ( manpage == NULL ) manpage = RB_malloc( MAXPATHLEN ); if ( cur_header->name ) { char *file = RB_Get_FullDocname( cur_header->owner->filename ); char *name = basename( cur_header->name ); char *path = basename( file ); int len, i; struct RB_Item *item; char *section = NULL; /* Search for SECTION header and use this section for man pages */ sec_item = RB_Get_Item_Type("SECTION"); for( item = cur_header->items; item ; item = item->next) { if( item->type == sec_item ) { /* Item found, search for nonempty line */ for(i = 0 ; i < item->no_lines; i++ ) { section = item->lines[i]->line; while( *section && utf8_isspace(*section) ) section++; if( *section ) { /* nonempty line found, break */ break; } } break; } } len = path - file; memcpy( manpage, file, len ); /* we found a section header, strip at next whitespace */ if( section && *section ) { char *to, *ptr; ptr = RB_malloc( strlen(section) + 1 ); to = ptr; while( *section && !utf8_isspace(*section) ) { *to++ = *section++; } *to++ = 0; section = ptr; } else { section = man_section; } sprintf( manpage + len, "%s.%s%s", name, section, compress_ext ); dest_doc = open_output_file( manpage ); if ( dest_doc == NULL ) { RB_Panic( "Cannot open %s: %s\n", manpage, strerror( errno ) ); } RB_Say( "+ Generating man page \"%s\"\n", SAY_INFO, manpage ); /* Check for aliases if we have symlink() */ #ifdef HAVE_SYMLINK for ( i = 1; i < cur_header->no_names; i++ ) { char *base = basename( cur_header->names[i] ); char *buf = strchr( manpage, 0 ) + 1; memcpy( buf, file, len ); sprintf( buf + len, "%s.%s%s", base, section, compress_ext ); unlink( buf ); symlink( basename( manpage ), buf ); RB_Say( "+ Linked with \"%s\"\n", SAY_INFO, buf ); } #else USE( i ); #endif /* Append document type and title */ fprintf( dest_doc, ".\\\" Source: %s\n", cur_header->owner->filename->fullname ); write_comment( dest_doc, COMMENT_ROBODOC COMMENT_COPYRIGHT ); fprintf( dest_doc, ".TH %s %s \"", name, section ); { time_t ttp; char timeBuffer[255]; time( &ttp ); strftime( timeBuffer, sizeof timeBuffer, "%b %d, %Y", localtime( &ttp ) ); fputs( timeBuffer, dest_doc ); if ( name > cur_header->name ) { path = cur_header->name; len = name - path - 1; } else len = strlen( path = name ); if ( len >= (signed)sizeof timeBuffer ) len = sizeof timeBuffer - 1; memcpy( timeBuffer, path, len ); timeBuffer[len] = 0; fprintf( dest_doc, "\" %s \"%s Reference\"\n", timeBuffer, timeBuffer ); } if( section != man_section ) { free(section); } } return dest_doc; }
/*=== write_type_header =================================================== * <Description Text> * * Assumes: ? * * Returns: nothing * * Modifies: ? * * Calls: nothing * * Called By: ? * * History: MM/DD/YY MRH Created initial version based on function * 'func()' in motif/csr/file.c */ void write_type_header(FILE *header) { char description[512]; FIELD *field; char define_name[80]; /* * Write header comment */ sprintf(description, "\ Public interface to the '%s' Abstract Datatype. \ This file was automatically generated.", gAPIType); write_header(header, gTypeHeaderName, description); fprintf(header, "#ifndef _%s_\n", gTypeHeaderNameUC); fprintf(header, "#define _%s_\n", gTypeHeaderNameUC); /* * extern "C" if a C++ compiler. */ fprintf(header, "\n#ifdef %s\n", CPLUSPLUS); fprintf(header, "extern \"C\"\n{\n"); fprintf(header, "#endif\n"); /* * #Defines for string lengths of objects. */ sprintf(description, "\n\n\ The following are '#define's of the string lengths of each of the %s \ field objects.", gAPIType); write_comment(header, 0, description); for (field = gFields; field; field = field->next) { if (field->exclude || (field->join && ! field->is_master_join)) continue; if (field->field_type == FIELD_STRING_TYPE) { sprintf(define_name, "GAL_%s_%s_LEN", gAPINameUC, ((field->has_alias) ? field->alias_uc : field->name_uc)); write_define(header, define_name, field->field_length + 1); } } /* * Insert type prototype. The key is public knowledge. */ sprintf(description, "\n\n\ %s provides a unique key interface to the %s abstract datatype.", gAPIKeyType, gAPIType); write_comment(header, 0, description); fprintf(header, "typedef struct _gal_%s_key_data_\n{\n", gAPIName); for (field = gFields; field; field = field->next) if (field->is_key) write_object_field(header, field); fprintf(header, "\n}"); fprintf(header, " %s,\n", gAPIKeyTypeData); fprintf(header, " *%s;\n", gAPIKeyType); /* * extern "C" if a C++ compiler. */ fprintf(header, "\n#ifdef %s\n", CPLUSPLUS); fprintf(header, "}\n"); fprintf(header, "#endif\n\n"); fprintf(header, "#endif /* #ifndef _%s_ */\n", gTypeHeaderNameUC); }
void xml_writer_impl::write_element(const variant& element) { try { if (element.is<variant::Collection>() && element.empty() && element.type() != variant::DataTable) { write_empty_element(); return; } switch(element.type()) { case variant::None: { write_empty_element(); break; } case variant::Any: case variant::String: { if (element.as<std::string>().empty()) { write_empty_element(); break; } } case variant::Float: case variant::Double: case variant::Int32: case variant::UInt32: case variant::Int64: case variant::UInt64: case variant::Boolean: case variant::Date: case variant::Time: case variant::DateTime: { m_os << start_tag(); write_text(element); m_os << end_tag(); break; } case variant::Dictionary: case variant::Bag: { if ((m_mode & xml_mode::Preserve)!=0) { if (element.has_key(xml_attributes)) { m_stack.top().m_attributes = element[xml_attributes]; if (element.size()==1) { write_empty_element(); break; } } m_os << start_tag(); bool prev_is_text = false; variant::const_iterator it, end(element.end()); for (it=element.begin(); it!=end; ++it) { if (it.key()==xml_attributes) { continue; } else if (it.key()==xml_text) { write_text(it.value()); prev_is_text = true; } else if (it.key()==xml_instruction) { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_instruction(it.value()); prev_is_text = false; pop(); } else if (it.key()==xml_comment) { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_comment(it.value()); prev_is_text = false; pop(); } else { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_element(it.value()); prev_is_text = false; pop(); } } if (!prev_is_text) { m_os << indent(); } m_os << end_tag(); } else { m_os << start_tag(); variant::const_iterator it, end(element.end()); for (it=element.begin(); it!=end; ++it) { push(it.key()); m_os << indent(); write_variant(it.value()); pop(); } m_os << indent() << end_tag(); } break; } case variant::List: { m_os << start_tag(); BOOST_FOREACH(const variant& item, element) { push(); m_os << indent(); write_variant(item); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Tuple: { m_stack.top().m_attributes.insert("size", variant(element.size())); m_os << start_tag(); BOOST_FOREACH(const variant& item, element) { push(); m_os << indent(); write_variant(item); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::TimeSeries: { m_os << start_tag(); variant::const_iterator it, end = element.end(); for (it=element.begin(); it!=end; ++it) { push().insert("time", variant(it.time())); m_os << indent(); write_variant(it.value()); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::DataTable: { const data_table& dt = element.m_value.get<variant::DataTable>(); m_stack.top().m_attributes .insert("rows", variant(dt.size())) .insert("columns", variant(dt.columns().size())); m_os << start_tag(); if (!dt.columns().empty()) { push("Columns"); m_os << indent() << start_tag(); for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin() ; column_iter != dt.columns().end() ; ++column_iter) { push("Column") .insert("name", variant(column_iter->name())) .insert("type", variant(variant::enum_to_string(column_iter->type()))); m_os << indent(); write_empty_element(); pop(); } m_os << indent() << end_tag(); pop(); } for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin() ; column_iter != dt.columns().end() ; ++column_iter) { push("Column").insert("name", variant(column_iter->name())); m_os << indent() << start_tag(); if (column_iter->type() & variant_base::Primitive) { boost::scoped_ptr<data_table_column_writer> column_writer( make_data_table_column_stream_writer(*column_iter, m_os) ); while (column_writer->has_next()) { push("V"); m_os << indent() << start_tag(); column_writer->write(); m_os << end_tag(); pop(); column_writer->advance(); } } else { variant::const_iterator iter(column_iter->begin()); variant::const_iterator end(column_iter->end()); while (iter != end) { push("V"); m_os << indent(); write_variant(*(iter++)); pop(); } } m_os << indent() << end_tag(); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Buffer: { m_os << start_tag(); const void *data = element.as<void*>(); size_t size = element.size(); if (data!=nullptr && size>0) { unsigned int n = 0; boost::scoped_ptr<char> b64(detail::b64_encode((const char*)data, (unsigned int)size, &n)); if (!b64.get()) { boost::throw_exception(variant_error("Unable to base64 encode data")); } m_os << b64.get(); } m_os << end_tag(); break; } case variant::Object: { const object& obj(element.as<object>()); // write class name m_stack.top().m_attributes .insert("class", variant(obj.name())) .insert("version", variant(obj.version())); m_os << start_tag(); // write parameter dictionary variant params; obj.deflate(params); push("params"); m_os << indent(); write_variant(params); pop(); m_os << indent(); m_os << end_tag(); break; } case variant::Exception: { m_os << start_tag(); exception_data e(element.as<exception_data>()); push("type"); m_os << indent(); write_element(variant(e.type())); pop(); push("message"); m_os << indent(); write_element(variant(e.message())); pop(); if (!e.source().empty()) { push("source"); m_os << indent(); write_element(variant(e.source())); pop(); } if (!e.stack().empty()) { push("stack"); m_os << indent(); write_element(variant(e.stack())); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Array: { const typed_array& a(element.as<typed_array>()); m_stack.top().m_attributes .insert("size", variant(a.size())) .insert("type", variant(variant::enum_to_string(a.type()))); m_os << start_tag(); for (size_t i=0; i<a.size(); ++i) { push(); m_os << indent(); write_element(variant(a[i])); pop(); } m_os << indent(); m_os << end_tag(); break; } default: boost::throw_exception(variant_error("Case exhaustion: " + variant::enum_to_string(element.type()))); }
void xml_writer_impl::write_document(const variant& document) { try { if ((m_mode & xml_mode::NoHeader)==0) { // output the XML header write_header(); } if ((m_mode & xml_mode::Preserve)!=0) { bool first(true); if (document.is<variant::Mapping>()) { std::string element_name; variant::const_iterator it, end(document.end()); for (it=document.begin(); it!=end; ++it) { if (it.key()==xml_text) { boost::throw_exception(variant_error("Encountered text in document node")); } else if (it.key()==xml_attributes) { boost::throw_exception(variant_error("Encountered attributes in document node")); } else if (it.key()==xml_instruction) { if (!first) { m_os << indent(); } write_instruction(it.value()); } else if (it.key()==xml_comment) { if (!first) { m_os << indent(); } write_comment(it.value()); } else { if (element_name.empty()) { element_name = it.key(); } else { boost::throw_exception(variant_error((boost::format("Illegal element %s encountered in document, expecting single element %s at root") % it.key() % element_name).str())); } push(it.key()); if (!first) { m_os << indent(); } write_element(it.value()); pop(); } first = false; } } else { boost::throw_exception(variant_error("Invalid document structure, root node must be a Dictionary or Bag")); } } else { push(); write_variant(document); pop(); } } catch (const std::exception &e) { boost::throw_exception(variant_error(e.what())); } catch (...) { boost::throw_exception(variant_error("Unhandled Exception")); } }
int ss_conf_getsvr(const ss_conf_data_t *conf, const char *product_name, const char *module_name, ss_svr_t *value, const char *comment) { if (NULL == conf) { return SS_CONF_NULL; } if (NULL == value && SS_CONF_READCONF == conf->build) { return SS_CONF_NULL; } if (NULL == module_name) { SS_LOG_WARNING("[ss_conf_getsvr] module name is NULL"); return SS_CONF_NULL; } if (SS_CONF_READCONF != conf->build) { if (write_comment(conf->conf_file,"") != SS_CONF_SUCCESS) { return SS_CONF_NULL; } if (write_comment(conf->conf_file, comment) != SS_CONF_SUCCESS) { return SS_CONF_NULL; } } char conf_name[WORD_SIZE]; char svr_name[WORD_SIZE]; int ret = SS_CONF_SUCCESS; int item_ret; unsigned int tmp; char str_tmp[WORD_SIZE]; //merge product name and module name if (NULL != product_name) { snprintf(conf_name, sizeof(conf_name), "%s_%s", product_name, module_name); } else { snprintf(conf_name, sizeof(conf_name), "%s", module_name); } //to be use show server name snprintf(svr_name, sizeof(svr_name), "_svr_%s_name", conf_name); item_ret = ss_conf_getnstr(conf, svr_name, str_tmp, sizeof(str_tmp), "server name"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { snprintf(value->svr_name, sizeof(value->svr_name), "%s", str_tmp); } //get port snprintf(svr_name, sizeof(svr_name), "_svr_%s_port", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "started sever port"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->port = tmp; } //get read timeout snprintf(svr_name, sizeof(svr_name), "_svr_%s_readtimeout", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "read timeout"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->read_timeout = tmp; } //get write timeout snprintf(svr_name, sizeof(svr_name), "_svr_%s_writetimeout", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "write timeout"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->write_timeout = tmp; } //get thread num snprintf(svr_name, sizeof(svr_name), "_svr_%s_threadnum", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "started thread num"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->threadnum = tmp; } //get connect type snprintf(svr_name, sizeof(svr_name), "_svr_%s_connecttype",conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "connecttype"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->connect_type = tmp; } //get pool type snprintf(svr_name, sizeof(svr_name), "_svr_%s_servertype", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "server type"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->server_type = tmp; } //get cpool size default = 100 unsigned int temp_default = 100; snprintf(svr_name, sizeof(svr_name), "_svr_%s_queuesize", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "queue size", &temp_default); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->queue_size = tmp; } //get sock size default = 500 temp_default = 500; snprintf(svr_name, sizeof(svr_name), "_svr_%s_socksize", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "sock size", &temp_default); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->sock_size = tmp; } //for beauty if(SS_CONF_READCONF != conf->build) { if (fputc('\n',conf->conf_file) == EOF) { return SS_CONF_NULL; } } printf("*********************ret : %d\n------" ,ret); return ret; }
int ss_conf_getfloat(const ss_conf_data_t *conf, const char *name, float *value, const char *comment, const float *default_value) { if (NULL == conf || NULL == name || NULL == value) { return SS_CONF_NULL; } if (conf->build != SS_CONF_READCONF) { if (write_comment(conf->conf_file, comment) != SS_CONF_SUCCESS) { if (default_value != NULL) { fprintf(conf->conf_file, "#[default configure[float], [%s : %f]\n%s : %f", name, *default_value, name, *default_value); return SS_CONF_DEFAULT; } else { fprintf(conf->conf_file, "%s : ", name); } return SS_CONF_SUCCESS; } return SS_CONF_NULL; } *value = 0; char conf_value_str[WORD_SIZE]; int ret; ret = load_str(conf, name, conf_value_str, sizeof(conf_value_str)); if (SS_CONF_LOST == ret) { if (default_value != NULL) { *value = *default_value; SS_LOG_WARNING("int [%s] no found, use default value [%f]", name, *default_value); return SS_CONF_DEFAULT; } SS_LOG_WARNING("load uint fail, no found[%s]", name); return SS_CONF_LOST; } if (is_blank_str(conf_value_str, sizeof(conf_value_str))) { SS_LOG_WARNING("int [%s] is empty", name); return SS_CONF_CHECKFAIL; } float num; char *endptr; errno = 0; num = strtod(conf_value_str, &endptr); if (errno == ERANGE || num < INT_MIN || num > INT_MAX) { SS_LOG_WARNING("int [%s] load error, [%s] overflow", name, conf_value_str); return SS_CONF_OVERFLOW; } if (!is_blank_str(endptr, sizeof(conf_value_str))) { SS_LOG_WARNING("int [%s] load error, [%s] is invalid", name, conf_value_str); return SS_CONF_CHECKFAIL; } if (check_uint64_range(conf, name, num) != SS_CONF_CHECKSUCCESS) { return SS_CONF_OVERFLOW; } *value = num; SS_LOG_TRACE("get int value [%s : %f]", name, *value); return SS_CONF_SUCCESS; }
int ss_conf_getreqsvr(const ss_conf_data_t *conf, const char *product_name, const char *module_name, ss_request_svr_t *value, const char *comment) { if (NULL == conf) { return SS_CONF_NULL; } if (NULL == value && SS_CONF_READCONF == conf->build) { return SS_CONF_NULL; } if (NULL == module_name) { return SS_CONF_NULL; } if (SS_CONF_READCONF != conf->build) { if (write_comment(conf->conf_file,"") != SS_CONF_SUCCESS) { return SS_CONF_NULL; } if (write_comment(conf->conf_file, comment) != SS_CONF_SUCCESS) { return SS_CONF_NULL; } } int ret = SS_CONF_SUCCESS; char conf_name[WORD_SIZE]; if (NULL == product_name) { snprintf(conf_name, sizeof(conf_name), "%s", module_name); } else { snprintf(conf_name, sizeof(conf_name), "%s_%s", product_name, module_name); } char svr_name[WORD_SIZE]; //the name of server int item_ret; unsigned int tmp; char str_tmp[WORD_SIZE]; snprintf(svr_name, sizeof(svr_name), "_svr_%s_name", conf_name); item_ret = ss_conf_getnstr(conf, svr_name, str_tmp, sizeof(str_tmp), "request server name"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { snprintf(value->svr_name, sizeof(value->svr_name), "%s", str_tmp); } //get ip_list snprintf(svr_name, sizeof(svr_name), "_svr_%s_ip", conf_name); item_ret = ss_conf_getnstr(conf, svr_name, str_tmp, sizeof(str_tmp), "request ip list"); if (item_ret != SS_CONF_SUCCESS) { item_ret = ret; } else { item_ret = parse_iplist(svr_name, str_tmp,value->ip_list, &value->num); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } } //get port snprintf(svr_name, sizeof(svr_name), "_svr_%s_port", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "server port"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->port = tmp; } //get read timeout snprintf(svr_name, sizeof(svr_name), "_svr_%s_readtimeout", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "server read timeout"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->read_timeout = tmp; } //get write timeout snprintf(svr_name, sizeof(svr_name), "_svr_%s_writetimeout", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "server write timeout"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->write_timeout = tmp; } //get connect timeout snprintf(svr_name, sizeof(svr_name), "_svr_%s_connecttimeout", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "connect timeout"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->connect_timeout = tmp; } //get max connect num snprintf(svr_name, sizeof(svr_name), "_svr_%s_maxconnect", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "max connect"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->max_connect = tmp; } //get retry time snprintf(svr_name, sizeof(svr_name), "_svr_%s_retry", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "retry time"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->retry = tmp; } //get connect type snprintf(svr_name, sizeof(svr_name), "_svr_%s_connecttype", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "connect type"); if (item_ret != SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->connect_type = tmp; } //get linger snprintf(svr_name, sizeof(svr_name), "_svr_%s_linger", conf_name); item_ret = ss_conf_getuint(conf, svr_name, &tmp, "linger"); if (item_ret == SS_CONF_SUCCESS) { ret = item_ret; } if (value != NULL && SS_CONF_READCONF == conf->build) { value->linger = tmp; } if (SS_CONF_READCONF != conf->build) { if (fputc('\n', conf->conf_file) == EOF) { return SS_CONF_NULL; } } return ret; }
static gboolean attribute_declaration(TreeState *state) { gboolean read_only = IDL_ATTR_DCL(state->tree).f_readonly; char *attribute_name = ATTR_IDENT(state->tree).str; gboolean method_noscript = (IDL_tree_property_get(ATTR_PROPS(state->tree), "noscript") != NULL); gboolean method_notxpcom = (IDL_tree_property_get(ATTR_PROPS(state->tree), "notxpcom") != NULL); GSList *doc_comments = IDL_IDENT(IDL_LIST(IDL_ATTR_DCL (state->tree).simple_declarations).data).comments; if (doc_comments != NULL) { fputs(" ", FILENAME(state)); printlist(FILENAME(state), doc_comments); } #if 0 /* * Disabled here because I can't verify this check against possible * users of the java xpidl backend. */ if (!verify_attribute_declaration(state->tree)) return FALSE; #endif /* Comment */ fputc('\n', FILENAME(state)); write_comment(state); if (method_notxpcom || method_noscript) return TRUE; state->tree = ATTR_TYPE_DECL(state->tree); /* * Write access permission ("public" unless nonscriptable) */ fputs(" ", FILENAME(state)); if (!method_noscript) { fputs("public ", FILENAME(state)); } /* * Write the proper Java return value for the get operation */ if (!xpcom_to_java_type(state)) { return FALSE; } /* * Write the name of the accessor ("get") method. */ fprintf(FILENAME(state), " get%c%s();\n", toupper(attribute_name[0]), attribute_name + 1); if (!read_only) { /* Nonscriptable methods become package-protected */ fputs(" ", FILENAME(state)); if (!method_noscript) { fputs("public ", FILENAME(state)); } /* * Write attribute access method name and return type */ fprintf(FILENAME(state), "void set%c%s(", toupper(attribute_name[0]), attribute_name+1); /* * Write the proper Java type for the set operation */ if (!xpcom_to_java_type(state)) { return FALSE; } /* * Write the name of the formal parameter. */ fputs(" value);\n", FILENAME(state)); } return TRUE; }
static gboolean constant_declaration(TreeState *state) { /* * The C++ header XPIDL module only allows for shorts and longs (ints) * to be constants, so we will follow the same convention */ struct _IDL_CONST_DCL *declaration = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(declaration->ident).str; IDL_tree real_type; gboolean success; gboolean isshort = FALSE; GSList *doc_comments = IDL_IDENT(declaration->ident).comments; /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(declaration->const_type); real_type = real_type ? real_type : declaration->const_type; /* * Consts must be in an interface */ if (!IDL_NODE_UP(IDL_NODE_UP(state->tree)) || IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(state->tree))) != IDLN_INTERFACE) { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was declared outside an interface." " It was ignored.", name)); return TRUE; } /* * Make sure this is a numeric short or long constant. */ success = (IDLN_TYPE_INTEGER == IDL_NODE_TYPE(real_type)); if (success) { /* * We aren't successful yet, we know it's an integer, but what *kind* * of integer? */ switch(IDL_TYPE_INTEGER(real_type).f_type) { case IDL_INTEGER_TYPE_SHORT: /* * We're OK */ isshort = TRUE; break; case IDL_INTEGER_TYPE_LONG: /* * We're OK */ break; default: /* * Whoops, it's some other kind of number */ success = FALSE; } } else { IDL_tree_error(state->tree, "const declaration \'%s\' must be of type short or long", name); return FALSE; } if (doc_comments != NULL) { fputs(" ", FILENAME(state)); printlist(FILENAME(state), doc_comments); } if (success) { fputc('\n', FILENAME(state)); write_comment(state); fprintf(FILENAME(state), " public static final %s %s = %d;\n", (isshort ? "short" : "int"), subscriptIdentifier(state, (char*) name), (int) IDL_INTEGER(declaration->const_exp).value); } else { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was not of type short or long." " It was ignored.", name)); } return TRUE; }
static gboolean method_declaration(TreeState *state) { /* IDL_tree method_tree = state->tree; */ const char* array = NULL; GSList *doc_comments = IDL_IDENT(IDL_OP_DCL(state->tree).ident).comments; struct _IDL_OP_DCL *method = &IDL_OP_DCL(state->tree); gboolean method_notxpcom = (IDL_tree_property_get(method->ident, "notxpcom") != NULL); gboolean method_noscript = (IDL_tree_property_get(method->ident, "noscript") != NULL); IDL_tree iterator = NULL; IDL_tree retval_param = NULL; char *method_name = g_strdup_printf("%c%s", tolower(IDL_IDENT(method->ident).str[0]), IDL_IDENT(method->ident).str + 1); if (doc_comments != NULL) { fputs(" ", FILENAME(state)); printlist(FILENAME(state), doc_comments); } if (method_notxpcom || method_noscript) return TRUE; if (!verify_method_declaration(state->tree)) return FALSE; fputc('\n', FILENAME(state)); write_comment(state); /* * Write beginning of method declaration */ fputs(" ", FILENAME(state)); if (!method_noscript) { /* Nonscriptable methods become package-protected */ fputs("public ", FILENAME(state)); } /* * Write return type * Unlike C++ headers, Java interfaces return the declared * return value; an exception indicates XPCOM method failure. */ if (method_notxpcom || method->op_type_spec) { state->tree = method->op_type_spec; if (!xpcom_to_java_type(state)) { return FALSE; } } else { /* Check for retval attribute */ for (iterator = method->parameter_dcls; iterator != NULL; iterator = IDL_LIST(iterator).next) { IDL_tree original_tree = state->tree; state->tree = IDL_LIST(iterator).data; if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator, "retval")) { retval_param = iterator; array = IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator, "array"); state->tree = IDL_PARAM_DCL(state->tree).param_type_spec; /* * Put in type of parameter */ if (!xpcom_to_java_type(state)) { return FALSE; } if (array) fputs("[]", FILENAME(state)); } state->tree = original_tree; } if (retval_param == NULL) { fputs("void", FILENAME(state)); } } /* * Write method name */ fprintf(FILENAME(state), " %s(", subscriptMethodName(state, method_name)); free(method_name); /* * Write parameters */ for (iterator = method->parameter_dcls; iterator != NULL; iterator = IDL_LIST(iterator).next) { /* Skip "retval" */ if (iterator == retval_param) { continue; } if (iterator != method->parameter_dcls) { fputs(", ", FILENAME(state)); } state->tree = IDL_LIST(iterator).data; if (!xpcom_to_java_param(state)) { return FALSE; } } fputs(")", FILENAME(state)); if (method->raises_expr) { IDL_tree iter = method->raises_expr; IDL_tree dataNode = IDL_LIST(iter).data; fputs(" throws ", FILENAME(state)); fputs(IDL_IDENT(dataNode).str, FILENAME(state)); iter = IDL_LIST(iter).next; while (iter) { dataNode = IDL_LIST(iter).data; fprintf(FILENAME(state), ", %s", IDL_IDENT(dataNode).str); iter = IDL_LIST(iter).next; } } fputs(";\n", FILENAME(state)); return TRUE; }
/*=== write_private_header ================================================== * Creates a private 'C' header file for the 'api_name_lc' API. * * Assumes: gTables contains the processed table information. * * Returns: nothing * * Modifies: Augments the 'file', appending the header information. * * Calls: nothing * * Called By: ? * * History: 08/30/95 MRH Created initial version based on * 'write_private_header()' in create_api.c */ void write_private_header(FILE *header) { char description[2048]; char join_description[1024]; FIELD *field; FIELD *joins; TABLE *table; char bit_type[80]; char define_name[80]; int num_fields; int num_tables; /* * Write header comment */ sprintf(description, "\ Private interface to the '%s' Abstract Datatype. \ This file was automatically generated.", gAPIType); write_header(header, gPrivateHeaderName, description); fprintf(header, "#ifndef _%s_\n", gPrivateHeaderNameUC); fprintf(header, "#define _%s_\n\n", gPrivateHeaderNameUC); /* * Add API definition includes. */ fprintf(header, "#include \"%s\"\n", GAL_API_TYPE_HEADER); /* * Include the type header... */ fprintf(header, "#include \"%s\"\n", gTypeHeaderName); fprintf(header, "\n"); /* * extern "C" if a C++ compiler. */ fprintf(header, "#ifdef %s\n", CPLUSPLUS); fprintf(header, "extern \"C\"\n{\n"); fprintf(header, "#endif\n\n\n"); /* * Don't compile in business rules or validation, by default. */ fprintf(header, "/*\n"); fprintf(header, " * Change these to '#define' to add validation and/or\n"); fprintf(header, " * business rules validation.\n"); fprintf(header, " */\n"); fprintf(header, "#undef %s_%s\n", DO_VALIDATE, gAPINameUC); fprintf(header, "#undef %s_%s\n\n\n", DO_BUSINESS, gAPINameUC); num_fields = 0; for (field = gFields; field; field = field->next) { if (field->exclude || (field->join && ! field->is_master_join)) continue; num_fields++; } sprintf(define_name, NUM_FIELDS, gAPINameUC); write_define(header, define_name, num_fields); fprintf(header, "\n"); num_fields = 0; for (field = gFields; field; field = field->next) { if (field->exclude || (field->join && ! field->is_master_join)) continue; sprintf(define_name, "%s_%s_FPOS", gAPIType, ((field->has_alias) ? field->alias_uc : field->name_uc)); write_define(header, define_name, num_fields); num_fields++; } fprintf(header, "\n"); num_tables = 0; for (table = gTables; table; table = table->next) { num_tables++; } sprintf(define_name, NUM_TABLES, gAPINameUC); write_define(header, define_name, num_tables); fprintf(header, "\n"); num_tables = 0; for (table = gTables; table; table = table->next) { sprintf(define_name, "%s_%s_TPOS", gAPIType, table->name_uc); write_define(header, define_name, num_tables); num_tables++; } fprintf(header, "\n"); write_field_name_array(header, PROTOTYPE); write_table_name_array(header, PROTOTYPE); fprintf(header, "\n\n"); /* * 'OBJECT' structure definition. */ sprintf(description, "%s private interface.", gAPIType); write_comment(header, 0, description); fprintf(header, "typedef struct _gal_%s_data_\n{\n", gAPIName); write_member(header, "GAL_OBJECT_INFO", 0, "info"); fprintf(header, "\n"); sprintf(description, "\ %s is defined in %s. (The public definition file).", gAPIKeyTypeData, gPublicHeaderName); for (field = gFields; field; field = field->next) if (field->is_key) sprintf(description, "%s\n %s", description, ((field->has_alias) ? field->alias_lc : field->name_lc)); write_comment(header, 2, description); write_member(header, gAPIKeyTypeData, 0, "ObjectKey"); fprintf(header, "\n"); sprintf(description, "Table Joins:"); for (field = gFields; field; field = field->next) { if (field->join && field->is_master_join) { sprintf(join_description, "\n '%s.%s' joins to:", field->table->name_uc, ((field->has_alias) ? field->alias_lc : field->name_lc)); strcat(description, join_description); for (joins = field->join; joins && joins != field; joins = joins->join) { if (joins->exclude) continue; sprintf(join_description, "\n %s.%s", joins->table->name_uc, joins->name_lc); strcat(description, join_description); } } } write_comment(header, 2, description); table = NULL; for (field = gFields; field; field = field->next) { if (field->exclude) continue; if (field->join && ! field->is_master_join) continue; if (field->is_key) continue; if (table != field->table) { fprintf(header, "\n"); table = field->table; sprintf(description, "'%s' fields", table->name_uc); write_comment(header, 2, description); } write_object_field(header, field); } fprintf(header, "\n\n"); sprintf(bit_type, BIT_TYPE, gAPINameUC); write_member(header, "char", 0, bit_type); fprintf(header, "\n"); fprintf(header, "} %s,\n", gAPITypeData); fprintf(header, " *%s;\n\n", gAPIType); fprintf(header, "#include \"%s\"\n", GAL_API_PRIVATE_HEADER); /* * Write prototypes for: * object * validate * business rules * database */ fprintf(header, "\n\n"); write_new_function (header, PROTOTYPE); write_unset_function (header, PROTOTYPE); fprintf(header, "\n\n"); fprintf(header, "#ifdef %s_%s\n", DO_VALIDATE, gAPINameUC); write_select_validate(header, PROTOTYPE); write_list_validate (header, PROTOTYPE); if (! gReadOnly) { write_insert_validate(header, PROTOTYPE); write_update_validate(header, PROTOTYPE); } fprintf(header, "#endif\n\n"); fprintf(header, "#ifdef %s_%s\n", DO_BUSINESS, gAPINameUC); write_select_business(header, PROTOTYPE); write_list_business (header, PROTOTYPE); if (! gReadOnly) { write_insert_business(header, PROTOTYPE); write_update_business(header, PROTOTYPE); } fprintf(header, "#endif\n\n"); write_select_database(header, PROTOTYPE); write_list_database (header, PROTOTYPE); if (! gReadOnly) { write_insert_database(header, PROTOTYPE); write_update_database(header, PROTOTYPE); } fprintf(header, "\n\n"); /* * extern "C" if a C++ compiler. */ fprintf(header, "#ifdef %s\n", CPLUSPLUS); fprintf(header, "}\n"); fprintf(header, "#endif\n\n"); fprintf(header, "#endif /* #ifndef _%s_ */\n", gPrivateHeaderNameUC); fflush(header); }
prolog(FILE *outfile, register chainp p) #endif { int addif, addif0, i, nd; ftnint size; int *ac; register Namep q; register struct Dimblock *dp; chainp p0, p1; if(procclass == CLBLOCK) return; p0 = p; p1 = p = argsort(p); wrote_comment = 0; comment_file = outfile; ac = 0; /* Compute the base addresses and offsets for the array parameters, and assign these values to local variables */ addif = addif0 = nentry > 1; for(; p ; p = p->nextp) { q = (Namep) p->datap; if(dp = q->vdim) /* if this param is an array ... */ { expptr Q, expr; /* See whether to protect the following with an if. */ /* This only happens when there are multiple entries. */ nd = dp->ndim - 1; if (addif0) { if (!ac) ac = count_args(); if (ac[q->argno] == nentry) addif = 0; else if (dp->basexpr || dp->baseoffset->constblock.Const.ci) addif = 1; else for(addif = i = 0; i <= nd; i++) if (dp->dims[i].dimexpr && (i < nd || !q->vlastdim)) { addif = 1; break; } if (addif) { write_comment(); nice_printf(outfile, "if (%s) {\n", /*}*/ q->cvarname); next_tab(outfile); } } for(i = 0 ; i <= nd; ++i) /* Store the variable length of each dimension (which is fixed upon runtime procedure entry) into a local variable */ if ((Q = dp->dims[i].dimexpr) && (i < nd || !q->vlastdim)) { expr = (expptr)cpexpr(Q); write_comment(); out_and_free_statement (outfile, mkexpr (OPASSIGN, fixtype(cpexpr(dp->dims[i].dimsize)), expr)); } /* if dp -> dims[i].dimexpr */ /* size will equal the size of a single element, or -1 if the type is variable length character type */ size = typesize[ q->vtype ]; if(q->vtype == TYCHAR) if( ISICON(q->vleng) ) size *= q->vleng->constblock.Const.ci; else size = -1; /* Fudge the argument pointers for arrays so subscripts * are 0-based. Not done if array bounds are being checked. */ if(dp->basexpr) { /* Compute the base offset for this procedure */ write_comment(); out_and_free_statement (outfile, mkexpr (OPASSIGN, cpexpr(fixtype(dp->baseoffset)), cpexpr(fixtype(dp->basexpr)))); } /* if dp -> basexpr */ if(! checksubs) { if(dp->basexpr) { expptr tp; /* If the base of this array has a variable adjustment ... */ tp = (expptr) cpexpr (dp -> baseoffset); if(size < 0 || q -> vtype == TYCHAR) tp = mkexpr (OPSTAR, tp, cpexpr (q -> vleng)); write_comment(); tp = mkexpr (OPMINUSEQ, mkconv (TYADDR, (expptr)p->datap), mkconv(TYINT, fixtype (fixtype (tp)))); /* Avoid type clash by removing the type conversion */ tp = prune_left_conv (tp); out_and_free_statement (outfile, tp); } else if(dp->baseoffset->constblock.Const.ci != 0) { /* if the base of this array has a nonzero constant adjustment ... */ expptr tp; write_comment(); if(size > 0 && q -> vtype != TYCHAR) { tp = prune_left_conv (mkexpr (OPMINUSEQ, mkconv (TYADDR, (expptr)p->datap), mkconv (TYINT, fixtype (cpexpr (dp->baseoffset))))); out_and_free_statement (outfile, tp); } else { tp = prune_left_conv (mkexpr (OPMINUSEQ, mkconv (TYADDR, (expptr)p->datap), mkconv (TYINT, fixtype (mkexpr (OPSTAR, cpexpr (dp -> baseoffset), cpexpr (q -> vleng)))))); out_and_free_statement (outfile, tp); } /* else */ } /* if dp -> baseoffset -> const */ } /* if !checksubs */ if (addif) { nice_printf(outfile, /*{*/ "}\n"); prev_tab(outfile); } } } if (wrote_comment) nice_printf (outfile, "\n/* Function Body */\n"); if (ac) free((char *)ac); if (p0 != p1) frchain(&p1); } /* prolog */