home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / utility / resgrep0.lzh / ResGrep / src / utils.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  1.8 KB  |  102 lines

  1. /*
  2.  * Kleine Utilities, die das Leben leichter machen (ganz ohne Zucker.)
  3.  *
  4.  * 22.03.1992 Andre geschrieben.
  5.  */
  6.  
  7. #include <exec/types.h>
  8. #include <libraries/asl.h>
  9. #include <dos/var.h>
  10.  
  11. #include "list.h"
  12. #include "utils.h"
  13.  
  14. /* Wandelt einen PASCAL-String in einen C-String um. */
  15. char *pstr2cstr(void *p)
  16. {
  17.    int index;
  18.    char *pa=(char *)p;
  19.    static char buffer[256];   /* Maximale LΣnge eines PASCAL-Strings  */
  20.  
  21.    for(index=0; index<*((char *)p); index++)
  22.       buffer[index]=pa[index+1];
  23.    buffer[index]='\0';
  24.    return buffer;
  25. }
  26.  
  27. // Wandelt einen gepackten Typ in einen C-String um.
  28. char *pack2cstr(unsigned long p)
  29. {
  30.    static unsigned long pa[2];
  31.  
  32.    pa[1]=0;
  33.    pa[0]=p;
  34.    return (char *)pa;
  35. }
  36.  
  37. // Wandelt einen C-String in einen Type um.
  38. unsigned long cstr2pack(char *s)
  39. {
  40.    unsigned long  p;
  41.    char *pp;
  42.  
  43.    pp=(char *)&p;
  44.    pp[0]=s[0];
  45.    pp[1]=s[1];
  46.    pp[2]=s[2];
  47.    pp[3]=s[3];
  48.    return p;
  49. }
  50.  
  51. // Holt einen File-Namen vom ASL-Requester
  52.  
  53. char *ASLGetName(void)
  54. {
  55.    BOOL          ret;
  56.    char          buffer[1024];
  57.    int             len;
  58.  
  59.    buffer[0]='\0';
  60.    if( AslRequestTags(fr, ASL_Hail, "ResGrep", TAG_DONE) )
  61.    {
  62.       // Den FileNamen zusammenpuzzlen.
  63.       strcpy(buffer,(char *)(fr->rf_Dir));
  64.       len=strlen(buffer);
  65.       if( len!=0 && *(buffer+len)!='/' && *(buffer+len)!=':' )
  66.      *(buffer+len++)='/';
  67.       strcpy(buffer+len,(char *)(fr->rf_File));
  68.    }
  69.    return strdup(buffer);
  70. }
  71.  
  72. // Fensterkoordinatenberechnung
  73. static int XPos=30;
  74. static int YPos=30;
  75.  
  76. int NewXPos(void)
  77. {
  78.    return XPos;
  79. }
  80.  
  81. int NewYPos(void)
  82. {
  83.    return YPos;
  84. }
  85.  
  86. void CoordsUsed(void)
  87. {
  88.    XPos= (XPos+5)%550;
  89.    YPos= (YPos+14)%200;
  90. }
  91.  
  92. // Berechnet eine neue Filenummer
  93. unsigned long GetNewFileNum(void)
  94. {
  95.    extern list FileList;
  96.  
  97.    if( FileList.getfirst()->getsucc()!=NULL )
  98.       return FileList.getlast()->getpri()+1;
  99.    else
  100.       return 1;
  101. }
  102.