/******************************************* Name : attemptAddDosVolume Descr.: adds a new volume to dos Input : volume - volume to add Output: DOSTRUE for success; DOSFALSE otherwise ********************************************/ LONG attemptAddDosVolume(struct AFSBase *afsbase, struct Volume *volume) { struct DosList *doslist; struct DosList *dl=NULL; char string[32]; BSTR bname; UBYTE i; if (volume->volumenode) { D(bug("[afs 0x%08lX] VolumeNode is already present!\n", volume)); return DOSTRUE; } bname = volume->devicelist.dl_Name; for (i=0; i<AROS_BSTR_strlen(bname); i++) string[i] = AROS_BSTR_getchar(bname,i); string[AROS_BSTR_strlen(bname)] = 0; D(bug("[afs 0x%08lX] Processing inserted volume %s\n", volume, string)); /* is the volume already in the list? */ doslist = AttemptLockDosList(LDF_WRITE | LDF_VOLUMES); if (doslist != NULL) { dl = FindDosEntry(doslist,string,LDF_VOLUMES); UnLockDosList(LDF_WRITE | LDF_VOLUMES); } else return TRUE; /* if not create a new doslist */ if (dl == NULL) { D(bug("[afs 0x%08lX] Creating new VolumeNode\n", volume)); doslist = MakeDosEntry(string,DLT_VOLUME); if (doslist == NULL) return DOSFALSE; doslist->dol_Task = &((struct Process *)FindTask(NULL))->pr_MsgPort; doslist->dol_misc.dol_volume.dol_VolumeDate.ds_Days = volume->devicelist.dl_VolumeDate.ds_Days; doslist->dol_misc.dol_volume.dol_VolumeDate.ds_Minute = volume->devicelist.dl_VolumeDate.ds_Minute; doslist->dol_misc.dol_volume.dol_VolumeDate.ds_Tick = volume->devicelist.dl_VolumeDate.ds_Tick; AddDosEntry(doslist); /* if we re-use "volume" clear locklist */ volume->locklist = NULL; dl = doslist; } volume->volumenode = dl; SendEvent(afsbase, IECLASS_DISKINSERTED); return DOSTRUE; }
void LIBFUNC L_BtoCStr( REG(a0, BSTR bstr), REG(a1, char *cstr), REG(d0, int len)) { int length = len; int size; #ifdef __AROS__ char *string = AROS_BSTR_ADDR(bstr); #else char *string = (char *)(bstr<<2); #endif length--; #ifdef __AROS__ size = AROS_BSTR_strlen(bstr); #else size = *((UBYTE *)string); string++; #endif if (size < len) length = size; for(size=0; size<length; size++) *(cstr++) = *(string++); *cstr = 0; }
void CopyStringBSTRToC(BSTR in, STRPTR out, uint32_t max) { uint32_t i; max = AROS_BSTR_strlen(in); for(i = 0; i < max; i++) { out[i] = *(AROS_BSTR_ADDR(in) + i); } out[i] = 0; }
APTR InternalRawDoFmt(CONST_STRPTR FormatString, APTR DataStream, VOID_FUNC PutChProc, APTR inPutChData, va_list VaListStream) { #if defined(mc68000) /* Frequently, AmigaOS users of RawDoFmt() rely upon the AmigaOS * behaviour that A3 *in this routine* is the pointer to PutChData, * *and* that it can be modified in PutChProc. */ register volatile UBYTE *PutChData asm("%a3"); #else UBYTE *PutChData = inPutChData; #endif /* As long as there is something to format left */ while (*FormatString) { /* Check for '%' sign */ if (*FormatString == '%') { /* left - left align flag fill - pad character minus - 1: number is negative minwidth - minimum width maxwidth - maximum width size - one of 'h', 'l', 'i'. width - width of printable string buf - pointer to printable string */ int left = 0; int fill = ' '; int minus = 0; int size = 'h'; ULONG minwidth = 0; ULONG maxwidth = ~0; ULONG width = 0; UBYTE *buf; /* Number of decimal places required to convert a unsigned long to ascii. The formula is: ceil(number_of_bits*log10(2)). Since I can't do this here I use .302 instead of log10(2) and +1 instead of ceil() which most often leads to exactly the same result (and never becomes smaller). Note that when the buffer is large enough for decimal it's large enough for hexadecimal as well. */ #define CBUFSIZE (sizeof(IPTR)*8*302/1000+1) /* The buffer for converting long to ascii. */ UBYTE cbuf[CBUFSIZE]; ULONG i; /* Skip over '%' character */ FormatString++; /* '-' modifier? (left align) */ if (*FormatString == '-') left = *FormatString++; /* '0' modifer? (pad with zeros) */ if (*FormatString == '0') fill = *FormatString++; /* Get minimal width */ while (*FormatString >= '0' && *FormatString <= '9') { minwidth = minwidth * 10 + (*FormatString++ - '0'); } /* Dot following width modifier? */ if(*FormatString == '.') { FormatString++; /* Get maximum width */ if(*FormatString >= '0' && *FormatString <= '9') { maxwidth = 0; do maxwidth = maxwidth *10 + (*FormatString++ - '0'); while (*FormatString >= '0' && *FormatString <= '9'); } } /* size modifiers */ switch (*FormatString) { case 'l': case 'i': size = *FormatString++; break; } /* Switch over possible format characters. Sets minus, width and buf. */ switch(*FormatString) { /* BCPL string */ case 'b': { BSTR s = fetch_arg(BSTR); if (s) { buf = AROS_BSTR_ADDR(s); width = AROS_BSTR_strlen(s); } else { buf = ""; width = 0; } break; } /* C string */ case 's': buf = fetch_arg(UBYTE *); if (!buf) buf = ""; width = strlen(buf); break; { IPTR number = 0; int base; static const char digits[] = "0123456789ABCDEF"; case 'p': case 'P': fill = '0'; minwidth = sizeof(APTR)*2; size = 'i'; case 'x': case 'X': base = 16; number = fetch_number(size, 1); goto do_number; case 'd': case 'D': base = 10; number = fetch_number(size, -1); minus = (SIPTR)number < 0; if (minus) number = -number; goto do_number; case 'u': case 'U': base = 10; number = fetch_number(size, 1); do_number: buf = &cbuf[CBUFSIZE]; do { *--buf = digits[number % base]; number /= base; width++; } while (number); break; } /* single character */ case 'c': /* Some space for the result */ buf = cbuf; width = 1; *buf = fetch_number(size, 1); break; /* '%' before '\0'? */ case '\0': /* This is nonsense - but do something useful: Instead of reading over the '\0' reuse the '\0'. */ FormatString--; /* Get compiler happy */ buf = NULL; break; /* Convert '%unknown' to 'unknown'. This includes '%%' to '%'. */ default: buf = (UBYTE *)FormatString; width = 1; break; } if (width > maxwidth) width = maxwidth; /* Skip the format character */ FormatString++; /* Now everything I need is known: buf - contains the string to be printed width - the size of the string minus - is 1 if there is a '-' to print fill - is the pad character left - is 1 if the string should be left aligned minwidth - is the minimal width of the field (maxwidth is already part of width) So just print it. */ /* Print '-' (if there is one and the pad character is no space) */ if (minus && fill != ' ') PutCh('-'); /* Pad left if not left aligned */ if (!left) for (i = width + minus; i < minwidth; i++) PutCh(fill); /* Print '-' (if there is one and the pad character is a space) */ if(minus && fill == ' ') PutCh('-'); /* Print body upto width */ for(i=0; i<width; i++) { PutCh(*buf); buf++; } /* Pad right if left aligned */ if(left) for(i = width + minus; i<minwidth; i++) PutCh(fill); } else {