home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2306 / DayName.c < prev    next >
C/C++ Source or Header  |  1990-12-28  |  4KB  |  111 lines

  1. /*
  2.  * Author: Jason Baietto, jason@ssd.csd.harris.com
  3.  * xdiary Copyright 1990 Harris Corporation
  4.  *
  5.  * Permission to use, copy, modify, and distribute, this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of the copyright holder be used in
  10.  * advertising or publicity pertaining to distribution of the software with
  11.  * specific, written prior permission, and that no fee is charged for further
  12.  * distribution of this software, or any modifications thereof.  The copyright
  13.  * holder makes no representations about the suitability of this software for
  14.  * any purpose.  It is provided "as is" without express or implied warranty.
  15.  *
  16.  * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND IN NO
  18.  * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ITS USE,
  20.  * LOSS OF DATA, PROFITS, QPA OR GPA, WHETHER IN AN ACTION OF CONTRACT,
  21.  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  22.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <ctype.h>
  27. #include <X11/StringDefs.h>
  28. #include <X11/IntrinsicP.h>
  29. #include "DayNameP.h"
  30. #include "common.h"
  31.  
  32. #define MAX_STRING_LEN 256
  33.  
  34. /*==========================================================================*/
  35. /*                                 Quarks:                                  */
  36. /*==========================================================================*/
  37. XrmQuark XtQSunday;
  38. XrmQuark XtQMonday;
  39. XrmQuark XtQTuesday;
  40. XrmQuark XtQWednesday;
  41. XrmQuark XtQThursday;
  42. XrmQuark XtQFriday;
  43. XrmQuark XtQSaturday;
  44.  
  45.  
  46. /*==========================================================================*/
  47. /*                         DayName Type Converter:                          */
  48. /*==========================================================================*/
  49. static void downcase_string(source, dest)
  50. char * source;
  51. char * dest;
  52. {
  53.    for (; *source != 0; source++, dest++) {
  54.       *dest = DOWNCASE(*source);
  55.    }
  56.    *dest = 0;
  57. }
  58.  
  59.  
  60.  
  61. /*ARGSUSED*/
  62. void DayNameConverter(args, num_args, fromVal, toVal)
  63. XrmValuePtr args;
  64. Cardinal    *num_args;
  65. XrmValuePtr fromVal;
  66. XrmValuePtr toVal;
  67. {
  68.    static int initialized = FALSE;
  69.    static XtDayName DayName;
  70.    XrmQuark q;
  71.    char lowerName[MAX_STRING_LEN];
  72.  
  73.    if (!initialized) {
  74.       /* Create quarks the first time we're called. */
  75.       XtQSunday     = XrmStringToQuark(XtNsunday);
  76.       XtQMonday     = XrmStringToQuark(XtNmonday);
  77.       XtQTuesday    = XrmStringToQuark(XtNtuesday);
  78.       XtQWednesday  = XrmStringToQuark(XtNwednesday);
  79.       XtQThursday   = XrmStringToQuark(XtNthursday);
  80.       XtQFriday     = XrmStringToQuark(XtNfriday);
  81.       XtQSaturday   = XrmStringToQuark(XtNsaturday);
  82.    }
  83.  
  84.    downcase_string((char*)fromVal->addr, lowerName);
  85.    q = XrmStringToQuark(lowerName);
  86.  
  87.    toVal->size = sizeof(XtDayName);
  88.    toVal->addr = (XtPointer) &DayName;
  89.  
  90.    if (q == XtQSunday) {
  91.       DayName = Sunday;
  92.    } else if (q == XtQMonday) {
  93.       DayName = Monday;
  94.    } else if (q == XtQTuesday) {
  95.       DayName = Tuesday;
  96.    } else if (q == XtQWednesday) {
  97.       DayName = Wednesday;
  98.    } else if (q == XtQThursday) {
  99.       DayName = Thursday;
  100.    } else if (q == XtQFriday) {
  101.       DayName = Friday;
  102.    } else if (q == XtQSaturday) {
  103.       DayName = Saturday;
  104.    } else {
  105.       XtStringConversionWarning(fromVal->addr, "XtRDayName");
  106.       toVal->addr = NULL;
  107.       toVal->size = 0;
  108.    }
  109. }
  110.  
  111.