home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / interf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.6 KB  |  262 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include "exinterfmotif.h"
  19. #include <string.h>
  20. #include "exglobals.h"
  21. #include "exinterf.h"
  22. #include "exbookglo.h"
  23.  
  24. extern struct indexlist *find_keyword();
  25.    int buttonwidth = 65;
  26.    int buttonhalf = 32;
  27.  
  28. /************************************************************
  29. *
  30. * Clears the buffer of a text thingy.
  31. *
  32. ************************************************************/
  33. bufclear(struct Tstruct *T)
  34. {
  35.    int i;
  36.    T->bufpos = 0;
  37.    for (i = 0; i < 300; i++)
  38.       T->buf[i] = '\0';
  39. }
  40.  
  41. /************************************************************
  42. *
  43. * Free storage used by the buttons in the add group window.
  44. *
  45. ************************************************************/
  46. void freegpform()
  47. {
  48.    struct charlist *charptr, *prevcharptr;
  49.  
  50.    charptr = HeadGrpChar;
  51.    while (charptr != NULL)
  52.       {
  53.       prevcharptr = charptr->next;
  54.       if (charptr->indexflag == 0)
  55.          free(charptr->str);
  56.       free(charptr);
  57.       charptr = prevcharptr;
  58.       }
  59.    HeadGrpChar = NULL;
  60.    TailGrpChar = NULL;
  61. }
  62.  
  63. void initExistKWList()
  64. {
  65.    long cumlength, limit;
  66.    static short nblocks = 1;
  67.    struct indexlist *ndxptr;
  68.    int count;
  69.  
  70.    ndxptr = Index;
  71.    count = 0;
  72.    ExistKeywordString[0] = '\0';
  73.    strcpy(ExistKeywordString, "");
  74.    cumlength = 0;
  75.    limit = (1024 * nblocks)-2;
  76.    while (ndxptr != NULL)
  77.       {
  78.       count++;
  79.       cumlength+=(strlen(ndxptr->string)+1);
  80.       if (cumlength > limit)
  81.          {
  82.          nblocks++;
  83.          ExistKeywordString = (char *)realloc((void *)ExistKeywordString, 1024*(nblocks));
  84.          limit = (1024 * nblocks)-2;
  85.          }
  86.       strcat(ExistKeywordString, (ndxptr->string));
  87.       strcat(ExistKeywordString, ",");
  88.       ndxptr = ndxptr->next;
  89.       }
  90.    ExistKeywordCount = count;
  91. }
  92.  
  93. /************************************************************
  94. *
  95. * Initialize the buttons in the add group window.
  96. *
  97. ************************************************************/
  98. long initgpform()
  99. {
  100.    AGKey.bufpos = 0;
  101.    bufclear(&AGKey);
  102.    AGName.bufpos = 0;
  103.    bufclear(&AGName);
  104.    AGHfile.bufpos = 0;
  105.    bufclear(&AGHfile);
  106.    GroupKeywordCount = 0;
  107.    GroupKeywordString[0] = '\0';
  108.  
  109.    initExistKWList();
  110. }
  111.  
  112. /************************************************************
  113. *
  114. * Initialize the buttons for the window where the user adds
  115. * demos to the book.
  116. *
  117. ************************************************************/
  118. long initadwin()
  119. {
  120.    struct indexlist *ndxptr;
  121.    short count;
  122.    struct icntmpltstruct *iconptr;
  123.    struct wordlist *wrdptr;
  124.    struct charlist *curchar;
  125.    struct filelist *tmpfptr;
  126.    long cl_demo, cl_files, lim_demo, lim_files;
  127.    static short nb_demo = 1;
  128.    static short nb_files = 1;
  129.  
  130.  
  131.    initExistKWList();
  132.  
  133.    DemoKeywordCount = 0;
  134.    ExeFileCount = 0;
  135.    DemoKeywordString[0] = '\0';
  136.    ExeFileString[0] = '\0';
  137.  
  138.    ADName.bufpos = 0;
  139.    bufclear(&ADName);
  140.    ADCommand.bufpos = 0;
  141.    bufclear(&ADCommand);
  142.    ADAltCommand.bufpos = 0;
  143.    bufclear(&ADAltCommand);
  144.    ADHfile.bufpos = 0;
  145.    bufclear(&ADHfile);
  146.    ADIfile.bufpos = 0;
  147.    bufclear(&ADIfile);
  148.    ADIfile2.bufpos = 0;
  149.    bufclear(&ADIfile2);
  150.    ADKey.bufpos = 0;
  151.    bufclear(&ADKey);
  152.  
  153.    HeadChar = NULL;
  154.    TailChar = NULL;
  155.    Head_FL = NULL;
  156.    Tail_FL = NULL;
  157.    if (EditDemoFlag == 1)
  158.       {
  159.       if (selected >= 0)
  160.          {
  161.          KW_change = FALSE;
  162.          iconptr = seliconptr->iconptr;
  163.          curicon = iconptr;
  164.          ADName.bufpos = strlen(iconptr->nameptr->string);
  165.          strcpy(ADName.buf, iconptr->nameptr->string);
  166.          ADCommand.bufpos = strlen(iconptr->startstring);
  167.          strcpy(ADCommand.buf, iconptr->startstring);
  168.          if (iconptr->alt_command != NULL)
  169.             { 
  170.             ADAltCommand.bufpos = strlen(iconptr->alt_command);
  171.             strcpy(ADAltCommand.buf, iconptr->alt_command);
  172.             }
  173.          if (iconptr->helpfile != NULL) 
  174.             {
  175.             ADHfile.bufpos = strlen(iconptr->helpfile->name);
  176.             strcpy(ADHfile.buf, iconptr->helpfile->name);
  177.             }
  178.          if (iconptr->geofile != NULL) 
  179.             {
  180.             ADIfile.bufpos = strlen(iconptr->geofile->name);
  181.             strcpy(ADIfile.buf, iconptr->geofile->name);
  182.             }
  183.          if (iconptr->imgfile != NULL) 
  184.             {
  185.             ADIfile2.bufpos = strlen(iconptr->imgfile->name);
  186.             strcpy(ADIfile2.buf, iconptr->imgfile->name);
  187.             }
  188.      count = 0;
  189.      DemoKeywordString[0] = '\0';
  190.      strcpy(DemoKeywordString, "");
  191.          cl_demo = 0;
  192.          lim_demo = (512 * nb_demo)-2;
  193.          wrdptr = iconptr->keywords;
  194.          while (wrdptr != NULL)
  195.             {
  196.             curchar = (struct charlist *) malloc(sizeof(struct charlist) );
  197.             curchar->str = NULL;
  198.             curchar->next = NULL;
  199.             if (HeadChar == NULL)
  200.                HeadChar = curchar;
  201.             else
  202.                TailChar->next = curchar;
  203.             TailChar = curchar;
  204.             TailChar->indexflag = 1;
  205.             TailChar->str = wrdptr->indexptr->string;
  206.             cl_demo+=strlen(wrdptr->indexptr->string)+1;
  207.             if (cl_demo > lim_demo)
  208.                {
  209.                nb_demo++;
  210.                DemoKeywordString = (char *)realloc( (void *)DemoKeywordString, 
  211.                                                   512*nb_demo);
  212.                lim_demo = (512 * nb_demo)-2;
  213.                }
  214.         strcat(DemoKeywordString, (wrdptr->indexptr->string));
  215.         strcat(DemoKeywordString, ",");
  216.         count++;
  217.             wrdptr = wrdptr->next;
  218.             }
  219.      DemoKeywordCount = count;
  220.          if (iconptr->addtlfiles != NULL)
  221.             {
  222.         count = 0;
  223.         ExeFileString[0] = '\0';
  224.         strcpy(ExeFileString, "");
  225.             tmpfptr = iconptr->addtlfiles;
  226.             cl_files = 0;
  227.             lim_files = (512*nb_files) -2;
  228.             while (tmpfptr != NULL)
  229.                {
  230.                curchar = (struct charlist *)malloc( sizeof(struct charlist) );
  231.                curchar->str = NULL;
  232.                curchar->next = NULL;
  233.                if (Head_FL == NULL)
  234.                   Head_FL = curchar;
  235.                else
  236.                   Tail_FL->next = curchar;
  237.                Tail_FL = curchar;
  238.                Tail_FL->indexflag = 1;  /* 1 means that this string was
  239.                                            already in the icons list of
  240.                                            additional files.  0 will mean
  241.                                            that this is a new file */
  242.                Tail_FL->str = tmpfptr->file->name;
  243.                if (cl_files > lim_files)
  244.                   {
  245.                   nb_files++;
  246.                   ExeFileString = (char *)realloc( (void *)ExeFileString,
  247.                               512*nb_files);
  248.                   lim_files = (512*nb_files) -2;
  249.                   }
  250.            strcat(ExeFileString, (tmpfptr->file->name));
  251.            strcat(ExeFileString, ",");
  252.            count++;
  253.                tmpfptr = tmpfptr->next;
  254.                }
  255.         ExeFileCount = count;
  256.             }
  257.          }
  258.       }
  259.    return(99);
  260. }
  261.  
  262.