/*ARGSUSED*/ _chat_init_config_func( int indx, char *rec, void *arg ) { char *equals; int i; strip_trailing_space(rec); if ((equals = strchr(rec, '=')) == NULL) return S_OK; *equals++ = '\0'; strip_trailing_space(rec); strip_trailing_space(equals); while (*rec && isspace(*rec)) rec++; while (*equals && isspace(*equals)) equals++; if (!strcasecmp(rec, "mainroom")) { if (*equals != '\0') strncpy(mainroom, equals, NAMELEN); } else if (!strcasecmp(rec, "operators")) { _chat_config_form_list(&manager_list, equals); } else if (!strcasecmp(rec, "restricted")) { _chat_config_form_list(&restricted_list, equals); } else if (!strcasecmp(rec, "nopunct")) { no_punct_in_chatids = (*equals == 'Y' || *equals == 'y'); } return S_OK; }
void say_formal(char* hours_buffer, char* minutes_buffer, int hours, int minutes) { memset(hours_buffer, 0, TIME_BUFFER_SIZE / 2); memset(minutes_buffer, 0, TIME_BUFFER_SIZE); hours = hours % 12; append_string(hours_buffer, HOURS_NOMINATIVE[hours], true); if (minutes <= 9) { append_string(minutes_buffer, MINUTES_NOMINATIVE_ONES[0], true); append_string(minutes_buffer, MINUTES_NOMINATIVE_ONES[minutes], true); } else { if (minutes > 9 && minutes < 20) { minutes = minutes % 10; append_string(minutes_buffer, MINUTES_NOMINATIVE_TEENS[minutes], true); } else { int minutes_ones = minutes % 10; int minutes_tens = (minutes - minutes_ones) / 10; append_string(minutes_buffer, MINUTES_NOMINATIVE_TENS[minutes_tens], true); if (minutes_ones > 0) { append_string(minutes_buffer, MINUTES_NOMINATIVE_ONES[minutes_ones], true); } } } strip_trailing_space(hours_buffer); strip_trailing_space(minutes_buffer); }
// Find path of source file SOURCE string dbx_path(const string& source) { string path; if (gdb->has_setenv_command() && gdb->has_edit_command()) { // The DBX `file' command issues only the base name of the // current file. The `edit' command, however, invokes an // editor with the entire path. So, we misuse the `edit' // command such that it reports the entire path. gdb_question("setenv EDITOR \"echo\""); path = gdb_question("edit " + source); gdb_question(string("setenv EDITOR ") + quote(getenv("EDITOR") ? getenv("EDITOR") : "vi")); } else if (gdb->type() == DBX) { // We have DBX, but no `setenv' and no `edit' command. Check // whether the `file' command with no arguments provides the // full path, as in AIX DBX 3.1. This shouldn't affect other // DBX variants as `file' will simply return the same thing // already contained in source. gdb_question("file " + source); path = gdb_question("file"); } strip_leading_space(path); if (!path.contains('/', 0) || path.contains(' ')) path = source; // Sanity check strip_trailing_space(path); return path; }
// Add ARG to the list of arguments static void add_argument(string arg, StringArray& arguments, string& last, bool& updated) { strip_trailing_space(arg); while (arg.length() > 0 && isspace(arg[0])) arg = arg.after(0); last = arg; // Insertion sort int i; for (i = 0; i < arguments.size(); i++) { int cmp = compare(arguments[i], arg); if (cmp == 0) return; // Already present if (cmp > 0) break; } arguments += "<dummy>"; for (int j = arguments.size() - 1; j > i; j--) arguments[j] = arguments[j - 1]; arguments[i] = arg; updated = false; }
// Store first function name in ANSWER after INDEX in BUFFER static void fetch_function(const string& answer, int index, string& buffer, bool in_required = false) { if (!buffer.empty()) return; // Already have a function string line = answer.from(index); line = line.before('\n'); if (in_required) line = line.after(" in "); // The function name is the word before the opening parenthesis line = line.before('('); strip_trailing_space(line); int ws_index = line.index(' ', -1) + 1; line = line.from(ws_index); strip_leading_space(line); if (!line.empty() && line.contains(rxidentifier, 0)) buffer = line; }
chat_query_user(char *cbuf) { ACCOUNT acct; char buf[80]; int in_now = 0; while (*cbuf && !isspace(*cbuf)) cbuf++; while (*cbuf && isspace(*cbuf)) cbuf++; strip_trailing_space(cbuf); if (!HasPerm(C_QUERY)) { printchatline("*** You do not have permission to query"); return 0; } if (*cbuf == '\0') { printchatline("*** You must specify a userid to query"); return 0; } if (bbs_query(cbuf, &acct) != S_OK) { sprintf(buf, "*** Userid '%s' not found", cbuf); printchatline(buf); return 0; } bbs_enum_users(20, 0, acct.userid, _query_if_logged_in, &in_now); printchatline("***"); sprintf(buf, "*** %s (%s):", acct.userid, acct.username); printchatline(buf); if (acct.lastlogin == 0) strcpy(buf, "*** Never logged in."); else sprintf(buf, "*** %s from %s %s %s", in_now ? "Logged in" : "Last login", acct.fromhost, in_now ? "since" : "at", Ctime((time_t *)&acct.lastlogin)); printchatline(buf); if (acct.realname[0] != '\0') { sprintf(buf, "*** Real name: %s", acct.realname); printchatline(buf); } return 0; }
string dbx_lookup(const string& func_name, bool silent) { // Protect against `1' or `' being looked up as function names if (!func_name.contains(rxidentifier, 0)) return ""; // Bad function name if (pos_cache.has(func_name)) { string pos = pos_cache[func_name]; if (silent || !pos.empty()) return pos; } string reply; switch (gdb->type()) { case DBG: case DBX: case GDB: case JDB: case PYDB: reply = gdb_question("list " + func_name, 0, true); break; case XDB: reply = gdb_question("v " + func_name, 0, true); break; case PERL: reply = gdb_question("l " + func_name, 0, true); break; case BASH: reply = gdb_question("l " + func_name, 0, true); break; case MAKE: reply = gdb_question("target " + func_name, 0, true); break; } if (reply == NO_GDB_ANSWER) { // post_gdb_busy(); return ""; } string file = ""; int line = 0; switch (gdb->type()) { case GDB: case PYDB: // XXX { file = reply.from('\"'); file = file.before('\"'); const string line_s = reply.after("Line "); line = atoi(line_s.chars()); break; } case DBX: line = line_of_listing(reply, silent); if (line > 0) { file = gdb_question("file"); strip_trailing_space(file); } break; case BASH: case DBG: case JDB: case MAKE: case PERL: line = line_of_listing(reply, silent); file = source_view->line_of_cursor(); file = file.before(':'); break; case XDB: { #if RUNTIME_REGEX static regex rxcolons("[^:]*:[^:]*: *[0-9][0-9]*.*"); #endif if (reply.matches(rxcolons)) { file = reply.before(':'); reply = reply.after(':'); // Skip file reply = reply.after(':'); // Skip function strip_leading_space(reply); const string line_s = reply.before(':'); line = atoi(line_s.chars()); } else { // post_gdb_message(reply); return ""; } break; } } string pos = ""; if (line > 0) pos = file + ":" + itostring(line); pos_cache[func_name] = pos; return pos; }
void PosBuffer::filter_dbg(string& answer) { int idx1, idx2; if (already_read != PosComplete && !answer.contains('\n')) { // Position info is incomplete answer_buffer = answer; answer = ""; already_read = PosPart; return; } idx1 = 0; while (idx1 < (int)answer.length()) { idx2 = answer.index('\n', idx1); if (idx2 < 0) idx2 = answer.length(); string line = answer.at(idx1, idx2 - idx1); if (line.contains('\n')) line = line.before('\n'); strip_trailing_space(line); // DBG uses a format like `test.php:4 <main>\n echo $a."hello world."' #if RUNTIME_REGEX static regex rxdbgpos("[^ \t]*:[ \t]*[1-9][0-9]*[ \t]*<.*>"); static regex rxdbgframepos("#[0-9]*[ \t]*<.*>[ \t]*at[ \t]*[^ \t]*:[ \t]*[1-9][0-9]*"); #endif if (line.matches(rxdbgpos)) { string file = line.before(':'); line = line.after(':'); string line_no = line; strip_leading_space(line_no); line_no = line_no.before(' '); line = line.after('<'); func_buffer = line.before('>'); strip_leading_space(func_buffer); pos_buffer = file + ":" + line_no; // Delete this line from output answer.at(idx1, idx2 - idx1 + 1) = ""; already_read = PosComplete; break; } else if (line.matches(rxdbgframepos)) { string addr = line.before(">"); func_buffer = addr.after('<'); strip_leading_space(func_buffer); string file = line.after(">"); file = file.after("at"); strip_leading_space(file); string line_no = file.after(':'); strip_leading_space(line_no); file = file.before(':'); pos_buffer = file + ":" + line_no; // Delete this line from output answer.at(idx1, idx2 - idx1 + 1) = ""; already_read = PosComplete; break; } idx1 = idx2+1; } }
void PosBuffer::filter_bash(string& answer) { // Check for regular source info int index1 = answer.index ("\032\032"); if (index1 < 0) { int index_p = answer.index ("\032"); if (index_p >= 0 && index_p == int(answer.length()) - 1) { // Possible begin of position info at end of ANSWER answer_buffer = "\032"; answer = answer.before (index_p); already_read = PosPart; return; } } else { // ANSWER contains position info int index2 = answer.index("\n", index1); if (index2 == -1) { // Position info is incomplete answer_buffer = answer.from (index1); answer = answer.before (index1); already_read = PosPart; return; } else { assert (index1 < index2); // Position info is complete already_read = PosComplete; pos_buffer = answer.at(index1 + 2, index2 - (index1 + 2)); answer.at(index1, index2 - index1 + 1) = ""; } } if (already_read != PosComplete) { // Try '(FILE:LINE):\n'; // INDEX points at the start of a line int index = 0; while (index >= 0 && !answer.empty()) { string line = answer.from(index); if (line.contains('\n')) line = line.before('\n'); strip_trailing_space(line); #if RUNTIME_REGEX static regex rxbashpos("[(][^:]*:[1-9][0-9]*[)]:"); #endif if (line.matches(rxbashpos)) { // Fetch position pos_buffer = line.after('('); pos_buffer = pos_buffer.before(')'); already_read = PosComplete; // Delete this line from output int next_index = answer.index('\n', index); if (next_index < 0) next_index = answer.length(); else next_index++; answer.at(index, next_index - index) = ""; break; } else { // Look at next line index = answer.index('\n', index); if (index >= 0) index++; } } } }
void PosBuffer::filter_xdb(string& answer) { if (already_read != PosComplete && !answer.contains('\n')) { // Position info is incomplete answer_buffer = answer; answer = ""; already_read = PosPart; return; } // INDEX points at the start of a line int index = 0; while (index >= 0 && !answer.empty()) { string line = answer.from(index); if (line.contains('\n')) line = line.before('\n'); strip_trailing_space(line); // XDB uses a format like `ctest.c: main: 4: int a = 33;' #if RUNTIME_REGEX static regex rxxdbpos("[^ \t]*:.*: [1-9][0-9]*[: ].*"); #endif if (line.matches(rxxdbpos)) { string file = line.before(':'); line = line.after(':'); // The function name may contain "::" string func = line; while (line.contains("::")) line = line.after("::"); line = line.from(':'); func = func.before(line); line = line.after(':'); string line_no = line.before(':'); strip_leading_space(func); strip_leading_space(line_no); line_no = line_no.through(rxint); pos_buffer = file + ":" + line_no; func_buffer = func; already_read = PosComplete; // Delete this line from output int next_index = answer.index('\n', index); if (next_index < 0) next_index = answer.length(); else next_index++; answer.at(index, next_index - index) = ""; break; } else { // Look at next line index = answer.index('\n', index); if (index >= 0) index++; } } // Check for trailing `:' in last line index = answer.index('\n', -1) + 1; if (already_read != PosComplete && answer.index(':', index) >= 0) { answer_buffer = answer.from(index); answer.from(index) = ""; already_read = PosPart; return; } }
void PosBuffer::filter_jdb(string& answer) { if (already_read != PosComplete && !answer.contains('\n')) { // Position info is incomplete answer_buffer = answer; answer = ""; already_read = PosPart; return; } int index = 0; while (index >= 0 && !answer.empty()) { string line = answer.from(index); if (line.contains('\n')) line = line.before('\n'); strip_trailing_space(line); // Having reached a breakpoint, JDB 1.1 uses a format like // `(HelloWorld:3)'. // Having loaded a class, JDB uses `class(foo.bar.HelloWorld)'. // This may be prefixed by the fully qualified class // name (`path'), as in // `GlobalView.Map.MapController.createMap (MapController:53)'. // In such a case, prefer the fully qualified name. #if RUNTIME_REGEX static regex rxjdbpos("((class|interface)[(][A-Za-z][A-Za-z0-9.]*[)]|" "[(][A-Za-z][A-Za-z0-9.]*:[1-9][0-9]*[)])"); #endif if (gdb->has_debug_command() && line.matches(rxjdbpos)) { string file = line.after('('); file = file.before(')'); string line_no = "0"; if (file.contains(':')) { line_no = file.after(':'); file = file.before(':'); } // Check whether a fully qualified class name is prepended int class_index = line.index('(') - 1; while (class_index >= 0 && line[class_index] == ' ') class_index--; while (class_index >= 1 && line[class_index - 1] != ' ') class_index--; if (class_index >= 0) { string class_name = line.from(class_index); class_name = class_name.before('('); strip_trailing_space(class_name); if (class_name.contains('.') && class_name.matches(rxchain)) { // Strip method class_name = class_name.before('.', -1); if (class_name.contains("." + file)) { // CLASS_NAME is more qualified - use it file = class_name; } } } pos_buffer = file + ":" + line_no; already_read = PosComplete; #if 0 // Delete this line from output int next_index = answer.index('\n', index); if (next_index < 0) next_index = answer.length(); else next_index++; answer.at(index, next_index - index) = ""; #endif break; } else if (line.contains("line=")) { // JDB 1.2 output format: // `Step completed: thread="main", jtest.array_test(), // line=77, bci=206' string line_no = line.after("line="); line_no = line_no.before(", "); string class_name = line.after(", "); class_name = class_name.before(", "); if (class_name.contains("(")) { // Within a method class_name = class_name.before('('); if (class_name.contains(".")) class_name = class_name.before('.', -1); } string file = class_name; strip_space(file); pos_buffer = file + ":" + line_no; already_read = PosComplete; break; } else { // Look at next line index = answer.index('\n', index); if (index >= 0) index++; } } }
int cddb_handle_data (const char *data, char **artist, char **dtitle, char *titles[], int *totaltracks, char **year, char **dgenre) { char *row, *mark; const char *tmp = data; int i, j, counter = 0, track, previoustrack = 100, ttcounter = 0; char *tempstr; if (strncmp (data, "# xmcd", 6) != 0) return -1; (*dtitle) = NULL; while (*tmp != 0) { /* check against end of string */ /* get the row */ i = strcspn (tmp, "\r\n"); while (tmp[i] == '\r' || tmp[i] == '\n') i++; row = (char *) malloc (i + 1); strncpy (row, tmp, i); row[i] = 0; tmp += i; /* eval the row */ if (strncmp (row, "DYEAR", 5) == 0) { /* CD Year */ tempstr = malloc (MAX_YEAR_LENGTH); strcpy (tempstr, row); tempstr = strchr (row, '='); tempstr++; j = strlen (tempstr); (*year) = (char *) malloc (j + 1); strncpy ((*year), tempstr, (j + 1)); remove_non_unix_chars (*year); } else if (strncmp (row, "DGENRE", 6) == 0) { /* Disc Genre */ tempstr = malloc (MAX_GENRE_LENGTH); strcpy (tempstr, row); tempstr = strchr (row, '='); tempstr++; j = strlen (tempstr); (*dgenre) = (char *) malloc (j + 1); strncpy ((*dgenre), tempstr, (j + 1)); remove_non_unix_chars (*dgenre); } else if (strncmp (row, "TTITLE", 6) == 0) { /* Track Title */ /* get the track number before going on */ /* skip the TTITLE */ mark = row + 6; counter = 0; /* convert ascii -> int */ while (*mark != '=') { counter *= 10; counter += *mark - 0x30; mark++; } mark++; /* and skip the '=' */ track = counter; if (previoustrack != track) ttcounter++; /* create the filename. Append previous title if necessary */ tempstr = malloc (MAX_TITLE_LENGTH); if (previoustrack == track) strcpy (tempstr, titles[track]); else strcpy (tempstr, ""); /* put in the track name */ titles[track] = strcat (tempstr, mark); strip_trailing_space (&titles[track]); strip_leading_space (&titles[track]); previoustrack = track; remove_non_unix_chars (titles[track]); #ifdef DEBUG printf ("Track %d: %s\n", track, titles[track]); #endif } else if ((strncmp (row, "DTITLE", 6) == 0) && (*dtitle == NULL)) { /* CD Title */ i = strcspn (row, "="); i++; /* skip to the data */ mark = row + i; // tm: hack around bogus CDDB entries if (strstr (mark, " / ")) { j = strstr (mark, " / ") - mark + 1; (*artist) = (char *) malloc (j + 1); strncpy ((*artist), mark, j); (*artist)[j] = 0; (*dtitle) = (char *) malloc (strlen (mark) - j); mark = mark + j + 1; strcpy ((*dtitle), mark); } else { #ifdef DEBUG printf ("malformed DTITLE, copying full DTITLE into both artist and dtitle\n"); #endif j = strlen (mark); (*artist) = (char *) malloc (j + 1); strncpy ((*artist), mark, j); (*artist)[j] = 0; (*dtitle) = (char *) malloc (j + 1); strncpy ((*dtitle), mark, j); (*dtitle)[j] = 0; } strip_trailing_space (artist); strip_leading_space (artist); strip_trailing_space (dtitle); strip_leading_space (dtitle); remove_non_unix_chars (*artist); remove_non_unix_chars (*dtitle); convert_slashes (*artist, '_'); // dc: _ Artist, - others convert_slashes (*dtitle, '-'); #ifdef CONVERT_SPACES_IN_ID3_DATA if (((int) config_read (CONF_CDDB_CONVSPC)) == TRUE) { convert_spaces (*artist, '_'); convert_spaces (*dtitle, '_'); } #endif #ifdef DEBUG printf ("Artist: %s\n", (*artist)); printf ("Dtitle: %s\n", (*dtitle)); #endif } /* ignore any other results */ free (row); } *totaltracks = ttcounter; return 0; }