home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / wf_expl / writeprj.c < prev   
Text File  |  1992-05-02  |  9KB  |  223 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*                                                                          */
  5. /* COPYRIGHT IBM CORP., 1992                                                */
  6. /*                                                                          */
  7. /* ------------------------------------------------------------------------ */
  8. /*                                                                          */
  9. /*                                                                          */
  10. /*   WriteProject                                                           */
  11. /*                                                                          */
  12. /*      Function to create a new PRJ file                                   */
  13. /*                                                                          */
  14. /*   Parameters:                                                            */
  15. /*                                                                          */
  16. /*      PSZ    projname     -  fully qualified file name                    */
  17. /*      PSZ    projdesc     -  description                                  */
  18. /*      PSZ    directory    -  fully qualified directory name               */
  19. /*      PSZ    exename      -  exe (unqualified)                            */
  20. /*      PSZ    makename     -  make file name (unqualified)                 */
  21. /*      void * compopts     -  NULL                                         */
  22. /*      USHORT compsize     -  0                                            */
  23. /*      void * linkopts     -  NULL                                         */
  24. /*      USHORT linksize     -  0                                            */
  25. /*      void * projlang     -  language eyecatcher                          */
  26. /*      USHORT projlangsize -  language eyecatcher size                     */
  27. /*      void * runopts      -  NULL                                         */
  28. /*      USHORT runsize      -  0                                            */
  29. /*      void * makeopts     -  NULL                                         */
  30. /*      USHORT makesize     -  0                                            */
  31. /*      void * debugopts    -  NULL                                         */
  32. /*      USHORT debugsize    -  0                                            */
  33. /*      PSZ    mask         -  "*.*"                                        */
  34. /*      BOOL   old          -  Reserved                                     */
  35. /*                                                                          */
  36. /*   Returns:                                                               */
  37. /*                                                                          */
  38. /*    MSG_THREAD_OUT_OF_MEMORY -  MEMORY ERROR                              */
  39. /*    MSG_FILE_ERROR           -  FILE ERROR                                */
  40. /*    MSG_NO_ERROR             -  NO ERROR                                  */
  41. /*                                                                          */
  42. /****************************************************************************/
  43.  
  44. #define MSG_NO_ERROR 0
  45. #define MSG_FILE_ERROR 8
  46. #define MSG_THREAD_OUT_OF_MEMORY 256
  47.  
  48. USHORT WriteProject( PSZ    projname,
  49.                      PSZ    projdesc,
  50.                      PSZ    directory,
  51.                      PSZ    exename,
  52.                      PSZ    makename,
  53.                      void * compopts,
  54.                      USHORT compsize,
  55.                      void * linkopts,
  56.                      USHORT linksize,
  57.                      void * projlang,
  58.                      USHORT projlangsize,
  59.                      void * runopts,
  60.                      USHORT runsize,
  61.                      void * makeopts,
  62.                      USHORT makesize,
  63.                      void * debugopts,
  64.                      USHORT debugsize,
  65.                      PSZ    mask,
  66.                      BOOL   old)
  67.    {
  68.    char * work;
  69.    char * workstart;
  70.    HFILE  outfile;
  71.    USHORT ActionTaken;
  72.    USHORT descsize,
  73.           dirsize,
  74.           exesize,
  75.           maksize,
  76.           masksize;
  77.    USHORT SizeRequired,  
  78.           rc;
  79.    int    byteswritten;
  80.  
  81.    descsize     = strlen(projdesc)+1;
  82.    dirsize      = strlen(directory)+1;
  83.    exesize      = strlen(exename)+1;
  84.    maksize      = strlen(makename)+1;
  85.    masksize     = strlen(mask)+1;
  86.    SizeRequired = descsize+dirsize+exesize+maksize+
  87.                   masksize+compsize+linksize+projlangsize+
  88.                   runsize+makesize+debugsize+14;
  89.  
  90.    work = malloc(SizeRequired);
  91.    if (work==NULL)
  92.       {
  93.       return MSG_THREAD_OUT_OF_MEMORY;
  94.       }
  95.  
  96.    workstart=work;
  97.    rc = DosOpen(projname,
  98.                 (PHFILE)&outfile,
  99.                 &ActionTaken,
  100.                 0L,                           /* FileSize            */
  101.                 0,                            /* FileAttribute       */
  102.                 OPEN_ACTION_CREATE_IF_NEW |
  103.                 OPEN_ACTION_REPLACE_IF_EXISTS,/* OpenFlag            */
  104.                 OPEN_SHARE_DENYREADWRITE  |
  105.                 OPEN_ACCESS_READWRITE,        /* OpenMode            */
  106.                 0L);                          /* ReservedDWord       */
  107.  
  108.    if (rc !=0)
  109.       {
  110.       free(workstart);
  111.       return MSG_FILE_ERROR ;
  112.       }
  113.  
  114.    /***************************************************/
  115.    /*   Store the Project type                        */
  116.    /***************************************************/
  117.    byteswritten = 0xFFFE;
  118.    memcpy(work,&byteswritten,2); 
  119.    work += 2;
  120.  
  121.    /***************************************************/
  122.    /*   Store the Project description                 */
  123.    /***************************************************/
  124.    memcpy(work,projdesc,descsize); 
  125.    work += descsize;
  126.  
  127.    /***************************************************/
  128.    /*   Store the Project directory                   */
  129.    /***************************************************/
  130.    strupr(directory);
  131.    memcpy(work,directory,dirsize);
  132.    work += dirsize;
  133.  
  134.    /***************************************************/
  135.    /*   Store the Project executable                  */
  136.    /***************************************************/
  137.    strupr(exename);
  138.    memcpy(work,exename  ,exesize);
  139.    work += exesize;
  140.  
  141.    /***************************************************/
  142.    /*   Store the Project make  file                  */
  143.    /***************************************************/
  144.    strupr(makename);
  145.    memcpy(work,makename  ,maksize);
  146.    work += maksize;
  147.  
  148.    /***************************************************/
  149.    /*   Store the Project selection mask              */
  150.    /***************************************************/
  151.    memcpy(work,mask      ,masksize);
  152.    work += masksize;
  153.  
  154.    /***************************************************/
  155.    /*   Store the Project compile options             */
  156.    /***************************************************/
  157.    memcpy(work,&compsize,2);
  158.    work +=2;
  159.    memcpy(work,compopts,compsize);
  160.    work += compsize;
  161.  
  162.    /***************************************************/
  163.    /*   Store the Project link    options             */
  164.    /***************************************************/
  165.    memcpy(work,&linksize,2);
  166.    work +=2;
  167.    memcpy(work,linkopts,linksize);
  168.    work += linksize;
  169.  
  170.    /***************************************************/
  171.    /*   Store the Project  run    options             */
  172.    /***************************************************/
  173.    memcpy(work,&runsize,2);
  174.    work +=2;
  175.    memcpy(work,runopts,runsize);
  176.    work += runsize;
  177.  
  178.    /***************************************************/
  179.    /*   Store the Project  make   options             */
  180.    /***************************************************/
  181.    memcpy(work,&makesize,2);
  182.    work +=2;
  183.    memcpy(work,makeopts,makesize);
  184.    work += makesize;
  185.  
  186.    /***************************************************/
  187.    /*   Store the Project debug   options             */
  188.    /***************************************************/
  189.    memcpy(work,&debugsize,2);
  190.    work +=2;
  191.    memcpy(work,debugopts,debugsize);
  192.    work += debugsize;
  193.  
  194.    /***************************************************/
  195.    /*   Store the Project options language            */
  196.    /***************************************************/
  197.    memcpy(work,&projlangsize,2);
  198.    work +=2;
  199.    memcpy(work,projlang,projlangsize);
  200.    work += projlangsize;
  201.  
  202.    /***************************************************/
  203.    /*   Write the file                                */
  204.    /***************************************************/
  205.    rc = DosWrite(outfile,workstart,SizeRequired,&byteswritten);
  206.    if (rc !=0 || SizeRequired != (USHORT)byteswritten)
  207.       {
  208.       free(workstart);
  209.       DosClose(outfile);
  210.       return MSG_FILE_ERROR;
  211.       }
  212.  
  213.    free(workstart);
  214.  
  215.    if ((rc=DosClose(outfile)) != 0)
  216.       {
  217.       return MSG_FILE_ERROR;
  218.       }
  219.  
  220.    return MSG_NO_ERROR;
  221.    }
  222.  
  223.