static void show_utf8(FILE *f, const char *text, const char *pre, const char *post, int is_attribute) { int len; if (!text) return; while (isspace(*text)) text++; len = strlen(text); if (!len) return; while (len && isspace(text[len-1])) len--; /* FIXME! Quoting! */ fputs(pre, f); quote(f, text, is_attribute); fputs(post, f); }
static int makedir(const string& name, std::ostream& msg, bool user_only = false) { StreamAction action(msg, "Creating " + quote(name + "/")); mode_t mask = umask(0); umask(mask); mode_t mode; if (user_only) mode = S_IRWXU & ~mask; else mode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~mask; int ret = mkdir(name.chars(), mode); if (ret != 0) action.failed(strerror(errno)); return ret; }
static void xheader_set_keyword_equal (char *kw, char *eq) { bool global = true; char *p = eq; if (eq[-1] == ':') { p--; global = false; } while (p > kw && isspace ((unsigned char) *p)) p--; *p = 0; for (p = eq + 1; *p && isspace ((unsigned char) *p); p++) ; if (strcmp (kw, "delete") == 0) { if (xheader_protected_pattern_p (p)) USAGE_ERROR ((0, 0, _("Pattern %s cannot be used"), quote (p))); xheader_list_append (&keyword_pattern_list, p, NULL); } else if (strcmp (kw, "exthdr.name") == 0) assign_string (&exthdr_name, p); else if (strcmp (kw, "globexthdr.name") == 0) assign_string (&globexthdr_name, p); else if (strcmp (kw, "exthdr.mtime") == 0) assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p); else if (strcmp (kw, "globexthdr.mtime") == 0) assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p); else { if (xheader_protected_keyword_p (kw)) USAGE_ERROR ((0, 0, _("Keyword %s cannot be overridden"), kw)); if (global) xheader_list_append (&keyword_global_override_list, kw, p); else xheader_list_append (&keyword_override_list, kw, p); } }
void compute_output_file_names (void) { char const *name[4]; int i; int j; int names = 0; compute_file_name_parts (); /* If not yet done. */ if (!src_extension) src_extension = ".c"; if (!header_extension) header_extension = ".h"; name[names++] = parser_file_name = spec_outfile ? spec_outfile : concat2 (all_but_ext, src_extension); if (defines_flag) { if (! spec_defines_file) spec_defines_file = concat2 (all_but_ext, header_extension); name[names++] = spec_defines_file; } if (graph_flag) { if (! spec_graph_file) spec_graph_file = concat2 (all_but_tab_ext, ".vcg"); name[names++] = spec_graph_file; } if (report_flag) { spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT); name[names++] = spec_verbose_file; } for (j = 0; j < names; j++) for (i = 0; i < j; i++) if (strcmp (name[i], name[j]) == 0) warn (_("conflicting outputs to file %s"), quote (name[i])); }
// virtual bool CEvaluationNodeCall::setData(const Data & data) { mData = unQuote(data); // We force quoting if the round trip unquote, quote does not recover the original input if (isKeyword(mData)) { mQuotesRequired = true; } if (mData != data && quote(mData) != data) { mQuotesRequired = true; } mRegisteredFunctionCN = std::string(""); return true; }
static void SaveTipCountCB(Widget, XtPointer = 0, XtPointer = 0) { create_session_dir(DEFAULT_SESSION); const string file = session_tips_file(); std::ofstream os(file.chars()); os << "! " DDD_NAME " tips file\n" "\n" << app_value(XtNstartupTipCount, itostring(++app_data.startup_tip_count)) << "\n"; os.close(); if (os.bad()) { post_error("Cannot save tip count in " + quote(file), "options_save_error"); } }
void muscle_percent_define_insert (char const *var, location variable_loc, muscle_kind kind, char const *value, muscle_percent_define_how how) { /* Backward compatibility. */ char *variable = muscle_percent_variable_update (var, variable_loc, &value); uniqstr name = muscle_name (variable, NULL); uniqstr loc_name = muscle_name (variable, "loc"); uniqstr syncline_name = muscle_name (variable, "syncline"); uniqstr how_name = muscle_name (variable, "how"); uniqstr kind_name = muscle_name (variable, "kind"); /* Command-line options are processed before the grammar file. */ if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE && muscle_find_const (name)) { muscle_percent_define_how how_old = atoi (muscle_find_const (how_name)); unsigned i = 0; if (how_old == MUSCLE_PERCENT_DEFINE_F) goto end; complain_indent (&variable_loc, complaint, &i, _("%%define variable %s redefined"), quote (variable)); i += SUB_INDENT; location loc = muscle_percent_define_get_loc (variable); complain_indent (&loc, complaint, &i, _("previous definition")); } MUSCLE_INSERT_STRING (name, value); muscle_insert (loc_name, ""); muscle_location_grow (loc_name, variable_loc); muscle_insert (syncline_name, ""); muscle_syncline_grow (syncline_name, variable_loc); muscle_user_name_list_grow ("percent_define_user_variables", variable, variable_loc); MUSCLE_INSERT_INT (how_name, how); MUSCLE_INSERT_STRING (kind_name, muscle_kind_string (kind)); end: free (variable); }
// ChangeDirectory program with given arguments static void gdbChangeDirectoryDCB(Widget, XtPointer, XtPointer) { Widget text = XmSelectionBoxGetChild(cd_dialog, XmDIALOG_TEXT); String _args = XmTextGetString(text); string args(_args); XtFree(_args); string path = source_view->full_path(args); switch (gdb->type()) { case PERL: gdb_command("chdir " + quote(path, '\'')); break; case BASH: gdb_command("eval cd " + path); break; default: gdb_command("cd " + path); } }
// Reformulate explicit user constraint so it matches the format of the constraint parser string ConstraintFomatter::consToFormula(const Model & model, const CompID ID) { string formula; // Resulting formula specifying all the constraints formula = "tt"; for (const string constraint : model.components[ID].constraints) { try { formula.append(" & " + addBrackets(formatConstraint(constraint, model, ID))); } catch (exception & e) { throw runtime_error("Error while parsing the constraint: " + quote(constraint) + ". " + e.what()); } } return addBrackets(formula); }
void dump_rec(const char* var, int i, struct initrec* p) { char** a; printf("static struct initrec %s%i = {\n", var, i); printf("\t.name = %s,\n", quote(p->name)); printf("\t.rlvl = %i,\n", p->rlvl); printf("\t.flags = %i,\n", p->flags); printf("\t.pid = %i,\n", p->pid); printf("\t.lastrun = %li,\n", (long)p->lastrun); printf("\t.lastsig = %li,\n", (long)p->lastsig); printf("\t.argv = { "); for(a = p->argv; *a; a++) // no quoting for now printf("\"%s\", ", *a); printf(" NULL }\n"); printf("};\n"); }
void start_graph (FILE *fout) { fprintf (fout, _("// Generated by %s.\n" "// Report bugs to <%s>.\n" "// Home page: <%s>.\n" "\n"), PACKAGE_STRING, PACKAGE_BUGREPORT, PACKAGE_URL); fprintf (fout, "digraph %s\n" "{\n", quote (grammar_file)); fprintf (fout, " node [fontname = courier, shape = box, colorscheme = paired6]\n" " edge [fontname = courier]\n" "\n"); }
bool ClientImpl::sync_upload( std::string remote_file, std::string local_file, callback_t callback, progress_t progress ) noexcept { bool is_existed = FileInfo::exists(local_file); if (!is_existed) return false; auto root_urn = Urn(this->webdav_root, true); auto file_urn = root_urn + remote_file; std::ifstream file_stream(local_file, std::ios::binary); auto size = FileInfo::size(local_file); Request request(this->options()); auto url = this->webdav_hostname + file_urn.quote(request.handle); Data response = { 0, 0, 0 }; request.set(CURLOPT_UPLOAD, 1L); request.set(CURLOPT_URL, url.c_str()); request.set(CURLOPT_READDATA, (size_t)&file_stream); request.set(CURLOPT_READFUNCTION, (size_t)Callback::Read::stream); request.set(CURLOPT_INFILESIZE_LARGE, (curl_off_t)size); request.set(CURLOPT_BUFFERSIZE, (long)Client::buffer_size); request.set(CURLOPT_WRITEDATA, (size_t)&response); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); if (progress != nullptr) { request.set(CURLOPT_XFERINFOFUNCTION, (size_t)progress.target<progress_funptr>()); request.set(CURLOPT_NOPROGRESS, 0L); } bool is_performed = request.perform(); if (callback != nullptr) callback(is_performed); return is_performed; }
static int love_album(struct mpdcron_connection *conn, bool love, const char *expr) { int changes; char *esc_album, *myexpr; struct mpd_song *song; if (expr != NULL) { if (!mpdcron_love_album_expr(conn, love, expr, &changes)) { eulog(LOG_ERR, "Failed to %s album: %s", love ? "love" : "hate", conn->error->message); return 1; } } else { if ((song = load_current_song()) == NULL) return 1; else if (mpd_song_get_tag(song, MPD_TAG_ALBUM, 0) == NULL) { eulog(LOG_ERR, "Current playing song has no album tag!"); mpd_song_free(song); return 1; } esc_album = quote(mpd_song_get_tag(song, MPD_TAG_ALBUM, 0)); myexpr = g_strdup_printf("name=%s", esc_album); g_free(esc_album); mpd_song_free(song); if (!mpdcron_love_album_expr(conn, love, myexpr, &changes)) { eulog(LOG_ERR, "Failed to %s current playing album: %s", love ? "love" : "hate", conn->error->message); g_free(myexpr); return 1; } g_free(myexpr); } printf("Modified %d entries\n", changes); return 0; }
bool PostgreAdapter::update(std::string table_I, std::map<std::string, std::string> attributes_I, std::map<std::string, std::string> where_I) { std::ostringstream query(""); query << "UPDATE " << table_I << " SET "; for (auto& it: attributes_I) { if (it != *attributes_I.begin()) query << ", "; query << it.first << " = " << quote(it.second); } query << makeWhere(where_I); return tryQuery(query.str()); }
void CChemEqInterface::addModifier(const std::string & name) { std::pair< std::string, std::string > Modifier = CMetabNameInterface::splitDisplayName(name); //is the name already in the list std::vector< std::string >::const_iterator it, itEnd = mModifierNames.end(); std::vector< std::string >::const_iterator itComp = mModifierCompartments.begin(); for (it = mModifierNames.begin(); it != itEnd; ++it, ++itComp) if (Modifier.first == *it && Modifier.second == *itComp) break; if (it == itEnd) { mModifierNames.push_back(Modifier.first); mModifierMult.push_back(1.0); mModifierCompartments.push_back(Modifier.second); mModifierDisplayNames.push_back(quote(name)); } }
bool BrowserFlow::undelete(bool, QString & warning, QString & renamed) { if (! deletedp()) return FALSE; if (def->get_start_node()->deletedp() || def->get_end_node()->deletedp()) { warning += QString("<li><b>") + quote(name) + "</b> " + TR("from") + " <b>" + def->get_start_node()->full_name() + "</b> " + TR("to") + " <b>" + def->get_end_node()->full_name() + "</b>\n"; return FALSE; } is_deleted = FALSE; def->undelete(warning, renamed); package_modified(); repaint(); return TRUE; }
strings_t Client::list(std::string remote_directory) noexcept { auto clientImpl = GetImpl(this); bool is_existed = this->check(remote_directory); if (!is_existed) return strings_t(); bool is_directory = this->is_dir(remote_directory); if (!is_directory) return strings_t(); auto target_urn = Urn(clientImpl->ftps_root, true) + remote_directory; target_urn = Urn(target_urn.path(), true); Header header = { "Accept: */*", "Depth: 1" }; Data data = { 0, 0, 0 }; Request request(clientImpl->options()); auto url = clientImpl->ftps_hostname + target_urn.quote(request.handle); request.set(CURLOPT_CUSTOMREQUEST, "PROPFIND"); request.set(CURLOPT_URL, url.c_str()); request.set(CURLOPT_HTTPHEADER, (struct curl_slist *)header.handle); request.set(CURLOPT_HEADER, 0); request.set(CURLOPT_WRITEDATA, (size_t)&data); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); bool is_performed = request.perform(); if (!is_performed) return strings_t(); strings_t resources; // TODO return resources; }
static int count_genre(struct mpdcron_connection *conn, const char *expr, const char *count) { int changes; char *esc_genre, *myexpr; struct mpd_song *song; if (expr != NULL) { if (!mpdcron_count_genre_expr(conn, expr, count, &changes)) { eulog(LOG_ERR, "Failed to change play count of genre: %s", conn->error->message); return 1; } } else { if ((song = load_current_song()) == NULL) return 1; else if (mpd_song_get_tag(song, MPD_TAG_GENRE, 0) == NULL) { eulog(LOG_ERR, "Current playing song has no genre tag!"); mpd_song_free(song); return 1; } esc_genre = quote(mpd_song_get_tag(song, MPD_TAG_GENRE, 0)); myexpr = g_strdup_printf("name=%s", esc_genre); g_free(esc_genre); mpd_song_free(song); if (!mpdcron_count_genre_expr(conn, myexpr, count, &changes)) { eulog(LOG_ERR, "Failed to change play count of count current playing genre: %s", conn->error->message); g_free(myexpr); return 1; } g_free(myexpr); } printf("Modified %d entries\n", changes); return 0; }
static int rmtag_artist(struct mpdcron_connection *conn, const char *tag, const char *expr) { int changes; if (expr != NULL) { if (!mpdcron_rmtag_artist_expr(conn, expr, tag, &changes)) { eulog(LOG_ERR, "Failed to remove tag from artist: %s", conn->error->message); return 1; } } else { char *esc_artist, *myexpr; struct mpd_song *song; if ((song = load_current_song()) == NULL) return 1; else if (mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) == NULL) { eulog(LOG_ERR, "Current playing song has no artist tag!"); mpd_song_free(song); return 1; } esc_artist = quote(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0)); myexpr = g_strdup_printf("name=%s", esc_artist); g_free(esc_artist); mpd_song_free(song); if (!mpdcron_rmtag_artist_expr(conn, myexpr, tag, &changes)) { eulog(LOG_ERR, "Failed to remove tag from current playing artist: %s", conn->error->message); g_free(myexpr); return 1; } g_free(myexpr); } printf("Modified %d entries\n", changes); return 0; }
//-----------------------------------------------------------------------------------------------------// STDMETHODIMP CMarketDataProvider::_AcceptQuote(const QuoteUpdateParams& Params, QuoteUpdateInfo& Info) { HRESULT __Result = E_FAIL; try { CTicker ticker(Params); CQuote quote(Info); AcceptQuote(ticker, quote); __Result = S_OK; } catch (_com_error& err) { TRACE_COM_ERROR(err); } catch (...) { TRACE_UNKNOWN_ERROR(); } return __Result; };
// Parsing DispValue *DispValue::parse(DispValue *parent, int depth, string& value, const string& full_name, const string& print_name, DispValueType type) { if (value_hook != 0) { DispValue *dv = (*value_hook)(value); if (dv != 0) { // Just take values from given element #if LOG_CREATE_VALUES std::clog << "External value " << quote(dv->full_name()) << "\n"; #endif return dv; } } return new DispValue(parent, depth, value, full_name, print_name, type); }
bool ClientImpl::sync_download_to( std::string remote_file, char * & buffer_ptr, unsigned long long int & buffer_size, callback_t callback, progress_t progress ) noexcept { bool is_existed = this->check(remote_file); if (!is_existed) return false; auto root_urn = Urn(this->webdav_root, true); auto file_urn = root_urn + remote_file; Data data = { 0, 0, 0 }; Request request(this->options()); auto url = this->webdav_hostname + file_urn.quote(request.handle); request.set(CURLOPT_CUSTOMREQUEST, "GET"); request.set(CURLOPT_URL, url.c_str()); request.set(CURLOPT_HEADER, 0L); request.set(CURLOPT_WRITEDATA, (size_t)&data); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); if (progress != nullptr) { request.set(CURLOPT_XFERINFOFUNCTION, (size_t)progress.target<progress_funptr>()); request.set(CURLOPT_NOPROGRESS, 0L); } bool is_performed = request.perform(); if (callback != nullptr) callback(is_performed); if (!is_performed) return false; buffer_ptr = data.buffer; buffer_size = data.size; return true; }
program() { var filename=COMMAND.a(2); var itemids=erase(COMMAND,1,0,0); eraser(itemids,1,0,0); var silent=index(ucase(OPTIONS),"S"); if (not filename or not itemids) abort("Syntax is 'delete filename itemid ... (S=Silent)'"); var file; if (not open(filename,file)) abort(filename^" file does not exist."); var sep=0; var posn=1; var ndeleted=0; do { var itemid=remove(itemids,posn,sep); if (itemid=="*") { clearfile(file); if (not silent) printl("All records deleted"); stop(); } if (deleterecord(file,itemid)) ++ndeleted; else if (not silent) printl(quote(itemid)^" does not exist."); } while (sep); if (not silent) printl(ndeleted^" record(s) deleted."); }
int builtin_quote(Environment &env, const std::vector<std::string> &tokens, const fdmask &fds) { // todo... //io_helper io(fds); bool space = false; bool n = false; for (const auto &s : make_offset_range(tokens, 1)) { if (s == "-n" || s == "-N") { n = true; continue; } if (space) { fdputs(" ", stdout); } fdputs(quote(s).c_str(), stdout); space = true; } if (!n) fdputs("\n", stdout); return 0; }
QString KAboutApplication::addPerson(const KAboutPerson *p) { QString res; if (!p->task().isEmpty()){ res += quote(p->task()); res += ":<br>"; } res += QString("%1 <<a href=\"mailto:%2\">%3</a>><br>") .arg(quote(p->name())) .arg(quote(p->emailAddress())) .arg(quote(p->emailAddress())); if (!p->webAddress().isEmpty()) res += QString("<a href=\"%1\">%2</a><br>") .arg(quote(p->webAddress())) .arg(quote(p->webAddress())); return res; }
bool ClientImpl::sync_upload_from( std::string remote_file, char * buffer, unsigned long long int buffer_size, callback_t callback, progress_t progress ) noexcept { auto root_urn = Urn(this->webdav_root, true); auto file_urn = root_urn + remote_file; Data data = { buffer, 0, buffer_size }; Request request(this->options()); auto url = this->webdav_hostname + file_urn.quote(request.handle); Data response = { 0, 0, 0 }; request.set(CURLOPT_UPLOAD, 1L); request.set(CURLOPT_URL, url.c_str()); request.set(CURLOPT_READDATA, (size_t)&data); request.set(CURLOPT_READFUNCTION, (size_t)Callback::Read::buffer); request.set(CURLOPT_INFILESIZE_LARGE, (curl_off_t)buffer_size); request.set(CURLOPT_BUFFERSIZE, (long)Client::buffer_size); request.set(CURLOPT_WRITEDATA, (size_t)&response); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); if (progress != nullptr) { request.set(CURLOPT_XFERINFOFUNCTION, (size_t)progress.target<progress_funptr>()); request.set(CURLOPT_NOPROGRESS, 0L); } bool is_performed = request.perform(); if (callback != nullptr) callback(is_performed); return is_performed; }
std::string KVCRedisPtotocol::sendGetCommand(KVCConnection* conn, std::string key){ std::string res; if (!(res = validateKey(key)).empty()) throw KVCIllegalArgumentException(res); std::string command = "GET " + quote(key) + "\r\n"; std::string tcpResult, value; conn->send(command); tcpResult = reciveFromConn(conn); size_t lineEnd = tcpResult.find("\r\n"); if (lineEnd == std::string::npos) throw KVCRuntimeException("Unknow response format"); if (str_left_cmp(tcpResult.c_str(), ":", tcpResult.length(), sizeof(":") - 1)) { value = tcpResult.substr(1, lineEnd - 1); return value; } else if (str_left_cmp(tcpResult.c_str(), "$", tcpResult.length(), sizeof("$") - 1)){ if (str_left_cmp(tcpResult.c_str(), "$-1", tcpResult.length(), sizeof("$-1") - 1)){ return ""; } else{ size_t valueLen; try{ valueLen = atoll((tcpResult.substr(1, lineEnd - 1)).c_str()); value = tcpResult.substr(lineEnd + 2, valueLen); if (value.length() != valueLen) throw KVCRuntimeException("Unknow response format, value missing"); } catch (std::invalid_argument& e) { throw KVCRuntimeException(("Unknow response format") + std::string().append(e.what())); } } return value; } throw KVCRuntimeException(getRedisResult(tcpResult)); }
CEvaluationNodeCall::CEvaluationNodeCall(const SubType & subType, const Data & data): CEvaluationNode(T_CALL, subType, data), mpFunction(NULL), mpExpression(NULL), mCallNodes(), mpCallParameters(NULL), mQuotesRequired(false), mBooleanRequired(false), mRegisteredFunctionCN() { setData(data); mData = unQuote(mData); // We force quoting if the round trip unquote, quote does not recover the original input if (isKeyword(mData)) { mQuotesRequired = true; } if (mData != data && quote(mData) != data) { mQuotesRequired = true; } switch (subType) { case S_FUNCTION: case S_EXPRESSION: break; default: fatalError(); break; } mPrecedence = PRECEDENCE_FUNCTION; }
static bool resolve_bind_address (struct sockaddr *sa) { struct address_list *al; /* Make sure this is called only once. opt.bind_address doesn't change during a Wget run. */ static bool called, should_bind; static ip_address ip; if (called) { if (should_bind) sockaddr_set_data (sa, &ip, 0); return should_bind; } called = true; al = lookup_host (opt.bind_address, LH_BIND | LH_SILENT); if (!al) { /* #### We should be able to print the error message here. */ logprintf (LOG_NOTQUIET, _("%s: unable to resolve bind address %s; disabling bind.\n"), exec_name, quote (opt.bind_address)); should_bind = false; return false; } /* Pick the first address in the list and use it as bind address. Perhaps we should try multiple addresses in succession, but I don't think that's necessary in practice. */ ip = *address_list_address_at (al, 0); address_list_release (al); sockaddr_set_data (sa, &ip, 0); should_bind = true; return true; }
bool ClientImpl::sync_upload_from( std::string remote_file, std::istream & stream, callback_t callback, progress_t progress ) noexcept { auto root_urn = Urn(this->ftps_root, true); auto file_urn = root_urn + remote_file; Request request(this->options()); auto url = this->ftps_hostname + file_urn.quote(request.handle); stream.seekg(0, std::ios::end); size_t stream_size = stream.tellg(); stream.seekg(0, std::ios::beg); Data response = { 0, 0, 0 }; request.set(CURLOPT_UPLOAD, 1L); request.set(CURLOPT_URL, url.c_str()); request.set(CURLOPT_READDATA, (size_t)&stream); request.set(CURLOPT_READFUNCTION, (size_t)Callback::Read::stream); request.set(CURLOPT_INFILESIZE_LARGE, (curl_off_t)stream_size); request.set(CURLOPT_BUFFERSIZE, (long)Client::buffer_size); request.set(CURLOPT_WRITEDATA, (size_t)&response); request.set(CURLOPT_WRITEFUNCTION, (size_t)Callback::Append::buffer); if (progress != nullptr) { request.set(CURLOPT_XFERINFOFUNCTION, (size_t)progress.target<progress_funptr>()); request.set(CURLOPT_NOPROGRESS, 0L); } bool is_performed = request.perform(); if (callback != nullptr) callback(is_performed); return is_performed; }