bool DOS_GetSFNPath(char const * const path,char * SFNPath,bool LFN) { char dir_current[DOS_PATHLENGTH + 1], pdir[LFN_NAMELENGTH], *p; Bit8u drive;char fulldir[DOS_PATHLENGTH],LFNPath[CROSS_LEN]; char name[DOS_NAMELENGTH_ASCII], lname[LFN_NAMELENGTH]; int w=0; DOS_DTA dta(dos.dta()); Bit32u size;Bit16u date;Bit16u time;Bit8u attr; if (!DOS_MakeName(path,fulldir,&drive)) return false; sprintf(SFNPath,"%c:\\",drive+'A'); strcpy(LFNPath,SFNPath); strcpy(dir_current,Drives[drive]->curdir); Drives[drive]->curdir,""; p = fulldir; if (*p==0) return true; for (char *s = strchr(p,'\\'); s != NULL; s = strchr(p,'\\')) { *s = 0; if (SFNPath[strlen(SFNPath)-1]=='\\') sprintf(pdir,"\"%s%s\"",SFNPath,p); else sprintf(pdir,"\"%s\\%s\"",SFNPath,p); if (!strrchr(p,'*') && !strrchr(p,'?')) { *s = '\\'; p = s + 1; if (DOS_FindFirst(pdir,0xffff & DOS_ATTR_DIRECTORY & ~DOS_ATTR_VOLUME,false)) { dta.GetResult(name,lname,size,date,time,attr); strcat(SFNPath,name); strcat(LFNPath,lname); Drives[drive]->curdir,SFNPath+3; strcat(SFNPath,"\\"); strcat(LFNPath,"\\"); } else { return false;} } else { strcat(SFNPath,p); strcat(LFNPath,p); strcat(SFNPath,"\\"); strcat(LFNPath,"\\"); *s = '\\'; p = s + 1; break; } } if (p != 0) { sprintf(pdir,"\"%s%s\"",SFNPath,p); if (!strrchr(p,'*')&&!strrchr(p,'?')&&DOS_FindFirst(pdir,0xffff & ~DOS_ATTR_VOLUME,false)) { dta.GetResult(name,lname,size,date,time,attr); strcat(SFNPath,name); strcat(LFNPath,lname); } else { strcat(SFNPath,p); strcat(LFNPath,p); } } Drives[drive]->curdir,dir_current; if (LFN) strcpy(SFNPath,LFNPath); return true; }
bool DOS_FindNext(void) { DOS_DTA dta(dos.dta()); Bit8u i = dta.GetSearchDrive(); if(i >= DOS_DRIVES || !Drives[i]) { /* Corrupt search. */ LOG(LOG_FILES,LOG_ERROR)("Corrupt search!!!!"); DOS_SetError(DOSERR_NO_MORE_FILES); return false; } if (Drives[i]->FindNext(dta)) return true; return false; }
/*!***************************************************************************** ******************************************************************************* \note motor_servo \date Feb 1999 \remarks This program is clocked by the ISR indirectly throught the motor_servo_sem semaphore. ******************************************************************************* Function Parameters: [in]=input,[out]=output none ******************************************************************************/ void motor_servo(void) { int j,i; int last_tick=0; double dt; if (motor_servo_calls == 1) { /* do some initializations if necessary */ } /********************************************************************** * start the loop */ while (servo_enabled) { /* wait to take semaphore */ semTake(motor_servo_sem,WAIT_FOREVER); /* execute the motor servo functions */ if (!run_motor_servo()) break; if (no_receive_flag) dta(d2a_hwm,d2a_bm,d2a_cm,2000); else dta(d2a_hwm,d2a_bm,d2a_cm,0); } /* end servo while loop */ semDelete(motor_servo_sem); printf("Motor Servo Error Count = %d\n",motor_servo_errors); }
void DOS_Shell::CMD_DELETE(char * args) { HELP("DELETE"); /* Command uses dta so set it to our internal dta */ RealPt save_dta=dos.dta(); dos.dta(dos.tables.tempdta); char * rem=ScanCMDRemain(args); if (rem) { WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem); return; } /* If delete accept switches mind the space infront of them. See the dir /p code */ char full[DOS_PATHLENGTH],sfull[DOS_PATHLENGTH+2]; char buffer[CROSS_LEN]; args = ExpandDot(args,buffer); StripSpaces(args); if (!DOS_Canonicalize(args,full)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH"));return; } //TODO Maybe support confirmation for *.* like dos does. char spath[DOS_PATHLENGTH],sargs[DOS_PATHLENGTH]; if (!DOS_GetSFNPath(args,spath,false)) { WriteOut(MSG_Get("SHELL_CMD_DEL_ERROR"),args); return; } sprintf(sargs,"\"%s\"",spath); bool res=DOS_FindFirst(sargs,0xffff & ~DOS_ATTR_VOLUME); if (!res) { WriteOut(MSG_Get("SHELL_CMD_DEL_ERROR"),args); dos.dta(save_dta); return; } //end can't be 0, but if it is we'll get a nice crash, who cares :) char * end=strrchr(full,'\\')+1;*end=0; char name[DOS_NAMELENGTH_ASCII],lname[LFN_NAMELENGTH+1]; Bit32u size;Bit16u time,date;Bit8u attr; DOS_DTA dta(dos.dta()); while (res) { dta.GetResult(name,lname,size,date,time,attr); if (!(attr & (DOS_ATTR_DIRECTORY|DOS_ATTR_READ_ONLY))) { strcpy(end,name); strcpy(sfull,full); if (uselfn) sprintf(sfull,"\"%s\"",full); if (!DOS_UnlinkFile(sfull)) WriteOut(MSG_Get("SHELL_CMD_DEL_ERROR"),full); } res=DOS_FindNext(); } dos.dta(save_dta); }
bool DOS_FindFirst(char * search,Bit16u attr,bool fcb_findfirst) { LOG(LOG_FILES,LOG_NORMAL)("file search attributes %X name %s",attr,search); DOS_DTA dta(dos.dta()); Bit8u drive; char fullsearch[DOS_PATHLENGTH]; char dir[DOS_PATHLENGTH]; char pattern[DOS_PATHLENGTH]; size_t len = strlen(search); if(len && search[len - 1] == '\\' && !( (len > 2) && (search[len - 2] == ':') && (attr == DOS_ATTR_VOLUME) )) { //Dark Forces installer, but c:\ is allright for volume labels(exclusively set) DOS_SetError(DOSERR_NO_MORE_FILES); return false; } if (!DOS_MakeName(search,fullsearch,&drive)) return false; //Check for devices. FindDevice checks for leading subdir as well bool device = (DOS_FindDevice(search) != DOS_DEVICES); /* Split the search in dir and pattern */ char * find_last; find_last=strrchr(fullsearch,'\\'); if (!find_last) { /*No dir */ strcpy(pattern,fullsearch); dir[0]=0; } else { *find_last=0; strcpy(pattern,find_last+1); strcpy(dir,fullsearch); } dta.SetupSearch(drive,(Bit8u)attr,pattern); if(device) { find_last = strrchr(pattern,'.'); if(find_last) *find_last = 0; //TODO use current date and time dta.SetResult(pattern,0,0,0,DOS_ATTR_DEVICE); LOG(LOG_DOSMISC,LOG_WARN)("finding device %s",pattern); return true; } if (Drives[drive]->FindFirst(dir,dta,fcb_findfirst)) return true; return false; }
bool DOS_FindFirst(char * search, Bit16u attr, bool fcb_findfirst) { DOS_DTA dta(dos.dta()); size_t len = strlen(search); if (len && search[len - 1] == '\\' && !((len > 2) && (search[len - 2] == ':') && (attr == DOS_ATTR_VOLUME))) { DOS_SetError(DOSERR_NO_MORE_FILES); // Dark Forces installer, but c:\ is allright for volume labels(exclusively set) return false; } char fullsearch[DOS_PATHLENGTH]; Bit8u drive; if (!DOS_MakeName(search, fullsearch, &drive)) return false; char dir[DOS_PATHLENGTH]; // Split the search in dir and pattern char pattern[DOS_PATHLENGTH]; char * find_last = strrchr(fullsearch, '\\'); if (!find_last) // No dir { strcpy(pattern, fullsearch); dir[0] = 0; } else { *find_last = 0; strcpy(pattern, find_last+1); strcpy(dir, fullsearch); } dta.SetupSearch(drive, (Bit8u)attr, pattern); if (bool device = (DOS_FindDevice(search) != DOS_DEVICES)) // Check for devices. FindDevice checks for leading subdir as well { if (!(attr & DOS_ATTR_DEVICE)) return false; if (find_last = strrchr(pattern, '.')) *find_last = 0; dta.SetResult(pattern, 0, 0, 0, DOS_ATTR_DEVICE); // TODO use current date and time return true; } return Drives[drive]->FindFirst(dir, dta, fcb_findfirst); }
void testMyDateTimeStore() { __int64 tmp; fielddefs* fds = fielddefs::create(); fielddef f; memset(&f, 0, sizeof(fielddef)); f.len = 8; f.pos = 0; //timestamp f.type = ft_mytimestamp; f.decimals = 6; field fd((unsigned char* )&tmp, f, fds); myTimeStamp dt(f.decimals, true); dt = "2010-10-10 00:00:00.123456"; fd = dt.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt.i64, "ft_mytimestamp7 value = " << fd.i64()); //Legacy format myTimeStamp dtl(f.decimals, false); dtl = "2010-10-10 00:00:00"; fd = dtl.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtl.i64, "ft_mytimestamp legacy value = " << fd.i64()); f.decimals = 4; f.len = 7; myTimeStamp dt2(f.decimals, true); dt2 = "2010-10-10 00:00:12.9988"; fd = dt2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt2.i64, "ft_mytimestamp6 value = " << fd.i64()); f.decimals = 2; f.len = 6; myTimeStamp dt3(f.decimals, true); dt3 = "2010-10-10 00:00:12.23"; fd = dt3.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt3.i64, "ft_mytimestamp5 value = " << fd.i64()); f.decimals = 0; f.len = 5; myTimeStamp dt4(f.decimals, true); dt4 = "2010-10-10 00:00:12"; fd = dt4.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt4.i64, "ft_mytimestamp4 value = " << fd.i64()); //datetime f.decimals = 6; f.len = 8; f.type = ft_mydatetime; myDateTime dt5(f.decimals, true); dt5 = "2015-10-10 00:00:12.445566"; fd = dt5.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt5.i64, "ft_mydatetime8 value = " << fd.i64()); //Legacy format myDateTime dt5l(f.decimals, true); dt5l = "2015-10-10 00:00:12"; fd = dt5l.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt5l.i64, "ft_mydatetime Legacy value = " << fd.i64()); f.decimals = 4; f.len = 7; myDateTime dt6(f.decimals, true); dt6 = "2015-10-10 00:00:12.7788"; fd = dt6.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt6.i64, "ft_mydatetime7 value = " << fd.i64()); f.decimals = 2; f.len = 6; myDateTime dt7(f.decimals, true); dt7 = "2015-10-10 00:00:12.00"; fd = dt7.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt7.i64, "ft_mydatetime6 value = " << fd.i64()); f.decimals = 0; f.len = 5; myDateTime dt71(f.decimals, true); dt71 = "2015-10-10 00:00:12"; fd = dt71.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt71.i64, "ft_mydatetime5 value = " << fd.i64()); //mariadb datetime f.setOptions(FIELD_OPTION_MARIADB); f.decimals = 6; f.len = 8; f.type = ft_mydatetime; maDateTime dta(f.decimals, true); dta = "2015-10-10 00:00:12.445566"; fd = dta.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta.i64, "ft_mydatetime8 maridb value = " << fd.i64()); f.decimals = 4; f.len = 7; maDateTime dta1(f.decimals, true); dta1 = "2015-10-10 00:00:12.7788"; fd = dta1.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta1.i64, "ft_mydatetime7 maridb value = " << fd.i64()); f.decimals = 2; f.len = 6; maDateTime dta2(f.decimals, true); dta2 = "2015-10-10 00:00:12.00"; fd = dta2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta2.i64, "ft_mydatetime6 maridb value = " << fd.i64()); f.decimals = 0; f.len = 5; maDateTime dta20(f.decimals, true); dta20 = "2015-10-10 00:00:12"; fd = dta20.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta20.i64, "ft_mydatetime6 maridb value = " << fd.i64()); // mariadb time f.decimals = 6; f.len = 6; f.type = ft_mytime; maTime dtma1(f.decimals, true); dtma1 = "00:00:12.123456"; fd = dtma1.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtma1.i64, "ft_mytime6 maridb value = " << fd.i64()); f.decimals = 4; f.len = 5; maTime dtma2(f.decimals, true); dtma2 = "00:00:12.1234"; fd = dtma2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtma2.i64, "ft_mytime5 maridb value = " << fd.i64()); f.decimals = 2; f.len = 4; maTime dta3(f.decimals, true); dta3 = "00:00:12.12"; fd = dta3.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta3.i64, "ft_mytime4 maridb value = " << fd.i64()); f.decimals = 0; f.len = 3; maTime dta4(f.decimals, true); dta4 = "00:00:12"; fd = dta4.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta4.i64, "ft_mytime3 maridb value = " << fd.i64()); maTime dta5(f.decimals, false); dta5 = "00:00:12"; fd = dta5.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta5.i64, "ft_mytime Legacy maridb value = " << fd.i64()); // MySQl time f.setOptions(0); f.decimals = 6; f.len = 6; f.type = ft_mytime; myTime dt10(f.decimals, true); dt10 = "00:00:12.123456"; fd = dt10.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt10.i64, "ft_mytime6 value = " << fd.i64()); f.decimals = 4; f.len = 5; myTime dt11(f.decimals, true); dt11 = "00:00:12.1234"; fd = dt11.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt11.i64, "ft_mytime5 value = " << fd.i64()); f.decimals = 2; f.len = 4; myTime dt12(f.decimals, true); dt12 = "00:00:12.12"; fd = dt12.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt12.i64, "ft_mytime4 value = " << fd.i64()); f.decimals = 0; f.len = 3; myTime dt13(f.decimals, true); dt13 = "00:00:12"; fd = dt13.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt13.i64, "ft_mytime3 value = " << fd.i64()); myTime dt13l(f.decimals, false); dt13l = "00:00:12"; fd = dt13l.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt13l.i64, "ft_mytime Legacy value = " << fd.i64()); //print f.type = ft_mydatetime; f.decimals = 6; f.len = 8; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.002000")) , "ft_mydatetime string8 = " << fd.c_str()); f.decimals = 4; f.len = 7; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.0020")) , "ft_mydatetime string7 = " << fd.c_str()); f.decimals = 2; f.len = 6; fd = _T("2015-10-01 20:50:36.052000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.05")) , "ft_mydatetime string6 = " << fd.c_str()); f.decimals = 0; f.len = 5; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36")) , "ft_mydatetime string5 = " << fd.c_str()); f.type = ft_mytimestamp; f.decimals = 6; f.len = 7; fd = _T("2015-10-01 20:50:36.052001"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.052001")) , "ft_mytimestamp string7 = " << fd.c_str()); f.decimals = 4; f.len = 6; fd = _T("2015-10-01 20:50:36.052001"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.0520")) , "ft_mytimestamp string6 = " << fd.c_str()); f.decimals = 2; f.len = 5; fd = _T("2015-10-01 20:50:36.052000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.05")) , "ft_mytimestamp string5 = " << fd.c_str()); f.decimals = 0; f.len = 4; fd = _T("2015-10-01 20:50:36.952000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36")) , "ft_mytimestamp string4 = " << fd.c_str()); fds->release(); }
int reduc_winformat(int *bufp, int *outp, int *messp, int *pesp, int *pdesp, int *pedesp, float final_edeshift[64], int *pwritestat, int *perrstat, int newoutlength) { float r; float evfrac; int ie, i, iE_counter; int header_id, header_mask; int tpu, nextpointer, temp, xrow, telescopeno; int header, xindex, yindex, currentpointer, pattern; int good, writestatus; int gevents, events, evlen; int rawevent[1024]; int bufferlength; int tel; int writestat, errstat; int outlength; int l_word; int words, nword, nboe, nbox; writestat = *pwritestat; errstat = *perrstat; outlength = newoutlength; r = drand48() - 0.5; /* Random between -0.5 and +0.5 */ bufferlength = 32768; errstat = 0; /* Initialisering */ words = 0; errstat = 0; /* Initialisering */ currentpointer = 0; nextpointer = 0; gevents = 0; events = 0; writestat = 0; good =-1; telescopeno = *(messp + 11); /* Number of telescopes used */ while (words < bufferlength) { /* Go through buffer */ dpnu = -1; /* Reset numbers */ pnu = -1; nanu = -1; tnanu = -1; nimnu = -1; cadcnu = -1; ctdcnu = -1; punu = -1; scnu = -1; iE_counter = -1; /* ************************************************************** */ /* Testing header word of event */ /* No more data in buffer if header = 0, return from function */ /* If this should occur too early (partly filled buffer), it may */ /* be a serious problem. Mark such a buffer as bad buffer. */ /* ************************************************************** */ currentpointer = nextpointer; l_word = *(bufp + nextpointer); nboe = boe(l_word); if(nboe == 0xc){ /* Begin of event */ nword = ndw(l_word); /* Number of words (ADCs) with data */ }else{ if(l_word != EOB ) errstat = -1; /* End of buffer */ goto L999; /* Drop current buffer */ } /* Save pointer to next event */ evlen = nword + 1; if( evlen > 1024){ printf("Warning, eventlength > 1024 \n"); errstat = -1; goto L999; } nextpointer = evlen + currentpointer; /* Save the raw event */ for( i = 0; i < evlen; i++){ rawevent[i] = *(bufp + currentpointer + i); } /* **************************************** */ /* Looping through all words (ADCs) and */ /* storing in respective vectors */ /* **************************************** */ for (i = 1; i <= nword; i++){ l_word = *(bufp + i + words); nbox = box(l_word); /* The box that has fired */ if(nbox == 0x00){ /* Pattern ch 0 - 3, NIM ADCs ch 4 - 15*/ nimnu++; nimi[nimnu] = chn(l_word); nim[nimnu] = dta(l_word); } if(nbox == 0x01){ nimnu++; /* Wall-clock time ch 16 - 17*/ nimi[nimnu] = chn(l_word); nim[nimnu] = dta(l_word); } if(nbox == 0x02){ /* VME scaler 1151N ch 0-31*/ scnu++; sci[scnu] = chn(l_word); sc[scnu] = dta(l_word); } if(nbox == 0x10){ /* Time of NaI ch 0-31*/ tnanu++; tnai[tnanu] = chn(l_word); tna[tnanu] = dta(l_word); } if(nbox == 0x20){ /* Energy of NaI ch 0-31*/ nanu++; nai[nanu] = chn(l_word); na[nanu] = dta(l_word); } if(nbox == 0x21){ /* Energy E ch 0-32 */ pnu++; /* Only 8 E counters in */ pi[pnu] = chn(l_word); /* ch 0, 2,..., 16 */ p[pnu] = dta(l_word); } if(nbox == 0x22){ /* Energy dE1 ch 0-31 */ dpnu++; dpi[dpnu] = chn(l_word); dp[dpnu] = dta(l_word); } if(nbox == 0x23){ /* Energy dE2 ch 32-61 */ dpnu++; dpi[dpnu] = chn(l_word) + 32; dp[dpnu] = dta(l_word); } #if 0 if(nbox == 6){ /* Camac ADC1 ch 0-7*/ cadcnu++; cadci[cadcnu] = chn(l_word); cadc[cadcnu] = dta(l_word); } if(nbox == 7){ /* Camac ADC2 ch 0-7*/ cadcnu++; cadci[cadcnu] = chn(l_word) + 8; cadc[cadcnu] = dta(l_word); } if(nbox == 8){ /* Camac ADC3 ch 0-7*/ cadcnu++; cadci[cadcnu] = chn(l_word) + 16; cadc[cadcnu] = dta(l_word); } if(nbox == 9){ /* Camac ADC4 ch 0-7*/ cadcnu++; cadci[cadcnu] = chn(l_word) + 24; cadc[cadcnu] = dta(l_word); } if(nbox == 10){ /* Camac TDC1 ch 0-7*/ ctdcnu++; ctdci[ctdcnu] = chn(l_word); ctdc[ctdcnu] = dta(l_word) ; } if(nbox == 11){ /* Camac TDC2 ch 0-7*/ ctdcnu++; ctdci[ctdcnu] = chn(l_word) + 8; ctdc[ctdcnu] = dta(l_word); } if(nbox == 12){ /* Camac TDC3 ch 0-7*/ ctdcnu++; ctdci[ctdcnu] = chn(l_word) + 16; ctdc[ctdcnu] = dta(l_word); } if(nbox == 13){ /* Camac TDC4 ch 0-7*/ ctdcnu++; ctdci[ctdcnu] = chn(l_word) + 24; ctdc[ctdcnu] = dta(l_word); } if(nbox == 14){ /* Camac Pile-up ch 0-1*/ punu++; pui[punu] = chn(l_word); pu[punu] = dta(l_word); } #endif } words = words + evlen; /* ====================================================== */ /* Now, the event is formatted and ready to be sorted */ /* ====================================================== */ good = reduc_winsort( pesp, pdesp, pedesp); /* Gate on particles, returns 0 of OK */ ++events; if (good == 0 ){ /* Good event, save it */ ++gevents; /* No of good events */ evfrac = (gevents * 100) / events; *(messp + 14) = (int) evfrac; /* Percent events accepted */ if (outlength > bufferlength - evlen) { writestatus = write_exa(outp, messp); /* Write databuffer to target device */ if (writestatus == -1){ /* Error in write, terminate session */ writestat = -1; printf("Error in write, terminate session = -1\n"); goto L999; } ++grec; /* Increment "good" buffers */ *(messp + 15) = grec; /* Number of accepted buffers */ outlength = 0; /* Reset local output buffer pointer */ for (i = 0; i < bufferlength; ++i){ /* Zeroing local output buffer */ *(outp + i) = 0; } } } /* ******************************************************************** */ /* Shift the E detector with the calculated shift. The event has one */ /* and only one particle event word for E, located in iE_counter */ /* ******************************************************************** */ p[pnu] = (int)((float)p[pnu] + final_edeshift[pi[pnu]] + r + 0.5); if(p[pnu] < 0 | p[pnu] > 2047) p[pnu] = 0; /* ********************************************* */ /* Replace the event word for E with new energy */ /* First we zero the energy, then add the energy */ /* ********************************************* */ rawevent[iE_counter] = rawevent[iE_counter] & 0xffff0000; rawevent[iE_counter] = rawevent[iE_counter] + p[pnu]; /* **************************************************** */ /* Store E-counter gain-stabilized event in good Buffer */ /* **************************************************** */ for (i = 0; i < evlen; ++i){ *(outp + outlength + i) = rawevent[i]; } outlength = outlength + evlen; } /* End of good event block */ /* End-Of-Event Loop, fetch next event */ L999: return outlength; }
void DOS_Shell::InputCommand(char * line) { Bitu size=CMD_MAXLINE-2; //lastcharacter+0 Bit8u c;Bit16u n=1; Bitu str_len=0;Bitu str_index=0; Bit16u len=0; bool current_hist=false; // current command stored in history? line[0] = '\0'; std::list<std::string>::iterator it_history = l_history.begin(), it_completion = l_completion.begin(); while (size) { dos.echo=false; while(!DOS_ReadFile(input_handle,&c,&n)) { Bit16u dummy; DOS_CloseFile(input_handle); DOS_OpenFile("con",2,&dummy); LOG(LOG_MISC,LOG_ERROR)("Reopening the input handle.This is a bug!"); } if (!n) { size=0; //Kill the while loop continue; } switch (c) { case 0x00: /* Extended Keys */ { DOS_ReadFile(input_handle,&c,&n); switch (c) { case 0x3d: /* F3 */ if (!l_history.size()) break; it_history = l_history.begin(); if (it_history != l_history.end() && it_history->length() > str_len) { const char *reader = &(it_history->c_str())[str_len]; while ((c = *reader++)) { line[str_index ++] = c; DOS_WriteFile(STDOUT,&c,&n); } str_len = str_index = (Bitu)it_history->length(); size = CMD_MAXLINE - str_index - 2; line[str_len] = 0; } break; case 0x4B: /* LEFT */ if (str_index) { outc(8); str_index --; } break; case 0x4D: /* RIGHT */ if (str_index < str_len) { outc(line[str_index++]); } break; case 0x47: /* HOME */ while (str_index) { outc(8); str_index--; } break; case 0x4F: /* END */ while (str_index < str_len) { outc(line[str_index++]); } break; case 0x48: /* UP */ if (l_history.empty() || it_history == l_history.end()) break; // store current command in history if we are at beginning if (it_history == l_history.begin() && !current_hist) { current_hist=true; l_history.push_front(line); } for (;str_index>0; str_index--) { // removes all characters outc(8); outc(' '); outc(8); } strcpy(line, it_history->c_str()); len = (Bit16u)it_history->length(); str_len = str_index = len; size = CMD_MAXLINE - str_index - 2; DOS_WriteFile(STDOUT, (Bit8u *)line, &len); it_history ++; break; case 0x50: /* DOWN */ if (l_history.empty() || it_history == l_history.begin()) break; // not very nice but works .. it_history --; if (it_history == l_history.begin()) { // no previous commands in history it_history ++; // remove current command from history if (current_hist) { current_hist=false; l_history.pop_front(); } break; } else it_history --; for (;str_index>0; str_index--) { // removes all characters outc(8); outc(' '); outc(8); } strcpy(line, it_history->c_str()); len = (Bit16u)it_history->length(); str_len = str_index = len; size = CMD_MAXLINE - str_index - 2; DOS_WriteFile(STDOUT, (Bit8u *)line, &len); it_history ++; break; case 0x53:/* DELETE */ { if(str_index>=str_len) break; Bit16u a=str_len-str_index-1; Bit8u* text=reinterpret_cast<Bit8u*>(&line[str_index+1]); DOS_WriteFile(STDOUT,text,&a);//write buffer to screen outc(' ');outc(8); for(Bitu i=str_index;i<str_len-1;i++) { line[i]=line[i+1]; outc(8); } line[--str_len]=0; size++; } break; default: break; } }; break; case 0x08: /* BackSpace */ if (str_index) { outc(8); Bit32u str_remain=str_len - str_index; size++; if (str_remain) { memmove(&line[str_index-1],&line[str_index],str_remain); line[--str_len]=0; str_index --; /* Go back to redraw */ for (Bit16u i=str_index; i < str_len; i++) outc(line[i]); } else { line[--str_index] = '\0'; str_len--; } outc(' '); outc(8); // moves the cursor left while (str_remain--) outc(8); } if (l_completion.size()) l_completion.clear(); break; case 0x0a: /* New Line not handled */ /* Don't care */ break; case 0x0d: /* Return */ outc('\n'); size=0; //Kill the while loop break; case'\t': { if (l_completion.size()) { it_completion ++; if (it_completion == l_completion.end()) it_completion = l_completion.begin(); } else { // build new completion list // Lines starting with CD will only get directories in the list bool dir_only = (strncasecmp(line,"CD ",3)==0); // get completion mask char *p_completion_start = strrchr(line, ' '); if (p_completion_start) { p_completion_start ++; completion_index = (Bit16u)(str_len - strlen(p_completion_start)); } else { p_completion_start = line; completion_index = 0; } char *path; if ((path = strrchr(line+completion_index,'\\'))) completion_index = (Bit16u)(path-line+1); if ((path = strrchr(line+completion_index,'/'))) completion_index = (Bit16u)(path-line+1); // build the completion list char mask[DOS_PATHLENGTH]; if (p_completion_start) { strcpy(mask, p_completion_start); char* dot_pos=strrchr(mask,'.'); char* bs_pos=strrchr(mask,'\\'); char* fs_pos=strrchr(mask,'/'); char* cl_pos=strrchr(mask,':'); // not perfect when line already contains wildcards, but works if ((dot_pos-bs_pos>0) && (dot_pos-fs_pos>0) && (dot_pos-cl_pos>0)) strcat(mask, "*"); else strcat(mask, "*.*"); } else { strcpy(mask, "*.*"); } RealPt save_dta=dos.dta(); dos.dta(dos.tables.tempdta); bool res = DOS_FindFirst(mask, 0xffff & ~DOS_ATTR_VOLUME); if (!res) { dos.dta(save_dta); break; // TODO: beep } DOS_DTA dta(dos.dta()); char name[DOS_NAMELENGTH_ASCII];Bit32u sz;Bit16u date;Bit16u time;Bit8u att; std::list<std::string> executable; while (res) { dta.GetResult(name,sz,date,time,att); // add result to completion list char *ext; // file extension if (strcmp(name, ".") && strcmp(name, "..")) { if (dir_only) { //Handle the dir only case different (line starts with cd) if(att & DOS_ATTR_DIRECTORY) l_completion.push_back(name); } else { ext = strrchr(name, '.'); if (ext && (strcmp(ext, ".BAT") == 0 || strcmp(ext, ".COM") == 0 || strcmp(ext, ".EXE") == 0)) // we add executables to the a seperate list and place that list infront of the normal files executable.push_front(name); else l_completion.push_back(name); } } res=DOS_FindNext(); } /* Add excutable list to front of completion list. */ std::copy(executable.begin(),executable.end(),std::front_inserter(l_completion)); it_completion = l_completion.begin(); dos.dta(save_dta); } if (l_completion.size() && it_completion->length()) { for (;str_index > completion_index; str_index--) { // removes all characters outc(8); outc(' '); outc(8); } strcpy(&line[completion_index], it_completion->c_str()); len = (Bit16u)it_completion->length(); str_len = str_index = completion_index + len; size = CMD_MAXLINE - str_index - 2; DOS_WriteFile(STDOUT, (Bit8u *)it_completion->c_str(), &len); } } break; case 0x1b: /* ESC */ //write a backslash and return to the next line outc('\\'); outc('\n'); *line = 0; // reset the line. if (l_completion.size()) l_completion.clear(); //reset the completion list. this->InputCommand(line); //Get the NEW line. size = 0; // stop the next loop str_len = 0; // prevent multiple adds of the same line break; default: if (l_completion.size()) l_completion.clear(); if(str_index < str_len && true) { //mem_readb(BIOS_KEYBOARD_FLAGS1)&0x80) dev_con.h ? outc(' ');//move cursor one to the right. Bit16u a = str_len - str_index; Bit8u* text=reinterpret_cast<Bit8u*>(&line[str_index]); DOS_WriteFile(STDOUT,text,&a);//write buffer to screen outc(8);//undo the cursor the right. for(Bitu i=str_len;i>str_index;i--) { line[i]=line[i-1]; //move internal buffer outc(8); //move cursor back (from write buffer to screen) } line[++str_len]=0;//new end (as the internal buffer moved one place to the right size--; }; line[str_index]=c; str_index ++; if (str_index > str_len){ line[str_index] = '\0'; str_len++; size--; } DOS_WriteFile(STDOUT,&c,&n); break; } } if (!str_len) return; str_len++; // remove current command from history if it's there if (current_hist) { current_hist=false; l_history.pop_front(); } // add command line to history l_history.push_front(line); it_history = l_history.begin(); if (l_completion.size()) l_completion.clear(); }
void modCalcEquinox::processLines( QTextStream &istream ) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut( outputFileName ); fOut.open(IO_WriteOnly); QTextStream ostream(&fOut); QString line; QString space = " "; int yearB; int i = 0; long double jdsp = 0., jdsu = 0., jdau = 0., jdwin = 0., jdsp1 = 0.; KStarsData *kd = (KStarsData*) parent()->parent()->parent(); KSSun *Sun = new KSSun(kd); while ( ! istream.eof() ) { line = istream.readLine(); line.stripWhiteSpace(); //Go through the line, looking for parameters QStringList fields = QStringList::split( " ", line ); i = 0; // Read year and write in ostream if corresponds if(yearCheckBatch->isChecked() ) { yearB = fields[i].toInt(); i++; } else yearB = yearEditBatch->text().toInt(); if ( allRadioBatch->isChecked() ) ostream << yearB << space; else if(yearCheckBatch->isChecked() ) ostream << yearB << space; jdsp = Sun->springEquinox(yearB); jdsu = Sun->summerSolstice(yearB); jdau = Sun->autumnEquinox(yearB); jdwin = Sun->winterSolstice(yearB); jdsp1 = Sun->springEquinox(yearB+1); KStarsDateTime dts( jdsp ); KStarsDateTime dtu( jdsu ); KStarsDateTime dta( jdau ); KStarsDateTime dtw( jdwin ); ostream << dts.toString(Qt::ISODate) << space << (float)(jdsu - jdsp) << space << dtu.toString(Qt::ISODate) << space << (float)(jdau - jdsu) << space << dta.toString(Qt::ISODate) << space << (float)(jdwin - jdau) << space << dtw.toString(Qt::ISODate) << space << (float)(jdsp1 - jdwin) << endl; } fOut.close(); }
void DOS_Shell::CMD_COPY(char * args) { HELP("COPY"); static char defaulttarget[] = "."; StripSpaces(args); /* Command uses dta so set it to our internal dta */ RealPt save_dta=dos.dta(); dos.dta(dos.tables.tempdta); DOS_DTA dta(dos.dta()); Bit32u size;Bit16u date;Bit16u time;Bit8u attr; char name[DOS_NAMELENGTH_ASCII], lname[LFN_NAMELENGTH+1]; std::vector<copysource> sources; // ignore /b and /t switches: always copy binary while(ScanCMDBool(args,"B")) ; while(ScanCMDBool(args,"T")) ; //Shouldn't this be A ? while(ScanCMDBool(args,"A")) ; ScanCMDBool(args,"Y"); ScanCMDBool(args,"-Y"); ScanCMDBool(args,"V"); char * rem=ScanCMDRemain(args); if (rem) { WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem); dos.dta(save_dta); return; } // Gather all sources (extension to copy more then 1 file specified at command line) // Concatenating files go as follows: All parts except for the last bear the concat flag. // This construction allows them to be counted (only the non concat set) char q[]="\""; char* source_p = NULL; char source_x[DOS_PATHLENGTH+CROSS_LEN]; while ( (source_p = StripArg(args)) && *source_p ) { do { char* plus = strchr(source_p,'+'); // If StripWord() previously cut at a space before a plus then // set concatenate flag on last source and remove leading plus. if (plus == source_p && sources.size()) { sources[sources.size()-1].concat = true; // If spaces also followed plus then item is only a plus. if (strlen(++source_p)==0) break; plus = strchr(source_p,'+'); } if (plus) *plus++ = 0; safe_strncpy(source_x,source_p,CROSS_LEN); bool has_drive_spec = false; size_t source_x_len = strlen(source_x); if (source_x_len>0) { if (source_x[source_x_len-1]==':') has_drive_spec = true; } if (!has_drive_spec && !strpbrk(source_p,"*?") ) { //doubt that fu*\*.* is valid char spath[DOS_PATHLENGTH]; if (DOS_GetSFNPath(source_p,spath,false) && DOS_FindFirst(spath,0xffff & ~DOS_ATTR_VOLUME)) { dta.GetResult(name,lname,size,date,time,attr); if (attr & DOS_ATTR_DIRECTORY) strcat(source_x,"\\*.*"); } } sources.push_back(copysource(source_x,(plus)?true:false)); source_p = plus; } while(source_p && *source_p); } // At least one source has to be there if (!sources.size() || !sources[0].filename.size()) { WriteOut(MSG_Get("SHELL_MISSING_PARAMETER")); dos.dta(save_dta); return; }; copysource target; // If more then one object exists and last target is not part of a // concat sequence then make it the target. if(sources.size()>1 && !sources[sources.size()-2].concat){ target = sources.back(); sources.pop_back(); } //If no target => default target with concat flag true to detect a+b+c if(target.filename.size() == 0) target = copysource(defaulttarget,true); copysource oldsource; copysource source; Bit32u count = 0; while(sources.size()) { /* Get next source item and keep track of old source for concat start end */ oldsource = source; source = sources[0]; sources.erase(sources.begin()); //Skip first file if doing a+b+c. Set target to first file if(!oldsource.concat && source.concat && target.concat) { target = source; continue; } /* Make a full path in the args */ char pathSourcePre[DOS_PATHLENGTH], pathSource[DOS_PATHLENGTH+2]; char pathTarget[DOS_PATHLENGTH]; if (!DOS_Canonicalize(const_cast<char*>(source.filename.c_str()),pathSourcePre)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); dos.dta(save_dta); return; } strcpy(pathSource,pathSourcePre); if (uselfn) sprintf(pathSource,"\"%s\"",pathSourcePre); // cut search pattern char* pos = strrchr(pathSource,'\\'); if (pos) *(pos+1) = 0; if (!DOS_Canonicalize(const_cast<char*>(target.filename.c_str()),pathTarget)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); dos.dta(save_dta); return; } char* temp = strstr(pathTarget,"*.*"); if(temp) *temp = 0;//strip off *.* from target // add '\\' if target is a directory bool target_is_file = true; if (pathTarget[strlen(pathTarget)-1]!='\\') { if (DOS_FindFirst(pathTarget,0xffff & ~DOS_ATTR_VOLUME)) { dta.GetResult(name,lname,size,date,time,attr); if (attr & DOS_ATTR_DIRECTORY) { strcat(pathTarget,"\\"); target_is_file = false; } } } else target_is_file = false; //Find first sourcefile char sPath[DOS_PATHLENGTH]; bool ret = DOS_GetSFNPath(source.filename.c_str(),sPath,false) && DOS_FindFirst(const_cast<char*>(sPath),0xffff & ~DOS_ATTR_VOLUME); if (!ret) { WriteOut(MSG_Get("SHELL_CMD_FILE_NOT_FOUND"),const_cast<char*>(source.filename.c_str())); dos.dta(save_dta); return; } Bit16u sourceHandle,targetHandle; char nameTarget[DOS_PATHLENGTH]; char nameSource[DOS_PATHLENGTH]; bool second_file_of_current_source = false; while (ret) { dta.GetResult(name,lname,size,date,time,attr); if ((attr & DOS_ATTR_DIRECTORY)==0) { strcpy(nameSource,pathSource); strcat(nameSource,name); // Open Source if (DOS_OpenFile(nameSource,0,&sourceHandle)) { // Create Target or open it if in concat mode strcpy(nameTarget,q); strcat(nameTarget,pathTarget); if (nameTarget[strlen(nameTarget)-1]=='\\') strcat(nameTarget,uselfn?lname:name); strcat(nameTarget,q); //Special variable to ensure that copy * a_file, where a_file is not a directory concats. bool special = second_file_of_current_source && target_is_file; second_file_of_current_source = true; if (special) oldsource.concat = true; //Don't create a new file when in concat mode if (oldsource.concat || DOS_CreateFile(nameTarget,0,&targetHandle)) { Bit32u dummy=0; //In concat mode. Open the target and seek to the eof if (!oldsource.concat || (DOS_OpenFile(nameTarget,OPEN_READWRITE,&targetHandle) && DOS_SeekFile(targetHandle,&dummy,DOS_SEEK_END))) { // Copy static Bit8u buffer[0x8000]; // static, otherwise stack overflow possible. bool failed = false; Bit16u toread = 0x8000; do { failed |= DOS_ReadFile(sourceHandle,buffer,&toread); failed |= DOS_WriteFile(targetHandle,buffer,&toread); } while (toread==0x8000); failed |= DOS_CloseFile(sourceHandle); failed |= DOS_CloseFile(targetHandle); if (strcmp(name,lname)&&uselfn) WriteOut(" %s [%s]\n",lname,name); else WriteOut(" %s\n",uselfn?lname:name); if(!source.concat && !special) count++; //Only count concat files once } else { DOS_CloseFile(sourceHandle); WriteOut(MSG_Get("SHELL_CMD_COPY_FAILURE"),const_cast<char*>(target.filename.c_str())); } } else { DOS_CloseFile(sourceHandle); WriteOut(MSG_Get("SHELL_CMD_COPY_FAILURE"),const_cast<char*>(target.filename.c_str())); } } else WriteOut(MSG_Get("SHELL_CMD_COPY_FAILURE"),const_cast<char*>(source.filename.c_str())); }; //On to the next file if the previous one wasn't a device if ((attr&DOS_ATTR_DEVICE) == 0) ret = DOS_FindNext(); else ret = false; }; } WriteOut(MSG_Get("SHELL_CMD_COPY_SUCCESS"),count); dos.dta(save_dta); }
void DOS_Shell::CMD_DIR(char * args) { HELP("DIR"); char numformat[16]; char path[DOS_PATHLENGTH]; char sargs[CROSS_LEN]; std::string line; if(GetEnvStr("DIRCMD",line)){ std::string::size_type idx = line.find('='); std::string value=line.substr(idx +1 , std::string::npos); line = std::string(args) + " " + value; args=const_cast<char*>(line.c_str()); } bool optW=ScanCMDBool(args,"W"); ScanCMDBool(args,"S"); bool optP=ScanCMDBool(args,"P"); if (ScanCMDBool(args,"WP") || ScanCMDBool(args,"PW")) { optW=optP=true; } bool optB=ScanCMDBool(args,"B"); bool optAD=ScanCMDBool(args,"AD"); char * rem=ScanCMDRemain(args); if (rem) { WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem); return; } Bit32u byte_count,file_count,dir_count; Bitu w_count=0; Bitu p_count=0; Bitu w_size = optW?5:1; byte_count=file_count=dir_count=0; char buffer[CROSS_LEN]; args = trim(args); size_t argLen = strlen(args); if (argLen == 0) { strcpy(args,"*.*"); //no arguments. } else { switch (args[argLen-1]) { case '\\': // handle \, C:\, etc. case ':' : // handle C:, etc. strcat(args,"*.*"); break; default: break; } } args = ExpandDot(args,buffer); if (!strrchr(args,'*') && !strrchr(args,'?')) { Bit16u attribute=0; if(!DOS_GetSFNPath(args,sargs,false)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); return; } if(DOS_GetFileAttr(sargs,&attribute) && (attribute&DOS_ATTR_DIRECTORY) ) { DOS_FindFirst(sargs,0xffff & ~DOS_ATTR_VOLUME); DOS_DTA dta(dos.dta()); strcpy(args,sargs); strcat(args,"\\*.*"); // if no wildcard and a directory, get its files } } if (!DOS_GetSFNPath(args,sargs,false)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); return; } sprintf(args,"\"%s\"",sargs); if (!strrchr(args,'.')) { strcat(args,".*"); // if no extension, get them all } /* Make a full path in the args */ if (!DOS_Canonicalize(args,path)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); return; } *(strrchr(path,'\\')+1)=0; if (!DOS_GetSFNPath(path,sargs,true)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); return; } if (*(sargs+strlen(sargs)-1) != '\\') strcat(sargs,"\\"); if (!optB) WriteOut(MSG_Get("SHELL_CMD_DIR_INTRO"),sargs); /* Command uses dta so set it to our internal dta */ RealPt save_dta=dos.dta(); dos.dta(dos.tables.tempdta); DOS_DTA dta(dos.dta()); bool ret=DOS_FindFirst(args,0xffff & ~DOS_ATTR_VOLUME); if (!ret) { if (!optB) WriteOut(MSG_Get("SHELL_CMD_FILE_NOT_FOUND"),args); dos.dta(save_dta); return; } do { /* File name and extension */ char name[DOS_NAMELENGTH_ASCII], lname[LFN_NAMELENGTH+1]; Bit32u size;Bit16u date;Bit16u time;Bit8u attr; dta.GetResult(name,lname,size,date,time,attr); /* Skip non-directories if option AD is present */ if(optAD && !(attr&DOS_ATTR_DIRECTORY) ) continue; /* output the file */ if (optB) { // this overrides pretty much everything if (strcmp(".",uselfn?lname:name) && strcmp("..",uselfn?lname:name)) { WriteOut("%s\n",uselfn?lname:name); } } else { char * ext = empty_string; if (!optW && (name[0] != '.')) { ext = strrchr(name, '.'); if (!ext) ext = empty_string; else *ext++ = 0; } Bit8u day = (Bit8u)(date & 0x001f); Bit8u month = (Bit8u)((date >> 5) & 0x000f); Bit16u year = (Bit16u)((date >> 9) + 1980); Bit8u hour = (Bit8u)((time >> 5 ) >> 6); Bit8u minute = (Bit8u)((time >> 5) & 0x003f); if (attr & DOS_ATTR_DIRECTORY) { if (optW) { WriteOut("[%s]",name); size_t namelen = strlen(name); if (namelen <= 14) { for (size_t i=14-namelen;i>0;i--) WriteOut(" "); } } else { WriteOut("%-8s %-3s %-16s %02d-%02d-%04d %2d:%02d %s\n",name,ext,"<DIR>",day,month,year,hour,minute,uselfn?lname:""); } dir_count++; } else { if (optW) { WriteOut("%-16s",name); } else { FormatNumber(size,numformat); WriteOut("%-8s %-3s %16s %02d-%02d-%04d %2d:%02d %s\n",name,ext,numformat,day,month,year,hour,minute,uselfn?lname:""); } file_count++; byte_count+=size; } if (optW) { w_count++; } } if (optP && !(++p_count%(22*w_size))) { CMD_PAUSE(empty_string); } } while ( (ret=DOS_FindNext()) ); if (optW) { if (w_count%5) WriteOut("\n"); } if (!optB) { /* Show the summary of results */ FormatNumber(byte_count,numformat); WriteOut(MSG_Get("SHELL_CMD_DIR_BYTES_USED"),file_count,numformat); Bit8u drive=dta.GetSearchDrive(); //TODO Free Space Bitu free_space=1024*1024*100; if (Drives[drive]) { Bit16u bytes_sector;Bit8u sectors_cluster;Bit16u total_clusters;Bit16u free_clusters; Drives[drive]->AllocationInfo(&bytes_sector,§ors_cluster,&total_clusters,&free_clusters); free_space=bytes_sector*sectors_cluster*free_clusters; } FormatNumber(free_space,numformat); WriteOut(MSG_Get("SHELL_CMD_DIR_BYTES_FREE"),dir_count,numformat); } dos.dta(save_dta); }