int retriever_services(ClientData clientData, Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ char **argv) /* Argument strings. */ { Tcl_CmdInfo infoPtr; ClientData wcdata = 0; Tcl_CmdProc* wcmd = NULL; char *wname; char *command, *contents; int pargc, i, size, itembuf_size[10], item_size[10]; char *p, *q, *line_items[10], *pline; int result, ret = TCL_OK, fnd = 0; int length; wname = argv[1]; if (wname[0]) { if (!Tcl_GetCommandInfo(interp, wname, &infoPtr)) { Tcl_AppendResult(interp, "wrong # \"", wname, "\" does not exist", (char *) NULL); return TCL_ERROR; } wcdata = infoPtr.clientData; wcmd = (Tcl_CmdProc *)infoPtr.proc; } pargc = 2; command = argv[pargc++]; contents = argv[pargc++]; if (contents[0] == '\0') { Tcl_SetResult (interp, "", TCL_STATIC); return ret; } Tcl_ResetResult (interp); for (i=0;i<10;i++) { line_items[i] = ckalloc (256); itembuf_size[i] = 256; } /* * given a list of found symbols, insert those into the * treetable. *******************************************************/ if ((argc == 5 || argc == 4) && *command == 'i' && strcmp (command, "insert") == 0) { int txtlen = 1024, datalen = 256, newlen, newdlen; int rargc = 0, slen; char *rargv[13]; char *text, *data, image[64], *scope; int fnd; text = ckalloc (txtlen); data = ckalloc (datalen); rargc = 0; rargv[rargc++] = wname; rargv[rargc++] = "insert"; rargv[rargc++] = "end"; rargv[rargc++] = "-text"; rargv[rargc++] = text; rargv[rargc++] = "-data"; rargv[rargc++] = data; rargv[rargc++] = "-image"; rargv[rargc++] = image; if (argc == 5) { rargv[rargc++] = "-parent"; rargv[rargc++] = argv[pargc++]; } for (length = strlen(contents), q = contents; 1;) { char *prevlist = q; result = TclFindElement(interp, q, length, &pline, &q, &size, NULL); if (result != TCL_OK || size == 0) { break; } length -= q - prevlist; /* split line into fields */ fnd = SplitLine (pline, size, itembuf_size, line_items, item_size); /* use dynamic buffers for data */ newdlen = item_size[FIL_POS] + item_size[FRM_POS] + item_size[TO__POS] + 10 /*scope*/ + 4; if (newdlen > datalen) { datalen = newdlen + newdlen / 2; data = ckrealloc (data, datalen); rargv[6] = data; } /* we parse files, when number of columns is 1-2 or * the file filed is empty */ if (fnd == 2 || fnd == 3 || line_items[FIL_POS][0] == 0) { strcpy (image, "file_+_image"); if (line_items[TYP_POS][0] == '1') { continue; /* skip directories */ } /* skip first character, if there is a space */ if (line_items[TYP_POS][0] == ' ') { strcpy (line_items[TYP_POS], line_items[TYP_POS]+1); } /* mark the files entries as special entries */ strcpy (data, "1"); } else { /* scope name */ scope = GetScope (line_items[NAM_POS]); if (scope[0] == 0) { scope = "ud"; } slen = strlen (scope); /* skip 'iu' and 'in': there are ref. to includes */ if (slen == 2 && scope[0] == 'i' && (scope[1] == 'u' || scope[1] == 'n')) { continue; } /* only 'fd' 'fu' 'md' 'mi' and 'fr' have parameter list */ if (! (slen == 2 && ( (scope[0] == 'm' && (scope[1] == 'i' || scope[1] == 'd')) || (scope[0] == 'f' && (scope[1] == 'd' || scope[1] == 'u' || scope[1] == 'r'))))) { line_items[PRM_POS][0] = 0; } sprintf (image, "type_%s_image", scope); sprintf (data, "%s\t%s\t%s\t%s", line_items[FIL_POS], line_items[FRM_POS], line_items[TO__POS], scope); } newlen = item_size[NAM_POS] + item_size[CLS_POS] + item_size[TYP_POS] + item_size[PRM_POS] + item_size[FIL_POS] + 5; if (newlen > txtlen) { txtlen = newlen + newlen / 2; text = ckrealloc (text, txtlen); rargv[4] = text; } if (line_items[CLS_POS][0] == '#') { line_items[CLS_POS][0] = 0; } sprintf (text, "%s\t%s\t%s\t%s\t%s", line_items[NAM_POS], line_items[CLS_POS], line_items[TYP_POS], line_items[PRM_POS], line_items[FIL_POS]); (*wcmd)(wcdata, interp, rargc, rargv); } ckfree (data); ckfree (text); } else if (argc == 10 && *command == 'f' && strcmp (command, "filter") == 0) { char *pattern, *file, *type, *parameter; int from, to; char *buf; int buf_size = 512; int length; pattern = argv[pargc++]; file = argv[pargc++]; type = argv[pargc++]; parameter = argv[pargc++]; from = atoi (argv[pargc++]); to = atoi (argv[pargc++]); buf = (char*)ckalloc (buf_size); if (*contents) for (length=strlen(contents), q = contents; 1;) { char *prevlist = q; result = TclFindElement(interp, q, length, &pline, &q, &size, NULL); if (result != TCL_OK || size == 0) { break; } length -= q - prevlist; SplitLine (pline, size, itembuf_size, line_items, item_size); if (*type) { if (item_size[TYP_POS] == 0) { continue; } if (strncmp (type, line_items[TYP_POS], item_size[TYP_POS]) != 0) { continue; } } if (*parameter) { if (item_size[PRM_POS] == 0) { continue; } /* delete () from parameter list, if parameter doesn't * begin with '(' */ if (*parameter != '(') { for (p=line_items[PRM_POS]; p[1] && p[2]; p++) { p[0] = p[1]; } p[0] = 0; } if (strcmp (parameter, line_items[PRM_POS]) != 0) { continue; } } if (*file) { if (*file != *line_items[FIL_POS] || strcmp (file, line_items[FIL_POS]) != 0) { continue; } } if (from != -1) { if (from < GetNumber (line_items[FRM_POS])) { continue; } } if (to != -1) { if (to > GetNumber (line_items[TO__POS])) { continue; } } if (buf_size < size+1) { buf_size += size; buf = (char*)ckrealloc (buf, buf_size); } memcpy (buf, pline, size); buf[size] = 0; Tcl_AppendElement (interp, buf); fnd = 1; } if (!fnd) { Tcl_SetResult (interp, "", TCL_STATIC); } ckfree (buf); } else { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " tree filter contents pattern file type parameter from to |\n" " tree insert contents ?parent?\"", (char *) NULL); ret = TCL_ERROR; } for(i=0;i<10;i++) { ckfree (line_items[i]); } return ret; }
int cross_services(ClientData clientData, Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ char **argv) /* Argument strings. */ { Tcl_CmdInfo infoPtr; ClientData wcdata; Tcl_CmdProc* wcmd; char *wname; char *command, *contents; int pargc, i, size; char *pline, *q; int result, ret = TCL_OK; wname = argv[1]; if (wname[0]) { if (!Tcl_GetCommandInfo(interp, wname, &infoPtr)) { Tcl_AppendResult(interp, "wrong # \"", wname, "\" does not exist", (char *) NULL); return TCL_ERROR; } wcdata = infoPtr.clientData; wcmd = (Tcl_CmdProc *)infoPtr.proc; } Tcl_ResetResult (interp); pargc = 2; command = argv[pargc++]; contents = argv[pargc++]; if (argc == 12 && *command == 'f' && strcmp (command, "filter") == 0) { char *refartStr, *testline, *shown_scopes, *ref_access; char *file = NULL; enum RefTypes refart; char **tfields, **lfields=NULL, **oldfields=NULL; char *tmpline; int tmpline_size = 512; int uniq, have, accept_static, accept_param, fsize, tsize; int AddRefArt=0; int length; char *line[line_arg_count], AddRefartStr[16] = {0}; Tcl_DString res, erg; refartStr = argv[pargc++]; testline = argv[pargc++]; uniq = atoi (argv[pargc++]); have = atoi (argv[pargc++]); accept_param = atoi (argv[pargc++]); accept_static= atoi (argv[pargc++]); shown_scopes = argv[pargc++]; ref_access = argv[pargc++]; if (accept_static) { /* Information to the actual scope */ if (Tcl_SplitList (interp, testline, &tsize, &tfields) != TCL_OK) { return TCL_ERROR; } file = tfields[file1_pos]; } if (strcmp (refartStr, "to") == 0) { refart = REF_TO; } else { refart = REF_BY; } /* init some variables */ for (i=0; i<line_arg_count; i++) { line[i] = ""; } Tcl_DStringInit(&res); Tcl_DStringInit(&erg); tmpline = (char*)ckalloc (tmpline_size); tmpline[0] = 0; for (length=strlen(contents), q = contents; 1;) { char *prevlist = q; result = TclFindElement(interp, q, length, &pline, &q, &size, NULL); if (result != TCL_OK || size == 0) { break; } length -= q - prevlist; if (size > tmpline_size) { tmpline_size += size; tmpline = ckrealloc (tmpline, tmpline_size); } memcpy (tmpline, pline, size); tmpline[size] = 0; if (Tcl_SplitList (interp, tmpline, &fsize, &lfields) != TCL_OK) { continue; } if (fsize != DB_COUNT) { ckfree ((char*)lfields); continue; } if (*shown_scopes && strstr (shown_scopes, lfields[DB_SCP2]) == NULL) { continue; } if (*ref_access && strstr (ref_access, lfields[DB_REFA]) == NULL) { continue; } if (uniq && oldfields) { if (strcmp (oldfields[DB_CLS2], lfields[DB_CLS2]) == 0 && strcmp (oldfields[DB_SYM2], lfields[DB_SYM2]) == 0 && strcmp (oldfields[DB_SCP2], lfields[DB_SCP2]) == 0 && (! accept_param || (accept_param && strcmp (oldfields[DB_PRM2], lfields[DB_PRM2]) == 0))) { if (!AddRefartStr[0] || (lfields[DB_REFA][0] && strchr (AddRefartStr, lfields[DB_REFA][0]) == NULL)) { strcat (AddRefartStr, lfields[DB_REFA]); } ckfree ((char *) lfields); continue; } } /* Static functions and variables */ if (accept_static && refart == REF_TO && lfields[DB_REFA][0] != 0 && ! cross_is_type_with_classes(lfields[DB_SCP2])) { int attr; if (Tcl_GetInt(interp, lfields[DB_REFA], &attr) == TCL_OK && (! (attr&PAF_STATIC) || strcmp (lfields[DB_FILE], file) != 0)) { ckfree ((char*)lfields); continue; } } if (have) { ckfree ((char *) lfields); Tcl_DStringAppendElement (&erg, "yes"); break; } if (AddRefArt) { Tcl_DStringAppendElement(&res, AddRefartStr); Tcl_DStringAppendElement(&erg, Tcl_DStringValue(&res)); } else { AddRefArt = 1; } strcpy (AddRefartStr, lfields[DB_REFA]); line[class1_pos] = lfields[DB_CLS2]; line[item1_pos] = lfields[DB_SYM2]; line[what1_pos] = lfields[DB_SCP2]; line[param1_pos] = lfields[DB_PRM2]; line[file_pos] = lfields[DB_FILE]; line[file_line_pos] = lfields[DB_LINE]; Tcl_DStringFree (&res); for (i=0; i<refart_pos; i++) { Tcl_DStringAppendElement (&res, line[i]); } /* Store last line */ if (oldfields) { ckfree ((char*)oldfields); } oldfields = lfields; } if (AddRefArt) { Tcl_DStringAppendElement(&res, AddRefartStr); Tcl_DStringAppendElement(&erg, Tcl_DStringValue(&res)); AddRefartStr[0] = 0; } Tcl_DStringFree (&res); if (accept_static) { ckfree ((char*)tfields); } if (oldfields) { ckfree ((char*)oldfields); } ckfree (tmpline); Tcl_DStringResult(interp, &erg); Tcl_DStringFree (&erg); } else if (argc == 7 && *command == 'i' && strcmp (command, "insert") == 0) { } else { char tmp[32]; sprintf (tmp, "%i", argc); Tcl_AppendResult(interp, "wrong # args(", tmp, "): should be \"", argv[0], " filter \"\" contents RefArt line unique have accept_param accept_static shown_scopes ref_access |\n" "insert widget contents RefArt id line\n", "\"", (char *) NULL); ret = TCL_ERROR; } return ret; }
int Tcl_SplitList( Tcl_Interp *interp /* Interpreter to use for error reporting. */ , unsigned char *list /* Pointer to string with list structure. */ , int *argcPtr /* Pointer to location to fill in with * the number of elements in the list. */ , unsigned char ***argvPtr /* Pointer to place to store pointer to array * of pointers to list elements. */ ) { unsigned char **argv; register unsigned char *p; int size, i, result, elSize, brace; unsigned char *element; /* * Figure out how much space to allocate. There must be enough * space for both the array of pointers and also for a copy of * the list. To estimate the number of pointers needed, count * the number of space characters in the list. */ for (size = 1, p = list; *p != 0; p++) { if (isspace(*p)) { size++; } } size++; /* Leave space for final NULL pointer. */ argv = (unsigned char**) mem_alloc (interp->pool, (unsigned) ((size * sizeof(char *)) + (p - list) + 1)); for (i = 0, p = ((unsigned char *) argv) + size*sizeof(char *); *list != 0; i++) { result = TclFindElement(interp, list, &element, &list, &elSize, &brace); if (result != TCL_OK) { mem_free (argv); return result; } if (*element == 0) { break; } if (i >= size) { mem_free (argv); Tcl_SetResult(interp, (unsigned char*) "internal error in Tcl_SplitList", TCL_STATIC); return TCL_ERROR; } argv[i] = p; if (brace) { strncpy(p, element, elSize); p += elSize; *p = 0; p++; } else { TclCopyAndCollapse(elSize, element, p); p += elSize+1; } } argv[i] = 0; *argvPtr = argv; *argcPtr = i; return TCL_OK; }