home *** CD-ROM | disk | FTP | other *** search
/ Phase 1 / phase1.bin / Utilities / FinalWrap / E / ENV_Locale.e next >
Encoding:
Text File  |  1995-07-19  |  2.1 KB  |  76 lines

  1. /* $VER: ENV_Locale 1.0 (27.04.94) by NDY's */
  2.  
  3. /* Usage:    ENV_Locale language
  4.    Effect:   OS40+    none
  5.              OS38/39  Default language to ENV[ARC]:Locale
  6.              OS37-    Set ENV[ARC]:Locale to "language"
  7.    Result:   5        Failed to open/write either ENV:Locale or ENVARC:Locale
  8.              10       Failed to open/write both files
  9.              15       Failed to open locale.library and no argument was given */
  10.  
  11. MODULE 'libraries/locale' /* Created with Iconvert from include/libraries/locale.i */
  12. DEF localebase
  13.  
  14. PROC main()
  15.   DEF res,file,fhandle,i,defloc:PTR TO locale,preflang,language[30]:STRING
  16.   IF (localebase:=OpenLibrary({locname},40))=NIL
  17.     IF localebase:=OpenLibrary({locname},0)
  18.       /* Locale V38/39 -> read preferred language (only first one) */
  19.       defloc:=openlocale(NIL)
  20.       preflang:=defloc.preflanguages
  21.       language:=^preflang
  22.       closelocale(defloc)
  23.       CloseLibrary(localebase)
  24.     ELSEIF StrLen(arg)>0
  25.       /* No locale -> use argument */
  26.       language:=arg
  27.     ELSE
  28.       /* Neither locale nor argument -> info */
  29.       WriteF({usage})
  30.       RETURN 15
  31.     ENDIF
  32.   ELSE
  33.     /* Locale V40+ -> ENV[ARC]:Language correctly set */
  34.     CloseLibrary(localebase)
  35.     RETURN NIL
  36.   ENDIF
  37.   file:={envarc}
  38.   res:=0
  39.   FOR i:=1 TO 2
  40.     IF fhandle:=Open(file,NEWFILE)
  41.       IF Write(fhandle,language,StrLen(language))<>StrLen(language) THEN res:=res+5
  42.       Close(fhandle)
  43.     ELSE
  44.       res:=res+5
  45.     ENDIF
  46.     file:={env}
  47.   ENDFOR
  48.   RETURN res
  49.              CHAR '$VER: ENV_Locale 1.0 (27.04.94) by NDY''s'
  50.   locname:   CHAR 'locale.library'
  51.   usage:     CHAR 'Usage: ENV_Locale language  equals: Echo >ENV[ARC]:Locale language\n'
  52.   envarc:    CHAR 'ENVARC:Locale'
  53.   env:       CHAR 'ENV:Locale'
  54. ENDPROC
  55.  
  56. /* The used locale.library functions */
  57. PROC openlocale(name)
  58.   DEF localeptr
  59.   CONST OPENLOCALE=-156
  60.   IF localebase<>NIL
  61.     MOVE.L  localebase,A6
  62.     MOVE.L  name,A0
  63.     JSR     OPENLOCALE(A6)
  64.     MOVE.L  D0,localeptr
  65.   ENDIF
  66. ENDPROC localeptr
  67. PROC closelocale(localeptr)
  68.   CONST CLOSELOCALE=-42
  69.   IF localebase<>NIL
  70.     MOVE.L  localebase,A6
  71.     MOVE.L  localeptr,A0
  72.     JSR     CLOSELOCALE(A6)
  73.   ENDIF
  74. ENDPROC
  75.  
  76.