void readUserData(void) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; printf("Reading user data...\n"); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR, "Out of memory."); } if(!(lock = Lock("NiKom:Users", ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users\n"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!scanUserDir(ed->ed_Name)) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); cleanup(EXIT_ERROR, "Could not read users."); } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock,(struct ExAllData *)buffer,2048,ED_NAME,ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); printf("Read users (Highest id: %d)\n", ((struct ShortUser *)Servermem->user_list.mlh_TailPred)->nummer); printf("User #0 : %s\n",((struct ShortUser *)Servermem->user_list.mlh_Head)->namn); }
int scanUserDir(char *dirname) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; char path[100]; printf(" Reading user directory %s...\n", dirname); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR,"Out of memory."); } sprintf(path, "NiKom:Users/%s", dirname); if(!(lock = Lock(path, ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users/x"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!readSingleUser(atoi(ed->ed_Name))) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 0; } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 1; }
int deleteDir(char *dirname) { char __aligned buffer[2048]; struct ExAllControl *ec; int moreFromExAll, success = TRUE; BPTR lock; if(!(lock = Lock(dirname, ACCESS_READ))) { return 1; } printf("Deleting all files in directory %s\n", dirname); ec = (struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL, NULL); ec->eac_LastKey=0L; ec->eac_MatchString=NULL; ec->eac_MatchFunc=NULL; do { moreFromExAll = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_TYPE, ec); if(!handleExAllResult(ec, (struct ExAllData *) buffer, dirname)) { success = FALSE; break; } } while(moreFromExAll); UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); if(success) { success = deleteFile(dirname); } return success; }
void ami_menu_arexx_scan(struct gui_window_2 *gwin) { int item = AMI_MENU_AREXX; BPTR lock = 0; UBYTE *buffer; struct ExAllControl *ctrl; char matchpatt[16]; LONG cont; struct ExAllData *ead; char *menu_lab; if(lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK)) { if(buffer = AllocVecTagList(1024, NULL)) { if(ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL)) { ctrl->eac_LastKey = 0; if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { ctrl->eac_MatchString = (char *)&matchpatt; } do { cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; if(!ctrl->eac_Entries) continue; for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { if(item >= AMI_MENU_AREXX_MAX) continue; if(EAD_IS_FILE(ead)) { gwin->menu[item].nm_Type = NM_ITEM; if(ead->ed_Comment[0] != '\0') menu_lab = ead->ed_Comment; else menu_lab = ead->ed_Name; ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL, ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name)); item++; } } }while(cont); FreeDosObject(DOS_EXALLCONTROL,ctrl); } FreeVec(buffer); } UnLock(lock); } gwin->menu[item].nm_Type = NM_END; gwin->menu[item].nm_Label = NULL; }
BOOL FileNameComplete(Object *obj, BOOL backwards, struct InstData *data) { BOOL edited = FALSE; ENTER(); if(data->FNCBuffer != NULL) { if(data->FileEntries == 1) { DisplayBeep(NULL); } else { if(backwards) { if(--data->FileNumber < 0) data->FileNumber = data->FileEntries-1; } else { if(++data->FileNumber >= data->FileEntries) data->FileNumber = 0; } } InsertFileName(data->FileNameStart, data); edited = TRUE; } else { LONG pos = DoMethod(obj, MUIM_BetterString_FileNameStart, data->Contents, data->BufferPos); switch(pos) { case MUIR_BetterString_FileNameStart_Volume: { struct DosList *dl; STRPTR volumeName = NULL; char tmpBuffer[256]; UWORD cut; pos = VolumeStart(data->Contents, data->BufferPos); if((cut = data->BufferPos-pos) != 0) { dl = LockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); while((dl = NextDosEntry(dl, LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS)) != NULL) { #ifdef __AROS__ strlcpy(tmpBuffer, dl->dol_Ext.dol_AROS.dol_DevName, sizeof tmpBuffer); #else // dol_Name is a BSTR, we have to convert it to a regular C string char *bstr = BADDR(dl->dol_Name); // a BSTR cannot exceed 255 characters, hence the buffer size of 256 is enough in any case strlcpy(tmpBuffer, &bstr[1], (unsigned char)bstr[0]); #endif if(Strnicmp(tmpBuffer, data->Contents+pos, cut) == 0) { volumeName = tmpBuffer; break; } } if(volumeName != NULL) { if(OverwriteA(volumeName, pos, cut, strlen(volumeName)+1, data)) data->Contents[data->BufferPos-1] = ':'; edited = TRUE; } UnLockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS); } } break; default: { struct FNCData *fncbuffer; struct FNCData *fncframe; struct ExAllControl *control; BPTR dirlock; char pattern[42]; UWORD namestart = data->BufferPos; char oldletter = '\0'; BOOL filename = TRUE; while(filename) { switch(*(data->Contents+namestart-1)) { case '/': case ':': filename = FALSE; break; default: namestart--; break; } } if((data->BufferPos-namestart) < 32) { strlcpy(pattern, data->Contents+namestart, sizeof(pattern)); strlcat(pattern, "~(#?.info)", sizeof(pattern)); oldletter = data->Contents[namestart]; data->Contents[namestart] = '\0'; if((fncbuffer = (struct FNCData *)SharedPoolAlloc(4100)) != NULL) { fncbuffer->next = NULL; if((control = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { char tokenized[sizeof(pattern) * 2 + 2]; if(ParsePatternNoCase(pattern, tokenized, sizeof(tokenized)) != -1) control->eac_MatchString = tokenized; if((dirlock = Lock(data->Contents+pos, ACCESS_READ))) { UWORD entries = 0; fncframe = fncbuffer; while(fncframe && ExAll(dirlock, &fncframe->buffer, 4096, ED_TYPE, control)) { entries += control->eac_Entries; if((fncframe->next = (struct FNCData *)SharedPoolAlloc(4100))) fncframe->next->next = NULL; fncframe = fncframe->next; } control->eac_Entries += entries; data->FileNumber = backwards ? control->eac_Entries-1 : 0; data->FileEntries = control->eac_Entries; data->FileNameStart = namestart; data->FNCBuffer = fncbuffer; if(control->eac_Entries) { data->Contents[namestart] = oldletter; InsertFileName(namestart, data); edited = TRUE; } UnLock(dirlock); } else { SharedPoolFree(fncbuffer); } FreeDosObject(DOS_EXALLCONTROL, (APTR)control); } } } if(edited == FALSE) data->Contents[namestart] = oldletter; } break; } } RETURN(edited); return edited; }