static int CheckDirCache(String path) { String dirName; String filePtr; String suffixPtr; int numDirs, dirNameLen, fileNameLen; Cardinal i, j; char stackString[MAX_DIR_PATH_LEN]; (void) _XmOSAbsolutePathName(path, &path, stackString); _XmOSFindPathParts(path, &filePtr, &suffixPtr); if (path == filePtr) { dirNameLen = 0; fileNameLen = strlen(path); } else { /* take the slash into account */ dirNameLen = filePtr - path - 1; fileNameLen = strlen(path) - dirNameLen - 1; } /* * set global variable for later use */ #ifndef XTHREADS GleafName = filePtr; #endif if (dirNameLen == 0) { return DtINVALID_CACHED_DIR; } /* * loop thru the dir list. on the last pass create the new cached * dir and process it. */ _XmProcessLock(); numDirs = cacheList.numDirs; for (i = 0; i <= numDirs; i++) { String currName; int currNameLen; String nameHeap; DtValidCachedDir currDir; if (i == cacheList.numDirs) { /* * we didn't get a hit on the directory list so create a new one */ if (cacheList.numDirs == cacheList.maxDirs) { cacheList.maxDirs += 16; cacheList.dirs = (DtCachedDir *) XtRealloc((char *)cacheList.dirs, cacheList.maxDirs * sizeof (DtCachedDir)); } dirName = strncpy(XtMalloc(dirNameLen+1), path, dirNameLen); dirName[dirNameLen] = '\0'; cacheList.dirs[cacheList.numDirs++] = MakeCachedDirEntry(dirName); } currDir = (DtValidCachedDir)cacheList.dirs[i]; /* * set global variable */ #ifndef XTHREADS GdirName = currDir->dirName; #endif if ((currDir->dirNameLen == dirNameLen) && (strncmp(currDir->dirName, path, dirNameLen) == 0)) { switch(currDir->cachedDirType) { case DtINVALID_CACHED_DIR: case DtUNCACHED_DIR: _XmProcessUnlock(); return currDir->cachedDirType; break; case DtVALID_CACHED_DIR: nameHeap = (String) &(currDir->nameOffsets[currDir->numFiles + 1]); for (j = 0; j < currDir->numFiles; j++) { /* * nameOffsets has an extra offset to indicate the * end of the last name (to handle border condition */ currNameLen = (currDir->nameOffsets[j + 1] - currDir->nameOffsets[j]); if (currNameLen == fileNameLen) { currName = &(nameHeap[currDir->nameOffsets[j]]); if (strncmp(currName, filePtr, currNameLen) == 0) { _XmProcessUnlock(); return DtVALID_CACHED_DIR; } } } _XmProcessUnlock(); return DtINVALID_CACHED_DIR; } } } _XmProcessUnlock(); return DtINVALID_CACHED_DIR; }
static Boolean read_atoms_table(Display *display, XmDndAtomsTable tbl) { Atom da, atype; Window win; int aformat, i; unsigned long nitems, bafter; XmDndAtoms *atoms = NULL; Boolean got_it = False; XmDndAtomsTableEntryRec atom_ent; XmDndBufMgrRec bmgr; DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_atoms_table(%d)\n", __FILE__, __LINE__)); da = XmInternAtom(display, _XA_MOTIF_DRAG_ATOMS, False); win = get_drag_window(display); begin_protection(display, win); if (XGetWindowProperty(display, win, da, 0L, PROP_LENGTH, False, da, &atype, &aformat, &nitems, &bafter, (unsigned char **)&atoms) == Success && nitems >= 8) { DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_atom_pairs(%d) - got property, bafter=%i\n", __FILE__, __LINE__, bafter)); got_it = True; } end_protection(display); if (bad_window) { _XmWarning((Widget)XmGetXmDisplay(display), "Invalid DRAG WINDOW fetching DRAG_ATOMS."); } if (!got_it) { if (atoms) { XFree((XPointer)atoms); } return False; } if (atoms->protocol_version != DND_PROTOCOL_VERSION) { _XmWarning((Widget)XmGetXmDisplay(display), "DND Protocol version mismatch."); } if (atoms->byte_order != _XmByteOrder()) { SWAP2BYTES(atoms->num_atoms); SWAP4BYTES(atoms->data_size); } if (!tbl) { tbl = (XmDndAtomsTable) XtMalloc(sizeof(XmDndAtomsTableRec)); tbl->num_entries = 0; tbl->entries = NULL; set_atoms_table(display, tbl); } if (tbl->num_entries < atoms->num_atoms) { tbl->entries = (XmDndAtomsTableEntry) XtRealloc((char *)tbl->entries, atoms->num_atoms * sizeof(XmDndAtomsTableEntryRec)); } if (atoms->num_atoms > 0) { bmgr.atoms = (char *)atoms; bmgr.atom_start = (char *)(atoms + 1); bmgr.atom_size = atoms->data_size; for (i = 0; i < atoms->num_atoms; i++) { _XmReadDragBuffer(&bmgr, False, (char *)&atom_ent, sizeof(XmDndAtomsTableEntryRec)); if (atoms->byte_order != _XmByteOrder()) { SWAP4BYTES(atom_ent.atom); SWAP4BYTES(atom_ent.time); } tbl->entries[i].atom = atom_ent.atom; tbl->entries[i].time = atom_ent.time; } } return True; }
void CheckChipsets(xf86cfgModuleOptions *opts, int *err) { int i, j, ichk, ivnd = 0, vendor = -1, device; const pciDeviceInfo **pDev; SymTabPtr chips = opts->chipsets; chipset_check *check = NULL; int num_check = 0; if (!chips) { CheckMsg(CHECKER_NO_CHIPSETS, "WARNING No chipsets specified.\n"); ++*err; return; } while (chips->name) { device = chips->token & 0xffff; vendor = (chips->token & 0xffff0000) >> 16; if (vendor == 0) vendor = opts->vendor; for (ichk = 0; ichk < num_check; ichk++) if (check[ichk].vendor == vendor) break; if (ichk >= num_check) { check = (chipset_check*) XtRealloc((XtPointer)check, sizeof(chipset_check) * (num_check + 1)); check[num_check].vendor = vendor; memset(&check[num_check], 0, sizeof(chipset_check)); ++num_check; } /* Search for vendor in xf86PCIVendorInfo */ if (xf86PCIVendorInfo) { for (ivnd = 0; xf86PCIVendorInfo[ivnd].VendorID; ivnd++) if (vendor == xf86PCIVendorInfo[ivnd].VendorID) break; } if (xf86PCIVendorInfo && xf86PCIVendorInfo[ivnd].VendorID) { check[ichk].valid_vendor = 1; check[ichk].ivendor = ivnd; } else { CheckMsg(CHECKER_CANNOT_VERIFY_CHIPSET, "WARNING Cannot verify chipset \"%s\" (0x%x)\n", chips->name, device); ++*err; ++chips; continue; } if (xf86PCIVendorInfo && (pDev = xf86PCIVendorInfo[ivnd].Device) != NULL) { if (check[ichk].chipsets == NULL) { for (j = 0; pDev[j]; j++) ; check[ichk].chipsets = (char*)XtCalloc(1, j); } for (j = 0; pDev[j]; j++) { if (device == pDev[j]->DeviceID) { if (strcmp(chips->name, pDev[j]->DeviceName)) { CheckMsg(CHECKER_NOMATCH_CHIPSET_STRINGS, "WARNING chipset strings don't match: \"%s\" \"%s\" (0x%x)\n", chips->name, xf86PCIVendorInfo[ivnd].Device[j]->DeviceName, device); ++*err; } break; } } if (!pDev[j]) { CheckMsg(CHECKER_CHIPSET_NOT_LISTED, "WARNING chipset \"%s\" (0x%x) not in list.\n", chips->name, device); ++*err; } else check[ichk].chipsets[j] = 1; } ++chips; } for (i = 0; i < num_check; i++) { if (!check[i].valid_vendor) { CheckMsg(CHECKER_CHIPSET_NO_VENDOR, "WARNING No such vendor 0x%x\n", vendor); ++*err; } for (j = 0; j < check[i].num_chipsets; j++) { if (xf86PCIVendorInfo && !check[i].chipsets[j]) { CheckMsg(CHECKER_CHIPSET_NOT_SUPPORTED, "NOTICE chipset \"%s\" (0x%x) not listed as supported.\n", xf86PCIVendorInfo[check[i].ivendor].Device[j]->DeviceName, xf86PCIVendorInfo[check[i].ivendor].Device[j]->DeviceID); } } XtFree(check[i].chipsets); } XtFree((XtPointer)check); }
static Boolean read_targets_table(Display *display, XmDndTargetsTable tbl) { Atom ta, atype; Window win; int aformat, i; unsigned long nitems, bafter; XmDndTargets *targets = NULL; Boolean got_it = False; XmDndBufMgrRec bmgr; CARD16 nents; DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_targets_table(%d)\n", __FILE__, __LINE__)); ta = XmInternAtom(display, _XA_MOTIF_DRAG_TARGETS, False); win = get_drag_window(display); begin_protection(display, win); if (XGetWindowProperty(display, win, ta, 0L, PROP_LENGTH, False, ta, &atype, &aformat, &nitems, &bafter, (unsigned char **)&targets) == Success && nitems >= 8) { DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_targets_table(%d) bafter=%i\n", __FILE__, __LINE__, bafter)); got_it = True; } end_protection(display); if (bad_window) { _XmWarning((Widget)XmGetXmDisplay(display), "Invalid DRAG WINDOW fetching DRAG_ATOMS."); } if (!got_it) { if (targets) { XFree((XPointer)targets); } DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_targets_table(%d) - False\n", __FILE__, __LINE__)); return False; } if (targets->protocol_version != DND_PROTOCOL_VERSION) { _XmWarning((Widget)XmGetXmDisplay(display), "DND Protocol version mismatch."); } if (targets->byte_order != _XmByteOrder()) { SWAP2BYTES(targets->num_target_lists); SWAP4BYTES(targets->data_size); } if (!tbl) { tbl = (XmDndTargetsTable)XtMalloc(sizeof(XmDndTargetsTableRec)); tbl->num_entries = 0; tbl->entries = NULL; set_targets_table(display, tbl); } if (tbl->num_entries < targets->num_target_lists) { tbl->num_entries = targets->num_target_lists; tbl->entries = (XmDndTargetsTableEntry)XtRealloc((char *)tbl->entries, targets->num_target_lists * sizeof(XmDndTargetsTableEntryRec)); } if (targets->num_target_lists > 0) { bmgr.atoms = (char *)targets; bmgr.atom_start = (char *)(targets + 1); bmgr.atom_size = targets->data_size; for (i = 0; i < targets->num_target_lists; i++) { _XmReadDragBuffer(&bmgr, False, (char *)&nents, sizeof(CARD16)); if (targets->byte_order != _XmByteOrder()) { SWAP2BYTES(nents); } tbl->entries[i].num_targets = nents; tbl->entries[i].targets = (Atom *)XtMalloc(nents * sizeof(Atom)); read_atoms_from_drag_buffer(&bmgr, tbl->entries[i].num_targets, targets->byte_order != _XmByteOrder(), tbl->entries[i].targets); } } DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:read_targets_table(%d) - True %p\n", __FILE__, __LINE__, tbl)); if (targets) { XFree((XPointer)targets); } return True; }
/* * called when a drag starts, to allocate an Atom for the DragContext */ extern Atom _XmAllocMotifAtom(Widget shell, Time time) { XmDndAtomsTable atoms; Display *dpy = XtDisplay(shell); Atom alloc = None; int i; char buf[32]; DEBUGOUT(_LtDebug(__FILE__, shell, "%s:_XmAllocMotifAtom(%d)\n", __FILE__, __LINE__)); DEBUGOUT(_LtDebug("DRAGSOURCE", shell, "%s:_XmAllocMotifAtom(%d)\n", __FILE__, __LINE__)); if ((atoms = get_atoms_table(dpy)) == NULL) { _XmInitTargetsTable(dpy); atoms = get_atoms_table(dpy); } XGrabServer(dpy); if (!read_atoms_table(dpy, atoms)) { XUngrabServer(dpy); _XmInitTargetsTable(dpy); XGrabServer(dpy); atoms = get_atoms_table(dpy); } if (atoms->num_entries != 0) { for (i = 0; i < atoms->num_entries; i++) { if (atoms->entries[i].time == CurrentTime) { alloc = atoms->entries[i].atom; atoms->entries[i].time = time; break; } } } if (alloc == None) { i = atoms->num_entries; atoms->num_entries++; atoms->entries = (XmDndAtomsTableEntry) XtRealloc((char *)atoms->entries, atoms->num_entries * sizeof(XmDndAtomsTableEntryRec)); sprintf(buf, _XA_MOTIF_ATOM_FORMAT, i); alloc = XmInternAtom(dpy, buf, False); atoms->entries[i].atom = alloc; atoms->entries[i].time = time; } write_atoms_table(dpy, atoms); XUngrabServer(dpy); XFlush(dpy); if (_LtDebugInDebug("DRAGSOURCE", shell)) { char *AtomName = XGetAtomName(dpy, alloc); DEBUGOUT(_LtDebug0("DRAGSOURCE", shell, "\t%s - 0x%x\n", AtomName, time)); XFree(AtomName); } return alloc; }
/*ARGUSED*/ static Bool EnumDatabase(XrmDatabase *db, XrmBindingList bindings, XrmQuarkList quarks, XrmRepresentation *type, XrmValue *value, XPointer closure) { char *module = XrmQuarkToString(quarks[0]), *option = XrmQuarkToString(quarks[1]); /* handle *.Option: value */ if (module && option == NULL) { option = module; module = "*"; } /* * NOTE: If the Options file is changed to support any other format than * * Module.Option: description text * * this code will also need to be updated. */ if (module) { XrmValue xrm; char *type, *value, query[256]; XmuSnprintf(query, sizeof(query), "%s.%s", module, option); if (XrmGetResource(options_xrm, query, "Module.Option", &type, &xrm)) value = (char*)xrm.addr; else value = NULL; if (value) { char *norm; unsigned char *ptr; int position; int length = strlen(module) + strlen(option) + strlen(value) + 4; rebuild_xrm.string = XtRealloc(rebuild_xrm.string, rebuild_xrm.offset + length); position = rebuild_xrm.offset + sprintf(rebuild_xrm.string + rebuild_xrm.offset, "%s.%s:", module, option); /* removes underlines and spaces */ norm = strchr(rebuild_xrm.string + rebuild_xrm.offset, '.') + 1; for (; *norm; norm++) { if (*norm == '_' || *norm == ' ' || *norm == '\t') { memmove(norm, norm + 1, strlen(norm) + 1); --position; --length; } } for (ptr = (unsigned char*)rebuild_xrm.string + rebuild_xrm.offset; *ptr; ptr++) *ptr = tolower(*ptr); sprintf(rebuild_xrm.string + position, "%s\n", value); rebuild_xrm.offset += length - 1; } } return (False); }
void XtRemoveCallbacks ( Widget widget, _Xconst char* name, XtCallbackList xtcallbacks) { InternalCallbackList *callbacks; Widget hookobj; int i; InternalCallbackList icl; XtCallbackList cl, ccl, rcl; XtAppContext app = XtWidgetToApplicationContext(widget); LOCK_APP(app); callbacks = FetchInternalList(widget, name); if (!callbacks) { XtAppWarningMsg(app, XtNinvalidCallbackList,XtNxtRemoveCallback,XtCXtToolkitError, "Cannot find callback list in XtRemoveCallbacks", (String *)NULL, (Cardinal *)NULL); UNLOCK_APP(app); return; } icl = *callbacks; if (!icl) { UNLOCK_APP(app); return; } i = icl->count; cl = ToList(icl); if (icl->call_state) { icl->call_state |= _XtCBFreeAfterCalling; icl = (InternalCallbackList)__XtMalloc(sizeof(InternalCallbackRec) + sizeof(XtCallbackRec) * i); icl->count = i; icl->call_state = 0; } ccl = ToList(icl); while (--i >= 0) { *ccl++ = *cl; for (rcl=xtcallbacks; rcl->callback; rcl++) { if (cl->callback == rcl->callback && cl->closure == rcl->closure) { ccl--; icl->count--; break; } } cl++; } if (icl->count) { icl = (InternalCallbackList) XtRealloc((char *)icl, (sizeof(InternalCallbackRec) + sizeof(XtCallbackRec) * icl->count)); icl->is_padded = 0; *callbacks = icl; } else { XtFree((char *)icl); *callbacks = NULL; } hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget)); if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) { XtChangeHookDataRec call_data; call_data.type = XtHremoveCallbacks; call_data.widget = widget; call_data.event_data = (XtPointer) name; XtCallCallbackList(hookobj, ((HookObject)hookobj)->hooks.changehook_callbacks, (XtPointer)&call_data); } UNLOCK_APP(app); } /* XtRemoveCallbacks */
static void DoStroke(XEvent *event, StrokeStatePtr State) { int i; int xtol; int ytol; int LastBox; int BoxWidth; int BoxHeight; int x0, x1, x2, x3; int y0, y1, y2, y3; String action; StrokeMapPtr *tmp = State->Map; int FinalPoints; /* fprintf(stderr, "DoStroke(%s) - %i %i %i %i\n", XtName(State->widget), State->xmin, State->ymin, State->xmax, State->ymax); */ if (State->npoints < 2) return; BoxWidth = State->xmax - State->xmin; BoxHeight = State->ymax - State->ymin; x0 = State->xmin; x1 = State->xmin + (1 * BoxWidth / 3); x2 = State->xmin + (2 * BoxWidth / 3); x3 = State->xmin + (3 * BoxWidth / 3); xtol = BoxWidth / State->slop; y0 = State->ymin; y1 = State->ymin + (1 * BoxHeight / 3); y2 = State->ymin + (2 * BoxHeight / 3); y3 = State->ymin + (3 * BoxHeight / 3); ytol = BoxHeight / State->slop; if (x3 - x0 < 20) { x1 = x0 - 1; x2 = x3 + 1; } if (y3 - y0 < 20) { y1 = y0 - 1; y2 = y3 + 1; } if (State->Debug) { XDrawRectangle(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y0, BoxWidth, BoxHeight); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x1, y0, x1, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x1 - xtol, y0, x1 - xtol, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x1 + xtol, y0, x1 + xtol, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x2, y0, x2, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x2 - xtol, y0, x2 - xtol, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x2 + xtol, y0, x2 + xtol, y3); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y1, x3, y1); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y1 - ytol, x3, y1 - ytol); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y1 + ytol, x3, y1 + ytol); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y2, x3, y2); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y2 - ytol, x3, y2 - ytol); XDrawLine(XtDisplay(State->widget), event->xbutton.root, State->gc, x0, y2 + ytol, x3, y2 + ytol); } for (i = 1; i < State->npoints; i++) { int dx = State->points[i - 1].x - State->points[i].x; int dy = State->points[i - 1].y - State->points[i].y; int maxx = (x2 - xtol) - (x1 + xtol); int maxy = (y2 - ytol) - (y1 + ytol); if (((dx * dx) >= (maxx * maxx)) || ((dy * dy) >= (maxy * maxy))) { int j; AllocatePoints(State); for (j = State->npoints; j > i; j--) { State->points[j].x = State->points[j - 1].x; State->points[j].y = State->points[j - 1].y; } State->npoints++; State->points[i].x = State->points[i - 1].x + (State->points[i].x - State->points[i - 1].x) / 2; State->points[i].y = State->points[i - 1].y + (State->points[i].y - State->points[i - 1].y) / 2; /* XDrawRectangle(XtDisplay(State->widget), XtWindow(State->widget), State->gc, State->points[i].x - 4, State->points[i].y - 4, 8, 8); */ i--; } } for (i = 0; i < State->npoints; i++) { if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) && (State->points[i].y >= y0 && State->points[i].y < y1 - ytol)) { State->box[i] = 1; } else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) && (State->points[i].y >= y0 && State->points[i].y < y1 - ytol)) { State->box[i] = 2; } else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) && (State->points[i].y >= y0 && State->points[i].y < y1 - ytol)) { State->box[i] = 3; } else if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) && (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol)) { State->box[i] = 4; } else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) && (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol)) { State->box[i] = 5; } else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) && (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol)) { State->box[i] = 6; } else if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) && (State->points[i].y >= y2 + ytol && State->points[i].y <= y3)) { State->box[i] = 7; } else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) && (State->points[i].y >= y2 + ytol && State->points[i].y <= y3)) { State->box[i] = 8; } else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) && (State->points[i].y >= y2 + ytol && State->points[i].y <= y3)) { State->box[i] = 9; } else { State->box[i] = 0; } } LastBox = 0; FinalPoints = 0; action = XtNewString("Stroke-"); for (i = 0; i < State->npoints; i++) { if ((State->box[i] != 0) && (State->box[i] != LastBox)) { action = XtRealloc(action, 2 + strlen(action)); sprintf(&action[strlen(action)], "%i", State->box[i]); LastBox = State->box[i]; FinalPoints++; } } { StrokeStatePtr WidgetState; WidgetState = StrokeGetMap(State->widget); tmp = WidgetState->Map; } while (tmp != NULL && (*tmp) != NULL && FinalPoints > 2) { if (strcmp(&action[7], (*tmp)->Stroke) == 0) { if (State->Debug) { fprintf(stderr, "%s(%i) - %s Calling action >%s<\n", __FILE__, __LINE__, XtName(State->widget), (*tmp)->Action); } if (State->Sound != NULL) { XtCallActionProc(State->widget, "PlaySound", NULL, &State->Sound, 1); } XtCallActionProc(State->widget, (*tmp)->Action, event, NULL, 0); break; } tmp++; } if (((tmp == NULL) || ((*tmp) == NULL)) && FinalPoints > 2) { if (State->Debug) { fprintf(stderr, "%s(%i) - %s Calling action >%s<\n", __FILE__, __LINE__, XtName(State->widget), action); } XtCallActionProc(State->widget, action, event, NULL, 0); } XtFree(action); }
int * BUCK_get_subv( int nvals , char * str ) { int * subv = NULL ; int ii , ipos , nout , slen ; int ibot,itop,istep , nused ; char * cpt ; /* Meaningless input? */ if( nvals < 1 ) return NULL ; /* No selection list ==> select it all */ if( str == NULL || str[0] == '\0' ){ subv = (int *) XtMalloc( sizeof(int) * (nvals+1) ) ; subv[0] = nvals ; for( ii=0 ; ii < nvals ; ii++ ) subv[ii+1] = ii ; return subv ; } /* skip initial '[' */ subv = (int *) XtMalloc( sizeof(int) * 2 ) ; subv[0] = nout = 0 ; ipos = 0 ; if( str[ipos] == '[' ) ipos++ ; /*** loop through each sub-selector until end of input ***/ slen = strlen(str) ; while( ipos < slen && str[ipos] != ']' ){ /** get starting value **/ if( str[ipos] == '$' ){ /* special case */ ibot = nvals-1 ; ipos++ ; } else { /* decode an integer */ ibot = strtol( str+ipos , &cpt , 10 ) ; if( ibot < 0 ){ myXtFree(subv) ; return NULL ; } if( ibot >= nvals ) ibot = nvals-1 ; nused = (cpt-(str+ipos)) ; if( ibot == 0 && nused == 0 ){ myXtFree(subv) ; return NULL ; } ipos += nused ; } /** if that's it for this sub-selector, add one value to list **/ if( str[ipos] == ',' || str[ipos] == '\0' || str[ipos] == ']' ){ nout++ ; subv = (int *) XtRealloc( (char *)subv , sizeof(int) * (nout+1) ) ; subv[0] = nout ; subv[nout] = ibot ; ipos++ ; continue ; /* re-start loop at next sub-selector */ } /** otherwise, must have '..' or '-' as next inputs **/ if( str[ipos] == '-' ){ ipos++ ; } else if( str[ipos] == '.' && str[ipos+1] == '.' ){ ipos++ ; ipos++ ; } else { myXtFree(subv) ; return NULL ; } /** get ending value for loop now **/ if( str[ipos] == '$' ){ /* special case */ itop = nvals-1 ; ipos++ ; } else { /* decode an integer */ itop = strtol( str+ipos , &cpt , 10 ) ; if( itop < 0 ){ myXtFree(subv) ; return NULL ; } if( itop >= nvals ) itop = nvals-1 ; nused = (cpt-(str+ipos)) ; if( itop == 0 && nused == 0 ){ myXtFree(subv) ; return NULL ; } ipos += nused ; } /** set default loop step **/ istep = (ibot <= itop) ? 1 : -1 ; /** check if we have a non-default loop step **/ if( str[ipos] == '(' ){ /* decode an integer */ ipos++ ; istep = strtol( str+ipos , &cpt , 10 ) ; if( istep == 0 ){ myXtFree(subv) ; return NULL ; } nused = (cpt-(str+ipos)) ; ipos += nused ; if( str[ipos] == ')' ) ipos++ ; } /** add values to output **/ for( ii=ibot ; (ii-itop)*istep <= 0 ; ii += istep ){ nout++ ; subv = (int *) XtRealloc( (char *)subv , sizeof(int) * (nout+1) ) ; subv[0] = nout ; subv[nout] = ii ; } /** check if we have a comma to skip over **/ if( str[ipos] == ',' ) ipos++ ; } /* end of loop through selector string */ return subv ; }
/* Do glob searching for PATTERN, placing results in PGLOB. The bits defined above may be set in FLAGS. If a directory cannot be opened or read and ERRFUNC is not nil, it is called with the pathname that caused the error, and the `errno' value from the failing call; if it returns non-zero `glob' returns GLOB_ABEND; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ int _Lesstif_glob(const char *pattern, int flags, errfunc_t errfunc, glob_t *pglob) { char *dirname; const char *filename; size_t dirlen; int status; int oldcount; if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) { errno = EINVAL; return -1; } DEBUGOUT(_LtDebug(__FILE__, NULL, "_Lesstif_glob(%s, %i)\n", pattern, flags)); /* Find the filename. */ filename = strrchr(pattern, '/'); if (filename == NULL) { dirname=XtMalloc(2); filename = pattern; strcpy(dirname, "."); dirlen = 0; } else if (filename == pattern) { /* "/pattern". */ dirname=XtMalloc(2); strcpy(dirname, "/"); dirlen = 1; ++filename; } else { dirlen = filename - pattern; dirname = XtMalloc(dirlen + 1); memcpy(dirname, pattern, dirlen); dirname[dirlen] = '\0'; ++filename; } if (filename[0] == '\0' && dirlen > 1) /* "pattern/". Expand "pattern", appending slashes. */ { int val = _Lesstif_glob(dirname, flags | GLOB_MARK, errfunc, pglob); if (val == 0) pglob->gl_flags = (pglob->gl_flags & ~GLOB_MARK) | (flags & GLOB_MARK); XtFree(dirname); return val; } if (!(flags & GLOB_APPEND)) { pglob->gl_pathc = 0; pglob->gl_pathv = NULL; } oldcount = pglob->gl_pathc; if (glob_pattern_p(dirname, !(flags & GLOB_NOESCAPE))) { /* The directory name contains metacharacters, so we have to glob for the directory, and then glob for the pattern in each directory found. */ glob_t dirs; register int i; DEBUGOUT(_LtDebug(__FILE__, NULL, "glob_pattern(%s, !(flags & GLOB_NOESCAPE))!=NULL\n", dirname)); status = _Lesstif_glob(dirname, ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE)) | GLOB_NOSORT), errfunc, &dirs); if (status != 0) { XtFree(dirname); return status; } /* We have successfully globbed the preceding directory name. For each name we found, call glob_in_dir on it and FILENAME, appending the results to PGLOB. */ for (i = 0; i < dirs.gl_pathc; ++i) { int oldcount; oldcount = pglob->gl_pathc; status = glob_in_dir(filename, dirs.gl_pathv[i], (flags | GLOB_APPEND) & ~GLOB_NOCHECK, errfunc, pglob); if (status == GLOB_NOMATCH) /* No matches in this directory. Try the next. */ continue; if (status != 0) { _Lesstif_globfree(&dirs); _Lesstif_globfree(pglob); XtFree(dirname); return status; } /* Stick the directory on the front of each name. */ if (prefix_array(dirs.gl_pathv[i], &pglob->gl_pathv[oldcount], pglob->gl_pathc - oldcount)) { _Lesstif_globfree(&dirs); _Lesstif_globfree(pglob); XtFree(dirname); return GLOB_NOSPACE; } } flags |= GLOB_MAGCHAR; if (pglob->gl_pathc == oldcount) { /* No matches. */ if (flags & GLOB_NOCHECK) { size_t len = strlen(pattern) + 1; char *patcopy = (char *)XtMalloc(len); if (patcopy == NULL) { XtFree(dirname); return GLOB_NOSPACE; } memcpy(patcopy, pattern, len); pglob->gl_pathv = (char **)XtRealloc((char *)pglob->gl_pathv, (pglob->gl_pathc + ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) + 1 + 1) * sizeof(char *)); if (pglob->gl_pathv == NULL) { XtFree(patcopy); XtFree(dirname); return GLOB_NOSPACE; } if (flags & GLOB_DOOFFS) while (pglob->gl_pathc < pglob->gl_offs) pglob->gl_pathv[pglob->gl_pathc++] = NULL; pglob->gl_pathv[pglob->gl_pathc++] = patcopy; pglob->gl_pathv[pglob->gl_pathc] = NULL; pglob->gl_flags = flags; } else { XtFree(dirname); return GLOB_NOMATCH; } } } /* if (glob_pattern_p(dirname, !(flags & GLOB_NOESCAPE))) */ else { DEBUGOUT(_LtDebug(__FILE__, NULL, "glob_pattern(%s, !(flags & GLOB_NOESCAPE))=NULL\n", dirname)); status = glob_in_dir(filename, dirname, flags, errfunc, pglob); if (status != 0) { XtFree(dirname); return status; } if (dirlen > 0) { /* Stick the directory on the front of each name. */ if (prefix_array(dirname, &pglob->gl_pathv[oldcount], pglob->gl_pathc - oldcount)) { _Lesstif_globfree(pglob); XtFree(dirname); return GLOB_NOSPACE; } } } /* else */ if (!(flags & GLOB_NOSORT)) /* Sort the vector. */ qsort((void *) & pglob->gl_pathv[oldcount], pglob->gl_pathc - oldcount, sizeof(char *), collated_compare); if (flags & GLOB_MARK) { /* Append slashes to directory names. glob_in_dir has already allocated the extra character for us. This must be done after the sorting to avoid screwing up the order (`"./" > "../"' but `"." < ".."'). */ int i; struct stat st; DEBUGOUT(_LtDebug(__FILE__, NULL, "_Lesstif_glob(): GLOB_NOSORT\n")); for (i = oldcount; i < pglob->gl_pathc; ++i) if (LTstat(pglob->gl_pathv[i], &st) == 0 && S_ISDIR(st.st_mode)) strcat(pglob->gl_pathv[i], "/"); } XtFree(dirname); return 0; } /* _Lesstif_glob() */
/* Like `glob', but PATTERN is a final pathname component, and matches are searched for in DIRECTORY. The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. The GLOB_APPEND flag is assumed to be set (always appends). */ static int glob_in_dir(const char *pattern, const char *directory, int flags, errfunc_t errfunc, glob_t *pglob) { #ifdef WIN32 HANDLE stream; WIN32_FIND_DATA findinfo; int first = 1; #else void *stream; #endif struct globlink { struct globlink *next; char *name; }; struct globlink *names = NULL; size_t nfound = 0; DEBUGOUT(_LtDebug(__FILE__, NULL, "glob_in_dir(%s, %s, %i,)\n", pattern, directory, flags)); if (!glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE))) { stream = NULL; flags |= GLOB_NOCHECK; } else { flags |= GLOB_MAGCHAR; #ifdef WIN32 stream = FindFirstFile(directory, &findinfo); if (stream == INVALID_HANDLE_VALUE) stream = NULL; #else stream = (__glob_opendir_hook ? (*__glob_opendir_hook) (directory) : (void *) opendir(directory)); #endif if (stream == NULL) { if ((errfunc != NULL && (*errfunc) (directory, errno)) || (flags & GLOB_ERR)) return GLOB_ABEND; } else while (1) { const char *name; size_t len; #ifdef WIN32 if (first) { /* The FindFirstFile call actaully reads the first one */ first = 0; } else { if (!FindNextFile(stream, &findinfo)) break; } name = findinfo.cFileName; len = 0; #else if (__glob_readdir_hook) { name = (*__glob_readdir_hook) (stream); if (name == NULL) break; len = 0; } else { struct dirent *d = readdir((DIR *) stream); if (d == NULL) break; DEBUGOUT(_LtDebug0(__FILE__, NULL, "glob_in_dir(%s)\n", d->d_name)); if (!REAL_DIR_ENTRY(d)) { DEBUGOUT(_LtDebug0(__FILE__, NULL, "glob_in_dir() continue\n")); continue; } name = d->d_name; #ifdef HAVE_D_NAMLEN len = d->d_namlen; #else len = 0; #endif } #endif if (_Lesstif_fnmatch(pattern, name, (!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)) == 0) { struct globlink *new_w = (struct globlink *)XtMalloc(sizeof(struct globlink)); if (len == 0) len = strlen(name); new_w->name = (char *)XtMalloc(len + ((flags & GLOB_MARK) ? 1 : 0) + 1); if (new_w->name == NULL) goto memory_error; memcpy((void *) new_w->name, name, len); new_w->name[len] = '\0'; new_w->next = names; names = new_w; ++nfound; } else { DEBUGOUT(_LtDebug0(__FILE__, NULL, "glob_in_dir() failed fnmatch\n")); } } } DEBUGOUT(_LtDebug0(__FILE__, NULL, "glob_in_dir() found %d\n", nfound)); if (nfound == 0 && (flags & GLOB_NOCHECK)) { size_t len = strlen(pattern); nfound = 1; names = (struct globlink *)XtMalloc(sizeof(struct globlink)); names->next = NULL; names->name = (char *)XtMalloc(len + 1); if (names->name == NULL) goto memory_error; memcpy(names->name, pattern, len); names->name[len] = '\0'; } pglob->gl_pathv = (char **)XtRealloc((char *)pglob->gl_pathv, (pglob->gl_pathc + ((flags & GLOB_DOOFFS) ? pglob->gl_offs : 0) + nfound + 1) * sizeof(char *)); if (pglob->gl_pathv == NULL) goto memory_error; if (flags & GLOB_DOOFFS) while (pglob->gl_pathc < pglob->gl_offs) pglob->gl_pathv[pglob->gl_pathc++] = NULL; while (names != NULL) { struct globlink *next = names->next; pglob->gl_pathv[pglob->gl_pathc++] = names->name; XtFree((char *)names); names = next; } pglob->gl_pathv[pglob->gl_pathc] = NULL; pglob->gl_flags = flags; if (stream != NULL) { int save = errno; #ifdef WIN32 FindClose(stream); #else if (__glob_closedir_hook) (*__glob_closedir_hook) (stream); else closedir((DIR *) stream); #endif errno = save; } return nfound == 0 ? GLOB_NOMATCH : 0; memory_error: { int save = errno; #ifdef WIN32 FindClose(stream); #else if (__glob_closedir_hook) (*__glob_closedir_hook) (stream); else closedir((DIR *) stream); #endif errno = save; } while (names != NULL) { if (names->name != NULL) XtFree((char *) names->name); names = names->next; } if (names) XtFree((char *)names); return GLOB_NOSPACE; } /* glob_in_dir() */
static int Apply(Widget w) { Widget list_w = XtNameToWidget(XtParent(w),"*interpreters"); XtPointer user_data; int nid; XmString *selections=NULL; String list = 0; String old_list; int num; int i; int status = 1; XtVaGetValues(list_w, XmNuserData, &user_data, NULL); nid = (intptr_t)user_data; old_list = XmdsGetNidText(nid); XtVaGetValues(list_w, XmNselectedItems, &selections, XmNselectedItemCount, &num, NULL); for (i=0;i<num;i++) { String item; item = XmStringUnparse(selections[i], NULL, 0, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL); if (item) { if (list) { list = XtRealloc(list, strlen(list) + strlen(item) + 2); strcat(list,item); } else { list = XtMalloc(strlen(item) + 2); strcpy(list,item); } strcat(list,"\n"); XtFree(item); } } if ( (list && (old_list ? strcmp(old_list,list) : 1)) || (!list && (old_list ? strlen(old_list) : 0)) ) { if (list) { static struct descriptor list_dsc = {0, DTYPE_T, CLASS_S, 0}; list_dsc.length = strlen(list); list_dsc.pointer = list; status = TreePutRecord(nid, &list_dsc,0) & 1; if (!status) XmdsComplain(XtParent(w), "Error writing interpreter selections"); } else { struct descriptor list_dsc = {0, DTYPE_T, CLASS_S, 0}; status = TreePutRecord(nid, &list_dsc,0) & 1; if (!status) XmdsComplain(XtParent(w), "Error writing interpreter selections"); } } XtFree(list); XtFree(old_list); if (status) XmdsApplyAllXds(XtParent(w)); return status & 1; }
/* Function Name: * brGetResourceValueForSetValues * * Description: * Returns the value that should be sent to SetValues. * * Arguments: * res_value - value to set to the resource * size - length of the string returned * * Returns: * value - allocated value. * * Calls: * Xrm- and Xt-stuff */ char *brGetResourceValueForSetValues(char *res_value, unsigned short *size) { static char *temp = NULL; static Cardinal tempSize = 0; static char *ptr = NULL; static Cardinal ptrSize = 0; Arg args[1]; XrmDatabase db = NULL; XrmValue value; char *type; /* * This makes sure that exactly the same thing happens during a set * values, that would happend of we were to insert this value into * the resource database. */ if (tempSize < sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2)) { tempSize = (sizeof(char) * (strlen(res_value) + strlen(RESOURCE_NAME) + 2)); if ( (temp = XtRealloc(temp, tempSize)) == NULL ) { fprintf(stderr, "XtRealloc failed!\n"); exit(EXIT_FAILURE); } } sprintf(temp, "%s:%s", RESOURCE_NAME, res_value); XrmPutLineResource(&db, temp); XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &type, &value); if (ptrSize < sizeof(char) * value.size) { ptrSize = sizeof(char) * value.size; if ( (ptr = XtRealloc(ptr, ptrSize)) == NULL ) { fprintf(stderr, "XtRealloc failed!\n"); exit(EXIT_FAILURE); } } memmove (ptr, value.addr, value.size); XrmDestroyDatabase(db); *size = (unsigned short) value.size; return(ptr); } /* brGetResourceValueForSetValues() */
static char * IncDigit(char *buf, Position *Place, int a) { if (*Place < 0) { if (a > 0) { buf = XtRealloc(buf, strlen(buf) + 2); memmove(&buf[1], &buf[0], strlen(buf) + 1); buf[0] = '0'; *Place += 1; buf = IncDigit(buf, Place, a); } else { buf[*Place + 1] = '0'; } return (buf); } if ((buf[*Place] >= '0') && (buf[*Place] <= '9')) { buf[*Place] = buf[*Place] + a; if (buf[*Place] > '9') { if (*Place < 0 || buf[*Place - 1] == '-') { buf = XtRealloc(buf, strlen(buf) + 2); memmove(&buf[*Place + 1], &buf[*Place], strlen(buf) + 1); buf[*Place] = '0'; *Place += 1; buf = IncDigit(buf, Place, a); } buf[*Place] = '0'; if (buf[*Place - 1] != '.') { *Place -= 1; buf = IncDigit(buf, Place, a); *Place += 1; } else { *Place -= 2; buf = IncDigit(buf, Place, a); *Place += 2; } } if (buf[*Place] < '0') { buf[*Place] = '9'; if (buf[*Place - 1] != '.') { *Place -= 1; buf = IncDigit(buf, Place, a); *Place += 1; } else { *Place -= 2; buf = IncDigit(buf, Place, a); *Place += 2; } } if (buf[*Place] == '0' && *Place == 0) { *Place -= 1; } } else { } return (buf); }
static XawCache * _XawGetCache(XawCache *xaw, Screen *screen, Colormap colormap, int depth) { XawCache *s_cache, *c_cache, *d_cache, *cache, *pcache; cache = _XawFindCache(xaw, screen, colormap, depth, FIND_ALL); if (!cache) { s_cache = _XawFindCache(xaw, screen, colormap, depth, FIND_SCREEN); if (!s_cache) { pcache = (XawCache *)XtMalloc(sizeof(XawCache)); if (!xaw->num_elems) { xaw->num_elems = 1; xaw->elems = (XtPointer*)XtMalloc(sizeof(XtPointer)); } else { ++xaw->num_elems; xaw->elems = (XtPointer*) XtRealloc((char *)xaw->elems, sizeof(XtPointer) * xaw->num_elems); } pcache->value = (long)screen; pcache->elems = NULL; pcache->num_elems = 0; xaw->elems[xaw->num_elems - 1] = (XtPointer)pcache; s_cache = (XawCache *)xaw->elems[xaw->num_elems - 1]; if (xaw->num_elems > 1) qsort(xaw->elems, xaw->num_elems, sizeof(XtPointer), qcmp_long); } c_cache = _XawFindCache(xaw, screen, colormap, depth, FIND_COLORMAP); if (!c_cache) { pcache = (XawCache *)XtMalloc(sizeof(XawCache)); if (!s_cache->num_elems) { s_cache->num_elems = 1; s_cache->elems = (XtPointer*)XtMalloc(sizeof(XtPointer)); } else { ++s_cache->num_elems; s_cache->elems = (XtPointer*) XtRealloc((char *)s_cache->elems, sizeof(XtPointer) * s_cache->num_elems); } pcache->value = (long)colormap; pcache->elems = NULL; pcache->num_elems = 0; s_cache->elems[s_cache->num_elems - 1] = (XtPointer)pcache; c_cache = (XawCache *)s_cache->elems[s_cache->num_elems - 1]; if (s_cache->num_elems > 1) qsort(s_cache->elems, s_cache->num_elems, sizeof(XtPointer), qcmp_long); } d_cache = _XawFindCache(xaw, screen, colormap, depth, FIND_DEPTH); if (!d_cache) { pcache = (XawCache *)XtMalloc(sizeof(XawCache)); if (!c_cache->num_elems) { c_cache->num_elems = 1; c_cache->elems = (XtPointer*)XtMalloc(sizeof(XtPointer)); } else { ++c_cache->num_elems; c_cache->elems = (XtPointer*) XtRealloc((char *)c_cache->elems, sizeof(XtPointer) * c_cache->num_elems); } pcache->value = (long)depth; pcache->elems = NULL; pcache->num_elems = 0; c_cache->elems[c_cache->num_elems - 1] = (XtPointer)pcache; d_cache = (XawCache *)c_cache->elems[c_cache->num_elems - 1]; if (c_cache->num_elems > 1) qsort(c_cache->elems, c_cache->num_elems, sizeof(XtPointer), qcmp_long); } cache = d_cache; } return (cache); }
static XawTextProperty * _XawTextSinkAddProperty(XawTextPropertyList *list, XawTextProperty *property, Bool replace) { XawTextProperty *result; XColor color; char identifier[1024]; char foreground[16]; char background[16]; char *foundry, *family, *weight, *slant, *setwidth, *addstyle, *pixel_size, *point_size, *res_x, *res_y, *spacing, *avgwidth, *registry, *encoding; char *xlfd; static char *asterisk = "*", *null = ""; XrmQuark quark; if (list == NULL || property == NULL) return (NULL); if (property->mask & XAW_TPROP_FOREGROUND) { color.pixel = property->foreground; XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color); XmuSnprintf(foreground, sizeof(foreground), "%04x%04x%04x", color.red, color.green, color.blue); } else strcpy(foreground, asterisk); if (property->mask & XAW_TPROP_BACKGROUND) { color.pixel = property->background; XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color); XmuSnprintf(background, sizeof(background), "%04x%04x%04x", color.red, color.green, color.blue); } else strcpy(background, asterisk); if (property->xlfd_mask & XAW_TPROP_FOUNDRY) foundry = XrmQuarkToString(property->foundry); else foundry = asterisk; /* use default, or what was requested */ if (property->family != NULLQUARK) family = XrmQuarkToString(property->family); else family = asterisk; if (property->weight != NULLQUARK) weight = XrmQuarkToString(property->weight); else weight = asterisk; if (property->slant != NULLQUARK) { slant = XrmQuarkToString(property->slant); if (toupper(*slant) != 'R') slant = asterisk; /* X defaults to italics, so, don't care in resolving between `I' and `O' */ } else slant = asterisk; if (property->xlfd_mask & XAW_TPROP_SETWIDTH) setwidth = XrmQuarkToString(property->setwidth); else setwidth = asterisk; if (property->xlfd_mask & XAW_TPROP_ADDSTYLE) addstyle = XrmQuarkToString(property->addstyle); else addstyle = null; /* use default, or what was requested */ if (!(property->mask & XAW_TPROP_POINTSIZE) && property->pixel_size != NULLQUARK) pixel_size = XrmQuarkToString(property->pixel_size); else pixel_size = asterisk; if (property->xlfd_mask & XAW_TPROP_POINTSIZE) point_size = XrmQuarkToString(property->point_size); else point_size = asterisk; if (property->xlfd_mask & XAW_TPROP_RESX) res_x = XrmQuarkToString(property->res_x); else res_x = asterisk; if (property->xlfd_mask & XAW_TPROP_RESY) res_y = XrmQuarkToString(property->res_y); else res_y = asterisk; if (property->xlfd_mask & XAW_TPROP_SPACING) spacing = XrmQuarkToString(property->spacing); else spacing = asterisk; if (property->xlfd_mask & XAW_TPROP_AVGWIDTH) avgwidth = XrmQuarkToString(property->avgwidth); else avgwidth = asterisk; /* use default, or what that was requested */ if (property->registry != NULLQUARK) registry = XrmQuarkToString(property->registry); else registry = asterisk; if (property->encoding != NULLQUARK) encoding = XrmQuarkToString(property->encoding); else encoding = asterisk; if (replace) { result = XtNew(XawTextProperty); memcpy(result, property, sizeof(XawTextProperty)); } else result = property; /* XXX should do the best to load a suitable font here */ if (!(result->mask & XAW_TPROP_FONT)) { XmuSnprintf(identifier, sizeof(identifier), "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", foundry, family, weight, slant, setwidth, addstyle, pixel_size, point_size, res_x, res_y, spacing, avgwidth, registry, encoding); if ((result->font = XLoadQueryFont(DisplayOfScreen(list->screen), identifier)) != NULL) { result->mask |= XAW_TPROP_FONT; SetXlfdDefaults(DisplayOfScreen(list->screen), result); } else result->mask &= ~XAW_TPROP_FONT; } if (result->font) xlfd = XrmQuarkToString(result->xlfd); else xlfd = null; XmuSnprintf(identifier, sizeof(identifier), "%08lx%08lx%s%s%d%d%d%d%s", property->mask, property->xlfd_mask, foreground, background, (result->mask & XAW_TPROP_UNDERLINE) != 0, (result->mask & XAW_TPROP_OVERSTRIKE) != 0, (result->mask & XAW_TPROP_SUBSCRIPT) != 0, (result->mask & XAW_TPROP_SUPERSCRIPT) != 0, xlfd); quark = XrmStringToQuark(identifier); if (result->identifier == NULLQUARK) result->identifier = quark; result->code = quark; if ((property = _XawTextSinkGetProperty(list, result->identifier)) != NULL) { if (result->font) XFreeFont(DisplayOfScreen(list->screen), result->font); if (replace) XtFree((XtPointer)result); return (property); } list->properties = (XawTextProperty**) XtRealloc((XtPointer)list->properties, sizeof(XawTextProperty*) * (list->num_properties + 1)); list->properties[list->num_properties++] = result; qsort((void*)list->properties, list->num_properties, sizeof(XawTextProperty*), qcmp_qident); return (result); }
void read_ascii(FILE *fp, xgobidata *xg) { register int ch; int i, j, k, jrows, nrows, jcols, fs; int nitems; float row1[NCOLS]; short row1_missing[NCOLS]; int nblocks; char word[64]; /* Initialize these before starting */ for (k=0; k<NCOLS; k++) { row1_missing[k] = 0; row1[k] = 0.0; } xg->ncols_used = 0; init_file_rows_sampled(xg); /* * Find the index of the first row of data that we're interested in. */ nrows = 0; if (xg->file_read_type == read_all) { if (find_data_start(fp) == False) return; } else { /* if -only was used on the command line */ if (!seek_to_file_row(nrows, fp, xg)) return; } /* * Read in the first row of the data file and calculate ncols. */ gotone = True; /* * I've left behind some checking that's done in bak/read_array.c -- * test xgobi on a text file and see what happens. */ while ( (ch = getc(fp)) != '\n') { if (ch == '\t' || ch == ' ') ; else if ( ungetc(ch, fp) == EOF || fscanf(fp, "%s", word) < 0 ) { fprintf(stderr, "read_array: error in reading first row of data\n"); fclose(fp); exit(0); } else { if ( strcasecmp(word, "na") == 0 || strcmp(word, ".") == 0) { xg->missing_values_present = True; xg->nmissing++; row1_missing[xg->ncols_used] = 1; } else { row1[xg->ncols_used] = (float) atof(word); } xg->ncols_used++ ; if (xg->ncols_used >= NCOLS) { fprintf(stderr, "This file has more than %d columns. In order to read it in,\n", NCOLS); fprintf(stderr, "increase NCOLS in xgobitypes.h and recompile.\n"); exit(0); } } } xg->ncols = xg->ncols_used + 1; /* * If we're reading everything, allocate the first block. * If -only has been used, allocate the whole shebang. */ if (xg->file_read_type == read_all) { xg->nrows = 0; alloc_block(1, xg); if (xg->missing_values_present) alloc_missing_block(1, xg); } else { /* -only has been used */ xg->nrows = xg->file_sample_size; xg->raw_data = (float **) XtMalloc( (Cardinal) xg->nrows * sizeof(float *)); for (i=0; i<xg->nrows; i++) xg->raw_data[i] = (float *) XtMalloc((Cardinal) xg->ncols * sizeof(float)); if (xg->missing_values_present) init_missing_array(xg->nrows, xg->ncols, xg); } /* * Fill in the first row */ for (j=0; j<xg->ncols_used; j++) xg->raw_data[0][j] = row1[j]; if (xg->missing_values_present) { for (j=0; j<xg->ncols_used; j++) xg->is_missing[0][j] = row1_missing[j]; } nrows++; /* * Read data, reallocating as needed. Determine nrows for the read_all case. */ nblocks = 1; nitems = xg->ncols_used; jrows = 1; jcols = 0; while (1) { if (jcols == 0) { if (xg->file_read_type == read_all) { if (!find_data_start(fp)) break; } else { /* if -only was used on the command line */ if (!seek_to_file_row(nrows, fp, xg)) break; } } fs = fscanf(fp, "%s", word); if (fs == EOF) break; else if (fs < 0) { fprintf(stderr, "Problem with input data\n"); fclose(fp); exit(0); } else { nitems++; if ( strcasecmp(word, "na") == 0 || strcmp(word, ".") == 0 ) { if (!xg->missing_values_present) { xg->missing_values_present = True; /* * Only when the first "na" or "." has been encountered * is it necessary to allocate space to contain the * missing values matrix. Initialize all previous values * to 0. */ if (xg->file_read_type == read_all) { alloc_missing_block(nblocks, xg); for (i=BLOCKSIZE*(nblocks-1); i<BLOCKSIZE*nblocks; i++) { for (k=0; k<xg->ncols_used; k++) xg->is_missing[i][k] = 0; } } else { init_missing_array(xg->nrows, xg->ncols, xg); } } xg->nmissing++; xg->is_missing[nrows][jcols] = 1; xg->raw_data[nrows][jcols] = 0.0; } else xg->raw_data[nrows][jcols] = (float) atof(word); jcols++; if (jcols == xg->ncols_used) { jcols = 0; nrows++; jrows++; } if (xg->file_read_type == read_all) { if (jrows == BLOCKSIZE) { jrows = 0; nblocks++; if (nblocks%20 == 0) fprintf(stderr, "reallocating; n > %d\n", nblocks*BLOCKSIZE); alloc_block(nblocks, xg); if (xg->missing_values_present) alloc_missing_block(nblocks, xg); } } else { /* -only was used */ if (nrows >= xg->nrows) break; } } } /* * Close the data file */ if (fclose(fp) == EOF) fprintf(stderr, "read_array: error in fclose"); if (xg->file_read_type == read_all) xg->nrows = nrows; fprintf(stderr, "size of data: %d x %d\n", xg->nrows, xg->ncols); if ( nitems != xg->nrows * xg->ncols_used ) { (void) fprintf(stderr, "read_array: nrows*ncols != nitems read\n"); (void) fprintf(stderr, "(nrows %d, ncols %d, nitems read %d)\n", xg->nrows, xg->ncols_used, nitems); exit(0); } else if (nitems == 0) { (void) fprintf(stderr, "No data read\n"); exit(0); } else { /* * If we haven't yet encountered a missing value, free up * the whole matrix. */ if (!xg->missing_values_present) xg->is_missing = (short **) NULL; if (xg->file_read_type == read_all) { /* * One last XtFree and XtRealloc to make raw_data take up exactly * the amount of space it needs. */ for (i=xg->nrows; i<BLOCKSIZE*nblocks; i++) XtFree((XtPointer) xg->raw_data[i]); xg->raw_data = (float **) XtRealloc((XtPointer) xg->raw_data, (Cardinal) xg->nrows * sizeof(float *)); if (xg->missing_values_present) { for (i=xg->nrows; i<BLOCKSIZE*nblocks; i++) XtFree((XtPointer) xg->is_missing[i]); xg->is_missing = (short **) XtRealloc((XtPointer) xg->is_missing, (Cardinal) xg->nrows * sizeof(short *)); } } /* * If the data contains only one column, add a second, * the numbers 1:nrows -- and let the added column be * the first column? */ xg->single_column = False; if (xg->ncols_used == 1) { xg->single_column = True; xg->ncols_used = 2; xg->ncols = 3; for (i=0; i<xg->nrows; i++) { xg->raw_data[i] = (float *) XtRealloc( (XtPointer) xg->raw_data[i], (Cardinal) 3 * sizeof(float)); xg->raw_data[i][1] = xg->raw_data[i][0] ; xg->raw_data[i][0] = (float) (i+1) ; /* And populate a column of missing values with 0s, if needed */ if (xg->missing_values_present) { xg->is_missing[i] = (short *) XtRealloc( (XtPointer) xg->is_missing[i], (Cardinal) 3 * sizeof(short)); xg->is_missing[i][1] = 0 ; } } } } }
static void SFgetHomeDirs (void) { struct passwd *pw; int alloc; int i; SFEntry *entries = NULL; int len; int maxChars; alloc = 1; i = 1; entries = (SFEntry *) XtMalloc (sizeof (SFEntry)); SFlogins = (SFLogin *) XtMalloc (sizeof (SFLogin)); entries[0].real = XtMalloc (3); strcpy (entries[0].real, "~"); entries[0].shown = entries[0].real; entries[0].statDone = 1; SFlogins[0].name = ""; pw = getpwuid ((int) getuid ()); SFstrdup (&SFlogins[0].dir, pw ? pw->pw_dir : "/"); maxChars = 0; setpwent (); while ((pw = getpwent ()) && (*(pw->pw_name))) { if (i >= alloc) { alloc *= 2; entries = (SFEntry *) XtRealloc ( (char *) entries, (unsigned) (alloc * sizeof (SFEntry)) ); SFlogins = (SFLogin *) XtRealloc ( (char *) SFlogins, (unsigned) (alloc * sizeof (SFLogin)) ); } len = strlen (pw->pw_name); entries[i].real = XtMalloc ((unsigned) (len + 3)); strcat (strcpy (entries[i].real, "~"), pw->pw_name); entries[i].shown = entries[i].real; entries[i].statDone = 1; if (len > maxChars) { maxChars = len; } SFstrdup (&SFlogins[i].name, pw->pw_name); SFstrdup (&SFlogins[i].dir, pw->pw_dir); i++; } SFhomeDir.dir = XtMalloc (1); SFhomeDir.dir[0] = 0; SFhomeDir.path = SFcurrentPath; SFhomeDir.entries = entries; SFhomeDir.nEntries = i; SFhomeDir.vOrigin = 0; /* :-) */ SFhomeDir.nChars = maxChars + 2; SFhomeDir.hOrigin = 0; SFhomeDir.changed = 1; SFhomeDir.beginSelection = -1; SFhomeDir.endSelection = -1; #if defined (SVR4) || defined (SYSV) || defined (USG) qsort ((char *) entries, (unsigned)i, sizeof (SFEntry), SFcompareEntries); qsort ((char *) SFlogins, (unsigned)i, sizeof (SFLogin), SFcompareLogins); #else /* defined (SVR4) || defined (SYSV) || defined (USG) */ qsort ((char *) entries, i, sizeof (SFEntry), SFcompareEntries); qsort ((char *) SFlogins, i, sizeof (SFLogin), SFcompareLogins); #endif /* defined (SVR4) || defined (SYSV) || defined (USG) */ for (i--; i >= 0; i--) { strcat (entries[i].real, "/"); } }
void ModuleOptionsPopup(Widget w, XtPointer user_data, XtPointer call_data) { xf86cfgModuleOptions *info = module_options; if (modOptionsShell == NULL) { char **ops; int nops; Widget pane, form, viewport, bottom, popdown; modOptionsShell = XtCreatePopupShell("moduleOptions", transientShellWidgetClass, optionsShell, NULL, 0); pane = XtCreateManagedWidget("pane", panedWidgetClass, modOptionsShell, NULL, 0); form = XtCreateManagedWidget("descriptions", formWidgetClass, pane, NULL, 0); labelType = XtCreateManagedWidget("labelType", labelWidgetClass, form, NULL, 0); XtCreateManagedWidget("module", labelWidgetClass, form, NULL, 0); viewport = XtCreateManagedWidget("viewM", viewportWidgetClass, form, NULL, 0); ops = NULL; nops = 0; while (info) { ++nops; ops = (char**)XtRealloc((XtPointer)ops, sizeof(char*) * nops); ops[nops - 1] = XtNewString(info->name); info = info->next; } if (nops == 0) { ops = (char**)XtMalloc(sizeof(char*)); ops[0] = XtNewString(""); nops = 1; } else qsort(ops, nops, sizeof(char*), qcmp_str); modList = XtVaCreateManagedWidget("modL", listWidgetClass, viewport, XtNlist, ops, XtNnumberStrings, nops, NULL); XtAddCallback(modList, XtNcallback, SelectModuleCallback, NULL); XtCreateManagedWidget("option", labelWidgetClass, form, NULL, 0); viewport = XtCreateManagedWidget("viewO", viewportWidgetClass, form, NULL, 0); ops = (char**)XtMalloc(sizeof(char*)); ops[0] = XtNewString(""); optList = XtVaCreateManagedWidget("optL", listWidgetClass, viewport, XtNlist, ops, XtNnumberStrings, 1, NULL); XtAddCallback(optList, XtNcallback, SelectModuleOptionCallback, NULL); desc = XtVaCreateManagedWidget("desc", asciiTextWidgetClass, form, XtNeditType, XawtextRead, NULL); bottom = XtCreateManagedWidget("bottom", formWidgetClass, pane, NULL, 0); popdown = XtVaCreateManagedWidget("popdown", commandWidgetClass, bottom, NULL); XtAddCallback(popdown, XtNcallback, ModuleOptionsPopdown, NULL); XtRealizeWidget(modOptionsShell); XSetWMProtocols(DPY, XtWindow(modOptionsShell), &wm_delete_window, 1); info = module_options; } if (module_sel && *module_sel) { XawListReturnStruct list; /* hack to call ballbacks */ char **strs; int nstrs, idx = 0; XtVaGetValues(modList, XtNlist, &strs, XtNnumberStrings, &nstrs, NULL); for (idx = nstrs - 1; idx > 0; idx--) if (strcmp(module_sel, strs[idx]) == 0) break; while (info) { if (strcmp(module_sel, info->name) == 0) break; info = info->next; } if (info) { list.string = info->name; list.list_index = idx; XawListHighlight(modList, idx); SelectModuleCallback(modList, NULL, (XtPointer)&list); } if (option_str && *option_str) { OptionInfoPtr opts = info->option; idx = 0; while (opts && opts->name) { if (strcmp(opts->name, option_str) == 0) break; ++idx; ++opts; } if (opts && opts->name) { list.string = (char *)opts->name; list.list_index = idx; XawListHighlight(optList, idx); SelectModuleOptionCallback(optList, NULL, (XtPointer)&list); } } } XtPopup(modOptionsShell, XtGrabNone); }
void SFupdatePath (void) { static int alloc; static int wasTwiddle = 0; char *begin, *end; int i, j; int prevChange; int SFdirPtrSave, SFdirEndSave; SFDir *dir; if (!SFdirs) { SFdirs = (SFDir *) XtMalloc ((alloc = 10) * sizeof (SFDir)); dir = &(SFdirs[0]); SFstrdup (&dir->dir, "/"); SFchdir ("/"); SFgetDir (dir); for (j = 1; j < alloc; j++) { SFdirs[j].dir = NULL; } dir->path = SFcurrentPath + 1; dir->vOrigin = 0; dir->hOrigin = 0; dir->changed = 1; dir->beginSelection = -1; dir->endSelection = -1; SFhomeDir.dir = NULL; } SFdirEndSave = SFdirEnd; SFdirEnd = 1; SFdirPtrSave = SFdirPtr; SFdirPtr = 0; begin = NULL; if (SFcurrentPath[0] == '~') { if (!SFtwiddle) { SFtwiddle = 1; dir = & (SFdirs[0]); SFrootDir = *dir; if (!SFhomeDir.dir) { SFgetHomeDirs (); } *dir = SFhomeDir; dir->changed = 1; } end = SFcurrentPath; SFdoNotTouchDirPtr = 1; wasTwiddle = 1; } else { if (SFtwiddle) { SFtwiddle = 0; dir = & (SFdirs[0]); *dir = SFrootDir; dir->changed = 1; } end = SFcurrentPath + 1; } i = 0; prevChange = 0; while (*end) { while (*end++ == '/') { ; } end--; begin = end; while ((*end) && (*end++ != '/')) { ; } if ((end - SFcurrentPath <= SFtextPos) && (* (end - 1) == '/')) { SFdirPtr = i - 1; if (SFdirPtr < 0) { SFdirPtr = 0; } } if (*begin) { if (*(end - 1) == '/') { char save = *end; if (SFtwiddle) { if (SFfindHomeDir (begin, end)) { return; } } *end = 0; i++; SFdirEnd++; if (i >= alloc) { SFdirs = (SFDir *) XtRealloc ( (char *) SFdirs, (unsigned) ((alloc *= 2) * sizeof (SFDir)) ); for (j = alloc / 2; j < alloc; j++) { SFdirs[j].dir = NULL; } } dir = &(SFdirs[i]); if ((!(dir->dir)) || prevChange || strcmp (dir->dir, begin)) { if (dir->dir) { SFfree (i); } prevChange = 1; SFstrdup (&dir->dir, begin); dir->path = end; dir->vOrigin = 0; dir->hOrigin = 0; dir->changed = 1; dir->beginSelection = -1; dir->endSelection = -1; SFfindFile (dir - 1, begin); if (SFchdir (SFcurrentPath) || SFgetDir (dir)) { SFunreadableDir (dir); break; } } *end = save; if (!save) { SFunselect (); } } else { if (SFfindFile (& (SFdirs[SFdirEnd-1]), begin)) { return; } } } else { SFunselect (); } } if ((end == SFcurrentPath + 1) && (!SFtwiddle)) { SFunselect (); } for (i = SFdirEnd; i < alloc; i++) { if (SFdirs[i].dir) { SFfree (i); } } if (SFdoNotTouchDirPtr) { if (wasTwiddle) { wasTwiddle = 0; SFdirPtr = SFdirEnd - 2; if (SFdirPtr < 0) { SFdirPtr = 0; } } else { SFdirPtr = SFdirPtrSave; } SFdoNotTouchDirPtr = 0; } if ((SFdirPtr != SFdirPtrSave) || (SFdirEnd != SFdirEndSave)) { XawScrollbarSetThumb ( selFileHScroll, (float) (((double) SFdirPtr) / SFdirEnd), (float) (((double) ((SFdirEnd < 3) ? SFdirEnd : 3)) / SFdirEnd) ); } if (SFdirPtr != SFdirPtrSave) { SFdrawLists (SF_DO_SCROLL); } else { for (i = 0; i < 3; i++) { if (SFdirPtr + i < SFdirEnd) { if (SFdirs[SFdirPtr + i].changed) { SFdirs[SFdirPtr + i].changed = 0; SFdrawList (i, SF_DO_SCROLL); } } else { SFclearList (i, SF_DO_SCROLL); } } } }
static void InitFds ( XtAppContext app, Boolean ignoreEvents, Boolean ignoreInputs, wait_fds_ptr_t wf) { int ii; app->rebuild_fdlist = FALSE; #ifndef USE_POLL wf->nfds = app->fds.nfds; if( !ignoreInputs ) { wf->rmask = app->fds.rmask; wf->wmask = app->fds.wmask; wf->emask = app->fds.emask; } else wf->rmask = wf->wmask = wf->emask = zero_fd; if (!ignoreEvents) for (ii = 0; ii < app->count; ii++) { FD_SET (ConnectionNumber(app->list[ii]), &wf->rmask); } #else #ifndef POLLRDNORM #define POLLRDNORM 0 #endif #ifndef POLLRDBAND #define POLLRDBAND 0 #endif #ifndef POLLWRNORM #define POLLWRNORM 0 #endif #ifndef POLLWRBAND #define POLLWRBAND 0 #endif #define XPOLL_READ (POLLIN|POLLRDNORM|POLLPRI|POLLRDBAND) #define XPOLL_WRITE (POLLOUT|POLLWRNORM|POLLWRBAND) #define XPOLL_EXCEPT 0 if (!ignoreEvents) wf->fdlistlen = wf->num_dpys = app->count; else wf->fdlistlen = wf->num_dpys = 0; if (!ignoreInputs && app->input_list != NULL) { int ii; for (ii = 0; ii < (int) app->input_max; ii++) if (app->input_list[ii] != NULL) wf->fdlistlen++; } if (!wf->fdlist || wf->fdlist == wf->stack) { wf->fdlist = (struct pollfd*) XtStackAlloc (sizeof (struct pollfd) * wf->fdlistlen, wf->stack); } else { wf->fdlist = (struct pollfd*) XtRealloc ((char*) wf->fdlist, sizeof (struct pollfd) * wf->fdlistlen); } if (wf->fdlistlen) { struct pollfd* fdlp = wf->fdlist; InputEvent* iep; if (!ignoreEvents) for (ii = 0 ; ii < wf->num_dpys; ii++, fdlp++) { fdlp->fd = ConnectionNumber (app->list[ii]); fdlp->events = POLLIN; } if (!ignoreInputs && app->input_list != NULL) for (ii = 0; ii < app->input_max; ii++) if (app->input_list[ii] != NULL) { iep = app->input_list[ii]; fdlp->fd = ii; fdlp->events = 0; for ( ; iep; iep = iep->ie_next) { if (iep->ie_condition & XtInputReadMask) fdlp->events |= XPOLL_READ; if (iep->ie_condition & XtInputWriteMask) fdlp->events |= XPOLL_WRITE; if (iep->ie_condition & XtInputExceptMask) fdlp->events |= XPOLL_EXCEPT; } fdlp++; } } #endif }
void EmbeddedClientRegister (ControlData * control_data, Boolean install) { char * client_name; Window client_window; int i, j; WmFpEmbeddedClientList embedded_client_list = (WmFpEmbeddedClientList) panel.embedded_client_list; WmFpEmbeddedClientData * embedded_client = NULL; if ((char) control_data-> element_values[CONTROL_TYPE].parsed_value != CONTROL_CLIENT) return; /* If this is a control installation, increase the list size, if */ /* needed, and initialize the embedded client structure. If it is */ /* a removal, find the control in the list and remove it by sliding */ /* each subsequent structure down one element in array. */ client_name = (char *) control_data->element_values[CONTROL_CLIENT_NAME].parsed_value; if (client_name == NULL) client_name = (char *) control_data->element_values[CONTROL_LABEL].parsed_value; if (install) { /* First see if this is an update to an already installed */ /* embedded client. If so, simply update the icon field */ for (i = 0; i < panel.embedded_client_count; i++) { if (strcmp (client_name, embedded_client_list[i].pchResName) == 0) { embedded_client_list[i].wControl = control_data->icon; break; } } if (i >= panel.embedded_client_count) { if (panel.embedded_client_count == panel.max_embedded_client_count) { panel.max_embedded_client_count += 10; embedded_client_list = (WmFpEmbeddedClientList) XtRealloc ((char *) embedded_client_list, sizeof (WmFpEmbeddedClientData) * panel.max_embedded_client_count); panel.embedded_client_list = (XtPointer) embedded_client_list; } embedded_client = &embedded_client_list[panel.embedded_client_count]; panel.embedded_client_count++; embedded_client->pchResName = XtNewString (client_name); embedded_client->wControl = control_data->icon; embedded_client->winParent = None; embedded_client->pCD = NULL; } for (i = 0; i < panel.embedded_client_count - 1; i++) { embedded_client = &embedded_client_list[i]; if (embedded_client->pCD != NULL) embedded_client->pCD->pECD = (void *) embedded_client; } } else { for (i = 0; i < panel.embedded_client_count; i++) { if (embedded_client_list[i].wControl == control_data->icon) { Position remove_y; Dimension adjust_y; /* This block will reparent the client window, move it */ /* to a new window location, and remap the window. */ if (embedded_client_list[i].pCD != NULL) { client_window = embedded_client_list[i].pCD->client; UnManageWindow (embedded_client_list[i].pCD); XSync (XtDisplay (panel.shell), False); XMoveWindow (XtDisplay (panel.shell), client_window, 0, 0); XMapWindow (XtDisplay (panel.shell), client_window); } remove_y = embedded_client_list[i].y; /* deleted control height plus 5 pixels of form offset */ adjust_y = XtHeight (control_data->icon) + 5; panel.embedded_client_count--; XtFree (embedded_client_list[i].pchResName); for (j = i; j < panel.embedded_client_count; j++) { embedded_client_list[j] = embedded_client_list[j + 1]; embedded_client = &embedded_client_list[j]; if (embedded_client_list[i].pCD != NULL) { embedded_client->pCD->pECD = (void *) embedded_client; if (XtParent(control_data->icon) == XtParent(embedded_client->wControl) && remove_y < embedded_client->y) { embedded_client->y -= adjust_y; XMoveWindow(XtDisplay(panel.shell), embedded_client->pCD->client, embedded_client->x, embedded_client->y); } } } break; } } } /* Set the embedded client list and count into the window manager's */ /* screen global data. */ EmbeddedClientSetData (); }
/* * also called from DropSMgr. Creates target list if not already * there. */ Cardinal _XmTargetsToIndex(Widget shell, Atom *tlist, Cardinal numTargets) { Display *dpy = XtDisplay(shell); XmDndTargetsTable targets; Cardinal i; Atom *atoms; DEBUGOUT(_LtDebug(__FILE__, shell, "%s:_XmTargetsToIndex(%d) - %p 0x%x targets %p\n", __FILE__, __LINE__, tlist, numTargets, tlist ? tlist[0] : 0 )); #if 0 /* For Netscape 4.5 PR1 binary compatibility testing. NS seems to be calling this routine with an invalid (huge) number of numTargets. I just bail out of the whole routine for testing. -jac Sept 22, 1998 */ return 0; #endif if ((targets = get_targets_table(dpy)) == NULL) { _XmInitTargetsTable(dpy); targets = get_targets_table(dpy); } DEBUGOUT(_LtDebug(__FILE__, shell, "%s:_XmTargetsToIndex(%d) - targets->num_entries %i\n", __FILE__, __LINE__, targets->num_entries )); #if 1 /* 28 Jul 1999 Navigator is still calling this with a huge value for numTargets. So for now just do a check for this and bail..... */ for (i = 0; i < targets->num_entries; i++) { if (numTargets == targets->entries[i].num_targets) { break; } } if ((int)numTargets > 1000) { return(0); } #endif atoms = (Atom *)XtMalloc(numTargets * sizeof(Atom)); for (i = 0; i < numTargets; i++) { atoms[i] = tlist[i]; } qsort(atoms, numTargets, sizeof(Atom), acompare); /* maybe it's already there ? */ for (i = 0; i < targets->num_entries; i++) { if (numTargets == targets->entries[i].num_targets && memcmp(atoms, targets->entries[i].targets, sizeof(Atom) * numTargets) == 0) { XtFree((char *)atoms); return i; } } XGrabServer(dpy); if (!read_targets_table(dpy, targets)) { XUngrabServer(dpy); _XmInitTargetsTable(dpy); XGrabServer(dpy); targets = get_targets_table(dpy); } /* maybe somebody added while we've been fooling around, but before * we said nuhuh with the grab */ for (i = 0; i < targets->num_entries; i++) { if (numTargets == targets->entries[i].num_targets && memcmp(atoms, targets->entries[i].targets, sizeof(Atom) * numTargets) == 0) { XtFree((char *)atoms); return i; } } /* nope. add them */ i = targets->num_entries; targets->num_entries++; targets->entries = (XmDndTargetsTableEntry)XtRealloc((char *)targets->entries, sizeof(XmDndTargetsTableEntryRec) * targets->num_entries); targets->entries[i].num_targets = numTargets; targets->entries[i].targets = atoms; write_targets_table(dpy, targets); XUngrabServer(dpy); XFlush(dpy); return i; }
void PushRecallRegister (ControlData * control_data, Boolean install) { char * client_name; int i, j; WmFpPushRecallClientList push_recall_list = (WmFpPushRecallClientList) panel.push_recall_list; WmFpPushRecallClientData * push_recall = NULL; /* If this is a control installation, increase the list size, if */ /* needed, and initialize the push recall structure. If it is a */ /* removal, find the control in the push recall list and remove */ /* it by sliding each subsequent structure down one element in */ /* array. */ if (install) { client_name = (char *) control_data->element_values[CONTROL_CLIENT_NAME].parsed_value; if (client_name == NULL) client_name = (char *) control_data->element_values[CONTROL_LABEL].parsed_value; /* First see if this is an update to an already installed */ /* push recall client. If so, simply update the icon field */ for (i = 0; i < panel.push_recall_count; i++) { if (strcmp (client_name, push_recall_list[i].pchResName) == 0) { push_recall_list[i].wControl = control_data->icon; break; } } if (i >= panel.push_recall_count) { if (panel.push_recall_count == panel.max_push_recall_count) { panel.max_push_recall_count += 10; push_recall_list = (WmFpPushRecallClientList) XtRealloc ((char *) push_recall_list, sizeof (WmFpPushRecallClientData) * panel.max_push_recall_count); panel.push_recall_list = (XtPointer) push_recall_list; } push_recall = &push_recall_list[panel.push_recall_count]; panel.push_recall_count++; push_recall->pchResName = XtNewString (client_name); push_recall->wControl = control_data->icon; push_recall->pCD = NULL; push_recall->tvTimeout.tv_sec = 0; } for (i = 0; i < panel.push_recall_count - 1; i++) { push_recall = &push_recall_list[i]; if (push_recall->pCD != NULL) push_recall->pCD->pPRCD = (void *) push_recall; } } else { for (i = 0; i < panel.push_recall_count; i++) { if (push_recall_list[i].wControl == control_data->icon) { panel.push_recall_count--; XtFree (push_recall_list[i].pchResName); for (j = i; j < panel.push_recall_count; j++) { push_recall_list[j] = push_recall_list[j + 1]; push_recall = &push_recall_list[j]; if (push_recall->pCD != NULL) push_recall->pCD->pPRCD = (void *) push_recall; } break; } } } /* Set the push recall list and count into the window manager's */ /* screen global data. */ PushRecallSetData (); }
/* * write to a drag buffer (sort of) * probably for Motif BC (binary compatibility?!) */ extern int _XmWriteDragBuffer(XmDndBufMgr bmgr, Boolean write_string, char *data, int size) { int increase_needed; DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:_XmWriteDragBuffer(%d) write_string %s size %i\n", __FILE__, __LINE__, write_string ? "True" : "False", size)); if (write_string) { increase_needed = (bmgr->name_size + size) - bmgr->name_avail; if (increase_needed > 0) { increase_needed /= 1000; increase_needed++; increase_needed *= 1000; bmgr->name_avail += increase_needed; if (bmgr->names == bmgr->name_ptr) { bmgr->names = XtMalloc(bmgr->name_avail); memcpy(bmgr->names, bmgr->name_ptr, bmgr->name_size); } else { bmgr->names = XtRealloc((char *)bmgr->names, bmgr->name_avail); } } memcpy(bmgr->names + bmgr->name_size, data, size); bmgr->name_size += size; return size; } else { increase_needed = (bmgr->atom_size + size) - bmgr->atom_avail; if (increase_needed) { increase_needed /= 1000; increase_needed++; increase_needed *= 1000; bmgr->atom_avail += increase_needed; if (bmgr->atoms == bmgr->atom_ptr) { bmgr->atoms = XtMalloc(bmgr->atom_avail); memcpy(bmgr->atoms, bmgr->atom_ptr, bmgr->atom_size); } else { bmgr->atoms = XtRealloc(bmgr->atoms, bmgr->atom_avail); } } memcpy(bmgr->atoms + bmgr->atom_size, data, size); bmgr->atom_size += size; return size; } }
GRAU( XtPointer, call) { #define CHUNK 512 Boolean first = True; String rscs = XtNewString((String)client); String *valueList = (String *)XtCalloc(CHUNK, sizeof(String)); char *start; char *ptr, *cptr; String name; String rsc; int i, count = 0; Widget *current; for ( start = rscs; rscs && *rscs; rscs = strtok(NULL, "\n")) { if ( first ) { rscs = strtok(rscs, "\n"); first = False; } valueList[count] = XtNewString(rscs); count++; if ( count == CHUNK ) { valueList = (String *)XtRealloc((char *)valueList, (count + CHUNK) * sizeof(String)); } } XtFree((char *)start); for ( i = 0; i < count; i++ ) { /* * First, extract the widget name and generate a string to * pass to BxWidgetIdsFromNames(). */ cptr = strrchr(valueList[i], '.'); if ( cptr != NULL ) { *cptr = '\000'; } else { printf("Callback Error (BxSetValuesCB):\n\t\ Syntax Error - specify BxSetValuesCB data as\n\t\ <Widget Name>.<Resource> = <Value>\n"); XtFree((char *)(valueList[i])); continue; } name = valueList[i]; while( (name && *name) && isspace(*name) ) { name++; } ptr = name + strlen(name) - 1; while( ptr && *ptr ) { if ( isspace(*ptr) ) { ptr--; } else { ptr++; break; } } if ( ptr && *ptr ) { *ptr = '\0'; } if ( ptr == NULL ) { printf("Callback Error (BxSetValuesCB):\n\t\ Syntax Error - specify BxSetValuesCB data as\n\t\ <Widget Name>.<Resource> = <Value>\n"); XtFree((char *)(valueList[i])); return; } /* * Next, get the resource name to set. */ rsc = ++cptr; cptr = strchr(rsc, '='); if ( cptr != NULL ) { *cptr = '\000'; } else { printf("Callback Error (BxSetValuesCB):\n\t\ Syntax Error - specify BxSetValuesCB data as\n\t\ <Widget Name>.<Resource> = <Value>\n"); XtFree((char *)(valueList[i])); continue; } while( (rsc && *rsc) && isspace(*rsc) ) { rsc++; } ptr = rsc + strlen(rsc) - 1; while( ptr && *ptr ) { if ( isspace(*ptr) ) { ptr--; } else { ptr++; break; } } if ( ptr && *ptr ) { *ptr = '\0'; } /* * Lastly, get the string value to which to set the resource. */ start = ++cptr; while( (start && *start) && isspace(*start) ) { start++; } if ( start == NULL ) { printf("Callback Error (BxSetValuesCB):\n\t\ Syntax Error - specify BxSetValuesCB data as\n\t\ <Widget Name>.<Resource> = <Value>\n"); XtFree((char *)(valueList[i])); return; }
void ReadCardsDatabase(void) { #ifdef USE_MODULES if (!nomodules) { int i, j, ivendor, idevice; char name[256]; _Xconst char *vendor, *device; CardsEntry *entry = NULL, *tmp; xf86cfgModuleOptions *opts = module_options; const pciDeviceInfo **pDev; /* Only list cards that have a driver installed */ while (opts) { if (opts->chipsets) { SymTabPtr chips = opts->chipsets; while (chips->name) { vendor = opts->name; device = chips->name; ivendor = (chips->token & 0xffff0000) >> 16; idevice = chips->token & 0xffff0; if (ivendor == 0) ivendor = opts->vendor; if (xf86PCIVendorInfo) { for (i = 0; xf86PCIVendorInfo[i].VendorName; i++) if (ivendor == xf86PCIVendorInfo[i].VendorID) { vendor = xf86PCIVendorInfo[i].VendorName; break; } if (xf86PCIVendorInfo[i].VendorName) { if ((pDev = xf86PCIVendorInfo[i].Device)) { for (j = 0; pDev[j]; j++) if (idevice == pDev[j]->DeviceID) { device = pDev[j]->DeviceName; break; } } } } /* Since frequently there is more than one driver for a * single vendor, it is required to avoid duplicates. */ XmuSnprintf(name, sizeof(name), "%s %s", vendor, device); tmp = LookupCard(name); if (tmp == NULL || strcmp(tmp->chipset, chips->name) || strcmp(tmp->driver, opts->name)) { entry = (CardsEntry*)XtCalloc(1, sizeof(CardsEntry)); if (NumCardsEntry % 16 == 0) { CardsDB = (CardsEntry**)XtRealloc((XtPointer)CardsDB, sizeof(CardsEntry*) * (NumCardsEntry + 16)); } CardsDB[NumCardsEntry++] = entry; entry->name = XtNewString(name); /* XXX no private copy of strings */ entry->chipset = (char*)chips->name; entry->driver = opts->name; /* better than linear searchs to find duplicates */ qsort(CardsDB, NumCardsEntry, sizeof(CardsEntry*), CompareCards); } ++chips; } } opts = opts->next; }
XawParams * XawParseParamsString(String name) { XawParams *xaw_params; char *tok, *str, *type = NULL, *ext = NULL, *params = NULL; if (!name) return (NULL); xaw_params = (XawParams *)XtMalloc(sizeof(XawParams)); str = XtNewString(name); /* Find type */ tok = str; while (tok = strchr(tok, ':'), tok) { if (tok == str || tok[-1] != '\\') break; memmove(&tok[-1], tok, strlen(tok) + 1); } if (tok) { *tok = '\0'; if (strchr(str, '?')) { *tok = ':'; } else { ++tok; type = XtNewString(str); memmove(str, tok, strlen(tok) + 1); } } /* Find params */ tok = str; while (tok = strchr(tok, '?'), tok) { if (tok == str || tok[-1] != '\\') params = tok; if (tok != str && tok[-1] == '\\') memmove(&tok[-1], tok, strlen(tok) + 1); else break; } if (params) { *params = '\0'; ++params; } /* Find ext */ tok = str; while (tok = strchr(tok, '.'), tok) { if (tok == str || tok[-1] != '\\') ext = tok; if (tok != str && tok[-1] == '\\') memmove(&tok[-1], tok, strlen(tok) + 1); else break; } if (ext) { ++ext; if (strchr(ext, '/')) ext = NULL; } xaw_params->name = XtNewString(str); xaw_params->type = type; xaw_params->ext = ext ? XtNewString(ext) : ext; xaw_params->args = NULL; xaw_params->num_args = 0; /* Parse params */ if (params) { char *arg, *val; XawArgVal *xaw_arg; for (tok = strtok(params, "&"); tok; tok = strtok(NULL, "&")) { val = strchr(tok, '='); if (val) { *val = '\0'; ++val; if (*val != '\0') val = XtNewString(val); else val = NULL; } arg = XtNewString(tok); xaw_arg = (XawArgVal *)XtMalloc(sizeof(XawArgVal)); xaw_arg->name = arg; xaw_arg->value = val; if (!xaw_params->num_args) { xaw_params->num_args = 1; xaw_params->args = (XawArgVal **) XtMalloc(sizeof(XawArgVal*)); } else { ++xaw_params->num_args; xaw_params->args = (XawArgVal **) XtRealloc((char *)xaw_params->args, sizeof(XawArgVal*) * xaw_params->num_args); } xaw_params->args[xaw_params->num_args - 1] = xaw_arg; } } if (xaw_params->num_args > 1) qsort(xaw_params->args, xaw_params->num_args, sizeof(XtPointer), qcmp_string); XtFree(str); return (xaw_params); }
void UpdatePresenceWorkspaces( WmScreenData *pSD ) { PtrWsPresenceData pPres = &pSD->presence; int wsnum; XmString xmsTmp; if (pPres->shellW) { if (pPres->numWorkspaces < pSD->numWorkspaces) { if (((pPres->ItemStrings = (XmStringTable) XtRealloc ((char *)pPres->ItemStrings, (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) || ((pPres->ItemSelected = (Boolean *) XtRealloc ((char *)pPres->ItemSelected, (pSD->numWorkspaces * sizeof(Boolean)))) == NULL)) { Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog."))); pPres->shellW = NULL; return; } } /* * Replace the names in the dialog's list */ for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++) { if (wsnum < pSD->numWorkspaces) { xmsTmp = XmStringCopy (pSD->pWS[wsnum].title); if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum])) { /* * Replace the string in our local list */ XmStringFree (pPres->ItemStrings[wsnum]); pPres->ItemStrings[wsnum] = xmsTmp; /* * Replace the item in the scrolled list. */ XmListDeletePos (pPres->workspaceListW, 1+wsnum); XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum); } else { XmStringFree (xmsTmp); } } else { /* * Delete this workspace from the list */ XmStringFree (pPres->ItemStrings[wsnum]); pPres->ItemStrings[wsnum] = NULL; XmListDeletePos (pPres->workspaceListW, 1+wsnum); } } for (; wsnum < pSD->numWorkspaces; wsnum++) { /* * Add these workspaces to the list. */ xmsTmp = XmStringCopy (pSD->pWS[wsnum].title); pPres->ItemStrings[wsnum] = xmsTmp; XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum); if (pPres->pCDforClient && (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum], pPres->pCDforClient))) { XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE); pPres->ItemSelected[wsnum] = True; } else { pPres->ItemSelected[wsnum] = False; } } pPres->numWorkspaces = pSD->numWorkspaces; } } /* END OF FUNCTION UpdatePresenceWorkspaces */
Cardinal UrmResizeResourceContext (URMResourceContextPtr context_id, int size) { /* * Local variables */ char *newbuf ; /* new buffer */ if ( ! UrmRCValid(context_id) ) return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0028, NULL, context_id, MrmBAD_CONTEXT) ; if ( size > MrmMaxResourceSize) return Urm__UT_Error ("MrmResizeResourceContext", _MrmMMsg_0029, NULL, context_id, MrmTOO_MANY) ; /* * CR 8391: buffer will eventually be passed to * Urm__CW_EvaluateValOrOffset which is expecting a long. Make sure to * allocate at least a long so that we don't get array bounds read * violations. Ideally Urm__CW_EvaluateValOrOffset and the code that * calls it should be rewritten, but we don't have time for that now. */ if (size < sizeof(long)) size = sizeof(long); /* * Resize unless buffer is bigger than requested size. */ if ( context_id->buffer_size > size ) return MrmSUCCESS ; /* * Allocate the new buffer, copy the old buffer contents, and * update the context. */ if ( context_id->alloc_func == XtMalloc ) { context_id->data_buffer = XtRealloc (context_id->data_buffer, size) ; context_id->buffer_size = size ; } else { newbuf = (char *) (*(context_id->alloc_func)) (size) ; if ( newbuf == NULL ) return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0001, NULL, context_id, MrmFAILURE) ; if ( context_id->data_buffer != NULL ) { UrmBCopy (context_id->data_buffer, newbuf, context_id->buffer_size) ; (*(context_id->free_func)) (context_id->data_buffer) ; } context_id->data_buffer = newbuf ; context_id->buffer_size = size ; } /* * Resize succeeded */ return MrmSUCCESS ; }