int EXP_LVL1 CS_isHlpAvailable () { if (csHlpIsAvail == 0) { if (csHelpFile [0] == '\0') { if (cs_DirP != NULL) { CS_stcpy (cs_DirP,"CS-MAP.hlp"); if (CS_access (cs_Dir,4) == 0) { csHlpIsAvail = 1; CS_stcpy (csHelpFile,cs_Dir); } } else { csHlpIsAvail = -1; } } else if (CS_access (csHelpFile,4) == 0) { csHlpIsAvail = 1; } else { csHlpIsAvail = -1; } } return (csHlpIsAvail > 0); }
int EXP_LVL1 CS_setHelpPath (const char *path) { CS_stncp (csHelpFile,path,sizeof (csHelpFile)); if (CS_access (path,4) != 0) return FALSE; csHlpIsAvail = 1; return TRUE; }
int EXP_LVL7 CS_tmpfn (char *tmp_fnm) { extern char cs_Dir []; extern char *cs_DirP; char cc_save; int count; char *cp; /* Establish the drive and the directory. */ cc_save = *cs_DirP; *cs_DirP = '\0'; cp = CS_stcpy (tmp_fnm,cs_Dir); *cs_DirP = cc_save; /* Add a file name. */ cp = CS_stcpy (cp,"DEL_ME.$"); /* Add an extension which will make this file unique in the directory. Hopefully, we will never need to iterate more than once since tempoary files should always be deleted after their use. */ count = 0; strcpy (unique,"ZZ"); do { count++; if (count >= 676) { CS_erpt (cs_TMPFN_MAXED); return (-1); } /* Bump the unique portion of the name by one, wrapping arround if necessary. */ if (unique [1] >= 'Z') { unique [1] = 'A'; if (unique [0] >= 'Z') { unique [0] = 'A'; } else unique [0]++; } else unique [1]++; /* Add the unique two character name generated above to the result. */ (void) CS_stcpy (cp,unique); /* We continue generating names until we find one that doesn't exist. In this case, access does just what we need it to. */ } while (CS_access (tmp_fnm,0) == 0); /* If we get here, we have made a unique name. */ return (0); }
void CcsDataDir::OnOK () { char *cp; CWnd *wp; char ctemp [MAXPATH]; if (!UpdateData (TRUE)) return; // Check the provided data. cp = CS_stncp (ctemp,m_DataDirectory,sizeof(ctemp)); if (strlen (ctemp) < 3 || ctemp [1] != ':') { AfxMessageBox ("Full path to a directory must be provided."); wp = GetDlgItem (IDC_MPDR_DIRECTORY); if (wp != NULL) GotoDlgCtrl (wp); return; } if (*(cp - 1) == '\\') { cp -= 1; *cp = '\0'; } if (CS_access (ctemp,0) != 0) { AfxMessageBox ("Directory provided does not exist."); wp = GetDlgItem (IDC_MPDR_DIRECTORY); if (wp != NULL) GotoDlgCtrl (wp); return; } *cp++ = '\\'; strcpy (cp,(LPCTSTR)m_CSName); if (CS_access (ctemp,4) != 0) { AfxMessageBox ("Coordinate System dictionary file with name provided\ndoes not exist in directory provided."); wp = GetDlgItem (IDC_MPDR_CSNAME); if (wp != NULL) GotoDlgCtrl (wp); return; } strcpy (cp,(LPCTSTR)m_DtName); if (CS_access (ctemp,4) != 0) { AfxMessageBox ("Datum dictionary file with name provided\ndoes not exist in directory provided."); wp = GetDlgItem (IDC_MPDR_DTNAME); if (wp != NULL) GotoDlgCtrl (wp); return; } strcpy (cp,(LPCTSTR)m_ElName); if (CS_access (ctemp,4) != 0) { AfxMessageBox ("Ellipsoid dictionary file with name provided\ndoes not exist in directory provided."); wp = GetDlgItem (IDC_MPDR_ELNAME); if (wp != NULL) GotoDlgCtrl (wp); return; } // If we are still here, it all checks out. We save the stuff in the proper // locations. CS_csfnm (m_CSName); CS_dtfnm (m_DtName); CS_elfnm (m_ElName); CS_altdr (m_DataDirectory); #ifdef __SKIP__ if (m_SaveInRegistry) { long reg_st; HKEY strtKey = HKEY_LOCAL_MACHINE; HKEY softKey = 0; HKEY mntrKey = 0; HKEY trlnKey = 0; HKEY vrsnKey = 0; reg_st = RegOpenKeyEx (strtKey,cs_RKeySoftware,0,KEY_SET_VALUE,&softKey); if (reg_st == ERROR_SUCCESS) { reg_st = RegOpenKeyEx (softKey,cs_RKeyCompany,0,KEY_SET_VALUE,&mntrKey); RegCloseKey (softKey); } if (reg_st == ERROR_SUCCESS) { reg_st = RegOpenKeyEx (mntrKey,cs_RKeyProduct,0,KEY_SET_VALUE,&trlnKey); RegCloseKey (mntrKey); } if (reg_st == ERROR_SUCCESS) { reg_st = RegOpenKeyEx (trlnKey,cs_RKeyVersion,0,KEY_SET_VALUE,&vrsnKey); RegCloseKey (trlnKey); } if (reg_st == ERROR_SUCCESS) { char uctemp [MAXPATH]; strcpy (uctemp,(LPCTSTR)m_DataDirectory); reg_st = RegSetValueEx (vrsnKey,"DataDir",0,REG_SZ,(unsigned char*)uctemp,strlen (uctemp)); if (reg_st == ERROR_SUCCESS) { strcpy (uctemp,(LPCTSTR)m_CSName); reg_st = RegSetValueEx (vrsnKey,"CSName",0,REG_SZ,(unsigned char*)uctemp,strlen (uctemp)); } if (reg_st == ERROR_SUCCESS) { strcpy (uctemp,(LPCTSTR)m_DtName); reg_st = RegSetValueEx (vrsnKey,"DtName",0,REG_SZ,(unsigned char *)uctemp,strlen (uctemp)); } if (reg_st == ERROR_SUCCESS) { strcpy (uctemp,(LPCTSTR)m_ElName); reg_st = RegSetValueEx (vrsnKey,"ElName",0,REG_SZ,(unsigned char *)uctemp,strlen (uctemp)); } RegCloseKey (vrsnKey); } } if (m_SaveInINI) { BOOL ok; char ctemp [MAXPATH]; CS_stncp (ctemp,theApp.m_FullPath,sizeof (ctemp)); cp = strrchr (ctemp,'.'); if (cp == NULL) return; strcpy (cp,".INI"); if (CS_access (ctemp,0) != 0) { FILE* fstr = fopen (ctemp,"w"); fclose (fstr); } if (CS_access (ctemp,2) != 0) { AfxMessageBox ("Write permission to .INI file has been denied."); return; } ok = WritePrivateProfileString ("Directories","DataDir",(LPCTSTR)m_DataDirectory,ctemp); if (ok) ok = WritePrivateProfileString ("Directories","CSName",(LPCTSTR)m_CSName,ctemp); if (ok) ok = WritePrivateProfileString ("Directories","DtName",(LPCTSTR)m_DtName,ctemp); if (ok) ok = WritePrivateProfileString ("Directories","ElName",(LPCTSTR)m_ElName,ctemp); } #endif CS_recvr (); CDialog::OnOK (); return; }
int CSjapanQ (struct csGeodeticXfromParmsFile_* fileParms,Const char* dictDir,int err_list [],int list_sz) { extern char cs_DirsepC; extern char cs_ExtsepC; int err_cnt; char *cp; csFILE* strm; char meshCode [] = "Meshcode"; char line1Buffer [256]; char line2Buffer [256]; char line3Buffer [256]; char pathBuffer [MAXPATH]; cp = fileParms->fileName; if (*cp == '.' && *(cp + 1) == cs_DirsepC) { CS_stncp (pathBuffer,dictDir,sizeof (pathBuffer)); CS_stncat (pathBuffer,cp,MAXPATH); } else { CS_stncp (pathBuffer,cp,MAXPATH); } /* We will return (err_cnt + 1) below. */ err_cnt = -1; if (err_list == NULL) list_sz = 0; /* Verify that the file exists and that the format appears to be correct. */ strm = CS_fopen (pathBuffer,_STRM_TXTRD); if (strm != NULL) { CS_fgets (line1Buffer,sizeof (line1Buffer),strm); CS_fgets (line2Buffer,sizeof (line2Buffer),strm); CS_fgets (line3Buffer,sizeof (line3Buffer),strm); CS_fclose (strm); strm = NULL; if (!CS_stristr (line1Buffer,meshCode) && !CS_stristr (line2Buffer,meshCode) && !CS_stristr (line3Buffer,meshCode)) { /* The pohrase meshcode was not found anywhere on the first three lines, we assume this is not a ".par" file. */ if (++err_cnt < list_sz) err_list [err_cnt] = cs_DTQ_FORMAT; } } else { //the txt file didn't exist - so, check whether at least the binary file does cp = strrchr (pathBuffer,cs_ExtsepC); if (cp == NULL) { if (++err_cnt < list_sz) err_list [err_cnt] = cs_DTQ_FILE; } else { CS_stcpy ((cp + 1),"_par"); if (0 != CS_access(pathBuffer, 4)) { if (++err_cnt < list_sz) err_list [err_cnt] = cs_DTQ_FILE; } } } return (err_cnt + 1); }
int main (int argc,char *argv []) { extern char cs_Dir []; extern char* cs_DirP; extern char cs_Csname []; extern char cs_Dtname []; extern char cs_Elname []; int cmpVal, iTmp; int csDiffCnt, dtDiffCnt, elDiffCnt; int dummy; int nlFlag; csFILE *wasStrm, *isStrm; char wasDir [MAXPATH]; char isDir [MAXPATH]; char errorText [260]; struct cs_Csdef_ wasCsDef, isCsDef; struct cs_Dtdef_ wasDtDef, isDtDef; struct cs_Eldef_ wasElDef, isElDef; csDiffCnt = 0; dtDiffCnt = 0; elDiffCnt = 0; if (argc != 3) Usage (); strncpy (wasDir,argv [1],sizeof (wasDir)); wasDir [sizeof (wasDir) - 1] = '\0'; strncpy (isDir,argv [2],sizeof (isDir)); isDir [sizeof (isDir) - 1] = '\0'; if (CS_altdr (wasDir) != 0) { printf ("%s file not found in %s directory.\n",cs_Csname,wasDir); Usage (); } CS_stcpy (cs_DirP,cs_Dtname); if (CS_access (cs_Dir,4) != 0) { printf ("%s file not found in %s directory.\n",cs_Dtname,wasDir); Usage (); } CS_stcpy (cs_DirP,cs_Elname); if (CS_access (cs_Dir,4) != 0) { printf ("%s file not found in %s directory.\n",cs_Elname,wasDir); Usage (); } if (CS_altdr (isDir) != 0) { printf ("%s file not found in %s directory.\n",cs_Csname,isDir); Usage (); } CS_stcpy (cs_DirP,cs_Dtname); if (CS_access (cs_Dir,4) != 0) { printf ("%s file not found in %s directory.\n",cs_Dtname,isDir); Usage (); } CS_stcpy (cs_DirP,cs_Elname); if (CS_access (cs_Dir,4) != 0) { printf ("%s file not found in %s directory.\n",cs_Elname,isDir); Usage (); } /* Ok, we're ready to do our thing. Do coordinate systems first. */ CS_altdr (wasDir); /*lint !e534 */ wasStrm = CS_csopn (_STRM_BINRD); if (wasStrm == NULL) { printf ("Open of %s in the 'WAS' directory failed.\n",cs_Csname); Usage (); } CS_altdr (isDir); /*lint !e534 */ isStrm = CS_csopn (_STRM_BINRD); if (isStrm == NULL) { printf ("Open of %s in the 'IS' directory failed.\n",cs_Csname); Usage (); } /* Now, we loop through the dictionaries. In this module, we simply compare key names, looking for new definitions, or deleted definitions. When we have definitions with the same name, we call CS_csDiff to report any differences. First, we prime the pump. */ iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'WAS' coordinate system dictionary is empty.\n"); Usage (); } iTmp = CS_csrd (isStrm,&isCsDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'IS' coordinate system dictionary is empty.\n"); Usage (); } nlFlag = FALSE; while (TRUE) { cmpVal = CS_stricmp (wasCsDef.key_nm,isCsDef.key_nm); if (cmpVal < 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from coordinate system dictionary!!!\n",wasCsDef.key_nm); csDiffCnt += 1; } else if (cmpVal > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to coordinate system dictionary!!!\n",isCsDef.key_nm); csDiffCnt += 1; } else { /* Normal case, we have two definitions with the same name, */ iTmp = CS_csDiff (stdout,&wasCsDef,&isCsDef); if (iTmp != 0) { csDiffCnt += 1; nlFlag = TRUE; } } if (cmpVal >= 0) { iTmp = CS_csrd (isStrm,&isCsDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; break; } } if (cmpVal <= 0) { iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; break; } } } /* Finish up properly. */ nlFlag = TRUE; while (wasStrm != NULL) { iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from coordinate system dictionary!!!\n",wasCsDef.key_nm); csDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } while (isStrm != NULL) { iTmp = CS_csrd (isStrm,&wasCsDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to coordinate system dictionary!!!\n",isCsDef.key_nm); csDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } if (csDiffCnt == 0) { printf ("\nCoordinate system dictionaries are the same.\n\n"); } else { printf ("\n%d coordinate systems are different.\n\n",csDiffCnt); } /* Done with the coordinate system dictionary. Same as above, but with the Datum Dictionary this time. */ CS_altdr (wasDir); /*lint !e534 */ wasStrm = CS_dtopn (_STRM_BINRD); if (wasStrm == NULL) { printf ("Open of %s in the 'WAS' directory failed.\n",cs_Dtname); Usage (); } CS_altdr (isDir); /*lint !e534 */ isStrm = CS_dtopn (_STRM_BINRD); if (isStrm == NULL) { printf ("Open of %s in the 'IS' directory failed.\n",cs_Dtname); Usage (); } iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'WAS' datum dictionary is empty.\n"); Usage (); } iTmp = CS_dtrd (isStrm,&isDtDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'IS' datum dictionary is empty.\n"); Usage (); } nlFlag = FALSE; while (TRUE) { cmpVal = CS_stricmp (wasDtDef.key_nm,isDtDef.key_nm); if (cmpVal < 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from datum dictionary!!!\n",wasDtDef.key_nm); dtDiffCnt += 1; } else if (cmpVal > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to datum dictionary!!!\n",isDtDef.key_nm); dtDiffCnt += 1; } else { /* Normal case, we have two definitions with the same name, */ iTmp = CS_dtDiff (stdout,&wasDtDef,&isDtDef); if (iTmp != 0) { dtDiffCnt += 1; nlFlag = TRUE; } } if (cmpVal >= 0) { iTmp = CS_dtrd (isStrm,&isDtDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; break; } } if (cmpVal <= 0) { iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; break; } } } nlFlag = TRUE; while (wasStrm != NULL) { iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from datum dictionary!!!\n",wasDtDef.key_nm); dtDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } while (isStrm != NULL) { iTmp = CS_dtrd (isStrm,&wasDtDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to datum dictionary!!!\n",isDtDef.key_nm); dtDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } if (dtDiffCnt == 0) { printf ("\nDatum dictionaries are the same.\n\n"); } else { printf ("\n%d datum definitions are different.\n\n",dtDiffCnt); } /* Ellipsoid Dictionary */ CS_altdr (wasDir); /*lint !e534 */ wasStrm = CS_elopn (_STRM_BINRD); if (wasStrm == NULL) { printf ("Open of %s in the 'WAS' directory failed.\n",cs_Elname); Usage (); } CS_altdr (isDir); /*lint !e534 */ isStrm = CS_elopn (_STRM_BINRD); if (isStrm == NULL) { printf ("Open of %s in the 'IS' directory failed.\n",cs_Elname); Usage (); } iTmp = CS_elrd (wasStrm,&wasElDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'WAS' ellipsoid dictionary is empty.\n"); Usage (); } iTmp = CS_elrd (isStrm,&isElDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { printf ("'IS' ellipsoid dictionary is empty.\n"); Usage (); } nlFlag = FALSE; while (TRUE) { cmpVal = CS_stricmp (wasElDef.key_nm,isElDef.key_nm); if (cmpVal < 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from ellipsoid dictionary!!!\n",wasElDef.key_nm); elDiffCnt += 1; } else if (cmpVal > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to ellipsoid dictionary!!!\n",isElDef.key_nm); elDiffCnt += 1; } else { /* Normal case, we have two definitions with the same name, */ iTmp = CS_elDiff (stdout,&wasElDef,&isElDef); if (iTmp != 0) { elDiffCnt += 1; nlFlag = TRUE; } } if (cmpVal >= 0) { iTmp = CS_elrd (isStrm,&isElDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; break; } } if (cmpVal <= 0) { iTmp = CS_elrd (wasStrm,&wasElDef,&dummy); if (iTmp < 0) { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; break; } } } nlFlag = TRUE; while (wasStrm != NULL) { iTmp = CS_elrd (wasStrm,&wasElDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s deleted from ellipsoid dictionary!!!\n",wasElDef.key_nm); elDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (wasStrm); wasStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } while (isStrm != NULL) { iTmp = CS_elrd (isStrm,&wasElDef,&dummy); if (iTmp > 0) { if (nlFlag) { printf ("\n"); nlFlag = FALSE; } printf ("%s added to ellipsoid dictionary!!!\n",isElDef.key_nm); dtDiffCnt += 1; } else if (iTmp == 0) { CS_fclose (isStrm); isStrm = NULL; } else { CS_errmsg (errorText,sizeof (errorText)); printf ("%s\n",errorText); Usage (); } } if (elDiffCnt == 0) { printf ("\nEllipsoid dictionaries are the same.\n\n"); } else { printf ("\n%d ellipsoid definitions are different.\n\n",elDiffCnt); } return 0; }