int hslink_input(user_data_rec *udta, /* current user data record */ int argc, /* argument count */ char *argv[]) /* argument values */ { /* allocate application workspace if needed */ if (udta->substt == 0) { udta->appws = (workspace_rec*)mem_alloc(sizeof(workspace_rec)); if (udta->appws == 0) { cprintf("Cannot allocate workspace for user %d!\r\n",usrnum); return 0; } } /* current workspace to application workspace for this user */ current_hsws = udta->appws; /* process current substate */ switch (udta->substt) { case 0: if (top_init()) { udta->substt = 0; break; } set_defaults(); if (argc == 1) { usage("No command line given\r\n",""); udta->substt = 0; break; } if (process_options(argc,argv)) { usage("No command line given\r\n",""); udta->substt = 0; break; } ComOpen(); WS.Option.ComSpeed = ComGetSpeed(); if (!WS.Option.EffSpeed) WS.Option.EffSpeed = WS.Option.ComSpeed; /* we're now ready for SlowHandshake to work */ WS.IoLevel = 0; /* allocate up to 10k for file buffers, but no more */ WS.buffer_sizes = mem_avail()-1000>10240: 10240:mem_avail()-1000; /* display opening screen */ prepare_display(); process_filespecs(argc,argv); /* verify hardware handshake status */ if (!ComGetCts() && !WS.Option.ForceCts) { cprintf("CTS signal missing! Please use -HC or -FC option.\r\n"); WS.Option.CtsHandshake = 0; } udta->substt = 1; break; case 1: /* wait for ready handshake with remote */ service_receive(); udta->substt = wait_for_ready()? 1:2; break; case 2: /* select first file in batch and begin transmit */ udta->curnode = WS.first_send; udta->substt = 3; break; case 3: /* end of batch? change to state 4 */ if (udta->curnode == NULL) { udta->substt = 4; PSEND("%d file%s transmitted.\r\n",WS.files_sent, WS.files_sent==1?"":"s"); break; } service_receive(); if (transmit_file(udta->curnode->name)) break; /* remain in state 3 */ /* advance to next file in the batch */ udta->curnode = udta->curnode->next; break; case 4: /* wait for remaining receive activity to terminate */ service_receive(); udta->substt = finish_receive()? 4:5; break; case 5: /* close down link */ udta->substt = terminate_link()? 5:6; break; case 6: /* process exit codes */ if (ComCarrierLost()) set_cancel_link(CANCEL_CARRIER_LOST); if ((WS.files_received+WS.files_sent) ==0) set_cancel_link(CANCEL_NO_FILES); ComClose(); close_display(); cprintf("HS/Link finished! (t:%d r:%d)",WS.files_sent,WS.files_received); cprintf(" Exit code = %d\r\n",(int)WS.cancel_link); udta->substt = 0; break; } /* if substt is 0 we are done and need to free the workspace */ if (udta->substt == 0) { current_hsws = 0; mem_free(udta->appws); udta->appws = 0; } /* otherwise we need more calls- return non 0 */ return udta->substt; }
int main(int argc, char **argv) { console_init(Version) ; //*********************************************************** // Check for NDIR environment variable //*********************************************************** // get program filename int startIdx = 1 ; char exename[PATH_MAX] ; // for (int j = 1; j < argc; j++) { // printf("0: %s\n", argv[j]) ; // } // interesting lessons from WinNT 4.0: // If the OS is WinNT 4.0, and; // If the executable file is located in the current directory, // THEN: // argv[0] does NOT contain the fully-qualified // path of the EXE, it *only* contains the EXE name. // In all other situations, argv[0] is fully qualified!! // // P.S. While we're here, derive default INI filename also // printf("argv0=%s\n", argv[0]) ; char* strptr = strrchr(argv[0], '\\') ; // no path present if (strptr == 0) { SearchPath(NULL, argv[0], ".exe", PATH_MAX, ininame, NULL) ; strptr = strrchr(ininame, '\\') ; if (strptr != 0) strcpy(strptr, "\\ndir.ini") ; strcpy(exename, argv[0]) ; // ininame[0] = 0 ; // ONLY support current location } else { // pick up INI filename strcpy(ininame, argv[0]) ; strptr = strrchr(ininame, '\\') ; if (strptr == 0) return 1; strcpy(strptr, "\\ndir.ini") ; // now process exe name for getenv() strptr++ ; //lint !e613: skip backslash strcpy(exename, strptr) ; //lint !e613 strptr = strchr(exename, '.') ; if (strptr != 0) *strptr = 0 ; // strip the extension } char* options = getenv(exename) ; if (options != 0) { argv[0] = options ; startIdx = 0 ; } // printf("ininame=%s\n", ininame) ; // getchar() ; // for (int j = startIdx; j < argc; j++) { // printf("1: %s\n", argv[j]) ; // } //*********************************************************** // first read default settings //*********************************************************** read_config_file() ; //*********************************************************** // override defaults with command line and environment vars //*********************************************************** parse_command_args(startIdx, argc, argv) ; verify_flags() ; // this may add extensions if -x is given //*********************************************************** // Execute the requested command //*********************************************************** // output_html_header("ndir32"); display_logo() ; if (n.help) info(helptxt) ; else if (n.info) info(idtxt) ; else if (n.drive_summary) display_drive_summary() ; else { // If no filespec was given, insert current path with *.* if (tcount==0) insert_target_filespec(".") ; sort_target_paths() ; // LFN: okay process_filespecs() ; } // output_html_footer(); error_exit(DATA_OKAY, NULL) ; return 0 ; }