home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / CHIPCD_3_98.iso / software / share / sharmies / unixdos / data.z / diff6a.txt < prev    next >
Text File  |  1997-11-18  |  13KB  |  349 lines

  1. #include "RGSTDAFX.H"
  2.  
  3. #ifndef __RMDEF_HPP
  4. #include "rmdef.hpp"
  5. #endif
  6.  
  7. #include "cfuncs.hpp"                                                                                   // This is a global C funtion man.
  8.  
  9. CObject* CreateRuntimeClassObject( char* szClassName )
  10. {
  11.   CRuntimeClass* pClassRef = FindRuntimeClass( szClassName, 0 );
  12.   if ( pClassRef )
  13.     {
  14.     // allocate a new object based on the class just acquired
  15.     CObject* object = pClassRef->CreateObject();
  16.     if (object == NULL)
  17.       AfxThrowMemoryException();
  18.     return object; 
  19.     }           
  20.   else
  21.     return NULL;
  22. }
  23.  
  24. CRuntimeClass* PASCAL FindRuntimeClass( char* szClassName, UINT* pwSchemaNum)
  25. {
  26.   CRuntimeClass* pClass;
  27.  
  28. #ifndef _AFXDLL
  29.   for (pClass = CRuntimeClass::pFirstClass; pClass != NULL; pClass = pClass->m_pNextClass)
  30.   {
  31.     if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  32.       return pClass;
  33.   }
  34. #else
  35.   // all registered CRuntimeClasses should be owned by the app or a DLL
  36.   ASSERT(CRuntimeClass::pFirstClass == NULL);
  37.  
  38.   // first walk through the app specific classes
  39.   for (pClass = _AfxGetAppData()->pFirstAppClass; pClass != NULL;
  40.     pClass = pClass->m_pNextClass)
  41.   {
  42.     if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  43.       return pClass;
  44.   }
  45.   // now walk through the classes in different DLLs
  46.   CDynLinkLibrary* pDLL;
  47.   for (pDLL = _AfxGetAppData()->pFirstDLL; pDLL != NULL;
  48.     pDLL = pDLL->m_pNextDLL)
  49.   {
  50.     for (pClass = pDLL->m_pFirstSharedClass; pClass != NULL;
  51.       pClass = pClass->m_pNextClass)
  52.     {
  53.       if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  54.         return pClass;
  55.     }
  56.   }
  57. #endif //_AFXDLL
  58.  
  59.   return NULL; // not found
  60. }
  61.  
  62. void GetOwnerNameFromDisplay( CString &displayString, CString &owner, CString &name )
  63. {
  64.   // Takes strings in format "name(owner)" and makes a owner and a name.
  65.   
  66.   owner.Empty();
  67.   name.Empty();
  68.   
  69.   if ( !displayString.IsEmpty() )
  70.     {
  71.     // Put into proper format.
  72.     int pos = displayString.Find( '(' );
  73.     CString tempOwner = displayString.Right( displayString.GetLength() - pos );
  74.     CString tempName  = displayString.Left( pos );
  75.   
  76.     // Get rid of parens and spaces for owner.
  77.     for( int i=0; i<tempOwner.GetLength(); i++ )
  78.       {
  79.       if ( tempOwner[i] != '(' && tempOwner[i] != ')' && tempOwner[i] != ' ' )
  80.         {
  81.         owner += tempOwner[i];
  82.         }
  83.       }
  84.     // Ditto for name.
  85.     for( i=0; i<tempName.GetLength(); i++ )
  86.       {
  87.       if ( tempName[i] != '(' && tempName[i] != ')' && tempName[i] != ' ' )
  88.         {
  89.         name += tempName[i];
  90.         }
  91.       }
  92.     }
  93. }
  94.  
  95. void GetTempDirectory( CString & pathName, CString & aFileName )
  96. {
  97.   // buffer to compare to find temp
  98.   char    firstfour[6];
  99.   
  100.   // get and hold the dos env. don't change anything!!
  101.   LPSTR   lpszEnv = ::GetDOSEnvironment();
  102.  
  103.   pathName.Empty();
  104.  
  105.   // Get the temp directory.
  106.   while ( *lpszEnv!=0 && pathName.IsEmpty() ) 
  107.     {
  108.     int len = lstrlen(lpszEnv);
  109.     lstrcpyn( firstfour, lpszEnv, ((len>5)?5:len) );
  110.     if ( !lstrcmpi( "temp", firstfour ) )
  111.       {
  112.       pathName = (const char*)&lpszEnv[5];
  113.       }
  114.     lpszEnv += len + 1;
  115.     }
  116.     
  117.   // If we didn't find the temp, use the windows dir.  
  118.   if ( pathName.IsEmpty() )
  119.     {
  120.     char * buf = new char[8000];
  121.     ::GetWindowsDirectory( buf, 8000 );
  122.     pathName = (const char *)buf;
  123.     delete [] buf;
  124.     }
  125.       
  126.   if ( !aFileName.IsEmpty() )
  127.     {
  128.     // caller wants a pathName appended.
  129.     if ( pathName[pathName.GetLength()-1] != '\\' )
  130.       {
  131.       pathName += '\\';
  132.       }
  133.     pathName += aFileName;
  134.     }
  135. }
  136.  
  137. int GetOsys_Val = -1;
  138.  
  139. #define WF_WINNT  0x4000
  140. #define WF_WIN95  0x2000
  141.  
  142. //****** RETURN OPERATING SYSTEM ENVIRONMENT ********************************//
  143. // AUTHOR:   Madhur Eichberger                                               //
  144. //                                                                           //
  145. // OBJECTIVE:                                                                //
  146. // Determine the current operation system environment                        //
  147. //                                                                           //
  148. // ARGUMENTS:                                                                //
  149. //                                                                           //
  150. // OUTPUT:                                                                   //
  151. // ret: OS_WIN31 Windows 3.1                                                 //
  152. // ret: OS_WIN95 Windows 95                                                  //
  153. // ret: OS_WINNT Windows NT                                                  //
  154. //                                                                           //
  155. // CREATED   07/18/95 MADHUR EICHBERGER                                      //
  156. //***************************************************************************//
  157. int GetOsys()
  158. {
  159. DWORD dwVersion;
  160. int ret;
  161.  
  162.     //****** CHECK IF FIRST TIME **********************************************
  163.     if (GetOsys_Val > 0)
  164.         return(GetOsys_Val);
  165.     
  166.     //****** CHECK FLAGS FOR OPERATION SYSTEM *********************************
  167.     dwVersion = GetWinFlags();
  168.     ret = OS_WIN31;     // assume win 3.11
  169.     if ((dwVersion & WF_WINNT) != 0) ret = OS_WINNT;
  170.     if ((dwVersion & WF_WIN95) != 0) ret = OS_WIN95;
  171.     GetOsys_Val = ret;  // save for direct access next time
  172. TRACE("GetOsys: ret=%d, GetWinFlags: 0x%lX",ret,dwVersion);
  173.     return(ret);
  174. }
  175.  
  176. /****** COUNT NUMBER OF ARGUMENTS IN DELIMITTED STRING ***********************/
  177. /* Input:                                                                    */
  178. /* str               = string containing all arguments separated with delim  */
  179. /*                     (no limit on the length !)                            */
  180. /* del               = delimiter character                                   */
  181. /*                                                                           */
  182. /* Output:                                                                   */
  183. /* number of arguments                                                       */
  184. /*****************************************************************************/
  185. int strcnt(char *str,char del)
  186. {
  187. char *p1, *pmax;
  188. int cntarg;
  189.  
  190.     cntarg = 0;                                    /* reset argument counter */
  191.     pmax = str + strlen(str) - 1;                    /* goto to end of input */
  192.     if (del != ' ') while((pmax >= str)&&(*pmax == ' ')) pmax--; /* cut blanks*/
  193.     p1 = str;
  194.     while ( (p1 <= pmax) && (*p1 == ' ') ) p1++;       /* skip leading blanks */
  195.     while (p1 <= pmax)
  196.         {
  197.         if ((p1 == pmax) && (*p1 != del)) cntarg++; /* simulate last delimter */
  198.         if ((del == ' ') && (*p1 == del) && (*(p1+1) == ' ')) cntarg--; /*skip*/
  199.         if (*(p1++) == del) cntarg++;              /* count normal delimiter */
  200.         }
  201.     return(cntarg);
  202. }
  203. #define MAXSTRARG    100
  204.  
  205. /****** SELECT ARGUMENT FROM ARGUMENT LIST (DIRECT OUTPUT) *******************/
  206. /* Input:                                                                    */
  207. /* str               = argument list input (no limit on length)              */
  208. /* del               = delimiter character between arguments in 'str'        */
  209. /* start             = first argument to be selected for output              */
  210. /*                     1  = first argument in list                           */
  211. /*                     -1 = last  argument in list (counted from back)       */
  212. /*                     maximal 100 arguments (MAXSTRARG)                     */
  213. /* stop              = last argument to be selected for output               */
  214. /*                     (can be negative if from back)                        */
  215. /* out               = output buffer (limit depending on your allocation)    */ 
  216. /* out_le            = output buffer limit                                   */ 
  217. /*                                                                           */
  218. /*                                                                           */
  219. /* Output:                                                                   */
  220. /* >=0               = number of bytes in out                                */
  221. /* -1                = invalid start stop specification                      */
  222. /*****************************************************************************/
  223. int strfld(char *str,char del,int start,int stop,char *out,int out_le)
  224. {
  225. register char *p;
  226. int i, i1, i2, nmax, cntarg, off[MAXSTRARG + 1];
  227.  
  228.     /****** CHECK IF VALID RANGE ********************************************/
  229.     out[0] = '\0';
  230.     if (stop == 0) stop = start;
  231.     if( ((start>0) && (start>stop)) || ((start<0) && (start>stop))) return(-1);
  232.     
  233.     /****** GET ACTUAL ARGUMENTS ********************************************/
  234.     cntarg = strcnt(str,del);           /* get real number of args          */
  235.     if( (start ==  99) && (start > cntarg   ))
  236.         {
  237.         start = cntarg;
  238.         }
  239.     if( (start == -99) && (start < (-cntarg)))
  240.         {
  241.         start = -cntarg;
  242.         }
  243.     if (abs(start) > cntarg) return(-2);
  244.  
  245.     /****** ADJUST START/STOP ***********************************************/
  246.     if( stop > cntarg ) stop  = cntarg;
  247.     if( (stop < 0) && (stop < (-cntarg))) stop  = -cntarg;
  248.     if( start < 0) i1 = cntarg - abs(stop) + 1;
  249.     if( stop  < 0) i2 = cntarg - abs(start) + 1;
  250.     if( start < 0) start = i2;
  251.     if( stop  < 0) stop  = i1;
  252.  
  253.     /****** BUILD OFFSET LIST ***********************************************/
  254.     p = str;
  255.     if( del == ' ')                     /* skip leading blanks              */
  256.         {
  257.         while (*p == ' ') p++;             
  258.         }
  259.     off[1] = 0;                         /* set the first arg offset         */
  260.     i1 = 2;
  261.     nmax = strlen(p);
  262.     for( i = 0; i < nmax; i++)
  263.         {
  264.         if( p[i] == del)                /* delimitter found (pack blanks)   */
  265.             {
  266.             if (del != ' ')
  267.                 {
  268.                 off[i1++] = i + 1;
  269.                 }
  270.             else{
  271.                 if( p[i+1] != del)     /* pack */
  272.                     {
  273.                         off[i1++] = i + 1;
  274.                     }
  275.                 }
  276.             }
  277.         }
  278.     off[i1] = i;                        /* save last byte */
  279.  
  280.     /****** EXTRACT SPECIFIED FIELDS ******************************************/
  281.     i1 = 0;                             /* reset output buffer counter */
  282.     for( i = off[start]; i < (off[stop + 1]); i++)
  283.         {
  284.         if( i1 >= out_le) break;
  285.         out[i1++] = p[i];
  286.         }
  287.     if( out[i1 - 1] == del)             /* supress last delimitter */
  288.         {
  289.         i1--;
  290.         }
  291.     out[i1] = '\0';                     /* set string termination  */
  292.     start = stop = 0;                   /* reset the arguments     */
  293.     return(strlen(out));
  294. }
  295.  
  296. void GetMatrixCellTitle(char *szTitle,int nRow,int nCol)
  297. {
  298.     int nID = nRow*100 + nCol;
  299.     switch (nID)
  300.     {
  301.     case 0*100 + 0: strcpy(szTitle,"Blank");                   break;
  302.     case 0*100 + 1: strcpy(szTitle,"Column Cell Header");      break;
  303.     case 0*100 + 2: strcpy(szTitle,"Column Total Header");     break;
  304.     case 0*100 + 3: strcpy(szTitle,"Column Grand Total Header"); break;
  305.                        
  306.     case 1*100 + 0: strcpy(szTitle,"Row Header");              break;
  307.     case 1*100 + 1: strcpy(szTitle,"Intersection");            break;
  308.     case 1*100 + 2: strcpy(szTitle,"Column Total");            break;
  309.     case 1*100 + 3: strcpy(szTitle,"Grand Total");             break;
  310.  
  311.     case 2*100 + 0: strcpy(szTitle,"Row Total Header");        break;
  312.     case 2*100 + 1: strcpy(szTitle,"Row Total");               break;
  313.     case 2*100 + 2: strcpy(szTitle,"Row Grand Total");         break;
  314.     case 2*100 + 3: strcpy(szTitle,"Final Grand Total");       break;
  315.  
  316.     default:       strcpy(szTitle,"Matrix Body");              break;
  317.     }
  318. }
  319.  
  320. void GetAggrText(char *szAggr,int nAggr)
  321. {
  322.     switch (nAggr)
  323.     {
  324.     case REP_MX_AGGR_NONE: strcpy(szAggr,REP_MX_AGGR_NONE_TXT);  break;
  325.     case REP_MX_AGGR_CNT : strcpy(szAggr,REP_MX_AGGR_CNT_TXT );  break;
  326.     case REP_MX_AGGR_SUM : strcpy(szAggr,REP_MX_AGGR_SUM_TXT );  break;
  327.     case REP_MX_AGGR_AVG : strcpy(szAggr,REP_MX_AGGR_AVG_TXT );  break;
  328.     case REP_MX_AGGR_MIN : strcpy(szAggr,REP_MX_AGGR_MIN_TXT );  break;
  329.     case REP_MX_AGGR_MAX : strcpy(szAggr,REP_MX_AGGR_MAX_TXT );  break;
  330.     case REP_MX_AGGR_MEAN: strcpy(szAggr,REP_MX_AGGR_MEAN_TXT);  break;
  331.     default              : sprintf(szAggr,"AGGR%02d",nAggr);     break;
  332.     }
  333. }
  334.  
  335. int GetAggrCode(char *szAggr)
  336. {
  337. int ret;
  338.  
  339.     ret = REP_MX_AGGR_NONE;
  340.     if (strcmp(szAggr,REP_MX_AGGR_CNT_TXT ) == 0) ret = REP_MX_AGGR_CNT;
  341.     if (strcmp(szAggr,REP_MX_AGGR_SUM_TXT ) == 0) ret = REP_MX_AGGR_SUM;
  342.     if (strcmp(szAggr,REP_MX_AGGR_AVG_TXT ) == 0) ret = REP_MX_AGGR_AVG;
  343.     if (strcmp(szAggr,REP_MX_AGGR_MIN_TXT ) == 0) ret = REP_MX_AGGR_MIN;
  344.     if (strcmp(szAggr,REP_MX_AGGR_MAX_TXT ) == 0) ret = REP_MX_AGGR_MAX;
  345.     if (strcmp(szAggr,REP_MX_AGGR_MEAN_TXT) == 0) ret = REP_MX_AGGR_MEAN;
  346.     return(ret);
  347. }
  348.  
  349.