ErrorLevel("syntax") # 2010/05/17 (Mon) ネット接続部分修正 SleepTime = 3 selindex[1] = "しない" selindex[2] = "する" Mortexe = systempath("ScriptExe") \ "MortScript.exe" Tenkimscr = systempath("ScriptPath") \ systempath( "ScriptName" ) & systempath( "ScriptExt" ) TenkiRunAtT = """" & Tenkimscr & """ RunAtTimer=ON" TenkiRunAtA = """" & Tenkimscr & """ RunAtAutoexec=ON" gozen = "Software\5zen\Weather24" NotifyApp = "\Program Files\cmdRegistryNotifyApp\cmdRegistryNotifyApp.exe" NotifyAppStop = "\Program Files\cmdRegistryNotifyApp\cmdRegistryStopNotification.exe" ConnectName = split("接続しない,その他,インターネット設定",",") ### URL設定 URL_root = "http://tenki.jp/" URL_tenki = URL_root & "forecast/" URL_index = URL_root & "indexes/" ### データフォルダのパス DATA_path = systempath("ScriptPath") \ "Tenki24" Script_Path = systempath("ScriptPath") rlTodayskin = "\Program Files\HomeScreen PlusPlus\Floyd\Weather" if(direxists(DATA_path) = 0) mkdir(DATA_path) endif if(direxists(DATA_path \ "show" ) = 0) mkdir(DATA_path \ "show" ) endif ### テンポラリファイル名 DL_temp = DATA_path \ "Tenki.txt" ### 各指数ファイル名 TodayIndex = DATA_path \ "TodayIndex.txt" TomorrowIndex = DATA_path \ "TomorrowIndex.txt" ### テキスト出力名 Tenkiout = DATA_path \ "TenkiText.txt" ### レジストリ読み込み # 終了時にToday画面を再描画させるか call("RegstorySet","RDToday",1) ### 取得項目選択 # 気温 call("RegstorySet","Temperature",1) # 降水量 call("RegstorySet","Precipitation",1) # 湿度 call("RegstorySet","Hygro",1) # 風向きの取得 call("RegstorySet","Wind",0) # 接続方法 call("RegstorySet","InternetConnect",3) # タイマー call("RegstorySet","Timelag",5) call("RegstorySet","Interval",5) ### タイマー起動 ### if(RunAtTimer eq "ON") # Desktopが表示されている場合、五分後に再実行 if (ActiveWindow() ne "Desktop") call("TimerSet",timestamp() + 5 * 60) exit endif # ネット接続 i = 0 callfunction("NetConnect",i) if(i) # 回線接続できなかった call("TimerSet",timestamp() + Interval * 60) exit else # お天気データダウンロード callfunction("TenkiDownload",i) if(i) call("TimerSet",timestamp() + Interval * 60) else call("TimerRoundSet") endif endif # ネット切断 call("NetDisconnect") exit endif ### マニュアル起動 ### if(RunAtManual eq "ON") # 実行問い合わせ if (Question("天気情報を取得します。",""."YesNo")) # ネット接続 i = 0 callfunction("NetConnect",i) if(i) message("ネット接続できませんでした") else call("TenkiDownload") call("NetDisconnect") endif endif exit endif ### 回線接続時の自動起動によるダウンロード ### if(RunAtAutoexec eq "ON") NowTime = (((timestamp() - TimeLag * 60) / 3600) + 1) / 6 NowTime = ((NowTime - ((NowTime mod 4) = 0)) * 6 - 1) * 3600 T_Year = formattime("Y",NowTime) T_Month = formattime("m",NowTime) T_Day = formattime("d",NowTime) T_Hour = formattime("H",NowTime) # 更新確認 if(((regread("HKCU",gozen,"ReleaseYear") = T_Year) and \ (regread("HKCU",gozen,"ReleaseMonth") = T_Month) and \ (regread("HKCU",gozen,"ReleaseDay") = T_Day) and \ (regread("HKCU",gozen,"ReleaseHour") = T_Hour)) = 0) NowTime = timestamp() + 60 while((regread("HKLM","System\State\Connections","Count") = 0) and (NowTime > timestamp())) sleep(1000) endwhile if(regread("HKLM","System\State\Connections","Count") = 0) exit endif for i = 1 to 3 callfunction("TenkiDownload",j) if(j) sleep(10000) else i = 3 endif next endif exit endif while(1) ### メニュー選択 ### callfunction("TimerStr",buff) choice("お天気情報","本日のお天気:" & regread("HKCU",gozen,"Weather1") & "^NL^現在のお天気情報は^NL^" & regread("HKCU",gozen,"ReleaseYMDT") & "^NL^のものです", \ "地域選択(" & regread("HKCU",gozen,"SelectArea") & ")" , \ "" , \ "TodayRedraw      " & selindex[RDToday + 1] , \ "" , \ "タイマー設定(" & buff & ")" , \ "その他の設定" , \ "" , \ "お天気情報ダウンロード") ## 終了 case(0) exit ## 地域選択 case(1) # ネット接続 i = 0 callfunction("NetConnect",i) if(i) message("ネット接続できませんでした") else # お天気 URL for AreaSelect = 3 to 0 switch(AreaSelect) ### 地域選択 ### case(3) # html読み込み callfunction("DL_html",text,URL_tenki & "index.html",DATA_path \ "index.txt") # 地域切り出し callfunction("BetweenStrings",text,text,1,"各地の天気","^NL^") callfunction("GetArea",i,text,"area-",".html",">","<") if(i) # 選択する i = choice("地方選択","地方を選択してください",1,0,area_dir_name) if(i) DL_url = URL_tenki & "area-" & area_dir[i] & ".html" DL_name = DATA_path \ "area-" & area_dir[i] & ".txt" else # キャンセル AreaSelect = 0 endif else # 切り出し失敗 AreaSelect = 0 endif ### 都道府県等の選択 ### Case(2) # html読み込み callfunction("DL_html",text,DL_url,DL_name) # 地域切り出し callfunction("BetweenStrings",text,text,1,"各地の天気","") callfunction("GetArea",i,text,"forecast/pref-",".html",">","<") area_dir_name[i + 1] = "戻る" # 選択する j = choice("都道府県選択","都道府県等を選択してください",1,0,area_dir_name) if(j) if(j <= i) # 選択 AreaName = area_dir_name[j] DL_url = URL_tenki & "pref-" & area_dir[j] & ".html" DL_name = DATA_path \ "pref-" & area_dir[j] & ".txt" else # 戻る AreaSelect = AreaSelect + 3 endif else # キャンセル AreaSelect = 0 endif Case(1) # html読み込み callfunction("DL_html",text,DL_url,DL_name) # 地域切り出し callfunction("BetweenStrings",text,text,1,"各地の天気","のフォト") callfunction("GetArea",i,text,"forecast/city-",".html",">","<") area_dir_name[i + 1] = "戻る" # 選択する j = choice("都道府県選択","都道府県等を選択してください",1,0,area_dir_name) if(j) if(j <= i) # 選択 AreaName = area_dir_name[j] callfunction("BetweenStrings",text,text,1,AreaName,"") callfunction("GetArea",i,text,"/forecast/point-",".html",">","<") page = 0 else # 戻る AreaSelect = AreaSelect + 3 endif else # キャンセル AreaSelect = 0 endif ### 地域の選択 ### Case(0) # 選択した都道府県の選択肢のあるテキストを切り出す # callfunction("BetweenStrings",text,text,1,AreaName,"") # 切り出したテキストから選択肢を作る # callfunction("GetArea",i,text,"/forecast/point-",".html",">","<") # 選択する maxpage = (maxindex(area_dir_name) / 20) s = 0 for f = 1 to 20 area_select_name[f] = area_dir_name[f + page * 20] if (area_select_name[f] ne "") s = s + 1 endif next if (page = maxpage && page <> 0) area_select_name[s + 1] = "前のページ" else if ( page = 0 && maxpage <> 0) area_select_name[s + 1] = "次のページ" else if ( page = 0 && maxpage = 0 ) else area_select_name[s + 1] = "次のページ" area_select_name[s + 2] = "前のページ" endif endif endif # j = Choice(AreaName ,"天気を知りたい地域を選択してください" ,1 ,0 ,area_dir_name) j = Choice(AreaName ,"天気を知りたい地域を選択してください" ,1 ,0 ,area_select_name) if ( area_select_name[j] eq "次のページ") page = page + 1 AreaSelect = 1 else if ( area_select_name[j] eq "前のページ") page = page - 1 AreaSelect = 1 else if (j = 0) AreaSelect = AreaSelect + 2 else regwritestring("HKCU",gozen,"DownloadURL","point-" & area_dir[j + page * 20] & ".html") regwritestring("HKCU",gozen,"SelectArea",area_dir_name[j + page * 20]) endif endif endif EndSwitch next endif ## Today画面の再描画 case(3) call("RegstoryToggle","RDToday") ## タイマー設定 case(5) i = 1 while(i) callfunction("TimerStr",buff) choice("メニュー選択","メニューを選択してください", \ "タイマーセット(" & buff & ")" , \ "タイマーキャンセル" , \ "タイムラグ(" & Timelag & "分)" , \ "インターバル(" & Interval & "分間隔)") # 終了 case(0) regwritedword("HKCU",gozen,"Timelag",Timelag) regwritedword("HKCU",gozen,"Interval",Interval) i = 0 # タイマーセット case(1) if(question("タイマーをセットしますか?")) call("TimerDelete") callfunction("TimerRoundSet",j) message("初回 " & formattime("y/m/d H:i:s",j) & " にセットしました") endif # タイマーキャンセル case(2) if(question("タイマーをキャンセルしますか?^NL^現在 " & buff)) call("TimerDelete") message("タイマーを削除しました") endif # タイムラグ設定 case(3) j = input("更新時間の何分後にチェックしますか?","タイムラグ",0,0,Timelag) * 1 if(j<0) j = 0 endif if(question(j & "分後でよろしいですか?")) Timelag = j endif # Interval設定 case(4) j = input("更新失敗時何分後に再度チェックしますか?","インターバル",0,0,Interval) * 1 if(j<1) j = 1 endif if(question(j & "分後でよろしいですか?")) Interval = j endif endchoice endwhile ## その他の設定 case(6) i = 1 while(i) LANautoexec = regkeyexists("HKLM","System\Notifications\Weather.LANautoexec") ASautoexec = regkeyexists("HKLM","System\Notifications\Weather.ASautoexec") choice("お天気情報","各種設定", \ "ネット接続設定(" & ConnectName[InternetConnect] & ")" , \ "LAN接続時に自動更新" & selindex[LANautoexec + 1] , \ "AS開始時に自動更新" & selindex[ASautoexec + 1] , \ "アイコンダウンロード") # キャンセル case(0) i = 0 # 接続設定 case(1) j = choice("お天気情報","インターネット接続名の選択",InternetConnect,0,ConnectName) if(j) InternetConnect = j regwritedword("HKCU",gozen,"InternetConnect",InternetConnect) endif #LAN接続時の自動更新 case(2) if(LANautoexec) runwait(NotifyAppStop,"3;Weather.LANautoexec") else runwait(NotifyApp,"3;Weather24.LANautoexec;HKLM;System\State\Hardware;WiFi;" & Mortexe & ";'" & TenkiRunAtA & "';-;-;-1;1;2;16;16;-") endif # AS開始時の自動更新 case(3) if(ASautoexec) runwait(NotifyAppStop,"3;Weather.ASautoexec") else runwait(NotifyApp,"3;Weather24.ASautoexec;HKLM;System\State\Hardware;Cradled;" & Mortexe & ";'" & TenkiRunAtA & "';-;-;-1;1;2;-;1;-") endif # アイコンダウンロード case(4) call("GIFDownload") endchoice endwhile ## お天気データダウンロード case(8) showwaitcursor i = 0 call("NetConnect", i) if(i) hidewaitcursor message("ネット接続できませんでした") else call("TenkiDownload") call("NetDisconnect") hidewaitcursor endif endchoice endwhile exit ### アイコンダウンロード ### sub GIFDownload local(i,x) callfunction("PrintQuestion",i,"アイコンデータをダウンロードしますか?(約700kb)") if(i) x = 0 call("NetConnect", x) if(x) hidewaitcursor message("ネット接続できませんでした") else for i = 1 to 8 j = substr("0" & i,-2) call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/weatherPointIcon/" & j & ".gif",DATA_path \ j & ".gif") call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/weatherPointIcon/" & j & "_n.gif",DATA_path \ j & "_n.gif") call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/weatherPointIcon/" & j & "_past.gif",DATA_path \ j & "_past.gif") call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/weatherPointIcon/" & j & "_n_past.gif",DATA_path \ j & "_n_past.gif") next call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/windPointIcon/00.gif",DATA_path \ "00.gif") for i = 1 to 5 for j = 1 to 16 s = substr("0" & j,-2) call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/windPointIcon/" & i & "_" & s & ".gif",DATA_path \ i & "_" & s & ".gif") call("ImageDL","http://a1771.g.akamai.net/f/1171/76692/7d/tenki.jp/images/icon/windPointIcon/" & i & "_" & s & "_past.gif",DATA_path \ i & "_" & s & "_past.gif") next next endif endif endsub ### ネット接続 ### # out...(ret.) 0...接続している/接続した 1...接続失敗 sub NetConnect WifiNow = regread( "HKLM" , "System\State\Hardware" , "Wifi" ) CellularNow = regread( "HKLM" , "System\State\Connections\Cellular", "Count") AsNow = regread( "HKLM" , "Drivers\USB\FunctionDrivers", "ActiveSyncConnected") ipAddr = regread( "HKLM" , "Comm\Tcpip\Hosts\dtpt_peer" , "ipaddr" ) ipAddrFlg = RegValueExists( "HKLM" , "Comm\Tcpip\Hosts\dtpt_peer", "ipaddr" ) if (CellularNow > 0) return(0) else if((WifiNow = 19) or (WifiNow = 23) or (WifiNow = 27)) return(0) else if (AsNow = 1 && ipAddrFlg = TRUE) #ActiveSync接続済みでIPアドレス割り当て済み return(0) else if (AsNow = 1 && ipAddrFlg = FALSE) #ActiveSync接続済みでIPアドレス割り当てなし return (1) else if ((CellularNow = 0) and (InternetConnect <> 1)) # 回線接続する Connect(ConnectName[InternetConnect]) Sleep( 8000 ) NetConnect = regread("HKLM","System\State\Connections","Count") endif return( NetConnect = 0 ) endif endif endif endif endsub ### ネット切断 ### sub NetDisconnect endsub ### ダウンロード(ファイルキャッシュ付) ### # in....[1] ダウンロードするURL # [2] 書き込むファイル名 sub DL_html local(i) i = fileexists(argv[2]) switch(1) case(i = 1) i = (filesize(argv[2]) > 0) case(i = 0) showwaitcursor download(argv[1],argv[2]) hidewaitcursor endswitch return(readfile(argv[2],0,"utf8-prefix")) endsub ### 配列に読み込む ### # in....[1] html # [2] html切り出し切欠 # [3] html切り出しここまで # [4] 地域名切り出し切欠 # [5] 地域名切り出しここまで # out...area_dir[] html # area_dir_name[] 地域名 sub GetArea local(i,GetStr) i = 1 x = 1 clear(area_dir) clear(area_dir_name) while(x) callfunction("BetweenStrings",GetStr,argv[1],x,argv[2],argv[3]) if(GetStr ne "") area_dir[i] = GetStr callfunction("BetweenStrings",area_dir_name[i],argv[1],x,argv[4],argv[5]) i = i + 1 else x = 0 endif endwhile return(i - 1) endsub ### レジストリ読み込み ### # in....[1] レジストリ名 # [2] 初期値 sub RegstorySet if(regvalueexists("HKCU",gozen,argv[1])) [argv[1]] = regread("HKCU",gozen,argv[1]) else [argv[1]] = argv[2] endif endsub ### レジストリトグル ### # in....[1] レジストリ名 sub RegstoryToggle [argv[1]] = 1 - [argv[1]] regwritedword("HKCU",gozen,argv[1],[argv[1]]) endsub ### タイマーをセットした時間を返す ### sub TimerStr call("RegstorySet","DownloadTime",0) if(DownloadTime) return(formattime("Y/m/d({W}) H:i:s",DownloadTime)) else return("----/--/--(---) --:--:--") endif endsub ### 巡回タイマーセット ### sub TimerRoundSet local(i,t,j) t = timestamp() j = ( 3 + (formattime("H", t) / 3) * 3 ) * 3600 i = t - ( t mod 86400 ) + j + Timelag * 60 call("TimerSet",i) return(i) endsub ### タイマーセット ### sub TimerSet runat(argv[1],Mortexe,TenkiRunAtT) regwritedword("HKCU",gozen,"DownloadTime",argv[1]) endsub ### タイマー削除 ### sub TimerDelete removenotifications(Mortexe,TenkiRunAtT) regwritedword("HKCU",gozen,"DownloadTime",0) endsub ### 画像読み込み ### # in....[1] ダウンロードファイル名 # [2] ダウン先ファイル名 sub ImageDL # DL済みか if(fileexists(argv[2]) = 0) # DLする download(argv[1],argv[2]) if(filesize(argv[2]) = 0) delete(argv[2]) endif endif endsub ### メッセージ表示 ### # タイマー起動の場合は表示しない sub PrintMessage if((RunAtTimer ne "ON") and (RunAtAutoexec ne "ON")) sleepmessage(SleepTime,argv[1]) endif endsub ### エラーメッセージ表示 ### # メッセージを表示して終了する sub PrintError call("PrintMessage",argv[1]) exit endsub ### Yes/No表示 ### # タイマー起動の場合はそのまま終了 sub PrintQuestion if((RunAtTimer eq "ON") or (RunAtAutoexec eq "ON")) exit endif return(question(argv[1])) endsub ### お天気データダウンロード ### sub TenkiDownload # ダウンロードする地域のURL TenkiURL = URL_tenki & regread("HKCU",gozen,"DownloadURL") if(TenkiURL eq URL_tenki) call("PrintError","ダウンロード地域が指定されていません^NL^終了します") endif # データダウンロード download(TenkiURL,DL_temp) # 読み込みに成功しているか if(fileexists(DL_temp)) text = readfile(DL_temp,0,"utf8-prefix") # 必要な所だけ切り出す callfunction("BetweenStrings",today,text,1,"","") ### 地域取得 ### callfunction("BetweenStrings",DT_area,today,1,"

","の天気",16) ### 発表日時 ### # 年 callfunction("BetweenStrings",DT_year,today,x,""">","年",4) # 月 callfunction("BeforeStrings",DT_month,today,x,"月",2) # 日 callfunction("BeforeStrings",DT_day,today,x,"日",2) # 時 callfunction("BeforeStrings",DT_hour,today,x + 1,"時",2) # 分 callfunction("BeforeStrings",DT_minute,today,x,"分",2) #発表時間+エリア情報 textout = DT_year & "年 " & DT_month & "月 " & DT_day & "日 " & DT_hour & "時" & DT_minute & "分発表(" & DT_area & ")" regwritestring("HKCU",gozen,"ReleaseArea",DT_area) regwritestring("HKCU",gozen,"ReleaseYear",DT_year) regwritestring("HKCU",gozen,"ReleaseMonth",DT_month) regwritestring("HKCU",gozen,"ReleaseDay",DT_day) regwritestring("HKCU",gozen,"ReleaseHour",DT_hour) regwritestring("HKCU",gozen,"ReleaseMinute",DT_minute) regwritestring("HKCU",gozen,"ReleaseYMDT",textout) ### 切り分け ### for i = 1 to 2 t = x callfunction("BetweenStrings",DT_month[i] ,today, x,"日 " ,"月") x = t callfunction("BetweenStrings",DT_days[i] ,today, x,"月" ,"日") callfunction("BetweenStrings",DT_week[i] ,today, x,"(" ,")") callfunction("BetweenStrings",DT_rokuyou[i] ,today, x,"[" ,"]") next # 天気 for i = 1 to 2 for j = 1 to 8 callfunction("BetweenStrings",DT_weather[i][j] ,today, x,"weatherPointIcon/" ,".gif") callfunction("BetweenStrings",temp ,today, x,"/>" ,"<") callfunction("BetweenStrings",DT_weatherstr[i][j] ,today, x,">" ,"

") next next # 気温 for i = 1 to 2 for j = 1 to 8 x = find(today,"" ,"<") next next # 降水量 for i = 1 to 2 for j = 1 to 8 x = find(today,"" ,"<") next next # 湿度 for i = 1 to 2 for j = 1 to 8 x = find(today,"" ,"<") next next # 風向き for i = 1 to 2 for j = 1 to 8 callfunction("BetweenStrings",DT_wind[i][j] ,today, x,"windPointIcon/" ,".gif") callfunction("BetweenStrings",temp ,today, x,"/>" ,"<") callfunction("BetweenStrings",DT_windstr[i][j] ,today, x,">" ,"

") next next # 風速 WindVelocity for i = 1 to 2 for j = 1 to 8 x = find(today,"" ,"<") next next ### レジストリに書き出す for i = 1 to 2 regwritestring("HKCU",gozen \ i, "Month", DT_month[i]) regwritestring("HKCU",gozen \ i, "Day", DT_days[i]) regwritestring("HKCU",gozen \ i, "Week", DT_week[i]) regwritestring("HKCU",gozen \ i, "Rokuyou", DT_rokuyou[i]) for j = 1 to 8 s = substr("0" & j,-2) regwritestring("HKCU",gozen \ i, "Weather" & s, DT_weather[i][j]) regwritestring("HKCU",gozen \ i, "WeatherStr" & s, DT_weatherstr[i][j]) regwritestring("HKCU",gozen \ i, "Temperature" & s, DT_Temperature[i][j]) regwritestring("HKCU",gozen \ i, "Precipitation" & s, DT_Precipitation[i][j]) regwritestring("HKCU",gozen \ i, "Hygro" & s, DT_Hygro[i][j]) regwritestring("HKCU",gozen \ i, "Wind" & s, DT_wind[i][j]) regwritestring("HKCU",gozen \ i, "WindStr" & s, DT_windstr[i][j]) regwritestring("HKCU",gozen \ i, "WindVelocity" & s, DT_WindVelocity[i][j]) next next # アイコンのコピー for j = 1 to 8 copy(DATA_path \ DT_weather[1][j] & ".png",DATA_path \ "show" \ "10" & j & ".png",1) copy(DATA_path \ DT_weather[2][j] & ".png",DATA_path \ "show" \ "20" & j & ".png",1) copy(DATA_path \ DT_wind[1][j] & ".png",DATA_path \ "show" \ "11" & j & ".png",1) copy(DATA_path \ DT_wind[2][j] & ".png",DATA_path \ "show" \ "21" & j & ".png",1) next return(0) # today画面の再描画 if(RDToday) redrawtoday endif delete(DL_temp) ### ダウンロードに失敗した else call("PrintMessage","お天気データがダウンロードできませんでした") return(1) endif endsub ### 指定文字列までの文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] チェックする文字列 # out...ret() 取得文字列 # x 検索後の位置 sub BeforeStrings local(i) i = find(argv[1],argv[3],argv[2]) switch(1) case(i = 1) return("") x = i + length(argv[3]) case(i > 1) return(substr(argv[1],argv[2],i - argv[2])) x = i + length(argv[3]) case(i = 0) return("") x = argv[2] endswitch endsub ### 指定文字列以降の文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] チェックする文字列 # out...ret() 取得文字列 # x 常に1 sub AfterStrings local(i) i = find(argv[1],argv[3],argv[2]) if(i) return(substr(argv[1],i + length(argv[3]))) else return("") endif x = 1 endsub ### 指定文字列間の文字列を返す ### # in....[1] 対象文字列 # [2] 検索位置 # [3] 最初の文字列 # [4] 最後の文字列 # [5] [返り血の文字数制限] # out...ret() 取得文字列 # x 検索後の位置 sub BetweenStrings local(i,text) i = find(argv[1],argv[3],argv[2]) text = "" if(i) i = i + length(argv[3]) x = find(argv[1],argv[4],i) if(x) text = substr(argv[1],i,x-i) x = x + length(argv[4]) endif else x = argv[2] endif # 返り値の制限の有無 if(argc > 4) return(substr(text,1,argv[5])) else return(text) endif endsub