int main() { printf(1, "this is the application program...\n"); printf(1, "date = %d\n", gdate()); printf(1, "month = %d\n", gmonth()); printf(1, "year = %d\n", gyear()); exit(); }
/* Inverse of sndaysb. */ struct date * sdateb(int nd, struct date *d) { if (nswitchb < nd) return (gdate(nd, d)); else return (jdate(nd, d)); }
/* * Compute the week number from the number of days since March 1st year 0. * The weeks are numbered per year starting with 1. If the first * week of a year includes at least four days of that year it is week 1, * otherwise it gets the number of the last week of the previous year. * The variable y will be filled with the year that contains the greater * part of the week. */ int week(int nd, int *y) { date dt; int fw; /* 1st day of week 1 of previous, this and * next year */ gdate(nd, &dt); for (*y = dt.y + 1; nd < (fw = firstweek(*y)); (*y)--) ; return ((nd - fw) / 7 + 1); }
int PXtoTM (unsigned long long number, struct tm *tm, int type ) { unsigned long long retval = 0; time_t t = 0; char *s = (char *)&number; char *d = (char *)&retval; long jd; int y,m,dy; struct tm *_tm = tm; switch (type) { case PX_Field_Type_Date: copy_from_be(d,s,4); if (s[0] & 0x80) { fix_sign(d, 4); } else if (retval == 0) { return VALUE_IS_NULL; } else { fprintf(stderr,"%s.%d: DATE can't be nagative\n", __FILE__, __LINE__); return VALUE_ERROR; } /* This is Y2K workaround !!! ** if the date is before 1.1.1970 i add 100 years (365*100 + 24) ** (seem not to be valid for paradox 7.0) */ #ifdef Y2K_WORKAROUND if (retval < 719528) { retval += 36524; } #endif #if 1 jd = jdatum(1,1,1); jd += retval - 1; gdate(jd, &y, &m, &dy); /* if the date has more than letters we assume that it some inserted correctly (not as an 2 letter short cut.) */ if (y >= 100) _tm->tm_year = y - 1900; else _tm->tm_year = y; _tm->tm_mon = m - 1; _tm->tm_mday = dy; #else t = (retval - 719528 + 365) * 24 * 60 * 60; _tm = localtime( &t ); #endif break; case PX_Field_Type_Time: copy_from_be(d,s,4); if (s[0] & 0x80) { fix_sign(d, 4); retval /= 1000; // lost miliseconds !! _tm->tm_sec = retval % 60; retval /= 60; _tm->tm_min = retval % 60; _tm->tm_hour = retval/60; } else if (retval == 0) { return VALUE_IS_NULL; } else { fprintf(stderr,"%s.%d: TIMESTAMP(%016llx -> %016llx) can't be nagative\n", __FILE__, __LINE__, number, retval); return VALUE_ERROR; } break; case PX_Field_Type_Timestamp: copy_from_be(d,s,8); if (s[0] & 0x80) { fix_sign(d, 8); /* the last byte is unused */ retval >>= 8; /* the timestamp seems to have a resolution of 1/500s */ retval /= 500; /* the adjustment that is neccesary to convert paradox ** timestamp to unix-timestamp [-> time()] ** ** FIXME: this value is guessed !! ** the garantued precission is +/- 1 second */ retval -= 37603860709183; t = retval; _tm = gmtime( &t ); } else if (retval == 0) {
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; } } }
int main(int argc,char **argv) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char nma[PATH_MAX], nmb[PATH_MAX], nmc[PATH_MAX], *qitem[100], *rprog = NULL; char nmd[PATH_MAX], grepquery[256]; static char oldname[30] ; static int was =0; /* these pointers are unions of pointer to int and pointer to long */ long *hpt = 0; unsigned *master =0; int falseflg, nhash, nitem, nfound = 0, frtbl, kk; /* special wart for refpart: default is tags only */ falseflg = 0; while (argc > 1 && argv[1][0] == '-') { switch(argv[1][1]) { case 'a': /* all output, incl. false drops */ falseflg = 1; break; case 'r': argc--; argv++; rprog = argv[1]; break; case 'F': /* put out full text */ full = setfrom(argv[1][2]); break; case 'T': /* put out tags */ tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ argc--; argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': argc--; argv++; soutput = argv[1]; if ((intptr_t) argv[2]<16000) { soutlen = (intptr_t)argv[2]; argc--; argv++; } break; case 't': /*tag output to string */ argc--; argv++; tagout = argv[1]; break; case 'l': /* length of internal lists */ argc--; argv++; lmaster = atoi(argv[1]); break; case 'g': /* suppress fgrep search on old files */ keepold = 0; break; case 'C': /* coordination level */ colevel = atoi(argv[1]+2); # if D1 fprintf(stderr, "colevel set to %d\n",colevel); # endif break; case 'P': /* print term freqs */ prfreqs=1; break; case 'm': measure=1; break; } argc--; argv++; } if(argc < 2) exit(1); strcpy (nma, todir(argv[1])); if (was == 0 || strcmp (oldname, nma) !=0) { strcpy (oldname,nma); strcpy (nmb, nma); strcpy (nmc, nmb); strcpy(nmd,nma); strcat (nma, ".ia"); strcat (nmb, ".ib"); strcat (nmc, ".ic"); strcat (nmd, ".id"); if (was) { fclose(fa); fclose(fb); fclose(fc); } fa = fopen(nma, "r"); if (fa==NULL) { strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname); fb=NULL; goto search; } fb = fopen(nmb, "r"); fc = fopen(nmc, "r"); was =1; if (fb== NULL || fc ==NULL) { err("Index incomplete %s", nmb); exit(1); } indexdate = gdate(fb); fd = fopen(nmd, "r"); } fseek (fa, 0, SEEK_SET); fread (&nhash, sizeof(nhash), 1, fa); fread (&iflong, sizeof(iflong), 1, fa); if(master==0) master = calloc (lmaster, iflong? sizeof(long): sizeof(unsigned)); hpt = calloc(nhash, sizeof(*hpt)); kk=fread( hpt, sizeof(*hpt), nhash, fa); # if D1 fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash); # endif assert (kk==nhash); hfreq = calloc(nhash, sizeof(*hfreq)); assert (hfreq != NULL); frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); hfrflg = (frtbl == nhash); # if D1 fprintf(stderr, "read freqs %d\n", frtbl); # endif search: while (1) { nitem = getq(qitem); if (measure) tick(); if (nitem==0) continue; if (nitem < 0) break; if (tagout) tagout[0]=0; if (fb!=NULL) { nfound = doquery(hpt, nhash, fb, nitem, qitem, master); # if D1 fprintf(stderr,"after doquery nfound %d\n", nfound); # endif fgnamp=fgnames; if (falseflg == 0) nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); # if D1 fprintf(stderr,"after baddrop nfound %d\n", nfound); # endif } if (fgnamp>fgnames) { char **fgp, tgbuff[100]; int k; # if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); # endif memset(tgbuff, 0, sizeof (tgbuff)); grepquery[0]=0; for(k=0; k<nitem; k++) { strcat(grepquery, " "); strcat(grepquery, qitem[k]); } # if D1 fprintf(stderr, "grepquery %s\n",grepquery); # endif for(fgp=fgnames; fgp<fgnamp; fgp++) { # if D1 fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery); # endif makefgrep(*fgp); # if D1 fprintf(stderr, "grepmade\n"); # endif if (tagout==0) tagout=tgbuff; grepcall(grepquery, tagout, *fgp); # if D1 fprintf(stderr, "tagout now /%s/\n", tagout); # endif if (full) { int nout; char *bout; char *tagp; char *oldtagp; tagp = tagout; while (*tagp) { oldtagp = tagp; while (*tagp && (*tagp != '\n')) tagp++; if (*tagp) tagp++; nout = findline(oldtagp, &bout, 1000, 0L); if (nout > 0) { fputs(bout, stdout); free(bout); } } } } } if (tags) result (master, nfound >tags ? tags: nfound, fc); if (measure) tock(); } /* NOTREACHED */ return 0; }
void huntmain(int argc,char **argv) { /* read query from stdin, expect name of indexes in argv[1] */ static FILE *fa, *fb, *fc; char indexname[PATH_MAX], *qitem[100], *rprog = 0; char grepquery[200]; static char oldname[30] ; static int nhash = 0; static int maxhash = 0; int falseflg = 0, nitem, nfound, frtbl; static long *hpt = 0; unsigned *masterp; # if D1 fprintf(stderr, "in glue1 argc %d argv %o %o\n", argc, argv[0],argv[1]); # endif savedir(); while (argv[1][0] == '-') { # if D1 fprintf(stderr, "argv.1 is %s\n",argv[1]); # endif switch(argv[1][1]) { case 'a': /* all output, incl. false drops */ falseflg = 1; break; case 'r': argc--; argv++; rprog = argv[1]; break; case 'F': /* put out full text */ full = setfrom(argv[1][2]); break; case 'T': /* put out tags */ tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ argc--; argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': argc--; argv++; soutput = argv[1]; if ((intptr_t) argv[2]<16000) { soutlen = (intptr_t) argv[2]; argc--; argv++; } break; case 't': /*tag output to string */ argc--; argv++; tagout = argv[1]; if ((intptr_t)argv[2]<16000) { taglen = (intptr_t)argv[2]; argc--; argv++; } break; case 'l': /* specify length of lists */ argc--; argv++; lmaster = atoi(argv[1]); # if D1 fprintf(stderr, "lmaster now %d\n",lmaster); # endif break; case 'C': argc--; argv++; colevel = atoi(argv[1]); break; } argc--; argv++; } n_strcpy (indexname, todir(argv[1]), sizeof(indexname)); # if D1 fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex); # endif if (typeindex == 0 || strcmp (oldname, indexname) !=0) { n_strcpy (oldname, indexname, sizeof(oldname)); unopen(fa); unopen(fb); unopen(fc); if (ckexist(indexname, ".ib")) { # if D1 fprintf(stderr, "found old index\n"); # endif fa = iopen(indexname, ".ia"); fb = iopen(indexname, ".ib"); fc = iopen(indexname, ".ic"); typeindex =1; # if D1 fprintf(stderr, "opened f's as %o %o %o\n",fa,fb,fc); # endif indexdate = gdate(fb); fread (&nhash, sizeof(nhash), 1, fa); fread (&iflong, sizeof(iflong), 1, fa); if (nhash > maxhash) { if (hpt) free (hpt); hpt=0; if (hfreq) free(hfreq); hfreq=0; maxhash=nhash; # if D1 fprintf(stderr, "Freed if needed maxhash %d\n",maxhash); # endif } if (hpt==0) hpt = zalloc(nhash, sizeof(*hpt)); # if D1 fprintf(stderr, "hpt now %o\n",hpt); # endif if (hpt == NULL) err("No space for hash list (%d)", nhash); fread( hpt, sizeof(*hpt), nhash, fa); if (hfreq==0) hfreq=zalloc(nhash, sizeof(*hfreq)); if (hfreq==NULL) err("No space for hash frequencies (%d)", nhash); frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); hfrflg = (frtbl == nhash); # if D1 fprintf(stderr,"Read pointer files\n"); # endif if (master.a == NULL) { if (iflong) master.b = zalloc(lmaster, sizeof(long)); else master.a = zalloc(lmaster, sizeof(int)); } if (master.a == NULL) err("no space for answer list", 0); } else if (makefgrep(indexname)) typeindex=2; else { err("No files %s\n", indexname); exit(1); } } if (iflong) masterp = (unsigned *) master.b; else masterp = master.a; # if D1 fprintf(stderr, "typeindex now %d\n",typeindex); # endif tagout[0]=0; if (typeindex==2) { grepcall(sinput, tagout, indexname); # if D1 fprintf(stderr, " back from grepcall\n"); # endif restodir(); return; } nitem = getq(qitem); # if D1 fprintf(stderr, "approaching doquery fb %o\n", fb); # endif nfound = doquery(hpt, nhash, fb, nitem, qitem, masterp); # ifdef D1 fprintf(stderr, "return from doquery with nfound %d\n", nfound); # endif if (falseflg == 0) nfound = baddrop(masterp, nfound, fc, nitem, qitem, rprog, full); # ifdef D1 fprintf(stderr, "after baddrop with nfound %d\n",nfound); fprintf(stderr, "tagout is /%s/, sout /%s/\n",tagout, soutput); # endif if (tags) result (masterp, nfound >tags ? tags : nfound, fc); # if D1 fprintf(stderr, "done with huntmain\n"); fprintf(stderr, "tagout is /%s/\n", tagout); fprintf(stderr, "string out is /%s/\n", soutput); # endif if (fgnamp>fgnames) { char **fgp; int k; # if D1 fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); # endif grepquery[0]=0; for(k=0; k<nitem; k++) { n_strcat(grepquery, " ", sizeof(grepquery)); n_strcat(grepquery, qitem[k], sizeof(grepquery)); } for(fgp=fgnames; fgp<fgnamp; fgp++) { # if D1 fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery); # endif makefgrep(*fgp); grepcall(grepquery, tagout, *fgp); # if D1 fprintf(stderr, "tagout now /%s/\n", tagout); # endif } } restodir(); }
int findline(char *_in, char **out, int outlen, long _indexdate) { static char name[100] = ""; char *p, **ftp; static FILE *fa = NULL; long lp, llen; # ifdef D1 int len; # endif int k, nofil; # if D1 fprintf(stderr, "findline: %s\n", _in); # endif if (mindex(_in, '!')) /* return(remote(in, *out)); /\* Does NOTHING */ return(0); nofil = _in[0]==0; for(p=_in; *p && *p != ':' && *p != ';'; p++) ; if (*p) *p++=0; else p=_in; k = sscanf(p, "%ld,%ld", &lp, &llen); # ifdef D1 fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen); # endif if (k<2) { lp = 0; llen=outlen; } # ifdef D1 fprintf(stderr, "lp %ld llen %ld\n",lp, llen); # endif # ifdef D1 fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,_in); # endif if (nofil) { # if D1 fprintf(stderr, "set fa to stdin\n"); # endif fa = stdin; } else if (strcmp (name, _in) != 0 || 1) { # if D1 fprintf(stderr, "old: %s new %s not equal\n",name,_in); # endif if (fa != NULL) fa = freopen(_in, "r", fa); else fa = fopen(_in, "r"); # if D1 if (fa==NULL) fprintf(stderr, "failed to (re)open *%s*\n",_in); # endif if (fa == NULL) return(0); /* err("Can't open %s", in); */ strcpy(name, _in); if (gdate(fa) > _indexdate && _indexdate != 0) { if (keepold) { for(ftp=fgnames; ftp<fgnamp; ftp++) if (strcmp(*ftp, name)==SAME) return(0); strcpy (*fgnamp++ = fgp, name); assert(fgnamp<fgnames+FGCT); while (*fgp && *fgp!=':') fgp++; *fgp++ = 0; assert (fgp<fgspace+FGSIZE); return(0); } fprintf(stderr, "Warning: index predates file '%s'\n", name); } } # if D1 else fprintf(stderr, "old %s new %s same fa %o\n", name,_in,fa); # endif if (fa != NULL) { fseek(fa, lp, SEEK_SET); *out = malloc(llen + 1); if (*out == NULL) { return(0); } # ifdef D1 len = # endif fread(*out, 1, llen, fa); *(*out + llen) = 0; # ifdef D1 fprintf(stderr, "length as read is %d\n",len); # endif } return(llen); }
/* Compute the Gregorian date of Easter Sunday in Julian Calendar */ date * easterog(int y, date *dt) { return (gdate(easterodn(y), dt)); }
// print the file on the default printer void ListPrintFile( void ) { register int i, n; int c, nRows, nBytesPrinted, nFH; long lTemp; POPWINDOWPTR wn; TCHAR szBuffer[MAXLISTLINE+1]; int fKBHit; // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 1, 4, strlen( LIST_PRINTING ) + 8, nInverse, LIST_PRINT_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); sprintf( szBuffer, LIST_QUERY_PRINT, LIST_PRINT_FILE_CHAR, LIST_PRINT_PAGE_CHAR ); wWriteListStr( 0, 1, wn, szBuffer ); if ((( c = GetKeystroke( EDIT_ECHO | EDIT_UC_SHIFT | EDIT_BIOS_KEY )) == LIST_PRINT_FILE_CHAR ) || ( c == LIST_PRINT_PAGE_CHAR )) { // save start position lTemp = LFile.lViewPtr; // display "Printing ..." wWriteListStr( 0, 1, wn, LIST_PRINTING ); if (( nFH = _sopen((( gpIniptr->Printer != INI_EMPTYSTR ) ? gpIniptr->StrData + gpIniptr->Printer : _TEXT("LPT1") ), (_O_BINARY | _O_WRONLY | _O_CREAT), _SH_DENYNO, _S_IWRITE | _S_IREAD )) >= 0 ) { if ( setjmp( cv.env ) == -1 ) { _close( nFH ); return; } // reset to beginning of file if ( c == LIST_PRINT_FILE_CHAR ) ListSetCurrent( 0L ); else { nRows = GetScrRows(); ListSetCurrent( LFile.lViewPtr ); } // print the header (filename, date & time) qprintf( nFH, _TEXT("%s %s %s\r\n\r\n"), LFile.szName, gdate( 0 ), gtime( gaCountryInfo.fsTimeFmt ) ); do { // abort printing if a key is hit // kbhit() in DOS tries to read from STDIN, which screws // up a LIST /S pipe _asm { mov ah, 1 int 16h mov fKBHit, 1 jnz KBHDone mov fKBHit, 0 KBHDone: } if ( fKBHit && ( GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY ) == ESC )) break; i = FormatLine( szBuffer, MAXLISTLINE, LFile.lViewPtr, &nBytesPrinted, TRUE ); LFile.lViewPtr += 16; // replace 0-31 with "." if ( lListFlags & LIST_HEX ) { for ( n = 0; ( n < i ); n++ ) { if ( szBuffer[n] < 32 ) szBuffer[n] = _TEXT('.'); } } if (( c == LIST_PRINT_PAGE_CHAR ) && ( nRows-- <= 0 )) break; } while (( nBytesPrinted > 0 ) && ( qprintf( nFH, _TEXT("%.*s\r\n"), i, szBuffer ) > 0 )); // print a formfeed qputc( nFH, _TEXT('\014') ); _close( nFH ); // restore start position LFile.lViewPtr = lTemp; ListSetCurrent( LFile.lViewPtr ); } else honk(); } wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); }