Example #1
0
time_t p_mktime (struct tm *timeptr) {
  time_t tt;

  if ((timeptr->tm_year < 70) || (timeptr->tm_year > 120)) {
    tt = (time_t)-1;
  } else {
    tt = ymd_to_scalar(timeptr->tm_year + 1900,
                       timeptr->tm_mon + 1,
                       timeptr->tm_mday)
      - ymd_to_scalar(1970, 1, 1);
    tt = tt * 24 + timeptr->tm_hour;
    tt = tt * 60 + timeptr->tm_min;
    tt = tt * 60 + timeptr->tm_sec;
  }
  return tt;
}
Example #2
0
long
string_to_scalar(char *d)
{
    char date[9];
    unsigned year,month,day;
    memcpy(date,d,9);
    day=atoi(date+6);
    date[6]=0;
    month=atoi(date+4);
    date[4]=0;
    year=atoi(date);
    return ymd_to_scalar(year,month,day);
}
Example #3
0
int main(int argc, char *argv[])
{
      int day, day_1, numdays, i, j;
      unsigned yr, mo;

      if (3 > argc)
            usage();

      yr = atoi(argv[2]);
      mo = atoi(argv[1]);

      if (!mo || 12 < mo)
            usage();

      if (100 > yr)
            yr += 1900;

      if (3000 < yr || 1800 > yr)
            usage();

      for (i = 0, mo -= 1; i < 3; ++i, ++mo)
      {
            if (!mo)
            {
                  mo = 12;
                  --yr;
            }
            if (12 < mo)
            {
                  mo = 1;
                  ++yr;
            }
            numdays = days[mo - 1];
            if (2 == mo && isleap(yr))
                  ++numdays;
            day_1 = (int)((ymd_to_scalar(yr, mo, 1) - (long)ISO) % 7L);

#ifdef MSDOS
            if (!i)
                  puts(topborder);
#endif
            fputs(line, stdout);
            for (j = 0; j < 7; )
            {
                  fputs(daynames[ISO + j], stdout);
                  if (7 != ++j)
                        fputc(' ', stdout);
            }
            printf("%s < %s, %d\n%s", line, month[mo - 1], yr, line);

            for (day = 0; day < day_1; ++day)
                  fputs("    ", stdout);
            for (day = 1; day <= numdays; ++day, ++day_1, day_1 %= 7)
            {
                  if (!day_1 && 1 != day)
                        printf("\b%s\n%s", line, line);
                  printf("%3d ", day);
            }
            for ( ; day_1; ++day_1, day_1 %= 7)
                  fputs("    ", stdout);
#ifdef MSDOS
            printf("\b%s\n", line);
            if (2 > i)
                  puts(midborder);
            else  puts(botborder);
#else
            fputc('\n', stdout);
#endif
      }
      return 0;
}
Example #4
0
/*--------------------------------------------------------------------------*/
int sci_calendar(char *fname, unsigned long fname_len)
{
    static int l1, n1, m1;

    int month = 0;
    int year = 0;
    int day, day_1, numdays, i;
    int a = 0;

    int *CALMONTH = NULL;
    int *tmpMatrix = NULL;

    Rhs = Max(0, Rhs);
    CheckRhs(2, 2);
    CheckLhs(1, 1);

    if ( IsAScalar(Rhs - 1) && IsAScalar(Rhs) )
    {
        GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1);
        year = *istk(l1);

        GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1);
        month = *istk(l1);

        if ( (year < 1800) || (year > 3000) )
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"), fname, 2, 1800, 3000);
            return 0;
        }

        if ( (month < 1) || (month > 12) )
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: Must be between %d and %d.\n"), fname, 1, 1, 12);
            return 0;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input arguments: Scalar values expected.\n"), fname);
        return 0;
    }
    CALMONTH = (int *)MALLOC( (NBRDAY * NBRWEEK) * sizeof(int) );
    for (i = 0; i < NBRDAY * NBRWEEK; i++)
    {
        CALMONTH[i] = 0;
    }

    /* check if the month of feb is 28 or 29 days */
    numdays = days[month - 1];
    if (2 == month && isBissextile(year))
    {
        ++numdays;
    }

    /* Starts the calendar on monday */
    day_1 = (int)((ymd_to_scalar(year, month, 1) - (long)1) % 7L);

    for (day = 0; day < day_1; ++day)
    {
        a++;
    }

    /* Browse all the days */
    for (day = 1; day <= numdays; ++day, ++day_1, day_1 %= 7)
    {
        CALMONTH[a] = day;
        a++;
    }
    m1 = NBRWEEK;
    n1 = NBRDAY;
    tmpMatrix = CALMONTH;

    CALMONTH = transposeMatrixInt(NBRDAY, NBRWEEK, CALMONTH);
    if (tmpMatrix)
    {
        FREE(tmpMatrix);
        tmpMatrix = NULL;
    }

    CreateVarFromPtr(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1 , &CALMONTH);
    LhsVar(1) = Rhs + 1;

    if (CALMONTH)
    {
        FREE(CALMONTH);
        CALMONTH = NULL;
    }

    PutLhsVar();
    return 0;
}
Example #5
0
File: ct_msg.c Project: Lopo/Lotos
/*** Display the reminders a user has to them
     login is used to show information at the login prompt, otherwise user
     is just using the .reminder command.  stage is used for inputting of a new reminder
     ***/
void show_reminders(UR_OBJECT user, int stage)
{
	char temp[ARR_SIZE];
	int i,j,d,m,y,cnt_total=0,cnt_today=0,del,done;

	set_crash();
/* display manually */
if (!stage) {
  if (word_count<2) {
    write_user(user, "~OLNa prezretie:\n");
    write_user(user, "       reminder all\n       reminder today\n       reminder <d> [<m> [<y>]]\n");
    write_user(user, "~OLNa upravu:\n");
    write_user(user, "       reminder set\n       reminder del <number>\n");
    return;
    }
  /* display all the reminders a user has set */
  cnt_total=0;
  if (!strcasecmp("all",word[1])) {
    write_user(user, ascii_tline);
    write_user(user,"~CT| All your reminders                                                           |\n");
    write_user(user, ascii_line);
    for (i=0;i<MAX_REMINDERS;i++) {
      /* no msg set, then no reminder */
      if (!user->reminder[i].msg[0]) continue;
      vwrite_user(user,"~OL%2d) ~FT%d%s %s, %d~RS - (%d/%d/%d)\n",++cnt_total,user->reminder[i].day,ordinal_text(user->reminder[i].day),
	      month[user->reminder[i].month-1],user->reminder[i].year,user->reminder[i].day,user->reminder[i].month,user->reminder[i].year);
      vwrite_user(user,"    %s\n",user->reminder[i].msg);
      }
    if (!cnt_total) write_user(user,"You do not have reminders set.\n");
    write_user(user, ascii_bline);
    return;
    }
  /* display all the reminders a user has for today */
  if (!strcasecmp("today",word[1])) {
    d=tmday;
    m=tmonth+1;
    y=tyear;
    cnt_today=0;
    write_user(user, ascii_tline);
    write_user(user,"~CT| Your reminders for today are                                                 |\n");
    write_user(user, ascii_line);
    for (i=0,j=0;i<MAX_REMINDERS;i++) {
      if (user->reminder[i].day==d && user->reminder[i].month==m && user->reminder[i].year==y) {
	vwrite_user(user,"~OL%2d)~RS %s\n",++j,user->reminder[i].msg);
	cnt_today++;
        }
      }
    if (!cnt_today) write_user(user,"You do not have reminders set for today.\n");
    write_user(user, ascii_bline);
    return;
    }
  /* allow a user to set a reminder */
  if (!strcasecmp("set",word[1])) {
    cnt_total=0;
    /* check to see if there is enough space to add another reminder */
    for (i=0;i<MAX_REMINDERS;i++) if (!user->reminder[i].msg[0]) cnt_total++;
    if (!cnt_total) {
      write_user(user,"You already have the maximum amount of reminders set.\n");
      return;
      }
    user->temp_remind.day=0;
    user->temp_remind.month=0;
    user->temp_remind.year=0;
    user->temp_remind.msg[0]='\0';
    write_user(user,"Please enter a date for the reminder (1-31): ");
    user->misc_op=20;
    return;
    }
  /* allow a user to delete one of their reminders */
  if (!strcasecmp("del",word[1])) {
    if (word_count<3) {
      write_usage(user,"reminder del <cislo>");
      write_user(user,"   kde <cislo> moze byt prebrate z 'reminder all'");
      return;
      }
    del=atoi(word[2]);
    cnt_total=0;  done=0;
    for (i=0;i<MAX_REMINDERS;i++) {
      if (!user->reminder[i].msg[0]) continue;
      cnt_total++;
      if (cnt_total==del) {
	user->reminder[i].day=0;
	user->reminder[i].month=0;
	user->reminder[i].year=0;
	user->reminder[i].msg[0]='\0';
	done=1;  break;
        }
      }
    if (!done) {
      vwrite_user(user,"Sorry, could not delete reminder number ~OL%d~RS.\n",del);
      return;
      }
    vwrite_user(user,"You have now deleted reminder number ~OL%d~RS.\n",del);
    write_user_reminders(user);
    return;
    }
  /* view reminders for a particular day */
  if (word_count>4) {
    write_usage(user,"reminder <d> [<m> [<y>]]");
    write_user(user,"   kde <d> = den od 1 po 31\n");
    write_user(user,"       <m> = mesiac od 1 po 12\n");
    write_user(user,"       <y> = rok od 1 po 99, alebo 1800 az 3000\n");
    return;
    }
  /* full date given */
  if (word_count==4) {
    y=atoi(word[3]);
    m=atoi(word[2]);
    d=atoi(word[1]);
    /* assume that year give xx is y2k if xx!=99 */
    if (y==99) y+=1900;
    else if (y<99) y+=2000;
    if ((y>3000) || (y<1800) || !m || (m>12) || !d || (d>31)) {
      write_usage(user,"reminder <d> [<m> [<y>]]");
      write_user(user,"   kde <d> = den od 1 po 31\n");
      write_user(user,"       <m> = mesiac od 1 po 12\n");
      write_user(user,"       <y> = rok od 1 po 99, alebo 1800 az 3000\n");
      return;
      }
    }
  /* only date and month given, so show for this year */
  else if (word_count==3) {
    y=tyear;
    m=atoi(word[2]);
    d=atoi(word[1]);
    if (!m || (m>12) || !d || (d>31)) {
      write_usage(user,"reminder <d> [<m> [<y>]]");
      write_user(user,"   kde <d> = den od 1 po 31\n");
      write_user(user,"       <m> = mesiac od 1 po 12\n");
      write_user(user,"       <y> = rok od 1 po 99, alebo 1800 az 3000\n");
      return;
      }
    }
  /* only date given, so show for this month and year */
  else {
    y=tyear;
    m=tmonth+1;
    d=atoi(word[1]);
    if (!d || (d>31)) {
      write_usage(user,"reminder <d> [<m> [<y>]]");
      write_user(user,"   kde <d> = den od 1 po 31\n");
      write_user(user,"       <m> = mesiac od 1 po 12\n");
      write_user(user,"       <y> = rok od 1 po 99, alebo 1800 az 3000\n");
      return;
      }
    }
  write_user(user, ascii_line);
  sprintf(temp, "Your reminders for %d%s %s, %d", d, ordinal_text(d), month[m-1], y);
  vwrite_user(user,"~CT| %-76.76s |\n", temp);
  write_user(user, ascii_line);
  cnt_today=0;
  for (i=0;i<MAX_REMINDERS;i++) {
    if (user->reminder[i].day==d && user->reminder[i].month==m && user->reminder[i].year==y) {
      vwrite_user(user,"~OL%2d)~RS %s\n",i+1,user->reminder[i].msg);
      cnt_today++;
      }
    }
  if (!cnt_today) vwrite_user(user,"You have no reminders set for %d%s %s, %d\n",d,ordinal_text(d),month[m-1],y);
  write_user(user, ascii_bline);
  return;
  }

/* next stages of asking for a new reminder */
switch(stage) {
  case 1:
    if (!user->temp_remind.day || user->temp_remind.day>31) {
      write_user(user,"The day for the reminder must be between 1 and 31.\n");
      user->temp_remind.day=0;
      user->misc_op=0;
      return;
      }
    write_user(user,"Please enter a month (1-12): ");
    user->misc_op=21;
    return;
  case 2:
    if (!user->temp_remind.month || user->temp_remind.month>12) {
      write_user(user,"The month for the reminder must be between 1 and 12.\n");
      user->temp_remind.day=0;
      user->temp_remind.month=0;
      user->misc_op=0;
      return;
      }
    write_user(user,"Please enter a year (xx or 19xx or 20xx, etc, <return> for this year): ");
    user->misc_op=22;
    return;
  case 3:
    /* assume that year give xx is y2k if xx!=99 */
    if (user->temp_remind.year==99) user->temp_remind.year+=1900;
    else if (user->temp_remind.year<99) user->temp_remind.year+=2000;
    if ((user->temp_remind.year>3000) || (user->temp_remind.year<1800)) {
      write_user(user,"The year for the reminder must be between 1-99 or 1800-3000.\n");
      user->temp_remind.day=0;
      user->temp_remind.month=0;
      user->temp_remind.year=0;
      user->misc_op=0;
      return;
      }
    /* check to see if date has past - why put in a remind for a date that has? */
    if ((int)(ymd_to_scalar(user->temp_remind.year,user->temp_remind.month,user->temp_remind.day)) < (int)(ymd_to_scalar(tyear,tmonth+1,tmday))) {
      write_user(user,"That date has already passed so there's no point setting a reminder for it.\n");
      user->temp_remind.day=0;
      user->temp_remind.month=0;
      user->temp_remind.year=0;
      user->misc_op=0;
      return;
      }
    write_user(user,"Please enter reminder message:\n~FG>>~RS");
    user->misc_op=23;
    return;
  case 4:
    /* tell them they MUST enter a message */
    if (!user->temp_remind.msg[0]) {
      write_user(user,"Please enter reminder message:\n~FG>>~RS");
      user->misc_op=23;
      return;
      }
    /* add in first available slot */
    for (i=0;i<MAX_REMINDERS;i++) {
      if (!user->reminder[i].msg[0]) {
	user->reminder[i].day=user->temp_remind.day;
	user->reminder[i].month=user->temp_remind.month;
	user->reminder[i].year=user->temp_remind.year;
	strcpy(user->reminder[i].msg,user->temp_remind.msg);
	break;
        }
      }
    write_user(user,"You have set the following reminder:\n");
    vwrite_user(user,"(%d/%d/%d) %s\n\n",user->reminder[i].day,user->reminder[i].month,user->reminder[i].year,user->reminder[i].msg);
    write_user_reminders(user);
    user->misc_op=0;
    return;
  }
}