home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 52 / af052sub.adf / lyr-o-mat.lha / Lyr-O-Mat / Source / Source.lha / words_temp.c < prev    next >
C/C++ Source or Header  |  1993-05-03  |  13KB  |  491 lines

  1. #include "words.h"
  2.  
  3. struct EasyStruct AboutReq =
  4.        {
  5.         0L,0L,(UBYTE *)"About " LYR_NAME,
  6.               (UBYTE *)LYR_NAME " is Copyright ©1993\nby CEKASOFT\nKarlheinz Klingbeil\nElzstr. 42\n7809 Gutach\nGermany\n\n  ENJOY !!!",
  7.               (UBYTE *)"incredible | silly | great",
  8.        };
  9.  
  10. struct EasyStruct ExitReq =
  11.        {
  12.         0L,0L,(UBYTE *)"Quit " LYR_NAME,
  13.               (UBYTE *)"Really quit ?",
  14.               (UBYTE *)"Yes (L-AMIGA+V) | No (L-AMIGA + B)",
  15.        };
  16.  
  17.        
  18. int templatestringClicked( void )
  19. {
  20.  /* routine when gadget "" is clicked. */
  21.  if(*(GetString(Project0Gadgets[GDX_templatestring])))
  22.  {
  23.   list_off(LIST_PT);newpattern(GetString(Project0Gadgets[GDX_templatestring]));list_on(LIST_PT);
  24.  
  25.   GT_SetGadgetAttrs(Project0Gadgets[GDX_templatelist],Project0Wnd,NULL,
  26.                      GTLV_Selected,NodeToNum(&winfo.pattern,(struct Node *)winfo.currentpattern),NULL,TAG_DONE);
  27.  }
  28.  if(edit.pattern)
  29.  {
  30.   edit.pattern = 0;
  31.   GT_SetGadgetAttrs(Project0Gadgets[GDX_templatestring],Project0Wnd,NULL,
  32.                     GA_Disabled,TRUE,TAG_DONE);
  33.   GT_SetGadgetAttrs(Project0Gadgets[GDX_deltemplate],Project0Wnd,NULL,
  34.                     GA_Disabled,TRUE,TAG_DONE);
  35.  }
  36.  else ActivateGadget(Project0Gadgets[GD_templatestring],Project0Wnd,NULL);
  37.  return (TRUE);
  38. }
  39.  
  40. int wordlistClicked( void )
  41. {
  42.     /* routine when gadget "Words" is clicked. */
  43.  if(winfo.currentclass)
  44.  {
  45.   winfo.currentword = (struct wordnode *)NumToNode(&winfo.currentclass->cl_Words,Project0Msg.Code);
  46.   GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  47.                     GA_Disabled,FALSE,TAG_DONE);
  48.   GT_SetGadgetAttrs(Project0Gadgets[GDX_delword],Project0Wnd,NULL,
  49.                     GA_Disabled,FALSE,TAG_DONE);
  50.   GT_SetGadgetAttrs(Project0Gadgets[GDX_addword],Project0Wnd,NULL,
  51.                     GA_Disabled,FALSE,TAG_DONE);
  52.   ActivateGadget(Project0Gadgets[GD_wordstring],Project0Wnd,NULL);
  53.   edit.word = 1;
  54.  }
  55.  return (TRUE);
  56. }
  57.  
  58. int class_stringClicked( void )
  59. {
  60.     /* routine when gadget "" is clicked. */
  61.  if(*(GetString(Project0Gadgets[GDX_class_string])))
  62.  {
  63.   list_off(LIST_CL);newclass(GetString(Project0Gadgets[GDX_class_string]));list_on(LIST_CL);
  64.   GT_SetGadgetAttrs(Project0Gadgets[GDX_classlist],Project0Wnd,NULL,
  65.                      GTLV_Selected,NodeToNum(&winfo.class,(struct Node *)winfo.currentclass),NULL,TAG_DONE);
  66.   list_off(LIST_WD);
  67.   list_on(LIST_WD);
  68.  }
  69.  if(edit.class)
  70.  {
  71.   edit.class = 0;
  72.   GT_SetGadgetAttrs(Project0Gadgets[GDX_class_string],Project0Wnd,NULL,
  73.                     GA_Disabled,TRUE,TAG_DONE);
  74.   GT_SetGadgetAttrs(Project0Gadgets[GDX_delclass],Project0Wnd,NULL,
  75.                     GA_Disabled,TRUE,TAG_DONE);
  76.   GT_SetGadgetAttrs(Project0Gadgets[GDX_addword],Project0Wnd,NULL,
  77.                     GA_Disabled,TRUE,TAG_DONE);
  78.   GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  79.                     GA_Disabled,TRUE,TAG_DONE);
  80.  }
  81.  else ActivateGadget(Project0Gadgets[GD_class_string],Project0Wnd,NULL);
  82.  return (TRUE);
  83. }
  84.  
  85. int classlistClicked( void )
  86. {
  87.     /* routine when gadget "Classes" is clicked. */
  88.  winfo.currentclass = (struct classnode *)NumToNode(&winfo.class,Project0Msg.Code);
  89.  winfo.currentword  = (struct wordnode  *)winfo.currentclass->cl_Words.lh_TailPred;
  90.  list_off(LIST_WD);
  91.  GT_SetGadgetAttrs(Project0Gadgets[GDX_class_string],Project0Wnd,NULL,
  92.                     GA_Disabled,FALSE,TAG_DONE);
  93.  GT_SetGadgetAttrs(Project0Gadgets[GDX_delclass],Project0Wnd,NULL,
  94.                     GA_Disabled,FALSE,TAG_DONE);
  95.  GT_SetGadgetAttrs(Project0Gadgets[GDX_addword],Project0Wnd,NULL,
  96.                     GA_Disabled,FALSE,TAG_DONE);
  97.  ActivateGadget(Project0Gadgets[GD_class_string],Project0Wnd,NULL);
  98.  list_on(LIST_CL);
  99.  edit.class = 1;
  100.  return (TRUE);
  101. }
  102.  
  103. int wordstringClicked( void )
  104. {
  105.     /* routine when gadget "" is clicked. */
  106.  if(*(GetString(Project0Gadgets[GDX_wordstring])))
  107.  {
  108.   list_off(LIST_WD);newword(GetString(Project0Gadgets[GDX_wordstring]));list_on(LIST_WD);
  109.   if(winfo.currentclass)
  110.   {
  111.    GT_SetGadgetAttrs(Project0Gadgets[GDX_wordlist],Project0Wnd,NULL,
  112.                      GTLV_Selected,NodeToNum(&winfo.currentclass->cl_Words,(struct Node *)winfo.currentword),NULL,TAG_DONE);
  113.   } 
  114.  }
  115.  if(edit.word)
  116.  {
  117.   edit.word = 0;
  118.   GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  119.                     GA_Disabled,TRUE,TAG_DONE);
  120.   GT_SetGadgetAttrs(Project0Gadgets[GDX_delword],Project0Wnd,NULL,
  121.                     GA_Disabled,TRUE,TAG_DONE);
  122.  }
  123.  else  ActivateGadget(Project0Gadgets[GD_wordstring],Project0Wnd,NULL);
  124.  return (TRUE);
  125. }
  126.  
  127. int templatelistClicked( void )
  128. {
  129.  /* routine when gadget "Pattern" is clicked. */
  130.  winfo.currentpattern = (struct patternnode *)NumToNode(&winfo.pattern,Project0Msg.Code);
  131.  GT_SetGadgetAttrs(Project0Gadgets[GDX_templatestring],Project0Wnd,NULL,
  132.                     GA_Disabled,FALSE,TAG_DONE);
  133.  GT_SetGadgetAttrs(Project0Gadgets[GDX_deltemplate],Project0Wnd,NULL,
  134.                     GA_Disabled,FALSE,TAG_DONE);
  135.  ActivateGadget(Project0Gadgets[GD_templatestring],Project0Wnd,NULL);
  136.  edit.pattern = 1;
  137.  return (TRUE);
  138. }
  139.  
  140. int numpatClicked( void )
  141. {
  142.  long num = GetNumber(Project0Gadgets[GDX_numpat]);
  143.  if(num > 0) NumGen = num;
  144.  else
  145.  {
  146.   GT_SetGadgetAttrs(Project0Gadgets[GDX_numpat],Project0Wnd,NULL,
  147.                     GTIN_Number,1,TAG_DONE);
  148.   NumGen = 1; 
  149.  }
  150.  return (TRUE);
  151. }
  152.  
  153. int generateClicked( void )
  154. {
  155.     /* routine when gadget "Generate" is clicked. */
  156.  int i;
  157.  int pattern;
  158.  struct Node *n;
  159.  if(edit.pmode)
  160.  {
  161.   if(winfo.numpattern)
  162.   {
  163.    for(i = 0;i < NumGen;i++)
  164.    {
  165.     pattern = (ULONG)RangeRand(winfo.numpattern);
  166.     n = NumToNode(&winfo.pattern,pattern);
  167.     winfo.nach = strdup(n->ln_Name);
  168.     ReplaceLine();
  169.     line_out(winfo.nach);
  170.     free(winfo.nach);
  171.    }
  172.   }
  173.  }
  174.  else
  175.  {
  176.   for(i = 0;i < NumGen;i++)
  177.   {
  178.    for(n = winfo.pattern.lh_Head;n->ln_Succ;n = n->ln_Succ)
  179.    {
  180.     winfo.nach = strdup(n->ln_Name);
  181.     ReplaceLine();
  182.     line_out(winfo.nach);
  183.     free(winfo.nach);
  184.    }
  185.   }
  186.  }
  187.  return (TRUE);
  188. }
  189.  
  190. int addtemplateClicked( void )
  191. {
  192.     /* routine when gadget "Add" is clicked. */
  193.  GT_SetGadgetAttrs(Project0Gadgets[GDX_templatestring],Project0Wnd,NULL,
  194.                    GA_Disabled,FALSE,TAG_DONE);
  195.  GT_SetGadgetAttrs(Project0Gadgets[GDX_templatestring],Project0Wnd,NULL,
  196.                    GTST_String,(ULONG)"",TAG_DONE);
  197.  ActivateGadget(Project0Gadgets[GD_templatestring],Project0Wnd,NULL);
  198.  edit.pattern = 0;
  199.  return (TRUE);
  200. }
  201.  
  202. int deltemplateClicked( void )
  203. {
  204.     /* routine when gadget "Delete" is clicked. */
  205.  delpattern();
  206.  GT_SetGadgetAttrs(Project0Gadgets[GDX_templatestring],Project0Wnd,NULL,
  207.                    GA_Disabled,TRUE,TAG_DONE);
  208.  GT_SetGadgetAttrs(Project0Gadgets[GDX_deltemplate],Project0Wnd,NULL,
  209.                    GA_Disabled,TRUE,TAG_DONE);
  210.  
  211.  return (TRUE);
  212. }
  213.  
  214. int addclassClicked( void )
  215. {
  216.     /* routine when gadget "Add" is clicked. */
  217.  GT_SetGadgetAttrs(Project0Gadgets[GDX_class_string],Project0Wnd,NULL,
  218.                    GA_Disabled,FALSE,TAG_DONE);
  219.  GT_SetGadgetAttrs(Project0Gadgets[GDX_addword],Project0Wnd,NULL,
  220.                    GA_Disabled,FALSE,TAG_DONE);
  221.  GT_SetGadgetAttrs(Project0Gadgets[GDX_class_string],Project0Wnd,NULL,
  222.                    GTST_String,(ULONG)"",TAG_DONE);
  223.  ActivateGadget(Project0Gadgets[GD_class_string],Project0Wnd,NULL);
  224.  edit.class = 0;
  225.  return (TRUE);
  226. }
  227.  
  228. int delclassClicked( void )
  229. {
  230.     /* routine when gadget "Delete" is clicked. */
  231.  delclass();
  232.  GT_SetGadgetAttrs(Project0Gadgets[GDX_class_string],Project0Wnd,NULL,
  233.                    GA_Disabled,TRUE,TAG_DONE);
  234.  GT_SetGadgetAttrs(Project0Gadgets[GDX_delclass],Project0Wnd,NULL,
  235.                    GA_Disabled,TRUE,TAG_DONE);
  236.  GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  237.                    GA_Disabled,TRUE,TAG_DONE);
  238.  GT_SetGadgetAttrs(Project0Gadgets[GDX_delword],Project0Wnd,NULL,
  239.                    GA_Disabled,TRUE,TAG_DONE);
  240.  GT_SetGadgetAttrs(Project0Gadgets[GDX_addword],Project0Wnd,NULL,
  241.                    GA_Disabled,TRUE,TAG_DONE);
  242.  return (TRUE);
  243. }
  244.  
  245. int addwordClicked( void )
  246. {
  247.     /* routine when gadget "Add" is clicked. */
  248.  GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  249.                    GA_Disabled,FALSE,TAG_DONE);
  250.  GT_SetGadgetAttrs(Project0Gadgets[GDX_wordstring],Project0Wnd,NULL,
  251.                    GTST_String,(ULONG)"",TAG_DONE);
  252.  ActivateGadget(Project0Gadgets[GD_wordstring],Project0Wnd,NULL);
  253.  edit.word = 0;
  254.  return (TRUE);
  255. }
  256.  
  257. int delwordClicked( void )
  258. {
  259.     /* routine when gadget "Delete" is clicked. */
  260.  delword();
  261.  return (TRUE);
  262. }
  263.  
  264. int modeClicked( void )
  265. {
  266.  edit.pmode = (edit.pmode) ? 0 : 1; 
  267.  return (TRUE);
  268. }
  269. int Project0Loadpattern( void )
  270. {
  271.  edit.l_p = 1;
  272.  edit.l_c = 0;
  273.  loadAll(MODE_LOADFILE,"Loading Patterns...");
  274.  return TRUE;
  275. }
  276. int Project0Loadclasses( void )
  277. {
  278.  edit.l_p = 0;
  279.  edit.l_c = 1;
  280.  loadAll(MODE_LOADFILE,"Loading Classes...");
  281.  return TRUE;
  282. }
  283. int Project0appendpattern( void )
  284. {
  285.  edit.l_p = 1;
  286.  edit.l_c = 0;
  287.  loadAll(MODE_APPENDFILE,"Appending Patterns...");
  288.  return TRUE;
  289. }
  290. int Project0appendclasses( void )
  291. {
  292.  edit.l_p = 0;
  293.  edit.l_c = 1;
  294.  loadAll(MODE_APPENDFILE,"Appending Classes...");
  295.  return TRUE;
  296. }
  297. int Project0savepattern( void )
  298. {
  299.  edit.s_p = 1;
  300.  edit.s_c = 0;
  301.  saveAll(MODE_SAVEFILE,"Lyr-O-Mat... Save Pattern only");
  302.  return TRUE;
  303. }
  304. int Project0saveclasses( void )
  305. {
  306.  edit.s_p = 0;
  307.  edit.s_c = 1;
  308.  saveAll(MODE_SAVEFILE,"Lyr-O-Mat... Save classes only");
  309.  return TRUE;
  310. }
  311. int Project0about( void )
  312. {
  313.  EasyRequestArgs(Project0Wnd,&AboutReq,NULL,NULL);
  314.  return TRUE;
  315. }
  316.  
  317. int Project0Loadall( void )
  318. {
  319.     /* routine when (sub)item "Load words..." is selected. */
  320.  edit.l_p = 1;
  321.  edit.l_c = 1;
  322.  loadAll(MODE_LOADFILE,"Loading Patterns & Classes");
  323.  return (TRUE);
  324. }
  325.  
  326. int Project0appendall( void )
  327. {
  328.     /* routine when (sub)item "Load words..." is selected. */
  329.  edit.l_p = 1;
  330.  edit.l_c = 1;
  331.  loadAll(MODE_APPENDFILE,"Appending Patterns & Classes...");
  332.  return (TRUE);
  333. }
  334.  
  335.  
  336. int Project0saveall( void )
  337. {
  338.     /* routine when (sub)item "Save words..." is selected. */
  339.  edit.s_p = 1;
  340.  edit.s_c = 1;
  341.  saveAll(MODE_SAVEFILE,"Lyr-O-Mat... Save all Data");
  342.  return (TRUE);
  343. }
  344.  
  345. int Project0savedefault( void )
  346. {
  347.     /* routine when (sub)item "Save as Default..." is selected. */
  348.  edit.s_p = 1;
  349.  edit.s_c = 1;
  350.  saveAll(MODE_SAVECONFIG,"Lyr-O-Mat... Save configuration");
  351.  return (TRUE);
  352. }
  353.  
  354. int Project0ShowInfo( void )
  355. {
  356.  Project0ShowPInfo(); 
  357.  Project0ShowCInfo();
  358.  return TRUE;
  359. }
  360.  
  361.  
  362. int Project0Item0( void )
  363. {
  364.     /* routine when (sub)item "Print" is selected. */
  365.  if(winfo.printfile)
  366.  {
  367.   fclose(winfo.printfile);
  368.   winfo.printfile = NULL;
  369.  }
  370.  else
  371.  {
  372.   winfo.printfile = fopen("prt:","w");
  373.  }
  374.  return (TRUE);
  375. }
  376.  
  377. int Project0ConWd( void )
  378. {
  379.  if(winfo.outfile)
  380.  {
  381.   fclose(winfo.outfile);
  382.   winfo.outfile = NULL;
  383.  }
  384.  else
  385.  {
  386.   winfo.outfile = fopen(winfo.outfilename,"w");
  387.  }
  388.  return (TRUE);
  389. }
  390.  
  391. int Project0quit( void )
  392. {
  393.     /* routine when (sub)item "Quit..." is selected. */
  394.  if( EasyRequestArgs(Project0Wnd,&ExitReq,NULL,NULL) == 1)
  395.    return FALSE;
  396.   else
  397.    return TRUE;
  398. }
  399.  
  400. int Project0CloseWindow( void )
  401. {
  402.     /* routine for "IDCMP_CLOSEWINDOW". */
  403.  return Project0quit();
  404. }
  405.  
  406. void line_out(UBYTE *line)
  407. {
  408.  if(winfo.outfile)   fprintf(winfo.outfile,"%s\n",line);
  409.  if(winfo.printfile) fprintf(winfo.printfile,"%s\n",line);
  410. }
  411.  
  412. int Project0VanillaKey( void)
  413. {
  414.  int rc = TRUE;
  415.  switch(Project0Msg.Code)
  416.  {
  417.   case '\n'  :
  418.   case ' '  :
  419.   case 'g'  :
  420.   case 'G'  : generateClicked();
  421.               break;
  422.   case 'q'  :
  423.   case 'Q'  : rc = Project0quit();
  424.   default   : break;
  425.  }
  426.  return rc;
  427. }
  428.  
  429. int Project0ShowPInfo( void )
  430. {
  431.  UBYTE line[256];
  432.  struct Node *p;
  433.  line_out("***************************************");
  434.  line_out("*      Lyr-O-Mat Pattern info         *");
  435.  line_out("***************************************");
  436.  if(winfo.numpattern)
  437.  {
  438.   sprintf(line,"* %6ld Patterns",winfo.numpattern);
  439.   line_out(line);
  440.   for(p = winfo.pattern.lh_Head;p->ln_Succ;p=p->ln_Succ)
  441.   {
  442.    sprintf(line,"** %s",p->ln_Name);
  443.    line_out(line);   
  444.   }
  445.  }
  446.  else
  447.  line_out("* No Patterns");
  448.  line_out("***************************************");  
  449.  return(TRUE);
  450. }
  451.  
  452. int Project0ShowCInfo( void )
  453. {
  454.  UBYTE line[256];
  455.  struct Node *p;
  456.  line_out("***************************************");
  457.  line_out("*       Lyr-O-Mat Class info          *");
  458.  line_out("***************************************");
  459.  if(winfo.numclass)
  460.  {
  461.   sprintf(line,"\n* %6ld Classes",winfo.numclass);
  462.   line_out(line);
  463.   for(p = winfo.class.lh_Head;p->ln_Succ;p=p->ln_Succ)
  464.   {
  465.    struct classnode *c;
  466.    c = (struct classnode *)p;   
  467.    if(c->cl_Words.lh_Head->ln_Succ)
  468.    {
  469.     if(c->cl_NumWords > 1)
  470.       sprintf(line,"** Class : %s :  %ld words ** %s, %s...",p->ln_Name,c->cl_NumWords,c->cl_Words.lh_Head->ln_Name,c->cl_Words.lh_Head->ln_Succ->ln_Name);
  471.     else
  472.       sprintf(line,"** Class : %s :  %ld words ** %s",p->ln_Name,c->cl_NumWords,c->cl_Words.lh_Head->ln_Name);
  473.     line_out(line);
  474.    }
  475.    else line_out("*** No words in this class !!");
  476.   }
  477.  }
  478.  else
  479.  line_out("* No Classes");
  480.  line_out("***************************************");  
  481.  return (TRUE);
  482. }
  483.  
  484. int Project0WriteIcon(void)
  485. {
  486.  if(edit.writeicon)
  487.   edit.writeicon = 0;
  488.  else
  489.   edit.writeicon = 1;
  490.  return TRUE;
  491. }