- Timestamp:
- Sep 26, 2007, 2:13:53 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/function.c
r1122 r1124 2675 2675 2676 2676 #ifdef CONFIG_WITH_DATE 2677 # if defined (_MSC_VER) /* FIXME: !defined (HAVE_STRPTIME) */ 2678 char *strptime(const char *s, const char *format, struct tm *tm) 2679 { 2680 return (char *)"strptime is not implemented"; 2681 } 2682 # endif 2683 /* Check if the string is all blanks or not. */ 2684 static int 2685 all_blanks (const char *s) 2686 { 2687 if (!s) 2688 return 1; 2689 while (isspace ((unsigned char)*s)) 2690 s++; 2691 return *s == '\0'; 2692 } 2693 2677 2694 /* The first argument is the strftime format string, a iso 2678 2695 timestamp is the default if nothing is given. … … 2684 2701 func_date (char *o, char **argv, const char *funcname) 2685 2702 { 2703 char *p; 2686 2704 char *buf; 2687 2705 size_t buf_size; 2688 time_t tval; 2689 const char *format = !strcmp (funcname, "date-utc") 2690 ? "%Y-%m-%dT%H:%M:%SZ" 2691 : "%Y-%m-%dT%H:%M:%S"; 2692 if (argv[0]) 2693 { 2694 buf = argv[0]; 2695 while (isspace ((unsigned char)*buf)) 2696 buf++; 2697 if (*buf) 2698 format = argv[0]; 2699 } 2700 2701 if (argv[1]) 2702 { 2703 /* FIXME */ 2704 fatal (NILF, _("The reverse strftime aspect of the $(date*) functions isn't implemented yet.\n")); 2706 struct tm t; 2707 const char *format; 2708 2709 /* determin the format - use a single word as the default. */ 2710 format = !strcmp (funcname, "date-utc") 2711 ? "%Y-%m-%dT%H:%M:%SZ" 2712 : "%Y-%m-%dT%H:%M:%S"; 2713 if (!all_blanks (argv[0])) 2714 format = argv[0]; 2715 2716 /* get the time. */ 2717 memset (&t, 0, sizeof(t)); 2718 if (argv[0] && !all_blanks (argv[1])) 2719 { 2720 const char *input_format = !all_blanks (argv[2]) ? argv[2] : format; 2721 p = strptime (argv[1], input_format, &t); 2722 if (!p || *p != '\0') 2723 { 2724 error (NILF, _("$(%s): strptime(%s,%s,) -> %s\n"), funcname, 2725 argv[1], input_format, p ? p : "<null>"); 2726 return variable_buffer_output (o, "", 1); 2727 } 2705 2728 } 2706 2729 else 2707 time(&tval); 2708 2730 { 2731 time_t tval; 2732 time (&tval); 2733 if (!strcmp (funcname, "date-utc")) 2734 t = *gmtime (&tval); 2735 else 2736 t = *localtime (&tval); 2737 } 2738 2739 /* format it. note that zero isn't necessarily an error, so we'll 2740 have to keep shut about failures. */ 2709 2741 buf_size = 64; 2710 2742 buf = xmalloc (buf_size); 2711 while (strftime (buf, buf_size, format, 2712 !strcmp (funcname, "date-utc") 2713 ? gmtime (&tval) : localtime (&tval)) == 0) 2714 buf = xrealloc (buf, buf_size <<= 1); 2743 while (strftime (buf, buf_size, format, &t) == 0) 2744 { 2745 if (buf_size >= 4096) 2746 { 2747 *buf = '\0'; 2748 break; 2749 } 2750 buf = xrealloc (buf, buf_size <<= 1); 2751 } 2715 2752 o = variable_buffer_output (o, buf, strlen (buf)); 2716 2753 free (buf); … … 3215 3252 #ifdef CONFIG_WITH_DATE 3216 3253 { STRING_SIZE_TUPLE("date"), 0, 1, 1, func_date}, 3217 { STRING_SIZE_TUPLE("date-utc"), 0, 1, 1, func_date},3254 { STRING_SIZE_TUPLE("date-utc"), 0, 3, 1, func_date}, 3218 3255 #endif 3219 3256 #ifdef CONFIG_WITH_FILE_SIZE
Note:
See TracChangeset
for help on using the changeset viewer.