home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / text / hyper / hsc_source.lha / hsc / source / hscprj / project.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-12  |  5.9 KB  |  272 lines

  1. /*
  2.  * hscprj/project.c
  3.  *
  4.  * project managment routines for hsc
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 12-Jan-1997
  23.  * created: 13-Apr-1996
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28. #include <string.h>
  29. #include <errno.h>
  30. #include <time.h>
  31.  
  32. #include "hsclib/ldebug.h"
  33. #include "hscprj/pdebug.h"
  34.  
  35. #include "ugly/utypes.h"
  36. #include "ugly/dllist.h"
  37. #include "ugly/expstr.h"
  38. #include "ugly/umemory.h"
  39. #include "ugly/infile.h"
  40. #include "ugly/ustring.h"
  41.  
  42. #include "hscprj/document.h"
  43. #include "hscprj/project.h"
  44.  
  45. /*
  46.  * new_project
  47.  */
  48. HSCPRJ *new_project(VOID)
  49. {
  50.     HSCPRJ *hp = (HSCPRJ *) umalloc(sizeof(HSCPRJ));
  51.  
  52.     if (hp)
  53.     {
  54.         memset(hp, 0, sizeof(HSCPRJ));
  55.         hp->documents = init_dllist(del_document);
  56.     }
  57.  
  58.     return (hp);
  59. }
  60.  
  61.  
  62. /*
  63.  * del_project
  64.  */
  65. VOID del_project(HSCPRJ * hp)
  66. {
  67.     if (hp)
  68.     {
  69.         del_dllist(hp->documents);
  70.         del_document(hp->document);
  71.         ufree(hp);
  72.     }
  73. }
  74.  
  75.  
  76. /*
  77.  * check_document_id
  78.  *
  79.  * append id to id_ref-list so it as checked when
  80.  * check_all_local_id_ref() is called
  81.  */
  82. int check_document_id(HSCPRJ * hp, STRPTR docname, STRPTR id)
  83. {
  84.     int err = ERR_CDI_OK;
  85.     HSCDOC *document = find_document(hp->documents, docname);
  86.  
  87.     DP(fprintf(stderr, DHP "  check id: `%s#%s'\n", docname, id));
  88.  
  89.     if (document)
  90.     {
  91.         HSCIDD *iddef = NULL;
  92.  
  93.         iddef = find_iddef(document, id);
  94.         if (!iddef)
  95.         {
  96.             DP(fprintf(stderr, DHP "    id unknown\n"));
  97.             err = ERR_CDI_NoID;
  98.         }
  99.         else
  100.         {
  101.             DP(fprintf(stderr, DHP "    id ok\n"));
  102.             err = ERR_CDI_OK;
  103.         }
  104.     }
  105.     else
  106.     {
  107.         DP(fprintf(stderr, DHP "    no file-entry in project\n"));
  108.         err = ERR_CDI_NoDocumentEntry;
  109.     }
  110.  
  111.     return (err);
  112. }
  113.  
  114. /*
  115.  * hsc_project_set_filename
  116.  *
  117.  * set project-filename (used by hsc_project_write_file())
  118.  */
  119. BOOL hsc_project_set_filename(HSCPRJ * hp, STRPTR new_prjname)
  120. {
  121.     BOOL ok = TRUE;
  122.     DP(fprintf(stderr, DHP "set project `%s'\n", new_prjname));
  123.  
  124.     if (hp->document->sourcename)
  125.     {
  126.         panic("project-name already set");
  127.     }
  128.  
  129.     hp->document->sourcename = strclone(new_prjname);
  130.  
  131.     return (ok);
  132. }
  133.  
  134. /*
  135.  * hsc_project_add_document
  136.  *
  137.  * add current document to project
  138.  */
  139. BOOL hsc_project_add_document(HSCPRJ * hp)
  140. {
  141.     BOOL ok = TRUE;
  142.  
  143.     if (hp->document)
  144.     {
  145.         if (hp->document->docname)
  146.         {
  147.             DP(fprintf(stderr, DHP "  add document `%s'\n",
  148.                        hp->document->docname));
  149.             app_dlnode(hp->documents, hp->document);
  150.         }
  151.         else
  152.         {
  153.             DP(fprintf(stderr, DHP "  add document <stdout>: skipped\n"));
  154.             del_document(hp->document);
  155.         }
  156.  
  157.         hp->document = NULL;
  158.     }
  159.     else
  160.     {
  161.         panic("no document to replace");
  162.     }
  163.  
  164.     return (ok);
  165. }
  166.  
  167. /*
  168.  * hsc_project_del_document
  169.  *
  170.  * remove document from project
  171.  */
  172. BOOL hsc_project_del_document(HSCPRJ * hp, STRPTR docname)
  173. {
  174.     BOOL deleted = FALSE;
  175.     DLNODE *docnd = find_document_node(hp->documents, docname);
  176.  
  177.     if (docnd)
  178.     {
  179.         DP(fprintf(stderr, DHP "  remove document `%s'\n", docname));
  180.         del_dlnode(hp->documents, docnd);
  181.         deleted = TRUE;
  182.     }
  183.     else
  184.     {
  185.         DP(fprintf(stderr, DHP "  remove document `%s': FAILED\n", docname));
  186.     }
  187.  
  188.     return (deleted);
  189. }
  190.  
  191. /*
  192.  * hsc_project_set_document
  193.  *
  194.  * Remove document from project's document list and
  195.  * create a new empty document with this name and
  196.  * make it the current document of the project.
  197.  * The new document is added to the project when the
  198.  * project-file is updated.
  199.  */
  200. BOOL hsc_project_set_document(HSCPRJ * hp, STRPTR new_docname)
  201. {
  202.     BOOL ok = TRUE;
  203.     DLNODE *nd = NULL;
  204.     if (new_docname)
  205.     {
  206.         DP(fprintf(stderr, DHP "set document `%s'\n", new_docname));
  207.  
  208.         /* dettach document from project */
  209.         nd = find_document_node(hp->documents, new_docname);
  210.         if (nd)
  211.         {
  212.             DP(fprintf(stderr, DHP "  remove old document `%s'\n",
  213.                        ((HSCDOC *) dln_data(nd))->docname));
  214.             del_dlnode(hp->documents, nd);
  215.         }
  216.         else
  217.         {
  218.             DP(fprintf(stderr, DHP "  new document `%s'\n", new_docname));
  219.         }
  220.     }
  221.     else
  222.     {
  223.         DP(fprintf(stderr, DHP "set document <stdout>\n"));
  224.     }
  225.  
  226.     /* remove current document */
  227.     if (hp->document)
  228.     {
  229.         DP(fprintf(stderr, DHP "  remove current document `%s'\n",
  230.                    hp->document->docname));
  231.         del_document(hp->document);
  232.     }
  233.  
  234.     hp->document = new_document(new_docname);
  235.  
  236.     return (ok);
  237. }
  238.  
  239. /*
  240.  * hsc_project_set_source
  241.  *
  242.  * set main source for project's current document
  243.  */
  244. BOOL hsc_project_set_source(HSCPRJ * hp, STRPTR new_sourcename)
  245. {
  246.     BOOL ok = TRUE;
  247.     DP(fprintf(stderr, DHP "set source `%s'\n", new_sourcename));
  248.  
  249.     if (!hp->document->sourcename)
  250.         hp->document->sourcename = strclone(new_sourcename);
  251.     else
  252.     {
  253.         panic("sourcename already set");
  254.         ok = FALSE;
  255.     }
  256.  
  257.     return (ok);
  258. }
  259.  
  260. /*
  261.  * hsc_project_add_include
  262.  *
  263.  * add include-file to project's current document
  264.  */
  265. BOOL hsc_project_add_include(HSCPRJ * hp, STRPTR new_includename)
  266. {
  267.     BOOL ok = TRUE;
  268.     DP(fprintf(stderr, DHP "add include `%s'\n", new_includename));
  269.     app_include(hp->document, new_includename);
  270.     return (ok);
  271. }
  272.