void main (void) { struct time dostime; struct date dosdate; time_t unix_format; struct tm *local; getdate(&dosdate); gettime(&dostime); unix_format = dostounix(&dosdate, &dostime); local = localtime(&unix_format); printf("UNIX time: %s\n", asctime(local)); }
int main (void) { struct date d; struct time t; time_t now = time (NULL); getdate (&d); gettime (&t); printf ("time now is: %s", ctime(&now)); now = dostounix (&d, &t); printf ("dostounix(): %s", ctime(&now)); printf ("unixtodos(): %02d/%02d/%04d %02d:%02d:%02d\n", d.da_day, d.da_mon, d.da_year, t.ti_hour, t.ti_min, t.ti_sec); return (0); }
void _FARFUNC ftime(struct timeb _FAR *TimeStructPtr) { struct date DosDate, Vdate; struct time DosTime; tzset(); /* Get timezone info. */ /* Because there is a window of vulnerability at exactly midnight when calling getdate(INT 21 fn 2A) and gettime(INT 21 fn 2C) in succession, we do 2 calls to getdate() to ensure we aren't in this window. */ do { getdate(&DosDate); gettime(&DosTime); getdate(&Vdate); } while ( (DosDate.da_year != Vdate.da_year) || (DosDate.da_day != Vdate.da_day) || (DosDate.da_mon != Vdate.da_mon) ); /* Convert extern 'timezone's seconds to structure 'timezone's minutes. Set daylight savings indicator. Convert DOS date and time to UNIX style time and store in structure. Set milliseconds structure field. DOS is only accurate to 100ths of a second so (100ths * 10) makes 1000ths. */ #if defined(_RTLDLL) TimeStructPtr->_timezone = (short)(timezone / 60L); #else TimeStructPtr->timezone = (short)(timezone / 60L); #endif if (daylight && __isDST( DosTime.ti_hour, DosDate.da_day, DosDate.da_mon, DosDate.da_year-1970) ) TimeStructPtr->dstflag = 1; else TimeStructPtr->dstflag = 0; TimeStructPtr->time = dostounix(&DosDate, &DosTime); TimeStructPtr->millitm = DosTime.ti_hund * 10; }
void TERMWINDOWMEMBER cron_commands(void) { int ich; SetDoWhat(SYSCRON); switch (toupper(ich = iCharNE())) { case 'A': { mPrintfCR(getsysmsg(68)); if (WAITFORmTIMED(CronMutex)) { CronEventListS *theEvent; for (int i = 1; (theEvent = Cron.GetEventNum(i)) != NULL; i++) { theEvent->Event.SetDone(); } RELEASEm(CronMutex); CRmPrintfCR(getsysmsg(69)); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'D': { mPrintfCR(getsysmsg(70)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->SetDone(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'E': { mPrintfCR(getsysmsg(71)); if (WAITFORmTIMED(CronMutex)) { Cron.ReadCronCit(WC_TWp); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'F': { mPrintfCR(getsysmsg(72)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->Do(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'L': { mPrintfCR(getsysmsg(73)); if (WAITFORmTIMED(CronMutex)) { ListAllEvents(); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'N': { mPrintfCR(getsysmsg(74)); if (WAITFORmTIMED(CronMutex)) { Cron.SetOnEvent(GetEventFromUser()); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'P': { Cron.TogglePause(); displayOnOff(getsysmsg(75), Cron.IsPaused()); doCR(); break; } case 'R': { mPrintfCR(getsysmsg(76)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->Reset(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'S': { mPrintfCR(getsysmsg(268)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { Bool First = TRUE; struct date dt; struct time tm; datestruct ds; timestruct ts; do { if (!HaveConnectionToUser()) { RELEASEm(CronMutex); return; } if (!First) { mPrintfCR(getmsg(156)); } First = FALSE; label usrIn; if (!GetStringWithBlurb(getmsg(266), usrIn, LABELSIZE, ns, B_DATESET)) { RELEASEm(CronMutex); return; } gdate(usrIn, &ds); } while (!ds.Date); First = TRUE; do { if (!HaveConnectionToUser()) { RELEASEm(CronMutex); return; } if (!First) { mPrintfCR(getmsg(121)); } First = FALSE; label usrIn; if (!GetStringWithBlurb(getmsg(230), usrIn, LABELSIZE, ns, B_TIMESET)) { RELEASEm(CronMutex); return; } gtime(usrIn, &ts); } while (ts.Hour < 0); tm.ti_min = (uchar) ts.Minute; tm.ti_hour = (uchar) ts.Hour; tm.ti_sec = (uchar) ts.Second; dt.da_year = ds.Year + 1900; // i hate dostounix dt.da_day = (char) ds.Date; dt.da_mon = (char) (ds.Month + 1); // i hate dostounix time_t tried = dostounix(&dt, &tm); theEvent->SetLastSuccess(tried); theEvent->SetLastTried(tried); label dtstr; strftime(dtstr, LABELSIZE, getmsg(435), tried); CRmPrintf(getmsg(598), dtstr); strftime(dtstr, LABELSIZE, getmsg(434), tried); CRmPrintfCR(getmsg(607), dtstr); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'Z': { mPrintfCR(getsysmsg(77)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->ToggleZap(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case '?': { oChar('?'); showMenu(M_CRON); break; } default: { BadMenuSelection(ich); break; } } }
//analyza PPP logu -> ziskani IP adresy //!!JdS: 2003/12/7 { // Rewritten so that 'ppplogtime' can also be initialized when // using BOOTP via a dial-up connection. See also ArachneTCPIP(). //!!JdS: 2003/12/7 } int PPPlog(void) { int f,i,j; char *p; struct ftime ft; struct time d_time; struct date d_date; f=sopen("PPP.LOG",O_RDONLY|O_TEXT,SH_COMPAT, S_IREAD); if (f>=0) { if (ipmode==MODE_PPP) { long l=a_filelength(f); int plen; char buf[LOGLEN]; if (l>LOGLEN) l=LOGLEN; lseek(f,-l,SEEK_END); i=read(f,buf,(int)l); buf[i]='\0'; //puts(buf); j=0; p=configvariable(&ARACHNEcfg,"IP_Grab",NULL); if (!p) p="IP address set to"; plen=strlen(p); while(j<i) { if (!strncmp(&buf[j],p,plen)) { char tecka=0; p=strchr(&buf[j],'\n'); if (p) *p='\0'; outs(&buf[j]); i=0; j+=plen; while(buf[j]==' ')j++; while(i<19 && (buf[j+i]>='0' && buf[j+i]<='9' || buf[j+i]=='.' && tecka<3)) { myIPstr[i]=buf[j+i]; if (myIPstr[i]=='.') tecka++; i++; } myIPstr[i]='\0'; my_ip_addr = resolve(myIPstr); break; } j++; } } //determine time online: if (my_ip_addr || ipmode==MODE_BOOTP) { getftime(f, &ft); d_date.da_year=ft.ft_year+1980; /* current year */ d_date.da_day=ft.ft_day; /* day of the month */ d_date.da_mon=ft.ft_month; /* month (1 = Jan) */ d_time.ti_min=ft.ft_min; /* minutes */ d_time.ti_hour=ft.ft_hour; /* hours */ d_time.ti_hund=0; /* hundredths of seconds */ d_time.ti_sec=ft.ft_tsec*2; /* seconds */ //ppplogtime is by default zero... ppplogtime = dostounix(&d_date, &d_time); } close(f); return(my_ip_addr || ipmode==MODE_BOOTP); } //puts(MSG_NOIP); return(0); }
void send_email2(void) { char s[81],scratch[81],log[81]; int f, i; long len,len2; char *b; long thetime,dat; int len3; mailrec m,m1; userrec ur; messagerec msg; struct date dt; struct time tm; char *month[] = {"Bug","Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"}; m.touser=user_to_num; time(&thetime); len=(unsigned) strlen(buffer); len2=len; b=((char *)malloc(len+1024)); len=0; sprintf(log,"þ Incoming mail for %s from %s (%s)\n",fido_to_user,fido_from_user,origi_node); write_log(log); sprintf(s,"%s (%s)",fido_from_user,origi_node); addline(b,s,&len); /* Get date/time of Email creation. */ /* Ditto the \015 for the time/date string. */ strncpy(scratch,fido_date_line,20); scratch[20]='\0'; /* Build the date - cumbersome, but it needs to be done */ /* Build tblock as we go along so we can have a pretty date */ scratch[2] = '\0'; /* make day a string */ dt.da_day = atoi(scratch); for (i=1;i<13;i++) if (strncmpi(month[i],&scratch[3],3) == 0) { dt.da_mon = i; break; } scratch[9] = '\0'; /* make year a string */ dt.da_year = atoi(&scratch[7]); if (dt.da_year>90) dt.da_year += 1900; else dt.da_year += 2000; scratch[13] = '\0'; /* make hour a string */ tm.ti_hour = atoi(&scratch[11]); scratch[16] = '\0'; /* make minute a string */ tm.ti_min = atoi(&scratch[14]); scratch[19] = '\0'; /* make second a string */ tm.ti_sec = atoi(&scratch[17]); tm.ti_hund = 0; dat = dostounix(&dt,&tm); strncpy(scratch,ctime(&(time_t)dat),24); scratch[24]='\0'; strcat(scratch,"\r\n"); strcpy(s,scratch); addline(b,s,&len); strcat(b,buffer); len += len2; len=(unsigned) strlen(b); if (b[len-1]!=26) b[len++]=26; m.msg.storage_type=2; msg.stored_as=0L; msg.storage_type=2; savefile(b,len,&msg,"EMAIL"); m.msg=msg; i=0; strcpy(m.title,fido_title); // i=strlen(m.title); // m.title[i+1]=net_num; // m.title[i+2]=0; m.title[80]=net_num; m.title[81]=0; // i=0; read_user(user_to_num,&ur); ++ur.waiting; write_user(user_to_num,&ur); lock_status(); save_status(); m.anony=i; m.fromsys=atoi(wwiv_node); m.fromuser=0; m.tosys=0; m.status=status_new_net; time((long *)&(m.daten)); f=open_email(1); len3=(int) filelength(f)/sizeof(mailrec); if (len3==0) i=0; else { i=len3-1; sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET); sh_read(f,(void *)&m1,sizeof(mailrec)); while ((i>0) && (m1.tosys==0) && (m1.touser==0)) { --i; sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET); sh_read(f,(void *)&m1,sizeof(mailrec)); } if ((m1.tosys) || (m1.touser)) ++i; } sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET); sh_write(f,(void *)&m,sizeof(mailrec)); sh_close(f); free(buffer); }
time_t _Cdecl mktime(struct tm * tm) { struct tm tmp; int temp; int days; time_t gmt_seconds; struct date date; struct time time; tzset(); if( tm->tm_sec < 0 || tm->tm_min < 0 || tm->tm_hour < 0 || tm->tm_mday < 0 || tm->tm_mon < 0 || tm->tm_year < 0 ) return(-1); tmp = *tm; temp = tmp.tm_mon % 12; tmp.tm_year += tmp.tm_mon / 12 + 1900; tmp.tm_mon = temp; if(tmp.tm_year < 0) return(-1); temp = tmp.tm_sec % 60; tmp.tm_min += tmp.tm_sec / 60; tmp.tm_sec = temp; if(tmp.tm_min < 0) return(-1); temp = tmp.tm_min % 60; tmp.tm_hour += tmp.tm_min / 60; tmp.tm_min = temp; if(tmp.tm_hour < 0) return(-1); temp = tmp.tm_hour % 24; tmp.tm_mday += tmp.tm_hour / 24; tmp.tm_hour = temp; if(tmp.tm_mday < 0) return(-1); while(tmp.tm_mday > (days = day_tab[isleap(tmp.tm_year)][tmp.tm_mon])) { tmp.tm_mday -= days; tmp.tm_mon++; if(tmp.tm_mon > 11) { tmp.tm_mon = 0; if(++tmp.tm_year < -1) return(-1); } } if(tmp.tm_year < 1980) return(-1); time.ti_hour = tmp.tm_hour; time.ti_min = tmp.tm_min; time.ti_sec = tmp.tm_sec; time.ti_hund = 0; date.da_year = tmp.tm_year; date.da_mon = tmp.tm_mon + 1; date.da_day = tmp.tm_mday; gmt_seconds = dostounix(&date, &time); memcpy( tm, localtime(&gmt_seconds), sizeof( struct tm ) ); return(gmt_seconds); }
/*-------------------------------------------------------------------------*/ int main(int argc, const char **argv) { int fileargc, switchargc; char *fileargv[255], *switchargv[255], env_prompt[MAXSWITCH], tmp_switch[MAXSWITCH] = "", src_pathname[MYMAXPATH] = "", src_filename[MAXFILE + MAXEXT] = "", dest_pathname[MYMAXPATH] = "", dest_filename[MAXFILE + MAXEXT] = "", *ptr, ch; int i, length; THEDATE dt; #ifdef __WATCOMC__ struct dostime_t tm; #else struct time tm; #endif cat = catopen ("xcopy", 0); /* initialize kitten */ classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv); if (fileargc < 1 || switchargv[0] == "?") { print_help(); catclose(cat); exit(4); } if (fileargc > 2) { printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters")); catclose(cat); exit(4); } /* activate termination function */ /* (writes no. of copied files at exit) */ atexit(exit_fn); /* read environment variable COPYCMD to set confirmation switch */ strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt)); if (env_prompt[0] != '\0') { strupr(env_prompt); if (strcmp(env_prompt, "/Y") == 0) /* overwrite existing file(s) */ switch_confirm = 0; else if (strcmp(env_prompt, "/N") == 0) /* skip existing file(s) */ switch_confirm = 1; else /* ask for confirmation */ switch_confirm = 2; } /* get switches */ for (i = 0; i < switchargc; i++) { strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch)); strupr(tmp_switch); if (strcmp(tmp_switch, "A") == 0) switch_archive = -1; else if (strcmp(tmp_switch, "C") == 0) switch_continue = -1; else if (strcmp(tmp_switch, "D") == 0) switch_date = -1; else if (strncmp(tmp_switch, "D:", 2) == 0) { if (strtodate(tmp_switch+2, &dt) != 0 || !datevalid(&dt)) { printf("%s\n",catgets(cat, 1, 2, "Invalid date")); catclose(cat); exit(4); } #ifdef __WATCOMC__ memset((void *)&tm, 0, sizeof(struct dostime_t)); /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */ #else memset((void *)&tm, 0, sizeof(struct time)); /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */ #endif switch_date = dostounix(&dt, &tm); } else if (strcmp(tmp_switch, "E") == 0) switch_emptydir = -1; else if (strcmp(tmp_switch, "F") == 0) switch_fullnames = -1; else if (strcmp(tmp_switch, "H") == 0) switch_hidden = -1; else if (strcmp(tmp_switch, "I") == 0) switch_intodir = -1; else if (strcmp(tmp_switch, "L") == 0) switch_listmode = -1; else if (strcmp(tmp_switch, "M") == 0) switch_archive_reset = -1; else if (strcmp(tmp_switch, "N") == 0) switch_confirm = 1; else if (strcmp(tmp_switch, "P") == 0) switch_prompt = -1; else if (strcmp(tmp_switch, "Q") == 0) switch_quiet = -1; else if (strcmp(tmp_switch, "R") == 0) switch_readonly = -1; else if (strcmp(tmp_switch, "S") == 0) switch_subdir = -1; else if (strcmp(tmp_switch, "T") == 0) switch_tree = -1; else if (strcmp(tmp_switch, "V") == 0) { switch_verify = -1; bak_verify = getverify(); setverify(1); } else if (strcmp(tmp_switch, "W") == 0) switch_wait = -1; else if (strcmp(tmp_switch, "Y") == 0) switch_confirm = 0; else if (strcmp(tmp_switch, "-Y") == 0) switch_confirm = 2; else { printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]); catclose(cat); exit(4); } } /* get source pathname (with trailing backspace) and filename/-pattern */ length = strlen(fileargv[0]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 4, "Source path too long")); catclose(cat); exit(4); } _fullpath(src_pathname, fileargv[0], MYMAXPATH); if (src_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification")); catclose(cat); exit(4); } /* check source path */ if (!dir_exists(src_pathname)) { /* source path contains a filename/-pattern -> separate it */ ptr = strrchr(src_pathname, *DIR_SEPARATOR); ptr++; strmcpy(src_filename, ptr, sizeof(src_filename)); *ptr = '\0'; if (!dir_exists(src_pathname)) { printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname); catclose(cat); exit(4); } } else { /* source is a directory -> filepattern = "*.*" */ strmcpy(src_filename, "*.*", sizeof(src_filename)); } cat_separator(src_pathname); length = strlen(src_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n", catgets(cat, 1, 7, "Source path too long")); catclose(cat); exit(4); } /* get destination pathname (with trailing backspace) and */ /* filename/-pattern */ if (fileargc < 2) { /* no destination path specified -> use current */ getcwd(dest_pathname, MAXPATH); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } else { /* destination path specified */ length = strlen(fileargv[1]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 8, "Destination path too long")); catclose(cat); exit(4); } _fullpath(dest_pathname, fileargv[1], MYMAXPATH); if (dest_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification")); catclose(cat); exit(4); } /* check destination path */ if (fileargv[1][length - 1] != *DIR_SEPARATOR && !dir_exists(dest_pathname)) { ptr = strrchr(dest_pathname, *DIR_SEPARATOR); ptr++; strmcpy(dest_filename, ptr, sizeof(dest_filename)); *ptr = '\0'; if ((ptr = strchr(dest_filename, '*')) == NULL && (ptr = strchr(dest_filename, '?')) == NULL) { /* last destination entry is not a filepattern -> does it specify */ /* a file or directory? */ if (((ptr = strchr(src_filename, '*')) == NULL && (ptr = strchr(src_filename, '?')) == NULL) || !switch_intodir) { /* source is a single file or switch /I was not specified -> ask */ /* user if destination should be a file or a directory */ printf("%s %s %s\n", catgets(cat, 1, 10, "Does"), dest_filename, catgets(cat, 1, 11, "specify a file name")); ch = confirm( catgets(cat, 1, 12, "or directory name on the target"), catgets(cat, 1, 13, "File"), catgets(cat, 1, 14, "Directory"), NULL, NULL); switch (ch) { case 1: /* 'F' */ /* file */ switch_file = -1; break; case 2: /* 'D' */ /* directory */ switch_intodir = -1; break; } } if (switch_intodir) { /* destination is a directory -> filepattern = "*.*" */ strmcat(dest_pathname, dest_filename, sizeof(dest_pathname)); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } } else { /* destination is a directory -> filepattern = "*.*" */ strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } cat_separator(dest_pathname); length = strlen(dest_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n",catgets(cat, 1, 15, "Destination path too long")); catclose(cat); exit(4); } /* check for cyclic path */ if ((switch_emptydir || switch_subdir) && cyclic_path(src_pathname, dest_pathname)) { printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy")); catclose(cat); exit(4); } /* get destination drive (1 = A, 2 = B, 3 = C, ...) */ dest_drive = toupper(dest_pathname[0]) - 64; if (switch_wait) { printf("%s\n",catgets(cat, 1, 17, "Press enter to continue...")); (void)getchar(); /* getch(); would need conio.h */ fflush(stdin); } xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename); if (!file_found) { printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename); catclose(cat); exit(1); } catclose(cat); return 0; }