bool ListDuplicateDefinitions (const wchar_t* listPath,const wchar_t* dictDir) { bool ok (false); int st; std::wofstream listStrm (listPath,std::ios_base::out | std::ios_base::trunc); ok = listStrm.is_open (); if (ok) { char dictDirC [1024]; wcstombs (dictDirC,dictDir,sizeof (dictDirC)); st = CS_altdr (dictDirC); ok = (st == 0); } if (ok) { ok = ListDuplicateCS (listStrm); } //if (ok) //{ // ok = ListDuplicateDT (listStrm); //} //if (ok) //{ // ok = ListDuplicateEL (listStrm); //} listStrm.close (); return ok; }
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 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; }