home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / as / source / c / riscos < prev    next >
Encoding:
Text File  |  1994-01-22  |  3.0 KB  |  119 lines

  1. /*
  2.  * riscos.c
  3.  * Copyright © 1992 Niklas Röjemo
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include "error.h"
  10. #include "riscos.h"
  11.  
  12. char *toriscos(char *name, char *oldsuffixes, char newsuffix)
  13. {
  14.   char *suf,*last;
  15.  
  16.   if((suf = strrchr(name,'.')) == 0) {
  17.     if(newsuffix != 'o')
  18.       error(ErrorError,TRUE,"Missing suffix/prefix in %s.",name);
  19.   } else if(strchr(oldsuffixes,suf[1]) != 0 && suf[2] == 0) { /* Unix style name.[so] */
  20.     last = strrchr(name,0); /* End of file name */
  21.     while(--suf >= name && *suf != '.')
  22.       *--last = *suf;   
  23.     suf[1] = newsuffix;
  24.     suf[2] = '.';
  25.   } else if(suf > name && strchr(oldsuffixes,suf[-1]) != 0 && (suf == name+1 || suf[-2] == '.')) {
  26.         suf[-1] = newsuffix;     /* RISC/OS style name s.name */
  27.   } /* else
  28.     if(newsuffix != 'o')
  29.       error(ErrorWarning,TRUE,"File %s is not an assembler file (s.name or name.s)",name);
  30.     */
  31.  
  32.   return name;
  33. }
  34.  
  35.  
  36.  
  37.  
  38. #define OS_FSControl                 0x29
  39. #define DDEUtils_ThrowbackRegister   0x42585
  40. #define DDEUtils_ThrowbackUnRegister 0x42586
  41. #define DDEUtils_ThrowbackStart      0x42587
  42. #define DDEUtils_ThrowbackSend       0x42588
  43. #define DDEUtils_ThrowbackEnd        0x42580
  44. #define Throwback_ReasonProcessing     0
  45. #define Throwback_ReasonErrorDetails   1
  46. #define Throwback_ReasonInfoDetails    2
  47.  
  48.  
  49.  
  50. os_error *ThrowbackStart(void)
  51. {
  52.   return os_swi0(os_X|DDEUtils_ThrowbackStart);
  53. }
  54.  
  55. static char *ErrorFile;
  56.  
  57. os_error *ThrowbackSendStart(char *filename)
  58. {
  59.   ErrorFile = filename;
  60.   return os_swi3(os_X|DDEUtils_ThrowbackSend,
  61.                  Throwback_ReasonProcessing,0,(int)filename);
  62. }
  63.  
  64. os_error *ThrowbackSendError(int level,int lineno,char *error)
  65. {
  66.   if(level == ThrowbackInfo)
  67.     return os_swi6(os_X|DDEUtils_ThrowbackSend,
  68.                    Throwback_ReasonInfoDetails,0,(int)ErrorFile,
  69.                    lineno,0,(int)error);
  70.   else
  71.     return os_swi6(os_X|DDEUtils_ThrowbackSend,
  72.                    Throwback_ReasonErrorDetails,0,(int)ErrorFile,
  73.                    lineno,level,(int)error);
  74. }
  75.  
  76. os_error *ThrowbackEnd(void)
  77. {
  78.   return os_swi0(os_X|DDEUtils_ThrowbackEnd);
  79. }
  80.  
  81.  
  82. #define FSControl_CanonicalisePath   37
  83.  
  84.  
  85. int OSCanonicalisePath(char *path,
  86.                        char *buffer, int bufferSize,
  87.                        char *systemVar, char *defaultPath)
  88. {
  89.   int r0,r1,r2,r3,r4,r5;
  90.   os_swi6r(OS_FSControl,FSControl_CanonicalisePath,
  91.            (int)path,(int)buffer,(int)systemVar,(int)defaultPath,bufferSize,
  92.            &r0,&r1,&r2,&r3,&r4,&r5);
  93.   return r5;
  94. }
  95.  
  96. static char filename[1024];
  97. extern int dde;
  98.  
  99. char *CanonicalisePath(char *path)
  100. {
  101.   int size;
  102.   char *buffer;
  103.   if(dde && *path == '@') { /* Replace @ with <Prefix$Dir> if dde flags */
  104.     strcpy(filename,"<Prefix$Dir>");
  105.     strcat(filename,path+1);
  106.   } else {
  107.     strcpy(filename,path);
  108.   }
  109.   size = 1-OSCanonicalisePath(filename,0,0,0,0);
  110.   buffer = malloc(size);
  111.   size = OSCanonicalisePath(filename,buffer,size,0,0);
  112.   if(size != 1) {
  113.     error(ErrorAbort,TRUE,"Internal error in CanonicalisePath (%d).",size);
  114.     exit(-1);
  115.   }
  116.   return buffer;
  117. }
  118.  
  119.