home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xbrowser / part01 / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-03  |  4.4 KB  |  209 lines

  1. /* Systems Sciences Laboratory, Webster Research Center */
  2.  
  3. static char *PROGRAM_information[] =
  4. {
  5.     "Copyright (c) 1988 Xerox Corporation.  All rights reserved.",
  6.     "$Header$",
  7.     "$Locker$"
  8. }
  9. ;
  10.  
  11. /*
  12.  * Copyright protection claimed includes all forms and matters of copyrightable
  13.  * material and information now allowed by statutory or judicial lay or
  14.  * herinafter granted, including without limitation, material generated from
  15.  * the software programs which are displayed on the screen such as icons,
  16.  * screen display looks, etc.
  17.  */
  18.  
  19.  
  20. #include "xfilebrowser.h"
  21. #include <ctype.h>
  22.  
  23. extern char *get_userdir();
  24.  
  25. /* ARGSUSED */
  26. disp_message(fmt, arg1, arg2, arg3, arg4)
  27.   char *fmt;
  28. {
  29.     char buf[1024];
  30.     int maxlength = 1024;
  31.     XtTextBlock text;
  32.     XtTextPosition pos, start;
  33.  
  34.     sprintf(buf, fmt, arg1, arg2, arg3, arg4);
  35.     text.length = strlen(buf);
  36.     text.ptr = buf;
  37.     text.firstPos = 0;
  38.     allowedit = 1;
  39.  
  40.     pos = (*messsource->Scan)(messsource, 0, XtstAll, XtsdRight,1,0);
  41.  
  42.     if ( (pos + text.length) > maxlength)  start = 0;
  43.     else start = pos;
  44.     XtTextReplace( messwidget, start, pos, &text);
  45.     XtTextSetInsertionPoint(messwidget, start + text.length);
  46.  
  47.     allowedit = 0;
  48.     /* Feep(); */
  49. }
  50.  
  51.  
  52. /* ARGSUSED */
  53. Widget makeCommandButton(box, name, function)
  54.   Window box;
  55.   char *name;
  56.   XtCallbackProc function;
  57. {
  58.   static XtCallbackRec callbackList[] = { {NULL, NULL}, {NULL, NULL} };
  59.   static Arg arg[] = { {XtNcallback,(XtArgVal)callbackList} };
  60.  
  61.     callbackList[0].callback = function;
  62.     return (XtCreateManagedWidget(name, commandWidgetClass, box, arg, 1));
  63. }
  64.  
  65. /* ARGSUSED */
  66. Widget makeStringBox(parentBox, string, length)
  67.   Widget parentBox;
  68.   char *string;
  69. {
  70.   Arg args[5];
  71.   Widget StringW;
  72.   int numargs;
  73.     numargs = 0;
  74.     MakeArg(XtNeditType, (XtArgVal)XttextEdit );
  75.     MakeArg(XtNtextOptions, (XtArgVal)( resizeWidth)); 
  76.     MakeArg(XtNstring,(XtArgVal)string);     
  77.     MakeArg(XtNwidth,  (XtArgVal)length);
  78.     MakeArg(XtNlength, (XtArgVal)1000);
  79.     StringW = XtCreateManagedWidget("stringthing", asciiStringWidgetClass, 
  80.                     parentBox, args, numargs);
  81.     return(StringW);  
  82. }
  83.  
  84. /* ARGSUSED */
  85. clear_widget(w, wsrc)
  86. Widget w;
  87. XtTextSource wsrc;
  88. {
  89.     XtTextBlock text;
  90.     XtTextPosition end;
  91.     
  92.     allowedit = 1;
  93.     text.length = 0;
  94.     text.ptr = "";
  95.     text.firstPos = 0;
  96.  
  97.     end = (*wsrc->Scan)(wsrc, 0, XtstAll, XtsdRight, 1, 0);
  98.  
  99.     XtTextReplace(w, 0, end, &text);
  100.     XtTextUnsetSelection(w);
  101.     XtTextSetInsertionPoint(w, 0);
  102.     allowedit = 0;
  103. }
  104.  
  105.  
  106. int setup_dirlabel(dir, pattern)
  107. char *dir, *pattern;
  108. {
  109.     Arg dirargs[1];
  110.     XtTextSource src;
  111.     XtTextBlock text, block;
  112.     XtTextPosition end;
  113.  
  114.         /* setup the new pattern in the fpatwindow widget */    
  115.     allowedit = 1;
  116.     text.length = strlen(pattern);
  117.     text.ptr = pattern;
  118.     text.firstPos = 0;
  119.  
  120.     src = XtTextGetSource(fpatwindow);
  121.     (void)(*src->Read)(src, 0, &block, 254);
  122.  
  123.     end = block.length;
  124.     XtTextReplace(fpatwindow, 0, end, &text);
  125.     allowedit = 0;
  126.  
  127.         /* setup the new directory label in dirwidget */
  128.     XtSetArg(dirargs[0], XtNlabel, dir);
  129.     XtSetValues(dirwidget, dirargs, XtNumber(dirargs));
  130. }
  131.  
  132.  
  133. setup_iconname()
  134. {
  135.     Arg topargs[1];
  136.     char *p;
  137.     char pattern[32];
  138.  
  139.     if ( ((p = rindex(curdirectory, '/')) == NULL) || (strlen(p) == 1))
  140.         XtSetArg(topargs[0], XtNiconName, (XtArgVal)"xbrowser");
  141.     else {
  142.        sprintf(pattern, "../%s", p+1);
  143.        XtSetArg(topargs[0], XtNiconName, (XtArgVal)pattern);
  144.     }
  145.     XtSetValues(toplevel, topargs, XtNumber(topargs));
  146. }
  147.  
  148. /* ARGSUSED */
  149. int getsize(w, width, height)
  150. Widget w;
  151. Dimension *width, *height;
  152. {
  153.     static Dimension twidth, theight;
  154.     
  155.     static Arg args[] = {
  156.       {XtNwidth, (XtArgVal)&twidth},
  157.           {XtNheight, (XtArgVal)&theight},
  158.         };
  159.  
  160.     XtGetValues(w, args, (Cardinal)2);
  161.     *width = twidth;
  162.     *height = theight;
  163. }
  164.  
  165. /* ARGSUSED */
  166. int getpos(w, posx, posy)
  167. Widget w;
  168. Position *posx, *posy;
  169. {
  170.     static  Position tposx, tposy;
  171.     
  172.     static Arg args[] = { 
  173.        {XtNy, (XtArgVal)&tposy},
  174.            {XtNx, (XtArgVal)&tposx},
  175.         };
  176.  
  177.     XtGetValues(w, args, (Cardinal)2);
  178.     *posx = tposx;
  179.     *posy = tposy;
  180. }
  181.  
  182. /* ARGSUSED */
  183. char *expand_tilde(s)
  184. char *s;
  185. {
  186.     char *home, *getenv();
  187.     char *p, *fullname;
  188.     int i;
  189.     char user[12];
  190.  
  191.     if (s[0] == '~' && (s[1] == '\0' || s[1] == '/') ) {
  192.        home = getenv("HOME");
  193.        p = s + 1;
  194.     }
  195.     else if (s[0] == '~' && isalnum(s[1])) {
  196.        p = s + 1;
  197.        i = 0;
  198.        while (*p != '/' && *p != '\0')   user[i++] = *p++; 
  199.        user[i] = '\0'; 
  200.  
  201.        if ( (home = get_userdir(user)) == NULL) return((char *)NULL);
  202.     }
  203.  
  204.     fullname = XtMalloc(strlen(home) + strlen(p));
  205.     sprintf(fullname, "%s%s", home, p);
  206.     return fullname;
  207. }
  208.  
  209.