static bool append_value(bson_t* bson, const char* key, size_t length, object_t* value) { switch (value->type) { case type_nil: bson_append_null(bson, key, length); break; case type_bool: bson_append_bool(bson, key, length, value->b); break; case type_double: bson_append_double(bson, key, length, value->d); break; case type_str: bson_append_utf8(bson, key, length, value->str, value->l); break; case type_int: append_int(bson, key, length, value->i); break; case type_uint: append_int(bson, key, length, (int64_t)value->u); break; case type_map: { bson_t child; bson_append_document_begin(bson, key, length, &child); append_document(&child, value); bson_append_document_end(bson, &child); } break; case type_array: { bson_t child; bson_append_array_begin(bson, key, length, &child); append_array(&child, value); bson_append_array_end(bson, &child); } break; default: return false; } return true; }
/*----------------Set up to send to the laserwriter------------------------*/ void lw_laser_open(void) { extern int getpid(void); char pps[]=".eps"; filnam=address; if(!filename_set) { strcpy(filnam, "/tmp/.cg"); append_int(getpid()); strcat(filnam, "-"); append_int(counter); counter++; filnam=strcat(filnam, pps); } if(useStandardOutput) cgstream = stdout; /* output to stdout */ else cgstream = fopen(filnam, "a"); /* open for append */ if(cgstream == NULL) { fprintf(stderr, "Cannot open %s for PS output\n", filnam); return; } return; /* successful file/device open */ }
void x264x_xlinkedx_xoptx_xo_storage_initializer_() { char buffer[1024]; char* ss; sprintf(buffer, "call x264x_xlinkedx_xoptx_xo_storage_initializer_ "); append_int(buffer,0); ADD_SPACE__(buffer); append_int(buffer,0); ADD_SPACE__(buffer); send_packet_and_wait_for_response(buffer,strlen(buffer)+1,"localhost",9999); return; }
void dct_engine() { char buffer[1024]; char* ss; sprintf(buffer, "call dct_engine "); append_int(buffer,0); ADD_SPACE__(buffer); append_int(buffer,0); ADD_SPACE__(buffer); send_packet_and_wait_for_response(buffer,strlen(buffer)+1,"localhost",9999); return; }
static int build_csv_record(char *buf, size_t bufsize, struct cw_cdr *cdr) { buf[0] = '\0'; /* Account code */ append_string(buf, cdr->accountcode, bufsize); /* Source */ append_string(buf, cdr->src, bufsize); /* Destination */ append_string(buf, cdr->dst, bufsize); /* Destination context */ append_string(buf, cdr->dcontext, bufsize); /* Caller*ID */ append_string(buf, cdr->clid, bufsize); /* Channel */ append_string(buf, cdr->channel, bufsize); /* Destination Channel */ append_string(buf, cdr->dstchannel, bufsize); /* Last Application */ append_string(buf, cdr->lastapp, bufsize); /* Last Data */ append_string(buf, cdr->lastdata, bufsize); /* Start Time */ append_date(buf, cdr->start, bufsize); /* Answer Time */ append_date(buf, cdr->answer, bufsize); /* End Time */ append_date(buf, cdr->end, bufsize); /* Duration */ append_int(buf, cdr->duration, bufsize); /* Billable seconds */ append_int(buf, cdr->billsec, bufsize); /* Disposition */ append_string(buf, cw_cdr_disp2str(cdr->disposition), bufsize); /* AMA Flags */ append_string(buf, cw_cdr_flags2str(cdr->amaflags), bufsize); #ifdef CSV_LOGUNIQUEID /* Unique ID */ append_string(buf, cdr->uniqueid, bufsize); #endif #ifdef CSV_LOGUSERFIELD /* append the user field */ append_string(buf, cdr->userfield,bufsize); #endif /* If we hit the end of our buffer, log an error */ if (strlen(buf) < bufsize - 5) { /* Trim off trailing comma */ buf[strlen(buf) - 1] = '\0'; strncat(buf, "\n", bufsize - strlen(buf) - 1); return 0; } return -1; }
/* Return: is the device_name (hostname) */ std::string SQL_Devices::sql_find_preferred_name ( int mUser_id, std::string mPreferredName ) { query_string = "SELECT preferred_name,hostname FROM "; query_string += table_name; query_string += " WHERE "; query_string += " user_id="; query_string += append_int( mUser_id ); query_string += " AND preferred_name='"; query_string += mPreferredName; query_string += "';"; int retval = query(true); // Now for all results, do the regex_search: goto_first_row(); bool found=false; std::regex exp; std::smatch match; while (m_row) { if (m_row[0]) exp=m_row[0]; found = std::regex_search( mPreferredName, match, exp ); if (found) return m_row[1]; // return device_name; goto_next_row(); } return NULL; }
// IN_ACCESS, IN_MODIFY, IN_CLOSE_NOWRITE, IN_OPEN, IN_DELETE, IN_DELETE_SELF int add_watch(void* inotify, char* path) { int watch_fd = inotify_add_watch(((inotify_t*)inotify)->instance, path, /*IN_ATTRIB | */ IN_CLOSE_WRITE | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE); if (watch_fd == -1) { perror("inotify_add_watch"); return -1; } append_int(&((inotify_t*)inotify)->watch_fds, watch_fd); append_str(&((inotify_t*)inotify)->files, path); return 0; }
int main() { printf("auto-array test program\n"); struct Integer_array my_array; create_int_array(&my_array, 4); for (int i=0; i<10; i++) { append_int(&my_array, 2*i); } print_array(&my_array); return 0; }
int SQL_Devices::sql_find ( int mUser_id, std::string mDevice_name ) { query_string = "SELECT * FROM "; query_string += table_name; query_string += " "; query_string += " WHERE hostname='"; // device_name is hostname query_string += mDevice_name; query_string += "' AND user_id="; query_string += append_int( mUser_id ); query_string += ";"; int retval = query(true); m_row = mysql_fetch_row( m_result ); if (m_row) _id = atoi(m_row[0]); printf("device_id = %d\n", _id ); return retval; }
void test_devices_db() { // Add some samples rows : connect_to_users_db(); std::string mRegex; int user_id = sql_users.sql_find("stenniswood"); printf("User_id=%d\n", user_id ); sql_devices.get_all_device_names_regex ( user_id, mRegex ); Sentence phrase = "main TV"; int result = phrase.regex_find( mRegex ); printf("REGEX result: %d\n", result ); if (result) { std::string tmp = phrase.m_sentence.regex_matches[1]; printf("REGEX MATCH: %s\n", tmp.c_str()); } std::string tmp = "("; tmp += append_int( user_id ); std::string tmp1 = tmp + ", 'successroad1', '(main TV|TV)', 'RPI')"; std::string tmp2 = tmp + ", 'successroad2', '(bedroom TV)', 'RPI')"; std::string tmp3 = tmp + ", 'portable', '(LCD pi)', 'RPI')"; // sql_devices.sql_add_if_not_already(user_id, dev_info_map ); // sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp1, "successroad1"); // sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp2, "successroad2"); // sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp3, "portable"); sql_devices.sql_find( user_id,"successroad1" ); sql_devices.print_results(); sql_devices.sql_find( user_id,"successroad2" ); sql_devices.print_results(); sql_devices.sql_find( user_id,"portable" ); sql_devices.print_results(); printf("Done with test_devices_db()\n"); }
/* * Like 'vsprintf', but ensures the target is big enough, resizing if * necessary. */ void archive_string_vsprintf(struct archive_string *as, const char *fmt, va_list ap) { char long_flag; intmax_t s; /* Signed integer temp. */ uintmax_t u; /* Unsigned integer temp. */ const char *p, *p2; const wchar_t *pw; if (archive_string_ensure(as, 64) == NULL) __archive_errx(1, "Out of memory"); if (fmt == NULL) { as->s[0] = 0; return; } for (p = fmt; *p != '\0'; p++) { const char *saved_p = p; if (*p != '%') { archive_strappend_char(as, *p); continue; } p++; long_flag = '\0'; switch(*p) { case 'j': case 'l': case 'z': long_flag = *p; p++; break; } switch (*p) { case '%': archive_strappend_char(as, '%'); break; case 'c': s = va_arg(ap, int); archive_strappend_char(as, (char)s); break; case 'd': switch(long_flag) { case 'j': s = va_arg(ap, intmax_t); break; case 'l': s = va_arg(ap, long); break; case 'z': s = va_arg(ap, ssize_t); break; default: s = va_arg(ap, int); break; } append_int(as, s, 10); break; case 's': switch(long_flag) { case 'l': pw = va_arg(ap, wchar_t *); if (pw == NULL) pw = L"(null)"; if (archive_string_append_from_wcs(as, pw, wcslen(pw)) != 0 && errno == ENOMEM) __archive_errx(1, "Out of memory"); break; default: p2 = va_arg(ap, char *); if (p2 == NULL) p2 = "(null)"; archive_strcat(as, p2); break; } break; case 'S': pw = va_arg(ap, wchar_t *); if (pw == NULL) pw = L"(null)"; if (archive_string_append_from_wcs(as, pw, wcslen(pw)) != 0 && errno == ENOMEM) __archive_errx(1, "Out of memory"); break; case 'o': case 'u': case 'x': case 'X': /* Common handling for unsigned integer formats. */ switch(long_flag) { case 'j': u = va_arg(ap, uintmax_t); break; case 'l': u = va_arg(ap, unsigned long); break; case 'z': u = va_arg(ap, size_t); break; default: u = va_arg(ap, unsigned int); break; } /* Format it in the correct base. */ switch (*p) { case 'o': append_uint(as, u, 8); break; case 'u': append_uint(as, u, 10); break; default: append_uint(as, u, 16); break; } break; default: /* Rewind and print the initial '%' literally. */ p = saved_p; archive_strappend_char(as, *p); } } }
void MenuItem::load_size_options(int mSize_id, int mRestaurant_id) { query_string = "select * from "; query_string += sql_global_knowledge_name; query_string += ".sizes_options WHERE size_id="; query_string += append_int(mSize_id); query_string += " and restaurant_id="; query_string += append_int(mRestaurant_id); query_string += ";"; // restaurant = restaurant_id; but we don't know the restaurant id. printf("%s\n", query_string.c_str() ); query(true); int type=-1; PickOne one; AdditionalToppings top; SuperString extra_cost; StandardOptions standard; while ((row = mysql_fetch_row(result)) ) { type = -1; if (row[6]) type = atoi(row[6]); extra_cost = row[4]; extra_cost.split(','); extra_cost.trim_spaces(); switch(type) { case 0 : standard.name = row[3]; standard.name.split(','); standard.name.trim_spaces(); for (int i=0; i < standard.name.m_split_words.size(); i++) standard.additional_cost[standard.name.m_split_words[i] ] = stof(extra_cost.m_split_words[i]); // .convert_to_float(); if (row[5]) standard.comment = row[5]; m_standard_toppings.push_back(standard); break; case 1 : one.name = row[3]; one.name.split_wordlist(); // "(small|medium|large)" Want to do this because the prices will be a map based on these names. for (int i=0; i < standard.name.m_split_words.size(); i++) one.additional_cost[one.name.m_split_words[i] ] = stof(extra_cost.m_split_words[i]); // .convert_to_float(); if (row[5]) one.comment = row[5]; m_required_options.push_back(one); break; case 2 : top.name = row[3]; top.name.split(','); top.name.trim_spaces(); for (int i=0; i < standard.name.m_split_words.size(); i++) top.additional_cost[top.name.m_split_words[i]] = stof(extra_cost.m_split_words[i]); // convert_to_float(); if (row[5]) top.comment = row[5]; m_additional_toppings.push_back(top); break; default: break; } } mysql_free_result( result ); }
static void xbt_log_layout_format_dynamic(xbt_log_layout_t l, xbt_log_event_t ev, const char *fmt, xbt_log_appender_t app) { xbt_strbuff_t buff = xbt_strbuff_new(); char tmpfmt[50]; int precision = -1; int length = -1; char *q = l->data; char *tmp; char *tmp2; while (*q != '\0') { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *) l->data); abort(); case '%': xbt_strbuff_append(buff, "%"); break; case 'n': /* platform-dependant line separator (LOG4J compliant) */ xbt_strbuff_append(buff, "\n"); break; case 'e': /* plain space (SimGrid extension) */ xbt_strbuff_append(buff, " "); break; case '.': /* precision specifyier */ q++; sscanf(q, "%d", &precision); q += (precision>9?2:1); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ sscanf(q, "%d", &length); q += (length>9?2:1); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ append_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ append_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ append_string(gras_os_myname()); break; case 't': /* thread name; LOG4J compliant */ append_string(xbt_thread_self_name()); break; case 'P': /* process name; SimGrid extension */ append_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ append_int((*xbt_getpid) ()); break; case 'F': /* file name; LOG4J compliant */ append_string(ev->fileName); break; case 'l': /* location; LOG4J compliant */ append2("%s:%d", ev->fileName, ev->lineNum); precision = -1; /* Ignored */ break; case 'L': /* line number; LOG4J compliant */ append_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ append_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) { xbt_ex_t e; int i; e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; e.msg = NULL; e.remote = 0; xbt_backtrace_current(&e); if (*q == 'B') { append_string(e.bt_strings[2] + 8); } else { for (i = 2; i < e.used; i++) { append_string(e.bt_strings[i] + 8); xbt_strbuff_append(buff, "\n"); } } xbt_ex_free(e); } #else append_string("(no backtrace on this arch)"); #endif break; case 'd': /* date; LOG4J compliant */ append_double(gras_os_time()); break; case 'r': /* application age; LOG4J compliant */ append_double(gras_os_time() - format_begin_of_time); break; case 'm': /* user-provided message; LOG4J compliant */ tmp2 = bvprintf(fmt, ev->ap_copy); append_string(tmp2); free(tmp2); break; default: fprintf(stderr, ERRMSG, *q, (char *) l->data); abort(); } q++; } else { char tmp2[2]; tmp2[0] = *(q++); tmp2[1] = '\0'; xbt_strbuff_append(buff, tmp2); } } app->do_append(app, buff->data); xbt_strbuff_free(buff); }
z_string & z_string::operator << (const int i) { return append_int(i); }