home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************
- * NCSA Telnet for the Macintosh *
- * *
- * National Center for Supercomputing Applications *
- * Software Development Group *
- * 152 Computing Applications Building *
- * 605 E. Springfield Ave. *
- * Champaign, IL 61820 *
- * *
- * Copyright (c) 1986-1994, *
- * Board of Trustees of the University of Illinois *
- ****************************************************************/
- #include <ctype.h>
- #include "TelnetHeader.h"
-
- #include "rsinterf.proto.h"
- #include "url.proto.h"
-
- #if 0
- Boolean MyStrNEqual (char *s1, char *s2, short n)
- {
- unsigned char *t = gTable;
- unsigned char *us1 = (unsigned char *)s1;
- unsigned char *us2 = (unsigned char *)s2;
-
- while (--n >= 0 && t[*us1++] == t[*us2++]) /* do nothing */;
- return n < 0;
- }
-
- static Boolean IsFTPURL (char *obj)
- {
- char *p;
-
- if (MyStrNEqual(obj, "ftp:", 4)) return true;
- p = obj;
- while (*p != '.' && *p != 0) p++;
- if (*p == 0) return false;
- p++;
- while (*p != ':' && *p != '/' && *p != 0) p++;
- if (*p == 0) return false;
-
- p = strstr(obj, "://");
- if (p == nil) return true;
- if (MyStrNEqual(obj, "ftp://", 6)) return true;
- return false;
- }
-
- static Boolean IsEmailAddress (CStr255 obj)
- {
- char *p;
-
- if (MyStrNEqual(obj, "mailto:", 7)) return true;
- for (p = obj; *p != 0; p++) {
- if (*p == '@') {
- for (p++; *p != 0; p++) if (*p == '.') return true;
- return false;
- }
- }
- return false;
- }
- #endif
-
- #define isLWSP(a) ((a) == ' ' || (a) == '\t')
- #define isLWSPorCR(a) (isLWSP(a) || (a) == CR)
-
- void ParseURL(short w)
- {
- char *textEnd, *p, *q, *x, *y;
- long len;
- Handle urlH;
-
- urlH = RSGetTextSel(w, 0);
- if ((urlH == (char **)-1L) || (urlH == nil)) {
- return;
- }
-
- HLock(urlH);
-
- p = *urlH;
- q = *urlH + GetHandleSize(urlH) - 1;
-
- textEnd = *urlH + GetHandleSize(urlH);
-
- while (p >= *urlH && !isLWSPorCR(*p) && *p != '<') p--;
- if (*p != '<') {
- p++;
- while (p < q && !isalnum(*p) && *p != '<') p++;
- }
-
- while (q < textEnd && !isLWSPorCR(*q) && *q != '>') q++;
- if (*q != '>') {
- q--;
- while (q > p && !isalnum(*q) && *q != '/' && *q != '>') q--;
- }
-
- if (p >= q) return /*kNotURL*/;
-
- while (p < q && isLWSPorCR(*p)) p++;
- while (p < q && isLWSPorCR(*q)) q--;
-
- len = q - p + 1;
- // if (len > 255) return kNotURL;
-
- for (x = p, y = p; x <= q; x++) {
- if (*x != CR) {
- y++;
- }
- else {
- *y++ = *x;
- }
- }
-
- *y = 0;
- len = y - p;
- if (len == 0) return /*kNotURL*/;
-
- // *urlBegin = p - **urlH;
- // *urlEnd = q - **urlH + 1;
-
- if (len >= 2 && *p == '<' && *q == '>') {
- len -= 2;
- BlockMoveData(p+1, p, len);
- p[len] = 0;
- }
-
- // if (IsFTPURL(url)) return kFtpURL;
-
- // if (IsEmailAddress(url)) return kEmailURL;
-
- DisposeHandle(urlH);
- return /*kNotURL*/;
-
- }