home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / misc / gadmget1.6.lha / GadMget1.6 / Source / GadMget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  63.0 KB  |  2,734 lines

  1. /* GadMGet.c  by Jeremy Friesner -- jfriesne@ucsd.edu  
  2.    Version 1.6, released 29 October 1994 */
  3.  
  4. #ifndef MGET_C
  5. #define MGET_C
  6.  
  7. #define INTUI_V36_NAMES_ONLY
  8. #define MAXFILELINELENGTH 300
  9. #define CHAR_SPACE 32
  10. #define INVALID 666
  11.  
  12. #define FIND_REQUESTTYPE                   0
  13. #define LINELENGTH_REQUESTTYPE          1
  14. #define OUTPUTFILE_REQUESTTYPE          2
  15.  
  16. #define SIZEUNITPOS 35        /* position of the ?, K, M in the Aminet line */
  17.     
  18. #define SORTBYDIR  1
  19. #define DIRNAMESIZE 10
  20. #define DIRNAMEPOS 21      /* position of first char of directory on Aminet line */
  21.  
  22. #define SORTBYNAME 2
  23. #define NAMESIZE 20
  24. #define NAMEPOS 0
  25.  
  26. #define SORTBYDESC 3
  27. #define DESCSIZE 42
  28. #define DESCPOS 37
  29.  
  30. #define SORTBYSIZE 4
  31. #define SIZEPOS 31
  32. #define SIZESIZE 5
  33.  
  34. #include "GadMget.h"
  35.  
  36. extern UWORD lastcode;
  37. extern ULONG appwinsig;
  38. extern struct NewGadget mgetNGad[];
  39. extern struct NewMenu mgetNewMenu[];
  40. extern struct Window *findwindow;
  41. extern struct AppMessage *amsg;
  42. extern struct MsgPort *awport;
  43. extern struct AppWindow *appwin;
  44. extern struct TextAttr listfont;
  45.  
  46. FILE *fpOut = stdout;
  47. int IntuitionBase; 
  48. ULONG winopenerror, lockscrnerror;
  49. ULONG handlereturn;
  50. BOOL done=FALSE,BStartedFromWB=FALSE;
  51. char windowtitle[95] = "Loading...";
  52. char sListFontName[36] = "";
  53. int nListFontSize = 0;  /* Default to a bad value */
  54. char version[] = "$VER: GadMget V1.6";
  55. char template[] = "Template:  GadMGet FILE/A,OUTPUT/K,LINELENGTH/K,TOP/K,LEFT/K,\
  56. WIDTH/K,HEIGHT/K,PUBSCREEN/K,WBSCREEN/S,DEFPUBSCREEN/S,NOFILES/S,GETREADMES/S,\
  57. NOPARSE/S,CASESENSITIVE/S,NOCOMMAND/S,NOSPLIT/S,NOAPPWINDOW/S,COMMAND/K,\
  58. NOSIMPLEPATHS/S,NOCD/S,HEADER/K,FOOTER/K,FONT/K,FONTSIZE/K,KEEPBLANKLINES/S,\
  59. KEEPGETSORT/S,KEEPFILESORT/S,FILESORT/K,GETSORT/K\n";
  60. char pnamestring[20],searchstring[MAXFILELINELENGTH];
  61. char szPubScreenName[40],*pubscreenname = NULL,defDir[200],defFile[40];
  62. char szCommandString[40] = "mget";
  63. char inputfile[300]="ram:RECENT";
  64. char sOutFileName[300]="";
  65. char szHeaderFile[300];
  66. char szFooterFile[300];
  67. int nTopListTop, nTopListHeight;
  68. int nSortType[2] = {SORTBYDIR, SORTBYDIR};
  69. int nKeepSorted[2] = {0,0};
  70.  
  71. /* default flags */
  72. int screentype             = USE_CUSTOMSCREEN,    
  73.      getreadmes                = 0, 
  74.      filesflag              = 1,                             /* get .lha files */
  75.      index                     = 0,                             /* start find at top */
  76.      filelist_length         = 0,                             /* no files loaded */
  77.      simplepaths             = 1,                             /* don't use ncftp style mgets */
  78.      casesensitive            = 0,                    
  79.      maxoutputlinelength = 254,                         /* shell's limit */
  80.      requesttype           = FIND_REQUESTTYPE,     /* subwindow is for string searches */
  81.      appwindow                 = 1,                            /* = YES */
  82.      added_bytes             = 0,                            /* used for debugging-- tracks */
  83.                                                                  /* the # of bytes allocated */
  84.      files_selected         = 0,                             /* no files selected */
  85.      screenisopen             = 0,                             /* = NO */
  86.      windowisopen             = 0,                            /* = NO */
  87.      noparse                 = 0,                             /* = yes, parse */
  88.      nocommand                = 0,                             /* = yes, generate command */
  89.      nosplit                 = 0,                             /* = yes, split */
  90.      nocd                        = 0,                            /* = generate CD commands */
  91.      mgetNGad_height         = 248,                        /* default first listview height */
  92.      keepblanklines        = 0;                    /* = don't show blank lines */
  93.  
  94. ULONG kbytes_selected = 0;                                
  95.      
  96. UWORD windowwidth     = 99999,                            /* window will be sized to fill */
  97.         windowheight     = 99999,                            /* screen unless these are */
  98.         windowtop         = 0,                                 /* overridden by parameters */
  99.         windowleft         = 0;
  100.         
  101.  
  102. void *findvi = NULL;
  103.  
  104. struct Library *Intuitionbase            = NULL;
  105. struct GfxBase *GraphicsBase            = NULL;
  106. struct Library *GadToolsBase            = NULL;
  107. struct Library *UtilityBase            = NULL;
  108. struct Library *AslBase                    = NULL;
  109. struct Library *IconBase                = NULL;
  110. struct Library *WorkbenchBase            = NULL;
  111. struct WBArg *argptr = NULL;
  112.  
  113. struct IntuiMessage *message                 = NULL;
  114. struct List *filelist                         = NULL, 
  115.                 *getlist                         = NULL;
  116. struct Node *search_current                 = NULL;
  117. struct Gadget *findgadlist                 = NULL;
  118. struct TextFont *listfontdata = NULL;
  119.  
  120. __chip UWORD waitPointer[] =
  121.     {
  122.     0x0000, 0x0000,
  123.     0x0400, 0x07c0,
  124.     0x0000, 0x07c0,
  125.     0x0100, 0x0380,
  126.     0x0000, 0x07e0,
  127.     0x07c0, 0x1ff8,
  128.     0x1ff0, 0x3fec,
  129.     0x3ff8, 0x7fde,
  130.     0x3ff8, 0x7fbe,
  131.     0x7ffc, 0xff7f,
  132.     0x7efc, 0xffff,
  133.     0x7ffc, 0xffff,
  134.     0x3ff8, 0x7ffe,
  135.     0x3ff8, 0x7ffe,
  136.     0x1ff0, 0x3ffc,
  137.     0x07c0, 0x1ff8,
  138.     0x0000, 0x07e0,
  139.     0x0000, 0x0000};
  140.     
  141.  
  142. void debug(int a)
  143. {
  144. fprintf(fpOut,"debug  %i\n",a);
  145. Delay(80);
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. int listviewgadgetClicked (VOID)
  154. {
  155. int i;
  156. struct Node *current = filelist->lh_Head;
  157. struct Gadget *toplist = mgetGadgets[0];
  158. struct Gadget *botlist = mgetGadgets[1];
  159. char *dataline = NULL;
  160. int minlinelength = 1,oktosend = 1;
  161.  
  162.  if (keepblanklines == 1) minlinelength = 0;
  163.  
  164.  for (i=0; i<lastcode; i++) current = current->ln_Succ;
  165.  
  166.  if (current != NULL)
  167.     {
  168.     /* check to make sure string is a valid file line */
  169.     dataline = current->ln_Name;
  170.     if (dataline == NULL) oktosend = 0;
  171.     if (strlen(current->ln_Name) < minlinelength) oktosend = 0;
  172.         
  173.     if (!noparse)
  174.         {
  175.         if ((dataline[0] < '0')||(dataline[0] > 'z')) oktosend = 0;
  176.         if ((dataline[35] != 'K')&&(dataline[35] != 'M')&&(dataline[35] != '?')) oktosend = 0;
  177.         if (dataline[21] < '0') oktosend = 0;
  178.         if ((filesflag == 0)&&(dataline[36] != '+')) oktosend = 0;
  179.         }    
  180.     if (oktosend)
  181.         {
  182.         UpdateByteCount(dataline,1);
  183.         /* Take it out of filelist */
  184.         GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  185.         Remove(current);
  186.         GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  187.     
  188.         if (search_current == current) search_current = current->ln_Succ;
  189.         
  190.         current->ln_Succ = NULL;        /* Clear now invalid field */
  191.         
  192.         /* And insert it in getlist */
  193.         /* first detach list to modify it */
  194.         GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  195.         if ((nKeepSorted[1] == 1)&&(!noparse))
  196.         {
  197.             SmartAdd(getlist,current,nSortType[1]);
  198.         }
  199.         else
  200.         {
  201.             AddTail(getlist,current);
  202.         }
  203.         GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  204.         
  205.         
  206.         files_selected++;
  207.         filelist_length--;
  208.         index--;                /* Is this the best thing, short of a search through the */
  209.         if (index<0) index = 0;    /* Whole list for the index of current?  */
  210.         
  211.         ChangeWindowTitle();
  212.         }
  213.     }
  214.     
  215. }
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. int list2Clicked (VOID)
  225. {
  226. /* This function will move a clicked item from the lower list to the upper one */
  227.  
  228. int i;
  229. struct Node *current = getlist->lh_Head;
  230. struct Gadget *toplist = mgetGadgets[0];
  231. struct Gadget *botlist = mgetGadgets[1];
  232.  
  233.  for (i=0; i<lastcode; i++)
  234.     {
  235.     current = current->ln_Succ;
  236.     }
  237.  
  238. UpdateByteCount(current->ln_Name,-1);
  239.  
  240. /* Take it out of getlist */
  241. GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  242. Remove(current);
  243. GT_SetGadgetAttrs(botlist, mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
  244.  
  245. current->ln_Succ = NULL;        /* Clear now invalid field */
  246.  
  247. /* And insert it in filelist */
  248. GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  249.  if ((nKeepSorted[0] == 1)&&(!noparse))
  250.  {    
  251.      SmartAdd(filelist,current,nSortType[0]);
  252.  }
  253. else
  254. {
  255.     AddTail(filelist,current);
  256. }
  257.  
  258. GT_SetGadgetAttrs(toplist, mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  259. /* and that's it! */
  260. files_selected--;
  261. filelist_length++;
  262.  
  263. ChangeWindowTitle();
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. int AreAminetNames(char *sString1, char *sString2)
  272. {
  273. /* checks to see if the appropriate chars K, M, or ? are in the file size
  274.    position */
  275.    
  276.   /* Should I check the string size to make sure i'm not reading memory 
  277.      after the end of the string?  I can, but it'll probably be really
  278.      expensive!  So we'll try it without... */
  279.   if (((sString1[SIZEUNITPOS] == 'K')||(sString1[SIZEUNITPOS] == 'M')||(sString1[SIZEUNITPOS] == '?'))
  280.      &&((sString2[SIZEUNITPOS] == 'K')||(sString2[SIZEUNITPOS] == 'M')||(sString2[SIZEUNITPOS] == '?')))
  281.             return(1);
  282.  return(0);
  283. }
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. int AminetFileSize(char *sString)
  292. {
  293. /* Returns file size, in kilobytes, of the given Aminet line */
  294. int multiplier = INVALID;
  295. int filesize = 0, wholenum;
  296. int outputlength = -1;
  297. int tenthofmultiplier = 0;
  298.  
  299. if (sString == NULL) {return(0);}
  300. if (sString[SIZEUNITPOS] == 'M') 
  301.     {
  302.     multiplier = 1024;   /* 1024 k in a M */
  303.     tenthofmultiplier = 102;
  304.     }
  305. if (sString[SIZEUNITPOS] == 'K') multiplier = 1;     /* 1 k in a k */
  306. if (sString[SIZEUNITPOS] == '?') multiplier = 0;
  307.  
  308. if (multiplier == INVALID) {return(0);}    /* If we don't know M or K, abort */
  309.  
  310.  if (sString[SIZEUNITPOS-2] == '.')        /* for when it's like:  3.5M */
  311.     {
  312.     /* figure out kilobytes */
  313.     wholenum = (int) (sString[SIZEUNITPOS-3] - '0');
  314.     
  315.     if ((wholenum >= 0)&&(wholenum <= 9))
  316.         {
  317.         filesize = filesize + (multiplier * wholenum);
  318.         }
  319.     wholenum = (int) (sString[SIZEUNITPOS-1] - '0');
  320.     if ((wholenum >= 0)&&(wholenum <= 9))
  321.         {
  322.         filesize = filesize + (tenthofmultiplier * wholenum);
  323.         }
  324.     }
  325.     else
  326.     {
  327.     wholenum = (int) (sString[SIZEUNITPOS-3] - '0');
  328.     if ((wholenum >= 0)&&(wholenum <= 9))
  329.         {
  330.         filesize = filesize + (100 * multiplier * wholenum);
  331.         }        
  332.     wholenum = (int) (sString[SIZEUNITPOS-2] - '0');
  333.         if ((wholenum >= 0)&&(wholenum <= 9))
  334.         {
  335.         filesize = filesize + ( 10 * multiplier * wholenum);
  336.         }
  337.     wholenum = (int) (sString[SIZEUNITPOS-1] - '0');
  338.     if ((wholenum >= 0)&&(wholenum <= 9))
  339.         {
  340.         filesize = filesize + (      multiplier * wholenum);
  341.         }
  342.     }
  343. return(filesize);
  344. }
  345.  
  346.  
  347.  
  348. void SmartAdd(struct List *thislist, struct Node *addme, int nThisSortType)
  349. {
  350. /* a simple add into the correct order of the list */
  351. struct Node *current, *past;
  352. char sBuffer1[43], sBuffer2[43];
  353.  
  354. current = thislist->lh_Head;
  355. past = NULL;
  356.  
  357. if ((addme == NULL)||(addme->ln_Name == NULL)) 
  358. {
  359.     printf("Tell Jeremy--bug #5!\n");
  360.     return();
  361. }
  362.  
  363. while (current != NULL)            
  364.         {
  365.             /* Only sort if this is an Aminet file line, or not an Aminet Sort */    
  366.             if ((current->ln_Name != NULL)&&(AreAminetNames(current->ln_Name, addme->ln_Name)))
  367.             {
  368.                 switch(nThisSortType)
  369.                 {
  370.                     case SORTBYDIR:
  371.                         strncpy(sBuffer1,addme->ln_Name+DIRNAMEPOS,DIRNAMESIZE);
  372.                         strncpy(sBuffer2,current->ln_Name+DIRNAMEPOS,DIRNAMESIZE);
  373.                         if ((strchr(sBuffer1,'/') != NULL)&&
  374.                              (strchr(sBuffer2,'/') != NULL)&&
  375.                               (strncmp(sBuffer1,sBuffer2,DIRNAMESIZE) < 0))
  376.                         {
  377.                             Insert(thislist, addme, past);    /* and put it back in after current */
  378.                             return();
  379.                         }
  380.                     break;
  381.                 
  382.                     case SORTBYDESC:
  383.                         if (strncmp(addme->ln_Name+DESCPOS,current->ln_Name+DESCPOS,DESCSIZE) < 0)
  384.                         {
  385.                             Insert(thislist, addme, past);    /* and put it back in after current */
  386.                             return();
  387.                         }
  388.                     break;
  389.                     
  390.                     case SORTBYNAME:
  391.                         memset(sBuffer1,NUL,NAMESIZE);  /* sort sometimes goes into infinite loops if you don't have this??? */
  392.                         memset(sBuffer2,NUL,NAMESIZE);  /* It shouldn't, though, because strncpy terminates everything right? */
  393.                         strncpy(sBuffer1,addme->ln_Name+NAMEPOS,NAMESIZE);
  394.                         strncpy(sBuffer2,current->ln_Name+NAMEPOS,NAMESIZE);    
  395.                         if (strncmp(sBuffer1,sBuffer2,NAMESIZE) < 0)
  396.                         {
  397.                             Insert(thislist, addme, past);    /* and put it back in after current */        
  398.                             return();
  399.                         }
  400.                     break;
  401.                     
  402.                     case SORTBYSIZE:
  403.                         if (AminetFileSize(addme->ln_Name) < AminetFileSize(current->ln_Name))
  404.                         {
  405.                             Insert(thislist, addme, past);    /* and put it back in after current */
  406.                             return();
  407.                         }
  408.                     break;
  409.                 }
  410.             }    
  411.             past = current;                /* step to next in list */
  412.             current = current->ln_Succ;
  413.         }
  414.         
  415.     AddTail(thislist,addme);        /* If we've got to the end without returning, add it to the end */
  416.     return();
  417. }
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425. void SortList(struct List *thislist, int nThisSortType)
  426. {
  427.     /* a simple swap-sort */
  428.     int nSwappedThisPass = 1, nUpdateTitle = 0, nUpdateCount = 0;
  429.     struct Node *current, *past;
  430.     char sBuffer1[43], sBuffer2[43],sSortWinString[20]; 
  431.     char sSortTypeString[25] = "Sorting by \0";
  432.     
  433.     /* Generate Window title prompt */
  434.     switch(nThisSortType)
  435.     {
  436.         case SORTBYDIR:
  437.             strcat(sSortTypeString,"Directory");
  438.         break;
  439.         
  440.         case SORTBYSIZE:
  441.             strcat(sSortTypeString,"Size");
  442.         break;
  443.         
  444.         case SORTBYDESC:
  445.             strcat(sSortTypeString,"Description");
  446.         break;
  447.  
  448.         case SORTBYNAME:
  449.             strcat(sSortTypeString,"FileName");
  450.         break;
  451.     }
  452.     
  453.     if (thislist == NULL)
  454.     {
  455.         return;
  456.     }
  457.     
  458.     /* Remove list from ListView if necessary  */
  459.      if (windowisopen)
  460.      {
  461.           if (thislist == filelist) GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  462.          if (thislist ==  getlist) GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  463.         SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  464.     }
  465.  
  466.     while (nSwappedThisPass > 0)
  467.     {
  468.         /* start a pass */
  469.         past = thislist->lh_Head;
  470.         if (past == NULL)
  471.         {
  472.             /* empty list ! */
  473.             if (windowisopen)
  474.             {
  475.                 /* Replace list into ListView */
  476.                 if (thislist == filelist) GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  477.                 if (thislist ==  getlist) GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels,  getlist, TAG_END);
  478.                 ChangeWindowTitle();
  479.                 ClearPointer(mgetWnd);
  480.             }
  481.             return;
  482.         }
  483.         current = past->ln_Succ;
  484.         nSwappedThisPass = 0;        /* start with none recorded */
  485.  
  486.         while (current != NULL)            
  487.         {
  488.             /* Only sort if this is an Aminet file line, or not an Aminet Sort */    
  489.             if ((current->ln_Name != NULL)&&(past->ln_Name != NULL)&&
  490.                 (AreAminetNames(current->ln_Name, past->ln_Name)))
  491.             {
  492.                 switch(nThisSortType)
  493.                 {
  494.                     case SORTBYDIR:
  495.                         strncpy(sBuffer1,past->ln_Name+DIRNAMEPOS,DIRNAMESIZE);
  496.                         strncpy(sBuffer2,current->ln_Name+DIRNAMEPOS,DIRNAMESIZE);
  497.                         if ((strchr(sBuffer1,'/') != NULL)&&
  498.                              (strchr(sBuffer2,'/') != NULL)&&
  499.                               (strncmp(sBuffer1,sBuffer2,DIRNAMESIZE) > 0))
  500.                         {
  501.                             /* Swap the two nodes */
  502.                             Remove(past);                            /* take previous out of list */
  503.                             Insert(thislist, past, current);    /* and put it back in after current */
  504.                             nSwappedThisPass++;
  505.                         }
  506.                     break;
  507.                 
  508.                     case SORTBYDESC:
  509.                         if (strncmp(past->ln_Name+DESCPOS,current->ln_Name+DESCPOS,DESCSIZE) > 0)
  510.                         {
  511.                             /* Swap the two nodes */
  512.                             Remove(past);                            /* take previous out of list */
  513.                             Insert(thislist, past, current);    /* and put it back in after current */
  514.                             nSwappedThisPass++;
  515.                         }
  516.                     break;
  517.                     
  518.                     case SORTBYNAME:
  519.                         strncpy(sBuffer1,past->ln_Name+NAMEPOS,NAMESIZE);
  520.                         strncpy(sBuffer2,current->ln_Name+NAMEPOS,NAMESIZE);    
  521.                         if (strncmp(sBuffer1,sBuffer2,NAMESIZE) > 0)
  522.                         {
  523.                             /* Swap the two nodes */
  524.                             Remove(past);                            /* take previous out of list */
  525.                             Insert(thislist, past, current);    /* and put it back in after current */
  526.                             nSwappedThisPass++;
  527.                         }
  528.                     break;
  529.                     
  530.                     case SORTBYSIZE:
  531.                         if (AminetFileSize(past->ln_Name) > AminetFileSize(current->ln_Name))
  532.                         {
  533.                         /* Swap the two nodes */
  534.                             Remove(past);                            /* take previous out of list */
  535.                             Insert(thislist, past, current);    /* and put it back in after current */
  536.                             nSwappedThisPass++;
  537.                         }
  538.                     break;
  539.                 }
  540.             }    
  541.             past = current;
  542.             current = current->ln_Succ;
  543.         }
  544.         
  545.         if (windowisopen)
  546.         {
  547.             sprintf(sSortWinString,"%s, please be patient:  %i",sSortTypeString,nUpdateCount);
  548.             SetWindowTitles(mgetWnd, sSortWinString, (char *) ~0);
  549.             nUpdateCount++; 
  550.          }              
  551.     }
  552.         
  553.     if (windowisopen)
  554.     {
  555.         /* Replace list into ListView */
  556.         if (thislist == filelist) GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  557.         if (thislist ==  getlist) GT_SetGadgetAttrs(mgetGadgets[1], mgetWnd, NULL, GTLV_Labels,  getlist, TAG_END);
  558.         ClearPointer(mgetWnd);
  559.     }
  560.     ChangeWindowTitle();
  561.     return;
  562. }
  563.         
  564.         
  565.  
  566.  
  567. int OutputList(struct List *thislist)
  568. {
  569. #define LASTDIRBUFSIZE 30
  570.  
  571.  char *j, *j2, *p;
  572.  int k,l,z,next_bytes,putnameOK = 0,putcommandOK = 1; 
  573.  int printed_bytes = maxoutputlinelength - 1, printreturnfirst = 0;
  574.  char outname[MAXFILELINELENGTH],szLastDir[LASTDIRBUFSIZE];
  575.  struct Node *current;
  576.  
  577.  memset(szLastDir,NUL,LASTDIRBUFSIZE);
  578.  
  579.  /* Get any readme files first, so user can browse them while d/l'ing the rest */
  580.  if (getreadmes)
  581.     {
  582.     current = thislist->lh_Head;
  583.      while (current != NULL)
  584.           {
  585.         /* watch out for empty nodes! */
  586.         if (current->ln_Name != NULL) 
  587.             {
  588.             z = strlen(current->ln_Name);
  589.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  590.             if ((current->ln_Name[0] < '0')||(current->ln_Name [0] > 'z')) z = 0;
  591.             if ((current->ln_Name[35] != 'K')&&(current->ln_Name[35] != 'M')&&(current->ln_Name[35] != '?')) z = 0;
  592.             if (current->ln_Name[21] < '0') z = 0;
  593.             if ((filesflag == 0)&&(current->ln_Name[36] != '+')) z = 0;
  594.             /* end code from mgetlistviewclicked() ... */
  595.             }
  596.             else z=0;
  597.         
  598.         
  599.         
  600.         if (z>21)
  601.             {
  602.             j = strchr(current->ln_Name,32);       /* address of first space after filename */
  603.             k = j - current->ln_Name;               /* length of filename */
  604.             j2 = strchr(current->ln_Name+21,32);    /* address of directory of file */
  605.             l = j2 - (current->ln_Name) - 21;        /* length of directory */
  606.     
  607.             if ((k<22)&&(k>0)&&(l<12)&&(l>2))
  608.                 {
  609.                 memset(outname,NUL,MAXFILELINELENGTH);
  610.                 strncat(outname,current->ln_Name+21,l);
  611.                 
  612.                 /* Here we have the directory name--see if it's different, generate cd */
  613.                 if ((current->ln_Name[36] == '+')&&
  614.                     (nocd == 0)&&
  615.                     (simplepaths == 1)&&
  616.                     (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  617.                 {
  618.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  619.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  620.                     putnameOK = 1;
  621.                     putcommandOK = 0;
  622.                 }
  623.                 
  624.                 if (simplepaths == 1)
  625.                 {    
  626.                     /* remove path so it won't be printed again in the mget command */
  627.                     memset(outname,NUL,sizeof(outname));
  628.                 }
  629.                 else
  630.                 {
  631.                     strncat(outname,"/",1);
  632.                 }
  633.                 
  634.                 strncat(outname,current->ln_Name,k);
  635.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  636.             
  637.                 if (current->ln_Name[36] == '+')
  638.                     {    
  639.                     /* find the last '.' in outname, and change whatever's after it to 'readme'! */
  640.                     p = strrchr(outname,'.');
  641.                     
  642.                     /* and if there is no "." ? */
  643.                     if (p == NULL)
  644.                     {
  645.                         strcat(outname,".");
  646.                         p = strrchr(outname,'.');
  647.                     }
  648.                     
  649.                     strcpy(p+1,"readme");
  650.                     
  651.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  652.                     if ((next_bytes>3)&&(next_bytes<39))
  653.                         {
  654.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  655.                             {
  656.                             PrintCommandString(&printreturnfirst, &printed_bytes);            
  657.                             putnameOK = 1;
  658.                             }            
  659.                         fprintf(fpOut,"%s ",outname);
  660.                         printed_bytes = printed_bytes + next_bytes;
  661.                         putcommandOK = 1;
  662.                         }
  663.                     }
  664.                 }
  665.             }
  666.         current = current->ln_Succ;    
  667.         }
  668.     }        
  669.  
  670.  if (filesflag)
  671.  {    
  672.  current = thislist->lh_Head;    
  673.     while (current != NULL)
  674.     {
  675.         /* watch out for empty nodes! */
  676.         if (current->ln_Name != NULL)
  677.             {
  678.             z = strlen(current->ln_Name);
  679.             /* Extra filtering code, borrowed from mgetlistviewclicked()... */
  680.             if ((current->ln_Name[0] < '0')||(current->ln_Name [0] > 'z')) z = 0;
  681.             if ((current->ln_Name[35] != 'K')&&(current->ln_Name[35] != 'M')&&(current->ln_Name[35] != '?')) z = 0;
  682.             if (current->ln_Name[21] < '0') z = 0;
  683.             if ((filesflag == 0)&&(current->ln_Name[36] != '+')) z = 0;
  684.             /* end code from mgetlistviewclicked() ... */
  685.             }
  686.             else
  687.             {
  688.             z=0;
  689.             }
  690.         
  691.         if (z>21)
  692.             {
  693.             j = strchr(current->ln_Name,32);   /* address of first space after filename */
  694.             k = j - current->ln_Name;           /* length of filename */
  695.             j2 = strchr(current->ln_Name+21,32);   /* address of directory of file */
  696.             l = j2 - (current->ln_Name) - 21;        /* length of directory */
  697.     
  698.             if ((k<22)&&(k>0)&&(l<12)&&(l>2))
  699.                 {
  700.                 memset(outname,NUL,MAXFILELINELENGTH);
  701.                 strncat(outname,current->ln_Name+21,l);
  702.  
  703.                 /* Here we have the directory name--see if it's different, generate cd */
  704.                 if ((nocd == 0)&&
  705.                      (simplepaths == 1)&&
  706.                      (strncmp(szLastDir,outname,LASTDIRBUFSIZE) != 0)) 
  707.                 {
  708.                     memset(szLastDir,NUL,LASTDIRBUFSIZE);
  709.                     GenerateCDCommand(&printreturnfirst, &printed_bytes, szLastDir, outname);
  710.                     putcommandOK = 0;
  711.                     putnameOK = 1;
  712.                 }
  713.                 
  714.                 if (simplepaths == 1)
  715.                 {    
  716.                     /* remove path so it won't be printed again in the mget command */
  717.                     memset(outname,NUL,sizeof(outname));
  718.                 }
  719.                 else
  720.                 {
  721.                     strncat(outname,"/",1);
  722.                 }
  723.                 
  724.                 
  725.                 strncat(outname,current->ln_Name,k);
  726.                 outname[79]=0;    /* just in case, we'll reterminate the string */            
  727.                 if (filesflag)
  728.                     {    
  729.                     next_bytes = strlen(outname) + 1;    /* + 1 for the space */
  730.                     if ((next_bytes>3)&&(next_bytes<33))
  731.                         {
  732.                         if ((putcommandOK == 1)&&(!nosplit)&&((printed_bytes + next_bytes) > maxoutputlinelength))
  733.                             {
  734.                             PrintCommandString(&printreturnfirst, &printed_bytes);    
  735.                             putnameOK = 1;
  736.                             }            
  737.                         fprintf(fpOut,"%s ",outname);
  738.                         putcommandOK = 1;
  739.                         printed_bytes = printed_bytes + next_bytes;
  740.                         }
  741.                     }
  742.                 }
  743.             }    
  744.         current = current->ln_Succ;    
  745.         }
  746.     }
  747. return(1);
  748. }
  749.  
  750.  
  751.  
  752.  
  753. void PrintCommandString(int *printreturnfirst, int *printed_bytes)
  754. {
  755.     if (*printreturnfirst) fprintf(fpOut,"\r\n"); 
  756.     *printreturnfirst = 1;
  757.         
  758.     if (nocommand) 
  759.     {
  760.         *printed_bytes = 0;
  761.     }
  762.     else
  763.     {
  764.         fprintf(fpOut,"%s ",szCommandString);
  765.         *printreturnfirst = 1;
  766.         *printed_bytes = strlen(szCommandString) + 1;    /* reset counter for next batch */
  767.     }
  768.     return;
  769. }
  770.  
  771.  
  772.  
  773.  
  774. void GenerateCDCommand(int *printreturnfirst, int *printed_bytes, char *szLastDir, char *outname)
  775. {
  776.     if (*printreturnfirst) fprintf(fpOut,"\r\n");
  777.     fprintf(fpOut,"cd ");
  778.                 
  779.     /* On the first item, we will be starting at the aminet root
  780.        directory, so we won't need to print the ../.. .  After that,
  781.         though, we will.  printreturnfirst serves nicely to tell
  782.         whether or not we're in the first iteration. */   
  783.     
  784.     if (*printreturnfirst == 1) fprintf(fpOut,"../../");
  785.             
  786.     fprintf(fpOut,"%s",outname);
  787.     *printreturnfirst = 1;
  788.     PrintCommandString(printreturnfirst, printed_bytes);
  789.  
  790.     /* update buffer */    
  791.     strncpy(szLastDir,outname,30);    
  792.  
  793.     return;
  794. }            
  795.  
  796.  
  797.  
  798. int RawOutputList(struct List *thislist)
  799. {
  800. struct Node *current = thislist->lh_Head;
  801. int minlinelength = 1;
  802.  
  803.  if (keepblanklines == 1) minlinelength = 0;
  804.       
  805.  while (current != NULL)
  806.     {    
  807.     if ((current->ln_Name != NULL)&&(current->ln_Name[0] < 128)&&(strlen(current->ln_Name) >= minlinelength))
  808.         {
  809.             if (current->ln_Name[0] < 14) 
  810.             {
  811.                 fprintf(fpOut,"\n",current->ln_Name);
  812.             }
  813.             else
  814.             {
  815.                 fprintf(fpOut,"%.300s\n",current->ln_Name);
  816.             }
  817.         }
  818.     current = current->ln_Succ;
  819.     }
  820. return(1);
  821. }
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831. int MakeReq(char *sText, char *sTitle, char *sGadgets)
  832. {
  833. struct EasyStruct myreq;
  834. LONG number = 0L;
  835. int nResult;
  836. char sDefaultTitle[] = "GadMGet Error";
  837.  
  838. if (sTitle == NULL) sTitle = sDefaultTitle;
  839. if (sText == NULL) sText = sDefaultTitle;
  840. if (sGadgets == NULL) sGadgets = "OK";
  841.  
  842. myreq.es_TextFormat   = sText;
  843. myreq.es_Title        = sTitle;
  844. myreq.es_GadgetFormat = sGadgets;
  845.  
  846. if (mgetWnd != NULL) SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  847. nResult = EasyRequest(mgetWnd, &myreq, NULL, NULL, number);
  848. if (mgetWnd != NULL) ClearPointer(mgetWnd);
  849.  
  850. return(nResult);
  851. }
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. int mgetabout (VOID)
  865. {
  866. char sAboutText[100];
  867.  
  868. strcpy(sAboutText,pnamestring);
  869. strcat(sAboutText,"\n%s\n\nby Jeremy Friesner\njfriesne@ucsd.edu\n");
  870. MakeReq(sAboutText,"About GadMGet","Hey, Cool!");
  871. return(1);
  872. }
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881. int mgetquit (VOID)
  882. {
  883. done=TRUE;
  884. }
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891. int mgetcase (VOID)
  892. {
  893. if (casesensitive == 0) casesensitive = 1; else casesensitive = 0;
  894. SetMenuValues();
  895. }
  896.  
  897.  
  898.  
  899.  
  900. int mgetCD (VOID)
  901. {
  902. if (simplepaths == 0) simplepaths = 1; else simplepaths = 0;
  903. SetMenuValues();
  904. }
  905.  
  906.  
  907.  
  908.  
  909. int mgetfind (VOID)
  910. {
  911. ULONG winsig, signals;
  912. int done = 0, found = 0;
  913. int fwindowwidth = 450, fwindowheight = 35 + Scr->RastPort.TxHeight;
  914. int fwindowleft = (mgetLeft + (windowwidth/2) - (fwindowwidth/2));
  915. int fwindowtop  = (mgetTop  + (windowheight/2)- (fwindowheight/2));
  916. struct NewGadget stringGad;
  917. struct IntuiMessage *imsg;
  918. struct Gadget *newgad = NULL;
  919. char numstring[100], *ss = searchstring, sTempOutString[300];
  920. char *wp = NULL,windowtitlestring0[] = "Search Window", 
  921.                 windowtitlestring1[] = "Line Length Window",
  922.                 windowtitlestring2[] = "Output File Change Window";
  923. FILE *fpTemp = NULL;
  924.     
  925. index = 0;        /* start searching at top again! */
  926.  
  927. findvi  = GetVisualInfo(Scr, TAG_END);
  928. if (findvi == NULL) return(0);
  929. if (findwindow != NULL) return(0);
  930.  
  931.  
  932. if (fwindowleft < 0) fwindowleft = mgetLeft;
  933. if (fwindowheight < 0) fwindowtop = mgetTop;
  934.  
  935.  newgad = CreateContext(&findgadlist);
  936.  if (newgad == 0)
  937.     {
  938.     MakeReq("Couldn't create findwindow gad context!\n",NULL,"Dammit!");
  939.     return(0);
  940.     }
  941.  
  942.  if (newgad == NULL) return(0);
  943.  
  944. stringGad.ng_TextAttr     = &topaz8;    /* Cant figure out how to get system default into a TextAttr!  No name string available! */
  945. stringGad.ng_VisualInfo  = findvi;
  946. stringGad.ng_LeftEdge     = 5;
  947. stringGad.ng_TopEdge        = 18 + Scr->RastPort.TxHeight;
  948. stringGad.ng_Width         = (fwindowwidth-10);
  949. stringGad.ng_Height         = 13;
  950. stringGad.ng_GadgetText  = "Please enter search string.";
  951. stringGad.ng_GadgetID     = 35;    
  952. stringGad.ng_Flags         = PLACETEXT_ABOVE;
  953.  
  954.  if (requesttype == FIND_REQUESTTYPE) 
  955.   {
  956.     wp = windowtitlestring0;
  957.   }
  958.  
  959.  if (requesttype == LINELENGTH_REQUESTTYPE)
  960.   {
  961.      wp = windowtitlestring1;
  962.      stringGad.ng_GadgetText = "Please enter new maximum line length.";
  963.      sprintf(numstring,"%i\0",maxoutputlinelength);    
  964.      ss = numstring;
  965.   }
  966.  if (requesttype == OUTPUTFILE_REQUESTTYPE)
  967.   {
  968.      wp = windowtitlestring2;
  969.      stringGad.ng_GadgetText = "Please enter new output file path/device.";
  970.      sprintf(numstring,"%s",sOutFileName);
  971.      strncpy(sTempOutString,sOutFileName,sizeof(sTempOutString));
  972.      ss = sTempOutString;
  973.   }
  974.  
  975.  
  976.  newgad = CreateGadget(STRING_KIND, newgad, &stringGad, 
  977.                   GTST_String, ss, 
  978.                   STRINGA_Justification, GACT_STRINGCENTER, 
  979.                   GA_Immediate, TRUE,
  980.                   TAG_END);  
  981.  
  982.  if (newgad == NULL) 
  983.     {
  984.     FreeGadgets(findgadlist);
  985.     FreeVisualInfo(findvi);
  986.     return(0);
  987.     }
  988.  
  989.  if (GadToolsBase->lib_Version == 37)
  990.     {
  991.     /* Only do it the "illegal" way under v37.  GA_Immediate in the CreateGadget
  992.        line, above, won't work under v37 but will on later releases. */
  993.     newgad->Activation |= GACT_IMMEDIATE; 
  994.     }    
  995.  
  996.  switch (screentype)
  997.     {
  998.     case USE_PUBSCREEN:
  999.         findwindow = OpenWindowTags(NULL,
  1000.                 WA_Left,        fwindowleft,
  1001.                 WA_Top,        fwindowtop,
  1002.                 WA_Width,         fwindowwidth,
  1003.                 WA_Height,    fwindowheight,
  1004.                 WA_PubScreen,    Scr,
  1005.                 WA_PubScreenFallBack, TRUE,
  1006.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1007.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1008.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1009.                 WA_Gadgets,    findgadlist,
  1010.                 WA_Title,         wp,
  1011.                 WA_ScreenTitle,    pnamestring,
  1012.                 TAG_DONE );
  1013.         break;
  1014.     case USE_CUSTOMSCREEN:
  1015.         findwindow = OpenWindowTags(NULL,
  1016.                 WA_Left,        fwindowleft,
  1017.                 WA_Top,        fwindowtop,
  1018.                 WA_Width,         fwindowwidth,
  1019.                 WA_Height,    fwindowheight,
  1020.                 WA_CustomScreen, Scr,
  1021.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1022.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1023.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1024.                 WA_Gadgets,    findgadlist,
  1025.                 WA_Title,         wp,
  1026.                 WA_ScreenTitle,    pnamestring,
  1027.                 WA_CustomScreen,    Scr,
  1028.                 TAG_DONE );
  1029.         break;
  1030.     case USE_WBSCREEN:
  1031.         findwindow = OpenWindowTags(NULL,
  1032.                 WA_Left,        fwindowleft,
  1033.                 WA_Top,        fwindowtop,
  1034.                 WA_Width,         fwindowwidth,
  1035.                 WA_Height,    fwindowheight,
  1036.                 WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|
  1037.                             IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  1038.                 WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  1039.                 WA_Gadgets,    findgadlist,
  1040.                 WA_Title,         wp,
  1041.                 WA_ScreenTitle,    pnamestring,
  1042.                 TAG_DONE );
  1043.         break;
  1044.     }
  1045.  
  1046. if (findwindow == NULL) return(0);
  1047. GT_RefreshWindow(findwindow, NULL); 
  1048.  
  1049. SetWindowTitles(mgetWnd, "MGet window inactive--close daughter window to continue", (char *) ~0); 
  1050. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1051.  
  1052. winsig = 1 << findwindow->UserPort->mp_SigBit;
  1053.  
  1054.  while (!done)
  1055.     {
  1056.     signals = Wait(winsig);
  1057.     if (signals&winsig)
  1058.         {
  1059.         while ((!done) && (imsg = GT_GetIMsg(findwindow->UserPort)))
  1060.             {
  1061.             
  1062.             switch(imsg->Class)
  1063.                 {            
  1064.                 case IDCMP_ACTIVEWINDOW:
  1065.                     ActivateGadget(newgad,findwindow,NULL);
  1066.                     break;
  1067.                         
  1068.                 case IDCMP_GADGETUP:
  1069.                     strncpy(ss,((struct StringInfo*)newgad->SpecialInfo)->Buffer,sizeof(searchstring));
  1070.                     done = 1;
  1071.                     break;
  1072.         
  1073.                 case IDCMP_CLOSEWINDOW:
  1074.                     done = 2;
  1075.                     break;
  1076.                     
  1077.                 case IDCMP_REFRESHWINDOW:
  1078.                     GT_BeginRefresh(findwindow);
  1079.                     GT_EndRefresh(findwindow, TRUE);
  1080.                     break;
  1081.                 }
  1082.             GT_ReplyIMsg(imsg);
  1083.             }
  1084.         }
  1085.     }
  1086.     
  1087. CloseWindow(findwindow);
  1088. FreeGadgets(findgadlist);
  1089. FreeVisualInfo(findvi); 
  1090. findwindow = NULL;
  1091.  
  1092. ClearPointer(mgetWnd);
  1093.  
  1094.  if (requesttype == LINELENGTH_REQUESTTYPE) 
  1095.     {
  1096.     ChangeWindowTitle();    
  1097.     return(atoi(ss));
  1098.     }
  1099.  if (requesttype == OUTPUTFILE_REQUESTTYPE)
  1100.     {
  1101.         if (strlen(sTempOutString) == 0)
  1102.         {
  1103.             if (BStartedFromWB == FALSE)
  1104.             {
  1105.                 fpOut = stdout;
  1106.                 *sOutFileName = '\0';    /* blank out filename string */
  1107.             }
  1108.             else
  1109.             {
  1110.                 strncpy(sTempOutString,"ram:GadMget.output",sizeof(sOutFileName));
  1111.             }
  1112.         }
  1113.         else
  1114.         {
  1115.             fpTemp = fopen(sTempOutString,"w");
  1116.             if (fpTemp == NULL)
  1117.             {
  1118.                 MakeReq("Couldn't open output file!\n",NULL,"Ok");
  1119.             }
  1120.             else
  1121.             {
  1122.                 fpOut = fpTemp;
  1123.                 strncpy(sOutFileName,sTempOutString,sizeof(sOutFileName));
  1124.                 fclose(fpTemp);
  1125.             }
  1126.         }
  1127.     ChangeWindowTitle();
  1128.     return(0);
  1129.     }
  1130.     
  1131.  if ((done == 2)||(strlen(searchstring) == 0))
  1132.     {
  1133.     ChangeWindowTitle();
  1134.     return(0);    /* can use searchstring now instead of ss */
  1135.     }            /* because we're no longer worried about the nums */
  1136.  
  1137. /* Now find it in the filelist */
  1138. search_current = (char *) filelist->lh_Head;
  1139. if (SearchList(searchstring) == -1) DisplayBeep(Scr); else findgadgoto(index,3);
  1140. return(1);
  1141. }
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153. int mgetfindnext (VOID)
  1154. {
  1155. /* bump to next node */
  1156. if (search_current == NULL) {DisplayBeep(Scr); return(0);}
  1157. search_current = search_current->ln_Succ;
  1158. if (search_current == NULL) {DisplayBeep(Scr); return(0);}
  1159. index++;
  1160. if (SearchList(searchstring) == -1) DisplayBeep(Scr); else findgadgoto(index,2);
  1161. return(1);
  1162. }
  1163.  
  1164.  
  1165.  
  1166.  
  1167. int mgetfilesbydir (void)
  1168. {
  1169. nSortType[0] = SORTBYDIR;
  1170.  
  1171. SortList(filelist,nSortType[0]);
  1172. }
  1173.  
  1174.  
  1175. int mgetfilesbysize (void)
  1176. {
  1177. nSortType[0] = SORTBYSIZE;
  1178.  
  1179. SortList(filelist,nSortType[0]);
  1180. }
  1181.  
  1182.  
  1183. int mgetfilesbyname (void)
  1184. {
  1185. nSortType[0] = SORTBYNAME;
  1186.  
  1187. SortList(filelist,nSortType[0]);
  1188. }
  1189.  
  1190.  
  1191. int mgetfilesbydesc (void)
  1192. {
  1193. nSortType[0] = SORTBYDESC;
  1194.  
  1195. SortList(filelist,nSortType[0]);
  1196. }
  1197.  
  1198. int mgetfileskeep (void)
  1199. {
  1200. if (nKeepSorted[0] == 1) 
  1201.     {
  1202.         nKeepSorted[0] = 0;
  1203.     }
  1204.     else
  1205.     {
  1206.         nKeepSorted[0] = 1;
  1207.         SortList(filelist,nSortType[0]);
  1208.     }
  1209. }
  1210.  
  1211.  
  1212. int mgetgetbydir (void)
  1213. {
  1214. nSortType[1] = SORTBYDIR;
  1215.  
  1216. SortList(getlist,nSortType[1]);
  1217. }
  1218.  
  1219.  
  1220. int mgetgetbysize (void)
  1221. {
  1222. nSortType[1] = SORTBYSIZE;
  1223.  
  1224. SortList(getlist,nSortType[1]);
  1225. }
  1226.  
  1227.  
  1228. int mgetgetbyname (void)
  1229. {
  1230. nSortType[1] = SORTBYNAME;
  1231.  
  1232. SortList(getlist,nSortType[1]);
  1233. }
  1234.  
  1235.  
  1236. int mgetgetbydesc (void)
  1237. {
  1238. nSortType[1] = SORTBYDESC;
  1239.  
  1240. SortList(getlist,nSortType[1]);
  1241. }
  1242.  
  1243.  
  1244. int mgetgetkeep (void)
  1245. {
  1246. if (nKeepSorted[1] == 1) 
  1247.     {
  1248.         nKeepSorted[1] = 0;
  1249.     }
  1250.     else
  1251.     {
  1252.         nKeepSorted[1] = 1;
  1253.         SortList(getlist,nSortType[1]);
  1254.     }
  1255. }
  1256.  
  1257.  
  1258.  
  1259. int SearchList(char *key)
  1260. {
  1261. int found = 0;
  1262. char sUpperBuffer[MAXFILELINELENGTH], sUppersearchstring[MAXFILELINELENGTH];
  1263.  
  1264. SetWindowTitles(mgetWnd, "Searching...", (char *) ~0); 
  1265. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1266.  
  1267. if (casesensitive)    
  1268.     {
  1269.     while ((search_current != NULL)&&(found == 0))
  1270.         {
  1271.         if ((search_current->ln_Name != NULL)&&(strstr(search_current->ln_Name,searchstring) != 0))
  1272.                 found = 1;
  1273.                 else
  1274.                 {
  1275.                 search_current = search_current->ln_Succ; 
  1276.                 index++;
  1277.                 }
  1278.         }
  1279.     }
  1280.     else
  1281.     {
  1282.     strncpy(sUppersearchstring,key,sizeof(sUppersearchstring));
  1283.     UpperCase(sUppersearchstring);
  1284.     while ((search_current != NULL)&&(found == 0))
  1285.         {
  1286.         if (search_current->ln_Name != NULL)
  1287.             {
  1288.             strncpy(sUpperBuffer,search_current->ln_Name,sizeof(sUpperBuffer)-1);
  1289.             UpperCase(sUpperBuffer);
  1290.             if (strstr(sUpperBuffer,sUppersearchstring) != 0)
  1291.                 found = 1;
  1292.             }
  1293.         if (found == 0)
  1294.             {
  1295.             search_current = search_current->ln_Succ; 
  1296.             index++;
  1297.             }
  1298.         }
  1299.     }
  1300.     
  1301. ChangeWindowTitle();
  1302. ClearPointer(mgetWnd);
  1303.  
  1304. if (found == 1) return(index); else return(-1);
  1305. }
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317. void findgadgoto (int index, int numberofflashes)
  1318. {
  1319. int i, xmin, ymin, xmax, ymax, ystep, midscreen;
  1320. int WindowHeightLines = nTopListHeight/(listfont.ta_YSize);
  1321.  
  1322.  midscreen = index-(WindowHeightLines/2);
  1323.  if (midscreen < 0) midscreen = 0;
  1324.  
  1325.  if (filelist_length > WindowHeightLines)
  1326.          GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Top, midscreen, TAG_END);
  1327.  
  1328.  ystep = WindowHeightLines/2;            /* default, for middle of list */                                 
  1329.  if ((filelist_length-index) < (WindowHeightLines/2))
  1330.          ystep = index - (filelist_length - WindowHeightLines);
  1331.  if ((index < (WindowHeightLines/2))||
  1332.        (filelist_length <= WindowHeightLines)) ystep = index;    /* if at top */ 
  1333.  
  1334.  xmin = Scr->WBorLeft + 4;
  1335.  ymin = (nTopListTop + ((listfont.ta_YSize) *ystep) + 2);
  1336.  xmax = windowwidth - Scr->WBorLeft - 20;
  1337.  ymax = ymin + (listfont.ta_YSize) - 1;
  1338.  
  1339.  SetDrMd(mgetWnd->RPort, 50); 
  1340.  for (i=0;i<numberofflashes;i++)
  1341.      {
  1342.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  1343.      Delay(5);
  1344.      RectFill(mgetWnd->RPort,xmin,ymin,xmax,ymax);
  1345.      if (i<(numberofflashes-1)) Delay(5);
  1346.      }
  1347. }
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359. int mgetnoparse (void)
  1360. {
  1361. if (noparse) 
  1362.     {
  1363.     noparse = 0; 
  1364.     if (nKeepSorted[0] == 1) SortList(filelist,nSortType[0]);
  1365.     if (nKeepSorted[1] == 1) SortList(getlist, nSortType[0]);
  1366.     SetMenuValues();
  1367.     }
  1368.     else 
  1369.     {
  1370.     noparse = 1;        
  1371.     SetMenuValues();
  1372.     }
  1373. }
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382. int mgetfiles (void)
  1383. {
  1384. if (filesflag) 
  1385.     {
  1386.     filesflag = 0;
  1387.     getreadmes = 1;
  1388.     SetMenuValues();     
  1389.     }
  1390.     else 
  1391.     filesflag = 1;
  1392. }
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400. int mgetreadmes (void)
  1401. {
  1402. if (getreadmes) 
  1403.     {getreadmes = 0; 
  1404.      filesflag = 1;
  1405.      SetMenuValues();
  1406.     }
  1407.     else 
  1408.     getreadmes = 1;
  1409. }
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416. int mgetsplit (void)
  1417. {
  1418. if (nosplit) nosplit = 0; else nosplit = 1;
  1419. SetMenuValues();    
  1420. }
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427. int mgetlinelength (void)
  1428. {
  1429. int lin;
  1430.  
  1431. requesttype = LINELENGTH_REQUESTTYPE;    /* This is a HORRIBLE way to program, but I don't want  */
  1432. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  1433. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                 */
  1434.  
  1435. if (lin >  0) maxoutputlinelength = lin;
  1436. }
  1437.  
  1438.  
  1439.  
  1440.  
  1441. int mgetoutputfile (void)
  1442. {
  1443. int lin;
  1444.  
  1445. requesttype = OUTPUTFILE_REQUESTTYPE;    /* This is a HORRIBLE way to program, but I don't want  */
  1446. lin = mgetfind();                                /* to try to change the parameters since it might screw */
  1447. requesttype = FIND_REQUESTTYPE;            /* up the mget_listview2 functions...                        */
  1448.  
  1449. }
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. void PrintList(struct List *thislist)
  1457. {
  1458. struct Node *nodecurrent = thislist->lh_Head;
  1459.  
  1460. fprintf(fpOut,"thislist = %p\n",thislist);
  1461.  
  1462.  while (nodecurrent != NULL)
  1463.     {
  1464.     if (nodecurrent->ln_Name == NULL) 
  1465.         {
  1466.         fprintf(fpOut,"[ <NULL> ]\n"); 
  1467.         }
  1468.         else
  1469.         {
  1470.         fprintf(fpOut,"[%s]\n",nodecurrent->ln_Name);
  1471.         }
  1472.     nodecurrent = nodecurrent->ln_Succ;
  1473.     }
  1474.     
  1475. return();
  1476. }
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485. int mgetopenfile (void)
  1486. {
  1487. FILE *test = NULL;
  1488.  
  1489.  memset(inputfile,NUL,sizeof(inputfile));
  1490.  
  1491.  SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1492.  
  1493.  while (test == NULL) 
  1494.     {
  1495.     if (RequestAFile(inputfile) == 0) 
  1496.         {
  1497.         ClearPointer(mgetWnd);
  1498.         return(0);
  1499.         }
  1500.     test = fopen(inputfile,"r");
  1501.     }
  1502.  
  1503.  fclose(test);
  1504.  SetReqDefaults(inputfile);
  1505.  
  1506.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1507.  FreeFileNodes(filelist); 
  1508.  FreeMem(filelist,sizeof(struct List));
  1509.  added_bytes -= sizeof(struct List);
  1510.  ClearPointer(mgetWnd);
  1511.  
  1512.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  1513.     {
  1514.     MakeReq("mgetOpen : Couldn't create filelist!  Out of memory?\n",NULL,"Uh-oh");
  1515.     return(0);
  1516.     }
  1517.  added_bytes += sizeof(struct List);
  1518.         
  1519.  /* These are all dependant on a given filelist, so RESET! */
  1520.  filelist_length = 0;
  1521.  search_current = NULL;
  1522.  index = 0;
  1523.  
  1524.  NewList(filelist);      
  1525.  ReadmyFile();
  1526.  if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);  /* keep sorted if that is selected! */
  1527.  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1528. return(1);
  1529. }
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538. int mgetappend(void)
  1539. {
  1540. int returnme = 0;
  1541.  
  1542. memset(inputfile,NUL,sizeof(inputfile));
  1543.  
  1544. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  1545. returnme = ReadmyFile();
  1546. if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);  /* keep sorted if that is selected! */
  1547. GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  1548. return(returnme);
  1549. }
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556. int mgetCloseWindow (void)
  1557. {
  1558. done=TRUE;
  1559. }
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569. void SetMenuValues (void)
  1570. {
  1571. struct Menu *currentMenu = mgetMenus;
  1572. struct MenuItem *currentItem, *currentSub;
  1573.  
  1574.  if (currentMenu == NULL)
  1575.     {
  1576.     MakeReq("SetMenuValues:  error, mgetMenus is NULL!",NULL,"Huh?");
  1577.     return;
  1578.     }
  1579.     
  1580.  if (mgetWnd != NULL) ClearMenuStrip(mgetWnd);
  1581.  
  1582.  /* Make sure the CaseSensitive item in the second menu is checked correctly. */    
  1583.  currentMenu = currentMenu->NextMenu;
  1584.  currentItem = currentMenu->FirstItem;        /* #1 : Find */
  1585.  
  1586.  currentItem = currentItem->NextItem;        /* #2 : Next */
  1587.  
  1588.  currentItem = currentItem->NextItem;        /* #3 : Case Sensitive. */
  1589.  
  1590.  if (casesensitive)  currentItem->Flags |= CHECKED; 
  1591.             else  mgetNewMenu[9].nm_Flags &= ~(CHECKED);    
  1592.  
  1593.  /* next we do the Sort menu. */
  1594.  currentMenu = currentMenu->NextMenu;
  1595.  if (noparse) currentMenu->Flags &= ~(MENUENABLED);
  1596.        else currentMenu->Flags |= MENUENABLED;
  1597.  
  1598.  currentItem = currentMenu->FirstItem;    /* #1: Files List */
  1599.  currentSub = currentItem->SubItem;    /* #1.1 : By Directory */
  1600.  
  1601.  currentSub = currentSub->NextItem;    /* #1.2 : By Size */
  1602.  
  1603.  currentSub = currentSub->NextItem;    /* #1.3 : By FileName */
  1604.  currentSub = currentSub->NextItem;    /* #1.4 : By Description */
  1605.  currentSub = currentSub->NextItem;        /* #1.5 : Keep Sorted */
  1606.  if (nKeepSorted[0] == 0) currentSub->Flags &= ~(CHECKED);
  1607.                            else currentSub->Flags |= CHECKED;
  1608.  
  1609.  currentItem = currentMenu->FirstItem;    /* #1: Files List */
  1610.  currentItem = currentItem->NextItem;    /* #2: Get List */
  1611.  currentSub = currentItem->SubItem;    /* #2.1 : By Directory */
  1612.  currentSub = currentSub->NextItem;    /* #2.2 : By Size */
  1613.  currentSub = currentSub->NextItem;    /* #2.3 : By FileName */
  1614.  currentSub = currentSub->NextItem;    /* #2.4 : By Description */
  1615.  currentSub = currentSub->NextItem;        /* #2.5 : Keep Sorted */
  1616.  if (nKeepSorted[1] == 0) currentSub->Flags &= ~(CHECKED);
  1617.                            else currentSub->Flags |= CHECKED;
  1618.  
  1619.  /* now the toughie-- the Output menu. */
  1620.  currentMenu = currentMenu->NextMenu;
  1621.  
  1622.  currentItem = currentMenu->FirstItem;        /* #1: Aminet Parse */
  1623.  
  1624.  if (noparse) currentItem->Flags &= ~(CHECKED);
  1625.        else currentItem->Flags |= CHECKED;
  1626.        
  1627.        
  1628.  currentItem = currentItem->NextItem;        /* #2: Get Files */
  1629.  
  1630.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1631.        else currentItem->Flags |= ITEMENABLED;
  1632.  if (filesflag) currentItem->Flags |= CHECKED;
  1633.           else currentItem->Flags &= ~(CHECKED);
  1634.           
  1635.  currentItem = currentItem->NextItem;        /* #3: Get Readmes */
  1636.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1637.        else currentItem->Flags |= ITEMENABLED;
  1638.  if (getreadmes) currentItem->Flags |= CHECKED;
  1639.            else currentItem->Flags &= ~(CHECKED);
  1640.     
  1641.  currentItem = currentItem->NextItem;        /* #4: Split Commands */
  1642.  
  1643.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1644.        else currentItem->Flags |= ITEMENABLED;
  1645.  if (nosplit) currentItem->Flags &= ~(CHECKED);
  1646.            else currentItem->Flags |= CHECKED;
  1647.            
  1648.  
  1649.  currentItem = currentItem->NextItem;        /* #5: Use CD's */
  1650.  if (noparse) currentItem->Flags &= ~(ITEMENABLED);
  1651.        else currentItem->Flags |= ITEMENABLED;
  1652.  if (simplepaths) currentItem->Flags |= CHECKED;
  1653.            else currentItem->Flags &= ~(CHECKED);
  1654.            
  1655.  currentItem = currentItem->NextItem;        /* #6: Line length */
  1656.  if ((noparse)||(nosplit)) currentItem->Flags &= ~(ITEMENABLED);
  1657.        else currentItem->Flags |= ITEMENABLED;
  1658.  
  1659.  ResetMenuStrip( mgetWnd, mgetMenus );                 
  1660. }
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667. /* Turns all \n's in input string into <space><newline>'s */
  1668. void FindReturns(char *mystring)
  1669. {
  1670. char *thischar=mystring, *prevchar=mystring;
  1671.  
  1672.  while (*thischar != NULL)
  1673.     {
  1674.     
  1675.     if ( (*prevchar  ==   92) &&                        /* any '/'s ? */
  1676.          ((*thischar ==   78)||(*thischar == 110)) &&      /* N's or n's */
  1677.          (prevchar   !=  NULL) &&                        /* Sanity chk */
  1678.          (thischar   !=  NULL))
  1679.         
  1680.         {
  1681.         *prevchar = 32;   /* set this to a space--easier than shortening string */
  1682.         *thischar = 10;   /* and end this line with a newline char */
  1683.         }
  1684.     
  1685.     prevchar = thischar;
  1686.     thischar++;
  1687.     }
  1688. }
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698. int AddFile(struct List *mylist, char *newstring)
  1699. {
  1700. struct Node *newnode;
  1701. char *newname, *i, returnchar = 10, spacechar = 32;
  1702. UBYTE diff=MAXFILELINELENGTH;
  1703. int minlinelength = 1;
  1704.  
  1705.  if (keepblanklines == 1) minlinelength = 0;
  1706.  if (newstring == NULL) return(0);
  1707.  if (strlen(newstring) < minlinelength) return(0); 
  1708.  
  1709.  if (!( newnode = AllocMem(sizeof(struct Node),MEMF_CLEAR) ))
  1710.     {
  1711.     MakeReq("AddFile: Couldn't allocate Memory for Node!",NULL,"Uh-oh");
  1712.     return(0);
  1713.     }
  1714.  added_bytes += sizeof(struct Node);
  1715.     
  1716.  i = strchr(newstring, (char) returnchar);
  1717.  if (i != NULL) diff = i-newstring;  /* number of chars into the string where newline is! */
  1718.  
  1719.  if (!( newname = AllocMem(diff+1,MEMF_CLEAR) ))
  1720.     {
  1721.     MakeReq("AddFile: Couldn't allocate memory for Node String!",NULL,"D-oh!");
  1722.     return(0);
  1723.     }
  1724.   added_bytes += diff+1;
  1725.     
  1726. strncpy(newname,newstring,diff);   /* copy over the bytes */
  1727.  
  1728. newnode->ln_Pri = diff - 126;        /* store string length in unused field */
  1729.                             /* really bad style, isn't it? */
  1730.  
  1731. newnode->ln_Name=newname;          /* and set ze pointer! */
  1732.  
  1733. AddTail(mylist, newnode);
  1734. return(1);
  1735. }
  1736.  
  1737.  
  1738.  
  1739. /* Prints out a file.  Makes sure there is a \r\n after the end of every line */
  1740. int PrintFile(char *szFileName, int PrintReturnFirst)
  1741. {
  1742.     FILE *input_file = fopen(szFileName,"r");
  1743.     char inputline[MAXFILELINELENGTH], *a, *b;
  1744.     int nLen;
  1745.  
  1746.      if (input_file == NULL) 
  1747.      {
  1748.         return(0);
  1749.      }
  1750.  
  1751.      if (PrintReturnFirst == 1)
  1752.      {
  1753.          fprintf(fpOut,"\r\n");
  1754.          
  1755.      }
  1756.          
  1757.     /* Read until we get a line-end */
  1758.     while(!feof(input_file))
  1759.     {
  1760.         memset(inputline,NUL,MAXFILELINELENGTH);
  1761.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  1762.         
  1763.         nLen = strlen(inputline);
  1764.         
  1765.         if (nLen >= 2)
  1766.         {
  1767.             /* make sure that it ends in a \r\n */
  1768.             a = &inputline[strlen(inputline)-2];
  1769.             b = &inputline[strlen(inputline)-1];
  1770.             
  1771.             if ((*a == '\r')&&(*b == '\n')) /* the easy case */
  1772.             {
  1773.                 fprintf(fpOut,"%s",inputline);
  1774.             }
  1775.             else
  1776.             {
  1777.                 if ((*a != '\r')&&(*b == '\n'))  /* the normal case, for Amigas */
  1778.                 {
  1779.                 /* make the newline a return, and then append a newline */
  1780.                     *b = '\r';
  1781.                     fprintf(fpOut,"%s\n",inputline);
  1782.                 }
  1783.                 else
  1784.                 {
  1785.                 if ((*a == '\r')&&(*b != '\n'))    /* the abnormal case */
  1786.                     {
  1787.                         *b = '\n';
  1788.                         fprintf(fpOut,"%s",inputline);
  1789.                     }
  1790.                     else
  1791.                     {
  1792.                         /* *a != \r, *b != \n */
  1793.                         fprintf(fpOut,"%s\r\n",inputline);
  1794.                     }
  1795.                 }
  1796.             }
  1797.         }
  1798.         else
  1799.         if (nLen == 1) fprintf(fpOut,"\r\n");
  1800.     }    
  1801.     fclose(input_file);
  1802.     return(1);
  1803. }
  1804.  
  1805.  
  1806.  
  1807. /* returns the number of lines successfully parsed and added to the list */
  1808. int ReadmyFile(void)
  1809. {
  1810. FILE *input_file = NULL;
  1811. char inputline[MAXFILELINELENGTH];
  1812. char *firstnull;
  1813. int nullpos = 0, okline = 0, nUpdate = 50;
  1814. int filelength = 0, failed_lines = 0;
  1815. int minlinelength = 1;
  1816.  
  1817. if (keepblanklines == 1) minlinelength = 0;
  1818.  
  1819. SetPointer(mgetWnd, waitPointer, 16, 16, -6, 0);
  1820.  
  1821.  while (input_file == NULL) 
  1822.     {
  1823.     input_file = fopen(inputfile,"r");
  1824.     if ((input_file == NULL)&&(RequestAFile(inputfile) == 0)) 
  1825.         {
  1826.         ClearPointer(mgetWnd);
  1827.         return(0);
  1828.         }
  1829.     }
  1830.     
  1831.  SetReqDefaults(inputfile);
  1832.  
  1833.  while (!feof(input_file))
  1834.     {
  1835.     filelength++;        
  1836.     okline=0;  
  1837.     /* Read until we get a line-end */
  1838.     while((okline==0)&&(!feof(input_file)))
  1839.         {
  1840.         memset(inputline,NUL,MAXFILELINELENGTH);
  1841.         fgets(inputline,MAXFILELINELENGTH,input_file);  /* Read up to MAXFILELINELENGTH chars from inputfile */
  1842.         firstnull = strchr(inputline,(char) 10); /* Find address of carriage return */
  1843.         nullpos = firstnull - inputline;           /* Subtract to get return pos */
  1844.         if ((nullpos >= minlinelength)&&(nullpos < MAXFILELINELENGTH)) okline=1;
  1845.         }
  1846.     
  1847.     if ((nullpos < MAXFILELINELENGTH)||(noparse))
  1848.           {
  1849.               if (AddFile(filelist, inputline) == 1)
  1850.               {
  1851.                   filelist_length++;
  1852.  
  1853.                     if (nUpdate == 0)
  1854.                     {
  1855.                         sprintf(windowtitle,"Loading: %i",filelist_length);   
  1856.                         SetWindowTitles(mgetWnd, windowtitle , (char *) ~0);                   
  1857.                         nUpdate = 50;
  1858.                     }
  1859.                     else
  1860.                     {
  1861.                         nUpdate--;
  1862.                     }
  1863.                  }
  1864.               else
  1865.               {
  1866.                   failed_lines++;
  1867.               }
  1868.           }
  1869.           else
  1870.           {
  1871.               failed_lines++;
  1872.           }
  1873.               
  1874.     }
  1875.  
  1876. fclose(input_file);
  1877. ClearPointer(mgetWnd);    
  1878. return(filelist_length);
  1879. }
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892. VOID FreeFileNodes(struct List *mylist)
  1893. {
  1894. struct Node *nextnode,*worknode = mylist->lh_Head;  
  1895. int nodesize = sizeof(struct Node);
  1896.  
  1897.  while (nextnode = (worknode->ln_Succ))
  1898.     {
  1899.     if (worknode->ln_Name != NULL)
  1900.         {
  1901.         FreeMem(worknode->ln_Name,worknode->ln_Pri+127);
  1902.         added_bytes -= worknode->ln_Pri+127;
  1903.         }        
  1904.     FreeMem(worknode,nodesize);
  1905.     worknode = nextnode;
  1906.     added_bytes -= nodesize;
  1907.     }
  1908. }
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920. void ChangeWindowTitle(void)
  1921. {
  1922. char *fstring = inputfile, *f2;
  1923. char sSubString[60];
  1924. int charlength = (windowwidth-81)/8 - 40;
  1925.  
  1926. if (charlength <= 0) 
  1927.     {
  1928.     fstring = sSubString;
  1929.     fstring[0] = NUL;
  1930.     }
  1931.     else
  1932.     if (strlen(fstring) > charlength)
  1933.         {
  1934.         f2 = inputfile + strlen(inputfile) - charlength - 1;    
  1935.         if (f2 > inputfile)
  1936.             {
  1937.             fstring = sSubString;
  1938.             strcpy(fstring,f2);
  1939.             }
  1940.         }    
  1941. sprintf(windowtitle,"(%s) %i files, %u kilobytes selected.",fstring, files_selected, kbytes_selected);   
  1942. SetWindowTitles(mgetWnd, windowtitle , (char *) ~0); 
  1943. return();
  1944. }
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956. VOID UpdateByteCount(char *mystring, int addorsub)
  1957. {
  1958. kbytes_selected = kbytes_selected + (AminetFileSize(mystring) * addorsub);
  1959. return();
  1960. }
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972. VOID Cleanup(void)
  1973. {
  1974.  
  1975. if ((fpOut != stdout)&&(fpOut != NULL)) fclose(fpOut);
  1976.  
  1977. if (listfontdata)  CloseFont(listfontdata);
  1978. if (windowisopen)  ClosemgetWindow();
  1979. if (screenisopen)  CloseDownScreen();
  1980. if (filelist)        
  1981.                 {
  1982.                 FreeFileNodes(filelist); 
  1983.                 FreeMem(filelist,sizeof(struct List));
  1984.                 added_bytes -= sizeof(struct List);
  1985.                }
  1986. if (getlist) 
  1987.               {
  1988.                 FreeFileNodes(getlist);
  1989.                 FreeMem(getlist,sizeof(struct List));
  1990.                 added_bytes -= sizeof(struct List);
  1991.                }
  1992. if (WorkbenchBase) CloseLibrary((struct Library *)WorkbenchBase);
  1993. if (IconBase)         CloseLibrary((struct Library *)IconBase);
  1994. if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  1995. if (AslBase)        CloseLibrary((struct Library *)AslBase);
  1996. if (UtilityBase)   CloseLibrary((struct Library *)UtilityBase);
  1997. if (GraphicsBase)  CloseLibrary((struct GraphicsLib *)GraphicsBase);
  1998. if (GadToolsBase)  CloseLibrary((struct Library *)GadToolsBase);
  1999. return();
  2000. }
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012. int RequestAFile(char *szBuffer)
  2013. {
  2014. int rvalue = 1;
  2015.  
  2016. if (strlen(defDir) == 0) strcpy(defDir,"ram:");
  2017. if (strlen(defFile)== 0) strcpy(defFile,"RECENT");
  2018.  
  2019. struct TagItem frtags[] =
  2020. {
  2021.     ASL_Hail,        (ULONG)"Select a text file to browse.",
  2022.     ASL_Height,    350,
  2023.     ASL_Width,    320,
  2024.     ASL_LeftEdge,    50,
  2025.     ASL_TopEdge,    35,
  2026.     ASL_OKText,    (ULONG)"Okay",
  2027.     ASL_CancelText,(ULONG)"Cancel",
  2028.     ASL_File,        defFile,
  2029.     ASL_Dir,         defDir,
  2030.     ASL_Window,    mgetWnd,
  2031.     TAG_DONE
  2032. };
  2033.  
  2034. struct FileRequester *fr;
  2035.  
  2036. fr = (struct FileRequester *) AllocAslRequest(ASL_FileRequest, frtags);
  2037.  
  2038. if (fr == NULL) 
  2039.     {
  2040.     rvalue = 0 ;
  2041.     }
  2042.  
  2043.  if ((rvalue)&&(AslRequest(fr, NULL)))
  2044.     {
  2045.     strcpy(szBuffer,fr->rf_Dir);
  2046.     strncpy(defDir,fr->rf_Dir,sizeof(defDir));
  2047.     strncpy(defFile,fr->rf_File,sizeof(defFile));
  2048.     if ((defDir[strlen(defDir)-1] != '/')&&
  2049.         (defDir[strlen(defDir)-1] != ':')) strcat(szBuffer,"/");
  2050.     strcat(szBuffer,fr->rf_File);
  2051.     }
  2052.     else
  2053.     rvalue = 0;
  2054.     
  2055. if (fr != NULL) FreeAslRequest(fr);
  2056.  
  2057. return(rvalue);
  2058. }
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068. void TurnOnAllMenuItems(struct Menu *myMenu)
  2069. {
  2070. struct MenuItem *mItem;
  2071.  
  2072.  while (myMenu != NULL)
  2073.     {
  2074.     mItem = myMenu->FirstItem;
  2075.     while (mItem != NULL)
  2076.         {
  2077.         mItem->Flags |= ITEMENABLED;
  2078.         mItem = mItem->NextItem;
  2079.         }
  2080.     myMenu = myMenu->NextMenu;
  2081.     }
  2082. return;
  2083. }
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094. VOID SetReqDefaults(char *szFilePath)
  2095. {
  2096. char *sFileStart;
  2097.  
  2098.  sFileStart = strrchr(szFilePath,'/');
  2099.  if (sFileStart == NULL)
  2100.      {
  2101.      sFileStart = strrchr(szFilePath,':');
  2102.      if (sFileStart == NULL)
  2103.          {
  2104.          sFileStart = szFilePath;
  2105.          }
  2106.      }
  2107.  
  2108.  if (sFileStart != NULL) strncpy(defFile,sFileStart+(sFileStart != szFilePath),sizeof(defFile));
  2109.  if ((sFileStart != NULL)&&(sFileStart != szFilePath)) strncpy(defDir,szFilePath,(sFileStart - szFilePath) + 1);
  2110.  return();
  2111. }
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121.  
  2122.  
  2123. VOID UpperCase(char *sOldString)
  2124. {
  2125. char *i = sOldString;
  2126. int diff = 'a' - 'A';
  2127.  
  2128.  if (sOldString == NULL) return();
  2129.  
  2130.  while (*i != '\0')
  2131.     {
  2132.     if ((*i >= 'a')&&(*i <= 'z')) *i = *i - diff;
  2133.     i++;
  2134.     }
  2135.  
  2136. return();
  2137. }
  2138.  
  2139.  
  2140. VOID LowerCase(char *sOldString)
  2141. {
  2142. char *i = sOldString;
  2143. int diff = 'a' - 'A';
  2144.  
  2145.  if (sOldString == NULL) return();
  2146.  
  2147.  while (*i != '\0')
  2148.     {
  2149.     if ((*i >= 'A')&&(*i <= 'Z')) *i = *i + diff;
  2150.     i++;
  2151.     }
  2152.  
  2153. return();
  2154. }
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161. int mgetoutput(void)
  2162. {
  2163. FILE *fpTemp = NULL;
  2164.  
  2165.         if (files_selected > 0) 
  2166.         {
  2167.             /* If no output name given, do default output... */
  2168.              if (strlen(sOutFileName) == 0)
  2169.              {
  2170.                  /* for Workbench, absolute default is ram:GadMget.output */
  2171.                  if (BStartedFromWB == TRUE)
  2172.                  {
  2173.                      fpTemp = fopen("ram:Gadmget.Output","w");
  2174.                      if (fpTemp == NULL) 
  2175.                      {
  2176.                         MakeReq("Error:  Couldn't open ram:GadMget.output for writing!",NULL,"Ok");
  2177.                         Cleanup();
  2178.                         exit(10);
  2179.                      }
  2180.                  }
  2181.                  else
  2182.                  {    /* for the CLI, default is stdout */
  2183.                      fpTemp = stdout;
  2184.                  }
  2185.              }
  2186.              else
  2187.              {
  2188.                  /* open requested output file for writing */
  2189.                  fpTemp = fopen(sOutFileName,"w");
  2190.                  if (fpTemp == NULL)
  2191.                  {
  2192.                      MakeReq("Error:  Couldn't open output file!",NULL,"Ok");
  2193.                  }
  2194.              }
  2195.              
  2196.              fpOut = fpTemp;
  2197.             PrintFile(szHeaderFile,0);
  2198.             if (noparse) RawOutputList(getlist);
  2199.                        else OutputList(getlist); 
  2200.             PrintFile(szFooterFile,1);
  2201.             if (fpOut != stdout) fclose(fpOut);            
  2202.         }
  2203. return(0);
  2204. }
  2205.  
  2206.  
  2207.  
  2208. VOID ParseCliArgs(int argc, char *argv[])
  2209. {
  2210.  int nextpasslookfor = 0;
  2211.  FILE *fpTemp = NULL;
  2212.  
  2213.  memset(defDir,NUL,sizeof(defDir));
  2214.  memset(defFile,NUL,sizeof(defFile));
  2215.  memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  2216.  memset(szFooterFile,NUL,sizeof(szFooterFile));
  2217.  memset(inputfile,NUL,sizeof(inputfile));
  2218.  
  2219.  if (argc > 1) 
  2220.      {
  2221.      strncpy(inputfile,argv[1],sizeof(inputfile));
  2222.      SetReqDefaults(inputfile);
  2223.      }
  2224.          
  2225.  if (*inputfile == '?')
  2226.     {
  2227.     fprintf(fpOut,"%s",template);
  2228.     Cleanup();
  2229.     exit(0);
  2230.     }
  2231.  
  2232.  
  2233.  for (int i=2; i<=argc; i++)
  2234.     {
  2235.     if (nextpasslookfor == 2)
  2236.         {
  2237.         strncpy(szPubScreenName,argv[i-1],sizeof(szPubScreenName));
  2238.         pubscreenname = szPubScreenName;
  2239.         screentype = USE_PUBSCREEN;
  2240.         continue;            /* skip to next loop */
  2241.         }
  2242.    if (nextpasslookfor == 7)         /* FILE PARAMETER */
  2243.          {
  2244.          strncpy(inputfile,argv[i-1],sizeof(inputfile));
  2245.          SetReqDefaults(inputfile);
  2246.          }
  2247.     if (nextpasslookfor == 9)        /* COMMAND PARAMETER */
  2248.         {
  2249.         strncpy(szCommandString,argv[i-1],sizeof(szCommandString));
  2250.         }
  2251.     
  2252.     UpperCase(argv[i-1]);
  2253.  
  2254.     switch(nextpasslookfor)
  2255.     {    
  2256.     case(1):
  2257.         if (atoi(argv[i-1]) > 0)  maxoutputlinelength = atoi(argv[i-1]);
  2258.         break;
  2259.         
  2260.     /* case 2 is up above, before the Upper() command */
  2261.     
  2262.     case(3):        /* WIDTH PARAMETER */
  2263.         if (atoi(argv[i-1]) > 0)  windowwidth = 155;    /* min level */
  2264.         if (atoi(argv[i-1]) > 155) windowwidth = atoi(argv[i-1]);
  2265.         break;
  2266.     case(4):        /* HEIGHT PARAMETER */
  2267.         if (atoi(argv[i-1]) > 0) windowheight = 167;    /* min level */
  2268.         if (atoi(argv[i-1]) > 167) windowheight = atoi(argv[i-1]);
  2269.         break;
  2270.     case(5):        /* TOP PARAMETER */
  2271.         if (atoi(argv[i-1]) > 0) windowtop = atoi(argv[i-1]);
  2272.         break;
  2273.     case(6):        /* LEFT PARAMETER */
  2274.         if (atoi(argv[i-1]) > 0) windowleft = atoi(argv[i-1]);
  2275.         break;
  2276.         
  2277.     /* Case 7 is up above, before the Upper() command */
  2278.     
  2279.     case(8):        /* OUTPUT PARAMETER */
  2280.         strncpy(sOutFileName,argv[i-1],sizeof(sOutFileName));
  2281.         break;
  2282.     
  2283.     /* Case 9 is up above, before the Upper() command */
  2284.     
  2285.     case(10):        /* HEADER PARAMETER */
  2286.         strncpy(szHeaderFile,argv[i-1],sizeof(szHeaderFile));
  2287.         break;
  2288.         
  2289.     case(11):        /* FOOTER PARAMETER */
  2290.         strncpy(szFooterFile,argv[i-1],sizeof(szFooterFile));
  2291.         break;
  2292.  
  2293.     case(12):        /* FONT PARAMETER */
  2294.         strncpy(sListFontName,argv[i-1],sizeof(sListFontName));
  2295.         LowerCase(sListFontName);
  2296.         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  2297.         break;
  2298.         
  2299.     case(13):        /* FONTSIZE PARAMETER */
  2300.         if (atoi(argv[i-1]) > 0) nListFontSize = atoi(argv[i-1]);
  2301.         break;
  2302.     
  2303.     case(14):        /* FILESORT PARAMETER */
  2304.         LowerCase(argv[i-1]);
  2305.         if (strcmp(argv[i-1],"directory") == 0)   nSortType[0] = SORTBYDIR;
  2306.         if (strcmp(argv[i-1],"filename") == 0)    nSortType[0] = SORTBYNAME;
  2307.         if (strcmp(argv[i-1],"size") == 0)        nSortType[0] = SORTBYSIZE;
  2308.         if (strcmp(argv[i-1],"description") == 0) nSortType[0] = SORTBYDESC;
  2309.         break;
  2310.             
  2311.     case(15):        /* GETSORT PARAMETER */
  2312.         LowerCase(argv[i-1]);
  2313.         if (strcmp(argv[i-1],"directory") == 0)   nSortType[1] = SORTBYDIR;
  2314.         if (strcmp(argv[i-1],"filename") == 0)    nSortType[1] = SORTBYNAME;
  2315.         if (strcmp(argv[i-1],"size") == 0)        nSortType[1] = SORTBYSIZE;
  2316.         if (strcmp(argv[i-1],"description") == 0) nSortType[1] = SORTBYDESC;
  2317.         break;
  2318.     
  2319.     default:
  2320.         /* nothing */
  2321.         break;        
  2322.     }
  2323.     nextpasslookfor = 0;
  2324.     
  2325.     
  2326.     
  2327.     if (strcmp(argv[i-1],"NOAPPWINDOW") == 0) appwindow         = 0;
  2328.     if (strcmp(argv[i-1],"CASESENSITIVE") == 0) casesensitive= 1;    
  2329.     if (strcmp(argv[i-1],"NOPARSE") == 0)         noparse             = 1;
  2330.     if (strcmp(argv[i-1],"NOCOMMAND") == 0)     nocommand        = 1;
  2331.     if (strcmp(argv[i-1],"NOSPLIT") == 0)         nosplit             = 1;
  2332.     if (strcmp(argv[i-1],"GETREADMES") == 0)     getreadmes         = 1;    
  2333.     if (strcmp(argv[i-1],"NOCD") == 0)            nocd                = 1;
  2334.    if (strcmp(argv[i-1],"NOFILES") == 0)     
  2335.                                             {
  2336.                                             filesflag     = 0;
  2337.                                             getreadmes  = 1;
  2338.                                             }
  2339.      if (strcmp(argv[i-1],"LINELENGTH") == 0)           nextpasslookfor= 1;
  2340.      if (strcmp(argv[i-1],"PUBSCREEN") == 0)           nextpasslookfor= 2;
  2341.     if (strcmp(argv[i-1],"DEFPUBSCREEN") == 0)       screentype = USE_PUBSCREEN;     
  2342.     if ((strcmp(argv[i-1],"WBSCREEN") == 0)||
  2343.         (strcmp(argv[i-1],"WORKBENCHSCREEN") == 0)) screentype = USE_WBSCREEN;
  2344.     if (strcmp(argv[i-1],"NOSIMPLEPATHS") == 0)       simplepaths  = 0;    
  2345.     if (strcmp(argv[i-1],"KEEPBLANKLINES") == 0)    keepblanklines = 1;
  2346.     if (strcmp(argv[i-1],"KEEPFILESSORT") == 0)   nKeepSorted[0] = 1;
  2347.     if (strcmp(argv[i-1],"KEEPGETSORT") == 0)     nKeepSorted[1] = 1;
  2348.                                                                                     
  2349.     if (strcmp(argv[i-1],"WIDTH") == 0)            nextpasslookfor = 3;
  2350.     if (strcmp(argv[i-1],"HEIGHT") == 0)        nextpasslookfor = 4;
  2351.     if (strcmp(argv[i-1],"TOP") == 0)            nextpasslookfor = 5;
  2352.     if (strcmp(argv[i-1],"LEFT") == 0)            nextpasslookfor = 6;
  2353.     if (strcmp(argv[i-1],"FILE") == 0)            nextpasslookfor = 7;
  2354.     if (strcmp(argv[i-1],"OUTPUT") == 0)        nextpasslookfor = 8;
  2355.     if (strcmp(argv[i-1],"COMMAND") == 0)        nextpasslookfor = 9;
  2356.     if (strcmp(argv[i-1],"HEADER") == 0)        nextpasslookfor = 10;
  2357.     if (strcmp(argv[i-1],"FOOTER") == 0)        nextpasslookfor = 11;
  2358.     if (strcmp(argv[i-1],"FONT") == 0)        nextpasslookfor = 12;
  2359.     if (strcmp(argv[i-1],"FONTSIZE") == 0)    nextpasslookfor = 13;
  2360.     if (strcmp(argv[i-1],"SIZE") == 0)        nextpasslookfor = 13;
  2361.     if (strcmp(argv[i-1],"FILESORT") == 0)    nextpasslookfor = 14;
  2362.     if (strcmp(argv[i-1],"GETSORT") == 0)     nextpasslookfor = 15;
  2363.     }
  2364.  
  2365.     return();
  2366. }
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377. VOID wbmain(struct WBStartup *argv)
  2378. {
  2379. BStartedFromWB = TRUE;
  2380. IconBase = OpenLibrary("icon.library",33);
  2381. if (IconBase == NULL)
  2382.      {
  2383.      exit(2);
  2384.      }
  2385. ParseWBArgs(argv);
  2386. main(0,argv);
  2387. }
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396. VOID ParseWBArgs(struct WBStartup *argv)
  2397. {
  2398. struct WBArg *wb_arg = argv->sm_ArgList;
  2399. struct DiskObject *dobj;
  2400. char **toolarray, *sTemp;
  2401. FILE *fpTemp = NULL;
  2402.  
  2403.  
  2404. memset(defDir,NUL,sizeof(defDir));
  2405. memset(defFile,NUL,sizeof(defFile));
  2406. memset(szHeaderFile,NUL,sizeof(szHeaderFile));
  2407. memset(szFooterFile,NUL,sizeof(szFooterFile));
  2408.  
  2409.  
  2410. /* Parse the tooltypes from the program file */
  2411. dobj = GetDiskObject(wb_arg->wa_Name);
  2412.  
  2413. if (dobj != NULL)
  2414.  {
  2415.      toolarray = (char **) dobj->do_ToolTypes;
  2416.     if (toolarray != NULL)
  2417.     {
  2418.     
  2419.         if (sTemp = (char *) FindToolType(toolarray,"OUTPUT")) 
  2420.         {
  2421.           strncpy(sOutFileName,sTemp,sizeof(sOutFileName));
  2422.         }
  2423.                                             
  2424.         if (sTemp = (char *) FindToolType(toolarray,"FILE")) 
  2425.                 {
  2426.                 strncpy(inputfile,sTemp,sizeof(inputfile));
  2427.                 SetReqDefaults(inputfile);
  2428.                 }
  2429.         if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))       noparse     = 1;
  2430.         if (sTemp = (char *) FindToolType(toolarray,"NOCOMMAND"))      nocommand   = 1;
  2431.        if (sTemp = (char *) FindToolType(toolarray,"NOSPLIT"))       nosplit     = 1;    
  2432.        if (sTemp = (char *) FindToolType(toolarray,"GETREADMES"))  getreadmes  = 1;
  2433.         if (sTemp = (char *) FindToolType(toolarray,"NOFILES"))
  2434.                                                              {
  2435.                                                             filesflag     = 0;
  2436.                                                             getreadmes  = 1;
  2437.                                                             }
  2438.        if (sTemp = (char *) FindToolType(toolarray,"LINELENGTH"))
  2439.                    {
  2440.                    if (atoi(sTemp) > 0)  maxoutputlinelength = atoi(sTemp); 
  2441.                    }
  2442.                   
  2443.           if (sTemp = (char *) FindToolType(toolarray,"PUBSCREEN"))   
  2444.                       {
  2445.                       strcpy(szPubScreenName,sTemp);
  2446.                       pubscreenname = szPubScreenName;
  2447.                       screentype = USE_PUBSCREEN;
  2448.                       }
  2449.           
  2450.           if (sTemp = (char *) FindToolType(toolarray,"NOSIMPLEPATHS"))     simplepaths = 0;        
  2451.           if (sTemp = (char *) FindToolType(toolarray,"NOPARSE"))   noparse = 1;        
  2452.         if (sTemp = (char *) FindToolType(toolarray,"NOAPPWINDOW")) appwindow = 0;
  2453.         if (sTemp = (char *) FindToolType(toolarray,"WBSCREEN"))           screentype = USE_WBSCREEN;
  2454.         if (sTemp = (char *) FindToolType(toolarray,"WORKBENCHSCREEN")) screentype = USE_WBSCREEN;                                
  2455.         if (sTemp = (char *) FindToolType(toolarray,"NOCD"))                 nocd = 1;
  2456.         if (sTemp = (char *) FindToolType(toolarray,"KEEPBLANKLINES")) keepblanklines = 1;
  2457.         if (sTemp = (char *) FindToolType(toolarray,"KEEPFILESORT")) nKeepSorted[0] = 1;
  2458.         if (sTemp = (char *) FindToolType(toolarray,"KEEPGETSORT")) nKeepSorted[1] = 1;
  2459.         
  2460.         if (sTemp = (char *) FindToolType(toolarray,"WIDTH"))                             
  2461.                         {
  2462.                         if (atoi(sTemp) > 0)  windowwidth = 155;    /* min level */
  2463.                         if (atoi(sTemp) > 155) windowwidth = atoi(sTemp);
  2464.                         }
  2465.         if (sTemp = (char *) FindToolType(toolarray,"HEIGHT"))     
  2466.                         {                        
  2467.                         if (atoi(sTemp) > 0) windowheight = 167;    /* min level */
  2468.                         if (atoi(sTemp) > 167) windowheight = atoi(sTemp);
  2469.                         }
  2470.         if (sTemp = (char *) FindToolType(toolarray,"TOP"))                             
  2471.                         {
  2472.                         if (atoi(sTemp) > 0) windowtop = atoi(sTemp);
  2473.                         }
  2474.         if (sTemp = (char *) FindToolType(toolarray,"LEFT"))                             
  2475.                         {
  2476.                         if (atoi(sTemp) > 0) windowleft = atoi(sTemp);
  2477.                         }                    
  2478.         if (sTemp = (char *) FindToolType(toolarray,"CASESENSITIVE"))                             
  2479.                         {
  2480.                         casesensitive = 1;
  2481.                         }
  2482.         if (sTemp = (char *) FindToolType(toolarray,"COMMAND"))
  2483.                         {
  2484.                         strncpy(szCommandString,sTemp,sizeof(szCommandString));
  2485.                         }
  2486.         if (sTemp = (char *) FindToolType(toolarray,"HEADER"))
  2487.                         {
  2488.                         strncpy(szHeaderFile,sTemp,sizeof(szHeaderFile));
  2489.                         }
  2490.         if (sTemp = (char *) FindToolType(toolarray,"FOOTER"))
  2491.                         {
  2492.                         strncpy(szFooterFile,sTemp,sizeof(szFooterFile));
  2493.                         }
  2494.         if (sTemp = (char *) FindToolType(toolarray,"FONT"))
  2495.                         {
  2496.                         strncpy(sListFontName,sTemp,sizeof(sListFontName));
  2497.                         LowerCase(sListFontName);
  2498.                         if (strstr(sListFontName,".font") == NULL) strncat(sListFontName,".font",sizeof(sListFontName));
  2499.                         }
  2500.         if (sTemp = (char *) FindToolType(toolarray,"FONTSIZE"))
  2501.                         {
  2502.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  2503.                         }
  2504.         if (sTemp = (char *) FindToolType(toolarray,"SIZE"))
  2505.                         {
  2506.                         if (atoi(sTemp) > 0) nListFontSize = atoi(sTemp);
  2507.                         }
  2508.         if (sTemp = (char *) FindToolType(toolarray,"FILESORT"))
  2509.                         {
  2510.                         LowerCase(sTemp);
  2511.                         if (strcmp(sTemp,"directory") == 0)   nSortType[0] = SORTBYDIR;
  2512.                         if (strcmp(sTemp,"filename") == 0)    nSortType[0] = SORTBYNAME;
  2513.                         if (strcmp(sTemp,"size") == 0)        nSortType[0] = SORTBYSIZE;
  2514.                         if (strcmp(sTemp,"description") == 0) nSortType[0] = SORTBYDESC;
  2515.                         }
  2516.         if (sTemp = (char *) FindToolType(toolarray,"GETSORT"))
  2517.                         {
  2518.                         LowerCase(sTemp);
  2519.                         if (strcmp(sTemp,"directory") == 0)   nSortType[1] = SORTBYDIR;
  2520.                         if (strcmp(sTemp,"filename") == 0)    nSortType[1] = SORTBYNAME;
  2521.                         if (strcmp(sTemp,"size") == 0)        nSortType[1] = SORTBYSIZE;
  2522.                         if (strcmp(sTemp,"description") == 0) nSortType[1] = SORTBYDESC;
  2523.                         }    
  2524.     }                     
  2525.  FreeDiskObject(dobj);
  2526.  }
  2527.  
  2528.  /* Get the name of the file extended_clicked, if there is one */
  2529.  if (argv->sm_NumArgs > 1) 
  2530.     {
  2531.     wb_arg++;    /* The first name is the programs name, the 2nd is the proj. icon */
  2532.     if (wb_arg->wa_Name != NULL) 
  2533.         {
  2534.         strncpy(inputfile,wb_arg->wa_Name,sizeof(inputfile));
  2535.         CurrentDir(wb_arg->wa_Lock);
  2536.         }
  2537.     }
  2538.     
  2539. return();
  2540. }
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551. /********/
  2552. /* MAIN */
  2553. /********/
  2554. VOID main(int argc, char *argv[])
  2555. {
  2556. FILE *test = NULL;
  2557. ULONG winsig,signals;
  2558. BPTR olddir;
  2559.  
  2560. GraphicsBase = OpenLibrary("graphics.library",37);
  2561.  if (GraphicsBase==NULL)
  2562.     {
  2563.     fprintf(fpOut,"couldn't open Graphics.library v37!");
  2564.     Cleanup();
  2565.     return;
  2566.     }
  2567. UtilityBase = OpenLibrary("utility.library",37);
  2568.  if (UtilityBase==NULL)
  2569.     {
  2570.     fprintf(fpOut,"couldn't open utility.library v37!");
  2571.     Cleanup();
  2572.     return;
  2573.     }
  2574. GadToolsBase = OpenLibrary("gadtools.library",37);
  2575.  if (GadToolsBase==NULL)
  2576.     {
  2577.     fprintf(fpOut,"couldn't open gadtools.library v37!\n");
  2578.     Cleanup();
  2579.     return;
  2580.     }
  2581. AslBase = OpenLibrary("asl.library", 37L);
  2582.  if (AslBase == NULL)
  2583.     {
  2584.     fprintf(fpOut,"couldn't open asl.library v37!\n");
  2585.     Cleanup();
  2586.     return;
  2587.     }
  2588. IntuitionBase = OpenLibrary("intuition.library",37);
  2589.  if (IntuitionBase == NULL)
  2590.      {
  2591.      fprintf(fpOut,"Couldn't open intuition.library!\n");
  2592.      Cleanup();
  2593.      return;
  2594.      }
  2595. WorkbenchBase = OpenLibrary("workbench.library",37);
  2596.  if (WorkbenchBase == NULL)
  2597.      {
  2598.      fprintf(fpOut,"Couldn't open workbench.library!\n");
  2599.      Cleanup();
  2600.      return;
  2601.      }
  2602.  
  2603. /* construct program name from version string */
  2604. memset(pnamestring,NUL,20);
  2605. strcpy(pnamestring,version+6);
  2606.  
  2607. memset(searchstring,NUL,sizeof(searchstring));
  2608.  
  2609. if (argc>1) ParseCliArgs(argc,argv);
  2610.      
  2611. /* Now add data to listView */
  2612. /* First, initialize List filelist */
  2613.     
  2614.  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2615.     {
  2616.     MakeReq("Couldn't create filelist!  Out of memory?",NULL,"Oh, Dear");
  2617.     Cleanup();
  2618.     return();
  2619.     }
  2620.  added_bytes += sizeof(struct List);
  2621.     
  2622.  if (!(getlist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2623.     {
  2624.     MakeReq("Couldn't create getlist!  Out of memory?",NULL,"Oh, Dear");
  2625.     Cleanup();
  2626.     return();
  2627.     }
  2628.  added_bytes += sizeof(struct List);
  2629.     
  2630.  NewList(filelist);
  2631.  NewList(getlist);
  2632.  
  2633.  
  2634.  lockscrnerror = SetupScreen();
  2635.  if (lockscrnerror)
  2636.     {
  2637.     MakeReq("Couldn't open screen!",NULL,"Sigh");
  2638.     Cleanup();
  2639.     return();
  2640.     }
  2641.  
  2642.  screenisopen = 1;
  2643.     
  2644.  winopenerror = OpenmgetWindow();
  2645.  if (winopenerror)
  2646.     {
  2647.     MakeReq("Couldn't open window!",NULL,"Sigh");
  2648.     Cleanup();
  2649.     return();
  2650.     }
  2651.  windowisopen = 1;
  2652.  
  2653.  if (ReadmyFile() > 0)
  2654.     {
  2655.         /* Sort if need be */
  2656.         if ((nKeepSorted[0] == 1)&&(!noparse)) SortList(filelist,nSortType[0]);
  2657.         
  2658.         /* First, make sure all the menus are enabled. */
  2659.         TurnOnAllMenuItems(mgetMenus);
  2660.         
  2661.         SetMenuValues();
  2662.     
  2663.         GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END); 
  2664.         files_selected = 0;
  2665.     
  2666.         if (noparse) SetWindowTitles(mgetWnd, "Please select desired lines now." , (char *) ~0); 
  2667.                    else ChangeWindowTitle();
  2668.         
  2669.         winsig = 1L << mgetWnd->UserPort->mp_SigBit;
  2670.         while (done==FALSE)
  2671.             {
  2672.             signals = Wait(winsig|appwinsig);
  2673.             if (signals&winsig) handlereturn = HandlemgetIDCMP();
  2674.             if (signals&appwinsig) 
  2675.                 {
  2676.                 while (amsg = (struct AppMessage *) GetMsg(awport))
  2677.                     {
  2678.                     argptr = amsg->am_ArgList;
  2679.                     if (argptr->wa_Name != NULL)
  2680.                         {
  2681.                         strcpy(inputfile,argptr->wa_Name);
  2682.                         if (argptr->wa_Lock != NULL) 
  2683.                             {
  2684.                             olddir = CurrentDir(argptr->wa_Lock);
  2685.                             SetReqDefaults(inputfile);
  2686.                              test = fopen(inputfile,"r");
  2687.                              if (test != NULL)
  2688.                                  {
  2689.                                  fclose(test);
  2690.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, ~0, TAG_END);
  2691.                                 FreeFileNodes(filelist); 
  2692.                                  FreeMem(filelist,sizeof(struct List));
  2693.                                  added_bytes -= sizeof(struct List);
  2694.                                  ClearPointer(mgetWnd);
  2695.          
  2696.                                  if (!(filelist = AllocMem(sizeof(struct List),MEMF_CLEAR)) )
  2697.                                     {
  2698.                                     MakeReq("AppOpen : Couldn't create filelist!  Out of memory?",NULL,"Ok");
  2699.                                     return;
  2700.                                     }
  2701.                                  added_bytes += sizeof(struct List);
  2702.                     
  2703.                                  filelist_length = 0;
  2704.                                  search_current = NULL;
  2705.                                  index = 0;
  2706.                                  
  2707.                                 NewList(filelist);
  2708.                                  ReadmyFile();
  2709.                                  GT_SetGadgetAttrs(mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
  2710.                                 CurrentDir(olddir);
  2711.                                 }
  2712.                                 else
  2713.                                 DisplayBeep(Scr);
  2714.                             }
  2715.                         }
  2716.                     ReplyMsg((struct Message *) amsg);
  2717.                     }
  2718.                 }
  2719.             }
  2720.         if (windowisopen)  ClosemgetWindow();
  2721.         if (screenisopen)  CloseDownScreen();
  2722.     
  2723.         mgetoutput();
  2724.     }
  2725. Cleanup();
  2726.         
  2727. exit(0);    
  2728. }
  2729.  
  2730. #endif
  2731.  
  2732.  
  2733.     
  2734.