/** * @info Fce ziska vstup od uzivatele * @param E_CODE - odkaz na chybovy kod * @return tSymbolData - nacteny retezec */ E_CODE input (tSymbolData *dest) { int c; tString save; E_CODE err = strInit(&save); while ((c = fgetc(stdin)) != EOF && c != '\n' && err == ERROR_OK) err = strAdd(&save, (char) c); dest->type = DT_STRING; dest->data.sData = save; return err; }
/** * @info Vytvori strukturu a prida do ni *char z parametru * @param char* - pole znaku, nad kterym vytvorime novou strukturu string * @return tString - Struktura s polem a jeho rozmery */ tString strCreate (const char *array) { tString str = {NULL, 0, 0}; if (strInit(&str) == ERROR_COMPILATOR) return str; int i = 0; while (array[i] != '\0') if (strAdd(&str, array[i++]) == ERROR_COMPILATOR) { strFree(&str); return str; } return str; }
ws_result wscString::Concat(wsiString ** ret, wsiString * str) const { ws_ptr<wsiString> strAdd (str); const ws_int len1 = GetLength(); const ws_int len2 = strAdd->GetLength(); const ws_char * const buf1 = GetBuffer(); const ws_char * const buf2 = strAdd->GetBuffer(); ws_ptr<wsiStringService> strServ; wscString::GetStringService( &strServ ); ws_ptr<wsiStringRW> strRW; strServ->AllocateString( &strRW , len1+len2 , buf1 , len1 ); ws_char * const buf = strRW->GetBufferRW(); wspr::ws_memcpy( buf+len1 , buf2 , len2 ); strRW->SetLength( len1 + len2 ); ws_ptr<wsiString> pstr( strRW ); pstr.CopyTo( ret ); return ws_result( WS_RLT_SUCCESS ); }
bool CMainFrame::SetLanguageMenu() { CMenu* pParentMenu = GetMenu(); CMenu* pMenu = GetMenu()->GetSubMenu( m_nLangOptionMenuPos ); CUStringConvert strCnv; ASSERT( pMenu ); if ( NULL == m_pPopupMenu ) { m_pPopupMenu = new CMenu; m_pPopupMenu->CreatePopupMenu(); CUString strAdd( g_language.GetString( IDS_CHECKFORADDITIONAL_LANGUAGE_FILES ) ); CUStringConvert strCnv; // Add Check for Updates m_pPopupMenu->AppendMenu( MF_STRING | MF_ENABLED, ID_LANGUAGE_START, strCnv.ToT( strAdd ) ); // Add language menu items for ( DWORD idx = 0; idx < g_language.GetNumLanguageStrings() ; idx++ ) { CUString strAdd( g_language.GetLanguageString( idx ) ); m_pPopupMenu->AppendMenu( MF_STRING | MF_ENABLED, ID_LANGUAGE_START + idx + 1, strCnv.ToT( strAdd ) ); } } CString strCurrent; pMenu->GetMenuString( m_nLangLangMenuPos, strCurrent, MF_BYPOSITION ); // Add language menu items for ( DWORD idx = 0; idx < m_pPopupMenu->GetMenuItemCount(); idx++ ) { CString strMenu; if ( 0 == idx ) { m_pPopupMenu->ModifyMenu( idx, MF_BYPOSITION | MF_STRING, ID_LANGUAGE_START, strCnv.ToT( g_language.GetString( IDS_CHECKFORADDITIONAL_LANGUAGE_FILES ) )); } // get menu string m_pPopupMenu->GetMenuString( idx, strMenu, MF_BYPOSITION ); // check if this is the selected language if ( 0 == g_language.GetLanguage().CompareNoCase( CUString( strMenu ) ) ) { m_pPopupMenu->CheckMenuItem( idx, MF_BYPOSITION | MF_CHECKED ); } else { m_pPopupMenu->CheckMenuItem( idx, MF_BYPOSITION | MF_UNCHECKED ); } } // remove exisiting menu item pMenu->RemoveMenu( m_nLangLangMenuPos, MF_BYPOSITION ); // insert new popup menu pMenu->InsertMenu( m_nLangLangMenuPos, MF_BYPOSITION | MF_POPUP, (UINT)m_pPopupMenu->m_hMenu, strCurrent ); // peform translation g_language.TranslateMenu( GetMenu(), m_nMenuID ); // refresh frame windows ActivateFrame( SW_HIDE ); ActivateFrame( SW_SHOW ); return true; }
int checkHdr(char *infile, int hdrflag, int hdu) { int i, len, ncard, morekeys; int status = 0; char *keyword; char *value; char fitskeyword[80]; char fitsvalue [80]; char fitscomment[80]; char tmpstr [80]; char *end; char line [1024]; char pline [1024]; char *ptr1; char *ptr2; FILE *fp; fitsfile *infptr; static int maxhdr; if(!mHeader) { mHeader = malloc(MAXHDR); maxhdr = MAXHDR; } havePLTRAH = 0; haveSIMPLE = 0; haveBITPIX = 0; haveNAXIS = 0; haveNAXIS1 = 0; haveNAXIS2 = 0; haveCTYPE1 = 0; haveCTYPE2 = 0; haveCRPIX1 = 0; haveCRPIX2 = 0; haveCDELT1 = 0; haveCDELT2 = 0; haveCD1_1 = 0; haveCD1_2 = 0; haveCD2_1 = 0; haveCD2_2 = 0; haveCRVAL1 = 0; haveCRVAL2 = 0; haveBSCALE = 0; haveBZERO = 0; haveBLANK = 0; haveEPOCH = 0; haveEQUINOX = 0; /****************************************/ /* Initialize the WCS transform library */ /* and find the pixel location of the */ /* sky coordinate specified */ /****************************************/ errorCount = 0; if(hdrCheck_outfile) { fout = fopen(hdrCheck_outfile, "w+"); if(fout == (FILE *)NULL) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"Cannot open output file %s.\"]\n", hdrCheck_outfile); fflush(fstatus); exit(1); } } strcpy(mHeader, ""); if(fits_open_file(&infptr, infile, READONLY, &status) == 0) { if(CHdebug) { printf("\nFITS file\n"); fflush(stdout); } if(hdrflag == HDR) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"FITS file (%s) cannot be used as a header template\"]\n", infile); fflush(fstatus); exit(1); } if(hdu > 0) { if(fits_movabs_hdu(infptr, hdu+1, NULL, &status)) FITSerror(status); } if(fits_get_hdrspace (infptr, &ncard, &morekeys, &status)) FITSerror(status); if(ncard > 1000) mHeader = realloc(mHeader, ncard * 80 + 1024); if(CHdebug) { printf("ncard = %d\n", ncard); fflush(stdout); } for (i=1; i<=ncard; i++) { if(fits_read_keyn (infptr, i, fitskeyword, fitsvalue, fitscomment, &status)) FITSerror(status); if(fitsvalue[0] == '\'') { strcpy(tmpstr, fitsvalue+1); if(tmpstr[strlen(tmpstr)-1] == '\'') tmpstr[strlen(tmpstr)-1] = '\0'; } else strcpy(tmpstr, fitsvalue); fitsCheck(fitskeyword, tmpstr); sprintf(line, "%-8s= %20s", fitskeyword, fitsvalue); if(strncmp(line, "COMMENT", 7) != 0) strAdd(mHeader, line); } strAdd(mHeader, "END"); if(fits_close_file(infptr, &status)) FITSerror(status); } else { if(CHdebug) { printf("\nTemplate file\n"); fflush(stdout); } if(hdrflag == FITS) { fp = fopen(infile, "r"); if(fp == (FILE *)NULL) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"File %s not found.\"]\n", infile); fflush(fstatus); exit(1); } fclose(fp); fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"File (%s) is not a FITS image\"]\n", infile); fflush(fstatus); exit(1); } fp = fopen(infile, "r"); if(fp == (FILE *)NULL) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"File %s not found.\"]\n", infile); fflush(fstatus); exit(1); } while(1) { if(fgets(line, 1024, fp) == (char *)NULL) break; if(line[(int)strlen(line)-1] == '\n') line[(int)strlen(line)-1] = '\0'; if(line[(int)strlen(line)-1] == '\r') line[(int)strlen(line)-1] = '\0'; strcpy(pline, line); if((int)strlen(line) > 80) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"FITS header lines cannot be greater than 80 characters.\"]\n"); fflush(fstatus); exit(1); } len = (int)strlen(pline); keyword = pline; while(*keyword == ' ' && keyword < pline+len) ++keyword; end = keyword; while(*end != ' ' && *end != '=' && end < pline+len) ++end; value = end; while((*value == '=' || *value == ' ' || *value == '\'') && value < pline+len) ++value; *end = '\0'; end = value; if(*end == '\'') ++end; while(*end != ' ' && *end != '\'' && end < pline+len) ++end; *end = '\0'; fitsCheck(keyword, value); strAdd(mHeader, line); if((int)strlen(mHeader) + 160 > maxhdr) { maxhdr += MAXHDR; mHeader = realloc(mHeader, maxhdr); } } fclose(fp); } /********************************************************/ /* */ /* Check to see if we have the minimum FITS header info */ /* */ /********************************************************/ if(!haveBITPIX) errorOutput("No BITPIX keyword in FITS header"); if(!haveNAXIS) errorOutput("No NAXIS keyword in FITS header"); if(!haveNAXIS1) errorOutput("No NAXIS1 keyword in FITS header"); if(!haveNAXIS2) errorOutput("No NAXIS2 keyword in FITS header"); if(havePLTRAH) { /* If we have this parameter, we'll assume this is a DSS header */ /* the WCS checking routine should be able to verify if it isn't */ free(mHeader); maxhdr = 0; mHeader = (char *)NULL; return(0); } if(!haveCTYPE1) errorOutput("No CTYPE1 keyword in FITS header"); if(!haveCTYPE2) errorOutput("No CTYPE2 keyword in FITS header"); if(!haveCRPIX1) errorOutput("No CRPIX1 keyword in FITS header"); if(!haveCRPIX2) errorOutput("No CRPIX2 keyword in FITS header"); if(!haveCRVAL1) errorOutput("No CRVAL1 keyword in FITS header"); if(!haveCRVAL2) errorOutput("No CRVAL2 keyword in FITS header"); if(!haveCD1_1 && !haveCD1_2 && !haveCD2_1 && !haveCD2_2) { if(!haveCDELT1) errorOutput("No CDELT1 keyword (or incomplete CD matrix) in FITS header"); else if(!haveCDELT2) errorOutput("No CDELT2 keyword (or incomplete CD matrix) in FITS header"); } if(strlen(ctype1) < 8) errorOutput("CTYPE1 must be at least 8 characters"); if(strlen(ctype2) < 8) errorOutput("CTYPE2 must be at least 8 characters"); ptr1 = ctype1; while(*ptr1 != '-' && *ptr1 != '\0') ++ptr1; while(*ptr1 == '-' && *ptr1 != '\0') ++ptr1; ptr2 = ctype2; while(*ptr2 != '-' && *ptr2 != '\0') ++ptr2; while(*ptr2 == '-' && *ptr2 != '\0') ++ptr2; if(strlen(ptr1) == 0 || strlen(ptr2) == 0) errorOutput("Invalid CTYPE1 or CTYPE2 projection information"); if(strcmp(ptr1, ptr2) != 0) errorOutput("CTYPE1, CTYPE2 projection information mismatch"); if(hdrStringent) { if(strlen(ptr1) != 3) errorOutput("Invalid CTYPE1 projection information"); if(strlen(ptr2) != 3) errorOutput("Invalid CTYPE2 projection information"); } /****************************************/ /* Initialize the WCS transform library */ /* and find the pixel location of the */ /* sky coordinate specified */ /****************************************/ /* if(CHdebug) { printf("header = \n%s\n", mHeader); fflush(stdout); } */ hdrCheck_wcs = wcsinit(mHeader); checkWCS(hdrCheck_wcs, 0); if(errorCount > 0) { fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"%d Errors\"]\n", errorCount); fflush(fstatus); exit(1); } return(0); }
void EnumFiles(VMenu2& Menu, const string& Str) { if(!Str.empty()) { string strStr(Str); size_t Pos = 0; if(std::count(ALL_CONST_RANGE(strStr), L'"') & 1) // odd quotes count { Pos = strStr.rfind(L'"'); } else { for(Pos=strStr.size()-1; Pos!=static_cast<size_t>(-1); Pos--) { if(strStr[Pos]==L'"') { Pos--; while(strStr[Pos]!=L'"' && Pos!=static_cast<size_t>(-1)) { Pos--; } } else if(strStr[Pos]==L' ') { Pos++; break; } } } if(Pos==static_cast<size_t>(-1)) { Pos=0; } bool StartQuote=false; if(Pos < strStr.size() && strStr[Pos]==L'"') { Pos++; StartQuote=true; } string strStart(strStr.data(),Pos); Unquote(strStr.erase(0, Pos)); if(!strStr.empty()) { string strExp = os::env::expand_strings(strStr); os::fs::enum_file Find(strExp+L"*"); bool Separator=false; std::for_each(CONST_RANGE(Find, i) { const wchar_t* FileName=PointToName(strStr); bool NameMatch=!StrCmpNI(FileName, i.strFileName.data(), StrLength(FileName)), AltNameMatch = NameMatch? false : !StrCmpNI(FileName, i.strAlternateFileName.data(), StrLength(FileName)); if(NameMatch || AltNameMatch) { strStr.resize(FileName-strStr.data()); string strAdd (strStr + (NameMatch ? i.strFileName : i.strAlternateFileName)); if (!StartQuote) QuoteSpace(strAdd); string strTmp(strStart+strAdd); if(StartQuote) strTmp += L'"'; if(!Separator) { if(Menu.GetItemCount()) { MenuItemEx Item; Item.strName = MSG(MCompletionFilesTitle); Item.Flags=LIF_SEPARATOR; Menu.AddItem(Item); } else { Menu.SetTitle(MSG(MCompletionFilesTitle)); } Separator=true; } Menu.AddItem(strTmp); } });