void cTokenizer::Tokenize(bool trim) { Clear(); MYDEBUG("String wird in Token zerlegt"); char *buffer = NULL; char *token = NULL; char *tok_pointer; buffer = strdup(String); if(trim) buffer = stripspace(buffer); for(token = strtok_r(buffer, Delim, &tok_pointer); token; token = strtok_r(NULL, Delim, &tok_pointer)) { MYDEBUG("Token gefunden: %s", token); if(!trim) Add(new cToken(token)); else Add(new cToken(stripspace(token))); } free(buffer); }
bool cNestedItemList::Parse(FILE *f, cList<cNestedItem> *List, int &Line) { char *s; cReadLine ReadLine; while ((s = ReadLine.Read(f)) != NULL) { Line++; char *p = strchr(s, '#'); if (p) *p = 0; s = skipspace(stripspace(s)); if (!isempty(s)) { p = s + strlen(s) - 1; if (*p == '{') { *p = 0; stripspace(s); cNestedItem *Item = new cNestedItem(s, true); List->Add(Item); if (!Parse(f, Item->SubItems(), Line)) return false; } else if (*s == '}') break; else List->Add(new cNestedItem(s)); } } return true; }
bool RoboTVChannels::read(FILE* f, cChannels* channels) { cReadLine ReadLine; for(char* line = ReadLine.Read(f); line != NULL; line = ReadLine.Read(f)) { char* hash = strchr(line, '#'); if(hash != NULL) { *hash = 0; } stripspace(line); if(!isempty(line)) { cChannel* c = new cChannel(); if(c->Parse(line)) { channels->Add(c); } else { delete c; ERRORLOG("Invalid channel: %s", line); return false; } } } channels->ReNumber(); return true; }
static void prepare_note_data(const unsigned char *object, struct note_data *d, const unsigned char *old_note) { if (d->use_editor || !d->given) { int fd; struct strbuf buf = STRBUF_INIT; /* write the template message before editing: */ d->edit_path = git_pathdup("NOTES_EDITMSG"); fd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (fd < 0) die_errno(_("could not create file '%s'"), d->edit_path); if (d->given) write_or_die(fd, d->buf.buf, d->buf.len); else if (old_note) copy_obj_to_fd(fd, old_note); strbuf_addch(&buf, '\n'); strbuf_add_commented_lines(&buf, note_template, strlen(note_template)); strbuf_addch(&buf, '\n'); write_or_die(fd, buf.buf, buf.len); write_commented_object(fd, object); close(fd); strbuf_release(&buf); strbuf_reset(&d->buf); if (launch_editor(d->edit_path, &d->buf, NULL)) { die(_("Please supply the note contents using either -m or -F option")); } stripspace(&d->buf, 1); } }
static int edit_branch_description(const char *branch_name) { FILE *fp; int status; struct strbuf buf = STRBUF_INIT; struct strbuf name = STRBUF_INIT; read_branch_desc(&buf, branch_name); if (!buf.len || buf.buf[buf.len-1] != '\n') strbuf_addch(&buf, '\n'); strbuf_commented_addf(&buf, "Please edit the description for the branch\n" " %s\n" "Lines starting with '%c' will be stripped.\n", branch_name, comment_line_char); fp = fopen(git_path(edit_description), "w"); if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) { strbuf_release(&buf); return error(_("could not write branch description template: %s"), strerror(errno)); } strbuf_reset(&buf); if (launch_editor(git_path(edit_description), &buf, NULL)) { strbuf_release(&buf); return -1; } stripspace(&buf, 1); strbuf_addf(&name, "branch.%s.description", branch_name); status = git_config_set(name.buf, buf.len ? buf.buf : NULL); strbuf_release(&name); strbuf_release(&buf); return status; }
astring *image_info_astring(running_machine *machine, astring *string) { device_image_interface *image = NULL; astring_printf(string, "%s\n\n", machine->gamedrv->description); #if 0 if (mess_ram_size > 0) { char buf2[RAM_STRING_BUFLEN]; astring_catprintf(string, "RAM: %s\n\n", ram_string(buf2, mess_ram_size)); } #endif for (bool gotone = machine->m_devicelist.first(image); gotone; gotone = image->next(image)) { const char *name = image->filename(); if (name != NULL) { const char *base_filename; const char *info; char *base_filename_noextension; base_filename = image->basename(); base_filename_noextension = strip_extension(base_filename); /* display device type and filename */ astring_catprintf(string, "%s: %s\n", image->image_config().devconfig().name(), base_filename); /* display long filename, if present and doesn't correspond to name */ info = image->longname(); if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension))) astring_catprintf(string, "%s\n", info); /* display manufacturer, if available */ info = image->manufacturer(); if (info != NULL) { astring_catprintf(string, "%s", info); info = stripspace(image->year()); if (info && *info) astring_catprintf(string, ", %s", info); astring_catprintf(string,"\n"); } /* display playable information, if available */ info = image->playable(); if (info != NULL) astring_catprintf(string, "%s\n", info); if (base_filename_noextension != NULL) free(base_filename_noextension); } else { astring_catprintf(string, "%s: ---\n", image->image_config().devconfig().name()); } } return string; }
void ui_menu_image_info::image_info_astring(running_machine &machine, astring &string) { string.printf("%s\n\n", machine.system().description); #if 0 if (mess_ram_size > 0) { char buf2[RAM_STRING_BUFLEN]; string.catprintf("RAM: %s\n\n", ram_string(buf2, mess_ram_size)); } #endif image_interface_iterator iter(machine.root_device()); for (device_image_interface *image = iter.first(); image != NULL; image = iter.next()) { const char *name = image->filename(); if (name != NULL) { const char *base_filename; const char *info; char *base_filename_noextension; base_filename = image->basename(); base_filename_noextension = strip_extension(base_filename); // display device type and filename string.catprintf("%s: %s\n", image->device().name(), base_filename); // display long filename, if present and doesn't correspond to name info = image->longname(); if (info && (!base_filename_noextension || core_stricmp(info, base_filename_noextension))) string.catprintf("%s\n", info); // display manufacturer, if available info = image->manufacturer(); if (info != NULL) { string.catprintf("%s", info); info = stripspace(image->year()); if (info && *info) string.catprintf(", %s", info); string.catprintf("\n"); } // display supported information, if available switch(image->supported()) { case SOFTWARE_SUPPORTED_NO : string.catprintf("Not supported\n"); break; case SOFTWARE_SUPPORTED_PARTIAL : string.catprintf("Partially supported\n"); break; default : break; } if (base_filename_noextension != NULL) free(base_filename_noextension); } else { string.catprintf("%s: ---\n", image->device().name()); } } }
static int parse_msg_arg(const struct option *opt, const char *arg, int unset) { struct note_data *d = opt->value; strbuf_grow(&d->buf, strlen(arg) + 2); if (d->buf.len) strbuf_addch(&d->buf, '\n'); strbuf_addstr(&d->buf, arg); stripspace(&d->buf, 0); d->given = 1; return 0; }
static int parse_msg_arg(const struct option *opt, const char *arg, int unset) { struct msg_arg *msg = opt->value; strbuf_grow(&(msg->buf), strlen(arg) + 2); if (msg->buf.len) strbuf_addch(&(msg->buf), '\n'); strbuf_addstr(&(msg->buf), arg); stripspace(&(msg->buf), 0); msg->given = 1; return 0; }
int main(void) { char *name, *command, *path, *s1; s1 = "user name is me"; name = stripspace(s1); printf("%s\n", name); path = malloc(50 * sizeof(char)); strcpy(path, "/bin/"); command = "ls"; strcat(path, command); printf("%s\n", path); exit(0); }
static int parse_file_arg(const struct option *opt, const char *arg, int unset) { struct msg_arg *msg = opt->value; if (msg->buf.len) strbuf_addch(&(msg->buf), '\n'); if (!strcmp(arg, "-")) { if (strbuf_read(&(msg->buf), 0, 1024) < 0) die_errno("cannot read '%s'", arg); } else if (strbuf_read_file(&(msg->buf), arg, 1024) < 0) die_errno("could not open or read '%s'", arg); stripspace(&(msg->buf), 0); msg->given = 1; return 0; }
static int parse_file_arg(const struct option *opt, const char *arg, int unset) { struct note_data *d = opt->value; if (d->buf.len) strbuf_addch(&d->buf, '\n'); if (!strcmp(arg, "-")) { if (strbuf_read(&d->buf, 0, 1024) < 0) die_errno(_("cannot read '%s'"), arg); } else strbuf_read_file_or_die(&(d->buf), arg, 0); stripspace(&d->buf, 0); d->given = 1; return 0; }
int cmd_stripspace(int argc, const char **argv, const char *prefix) { struct strbuf buf = STRBUF_INIT; int strip_comments = 0; if (argc > 1 && (!strcmp(argv[1], "-s") || !strcmp(argv[1], "--strip-comments"))) strip_comments = 1; if (strbuf_read(&buf, 0, 1024) < 0) die_errno("could not read the input"); stripspace(&buf, strip_comments); write_or_die(1, buf.buf, buf.len); strbuf_release(&buf); return 0; }
/* * See if the user edited the message in the editor or left what * was in the template intact */ static int template_untouched(struct strbuf *sb) { struct strbuf tmpl = STRBUF_INIT; char *start; if (cleanup_mode == CLEANUP_NONE && sb->len) return 0; if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0) return 0; stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); start = (char *)skip_prefix(sb->buf, tmpl.buf); if (!start) start = sb->buf; strbuf_release(&tmpl); return rest_is_empty(sb, start - sb->buf); }
static void prepare_to_commit(void) { struct strbuf msg = STRBUF_INIT; strbuf_addbuf(&msg, &merge_msg); strbuf_addch(&msg, '\n'); write_merge_msg(&msg); run_hook(get_index_file(), "prepare-commit-msg", git_path("MERGE_MSG"), "merge", NULL, NULL); if (option_edit) { if (launch_editor(git_path("MERGE_MSG"), NULL, NULL)) abort_commit(NULL); } read_merge_msg(&msg); stripspace(&msg, option_edit); if (!msg.len) abort_commit(_("Empty commit message.")); strbuf_release(&merge_msg); strbuf_addbuf(&merge_msg, &msg); strbuf_release(&msg); }
eOSState cCMDDir::New(eKeys Key) { switch(Key) { case kOk: if(!isempty(Dir)) { char *buffer = NULL; asprintf(&buffer, "%s/%s", CurrentDir(), stripspace(Dir)); MYDEBUG("Verzeichnis: Neu: Anlegen: %s", buffer); cFileInfo *info = new cFileInfo(buffer); if(info->isExists()) { MYDEBUG("Verzeichnis existiert bereits"); OSD_WARNMSG(tr("Directory exists")); FREENULL(buffer); DELETENULL(info); return osContinue; } if(cFileCMD::Mkdir(buffer)) { MYDEBUG("Verzeichnis anlegen erfolgreich"); LastSelDir(buffer); if(!Select) OsdObject->SetState(mmsReInit); } FREENULL(buffer); DELETENULL(info); } case kBack: State = csNone; Build(); return osContinue; break; default: break; } return cOsdMenu::ProcessKey(Key); }
/* * Find out if the message starting at position 'start' in the strbuf * contains only whitespace and Signed-off-by lines. */ static int message_is_empty(struct strbuf *sb, int start) { struct strbuf tmpl; const char *nl; int eol, i; if (cleanup_mode == CLEANUP_NONE && sb->len) return 0; /* See if the template is just a prefix of the message. */ strbuf_init(&tmpl, 0); if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) { stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); if (start + tmpl.len <= sb->len && memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0) start += tmpl.len; } strbuf_release(&tmpl); /* Check if the rest is just whitespace and Signed-of-by's. */ for (i = start; i < sb->len; i++) { nl = memchr(sb->buf + i, '\n', sb->len - i); if (nl) eol = nl - sb->buf; else eol = sb->len; if (strlen(sign_off_header) <= eol - i && !prefixcmp(sb->buf + i, sign_off_header)) { i = eol; continue; } while (i < eol) if (!isspace(sb->buf[i++])) return 0; } return 1; }
eOSState cCMDDir::Edit(eKeys Key) { switch(Key) { case kOk: if(!isempty(Dir)) { char *buffer = NULL; asprintf(&buffer, "%s/%s", CurrentDir(), stripspace(Dir)); MYDEBUG("Verzeichnis: Edit: OK: %s", buffer); cFileInfo *info = new cFileInfo(buffer); if(info->isExists()) { MYDEBUG("Verzeichnis: Edit: Existiert schon"); OSD_WARNMSG(tr("Directory exists")); FREENULL(buffer); DELETENULL(info); return osUnknown; } if(cFileCMD::Rn(LastSelDir(), buffer)) { MYDEBUG("Verzeichnis: Edit: Rename OK"); LastSelDir(buffer); OsdObject->SetState(mmsReInit); } FREENULL(buffer); DELETENULL(info); } case kBack: State = csNone; Build(); return osContinue; break; default: break; } return cOsdMenu::ProcessKey(Key); }
int cmd_stripspace(int argc, const char **argv, const char *prefix) { struct strbuf buf = STRBUF_INIT; int strip_comments = 0; enum { INVAL = 0, STRIP_SPACE = 1, COMMENT_LINES = 2 } mode = STRIP_SPACE; if (argc == 2) { if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "--strip-comments")) { strip_comments = 1; } else if (!strcmp(argv[1], "-c") || !strcmp(argv[1], "--comment-lines")) { mode = COMMENT_LINES; } else { mode = INVAL; } } else if (argc > 1) { mode = INVAL; } if (mode == INVAL) usage(usage_msg); if (strip_comments || mode == COMMENT_LINES) git_config(git_default_config, NULL); if (strbuf_read(&buf, 0, 1024) < 0) die_errno("could not read the input"); if (mode == STRIP_SPACE) stripspace(&buf, strip_comments); else comment_lines(&buf); write_or_die(1, buf.buf, buf.len); strbuf_release(&buf); return 0; }
static void prepare_to_commit(struct commit_list *remoteheads) { struct strbuf msg = STRBUF_INIT; strbuf_addbuf(&msg, &merge_msg); strbuf_addch(&msg, '\n'); if (0 < option_edit) strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char); write_merge_msg(&msg); if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg", git_path("MERGE_MSG"), "merge", NULL)) abort_commit(remoteheads, NULL); if (0 < option_edit) { if (launch_editor(git_path("MERGE_MSG"), NULL, NULL)) abort_commit(remoteheads, NULL); } read_merge_msg(&msg); stripspace(&msg, 0 < option_edit); if (!msg.len) abort_commit(remoteheads, _("Empty commit message.")); strbuf_release(&merge_msg); strbuf_addbuf(&merge_msg, &msg); strbuf_release(&msg); }
bool cSystemCardClient::ProcessECM(const cEcmInfo *ecm, unsigned char *data) { cCardClient *startCc=cc, *oldcc; do { if(cc) { cTimeMs start; int id=cc->msECM.Get(data,SCT_LEN(data),cw); if(id==0 || (id>0 && cc->ProcessECM(ecm,data,cw))) { int dur=start.Elapsed(); if(dur>2000) { char bb[32]; time_t now=time(0); ctime_r(&now,bb); stripspace(bb); PRINTF(L_CC_CORE,"%s: lagged cw %d ms (%s)",bb,dur,cc->Name()); } char buff[32]; snprintf(buff,sizeof(buff),"CC %s",cc->Name()); KeyOK(buff); if(id>0) cc->msECM.Cache(id,true,cw); return true; } if(id>0) { PRINTF(L_CC_CORE,"client %s (%s:%d) ECM failed (%d ms)",cc->Name(),cc->hostname,cc->port,(int)start.Elapsed()); cc->msECM.Cache(id,false,cw); } if(id<0) { PRINTF(L_CC_CORE,"client %s (%s:%d) ECM already cached as failed",cc->Name(),cc->hostname,cc->port); } } if(!cc) PRINTF(L_CC_CORE,"cc-loop"); oldcc=cc; cc=staticCcl.FindBySysId(ecm->caId,cc); if(cc && cc!=startCc) PRINTF(L_CC_CORE,"now trying client %s (%s:%d)",cc->Name(),cc->hostname,cc->port); } while(cc!=startCc && cc!=oldcc); return false; }
astring *image_info_astring(running_machine &machine, astring *string) { device_image_interface *image = NULL; astring_printf(string, "%s\n\n", machine.system().description); #if 0 if (mess_ram_size > 0) { char buf2[RAM_STRING_BUFLEN]; astring_catprintf(string, "RAM: %s\n\n", ram_string(buf2, mess_ram_size)); } #endif for (bool gotone = machine.devicelist().first(image); gotone; gotone = image->next(image)) { const char *name = image->filename(); if (name != NULL) { const char *base_filename; const char *info; char *base_filename_noextension; base_filename = image->basename(); base_filename_noextension = strip_extension(base_filename); /* display device type and filename */ astring_catprintf(string, "%s: %s\n", image->device().name(), base_filename); /* display long filename, if present and doesn't correspond to name */ info = image->longname(); if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension))) astring_catprintf(string, "%s\n", info); /* display manufacturer, if available */ info = image->manufacturer(); if (info != NULL) { astring_catprintf(string, "%s", info); info = stripspace(image->year()); if (info && *info) astring_catprintf(string, ", %s", info); astring_catprintf(string,"\n"); } /* display supported information, if available */ switch(image->supported()) { case SOFTWARE_SUPPORTED_NO : astring_catprintf(string, "Not supported\n"); break; case SOFTWARE_SUPPORTED_PARTIAL : astring_catprintf(string, "Partialy supported\n"); break; default : break; } if (base_filename_noextension != NULL) free(base_filename_noextension); } else { astring_catprintf(string, "%s: ---\n", image->device().name()); } } return string; }
static void ConfirmShutdown(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) { gboolean ignoreuser = FALSE; g_variant_get(Parameters, "(b)", &ignoreuser); // this is nearly a copy of vdr's cShutdownHandler::ConfirmShutdown // if the original changes take this into account if (!ignoreuser && !ShutdownHandler.IsUserInactive()) { SendReply(Invocation, 901, "user is active", 0, ""); return; } #if APIVERSNUM > 20101 if (RecordingsHandler.Active()) { #else if (cCutter::Active()) { #endif SendReply(Invocation, 902, "cutter is active", 0, ""); return; } time_t Now = time(NULL); #if VDRVERSNUM > 20300 LOCK_TIMERS_READ; const cTimers *timers = Timers; #else cTimers *timers = &Timers; #endif const cTimer *timer = timers->GetNextActiveTimer(); time_t Next = timer ? timer->StartTime() : 0; time_t Delta = timer ? Next - Now : 0; if (cRecordControls::Active() || (Next && Delta <= 0)) { // VPS recordings in timer end margin may cause Delta <= 0 SendReply(Invocation, 903, "recording is active", 0, ""); return; } else if (Next && Delta <= Setup.MinEventTimeout * 60) { // Timer within Min Event Timeout SendReply(Invocation, 904, "recording is active in the near future", 0, ""); return; } if (cPluginManager::Active(NULL)) { SendReply(Invocation, 905, "some plugin is active", 0, ""); return; } cPlugin *Plugin = cPluginManager::GetNextWakeupPlugin(); time_t NextPlugin = Plugin ? Plugin->WakeupTime() : 0; Delta = NextPlugin ? NextPlugin - Now : 0; if (NextPlugin && Delta <= Setup.MinEventTimeout * 60) { // Plugin wakeup within Min Event Timeout cString buf = cString::sprintf("plugin %s wakes up in %ld min", Plugin->Name(), Delta / 60); SendReply(Invocation, 906, *buf, 0, ""); return; } // insanity check: ask vdr again, if implementation of ConfirmShutdown has changed... if (cRemote::Enabled() && !ShutdownHandler.ConfirmShutdown(false)) { SendReply(Invocation, 550, "vdr is not ready for shutdown", 0, ""); return; } if (((*cDBusShutdown::_shutdownHooksDir) != NULL) && (strlen(*cDBusShutdown::_shutdownHooksDir) > 0) && ((*cDBusShutdown::_shutdownHooksWrapper) != NULL) && (strlen(*cDBusShutdown::_shutdownHooksWrapper) > 0)) { if (NextPlugin && (!Next || Next > NextPlugin)) { Next = NextPlugin; timer = NULL; } Delta = Next ? Next - Now : 0; char *tmp; if (Next && timer) tmp = strdup(*cString::sprintf("%ld %ld %d \"%s\" %d", Next, Delta, timer->Channel()->Number(), *strescape(timer->File(), "\\\"$"), false)); else if (Next && Plugin) tmp = strdup(*cString::sprintf("%ld %ld %d \"%s\" %d", Next, Delta, 0, Plugin->Name(), false)); else tmp = strdup(*cString::sprintf("%ld %ld %d \"%s\" %d", Next, Delta, 0, "", false)); cString params = strescape(tmp, "\\\""); cString shutdowncmd; cString cmd = cString::sprintf("%s %s \"%s\"", *cDBusShutdown::_shutdownHooksWrapper, *cDBusShutdown::_shutdownHooksDir, *params); if (access(*cDBusShutdown::_shutdownHooksWrapper, X_OK) != 0) cmd = cString::sprintf("/bin/sh %s %s \"%s\"", *cDBusShutdown::_shutdownHooksWrapper, *cDBusShutdown::_shutdownHooksDir, *params); isyslog("dbus2vdr: calling shutdown-hook-wrapper %s", *cmd); tmp = NULL; cExitPipe p; int ret = -1; if (p.Open(*cmd, "r")) { int l = 0; int c; while ((c = fgetc(p)) != EOF) { if (l % 20 == 0) { if (char *NewBuffer = (char *)realloc(tmp, l + 21)) tmp = NewBuffer; else { esyslog("dbus2vdr: out of memory"); break; } } tmp[l++] = char(c); } if (tmp) tmp[l] = 0; ret = p.Close(); } else esyslog("dbus2vdr: can't open pipe for command '%s'", *cmd); cString result(stripspace(tmp), true); // for automatic free isyslog("dbus2vdr: result(%d) = %s", ret, *result); if (ret != 0) { if (*result) { static const char *message = "ABORT_MESSAGE=\""; if ((strlen(*result) > strlen(message)) && startswith(*result, message)) { cString abort_message = tmp + strlen(message); abort_message.Truncate(-1); SendReply(Invocation, 992, *abort_message, ret, ""); return; } } SendReply(Invocation, 999, "shutdown-hook returned a non-zero exit code", ret, ""); return; } if (*result) { static const char *message = "TRY_AGAIN=\""; if ((strlen(*result) > strlen(message)) && startswith(*result, message)) { cString s_try_again = tmp + strlen(message); s_try_again.Truncate(-1); if ((strlen(*s_try_again) > 0) && isnumber(*s_try_again)) { int try_again = strtol(s_try_again, NULL, 10); if (try_again > 0) { SendReply(Invocation, 991, *s_try_again, 0, ""); return; } } } } if (*result) { static const char *message = "SHUTDOWNCMD=\""; if ((strlen(*result) > strlen(message)) && startswith(*result, message)) { shutdowncmd = tmp + strlen(message); shutdowncmd.Truncate(-1); } } if (*shutdowncmd && (strlen(*shutdowncmd) > 0)) { SendReply(Invocation, 990, *shutdowncmd, 0, *params); return; } } SendReply(Invocation, 250, "vdr is ready for shutdown", 0, ""); }; static void ManualStart(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) { gboolean manual = FALSE; time_t Delta = Setup.NextWakeupTime ? Setup.NextWakeupTime - cDBusShutdown::StartupTime : 0; if (!Setup.NextWakeupTime || (abs(Delta) > 600)) // 600 comes from vdr's MANUALSTART constant in vdr.c manual = TRUE; g_dbus_method_invocation_return_value(Invocation, g_variant_new("(b)", manual)); };
int cmd_commit(int argc, const char **argv, const char *prefix) { static struct wt_status s; static struct option builtin_commit_options[] = { OPT__QUIET(&quiet, N_("suppress summary after successful commit")), OPT__VERBOSE(&verbose, N_("show diff in commit message template")), OPT_GROUP(N_("Commit message options")), OPT_FILENAME('F', "file", &logfile, N_("read message from file")), OPT_STRING(0, "author", &force_author, N_("author"), N_("override author for commit")), OPT_STRING(0, "date", &force_date, N_("date"), N_("override date for commit")), OPT_CALLBACK('m', "message", &message, N_("message"), N_("commit message"), opt_parse_m), OPT_STRING('c', "reedit-message", &edit_message, N_("commit"), N_("reuse and edit message from specified commit")), OPT_STRING('C', "reuse-message", &use_message, N_("commit"), N_("reuse message from specified commit")), OPT_STRING(0, "fixup", &fixup_message, N_("commit"), N_("use autosquash formatted message to fixup specified commit")), OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")), OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")), OPT_BOOL('s', "signoff", &signoff, N_("add Signed-off-by:")), OPT_FILENAME('t', "template", &template_file, N_("use specified template file")), OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")), OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")), OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")), { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, /* end commit message options */ OPT_GROUP(N_("Commit contents options")), OPT_BOOL('a', "all", &all, N_("commit all changed files")), OPT_BOOL('i', "include", &also, N_("add specified files to index for commit")), OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")), OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")), OPT_BOOL('o', "only", &only, N_("commit only specified files")), OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit hook")), OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")), OPT_SET_INT(0, "short", &status_format, N_("show status concisely"), STATUS_FORMAT_SHORT), OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")), OPT_SET_INT(0, "porcelain", &status_format, N_("machine-readable output"), STATUS_FORMAT_PORCELAIN), OPT_SET_INT(0, "long", &status_format, N_("show status in long format (default)"), STATUS_FORMAT_LONG), OPT_BOOL('z', "null", &s.null_termination, N_("terminate entries with NUL")), OPT_BOOL(0, "amend", &amend, N_("amend previous commit")), OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" }, /* end commit contents options */ OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty, N_("ok to record an empty change")), OPT_HIDDEN_BOOL(0, "allow-empty-message", &allow_empty_message, N_("ok to record a change with an empty message")), OPT_END() }; struct strbuf sb = STRBUF_INIT; struct strbuf author_ident = STRBUF_INIT; const char *index_file, *reflog_msg; char *nl; unsigned char sha1[20]; struct ref_lock *ref_lock; struct commit_list *parents = NULL, **pptr = &parents; struct stat statbuf; struct commit *current_head = NULL; struct commit_extra_header *extra = NULL; if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_commit_usage, builtin_commit_options); status_init_config(&s, git_commit_config); status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ s.colopts = 0; if (get_sha1("HEAD", sha1)) current_head = NULL; else { current_head = lookup_commit_or_die(sha1, "HEAD"); if (parse_commit(current_head)) die(_("could not parse HEAD commit")); } argc = parse_and_validate_options(argc, argv, builtin_commit_options, builtin_commit_usage, prefix, current_head, &s); if (dry_run) return dry_run_commit(argc, argv, prefix, current_head, &s); index_file = prepare_index(argc, argv, prefix, current_head, 0); /* Set up everything for writing the commit object. This includes running hooks, writing the trees, and interacting with the user. */ if (!prepare_to_commit(index_file, prefix, current_head, &s, &author_ident)) { rollback_index_files(); return 1; } /* Determine parents */ reflog_msg = getenv("GIT_REFLOG_ACTION"); if (!current_head) { if (!reflog_msg) reflog_msg = "commit (initial)"; } else if (amend) { struct commit_list *c; if (!reflog_msg) reflog_msg = "commit (amend)"; for (c = current_head->parents; c; c = c->next) pptr = &commit_list_insert(c->item, pptr)->next; } else if (whence == FROM_MERGE) { struct strbuf m = STRBUF_INIT; FILE *fp; int allow_fast_forward = 1; if (!reflog_msg) reflog_msg = "commit (merge)"; pptr = &commit_list_insert(current_head, pptr)->next; fp = fopen(git_path("MERGE_HEAD"), "r"); if (fp == NULL) die_errno(_("could not open '%s' for reading"), git_path("MERGE_HEAD")); while (strbuf_getline(&m, fp, '\n') != EOF) { struct commit *parent; parent = get_merge_parent(m.buf); if (!parent) die(_("Corrupt MERGE_HEAD file (%s)"), m.buf); pptr = &commit_list_insert(parent, pptr)->next; } fclose(fp); strbuf_release(&m); if (!stat(git_path("MERGE_MODE"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0) die_errno(_("could not read MERGE_MODE")); if (!strcmp(sb.buf, "no-ff")) allow_fast_forward = 0; } if (allow_fast_forward) parents = reduce_heads(parents); } else { if (!reflog_msg) reflog_msg = (whence == FROM_CHERRY_PICK) ? "commit (cherry-pick)" : "commit"; pptr = &commit_list_insert(current_head, pptr)->next; } /* Finally, get the commit message */ strbuf_reset(&sb); if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { int saved_errno = errno; rollback_index_files(); die(_("could not read commit message: %s"), strerror(saved_errno)); } /* Truncate the message just before the diff, if any. */ if (verbose) wt_status_truncate_message_at_cut_line(&sb); if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, cleanup_mode == CLEANUP_ALL); if (template_untouched(&sb) && !allow_empty_message) { rollback_index_files(); fprintf(stderr, _("Aborting commit; you did not edit the message.\n")); exit(1); } if (message_is_empty(&sb) && !allow_empty_message) { rollback_index_files(); fprintf(stderr, _("Aborting commit due to empty commit message.\n")); exit(1); } if (amend) { const char *exclude_gpgsig[2] = { "gpgsig", NULL }; extra = read_commit_extra_headers(current_head, exclude_gpgsig); } else { struct commit_extra_header **tail = &extra; append_merge_tag_headers(parents, &tail); } if (commit_tree_extended(&sb, active_cache_tree->sha1, parents, sha1, author_ident.buf, sign_commit, extra)) { rollback_index_files(); die(_("failed to write commit object")); } strbuf_release(&author_ident); free_commit_extra_headers(extra); ref_lock = lock_any_ref_for_update("HEAD", !current_head ? NULL : current_head->object.sha1, 0, NULL); nl = strchr(sb.buf, '\n'); if (nl) strbuf_setlen(&sb, nl + 1 - sb.buf); else strbuf_addch(&sb, '\n'); strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg)); strbuf_insert(&sb, strlen(reflog_msg), ": ", 2); if (!ref_lock) { rollback_index_files(); die(_("cannot lock HEAD ref")); } if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) { rollback_index_files(); die(_("cannot update HEAD ref")); } unlink(git_path("CHERRY_PICK_HEAD")); unlink(git_path("REVERT_HEAD")); unlink(git_path("MERGE_HEAD")); unlink(git_path("MERGE_MSG")); unlink(git_path("MERGE_MODE")); unlink(git_path("SQUASH_MSG")); if (commit_index_files()) die (_("Repository has been updated, but unable to write\n" "new_index file. Check that disk is not full or quota is\n" "not exceeded, and then \"git reset HEAD\" to recover.")); rerere(0); run_hook(get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { struct notes_rewrite_cfg *cfg; cfg = init_copy_notes_for_rewrite("amend"); if (cfg) { /* we are amending, so current_head is not NULL */ copy_note_for_rewrite(cfg, current_head->object.sha1, sha1); finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); } run_rewrite_hook(current_head->object.sha1, sha1); } if (!quiet) print_summary(prefix, sha1, !current_head); return 0; }
static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, struct strbuf *author_ident) { struct stat statbuf; struct strbuf committer_ident = STRBUF_INIT; int commitable; struct strbuf sb = STRBUF_INIT; const char *hook_arg1 = NULL; const char *hook_arg2 = NULL; int clean_message_contents = (cleanup_mode != CLEANUP_NONE); int old_display_comment_prefix; /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); if (!no_verify && run_hook(index_file, "pre-commit", NULL)) return 0; if (squash_message) { /* * Insert the proper subject line before other commit * message options add their content. */ if (use_message && !strcmp(use_message, squash_message)) strbuf_addstr(&sb, "squash! "); else { struct pretty_print_context ctx = {0}; struct commit *c; c = lookup_commit_reference_by_name(squash_message); if (!c) die(_("could not lookup commit %s"), squash_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(c, "squash! %s\n\n", &sb, &ctx); } } if (message.len) { strbuf_addbuf(&sb, &message); hook_arg1 = "message"; } else if (logfile && !strcmp(logfile, "-")) { if (isatty(0)) fprintf(stderr, _("(reading log message from standard input)\n")); if (strbuf_read(&sb, 0, 0) < 0) die_errno(_("could not read log from standard input")); hook_arg1 = "message"; } else if (logfile) { if (strbuf_read_file(&sb, logfile, 0) < 0) die_errno(_("could not read log file '%s'"), logfile); hook_arg1 = "message"; } else if (use_message) { char *buffer; buffer = strstr(use_message_buffer, "\n\n"); if (!use_editor && (!buffer || buffer[2] == '\0')) die(_("commit has empty message")); strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { struct pretty_print_context ctx = {0}; struct commit *commit; commit = lookup_commit_reference_by_name(fixup_message); if (!commit) die(_("could not lookup commit %s"), fixup_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(commit, "fixup! %s\n\n", &sb, &ctx); hook_arg1 = "message"; } else if (!stat(git_path("MERGE_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) die_errno(_("could not read MERGE_MSG")); hook_arg1 = "merge"; } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) die_errno(_("could not read SQUASH_MSG")); hook_arg1 = "squash"; } else if (template_file) { if (strbuf_read_file(&sb, template_file, 0) < 0) die_errno(_("could not read '%s'"), template_file); hook_arg1 = "template"; clean_message_contents = 0; } /* * The remaining cases don't modify the template message, but * just set the argument(s) to the prepare-commit-msg hook. */ else if (whence == FROM_MERGE) hook_arg1 = "merge"; else if (whence == FROM_CHERRY_PICK) { hook_arg1 = "commit"; hook_arg2 = "CHERRY_PICK_HEAD"; } if (squash_message) { /* * If squash_commit was used for the commit subject, * then we're possibly hijacking other commit log options. * Reset the hook args to tell the real story. */ hook_arg1 = "message"; hook_arg2 = ""; } s->fp = fopen(git_path(commit_editmsg), "w"); if (s->fp == NULL) die_errno(_("could not open '%s'"), git_path(commit_editmsg)); /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */ old_display_comment_prefix = s->display_comment_prefix; s->display_comment_prefix = 1; /* * Most hints are counter-productive when the commit has * already started. */ s->hints = 0; if (clean_message_contents) stripspace(&sb, 0); if (signoff) { /* * See if we have a Conflicts: block at the end. If yes, count * its size, so we can ignore it. */ int ignore_footer = 0; int i, eol, previous = 0; const char *nl; for (i = 0; i < sb.len; i++) { nl = memchr(sb.buf + i, '\n', sb.len - i); if (nl) eol = nl - sb.buf; else eol = sb.len; if (starts_with(sb.buf + previous, "\nConflicts:\n")) { ignore_footer = sb.len - previous; break; } while (i < eol) i++; previous = eol; } append_signoff(&sb, ignore_footer, 0); } if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); strbuf_release(&sb); /* This checks if committer ident is explicitly given */ strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT)); if (use_editor && include_status) { int ident_shown = 0; int saved_color_setting; char *ai_tmp, *ci_tmp; if (whence != FROM_COMMIT) status_printf_ln(s, GIT_COLOR_NORMAL, whence == FROM_MERGE ? _("\n" "It looks like you may be committing a merge.\n" "If this is not correct, please remove the file\n" " %s\n" "and try again.\n") : _("\n" "It looks like you may be committing a cherry-pick.\n" "If this is not correct, please remove the file\n" " %s\n" "and try again.\n"), git_path(whence == FROM_MERGE ? "MERGE_HEAD" : "CHERRY_PICK_HEAD")); fprintf(s->fp, "\n"); if (cleanup_mode == CLEANUP_ALL) status_printf(s, GIT_COLOR_NORMAL, _("Please enter the commit message for your changes." " Lines starting\nwith '%c' will be ignored, and an empty" " message aborts the commit.\n"), comment_line_char); else /* CLEANUP_SPACE, that is. */ status_printf(s, GIT_COLOR_NORMAL, _("Please enter the commit message for your changes." " Lines starting\n" "with '%c' will be kept; you may remove them" " yourself if you want to.\n" "An empty message aborts the commit.\n"), comment_line_char); if (only_include_assumed) status_printf_ln(s, GIT_COLOR_NORMAL, "%s", only_include_assumed); ai_tmp = cut_ident_timestamp_part(author_ident->buf); ci_tmp = cut_ident_timestamp_part(committer_ident.buf); if (strcmp(author_ident->buf, committer_ident.buf)) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" "Author: %s"), ident_shown++ ? "" : "\n", author_ident->buf); if (!committer_ident_sufficiently_given()) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" "Committer: %s"), ident_shown++ ? "" : "\n", committer_ident.buf); if (ident_shown) status_printf_ln(s, GIT_COLOR_NORMAL, ""); saved_color_setting = s->use_color; s->use_color = 0; commitable = run_status(s->fp, index_file, prefix, 1, s); s->use_color = saved_color_setting; *ai_tmp = ' '; *ci_tmp = ' '; } else { unsigned char sha1[20]; const char *parent = "HEAD"; if (!active_nr && read_cache() < 0) die(_("Cannot read index")); if (amend) parent = "HEAD^1"; if (get_sha1(parent, sha1)) commitable = !!active_nr; else commitable = index_differs_from(parent, 0); } strbuf_release(&committer_ident); fclose(s->fp); /* * Reject an attempt to record a non-merge empty commit without * explicit --allow-empty. In the cherry-pick case, it may be * empty due to conflict resolution, which the user should okay. */ if (!commitable && whence != FROM_MERGE && !allow_empty && !(amend && is_a_merge(current_head))) { s->display_comment_prefix = old_display_comment_prefix; run_status(stdout, index_file, prefix, 0, s); if (amend) fputs(_(empty_amend_advice), stderr); else if (whence == FROM_CHERRY_PICK) { fputs(_(empty_cherry_pick_advice), stderr); if (!sequencer_in_use) fputs(_(empty_cherry_pick_advice_single), stderr); else fputs(_(empty_cherry_pick_advice_multi), stderr); } return 0; } /* * Re-read the index as pre-commit hook could have updated it, * and write it out as a tree. We must do this before we invoke * the editor and after we invoke run_status above. */ discard_cache(); read_cache_from(index_file); if (update_main_cache_tree(0)) { error(_("Error building trees")); return 0; } if (run_hook(index_file, "prepare-commit-msg", git_path(commit_editmsg), hook_arg1, hook_arg2, NULL)) return 0; if (use_editor) { char index[PATH_MAX]; const char *env[2] = { NULL }; env[0] = index; snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); if (launch_editor(git_path(commit_editmsg), NULL, env)) { fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); } } if (!no_verify && run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) { return 0; } return 1; }
struct stormdata *read_stormdata_hurdat2(struct stormdata *storms, struct storm_arg *args) { FILE *file; int i; char *line, *linecopy, buf[10240]; struct storm storm; char *token[35]; char recID[4]; int points = 0; int minute = 0; int lasttype; bool dateset = false; bool syn_time = false; struct pos pos; file = fopen(args->input, "r"); if (!file) { fprintf(stderr, "Couldn't open file '%s': %s\n", args->input, strerror(errno)); exit(-1); } while ((line = fgets(buf, sizeof(buf), file))) { /* Clean up the line */ line = stripspace(line); linecopy = strdup(line); // Need to make a copy here, as strtok() is a destructive operation /* Begin parsing the line */ token[0] = strtok(linecopy, ","); i = 1; while ((token[i-1] != NULL) && (i<35)) { token[i-1] = stripspace(token[i-1]); token[i] = strtok(NULL, ","); i++; } /* Preventing horrible explosions in case we can't read anything */ if (i == 1) { fprintf(stderr, "Parsing error in file '%s': Could not parse the following input line:\n%s\n", args->input, line); exit(-1); } /* Check if this is a header line; if it is, the first character of the line should be non-numeric */ if (isalpha(token[0][0]) && i==4) { /***** Parse the header row *****/ /* Before we do anything, check whether we had already processed points * for a storm; if we have, we should probably try to save it before we * start processing the new storm */ if (points > 0) { save_storm(args, storms, &storm); } init_storm(&storm); /* Copy the cyclone identifier */ /* Split it into multiple parts */ strncpy(storm.header.basin, token[0], 2); storm.header.basin[2] = '\0'; storm.header.id = substr_to_int(token[0], 2, 2); storm.header.year = substr_to_int(token[0], 4, 4); /* Figure out the name */ strncpy(storm.header.name, token[1], strlen(token[1])); /* Mark that the initial date for the storm has not been set */ dateset = false; /* Reset row counter */ points = 0; } else if (isdigit(token[0][0]) && i>8) { /***** Parse the data row *****/ /* For the first time stamp: Set initial map date * NOTE: THIS IS NOT NECESSARILY THE DATE OF CYCLOGENESIS */ if (!dateset) { storm.header.year = substr_to_int(token[0], 0, 4); storm.header.month = substr_to_int(token[0], 4, 2); storm.header.day = substr_to_int(token[0], 6, 2); dateset = true; } /* Parse this date for our position point data */ /* year, month, day */ pos.year = substr_to_int(token[0], 0, 4); pos.month = substr_to_int(token[0], 4, 2); pos.day = substr_to_int(token[0], 6, 2); /* hour */ pos.hour = substr_to_int(token[1], 0, 2); minute = substr_to_int(token[1], 2, 2); /* Check whether this is a synoptic time */ if ((pos.hour % 6 == 0) && minute == 0) { /* This is a synoptic time */ syn_time = true; } else { /* This is not a synoptic time */ syn_time = false; } /* Copy the record ID to DS (and figure out what to do with it later * Possible values: * L = landfall; * W = peak wind; * P = min pressure; * I = peak wind/pressure; * C = closest approach; * S = change in status; * G = genesis; * T = extra detail */ strncpy(recID, token[2], strlen(token[3])); /* Check the storm's status for this time point */ if ((strcasecmp(token[3], "TD") == 0) || (strcasecmp(token[3], "TS") == 0) || (strcasecmp(token[3], "TY") == 0) || (strcasecmp(token[3], "ST") == 0) || (strcasecmp(token[3], "TC") == 0) || (strcasecmp(token[3], "HU") == 0)) { pos.type = TROPICAL; lasttype = TROPICAL; } else if ((strcasecmp(token[3], "SD") == 0) || (strcasecmp(token[3], "SS") == 0)) { pos.type = SUBTROPICAL; lasttype = SUBTROPICAL; } else if ((strcasecmp(token[3], "EX") == 0)) { pos.type = EXTRATROPICAL; lasttype = EXTRATROPICAL; } else if ((strcasecmp(token[3], "LO") == 0) || (strcasecmp(token[3], "WV") == 0) || (strcasecmp(token[3], "DB") == 0)) { pos.type = LOW; lasttype = LOW; } else { /* If we have a different condition (e.g. inland, dissipating), * assume that the last valid condition is still true */ pos.type = lasttype; } /* latitude */ if (token[4][strlen(token[4])-1] == 'N') { pos.lat = substr_to_double(token[4], 0, (int)strlen(token[4])-1); } else { pos.lat = - substr_to_double(token[4], 0, (int)strlen(token[4])-1); } if (token[5][strlen(token[5])-1] == 'W') { pos.lon = substr_to_double(token[5], 0, (int)strlen(token[5])-1); } else { pos.lon = - substr_to_double(token[5], 0, (int)strlen(token[5])-1); } /* wind */ pos.wind = atoi(token[6]); /* if peak wind: store the current classification */ if (pos.wind > storm.maxwind) { strncpy(storm.header.stormclass, token[3],2); storm.header.stormclass[2] = '\0'; } /* pressure */ pos.pres = atoi(token[7]); /* Check if no wind and jump out for whatever reason */ if (pos.wind == 0) { break; } /* Update the number of rows processed */ points++; /* Save the parsed position point */ /* NOTE: We are skipping non-synoptic times right now, * until we figure out what to do with them! */ if (syn_time) save_pos(args, storms, &storm, &pos); /* The following fields are not parsed yet: * token[ 8]: TS radii NE * token[ 9]: TS radii SE * token[10]: TS radii SW * token[11]: TS radii NW * token[12]: gale radii NE * token[13]: gale radii SE * token[14]: gale radii SW * token[15]: gale radii NW * token[16]: HU radii NE * token[17]: HU radii SE * token[18]: HU radii SW * token[19]: HU radii NW */ } else { /* Something is off */ fprintf(stderr, "Parsing error in file '%s': Could not parse the following input line:\n%s\n", args->input, line); exit(-1); } free(linecopy); } fclose(file); #if 0 printf("Longitude: %d, %d\n", minlon, maxlon); printf("Latitude: %d, %d\n", minlat, maxlat); printf("%d %d %d %d\n", t, s, e, l); #endif return storms; }
bool cDll::Load(bool Log) { if (Log) isyslog("loading plugin: %s", fileName); if (handle) { esyslog("attempt to load plugin '%s' twice!", fileName); return false; } handle = dlopen(fileName, RTLD_NOW); const char *error = dlerror(); if (!error) { void *(*creator)(void); creator = (void *(*)(void))dlsym(handle, "VDRPluginCreator"); if (!(error = dlerror())) plugin = (cPlugin *)creator(); } if (!error) { if (plugin && args) { int argc = 0; char *argv[MAXPLUGINARGS]; char *p = skipspace(stripspace(args)); char *q = NULL; bool done = false; while (!done) { if (!q) q = p; switch (*p) { case '\\': strcpy(p, p + 1); if (*p) p++; else { esyslog("ERROR: missing character after \\"); fprintf(stderr, "vdr: missing character after \\\n"); return false; } break; case '"': case '\'': if ((p = SkipQuote(p)) == NULL) return false; break; default: if (!*p || isspace(*p)) { done = !*p; *p = 0; if (q) { if (argc < MAXPLUGINARGS - 1) argv[argc++] = q; else { esyslog("ERROR: plugin argument list too long"); fprintf(stderr, "vdr: plugin argument list too long\n"); return false; } q = NULL; } } if (!done) p = *p ? p + 1 : skipspace(p + 1); } } argv[argc] = NULL; if (argc) plugin->SetName(argv[0]); optind = 0; // to reset the getopt() data return !Log || !argc || plugin->ProcessArgs(argc, argv); } } else { esyslog("ERROR: %s", error); esyslog("WARNING: failed to load plugin %s. Continuing anyway.", fileName); fprintf(stderr, "vdr: %s\n", error); } return !error && plugin; }
int ui_sprintf_image_info(char *buf) { char *dst = buf; const struct IODevice *dev; int id; dst += sprintf(dst, "%s\n\n", Machine->gamedrv->description); if (options.ram) { char buf2[RAM_STRING_BUFLEN]; dst += sprintf(dst, "RAM: %s\n\n", ram_string(buf2, options.ram)); } for (dev = Machine->devices; dev->type < IO_COUNT; dev++) { for (id = 0; id < dev->count; id++) { mess_image *img = image_from_device_and_index(dev, id); const char *name = image_filename(img); if( name ) { const char *base_filename; const char *info; char *base_filename_noextension; base_filename = image_basename(img); base_filename_noextension = strip_extension((char *) base_filename); /* display device type and filename */ dst += sprintf(dst,"%s: %s\n", image_typename_id(img), base_filename); /* display long filename, if present and doesn't correspond to name */ info = image_longname(img); if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension))) dst += sprintf(dst,"%s\n", info); /* display manufacturer, if available */ info = image_manufacturer(img); if (info) { dst += sprintf(dst,"%s", info); info = stripspace(image_year(img)); if (info && *info) dst += sprintf(dst,", %s", info); dst += sprintf(dst,"\n"); } /* display playable information, if available */ info = image_playable(img); if (info) dst += sprintf(dst,"%s\n", info); if (base_filename_noextension) free(base_filename_noextension); } else { dst += sprintf(dst,"%s: ---\n", image_typename_id(img)); } } } return dst - buf; }
static void create_note(const unsigned char *object, struct msg_arg *msg, int append_only, const unsigned char *prev, unsigned char *result) { char *path = NULL; if (msg->use_editor || !msg->given) { int fd; /* write the template message before editing: */ path = git_pathdup("NOTES_EDITMSG"); fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (fd < 0) die_errno("could not create file '%s'", path); if (msg->given) write_or_die(fd, msg->buf.buf, msg->buf.len); else if (prev && !append_only) write_note_data(fd, prev); write_or_die(fd, note_template, strlen(note_template)); write_commented_object(fd, object); close(fd); strbuf_reset(&(msg->buf)); if (launch_editor(path, &(msg->buf), NULL)) { die("Please supply the note contents using either -m" \ " or -F option"); } stripspace(&(msg->buf), 1); } if (prev && append_only) { /* Append buf to previous note contents */ unsigned long size; enum object_type type; char *prev_buf = read_sha1_file(prev, &type, &size); strbuf_grow(&(msg->buf), size + 1); if (msg->buf.len && prev_buf && size) strbuf_insert(&(msg->buf), 0, "\n", 1); if (prev_buf && size) strbuf_insert(&(msg->buf), 0, prev_buf, size); free(prev_buf); } if (!msg->buf.len) { fprintf(stderr, "Removing note for object %s\n", sha1_to_hex(object)); hashclr(result); } else { if (write_sha1_file(msg->buf.buf, msg->buf.len, blob_type, result)) { error("unable to write note object"); if (path) error("The note contents has been left in %s", path); exit(128); } } if (path) { unlink_or_warn(path); free(path); } }
bool cTheme::Load(const char *FileName, bool OnlyDescriptions) { if (!FileNameOk(FileName, true)) return false; bool result = false; if (!OnlyDescriptions) isyslog("loading %s", FileName); FILE *f = fopen(FileName, "r"); if (f) { int line = 0; result = true; char *s; const char *error = NULL; cReadLine ReadLine; while ((s = ReadLine.Read(f)) != NULL) { line++; char *p = strchr(s, '#'); if (p) *p = 0; s = stripspace(skipspace(s)); if (!isempty(s)) { char *n = s; char *v = strchr(s, '='); if (v) { *v++ = 0; n = stripspace(skipspace(n)); v = stripspace(skipspace(v)); if (strstr(n, "Description") == n) { int lang = 0; char *l = strchr(n, '.'); if (l) lang = I18nLanguageIndex(++l); if (lang >= 0) { free(descriptions[lang]); descriptions[lang] = strdup(v); } else error = "invalid language code"; } else if (!OnlyDescriptions) { for (int i = 0; i < MaxThemeColors; i++) { if (colorNames[i]) { if (strcmp(n, colorNames[i]) == 0) { char *p = NULL; errno = 0; tColor c = strtoul(v, &p, 16); if (!errno && !*p) colorValues[i] = c; else error = "invalid color value"; break; } } else { error = "unknown color name"; break; } } } } else error = "missing value"; } if (error) { result = false; break; } } if (!result) esyslog("ERROR: error in %s, line %d%s%s", FileName, line, error ? ": " : "", error ? error : ""); fclose(f); } else LOG_ERROR_STR(FileName); return result; }