/* ----------------------------------------------------------------------------- * Swig_string_regex() * * Executes a regular expression substitution. For example: * * Printf(stderr,"gsl%(regex:/GSL_.*_/\\1/)s","GSL_Hello_") -> gslHello * ----------------------------------------------------------------------------- */ String *Swig_string_regex(String *s) { const int pcre_options = 0; String *res = 0; pcre *compiled_pat = 0; const char *pcre_error, *input; int pcre_errorpos; String *pattern = 0, *subst = 0; int captures[30]; if (split_regex_pattern_subst(s, &pattern, &subst, &input)) { int rc; compiled_pat = pcre_compile( Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL); if (!compiled_pat) { Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n", pcre_error, Char(pattern), pcre_errorpos); exit(1); } rc = pcre_exec(compiled_pat, NULL, input, (int)strlen(input), 0, 0, captures, 30); if (rc >= 0) { res = replace_captures(rc, input, subst, captures, pattern, s); } else if (rc != PCRE_ERROR_NOMATCH) { Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n", rc, Char(pattern), input); exit(1); } } DohDelete(pattern); DohDelete(subst); pcre_free(compiled_pat); return res ? res : NewStringEmpty(); }
int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) { pcre *compiled_pat; const char *err; int errpos; int rc; compiled_pat = pcre_compile(Char(pattern), 0, &err, &errpos, NULL); if (!compiled_pat) { Swig_error("SWIG", Getline(n), "Invalid regex \"%s\": compilation failed at %d: %s\n", Char(pattern), errpos, err); exit(1); } rc = pcre_exec(compiled_pat, NULL, Char(s), Len(s), 0, 0, NULL, 0); pcre_free(compiled_pat); if (rc == PCRE_ERROR_NOMATCH) return 0; if (rc < 0 ) { Swig_error("SWIG", Getline(n), "Matching \"%s\" against regex \"%s\" failed: %d\n", Char(s), Char(pattern), rc); exit(1); } return 1; }
int main() { char s1[MAXLINE], s2[MAXLINE]; Getline(s1, MAXLINE); Getline(s2, MAXLINE); printf("%d\n", any(s1, s2)); return 0; }
void Swig_extend_merge(Node *cls, Node *am) { Node *n; Node *csym; n = firstChild(am); while (n) { String *symname; if (Strcmp(nodeType(n),"constructor") == 0) { symname = Getattr(n,"sym:name"); if (symname) { if (Strcmp(symname,Getattr(n,"name")) == 0) { /* If the name and the sym:name of a constructor are the same, then it hasn't been renamed. However---the name of the class itself might have been renamed so we need to do a consistency check here */ if (Getattr(cls,"sym:name")) { Setattr(n,"sym:name", Getattr(cls,"sym:name")); } } } } symname = Getattr(n,"sym:name"); DohIncref(symname); if ((symname) && (!Getattr(n,"error"))) { /* Remove node from its symbol table */ Swig_symbol_remove(n); csym = Swig_symbol_add(symname,n); if (csym != n) { /* Conflict with previous definition. Nuke previous definition */ String *e = NewStringEmpty(); String *en = NewStringEmpty(); String *ec = NewStringEmpty(); Printf(ec,"Identifier '%s' redefined by %%extend (ignored),",symname); Printf(en,"%%extend definition of '%s'.",symname); SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_REDEFINED,Getfile(csym),Getline(csym),"%s\n",ec); Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en); SWIG_WARN_NODE_END(n); Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(csym),Getline(csym),ec, Getfile(n),Getline(n),en); Setattr(csym,"error",e); Delete(e); Delete(en); Delete(ec); Swig_symbol_remove(csym); /* Remove class definition */ Swig_symbol_add(symname,n); /* Insert extend definition */ } } n = nextSibling(n); } }
static int split_regex_pattern_subst(String *s, String **pattern, String **subst, const char **input) { const char *pats, *pate; const char *subs, *sube; /* Locate the search pattern */ const char *p = Char(s); if (*p++ != '/') goto err_out; pats = p; p = strchr(p, '/'); if (!p) goto err_out; pate = p; /* Locate the substitution string */ subs = ++p; p = strchr(p, '/'); if (!p) goto err_out; sube = p; *pattern = NewStringWithSize(pats, (int)(pate - pats)); *subst = NewStringWithSize(subs, (int)(sube - subs)); *input = p + 1; return 1; err_out: Swig_error("SWIG", Getline(s), "Invalid regex substitution: '%s'.\n", s); exit(1); }
void VetoThres2(Int_t Lo, Int_t Hi) { TCanvas* Window; TTimer* Refresh; TH1F* Energy; Char_t Buff[256]; Char_t* Keyb; Double_t Pos[438]; Window = new TCanvas(); Window->SetCrosshair(); Window->ToggleEventStatus(); Refresh = new TTimer("Flush()", 50, kFALSE); for(Int_t ch=Lo; ch<Hi+1; ch++) { sprintf(Buff, "Veto_Energy%d", ch); Energy = (TH1F*)gROOT->FindObject(Buff); Energy->GetXaxis()->SetRange(0, 250); Energy->Draw(); Window->Update(); sprintf(Buff, "Threshold for %d: ", ch); Refresh->TurnOn(); Refresh->Reset(); Keyb = Getline(Buff); Refresh->TurnOff(); Pos[ch] = atof(Keyb); } for(Int_t ch=Lo; ch<Hi+1; ch++) printf("%5.1f\n", Pos[ch]); }
/* internal function for processing an encoding */ static DOH *encode(char *name, DOH *s) { DOH *handle, *ns; DOH *(*fn) (DOH *); long pos; char *cfmt = strchr(name, ':'); DOH *tmp = 0; if (cfmt) { tmp = NewString(cfmt + 1); Append(tmp, s); Setfile(tmp, Getfile((DOH *) s)); Setline(tmp, Getline((DOH *) s)); *cfmt = '\0'; } if (!encodings || !(handle = Getattr(encodings, name))) { return Copy(s); } if (tmp) s = tmp; pos = Tell(s); Seek(s, 0, SEEK_SET); fn = (DOH *(*)(DOH *)) Data(handle); ns = (*fn) (s); Seek(s, pos, SEEK_SET); if (tmp) Delete(tmp); return ns; }
Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl) { if (!namewarn_hash && !namewarn_list) return 0; if (n) { /* Return in the obvious cases */ if (!name || !Swig_need_name_warning(n)) { return 0; } else { String *access = Getattr(n, "access"); int is_public = !access || Equal(access, "public"); if (!is_public && !Swig_need_protected(n)) { return 0; } } } if (name) { /* Check to see if the name is in the hash */ Hash *wrn = Swig_name_object_get(Swig_name_namewarn_hash(), prefix, name, decl); if (wrn && !Swig_name_match_nameobj(wrn, n)) wrn = 0; if (!wrn) { wrn = Swig_name_nameobj_lget(Swig_name_namewarn_list(), n, prefix, name, decl); } if (wrn && Getattr(wrn, "error")) { if (n) { Swig_error(Getfile(n), Getline(n), "%s\n", Getattr(wrn, "name")); } else { Swig_error(cparse_file, cparse_line, "%s\n", Getattr(wrn, "name")); } } return wrn; } else { return 0; } }
int Swig_name_regexmatch_value(Node *n, String *pattern, String *s) { (void)pattern; (void)s; Swig_error("SWIG", Getline(n), "PCRE regex matching is not available in this SWIG build.\n"); exit(1); }
String *Swig_stringify_with_location(DOH *object) { String *str = NewStringEmpty(); if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); if (object) { int line = Getline(object); String *formatted_filename = format_filename(Getfile(object)); if (line > 0) { Printf(str, diag_line_fmt, formatted_filename, line); } else { Printf(str, diag_eof_fmt, formatted_filename); } if (Len(object) == 0) { Printf(str, "[EMPTY]"); } else { Printf(str, "[%s]", object); } Delete(formatted_filename); } else { Printf(str, "[NULL]"); } return str; }
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s) { String *result = NewStringEmpty(); const char *p = Char(subst); while (*p) { /* Copy part without substitutions */ const char *q = strchr(p, '\\'); if (!q) { Write(result, p, strlen(p)); break; } Write(result, p, q - p); p = q + 1; /* Handle substitution */ if (*p == '\0') { Putc('\\', result); } else if (isdigit((unsigned char)*p)) { int group = *p++ - '0'; if (group < num_captures) { int l = captures[group*2], r = captures[group*2 + 1]; if (l != -1) { Write(result, input + l, r - l); } } else { Swig_error("SWIG", Getline(s), "PCRE capture replacement failed while matching \"%s\" using \"%s\" - request for group %d is greater than the number of captures %d.\n", Char(pattern), input, group, num_captures-1); } } } return result; }
int main() /* Reverse Polish notation */ { int type; double op2; char s[MAXOP]; double ans = 0.0; while (Getline(expression, MAXOP)) while ((type = getop(s)) != EOF) { switch (type) { case NUMBER: push(atof(s)); break; case 'a': push(ans); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '/': op2 = pop(); if (op2 != 0.0) push(pop() / op2); else printf("error: zero divisor\n"); break; case '%': op2 = pop(); if (op2 != 0.0) push(fmod(pop(), op2)); /* use g++ to compile */ else printf("error: zero divisor\n"); break; case SIN: push(sin(pop())); break; case EXP: push(exp(pop())); break; case POW: op2 = pop(); push(pow(pop(), op2)); break; case '\n': ans = pop(); printf("\t%.8g\n", ans); break; default: printf("error: unknown command %s\n", s); break; } if (type == '\n') break; } return 0; }
void SwigScanner_push(SwigScanner *s, String *txt) { assert(s && txt); Push(s->scanobjs,txt); if (s->str) Delete(s->str); s->str = txt; DohIncref(s->str); s->line = Getline(txt); }
int Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; char temp[512]; va_start(ap, n); name = va_arg(ap, char *); while (name) { int newref = 0; int opt = 0; if (*name == '*') { newref = 1; name++; } else if (*name == '?') { newref = 1; opt = 1; name++; } obj = Getattr(n,name); if (!opt && !obj) { Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", Getfile(n), Getline(n), name, nodeType(n)); assert(obj); } if (!obj) obj = DohNone; if (newref) { /* Save a copy of the attribute */ strcpy(temp,ns); strcat(temp,":"); strcat(temp,name); Setattr(n,temp,obj); } name = va_arg(ap, char *); } va_end(ap); /* Save the view */ { String *view = Getattr(n,"view"); if (view) { if (Strcmp(view,ns) != 0) { strcpy(temp,ns); strcat(temp,":view"); Setattr(n,temp,view); Setattr(n,"view",ns); } } else { Setattr(n,"view",ns); } } return 1; }
int main() { int i; char len[MAX_LEN]; Getline(len, MAX_LEN); for(i = 0; len[i] != '\0'; i++) ; reverse_line(len, i); }
int main() { char line[MAXLINE]; int found = 0; while (Getline(line, MAXLINE) > 0) if (strrindex(line, pattern) >= 0) { printf("%s", line); found++; } return found; }
void Swig_extend_unused_check(void) { Iterator ki; if (!extendhash) return; for (ki = First(extendhash); ki.key; ki = Next(ki)) { if (!Strchr(ki.key,'<')) { SWIG_WARN_NODE_BEGIN(ki.item); Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", SwigType_namestr(ki.key)); SWIG_WARN_NODE_END(ki.item); } } }
Node *copyNode(Node *n) { Iterator ki; Node *c = NewHash(); for (ki = First(n); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { Setattr(c, ki.key, Copy(ki.item)); } } Setfile(c, Getfile(n)); Setline(c, Getline(n)); return c; }
/************ wait funtion !! *************************************************************** *********************************************************************************************/ void wait(){ TTimer *timer = new TTimer("gSystem->ProcessEvents();", 50, kFALSE); char *input; Bool_t done = kFALSE; do{ timer->TurnOn(); timer->Reset(); input=Getline("Type <return> to continue : "); timer->TurnOff(); if(input){ done =kTRUE; } }while(!done); }
void SwigScanner_skip_line(SwigScanner *s) { char c; int done = 0; Clear(s->text); Setfile(s->text,Getfile(s->str)); Setline(s->text,Getline(s->str)); while (!done) { if ((c = nextchar(s)) == 0) return; if (c == '\\') c = nextchar(s); else if (c == '\n') done = 1; } return; }
int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; nlines = 0; while ((len = Getline(line, MAXLEN)) > 0) if (nlines >= maxlines || (p = alloc(len)) == NULL) return -1; else { line[len - 1] = '\0'; strcpy(p, line); lineptr[nlines++] = p; } return nlines; }
Parm *CopyParm(Parm *p) { Parm *np = NewHash(); Iterator ki; for (ki = First(p); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { DOH *c = Copy(ki.item); Setattr(np,ki.key,c); Delete(c); } } Setfile(np, Getfile(p)); Setline(np, Getline(p)); return np; }
void Swig_cparse_replace_descriptor(String *s) { char tmp[512]; String *arg = 0; SwigType *t; char *c = 0; while ((c = strstr(Char(s), "$descriptor("))) { char *d = tmp; int level = 0; while (*c) { if (*c == '(') level++; if (*c == ')') { level--; if (level == 0) { break; } } *d = *c; d++; c++; } *d = 0; arg = NewString(tmp + 12); t = Swig_cparse_type(arg); Delete(arg); arg = 0; if (t) { String *mangle; String *descriptor; mangle = SwigType_manglestr(t); descriptor = NewStringf("SWIGTYPE%s", mangle); SwigType_remember(t); *d = ')'; d++; *d = 0; Replace(s, tmp, descriptor, DOH_REPLACE_ANY); Delete(mangle); Delete(descriptor); Delete(t); } else { Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n"); break; } } }
/* Print the length of arbitrary long input lines. */ int main(){ int len; /* current line length */ int max; /* maximum length seen so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line saved here */ max =0; while ((len = Getline(line, MAXLINE)) > 0) if (len > max){ max = len; copy(longest, line); } if (max > 0) printf("The longest input line is: %s\nIt's length is: %d\n", longest, max-1); return 0; }
main() { int len; /* current line length */ int max = 0; /* maximum length seen so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line saved here */ while ((len = Getline(line, MAXLINE)) > 0) if (len > max) { max = len; copyline(longest, line); } if (max> 0) /* there was a line */ printf("\n\nThe line : %swas the longest.\n\n", longest); return 0; }
main () { int len; extern int max; extern char longest[]; while ((len = Getline()) > 0) if (len > max) { max = len; copy( ); } if (max > 0) /* there was a line */ printf("%s", longest); return 0; }
void Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; va_start(ap, n); name = va_arg(ap, char *); while (name) { int newref = 0; int opt = 0; if (*name == '*') { newref = 1; name++; } else if (*name == '?') { newref = 1; opt = 1; name++; } obj = Getattr(n, name); if (!opt && !obj) { Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n)); assert(obj); } if (!obj) obj = DohNone; if (newref) { /* Save a copy of the attribute */ Setattr(n, NewStringf("%s:%s", ns, name), obj); } name = va_arg(ap, char *); } va_end(ap); /* Save the view */ { String *view = Getattr(n, "view"); if (view) { if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); Setattr(n, "view", NewString(ns)); } } else { Setattr(n, "view", NewString(ns)); } } }
int main(int argc, char *argv[]) { //int line=0,hang=0; int i = 0; int len = 0; int line[MAX_LINE]; //int strock[MAX_LINE][MAX_LINE]; int strock[MAX_LINE]; while ((len = Getline(line, MAX_LINE)) > 0){ reverse(line, strock); } for(i=0; strock[i]!='\0'; i++){ printf("%c",strock[i]); } }
/* ----------------------------------------------------------------------------- * nextchar() * * Returns the next character from the scanner or 0 if end of the string. * ----------------------------------------------------------------------------- */ static char nextchar(Scanner *s) { int nc; if (!s->str) return 0; while ((nc = Getc(s->str)) == EOF) { Delete(s->str); s->str = 0; Delitem(s->scanobjs, 0); if (Len(s->scanobjs) == 0) return 0; s->str = Getitem(s->scanobjs, 0); s->line = Getline(s->str); DohIncref(s->str); } if ((nc == '\n') && (!s->freeze_line)) s->line++; Putc(nc,s->text); return (char)nc; }
void Swig_fragment_emit(String *name) { String *code; if (!fragments) return; code = Getattr(fragments,name); if (code) { String *section = Getmeta(code,"section"); if (section) { File *f = Swig_filebyname(section); if (!f) { Swig_error(Getfile(code),Getline(code),"Bad section '%s' for code fragment '%s'\n", section,name); } else { Printf(f,"%s\n",code); } } Delattr(fragments,name); } }