home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / utility / disk / maxid_22 / set_time.c < prev    next >
C/C++ Source or Header  |  1992-01-28  |  3KB  |  152 lines

  1. /* 15.11.86  Max Böhm */
  2.  
  3. #include <osbind.h>
  4.  
  5. read_str (str, len)      /* str[] muss len+1 Elemente haben */
  6. char str[];
  7. int len;
  8. {
  9. long c;
  10. int scan,ascii,i;
  11.    i=0;
  12.    do
  13.    {  c=Crawcin ();
  14.       ascii=c;
  15.       scan=c>>16;
  16.       if ((scan==14||scan==75)&&i)      /* Backspace */
  17.       {  Cconws ("\10 \10");
  18.          i--;
  19.       }
  20.       if (i<len&&ascii>=32&&ascii!=127&&(scan<58||scan==74||scan==78||scan>98))
  21.       {  Cconout (ascii);
  22.          str[i++]=ascii;
  23.       }
  24.    }
  25.    while (scan!=28&&scan!=114);      /* nicht Return */
  26.    Cconws ("\r\n");
  27.    str[i]=0;
  28.    return (i);
  29. }
  30.  
  31. get_date (day, month, year)
  32. int *day, *month, *year;
  33. {
  34. unsigned int date;
  35.    date=Tgetdate ();
  36.    *day=date&31;
  37.    *month=date>>5&15;
  38.    *year=(date>>9)+80;
  39. }
  40.  
  41. set_date (day, month, year)
  42. int day, month, year;
  43. {
  44.    Tsetdate (day+(month<<5)+((year-80)<<9));
  45. }
  46.  
  47. get_time (hour, minute, second)
  48. int *hour, *minute, *second;
  49. {
  50. unsigned int time;
  51.    time=Tgettime ();
  52.    *second=2*(time&31);
  53.    *minute=time>>5&63;
  54.    *hour=time>>11;
  55. }
  56.  
  57. set_time (hour, minute, second)
  58. int hour, minute, second;
  59. {
  60.    Tsettime (second/2+(minute<<5)+(hour<<11));
  61. }
  62.  
  63. atoi (str_pt, n, num)
  64. char **str_pt;
  65. int n, *num;
  66. {
  67. char ch;
  68.    do
  69.    {  if (!(ch=**str_pt))
  70.          return;
  71.       (*str_pt)++;
  72.    }
  73.    while (ch<'0'||ch>'9');
  74.    *num=ch-'0';
  75.    while (--n&&(ch=**str_pt)>='0'&&ch<='9')
  76.    {  *num=10 * *num + ch-'0';
  77.       (*str_pt)++;
  78.    }
  79. }
  80.  
  81. itoa_2 (str, num)
  82. char *str;
  83. int num;
  84. {
  85.    str[0]=(num/10)%10 + '0';
  86.    str[1]=num%10 + '0';
  87. }
  88.  
  89. set_num (str, a, b, c)
  90. char *str;
  91. int *a, *b, *c;
  92. {
  93.    atoi (&str, 2, a);
  94.    atoi (&str, 2, b);
  95.    atoi (&str, 0, c);
  96.    *c%=100;
  97. }
  98.  
  99. set_str (str, a, b, c, ch)
  100. char *str, ch;
  101. int a, b, c;
  102. {
  103.    itoa_2 (str, a);
  104.    itoa_2 (str+3, b);
  105.    itoa_2 (str+6, c);
  106.    str[2]=str[5]=ch;
  107.    str[8]=0;
  108. }
  109.  
  110. put_date (str)
  111. char *str;
  112. {
  113. int day, month, year;
  114.    get_date (&day, &month, &year);
  115.    set_num (str, &day, &month, &year);
  116.    set_date (day, month, year);
  117.    get_date (&day, &month, &year);
  118.    set_str (str, day, month, year, '/');
  119. }
  120.  
  121. put_time (str)
  122. char *str;
  123. {
  124. int hour, minute, second;
  125.    get_time (&hour, &minute, &second);
  126.    second=0;
  127.    set_num (str, &hour, &minute, &second);
  128.    set_time (hour, minute, second);
  129.    get_time (&hour, &minute, &second);
  130.    set_str (str, hour, minute, second, ':');
  131. }
  132.  
  133.  
  134. main ()
  135. {
  136. char str[9];
  137. unsigned int date, time;
  138.    Cconws ("\33eDatum: ");
  139.    read_str (str, 8);
  140.    put_date (str);
  141.    Cconws ("\33IDatum: ");
  142.    puts (str);
  143.    Cconws ("Zeit : ");
  144.    read_str (str, 8);
  145.    put_time (str);
  146.    Cconws ("\33IZeit : ");
  147.    puts (str);
  148.    date=Tgetdate ();
  149.    time=Tgettime ();
  150.    Settime(((long)date<<16) + time);
  151. }
  152.