home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFILEMAN / XFILEMAN.TAR / xfilemanager / merge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  10.0 KB  |  385 lines

  1. /*
  2.  * Copyright 1993 by Ove Kalkan, Cremlingen, Germany
  3.  *
  4.  * Permission to use, copy, modify, distribute and sell this software and it's
  5.  * documentation for any purpose is hereby granted without fee, rpovided that
  6.  * the above copyright notice and this permission appear in supporting
  7.  * documentation, and that the name of Ove Kalkan not to be used in
  8.  * advertising or publicity pertaining to distributiopn of the software without
  9.  * specific, written prior permission. Ove Kalkan makes no representations
  10.  * about the suitability of this software for any purpose. It is provided
  11.  * as is without express or implied warranty.
  12.  *
  13.  * OVE KALKAN DISPLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  14.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS, IN NO
  15.  * EVENT SHALL OVE KALKAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  16.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  17.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19.  * PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * $Header: filename,v 1.0 yyyy/mm/dd hh:mm:ss loginname Exp $
  22.  */
  23.  
  24. #include "global.h"
  25.  
  26. /*
  27.  * Globals
  28.  */
  29.  
  30.  
  31. static    Widget    merge_shell = NULL;
  32. static    Widget    t_1;
  33. static    Widget    but_a, but_d;
  34. static    Widget    tog_1, tog_2;
  35. static    XawTextSelectType    select_types[] = {XawselectLine, XawselectParagraph,
  36.                           XawselectAll, XawselectNull};
  37.  
  38. static    void    hide_merger (void);
  39. static    void    clear_merger (void);
  40. static    void    remove_merger (void);
  41. static    void    apply_merger (void);
  42.  
  43.  
  44. /*********************************************************
  45.  * name:    start_merger
  46.  * description:    Aufrufen des Merge-Feldes
  47.  * input:    none
  48.  * output:    none
  49.  * author:    Ove Kalkan
  50.  * date:    27.Aug.1993
  51.  *********************************************************/
  52. void    start_merger (void)
  53. {
  54.     Widget    icon, label;
  55.     Widget    form, f;
  56.     char    *file;
  57.     Boolean    b;
  58.  
  59.     /*
  60.      * Alte Shell zerstoeren
  61.      */
  62.     if (merge_shell)
  63.         XtDestroyWidget(merge_shell);
  64.  
  65.     /*
  66.      * Neu Shell erzeugen
  67.      */
  68.     merge_shell = XtVaCreatePopupShell ("package_builder",topLevelShellWidgetClass,
  69.                         toplevel,
  70.                         XtNallowShellResize, TRUE,
  71.                         NULL);
  72.  
  73.     /*
  74.      * Form darauf erzeugen
  75.      */
  76.     form = XtVaCreateManagedWidget ("package_form",formWidgetClass,
  77.                         merge_shell,
  78.                         NULL);
  79.  
  80.     /*
  81.      * Das Icon und den Label darauf erzeugen
  82.      */
  83.     icon = XtVaCreateManagedWidget ("package_icon", iconWidgetClass, form,
  84.                         XtNleft, XtChainLeft,
  85.                         XtNright, XtChainLeft,
  86.                         XtNtop, XtChainTop,
  87.                         XtNbottom, XtChainTop,
  88.                         XtNborderWidth, 0,
  89.                         XtNimageWidth, 32,
  90.                         XtNimageHeight, 32,
  91.                         XtNimage, Icon_Pack_PM,
  92.                         NULL);
  93.     label = XtVaCreateManagedWidget ("package_label", labelWidgetClass, form,
  94.                         XtNleft, XtChainLeft,
  95.                         XtNright, XtChainLeft,
  96.                         XtNtop, XtChainTop,
  97.                         XtNbottom, XtChainTop,
  98.                         XtNborderWidth, 0,
  99.                         XtNfromHoriz, icon,
  100.                         XtNlabel, "Package Builder",
  101.                         NULL);
  102.  
  103.     /*
  104.      * Das Textfeld und den Label fuer den Archive-Namen.
  105.      */
  106.     label = XtVaCreateManagedWidget ("package_label", labelWidgetClass, form,
  107.                         XtNleft, XtChainLeft,
  108.                         XtNright, XtChainLeft,
  109.                         XtNtop, XtChainTop,
  110.                         XtNbottom, XtChainTop,
  111.                         XtNborderWidth, 0,
  112.                         XtNfromVert, icon,
  113.                         XtNlabel, "Package Name (without .tar, etc) :",
  114.                         NULL);
  115.  
  116.     file = getString();
  117.     if (!file)
  118.         file = getenv("HOME");
  119.  
  120.     t_1 = XtVaCreateManagedWidget ("package_text", asciiTextWidgetClass, form,
  121.                         XtNleft, XtChainLeft,
  122.                         XtNright, XtChainRight,
  123.                         XtNtop, XtChainTop,
  124.                         XtNbottom, XtChainTop,
  125.                         XtNeditType, XawtextEdit,
  126.                         XtNstring, file,
  127.                         XtNfromVert, icon,
  128.                         XtNfromHoriz, label,
  129.                         XtNresizable, TRUE,
  130.                         XtNresize, XawtextResizeWidth,
  131.                         NULL);
  132.     XtOverrideTranslations(t_1, XtParseTranslationTable(
  133.                     "<Key>Return: no-op()"));
  134.  
  135.     /*
  136.      * Darunter jetzt eine Box mit den moeglichen Compressionsmethoden
  137.      */
  138.     label = XtVaCreateManagedWidget ("package_label", labelWidgetClass, form,
  139.                         XtNleft, XtChainLeft,
  140.                         XtNright, XtChainLeft,
  141.                         XtNtop, XtChainTop,
  142.                         XtNbottom, XtChainTop,
  143.                         XtNborderWidth, 0,
  144.                         XtNfromVert, t_1,
  145.                         XtNlabel, "Compression :",
  146.                         XtNvertDistance,10,
  147.                         NULL);
  148.  
  149.     b = FALSE;
  150.     if (strstr(file,".tar.Z"))
  151.         b = TRUE;
  152.  
  153.     tog_1 = XtVaCreateManagedWidget ("package_label", toggleWidgetClass, form,
  154.                         XtNleft, XtChainLeft,
  155.                         XtNright, XtChainLeft,
  156.                         XtNtop, XtChainTop,
  157.                         XtNbottom, XtChainTop,
  158.                         XtNfromHoriz, label,
  159.                         XtNfromVert, t_1,
  160.                         XtNlabel, " Compress ",
  161.                         XtNvertDistance,10,
  162.                         XtNstate, b,
  163.                         NULL);
  164.  
  165.     if (strstr(file,".tar.gz") || strstr(file,"tar.z"))
  166.         b = TRUE;
  167.     tog_2 = XtVaCreateManagedWidget ("package_label", toggleWidgetClass, form,
  168.                         XtNleft, XtChainLeft,
  169.                         XtNright, XtChainLeft,
  170.                         XtNtop, XtChainTop,
  171.                         XtNbottom, XtChainTop,
  172.                         XtNfromHoriz, tog_1,
  173.                         XtNfromVert, t_1,
  174.                         XtNradioGroup, tog_1,
  175.                         XtNlabel, " GNU-Zip ",
  176.                         XtNstate, b,
  177.                         XtNvertDistance,10,
  178.                         NULL);
  179.  
  180.     /*
  181.      * Das Text-Widget fuer die zu verpackenden Files
  182.      */
  183.     merge_window = XtVaCreateManagedWidget ("package_field", asciiTextWidgetClass, form,
  184.                         XtNleft, XtChainLeft,
  185.                         XtNright, XtChainRight,
  186.                         XtNtop, XtChainTop,
  187.                         XtNbottom, XtChainBottom,
  188.                         XtNfromVert, label,
  189.                         XtNvertDistance, 10,
  190.                         XtNscrollVertical, XawtextScrollWhenNeeded,
  191.                         XtNscrollHorizontal, XawtextScrollWhenNeeded,
  192.                         XtNheight,100,
  193.                         XtNwidth, 400,
  194.                         XtNselectTypes, select_types,
  195.                         XtNdisplayCaret, FALSE,
  196.                         NULL);
  197.     XtOverrideTranslations (merge_window, XtParseTranslationTable(
  198.                         "<Btn1Up>: end-single()"));
  199.  
  200.     /*
  201.      * Die Form fuer die Buttons
  202.      */
  203.     f = XtVaCreateManagedWidget ("package_bform", formWidgetClass, form,
  204.                         XtNleft, XtChainLeft,
  205.                         XtNright, XtChainRight,
  206.                         XtNtop, XtChainBottom,
  207.                         XtNbottom, XtChainBottom,
  208.                         XtNfromVert, merge_window,
  209.                         XtNborderWidth, 0,
  210.                         XtNvertDistance, 20,
  211.                         NULL);
  212.  
  213.     icon = XtVaCreateManagedWidget ("hide_info", commandWidgetClass, f,
  214.                         XtNleft, XtChainLeft,
  215.                         XtNright, XtChainLeft,
  216.                         XtNlabel,"  Hide  ",
  217.                         NULL);
  218.     XtAddCallback (icon, XtNcallback, (XtCallbackProc) hide_merger, NULL);
  219.  
  220.     icon = XtVaCreateManagedWidget ("hide_info", commandWidgetClass, f,
  221.                         XtNhorizDistance,145,
  222.                         XtNleft, XtChainLeft,
  223.                         XtNright, XtChainLeft,
  224.                         XtNlabel," Clear ",
  225.                         XtNfromHoriz, icon,
  226.                         NULL);
  227.     XtAddCallback (icon, XtNcallback, (XtCallbackProc) clear_merger, NULL);
  228.  
  229.     icon = XtVaCreateManagedWidget ("hide_info", commandWidgetClass, f,
  230.                         XtNleft, XtChainLeft,
  231.                         XtNright, XtChainLeft,
  232.                         XtNlabel," Remove ",
  233.                         XtNfromHoriz, icon,
  234.                         NULL);
  235.     XtAddCallback (icon, XtNcallback, (XtCallbackProc) remove_merger, NULL);
  236.  
  237.     icon = XtVaCreateManagedWidget ("apply_info", commandWidgetClass, f,
  238.                         XtNleft, XtChainLeft,
  239.                         XtNright, XtChainLeft,
  240.                         XtNlabel," Create ",
  241.                         XtNfromHoriz, icon,
  242.                         NULL);
  243.     XtAddCallback (icon, XtNcallback, (XtCallbackProc) apply_merger, NULL);
  244.  
  245.     /*
  246.      * Shell managen
  247.      */
  248.     XtManageChild(merge_shell);
  249. }
  250.  
  251.  
  252.  
  253.  
  254. /*********************************************************
  255.  * name:    hide_merger
  256.  * description:    verstecken des Mergerwindows.
  257.  * input:    none
  258.  * output:    none
  259.  * author:    Ove Kalkan
  260.  * date:    7.Sep.1993
  261.  *********************************************************/
  262. static void    hide_merger (void)
  263. {
  264.     XtDestroyWidget(merge_shell);
  265.     merge_shell = NULL;
  266.     merge_window = NULL;
  267. }
  268.  
  269.  
  270. /*********************************************************
  271.  * name:    clear_merger
  272.  * description:    loeschen und ruecksetzen der felder im Merger
  273.  * input:    none
  274.  * output:    none
  275.  * author:    Ove Kalkan
  276.  * date:    7.Sep.1993
  277.  *********************************************************/
  278. static    void    clear_merger (void)
  279. {
  280.     char    *got = getPath(&root);
  281.  
  282.     XtVaSetValues(merge_window,XtNstring,NULL,NULL);
  283.     XtVaSetValues(t_1,XtNstring,got,NULL);
  284.     XtVaSetValues(tog_1,XtNstate,FALSE);
  285.     XtVaSetValues(tog_2,XtNstate,FALSE);
  286.     free(got);
  287. }
  288.  
  289.  
  290.  
  291. /*********************************************************
  292.  * name:    remove_merger
  293.  * description:    loeschen eines Eintrags aus der Merger-Liste.
  294.  * input:    none
  295.  * output:    none
  296.  * author:    Ove Kalkan
  297.  * date:    8.Sep.1993
  298.  *********************************************************/
  299. static    void    remove_merger (void)
  300. {
  301.     XawTextPosition    begin,end;
  302.  
  303.     XawTextGetSelectionPos (merge_window, &begin, &end);
  304.     if (end > begin) {
  305.         XawTextBlock    text;
  306.  
  307.         text.ptr = NULL;
  308.         text.length = 0;
  309.         text.firstPos = 0;
  310.         text.format = FMT8BIT;
  311.  
  312.         XawTextUnsetSelection(merge_window);
  313.         XtVaSetValues(merge_window,XtNeditType,XawtextAppend,NULL);
  314.         XawTextReplace(merge_window,begin,end,&text);
  315.         XtVaSetValues(merge_window,XtNeditType,XawtextRead,NULL);
  316.     }
  317.     else
  318.         WARNING ("You have to select some items before trying\nto remove them from the list.");
  319. }
  320.  
  321.  
  322. /*********************************************************
  323.  * name:    apply_merger
  324.  * description:    Ein Tar-Archive erstellen, sofern es moeglich ist.
  325.  * input:    none
  326.  * output:    none
  327.  * author:    Ove Kalkan
  328.  * date:    8.Sep.1993
  329.  *********************************************************/
  330. static    void    apply_merger (void)
  331. {
  332.     char    *s;
  333.     char    *a;
  334.     Boolean    gzip;
  335.     Boolean    compress;
  336.     char    *filename;
  337.     FILE    *fp;
  338.     char    dummy[255];
  339.  
  340.     XtVaGetValues(merge_window,XtNstring,&s,NULL);
  341.     if (!strlen(s)) {
  342.         WARNING("There are no items in this package.\nPut some in before pressing this\nbutton!");
  343.         return;
  344.     }
  345.  
  346.     a = s;
  347.     while ((a = strchr(a,'\n')))
  348.         *a = ' ';
  349.  
  350.     XtVaGetValues(tog_1,XtNstate,&compress,NULL);
  351.     XtVaGetValues(tog_2,XtNstate,&gzip,NULL);
  352.  
  353.     XtVaGetValues(t_1,XtNstring, &filename,NULL);
  354.  
  355.     if ((a = strrstr(filename,".tar.gz")) ||
  356.         (a = strrstr(filename,".tar.z")) ||
  357.         (a = strrstr(filename,".tar.Z")))
  358.         *a = '\0';
  359.  
  360.     if (compress)
  361.         sprintf(dummy,"%s.tar.Z",filename);
  362.     else if (gzip)
  363.         sprintf(dummy,"%s.tar.gz",filename);
  364.     else
  365.         sprintf(dummy,"%s.tar",filename);
  366.  
  367.     if ((fp = fopen(dummy,"w"))) {
  368.         char    buf[1024];
  369.  
  370.         fclose(fp);
  371.         if (compress) {
  372.             sprintf(buf,"tar -cf - %s | compress > %s",s,dummy);
  373.         }
  374.         else if (gzip) {
  375.             sprintf(buf,"tar -cf - %s | gzip > %s",s,dummy);
  376.         }
  377.         else
  378.             sprintf(buf,"tar -cf %s %s",dummy,s);
  379.         system(buf);
  380.         refreshFolderByPathname(filename);
  381.     }
  382.     else
  383.         WARNING("Error: Cannot create package!");
  384. }
  385.