home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Telnet 2.7b5 / source / Url / url.c next >
Encoding:
Text File  |  1995-04-01  |  17.9 KB  |  183 lines  |  [TEXT/CWIE]

  1. ig, char *url)
  2. {
  3.     OSErr err = noErr;
  4.     ProcessSerialNumber psn;
  5.     FSSpec appSpec;
  6.     Boolean running;
  7.     unsigned short launchControlFlags;
  8.     
  9.     launchControlFlags = launchContinue | launchNoFileFlags;
  10.         
  11.     err = FindAppFromSig(sig, &appSpec, &running, &psn);
  12.     if (err != noErr) return err;            
  13.             
  14.     err = LaunchAppWithEventAndString(running, &appSpec, &psn,
  15.                 kGetURLEventClass, kGetURLEventID,
  16.                 keyDirectObject, url, 0, launchControlFlags);
  17.     return err;
  18. }
  19. #define isurlschemechar(c)                (isalnum((c)) || c == '+' || c == '.' || c == '-')
  20.  
  21. Boolean FindURLAroundPoint(Point curr, short w)
  22. {
  23.     /* called by RSSelect when Command Click has occured outside any selection.
  24.    This routine looks for urls around the current point, makes that the selected area if 
  25.    it finds one, and returns TRUE.  Otherwise leaves the current selection area untouched
  26.    and returns FALSE. */
  27. /* Note: the point we receive is already normalized to a character position */
  28.     short columns;    
  29.     Handle block;
  30.     char *original, *start, *end, *textEnd, *p, *q;
  31.     short i, numLines = 1;
  32.     char EOLS = CR;
  33.     short neededLines, endLine = 0, startLine = 0;
  34.     short blockSize;
  35.     Point startPoint, endPoint;
  36.     short  currentLine;
  37.     char *tempBlockPtr;
  38.     short tempCounter, lineLength[20];
  39.     Boolean found = FALSE, allowSpaces=FALSE;
  40.     
  41.     columns = VSgetcols(w) + 1; //VSgetcols returns one less than the number of columns
  42.     
  43.     /* we need enough space to find a 255 char URL on either side of the cursor */
  44.     neededLines = 510/columns; 
  45.     if (255%columns != 0)
  46.         neededLines += 2;
  47.     
  48.     /* want it to be symmetric about this line */
  49.     if (neededLines%2 == 0)
  50.         neededLines += 1;
  51.     
  52.     blockSize = neededLines*(columns + 1); //we need space for the \r
  53.     
  54.     block = myNewHandle((long)blockSize);
  55.     
  56.     textEnd = *block + blockSize;
  57.     
  58.     HLock(block);
  59.  
  60.     /* get the lines we need */
  61.     VSgettext(w, 0, curr.v-(neededLines-1)/2, columns-1, curr.v+(neededLines-1)/2, *block, blockSize, &EOLS, 0); 
  62.     
  63.     original = *block;
  64.     for (i = 0; i < (neededLines-1)/2; i++)
  65.     {
  66.         while (*original != CR)
  67.             original++;
  68.         original++;
  69.     }
  70.     original+= curr.h + 1;
  71.  
  72.     tempBlockPtr = *block;
  73.     for (i = 0; i < neededLines; i++)
  74.     {
  75.         tempCounter = 0;
  76.         while (*tempBlockPtr++ != CR) tempCounter++;
  77.         lineLength[i] = tempCounter;
  78.     }
  79.  
  80.     p = original;
  81.     
  82.     q = original - 1;
  83.     currentLine = (neededLines-1)/2 + 1;
  84.     while ((!found)&&(p > *block))
  85.     {
  86.         while (p >= *block && !isLWSPorCR(*p) && *p != '<' && *p != '"') p--;
  87.         if (*p == CR)
  88.         {
  89.             if (lineLength[currentLine - 2] == columns)
  90.             {    
  91.                 p--; //this is just a wrapped line
  92.                 currentLine--;
  93.             }
  94.             else
  95.                 found = TRUE;
  96.         }
  97.         else
  98.             found = TRUE;
  99.     }
  100.     
  101.     startLine = currentLine;
  102.     if (*p != '<') 
  103.         p++;
  104.     else
  105.         allowSpaces = TRUE;
  106.     
  107.     
  108.     currentLine = (neededLines-1)/2 + 1;
  109.     
  110.     found = FALSE;
  111.     while (!found)
  112.     {
  113.         while (q < textEnd && (*q != CR) &&(!isLWSP(*q) || allowSpaces) 
  114.                         && *q != '>' && *q != '"') q++;
  115.         if (*q == CR)
  116.         {
  117.             if (lineLength[currentLine-1] == columns)
  118.             {    
  119.                 q++; //this is just a wrapped line
  120.                 currentLine++;
  121.             }
  122.             else
  123.                 found = TRUE;
  124.         }
  125.         else
  126.             found = TRUE;
  127.     }
  128.     endLine = currentLine;
  129.     if (*q != '>') q--;
  130.     
  131.     if (p >= q) return FALSE;
  132.  
  133.     while (p < q && (isLWSPorCR(*p))) p++;
  134.     while (p < q && (isLWSPorCR(*q))) q--;
  135.  
  136.     if (*p == '<') 
  137.     {
  138.         if (*q != '>') return FALSE;
  139.     }
  140.     else 
  141.     {
  142.         if (*q == '>') return FALSE;
  143.     } 
  144.  
  145.     start = p;
  146.     end = q;
  147.  
  148.              
  149.     UnHiliteSelection(w);
  150.     HUnlock(block);
  151.     
  152.     startPoint.v = curr.v - ((neededLines-1)/2 + 1 - startLine);
  153.     endPoint.v   = curr.v + (endLine -(neededLines-1)/2 - 1);
  154.     
  155.     if (startPoint.v == curr.v)
  156.         startPoint.h = curr.h - (original - start);
  157.     else
  158.     {
  159.         long numChars = 0;
  160.         for (i = 0; i < startLine - 1; i++)
  161.             numChars += lineLength[i] + 1;
  162.         startPoint.h = (start - *block - numChars - 1);
  163.     }    
  164.     if (endPoint.v == curr.v)
  165.         endPoint.h = curr.h + (end - original + 1);
  166.     else
  167.     {
  168.         long numChars = 0;
  169.         for (i = 0; i < endLine - 1; i++)
  170.             numChars += lineLength[i] + 1;
  171.         endPoint.h = (end - *block - numChars);
  172.     }    
  173.  
  174.     HiliteThis(w, startPoint, endPoint);
  175.     
  176.     return TRUE;
  177. }
  178.     
  179.             
  180.         
  181.         
  182.         
  183.