cf0f19a719fa5b19ac2bca77e929b7f8ac6fbc43 tdreszer Tue Oct 19 17:20:49 2010 -0700 Cleaned up some comments and code as suggested by Jim diff --git src/hg/lib/web.c src/hg/lib/web.c index 75da1f0..8afa230 100644 --- src/hg/lib/web.c +++ src/hg/lib/web.c @@ -1240,6 +1240,7 @@ char *webTimeStampedLinkToResource(char *fileName, boolean wrapInHtml) // Returns full path of timestamped link to the requested resource file (js, or css). // If wrapInHtml, then returns link embedded in style or script html. Free after use. +// NOTE: png, jpg and gif should also be supported but are untested. { char baseName[PATH_LEN]; char extension[FILEEXT_LEN]; @@ -1247,16 +1248,16 @@ boolean js = sameString(".js",extension); boolean style = !js && sameString(".css",extension); boolean image = !js && !style && (sameString(".png",extension) || sameString(".jpg",extension) || sameString(".gif",extension)); -if(!js && !style && !image) +if(!js && !style) // && !image) NOTE: This code has not been tested on images but should work. errAbort("webTimeStampedLinkToResource: unknown resource type for %s.\n", fileName); // Build and verify directory -char *dirName = NULL; +char *dirName = ""; if (js) dirName = cfgOptionDefault("browser.javaScriptDir", "js"); else if (style) dirName = "style"; -else +else if (image) dirName = "style/images"; struct dyString *fullDirName = NULL; char *docRoot = hDocumentRoot(); @@ -1322,8 +1323,8 @@ dyStringPrintf(wrapped,"\n", link); else if (style) dyStringPrintf(wrapped,"\n", link); - else // assume image! - dyStringPrintf(wrapped,"\n", link); // NOTE: perhaps it is better to errAbort! + else // Will be image, since these are the only three choices allowed + dyStringPrintf(wrapped,"\n", link); freeMem(link); link = dyStringCannibalize(&wrapped); } @@ -1335,6 +1336,7 @@ // If this is the first call, will // Return full path of timestamped link to the requested resource file (js, or css). Free after use. // else returns NULL. Useful to ensure multiple references to the same resource file are not made +// NOTE: png, jpg and gif should also be supported but are untested. { static struct hash *includedResourceFiles = NULL; if(!includedResourceFiles) @@ -1349,17 +1351,22 @@ return link; } -boolean webIncludeResourceFile(char *fileName) -// Converts fileName to web Resource link and hPrintfs the html reference +boolean webIncludeResourcePrintToFile(FILE * toFile, char *fileName) +// Converts fileName to web Resource link and prints the html reference // This only prints and returns TRUE on first call for this resource. +// Passing in NULL as the file pointer results in hPrintf call // The reference will be to a link with timestamp. { char *link = webTimeStampedLinkToResourceOnFirstCall(fileName,TRUE); if (link) { + if (toFile == NULL) hPrintf("%s",link); + else + fprintf(toFile,"%s",link); freeMem(link); return TRUE; } return FALSE; } +