home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / show / amiga / ShowOpt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-16  |  8.2 KB  |  325 lines

  1. /* externally define -dTEST to compile a standalone version    */
  2. /* otherwise, link to DVIprint                    */
  3.  
  4. #ifdef TEST
  5. #define MAIN
  6. #define DISPLAY
  7. #endif
  8.  
  9. #define TEX
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <stddef.h>
  14. #include <string.h>
  15.  
  16. #include "globals.h"
  17. #include <dos/dos.h>
  18. #include <dos/dosextens.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <pragmas/exec_pragmas.h>
  22. extern struct ExecBase        *SysBase;
  23. #include <clib/dos_protos.h>
  24. #include <pragmas/dos_pragmas.h>
  25. extern struct DosLibrary    *DOSBase;
  26.  
  27. #include "GetOpt.h"
  28. #include "GetOpt.i"
  29. #include "globals.h"
  30. #include "globals.i"
  31. #include "PrintOpt.i"    /* ShowOpt.i = PrintOpt.i */
  32.  
  33. /*
  34. #ifndef TEST
  35. #include "prhelp.h"
  36. #include "prhelp.i"
  37. #endif
  38. */
  39.  
  40. static void PrintHelp        (struct Options opt[], short long_hlp);
  41.  
  42. #ifdef TEST
  43.  
  44. extern char *_ProgramName;
  45.  
  46. static char ver[] = "$VER: ShowOpt 0.34 ("__DATE__")";
  47.  
  48.  
  49. /* liefert den Pfad zum file, falls file=="" dann Pfad des akt. Verz. */
  50. void getdir(char *file, char *dir)
  51. {
  52.   BPTR lock, lock1;
  53.   char strh[108], *h;
  54.   struct FileInfoBlock *fib;
  55.   struct Process *pr;
  56.  
  57.   if (*file == '\0') {
  58.     pr = (struct Process *)FindTask(NULL);
  59.     if (pr->pr_CurrentDir == NULL) {
  60.       strcpy(dir,"SYS:");
  61.       return;
  62.     }
  63.     else {
  64.       lock = DupLock(pr->pr_CurrentDir);
  65.     }
  66.   }
  67.   else {
  68.     lock = Lock(file,ACCESS_READ);
  69.   }
  70.  
  71.   if (lock==(BPTR)NULL) {
  72.      Fatal(5,"can't find file \"%s\" to examine!",file);
  73.   }
  74.  
  75.   dir[0]='\0';
  76.  
  77.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  78.   if (Examine(lock,fib) == 0) {
  79.     Fatal(3,"can't examine file!",17);
  80.   }
  81.  
  82.   if (file[0] == '\0' || fib->fib_DirEntryType > 0 ) {    /* aktuelles Verz. oder Dir.*/
  83.      strcpy(dir, fib->fib_FileName);
  84.      strcat(dir,"/");
  85.   }
  86.   lock1 = ParentDir(lock);
  87.   UnLock((BPTR)lock);
  88.   lock = lock1;
  89.   while (lock!=(BPTR)NULL)
  90.    {
  91.     if (Examine(lock,fib)==0) {
  92.        Fatal(3,"can't examine file!",17);
  93.     }
  94.     else {
  95.        strcpy(strh,fib->fib_FileName);
  96.        strcat(strh,"/");
  97.        strcat(strh,dir);
  98.        strcpy(dir,strh);
  99.     }
  100.     lock1 = ParentDir(lock);
  101.     UnLock((BPTR)lock);
  102.     lock = lock1;
  103.    }
  104.   h = strchr(dir,'/');
  105.   if (h != NULL) {
  106.     h[0] = ':';
  107.   }
  108.   xfree((char *)fib);
  109. }
  110.  
  111. int is_dir(char *file)
  112. {
  113.   struct FileLock *lock;
  114.   struct FileInfoBlock *fib;
  115.   int is = FALSE;
  116.  
  117.   fib = (struct FileInfoBlock *)xmalloc((unsigned)sizeof(struct FileInfoBlock));
  118.   lock = (struct FileLock *)Lock(file,ACCESS_READ);
  119.  
  120.   if (lock!=NULL) {
  121.     if (Examine((BPTR)lock,fib)!=0) {
  122.       if (fib->fib_DirEntryType>0) {
  123.         is = TRUE;
  124.       }
  125.     }
  126.     UnLock((BPTR)lock);
  127.   }
  128.   xfree((char *)fib);
  129.   return (is);
  130. }
  131.  
  132. #endif /* TEST */
  133.  
  134.  
  135.  
  136. static long help;
  137. static long o_nlogging;
  138. static char *filenameptr;
  139.  
  140.  
  141. START_PARAM(opt)
  142.   /* req?      key-name     abbrev  type         variable       help-txt */
  143.   NOREQ_PARAM ("HELP",        "?",  OPT_HELP,    &help,        "print help information", NULL)
  144.   NOREQ_PARAM ("FONTDir",     "-a", OPT_STRING,  &PXLpath,    "additional dir for fontlibs/pk-files", NULL)
  145.   NOREQ_PARAM ("FONTMem",     "-b", OPT_LONG,    &fontmemsize,    "size of the fontmemory", NULL)
  146.   NOREQ_PARAM ("Page",        NULL, OPT_LONG,    &FirstPage,    "start at page", NULL)
  147.   NOREQ_PARAM ("HOFFset",     "-h", OPT_TEX_DIM, &hoffset_in_fix, "horizontal offset `num'[true]`unit'",
  148.         "(unit out of: pt|cm|in|pc|dd|cc|bp|mm|mi|cp)")
  149.   NOREQ_PARAM ("VOFFset",     "-v", OPT_TEX_DIM, &voffset_in_fix, "vertical offset `num'[true]`unit'",
  150.         "(unit out of: pt|cm|in|pc|dd|cc|bp|mm|mi|cp)")
  151.   NOREQ_PARAM ("PREload",     "-p", OPT_BOOLEAN, &PreLoad,    "preload all fonts", NULL)
  152.   NOREQ_PARAM ("RESolution",  "-z", OPT_LONG,    &resolution,    "starting resolution in DPI", NULL)
  153.   NOREQ_PARAM ("STATistic",   "-s", OPT_BOOLEAN, &Stats,    "more output to the logfile", NULL)
  154.   HIDDEN_PARAM("DEBUGStat",   "-S", OPT_BOOLEAN, &DebugStats,    "close logfile after every line", NULL)
  155.   NOREQ_PARAM ("NOLog",       "-l", OPT_BOOLEAN, &o_nlogging,    "create logfile (ShowDVI.log)", NULL)
  156.   NOREQ_PARAM ("LOGFile",     NULL, OPT_STRING,  &g_Logname,    "logfile name", NULL)
  157.   HIDDEN_PARAM("PRINTAUTHOR", NULL, OPT_BOOLEAN, &g_authors,    "show author name", NULL)
  158.   NOREQ_PARAM (NULL,          NULL, OPT_OPTIONSTRING, &filenameptr,"DVI-file", NULL)
  159. END_PARAM
  160.  
  161.  
  162. void DecodeArgs(int argc, char *argv[])
  163. {
  164.   BOOL error;
  165.  
  166.   /*  PXLpath = FONTAREA;  */     /* default font area */
  167.  
  168.   hoffset_in_fix  = HOFFSET_IN;        /* inch */
  169.   hoffset_is_true = TRUE;        /* true inch? */
  170.   voffset_in_fix  = VOFFSET_IN;        /* inch */
  171.   voffset_is_true = TRUE;        /* true inch? */
  172.  
  173.   {
  174.     struct Option * o;
  175.     o = GetOneOpt(&hoffset_in_fix, opt)
  176.     if (o) o->special = hoffset_is_true;
  177.     o = GetOneOpt(&voffset_in_fix, opt)
  178.     if (o) o->special = voffset_is_true;
  179.   }
  180.  
  181.   fontmemsize      = FONTMEMSIZE;
  182.   FirstPage      = -1000000L;        /* first page to print (uses count0)    */
  183.   resolution      =  100;        /* hes: eher in ShowDVI.config nachschauen*/
  184.  
  185.  
  186.   /*----------------------------------------------------------------*/
  187.   error = GetOpt(argc, argv, "ShowDVI", TRUE, opt);
  188.   /*----------------------------------------------------------------*/
  189.  
  190.  
  191.   if (error) {
  192.     PrintHelp(opt, FALSE);
  193.     AbortRun(5);    /* Programm Ende */
  194.   }
  195.   if (help) {
  196.     PrintHelp(opt, TRUE);
  197.     AbortRun(0);
  198.   }
  199.  
  200.   /* true Flags setzen */
  201.   hoffset_is_true = GetOneOpt(&hoffset_in_fix, opt)->special;
  202.   voffset_is_true = GetOneOpt(&voffset_in_fix, opt)->special;
  203.  
  204.   /* Now we can check the arguments        */
  205.   g_logging    = o_nlogging ? -1 : 0;
  206.   if (DebugStats)    Stats = 2;
  207.   hconvresolution = vconvresolution = resolution;
  208.   /* fontmemsize ? */
  209.  
  210.   /* ToDo initialisieren ? */
  211.  
  212.   if (filenameptr == NULL) {
  213.     getdir("",filename);
  214.   }
  215.   else {
  216.     strcpy(filename, filenameptr);
  217.   }
  218.  
  219.   { char dir[250];        /* lokale Definition wg. Stack */
  220.     char *ext, *ptr;
  221.  
  222.     if (!is_dir(filename)) {
  223.  
  224.       if ((ext = strrchr(filename, '.')) == NULL) {
  225.         strcat(filename, ".dvi");
  226.       }
  227.       else {
  228.         if (stricmp(ext, ".tex") == NULL) {
  229.           strcpy(ext, ".dvi");    /* Ueberschreibe das '.tex' */
  230.         }
  231.         else {
  232.           if (stricmp(ext, ".dvi") != NULL) {
  233.             strcat(filename, ".dvi");
  234.           }
  235.         }
  236.       }
  237.       dvifp = fopen(filename, "r");
  238.       if (dvifp != NULL) {
  239.         /* bastle nun den vollen Pfad */
  240.         getdir(filename, dir);
  241.         if ((ptr = strrchr(filename, '/')) == NULL) {
  242.           if ((ptr = strrchr(filename, ':')) == NULL) {
  243.             strcat(dir, filename);
  244.           }
  245.           else {
  246.             strcat(dir, ptr+1);
  247.           }
  248.         }
  249.         else {
  250.           strcat(dir, ptr+1);
  251.         }
  252.         strcpy(filename, dir);
  253.       }
  254.       else {
  255.         if (strrchr(filename, ':') == NULL) {
  256.           if (strrchr(filename, '/') == NULL) {
  257.             getdir("", dir);        /* nicht gefunden, aber ohne Pfad */
  258.             strcat(dir, filename);    /* haenge Pfad an. */
  259.             strcpy(filename, dir);
  260.           }
  261.         }
  262.         Message("*** Can't find file '%s'!",filename);
  263.       }
  264.     }
  265.     else {        /* es ist ein Directory */
  266.       getdir(filename, dir);
  267.       strcpy(filename, dir);
  268.     }
  269.   }
  270. }
  271.  
  272.  
  273. static void PrintHelp(struct Options opt[], short long_hlp)
  274. {
  275.   char hlp[100];
  276.  
  277.   Message(NULL);
  278.   Message("(c)Copyright 1990-92, (hes). All rights reserved. %s\n",__DATE__);
  279.  
  280.   sprintf(hlp, "usage: %s ", g_progname);
  281.   GetOptShortHelp(hlp, 73, opt);
  282.  
  283.   if (long_hlp) {
  284.     Message("");
  285.     GetOptHelp(opt);  
  286.   }
  287.   
  288. }
  289.  
  290. #ifdef TEST
  291. void main(int argc, char *argv[])
  292. {
  293.   g_progname = 0 == argc ? _ProgramName : argv[0];
  294.   g_Logname = SHOWDVI_LOGFILE;
  295.  
  296.   DecodeArgs(argc, argv);
  297.   
  298.   printf("help:           '%ld'\n", help);
  299.   printf("PXLpath:        '%s'\n",  PXLpath);
  300.   printf("fontmemsize:    '%ld'\n", fontmemsize);
  301.   printf("FirstPage:      '%ld'\n", FirstPage);
  302.   printf("hoffset_in_fix: '%f'\n",  hoffset_in_fix);
  303.   printf("voffset_in_fix: '%f'\n",  voffset_in_fix);
  304.   printf("PreLoad:        '%ld'\n", PreLoad);
  305.   printf("resolution:     '%d'\n",  resolution);
  306.   printf("Stats:          '%ld'\n", Stats);
  307.   printf("DebugStats:     '%ld'\n", DebugStats);
  308.   printf("logging:        '%ld'\n", !o_nlogging);
  309.   printf("g_authors:      '%ld'\n", g_authors);
  310.   printf("Logfile:        '%s'\n",  g_Logname);
  311.   printf("Filename:       '%s'\n",  filename);
  312.  
  313.   {
  314.   char buf[128];
  315.  
  316.   getdir("",buf);
  317.   printf("\ngetdir(\"\",buf) = %s\n",buf);
  318.   }
  319.  
  320.   if (argc == 0) { /* WB: Lesezeit */
  321.     Delay(200);
  322.   }
  323. }
  324. #endif /* TEST */
  325.