home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / dev / Libraries / Date / src / textenginetest.c < prev   
Encoding:
C/C++ Source or Header  |  1995-06-18  |  5.0 KB  |  178 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "TextEngine.h"
  6.  
  7.  
  8.  Languages readlanguage(void)
  9.   {
  10.    unsigned int lang=0;
  11.  
  12.   do
  13.    {
  14.     printf("language: 0=locale.library; 1=English; 2=Deutsch; 3=francais; 4=espanol; 5=portugues; 6=dansk 7=italiano 8=nederlands 9=norsk 10=svenska 11=polski 12=suomalainen: ");
  15.     scanf("%u",&lang);
  16.    }
  17.   while (lang > 10);
  18.   return((Languages)lang);
  19.   }
  20.  
  21.  
  22.  char *readstring(void)
  23.   {
  24.    char *str = (char *)malloc(sizeof(char)*256);
  25.  
  26.    do
  27.     {
  28.      unsigned short i=0;
  29.  
  30.      printf("string: ");
  31.      do
  32.       {
  33.        str[i] = (char)getc(stdin);
  34.       }
  35.      while (str[i++]!='\n');
  36.      str[--i] = '\x0';
  37.     }
  38.    while (str[0] == '\n');
  39.    return(str);
  40.   }
  41.  
  42.  
  43.  char **readstrarr(void)
  44.   {
  45.    char **strarr = (char **)malloc(sizeof(char *)*256);
  46.    char *str;
  47.    unsigned short i=0;
  48.  
  49.    do
  50.     {
  51.      unsigned short j=0;
  52.      str = (char *)malloc(sizeof(char)*1024);
  53.  
  54.      printf("string of array[%hu]: ",i);
  55.      do
  56.       {
  57.        str[j] = (char)getc(stdin);
  58.       }
  59.      while (str[j++]!='\n');
  60.      str[--j] = '\x0';
  61.      strarr[i++] = str;
  62.     }
  63.    while (str[0] != '\x0');
  64.    strarr[--i] = NULL;
  65.    free(str);
  66.    return(strarr);
  67.   }
  68.  
  69.  
  70.  void main(void)
  71.   {
  72.    unsigned int input=0,repeat=0;
  73.    char *str,**strarr;
  74.    unsigned short day1,month1,day2,month2,hour1,min1,sec1,hour2,min2,sec2;
  75.    int year1,year2;
  76.    double jd1,jd2;
  77.    unsigned short i;
  78.    time_t TIME;
  79.    struct tm *LTIME;
  80.  
  81.    #ifndef __SASC_650
  82.      _DateInit();
  83.    #endif
  84.    TIME = time(NULL);
  85.    LTIME = localtime(&TIME);
  86.    day1 = (unsigned short)LTIME->tm_mday;
  87.    month1 = (unsigned short)(LTIME->tm_mon+1);
  88.    year1 = LTIME->tm_year;
  89.    year1 += (year1 < 90 ? 2000 : 1900);
  90.    hour1 = (unsigned short)LTIME->tm_hour;
  91.    min1 = (unsigned short)LTIME->tm_min;
  92.    sec1 = (unsigned short)LTIME->tm_sec;
  93.    jd1 = (double)HeisToJD(day1,month1,year1)+(double)TimeToJD(hour1,min1,sec1);
  94.    #ifndef __cplusplus
  95.      HeisDiffDate(day1,month1,year1,500,&day2,&month2,&year2);
  96.    #else
  97.      HeisDiffDate(day1,month1,year1,500,day2,month2,year2);
  98.    #endif
  99.    hour2 = hour1;
  100.    min2 = min1;
  101.    sec2 = sec1;
  102.    /* DiffTime(hour1,min1,sec1,+6,+30,+30,&hour2,&min2,&sec2); */
  103.    jd2 = (double)HeisToJD(day2,month2,year2)+(double)TimeToJD(hour2,min2,sec2);
  104.    do
  105.     {
  106.      printf("----------------------------------------------------------------\n");
  107.      printf("01 : TextEngine                | 02 : TextEngineJD\n");
  108.      printf("00 : Quit\n");
  109.      printf("It's your turn: ");
  110.      scanf("%u",&input);
  111.      getc(stdin);
  112.      printf("----------------------------------------------------------------\n");
  113.      do
  114.       {
  115.        if (input != 0)
  116.         {
  117.          printf("%%%%         : %%\n");
  118.          printf("%%+DTj      : JD.JD  date+time\n");
  119.          printf("%%+DTJ      : MJD.JD date+time\n");
  120.          printf("%%D1[2][3]  1 : d-day/m-month/M-month text/y-year/w-weekday/\n");
  121.          printf("               W-week/s-scaliger year/j-JD/J-MJD\n");
  122.          printf("           2 : v-variablen length/f-fixed length/s-short text/\n");
  123.          printf("               l-long text\n");
  124.          printf("           3 : 2-short year/4-full year\n");
  125.          printf("%%T1[2]     1 : h-24h hour/H-12h hour/M-am|pm/m-minute/s-second/\n");
  126.          printf("               j-jd time\n");
  127.          printf("           2 : v-variable length/f-fixed length\n");
  128.          printf("%%AD1       1 : d-difference in days/y-difference in years\n");
  129.          printf("%%AT1       1 : h-full hours/m-full minutes/s-full seconds/\n");
  130.          printf("               H-all in hours/M-all in minutes/S-all in seconds/\n");
  131.          printf("               j-as JD difference\n");
  132.          printf("%%S1        1 : number of array string\n");
  133.          printf("----------------------------------------------------------------\n");
  134.         }
  135.        switch (input)
  136.         {
  137.          case  0 : break;
  138.          case  1 : str = readstring();
  139.                    strarr = readstrarr();
  140.                    TextEngine(str,day1,month1,year1,hour1,min1,sec1,readlanguage(),day2,month2,year2,hour2,min2,sec2,strarr);
  141.                    printf("%s\n",str);
  142.                    free(str);
  143.                    for (i=0;strarr[i]!=NULL;i++)
  144.                      free(strarr[i]);
  145.                    free(strarr);
  146.                break;
  147.          case  2 : str = readstring();
  148.                    strarr = readstrarr();
  149.                    #ifndef __cplusplus
  150.              TextEngineJD(str,jd1,readlanguage(),jd2,strarr);
  151.            #else
  152.              TextEngine(str,jd1,readlanguage(),jd2,strarr);
  153.            #endif
  154.            printf("%s\n",str);
  155.            free(str);
  156.            for (i=0;strarr[i]!=NULL;i++)
  157.              free(strarr[i]);
  158.            free(strarr);
  159.                    break;
  160.          default : printf("Wong number! Try again!\n");
  161.         }
  162.        if (input > 0)
  163.         {
  164.          printf("0 : Menu; >0 : test again - ");
  165.          scanf("%u",&repeat);
  166.          getc(stdin);
  167.         }
  168.        else
  169.          repeat = 0;
  170.       }
  171.      while (repeat != 0);
  172.     }
  173.    while (input != 0);
  174.    #ifndef __SASC_650
  175.      _DateCleanup();
  176.    #endif
  177.   }
  178.