Fossil SCM

Eliminated an unnecessary allocation. Code style conformance tweaks.

stephan 2020-05-17 19:49 style-css-revamp
Commit e2a9fe4bc87824ea2e793898c25847a246eda1c28150ad057cd807ded4bc4016
1 file changed +11 -12
+11 -12
--- src/style.c
+++ src/style.c
@@ -340,12 +340,12 @@
340340
const struct Submenu *A = (const struct Submenu*)a;
341341
const struct Submenu *B = (const struct Submenu*)b;
342342
return fossil_strcmp(A->zLabel, B->zLabel);
343343
}
344344
345
-/* Use this for the $current_page variable if it is not NULL. If it is
346
-** NULL then use g.zPath.
345
+/* Use this for the $current_page variable if it is not NULL. If it
346
+** is NULL then use g.zPath.
347347
*/
348348
static char *local_zCurrentPage = 0;
349349
350350
/*
351351
** Set the desired $current_page to something other than g.zPath
@@ -361,38 +361,37 @@
361361
va_end(ap);
362362
}
363363
}
364364
365365
/*
366
-** Create a TH1 variable containing the URL for the specified config resource.
367
-** The resulting variable name will be of the form $[zVarPrefix]_url.
366
+** Create a TH1 variable containing the URL for the specified config
367
+** resource. The resulting variable name will be of the form
368
+** $[zVarPrefix]_url.
368369
*/
369370
static void url_var(
370371
const char *zVarPrefix,
371372
const char *zConfigName,
372373
const char *zPageName
373374
){
374375
char *zVarName = mprintf("%s_url", zVarPrefix);
375
- char *zExtra = 0;
376
- char *zUrl = 0;
376
+ char *zUrl = 0; /* stylesheet URL */
377
+ int hasBuiltin = 0; /* true for built-in page-specific CSS */
378
+
377379
if(0==strcmp("css",zConfigName)){
378380
/* Account for page-specific CSS, appending a /{{g.zPath}} to the
379381
** url only if we have a corresponding built-in page-specific CSS
380382
** file. Do not append it to all pages because we would
381383
** effectively cache-bust all pages which do not have
382384
** page-specific CSS. */
383385
char * zBuiltin = mprintf("style.%s.css", g.zPath);
384
- if(builtin_file(zBuiltin,0)!=0){
385
- zExtra = mprintf("/%s", g.zPath);
386
- }
386
+ hasBuiltin = builtin_file(zBuiltin,0)!=0;
387387
fossil_free(zBuiltin);
388388
}
389
- zUrl = mprintf("%R/%s%s?id=%x", zPageName,
390
- zExtra ? zExtra : "",
389
+ zUrl = mprintf("%R/%s%s%s?id=%x", zPageName,
390
+ hasBuiltin ? "/" : "", hasBuiltin ? g.zPath : "",
391391
skin_id(zConfigName));
392392
Th_Store(zVarName, zUrl);
393
- fossil_free(zExtra);
394393
fossil_free(zUrl);
395394
fossil_free(zVarName);
396395
}
397396
398397
/*
399398
--- src/style.c
+++ src/style.c
@@ -340,12 +340,12 @@
340 const struct Submenu *A = (const struct Submenu*)a;
341 const struct Submenu *B = (const struct Submenu*)b;
342 return fossil_strcmp(A->zLabel, B->zLabel);
343 }
344
345 /* Use this for the $current_page variable if it is not NULL. If it is
346 ** NULL then use g.zPath.
347 */
348 static char *local_zCurrentPage = 0;
349
350 /*
351 ** Set the desired $current_page to something other than g.zPath
@@ -361,38 +361,37 @@
361 va_end(ap);
362 }
363 }
364
365 /*
366 ** Create a TH1 variable containing the URL for the specified config resource.
367 ** The resulting variable name will be of the form $[zVarPrefix]_url.
 
368 */
369 static void url_var(
370 const char *zVarPrefix,
371 const char *zConfigName,
372 const char *zPageName
373 ){
374 char *zVarName = mprintf("%s_url", zVarPrefix);
375 char *zExtra = 0;
376 char *zUrl = 0;
 
377 if(0==strcmp("css",zConfigName)){
378 /* Account for page-specific CSS, appending a /{{g.zPath}} to the
379 ** url only if we have a corresponding built-in page-specific CSS
380 ** file. Do not append it to all pages because we would
381 ** effectively cache-bust all pages which do not have
382 ** page-specific CSS. */
383 char * zBuiltin = mprintf("style.%s.css", g.zPath);
384 if(builtin_file(zBuiltin,0)!=0){
385 zExtra = mprintf("/%s", g.zPath);
386 }
387 fossil_free(zBuiltin);
388 }
389 zUrl = mprintf("%R/%s%s?id=%x", zPageName,
390 zExtra ? zExtra : "",
391 skin_id(zConfigName));
392 Th_Store(zVarName, zUrl);
393 fossil_free(zExtra);
394 fossil_free(zUrl);
395 fossil_free(zVarName);
396 }
397
398 /*
399
--- src/style.c
+++ src/style.c
@@ -340,12 +340,12 @@
340 const struct Submenu *A = (const struct Submenu*)a;
341 const struct Submenu *B = (const struct Submenu*)b;
342 return fossil_strcmp(A->zLabel, B->zLabel);
343 }
344
345 /* Use this for the $current_page variable if it is not NULL. If it
346 ** is NULL then use g.zPath.
347 */
348 static char *local_zCurrentPage = 0;
349
350 /*
351 ** Set the desired $current_page to something other than g.zPath
@@ -361,38 +361,37 @@
361 va_end(ap);
362 }
363 }
364
365 /*
366 ** Create a TH1 variable containing the URL for the specified config
367 ** resource. The resulting variable name will be of the form
368 ** $[zVarPrefix]_url.
369 */
370 static void url_var(
371 const char *zVarPrefix,
372 const char *zConfigName,
373 const char *zPageName
374 ){
375 char *zVarName = mprintf("%s_url", zVarPrefix);
376 char *zUrl = 0; /* stylesheet URL */
377 int hasBuiltin = 0; /* true for built-in page-specific CSS */
378
379 if(0==strcmp("css",zConfigName)){
380 /* Account for page-specific CSS, appending a /{{g.zPath}} to the
381 ** url only if we have a corresponding built-in page-specific CSS
382 ** file. Do not append it to all pages because we would
383 ** effectively cache-bust all pages which do not have
384 ** page-specific CSS. */
385 char * zBuiltin = mprintf("style.%s.css", g.zPath);
386 hasBuiltin = builtin_file(zBuiltin,0)!=0;
 
 
387 fossil_free(zBuiltin);
388 }
389 zUrl = mprintf("%R/%s%s%s?id=%x", zPageName,
390 hasBuiltin ? "/" : "", hasBuiltin ? g.zPath : "",
391 skin_id(zConfigName));
392 Th_Store(zVarName, zUrl);
 
393 fossil_free(zUrl);
394 fossil_free(zVarName);
395 }
396
397 /*
398

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button