home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 376.lha / Softfont_v4-4-90 / requester.c < prev   
C/C++ Source or Header  |  1990-05-05  |  9KB  |  330 lines

  1. /*****
  2.     getfile(Window,Hailing_string,file_name,directory_name);
  3.  
  4. Where:
  5.     Window is a pointer to your window
  6.     Hailing_string is a prompt displayed in the requester
  7.     file_name is a text array which will be altered by getfile,
  8.         it returns the file name.
  9.     directory_name is a text array altered by getfile, it
  10.         is the directory.
  11.  
  12.     The return value is either a pointer to your buffer, file_name,
  13.     or NULL if the user selected CANCEL.
  14.  
  15. *****/
  16.  
  17. #include <exec/types.h>
  18. #include <exec/devices.h>
  19. #include <intuition/intuition.h>
  20. #include <string.h>
  21.  
  22. extern convert();
  23. struct IntuitionBase *IntuitionBase;    /* Handles for inutition and    */
  24. struct GfxBase    *GfxBase;        /* graphics libraries        */
  25.  
  26. #define ONE 1
  27.  
  28. TEXT file_name[34];
  29. TEXT dir_name[67];
  30. TEXT portrait[67];
  31. TEXT landscape[67];
  32. TEXT slash[10] = "/";
  33. int  SLASH = '\057'; /* decimal 42, forward slash (UNIX, AMIGA) */
  34.  
  35. char *LAND  = ".land";
  36. char *temp;
  37.  
  38. struct Window    *p_Window;        /* Handle for window we open  */
  39.  
  40. /* Struct to open Window   */
  41. struct NewWindow NewWindow = {
  42.    10,10,400,150, 2,1,        /* Left,Top, Width,Height, Pens  */
  43.    MOUSEBUTTONS | MOUSEMOVE | MENUPICK | CLOSEWINDOW, /* IDCMP flags */
  44.    SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWCLOSE |
  45.    WINDOWDRAG | WINDOWDEPTH | REPORTMOUSE,    /* Window flags    */
  46.    NULL, NULL,            /* First Gadget, Checkmark image */
  47.    (UBYTE *)"Portrait-to-Landscape", /* Window Title    */
  48.    NULL, NULL,            /* Screen and BitMap        */
  49.    100,60, 32767,32767,        /* Window Sizing limits        */
  50.    WBENCHSCREEN};        /* WBENCH or CUSTOMSCREEN    */
  51.  
  52. /* Menu description  */
  53. struct IntuiText menu_text = { 2,1,JAM2, 20,1, NULL, (UBYTE *)"Start",NULL };
  54.  
  55. struct MenuItem menu_item = {
  56.    NULL, 0,10,100,10,        /* Next item, Left, Top, Width, Height */
  57.    HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
  58.    NULL,(APTR)&menu_text,    /* MutualExclude, ItemFill        */
  59.    NULL, 'S', NULL };        /* SelectFill, Command , SubItem    */
  60.  
  61. struct Menu simple_menu = {
  62.    NULL, 0,0,60,10, MENUENABLED, "Menu", &menu_item };
  63.  
  64. struct IntuiText SeventhText =
  65.     {
  66.     1,0,                /* FrontPen, BackPen */
  67.     JAM2,                /* DrawMode         */
  68.     15,90,                /* LeftEdge, TopEdge */
  69.     NULL,                /* Font (std ROM font) */
  70.     (UBYTE *)"Tom Lynch (818)709-2988",
  71.     NULL                /* NextText         */
  72. };
  73.  
  74. struct IntuiText SixthText =
  75.     {
  76.     1,0,                /* FrontPen, BackPen */
  77.     JAM2,                /* DrawMode         */
  78.     15,75,                /* LeftEdge, TopEdge */
  79.     NULL,                /* Font (std ROM font) */
  80.     (UBYTE *)"         100 filenames or system will crash.",
  81.     &SeventhText                /* NextText         */
  82. };
  83.  
  84. struct IntuiText FifthText =
  85.     {
  86.     1,0,                /* FrontPen, BackPen */
  87.     JAM2,                /* DrawMode         */
  88.     15,65,                /* LeftEdge, TopEdge */
  89.     NULL,                /* Font (std ROM font) */
  90.     (UBYTE *)"WARNING: Font directory should have less than",
  91.     &SixthText                /* NextText         */
  92. };
  93.  
  94. struct IntuiText FourthText =
  95.     {
  96.     1,0,                /* FrontPen, BackPen */
  97.     JAM2,                /* DrawMode         */
  98.     15,20,                /* LeftEdge, TopEdge */
  99.     NULL,                /* Font (std ROM font) */
  100.     (UBYTE *)"    This program will convert soft fonts",
  101.     &FifthText                /* NextText         */
  102. };
  103.  
  104. struct IntuiText ThirdText =
  105.     {
  106.     1,0,                /* FrontPen, BackPen */
  107.     JAM2,                /* DrawMode         */
  108.     15,30,                /* LeftEdge, TopEdge */
  109.     NULL,                /* Font (std ROM font) */
  110.     (UBYTE *)"for the HP LaserJet compatibles from Portrait",
  111.     &FourthText                /* NextText         */
  112. };
  113.  
  114. struct IntuiText SecondText =
  115.     {
  116.     1,0,                /* FrontPen, BackPen */
  117.     JAM2,                /* DrawMode         */
  118.     15,40,                /* LeftEdge, TopEdge */
  119.     NULL,                /* Font (std ROM font) */
  120.     (UBYTE *)"to Landscape. Repeat for each font you wish ",
  121.     &ThirdText                /* NextText         */
  122. };
  123.  
  124. struct IntuiText FirstText =
  125.     {
  126.     1,0,                /* FrontPen, BackPen */
  127.     JAM2,                /* DrawMode         */
  128.     15,50,                /* LeftEdge, TopEdge */
  129.     NULL,                /* Font (std ROM font) */
  130.     (UBYTE *)"to convert. Rename each font as desired.",
  131.     &SecondText                /* NextText         */
  132. };
  133.  
  134. /****************************************************************/
  135. /* init_window()                        */
  136. /*    Opens Window, sets up menu strip and I/O Port        */
  137. /****************************************************************/
  138. init_window()
  139. {
  140.  
  141. struct RastPort *p_WindowRastPort;
  142.  
  143. if ( ! (IntuitionBase = (struct IntuitionBase *)
  144.     OpenLibrary("intuition.library",29)) ||
  145.      ! (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",29)) )
  146.          return(2);
  147.  
  148. /* Open the window, sets handle p_Window   */
  149. if ( ! (p_Window = (struct Window *)OpenWindow( &NewWindow )) ) {
  150.     CloseLibrary(GfxBase);    CloseLibrary(IntuitionBase);
  151.     return(3);
  152.     }
  153.  
  154.     SetMenuStrip( p_Window, &simple_menu );
  155.  
  156.     p_WindowRastPort = p_Window->RPort; /* set up text window */
  157.  
  158.     PrintIText(p_WindowRastPort, &FirstText, 10L, 20L); /* write it! */
  159.  
  160.     return NULL;
  161. }
  162.  
  163. /***************************************************************/
  164. /* clear_window                                                */
  165. /*     Clears window and screen set up by init_window          */
  166. /***************************************************************/
  167. clear_window()
  168. {
  169.    ClearMenuStrip(p_Window);
  170.    CloseWindow(p_Window);
  171.     return NULL;
  172. }
  173. delay()        /* delay for 2 seconds to read error codes */
  174.     {
  175.     long t;
  176.     long tptr;
  177.     
  178.     t = time(&tptr);
  179.     while((t + 2) > time(&tptr));
  180.     return NULL;
  181. }
  182.  
  183. /*** Main:  Open window, process inputs , close window ***/
  184. void main(argc, argv)
  185. int argc;
  186. char *argv[];
  187. {
  188.             
  189. struct IntuiMessage *message;    /* Gets input event    */
  190. int    class,code;        /* Event information    */
  191. BOOL    quit_flag;        /* Application flags    */
  192. extern int n;
  193. int    error;
  194.  
  195. if (argc > 1)
  196.     {
  197.     if (argc == 3)
  198.         {
  199.         if (error = convert(argv[1],argv[2]) != 0) { /*  process the request */
  200.             printf("Failure to process font through CLI\n");
  201.             printf("\nError message: %d\n ",error); 
  202.             switch(error){
  203.                 case '4':
  204.                     printf("Failure to open portrait font file\n");
  205.                     break;
  206.                 case '5':
  207.                     printf("Landscape file exists; rename.\n");
  208.                     break;
  209.                 case '6':
  210.                     printf("Not font file?? First char should be 'escape'\n");
  211.                     break;
  212.                 case '7':
  213.                     printf("Char size exceeds 32768; cannot process font, stopped\n");
  214.                     break;
  215.                 case '8':
  216.                     printf("escape char not found when expected, stopped\n");
  217.                     break;
  218.                 case '9':
  219.                     printf("The font descriptor is larger than expected, stopped\n");
  220.                     break;
  221.                 default:
  222.                     break;}
  223.             exit(0); 
  224.             }
  225.         printf("\nFont converted: %s --> %s\n",argv[1],argv[2]);
  226.         exit(0);
  227.     }
  228.     else {
  229.         printf("\nArgument ERROR. Correct form is:");
  230.         printf("\n'path'PORTOLAN  PORTRAIT LANDSCAPE\n\n");
  231.         exit(0);
  232.     }
  233. }
  234.  
  235. if(error = init_window() != 0) {
  236.     clear_window();
  237.     exit(FALSE);                 /* Open the window    */
  238.     }
  239. for ( quit_flag = FALSE; ! quit_flag ; ) {
  240.  
  241.     while (! (message=(struct IntuiMessage *)GetMsg(p_Window->UserPort)) )
  242.     WaitPort( p_Window->UserPort );  /* Wait for input event          */
  243.  
  244.     class = message->Class;    code = message->Code;   /* Get event info */
  245.     ReplyMsg( message );    /* Tell intuition we're through with event   */
  246.  
  247.     switch ( class ) {           /*    Process the input event           */
  248.     case CLOSEWINDOW:   quit_flag = TRUE;
  249.         break;
  250.  
  251.     /* Heres what you're looking for...    */
  252.     case MENUPICK:
  253.        if ( (MENUNUM( code ) == 0) && (ITEMNUM( code ) == 0) ) {
  254.         /* Call up the filename requester for portrait font */
  255.  
  256.         if ( get_fname(p_Window, "Portrait Path/File",file_name,dir_name) ) {
  257.             temp = strrchr(dir_name,SLASH);
  258.             if (strlen(temp) != ONE) 
  259.                 strcat(dir_name, slash);  /* add '/' if missing */
  260.             strcpy(portrait,dir_name);    /* form path name */
  261.             strcat(portrait,file_name); /* complete portrait path */
  262.             strcat(file_name,LAND);  /* add default extension */ 
  263.         }
  264.         else {
  265.             printf("User aborted request\n");
  266.             delay();
  267.             clear_window();
  268.             exit(0); }
  269.             
  270.         /* Call up the filename requester for landscape font */
  271.  
  272.         if ( get_fname(p_Window, "Rename for LANDscape:",file_name,dir_name) )  {
  273.             temp = strrchr(dir_name,SLASH);
  274.             if (strlen(temp) != ONE) 
  275.                 strcat(dir_name, slash);  /* add '/' if missing */
  276.             strcpy(landscape,dir_name);    /* form path name */
  277.             strcat(landscape,file_name);
  278.         }  
  279.         else {   
  280.             printf("User aborted file requester\n");
  281.             delay();
  282.             clear_window();
  283.             exit(0); }
  284.  
  285.         if (error = convert(portrait,landscape) != 0) { /*  process the request */
  286.             printf("Failure to process font through WB\n");
  287.             printf("\nError message: %d\n ",error); 
  288.             switch(error){
  289.                 case '4':
  290.                     printf("Failure to open portrait font file\n");
  291.                     break;
  292.                 case '5':
  293.                     printf("Landscape file exists; rename.\n");
  294.                     break;
  295.                 case '6':
  296.                     printf("Not font file?? First char should be 'escape'\n");
  297.                     break;
  298.  
  299.                 case '7':
  300.                     printf("Char size exceeds 32768; cannot process font\n");
  301.                     break;
  302.                 case '8':
  303.                     printf("escape char not found when expected, stopped\n");
  304.                     break;
  305.                 case '9':
  306.                     printf("The font descriptor is larger than expected, stopped\n");
  307.                     break;
  308.                 default:
  309.                     break;
  310.             }
  311.             delay();
  312.             clear_window();
  313.             exit(0); 
  314.             }
  315.  
  316.         strcpy(file_name,"");
  317.         break;
  318.  
  319.     } /* if MENUM */
  320.     
  321.     } /* SWITCH */ 
  322.     
  323.         
  324.    } /* for loop looking for quit.flag */
  325.    
  326. delay();   
  327. clear_window();               /* Return all resources and exit */
  328.  
  329. }
  330.