home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / APPLAUNC.PAK / APPMGR.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  3KB  |  118 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\buttonga.h>
  6. #include <stdlib.h>
  7. #include "appmgr.h"
  8.  
  9. //
  10. // Constructor. Create an app rec from a string.  The string consists of
  11. // fields separated by ';'.  Here is the format:
  12. //  <program path>;<program args>;<icon path>;<prompt for input>;<startup opts>
  13. // If the format is not correct an error state is set.
  14. //
  15. TAppRec::TAppRec(const string& rec)
  16. {
  17.   // holds each field of the record.
  18.   //
  19.   char*       pp;
  20.   char*       pa;
  21.   char*       ip;
  22.   char*       pfi;
  23.   char*       ss;
  24.   char*       temp = new char[rec.length()+1];
  25.   string      nullStr;
  26.  
  27.   Error = 0;
  28.   strcpy(temp, rec.c_str());
  29.   if ((pp = strtok(temp, ";")) != 0 &&
  30.       (pa = strtok(0, ";")) != 0 &&
  31.       (ip = strtok(0, ";")) != 0 &&
  32.       (pfi= strtok(0, ";")) != 0 &&
  33.       (ss = strtok(0, ";")) != 0 ) {
  34.     ProgramPath = pp;
  35.     ProgramArgs = pa;
  36.     IconPath = ip;
  37.     PromptForInput = atoi(pfi);
  38.     StartupStyle = atoi(ss);
  39.     Error = (StartupStyle != 1 && StartupStyle != 2 && StartupStyle != 3);
  40.   } else
  41.     Error = 1;
  42.  
  43.   delete temp;
  44. }
  45.  
  46. //
  47. // ReturnAsString().  Contatenate a TAppRec's values into a string and return
  48. // it.  Any empty (or null) fields are converted to 1 space strings for
  49. // easier manipulation later.
  50. //
  51. string
  52. TAppRec::AsString()
  53. {
  54.   char        num[5];
  55.   string      empty(" ");
  56.   string      str;
  57.  
  58.   str = ProgramPath + ";";
  59.   str += ProgramArgs.is_null() ? empty : ProgramArgs;
  60.   str += ";";
  61.   str += IconPath.is_null() ? empty : IconPath;
  62.   str += ";";
  63.   itoa(PromptForInput, num, 10);
  64.   str += num;
  65.   str += ";";
  66.   itoa(StartupStyle, num, 10);
  67.   str += num;
  68.  
  69.   return str;
  70. }
  71.  
  72. //
  73. // GetIconPath().  Return the path to the icon for current app through
  74. // 'iconPath'.  If the 'IconPath' member is not empty use it, else use
  75. // program path.
  76. //
  77. string
  78. TAppRec::GetIconPath()
  79. {
  80.   string iconPath = ProgramPath;
  81.   if (!IconPath.is_null() && IconPath[0] != ' ')
  82.     iconPath = IconPath;
  83.   return iconPath;
  84. }
  85.  
  86. //////////////////////////////////////////////////////////////////////
  87.  
  88. //
  89. // Assignment operator.  Copy recs to recieving object.
  90. //
  91. TAppMgr&
  92. TAppMgr::operator =(const TAppMgr& am)
  93. {
  94.   unsigned  end = am.Limit();
  95.  
  96.   for (unsigned i = 0; i < end; i++) {
  97.     if (am[i] != 0)
  98.       Add(new TAppRec(*am[i]));
  99.   }
  100.   return *this;
  101. }
  102.  
  103. //
  104. // AddFromString(). Parses given string into a TAppRec and stores it.
  105. // Assumes the string contains the correct info. Does check for correct
  106. // number of items.
  107. //
  108. int
  109. TAppMgr::AddFromString(const string& rec, unsigned loc)
  110. {
  111.   TAppRec* appRec = new TAppRec(rec);
  112.  
  113.   if (!appRec->IsBad())
  114.     return AddAt(appRec, loc);
  115.   return 0;
  116. }
  117.  
  118.