home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / APPLAUNC.PAK / APPMGR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.9 KB  |  119 lines

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