// Add an entry to the OpenWith file void add_open_with(char *line) { APTR file; struct Node *node; // Lock list lock_listlock(&GUI->open_with_list,1); // Too many nodes? if (Att_NodeCount((Att_List *)&GUI->open_with_list)>=environment->env->settings.max_openwith) { // List is empty? if (IsListEmpty((struct List *)&GUI->open_with_list.list)) return; // Get first node node=GUI->open_with_list.list.lh_Head; // Remove first node and free it RemHead((struct List *)&GUI->open_with_list); FreeMemH(node); } // Allocate a new node if (node=AllocMemH(global_memory_pool,sizeof(struct Node)+strlen(line)+1)) { // Initialise node and copy string node->ln_Name=(char *)(node+1); strcpy(node->ln_Name,line); // Add to Open With list AddTail((struct List *)&GUI->open_with_list,node); } // Open file for output if (file=OpenBuf("DOpus5:System/OpenWith",MODE_NEWFILE,4000)) { // Write lines for (node=GUI->open_with_list.list.lh_Head;node->ln_Succ;node=node->ln_Succ) { // Write line WriteBuf(file,node->ln_Name,strlen(node->ln_Name)); WriteBuf(file,"\n",1); } // Close file CloseBuf(file); } // Unlock list unlock_listlock(&GUI->open_with_list); }
main() { VM=MaxV*RESX; // Max allowed feed rate counts/sec A=MaxA*RESX; // Max acceleration counts/sec2 LastAngle=ch3->Dest/RESA; // initialize last angle to where we currently are OpenBuf(); // open the coordinated motion buffer DoEllipse(); // Trajectory Plan the ellipse CS0_Flushed=TRUE; // Allow Motion to run to end ExecBuf(); // launch the motion while (!CheckDoneBuf()) ; // wait till finished }
// Update pathlist void env_update_pathlist() { // Path list use allowed? if (environment->env->env_flags&ENVF_USE_PATHLIST) { APTR file; char *path; //short num; // Build environment variables //for (num=0,path="env:dopus/paths";num<2;num++,path="envarc:dopus/paths") path="env:dopus/paths"; { if ((file=OpenBuf(path,MODE_NEWFILE,4096))) { struct MinNode *node; if (IsListEmpty((struct List *)&environment->path_list.mlh_Head)) WriteBuf(file,"c:\n",3); else for (node=environment->path_list.mlh_Head;node->mln_Succ;node=node->mln_Succ) { WriteBuf(file,(char *)(node+1),-1); WriteBuf(file,"\n",1); } CloseBuf(file); } } } // Remove environment variable else { DeleteFile("env:dopus/paths"); //DeleteFile("envarc:dopus/paths"); } // Update library path list UpdatePathList(); }
// Read the OpenWith file void startup_read_openwith(void) { APTR file; // Lock list lock_listlock(&GUI->open_with_list,1); // Open file if (file=OpenBuf("DOpus5:System/OpenWith",MODE_OLDFILE,4000)) { char line[256]; short len; // Read lines while ((len=ReadBufLine(file,line,255))>0) { struct Node *node; // Allocate node if (node=AllocMemH(global_memory_pool,sizeof(struct Node)+len+1)) { // Initialise node and copy string node->ln_Name=(char *)(node+1); strcpy(node->ln_Name,line); // Add to Open With list AddTail((struct List *)&GUI->open_with_list,node); } } // Close file CloseBuf(file); } // Unlock list unlock_listlock(&GUI->open_with_list); }
// Save theme file long save_theme(struct Screen *screen,DOpusCallbackInfo *info,char *filename,BOOL build) { APTR file; APTR progress=0; char build_path[300]; struct MsgPort *reply_port; struct GetPointerPkt pkt; Att_List *list; long res=0; short a; // Building theme? if (build) { BPTR lock; short len; long count; // Copy filename to get path strcpy(build_path,filename); if ((len=strlen(build_path))>6 && stricmp(build_path+len-6,".theme")==0) build_path[len-6]=0; else strcat(build_path,".dir"); // Create theme directory if ((lock=CreateDir(build_path)) || IoErr()==ERROR_OBJECT_EXISTS) UnLock(lock); else return 0; // Get file count count=3; pkt.gpp_Type=MODPTR_SCRIPTS; pkt.gpp_Ptr=0; if ((list=(APTR)DC_CALL1(info, dc_GetPointer, DC_REGA0, &pkt))) //if ((list=DC_GetPointer(info,&pkt))) //if ((list=info->dc_GetPointer(&pkt))) { count+=Att_NodeCount(list); DC_CALL1(info, dc_FreePointer, DC_REGA0, &pkt); //DC_FreePointer(info,&pkt); //info->dc_FreePointer(&pkt); } // Open progress indicator progress=OpenProgressWindowTags( PW_Screen,(IPTR)screen, PW_Title,(IPTR)"Directory Opus Themes", PW_Info,(IPTR)GetString(locale,MSG_BUILDING_THEME), PW_Flags,PWF_INFO|PWF_GRAPH, PW_FileCount,count, PW_FileNum,0, TAG_END); } else build_path[0]=0; // Open output file if (!(file=OpenBuf(filename,MODE_NEWFILE,4096))) { CloseProgressWindow(progress); return 0; } // Create a reply port reply_port=CreateMsgPort(); // Write file introduction write_theme_intro(file,filename); // Background pictures WriteBuf(file, "/* Set background pictures */\n", -1); WriteBuf(file, "if index( apply_flags , \"B\") ~= 0 then do\n", -1); WriteBuf(file, "\tdopus set background on\n", -1); if (!save_theme_background(file,info,"desktop",reply_port,build_path,progress) || !save_theme_background(file,info,"lister",reply_port,build_path,progress) || !save_theme_background(file,info,"req",reply_port,build_path,progress)) { res=IoErr(); CloseBuf(file); CloseProgressWindow(progress); return res; } WriteBuf(file, "end\n\n",-1); // Sounds WriteBuf(file, "/* Set sound events */\n", -1); WriteBuf(file, "if index( apply_flags , \"S\") ~= 0 then do\n", -1); // Get script list (for sounds) pkt.gpp_Type=MODPTR_SCRIPTS; pkt.gpp_Ptr=0; if ((list=(APTR)DC_CALL1(info, dc_GetPointer, DC_REGA0, &pkt))) //if ((list=DC_GetPointer(info,&pkt))) //if ((list=info->dc_GetPointer(&pkt))) { Att_Node *node; // Go through scripts, find sounds for (node=(Att_Node *)list->list.lh_Head;node->node.ln_Succ;node=(Att_Node *)node->node.ln_Succ) { // No sound? if (node->data&(1<<1)) { if (progress) SetProgressWindowTags(progress,PW_FileInc,1,TAG_END); continue; } // Save the sound if (!save_theme_sound(file,info,node->node.ln_Name,reply_port,build_path,progress)) break; } // Failed? if (node->node.ln_Succ) res=IoErr(); // Free list DC_CALL1(info, dc_FreePointer, DC_REGA0, &pkt); //DC_FreePointer(info,&pkt); //info->dc_FreePointer(&pkt); // Failed? if (res) { CloseBuf(file); CloseProgressWindow(progress); return res; } } WriteBuf(file, "end\n\n",-1); // Fonts WriteBuf(file, "/* Set fonts */\n", -1); WriteBuf(file, "if index( apply_flags , \"F\") ~= 0 then do\n", -1); if (!save_theme_font(file,info,"screen",reply_port) || !save_theme_font(file,info,"listers",reply_port) || !save_theme_font(file,info,"iconsd",reply_port) || !save_theme_font(file,info,"iconsw",reply_port)) { res=IoErr(); CloseBuf(file); CloseProgressWindow(progress); return res; } WriteBuf(file, "end\n\n",-1); // Colour settings WriteBuf(file, "/* Set colour settings*/\n",-1); WriteBuf(file, "if index( apply_flags , \"P\") ~= 0 then do\n", -1); for (a=0;pen_settings[a];a++) { if (!save_theme_pens(file,info,pen_settings[a],reply_port)) break; } if (pen_settings[a] || !(save_theme_palette(file,info,reply_port))) { // Failure res=IoErr(); CloseBuf(file); CloseProgressWindow(progress); return res; } WriteBuf(file, "end\n\n",-1); // Write file outroduction write_theme_outro(file); // Close file CloseBuf(file); CloseProgressWindow(progress); return res; }
// // Get a remote file, calling the update function after each block arrives // Returns the total bytes received. // fi_errno MUST be checked for errors // Returns -2 for AmigaDos errors - Use IoErr() to report/handle them // Returns -3 for FTP server errors - Use the fi_reply and fi_iobuf fields to report/handle them // Returns -1 for rare unlikely errors - Could cause DisplayBeep() etc... // now uses IOBUFSIZE // // Update callback must specify 0xffffffff for total and length if REST fails // Update callback must specify 0xffffffff for unknown total // Update callback must specify 0 for length of final call // unsigned int get( struct ftp_info *info, int (*updatefn)(void *,unsigned int,unsigned int), void *updateinfo, char *remote_path, char *local_path, BOOL restart ) { // Needed because socket library base is in our task's tc_userdata field //struct opusftp_globals *ogp = info->fi_og; unsigned int total = 0xffffffff; // Length of file unsigned int bytes = 0; // Bytes received so far APTR f; // Output file int ds; // Data socket int b; // Byte count int reply; // FTP reply fd_set rd, ex; ULONG flags; struct timeval timer = {0}; int display_bytes; int done; D(bug( "get() '%s' -> '%s'\n", remote_path, local_path )); // Valid? if (!info) return 0; // No abort/error yet info->fi_aborted = 0; info->fi_errno = 0; info->fi_ioerr = 0; *info->fi_serverr = 0; // More validity if (!remote_path || !local_path) { info->fi_errno |= FTPERR_XFER_RARERR; return 0; } // init counters etc display_bytes = done = 0; // open output file for writing if ((f = OpenBuf( (char *)local_path, restart ? MODE_OLDFILE : MODE_NEWFILE, WBUFSIZE ))) { // Resuming? So find out where to resume from if (restart) { SeekBuf( f, 0, OFFSET_END ); bytes = SeekBuf( f, 0, OFFSET_CURRENT ); } // get connected - bytes is a market flag 0/x for RETR/REST if ((ds = dataconna( info, bytes, "RETR %s", remote_path )) < 0) { // Source (server error)? if (ds == -2 || ds == -3) { info->fi_errno |= FTPERR_XFER_SRCERR; stccpy( info->fi_serverr, info->fi_iobuf, IOBUFSIZE + 1 ); } else info->fi_errno |= FTPERR_XFER_RARERR; } else { char *p; // Reset bytes if REST failed if (bytes && (info->fi_flags & FTP_NO_REST)) { if (updatefn) (*updatefn)( updateinfo, 0xffffffff, 0xffffffff ); SeekBuf( f, 0, OFFSET_BEGINNING ); bytes = 0; } // First update tells callback where we're starting from if (updatefn) (*updatefn)( updateinfo, total, bytes ); // Does the RETR reply contain the file length? if ((p = strstr( info->fi_iobuf, " bytes)" ))) if (isdigit(*--p)) { while (isdigit(*p--)) ; total = atoi(p+2); } // do the transfer FD_ZERO( &rd ); FD_ZERO( &ex ); // set network timeout for the select wait call set_timeout(info,&timer); // loop fetch tcp data and save it while (!done) { // Note: these masks must be set before every call and // are all cleared by select wait. Examine the masks // afterwards to see what was set FD_SET( ds, &rd ); FD_SET( ds, &ex ); flags = SIGBREAKF_CTRL_D; if (WaitSelect( ds + 1 , &rd, NULL, &ex, &timer, &flags ) >= 0) { // Is there some data ready for us? if (FD_ISSET( ds, &rd )) { // then get it and store it if ((b = recv( ds, info->fi_iobuf, IOBUFSIZE, 0 ))) { // save data if (WriteBuf( f, info->fi_iobuf, b ) == b) { bytes += b; // progress bar uprate display_bytes += b; if (display_bytes >= UPDATE_BYTE_LIMIT) { if (updatefn) (*updatefn)( updateinfo, total, display_bytes ); display_bytes = 0; } } // Write Error else { info->fi_errno |= FTPERR_XFER_DSTERR; info->fi_ioerr = IoErr(); info->fi_aborted = 1; ftp_abor( info ); done = TRUE; } } else done = TRUE; } // did we get a signal to abort? if (!done && (flags & SIGBREAKF_CTRL_D)) { D(bug( "*** get() CTRL-D SIGNAL ***\n" )); info->fi_abortsignals = 0; info->fi_aborted = 1; ftp_abor( info ); // NEEDED why not just close socket? done = TRUE; } // did we get an exception? Other end closed connection maybe if (FD_ISSET( ds, &ex )) { D(bug("** get() socket exception\n")); // has been aborted from remote ? done = TRUE; } } else { // some socket error -ve a 0 == timeout D(bug( "** get() WaitSelect error\n" )); done = TRUE; } } // Final progress bar redraw at 100% (if it finished) if (!info->fi_aborted && !info->fi_errno && updatefn) (*updatefn)( updateinfo, total, 0 ); //D(bug( "--> close(%ld)\n", ds )); CloseSocket( ds ); #ifdef DEBUG // if (ui) // timeit( ui, bytes ); #endif // Get reply to socket closure Can TIMEOUT reply = getreply( info ); // If transfer was aborted, read the ABOR reply (426) // (This could get the reply to RETR (226) but it don't matter) if (info->fi_aborted && reply != 421) reply = getreply( info ); // RETR successful? - Don't set error if we forced it! // (This could get the reply to ABOR (225) but it don't matter) if (reply / 100 != COMPLETE) if (!info->fi_errno) { info->fi_errno |= FTPERR_XFER_SRCERR; stccpy( info->fi_serverr, info->fi_iobuf, IOBUFSIZE + 1 ); } } CloseBuf( f ); // Delete empty files if there was an error and we created it if (info->fi_errno && bytes == 0 && !restart) DeleteFile( (char *)local_path ); } else { info->fi_errno |= FTPERR_XFER_DSTERR; info->fi_ioerr = IoErr(); } return bytes; }
unsigned int put( struct ftp_info *info, int (*updatefn)(void *,unsigned int,unsigned int), void *updateinfo, char *local_path, char *remote_path, unsigned int restart ) { //struct opusftp_globals *ogp = info->fi_og; unsigned int bytes = 0; APTR f; // Output file int ds; // Data socket int b; // Byte count fd_set wd, ex; ULONG flags = SIGBREAKF_CTRL_D; struct timeval timer = {0}; BOOL done = FALSE; int display_bytes = 0; // Valid? if (!info) return 0; // No abort/error yet info->fi_aborted = 0; info->fi_errno = 0; info->fi_ioerr = 0; *info->fi_serverr = 0; // More validity if (!remote_path || !local_path) { info->fi_errno |= FTPERR_XFER_RARERR; return 0; } if ((f = OpenBuf( (char *)local_path, MODE_OLDFILE, WBUFSIZE ))) { // Can TIMEOUT if ((ds = dataconna( info, restart, "STOR %s", remote_path )) < 0) { // Destination (server) error? if (ds == -2 || ds == -3) { info->fi_errno |= FTPERR_XFER_DSTERR; stccpy( info->fi_serverr, info->fi_iobuf, IOBUFSIZE + 1 ); } else info->fi_errno |= FTPERR_XFER_RARERR; } else { // Resuming a transfer? if (restart) { // Start at 0 if REST failed if (info->fi_flags & FTP_NO_REST) { if (updatefn) (*updatefn)( updateinfo, 0xffffffff, 0xffffffff ); bytes = restart = 0; } // Otherwise seek to restart position else { SeekBuf( f, restart, OFFSET_BEGINNING ); bytes = restart; } } // First update tells callback where we're starting from if (updatefn) (*updatefn)( updateinfo, 0xffffffff, bytes ); // Transfer FD_ZERO( &wd ); FD_ZERO( &ex ); // set network timeout for the select wait call set_timeout(info,&timer); while (!done) { // Note: these masks must be set before every call and // are all cleared by select wait. Examine the masks // afterwards to see what was set FD_SET( ds, &wd ); FD_SET( ds, &ex ); flags = SIGBREAKF_CTRL_D; if (WaitSelect(ds+1, 0L, &wd, &ex, &timer, &flags ) >= 0) { if (FD_ISSET( ds, &wd )) { if ((b = ReadBuf( f, info->fi_iobuf, IOBUFSIZE )) > 0) { send( ds, info->fi_iobuf, b, 0 ); bytes += b; if ((display_bytes += b) >= UPDATE_BYTE_LIMIT || bytes < UPDATE_BYTE_LIMIT) { if (updatefn) (*updatefn)( updateinfo, 0xffffffff, display_bytes ); display_bytes = 0; } } else { done = TRUE; if (b < 0) { info->fi_errno |= FTPERR_XFER_SRCERR; info->fi_ioerr = IoErr(); } } } if (!done && (flags & SIGBREAKF_CTRL_D)) { D(bug( "*** put() CTRL-D SIGNAL ***\n" )); info->fi_abortsignals = 0; info->fi_aborted = TRUE; done = TRUE; } if (FD_ISSET( ds, &ex )) { D(bug( "** put() socket exception\n" )); info->fi_abortsignals = 0; done = TRUE; } } else { // some socket error -ve a 0== timeout D(bug("** put() WaitSelect error\n")); done = TRUE; } } // Final progress bar redraw at 100% (if it finished) if (!info->fi_aborted && !info->fi_errno && updatefn) (*updatefn)( updateinfo, 0xffffffff, 0 ); // Close data socket //D(bug( "--> close(%ld)\n", ds )); CloseSocket( ds ); // Get reply to socket closure - Can TIMEOUT if (getreply( info ) / 100 != COMPLETE) { info->fi_errno |= FTPERR_XFER_DSTERR; stccpy( info->fi_serverr, info->fi_iobuf, IOBUFSIZE + 1 ); } } CloseBuf( f ); } else { info->fi_errno |= FTPERR_XFER_SRCERR; info->fi_ioerr = IoErr(); } return bytes; }